From: Giovanni Mascellani Subject: [PATCH vkd3d v3 3/6] vkd3d-shader/hlsl: Write SM4 unsigned multiplication instructions. Message-Id: <20220127140945.636918-3-gmascellani@codeweavers.com> Date: Thu, 27 Jan 2022 15:09:42 +0100 In-Reply-To: <20220127140945.636918-1-gmascellani@codeweavers.com> References: <20220127140945.636918-1-gmascellani@codeweavers.com> Signed-off-by: Giovanni Mascellani --- v2: * Rename to write_sm4_binary_op_with_two_destinations(). * Fix writemask mapping (before it always used the writemask from destination 1, but of course it has to use dst_idx). v3: * Rebased onto master. --- libs/vkd3d-shader/hlsl_sm4.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/libs/vkd3d-shader/hlsl_sm4.c b/libs/vkd3d-shader/hlsl_sm4.c index 4eebd583..3ab60c26 100644 --- a/libs/vkd3d-shader/hlsl_sm4.c +++ b/libs/vkd3d-shader/hlsl_sm4.c @@ -786,7 +786,7 @@ struct sm4_instruction { struct sm4_register reg; unsigned int writemask; - } dsts[1]; + } dsts[2]; unsigned int dst_count; struct sm4_src_register @@ -1266,6 +1266,31 @@ static void write_sm4_binary_op(struct vkd3d_bytecode_buffer *buffer, enum vkd3d write_sm4_instruction(buffer, &instr); } +static void write_sm4_binary_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 *src1, const struct hlsl_ir_node *src2) +{ + struct sm4_instruction instr; + unsigned int writemask; + + memset(&instr, 0, sizeof(instr)); + instr.opcode = opcode; + + 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; + sm4_register_from_node(&instr.dsts[dst_idx].reg, &instr.dsts[dst_idx].writemask, NULL, dst); + instr.dst_count = 2; + + sm4_register_from_node(&instr.srcs[0].reg, &writemask, &instr.srcs[0].swizzle_type, src1); + instr.srcs[0].swizzle = hlsl_map_swizzle(hlsl_swizzle_from_writemask(writemask), instr.dsts[dst_idx].writemask); + sm4_register_from_node(&instr.srcs[1].reg, &writemask, &instr.srcs[1].swizzle_type, src2); + instr.srcs[1].swizzle = hlsl_map_swizzle(hlsl_swizzle_from_writemask(writemask), instr.dsts[dst_idx].writemask); + instr.src_count = 2; + + write_sm4_instruction(buffer, &instr); +} + static void write_sm4_constant(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *buffer, const struct hlsl_ir_constant *constant) { @@ -1578,6 +1603,13 @@ static void write_sm4_expr(struct hlsl_ctx *ctx, write_sm4_binary_op(buffer, VKD3D_SM4_OP_UMIN, &expr->node, arg1, arg2); break; + case HLSL_OP2_MUL: + /* Using IMUL instead of UMUL because we're taking + * the low bits, and the native compiler generates + * IMUL. */ + write_sm4_binary_op_with_two_destinations(buffer, VKD3D_SM4_OP_IMUL, &expr->node, 1, arg1, arg2); + break; + default: hlsl_fixme(ctx, &expr->node.loc, "SM4 uint \"%s\" expression.\n", debug_hlsl_expr_op(expr->op)); break; -- 2.34.1