Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com
Il 28/09/21 03:51, Zebediah Figura ha scritto:
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
Makefile.am | 1 + libs/vkd3d-shader/hlsl.h | 2 + libs/vkd3d-shader/hlsl.y | 54 ++++++- tests/hlsl-state-block-syntax.shader_test | 173 ++++++++++++++++++++++ 4 files changed, 223 insertions(+), 7 deletions(-) create mode 100644 tests/hlsl-state-block-syntax.shader_test
diff --git a/Makefile.am b/Makefile.am index 4a2bf8e18..bc33e0f60 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 \
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 27afeedd4..abc870f4f 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -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
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 19745e725..8ad892f9e 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -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
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)