From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- tests/hlsl/conditional.shader_test | 68 ++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+)
diff --git a/tests/hlsl/conditional.shader_test b/tests/hlsl/conditional.shader_test index d83596fcd..2d2ba2e9c 100644 --- a/tests/hlsl/conditional.shader_test +++ b/tests/hlsl/conditional.shader_test @@ -14,3 +14,71 @@ probe all rgba (0.9, 0.8, 0.7, 0.6) uniform 0 float4 0.1 0.0 0.0 0.0 draw quad probe all rgba (0.1, 0.2, 0.3, 0.4) + +[pixel shader todo] +float4 main(uniform float4 u) : sv_target +{ + [attr1] + if (u.x > 0.0) + return float4(0.1, 0.2, 0.3, 0.4); + else + return float4(0.9, 0.8, 0.7, 0.6); +} + +[pixel shader todo] +float4 main(uniform float4 u) : sv_target +{ + [flatten] + if (u.x > 0.0) + return float4(0.1, 0.2, 0.3, 0.4); + else + return float4(0.9, 0.8, 0.7, 0.6); +} + +[test] +uniform 0 float4 0.0 0.0 0.0 0.0 +todo draw quad +todo probe all rgba (0.9, 0.8, 0.7, 0.6) + +[pixel shader fail] +float4 u; + +float main() : sv_target +{ + [branch] [branch] + if (u.x > 0.0) + return float4(0.1, 0.2, 0.3, 0.4); + else + return float4(0.9, 0.8, 0.7, 0.6); +} + +[pixel shader fail] +float4 u; + +float main() : sv_target +{ + [branch] [flatten] + if (u.x > 0.0) + return float4(0.1, 0.2, 0.3, 0.4); + else + return float4(0.9, 0.8, 0.7, 0.6); +} + +% Using older profiles fails to compile with forced control flow instruction +[require] +shader model >= 3.0 + +[pixel shader todo] +float4 main(uniform float4 u) : sv_target +{ + [branch] + if (u.x > 0.0) + return float4(0.1, 0.2, 0.3, 0.4); + else + return float4(0.9, 0.8, 0.7, 0.6); +} + +[test] +uniform 0 float4 0.0 0.0 0.0 0.0 +todo draw quad +todo probe all rgba (0.9, 0.8, 0.7, 0.6)
From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- libs/vkd3d-shader/hlsl.y | 40 ++++++++++++++++++++++-------- tests/hlsl/conditional.shader_test | 4 +-- 2 files changed, 32 insertions(+), 12 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 0d9946731..d2e6891d8 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -493,11 +493,11 @@ static struct hlsl_block *create_loop(struct hlsl_ctx *ctx, enum loop_type type, || !strcmp(attr->name, "fastopt") || !strcmp(attr->name, "allow_uav_condition")) { - hlsl_fixme(ctx, loc, "Unhandled attribute %s.", attr->name); + hlsl_fixme(ctx, loc, "Unhandled attribute '%s'.", attr->name); } else { - hlsl_warning(ctx, loc, VKD3D_SHADER_ERROR_HLSL_NOT_IMPLEMENTED, "Unrecognized attribute %s.", attr->name); + hlsl_warning(ctx, loc, VKD3D_SHADER_ERROR_HLSL_NOT_IMPLEMENTED, "Unrecognized attribute '%s'.", attr->name); } }
@@ -6111,19 +6111,39 @@ jump_statement: }
selection_statement: - KW_IF '(' expr ')' if_body + attribute_list_optional KW_IF '(' expr ')' if_body { - struct hlsl_ir_node *condition = node_from_block($3); + struct hlsl_ir_node *condition = node_from_block($4); + const struct parse_attribute_list *attributes = &$1; struct hlsl_ir_node *instr; + unsigned int i; + + if (attribute_list_has_duplicates(attributes)) + hlsl_error(ctx, &@1, VKD3D_SHADER_ERROR_HLSL_INVALID_SYNTAX, "Found duplicate attribute.");
- if (!(instr = hlsl_new_if(ctx, condition, $5.then_block, $5.else_block, &@1))) + for (i = 0; i < attributes->count; ++i) { - destroy_block($5.then_block); - destroy_block($5.else_block); + const struct hlsl_attribute *attr = attributes->attrs[i]; + + if (!strcmp(attr->name, "branch") + || !strcmp(attr->name, "flatten")) + { + hlsl_fixme(ctx, &@1, "Unhandled attribute '%s'.", attr->name); + } + else + { + hlsl_warning(ctx, &@1, VKD3D_SHADER_ERROR_HLSL_NOT_IMPLEMENTED, "Unrecognized attribute '%s'.", attr->name); + } + } + + if (!(instr = hlsl_new_if(ctx, condition, $6.then_block, $6.else_block, &@2))) + { + destroy_block($6.then_block); + destroy_block($6.else_block); YYABORT; } - destroy_block($5.then_block); - destroy_block($5.else_block); + destroy_block($6.then_block); + destroy_block($6.else_block); if (condition->data_type->dimx > 1 || condition->data_type->dimy > 1) { struct vkd3d_string_buffer *string; @@ -6133,7 +6153,7 @@ selection_statement: "if condition type %s is not scalar.", string->buffer); hlsl_release_string_buffer(ctx, string); } - $$ = $3; + $$ = $4; hlsl_block_add_instr($$, instr); }
diff --git a/tests/hlsl/conditional.shader_test b/tests/hlsl/conditional.shader_test index 2d2ba2e9c..e7504c9c9 100644 --- a/tests/hlsl/conditional.shader_test +++ b/tests/hlsl/conditional.shader_test @@ -15,7 +15,7 @@ uniform 0 float4 0.1 0.0 0.0 0.0 draw quad probe all rgba (0.1, 0.2, 0.3, 0.4)
-[pixel shader todo] +[pixel shader] float4 main(uniform float4 u) : sv_target { [attr1] @@ -52,7 +52,7 @@ float main() : sv_target return float4(0.9, 0.8, 0.7, 0.6); }
-[pixel shader fail] +[pixel shader fail todo] float4 u;
float main() : sv_target
Zebediah Figura (@zfigura) commented about libs/vkd3d-shader/hlsl.y:
if (attribute_list_has_duplicates(attributes))
hlsl_error(ctx, &@1, VKD3D_SHADER_ERROR_HLSL_INVALID_SYNTAX, "Found duplicate attribute.");
if (!(instr = hlsl_new_if(ctx, condition, $5.then_block, $5.else_block, &@1)))
for (i = 0; i < attributes->count; ++i) {
destroy_block($5.then_block);
destroy_block($5.else_block);
const struct hlsl_attribute *attr = attributes->attrs[i];
if (!strcmp(attr->name, "branch")
|| !strcmp(attr->name, "flatten"))
{
hlsl_fixme(ctx, &@1, "Unhandled attribute '%s'.", attr->name);
}
Does this need to be a hlsl_fixme()? Do we know that these affect code semantics?
Zebediah Figura (@zfigura) commented about libs/vkd3d-shader/hlsl.y:
if (!(instr = hlsl_new_if(ctx, condition, $5.then_block, $5.else_block, &@1)))
for (i = 0; i < attributes->count; ++i) {
destroy_block($5.then_block);
destroy_block($5.else_block);
const struct hlsl_attribute *attr = attributes->attrs[i];
if (!strcmp(attr->name, "branch")
|| !strcmp(attr->name, "flatten"))
{
hlsl_fixme(ctx, &@1, "Unhandled attribute '%s'.", attr->name);
}
else
{
hlsl_warning(ctx, &@1, VKD3D_SHADER_ERROR_HLSL_NOT_IMPLEMENTED, "Unrecognized attribute '%s'.", attr->name);
I missed this before when it came up for loops, but I think we need to invent a new constant for this; VKD3D_SHADER_ERROR_HLSL_NOT_IMPLEMENTED is an error ID, not a warning ID.
On Sun Aug 13 21:36:36 2023 +0000, Zebediah Figura wrote:
Does this need to be a hlsl_fixme()? Do we know that these affect code semantics?
It's possible warning is enough, for example writing to RW buffer in conditional branches, and using [flatten] produces an error, explicitly saying that side effects are disallowed.