On 07/20/2012 03:49 PM, Brian Paul wrote:
On 07/20/2012 04:33 PM, Eric Anholt wrote:
Part of fixing piglit maxblocks.
---
  src/glsl/linker.cpp |   34 ++++++++++++++++++++++++++++++++++
  1 file changed, 34 insertions(+)

diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp
index bfdde40..f4e578f 100644
--- a/src/glsl/linker.cpp
+++ b/src/glsl/linker.cpp
@@ -2324,6 +2324,12 @@ check_resources(struct gl_context *ctx, struct
gl_shader_program *prog)
        0          /* FINISHME: Geometry shaders. */
     };

+   const unsigned max_uniform_blocks[MESA_SHADER_TYPES] = {
+      ctx->Const.VertexProgram.MaxUniformBlocks,
+      ctx->Const.FragmentProgram.MaxUniformBlocks,
+      ctx->Const.GeometryProgram.MaxUniformBlocks,
+   };
+
     for (unsigned i = 0; i<  MESA_SHADER_TYPES; i++) {
        struct gl_shader *sh = prog->_LinkedShaders[i];

@@ -2348,6 +2354,34 @@ check_resources(struct gl_context *ctx, struct
gl_shader_program *prog)
        }
     }

+   unsigned blocks[] = {0, 0, 0};

Should that be:
    unsigned blocks[MESA_SHADER_TYPES] = { 0, 0, 0 };

The idea would be to get a compiler warning if the blocks array isn't
grown in the future for new shader types.

This is a good idea, but it won't cause a warning. At least it won't on a C99 savvy compiler. The C99 rules for that usage cause the missing fields to get initialized to 0.

+   unsigned total_uniform_blocks = 0;
+
+   for (unsigned i = 0; i<  prog->NumUniformBlocks; i++) {
+      for (unsigned j = 0; j<  MESA_SHADER_TYPES; j++) {
+     if (prog->UniformBlockStageIndex[j][i] != -1) {
+        blocks[j]++;
+        total_uniform_blocks++;
+     }
+      }
+
+      if (total_uniform_blocks>  ctx->Const.MaxCombinedUniformBlocks) {
+     linker_error(prog, "Too many combined uniform blocks (%d/%d)",
+              prog->NumUniformBlocks,
+              ctx->Const.MaxCombinedUniformBlocks);
+      } else {
+     for (unsigned i = 0; i<  MESA_SHADER_TYPES; i++) {
+        if (blocks[i]>  max_uniform_blocks[i]) {
+           linker_error(prog, "Too many %s uniform blocks (%d/%d)",
+                shader_names[i],
+                blocks[i],
+                max_uniform_blocks[i]);
+           break;
+        }
+     }
+      }
+   }
+
     return prog->LinkStatus;
  }


_______________________________________________
mesa-dev mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

_______________________________________________
mesa-dev mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to