Mesa (staging/19.0): glsl: Allow gl_nir_lower_samplers*() without a gl_shader_program

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Apr 29 16:03:22 UTC 2019


Module: Mesa
Branch: staging/19.0
Commit: 9919ba09296c5cd6f097ebd69994487d1cb49cf5
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=9919ba09296c5cd6f097ebd69994487d1cb49cf5

Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Tue Feb  5 19:08:04 2019 -0800

glsl: Allow gl_nir_lower_samplers*() without a gl_shader_program

I would like to be able to run gl_nir_lower_samplers() to turn texture
and sampler variable dereferences into indexes and offsets, even for
ARB programs, and built-in shaders.  This would make sampler handling
more consistent across the various types of shaders.

For GLSL programs, the gl_nir_lower_samplers_as_deref() pass looks up
the variable bindings in the shader program's uniform storage.  But
ARB programs and built-in shaders don't have a gl_shader_program, and
uniform storage doesn't exist.  In this case, we simply skip that
lookup, and trust var->data.binding to be set correctly by whoever
created the shader.

Reviewed-by: Eric Anholt <eric at anholt.net>
(cherry picked from commit d34e434989ec8e8ca780421f6909cfd796573520)

---

 src/compiler/glsl/gl_nir_lower_samplers_as_deref.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/compiler/glsl/gl_nir_lower_samplers_as_deref.c b/src/compiler/glsl/gl_nir_lower_samplers_as_deref.c
index a33486b702f..5d0430c0add 100644
--- a/src/compiler/glsl/gl_nir_lower_samplers_as_deref.c
+++ b/src/compiler/glsl/gl_nir_lower_samplers_as_deref.c
@@ -147,10 +147,18 @@ lower_deref(nir_builder *b, struct lower_samplers_as_deref_state *state,
 
    remove_struct_derefs_prep(path.path, &name, &location, &type);
 
-   assert(location < state->shader_program->data->NumUniformStorage &&
-          state->shader_program->data->UniformStorage[location].opaque[stage].active);
+   if (state->shader_program) {
+      /* For GLSL programs, look up the bindings in the uniform storage. */
+      assert(location < state->shader_program->data->NumUniformStorage &&
+             state->shader_program->data->UniformStorage[location].opaque[stage].active);
 
-   binding = state->shader_program->data->UniformStorage[location].opaque[stage].index;
+      binding = state->shader_program->data->UniformStorage[location].opaque[stage].index;
+   } else {
+      /* For ARB programs or built-in shaders, assume that whoever created
+       * the shader set the bindings correctly already.
+       */
+      binding = var->data.binding;
+   }
 
    if (var->type == type) {
       /* Fast path: We did not encounter any struct derefs. */




More information about the mesa-commit mailing list