vkd3d-shader/hlsl: Implement the asint() intrinsic.

This commit is contained in:
Victor Chiletto
2024-07-05 14:59:19 -03:00
committed by Henri Verbeet
parent 91dce79227
commit a0de05f0b4
Notes: Henri Verbeet 2024-07-24 16:16:07 +02:00
Approved-by: Elizabeth Figura (@zfigura)
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/953
3 changed files with 85 additions and 0 deletions

View File

@@ -3299,6 +3299,29 @@ static bool intrinsic_asfloat(struct hlsl_ctx *ctx,
return add_expr(ctx, params->instrs, HLSL_OP1_REINTERPRET, operands, data_type, loc);
}
static bool intrinsic_asint(struct hlsl_ctx *ctx,
const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
{
struct hlsl_ir_node *operands[HLSL_MAX_OPERANDS] = {0};
struct hlsl_type *data_type;
data_type = params->args[0]->data_type;
if (data_type->e.numeric.type == HLSL_TYPE_BOOL || data_type->e.numeric.type == HLSL_TYPE_DOUBLE)
{
struct vkd3d_string_buffer *string;
if ((string = hlsl_type_to_string(ctx, data_type)))
hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
"Wrong argument type of asint(): expected 'int', 'uint', 'float', or 'half', but got '%s'.",
string->buffer);
hlsl_release_string_buffer(ctx, string);
}
data_type = convert_numeric_type(ctx, data_type, HLSL_TYPE_INT);
operands[0] = params->args[0];
return add_expr(ctx, params->instrs, HLSL_OP1_REINTERPRET, operands, data_type, loc);
}
static bool intrinsic_asuint(struct hlsl_ctx *ctx,
const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
{
@@ -4825,6 +4848,7 @@ intrinsic_functions[] =
{"any", 1, true, intrinsic_any},
{"asfloat", 1, true, intrinsic_asfloat},
{"asin", 1, true, intrinsic_asin},
{"asint", 1, true, intrinsic_asint},
{"asuint", -1, true, intrinsic_asuint},
{"atan", 1, true, intrinsic_atan},
{"atan2", 2, true, intrinsic_atan2},