Module: Mesa
Branch: main
Commit: e95531e101f0ba61d28195fe38414e411bf418b3
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=e95531e101f0ba61d28195fe38414e411bf418b3

Author: Samuel Pitoiset <[email protected]>
Date:   Mon Aug  8 15:18:18 2022 +0200

radv: fix gathering XFB info if there is dead outputs

The driver should still gather XFB info even if all XFB outputs are
dead, otherwise the pipeline can't find the streamout shader.

RADV should use vk_spirv_to_nir() at some point to reduce code
duplication during SPIRV->NIR compilation.

This fixes new dEQP-VK.transform_feedback.simple.*.

Cc: mesa-stable
Signed-off-by: Samuel Pitoiset <[email protected]>
Reviewed-by: Mike Blumenkrantz <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17939>

---

 src/amd/vulkan/radv_shader.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/src/amd/vulkan/radv_shader.c b/src/amd/vulkan/radv_shader.c
index 9629725b7f1..2ff67029bf0 100644
--- a/src/amd/vulkan/radv_shader.c
+++ b/src/amd/vulkan/radv_shader.c
@@ -654,6 +654,16 @@ lower_sincos(struct nir_builder *b, nir_instr *instr, void 
*_)
    return sincos->op == nir_op_fsin ? nir_fsin_amd(b, src) : nir_fcos_amd(b, 
src);
 }
 
+static bool
+is_not_xfb_output(nir_variable *var, void *data)
+{
+   if (var->data.mode != nir_var_shader_out)
+      return true;
+
+   return !var->data.explicit_xfb_buffer &&
+          !var->data.explicit_xfb_stride;
+}
+
 nir_shader *
 radv_shader_spirv_to_nir(struct radv_device *device, const struct 
radv_pipeline_stage *stage,
                          const struct radv_pipeline_key *key)
@@ -837,9 +847,12 @@ radv_shader_spirv_to_nir(struct radv_device *device, const 
struct radv_pipeline_
                      .use_layer_id_sysval = false,
                   });
 
+      nir_remove_dead_variables_options dead_vars_opts = {
+         .can_remove_var = is_not_xfb_output,
+      };
       NIR_PASS(_, nir, nir_remove_dead_variables,
                nir_var_shader_in | nir_var_shader_out | nir_var_system_value | 
nir_var_mem_shared,
-               NULL);
+               &dead_vars_opts);
 
       /* Variables can make nir_propagate_invariant more conservative
        * than it needs to be.
@@ -851,6 +864,11 @@ radv_shader_spirv_to_nir(struct radv_device *device, const 
struct radv_pipeline_
 
       NIR_PASS(_, nir, nir_lower_clip_cull_distance_arrays);
 
+      if (nir->info.stage == MESA_SHADER_VERTEX ||
+          nir->info.stage == MESA_SHADER_TESS_EVAL ||
+          nir->info.stage == MESA_SHADER_GEOMETRY)
+         NIR_PASS_V(nir, nir_shader_gather_xfb_info);
+
       NIR_PASS(_, nir, nir_lower_discard_or_demote, 
key->ps.lower_discard_to_demote);
 
       nir_lower_doubles_options lower_doubles = 
nir->options->lower_doubles_options;
@@ -1038,10 +1056,6 @@ radv_shader_spirv_to_nir(struct radv_device *device, 
const struct radv_pipeline_
       radv_optimize_nir(nir, false, false);
    }
 
-   if (nir->info.stage == MESA_SHADER_VERTEX ||
-       nir->info.stage == MESA_SHADER_TESS_EVAL ||
-       nir->info.stage == MESA_SHADER_GEOMETRY)
-      NIR_PASS_V(nir, nir_shader_gather_xfb_info);
 
    return nir;
 }

Reply via email to