[Mesa-dev] [PATCH 51/58] mesa/glsl: move ProgramResourceList to gl_shader_program_data

Timothy Arceri timothy.arceri at collabora.com
Sun Nov 20 13:29:30 UTC 2016


We also move NumProgramResourceList at the same time.

GLES does interface validation on SSO at runtime so we need to move
this to be able to switch to storing gl_program pointers in
CurrentProgram.
---
 src/compiler/glsl/linker.cpp     | 20 +++++++++----------
 src/mesa/main/mtypes.h           |  8 ++++----
 src/mesa/main/program_resource.c | 40 ++++++++++++++++++-------------------
 src/mesa/main/shader_query.cpp   | 43 +++++++++++++++++++++++-----------------
 src/mesa/main/shaderobj.c        |  8 ++++----
 5 files changed, 63 insertions(+), 56 deletions(-)

diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp
index 182e560..77017d7 100644
--- a/src/compiler/glsl/linker.cpp
+++ b/src/compiler/glsl/linker.cpp
@@ -3520,25 +3520,25 @@ add_program_resource(struct gl_shader_program *prog,
    if (_mesa_set_search(resource_set, data))
       return true;
 
-   prog->ProgramResourceList =
+   prog->data->ProgramResourceList =
       reralloc(prog,
-               prog->ProgramResourceList,
+               prog->data->ProgramResourceList,
                gl_program_resource,
-               prog->NumProgramResourceList + 1);
+               prog->data->NumProgramResourceList + 1);
 
-   if (!prog->ProgramResourceList) {
+   if (!prog->data->ProgramResourceList) {
       linker_error(prog, "Out of memory during linking.\n");
       return false;
    }
 
    struct gl_program_resource *res =
-      &prog->ProgramResourceList[prog->NumProgramResourceList];
+      &prog->data->ProgramResourceList[prog->data->NumProgramResourceList];
 
    res->Type = type;
    res->Data = data;
    res->StageReferences = stages;
 
-   prog->NumProgramResourceList++;
+   prog->data->NumProgramResourceList++;
 
    _mesa_set_add(resource_set, data);
 
@@ -4167,10 +4167,10 @@ build_program_resource_list(struct gl_context *ctx,
                             struct gl_shader_program *shProg)
 {
    /* Rebuild resource list. */
-   if (shProg->ProgramResourceList) {
-      ralloc_free(shProg->ProgramResourceList);
-      shProg->ProgramResourceList = NULL;
-      shProg->NumProgramResourceList = 0;
+   if (shProg->data->ProgramResourceList) {
+      ralloc_free(shProg->data->ProgramResourceList);
+      shProg->data->ProgramResourceList = NULL;
+      shProg->data->NumProgramResourceList = 0;
    }
 
    int input_stage = MESA_SHADER_STAGES, output_stage = 0;
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index da5c23d..f078b25 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2644,6 +2644,10 @@ struct gl_shader_program_data
    struct gl_active_atomic_buffer *AtomicBuffers;
    unsigned NumAtomicBuffers;
 
+   /** List of all active resources after linking. */
+   struct gl_program_resource *ProgramResourceList;
+   unsigned NumProgramResourceList;
+
    GLboolean LinkStatus;   /**< GL_LINK_STATUS */
    GLboolean Validated;
    GLchar *InfoLog;
@@ -2833,10 +2837,6 @@ struct gl_shader_program
     */
    struct gl_linked_shader *_LinkedShaders[MESA_SHADER_STAGES];
 
-   /** List of all active resources after linking. */
-   struct gl_program_resource *ProgramResourceList;
-   unsigned NumProgramResourceList;
-
    /* True if any of the fragment shaders attached to this program use:
     * #extension ARB_fragment_coord_conventions: enable
     */
diff --git a/src/mesa/main/program_resource.c b/src/mesa/main/program_resource.c
index 4cf4b80..6c9358a 100644
--- a/src/mesa/main/program_resource.c
+++ b/src/mesa/main/program_resource.c
@@ -213,8 +213,8 @@ _mesa_GetProgramInterfaceiv(GLuint program, GLenum programInterface,
 
          *params = sh ? sh->Program->sh.NumSubroutineUniforms : 0;
       } else {
-         for (i = 0, *params = 0; i < shProg->NumProgramResourceList; i++)
-            if (shProg->ProgramResourceList[i].Type == programInterface)
+         for (i = 0, *params = 0; i < shProg->data->NumProgramResourceList; i++)
+            if (shProg->data->ProgramResourceList[i].Type == programInterface)
                (*params)++;
       }
       break;
@@ -230,32 +230,32 @@ _mesa_GetProgramInterfaceiv(GLuint program, GLenum programInterface,
       /* Name length consists of base name, 3 additional chars '[0]' if
        * resource is an array and finally 1 char for string terminator.
        */
-      for (i = 0, *params = 0; i < shProg->NumProgramResourceList; i++) {
-         if (shProg->ProgramResourceList[i].Type != programInterface)
+      for (i = 0, *params = 0; i < shProg->data->NumProgramResourceList; i++) {
+         if (shProg->data->ProgramResourceList[i].Type != programInterface)
             continue;
          unsigned len =
-            _mesa_program_resource_name_len(&shProg->ProgramResourceList[i]);
+            _mesa_program_resource_name_len(&shProg->data->ProgramResourceList[i]);
          *params = MAX2(*params, len + 1);
       }
       break;
    case GL_MAX_NUM_ACTIVE_VARIABLES:
       switch (programInterface) {
       case GL_UNIFORM_BLOCK:
-         for (i = 0, *params = 0; i < shProg->NumProgramResourceList; i++) {
-            if (shProg->ProgramResourceList[i].Type == programInterface) {
+         for (i = 0, *params = 0; i < shProg->data->NumProgramResourceList; i++) {
+            if (shProg->data->ProgramResourceList[i].Type == programInterface) {
                struct gl_uniform_block *block =
                   (struct gl_uniform_block *)
-                  shProg->ProgramResourceList[i].Data;
+                  shProg->data->ProgramResourceList[i].Data;
                *params = MAX2(*params, block->NumUniforms);
             }
          }
          break;
       case GL_SHADER_STORAGE_BLOCK:
-         for (i = 0, *params = 0; i < shProg->NumProgramResourceList; i++) {
-            if (shProg->ProgramResourceList[i].Type == programInterface) {
+         for (i = 0, *params = 0; i < shProg->data->NumProgramResourceList; i++) {
+            if (shProg->data->ProgramResourceList[i].Type == programInterface) {
                struct gl_uniform_block *block =
                   (struct gl_uniform_block *)
-                  shProg->ProgramResourceList[i].Data;
+                  shProg->data->ProgramResourceList[i].Data;
                GLint block_params = 0;
                for (unsigned j = 0; j < block->NumUniforms; j++) {
                   const char *iname = block->Uniforms[j].IndexName;
@@ -271,21 +271,21 @@ _mesa_GetProgramInterfaceiv(GLuint program, GLenum programInterface,
          }
          break;
       case GL_ATOMIC_COUNTER_BUFFER:
-         for (i = 0, *params = 0; i < shProg->NumProgramResourceList; i++) {
-            if (shProg->ProgramResourceList[i].Type == programInterface) {
+         for (i = 0, *params = 0; i < shProg->data->NumProgramResourceList; i++) {
+            if (shProg->data->ProgramResourceList[i].Type == programInterface) {
                struct gl_active_atomic_buffer *buffer =
                   (struct gl_active_atomic_buffer *)
-                  shProg->ProgramResourceList[i].Data;
+                  shProg->data->ProgramResourceList[i].Data;
                *params = MAX2(*params, buffer->NumUniforms);
             }
          }
          break;
       case GL_TRANSFORM_FEEDBACK_BUFFER:
-         for (i = 0, *params = 0; i < shProg->NumProgramResourceList; i++) {
-            if (shProg->ProgramResourceList[i].Type == programInterface) {
+         for (i = 0, *params = 0; i < shProg->data->NumProgramResourceList; i++) {
+            if (shProg->data->ProgramResourceList[i].Type == programInterface) {
                struct gl_transform_feedback_buffer *buffer =
                   (struct gl_transform_feedback_buffer *)
-                  shProg->ProgramResourceList[i].Data;
+                  shProg->data->ProgramResourceList[i].Data;
                *params = MAX2(*params, buffer->NumVaryings);
             }
          }
@@ -305,11 +305,11 @@ _mesa_GetProgramInterfaceiv(GLuint program, GLenum programInterface,
       case GL_COMPUTE_SUBROUTINE_UNIFORM:
       case GL_TESS_CONTROL_SUBROUTINE_UNIFORM:
       case GL_TESS_EVALUATION_SUBROUTINE_UNIFORM: {
-         for (i = 0, *params = 0; i < shProg->NumProgramResourceList; i++) {
-            if (shProg->ProgramResourceList[i].Type == programInterface) {
+         for (i = 0, *params = 0; i < shProg->data->NumProgramResourceList; i++) {
+            if (shProg->data->ProgramResourceList[i].Type == programInterface) {
                struct gl_uniform_storage *uni =
                   (struct gl_uniform_storage *)
-                  shProg->ProgramResourceList[i].Data;
+                  shProg->data->ProgramResourceList[i].Data;
                *params = MAX2(*params, uni->num_compatible_subroutines);
             }
          }
diff --git a/src/mesa/main/shader_query.cpp b/src/mesa/main/shader_query.cpp
index 9c667bf..12b08f9 100644
--- a/src/mesa/main/shader_query.cpp
+++ b/src/mesa/main/shader_query.cpp
@@ -198,9 +198,10 @@ _mesa_count_active_attribs(struct gl_shader_program *shProg)
       return 0;
    }
 
-   struct gl_program_resource *res = shProg->ProgramResourceList;
+   struct gl_program_resource *res = shProg->data->ProgramResourceList;
    unsigned count = 0;
-   for (unsigned j = 0; j < shProg->NumProgramResourceList; j++, res++) {
+   for (unsigned j = 0; j < shProg->data->NumProgramResourceList;
+        j++, res++) {
       if (res->Type == GL_PROGRAM_INPUT &&
           res->StageReferences & (1 << MESA_SHADER_VERTEX))
          count++;
@@ -217,9 +218,10 @@ _mesa_longest_attribute_name_length(struct gl_shader_program *shProg)
       return 0;
    }
 
-   struct gl_program_resource *res = shProg->ProgramResourceList;
+   struct gl_program_resource *res = shProg->data->ProgramResourceList;
    size_t longest = 0;
-   for (unsigned j = 0; j < shProg->NumProgramResourceList; j++, res++) {
+   for (unsigned j = 0; j < shProg->data->NumProgramResourceList;
+        j++, res++) {
       if (res->Type == GL_PROGRAM_INPUT &&
           res->StageReferences & (1 << MESA_SHADER_VERTEX)) {
 
@@ -466,8 +468,9 @@ _mesa_program_resource_find_name(struct gl_shader_program *shProg,
                                  GLenum programInterface, const char *name,
                                  unsigned *array_index)
 {
-   struct gl_program_resource *res = shProg->ProgramResourceList;
-   for (unsigned i = 0; i < shProg->NumProgramResourceList; i++, res++) {
+   struct gl_program_resource *res = shProg->data->ProgramResourceList;
+   for (unsigned i = 0; i < shProg->data->NumProgramResourceList;
+        i++, res++) {
       if (res->Type != programInterface)
          continue;
 
@@ -570,10 +573,10 @@ calc_resource_index(struct gl_shader_program *shProg,
 {
    unsigned i;
    GLuint index = 0;
-   for (i = 0; i < shProg->NumProgramResourceList; i++) {
-      if (&shProg->ProgramResourceList[i] == res)
+   for (i = 0; i < shProg->data->NumProgramResourceList; i++) {
+      if (&shProg->data->ProgramResourceList[i] == res)
          return index;
-      if (shProg->ProgramResourceList[i].Type == res->Type)
+      if (shProg->data->ProgramResourceList[i].Type == res->Type)
          index++;
    }
    return GL_INVALID_INDEX;
@@ -614,8 +617,9 @@ _mesa_program_resource_index(struct gl_shader_program *shProg,
 static struct gl_program_resource*
 program_resource_find_data(struct gl_shader_program *shProg, void *data)
 {
-   struct gl_program_resource *res = shProg->ProgramResourceList;
-   for (unsigned i = 0; i < shProg->NumProgramResourceList; i++, res++) {
+   struct gl_program_resource *res = shProg->data->ProgramResourceList;
+   for (unsigned i = 0; i < shProg->data->NumProgramResourceList;
+        i++, res++) {
       if (res->Data == data)
          return res;
    }
@@ -628,10 +632,11 @@ struct gl_program_resource *
 _mesa_program_resource_find_index(struct gl_shader_program *shProg,
                                   GLenum programInterface, GLuint index)
 {
-   struct gl_program_resource *res = shProg->ProgramResourceList;
+   struct gl_program_resource *res = shProg->data->ProgramResourceList;
    int idx = -1;
 
-   for (unsigned i = 0; i < shProg->NumProgramResourceList; i++, res++) {
+   for (unsigned i = 0; i < shProg->data->NumProgramResourceList;
+        i++, res++) {
       if (res->Type != programInterface)
          continue;
 
@@ -1405,7 +1410,7 @@ validate_io(struct gl_shader_program *producer,
    size_t name_buffer_size = 0;
 
    gl_shader_variable const **outputs =
-      (gl_shader_variable const **) calloc(producer->NumProgramResourceList,
+      (gl_shader_variable const **) calloc(producer->data->NumProgramResourceList,
                                            sizeof(gl_shader_variable *));
    if (outputs == NULL)
       return false;
@@ -1428,8 +1433,9 @@ validate_io(struct gl_shader_program *producer,
     * some output that did not have an input.
     */
    unsigned num_outputs = 0;
-   for (unsigned i = 0; i < producer->NumProgramResourceList; i++) {
-      struct gl_program_resource *res = &producer->ProgramResourceList[i];
+   for (unsigned i = 0; i < producer->data->NumProgramResourceList; i++) {
+      struct gl_program_resource *res =
+         &producer->data->ProgramResourceList[i];
 
       if (res->Type != GL_PROGRAM_OUTPUT)
          continue;
@@ -1448,8 +1454,9 @@ validate_io(struct gl_shader_program *producer,
    }
 
    unsigned match_index = 0;
-   for (unsigned i = 0; i < consumer->NumProgramResourceList; i++) {
-      struct gl_program_resource *res = &consumer->ProgramResourceList[i];
+   for (unsigned i = 0; i < consumer->data->NumProgramResourceList; i++) {
+      struct gl_program_resource *res =
+         &consumer->data->ProgramResourceList[i];
 
       if (res->Type != GL_PROGRAM_INPUT)
          continue;
diff --git a/src/mesa/main/shaderobj.c b/src/mesa/main/shaderobj.c
index 0123ea6..6229049 100644
--- a/src/mesa/main/shaderobj.c
+++ b/src/mesa/main/shaderobj.c
@@ -365,10 +365,10 @@ _mesa_clear_shader_program_data(struct gl_context *ctx,
    shProg->data->AtomicBuffers = NULL;
    shProg->data->NumAtomicBuffers = 0;
 
-   if (shProg->ProgramResourceList) {
-      ralloc_free(shProg->ProgramResourceList);
-      shProg->ProgramResourceList = NULL;
-      shProg->NumProgramResourceList = 0;
+   if (shProg->data->ProgramResourceList) {
+      ralloc_free(shProg->data->ProgramResourceList);
+      shProg->data->ProgramResourceList = NULL;
+      shProg->data->NumProgramResourceList = 0;
    }
 }
 
-- 
2.7.4



More information about the mesa-dev mailing list