summaryrefslogtreecommitdiffstats
path: root/src/compiler/glsl/linker_util.cpp
diff options
context:
space:
mode:
authorTimothy Arceri <[email protected]>2019-04-29 16:37:42 +1000
committerTimothy Arceri <[email protected]>2019-05-23 15:06:20 +1000
commita482cf6ab27aef30ec8caaea5b734504ffaa28d9 (patch)
tree5c04b806bf37a7ea11e801467b9760e30dca1e79 /src/compiler/glsl/linker_util.cpp
parent96c2851586e8d76397823624321d5d24b3d22b36 (diff)
glsl: simplify resource list building code
This greatly simplifies the code to calculate if we should add a buffer to the resource list. This uses the spec rules and simple math to decide if we should add the buffer rather than complex string processing. This patch refines a patch present in the ARB_gl_spriv merge request for the NIR linker and applies it to the GLSL IR linker. This is why we also move the function to the shared linker code, because we will want to reuse the code for the NIR linker also. Reviewed-by: Tapani Pälli <[email protected]>
Diffstat (limited to 'src/compiler/glsl/linker_util.cpp')
-rw-r--r--src/compiler/glsl/linker_util.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/compiler/glsl/linker_util.cpp b/src/compiler/glsl/linker_util.cpp
index d2724c239e6..99e3693b548 100644
--- a/src/compiler/glsl/linker_util.cpp
+++ b/src/compiler/glsl/linker_util.cpp
@@ -28,6 +28,43 @@
/* Utility methods shared between the GLSL IR and the NIR */
+/* From the OpenGL 4.6 specification, 7.3.1.1 Naming Active Resources:
+ *
+ * "For an active shader storage block member declared as an array of an
+ * aggregate type, an entry will be generated only for the first array
+ * element, regardless of its type. Such block members are referred to as
+ * top-level arrays. If the block member is an aggregate type, the
+ * enumeration rules are then applied recursively."
+ */
+bool
+link_util_should_add_buffer_variable(struct gl_shader_program *prog,
+ struct gl_uniform_storage *uniform,
+ int top_level_array_base_offset,
+ int top_level_array_size_in_bytes,
+ int second_element_offset,
+ int block_index)
+{
+ /* If the uniform is not a shader storage buffer or is not an array return
+ * true.
+ */
+ if (!uniform->is_shader_storage || top_level_array_size_in_bytes == 0)
+ return true;
+
+ int after_top_level_array = top_level_array_base_offset +
+ top_level_array_size_in_bytes;
+
+ /* Check for a new block, or that we are not dealing with array elements of
+ * a top member array other than the first element.
+ */
+ if (block_index != uniform->block_index ||
+ uniform->offset >= after_top_level_array ||
+ uniform->offset < second_element_offset) {
+ return true;
+ }
+
+ return false;
+}
+
bool
link_util_add_program_resource(struct gl_shader_program *prog,
struct set *resource_set,