[Mesa-dev] [PATCH 3/5] glsl: Index into ctx->Const.Program[] rather than using ad-hoc code.

Ian Romanick idr at freedesktop.org
Thu Jan 9 09:54:25 PST 2014


On 01/08/2014 11:20 AM, Paul Berry wrote:
> ---
>  src/glsl/ast_to_hir.cpp    | 13 +------------
>  src/glsl/link_atomics.cpp  | 16 ++--------------
>  src/glsl/link_varyings.cpp | 32 ++++++--------------------------
>  src/glsl/linker.cpp        | 43 ++++++++-----------------------------------
>  4 files changed, 17 insertions(+), 87 deletions(-)
> 
> diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
> index 1ac6047..ef8e699 100644
> --- a/src/glsl/ast_to_hir.cpp
> +++ b/src/glsl/ast_to_hir.cpp
> @@ -1983,18 +1983,7 @@ validate_binding_qualifier(struct _mesa_glsl_parse_state *state,
>         *  with an array of size N, all elements of the array from binding
>         *  through binding + N - 1 must be within this range."
>         */
> -      unsigned limit = 0;
> -      switch (state->stage) {
> -      case MESA_SHADER_VERTEX:
> -         limit = ctx->Const.Program[MESA_SHADER_VERTEX].MaxTextureImageUnits;
> -         break;
> -      case MESA_SHADER_GEOMETRY:
> -         limit = ctx->Const.Program[MESA_SHADER_GEOMETRY].MaxTextureImageUnits;
> -         break;
> -      case MESA_SHADER_FRAGMENT:
> -         limit = ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits;
> -         break;
> -      }
> +      unsigned limit = ctx->Const.Program[state->stage].MaxTextureImageUnits;

Now this can be const. :)  I think a bunch of the others can be too.

>  
>        if (max_index >= limit) {
>           _mesa_glsl_error(loc, state, "layout(binding = %d) for %d samplers "
> diff --git a/src/glsl/link_atomics.cpp b/src/glsl/link_atomics.cpp
> index 7f4ddaf..db9c539 100644
> --- a/src/glsl/link_atomics.cpp
> +++ b/src/glsl/link_atomics.cpp
> @@ -214,18 +214,6 @@ void
>  link_check_atomic_counter_resources(struct gl_context *ctx,
>                                      struct gl_shader_program *prog)
>  {
> -   const unsigned max_atomic_counters[] = {
> -      ctx->Const.Program[MESA_SHADER_VERTEX].MaxAtomicCounters,
> -      ctx->Const.Program[MESA_SHADER_GEOMETRY].MaxAtomicCounters,
> -      ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxAtomicCounters
> -   };
> -   STATIC_ASSERT(Elements(max_atomic_counters) == MESA_SHADER_STAGES);
> -   const unsigned max_atomic_buffers[] = {
> -      ctx->Const.Program[MESA_SHADER_VERTEX].MaxAtomicBuffers,
> -      ctx->Const.Program[MESA_SHADER_GEOMETRY].MaxAtomicBuffers,
> -      ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxAtomicBuffers
> -   };
> -   STATIC_ASSERT(Elements(max_atomic_buffers) == MESA_SHADER_STAGES);
>     unsigned num_buffers;
>     active_atomic_buffer *const abs =
>        find_active_atomic_counters(ctx, prog, &num_buffers);
> @@ -257,11 +245,11 @@ link_check_atomic_counter_resources(struct gl_context *ctx,
>  
>     /* Check that they are within the supported limits. */
>     for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
> -      if (atomic_counters[i] > max_atomic_counters[i])
> +      if (atomic_counters[i] > ctx->Const.Program[i].MaxAtomicCounters)
>           linker_error(prog, "Too many %s shader atomic counters",
>                        _mesa_shader_stage_to_string(i));
>  
> -      if (atomic_buffers[i] > max_atomic_buffers[i])
> +      if (atomic_buffers[i] > ctx->Const.Program[i].MaxAtomicBuffers)
>           linker_error(prog, "Too many %s shader atomic counter buffers",
>                        _mesa_shader_stage_to_string(i));
>     }
> diff --git a/src/glsl/link_varyings.cpp b/src/glsl/link_varyings.cpp
> index 6672b87..c925c00 100644
> --- a/src/glsl/link_varyings.cpp
> +++ b/src/glsl/link_varyings.cpp
> @@ -1249,19 +1249,9 @@ check_against_output_limit(struct gl_context *ctx,
>        }
>     }
>  
> -   unsigned max_output_components;
> -   switch (producer->Stage) {
> -   case MESA_SHADER_VERTEX:
> -      max_output_components = ctx->Const.Program[MESA_SHADER_VERTEX].MaxOutputComponents;
> -      break;
> -   case MESA_SHADER_GEOMETRY:
> -      max_output_components = ctx->Const.Program[MESA_SHADER_GEOMETRY].MaxOutputComponents;
> -      break;
> -   case MESA_SHADER_FRAGMENT:
> -   default:
> -      assert(!"Should not get here.");
> -      return false;
> -   }
> +   assert(producer->Stage != MESA_SHADER_FRAGMENT);
> +   unsigned max_output_components =
> +      ctx->Const.Program[producer->Stage].MaxOutputComponents;
>  
>     const unsigned output_components = output_vectors * 4;
>     if (output_components > max_output_components) {
> @@ -1298,19 +1288,9 @@ check_against_input_limit(struct gl_context *ctx,
>        }
>     }
>  
> -   unsigned max_input_components;
> -   switch (consumer->Stage) {
> -   case MESA_SHADER_GEOMETRY:
> -      max_input_components = ctx->Const.Program[MESA_SHADER_GEOMETRY].MaxInputComponents;
> -      break;
> -   case MESA_SHADER_FRAGMENT:
> -      max_input_components = ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxInputComponents;
> -      break;
> -   case MESA_SHADER_VERTEX:
> -   default:
> -      assert(!"Should not get here.");
> -      return false;
> -   }
> +   assert(consumer->Stage != MESA_SHADER_VERTEX);
> +   unsigned max_input_components =
> +      ctx->Const.Program[consumer->Stage].MaxInputComponents;
>  
>     const unsigned input_components = input_vectors * 4;
>     if (input_components > max_input_components) {
> diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp
> index 7efc29e..e820f0f 100644
> --- a/src/glsl/linker.cpp
> +++ b/src/glsl/linker.cpp
> @@ -1894,48 +1894,19 @@ store_fragdepth_layout(struct gl_shader_program *prog)
           ^^       ^^

Nice!

>  static void
>  check_resources(struct gl_context *ctx, struct gl_shader_program *prog)
>  {
> -   const unsigned max_samplers[] = {
> -      ctx->Const.Program[MESA_SHADER_VERTEX].MaxTextureImageUnits,
> -      ctx->Const.Program[MESA_SHADER_GEOMETRY].MaxTextureImageUnits,
> -      ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits
> -   };
> -   STATIC_ASSERT(Elements(max_samplers) == MESA_SHADER_STAGES);
> -
> -   const unsigned max_default_uniform_components[] = {
> -      ctx->Const.Program[MESA_SHADER_VERTEX].MaxUniformComponents,
> -      ctx->Const.Program[MESA_SHADER_GEOMETRY].MaxUniformComponents,
> -      ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxUniformComponents
> -   };
> -   STATIC_ASSERT(Elements(max_default_uniform_components) ==
> -                 MESA_SHADER_STAGES);
> -
> -   const unsigned max_combined_uniform_components[] = {
> -      ctx->Const.Program[MESA_SHADER_VERTEX].MaxCombinedUniformComponents,
> -      ctx->Const.Program[MESA_SHADER_GEOMETRY].MaxCombinedUniformComponents,
> -      ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxCombinedUniformComponents
> -   };
> -   STATIC_ASSERT(Elements(max_combined_uniform_components) ==
> -                 MESA_SHADER_STAGES);
> -
> -   const unsigned max_uniform_blocks[] = {
> -      ctx->Const.Program[MESA_SHADER_VERTEX].MaxUniformBlocks,
> -      ctx->Const.Program[MESA_SHADER_GEOMETRY].MaxUniformBlocks,
> -      ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxUniformBlocks
> -   };
> -   STATIC_ASSERT(Elements(max_uniform_blocks) == MESA_SHADER_STAGES);
> -
>     for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
>        struct gl_shader *sh = prog->_LinkedShaders[i];
>  
>        if (sh == NULL)
>  	 continue;
>  
> -      if (sh->num_samplers > max_samplers[i]) {
> +      if (sh->num_samplers > ctx->Const.Program[i].MaxTextureImageUnits) {
>  	 linker_error(prog, "Too many %s shader texture samplers",
>  		      _mesa_shader_stage_to_string(i));
>        }
>  
> -      if (sh->num_uniform_components > max_default_uniform_components[i]) {
> +      if (sh->num_uniform_components >
> +          ctx->Const.Program[i].MaxUniformComponents) {
>           if (ctx->Const.GLSLSkipStrictMaxUniformLimitCheck) {
>              linker_warning(prog, "Too many %s shader default uniform block "
>                             "components, but the driver will try to optimize "
> @@ -1950,7 +1921,7 @@ check_resources(struct gl_context *ctx, struct gl_shader_program *prog)
>        }
>  
>        if (sh->num_combined_uniform_components >
> -	  max_combined_uniform_components[i]) {
> +	  ctx->Const.Program[i].MaxCombinedUniformComponents) {
>           if (ctx->Const.GLSLSkipStrictMaxUniformLimitCheck) {
>              linker_warning(prog, "Too many %s shader uniform components, "
>                             "but the driver will try to optimize them out; "
> @@ -1980,11 +1951,13 @@ check_resources(struct gl_context *ctx, struct gl_shader_program *prog)
>  		      ctx->Const.MaxCombinedUniformBlocks);
>        } else {
>  	 for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
> -	    if (blocks[i] > max_uniform_blocks[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)",
>  			    _mesa_shader_stage_to_string(i),
>  			    blocks[i],
> -			    max_uniform_blocks[i]);
> +			    max_uniform_blocks);
>  	       break;
>  	    }
>  	 }
> 



More information about the mesa-dev mailing list