// Copyright 2019 The Dawn & Tint Authors // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // // 1. Redistributions of source code must retain the above copyright notice, this // list of conditions and the following disclaimer. // // 2. Redistributions in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // // 3. Neither the name of the copyright holder nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "dawn/native/vulkan/ResourceMemoryAllocatorVk.h" #include <algorithm> #include <utility> #include "dawn/common/Math.h" #include "dawn/native/BuddyMemoryAllocator.h" #include "dawn/native/Queue.h" #include "dawn/native/ResourceHeapAllocator.h" #include "dawn/native/vulkan/DeviceVk.h" #include "dawn/native/vulkan/FencedDeleter.h" #include "dawn/native/vulkan/ResourceHeapVk.h" #include "dawn/native/vulkan/VulkanError.h" #include "partition_alloc/pointers/raw_ptr.h" namespace dawn::native::vulkan { namespace { // TODO(crbug.com/dawn/849): This is a hardcoded heurstic to choose when to // suballocate but it should ideally depend on the size of the memory heaps and other // factors. constexpr uint64_t kMaxSizeForSubAllocation = …; // 4MiB // Have each bucket of the buddy system allocate at least some resource of the maximum // size constexpr uint64_t kBuddyHeapsSize = …; bool IsMemoryKindMappable(MemoryKind memoryKind) { … } } // anonymous namespace // SingleTypeAllocator is a combination of a BuddyMemoryAllocator and its client and can // service suballocation requests, but for a single Vulkan memory type. class ResourceMemoryAllocator::SingleTypeAllocator : public ResourceHeapAllocator { … }; // Implementation of ResourceMemoryAllocator ResourceMemoryAllocator::ResourceMemoryAllocator(Device* device) : … { … } ResourceMemoryAllocator::~ResourceMemoryAllocator() = default; ResultOrError<ResourceMemoryAllocation> ResourceMemoryAllocator::Allocate( const VkMemoryRequirements& requirements, MemoryKind kind, bool forceDisableSubAllocation) { … } void ResourceMemoryAllocator::Deallocate(ResourceMemoryAllocation* allocation) { … } void ResourceMemoryAllocator::Tick(ExecutionSerial completedSerial) { … } int ResourceMemoryAllocator::FindBestTypeIndex(VkMemoryRequirements requirements, MemoryKind kind) { … } void ResourceMemoryAllocator::DestroyPool() { … } } // namespace dawn::native::vulkan