From a66f14b5c3b4ea44d956d3c0dbf49c8708fce85c Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Fri, 25 Dec 2020 18:01:54 +1000 Subject: [PATCH] Vulkan/Texture: Add UpdateFromBuffer method --- src/common/vulkan/texture.cpp | 18 ++++++++++++++++++ src/common/vulkan/texture.h | 3 +++ 2 files changed, 21 insertions(+) diff --git a/src/common/vulkan/texture.cpp b/src/common/vulkan/texture.cpp index 7078b8e6c..7ca806ac7 100644 --- a/src/common/vulkan/texture.cpp +++ b/src/common/vulkan/texture.cpp @@ -371,4 +371,22 @@ VkFramebuffer Texture::CreateFramebuffer(VkRenderPass render_pass) return fb; } +void Texture::UpdateFromBuffer(VkCommandBuffer cmdbuf, u32 level, u32 layer, u32 x, u32 y, u32 width, u32 height, + VkBuffer buffer, u32 buffer_offset) +{ + const VkImageLayout old_layout = m_layout; + TransitionToLayout(cmdbuf, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); + + const VkBufferImageCopy bic = {static_cast(buffer_offset), + width, + height, + {VK_IMAGE_ASPECT_COLOR_BIT, 0u, 0u, 1u}, + {static_cast(x), static_cast(y), 0}, + {width, height, 1u}}; + + vkCmdCopyBufferToImage(cmdbuf, buffer, m_image, m_layout, 1, &bic); + + TransitionToLayout(cmdbuf, old_layout); +} + } // namespace Vulkan diff --git a/src/common/vulkan/texture.h b/src/common/vulkan/texture.h index 15d8dcdd5..8c55935a7 100644 --- a/src/common/vulkan/texture.h +++ b/src/common/vulkan/texture.h @@ -54,6 +54,9 @@ 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); + private: u32 m_width = 0; u32 m_height = 0;