[Mesa-dev] [PATCH 64/65] i965: copy and restore sampler units when doing full relink

Timothy Arceri timothy.arceri at collabora.com
Fri Apr 29 13:34:03 UTC 2016


If we don't find the program in the cache we need to make sure to
store the current sampler units and restore them after falling back
to relinking.

In this change we also avoid reseting the sampler and image units
stored in gl_shader back to 0 during relinking.
---
 src/compiler/glsl/link_uniforms.cpp          |  6 ++++--
 src/mesa/drivers/dri/i965/brw_shader_cache.c | 24 ++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/src/compiler/glsl/link_uniforms.cpp b/src/compiler/glsl/link_uniforms.cpp
index fc566ac..c791eea 100644
--- a/src/compiler/glsl/link_uniforms.cpp
+++ b/src/compiler/glsl/link_uniforms.cpp
@@ -1033,8 +1033,10 @@ link_assign_uniform_locations(struct gl_shader_program *prog,
        *     initializer, if present, or 0 if no initializer is present. Sampler
        *     types cannot have initializers."
        */
-      memset(sh->SamplerUnits, 0, sizeof(sh->SamplerUnits));
-      memset(sh->ImageUnits, 0, sizeof(sh->ImageUnits));
+      if (!skip_cache) {
+         memset(sh->SamplerUnits, 0, sizeof(sh->SamplerUnits));
+         memset(sh->ImageUnits, 0, sizeof(sh->ImageUnits));
+      }
 
       link_update_uniform_buffer_variables(sh);
 
diff --git a/src/mesa/drivers/dri/i965/brw_shader_cache.c b/src/mesa/drivers/dri/i965/brw_shader_cache.c
index 5d47122..105b8ef 100644
--- a/src/mesa/drivers/dri/i965/brw_shader_cache.c
+++ b/src/mesa/drivers/dri/i965/brw_shader_cache.c
@@ -39,6 +39,14 @@
 #include "brw_context.h"
 
 static void
+copy_sampler_units(struct gl_shader_program *shProg, unsigned stage,
+                   GLubyte *SamplerUnits)
+{
+      struct gl_program *prog = shProg->_LinkedShaders[stage]->Program;
+      memcpy(SamplerUnits, prog->SamplerUnits, sizeof(prog->SamplerUnits));
+}
+
+static void
 gen_binary_sha1(struct brw_context *brw, struct gl_shader_program *prog,
                 struct brw_vs_prog_key *vs_key,
                 struct brw_wm_prog_key *wm_key)
@@ -381,6 +389,13 @@ FAIL:
    if (brw->vertex_program->Base.nir == NULL) {
       struct gl_shader_program *prog =
          brw->ctx._Shader->CurrentProgram[MESA_SHADER_VERTEX];
+
+      /* Make a copy of the current sampler units */
+      GLubyte vSamplerUnits[MAX_SAMPLERS];
+      GLubyte fSamplerUnits[MAX_SAMPLERS];
+      copy_sampler_units(prog, MESA_SHADER_VERTEX, vSamplerUnits);
+      copy_sampler_units(prog, MESA_SHADER_FRAGMENT, fSamplerUnits);
+
       for (unsigned i = 0; i < prog->NumShaders; i++) {
          _mesa_glsl_compile_shader(&brw->ctx, prog->Shaders[i], false, false,
                                    true);
@@ -394,12 +409,19 @@ FAIL:
       struct gl_program *fp =
          prog->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program;
       brw->fragment_program = gl_fragment_program(fp);
+
+      memcpy(vp->SamplerUnits, vSamplerUnits, sizeof(vp->SamplerUnits));
+      memcpy(fp->SamplerUnits, fSamplerUnits, sizeof(fp->SamplerUnits));
    }
 
    if (brw->fragment_program->Base.nir == NULL) {
       struct gl_shader_program *prog =
          brw->ctx._Shader->_CurrentFragmentProgram;
 
+      /* Make a copy of the current sampler units */
+      GLubyte fSamplerUnits[MAX_SAMPLERS];
+      copy_sampler_units(prog, MESA_SHADER_FRAGMENT, fSamplerUnits);
+
       for (unsigned i = 0; i < prog->NumShaders; i++) {
          _mesa_glsl_compile_shader(&brw->ctx, prog->Shaders[i], false, false,
                                    true);
@@ -409,6 +431,8 @@ FAIL:
       struct gl_program *fp =
          prog->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program;
       brw->fragment_program = gl_fragment_program(fp);
+
+      memcpy(fp->SamplerUnits, fSamplerUnits, sizeof(fp->SamplerUnits));
    }
 
    free(buffer);
-- 
2.5.5



More information about the mesa-dev mailing list