[Mesa-dev] [PATCH 1/2] st/mesa: don't propagate uniforms when restoring from cache

Timothy Arceri tarceri at itsqueeze.com
Fri Mar 3 05:59:48 UTC 2017


We will have already loaded the uniforms when the parameter list
was restored from cache.
---
 src/mesa/program/ir_to_mesa.cpp            | 14 +++++++++-----
 src/mesa/program/ir_to_mesa.h              |  3 ++-
 src/mesa/state_tracker/st_glsl_to_nir.cpp  |  3 ++-
 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |  3 ++-
 src/mesa/state_tracker/st_shader_cache.c   |  3 ++-
 5 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
index a4f61ac..3898cb8 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -2525,21 +2525,22 @@ _mesa_generate_parameters_list_for_uniforms(struct gl_shader_program
 	  || var->is_in_buffer_block() || (strncmp(var->name, "gl_", 3) == 0))
 	 continue;
 
       add.process(var);
    }
 }
 
 void
 _mesa_associate_uniform_storage(struct gl_context *ctx,
 				struct gl_shader_program *shader_program,
-				struct gl_program_parameter_list *params)
+                                struct gl_program_parameter_list *params,
+                                bool propagate_to_storage)
 {
    /* After adding each uniform to the parameter list, connect the storage for
     * the parameter with the tracking structure used by the API for the
     * uniform.
     */
    unsigned last_location = unsigned(~0);
    for (unsigned i = 0; i < params->NumParameters; i++) {
       if (params->Parameters[i].Type != PROGRAM_UNIFORM)
 	 continue;
 
@@ -2615,23 +2616,25 @@ _mesa_associate_uniform_storage(struct gl_context *ctx,
 	 _mesa_uniform_attach_driver_storage(storage,
 					     dmul * columns,
 					     dmul,
 					     format,
 					     &params->ParameterValues[i]);
 
 	 /* After attaching the driver's storage to the uniform, propagate any
 	  * data from the linker's backing store.  This will cause values from
 	  * initializers in the source code to be copied over.
 	  */
-	 _mesa_propagate_uniforms_to_driver_storage(storage,
-						    0,
-						    MAX2(1, storage->array_elements));
+         if (propagate_to_storage) {
+            unsigned array_elements = MAX2(1, storage->array_elements);
+            _mesa_propagate_uniforms_to_driver_storage(storage, 0,
+                                                       array_elements);
+         }
 
 	 last_location = location;
       }
    }
 }
 
 /*
  * On a basic block basis, tracks available PROGRAM_TEMPORARY register
  * channels for copy propagation and updates following instructions to
  * use the original versions.
@@ -2977,21 +2980,22 @@ get_mesa_program(struct gl_context *ctx,
    }
 
    if ((ctx->_Shader->Flags & GLSL_NO_OPT) == 0) {
       _mesa_optimize_program(ctx, prog, prog);
    }
 
    /* This has to be done last.  Any operation that can cause
     * prog->ParameterValues to get reallocated (e.g., anything that adds a
     * program constant) has to happen before creating this linkage.
     */
-   _mesa_associate_uniform_storage(ctx, shader_program, prog->Parameters);
+   _mesa_associate_uniform_storage(ctx, shader_program, prog->Parameters,
+                                   true);
    if (!shader_program->data->LinkStatus) {
       goto fail_exit;
    }
 
    return prog;
 
 fail_exit:
    ralloc_free(mesa_instructions);
    _mesa_reference_program(ctx, &shader->Program, NULL);
    return NULL;
diff --git a/src/mesa/program/ir_to_mesa.h b/src/mesa/program/ir_to_mesa.h
index be45ba0..c46d090 100644
--- a/src/mesa/program/ir_to_mesa.h
+++ b/src/mesa/program/ir_to_mesa.h
@@ -38,15 +38,16 @@ GLboolean _mesa_ir_link_shader(struct gl_context *ctx, struct gl_shader_program
 
 void
 _mesa_generate_parameters_list_for_uniforms(struct gl_shader_program
 					    *shader_program,
 					    struct gl_linked_shader *sh,
 					    struct gl_program_parameter_list
 					    *params);
 void
 _mesa_associate_uniform_storage(struct gl_context *ctx,
 				struct gl_shader_program *shader_program,
-				struct gl_program_parameter_list *params);
+                                struct gl_program_parameter_list *params,
+                                bool propagate_to_storage);
 
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp b/src/mesa/state_tracker/st_glsl_to_nir.cpp
index 60d101c..674ccd0 100644
--- a/src/mesa/state_tracker/st_glsl_to_nir.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp
@@ -419,21 +419,22 @@ st_nir_get_mesa_program(struct gl_context *ctx,
    /* Avoid reallocation of the program parameter list, because the uniform
     * storage is only associated with the original parameter list.
     * This should be enough for Bitmap and DrawPixels constants.
     */
    _mesa_reserve_parameter_storage(prog->Parameters, 8);
 
    /* This has to be done last.  Any operation the can cause
     * prog->ParameterValues to get reallocated (e.g., anything that adds a
     * program constant) has to happen before creating this linkage.
     */
-   _mesa_associate_uniform_storage(ctx, shader_program, prog->Parameters);
+   _mesa_associate_uniform_storage(ctx, shader_program, prog->Parameters,
+                                   true);
 
    struct st_vertex_program *stvp;
    struct st_fragment_program *stfp;
 
    switch (shader->Stage) {
    case MESA_SHADER_VERTEX:
       stvp = (struct st_vertex_program *)prog;
       stvp->shader_program = shader_program;
       break;
    case MESA_SHADER_FRAGMENT:
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index af41bdb..0757d14 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -6763,21 +6763,22 @@ get_mesa_program_tgsi(struct gl_context *ctx,
    /* Avoid reallocation of the program parameter list, because the uniform
     * storage is only associated with the original parameter list.
     * This should be enough for Bitmap and DrawPixels constants.
     */
    _mesa_reserve_parameter_storage(prog->Parameters, 8);
 
    /* This has to be done last.  Any operation the can cause
     * prog->ParameterValues to get reallocated (e.g., anything that adds a
     * program constant) has to happen before creating this linkage.
     */
-   _mesa_associate_uniform_storage(ctx, shader_program, prog->Parameters);
+   _mesa_associate_uniform_storage(ctx, shader_program, prog->Parameters,
+                                   true);
    if (!shader_program->data->LinkStatus) {
       free_glsl_to_tgsi_visitor(v);
       _mesa_reference_program(ctx, &shader->Program, NULL);
       return NULL;
    }
 
    struct st_vertex_program *stvp;
    struct st_fragment_program *stfp;
    struct st_geometry_program *stgp;
    struct st_tessctrl_program *sttcp;
diff --git a/src/mesa/state_tracker/st_shader_cache.c b/src/mesa/state_tracker/st_shader_cache.c
index fba4b0a..f22380c 100644
--- a/src/mesa/state_tracker/st_shader_cache.c
+++ b/src/mesa/state_tracker/st_shader_cache.c
@@ -372,21 +372,22 @@ st_load_tgsi_from_disk_cache(struct gl_context *ctx,
             goto fallback_recompile;
          }
 
          if (ctx->_Shader->Flags & GLSL_CACHE_INFO) {
             _mesa_sha1_format(sha1_buf, sha1);
             fprintf(stderr, "%s tgsi_tokens retrieved from cache: %s\n",
                     _mesa_shader_stage_to_string(i), sha1_buf);
          }
 
          st_set_prog_affected_state_flags(glprog);
-         _mesa_associate_uniform_storage(ctx, prog, glprog->Parameters);
+         _mesa_associate_uniform_storage(ctx, prog, glprog->Parameters,
+                                         false);
 
          free(buffer);
       } else {
          /* Failed to find a matching cached shader so fallback to recompile.
           */
          if (ctx->_Shader->Flags & GLSL_CACHE_INFO) {
             fprintf(stderr, "TGSI cache item not found falling back to "
                     "compile.\n");
          }
 
-- 
2.9.3



More information about the mesa-dev mailing list