Skip to content
Snippets Groups Projects

hlsl: More ternary fixes.

Merged Elizabeth Figura requested to merge zfigura/vkd3d:mr0 into master
2 files
+ 52
12
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 40
0
@@ -4089,14 +4089,54 @@ 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_type->class > HLSL_CLASS_LAST_NUMERIC)
{
struct vkd3d_string_buffer *string;
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);
}
if (first->data_type->class <= HLSL_CLASS_LAST_NUMERIC
&& second->data_type->class <= HLSL_CLASS_LAST_NUMERIC)
{
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;
}
else if (common_type->dimx == 1 && common_type->dimy == 1)
{
common_type = hlsl_get_numeric_type(ctx, cond_type->class,
common_type->base_type, cond_type->dimx, cond_type->dimy);
}
else if (cond_type->dimx != common_type->dimx || cond_type->dimy != common_type->dimy)
{
/* This condition looks wrong but is correct.
* floatN is compatible with float1xN, but not with floatNx1. */
struct vkd3d_string_buffer *cond_string, *value_string;
cond_string = hlsl_type_to_string(ctx, cond_type);
value_string = hlsl_type_to_string(ctx, common_type);
if (cond_string && value_string)
hlsl_error(ctx, &first->loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
"Ternary condition type '%s' is not compatible with value type '%s'.",
cond_string->buffer, value_string->buffer);
hlsl_release_string_buffer(ctx, cond_string);
hlsl_release_string_buffer(ctx, value_string);
}
if (!(first = add_implicit_conversion(ctx, block, first, common_type, &first->loc)))
return false;
Loading