Support alpha-to-coverage without a color attachment.

If alpha-to-coverage is enabled, we must enable the fragment shader first color output,
even without a color attachment present or in use, so that coverage can be calculated.
This commit is contained in:
Bill Hollings 2021-07-10 15:38:02 -04:00
parent a7ffaad975
commit b1a8b59f66
2 changed files with 7 additions and 1 deletions

View File

@ -22,6 +22,7 @@ Released TBD
- Fix swizzle of depth and stencil values into RGBA (`float4`) variable in shaders.
- Disable `VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT` for
`VK_FORMAT_E5B9G9R9_UFLOAT_PACK32` on macOS Apple Silicon.
- Support alpha-to-coverage without a color attachment.

View File

@ -1546,7 +1546,12 @@ void MVKGraphicsPipeline::initShaderConversionConfig(SPIRVToMSLConversionConfigu
MVKPixelFormats* pixFmts = getPixelFormats();
MTLPixelFormat mtlDSFormat = pixFmts->getMTLPixelFormat(mvkRenderSubpass->getDepthStencilFormat());
shaderConfig.options.mslOptions.enable_frag_output_mask = 0;
// Disable any unused color attachments, because Metal validation can complain if the
// fragment shader outputs a color value without a corresponding color attachment.
// However, if alpha-to-coverage is enabled, we must enable the fragment shader first color output,
// even without a color attachment present or in use, so that coverage can be calculated.
bool hasA2C = pCreateInfo->pMultisampleState && pCreateInfo->pMultisampleState->alphaToCoverageEnable;
shaderConfig.options.mslOptions.enable_frag_output_mask = hasA2C ? 1 : 0;
if (pCreateInfo->pColorBlendState) {
for (uint32_t caIdx = 0; caIdx < pCreateInfo->pColorBlendState->attachmentCount; caIdx++) {
if (mvkRenderSubpass->isColorAttachmentUsed(caIdx)) {