vkd3d-shader/msl: Implement VKD3DSIH_DP3.

This commit is contained in:
Feifan He 2024-11-22 15:45:54 +08:00 committed by Henri Verbeet
parent 74365417ac
commit 046e9b5286
Notes: Henri Verbeet 2024-12-03 14:57:01 +01:00
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1291
2 changed files with 27 additions and 2 deletions

View File

@ -398,6 +398,28 @@ static void msl_binop(struct msl_generator *gen, const struct vkd3d_shader_instr
msl_dst_cleanup(&dst, &gen->string_buffers);
}
static void msl_dot(struct msl_generator *gen, const struct vkd3d_shader_instruction *ins, uint32_t src_mask)
{
unsigned int component_count;
struct msl_src src[2];
struct msl_dst dst;
uint32_t dst_mask;
dst_mask = msl_dst_init(&dst, gen, ins, &ins->dst[0]);
msl_src_init(&src[0], gen, &ins->src[0], src_mask);
msl_src_init(&src[1], gen, &ins->src[1], src_mask);
if ((component_count = vsir_write_mask_component_count(dst_mask)) > 1)
msl_print_assignment(gen, &dst, "float%u(dot(%s, %s))",
component_count, src[0].str->buffer, src[1].str->buffer);
else
msl_print_assignment(gen, &dst, "dot(%s, %s)", src[0].str->buffer, src[1].str->buffer);
msl_src_cleanup(&src[1], &gen->string_buffers);
msl_src_cleanup(&src[0], &gen->string_buffers);
msl_dst_cleanup(&dst, &gen->string_buffers);
}
static void msl_intrinsic(struct msl_generator *gen, const struct vkd3d_shader_instruction *ins, const char *op)
{
struct msl_src src;
@ -518,6 +540,9 @@ static void msl_handle_instruction(struct msl_generator *gen, const struct vkd3d
case VKD3DSIH_DIV:
msl_binop(gen, ins, "/");
break;
case VKD3DSIH_DP3:
msl_dot(gen, ins, vkd3d_write_mask_from_component_count(3));
break;
case VKD3DSIH_FRC:
msl_intrinsic(gen, ins, "fract");
break;

View File

@ -64,7 +64,7 @@ float4 main() : sv_target
uniform 0 float4 1.0 2.0 3.0 4.0
uniform 4 float4 5.0 -6.0 7.0 8.0
uniform 8 float4 9.0 10.0 11.0 12.0
todo(msl) draw quad
draw quad
probe (0, 0) rgba (192.0, 192.0, 192.0, 192.0)
[pixel shader]
@ -96,7 +96,7 @@ uniform 0 float4 1.0 2.0 3.0 0.0
uniform 4 float4 5.0 -6.0 7.0 0.0
uniform 8 float4 9.0 10.0 11.0 0.0
uniform 12 float4 0.0 0.0 0.0 0.0
todo(msl) draw quad
draw quad
probe (0, 0) rgba (192.0, 192.0, 192.0, 192.0)
[pixel shader fail]