From a062cc47062d967a25add46e94ba305d10eec8d7 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sun, 18 Sep 2022 12:10:36 +1000 Subject: [PATCH] VulkanHostDisplay: Fix uploading of strided textures --- src/common/vulkan/texture.cpp | 4 ++-- src/common/vulkan/texture.h | 2 +- src/core/gpu_hw_vulkan.cpp | 3 ++- src/frontend-common/vulkan_host_display.cpp | 7 +++++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/common/vulkan/texture.cpp b/src/common/vulkan/texture.cpp index cef5bbedb..e63c5d268 100644 --- a/src/common/vulkan/texture.cpp +++ b/src/common/vulkan/texture.cpp @@ -385,7 +385,7 @@ VkFramebuffer Texture::CreateFramebuffer(VkRenderPass render_pass) } void Texture::UpdateFromBuffer(VkCommandBuffer cmdbuf, u32 level, u32 layer, u32 x, u32 y, u32 width, u32 height, - VkBuffer buffer, u32 buffer_offset) + VkBuffer buffer, u32 buffer_offset, u32 row_length) { const VkImageLayout old_layout = m_layout; const Vulkan::Util::DebugScope debugScope(cmdbuf, "Texture::UpdateFromBuffer: Lvl:%u Lyr:%u {%u,%u} %ux%u", level, @@ -393,7 +393,7 @@ void Texture::UpdateFromBuffer(VkCommandBuffer cmdbuf, u32 level, u32 layer, u32 TransitionToLayout(cmdbuf, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); const VkBufferImageCopy bic = {static_cast(buffer_offset), - width, + row_length, height, {VK_IMAGE_ASPECT_COLOR_BIT, 0u, 0u, 1u}, {static_cast(x), static_cast(y), 0}, diff --git a/src/common/vulkan/texture.h b/src/common/vulkan/texture.h index c8fc6eeee..86e1da7a3 100644 --- a/src/common/vulkan/texture.h +++ b/src/common/vulkan/texture.h @@ -60,7 +60,7 @@ public: VkFramebuffer CreateFramebuffer(VkRenderPass render_pass); void UpdateFromBuffer(VkCommandBuffer cmdbuf, u32 level, u32 layer, u32 x, u32 y, u32 width, u32 height, - VkBuffer buffer, u32 buffer_offset); + VkBuffer buffer, u32 buffer_offset, u32 row_length); private: u32 m_width = 0; diff --git a/src/core/gpu_hw_vulkan.cpp b/src/core/gpu_hw_vulkan.cpp index b17f0ac81..a7cfd9621 100644 --- a/src/core/gpu_hw_vulkan.cpp +++ b/src/core/gpu_hw_vulkan.cpp @@ -1878,7 +1878,8 @@ bool GPU_HW_Vulkan::BlitVRAMReplacementTexture(const TextureReplacementTexture* // buffer -> texture m_vram_write_replacement_texture.UpdateFromBuffer(cmdbuf, 0, 0, 0, 0, tex->GetWidth(), tex->GetHeight(), - m_texture_replacment_stream_buffer.GetBuffer(), buffer_offset); + m_texture_replacment_stream_buffer.GetBuffer(), buffer_offset, + tex->GetWidth()); // texture -> vram const VkImageBlit blit = { diff --git a/src/frontend-common/vulkan_host_display.cpp b/src/frontend-common/vulkan_host_display.cpp index c7a26019b..83e36b478 100644 --- a/src/frontend-common/vulkan_host_display.cpp +++ b/src/frontend-common/vulkan_host_display.cpp @@ -75,7 +75,8 @@ public: buffer.CommitMemory(required_size); m_texture.UpdateFromBuffer(g_vulkan_context->GetCurrentCommandBuffer(), 0, 0, x, y, width, height, - buffer.GetBuffer(), buffer_offset); + buffer.GetBuffer(), buffer_offset, + HostDisplay::GetDisplayPixelFormatSize(m_format) / width); } const Vulkan::Texture& GetTexture() const { return m_texture; } @@ -240,11 +241,13 @@ std::unique_ptr VulkanHostDisplay::CreateTexture(u32 width, const u32 buffer_offset = buffer.GetCurrentOffset(); buffer.CommitMemory(data_size); texture.UpdateFromBuffer(g_vulkan_context->GetCurrentCommandBuffer(), 0, 0, 0, 0, width, height, - buffer.GetBuffer(), buffer_offset); + buffer.GetBuffer(), buffer_offset, + data_upload_pitch / GetDisplayPixelFormatSize(format)); } else { use_staging: + // TODO: Drop this thing completely. It's not using the buffer copy row pitch alignment. Vulkan::StagingTexture staging_texture; if (!staging_texture.Create(Vulkan::StagingBuffer::Type::Upload, vk_format, width, height)) return {};