[Mesa-dev] [PATCH 33/56] glsl: don't lose uniform values when falling back to full compile

Timothy Arceri timothy.arceri at collabora.com
Tue Nov 29 03:58:32 UTC 2016


Here we skip the recreation of uniform storage if we are relinking
after a cache miss. This is improtant because uniform values may
have already been set by the application and we don't want to reset
them.
---
 src/compiler/glsl/link_uniforms.cpp | 31 +++++++++++++++++++++++--------
 src/mesa/main/shaderobj.c           |  4 ++--
 2 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/src/compiler/glsl/link_uniforms.cpp b/src/compiler/glsl/link_uniforms.cpp
index 770fc3f..000b21b 100644
--- a/src/compiler/glsl/link_uniforms.cpp
+++ b/src/compiler/glsl/link_uniforms.cpp
@@ -1209,11 +1209,17 @@ link_assign_uniform_storage(struct gl_context *ctx,
 
    unsigned int boolean_true = ctx->Const.UniformBooleanTrue;
 
-   prog->data->UniformStorage = rzalloc_array(prog, struct gl_uniform_storage,
-                                              prog->data->NumUniformStorage);
-   union gl_constant_value *data = rzalloc_array(prog->data->UniformStorage,
-                                                 union gl_constant_value,
-                                                 num_data_slots);
+   union gl_constant_value *data;
+   if (prog->data->UniformStorage == NULL) {
+      prog->data->UniformStorage = rzalloc_array(prog,
+                                                 struct gl_uniform_storage,
+                                                 prog->data->NumUniformStorage);
+      data = rzalloc_array(prog->data->UniformStorage,
+                           union gl_constant_value, num_data_slots);
+   } else {
+      data = prog->data->UniformDataSlots;
+   }
+
 #ifndef NDEBUG
    union gl_constant_value *data_end = &data[num_data_slots];
 #endif
@@ -1248,6 +1254,13 @@ link_assign_uniform_storage(struct gl_context *ctx,
              sizeof(prog->_LinkedShaders[i]->Program->sh.SamplerTargets));
    }
 
+   /* If this is a fallback compile for a cache miss we already have the
+    * correct uniform mappings and we don't want to reinitialise uniforms so
+    * just return now.
+    */
+   if (prog->data->cache_fallback)
+      return;
+
 #ifndef NDEBUG
    for (unsigned i = 0; i < prog->data->NumUniformStorage; i++) {
       assert(prog->data->UniformStorage[i].storage != NULL ||
@@ -1273,9 +1286,11 @@ link_assign_uniform_locations(struct gl_shader_program *prog,
                               struct gl_context *ctx,
                               unsigned int num_explicit_uniform_locs)
 {
-   ralloc_free(prog->data->UniformStorage);
-   prog->data->UniformStorage = NULL;
-   prog->data->NumUniformStorage = 0;
+   if (!prog->data->cache_fallback) {
+      ralloc_free(prog->data->UniformStorage);
+      prog->data->UniformStorage = NULL;
+      prog->data->NumUniformStorage = 0;
+   }
 
    if (prog->UniformHash != NULL) {
       prog->UniformHash->clear();
diff --git a/src/mesa/main/shaderobj.c b/src/mesa/main/shaderobj.c
index 61df247..b197144 100644
--- a/src/mesa/main/shaderobj.c
+++ b/src/mesa/main/shaderobj.c
@@ -330,7 +330,7 @@ _mesa_clear_shader_program_data(struct gl_context *ctx,
       }
    }
 
-   if (shProg->data->UniformStorage) {
+   if (shProg->data->UniformStorage && !shProg->data->cache_fallback) {
       for (unsigned i = 0; i < shProg->data->NumUniformStorage; ++i)
          _mesa_uniform_detach_all_driver_storage(&shProg->data->
                                                     UniformStorage[i]);
@@ -339,7 +339,7 @@ _mesa_clear_shader_program_data(struct gl_context *ctx,
       shProg->data->UniformStorage = NULL;
    }
 
-   if (shProg->UniformRemapTable) {
+   if (shProg->UniformRemapTable && !shProg->data->cache_fallback) {
       ralloc_free(shProg->UniformRemapTable);
       shProg->NumUniformRemapTable = 0;
       shProg->UniformRemapTable = NULL;
-- 
2.7.4



More information about the mesa-dev mailing list