Module: vkd3d Branch: master Commit: 11112798c8812c507266c2be4d36494e6135ec20 URL: https://gitlab.winehq.org/wine/vkd3d/-/commit/11112798c8812c507266c2be4d3649...
Author: Zebediah Figura zfigura@codeweavers.com Date: Tue Jan 16 18:09:43 2024 -0600
vkd3d-shader/hlsl: Handle scalar conditions in ternaries.
---
libs/vkd3d-shader/hlsl.y | 13 +++++++++++-- tests/hlsl/ternary.shader_test | 6 +++--- 2 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 5552db11..9ee67914 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -4089,13 +4089,14 @@ static bool add_ternary(struct hlsl_ctx *ctx, struct hlsl_block *block, struct hlsl_ir_node *cond, struct hlsl_ir_node *first, struct hlsl_ir_node *second) { struct hlsl_ir_node *args[HLSL_MAX_OPERANDS] = {0}; + struct hlsl_type *cond_type = cond->data_type; struct hlsl_type *common_type;
- if (cond->data_type->class > HLSL_CLASS_LAST_NUMERIC) + if (cond_type->class > HLSL_CLASS_LAST_NUMERIC) { struct vkd3d_string_buffer *string;
- if ((string = hlsl_type_to_string(ctx, cond->data_type))) + if ((string = hlsl_type_to_string(ctx, cond_type))) hlsl_error(ctx, &cond->loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE, "Ternary condition type '%s' is not numeric.", string->buffer); hlsl_release_string_buffer(ctx, string); @@ -4107,6 +4108,14 @@ static bool add_ternary(struct hlsl_ctx *ctx, struct hlsl_block *block, if (!(common_type = get_common_numeric_type(ctx, first, second, &first->loc))) return false;
+ if (cond_type->dimx == 1 && cond_type->dimy == 1) + { + cond_type = hlsl_get_numeric_type(ctx, common_type->class, + HLSL_TYPE_BOOL, common_type->dimx, common_type->dimy); + if (!(cond = add_implicit_conversion(ctx, block, cond, cond_type, &cond->loc))) + return false; + } + if (!(first = add_implicit_conversion(ctx, block, first, common_type, &first->loc))) return false;
diff --git a/tests/hlsl/ternary.shader_test b/tests/hlsl/ternary.shader_test index f4fffb29..3b62513d 100644 --- a/tests/hlsl/ternary.shader_test +++ b/tests/hlsl/ternary.shader_test @@ -114,7 +114,7 @@ float4 main() : sv_target
[test] draw quad -todo probe all rgba (5.0, 6.0, 7.0, 1.0) +probe all rgba (5.0, 6.0, 7.0, 1.0)
% More restrictions are placed on the type of the first (condition) operand, @@ -265,7 +265,7 @@ draw quad probe all rgba (1.0, 2.0, 3.0, 4.0)
-[pixel shader todo] +[pixel shader]
// "scalar" can mean any 1-component numeric type. static float1x1 cond = {0}; @@ -278,7 +278,7 @@ float4 main() : sv_target }
[test] -todo draw quad +draw quad probe all rgba (5.0, 6.0, 7.0, 8.0)