From 5ea946aa90e0de4a4851c98bfeb4e5bcc6825bb7 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Sun, 27 Oct 2024 14:31:20 +0100 Subject: [PATCH] vkd3d-shader/hlsl: Accept multiple colon-separated attributes. Signed-off-by: Nikolay Sivov --- libs/vkd3d-shader/hlsl.y | 47 ++++++++++++------- tests/hlsl/cbuffer.shader_test | 2 +- tests/hlsl/entry-point-semantics.shader_test | 12 ++++- .../register-reservations-numeric.shader_test | 23 +++++++-- tests/hlsl/uniform-semantics.shader_test | 14 ++++++ 5 files changed, 75 insertions(+), 23 deletions(-) diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index dcbba46e..e57769f5 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -53,7 +53,7 @@ struct parse_parameter struct parse_initializer initializer; }; -struct parse_colon_attribute +struct parse_colon_attributes { struct hlsl_semantic semantic; struct hlsl_reg_reservation reg_reservation; @@ -6490,7 +6490,7 @@ static void validate_uav_type(struct hlsl_ctx *ctx, enum hlsl_sampler_dim dim, struct parse_if_body if_body; enum parse_assign_op assign_op; struct hlsl_reg_reservation reg_reservation; - struct parse_colon_attribute colon_attribute; + struct parse_colon_attributes colon_attributes; struct hlsl_semantic semantic; enum hlsl_buffer_type buffer_type; enum hlsl_sampler_dim sampler_dim; @@ -6687,7 +6687,7 @@ static void validate_uav_type(struct hlsl_ctx *ctx, enum hlsl_sampler_dim dim, %type buffer_type -%type colon_attribute +%type colon_attributes %type field %type fields_list @@ -6875,7 +6875,7 @@ effect_group: } buffer_declaration: - var_modifiers buffer_type any_identifier colon_attribute annotations_opt + var_modifiers buffer_type any_identifier colon_attributes annotations_opt { if ($4.semantic.name) hlsl_error(ctx, &@4, VKD3D_SHADER_ERROR_HLSL_INVALID_SEMANTIC, "Semantics are not allowed on buffers."); @@ -7200,7 +7200,7 @@ func_declaration: func_prototype_no_attrs: /* var_modifiers is necessary to avoid shift/reduce conflicts. */ - var_modifiers type var_identifier '(' parameters ')' colon_attribute + var_modifiers type var_identifier '(' parameters ')' colon_attributes { uint32_t modifiers = $1; struct hlsl_ir_var *var; @@ -7377,28 +7377,39 @@ var_identifier: VAR_IDENTIFIER | NEW_IDENTIFIER -colon_attribute: +colon_attributes: %empty { $$.semantic = (struct hlsl_semantic){0}; $$.reg_reservation.reg_type = 0; $$.reg_reservation.offset_type = 0; } - | semantic + | colon_attributes semantic { - $$.semantic = $1; - $$.reg_reservation.reg_type = 0; - $$.reg_reservation.offset_type = 0; + hlsl_cleanup_semantic(&$$.semantic); + $$.semantic = $2; } - | register_reservation + | colon_attributes register_reservation { - $$.semantic = (struct hlsl_semantic){0}; - $$.reg_reservation = $1; + if ($$.reg_reservation.reg_type) + hlsl_fixme(ctx, &@2, "Multiple register() reservations."); + + $$.reg_reservation.reg_type = $2.reg_type; + $$.reg_reservation.reg_index = $2.reg_index; + $$.reg_reservation.reg_space = $2.reg_space; } - | packoffset_reservation + | colon_attributes packoffset_reservation { - $$.semantic = (struct hlsl_semantic){0}; - $$.reg_reservation = $1; + if (ctx->cur_buffer == ctx->globals_buffer) + { + hlsl_error(ctx, &@2, VKD3D_SHADER_ERROR_HLSL_INVALID_RESERVATION, + "The packoffset() reservation is only allowed within 'cbuffer' blocks."); + } + else + { + $$.reg_reservation.offset_type = $2.offset_type; + $$.reg_reservation.offset_index = $2.offset_index; + } } semantic: @@ -7594,7 +7605,7 @@ parameter: } parameter_decl: - var_modifiers type_no_void any_identifier arrays colon_attribute + var_modifiers type_no_void any_identifier arrays colon_attributes { uint32_t modifiers = $1; struct hlsl_type *type; @@ -8095,7 +8106,7 @@ variables_def_typed: } variable_decl: - any_identifier arrays colon_attribute annotations_opt + any_identifier arrays colon_attributes annotations_opt { $$ = hlsl_alloc(ctx, sizeof(*$$)); $$->loc = @1; diff --git a/tests/hlsl/cbuffer.shader_test b/tests/hlsl/cbuffer.shader_test index 43db2c47..0b12cd7d 100644 --- a/tests/hlsl/cbuffer.shader_test +++ b/tests/hlsl/cbuffer.shader_test @@ -639,7 +639,7 @@ float4 main() : sv_target return tex.Sample(sam, float2(0, 0)); } -[pixel shader todo] +[pixel shader] Texture2D tex; cbuffer buffer diff --git a/tests/hlsl/entry-point-semantics.shader_test b/tests/hlsl/entry-point-semantics.shader_test index b1c27acc..ccf9f423 100644 --- a/tests/hlsl/entry-point-semantics.shader_test +++ b/tests/hlsl/entry-point-semantics.shader_test @@ -39,6 +39,16 @@ float4 main(float tex : texcoord) : sv_target todo(msl) draw quad probe (0, 0) rgba (0.2, 0.2, 0.2, 0.2) +[pixel shader fail(sm>=6)] +float4 main(float tex : texcoord) : semantic : sv_target +{ + return tex; +} + +[test] +todo(msl) draw quad +probe (0, 0) rgba (0.2, 0.2, 0.2, 0.2) + [pixel shader] float4 main(float tex : texcoord) : sv_target @@ -76,7 +86,7 @@ float4 main(in float2 arr[2]) : sv_target [pixel shader] struct apple { - float3 tp[4] : TEXCOORD0; + float3 tp[4] : BOGUS : TEXCOORD0; }; float4 main(in apple a) : sv_target diff --git a/tests/hlsl/register-reservations-numeric.shader_test b/tests/hlsl/register-reservations-numeric.shader_test index 19ff5628..e1593dfa 100644 --- a/tests/hlsl/register-reservations-numeric.shader_test +++ b/tests/hlsl/register-reservations-numeric.shader_test @@ -224,7 +224,7 @@ uniform 4 float 101 todo(msl) draw quad probe (0, 0) rgba (100, 100, 100, 100) -[pixel shader todo] +[pixel shader] cbuffer c { float a : packoffset(c1); @@ -241,9 +241,26 @@ float4 main() : sv_target uniform 0 float 200 uniform 4 float 201 uniform 8 float 202 -todo(sm<6) draw quad -todo(sm<6) probe (0,0) rgba (201.0, 202.0, 0.0, 0.0) +draw quad +probe (0,0) rgba (201.0, 202.0, 0.0, 0.0) +[pixel shader] +cbuffer c +{ + float a : packoffset(c1) : packoffset(c2); +} + +float4 main() : sv_target +{ + return float4(a, 0, 0, 0); +} + +[test] +uniform 0 float 201 +uniform 4 float 202 +uniform 8 float 203 +draw quad +probe (0,0) rgba (203.0, 0.0, 0.0, 0.0) [pixel shader fail(sm<4)] int k : register(i0); // register(cX) is also required. diff --git a/tests/hlsl/uniform-semantics.shader_test b/tests/hlsl/uniform-semantics.shader_test index 3e625b26..c0cac17a 100644 --- a/tests/hlsl/uniform-semantics.shader_test +++ b/tests/hlsl/uniform-semantics.shader_test @@ -26,3 +26,17 @@ float4 main() : sv_target uniform 0 float4 4.0 5.0 6.0 7.0 todo(msl) draw quad probe (0, 0) rgba (4.0, 5.0, 4.0, 5.0) + + +[pixel shader] +float a : SEMANTIC : ANOTHER_SEMANTIC; + +float4 main() : sv_target +{ + return a; +} + +[test] +uniform 0 float 3.5 +todo(msl) draw quad +probe (0, 0) rgba (3.5, 3.5, 3.5, 3.5)