[Vulkan] Add support for transient attachments

This CL adds support for the transient attachment feature and texture
usage flag to Vulkan, using the usage flag to allocate textures via
lazily-allocated memory if the latter is available.

Testing is covered by the
MultisampledRenderingWithTransientAttachmentTest now being run on
Vulkan due to transient attachments feature now being supported on
Vulkan.

Bug: dawn:1695
Change-Id: I45a04d21b1b6ea612086a368b9c77a0ff43e93f8
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/130180
Reviewed-by: Loko Kung <lokokung@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Colin Blundell <blundell@chromium.org>
This commit is contained in:
Colin Blundell 2023-05-10 09:08:50 +00:00 committed by Dawn LUCI CQ
parent 49bae34149
commit 2107af0396
4 changed files with 24 additions and 6 deletions

View File

@ -265,6 +265,7 @@ void PhysicalDevice::InitializeSupportedFeaturesImpl() {
#endif // DAWN_PLATFORM_IS(ANDROID) || DAWN_PLATFORM_IS(CHROMEOS)
EnableFeature(Feature::SurfaceCapabilities);
EnableFeature(Feature::TransientAttachments);
}
MaybeError PhysicalDevice::InitializeSupportedLimitsImpl(CombinedLimits* limits) {

View File

@ -258,7 +258,23 @@ int ResourceMemoryAllocator::FindBestTypeIndex(VkMemoryRequirements requirements
continue;
}
// For non-mappable resources, favor device local memory.
// For non-mappable resources that can be lazily allocated, favor lazy
// allocation (note: this is a more important property than that of
// device local memory and hence is checked first).
bool currentLazilyAllocated =
info.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT;
bool bestLazilyAllocated =
info.memoryTypes[bestType].propertyFlags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT;
if ((kind == MemoryKind::LazilyAllocated) &&
(currentLazilyAllocated != bestLazilyAllocated)) {
if (currentLazilyAllocated) {
bestType = static_cast<int>(i);
}
continue;
}
// For non-mappable, non-lazily-allocated resources, favor device local
// memory.
bool currentDeviceLocal =
info.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
bool bestDeviceLocal =

View File

@ -32,6 +32,7 @@ class Device;
// Various kinds of memory that influence the result of the allocation. For example, to take
// into account mappability and Vulkan's bufferImageGranularity.
enum class MemoryKind {
LazilyAllocated,
Linear,
LinearMappable,
Opaque,

View File

@ -494,8 +494,6 @@ VkImageUsageFlags VulkanImageUsage(wgpu::TextureUsage usage, const Format& forma
} else {
flags |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
}
// TODO(1695): Check for TransientAttachment flag being present and
// convert it into the proper Vulkan flag.
}
// Choosing Vulkan image usages should not know about kReadOnlyRenderAttachment because that's
@ -745,9 +743,11 @@ MaybeError Texture::InitializeAsInternalTexture(VkImageUsageFlags extraUsages) {
Toggle::DisableSubAllocationFor2DTextureWithCopyDstOrRenderAttachment)) &&
GetDimension() == wgpu::TextureDimension::e2D &&
(GetInternalUsage() & (wgpu::TextureUsage::CopyDst | wgpu::TextureUsage::RenderAttachment));
DAWN_TRY_ASSIGN(mMemoryAllocation,
device->GetResourceMemoryAllocator()->Allocate(requirements, MemoryKind::Opaque,
forceDisableSubAllocation));
auto memoryKind = (GetInternalUsage() & wgpu::TextureUsage::TransientAttachment)
? MemoryKind::LazilyAllocated
: MemoryKind::Opaque;
DAWN_TRY_ASSIGN(mMemoryAllocation, device->GetResourceMemoryAllocator()->Allocate(
requirements, memoryKind, forceDisableSubAllocation));
DAWN_TRY(CheckVkSuccess(
device->fn.BindImageMemory(device->GetVkDevice(), mHandle,