1 /* 2 * Copyright 2018 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef skgpu_VulkanAMDMemoryAllocator_DEFINED 9 #define skgpu_VulkanAMDMemoryAllocator_DEFINED 10 11 #include "include/core/SkRefCnt.h" 12 #include "include/gpu/vk/VulkanMemoryAllocator.h" 13 #include "include/gpu/vk/VulkanTypes.h" 14 #include "include/private/gpu/vk/SkiaVulkan.h" 15 #include "src/gpu/vk/vulkanmemoryallocator/VulkanMemoryAllocatorWrapper.h" 16 17 #include <cstdint> 18 #include <optional> 19 #include <utility> 20 21 namespace skgpu { 22 23 class VulkanExtensions; 24 enum class ThreadSafe : bool; 25 struct VulkanInterface; 26 27 class VulkanAMDMemoryAllocator : public VulkanMemoryAllocator { 28 public: 29 static sk_sp<VulkanMemoryAllocator> Make(VkInstance instance, 30 VkPhysicalDevice physicalDevice, 31 VkDevice device, 32 uint32_t physicalDeviceVersion, 33 const VulkanExtensions* extensions, 34 const VulkanInterface* interface, 35 ThreadSafe, 36 std::optional<VkDeviceSize> blockSize); 37 38 ~VulkanAMDMemoryAllocator() override; 39 40 VkResult allocateImageMemory(VkImage image, 41 uint32_t allocationPropertyFlags, 42 skgpu::VulkanBackendMemory*) override; 43 44 VkResult allocateBufferMemory(VkBuffer buffer, 45 BufferUsage usage, 46 uint32_t allocationPropertyFlags, 47 skgpu::VulkanBackendMemory*) override; 48 49 void freeMemory(const VulkanBackendMemory&) override; 50 51 void getAllocInfo(const VulkanBackendMemory&, VulkanAlloc*) const override; 52 53 VkResult mapMemory(const VulkanBackendMemory&, void** data) override; 54 void unmapMemory(const VulkanBackendMemory&) override; 55 56 VkResult flushMemory(const VulkanBackendMemory&, 57 VkDeviceSize offset, 58 VkDeviceSize size) override; 59 VkResult invalidateMemory(const VulkanBackendMemory&, 60 VkDeviceSize offset, 61 VkDeviceSize size) override; 62 63 std::pair<uint64_t, uint64_t> totalAllocatedAndUsedMemory() const override; 64 65 private: 66 VulkanAMDMemoryAllocator(VmaAllocator allocator); 67 68 VmaAllocator fAllocator; 69 }; 70 71 } // namespace skgpu 72 73 #endif // skgpu_VulkanAMDMemoryAllocator_DEFINED 74