aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/compiler/glsl/link_uniforms.cpp34
-rw-r--r--src/compiler/glsl/linker.cpp19
-rw-r--r--src/compiler/glsl/linker.h13
-rw-r--r--src/compiler/glsl/linker_util.cpp55
-rw-r--r--src/compiler/glsl/linker_util.h21
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..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++;
+ }
+ }
+}
diff --git a/src/compiler/glsl/linker_util.h b/src/compiler/glsl/linker_util.h
index 17da92fca99..1c3674f35a5 100644
--- a/src/compiler/glsl/linker_util.h
+++ b/src/compiler/glsl/linker_util.h
@@ -25,11 +25,25 @@
#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