[Mesa-dev] [RFC PATCH 31/56] glsl: Add builtin uniforms for default inner/outer tess levels

Marek Olšák maraeo at gmail.com
Thu Oct 2 07:24:22 PDT 2014


On Sun, Sep 21, 2014 at 3:41 AM, Chris Forbes <chrisf at ijw.co.nz> wrote:
> If the hardware needs to always have a control shader present if
> and evaluation shader is present, then the control shader will need
> these values.
> ---
>  src/glsl/builtin_variables.cpp    | 14 ++++++++++++++
>  src/mesa/program/prog_statevars.c | 24 ++++++++++++++++++++++++
>  src/mesa/program/prog_statevars.h |  3 +++
>  3 files changed, 41 insertions(+)
>
> diff --git a/src/glsl/builtin_variables.cpp b/src/glsl/builtin_variables.cpp
> index 97ef68c..0909818 100644
> --- a/src/glsl/builtin_variables.cpp
> +++ b/src/glsl/builtin_variables.cpp
> @@ -33,6 +33,14 @@ static const struct gl_builtin_uniform_element gl_NumSamples_elements[] = {
>     {NULL, {STATE_NUM_SAMPLES, 0, 0}, SWIZZLE_XXXX}
>  };
>
> +static const struct gl_builtin_uniform_element gl_DefaultTessLevelOuterMESA_elements[] = {
> +   {NULL, {STATE_INTERNAL, STATE_DEFAULT_TESS_LEVEL_OUTER, 0, 0}, SWIZZLE_XXXX}
> +};
> +
> +static const struct gl_builtin_uniform_element gl_DefaultTessLevelInnerMESA_elements[] = {
> +   {NULL, {STATE_INTERNAL, STATE_DEFAULT_TESS_LEVEL_INNER, 0, 0}, SWIZZLE_XXXX}
> +};
> +
>  static const struct gl_builtin_uniform_element gl_DepthRange_elements[] = {
>     {"near", {STATE_DEPTH_RANGE, 0, 0}, SWIZZLE_XXXX},
>     {"far", {STATE_DEPTH_RANGE, 0, 0}, SWIZZLE_YYYY},
> @@ -280,6 +288,9 @@ static const struct gl_builtin_uniform_desc _mesa_builtin_uniform_desc[] = {
>     STATEVAR(gl_CurrentAttribVertMESA),
>     STATEVAR(gl_CurrentAttribFragMESA),
>
> +   STATEVAR(gl_DefaultTessLevelOuterMESA),
> +   STATEVAR(gl_DefaultTessLevelInnerMESA),
> +
>     {NULL, NULL, 0}
>  };
>
> @@ -743,6 +754,9 @@ builtin_variable_generator::generate_uniforms()
>     add_uniform(array(vec4_t, VERT_ATTRIB_MAX), "gl_CurrentAttribVertMESA");
>     add_uniform(array(vec4_t, VARYING_SLOT_MAX), "gl_CurrentAttribFragMESA");
>
> +   add_uniform(array(float_t, 4), "gl_DefaultTessLevelOuterMESA");
> +   add_uniform(array(float_t, 2), "gl_DefaultTessLevelInnerMESA");
> +
>     if (compatibility) {
>        add_uniform(mat4_t, "gl_ModelViewMatrix");
>        add_uniform(mat4_t, "gl_ProjectionMatrix");
> diff --git a/src/mesa/program/prog_statevars.c b/src/mesa/program/prog_statevars.c
> index be5ddb1..785257b 100644
> --- a/src/mesa/program/prog_statevars.c
> +++ b/src/mesa/program/prog_statevars.c
> @@ -593,6 +593,20 @@ _mesa_fetch_state(struct gl_context *ctx, const gl_state_index state[],
>           }
>           return;
>
> +      case STATE_DEFAULT_TESS_LEVEL_OUTER:
> +         value[0] = ctx->TessCtrlProgram.patch_default_outer_level[state[2]];
> +         value[1] = 0.0F;
> +         value[2] = 0.0F;
> +         value[3] = 0.0F;

Having a single vec4 for patch_default_outer_level would be nicer.
This adds 4 vec4s to the default constant buffer, which is not nice,
but it's not a big deal.

> +         return;
> +
> +      case STATE_DEFAULT_TESS_LEVEL_INNER:
> +         value[0] = ctx->TessCtrlProgram.patch_default_inner_level[state[2]];
> +         value[1] = 0.0F;
> +         value[2] = 0.0F;
> +         value[3] = 0.0F;
> +         return;

Same as above. We need only vec4.xy for this one.

> +
>        /* XXX: make sure new tokens added here are also handled in the
>         * _mesa_program_state_flags() switch, below.
>         */
> @@ -703,6 +717,10 @@ _mesa_program_state_flags(const gl_state_index state[STATE_LENGTH])
>        case STATE_FB_WPOS_Y_TRANSFORM:
>           return _NEW_BUFFERS;
>
> +      case STATE_DEFAULT_TESS_LEVEL_OUTER:
> +      case STATE_DEFAULT_TESS_LEVEL_INNER:
> +         return _NEW_PROGRAM;

This won't catch state changes made by glPatchParameterfv.
glPatchParameterfv should add a flag and also call FLUSH_VERTICES and
the same flag should be used for these 2 state variables. Otherwise,
the constant buffer won't be updated after glPatchParameterfv is
called.

Marek


More information about the mesa-dev mailing list