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/gpu/vk/VulkanMemoryAllocator.h" 12 #include "src/gpu/vk/vulkanmemoryallocator/VulkanMemoryAllocatorWrapper.h" 13 #include "include/core/SkRefCnt.h" 14 #include "include/gpu/vk/VulkanTypes.h" 15 #include "include/private/gpu/vk/SkiaVulkan.h" 16 17 #include <cstdint> 18 #include <utility> 19 20 namespace skgpu { 21 22 class VulkanExtensions; 23 struct VulkanInterface; 24 25 enum class ThreadSafe : bool { 26 kNo = false, 27 kYes = true, 28 }; 29 30 class VulkanAMDMemoryAllocator : public VulkanMemoryAllocator { 31 public: 32 static sk_sp<VulkanMemoryAllocator> Make(VkInstance instance, 33 VkPhysicalDevice physicalDevice, 34 VkDevice device, 35 uint32_t physicalDeviceVersion, 36 const VulkanExtensions* extensions, 37 const VulkanInterface* interface, 38 ThreadSafe); 39 40 ~VulkanAMDMemoryAllocator() override; 41 42 VkResult allocateImageMemory(VkImage image, uint32_t allocationPropertyFlags, 43 skgpu::VulkanBackendMemory*) override; 44 45 VkResult allocateBufferMemory(VkBuffer buffer, 46 BufferUsage usage, 47 uint32_t allocationPropertyFlags, 48 skgpu::VulkanBackendMemory*) override; 49 50 void freeMemory(const VulkanBackendMemory&) override; 51 52 void getAllocInfo(const VulkanBackendMemory&, VulkanAlloc*) const override; 53 54 VkResult mapMemory(const VulkanBackendMemory&, void** data) override; 55 void unmapMemory(const VulkanBackendMemory&) override; 56 57 VkResult flushMemory(const VulkanBackendMemory&, VkDeviceSize offset, 58 VkDeviceSize size) override; 59 VkResult invalidateMemory(const VulkanBackendMemory&, VkDeviceSize offset, 60 VkDeviceSize size) override; 61 62 std::pair<uint64_t, uint64_t> totalAllocatedAndUsedMemory() const override; 63 64 private: 65 VulkanAMDMemoryAllocator(VmaAllocator allocator); 66 67 VmaAllocator fAllocator; 68 }; 69 70 } // namespace skgpu 71 72 #endif // skgpu_VulkanAMDMemoryAllocator_DEFINED 73