vkd3d-shader/hlsl: Parse state blocks in variable definitions.

Signed-off-by: Zebediah Figura <zfigura@codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni@codeweavers.com>
Signed-off-by: Giovanni Mascellani <gmascellani@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2021-09-27 20:51:42 -05:00 committed by Alexandre Julliard
parent 04bb6c395f
commit efab7c82a5
4 changed files with 223 additions and 7 deletions

View File

@ -74,6 +74,7 @@ vkd3d_shader_tests = \
tests/hlsl-return-implicit-conversion.shader_test \
tests/hlsl-return-void.shader_test \
tests/hlsl-shape.shader_test \
tests/hlsl-state-block-syntax.shader_test \
tests/hlsl-static-initializer.shader_test \
tests/hlsl-storage-qualifiers.shader_test \
tests/hlsl-struct-assignment.shader_test \

View File

@ -469,6 +469,8 @@ struct hlsl_ctx
size_t count, size;
} constant_defs;
uint32_t temp_count;
uint32_t in_state_block : 1;
};
enum hlsl_error_level

View File

@ -2558,6 +2558,23 @@ variable_decl:
$$->reg_reservation = $3.reg_reservation;
}
state:
any_identifier '=' expr ';'
{
vkd3d_free($1);
hlsl_free_instr_list($3);
}
state_block_start:
%empty
{
ctx->in_state_block = 1;
}
state_block:
%empty
| state_block state
variable_def:
variable_decl
| variable_decl '=' complex_initializer
@ -2565,6 +2582,11 @@ variable_def:
$$ = $1;
$$->initializer = $3;
}
| variable_decl '{' state_block_start state_block '}'
{
$$ = $1;
ctx->in_state_block = 0;
}
arrays:
%empty
@ -2861,13 +2883,10 @@ primary_expr:
hlsl_error(ctx, @1, VKD3D_SHADER_ERROR_HLSL_NOT_DEFINED, "Variable \"%s\" is not defined.", $1);
YYABORT;
}
if ((load = hlsl_new_var_load(ctx, var, @1)))
{
if (!($$ = make_list(ctx, &load->node)))
YYABORT;
}
else
$$ = NULL;
if (!(load = hlsl_new_var_load(ctx, var, @1)))
YYABORT;
if (!($$ = make_list(ctx, &load->node)))
YYABORT;
}
| '(' expr ')'
{
@ -2878,6 +2897,27 @@ 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_synthetic_var(ctx, "<state-block-expr>",
ctx->builtin_types.scalar[HLSL_TYPE_INT], @1)))
YYABORT;
if (!(load = hlsl_new_var_load(ctx, var, @1)))
YYABORT;
if (!($$ = make_list(ctx, &load->node)))
YYABORT;
}
else
{
hlsl_error(ctx, @1, VKD3D_SHADER_ERROR_HLSL_NOT_DEFINED, "Identifier \"%s\" is not declared.\n", $1);
YYABORT;
}
}
postfix_expr:
primary_expr

View File

@ -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)