diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 56736a65..1a635648 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -73,6 +73,7 @@ struct parse_variable_def struct hlsl_semantic semantic; struct hlsl_reg_reservation reg_reservation; struct parse_initializer initializer; + struct hlsl_scope *annotations; struct hlsl_type *basic_type; uint32_t modifiers; @@ -2498,6 +2499,8 @@ static void declare_var(struct hlsl_ctx *ctx, struct parse_variable_def *v) return; } + var->annotations = v->annotations; + if (constant_buffer && ctx->cur_scope == ctx->globals) { if (!(var_name = vkd3d_strdup(v->name))) @@ -2567,6 +2570,12 @@ static void declare_var(struct hlsl_ctx *ctx, struct parse_variable_def *v) hlsl_error(ctx, &v->loc, VKD3D_SHADER_ERROR_HLSL_MISSING_INITIALIZER, "Const variable \"%s\" is missing an initializer.", var->name); } + + if (var->annotations) + { + hlsl_error(ctx, &v->loc, VKD3D_SHADER_ERROR_HLSL_INVALID_SYNTAX, + "Annotations are only allowed for objects in the global scope."); + } } if ((var->storage_modifiers & HLSL_STORAGE_STATIC) && type_has_numeric_components(var->data_type) @@ -7370,7 +7379,7 @@ variables_def_typed: } variable_decl: - any_identifier arrays colon_attribute + any_identifier arrays colon_attribute annotations_opt { $$ = hlsl_alloc(ctx, sizeof(*$$)); $$->loc = @1; @@ -7378,6 +7387,7 @@ variable_decl: $$->arrays = $2; $$->semantic = $3.semantic; $$->reg_reservation = $3.reg_reservation; + $$->annotations = $4; } state_block_start: diff --git a/tests/hlsl/annotations.shader_test b/tests/hlsl/annotations.shader_test index 3f6739a5..6f805dcf 100644 --- a/tests/hlsl/annotations.shader_test +++ b/tests/hlsl/annotations.shader_test @@ -52,6 +52,19 @@ technique10 < int a = 1, b = 2; > {} // Majority modifier technique10 < row_major float3x2 m = {1, 2, 3, 4, 5, 6}; > {} +[effect] +float4 var : SEMANTIC < int a = 123; > = 123; +technique10 {} + +[effect] +float4 main() : sv_target +{ + float var < > = 0; + return 0; +} + +technique10 {} + [effect fail] // Without closing semicolon technique10 t1 < int a = 1 > {} @@ -88,3 +101,12 @@ technique10 < int a = 1, b = a; > {} [effect fail] technique10 < int a = 1; int b = a; > {} + +[effect fail] +float4 main() : sv_target +{ + float var < int a = 1; > = 0; + return 0; +} + +technique10 {}