nir: Add nir_foreach_shader_in/out_variable helpers
Reviewed-by: Jose Maria Casanova Crespo <jmcasanova@igalia.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5966>
This commit is contained in:

committed by
Marge Bot

parent
9bf8572222
commit
2956d53400
@@ -2209,14 +2209,14 @@ nir_remap_dual_slot_attributes(nir_shader *shader, uint64_t *dual_slot)
|
||||
assert(shader->info.stage == MESA_SHADER_VERTEX);
|
||||
|
||||
*dual_slot = 0;
|
||||
nir_foreach_variable(var, &shader->inputs) {
|
||||
nir_foreach_shader_in_variable(var, shader) {
|
||||
if (glsl_type_is_dual_slot(glsl_without_array(var->type))) {
|
||||
unsigned slots = glsl_count_attribute_slots(var->type, true);
|
||||
*dual_slot |= BITFIELD64_MASK(slots) << var->data.location;
|
||||
}
|
||||
}
|
||||
|
||||
nir_foreach_variable(var, &shader->inputs) {
|
||||
nir_foreach_shader_in_variable(var, shader) {
|
||||
var->data.location +=
|
||||
util_bitcount64(*dual_slot & BITFIELD64_MASK(var->data.location));
|
||||
}
|
||||
|
@@ -624,6 +624,18 @@ typedef struct nir_variable {
|
||||
#define nir_foreach_variable_safe(var, var_list) \
|
||||
foreach_list_typed_safe(nir_variable, var, node, var_list)
|
||||
|
||||
#define nir_foreach_shader_in_variable(var, shader) \
|
||||
nir_foreach_variable(var, &(shader)->inputs)
|
||||
|
||||
#define nir_foreach_shader_in_variable_safe(var, shader) \
|
||||
nir_foreach_variable_safe(var, &(shader)->inputs)
|
||||
|
||||
#define nir_foreach_shader_out_variable(var, shader) \
|
||||
nir_foreach_variable(var, &(shader)->outputs)
|
||||
|
||||
#define nir_foreach_shader_out_variable_safe(var, shader) \
|
||||
nir_foreach_variable_safe(var, &(shader)->outputs)
|
||||
|
||||
static inline bool
|
||||
nir_variable_is_global(const nir_variable *var)
|
||||
{
|
||||
|
@@ -202,7 +202,7 @@ nir_gather_xfb_info_with_varyings(const nir_shader *shader,
|
||||
unsigned num_outputs = 0;
|
||||
unsigned num_varyings = 0;
|
||||
nir_xfb_varyings_info *varyings_info = NULL;
|
||||
nir_foreach_variable(var, &shader->outputs) {
|
||||
nir_foreach_shader_out_variable(var, shader) {
|
||||
if (var->data.explicit_xfb_buffer) {
|
||||
num_outputs += glsl_count_attribute_slots(var->type, false);
|
||||
num_varyings += glsl_varying_count(var->type);
|
||||
@@ -218,7 +218,7 @@ nir_gather_xfb_info_with_varyings(const nir_shader *shader,
|
||||
}
|
||||
|
||||
/* Walk the list of outputs and add them to the array */
|
||||
nir_foreach_variable(var, &shader->outputs) {
|
||||
nir_foreach_shader_out_variable(var, shader) {
|
||||
if (!var->data.explicit_xfb_buffer)
|
||||
continue;
|
||||
|
||||
|
@@ -175,7 +175,7 @@ nir_remove_unused_varyings(nir_shader *producer, nir_shader *consumer)
|
||||
uint64_t read[4] = { 0 }, written[4] = { 0 };
|
||||
uint64_t patches_read[4] = { 0 }, patches_written[4] = { 0 };
|
||||
|
||||
nir_foreach_variable(var, &producer->outputs) {
|
||||
nir_foreach_shader_out_variable(var, producer) {
|
||||
for (unsigned i = 0; i < get_num_components(var); i++) {
|
||||
if (var->data.patch) {
|
||||
patches_written[var->data.location_frac + i] |=
|
||||
@@ -187,7 +187,7 @@ nir_remove_unused_varyings(nir_shader *producer, nir_shader *consumer)
|
||||
}
|
||||
}
|
||||
|
||||
nir_foreach_variable(var, &consumer->inputs) {
|
||||
nir_foreach_shader_in_variable(var, consumer) {
|
||||
for (unsigned i = 0; i < get_num_components(var); i++) {
|
||||
if (var->data.patch) {
|
||||
patches_read[var->data.location_frac + i] |=
|
||||
@@ -493,7 +493,7 @@ gather_varying_component_info(nir_shader *producer, nir_shader *consumer,
|
||||
/* Count the number of varying that can be packed and create a mapping
|
||||
* of those varyings to the array we will pass to qsort.
|
||||
*/
|
||||
nir_foreach_variable(var, &producer->outputs) {
|
||||
nir_foreach_shader_out_variable(var, producer) {
|
||||
|
||||
/* Only remap things that aren't builtins. */
|
||||
if (var->data.location >= VARYING_SLOT_VAR0 &&
|
||||
@@ -838,7 +838,7 @@ nir_link_xfb_varyings(nir_shader *producer, nir_shader *consumer)
|
||||
{
|
||||
nir_variable *input_vars[MAX_VARYING] = { 0 };
|
||||
|
||||
nir_foreach_variable(var, &consumer->inputs) {
|
||||
nir_foreach_shader_in_variable(var, consumer) {
|
||||
if (var->data.location >= VARYING_SLOT_VAR0 &&
|
||||
var->data.location - VARYING_SLOT_VAR0 < MAX_VARYING) {
|
||||
|
||||
@@ -847,7 +847,7 @@ nir_link_xfb_varyings(nir_shader *producer, nir_shader *consumer)
|
||||
}
|
||||
}
|
||||
|
||||
nir_foreach_variable(var, &producer->outputs) {
|
||||
nir_foreach_shader_out_variable(var, producer) {
|
||||
if (var->data.location >= VARYING_SLOT_VAR0 &&
|
||||
var->data.location - VARYING_SLOT_VAR0 < MAX_VARYING) {
|
||||
|
||||
@@ -872,7 +872,7 @@ does_varying_match(nir_variable *out_var, nir_variable *in_var)
|
||||
static nir_variable *
|
||||
get_matching_input_var(nir_shader *consumer, nir_variable *out_var)
|
||||
{
|
||||
nir_foreach_variable(var, &consumer->inputs) {
|
||||
nir_foreach_shader_in_variable(var, consumer) {
|
||||
if (does_varying_match(out_var, var))
|
||||
return var;
|
||||
}
|
||||
@@ -1253,7 +1253,7 @@ nir_assign_linked_io_var_locations(nir_shader *producer, nir_shader *consumer)
|
||||
uint64_t producer_output_mask = 0;
|
||||
uint64_t producer_patch_output_mask = 0;
|
||||
|
||||
nir_foreach_variable(variable, &producer->outputs) {
|
||||
nir_foreach_shader_out_variable(variable, producer) {
|
||||
uint64_t mask = get_linked_variable_io_mask(variable, producer->info.stage);
|
||||
uint64_t loc = get_linked_variable_location(variable->data.location, variable->data.patch);
|
||||
|
||||
@@ -1266,7 +1266,7 @@ nir_assign_linked_io_var_locations(nir_shader *producer, nir_shader *consumer)
|
||||
uint64_t consumer_input_mask = 0;
|
||||
uint64_t consumer_patch_input_mask = 0;
|
||||
|
||||
nir_foreach_variable(variable, &consumer->inputs) {
|
||||
nir_foreach_shader_in_variable(variable, consumer) {
|
||||
uint64_t mask = get_linked_variable_io_mask(variable, consumer->info.stage);
|
||||
uint64_t loc = get_linked_variable_location(variable->data.location, variable->data.patch);
|
||||
|
||||
@@ -1279,7 +1279,7 @@ nir_assign_linked_io_var_locations(nir_shader *producer, nir_shader *consumer)
|
||||
uint64_t io_mask = producer_output_mask | consumer_input_mask;
|
||||
uint64_t patch_io_mask = producer_patch_output_mask | consumer_patch_input_mask;
|
||||
|
||||
nir_foreach_variable(variable, &producer->outputs) {
|
||||
nir_foreach_shader_out_variable(variable, producer) {
|
||||
uint64_t loc = get_linked_variable_location(variable->data.location, variable->data.patch);
|
||||
|
||||
if (variable->data.patch)
|
||||
@@ -1288,7 +1288,7 @@ nir_assign_linked_io_var_locations(nir_shader *producer, nir_shader *consumer)
|
||||
variable->data.driver_location = util_bitcount64(io_mask & u_bit_consecutive64(0, loc)) * 4;
|
||||
}
|
||||
|
||||
nir_foreach_variable(variable, &consumer->inputs) {
|
||||
nir_foreach_shader_in_variable(variable, consumer) {
|
||||
uint64_t loc = get_linked_variable_location(variable->data.location, variable->data.patch);
|
||||
|
||||
if (variable->data.patch)
|
||||
|
@@ -61,7 +61,7 @@ nir_lower_alpha_test(nir_shader *shader, enum compare_func func,
|
||||
break;
|
||||
case nir_intrinsic_store_output:
|
||||
/* already had i/o lowered.. lookup the matching output var: */
|
||||
nir_foreach_variable(var, &shader->outputs) {
|
||||
nir_foreach_shader_out_variable(var, shader) {
|
||||
int drvloc = var->data.driver_location;
|
||||
if (nir_intrinsic_base(intr) == drvloc) {
|
||||
out = var;
|
||||
|
@@ -58,7 +58,7 @@ get_texcoord(nir_shader *shader)
|
||||
nir_variable *texcoord = NULL;
|
||||
|
||||
/* find gl_TexCoord, if it exists: */
|
||||
nir_foreach_variable(var, &shader->inputs) {
|
||||
nir_foreach_shader_in_variable(var, shader) {
|
||||
if (var->data.location == VARYING_SLOT_TEX0) {
|
||||
texcoord = var;
|
||||
break;
|
||||
|
@@ -68,7 +68,7 @@ lower_intrinsic(lower_state *state, nir_intrinsic_instr *intr)
|
||||
break;
|
||||
case nir_intrinsic_store_output:
|
||||
/* already had i/o lowered.. lookup the matching output var: */
|
||||
nir_foreach_variable(var, &state->shader->outputs) {
|
||||
nir_foreach_shader_out_variable(var, state->shader) {
|
||||
int drvloc = var->data.driver_location;
|
||||
if (nir_intrinsic_base(intr) == drvloc) {
|
||||
out = var;
|
||||
|
@@ -184,7 +184,7 @@ find_clipvertex_and_position_outputs(nir_shader *shader,
|
||||
nir_variable **clipvertex,
|
||||
nir_variable **position)
|
||||
{
|
||||
nir_foreach_variable(var, &shader->outputs) {
|
||||
nir_foreach_shader_out_variable(var, shader) {
|
||||
switch (var->data.location) {
|
||||
case VARYING_SLOT_POS:
|
||||
*position = var;
|
||||
@@ -464,7 +464,7 @@ fs_has_clip_dist_input_var(nir_shader *shader, nir_variable **io_vars,
|
||||
unsigned *ucp_enables)
|
||||
{
|
||||
assert(shader->info.stage == MESA_SHADER_FRAGMENT);
|
||||
nir_foreach_variable(var, &shader->inputs) {
|
||||
nir_foreach_shader_in_variable(var, shader) {
|
||||
switch (var->data.location) {
|
||||
case VARYING_SLOT_CLIP_DIST0:
|
||||
assert(var->data.compact);
|
||||
|
@@ -101,7 +101,7 @@ nir_lower_clip_disable(nir_shader *shader, unsigned clip_plane_enable)
|
||||
{
|
||||
bool progress = false;
|
||||
|
||||
nir_foreach_variable(var, &shader->outputs) {
|
||||
nir_foreach_shader_out_variable(var, shader) {
|
||||
if (var->data.location == VARYING_SLOT_CLIP_DIST0) {
|
||||
unsigned size = glsl_get_length(var->type);
|
||||
/* if currently-enabled planes match used planes then no-op */
|
||||
|
@@ -45,7 +45,7 @@ get_texcoord(lower_drawpixels_state *state)
|
||||
nir_variable *texcoord = NULL;
|
||||
|
||||
/* find gl_TexCoord, if it exists: */
|
||||
nir_foreach_variable(var, &state->shader->inputs) {
|
||||
nir_foreach_shader_in_variable(var, state->shader) {
|
||||
if (var->data.location == VARYING_SLOT_TEX0) {
|
||||
texcoord = var;
|
||||
break;
|
||||
@@ -267,7 +267,7 @@ lower_drawpixels_block(lower_drawpixels_state *state, nir_block *block)
|
||||
/* The intrinsic doesn't carry the variable. We need to find it
|
||||
* manually.
|
||||
*/
|
||||
nir_foreach_variable(var, &state->b.shader->inputs) {
|
||||
nir_foreach_shader_in_variable(var, state->b.shader) {
|
||||
if ((var->data.driver_location == nir_intrinsic_base(intr)) &&
|
||||
(nir_intrinsic_component(intr) >= var->data.location_frac &&
|
||||
nir_intrinsic_component(intr) <
|
||||
|
@@ -42,7 +42,7 @@ nir_lower_flatshade(nir_shader *shader)
|
||||
{
|
||||
bool progress = false;
|
||||
|
||||
nir_foreach_variable(var, &shader->inputs) {
|
||||
nir_foreach_shader_in_variable(var, shader) {
|
||||
progress |= lower_input(shader, var);
|
||||
}
|
||||
|
||||
|
@@ -27,7 +27,7 @@
|
||||
static nir_ssa_def *
|
||||
load_frag_coord(nir_builder *b)
|
||||
{
|
||||
nir_foreach_variable(var, &b->shader->inputs) {
|
||||
nir_foreach_shader_in_variable(var, b->shader) {
|
||||
if (var->data.location == VARYING_SLOT_POS)
|
||||
return nir_load_var(b, var);
|
||||
}
|
||||
|
@@ -47,7 +47,7 @@ nir_lower_mediump_outputs(nir_shader *nir)
|
||||
if (intr->intrinsic != nir_intrinsic_store_output)
|
||||
continue;
|
||||
|
||||
nir_foreach_variable (var, &nir->outputs) {
|
||||
nir_foreach_shader_out_variable(var, nir) {
|
||||
if (var->data.driver_location != nir_intrinsic_base(intr))
|
||||
continue; /* not found yet */
|
||||
|
||||
|
@@ -72,7 +72,7 @@ nir_lower_point_size_mov(nir_shader *shader,
|
||||
shader->info.stage != MESA_SHADER_COMPUTE);
|
||||
|
||||
nir_variable *out = NULL;
|
||||
nir_foreach_variable(var, &shader->outputs) {
|
||||
nir_foreach_shader_out_variable(var, shader) {
|
||||
if (var->data.location == VARYING_SLOT_PSIZ) {
|
||||
out = var;
|
||||
break;
|
||||
|
@@ -69,7 +69,7 @@ create_input(nir_shader *shader, gl_varying_slot slot,
|
||||
static nir_variable *
|
||||
create_face_input(nir_shader *shader)
|
||||
{
|
||||
nir_foreach_variable(var, &shader->inputs) {
|
||||
nir_foreach_shader_in_variable(var, shader) {
|
||||
if (var->data.location == VARYING_SLOT_FACE)
|
||||
return var;
|
||||
}
|
||||
@@ -108,7 +108,7 @@ static int
|
||||
setup_inputs(lower_2side_state *state)
|
||||
{
|
||||
/* find color inputs: */
|
||||
nir_foreach_variable(var, &state->shader->inputs) {
|
||||
nir_foreach_shader_in_variable(var, state->shader) {
|
||||
switch (var->data.location) {
|
||||
case VARYING_SLOT_COL0:
|
||||
case VARYING_SLOT_COL1:
|
||||
|
@@ -1141,7 +1141,7 @@ search_phi_bcsel(nir_ssa_scalar scalar, nir_ssa_scalar *buf, unsigned buf_size,
|
||||
static nir_variable *
|
||||
lookup_input(nir_shader *shader, unsigned driver_location)
|
||||
{
|
||||
nir_foreach_variable(var, &shader->inputs) {
|
||||
nir_foreach_shader_in_variable(var, shader) {
|
||||
if (driver_location == var->data.driver_location)
|
||||
return var;
|
||||
}
|
||||
|
Reference in New Issue
Block a user