[Mesa-dev] [PATCH 22/88] glsl: add basic support for resource list to shader cache

Timothy Arceri timothy.arceri at collabora.com
Sat Sep 24 05:25:03 UTC 2016


This initially adds support for simple uniforms and varyings.
---
 src/compiler/glsl/shader_cache.cpp | 114 +++++++++++++++++++++++++++++++++++++
 1 file changed, 114 insertions(+)

diff --git a/src/compiler/glsl/shader_cache.cpp b/src/compiler/glsl/shader_cache.cpp
index 6a3267c..cd3d9e8 100644
--- a/src/compiler/glsl/shader_cache.cpp
+++ b/src/compiler/glsl/shader_cache.cpp
@@ -303,6 +303,116 @@ read_hash_tables(struct blob_reader *metadata, struct gl_shader_program *prog)
 }
 
 static void
+write_program_resource_data(struct blob *metadata,
+                            struct gl_shader_program *prog,
+                            struct gl_program_resource *res)
+{
+   switch(res->Type) {
+   case GL_PROGRAM_INPUT:
+   case GL_PROGRAM_OUTPUT: {
+      const gl_shader_variable *var = (gl_shader_variable *)res->Data;
+      encode_type_to_blob(metadata, var->type);
+      blob_write_string(metadata, var->name);
+      blob_write_uint32(metadata, var->location);
+
+      unsigned data = var->index;
+      data |= var->patch << 1;
+      data |= var->mode << 2;
+      blob_write_uint32(metadata, data);
+      break;
+   }
+   case GL_BUFFER_VARIABLE:
+   case GL_VERTEX_SUBROUTINE_UNIFORM:
+   case GL_GEOMETRY_SUBROUTINE_UNIFORM:
+   case GL_FRAGMENT_SUBROUTINE_UNIFORM:
+   case GL_COMPUTE_SUBROUTINE_UNIFORM:
+   case GL_TESS_CONTROL_SUBROUTINE_UNIFORM:
+   case GL_TESS_EVALUATION_SUBROUTINE_UNIFORM:
+   case GL_UNIFORM:
+      for (unsigned i = 0; i < prog->NumUniformStorage; i++) {
+         if (strcmp(((gl_uniform_storage *)res->Data)->name,
+                    prog->UniformStorage[i].name) == 0) {
+            blob_write_uint32(metadata, i);
+            break;
+         }
+      }
+      break;
+   default:
+      assert(!"Support for writting resource not yet implemented.");
+   }
+}
+
+static void
+read_program_resource_data(struct blob_reader *metadata,
+                           struct gl_shader_program *prog,
+                           struct gl_program_resource *res)
+{
+   switch(res->Type) {
+   case GL_PROGRAM_INPUT:
+   case GL_PROGRAM_OUTPUT: {
+      gl_shader_variable *var = ralloc(prog, struct gl_shader_variable);
+      var->type = decode_type_from_blob(metadata);
+      var->name = ralloc_strdup(prog, blob_read_string(metadata));
+      var->location = blob_read_uint32(metadata);
+
+      unsigned data = blob_read_uint32(metadata);
+      var->index = data & 1;
+      var->patch = data >> 1 & 1;
+      var->mode = data >> 2;
+
+      res->Data = var;
+      break;
+   }
+   case GL_BUFFER_VARIABLE:
+   case GL_VERTEX_SUBROUTINE_UNIFORM:
+   case GL_GEOMETRY_SUBROUTINE_UNIFORM:
+   case GL_FRAGMENT_SUBROUTINE_UNIFORM:
+   case GL_COMPUTE_SUBROUTINE_UNIFORM:
+   case GL_TESS_CONTROL_SUBROUTINE_UNIFORM:
+   case GL_TESS_EVALUATION_SUBROUTINE_UNIFORM:
+   case GL_UNIFORM:
+      res->Data = &prog->UniformStorage[blob_read_uint32(metadata)];
+      break;
+   default:
+      assert(!"Support for reading resource not yet implemented.");
+   }
+}
+
+static void
+write_program_resource_list(struct blob *metadata,
+                            struct gl_shader_program *prog)
+{
+   blob_write_uint32(metadata, prog->NumProgramResourceList);
+
+   for (unsigned i = 0; i < prog->NumProgramResourceList; i++) {
+      blob_write_uint32(metadata, prog->ProgramResourceList[i].Type);
+      write_program_resource_data(metadata, prog,
+                                  &prog->ProgramResourceList[i]);
+      blob_write_bytes(metadata, &prog->ProgramResourceList[i].StageReferences,
+                       sizeof(prog->ProgramResourceList[i].StageReferences));
+   }
+}
+
+static void
+read_program_resource_list(struct blob_reader *metadata,
+                           struct gl_shader_program *prog)
+{
+   prog->NumProgramResourceList = blob_read_uint32(metadata);
+
+   prog->ProgramResourceList = ralloc_array(prog, gl_program_resource,
+                                            prog->NumProgramResourceList);
+
+   for (unsigned i = 0; i < prog->NumProgramResourceList; i++) {
+      prog->ProgramResourceList[i].Type = blob_read_uint32(metadata);
+      read_program_resource_data(metadata, prog,
+                                 &prog->ProgramResourceList[i]);
+      blob_copy_bytes(metadata,
+                      (uint8_t *) &prog->ProgramResourceList[i].StageReferences,
+                      sizeof(prog->ProgramResourceList[i].StageReferences));
+   }
+}
+
+static void
 write_shader_parameters(struct blob *metadata,
                         struct gl_program_parameter_list *params)
 {
@@ -463,6 +573,8 @@ shader_cache_write_program_metadata(struct gl_context *ctx,
 
    write_uniform_remap_table(metadata, prog);
 
+   write_program_resource_list(metadata, prog);
+
    for (unsigned i = 0; i < prog->NumShaders; i++) {
       cache_put_key(cache, prog->Shaders[i]->sha1);
       if (ctx->_Shader->Flags & GLSL_CACHE_INFO) {
@@ -565,6 +677,8 @@ shader_cache_read_program_metadata(struct gl_context *ctx,
 
    read_uniform_remap_table(&metadata, prog);
 
+   read_program_resource_list(&metadata, prog);
+
    if (metadata.current != metadata.end || metadata.overrun) {
       /* FIXME: At this point, we should discard the item from the cache and
        * rebuild from source.
-- 
2.7.4



More information about the mesa-dev mailing list