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

Timothy Arceri timothy.arceri at collabora.com
Fri Apr 29 13:33:32 UTC 2016


---
 src/compiler/glsl/shader_cache.cpp | 53 ++++++++++++++++++++++++++++++++------
 1 file changed, 45 insertions(+), 8 deletions(-)

diff --git a/src/compiler/glsl/shader_cache.cpp b/src/compiler/glsl/shader_cache.cpp
index 4599e5a..f9b2157 100644
--- a/src/compiler/glsl/shader_cache.cpp
+++ b/src/compiler/glsl/shader_cache.cpp
@@ -275,8 +275,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);
@@ -284,11 +284,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_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);
@@ -307,6 +319,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_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
@@ -687,11 +724,11 @@ shader_cache_write_program_metadata(struct gl_context *ctx,
 
    write_hash_tables(metadata, prog);
 
-   write_uniform_remap_table(metadata, prog);
-
    write_shader_metadata(metadata, prog->_LinkedShaders[MESA_SHADER_VERTEX]);
    write_shader_metadata(metadata, prog->_LinkedShaders[MESA_SHADER_FRAGMENT]);
 
+   write_uniform_remap_tables(metadata, prog);
+
    write_subroutines(metadata, prog);
 
    write_program_resource_list(metadata, prog);
@@ -786,8 +823,6 @@ shader_cache_read_program_metadata(struct gl_context *ctx,
 
    read_hash_tables(&metadata, prog);
 
-   read_uniform_remap_table(&metadata, prog);
-
    linked = ctx->Driver.NewShader(NULL, 0, GL_VERTEX_SHADER);
    glprog = ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, prog->Name);
    read_shader_metadata(&metadata, glprog, linked);
@@ -802,6 +837,8 @@ shader_cache_read_program_metadata(struct gl_context *ctx,
    _mesa_reference_shader(ctx, &prog->_LinkedShaders[MESA_SHADER_FRAGMENT],
                           linked);
 
+   read_uniform_remap_tables(&metadata, prog);
+
    read_subroutines(&metadata, prog);
 
    read_program_resource_list(&metadata, prog);
-- 
2.5.5



More information about the mesa-dev mailing list