glsl/nir: only set uses_sample_shading when the output is a fbfetch

Constructs like

  out vec4 fs_out;
  ....
  fs_out = vec4(...);
  if (fs_out.w < alpha_test_value)
     discard;

lead to initial nir that reads from fs_out, even though we don't actually
do a framebuffer fetch, and later nir passes will eliminate that direct
read from the output variable. As given in the commit message of 1124bee4
we are actually only interested in the framebuffer fetch, so set the
property only when an output is used for fbfetch reads.

v2: Iterate over all variables (Jason)

Fixes: commit 1124bee4ba
  glsl/nir: Set sample_shading if a FS output ever shows up as an rvalue

Signed-off-by: Gert Wollny <gert.wollny@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20694>
This commit is contained in:
Gert Wollny
2023-01-13 10:53:16 +01:00
committed by Marge Bot
parent 03105138f1
commit 0ca325cc10

View File

@@ -81,9 +81,6 @@ public:
void create_function(ir_function_signature *ir);
/* True if we have any output rvalues */
bool has_output_rvalue;
private:
void add_instr(nir_instr *instr, unsigned num_components, unsigned bit_size);
nir_ssa_def *evaluate_rvalue(ir_rvalue *ir);
@@ -263,9 +260,7 @@ glsl_to_nir(const struct gl_constants *consts,
shader->info.fs.origin_upper_left = sh->Program->info.fs.origin_upper_left;
shader->info.fs.advanced_blend_modes = sh->Program->info.fs.advanced_blend_modes;
nir_foreach_variable_with_modes(var, shader,
nir_var_shader_in |
nir_var_system_value) {
nir_foreach_variable_in_shader(var, shader) {
if (var->data.mode == nir_var_system_value &&
(var->data.location == SYSTEM_VALUE_SAMPLE_ID ||
var->data.location == SYSTEM_VALUE_SAMPLE_POS))
@@ -273,10 +268,10 @@ glsl_to_nir(const struct gl_constants *consts,
if (var->data.mode == nir_var_shader_in && var->data.sample)
shader->info.fs.uses_sample_shading = true;
}
if (v1.has_output_rvalue)
shader->info.fs.uses_sample_shading = true;
if (var->data.mode == nir_var_shader_out && var->data.fb_fetch_output)
shader->info.fs.uses_sample_shading = true;
}
}
return shader;
@@ -287,7 +282,6 @@ nir_visitor::nir_visitor(const struct gl_constants *consts, nir_shader *shader)
this->supports_std430 = consts->UseSTD430AsDefaultPacking;
this->shader = shader;
this->is_global = true;
this->has_output_rvalue = false;
this->var_table = _mesa_pointer_hash_table_create(NULL);
this->overload_table = _mesa_pointer_hash_table_create(NULL);
this->sparse_variable_set = _mesa_pointer_set_create(NULL);
@@ -1826,9 +1820,6 @@ nir_visitor::evaluate_rvalue(ir_rvalue* ir)
enum gl_access_qualifier access = deref_get_qualifier(this->deref);
this->result = nir_load_deref_with_access(&b, this->deref, access);
if (nir_deref_mode_is(this->deref, nir_var_shader_out))
this->has_output_rvalue = true;
}
return this->result;