From 811c001049789cf6beb9c9064595d89021f1deff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timur=20Krist=C3=B3f?= Date: Fri, 17 Dec 2021 17:51:18 +0100 Subject: [PATCH] radv: Lower primitive shading rate for mesh shaders. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Timur Kristóf Reviewed-by: Samuel Pitoiset Reviewed-by: Bas Nieuwenhuizen Part-of: --- src/amd/vulkan/radv_shader.c | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/src/amd/vulkan/radv_shader.c b/src/amd/vulkan/radv_shader.c index 0eba1f21a53..10d09d8edae 100644 --- a/src/amd/vulkan/radv_shader.c +++ b/src/amd/vulkan/radv_shader.c @@ -403,12 +403,30 @@ radv_lower_primitive_shading_rate(nir_shader *nir) nir_ssa_def *y_rate = nir_iand(&b, val, nir_imm_int(&b, 3)); y_rate = nir_b2i32(&b, nir_ine(&b, y_rate, nir_imm_int(&b, 0))); - /* Bits [2:3] = VRS rate X - * Bits [4:5] = VRS rate Y - * HW shading rate = (xRate << 2) | (yRate << 4) - */ - nir_ssa_def *out = nir_ior(&b, nir_ishl(&b, x_rate, nir_imm_int(&b, 2)), - nir_ishl(&b, y_rate, nir_imm_int(&b, 4))); + nir_ssa_def *out = NULL; + + if (nir->info.stage == MESA_SHADER_MESH) { + /* MS: + * Primitive shading rate is a per-primitive output, it is + * part of the second channel of the primitive export. + * + * Bits [28:29] = VRS rate X + * Bits [30:31] = VRS rate Y + * This will be added to the other bits of that channel in the backend. + */ + out = nir_ior(&b, nir_ishl(&b, x_rate, nir_imm_int(&b, 28)), + nir_ishl(&b, y_rate, nir_imm_int(&b, 30))); + } else { + /* VS, TES, GS: + * Primitive shading rate is a per-vertex output pos export. + * + * Bits [2:3] = VRS rate X + * Bits [4:5] = VRS rate Y + * HW shading rate = (xRate << 2) | (yRate << 4) + */ + out = nir_ior(&b, nir_ishl(&b, x_rate, nir_imm_int(&b, 2)), + nir_ishl(&b, y_rate, nir_imm_int(&b, 4))); + } nir_instr_rewrite_src(&intr->instr, &intr->src[1], nir_src_for_ssa(out)); @@ -761,7 +779,8 @@ radv_shader_compile_to_nir(struct radv_device *device, struct vk_shader_module * /* Lower primitive shading rate to match HW requirements. */ if ((nir->info.stage == MESA_SHADER_VERTEX || - nir->info.stage == MESA_SHADER_GEOMETRY) && + nir->info.stage == MESA_SHADER_GEOMETRY || + nir->info.stage == MESA_SHADER_MESH) && nir->info.outputs_written & BITFIELD64_BIT(VARYING_SLOT_PRIMITIVE_SHADING_RATE)) { NIR_PASS_V(nir, radv_lower_primitive_shading_rate); }