diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 94a43833..a270d5e8 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -298,12 +298,9 @@ bool hlsl_type_is_patch_array(const struct hlsl_type *type) || 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)) - return false; - - switch (type->e.numeric.type) + switch (type) { case HLSL_TYPE_BOOL: case HLSL_TYPE_INT: @@ -319,6 +316,12 @@ bool hlsl_type_is_integer(const struct hlsl_type *type) 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) { if (!hlsl_is_numeric_type(type)) diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 76cc51c1..f16c475b 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -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_base_type_is_integer(enum hlsl_base_type type); + struct hlsl_type *hlsl_type_clone(struct hlsl_ctx *ctx, struct hlsl_type *old, unsigned int default_majority, uint32_t modifiers); 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_major_size(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_shader(const struct hlsl_type *type); bool hlsl_type_is_patch_array(const struct hlsl_type *type); diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 8ee7d769..7e4c937e 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -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); } -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) { const struct hlsl_type *type = instr->data_type; struct vkd3d_string_buffer *string; - if (type_is_integer(type->e.numeric.type)) + if (hlsl_type_is_integer(type)) return; 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; - if (!type_is_integer(type->e.numeric.type)) + if (!hlsl_type_is_integer(type)) return arg; 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))) 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); return convert_args(ctx, params, type, loc); @@ -3676,7 +3658,7 @@ static bool intrinsic_cross(struct hlsl_ctx *ctx, enum hlsl_base_type base; 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; cast_type = hlsl_get_vector_type(ctx, base, 3); diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index fb9d5f6c..b2d67e00 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -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; } -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, 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; 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); return true; @@ -9104,17 +9097,17 @@ static bool sm4_generate_vsir_instr_expr(struct hlsl_ctx *ctx, } 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); return true; 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); return true; 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); return true; @@ -9242,7 +9235,7 @@ static bool sm4_generate_vsir_instr_expr(struct hlsl_ctx *ctx, return true; 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); generate_vsir_instr_expr_single_instr_op(ctx, program, expr, VKD3DSIH_ISHL, 0, 0, true); return true; @@ -9357,7 +9350,7 @@ static bool sm4_generate_vsir_instr_expr(struct hlsl_ctx *ctx, } 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); 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); @@ -11918,7 +11911,7 @@ static bool lower_isinf(struct hlsl_ctx *ctx, struct hlsl_ir_node *node, struct template = template_sm2; else if (hlsl_version_lt(ctx, 4, 0)) template = template_sm3; - else if (type_is_integer(rhs->data_type)) + else if (hlsl_type_is_integer(rhs->data_type)) template = template_int; else template = template_sm4;