VulkanHostDisplay: Fix uploading of strided textures

This commit is contained in:
Connor McLaughlin 2022-09-18 12:10:36 +10:00
parent 1e6abc1d64
commit a062cc4706
4 changed files with 10 additions and 6 deletions

View file

@ -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, 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 VkImageLayout old_layout = m_layout;
const Vulkan::Util::DebugScope debugScope(cmdbuf, "Texture::UpdateFromBuffer: Lvl:%u Lyr:%u {%u,%u} %ux%u", level, 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); TransitionToLayout(cmdbuf, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
const VkBufferImageCopy bic = {static_cast<VkDeviceSize>(buffer_offset), const VkBufferImageCopy bic = {static_cast<VkDeviceSize>(buffer_offset),
width, row_length,
height, height,
{VK_IMAGE_ASPECT_COLOR_BIT, 0u, 0u, 1u}, {VK_IMAGE_ASPECT_COLOR_BIT, 0u, 0u, 1u},
{static_cast<int32_t>(x), static_cast<int32_t>(y), 0}, {static_cast<int32_t>(x), static_cast<int32_t>(y), 0},

View file

@ -60,7 +60,7 @@ public:
VkFramebuffer CreateFramebuffer(VkRenderPass render_pass); VkFramebuffer CreateFramebuffer(VkRenderPass render_pass);
void UpdateFromBuffer(VkCommandBuffer cmdbuf, u32 level, u32 layer, u32 x, u32 y, u32 width, u32 height, 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: private:
u32 m_width = 0; u32 m_width = 0;

View file

@ -1878,7 +1878,8 @@ bool GPU_HW_Vulkan::BlitVRAMReplacementTexture(const TextureReplacementTexture*
// buffer -> texture // buffer -> texture
m_vram_write_replacement_texture.UpdateFromBuffer(cmdbuf, 0, 0, 0, 0, tex->GetWidth(), tex->GetHeight(), 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 // texture -> vram
const VkImageBlit blit = { const VkImageBlit blit = {

View file

@ -75,7 +75,8 @@ public:
buffer.CommitMemory(required_size); buffer.CommitMemory(required_size);
m_texture.UpdateFromBuffer(g_vulkan_context->GetCurrentCommandBuffer(), 0, 0, x, y, width, height, 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; } const Vulkan::Texture& GetTexture() const { return m_texture; }
@ -240,11 +241,13 @@ std::unique_ptr<HostDisplayTexture> VulkanHostDisplay::CreateTexture(u32 width,
const u32 buffer_offset = buffer.GetCurrentOffset(); const u32 buffer_offset = buffer.GetCurrentOffset();
buffer.CommitMemory(data_size); buffer.CommitMemory(data_size);
texture.UpdateFromBuffer(g_vulkan_context->GetCurrentCommandBuffer(), 0, 0, 0, 0, width, height, 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 else
{ {
use_staging: use_staging:
// TODO: Drop this thing completely. It's not using the buffer copy row pitch alignment.
Vulkan::StagingTexture staging_texture; Vulkan::StagingTexture staging_texture;
if (!staging_texture.Create(Vulkan::StagingBuffer::Type::Upload, vk_format, width, height)) if (!staging_texture.Create(Vulkan::StagingBuffer::Type::Upload, vk_format, width, height))
return {}; return {};