Signed-off-by: Zebediah Figura zfigura@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/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..420156e66 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 @@ -2827,7 +2849,10 @@ primary_expr: init_node(&c->node, HLSL_IR_CONSTANT, ctx->builtin_types.scalar[HLSL_TYPE_FLOAT], @1); c->value[0].f = $1; if (!($$ = make_list(ctx, &c->node))) + { + hlsl_free_instr(&c->node); YYABORT; + } } | C_INTEGER { @@ -2838,7 +2863,10 @@ primary_expr: init_node(&c->node, HLSL_IR_CONSTANT, ctx->builtin_types.scalar[HLSL_TYPE_INT], @1); c->value[0].i = $1; if (!($$ = make_list(ctx, &c->node))) + { + hlsl_free_instr(&c->node); YYABORT; + } } | boolean { @@ -2849,7 +2877,10 @@ primary_expr: init_node(&c->node, HLSL_IR_CONSTANT, ctx->builtin_types.scalar[HLSL_TYPE_BOOL], @1); c->value[0].b = $1; if (!($$ = make_list(ctx, &c->node))) + { + hlsl_free_instr(&c->node); YYABORT; + } } | VAR_IDENTIFIER { @@ -2861,13 +2892,13 @@ 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 (!(load = hlsl_new_var_load(ctx, var, @1))) + YYABORT; + if (!($$ = make_list(ctx, &load->node))) { - if (!($$ = make_list(ctx, &load->node))) - YYABORT; + hlsl_free_instr(&load->node); + YYABORT; } - else - $$ = NULL; } | '(' expr ')' { @@ -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; + } + } + 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)