From: Józef Kucia jkucia@codeweavers.com
Eliminates redundant OpVectorShuffle instructions.
Signed-off-by: Józef Kucia jkucia@codeweavers.com --- libs/vkd3d-shader/spirv.c | 8 +++++--- libs/vkd3d-shader/vkd3d_shader_private.h | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/libs/vkd3d-shader/spirv.c b/libs/vkd3d-shader/spirv.c index dee561ac033c..9493d53591bb 100644 --- a/libs/vkd3d-shader/spirv.c +++ b/libs/vkd3d-shader/spirv.c @@ -2528,10 +2528,13 @@ static uint32_t vkd3d_dxbc_compiler_emit_swizzle_ext(struct vkd3d_dxbc_compiler struct vkd3d_spirv_builder *builder = &compiler->spirv_builder; uint32_t type_id, components[VKD3D_VEC4_SIZE];
- if (swizzle == VKD3D_NO_SWIZZLE && write_mask == val_write_mask) + component_count = vkd3d_write_mask_component_count(write_mask); + val_component_count = vkd3d_write_mask_component_count(val_write_mask); + + if (component_count == val_component_count + && vkd3d_compact_swizzle(swizzle, write_mask) == vkd3d_compact_swizzle(VKD3D_NO_SWIZZLE, val_write_mask)) return val_id;
- component_count = vkd3d_write_mask_component_count(write_mask); type_id = vkd3d_spirv_get_type_id(builder, component_type, component_count);
if (component_count == 1) @@ -2541,7 +2544,6 @@ static uint32_t vkd3d_dxbc_compiler_emit_swizzle_ext(struct vkd3d_dxbc_compiler return vkd3d_spirv_build_op_composite_extract1(builder, type_id, val_id, component_idx); }
- val_component_count = vkd3d_write_mask_component_count(val_write_mask); if (val_component_count == 1) { for (i = 0, component_idx = 0; i < VKD3D_VEC4_SIZE; ++i) diff --git a/libs/vkd3d-shader/vkd3d_shader_private.h b/libs/vkd3d-shader/vkd3d_shader_private.h index dd3650b2d828..651a5959f1d1 100644 --- a/libs/vkd3d-shader/vkd3d_shader_private.h +++ b/libs/vkd3d-shader/vkd3d_shader_private.h @@ -882,6 +882,22 @@ static inline unsigned int vkd3d_swizzle_get_component(DWORD swizzle, return (swizzle >> VKD3D_SWIZZLE_SHIFT(idx)) & VKD3D_SWIZZLE_MASK; }
+static inline unsigned int vkd3d_compact_swizzle(unsigned int swizzle, unsigned int write_mask) +{ + unsigned int i, compacted_swizzle = 0; + + for (i = 0; i < VKD3D_VEC4_SIZE; ++i) + { + if (write_mask & (VKD3DSP_WRITEMASK_0 << i)) + { + compacted_swizzle <<= VKD3D_SWIZZLE_SHIFT(1); + compacted_swizzle |= vkd3d_swizzle_get_component(swizzle, i); + } + } + + return compacted_swizzle; +} + #define VKD3D_DXBC_MAX_SOURCE_COUNT 6 #define VKD3D_DXBC_HEADER_SIZE (8 * sizeof(uint32_t))