nir: Add a nir_foreach_uniform_variable helper
authorJason Ekstrand <jason@jlekstrand.net>
Sat, 18 Jul 2020 23:45:18 +0000 (18:45 -0500)
committerMarge Bot <eric+marge@anholt.net>
Wed, 29 Jul 2020 17:38:58 +0000 (17:38 +0000)
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 <gert.wollny@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5966>

13 files changed:
src/broadcom/compiler/vir.c
src/compiler/glsl/gl_nir_link_atomics.c
src/compiler/nir/nir.h
src/compiler/nir/nir_gather_info.c
src/compiler/nir/nir_lower_atomics_to_ssbo.c
src/gallium/auxiliary/nir/nir_draw_helpers.c
src/gallium/drivers/r600/sfn/sfn_instruction_tex.cpp
src/intel/vulkan/anv_nir_apply_pipeline_layout.c
src/mesa/drivers/dri/i965/brw_link.cpp
src/mesa/drivers/dri/i965/brw_nir_uniforms.cpp
src/mesa/state_tracker/st_glsl_to_nir.cpp
src/mesa/state_tracker/st_nir_lower_builtin.c
src/mesa/state_tracker/st_nir_lower_tex_src_plane.c

index 44587d3e6e983c2167681b85d3bfe438809f6ed2..d7e9784a10aaf28c1bac037592ba37aac0a1efbc 100644 (file)
@@ -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);
 
index 62f04af9d8768c4638386bafd607dd4abbf2ca1a..5a1a7899cc97a640de66f4221607b6a82cabef83 100644 (file)
@@ -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;
 
index de26c937722421111744fd1a50d1aac67d2b80cc..b7fba8b59a4c5590ce1b463ad38bef1f5f09a68b 100644 (file)
@@ -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)
 {
index 7a6448887b459a5acae19ea97d24c5f5241d8f1d..0e2624c4219298c633f21ebeaff53757ed4dc1d8 100644 (file)
@@ -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.
index 8c8f9f8121eb23b5438d419f5e6571b912665996..b9ba4e4b273a6a6ad994ff3837fe26af6887eb19 100644 (file)
@@ -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);
 
index 3349d0f5eb0fbf23c2774713ba0444b69b636657..5ad6c7964d9711c053e67cd52746e0ffe8401f16 100644 (file)
@@ -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;
index 0f0de2134296053154bb7f5981fb0749f5bd79c5..823674c2f975e488443929f179d97f28fcfaff5f 100644 (file)
@@ -212,7 +212,7 @@ bool r600_nir_lower_int_tg4(nir_shader *shader)
    std::vector<bool> 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;
index b5b7cd080411c5b01b834d921830283e49307f87..ded0310695b75182801e0bcc8cb87599a11023c9 100644 (file)
@@ -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))
index cfd56cef0df34201a5773d2bbbefce8adf15e766..20845a7aac76dd27fa736b9da14acc31a7dcd8f9 100644 (file)
@@ -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);
index 639bdfc0f2cbe1750dc78200367e2d51d87e3b77..25df2cf5b2704a91432bb6360a5dae27df877a29 100644 (file)
@@ -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;
 
index 6b1c1d6c39131008734c86c367de6ea7565115db..bc8592d22e292bccf1253e91a8f415170d78ed18 100644 (file)
@@ -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);
index 4227ee5529a954dc1db0d1bfd0162fb608098004..dd4a30c518d9cbb55e483ba1f75d588ddf6e586c 100644 (file)
@@ -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;
index 44597e789a2853e83c9eea452d654fd79060c19e..2697c1460b2a79e24561f831a91b0ec740781518 100644 (file)
@@ -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;