Skip to content

Commit

Permalink
Attachment tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
mdagois committed Aug 6, 2024
1 parent f0f1c39 commit c3e128f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
3 changes: 2 additions & 1 deletion filament/backend/include/backend/DriverEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion filament/backend/src/vulkan/VulkanHandles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions filament/backend/src/vulkan/VulkanTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c3e128f

Please sign in to comment.