[Mesa-dev] [PATCH 4/7] glsl: simplify buffer block resource limit checking

Kenneth Graunke kenneth at whitecape.org
Sat Apr 2 04:43:47 UTC 2016


On Saturday, April 2, 2016 3:03:55 PM PDT Timothy Arceri wrote:
> 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.
> ---
>  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 c9eaa6b..1f2b77f 100644
> --- a/src/compiler/glsl/linker.cpp
> +++ b/src/compiler/glsl/linker.cpp
> @@ -2893,6 +2893,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];
>  
> @@ -2931,12 +2934,37 @@ check_resources(struct gl_context *ctx, struct 
gl_shader_program *prog)
>                           _mesa_shader_stage_to_string(i));
>           }
>        }
> +
> +      total_shader_storage_blocks += sh->NumUniformBlocks;
> +      total_uniform_blocks += sh->NumShaderStorageBlocks;

This looks backwards...

With that fixed, this is:
Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>

> +
> +      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 */
> @@ -2955,57 +2983,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;
> -            }
> -         }
> -      }
>     }
>  }
>  
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20160401/83188d46/attachment.sig>


More information about the mesa-dev mailing list