vkd3d-shader/hlsl: Write SM4 dot product instructions.

Signed-off-by: Giovanni Mascellani <gmascellani@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Zebediah Figura <zfigura@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Giovanni Mascellani 2022-06-24 09:41:28 +02:00 committed by Alexandre Julliard
parent 58d017ccc1
commit c7198bc964
2 changed files with 54 additions and 3 deletions

View File

@ -1314,6 +1314,25 @@ static void write_sm4_binary_op(struct vkd3d_bytecode_buffer *buffer, enum vkd3d
write_sm4_instruction(buffer, &instr); write_sm4_instruction(buffer, &instr);
} }
/* dp# instructions don't map the swizzle. */
static void write_sm4_binary_op_dot(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)
{
struct sm4_instruction instr;
memset(&instr, 0, sizeof(instr));
instr.opcode = opcode;
sm4_dst_from_node(&instr.dsts[0], dst);
instr.dst_count = 1;
sm4_src_from_node(&instr.srcs[0], src1, VKD3DSP_WRITEMASK_ALL);
sm4_src_from_node(&instr.srcs[1], src2, VKD3DSP_WRITEMASK_ALL);
instr.src_count = 2;
write_sm4_instruction(buffer, &instr);
}
static void write_sm4_binary_op_with_two_destinations(struct vkd3d_bytecode_buffer *buffer, 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, 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) const struct hlsl_ir_node *src1, const struct hlsl_ir_node *src2)
@ -1679,6 +1698,38 @@ static void write_sm4_expr(struct hlsl_ctx *ctx,
} }
break; break;
case HLSL_OP2_DOT:
switch (dst_type->base_type)
{
case HLSL_TYPE_FLOAT:
switch (arg1->data_type->dimx)
{
case 4:
write_sm4_binary_op_dot(buffer, VKD3D_SM4_OP_DP4, &expr->node, arg1, arg2);
break;
case 3:
write_sm4_binary_op_dot(buffer, VKD3D_SM4_OP_DP3, &expr->node, arg1, arg2);
break;
case 2:
write_sm4_binary_op_dot(buffer, VKD3D_SM4_OP_DP2, &expr->node, arg1, arg2);
break;
case 1:
assert(0);
break;
default:
assert(0);
}
break;
default:
hlsl_fixme(ctx, &expr->node.loc, "SM4 %s dot expression.", dst_type_string->buffer);
}
break;
case HLSL_OP2_EQUAL: case HLSL_OP2_EQUAL:
{ {
const struct hlsl_type *src_type = arg1->data_type; const struct hlsl_type *src_type = arg1->data_type;

View File

@ -10,7 +10,7 @@ float4 main() : SV_TARGET
[test] [test]
uniform 0 float4 2.0 3.0 4.0 5.0 uniform 0 float4 2.0 3.0 4.0 5.0
uniform 4 float4 10.0 11.0 12.0 13.0 uniform 4 float4 10.0 11.0 12.0 13.0
todo draw quad draw quad
probe all rgba (166.0, 166.0, 166.0, 166.0) probe all rgba (166.0, 166.0, 166.0, 166.0)
[pixel shader] [pixel shader]
@ -25,7 +25,7 @@ float4 main() : SV_TARGET
[test] [test]
uniform 0 float4 2.0 3.0 0.0 0.0 uniform 0 float4 2.0 3.0 0.0 0.0
uniform 4 float4 10.0 11.0 12.0 13.0 uniform 4 float4 10.0 11.0 12.0 13.0
todo draw quad draw quad
probe all rgba (53.0, 53.0, 53.0, 53.0) probe all rgba (53.0, 53.0, 53.0, 53.0)
[pixel shader] [pixel shader]
@ -40,7 +40,7 @@ float4 main() : SV_TARGET
[test] [test]
uniform 0 float4 2.0 0.0 0.0 0.0 uniform 0 float4 2.0 0.0 0.0 0.0
uniform 4 float4 10.0 11.0 12.0 13.0 uniform 4 float4 10.0 11.0 12.0 13.0
todo draw quad draw quad
probe all rgba (92.0, 92.0, 92.0, 92.0) probe all rgba (92.0, 92.0, 92.0, 92.0)
[pixel shader] [pixel shader]