From b92baa40ec51f38da4dbf8df96a8d2937129d324 Mon Sep 17 00:00:00 2001 From: Francisco Casas Date: Thu, 9 May 2024 12:32:35 -0400 Subject: [PATCH] vkd3d-shader/d3dbc: Don't write inconsequential MOVs. CASTs from floats to integers are implemented as mere MOVs. These often, but not always, end up moving the value from one register to the same register. This patch avoids writing the MOV instructions if they have no effect. --- libs/vkd3d-shader/d3dbc.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/libs/vkd3d-shader/d3dbc.c b/libs/vkd3d-shader/d3dbc.c index 53cf7169..ea9fe775 100644 --- a/libs/vkd3d-shader/d3dbc.c +++ b/libs/vkd3d-shader/d3dbc.c @@ -1882,6 +1882,32 @@ struct sm1_instruction unsigned int has_dst; }; +static bool is_inconsequential_instr(const struct sm1_instruction *instr) +{ + const struct sm1_src_register *src = &instr->srcs[0]; + const struct sm1_dst_register *dst = &instr->dst; + unsigned int i; + + if (instr->opcode != D3DSIO_MOV) + return false; + if (dst->mod != D3DSPDM_NONE) + return false; + if (src->mod != D3DSPSM_NONE) + return false; + if (src->type != dst->type) + return false; + if (src->reg != dst->reg) + return false; + + for (i = 0; i < 4; ++i) + { + if ((dst->writemask & (1 << i)) && (vsir_swizzle_get_component(src->swizzle, i) != i)) + return false; + } + + return true; +} + static void write_sm1_dst_register(struct vkd3d_bytecode_buffer *buffer, const struct sm1_dst_register *reg) { assert(reg->writemask); @@ -1901,6 +1927,9 @@ static void d3dbc_write_instruction(struct d3dbc_compiler *d3dbc, const struct s uint32_t token = instr->opcode; unsigned int i; + if (is_inconsequential_instr(instr)) + return; + token |= VKD3D_SM1_INSTRUCTION_FLAGS_MASK & (instr->flags << VKD3D_SM1_INSTRUCTION_FLAGS_SHIFT); if (version->major > 1)