[PATCH vkd3d 6/6] vkd3d-shader/hlsl: Parse state blocks in variable definitions.

Matteo Bruni matteo.mystral at gmail.com
Sat Sep 25 07:09:05 CDT 2021


On Thu, Sep 23, 2021 at 11:47 PM Zebediah Figura
<zfigura at codeweavers.com> wrote:
>
> Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
> ---
>  Makefile.am                               |   1 +
>  libs/vkd3d-shader/hlsl.h                  |   2 +
>  libs/vkd3d-shader/hlsl.y                  |  64 +++++++-
>  tests/hlsl-state-block-syntax.shader_test | 173 ++++++++++++++++++++++
>  4 files changed, 235 insertions(+), 5 deletions(-)
>  create mode 100644 tests/hlsl-state-block-syntax.shader_test

> diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y
> index 19745e725..420156e66 100644
> --- a/libs/vkd3d-shader/hlsl.y
> +++ b/libs/vkd3d-shader/hlsl.y

> @@ -2878,6 +2909,29 @@ primary_expr:
>              if (!($$ = add_call(ctx, $1, &$3, @1)))
>                  YYABORT;
>          }
> +    | NEW_IDENTIFIER
> +        {
> +            if (ctx->in_state_block)
> +            {
> +                struct hlsl_ir_load *load;
> +                struct hlsl_ir_var *var;
> +
> +                if (!(var = hlsl_new_var(ctx, $1, ctx->builtin_types.scalar[HLSL_TYPE_INT], @1, NULL, 0, NULL)))
> +                    YYABORT;
> +                if (!(load = hlsl_new_var_load(ctx, var, @1)))
> +                    YYABORT;
> +                if (!($$ = make_list(ctx, &load->node)))
> +                {
> +                    hlsl_free_instr(&load->node);
> +                    YYABORT;
> +                }
> +            }

This leaks var on error.
Actually, does it also leak it on success? We usually store the
variables into scopes and go through the scopes when we want to free
them, but that's not the case here.

> diff --git a/tests/hlsl-state-block-syntax.shader_test b/tests/hlsl-state-block-syntax.shader_test
> new file mode 100644
> index 000000000..26853bf40
> --- /dev/null
> +++ b/tests/hlsl-state-block-syntax.shader_test
> @@ -0,0 +1,173 @@
> +[pixel shader fail]
> +sampler s
> +{
> +    foo = float;
> +};
> +
> +float4 main() : sv_target
> +{
> +    return float4(0, 0, 0, 0);
> +}
> +
> +[pixel shader fail]
> +sampler s = sampler_state
> +{
> +    foo = float;
> +};
> +
> +float4 main() : sv_target
> +{
> +    return float4(0, 0, 0, 0);
> +}
> +
> +[pixel shader fail]
> +sampler s
> +{
> +    2 = 3;
> +};
> +
> +float4 main() : sv_target
> +{
> +    return float4(0, 0, 0, 0);
> +}
> +
> +[pixel shader fail]
> +sampler s
> +{
> +    2;
> +};
> +
> +float4 main() : sv_target
> +{
> +    return float4(0, 0, 0, 0);
> +}
> +
> +[pixel shader fail]
> +sampler s
> +{
> +    foo;
> +};
> +
> +float4 main() : sv_target
> +{
> +    return float4(0, 0, 0, 0);
> +}
> +
> +[pixel shader fail]
> +sampler s
> +{
> +    foo = bar
> +};
> +
> +float4 main() : sv_target
> +{
> +    return float4(0, 0, 0, 0);
> +}
> +
> +[pixel shader fail]
> +sampler s {}
> +
> +float4 main() : sv_target
> +{
> +    return float4(0, 0, 0, 0);
> +}
> +
> +[pixel shader fail]
> +float f {} = 1;
> +
> +float4 main() : sv_target
> +{
> +    return float4(0, 0, 0, 0);
> +}
> +
> +[pixel shader fail]
> +float f = 1 {};
> +
> +float4 main() : sv_target
> +{
> +    return float4(0, 0, 0, 0);
> +}
> +
> +[pixel shader fail]
> +sampler s = sampler_state;
> +
> +float4 main() : sv_target
> +{
> +    return float4(0, 0, 0, 0);
> +}
> +
> +[pixel shader fail]
> +float f {} : register(c1);
> +
> +float4 main() : sv_target
> +{
> +    return float4(0, 0, 0, 0);
> +}
> +
> +[pixel shader fail]
> +float f
> +{
> +    foo = (sampler)2;
> +};
> +
> +float4 main() : sv_target
> +{
> +    return float4(0, 0, 0, 0);
> +}
> +
> +[pixel shader fail]
> +float f
> +{
> +    foo = (faketype)2;
> +};
> +
> +float4 main() : sv_target
> +{
> +    return float4(0, 0, 0, 0);
> +}
> +
> +[pixel shader fail]
> +float f
> +{
> +    foo = (sampler)bar;
> +};
> +
> +float4 main() : sv_target
> +{
> +    return float4(0, 0, 0, 0);
> +}
> +
> +[pixel shader fail]
> +float f
> +{
> +    foo = bar();
> +};
> +
> +float4 main() : sv_target
> +{
> +    return float4(0, 0, 0, 0);
> +}
> +
> +[pixel shader]
> +float u : register(c1) {};
> +float4 main() : sv_target
> +{
> +    float zero = 0;
> +    float a {};
> +    float b
> +    {
> +        foo = bar;
> +        foo = bar;
> +        foo = (int)2;
> +        foo = (int)bar;
> +        foo = float4(bar, baz, qux, xyzzy);
> +        foo = zero++;
> +    };
> +    float c {}, d = 1, e;
> +    struct {int a;} s {foo = bar;};
> +    return float4(0, 1, zero, 1);
> +}
> +
> +[test]
> +draw quad
> +probe all rgba (0, 1, 0, 1)

Hmm, that's something...



More information about the wine-devel mailing list