Mesa (master): glsl: simplify buffer block resource limit checking

Timothy Arceri tarceri at kemper.freedesktop.org
Sat Apr 2 06:12:05 UTC 2016


Module: Mesa
Branch: master
Commit: d8855d66f4ae2acf994eae31e59fd2cfa5483627
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=d8855d66f4ae2acf994eae31e59fd2cfa5483627

Author: Timothy Arceri <timothy.arceri at collabora.com>
Date:   Sat Apr  2 12:16:01 2016 +1100

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 <kenneth at whitecape.org>

---

 src/compiler/glsl/linker.cpp | 87 ++++++++++++++++----------------------------
 1 file changed, 32 insertions(+), 55 deletions(-)

diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp
index 47087c8..f440dbc 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;
-            }
-         }
-      }
    }
 }
 




More information about the mesa-commit mailing list