[Mesa-dev] [PATCH 02/18] compiler/glsl: refactor empty_uniform_block utilities to linker_util

Timothy Arceri tarceri at itsqueeze.com
Sat Jun 30 06:13:14 UTC 2018



On 30/06/18 00:28, Alejandro PiƱeiro wrote:
> This includes:
>    * Move the defition of empty_uniform_block to linker_util.h
>    * Move find_empty_block (with a rename) to linker_util.h
>    * Refactor some code at linker.cpp to a new method at linker_util.h
>      (link_util_update_empty_uniform_locations)
> 
> So all that code could be used by the GLSL linker and the NIR linker
> used for ARB_gl_spirv.
> ---
>   src/compiler/glsl/link_uniforms.cpp | 34 +----------------------
>   src/compiler/glsl/linker.cpp        | 19 ++-----------
>   src/compiler/glsl/linker.h          | 13 ---------
>   src/compiler/glsl/linker_util.cpp   | 55 +++++++++++++++++++++++++++++++++++++
>   src/compiler/glsl/linker_util.h     | 21 ++++++++++++++
>   5 files changed, 79 insertions(+), 63 deletions(-)
> 
> diff --git a/src/compiler/glsl/link_uniforms.cpp b/src/compiler/glsl/link_uniforms.cpp
> index 23ff7ec6728..8d3f95fe114 100644
> --- a/src/compiler/glsl/link_uniforms.cpp
> +++ b/src/compiler/glsl/link_uniforms.cpp
> @@ -1153,38 +1153,6 @@ assign_hidden_uniform_slot_id(const char *name, unsigned hidden_id,
>      uniform_size->map->put(hidden_uniform_start + hidden_id, name);
>   }
>   
> -/**
> - * Search through the list of empty blocks to find one that fits the current
> - * uniform.
> - */
> -static int
> -find_empty_block(struct gl_shader_program *prog,
> -                 struct gl_uniform_storage *uniform)
> -{
> -   const unsigned entries = MAX2(1, uniform->array_elements);
> -
> -   foreach_list_typed(struct empty_uniform_block, block, link,
> -                      &prog->EmptyUniformLocations) {
> -      /* Found a block with enough slots to fit the uniform */
> -      if (block->slots == entries) {
> -         unsigned start = block->start;
> -         exec_node_remove(&block->link);
> -         ralloc_free(block);
> -
> -         return start;
> -      /* Found a block with more slots than needed. It can still be used. */
> -      } else if (block->slots > entries) {
> -         unsigned start = block->start;
> -         block->start += entries;
> -         block->slots -= entries;
> -
> -         return start;
> -      }
> -   }
> -
> -   return -1;
> -}
> -
>   static void
>   link_setup_uniform_remap_tables(struct gl_context *ctx,
>                                   struct gl_shader_program *prog)
> @@ -1239,7 +1207,7 @@ link_setup_uniform_remap_tables(struct gl_context *ctx,
>         int chosen_location = -1;
>   
>         if (empty_locs)
> -         chosen_location = find_empty_block(prog, &prog->data->UniformStorage[i]);
> +         chosen_location = link_util_find_empty_block(prog, &prog->data->UniformStorage[i]);
>   
>         /* Add new entries to the total amount of entries. */
>         total_entries += entries;
> diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp
> index 95e7c3c5e99..6a9d19e8695 100644
> --- a/src/compiler/glsl/linker.cpp
> +++ b/src/compiler/glsl/linker.cpp
> @@ -76,6 +76,7 @@
>   #include "util/set.h"
>   #include "string_to_uint_map.h"
>   #include "linker.h"
> +#include "linker_util.h"
>   #include "link_varyings.h"
>   #include "ir_optimization.h"
>   #include "ir_rvalue_visitor.h"
> @@ -3527,23 +3528,7 @@ check_explicit_uniform_locations(struct gl_context *ctx,
>         }
>      }
>   
> -   struct empty_uniform_block *current_block = NULL;
> -
> -   for (unsigned i = 0; i < prog->NumUniformRemapTable; i++) {
> -      /* We found empty space in UniformRemapTable. */
> -      if (prog->UniformRemapTable[i] == NULL) {
> -         /* We've found the beginning of a new continous block of empty slots */
> -         if (!current_block || current_block->start + current_block->slots != i) {
> -            current_block = rzalloc(prog, struct empty_uniform_block);
> -            current_block->start = i;
> -            exec_list_push_tail(&prog->EmptyUniformLocations,
> -                                &current_block->link);
> -         }
> -
> -         /* The current block continues, so we simply increment its slots */
> -         current_block->slots++;
> -      }
> -   }
> +   link_util_update_empty_uniform_locations(prog);
>   
>      delete uniform_map;
>      prog->NumExplicitUniformLocations = entries_total;
> diff --git a/src/compiler/glsl/linker.h b/src/compiler/glsl/linker.h
> index 6e9b4861673..f6fb00351d4 100644
> --- a/src/compiler/glsl/linker.h
> +++ b/src/compiler/glsl/linker.h
> @@ -194,17 +194,4 @@ private:
>                     const glsl_struct_field *named_ifc_member);
>   };
>   
> -/**
> - * Sometimes there are empty slots left over in UniformRemapTable after we
> - * allocate slots to explicit locations. This struct represents a single
> - * continouous block of empty slots in UniformRemapTable.
> - */
> -struct empty_uniform_block {
> -   struct exec_node link;
> -   /* The start location of the block */
> -   unsigned start;
> -   /* The number of slots in the block */
> -   unsigned slots;
> -};
> -
>   #endif /* GLSL_LINKER_H */
> diff --git a/src/compiler/glsl/linker_util.cpp b/src/compiler/glsl/linker_util.cpp
> index 0e6f4166d64..e80c9e22ae2 100644
> --- a/src/compiler/glsl/linker_util.cpp
> +++ b/src/compiler/glsl/linker_util.cpp
> @@ -24,6 +24,7 @@
>   #include "main/mtypes.h"
>   #include "linker_util.h"
>   #include "util/set.h"
> +#include "compiler/glsl/ir_uniform.h" /* for gl_uniform_storage */

This only needs to be #include "ir_uniform.h"

With that this patch is:

Reviewed-by: Timothy Arceri <tarceri at itsqueeze.com>


More information about the mesa-dev mailing list