Module: vkd3d Branch: master Commit: ea177a7750401c898699c5e3ab50f991195c550d URL: https://gitlab.winehq.org/wine/vkd3d/-/commit/ea177a7750401c898699c5e3ab50f9...
Author: Nikolay Sivov nsivov@codeweavers.com Date: Sat May 18 23:29:58 2024 +0200
vkd3d-shader/hlsl: Handle "unsigned int" type.
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com
---
Makefile.am | 1 + libs/vkd3d-shader/hlsl.l | 3 +- libs/vkd3d-shader/hlsl.y | 21 +++++++++++++ tests/hlsl/unsigned.shader_test | 66 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 90 insertions(+), 1 deletion(-)
diff --git a/Makefile.am b/Makefile.am index 7936b988..619bcdf4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -234,6 +234,7 @@ vkd3d_shader_tests = \ tests/hlsl/uav-rwstructuredbuffer.shader_test \ tests/hlsl/uav-rwtexture.shader_test \ tests/hlsl/unbounded-array-5.1.shader_test \ + tests/hlsl/unsigned.shader_test \ tests/hlsl/uniform-parameters.shader_test \ tests/hlsl/uniform-semantics.shader_test \ tests/hlsl/vector-indexing-uniform.shader_test \ diff --git a/libs/vkd3d-shader/hlsl.l b/libs/vkd3d-shader/hlsl.l index a5923d8b..91418775 100644 --- a/libs/vkd3d-shader/hlsl.l +++ b/libs/vkd3d-shader/hlsl.l @@ -49,7 +49,7 @@ static void update_location(struct hlsl_ctx *ctx, YYLTYPE *loc); RESERVED1 auto|catch|char|class|const_cast|delete|dynamic_cast|enum RESERVED2 explicit|friend|goto|long|mutable|new|operator|private|protected|public RESERVED3 reinterpret_cast|short|signed|sizeof|static_cast|template|this|throw|try -RESERVED4 typename|union|unsigned|using|virtual +RESERVED4 typename|union|using|virtual
WS [ \t] NEWLINE (\n)|(\r\n) @@ -164,6 +164,7 @@ textureCUBE {return KW_TEXTURECUBE; } TextureCubeArray {return KW_TEXTURECUBEARRAY; } true {return KW_TRUE; } typedef {return KW_TYPEDEF; } +unsigned {return KW_UNSIGNED; } uniform {return KW_UNIFORM; } vector {return KW_VECTOR; } VertexShader {return KW_VERTEXSHADER; } diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 9c1bdef9..0b742f12 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -5566,6 +5566,7 @@ static bool state_block_add_entry(struct hlsl_state_block *state_block, struct h %token KW_TEXTURECUBEARRAY %token KW_TRUE %token KW_TYPEDEF +%token KW_UNSIGNED %token KW_UNIFORM %token KW_VECTOR %token KW_VERTEXSHADER @@ -6713,6 +6714,26 @@ type_no_void: } vkd3d_free($1); } + | KW_UNSIGNED TYPE_IDENTIFIER + { + struct hlsl_type *type = hlsl_get_type(ctx->cur_scope, $2, true, true); + + if (hlsl_is_numeric_type(type) && type->e.numeric.type == HLSL_TYPE_INT) + { + if (!(type = hlsl_type_clone(ctx, type, 0, 0))) + YYABORT; + vkd3d_free((void *)type->name); + type->name = NULL; + type->e.numeric.type = HLSL_TYPE_UINT; + } + else + { + hlsl_error(ctx, &@2, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE, + "The 'unsigned' keyword can't be used with type %s.", $2); + } + + $$ = type; + } | KW_STRUCT TYPE_IDENTIFIER { $$ = hlsl_get_type(ctx->cur_scope, $2, true, true); diff --git a/tests/hlsl/unsigned.shader_test b/tests/hlsl/unsigned.shader_test new file mode 100644 index 00000000..8f7aa3dc --- /dev/null +++ b/tests/hlsl/unsigned.shader_test @@ -0,0 +1,66 @@ +[pixel shader] +unsigned int var1; +unsigned int2x2 var2; +unsigned int2 var3; +unsigned int var4[2]; + +typedef int Int; +typedef int2x2 Int2x2; +typedef int2 Int2; + +unsigned Int var5; +unsigned Int2x2 var6; +unsigned Int2 var7; + +float4 main() : sv_target +{ + return 0; +} + +[pixel shader fail(sm<6)] +unsigned uint var; + +float4 main() : sv_target +{ + return 0; +} + +[pixel shader fail(sm<6)] +unsigned uint2 var; + +float4 main() : sv_target +{ + return 0; +} + +[pixel shader fail(sm<6)] +unsigned uint2x2 var; + +float4 main() : sv_target +{ + return 0; +} + +[require] +shader model >= 4.0 + +[pixel shader] +Texture2D<unsigned int> t; + +float4 main() : sv_target +{ + return 0; +} + +[require] +shader model < 6.0 + +[pixel shader fail] +// crashes with dxc +typedef int Int[2]; +unsigned Int var; + +float4 main() : sv_target +{ + return 0; +}