summaryrefslogtreecommitdiffstats
path: root/src/compiler/glsl/linker_util.cpp
diff options
context:
space:
mode:
authorAlejandro Piñeiro <[email protected]>2018-06-26 16:28:59 +0200
committerAlejandro Piñeiro <[email protected]>2018-07-03 12:37:32 +0200
commitb0712df6cfbc40ce770077a12e7e2beccd692019 (patch)
treec6c7e27dd27f695e3dfec62492a6991392c4cfb5 /src/compiler/glsl/linker_util.cpp
parent995d9937103771d9318124b91adfd20d7c6d5fed (diff)
compiler/glsl: refactor empty_uniform_block utilities to linker_util
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 <[email protected]>
Diffstat (limited to 'src/compiler/glsl/linker_util.cpp')
-rw-r--r--src/compiler/glsl/linker_util.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/compiler/glsl/linker_util.cpp b/src/compiler/glsl/linker_util.cpp
index 0e6f4166d64..d2724c239e6 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 "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++;
+ }
+ }
+}