summaryrefslogtreecommitdiffstats
path: root/src/compiler/glsl/linker.cpp
diff options
context:
space:
mode:
authorTimothy Arceri <[email protected]>2016-04-02 12:16:01 +1100
committerTimothy Arceri <[email protected]>2016-04-02 17:10:56 +1100
commitd8855d66f4ae2acf994eae31e59fd2cfa5483627 (patch)
tree618f2849575d1bc19b7c314618d7e106f42eeea2 /src/compiler/glsl/linker.cpp
parent0082b33a78cd007054f7774c57a4f7ea9fc1d209 (diff)
glsl: simplify buffer block resource limit checking
This changes the code to use the buffer counts stored for each stage rather than counting from scratch. It also moves the checks outside of the for loop which means we now just get a single link error message if we go over the max rather than X error messages where X is the number we have exceeded the max by. Reviewed-by: Kenneth Graunke <[email protected]>
Diffstat (limited to 'src/compiler/glsl/linker.cpp')
-rw-r--r--src/compiler/glsl/linker.cpp87
1 files changed, 32 insertions, 55 deletions
diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp
index 47087c86243..f440dbce888 100644
--- a/src/compiler/glsl/linker.cpp
+++ b/src/compiler/glsl/linker.cpp
@@ -2890,6 +2890,9 @@ store_fragdepth_layout(struct gl_shader_program *prog)
static void
check_resources(struct gl_context *ctx, struct gl_shader_program *prog)
{
+ unsigned total_uniform_blocks = 0;
+ unsigned total_shader_storage_blocks = 0;
+
for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
struct gl_shader *sh = prog->_LinkedShaders[i];
@@ -2928,12 +2931,37 @@ check_resources(struct gl_context *ctx, struct gl_shader_program *prog)
_mesa_shader_stage_to_string(i));
}
}
+
+ total_shader_storage_blocks += sh->NumShaderStorageBlocks;
+ total_uniform_blocks += sh->NumUniformBlocks;
+
+ const unsigned max_uniform_blocks =
+ ctx->Const.Program[i].MaxUniformBlocks;
+ if (max_uniform_blocks < sh->NumUniformBlocks) {
+ linker_error(prog, "Too many %s uniform blocks (%d/%d)\n",
+ _mesa_shader_stage_to_string(i), sh->NumUniformBlocks,
+ max_uniform_blocks);
+ }
+
+ const unsigned max_shader_storage_blocks =
+ ctx->Const.Program[i].MaxShaderStorageBlocks;
+ if (max_shader_storage_blocks < sh->NumShaderStorageBlocks) {
+ linker_error(prog, "Too many %s shader storage blocks (%d/%d)\n",
+ _mesa_shader_stage_to_string(i),
+ sh->NumShaderStorageBlocks, max_shader_storage_blocks);
+ }
}
- unsigned blocks[MESA_SHADER_STAGES] = {0};
- unsigned total_uniform_blocks = 0;
- unsigned shader_blocks[MESA_SHADER_STAGES] = {0};
- unsigned total_shader_storage_blocks = 0;
+ if (total_uniform_blocks > ctx->Const.MaxCombinedUniformBlocks) {
+ linker_error(prog, "Too many combined uniform blocks (%d/%d)\n",
+ total_uniform_blocks, ctx->Const.MaxCombinedUniformBlocks);
+ }
+
+ if (total_shader_storage_blocks > ctx->Const.MaxCombinedShaderStorageBlocks) {
+ linker_error(prog, "Too many combined shader storage blocks (%d/%d)\n",
+ total_shader_storage_blocks,
+ ctx->Const.MaxCombinedShaderStorageBlocks);
+ }
for (unsigned i = 0; i < prog->NumBufferInterfaceBlocks; i++) {
/* Don't check SSBOs for Uniform Block Size */
@@ -2952,57 +2980,6 @@ check_resources(struct gl_context *ctx, struct gl_shader_program *prog)
prog->BufferInterfaceBlocks[i].UniformBufferSize,
ctx->Const.MaxShaderStorageBlockSize);
}
-
- for (unsigned j = 0; j < MESA_SHADER_STAGES; j++) {
- if (prog->InterfaceBlockStageIndex[j][i] != -1) {
- struct gl_shader *sh = prog->_LinkedShaders[j];
- int stage_index = prog->InterfaceBlockStageIndex[j][i];
- if (sh &&
- sh->BufferInterfaceBlocks[stage_index]->IsShaderStorage) {
- shader_blocks[j]++;
- total_shader_storage_blocks++;
- } else {
- blocks[j]++;
- total_uniform_blocks++;
- }
- }
- }
-
- if (total_uniform_blocks > ctx->Const.MaxCombinedUniformBlocks) {
- linker_error(prog, "Too many combined uniform blocks (%d/%d)\n",
- total_uniform_blocks,
- ctx->Const.MaxCombinedUniformBlocks);
- } else {
- for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
- const unsigned max_uniform_blocks =
- ctx->Const.Program[i].MaxUniformBlocks;
- if (blocks[i] > max_uniform_blocks) {
- linker_error(prog, "Too many %s uniform blocks (%d/%d)\n",
- _mesa_shader_stage_to_string(i),
- blocks[i],
- max_uniform_blocks);
- break;
- }
- }
- }
-
- if (total_shader_storage_blocks > ctx->Const.MaxCombinedShaderStorageBlocks) {
- linker_error(prog, "Too many combined shader storage blocks (%d/%d)\n",
- total_shader_storage_blocks,
- ctx->Const.MaxCombinedShaderStorageBlocks);
- } else {
- for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
- const unsigned max_shader_storage_blocks =
- ctx->Const.Program[i].MaxShaderStorageBlocks;
- if (shader_blocks[i] > max_shader_storage_blocks) {
- linker_error(prog, "Too many %s shader storage blocks (%d/%d)\n",
- _mesa_shader_stage_to_string(i),
- shader_blocks[i],
- max_shader_storage_blocks);
- break;
- }
- }
- }
}
}