vkd3d-shader/hlsl: Handle scalar conditions in ternaries.

This commit is contained in:
Zebediah Figura 2024-01-16 18:09:43 -06:00 committed by Alexandre Julliard
parent 2c8751478f
commit 11112798c8
Notes: Alexandre Julliard 2024-01-18 23:20:41 +01:00
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Henri Verbeet (@hverbeet)
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/571
2 changed files with 14 additions and 5 deletions

View File

@ -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;

View File

@ -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)