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; }