mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-01-28 13:05:02 -08:00
vkd3d-shader/hlsl: Parse the asuint() intrinsic.
This commit is contained in:
parent
eb70f1aeb5
commit
2d4d2e1244
Notes:
Alexandre Julliard
2022-10-18 00:13:00 +02: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/25
@ -1642,6 +1642,7 @@ const char *debug_hlsl_expr_op(enum hlsl_ir_expr_op op)
|
||||
[HLSL_OP1_NEG] = "-",
|
||||
[HLSL_OP1_NRM] = "nrm",
|
||||
[HLSL_OP1_RCP] = "rcp",
|
||||
[HLSL_OP1_REINTERPRET] = "reinterpret",
|
||||
[HLSL_OP1_ROUND] = "round",
|
||||
[HLSL_OP1_RSQ] = "rsq",
|
||||
[HLSL_OP1_SAT] = "sat",
|
||||
|
@ -312,6 +312,7 @@ enum hlsl_ir_expr_op
|
||||
HLSL_OP1_NEG,
|
||||
HLSL_OP1_NRM,
|
||||
HLSL_OP1_RCP,
|
||||
HLSL_OP1_REINTERPRET,
|
||||
HLSL_OP1_ROUND,
|
||||
HLSL_OP1_RSQ,
|
||||
HLSL_OP1_SAT,
|
||||
|
@ -2053,6 +2053,50 @@ static bool intrinsic_abs(struct hlsl_ctx *ctx,
|
||||
return !!add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_ABS, params->args[0], loc);
|
||||
}
|
||||
|
||||
/* Find the type corresponding to the given source type, with the same
|
||||
* dimensions but a different base type. */
|
||||
static struct hlsl_type *convert_numeric_type(const struct hlsl_ctx *ctx,
|
||||
const struct hlsl_type *type, enum hlsl_base_type base_type)
|
||||
{
|
||||
return hlsl_get_numeric_type(ctx, type->type, base_type, type->dimx, type->dimy);
|
||||
}
|
||||
|
||||
static bool intrinsic_asuint(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;
|
||||
|
||||
if (params->args_count != 1 && params->args_count != 3)
|
||||
{
|
||||
hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_WRONG_PARAMETER_COUNT,
|
||||
"Wrong number of arguments to function 'asuint': expected 1 or 3, but got %u.", params->args_count);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (params->args_count == 3)
|
||||
{
|
||||
hlsl_fixme(ctx, loc, "Double-to-integer conversion.");
|
||||
return false;
|
||||
}
|
||||
|
||||
data_type = params->args[0]->data_type;
|
||||
if (data_type->base_type == HLSL_TYPE_BOOL || data_type->base_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 type for argument 0 of asuint(): 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_UINT);
|
||||
|
||||
operands[0] = params->args[0];
|
||||
return add_expr(ctx, params->instrs, HLSL_OP1_REINTERPRET, operands, data_type, loc);
|
||||
}
|
||||
|
||||
static bool intrinsic_clamp(struct hlsl_ctx *ctx,
|
||||
const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
|
||||
{
|
||||
@ -2361,6 +2405,7 @@ intrinsic_functions[] =
|
||||
{
|
||||
/* Note: these entries should be kept in alphabetical order. */
|
||||
{"abs", 1, true, intrinsic_abs},
|
||||
{"asuint", -1, true, intrinsic_asuint},
|
||||
{"clamp", 3, true, intrinsic_clamp},
|
||||
{"cross", 2, true, intrinsic_cross},
|
||||
{"dot", 2, true, intrinsic_dot},
|
||||
|
Loading…
x
Reference in New Issue
Block a user