vkd3d-shader/hlsl: Add a helper to check for a numeric type.

This commit is contained in:
Nikolay Sivov 2023-11-13 02:05:50 +01:00 committed by Alexandre Julliard
parent 76eb0adf03
commit 88caf87789
Notes: Alexandre Julliard 2023-11-15 22:59:15 +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/472
5 changed files with 25 additions and 20 deletions

View File

@ -220,7 +220,7 @@ bool hlsl_type_is_resource(const struct hlsl_type *type)
* resources, since for both their data types span across a single regset. */
static enum hlsl_regset type_get_regset(const struct hlsl_type *type)
{
if (type->class <= HLSL_CLASS_LAST_NUMERIC)
if (hlsl_is_numeric_type(type))
return HLSL_REGSET_NUMERIC;
if (type->class == HLSL_CLASS_ARRAY)

View File

@ -1105,6 +1105,11 @@ static inline struct hlsl_type *hlsl_get_numeric_type(const struct hlsl_ctx *ctx
return hlsl_get_matrix_type(ctx, base_type, dimx, dimy);
}
static inline bool hlsl_is_numeric_type(const struct hlsl_type *type)
{
return type->class <= HLSL_CLASS_LAST_NUMERIC;
}
static inline unsigned int hlsl_sampler_dim_count(enum hlsl_sampler_dim dim)
{
switch (dim)

View File

@ -211,7 +211,7 @@ static bool hlsl_types_are_componentwise_equal(struct hlsl_ctx *ctx, struct hlsl
return true;
}
static bool type_contains_only_numerics(struct hlsl_type *type)
static bool type_contains_only_numerics(const struct hlsl_type *type)
{
unsigned int i;
@ -226,12 +226,12 @@ static bool type_contains_only_numerics(struct hlsl_type *type)
}
return true;
}
return type->class <= HLSL_CLASS_LAST_NUMERIC;
return hlsl_is_numeric_type(type);
}
static bool explicit_compatible_data_types(struct hlsl_ctx *ctx, struct hlsl_type *src, struct hlsl_type *dst)
{
if (src->class <= HLSL_CLASS_LAST_NUMERIC && src->dimx == 1 && src->dimy == 1 && type_contains_only_numerics(dst))
if (hlsl_is_numeric_type(src) && src->dimx == 1 && src->dimy == 1 && type_contains_only_numerics(dst))
return true;
if (src->class == HLSL_CLASS_MATRIX && dst->class == HLSL_CLASS_MATRIX
@ -251,10 +251,10 @@ static bool explicit_compatible_data_types(struct hlsl_ctx *ctx, struct hlsl_typ
static bool implicit_compatible_data_types(struct hlsl_ctx *ctx, struct hlsl_type *src, struct hlsl_type *dst)
{
if ((src->class <= HLSL_CLASS_LAST_NUMERIC) != (dst->class <= HLSL_CLASS_LAST_NUMERIC))
if (hlsl_is_numeric_type(src) != hlsl_is_numeric_type(dst))
return false;
if (src->class <= HLSL_CLASS_LAST_NUMERIC)
if (hlsl_is_numeric_type(src))
{
/* Scalar vars can be converted to any other numeric data type */
if (src->dimx == 1 && src->dimy == 1)
@ -311,7 +311,7 @@ static struct hlsl_ir_node *add_cast(struct hlsl_ctx *ctx, struct hlsl_block *bl
struct hlsl_ir_var *var;
unsigned int dst_idx;
broadcast = src_type->class <= HLSL_CLASS_LAST_NUMERIC && src_type->dimx == 1 && src_type->dimy == 1;
broadcast = hlsl_is_numeric_type(src_type) && src_type->dimx == 1 && src_type->dimy == 1;
matrix_cast = !broadcast && dst_comp_count != src_comp_count
&& src_type->class == HLSL_CLASS_MATRIX && dst_type->class == HLSL_CLASS_MATRIX;
assert(src_comp_count >= dst_comp_count || broadcast);
@ -1292,7 +1292,7 @@ static enum hlsl_base_type expr_common_base_type(enum hlsl_base_type t1, enum hl
static bool expr_common_shape(struct hlsl_ctx *ctx, struct hlsl_type *t1, struct hlsl_type *t2,
const struct vkd3d_shader_location *loc, enum hlsl_type_class *type, unsigned int *dimx, unsigned int *dimy)
{
if (t1->class > HLSL_CLASS_LAST_NUMERIC)
if (!hlsl_is_numeric_type(t1))
{
struct vkd3d_string_buffer *string;
@ -1303,7 +1303,7 @@ static bool expr_common_shape(struct hlsl_ctx *ctx, struct hlsl_type *t1, struct
return false;
}
if (t2->class > HLSL_CLASS_LAST_NUMERIC)
if (!hlsl_is_numeric_type(t2))
{
struct vkd3d_string_buffer *string;
@ -1775,7 +1775,7 @@ static struct hlsl_ir_node *add_assignment(struct hlsl_ctx *ctx, struct hlsl_blo
return NULL;
}
if (lhs_type->class <= HLSL_CLASS_LAST_NUMERIC)
if (hlsl_is_numeric_type(lhs_type))
writemask = (1 << lhs_type->dimx) - 1;
if (!(rhs = add_implicit_conversion(ctx, block, rhs, lhs_type, &rhs->loc)))
@ -2005,7 +2005,7 @@ static bool type_has_object_components(struct hlsl_type *type, bool must_be_in_s
static bool type_has_numeric_components(struct hlsl_type *type)
{
if (type->class <= HLSL_CLASS_LAST_NUMERIC)
if (hlsl_is_numeric_type(type))
return true;
if (type->class == HLSL_CLASS_ARRAY)
return type_has_numeric_components(type->e.array.type);
@ -3926,7 +3926,7 @@ static struct hlsl_block *add_call(struct hlsl_ctx *ctx, const char *name,
for (i = 0; i < args->args_count; ++i)
{
if (args->args[i]->data_type->class > HLSL_CLASS_LAST_NUMERIC)
if (!hlsl_is_numeric_type(args->args[i]->data_type))
{
struct vkd3d_string_buffer *string;
@ -6776,7 +6776,7 @@ postfix_expr:
YYABORT;
$$ = $1;
}
else if (node->data_type->class <= HLSL_CLASS_LAST_NUMERIC)
else if (hlsl_is_numeric_type(node->data_type))
{
struct hlsl_ir_node *swizzle;
@ -6819,7 +6819,7 @@ postfix_expr:
free_parse_initializer(&$4);
YYABORT;
}
if ($2->class > HLSL_CLASS_LAST_NUMERIC)
if (!hlsl_is_numeric_type($2))
{
struct vkd3d_string_buffer *string;

View File

@ -229,7 +229,7 @@ static void prepend_uniform_copy(struct hlsl_ctx *ctx, struct hlsl_block *block,
static void validate_field_semantic(struct hlsl_ctx *ctx, struct hlsl_struct_field *field)
{
if (!field->semantic.name && hlsl_get_multiarray_element_type(field->type)->class <= HLSL_CLASS_LAST_NUMERIC
if (!field->semantic.name && hlsl_is_numeric_type(hlsl_get_multiarray_element_type(field->type))
&& !field->semantic.reported_missing)
{
hlsl_error(ctx, &field->loc, VKD3D_SHADER_ERROR_HLSL_MISSING_SEMANTIC,
@ -339,7 +339,7 @@ static void prepend_input_copy(struct hlsl_ctx *ctx, struct hlsl_block *block, s
struct hlsl_ir_node *c;
unsigned int i;
if (type->class > HLSL_CLASS_LAST_NUMERIC)
if (!hlsl_is_numeric_type(type))
{
struct vkd3d_string_buffer *string;
if (!(string = hlsl_type_to_string(ctx, type)))
@ -481,7 +481,7 @@ static void append_output_copy(struct hlsl_ctx *ctx, struct hlsl_block *block, s
struct hlsl_ir_node *c;
unsigned int i;
if (type->class > HLSL_CLASS_LAST_NUMERIC)
if (!hlsl_is_numeric_type(type))
{
struct vkd3d_string_buffer *string;
if (!(string = hlsl_type_to_string(ctx, type)))
@ -3942,7 +3942,7 @@ static void allocate_const_registers_recurse(struct hlsl_ctx *ctx,
constant->reg = allocate_numeric_registers_for_type(ctx, allocator, 1, UINT_MAX, type);
TRACE("Allocated constant @%u to %s.\n", instr->index, debug_register('c', constant->reg, type));
assert(type->class <= HLSL_CLASS_LAST_NUMERIC);
assert(hlsl_is_numeric_type(type));
assert(type->dimy == 1);
assert(constant->reg.writemask);
@ -4634,7 +4634,7 @@ struct hlsl_reg hlsl_reg_from_deref(struct hlsl_ctx *ctx, const struct hlsl_dere
unsigned int offset = hlsl_offset_from_deref_safe(ctx, deref);
assert(deref->data_type);
assert(deref->data_type->class <= HLSL_CLASS_LAST_NUMERIC);
assert(hlsl_is_numeric_type(deref->data_type));
ret.id += offset / 4;

View File

@ -5411,7 +5411,7 @@ static void write_sm4_load(const struct tpf_writer *tpf, const struct hlsl_ir_lo
sm4_dst_from_node(&instr.dsts[0], &load->node);
instr.dst_count = 1;
assert(type->class <= HLSL_CLASS_LAST_NUMERIC);
assert(hlsl_is_numeric_type(type));
if (type->base_type == HLSL_TYPE_BOOL && var_is_user_input(tpf->ctx, load->src.var))
{
struct hlsl_constant_value value;