[Mesa-stable] [Mesa-dev] [PATCH 2/5] glsl: Optionally lower TES gl_PatchVerticesIn to a uniform.

Alejandro Piñeiro apinheiro at igalia.com
Wed Jun 8 17:45:16 UTC 2016


On 02/06/16 23:09, Kenneth Graunke wrote:
> i965 has no special hardware for this, so we need to pass this value in
> as a uniform (unless the TES is linked against a TCS, in which case the
> linker can just replace this with a constant).
>
> Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
> Cc: mesa-stable at lists.freedesktop.org
> ---
>  src/compiler/glsl/linker.cpp      | 20 +++++++++++++++++---
>  src/mesa/main/mtypes.h            |  1 +
>  src/mesa/program/prog_statevars.c |  7 +++++++
>  src/mesa/program/prog_statevars.h |  1 +
>  4 files changed, 26 insertions(+), 3 deletions(-)
>
> diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp
> index 9e65590..7c7dbfe 100644
> --- a/src/compiler/glsl/linker.cpp
> +++ b/src/compiler/glsl/linker.cpp
> @@ -72,6 +72,7 @@
>  #include "ir.h"
>  #include "program.h"
>  #include "program/hash_table.h"
> +#include "program/prog_instruction.h"
>  #include "linker.h"
>  #include "link_varyings.h"
>  #include "ir_optimization.h"
> @@ -2485,7 +2486,7 @@ resize_tes_inputs(struct gl_context *ctx,
>        ir->accept(&input_resize_visitor);
>     }
>  
> -   if (tcs) {
> +   if (tcs || ctx->Const.LowerTESPatchVerticesIn) {
>        /* Convert the gl_PatchVerticesIn system value into a constant, since
>         * the value is known at this point.

Now this comment became obsolete as can be converted to a constant or a
uniform. Perhaps it would be better to just remove the comment.

>         */
> @@ -2494,9 +2495,22 @@ resize_tes_inputs(struct gl_context *ctx,
>           if (var && var->data.mode == ir_var_system_value &&
>               var->data.location == SYSTEM_VALUE_VERTICES_IN) {
>              void *mem_ctx = ralloc_parent(var);
> -            var->data.mode = ir_var_auto;
>              var->data.location = 0;
> -            var->constant_value = new(mem_ctx) ir_constant(num_vertices);
> +            var->data.explicit_location = false;

Nitpick: With this change you are also changing slightly the option that
was present before (use a constant) in addition to add the option to
lower to an uniform. Not sure if it is worth to be mentioned though,
feel free to ignore.

> +            if (tcs) {
> +               var->data.mode = ir_var_auto;
> +               var->constant_value = new(mem_ctx) ir_constant(num_vertices);
> +            } else {
> +               var->data.mode = ir_var_uniform;
> +               var->data.how_declared = ir_var_hidden;
> +               var->allocate_state_slots(1);
> +               ir_state_slot *slot0 = &var->get_state_slots()[0];
> +               slot0->swizzle = SWIZZLE_XXXX;
> +               slot0->tokens[0] = STATE_INTERNAL;
> +               slot0->tokens[1] = STATE_TES_PATCH_VERTICES_IN;
> +               for (int i = 2; i < STATE_LENGTH; i++)
> +                  slot0->tokens[i] = 0;
> +            }
>           }
>        }
>     }
> diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
> index d0f3760..8970274 100644
> --- a/src/mesa/main/mtypes.h
> +++ b/src/mesa/main/mtypes.h
> @@ -3762,6 +3762,7 @@ struct gl_constants
>     GLuint MaxTessPatchComponents;
>     GLuint MaxTessControlTotalOutputComponents;
>     bool LowerTessLevel; /**< Lower gl_TessLevel* from float[n] to vecn? */
> +   bool LowerTESPatchVerticesIn; /**< Lower gl_PatchVerticesIn to a uniform */
>     bool PrimitiveRestartForPatches;
>     bool LowerCsDerivedVariables;    /**< Lower gl_GlobalInvocationID and
>                                       *   gl_LocalInvocationIndex based on
> diff --git a/src/mesa/program/prog_statevars.c b/src/mesa/program/prog_statevars.c
> index 27ff333..23e3015 100644
> --- a/src/mesa/program/prog_statevars.c
> +++ b/src/mesa/program/prog_statevars.c
> @@ -598,6 +598,13 @@ _mesa_fetch_state(struct gl_context *ctx, const gl_state_index state[],
>           }
>           return;
>  
> +      case STATE_TES_PATCH_VERTICES_IN:
> +         if (ctx->TessCtrlProgram._Current)
> +            val[0].i = ctx->TessCtrlProgram._Current->VerticesOut;
> +         else
> +            val[0].i = ctx->TessCtrlProgram.patch_vertices;
> +         return;
> +
>        /* XXX: make sure new tokens added here are also handled in the 
>         * _mesa_program_state_flags() switch, below.
>         */
> diff --git a/src/mesa/program/prog_statevars.h b/src/mesa/program/prog_statevars.h
> index 6333e63..4b27527 100644
> --- a/src/mesa/program/prog_statevars.h
> +++ b/src/mesa/program/prog_statevars.h
> @@ -128,6 +128,7 @@ typedef enum gl_state_index_ {
>     STATE_PT_BIAS,               /**< Pixel transfer RGBA bias */
>     STATE_FB_SIZE,               /**< (width-1, height-1, 0, 0) */
>     STATE_FB_WPOS_Y_TRANSFORM,   /**< (1, 0, -1, height) if a FBO is bound, (-1, height, 1, 0) otherwise */
> +   STATE_TES_PATCH_VERTICES_IN, /**< gl_PatchVerticesIn for TES (integer) */
>     STATE_INTERNAL_DRIVER	/* first available state index for drivers (must be last) */
>  } gl_state_index;
>  

In any case:
Reviewed-by: Alejandro Piñeiro <apinheiro at igalia.com>



More information about the mesa-stable mailing list