vkd3d-shader/hlsl: Support sin() intrinsic.

This commit is contained in:
Francisco Casas 2023-01-13 15:22:13 -03:00 committed by Alexandre Julliard
parent b65c450101
commit 3239ea5ff1
Notes: Alexandre Julliard 2023-01-19 22:45:36 +01: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/62
3 changed files with 43 additions and 3 deletions

View File

@ -2736,6 +2736,17 @@ static bool intrinsic_saturate(struct hlsl_ctx *ctx,
return !!add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_SAT, arg, loc);
}
static bool intrinsic_sin(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_SIN, arg, loc);
}
/* smoothstep(a, b, x) = p^2 (3 - 2p), where p = saturate((x - a)/(b - a)) */
static bool intrinsic_smoothstep(struct hlsl_ctx *ctx,
const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
@ -2880,6 +2891,7 @@ intrinsic_functions[] =
{"pow", 2, true, intrinsic_pow},
{"round", 1, true, intrinsic_round},
{"saturate", 1, true, intrinsic_saturate},
{"sin", 1, true, intrinsic_sin},
{"smoothstep", 3, true, intrinsic_smoothstep},
{"transpose", 1, true, intrinsic_transpose},
};

View File

@ -1319,6 +1319,29 @@ static void write_sm4_unary_op(struct vkd3d_bytecode_buffer *buffer, enum vkd3d_
write_sm4_instruction(buffer, &instr);
}
static void write_sm4_unary_op_with_two_destinations(struct vkd3d_bytecode_buffer *buffer,
enum vkd3d_sm4_opcode opcode, const struct hlsl_ir_node *dst, unsigned dst_idx,
const struct hlsl_ir_node *src)
{
struct sm4_instruction instr;
memset(&instr, 0, sizeof(instr));
instr.opcode = opcode;
assert(dst_idx < ARRAY_SIZE(instr.dsts));
sm4_dst_from_node(&instr.dsts[dst_idx], dst);
assert(1 - dst_idx >= 0);
instr.dsts[1 - dst_idx].reg.type = VKD3D_SM4_RT_NULL;
instr.dsts[1 - dst_idx].reg.dim = VKD3D_SM4_DIMENSION_NONE;
instr.dsts[1 - dst_idx].reg.idx_count = 0;
instr.dst_count = 2;
sm4_src_from_node(&instr.srcs[0], src, instr.dsts[dst_idx].writemask);
instr.src_count = 1;
write_sm4_instruction(buffer, &instr);
}
static void write_sm4_binary_op(struct vkd3d_bytecode_buffer *buffer, enum vkd3d_sm4_opcode opcode,
const struct hlsl_ir_node *dst, const struct hlsl_ir_node *src1, const struct hlsl_ir_node *src2)
{
@ -1738,6 +1761,11 @@ static void write_sm4_expr(struct hlsl_ctx *ctx,
&expr->node, arg1, 0);
break;
case HLSL_OP1_SIN:
assert(type_is_float(dst_type));
write_sm4_unary_op_with_two_destinations(buffer, VKD3D_SM4_OP_SINCOS, &expr->node, 0, arg1);
break;
case HLSL_OP1_SQRT:
assert(type_is_float(dst_type));
write_sm4_unary_op(buffer, VKD3D_SM4_OP_SQRT, &expr->node, arg1, 0);

View File

@ -31,7 +31,7 @@ probe (14, 0) rgba ( 0.99060736, 0.13673722, 0.0, 0.0) 1024
probe (15, 0) rgba ( 0.65028784, -0.75968791, 0.0, 0.0) 1024
[pixel shader todo]
[pixel shader]
uniform float4 a;
float4 main() : sv_target
@ -41,8 +41,8 @@ float4 main() : sv_target
[test]
uniform 0 float4 0.0 0.52359877 2.61799387 3.14159265
todo draw quad
todo probe all rgba (0.0, 500.0, 500.0, 0.0)
draw quad
probe all rgba (0.0, 500.0, 500.0, 0.0)
[pixel shader todo]