[Mesa-dev] [PATCH 34/87] glsl: add support for caching atomic buffers

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


---
 src/compiler/glsl/shader_cache.cpp | 87 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 87 insertions(+)

diff --git a/src/compiler/glsl/shader_cache.cpp b/src/compiler/glsl/shader_cache.cpp
index da075cd..ed9c9a5 100644
--- a/src/compiler/glsl/shader_cache.cpp
+++ b/src/compiler/glsl/shader_cache.cpp
@@ -337,6 +337,77 @@ read_buffer_blocks(struct blob_reader *metadata,
 }
 
 static void
+write_atomic_buffers(struct blob *metadata, struct gl_shader_program *prog)
+{
+   blob_write_uint32(metadata, prog->NumAtomicBuffers);
+
+   for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
+      if (prog->_LinkedShaders[i]) {
+         blob_write_uint32(metadata,
+                           prog->_LinkedShaders[i]->NumAtomicBuffers);
+      }
+   }
+
+   for (unsigned i = 0; i < prog->NumAtomicBuffers; i++) {
+      blob_write_uint32(metadata, prog->AtomicBuffers[i].Binding);
+      blob_write_uint32(metadata, prog->AtomicBuffers[i].MinimumSize);
+      blob_write_uint32(metadata, prog->AtomicBuffers[i].NumUniforms);
+
+      blob_write_bytes(metadata, prog->AtomicBuffers[i].StageReferences,
+                       sizeof(prog->AtomicBuffers[i].StageReferences));
+
+      for (unsigned j = 0; j < prog->AtomicBuffers[i].NumUniforms; j++) {
+         blob_write_uint32(metadata, prog->AtomicBuffers[i].Uniforms[j]);
+      }
+   }
+}
+
+static void
+read_atomic_buffers(struct blob_reader *metadata,
+                     struct gl_shader_program *prog)
+{
+   prog->NumAtomicBuffers = blob_read_uint32(metadata);
+   prog->AtomicBuffers =
+      rzalloc_array(prog, gl_active_atomic_buffer, prog->NumAtomicBuffers);
+
+   struct gl_active_atomic_buffer **stage_buff_list[MESA_SHADER_STAGES];
+   for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
+      if (prog->_LinkedShaders[i]) {
+         prog->_LinkedShaders[i]->NumAtomicBuffers =
+            blob_read_uint32(metadata);
+         prog->_LinkedShaders[i]->AtomicBuffers =
+            rzalloc_array(prog, gl_active_atomic_buffer *,
+                          prog->_LinkedShaders[i]->NumAtomicBuffers);
+         stage_buff_list[i] = prog->_LinkedShaders[i]->AtomicBuffers;
+      }
+   }
+
+   for (unsigned i = 0; i < prog->NumAtomicBuffers; i++) {
+      prog->AtomicBuffers[i].Binding = blob_read_uint32(metadata);
+      prog->AtomicBuffers[i].MinimumSize = blob_read_uint32(metadata);
+      prog->AtomicBuffers[i].NumUniforms = blob_read_uint32(metadata);
+
+      blob_copy_bytes(metadata,
+                      (uint8_t *) &prog->AtomicBuffers[i].StageReferences,
+                      sizeof(prog->AtomicBuffers[i].StageReferences));
+
+      prog->AtomicBuffers[i].Uniforms =
+         rzalloc_array(prog, unsigned, prog->AtomicBuffers[i].NumUniforms);
+
+      for (unsigned j = 0; j < prog->AtomicBuffers[i].NumUniforms; j++) {
+         prog->AtomicBuffers[i].Uniforms[j] = blob_read_uint32(metadata);
+      }
+
+      for (unsigned j = 0; j < MESA_SHADER_STAGES; j++) {
+         if (prog->AtomicBuffers[i].StageReferences[j]) {
+            *stage_buff_list[j] = &prog->AtomicBuffers[i];
+            stage_buff_list[j]++;
+         }
+      }
+   }
+}
+
+static void
 write_uniforms(struct blob *metadata, struct gl_shader_program *prog)
 {
    uint32_t i;
@@ -627,6 +698,15 @@ write_program_resource_data(struct blob *metadata,
          }
       }
       break;
+   case GL_ATOMIC_COUNTER_BUFFER:
+      for (unsigned i = 0; i < prog->NumAtomicBuffers; i++) {
+         if (((gl_active_atomic_buffer *)res->Data)->Binding ==
+             prog->AtomicBuffers[i].Binding) {
+            blob_write_uint32(metadata, i);
+            break;
+         }
+      }
+      break;
    case GL_TRANSFORM_FEEDBACK_BUFFER:
    case GL_TRANSFORM_FEEDBACK_VARYING:
       /* Don't bother caching transform feedback varyings/buffers as we will
@@ -688,6 +768,9 @@ read_program_resource_data(struct blob_reader *metadata,
    case GL_UNIFORM:
       res->Data = &prog->UniformStorage[blob_read_uint32(metadata)];
       break;
+   case GL_ATOMIC_COUNTER_BUFFER:
+      res->Data = &prog->AtomicBuffers[blob_read_uint32(metadata)];
+      break;
    case GL_VERTEX_SUBROUTINE:
    case GL_TESS_CONTROL_SUBROUTINE:
    case GL_TESS_EVALUATION_SUBROUTINE:
@@ -914,6 +997,8 @@ shader_cache_write_program_metadata(struct gl_context *ctx,
 
    write_uniform_remap_tables(metadata, prog);
 
+   write_atomic_buffers(metadata, prog);
+
    write_buffer_blocks(metadata, prog);
 
    write_subroutines(metadata, prog);
@@ -1023,6 +1108,8 @@ shader_cache_read_program_metadata(struct gl_context *ctx,
 
    read_uniform_remap_tables(&metadata, prog);
 
+   read_atomic_buffers(&metadata, prog);
+
    read_buffer_blocks(&metadata, prog);
 
    read_subroutines(&metadata, prog);
-- 
2.7.4



More information about the mesa-dev mailing list