[Mesa-dev] [PATCH 1/2] glsl: add size of the program resource for later validation

Tapani Pälli tapani.palli at intel.com
Fri Aug 11 07:45:14 UTC 2017


Signed-off-by: Tapani Pälli <tapani.palli at intel.com>
---
 src/compiler/glsl/linker.cpp | 32 ++++++++++++++++++++++----------
 src/mesa/main/mtypes.h       |  1 +
 2 files changed, 23 insertions(+), 10 deletions(-)

(Alternatively, we could make add_program_resource a template function
so we would not need to modify all the callers.)

diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp
index 9af7d80..3c0ab79 100644
--- a/src/compiler/glsl/linker.cpp
+++ b/src/compiler/glsl/linker.cpp
@@ -3597,7 +3597,8 @@ should_add_buffer_variable(struct gl_shader_program *shProg,
 static bool
 add_program_resource(struct gl_shader_program *prog,
                      struct set *resource_set,
-                     GLenum type, const void *data, uint8_t stages)
+                     GLenum type, const void *data, uint8_t type_size,
+                     uint8_t stages)
 {
    assert(data);
 
@@ -3621,6 +3622,7 @@ add_program_resource(struct gl_shader_program *prog,
 
    res->Type = type;
    res->Data = data;
+   res->TypeSize = type_size;
    res->StageReferences = stages;
 
    prog->data->NumProgramResourceList++;
@@ -3886,7 +3888,8 @@ add_shader_variable(const struct gl_context *ctx,
          return false;
 
       return add_program_resource(shProg, resource_set,
-                                  programInterface, sha_v, stage_mask);
+                                  programInterface, sha_v, sizeof(*sha_v),
+                                  stage_mask);
    }
    }
 }
@@ -4297,7 +4300,8 @@ build_program_resource_list(struct gl_context *ctx,
          for (int i = 0; i < linked_xfb->NumVarying; i++) {
             if (!add_program_resource(shProg, resource_set,
                                       GL_TRANSFORM_FEEDBACK_VARYING,
-                                      &linked_xfb->Varyings[i], 0))
+                                      &linked_xfb->Varyings[i],
+                                      sizeof(linked_xfb->Varyings[i]), 0))
             return;
          }
       }
@@ -4308,7 +4312,8 @@ build_program_resource_list(struct gl_context *ctx,
             linked_xfb->Buffers[i].Binding = i;
             if (!add_program_resource(shProg, resource_set,
                                       GL_TRANSFORM_FEEDBACK_BUFFER,
-                                      &linked_xfb->Buffers[i], 0))
+                                      &linked_xfb->Buffers[i],
+                                      sizeof(linked_xfb->Buffers[i]), 0))
             return;
          }
       }
@@ -4345,28 +4350,33 @@ build_program_resource_list(struct gl_context *ctx,
       }
 
       if (!add_program_resource(shProg, resource_set, type,
-                                &shProg->data->UniformStorage[i], stageref))
+                                &shProg->data->UniformStorage[i],
+                                sizeof(shProg->data->UniformStorage[i]),
+                                stageref))
          return;
    }
 
    /* Add program uniform blocks. */
    for (unsigned i = 0; i < shProg->data->NumUniformBlocks; i++) {
       if (!add_program_resource(shProg, resource_set, GL_UNIFORM_BLOCK,
-          &shProg->data->UniformBlocks[i], 0))
+          &shProg->data->UniformBlocks[i],
+          sizeof(shProg->data->UniformBlocks[i]), 0))
          return;
    }
 
    /* Add program shader storage blocks. */
    for (unsigned i = 0; i < shProg->data->NumShaderStorageBlocks; i++) {
       if (!add_program_resource(shProg, resource_set, GL_SHADER_STORAGE_BLOCK,
-          &shProg->data->ShaderStorageBlocks[i], 0))
+          &shProg->data->ShaderStorageBlocks[i],
+          sizeof(shProg->data->ShaderStorageBlocks[i]), 0))
          return;
    }
 
    /* Add atomic counter buffers. */
    for (unsigned i = 0; i < shProg->data->NumAtomicBuffers; i++) {
       if (!add_program_resource(shProg, resource_set, GL_ATOMIC_COUNTER_BUFFER,
-                                &shProg->data->AtomicBuffers[i], 0))
+                                &shProg->data->AtomicBuffers[i],
+                                sizeof(shProg->data->AtomicBuffers[i]), 0))
          return;
    }
 
@@ -4383,7 +4393,8 @@ build_program_resource_list(struct gl_context *ctx,
          type = _mesa_shader_stage_to_subroutine_uniform((gl_shader_stage)j);
          /* add shader subroutines */
          if (!add_program_resource(shProg, resource_set,
-                                   type, &shProg->data->UniformStorage[i], 0))
+                                   type, &shProg->data->UniformStorage[i],
+                                   sizeof(shProg->data->UniformStorage[i]), 0))
             return;
       }
    }
@@ -4396,7 +4407,8 @@ build_program_resource_list(struct gl_context *ctx,
       GLuint type = _mesa_shader_stage_to_subroutine((gl_shader_stage)i);
       for (unsigned j = 0; j < p->sh.NumSubroutineFunctions; j++) {
          if (!add_program_resource(shProg, resource_set,
-                                   type, &p->sh.SubroutineFunctions[j], 0))
+                                   type, &p->sh.SubroutineFunctions[j],
+                                   sizeof(p->sh.SubroutineFunctions[j]), 0))
             return;
       }
    }
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 49eb7d5..a2dddf6 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2823,6 +2823,7 @@ struct gl_program_resource
 {
    GLenum Type; /** Program interface type. */
    const void *Data; /** Pointer to resource associated data structure. */
+   uint8_t TypeSize; /** Size of the program resource type. */
    uint8_t StageReferences; /** Bitmask of shader stage references. */
 };
 
-- 
2.9.4



More information about the mesa-dev mailing list