diff --git a/Docs/Whats_New.md b/Docs/Whats_New.md index ed29646a..32b01359 100644 --- a/Docs/Whats_New.md +++ b/Docs/Whats_New.md @@ -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. diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm b/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm index 6cf3d3be..b6bde214 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm @@ -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)) {