tu: Handle case where pipeline writes unused color attachments

With VK_EXT_unused_attachments, we may have a case where the FS writes
to attachments 0 and 1, both have valid formats and are enabled, yet the
renderpass only has 1 color attachment. In this case we would set
RB_PS_MRT_CNTL to 2, but since we never emitted RB_MRT_BUF_INFO[1] and
so on, we would get garbage attachment info from the last render pass
and end up writing to an attachment that doesn't exist.

Fix this by disabling attachments that are unused. We can't move setting
RB_PS_MRT_CNTL to emitting when we emit color RT state, because then we
have the inverse problem of a FS that writes to attachments 0 and 1, a
renderpass that has 2 attachments, but a blend state that only includes
1 attachment (and therefore disables color writes for attachment 1). At
least one side (blending or RT emission) has to assume that the other
side may have more RTs enabled and disable the rest of the RTs up to
MAX_RTS.

Fixes: c2eb768eb2 ("tu: Expose VK_EXT_dynamic_rendering_unused_attachments")
(cherry picked from commit 6064e3a7d8)

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38803>
This commit is contained in:
Connor Abbott 2025-11-03 21:18:53 +01:00 committed by Dylan Baker
parent b475bf8f26
commit 1f1b69c35a
2 changed files with 6 additions and 2 deletions

View file

@ -1014,7 +1014,7 @@
"description": "tu: Handle case where pipeline writes unused color attachments",
"nominated": true,
"nomination_type": 2,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": "c2eb768eb22287a5cc0cf578f677dc0157ab008e",
"notes": null

View file

@ -588,7 +588,7 @@ tu6_emit_mrt(struct tu_cmd_buffer *cmd,
}
u_foreach_bit (i, ~written) {
if (i >= subpass->color_count)
if (i >= MAX_RTS)
break;
/* From the VkPipelineRenderingCreateInfo definition:
@ -602,6 +602,10 @@ tu6_emit_mrt(struct tu_cmd_buffer *cmd,
* here should prevent them from writing to anything. This also seems
* to also be required for alpha-to-coverage which can use the alpha
* value for an otherwise-unused attachment.
*
* With VK_EXT_dynamic_rendering_unused_attachments, pipelines may also
* write to attachments beyond those that exist in the render pass, so
* we have all attachments not written up to MAX_RTS.
*/
tu_cs_emit_regs(cs,
RB_MRT_BUF_INFO(CHIP, i),