diff options
author | Eric Anholt <[email protected]> | 2012-06-25 12:47:01 -0700 |
---|---|---|
committer | Eric Anholt <[email protected]> | 2012-07-31 12:06:20 -0700 |
commit | 877a897adc40d98c8ee5abaaf0ae16028866c766 (patch) | |
tree | f9d9161ecaad9fdd0411d7a9dcebe7ab4d3c0cf8 | |
parent | fa08b8ad549ef0ad0ee46f525f6f5dd0d6332f99 (diff) |
glsl: Reject linking shaders with too many uniform blocks.
Part of fixing piglit maxblocks.
Reviewed-by: Kenneth Graunke <[email protected]>
Reviewed-by: Ian Romanick <[email protected]>
-rw-r--r-- | src/glsl/linker.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp index bfdde4023e9..34ce13372b2 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[MESA_SHADER_TYPES] = {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; } |