radv: update VRS rates on GFX11
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Tue, 10 May 2022 13:02:57 +0000 (15:02 +0200)
committerMarge Bot <emma+marge@anholt.net>
Thu, 26 May 2022 07:43:38 +0000 (07:43 +0000)
GFX11 uses enum instead of 2-bit integer numbers.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
iReviewed-by: Timur Kristóf <timur.kristof@gmail.com>

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16557>

src/amd/vulkan/radv_cmd_buffer.c
src/amd/vulkan/radv_shader.c

index 7596fe6..e87ab42 100644 (file)
@@ -3686,6 +3686,7 @@ static void
 radv_flush_force_vrs_state(struct radv_cmd_buffer *cmd_buffer)
 {
    struct radv_graphics_pipeline *pipeline = cmd_buffer->state.graphics_pipeline;
+   enum amd_gfx_level gfx_level = pipeline->base.device->physical_device->rad_info.gfx_level;
    const unsigned stage = pipeline->last_vgt_api_stage;
    struct radv_userdata_info *loc;
    uint32_t vrs_rates = 0;
@@ -3704,13 +3705,13 @@ radv_flush_force_vrs_state(struct radv_cmd_buffer *cmd_buffer)
 
    switch (cmd_buffer->device->force_vrs) {
    case RADV_FORCE_VRS_2x2:
-      vrs_rates = (1u << 2) | (1u << 4);
+      vrs_rates = gfx_level >= GFX11 ? V_0283D0_VRS_SHADING_RATE_2X2 : (1u << 2) | (1u << 4);
       break;
    case RADV_FORCE_VRS_2x1:
-      vrs_rates = (1u << 2) | (0u << 4);
+      vrs_rates = gfx_level >= GFX11 ? V_0283D0_VRS_SHADING_RATE_2X1 : (1u << 2) | (0u << 4);
       break;
    case RADV_FORCE_VRS_1x2:
-      vrs_rates = (0u << 2) | (1u << 4);
+      vrs_rates = gfx_level >= GFX11 ? V_0283D0_VRS_SHADING_RATE_1X2 : (0u << 2) | (1u << 4);
       break;
    default:
       break;
index ec6fb42..d486795 100644 (file)
@@ -342,7 +342,7 @@ lower_intrinsics(nir_shader *nir, const struct radv_pipeline_key *key)
 }
 
 static bool
-radv_lower_primitive_shading_rate(nir_shader *nir)
+radv_lower_primitive_shading_rate(nir_shader *nir, enum amd_gfx_level gfx_level)
 {
    nir_function_impl *impl = nir_shader_get_entrypoint(nir);
    bool progress = false;
@@ -381,27 +381,34 @@ radv_lower_primitive_shading_rate(nir_shader *nir)
 
          nir_ssa_def *out = NULL;
 
+         /* MS:
+          * Primitive shading rate is a per-primitive output, it is
+          * part of the second channel of the primitive export.
+          * Bits [28:31] = VRS rate
+          * This will be added to the other bits of that channel in the backend.
+          *
+          * VS, TES, GS:
+          * Primitive shading rate is a per-vertex output pos export.
+          * Bits [2:5] = VRS rate
+          * HW shading rate = (xRate << 2) | (yRate << 4)
+          *
+          * GFX11: 4-bit VRS_SHADING_RATE enum
+          * GFX10: X = low 2 bits, Y = high 2 bits
+          */
+         unsigned x_rate_shift = 2;
+         unsigned y_rate_shift = 4;
+
+         if (gfx_level >= GFX11) {
+            x_rate_shift = 4;
+            y_rate_shift = 2;
+         }
          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_imm(&b, x_rate, 28), nir_ishl_imm(&b, y_rate, 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_imm(&b, x_rate, 2), nir_ishl_imm(&b, y_rate, 4));
+            x_rate_shift += 26;
+            y_rate_shift += 26;
          }
 
+         out = nir_ior(&b, nir_ishl_imm(&b, x_rate, x_rate_shift), nir_ishl_imm(&b, y_rate, y_rate_shift));
+
          nir_instr_rewrite_src(&intr->instr, &intr->src[1], nir_src_for_ssa(out));
 
          progress = true;
@@ -937,7 +944,8 @@ radv_shader_spirv_to_nir(struct radv_device *device, const struct radv_pipeline_
         nir->info.stage == MESA_SHADER_MESH) &&
        nir->info.outputs_written & BITFIELD64_BIT(VARYING_SLOT_PRIMITIVE_SHADING_RATE)) {
       /* Lower primitive shading rate to match HW requirements. */
-      NIR_PASS(_, nir, radv_lower_primitive_shading_rate);
+      NIR_PASS(_, nir, radv_lower_primitive_shading_rate,
+               device->physical_device->rad_info.gfx_level);
    }
 
    /* Indirect lowering must be called after the radv_optimize_nir() loop