diff --git a/src/dawn/native/vulkan/PhysicalDeviceVk.cpp b/src/dawn/native/vulkan/PhysicalDeviceVk.cpp index affb18240a..fafd7a05a9 100644 --- a/src/dawn/native/vulkan/PhysicalDeviceVk.cpp +++ b/src/dawn/native/vulkan/PhysicalDeviceVk.cpp @@ -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) { diff --git a/src/dawn/native/vulkan/ResourceMemoryAllocatorVk.cpp b/src/dawn/native/vulkan/ResourceMemoryAllocatorVk.cpp index ba1816eb26..e8466a7588 100644 --- a/src/dawn/native/vulkan/ResourceMemoryAllocatorVk.cpp +++ b/src/dawn/native/vulkan/ResourceMemoryAllocatorVk.cpp @@ -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(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 = diff --git a/src/dawn/native/vulkan/ResourceMemoryAllocatorVk.h b/src/dawn/native/vulkan/ResourceMemoryAllocatorVk.h index 2be1895980..452819cf71 100644 --- a/src/dawn/native/vulkan/ResourceMemoryAllocatorVk.h +++ b/src/dawn/native/vulkan/ResourceMemoryAllocatorVk.h @@ -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, diff --git a/src/dawn/native/vulkan/TextureVk.cpp b/src/dawn/native/vulkan/TextureVk.cpp index ebd138c6a0..f1bb1ce402 100644 --- a/src/dawn/native/vulkan/TextureVk.cpp +++ b/src/dawn/native/vulkan/TextureVk.cpp @@ -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,