compiler/glsl: refactor empty_uniform_block utilities to linker_util
authorAlejandro Piñeiro <apinheiro@igalia.com>
Tue, 26 Jun 2018 14:28:59 +0000 (16:28 +0200)
committerAlejandro Piñeiro <apinheiro@igalia.com>
Tue, 3 Jul 2018 10:37:32 +0000 (12:37 +0200)
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.

v2: include just "ir_uniform.h" (Timothy Arceri)

Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
src/compiler/glsl/link_uniforms.cpp
src/compiler/glsl/linker.cpp
src/compiler/glsl/linker.h
src/compiler/glsl/linker_util.cpp
src/compiler/glsl/linker_util.h

index 23ff7ec6728249b9deeb40db832e3f2685ef70b6..8d3f95fe1148f0fdfea3e968c00855f31bb9110a 100644 (file)
@@ -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;
index 95e7c3c5e99c9635d098594b27ac021664bd00ec..6a9d19e8695c09304bda040f6f3d7941ca0fdef5 100644 (file)
@@ -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;
index 6e9b4861673cb95ba9b059ad6e30837d66590bb6..f6fb00351d42c2bf5dac61a2c753098d9ee9b14a 100644 (file)
@@ -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 */
index 0e6f4166d64bba3c20de88b823b03f71f53b0c52..d2724c239e68ad69073f46bcb84a327b98c5b47a 100644 (file)
@@ -24,6 +24,7 @@
 #include "main/mtypes.h"
 #include "linker_util.h"
 #include "util/set.h"
+#include "ir_uniform.h" /* for gl_uniform_storage */
 
 /* Utility methods shared between the GLSL IR and the NIR */
 
@@ -62,3 +63,57 @@ link_util_add_program_resource(struct gl_shader_program *prog,
 
    return true;
 }
+
+/**
+ * Search through the list of empty blocks to find one that fits the current
+ * uniform.
+ */
+int
+link_util_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;
+}
+
+void
+link_util_update_empty_uniform_locations(struct gl_shader_program *prog)
+{
+   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++;
+      }
+   }
+}
index 17da92fca99245dde1cd27ef8f932a223718445e..1c3674f35a5d7d34716a817b6ae17ba92e1f9e97 100644 (file)
 #define GLSL_LINKER_UTIL_H
 
 struct gl_shader_program;
+struct gl_uniform_storage;
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+/**
+ * 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;
+};
+
 void
 linker_error(struct gl_shader_program *prog, const char *fmt, ...);
 
@@ -41,6 +55,13 @@ link_util_add_program_resource(struct gl_shader_program *prog,
                                struct set *resource_set,
                                GLenum type, const void *data, uint8_t stages);
 
+int
+link_util_find_empty_block(struct gl_shader_program *prog,
+                           struct gl_uniform_storage *uniform);
+
+void
+link_util_update_empty_uniform_locations(struct gl_shader_program *prog);
+
 #ifdef __cplusplus
 }
 #endif