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

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


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

diff --git a/src/compiler/glsl/shader_cache.cpp b/src/compiler/glsl/shader_cache.cpp
index 776292f..262596b 100644
--- a/src/compiler/glsl/shader_cache.cpp
+++ b/src/compiler/glsl/shader_cache.cpp
@@ -312,6 +312,119 @@ 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 (prog->UniformStorage[i].hidden)
+            break; /* No more user defined uniforms */
+
+         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 implemneted.");
+   }
+}
+
+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 implemneted.");
+   }
+}
+
+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)
 {
@@ -451,6 +564,8 @@ shader_cache_write_program_metadata(struct gl_context *ctx,
 
    write_uniform_remap_table(metadata, prog);
 
+   write_program_resource_list(metadata, prog);
+
    write_shader_metadata(metadata, prog->_LinkedShaders[MESA_SHADER_VERTEX]);
    write_shader_metadata(metadata, prog->_LinkedShaders[MESA_SHADER_FRAGMENT]);
 
@@ -545,6 +660,8 @@ shader_cache_read_program_metadata(struct gl_context *ctx,
 
    read_uniform_remap_table(&metadata, prog);
 
+   read_program_resource_list(&metadata, prog);
+
    _mesa_HashLockMutex(ctx->Shared->ShaderObjects);
    unsigned name = _mesa_HashFindFreeKeyBlock(ctx->Shared->ShaderObjects, 1);
    linked = ctx->Driver.NewShader(ctx, name, GL_VERTEX_SHADER);
-- 
2.5.5



More information about the mesa-dev mailing list