mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-01-28 13:05:02 -08:00
vkd3d-shader/hlsl: Partially implement trunc().
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
This commit is contained in:
parent
5366ca7001
commit
4b3707aeb4
Notes:
Alexandre Julliard
2023-04-28 22:03:23 +02:00
Approved-by: Giovanni Mascellani (@giomasce) Approved-by: Zebediah Figura (@zfigura) Approved-by: Henri Verbeet (@hverbeet) Approved-by: Alexandre Julliard (@julliard) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/161
@ -123,6 +123,7 @@ vkd3d_shader_tests = \
|
||||
tests/hlsl-struct-semantics.shader_test \
|
||||
tests/hlsl-ternary.shader_test \
|
||||
tests/hlsl-transpose.shader_test \
|
||||
tests/hlsl-trunc.shader_test \
|
||||
tests/hlsl-type-names.shader_test \
|
||||
tests/hlsl-vector-indexing.shader_test \
|
||||
tests/hlsl-vector-indexing-uniform.shader_test \
|
||||
|
@ -2295,6 +2295,7 @@ const char *debug_hlsl_expr_op(enum hlsl_ir_expr_op op)
|
||||
[HLSL_OP1_SIN] = "sin",
|
||||
[HLSL_OP1_SIN_REDUCED] = "sin_reduced",
|
||||
[HLSL_OP1_SQRT] = "sqrt",
|
||||
[HLSL_OP1_TRUNC] = "trunc",
|
||||
|
||||
[HLSL_OP2_ADD] = "+",
|
||||
[HLSL_OP2_BIT_AND] = "&",
|
||||
|
@ -492,6 +492,7 @@ enum hlsl_ir_expr_op
|
||||
HLSL_OP1_SIN,
|
||||
HLSL_OP1_SIN_REDUCED, /* Reduced range [-pi, pi] */
|
||||
HLSL_OP1_SQRT,
|
||||
HLSL_OP1_TRUNC,
|
||||
|
||||
HLSL_OP2_ADD,
|
||||
HLSL_OP2_BIT_AND,
|
||||
|
@ -3384,6 +3384,17 @@ static bool intrinsic_transpose(struct hlsl_ctx *ctx,
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool intrinsic_trunc(struct hlsl_ctx *ctx,
|
||||
const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
|
||||
{
|
||||
struct hlsl_ir_node *arg;
|
||||
|
||||
if (!(arg = intrinsic_float_convert_arg(ctx, params, params->args[0], loc)))
|
||||
return false;
|
||||
|
||||
return !!add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_TRUNC, arg, loc);
|
||||
}
|
||||
|
||||
static const struct intrinsic_function
|
||||
{
|
||||
const char *name;
|
||||
@ -3433,6 +3444,7 @@ intrinsic_functions[] =
|
||||
{"tex2D", -1, false, intrinsic_tex2D},
|
||||
{"tex3D", -1, false, intrinsic_tex3D},
|
||||
{"transpose", 1, true, intrinsic_transpose},
|
||||
{"trunc", 1, true, intrinsic_trunc},
|
||||
};
|
||||
|
||||
static int intrinsic_function_name_compare(const void *a, const void *b)
|
||||
|
@ -4031,6 +4031,11 @@ static void write_sm4_expr(struct hlsl_ctx *ctx,
|
||||
write_sm4_unary_op(buffer, VKD3D_SM4_OP_SQRT, &expr->node, arg1, 0);
|
||||
break;
|
||||
|
||||
case HLSL_OP1_TRUNC:
|
||||
assert(type_is_float(dst_type));
|
||||
write_sm4_unary_op(buffer, VKD3D_SM4_OP_ROUND_Z, &expr->node, arg1, 0);
|
||||
break;
|
||||
|
||||
case HLSL_OP2_ADD:
|
||||
switch (dst_type->base_type)
|
||||
{
|
||||
|
44
tests/hlsl-trunc.shader_test
Normal file
44
tests/hlsl-trunc.shader_test
Normal file
@ -0,0 +1,44 @@
|
||||
[pixel shader]
|
||||
float4 main(uniform float4 u) : sv_target
|
||||
{
|
||||
return trunc(u);
|
||||
}
|
||||
|
||||
[test]
|
||||
uniform 0 float4 -0.5 6.5 7.5 3.4
|
||||
draw quad
|
||||
probe all rgba (0.0, 6.0, 7.0, 3.0)
|
||||
uniform 0 float4 -1.5 6.5 7.5 3.4
|
||||
draw quad
|
||||
probe all rgba (-1.0, 6.0, 7.0, 3.0)
|
||||
|
||||
[pixel shader]
|
||||
float4 main(uniform float4 u) : sv_target
|
||||
{
|
||||
float a = trunc(u.r);
|
||||
int2 b = trunc(u.gb);
|
||||
float4 res = float4(b, a, u.a);
|
||||
return trunc(res);
|
||||
}
|
||||
|
||||
[test]
|
||||
uniform 0 float4 -0.5 6.5 7.5 3.4
|
||||
draw quad
|
||||
probe all rgba (6.0, 7.0, 0.0, 3.0)
|
||||
|
||||
[require]
|
||||
shader model >= 4.0
|
||||
|
||||
[pixel shader]
|
||||
float4 main(uniform int4 u) : sv_target
|
||||
{
|
||||
float a = trunc(u.r);
|
||||
int2 b = trunc(u.gb);
|
||||
float4 res = float4(b, a, u.a);
|
||||
return trunc(res);
|
||||
}
|
||||
|
||||
[test]
|
||||
uniform 0 int4 -1 6 7 3
|
||||
draw quad
|
||||
probe all rgba (6.0, 7.0, -1.0, 3.0)
|
Loading…
x
Reference in New Issue
Block a user