From: Józef Kucia jkucia@codeweavers.com
Signed-off-by: Józef Kucia jkucia@codeweavers.com --- libs/vkd3d-shader/spirv.c | 43 +++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 15 deletions(-)
diff --git a/libs/vkd3d-shader/spirv.c b/libs/vkd3d-shader/spirv.c index a925d68eeeb4..9aee6928e993 100644 --- a/libs/vkd3d-shader/spirv.c +++ b/libs/vkd3d-shader/spirv.c @@ -2669,22 +2669,22 @@ static uint32_t vkd3d_dxbc_compiler_emit_swizzle(struct vkd3d_dxbc_compiler *com }
static uint32_t vkd3d_dxbc_compiler_emit_vector_shuffle(struct vkd3d_dxbc_compiler *compiler, - uint32_t vector1_id, uint32_t vector2_id, uint32_t write_mask, + uint32_t vector1_id, uint32_t vector2_id, unsigned int swizzle, unsigned int write_mask, enum vkd3d_component_type component_type, unsigned int component_count) { struct vkd3d_spirv_builder *builder = &compiler->spirv_builder; uint32_t components[VKD3D_VEC4_SIZE]; - unsigned int i, component_idx; uint32_t type_id; + unsigned int i;
assert(component_count <= ARRAY_SIZE(components));
- for (i = 0, component_idx = 0; i < component_count; ++i) + for (i = 0; i < component_count; ++i) { if (write_mask & (VKD3DSP_WRITEMASK_0 << i)) - components[i] = VKD3D_VEC4_SIZE + component_idx++; + components[i] = vkd3d_swizzle_get_component(swizzle, i); else - components[i] = i; + components[i] = VKD3D_VEC4_SIZE + vkd3d_swizzle_get_component(swizzle, i); }
type_id = vkd3d_spirv_get_type_id(builder, component_type, component_count); @@ -2926,6 +2926,8 @@ static void vkd3d_dxbc_compiler_emit_store(struct vkd3d_dxbc_compiler *compiler, { struct vkd3d_spirv_builder *builder = &compiler->spirv_builder; unsigned int component_count, dst_component_count; + uint32_t components[VKD3D_VEC4_SIZE]; + unsigned int i, component_idx; uint32_t type_id, dst_val_id;
assert(write_mask); @@ -2944,8 +2946,18 @@ static void vkd3d_dxbc_compiler_emit_store(struct vkd3d_dxbc_compiler *compiler, type_id = vkd3d_spirv_get_type_id(builder, component_type, dst_component_count); dst_val_id = vkd3d_spirv_build_op_load(builder, type_id, dst_id, SpvMemoryAccessMaskNone);
- val_id = vkd3d_dxbc_compiler_emit_vector_shuffle(compiler, - dst_val_id, val_id, write_mask, component_type, dst_component_count); + assert(component_count <= ARRAY_SIZE(components)); + + for (i = 0, component_idx = 0; i < dst_component_count; ++i) + { + if (write_mask & (VKD3DSP_WRITEMASK_0 << i)) + components[i] = VKD3D_VEC4_SIZE + component_idx++; + else + components[i] = i; + } + + val_id = vkd3d_spirv_build_op_vector_shuffle(builder, + type_id, dst_val_id, val_id, components, dst_component_count); }
vkd3d_spirv_build_op_store(builder, dst_id, val_id, SpvMemoryAccessMaskNone); @@ -4039,23 +4051,18 @@ static void vkd3d_dxbc_compiler_emit_store_shader_output(struct vkd3d_dxbc_compi uint32_t type_id, zero_id, ptr_type_id, chain_id, object_id; uint32_t write_mask, use_mask, uninit_mask, swizzle, mask; uint32_t output_id, indexes[1]; - unsigned int component_count; unsigned int i, index;
write_mask = output->mask & 0xff; use_mask = (output->mask >> 8) & 0xff; - swizzle = get_shader_output_swizzle(compiler, output->register_index); - val_id = vkd3d_dxbc_compiler_emit_swizzle(compiler, - val_id, VKD3DSP_WRITEMASK_ALL, VKD3D_TYPE_FLOAT, swizzle, write_mask); - - component_count = vkd3d_write_mask_component_count(write_mask);
if (output_info->component_type != VKD3D_TYPE_FLOAT) { - type_id = vkd3d_spirv_get_type_id(builder, output_info->component_type, component_count); + type_id = vkd3d_spirv_get_type_id(builder, output_info->component_type, VKD3D_VEC4_SIZE); val_id = vkd3d_spirv_build_op_bitcast(builder, type_id, val_id); }
+ swizzle = get_shader_output_swizzle(compiler, output->register_index); uninit_mask = write_mask & use_mask; if (uninit_mask) { @@ -4063,7 +4070,13 @@ static void vkd3d_dxbc_compiler_emit_store_shader_output(struct vkd3d_dxbc_compi zero_id = vkd3d_dxbc_compiler_get_constant_vector(compiler, output_info->component_type, VKD3D_VEC4_SIZE, 0); val_id = vkd3d_dxbc_compiler_emit_vector_shuffle(compiler, - val_id, zero_id, uninit_mask, output_info->component_type, component_count); + zero_id, val_id, swizzle, uninit_mask, output_info->component_type, + vkd3d_write_mask_component_count(write_mask)); + } + else + { + val_id = vkd3d_dxbc_compiler_emit_swizzle(compiler, + val_id, VKD3DSP_WRITEMASK_ALL, output_info->component_type, swizzle, write_mask); }
output_id = output_info->id;