Mesa (staging/20.1): ir_constant: Return zero on out-of-bounds vector accesses
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Thu Aug 27 22:05:35 UTC 2020
Module: Mesa
Branch: staging/20.1
Commit: d91921c0d21acdd69795f76a21be786389aafa1c
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=d91921c0d21acdd69795f76a21be786389aafa1c
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>
(cherry picked from commit e93979ba599355c42df01a89073362b970489a3a)
---
.pick_status.json | 2 +-
src/compiler/glsl/ir.cpp | 14 ++++++++++++++
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/.pick_status.json b/.pick_status.json
index 7921ef3a8a2..8928a5efde6 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -1777,7 +1777,7 @@
"description": "ir_constant: Return zero on out-of-bounds vector accesses",
"nominated": true,
"nomination_type": 0,
- "resolution": 0,
+ "resolution": 1,
"master_sha": null,
"because_sha": null
},
diff --git a/src/compiler/glsl/ir.cpp b/src/compiler/glsl/ir.cpp
index 922dcd3c819..12faf8e41fc 100644
--- a/src/compiler/glsl/ir.cpp
+++ b/src/compiler/glsl/ir.cpp
@@ -799,6 +799,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_UINT: this->value.u[0] = c->value.u[i]; break;
case GLSL_TYPE_INT: this->value.i[0] = c->value.i[i]; break;
More information about the mesa-commit
mailing list