From c3e128faa7c46f513c016d83f1208f0044509e22 Mon Sep 17 00:00:00 2001 From: Maximilien Dagois Date: Tue, 6 Aug 2024 17:11:39 +0900 Subject: [PATCH] Attachment tweaks --- filament/backend/include/backend/DriverEnums.h | 3 ++- filament/backend/src/vulkan/VulkanHandles.cpp | 2 +- filament/backend/src/vulkan/VulkanTexture.cpp | 5 ++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/filament/backend/include/backend/DriverEnums.h b/filament/backend/include/backend/DriverEnums.h index d69a9991d288..4e4759150183 100644 --- a/filament/backend/include/backend/DriverEnums.h +++ b/filament/backend/include/backend/DriverEnums.h @@ -693,7 +693,8 @@ enum class TextureUsage : uint16_t { BLIT_SRC = 0x0040, //!< Texture can be used the source of a blit() BLIT_DST = 0x0080, //!< Texture can be used the destination of a blit() PROTECTED = 0x0100, //!< Texture can be used for protected content - DEFAULT = UPLOADABLE | SAMPLEABLE //!< Default texture usage + DEFAULT = UPLOADABLE | SAMPLEABLE, //!< Default texture usage + ALL_ATTACHMENTS = COLOR_ATTACHMENT | DEPTH_ATTACHMENT | STENCIL_ATTACHMENT | SUBPASS_INPUT, //!< Attachments }; //! Texture swizzle diff --git a/filament/backend/src/vulkan/VulkanHandles.cpp b/filament/backend/src/vulkan/VulkanHandles.cpp index fc33268fb0c3..65587315037a 100644 --- a/filament/backend/src/vulkan/VulkanHandles.cpp +++ b/filament/backend/src/vulkan/VulkanHandles.cpp @@ -355,7 +355,7 @@ VulkanRenderTarget::VulkanRenderTarget(VkDevice device, VkPhysicalDevice physica // TODO: This should be allocated with the ResourceAllocator. msTexture = new VulkanTexture(device, physicalDevice, context, allocator, commands, texture->target, ((VulkanTexture const*) texture)->levels, texture->format, - samples, texture->width, texture->height, texture->depth, texture->usage, + samples, texture->width, texture->height, texture->depth, texture->usage & TextureUsage::ALL_ATTACHMENTS, stagePool, true /* heap allocated */, {} /* swizzle */, true /* preferTransientAttachment */); texture->setSidecar(msTexture); diff --git a/filament/backend/src/vulkan/VulkanTexture.cpp b/filament/backend/src/vulkan/VulkanTexture.cpp index 7eff128890d3..4456399eecaa 100644 --- a/filament/backend/src/vulkan/VulkanTexture.cpp +++ b/filament/backend/src/vulkan/VulkanTexture.cpp @@ -97,16 +97,15 @@ VulkanTexture::VulkanTexture(VkDevice device, VkPhysicalDevice physicalDevice, imageInfo.extent.depth = 1; } - constexpr TextureUsage attachmentUsageFlags = TextureUsage::COLOR_ATTACHMENT | TextureUsage::DEPTH_ATTACHMENT | TextureUsage::STENCIL_ATTACHMENT | TextureUsage::SUBPASS_INPUT; const bool useTransientAttachment = // Transient attachment is requested. preferTransientAttachment && // Lazily allocated memory is available. context.isLazilyAllocatedMemorySupported() && // Usage consists of attachment flags only. - !any(tusage & ~attachmentUsageFlags) && + !any(tusage & ~TextureUsage::ALL_ATTACHMENTS) && // Usage contains at least one attachment flag. - any(tusage & attachmentUsageFlags); + any(tusage & TextureUsage::ALL_ATTACHMENTS); // Filament expects blit() to work with any texture, so we almost always set these usage flags. // We do not add the flags for transient attachments, because that would prevent the usage of