From e0ef45c0a37b70f7e0ecc49605410512a6180bcd Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Sun, 25 Feb 2024 02:51:58 +0100 Subject: [PATCH] vkd3d-shader: Parse a 'single' modifier. Signed-off-by: Nikolay Sivov --- libs/vkd3d-shader/hlsl.h | 1 + libs/vkd3d-shader/hlsl.y | 2 ++ tests/hlsl/cbuffer.shader_test | 60 ++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 1fb8b834..9781dd33 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -374,6 +374,7 @@ struct hlsl_attribute #define HLSL_STORAGE_CENTROID 0x00004000 #define HLSL_STORAGE_NOPERSPECTIVE 0x00008000 #define HLSL_STORAGE_LINEAR 0x00010000 +#define HLSL_MODIFIER_SINGLE 0x00020000 #define HLSL_TYPE_MODIFIERS_MASK (HLSL_MODIFIER_PRECISE | HLSL_MODIFIER_VOLATILE | \ HLSL_MODIFIER_CONST | HLSL_MODIFIER_ROW_MAJOR | \ diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index fda6f597..ec8b3d22 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -6874,6 +6874,8 @@ var_modifiers: { if (!strcmp($1, "precise")) $$ = add_modifiers(ctx, $2, HLSL_MODIFIER_PRECISE, &@1); + else if (!strcmp($1, "single")) + $$ = add_modifiers(ctx, $2, HLSL_MODIFIER_SINGLE, &@1); else hlsl_error(ctx, &@1, VKD3D_SHADER_ERROR_HLSL_UNKNOWN_MODIFIER, "Unknown modifier %s.", debugstr_a($1)); diff --git a/tests/hlsl/cbuffer.shader_test b/tests/hlsl/cbuffer.shader_test index bb0937ed..517fe636 100644 --- a/tests/hlsl/cbuffer.shader_test +++ b/tests/hlsl/cbuffer.shader_test @@ -29,11 +29,71 @@ float4 main() : sv_target return foo; } +[pixel shader fail(sm>=6)] +// The 'single' modifier is not a keyword. It's meaningful only for fx_5_0. +single cbuffer cb +{ + float4 single; +}; + +float4 main() : sv_target +{ + return single; +} + [test] uniform 0 float4 1.0 2.0 3.0 4.0 draw quad probe all rgba (1.0, 2.0, 3.0, 4.0) +[pixel shader fail(sm>=6)] +// 'single' modifier is usable when there is a variable with the same name +cbuffer cb +{ + float4 single; +}; + +single cbuffer cb2 +{ + float4 var; +}; + +float4 main() : sv_target +{ + return single; +} + +[test] +uniform 0 float4 1.0 2.0 3.0 4.0 +draw quad +probe all rgba (1.0, 2.0, 3.0, 4.0) + +[pixel shader] +typedef float4 single; +single var; + +float4 main() : sv_target +{ + return var; +} + +[test] +uniform 0 float4 1.0 2.0 3.0 4.0 +draw quad +probe all rgba (1.0, 2.0, 3.0, 4.0) + +[pixel shader fail] +typedef float4 single; +single cbuffer cb +{ + float4 var; +}; + +float4 main() : sv_target +{ + return var; +} + % SM1 buffer offset allocation follows different rules than SM4. % Those would have to be tested separately. [require]