• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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                                              bool cacheFlag = false,
38                                              size_t maxBlockCount = SIZE_MAX);
39 
40     ~VulkanAMDMemoryAllocator() override;
41 
42     VkResult allocateImageMemory(VkImage image,
43                                  uint32_t allocationPropertyFlags,
44                                  skgpu::VulkanBackendMemory*) override;
45 
46     VkResult allocateBufferMemory(VkBuffer buffer,
47                                   BufferUsage usage,
48                                   uint32_t allocationPropertyFlags,
49                                   skgpu::VulkanBackendMemory*) override;
50 
51     void freeMemory(const VulkanBackendMemory&) override;
52 
53     void getAllocInfo(const VulkanBackendMemory&, VulkanAlloc*) const override;
54 
55     VkResult mapMemory(const VulkanBackendMemory&, void** data) override;
56     void unmapMemory(const VulkanBackendMemory&) override;
57 
58     VkResult flushMemory(const VulkanBackendMemory&,
59                          VkDeviceSize offset,
60                          VkDeviceSize size) override;
61     VkResult invalidateMemory(const VulkanBackendMemory&,
62                               VkDeviceSize offset,
63                               VkDeviceSize size) override;
64 
65     std::pair<uint64_t, uint64_t> totalAllocatedAndUsedMemory() const override;
66 
67     void vmaDefragment() override;
68     void dumpVmaStats(SkString *out, const char *sep = ", ") const override;
69 
70 private:
71     VulkanAMDMemoryAllocator(VmaAllocator allocator);
72 
73     VmaAllocator fAllocator;
74 };
75 
76 }  // namespace skgpu
77 
78 #endif  // skgpu_VulkanAMDMemoryAllocator_DEFINED
79