Mesa (master): st/glsl_to_nir: fix incorrect arrary access

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Mar 12 03:47:37 UTC 2019


Module: Mesa
Branch: master
Commit: cb2898f4786f9e80e0a2dd061d620fc7ced6f1ea
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=cb2898f4786f9e80e0a2dd061d620fc7ced6f1ea

Author: Timothy Arceri <tarceri at itsqueeze.com>
Date:   Fri Mar  1 21:35:41 2019 +1100

st/glsl_to_nir: fix incorrect arrary access

This fixes a segfault when we try to access the array using a
-1 when the array wasn't allocated in the first place.

Before 7536af670b75 we would just access a pre-allocated array
that was also load/stored to/from the shader cache. But now the
cache will no longer allocate these arrays if they are empty.
The change resulted in tests such as the following segfaulting
when run with a warm shader cache.

tests/spec/arb_arrays_of_arrays/execution/sampler/fs-struct-const-index.shader_test

---

 src/mesa/state_tracker/st_glsl_to_nir.cpp | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp b/src/mesa/state_tracker/st_glsl_to_nir.cpp
index 7b339e9e043..03637299ca4 100644
--- a/src/mesa/state_tracker/st_glsl_to_nir.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp
@@ -288,13 +288,16 @@ st_nir_assign_uniform_locations(struct gl_context *ctx,
       } else {
          loc = st_nir_lookup_parameter_index(prog->Parameters, uniform->name);
 
-         if (ctx->Const.PackedDriverUniformStorage) {
+         /* We need to check that loc is not -1 here before accessing the
+          * array. It can be negative for example when we have a struct that
+          * only contains opaque types.
+          */
+         if (loc >= 0 && ctx->Const.PackedDriverUniformStorage) {
             loc = prog->Parameters->ParameterValueOffset[loc];
          }
       }
 
       uniform->data.driver_location = loc;
-
       max = MAX2(max, loc + type_size(uniform->type));
    }
    *size = max;




More information about the mesa-commit mailing list