Mesa (master): ir_constant: Return zero on out-of-bounds vector accesses
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Fri Aug 21 15:19:37 UTC 2020
Module: Mesa
Branch: master
Commit: e93979ba599355c42df01a89073362b970489a3a
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=e93979ba599355c42df01a89073362b970489a3a
Author: Danylo Piliaiev <danylo.piliaiev at globallogic.com>
Date: Mon Aug 17 18:13:24 2020 +0300
ir_constant: Return zero on out-of-bounds vector accesses
Several optimization paths, including constant folding, can lead to
accessing an ir_constant vector with an out of bounds index.
Return 0 since GL_ARB_robustness and GL_KHR_robustness encourage
us to do so.
Fixes piglit tests:
spec at glsl-1.20@execution at vector-out-of-bounds-access@fs-vec4-out-of-bounds-2
spec at glsl-1.20@execution at vector-out-of-bounds-access@fs-vec4-out-of-bounds-4
spec at glsl-1.20@execution at vector-out-of-bounds-access@fs-vec4-out-of-bounds-5
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/2604
CC: <mesa-stable at lists.freedesktop.org>
Signed-off-by: Danylo Piliaiev <danylo.piliaiev at globallogic.com>
Reviewed-by: Eric Anholt <eric at anholt.net>
Reviewed-by: Marcin Ślusarz <marcin.slusarz at intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6363>
---
.gitlab-ci/piglit/quick_shader.txt | 7 ++-----
src/compiler/glsl/ir.cpp | 14 ++++++++++++++
2 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/.gitlab-ci/piglit/quick_shader.txt b/.gitlab-ci/piglit/quick_shader.txt
index 1f1c83e86b0..ff29f613bc7 100644
--- a/.gitlab-ci/piglit/quick_shader.txt
+++ b/.gitlab-ci/piglit/quick_shader.txt
@@ -370,9 +370,6 @@ spec/glsl-1.10/execution/built-in-functions/vs-pow-float-float: fail
spec/glsl-1.10/preprocessor/extension-defined-test: skip
spec/glsl-1.10/preprocessor/extension-if-1: skip
spec/glsl-1.20/execution/vector-out-of-bounds-access/fs-vec4-out-of-bounds-1: crash
-spec/glsl-1.20/execution/vector-out-of-bounds-access/fs-vec4-out-of-bounds-2: crash
-spec/glsl-1.20/execution/vector-out-of-bounds-access/fs-vec4-out-of-bounds-4: crash
-spec/glsl-1.20/execution/vector-out-of-bounds-access/fs-vec4-out-of-bounds-5: crash
spec/glsl-1.20/execution/vector-out-of-bounds-access/fs-vec4-out-of-bounds-6: crash
spec/glsl-1.30/execution/fs-texturegrad-miplevels: fail
spec/glsl-1.30/execution/fs-texturelod-miplevels: fail
@@ -595,9 +592,9 @@ spec/nv_viewport_swizzle/viewport_swizzle: skip
summary:
name: results
---- --------
- pass: 15781
+ pass: 15784
fail: 104
- crash: 175
+ crash: 172
skip: 315
timeout: 0
warn: 0
diff --git a/src/compiler/glsl/ir.cpp b/src/compiler/glsl/ir.cpp
index 607cb3e78ef..71be1e1c7c1 100644
--- a/src/compiler/glsl/ir.cpp
+++ b/src/compiler/glsl/ir.cpp
@@ -857,6 +857,20 @@ ir_constant::ir_constant(const ir_constant *c, unsigned i)
this->const_elements = NULL;
this->type = c->type->get_base_type();
+ /* Section 5.11 (Out-of-Bounds Accesses) of the GLSL 4.60 spec says:
+ *
+ * In the subsections described above for array, vector, matrix and
+ * structure accesses, any out-of-bounds access produced undefined
+ * behavior....Out-of-bounds reads return undefined values, which
+ * include values from other variables of the active program or zero.
+ *
+ * GL_KHR_robustness and GL_ARB_robustness encourage us to return zero.
+ */
+ if (i >= c->type->vector_elements) {
+ this->value = { { 0 } };
+ return;
+ }
+
switch (this->type->base_type) {
case GLSL_TYPE_UINT16: this->value.u16[0] = c->value.u16[i]; break;
case GLSL_TYPE_INT16: this->value.i16[0] = c->value.i16[i]; break;
More information about the mesa-commit
mailing list