From 1fc25c8c7936abf503e26ee62328271631ab3bed Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Mon, 28 Nov 2022 20:26:26 -0500 Subject: [PATCH] nir/lower_blend: Handle undefs in stores nir/lower_blend asserts: assert(nir_intrinsic_write_mask(store) == nir_component_mask(store->num_components)); For the special blend shaders used in Panfrost, this holds. But for arbitrary shaders coming out of GLSL-to-NIR (as used with Asahi), this does not hold. In particular, after nir_opt_undef runs, undefined components can be trimmed. Concretely, if we have the shader: gl_FragColor.xyz = foo; Then this becomes in NIR gl_FragColor = vec4(foo.xyz, undef); and then opt_undef will give the store_deref a wrmask of xyz but 4 components. Then lower_blend asserts out. Found in a gfxbench shader on asahi. Closes: #6982 Signed-off-by: Alyssa Rosenzweig Reviewed-by: Gert Wollny Part-of: --- src/compiler/nir/nir_lower_blend.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/compiler/nir/nir_lower_blend.c b/src/compiler/nir/nir_lower_blend.c index 02b7fee85cb..610b3411fba 100644 --- a/src/compiler/nir/nir_lower_blend.c +++ b/src/compiler/nir/nir_lower_blend.c @@ -512,11 +512,10 @@ nir_lower_blend_store(nir_builder *b, nir_intrinsic_instr *store, blended = nir_trim_vector(b, blended, num_components); /* Grow or shrink the store destination as needed */ - assert(nir_intrinsic_write_mask(store) == - nir_component_mask(store->num_components)); store->num_components = num_components; store->dest.ssa.num_components = num_components; - nir_intrinsic_set_write_mask(store, nir_component_mask(num_components)); + nir_intrinsic_set_write_mask(store, nir_intrinsic_write_mask(store) & + nir_component_mask(num_components)); /* Write out the final color instead of the input */ nir_instr_rewrite_src_ssa(&store->instr, &store->src[1], blended);