[Mesa-dev] [PATCH 44/68] glsl: cache uniform values

Timothy Arceri timothy.arceri at collabora.com
Wed Jun 1 06:23:25 UTC 2016


These may be lowered constant arrays or uniform values that we set before linking
so we need to cache the actual uniform values.
---
 src/compiler/glsl/shader_cache.cpp | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/src/compiler/glsl/shader_cache.cpp b/src/compiler/glsl/shader_cache.cpp
index d3499ec..285c600 100644
--- a/src/compiler/glsl/shader_cache.cpp
+++ b/src/compiler/glsl/shader_cache.cpp
@@ -421,12 +421,14 @@ write_uniforms(struct blob *metadata, struct gl_shader_program *prog)
       blob_write_string(metadata, prog->UniformStorage[i].name);
       blob_write_uint32(metadata, prog->UniformStorage[i].storage -
                                   prog->UniformDataSlots);
+      blob_write_uint32(metadata, prog->UniformStorage[i].builtin);
       blob_write_uint32(metadata, prog->UniformStorage[i].remap_location);
 
       blob_write_uint32(metadata, prog->UniformStorage[i].block_index);
       blob_write_uint32(metadata, prog->UniformStorage[i].atomic_buffer_index);
       blob_write_uint32(metadata, prog->UniformStorage[i].offset);
       blob_write_uint32(metadata, prog->UniformStorage[i].array_stride);
+      blob_write_uint32(metadata, prog->UniformStorage[i].hidden);
       blob_write_uint32(metadata, prog->UniformStorage[i].matrix_stride);
       blob_write_uint32(metadata, prog->UniformStorage[i].row_major);
       blob_write_uint32(metadata,
@@ -439,6 +441,21 @@ write_uniforms(struct blob *metadata, struct gl_shader_program *prog)
       blob_write_bytes(metadata, prog->UniformStorage[i].opaque,
                        sizeof(prog->UniformStorage[i].opaque));
    }
+
+   /* Here we cache all uniform values. We do this to retain values for
+    * uniforms with initialisers and also hidden uniforms that may be lowered
+    * constant arrays. We could possibly just store the values we need but for
+    * now we just store everything.
+    */
+   blob_write_uint32(metadata, prog->NumHiddenUniforms);
+   for (i = 0; i < prog->NumUniformStorage; i++) {
+      if (!prog->UniformStorage[i].builtin) {
+         unsigned vec_size = values_for_type(prog->UniformStorage[i].type) *
+            MAX2(prog->UniformStorage[i].array_elements, 1);
+         blob_write_bytes(metadata, prog->UniformStorage[i].storage,
+                          sizeof(union gl_constant_value) * vec_size);
+      }
+   }
 }
 
 static void
@@ -467,11 +484,13 @@ read_uniforms(struct blob_reader *metadata, struct gl_shader_program *prog)
       uniforms[i].array_elements = blob_read_uint32(metadata);
       uniforms[i].name = ralloc_strdup(prog, blob_read_string (metadata));
       uniforms[i].storage = data + blob_read_uint32(metadata);
+      uniforms[i].builtin = blob_read_uint32(metadata);
       uniforms[i].remap_location = blob_read_uint32(metadata);
       uniforms[i].block_index = blob_read_uint32(metadata);
       uniforms[i].atomic_buffer_index = blob_read_uint32(metadata);
       uniforms[i].offset = blob_read_uint32(metadata);
       uniforms[i].array_stride = blob_read_uint32(metadata);
+      uniforms[i].hidden = blob_read_uint32(metadata);
       uniforms[i].matrix_stride = blob_read_uint32(metadata);
       uniforms[i].row_major = blob_read_uint32(metadata);
       uniforms[i].num_compatible_subroutines = blob_read_uint32(metadata);
@@ -487,6 +506,18 @@ read_uniforms(struct blob_reader *metadata, struct gl_shader_program *prog)
       printf("uniform %d: %s %s\n",
              i, uniforms[i].type->name, uniforms[i].name);
    }
+
+   /* Restore uniform values. */
+   prog->NumHiddenUniforms = blob_read_uint32(metadata);
+   for (i = 0; i < prog->NumUniformStorage; i++) {
+      if (!prog->UniformStorage[i].builtin) {
+         unsigned vec_size = values_for_type(prog->UniformStorage[i].type) *
+            MAX2(prog->UniformStorage[i].array_elements, 1);
+         blob_copy_bytes(metadata,
+                         (uint8_t *) prog->UniformStorage[i].storage,
+                         sizeof(union gl_constant_value) * vec_size);
+      }
+   }
 }
 
 
-- 
2.5.5



More information about the mesa-dev mailing list