diff --git a/src/common/vulkan/swap_chain.cpp b/src/common/vulkan/swap_chain.cpp index 06b2eb1f5..d9a54e0dd 100644 --- a/src/common/vulkan/swap_chain.cpp +++ b/src/common/vulkan/swap_chain.cpp @@ -715,7 +715,8 @@ bool SwapChain::SetupSwapChainImages() // Create texture object, which creates a view of the backbuffer if (!image.texture.Adopt(image.image, VK_IMAGE_VIEW_TYPE_2D, m_window_info.surface_width, - m_window_info.surface_height, 1, 1, m_surface_format.format, VK_SAMPLE_COUNT_1_BIT)) + m_window_info.surface_height, 1, 1, m_surface_format.format, VK_SAMPLE_COUNT_1_BIT, + VK_IMAGE_LAYOUT_UNDEFINED)) { return false; } diff --git a/src/common/vulkan/texture.cpp b/src/common/vulkan/texture.cpp index 59166ee92..82f57fb32 100644 --- a/src/common/vulkan/texture.cpp +++ b/src/common/vulkan/texture.cpp @@ -163,6 +163,7 @@ bool Vulkan::Texture::Create(u32 width, u32 height, u32 levels, u32 layers, VkFo m_samples = static_cast(samples); m_format = LookupBaseFormat(format); m_view_type = view_type; + m_layout = VK_IMAGE_LAYOUT_UNDEFINED; m_image = image; m_allocation = allocation; m_view = view; @@ -170,7 +171,7 @@ bool Vulkan::Texture::Create(u32 width, u32 height, u32 levels, u32 layers, VkFo } bool Vulkan::Texture::Adopt(VkImage existing_image, VkImageViewType view_type, u32 width, u32 height, u32 levels, - u32 layers, VkFormat format, VkSampleCountFlagBits samples, + u32 layers, VkFormat format, VkSampleCountFlagBits samples, VkImageLayout layout, const VkComponentMapping* swizzle /* = nullptr */) { // Only need to create the image view, this is mainly for swap chains. @@ -205,6 +206,7 @@ bool Vulkan::Texture::Adopt(VkImage existing_image, VkImageViewType view_type, u m_format = LookupBaseFormat(format); m_samples = static_cast(samples); m_view_type = view_type; + m_layout = layout; m_image = existing_image; m_view = view; return true; @@ -395,8 +397,11 @@ VkFramebuffer Vulkan::Texture::CreateFramebuffer(VkRenderPass render_pass) void Vulkan::Texture::UpdateFromBuffer(VkCommandBuffer cmdbuf, u32 level, u32 layer, u32 x, u32 y, u32 width, u32 height, VkBuffer buffer, u32 buffer_offset, u32 row_length) { + // If we're previously undefined, don't leave any images in this layout. const VkImageLayout old_layout = m_layout; - if (old_layout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) + if (old_layout == VK_IMAGE_LAYOUT_UNDEFINED) + TransitionToLayout(cmdbuf, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); + else if (old_layout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) TransitionSubresourcesToLayout(cmdbuf, level, 1, layer, 1, old_layout, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); const VkBufferImageCopy bic = {static_cast(buffer_offset), @@ -406,9 +411,9 @@ void Vulkan::Texture::UpdateFromBuffer(VkCommandBuffer cmdbuf, u32 level, u32 la {static_cast(x), static_cast(y), 0}, {width, height, 1u}}; - vkCmdCopyBufferToImage(cmdbuf, buffer, m_image, m_layout, 1, &bic); + vkCmdCopyBufferToImage(cmdbuf, buffer, m_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &bic); - if (old_layout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) + if (old_layout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL && old_layout != VK_IMAGE_LAYOUT_UNDEFINED) TransitionSubresourcesToLayout(cmdbuf, level, 1, layer, 1, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, old_layout); } diff --git a/src/common/vulkan/texture.h b/src/common/vulkan/texture.h index c8daedd4b..644e1d87d 100644 --- a/src/common/vulkan/texture.h +++ b/src/common/vulkan/texture.h @@ -46,7 +46,8 @@ public: const VkComponentMapping* swizzle = nullptr); bool Adopt(VkImage existing_image, VkImageViewType view_type, u32 width, u32 height, u32 levels, u32 layers, - VkFormat format, VkSampleCountFlagBits samples, const VkComponentMapping* swizzle = nullptr); + VkFormat format, VkSampleCountFlagBits samples, VkImageLayout layout, + const VkComponentMapping* swizzle = nullptr); void Destroy(bool defer = true); diff --git a/src/frontend-common/imgui_impl_vulkan.cpp b/src/frontend-common/imgui_impl_vulkan.cpp index d157767e6..381e4a96c 100644 --- a/src/frontend-common/imgui_impl_vulkan.cpp +++ b/src/frontend-common/imgui_impl_vulkan.cpp @@ -413,6 +413,7 @@ bool ImGui_ImplVulkan_CreateFontsTexture() // Store our identifier bd->FontTexture.Update(0, 0, width, height, 0, 0, pixels, sizeof(u32) * width); + bd->FontTexture.TransitionToLayout(g_vulkan_context->GetCurrentCommandBuffer(), VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); io.Fonts->SetTexID((ImTextureID)&bd->FontTexture); return true; }