mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-04-13 05:43:18 -07:00
vkd3d-shader/hlsl: Use common hlsl_type_is_integer() and hlsl_base_type_is_integer() helpers.
This commit is contained in:
committed by
Henri Verbeet
parent
bd34ec1fb3
commit
3cf4a4e95e
Notes:
Henri Verbeet
2025-03-06 17:32:40 +01:00
Approved-by: Francisco Casas (@fcasas) Approved-by: Henri Verbeet (@hverbeet) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1387
@ -298,12 +298,9 @@ bool hlsl_type_is_patch_array(const struct hlsl_type *type)
|
|||||||
|| type->e.array.array_type == HLSL_ARRAY_PATCH_OUTPUT);
|
|| type->e.array.array_type == HLSL_ARRAY_PATCH_OUTPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hlsl_type_is_integer(const struct hlsl_type *type)
|
bool hlsl_base_type_is_integer(enum hlsl_base_type type)
|
||||||
{
|
{
|
||||||
if (!hlsl_is_numeric_type(type))
|
switch (type)
|
||||||
return false;
|
|
||||||
|
|
||||||
switch (type->e.numeric.type)
|
|
||||||
{
|
{
|
||||||
case HLSL_TYPE_BOOL:
|
case HLSL_TYPE_BOOL:
|
||||||
case HLSL_TYPE_INT:
|
case HLSL_TYPE_INT:
|
||||||
@ -319,6 +316,12 @@ bool hlsl_type_is_integer(const struct hlsl_type *type)
|
|||||||
vkd3d_unreachable();
|
vkd3d_unreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool hlsl_type_is_integer(const struct hlsl_type *type)
|
||||||
|
{
|
||||||
|
VKD3D_ASSERT(hlsl_is_numeric_type(type));
|
||||||
|
return hlsl_base_type_is_integer(type->e.numeric.type);
|
||||||
|
}
|
||||||
|
|
||||||
bool hlsl_type_is_floating_point(const struct hlsl_type *type)
|
bool hlsl_type_is_floating_point(const struct hlsl_type *type)
|
||||||
{
|
{
|
||||||
if (!hlsl_is_numeric_type(type))
|
if (!hlsl_is_numeric_type(type))
|
||||||
|
@ -1696,6 +1696,8 @@ void hlsl_pop_scope(struct hlsl_ctx *ctx);
|
|||||||
|
|
||||||
bool hlsl_scope_add_type(struct hlsl_scope *scope, struct hlsl_type *type);
|
bool hlsl_scope_add_type(struct hlsl_scope *scope, struct hlsl_type *type);
|
||||||
|
|
||||||
|
bool hlsl_base_type_is_integer(enum hlsl_base_type type);
|
||||||
|
|
||||||
struct hlsl_type *hlsl_type_clone(struct hlsl_ctx *ctx, struct hlsl_type *old,
|
struct hlsl_type *hlsl_type_clone(struct hlsl_ctx *ctx, struct hlsl_type *old,
|
||||||
unsigned int default_majority, uint32_t modifiers);
|
unsigned int default_majority, uint32_t modifiers);
|
||||||
unsigned int hlsl_type_component_count(const struct hlsl_type *type);
|
unsigned int hlsl_type_component_count(const struct hlsl_type *type);
|
||||||
@ -1710,6 +1712,7 @@ bool hlsl_type_is_row_major(const struct hlsl_type *type);
|
|||||||
unsigned int hlsl_type_minor_size(const struct hlsl_type *type);
|
unsigned int hlsl_type_minor_size(const struct hlsl_type *type);
|
||||||
unsigned int hlsl_type_major_size(const struct hlsl_type *type);
|
unsigned int hlsl_type_major_size(const struct hlsl_type *type);
|
||||||
unsigned int hlsl_type_element_count(const struct hlsl_type *type);
|
unsigned int hlsl_type_element_count(const struct hlsl_type *type);
|
||||||
|
bool hlsl_type_is_integer(const struct hlsl_type *type);
|
||||||
bool hlsl_type_is_resource(const struct hlsl_type *type);
|
bool hlsl_type_is_resource(const struct hlsl_type *type);
|
||||||
bool hlsl_type_is_shader(const struct hlsl_type *type);
|
bool hlsl_type_is_shader(const struct hlsl_type *type);
|
||||||
bool hlsl_type_is_patch_array(const struct hlsl_type *type);
|
bool hlsl_type_is_patch_array(const struct hlsl_type *type);
|
||||||
|
@ -1616,30 +1616,12 @@ static struct hlsl_ir_node *add_expr(struct hlsl_ctx *ctx, struct hlsl_block *bl
|
|||||||
return hlsl_block_add_expr(ctx, block, op, operands, type, loc);
|
return hlsl_block_add_expr(ctx, block, op, operands, type, loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool type_is_integer(enum hlsl_base_type type)
|
|
||||||
{
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case HLSL_TYPE_BOOL:
|
|
||||||
case HLSL_TYPE_INT:
|
|
||||||
case HLSL_TYPE_UINT:
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case HLSL_TYPE_DOUBLE:
|
|
||||||
case HLSL_TYPE_FLOAT:
|
|
||||||
case HLSL_TYPE_HALF:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
vkd3d_unreachable();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void check_integer_type(struct hlsl_ctx *ctx, const struct hlsl_ir_node *instr)
|
static void check_integer_type(struct hlsl_ctx *ctx, const struct hlsl_ir_node *instr)
|
||||||
{
|
{
|
||||||
const struct hlsl_type *type = instr->data_type;
|
const struct hlsl_type *type = instr->data_type;
|
||||||
struct vkd3d_string_buffer *string;
|
struct vkd3d_string_buffer *string;
|
||||||
|
|
||||||
if (type_is_integer(type->e.numeric.type))
|
if (hlsl_type_is_integer(type))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ((string = hlsl_type_to_string(ctx, type)))
|
if ((string = hlsl_type_to_string(ctx, type)))
|
||||||
@ -3161,7 +3143,7 @@ static struct hlsl_ir_node *intrinsic_float_convert_arg(struct hlsl_ctx *ctx,
|
|||||||
{
|
{
|
||||||
struct hlsl_type *type = arg->data_type;
|
struct hlsl_type *type = arg->data_type;
|
||||||
|
|
||||||
if (!type_is_integer(type->e.numeric.type))
|
if (!hlsl_type_is_integer(type))
|
||||||
return arg;
|
return arg;
|
||||||
|
|
||||||
type = hlsl_get_numeric_type(ctx, type->class, HLSL_TYPE_FLOAT, type->e.numeric.dimx, type->e.numeric.dimy);
|
type = hlsl_get_numeric_type(ctx, type->class, HLSL_TYPE_FLOAT, type->e.numeric.dimx, type->e.numeric.dimy);
|
||||||
@ -3253,7 +3235,7 @@ static bool elementwise_intrinsic_float_convert_args(struct hlsl_ctx *ctx,
|
|||||||
|
|
||||||
if (!(type = elementwise_intrinsic_get_common_type(ctx, params, loc)))
|
if (!(type = elementwise_intrinsic_get_common_type(ctx, params, loc)))
|
||||||
return false;
|
return false;
|
||||||
if (type_is_integer(type->e.numeric.type))
|
if (hlsl_type_is_integer(type))
|
||||||
type = hlsl_get_numeric_type(ctx, type->class, HLSL_TYPE_FLOAT, type->e.numeric.dimx, type->e.numeric.dimy);
|
type = hlsl_get_numeric_type(ctx, type->class, HLSL_TYPE_FLOAT, type->e.numeric.dimx, type->e.numeric.dimy);
|
||||||
|
|
||||||
return convert_args(ctx, params, type, loc);
|
return convert_args(ctx, params, type, loc);
|
||||||
@ -3676,7 +3658,7 @@ static bool intrinsic_cross(struct hlsl_ctx *ctx,
|
|||||||
enum hlsl_base_type base;
|
enum hlsl_base_type base;
|
||||||
|
|
||||||
base = expr_common_base_type(arg1->data_type->e.numeric.type, arg2->data_type->e.numeric.type);
|
base = expr_common_base_type(arg1->data_type->e.numeric.type, arg2->data_type->e.numeric.type);
|
||||||
if (type_is_integer(base))
|
if (hlsl_base_type_is_integer(base))
|
||||||
base = HLSL_TYPE_FLOAT;
|
base = HLSL_TYPE_FLOAT;
|
||||||
|
|
||||||
cast_type = hlsl_get_vector_type(ctx, base, 3);
|
cast_type = hlsl_get_vector_type(ctx, base, 3);
|
||||||
|
@ -8723,13 +8723,6 @@ static bool type_is_float(const struct hlsl_type *type)
|
|||||||
return type->e.numeric.type == HLSL_TYPE_FLOAT || type->e.numeric.type == HLSL_TYPE_HALF;
|
return type->e.numeric.type == HLSL_TYPE_FLOAT || type->e.numeric.type == HLSL_TYPE_HALF;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool type_is_integer(const struct hlsl_type *type)
|
|
||||||
{
|
|
||||||
return type->e.numeric.type == HLSL_TYPE_BOOL
|
|
||||||
|| type->e.numeric.type == HLSL_TYPE_INT
|
|
||||||
|| type->e.numeric.type == HLSL_TYPE_UINT;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void sm4_generate_vsir_cast_from_bool(struct hlsl_ctx *ctx, struct vsir_program *program,
|
static void sm4_generate_vsir_cast_from_bool(struct hlsl_ctx *ctx, struct vsir_program *program,
|
||||||
const struct hlsl_ir_expr *expr, uint32_t bits)
|
const struct hlsl_ir_expr *expr, uint32_t bits)
|
||||||
{
|
{
|
||||||
@ -8935,7 +8928,7 @@ static bool sm4_generate_vsir_instr_expr(struct hlsl_ctx *ctx,
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
case HLSL_OP1_BIT_NOT:
|
case HLSL_OP1_BIT_NOT:
|
||||||
VKD3D_ASSERT(type_is_integer(dst_type));
|
VKD3D_ASSERT(hlsl_type_is_integer(dst_type));
|
||||||
generate_vsir_instr_expr_single_instr_op(ctx, program, expr, VKD3DSIH_NOT, 0, 0, true);
|
generate_vsir_instr_expr_single_instr_op(ctx, program, expr, VKD3DSIH_NOT, 0, 0, true);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@ -9104,17 +9097,17 @@ static bool sm4_generate_vsir_instr_expr(struct hlsl_ctx *ctx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
case HLSL_OP2_BIT_AND:
|
case HLSL_OP2_BIT_AND:
|
||||||
VKD3D_ASSERT(type_is_integer(dst_type));
|
VKD3D_ASSERT(hlsl_type_is_integer(dst_type));
|
||||||
generate_vsir_instr_expr_single_instr_op(ctx, program, expr, VKD3DSIH_AND, 0, 0, true);
|
generate_vsir_instr_expr_single_instr_op(ctx, program, expr, VKD3DSIH_AND, 0, 0, true);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case HLSL_OP2_BIT_OR:
|
case HLSL_OP2_BIT_OR:
|
||||||
VKD3D_ASSERT(type_is_integer(dst_type));
|
VKD3D_ASSERT(hlsl_type_is_integer(dst_type));
|
||||||
generate_vsir_instr_expr_single_instr_op(ctx, program, expr, VKD3DSIH_OR, 0, 0, true);
|
generate_vsir_instr_expr_single_instr_op(ctx, program, expr, VKD3DSIH_OR, 0, 0, true);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case HLSL_OP2_BIT_XOR:
|
case HLSL_OP2_BIT_XOR:
|
||||||
VKD3D_ASSERT(type_is_integer(dst_type));
|
VKD3D_ASSERT(hlsl_type_is_integer(dst_type));
|
||||||
generate_vsir_instr_expr_single_instr_op(ctx, program, expr, VKD3DSIH_XOR, 0, 0, true);
|
generate_vsir_instr_expr_single_instr_op(ctx, program, expr, VKD3DSIH_XOR, 0, 0, true);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@ -9242,7 +9235,7 @@ static bool sm4_generate_vsir_instr_expr(struct hlsl_ctx *ctx,
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
case HLSL_OP2_LSHIFT:
|
case HLSL_OP2_LSHIFT:
|
||||||
VKD3D_ASSERT(type_is_integer(dst_type));
|
VKD3D_ASSERT(hlsl_type_is_integer(dst_type));
|
||||||
VKD3D_ASSERT(dst_type->e.numeric.type != HLSL_TYPE_BOOL);
|
VKD3D_ASSERT(dst_type->e.numeric.type != HLSL_TYPE_BOOL);
|
||||||
generate_vsir_instr_expr_single_instr_op(ctx, program, expr, VKD3DSIH_ISHL, 0, 0, true);
|
generate_vsir_instr_expr_single_instr_op(ctx, program, expr, VKD3DSIH_ISHL, 0, 0, true);
|
||||||
return true;
|
return true;
|
||||||
@ -9357,7 +9350,7 @@ static bool sm4_generate_vsir_instr_expr(struct hlsl_ctx *ctx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
case HLSL_OP2_RSHIFT:
|
case HLSL_OP2_RSHIFT:
|
||||||
VKD3D_ASSERT(type_is_integer(dst_type));
|
VKD3D_ASSERT(hlsl_type_is_integer(dst_type));
|
||||||
VKD3D_ASSERT(dst_type->e.numeric.type != HLSL_TYPE_BOOL);
|
VKD3D_ASSERT(dst_type->e.numeric.type != HLSL_TYPE_BOOL);
|
||||||
generate_vsir_instr_expr_single_instr_op(ctx, program, expr,
|
generate_vsir_instr_expr_single_instr_op(ctx, program, expr,
|
||||||
dst_type->e.numeric.type == HLSL_TYPE_INT ? VKD3DSIH_ISHR : VKD3DSIH_USHR, 0, 0, true);
|
dst_type->e.numeric.type == HLSL_TYPE_INT ? VKD3DSIH_ISHR : VKD3DSIH_USHR, 0, 0, true);
|
||||||
@ -11918,7 +11911,7 @@ static bool lower_isinf(struct hlsl_ctx *ctx, struct hlsl_ir_node *node, struct
|
|||||||
template = template_sm2;
|
template = template_sm2;
|
||||||
else if (hlsl_version_lt(ctx, 4, 0))
|
else if (hlsl_version_lt(ctx, 4, 0))
|
||||||
template = template_sm3;
|
template = template_sm3;
|
||||||
else if (type_is_integer(rhs->data_type))
|
else if (hlsl_type_is_integer(rhs->data_type))
|
||||||
template = template_int;
|
template = template_int;
|
||||||
else
|
else
|
||||||
template = template_sm4;
|
template = template_sm4;
|
||||||
|
Reference in New Issue
Block a user