From cc75eb3aa2e25070f8e822e4318fa9aa8b6031ad Mon Sep 17 00:00:00 2001 From: Philip Rideout Date: Tue, 15 Feb 2022 14:19:27 -0800 Subject: [PATCH] Vulkan: add comments explaining layout strategy. --- filament/backend/src/vulkan/VulkanDriver.cpp | 3 ++- filament/backend/src/vulkan/VulkanUtility.cpp | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/filament/backend/src/vulkan/VulkanDriver.cpp b/filament/backend/src/vulkan/VulkanDriver.cpp index 7a2afffe00..23d0bbdead 100644 --- a/filament/backend/src/vulkan/VulkanDriver.cpp +++ b/filament/backend/src/vulkan/VulkanDriver.cpp @@ -1512,7 +1512,8 @@ void VulkanDriver::readPixels(Handle src, uint32_t x, uint32_t y VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, stagingImage, VK_IMAGE_LAYOUT_GENERAL, 1, &imageCopyRegion); - // Restore the source image layout. + // Restore the source image layout. Between driver API calls, color images are always kept in + // UNDEFINED layout or in their "usage default" layout (see comment for getDefaultImageLayout). srcTexture->transitionLayout(cmdbuffer, srcRange, getDefaultImageLayout(TextureUsage::COLOR_ATTACHMENT)); diff --git a/filament/backend/src/vulkan/VulkanUtility.cpp b/filament/backend/src/vulkan/VulkanUtility.cpp index d600f5ccfb..00f5f0dc0c 100644 --- a/filament/backend/src/vulkan/VulkanUtility.cpp +++ b/filament/backend/src/vulkan/VulkanUtility.cpp @@ -514,6 +514,11 @@ VkImageViewType getImageViewType(SamplerType target) { } } +// Between Driver API calls, non-presentable texture images are generally kept either in the +// UNDEFINED layout, or in the usage-specific layout specified by this function. This simple +// convention allows the use of a bitfield to represent layout in RenderPassKey. However there are +// exceptions for depth and for transient use of specialized layouts, which is why VulkanTexture +// tracks actual layout at the subresource level. VkImageLayout getDefaultImageLayout(TextureUsage usage) { // Filament sometimes samples from depth while it is bound to the current render target, (e.g. // SSAO does this while depth writes are disabled) so let's keep it simple and use GENERAL for