vkd3d-shader/hlsl: Allow annotations on global variables.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
This commit is contained in:
Nikolay Sivov 2024-07-09 14:58:50 +02:00 committed by Henri Verbeet
parent ba0fec4c51
commit 958117df2f
Notes: Henri Verbeet 2024-07-23 15:42:44 +02:00
Approved-by: Elizabeth Figura (@zfigura)
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/937
2 changed files with 33 additions and 1 deletions

View File

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

View File

@ -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 {}