Module: vkd3d Branch: master Commit: 26784672d82506c214374344ee575b6e4cd55c23 URL: https://gitlab.winehq.org/wine/vkd3d/-/commit/26784672d82506c214374344ee575b...
Author: Nikolay Sivov nsivov@codeweavers.com Date: Sat Oct 28 21:30:29 2023 +0200
vkd3d-shader: Check loop [unroll] attribute for conflict with other attributes.
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com
---
libs/vkd3d-shader/hlsl.y | 24 ++++++++++++++++++++++++ tests/hlsl/loop.shader_test | 8 ++++---- 2 files changed, 28 insertions(+), 4 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 5fd140fb..9a1be71e 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -514,6 +514,28 @@ static void resolve_loop_continue(struct hlsl_ctx *ctx, struct hlsl_block *block } }
+static void check_loop_attributes(struct hlsl_ctx *ctx, const struct parse_attribute_list *attributes, + const struct vkd3d_shader_location *loc) +{ + bool has_unroll = false, has_loop = false, has_fastopt = false; + unsigned int i; + + for (i = 0; i < attributes->count; ++i) + { + const char *name = attributes->attrs[i]->name; + + has_loop |= !strcmp(name, "loop"); + has_unroll |= !strcmp(name, "unroll"); + has_fastopt |= !strcmp(name, "fastopt"); + } + + if (has_unroll && has_loop) + hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_SYNTAX, "Unroll attribute can't be used with 'loop' attribute."); + + if (has_unroll && has_fastopt) + hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_SYNTAX, "Unroll attribute can't be used with 'fastopt' attribute."); +} + static struct hlsl_block *create_loop(struct hlsl_ctx *ctx, enum loop_type type, const struct parse_attribute_list *attributes, struct hlsl_block *init, struct hlsl_block *cond, struct hlsl_block *iter, struct hlsl_block *body, const struct vkd3d_shader_location *loc) @@ -524,6 +546,8 @@ static struct hlsl_block *create_loop(struct hlsl_ctx *ctx, enum loop_type type, if (attribute_list_has_duplicates(attributes)) hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_SYNTAX, "Found duplicate attribute.");
+ check_loop_attributes(ctx, attributes, loc); + /* Ignore unroll(0) attribute, and any invalid attribute. */ for (i = 0; i < attributes->count; ++i) { diff --git a/tests/hlsl/loop.shader_test b/tests/hlsl/loop.shader_test index 3d515c9d..6a5240a7 100644 --- a/tests/hlsl/loop.shader_test +++ b/tests/hlsl/loop.shader_test @@ -158,7 +158,7 @@ todo draw quad probe all rgba (10.0, 10.0, 10.0, 10.0)
% unroll can't be used with fastopt or loop -[pixel shader fail todo] +[pixel shader fail] float4 main() : sv_target { float ret = 0.0; @@ -171,7 +171,7 @@ float4 main() : sv_target return ret; }
-[pixel shader fail todo] +[pixel shader fail] float4 main() : sv_target { float ret = 0.0; @@ -184,7 +184,7 @@ float4 main() : sv_target return ret; }
-[pixel shader fail todo] +[pixel shader fail] float4 main() : sv_target { float ret = 0.0; @@ -199,7 +199,7 @@ float4 main() : sv_target return ret; }
-[pixel shader fail todo] +[pixel shader fail] float4 main() : sv_target { float ret = 0.0;