[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:
parent
49bae34149
commit
2107af0396
|
@ -265,6 +265,7 @@ void PhysicalDevice::InitializeSupportedFeaturesImpl() {
|
||||||
#endif // DAWN_PLATFORM_IS(ANDROID) || DAWN_PLATFORM_IS(CHROMEOS)
|
#endif // DAWN_PLATFORM_IS(ANDROID) || DAWN_PLATFORM_IS(CHROMEOS)
|
||||||
|
|
||||||
EnableFeature(Feature::SurfaceCapabilities);
|
EnableFeature(Feature::SurfaceCapabilities);
|
||||||
|
EnableFeature(Feature::TransientAttachments);
|
||||||
}
|
}
|
||||||
|
|
||||||
MaybeError PhysicalDevice::InitializeSupportedLimitsImpl(CombinedLimits* limits) {
|
MaybeError PhysicalDevice::InitializeSupportedLimitsImpl(CombinedLimits* limits) {
|
||||||
|
|
|
@ -258,7 +258,23 @@ int ResourceMemoryAllocator::FindBestTypeIndex(VkMemoryRequirements requirements
|
||||||
continue;
|
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 =
|
bool currentDeviceLocal =
|
||||||
info.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
|
info.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
|
||||||
bool bestDeviceLocal =
|
bool bestDeviceLocal =
|
||||||
|
|
|
@ -32,6 +32,7 @@ class Device;
|
||||||
// Various kinds of memory that influence the result of the allocation. For example, to take
|
// Various kinds of memory that influence the result of the allocation. For example, to take
|
||||||
// into account mappability and Vulkan's bufferImageGranularity.
|
// into account mappability and Vulkan's bufferImageGranularity.
|
||||||
enum class MemoryKind {
|
enum class MemoryKind {
|
||||||
|
LazilyAllocated,
|
||||||
Linear,
|
Linear,
|
||||||
LinearMappable,
|
LinearMappable,
|
||||||
Opaque,
|
Opaque,
|
||||||
|
|
|
@ -494,8 +494,6 @@ VkImageUsageFlags VulkanImageUsage(wgpu::TextureUsage usage, const Format& forma
|
||||||
} else {
|
} else {
|
||||||
flags |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
|
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
|
// Choosing Vulkan image usages should not know about kReadOnlyRenderAttachment because that's
|
||||||
|
@ -745,9 +743,11 @@ MaybeError Texture::InitializeAsInternalTexture(VkImageUsageFlags extraUsages) {
|
||||||
Toggle::DisableSubAllocationFor2DTextureWithCopyDstOrRenderAttachment)) &&
|
Toggle::DisableSubAllocationFor2DTextureWithCopyDstOrRenderAttachment)) &&
|
||||||
GetDimension() == wgpu::TextureDimension::e2D &&
|
GetDimension() == wgpu::TextureDimension::e2D &&
|
||||||
(GetInternalUsage() & (wgpu::TextureUsage::CopyDst | wgpu::TextureUsage::RenderAttachment));
|
(GetInternalUsage() & (wgpu::TextureUsage::CopyDst | wgpu::TextureUsage::RenderAttachment));
|
||||||
DAWN_TRY_ASSIGN(mMemoryAllocation,
|
auto memoryKind = (GetInternalUsage() & wgpu::TextureUsage::TransientAttachment)
|
||||||
device->GetResourceMemoryAllocator()->Allocate(requirements, MemoryKind::Opaque,
|
? MemoryKind::LazilyAllocated
|
||||||
forceDisableSubAllocation));
|
: MemoryKind::Opaque;
|
||||||
|
DAWN_TRY_ASSIGN(mMemoryAllocation, device->GetResourceMemoryAllocator()->Allocate(
|
||||||
|
requirements, memoryKind, forceDisableSubAllocation));
|
||||||
|
|
||||||
DAWN_TRY(CheckVkSuccess(
|
DAWN_TRY(CheckVkSuccess(
|
||||||
device->fn.BindImageMemory(device->GetVkDevice(), mHandle,
|
device->fn.BindImageMemory(device->GetVkDevice(), mHandle,
|
||||||
|
|
Loading…
Reference in New Issue