[Mesa-dev] [PATCH 30/87] glsl: store subroutine remap table in shader cache

Timothy Arceri timothy.arceri at collabora.com
Wed Jul 13 02:47:25 UTC 2016


---
 src/compiler/glsl/shader_cache.cpp | 49 +++++++++++++++++++++++++++++++++-----
 1 file changed, 43 insertions(+), 6 deletions(-)

diff --git a/src/compiler/glsl/shader_cache.cpp b/src/compiler/glsl/shader_cache.cpp
index 48014f4..ed1c06f 100644
--- a/src/compiler/glsl/shader_cache.cpp
+++ b/src/compiler/glsl/shader_cache.cpp
@@ -267,8 +267,8 @@ read_uniforms(struct blob_reader *metadata, struct gl_shader_program *prog)
 
 
 static void
-write_uniform_remap_table(struct blob *metadata,
-                          struct gl_shader_program *prog)
+write_uniform_remap_tables(struct blob *metadata,
+                           struct gl_shader_program *prog)
 {
    blob_write_intptr(metadata, (intptr_t) prog->UniformStorage);
    blob_write_uint32(metadata, prog->NumUniformRemapTable);
@@ -276,11 +276,23 @@ write_uniform_remap_table(struct blob *metadata,
    for (unsigned i = 0; i < prog->NumUniformRemapTable; i++) {
       blob_write_intptr(metadata, (intptr_t) prog->UniformRemapTable[i]);
    }
+
+   for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
+      struct gl_linked_shader *sh = prog->_LinkedShaders[i];
+      if (sh) {
+         blob_write_uint32(metadata, sh->NumSubroutineUniformRemapTable);
+
+         for (unsigned j = 0; j < sh->NumSubroutineUniformRemapTable; j++) {
+            blob_write_intptr(metadata,
+                              (intptr_t) sh->SubroutineUniformRemapTable[j]);
+         }
+      }
+   }
 }
 
 static void
-read_uniform_remap_table(struct blob_reader *metadata,
-                         struct gl_shader_program *prog)
+read_uniform_remap_tables(struct blob_reader *metadata,
+                          struct gl_shader_program *prog)
 {
    intptr_t uni_store_base = blob_read_intptr(metadata);
    prog->NumUniformRemapTable = blob_read_uint32(metadata);
@@ -299,6 +311,31 @@ read_uniform_remap_table(struct blob_reader *metadata,
          prog->UniformRemapTable[i] = prog->UniformStorage + uni_offset;
       }
    }
+
+   for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
+      struct gl_linked_shader *sh = prog->_LinkedShaders[i];
+      if (sh) {
+         sh->NumSubroutineUniformRemapTable = blob_read_uint32(metadata);
+
+         sh->SubroutineUniformRemapTable =
+            rzalloc_array(sh, struct gl_uniform_storage *,
+                          sh->NumSubroutineUniformRemapTable);
+
+         for (unsigned j = 0; j < sh->NumSubroutineUniformRemapTable; j++) {
+            intptr_t uni_ptr = blob_read_intptr(metadata);
+            if (uni_ptr == (intptr_t) INACTIVE_UNIFORM_EXPLICIT_LOCATION ||
+                uni_ptr == (intptr_t) NULL) {
+               sh->SubroutineUniformRemapTable[j] =
+                  (gl_uniform_storage *) uni_ptr;
+            } else {
+               intptr_t uni_offset =
+                  (uni_ptr - uni_store_base) / sizeof(gl_uniform_storage);
+               sh->SubroutineUniformRemapTable[j] =
+                  prog->UniformStorage + uni_offset;
+            }
+         }
+      }
+   }
 }
 
 struct whte_closure
@@ -703,7 +740,7 @@ shader_cache_write_program_metadata(struct gl_context *ctx,
          write_shader_metadata(metadata, prog->_LinkedShaders[i]);
    }
 
-   write_uniform_remap_table(metadata, prog);
+   write_uniform_remap_tables(metadata, prog);
 
    write_subroutines(metadata, prog);
 
@@ -810,7 +847,7 @@ shader_cache_read_program_metadata(struct gl_context *ctx,
       }
    }
 
-   read_uniform_remap_table(&metadata, prog);
+   read_uniform_remap_tables(&metadata, prog);
 
    read_subroutines(&metadata, prog);
 
-- 
2.7.4



More information about the mesa-dev mailing list