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

Timothy Arceri timothy.arceri at collabora.com
Mon Oct 3 06:04:47 UTC 2016


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

diff --git a/src/compiler/glsl/shader_cache.cpp b/src/compiler/glsl/shader_cache.cpp
index 793a909..cd18edc 100644
--- a/src/compiler/glsl/shader_cache.cpp
+++ b/src/compiler/glsl/shader_cache.cpp
@@ -327,8 +327,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_uint32(metadata, prog->NumUniformRemapTable);
 
@@ -347,11 +347,30 @@ write_uniform_remap_table(struct blob *metadata,
          blob_write_uint32(metadata, offset);
       }
    }
+
+   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++) {
+            struct gl_uniform_storage *sr =
+               sh->SubroutineUniformRemapTable[j];
+
+            blob_write_uint64(metadata, ptr_to_uint64_t(sr));
+
+            if (sr != INACTIVE_UNIFORM_EXPLICIT_LOCATION && sr != NULL) {
+               uint32_t offset = sr - prog->UniformStorage;
+               blob_write_uint32(metadata, offset);
+            }
+         }
+      }
+   }
 }
 
 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)
 {
    prog->NumUniformRemapTable = blob_read_uint32(metadata);
 
@@ -368,6 +387,30 @@ 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++) {
+            uint64_t uni_ptr = blob_read_uint64(metadata);
+            if (uni_ptr == (uint64_t) INACTIVE_UNIFORM_EXPLICIT_LOCATION ||
+                uni_ptr == (uint64_t) NULL) {
+               sh->SubroutineUniformRemapTable[j] =
+                  (gl_uniform_storage *) uni_ptr;
+            } else {
+               uint32_t uni_offset = blob_read_uint32(metadata);
+               sh->SubroutineUniformRemapTable[j] =
+                  prog->UniformStorage + uni_offset;
+            }
+         }
+      }
+   }
 }
 
 struct whte_closure
@@ -797,7 +840,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);
 
@@ -906,7 +949,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