Merge pull request #284 from cdavis5e/no-attachments

Add a dummy attachment in case no attachments were specified.
This commit is contained in:
Bill Hollings 2018-09-27 16:29:06 -04:00 committed by GitHub
commit 8c58c0bf72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 0 deletions

View File

@ -398,6 +398,18 @@ MTLRenderPipelineDescriptor* MVKGraphicsPipeline::getMTLRenderPipelineDescriptor
if (mvkMTLPixelFormatIsDepthFormat(mtlDSFormat)) { plDesc.depthAttachmentPixelFormat = mtlDSFormat; } if (mvkMTLPixelFormatIsDepthFormat(mtlDSFormat)) { plDesc.depthAttachmentPixelFormat = mtlDSFormat; }
if (mvkMTLPixelFormatIsStencilFormat(mtlDSFormat)) { plDesc.stencilAttachmentPixelFormat = mtlDSFormat; } if (mvkMTLPixelFormatIsStencilFormat(mtlDSFormat)) { plDesc.stencilAttachmentPixelFormat = mtlDSFormat; }
// In Vulkan, it's perfectly valid to do rasterization with no attachments.
// Not so in Metal. If we have no attachments and rasterization is enabled,
// then we'll have to add a dummy attachment.
if (plDesc.rasterizationEnabled &&
(!pCreateInfo->pColorBlendState || !pCreateInfo->pColorBlendState->attachmentCount) &&
!mvkMTLPixelFormatIsDepthFormat(mtlDSFormat) &&
!mvkMTLPixelFormatIsStencilFormat(mtlDSFormat)) {
MTLRenderPipelineColorAttachmentDescriptor* colorDesc = plDesc.colorAttachments[0];
colorDesc.pixelFormat = MTLPixelFormatR8Unorm;
colorDesc.writeMask = MTLColorWriteMaskNone;
}
// Multisampling // Multisampling
if (pCreateInfo->pMultisampleState) { if (pCreateInfo->pMultisampleState) {
plDesc.sampleCount = mvkSampleCountFromVkSampleCountFlagBits(pCreateInfo->pMultisampleState->rasterizationSamples); plDesc.sampleCount = mvkSampleCountFromVkSampleCountFlagBits(pCreateInfo->pMultisampleState->rasterizationSamples);

View File

@ -80,6 +80,7 @@ private:
std::vector<VkAttachmentReference> _resolveAttachments; std::vector<VkAttachmentReference> _resolveAttachments;
std::vector<uint32_t> _preserveAttachments; std::vector<uint32_t> _preserveAttachments;
VkAttachmentReference _depthStencilAttachment; VkAttachmentReference _depthStencilAttachment;
id<MTLTexture> _mtlDummyTex = nil;
}; };

View File

@ -115,6 +115,36 @@ void MVKRenderSubpass::populateMTLRenderPassDescriptor(MTLRenderPassDescriptor*
} }
} }
} }
_mtlDummyTex = nil;
if (caCnt == 0 && dsRPAttIdx == VK_ATTACHMENT_UNUSED) {
// Add a dummy attachment so this passes validation.
VkExtent2D fbExtent = framebuffer->getExtent2D();
MTLTextureDescriptor* mtlTexDesc = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat: MTLPixelFormatR8Unorm width: fbExtent.width height: fbExtent.height mipmapped: NO];
if (framebuffer->getLayerCount() > 1) {
mtlTexDesc.textureType = MTLTextureType2DArray;
mtlTexDesc.arrayLength = framebuffer->getLayerCount();
}
#if MVK_IOS
if ([_renderPass->getDevice()->getMTLDevice() supportsFeatureSet: MTLFeatureSet_iOS_GPUFamily1_v3]) {
mtlTexDesc.storageMode = MTLStorageModeMemoryless;
} else {
mtlTexDesc.storageMode = MTLStorageModePrivate;
}
#else
mtlTexDesc.storageMode = MTLStorageModePrivate;
#endif
mtlTexDesc.usage = MTLTextureUsageRenderTarget;
_mtlDummyTex = [_renderPass->getDevice()->getMTLDevice() newTextureWithDescriptor: mtlTexDesc]; // not retained
[_mtlDummyTex setPurgeableState: MTLPurgeableStateVolatile];
MTLRenderPassColorAttachmentDescriptor* mtlColorAttDesc = mtlRPDesc.colorAttachments[0];
mtlColorAttDesc.texture = _mtlDummyTex;
mtlColorAttDesc.level = 0;
mtlColorAttDesc.slice = 0;
mtlColorAttDesc.depthPlane = 0;
mtlColorAttDesc.loadAction = MTLLoadActionDontCare;
mtlColorAttDesc.storeAction = MTLStoreActionDontCare;
}
} }
void MVKRenderSubpass::populateClearAttachments(vector<VkClearAttachment>& clearAtts, void MVKRenderSubpass::populateClearAttachments(vector<VkClearAttachment>& clearAtts,