From: Jason Ekstrand Date: Sat, 18 Jul 2020 23:45:18 +0000 (-0500) Subject: nir: Add a nir_foreach_uniform_variable helper X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=feb32f898c6d36f3c81c3ce2d5a3f8ddd915e332;p=mesa.git nir: Add a nir_foreach_uniform_variable helper This one's a bit more complex because it filters off only those variables with mode == nir_var_uniform. As such, it's not exactly a drop-in replacement for nir_foreach_variable(var, &nir->uniforms). Reviewed-by: Gert Wollny Part-of: --- diff --git a/src/broadcom/compiler/vir.c b/src/broadcom/compiler/vir.c index 44587d3e6e9..d7e9784a10a 100644 --- a/src/broadcom/compiler/vir.c +++ b/src/broadcom/compiler/vir.c @@ -570,7 +570,7 @@ v3d_lower_nir(struct v3d_compile *c) } /* CS textures may not have return_size reflecting the shadow state. */ - nir_foreach_variable(var, &c->s->uniforms) { + nir_foreach_uniform_variable(var, c->s) { const struct glsl_type *type = glsl_without_array(var->type); unsigned array_len = MAX2(glsl_get_length(var->type), 1); diff --git a/src/compiler/glsl/gl_nir_link_atomics.c b/src/compiler/glsl/gl_nir_link_atomics.c index 62f04af9d87..5a1a7899cc9 100644 --- a/src/compiler/glsl/gl_nir_link_atomics.c +++ b/src/compiler/glsl/gl_nir_link_atomics.c @@ -148,7 +148,7 @@ find_active_atomic_counters(struct gl_context *ctx, nir_shader *nir = sh->Program->nir; - nir_foreach_variable(var, &nir->uniforms) { + nir_foreach_uniform_variable(var, nir) { if (!glsl_contains_atomic(var->type)) continue; diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index de26c937722..b7fba8b59a4 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -636,6 +636,14 @@ typedef struct nir_variable { #define nir_foreach_shader_out_variable_safe(var, shader) \ nir_foreach_variable_safe(var, &(shader)->outputs) +#define nir_foreach_uniform_variable(var, shader) \ + nir_foreach_variable(var, &(shader)->uniforms) \ + if (var->data.mode == nir_var_uniform) + +#define nir_foreach_uniform_variable_safe(var, shader) \ + nir_foreach_variable_safe(var, &(shader)->uniforms) \ + if (var->data.mode == nir_var_uniform) + static inline bool nir_variable_is_global(const nir_variable *var) { diff --git a/src/compiler/nir/nir_gather_info.c b/src/compiler/nir/nir_gather_info.c index 7a6448887b4..0e2624c4219 100644 --- a/src/compiler/nir/nir_gather_info.c +++ b/src/compiler/nir/nir_gather_info.c @@ -601,7 +601,7 @@ nir_shader_gather_info(nir_shader *shader, nir_function_impl *entrypoint) shader->info.image_buffers = 0; shader->info.msaa_images = 0; - nir_foreach_variable(var, &shader->uniforms) { + nir_foreach_uniform_variable(var, shader) { /* Bindless textures and images don't use non-bindless slots. * Interface blocks imply inputs, outputs, UBO, or SSBO, which can only * mean bindless. diff --git a/src/compiler/nir/nir_lower_atomics_to_ssbo.c b/src/compiler/nir/nir_lower_atomics_to_ssbo.c index 8c8f9f8121e..b9ba4e4b273 100644 --- a/src/compiler/nir/nir_lower_atomics_to_ssbo.c +++ b/src/compiler/nir/nir_lower_atomics_to_ssbo.c @@ -188,7 +188,7 @@ nir_lower_atomics_to_ssbo(nir_shader *shader) if (progress) { /* replace atomic_uint uniforms with ssbo's: */ unsigned replaced = 0; - nir_foreach_variable_safe(var, &shader->uniforms) { + nir_foreach_uniform_variable_safe(var, shader) { if (is_atomic_uint(var->type)) { exec_node_remove(&var->node); diff --git a/src/gallium/auxiliary/nir/nir_draw_helpers.c b/src/gallium/auxiliary/nir/nir_draw_helpers.c index 3349d0f5eb0..5ad6c7964d9 100644 --- a/src/gallium/auxiliary/nir/nir_draw_helpers.c +++ b/src/gallium/auxiliary/nir/nir_draw_helpers.c @@ -123,7 +123,7 @@ nir_lower_pstipple_fs(struct nir_shader *shader, return; int binding = 0; - nir_foreach_variable(var, &shader->uniforms) { + nir_foreach_uniform_variable(var, shader) { if (glsl_type_is_sampler(var->type)) { if (var->data.binding >= binding) binding = var->data.binding + 1; diff --git a/src/gallium/drivers/r600/sfn/sfn_instruction_tex.cpp b/src/gallium/drivers/r600/sfn/sfn_instruction_tex.cpp index 0f0de213429..823674c2f97 100644 --- a/src/gallium/drivers/r600/sfn/sfn_instruction_tex.cpp +++ b/src/gallium/drivers/r600/sfn/sfn_instruction_tex.cpp @@ -212,7 +212,7 @@ bool r600_nir_lower_int_tg4(nir_shader *shader) std::vector lower_sampler(shader->uniforms.length(), false); auto is = lower_sampler.begin(); - nir_foreach_variable(var, &shader->uniforms) { + nir_foreach_uniform_variable(var, shader) { if (var->type->is_sampler()) { if (glsl_base_type_is_integer(var->type->sampled_type)) { need_lowering = *is = true; diff --git a/src/intel/vulkan/anv_nir_apply_pipeline_layout.c b/src/intel/vulkan/anv_nir_apply_pipeline_layout.c index b5b7cd08041..ded0310695b 100644 --- a/src/intel/vulkan/anv_nir_apply_pipeline_layout.c +++ b/src/intel/vulkan/anv_nir_apply_pipeline_layout.c @@ -1286,7 +1286,7 @@ anv_nir_apply_pipeline_layout(const struct anv_physical_device *pdevice, } } - nir_foreach_variable(var, &shader->uniforms) { + nir_foreach_uniform_variable(var, shader) { const struct glsl_type *glsl_type = glsl_without_array(var->type); if (!glsl_type_is_image(glsl_type)) diff --git a/src/mesa/drivers/dri/i965/brw_link.cpp b/src/mesa/drivers/dri/i965/brw_link.cpp index cfd56cef0df..20845a7aac7 100644 --- a/src/mesa/drivers/dri/i965/brw_link.cpp +++ b/src/mesa/drivers/dri/i965/brw_link.cpp @@ -346,7 +346,7 @@ brw_link_shader(struct gl_context *ctx, struct gl_shader_program *shProg) * too late. At that point, the values for the built-in uniforms won't * get sent to the shader. */ - nir_foreach_variable(var, &prog->nir->uniforms) { + nir_foreach_uniform_variable(var, prog->nir) { const nir_state_slot *const slots = var->state_slots; for (unsigned int i = 0; i < var->num_state_slots; i++) { assert(slots != NULL); diff --git a/src/mesa/drivers/dri/i965/brw_nir_uniforms.cpp b/src/mesa/drivers/dri/i965/brw_nir_uniforms.cpp index 639bdfc0f2c..25df2cf5b27 100644 --- a/src/mesa/drivers/dri/i965/brw_nir_uniforms.cpp +++ b/src/mesa/drivers/dri/i965/brw_nir_uniforms.cpp @@ -222,7 +222,7 @@ brw_nir_setup_glsl_uniforms(void *mem_ctx, nir_shader *shader, stage_prog_data->nr_params = nr_params; stage_prog_data->param = rzalloc_array(mem_ctx, uint32_t, nr_params); - nir_foreach_variable(var, &shader->uniforms) { + nir_foreach_uniform_variable(var, shader) { /* UBO's, atomics and samplers don't take up space in the uniform file */ if (var->interface_type != NULL || var->type->contains_atomic()) @@ -306,7 +306,7 @@ brw_nir_lower_gl_images(nir_shader *shader, const struct gl_program *prog) { /* We put image uniforms at the end */ - nir_foreach_variable(var, &shader->uniforms) { + nir_foreach_uniform_variable(var, shader) { if (!var->type->contains_image()) continue; diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp b/src/mesa/state_tracker/st_glsl_to_nir.cpp index 6b1c1d6c391..bc8592d22e2 100644 --- a/src/mesa/state_tracker/st_glsl_to_nir.cpp +++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp @@ -195,21 +195,14 @@ st_nir_lookup_parameter_index(struct gl_program *prog, nir_variable *var) static void st_nir_assign_uniform_locations(struct gl_context *ctx, struct gl_program *prog, - struct exec_list *uniform_list) + nir_shader *nir) { int shaderidx = 0; int imageidx = 0; - nir_foreach_variable(uniform, uniform_list) { + nir_foreach_uniform_variable(uniform, nir) { int loc; - /* - * UBO's have their own address spaces, so don't count them towards the - * number of global uniforms - */ - if (uniform->data.mode == nir_var_mem_ubo || uniform->data.mode == nir_var_mem_ssbo) - continue; - const struct glsl_type *type = glsl_without_array(uniform->type); if (!uniform->data.bindless && (type->is_sampler() || type->is_image())) { if (type->is_sampler()) { @@ -448,7 +441,7 @@ st_glsl_to_nir_post_opts(struct st_context *st, struct gl_program *prog, * too late. At that point, the values for the built-in uniforms won't * get sent to the shader. */ - nir_foreach_variable(var, &nir->uniforms) { + nir_foreach_uniform_variable(var, nir) { const nir_state_slot *const slots = var->state_slots; if (slots != NULL) { const struct glsl_type *type = glsl_without_array(var->type); @@ -949,8 +942,7 @@ st_finalize_nir(struct st_context *st, struct gl_program *prog, NIR_PASS_V(nir, nir_lower_var_copies); st_nir_assign_varying_locations(st, nir); - st_nir_assign_uniform_locations(st->ctx, prog, - &nir->uniforms); + st_nir_assign_uniform_locations(st->ctx, prog, nir); /* Set num_uniforms in number of attribute slots (vec4s) */ nir->num_uniforms = DIV_ROUND_UP(prog->Parameters->NumParameterValues, 4); diff --git a/src/mesa/state_tracker/st_nir_lower_builtin.c b/src/mesa/state_tracker/st_nir_lower_builtin.c index 4227ee5529a..dd4a30c518d 100644 --- a/src/mesa/state_tracker/st_nir_lower_builtin.c +++ b/src/mesa/state_tracker/st_nir_lower_builtin.c @@ -126,7 +126,7 @@ get_variable(lower_builtin_state *state, nir_deref_path *path, char *name = _mesa_program_state_string(tokens); - nir_foreach_variable(var, &shader->uniforms) { + nir_foreach_uniform_variable(var, shader) { if (strcmp(var->name, name) == 0) { free(name); return var; diff --git a/src/mesa/state_tracker/st_nir_lower_tex_src_plane.c b/src/mesa/state_tracker/st_nir_lower_tex_src_plane.c index 44597e789a2..2697c1460b2 100644 --- a/src/mesa/state_tracker/st_nir_lower_tex_src_plane.c +++ b/src/mesa/state_tracker/st_nir_lower_tex_src_plane.c @@ -50,7 +50,7 @@ static nir_variable * find_sampler(lower_tex_src_state *state, unsigned samp) { /* NOTE: arrays of samplerExternalOES do not appear to be allowed: */ - nir_foreach_variable(var, &state->shader->uniforms) + nir_foreach_uniform_variable(var, state->shader) if (var->data.binding == samp) return var; return NULL;