[Mesa-dev] [PATCH 53/77] glsl: don't try to load/store buffer object values in the cache

Timothy Arceri timothy.arceri at collabora.com
Mon Oct 3 06:05:12 UTC 2016


Also add an assert to catch buffer overflows.
---
 src/compiler/glsl/shader_cache.cpp | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/compiler/glsl/shader_cache.cpp b/src/compiler/glsl/shader_cache.cpp
index a8ca719..fe553df 100644
--- a/src/compiler/glsl/shader_cache.cpp
+++ b/src/compiler/glsl/shader_cache.cpp
@@ -488,6 +488,7 @@ write_uniforms(struct blob *metadata, struct gl_shader_program *prog)
       blob_write_uint32(metadata, prog->UniformStorage[i].offset);
       blob_write_uint32(metadata, prog->UniformStorage[i].array_stride);
       blob_write_uint32(metadata, prog->UniformStorage[i].hidden);
+      blob_write_uint32(metadata, prog->UniformStorage[i].is_shader_storage);
       blob_write_uint32(metadata, prog->UniformStorage[i].matrix_stride);
       blob_write_uint32(metadata, prog->UniformStorage[i].row_major);
       blob_write_uint32(metadata,
@@ -507,7 +508,9 @@ write_uniforms(struct blob *metadata, struct gl_shader_program *prog)
     */
    blob_write_uint32(metadata, prog->NumHiddenUniforms);
    for (i = 0; i < prog->NumUniformStorage; i++) {
-      if (!prog->UniformStorage[i].builtin) {
+      if (!prog->UniformStorage[i].builtin &&
+          !prog->UniformStorage[i].is_shader_storage &&
+          prog->UniformStorage[i].block_index == -1) {
          unsigned vec_size = values_for_type(prog->UniformStorage[i].type) *
             MAX2(prog->UniformStorage[i].array_elements, 1);
          blob_write_bytes(metadata, prog->UniformStorage[i].storage,
@@ -549,6 +552,7 @@ read_uniforms(struct blob_reader *metadata, struct gl_shader_program *prog)
       uniforms[i].offset = blob_read_uint32(metadata);
       uniforms[i].array_stride = blob_read_uint32(metadata);
       uniforms[i].hidden = blob_read_uint32(metadata);
+      uniforms[i].is_shader_storage = blob_read_uint32(metadata);
       uniforms[i].matrix_stride = blob_read_uint32(metadata);
       uniforms[i].row_major = blob_read_uint32(metadata);
       uniforms[i].num_compatible_subroutines = blob_read_uint32(metadata);
@@ -564,12 +568,17 @@ read_uniforms(struct blob_reader *metadata, struct gl_shader_program *prog)
    /* Restore uniform values. */
    prog->NumHiddenUniforms = blob_read_uint32(metadata);
    for (i = 0; i < prog->NumUniformStorage; i++) {
-      if (!prog->UniformStorage[i].builtin) {
+      if (!prog->UniformStorage[i].builtin &&
+          !prog->UniformStorage[i].is_shader_storage &&
+          prog->UniformStorage[i].block_index == -1) {
          unsigned vec_size = values_for_type(prog->UniformStorage[i].type) *
             MAX2(prog->UniformStorage[i].array_elements, 1);
          blob_copy_bytes(metadata,
                          (uint8_t *) prog->UniformStorage[i].storage,
                          sizeof(union gl_constant_value) * vec_size);
+
+        assert(vec_size + prog->UniformStorage[i].storage <=
+               data +  prog->NumUniformDataSlots);
       }
    }
 }
-- 
2.7.4



More information about the mesa-dev mailing list