From db1371cce1d4e0f0f4fa2518379db78efde53ea4 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Thu, 23 Mar 2023 12:48:53 -0400 Subject: [PATCH] llvmpipe: fix handling of unused color attachments if an attachment doesn't have blending or color output from the shader, nothing should touch the attachment this is consistent with vulkan spec and needed for upcoming cts coverage cc: mesa-stable Reviewed-by: Roland Scheidegger Reviewed-by: Brian Paul Part-of: --- src/gallium/drivers/llvmpipe/lp_state_fs.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c index 605fad7ac29..a06f79c2328 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_fs.c +++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c @@ -3466,7 +3466,9 @@ generate_fragment(struct llvmpipe_context *lp, /* Loop over color outputs / color buffers to do blending */ for (unsigned cbuf = 0; cbuf < key->nr_cbufs; cbuf++) { - if (key->cbuf_format[cbuf] != PIPE_FORMAT_NONE) { + if (key->cbuf_format[cbuf] != PIPE_FORMAT_NONE && + (key->blend.rt[cbuf].blend_enable || key->blend.logicop_enable || + find_output_by_semantic(&shader->info.base, TGSI_SEMANTIC_COLOR, cbuf) != -1)) { LLVMValueRef color_ptr; LLVMValueRef stride; LLVMValueRef sample_stride = NULL; @@ -3971,7 +3973,12 @@ llvmpipe_create_fs_state(struct pipe_context *pipe, shader->base.tokens = tgsi_dup_tokens(templ->tokens); } else { shader->base.ir.nir = templ->ir.nir; - nir_tgsi_scan_shader(templ->ir.nir, &shader->info.base, true); + + /* lower FRAG_RESULT_COLOR -> DATA[0-7] to correctly handle unused attachments */ + nir_shader *nir = shader->base.ir.nir; + NIR_PASS_V(nir, nir_lower_fragcolor, nir->info.fs.color_is_dual_source ? 1 : 8); + + nir_tgsi_scan_shader(nir, &shader->info.base, true); } shader->draw_data = draw_create_fragment_shader(llvmpipe->draw, templ);