Mesa (staging/21.2): glsl: Properly handle .length() of an unsized array
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Tue Jul 27 18:59:27 UTC 2021
Module: Mesa
Branch: staging/21.2
Commit: 319818e9fdd8adb81d87d838cecbb343a272a34f
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=319818e9fdd8adb81d87d838cecbb343a272a34f
Author: Yevhenii Kolesnikov <yevhenii.kolesnikov at globallogic.com>
Date: Wed Jul 14 20:52:56 2021 +0300
glsl: Properly handle .length() of an unsized array
There are two distinct cases:
- The last member of a shader storage block (length determined at run-time)
- Implicitly-sized array (length determined at link-time)
Fixes: 273f61a0051a ("glsl: Add parser/compiler support for unsized array's length()")
Signed-off-by: Yevhenii Kolesnikov <yevhenii.kolesnikov at globallogic.com>
Reviewed-by: Timothy Arceri <tarceri at itsqueeze.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11952>
(cherry picked from commit c3f47f6e300ef1ec18b2c55ec82bccf263292351)
---
.pick_status.json | 2 +-
src/compiler/glsl/ast_function.cpp | 14 +++++++++++---
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/.pick_status.json b/.pick_status.json
index 9e087012cce..5c44ab19916 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -94,7 +94,7 @@
"description": "glsl: Properly handle .length() of an unsized array",
"nominated": true,
"nomination_type": 1,
- "resolution": 0,
+ "resolution": 1,
"main_sha": null,
"because_sha": "273f61a0051a794d1a39d70fb1dbf46a3ca3c63f"
},
diff --git a/src/compiler/glsl/ast_function.cpp b/src/compiler/glsl/ast_function.cpp
index 73e72b5baa9..92ca6a4cf1b 100644
--- a/src/compiler/glsl/ast_function.cpp
+++ b/src/compiler/glsl/ast_function.cpp
@@ -2047,10 +2047,18 @@ ast_function_expression::handle_method(exec_list *instructions,
"length called on unsized array"
" only available with"
" ARB_shader_storage_buffer_object");
+ goto fail;
+ } else if (op->variable_referenced()->is_in_shader_storage_block()) {
+ /* Calculate length of an unsized array in run-time */
+ result = new(ctx)
+ ir_expression(ir_unop_ssbo_unsized_array_length, op);
+ } else {
+ /* When actual size is known at link-time, this will be
+ * replaced with a constant expression.
+ */
+ result = new (ctx)
+ ir_expression(ir_unop_implicitly_sized_array_length, op);
}
- /* Calculate length of an unsized array in run-time */
- result = new(ctx) ir_expression(ir_unop_ssbo_unsized_array_length,
- op);
} else {
result = new(ctx) ir_constant(op->type->array_size());
}
More information about the mesa-commit
mailing list