diff --git a/rpcs3/Emu/RSX/Common/TextureUtils.cpp b/rpcs3/Emu/RSX/Common/TextureUtils.cpp index e41c2c5934..090479c006 100644 --- a/rpcs3/Emu/RSX/Common/TextureUtils.cpp +++ b/rpcs3/Emu/RSX/Common/TextureUtils.cpp @@ -391,16 +391,32 @@ namespace } template<typename T> -u32 get_row_pitch_in_block(u16 width_in_block, size_t multiple_constraints_in_byte) +u32 get_row_pitch_in_block(u16 width_in_block, size_t alignment) { - size_t divided = (width_in_block * sizeof(T) + multiple_constraints_in_byte - 1) / multiple_constraints_in_byte; - return static_cast<u32>(divided * multiple_constraints_in_byte / sizeof(T)); + if (const size_t pitch = width_in_block * sizeof(T); + pitch == alignment) + { + return width_in_block; + } + else + { + size_t divided = (pitch + alignment - 1) / alignment; + return static_cast<u32>(divided * alignment / sizeof(T)); + } } -u32 get_row_pitch_in_block(u16 block_size_in_bytes, u16 width_in_block, size_t multiple_constraints_in_byte) +u32 get_row_pitch_in_block(u16 block_size_in_bytes, u16 width_in_block, size_t alignment) { - size_t divided = (width_in_block * block_size_in_bytes + multiple_constraints_in_byte - 1) / multiple_constraints_in_byte; - return static_cast<u32>(divided * multiple_constraints_in_byte / block_size_in_bytes); + if (const size_t pitch = width_in_block * block_size_in_bytes; + pitch == alignment) + { + return width_in_block; + } + else + { + size_t divided = (pitch + alignment - 1) / alignment; + return static_cast<u32>(divided * alignment / block_size_in_bytes); + } } /** diff --git a/rpcs3/Emu/RSX/VK/VKHelpers.h b/rpcs3/Emu/RSX/VK/VKHelpers.h index 824f02b250..451a4b128b 100644 --- a/rpcs3/Emu/RSX/VK/VKHelpers.h +++ b/rpcs3/Emu/RSX/VK/VKHelpers.h @@ -141,7 +141,7 @@ namespace vk */ void copy_mipmaped_image_using_buffer(VkCommandBuffer cmd, vk::image* dst_image, const std::vector<rsx_subresource_layout>& subresource_layout, int format, bool is_swizzled, u16 mipmap_count, - VkImageAspectFlags flags, vk::data_heap &upload_heap, u32 heap_align = 256); + VkImageAspectFlags flags, vk::data_heap &upload_heap, u32 heap_align = 0); //Other texture management helpers void change_image_layout(VkCommandBuffer cmd, VkImage image, VkImageLayout current_layout, VkImageLayout new_layout, const VkImageSubresourceRange& range); diff --git a/rpcs3/Emu/RSX/VK/VKTexture.cpp b/rpcs3/Emu/RSX/VK/VKTexture.cpp index 9e5b9f82e4..7c0a65db27 100644 --- a/rpcs3/Emu/RSX/VK/VKTexture.cpp +++ b/rpcs3/Emu/RSX/VK/VKTexture.cpp @@ -519,12 +519,22 @@ namespace vk texture_uploader_capabilities caps{ true, false, heap_align }; vk::buffer* scratch_buf = nullptr; u32 scratch_offset = 0; + u32 row_pitch, image_linear_size; for (const rsx_subresource_layout &layout : subresource_layout) { - u32 row_pitch = (((layout.width_in_block * block_size_in_bytes) + heap_align - 1) / heap_align) * heap_align; - if (heap_align != 256) verify(HERE), row_pitch == heap_align; - u32 image_linear_size = row_pitch * layout.height_in_block * layout.depth; + if (LIKELY(!heap_align)) + { + row_pitch = (layout.pitch_in_block * block_size_in_bytes); + caps.alignment = row_pitch; + } + else + { + row_pitch = (((layout.width_in_block * block_size_in_bytes) + heap_align - 1) / heap_align) * heap_align; + verify(HERE), row_pitch == heap_align; + } + + image_linear_size = row_pitch * layout.height_in_block * layout.depth; // Map with extra padding bytes in case of realignment size_t offset_in_buffer = upload_heap.alloc<512>(image_linear_size + 8);