nir: Add and use some deref mode helpers
NIR derefs currently have exactly one variable mode. This is about to change so we can handle OpenCL generic pointers. In order to transition safely, we need to audit every deref->mode check. This commit adds a set of helpers that provide more nuanced mode checks and converts most of NIR to use them. For simple cases, we add nir_deref_mode_is and nir_deref_mode_is_one_of helpers. These can be used in passes which don't have to bother with generic pointers and just want to know what mode a thing is. If the pass ever encounters generic pointers in a way that this check would be unsafe, it will assert-fail to alert developers that they need to think harder about things and fix the pass. For more complex passes which require a more nuanced understanding of modes, we add nir_deref_mode_may_be and nir_deref_mode_must_be helpers which accurately describe the compiler's best knowledge about the given deref. Unfortunately, we may not be able to exactly identify the mode in a generic pointers scenario so we have to be very careful when we use these. Conversion of these passes is left to later commits. For the case of mass lowering of a particular mode (nir_lower_explicit_io is one good example), we add nir_deref_mode_is_in_set. This is also pretty assert-happy like nir_deref_mode_is but is for a set containment comparison on deref modes where you expect the deref to either be all-in or all-out. Reviewed-by: Jesse Natalie <jenatali@microsoft.com> Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6332>
This commit is contained in:

committed by
Marge Bot

parent
74886cabaa
commit
3cc58e6470
@@ -85,7 +85,7 @@ tcs_add_output_reads(nir_shader *shader, uint64_t *read, uint64_t *patches_read)
|
||||
continue;
|
||||
|
||||
nir_deref_instr *deref = nir_src_as_deref(intrin->src[0]);
|
||||
if (deref->mode != nir_var_shader_out)
|
||||
if (!nir_deref_mode_is(deref, nir_var_shader_out))
|
||||
continue;
|
||||
|
||||
nir_variable *var = nir_deref_instr_get_variable(deref);
|
||||
@@ -540,7 +540,7 @@ gather_varying_component_info(nir_shader *producer, nir_shader *consumer,
|
||||
continue;
|
||||
|
||||
nir_deref_instr *deref = nir_src_as_deref(intr->src[0]);
|
||||
if (deref->mode != nir_var_shader_in)
|
||||
if (!nir_deref_mode_is(deref, nir_var_shader_in))
|
||||
continue;
|
||||
|
||||
/* We only remap things that aren't builtins. */
|
||||
@@ -597,7 +597,7 @@ gather_varying_component_info(nir_shader *producer, nir_shader *consumer,
|
||||
continue;
|
||||
|
||||
nir_deref_instr *deref = nir_src_as_deref(intr->src[0]);
|
||||
if (deref->mode != nir_var_shader_out)
|
||||
if (!nir_deref_mode_is(deref, nir_var_shader_out))
|
||||
continue;
|
||||
|
||||
/* We only remap things that aren't builtins. */
|
||||
@@ -928,7 +928,7 @@ replace_constant_input(nir_shader *shader, nir_intrinsic_instr *store_intr)
|
||||
continue;
|
||||
|
||||
nir_deref_instr *in_deref = nir_src_as_deref(intr->src[0]);
|
||||
if (in_deref->mode != nir_var_shader_in)
|
||||
if (!nir_deref_mode_is(in_deref, nir_var_shader_in))
|
||||
continue;
|
||||
|
||||
nir_variable *in_var = nir_deref_instr_get_variable(in_deref);
|
||||
@@ -980,7 +980,7 @@ replace_duplicate_input(nir_shader *shader, nir_variable *input_var,
|
||||
continue;
|
||||
|
||||
nir_deref_instr *in_deref = nir_src_as_deref(intr->src[0]);
|
||||
if (in_deref->mode != nir_var_shader_in)
|
||||
if (!nir_deref_mode_is(in_deref, nir_var_shader_in))
|
||||
continue;
|
||||
|
||||
nir_variable *in_var = nir_deref_instr_get_variable(in_deref);
|
||||
@@ -1031,7 +1031,7 @@ nir_link_opt_varyings(nir_shader *producer, nir_shader *consumer)
|
||||
continue;
|
||||
|
||||
nir_deref_instr *out_deref = nir_src_as_deref(intr->src[0]);
|
||||
if (out_deref->mode != nir_var_shader_out)
|
||||
if (!nir_deref_mode_is(out_deref, nir_var_shader_out))
|
||||
continue;
|
||||
|
||||
nir_variable *out_var = nir_deref_instr_get_variable(out_deref);
|
||||
|
Reference in New Issue
Block a user