• 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 GrVkAMDMemoryAllocator_DEFINED
9 #define GrVkAMDMemoryAllocator_DEFINED
10 
11 #include "include/gpu/vk/GrVkMemoryAllocator.h"
12 
13 class GrVkCaps;
14 class GrVkExtensions;
15 struct GrVkInterface;
16 
17 #ifndef SK_USE_VMA
18 class GrVkAMDMemoryAllocator {
19 public:
20     static sk_sp<GrVkMemoryAllocator> Make(VkInstance instance,
21                                            VkPhysicalDevice physicalDevice,
22                                            VkDevice device,
23                                            uint32_t physicalDeviceVersion,
24                                            const GrVkExtensions* extensions,
25                                            sk_sp<const GrVkInterface> interface,
26                                            const GrVkCaps* caps);
27 };
28 
29 #else
30 
31 #include "GrVulkanMemoryAllocator.h"
32 
33 class GrVkAMDMemoryAllocator : public GrVkMemoryAllocator {
34 public:
35     static sk_sp<GrVkMemoryAllocator> Make(VkInstance instance,
36                                            VkPhysicalDevice physicalDevice,
37                                            VkDevice device,
38                                            uint32_t physicalDeviceVersion,
39                                            const GrVkExtensions* extensions,
40                                            sk_sp<const GrVkInterface> interface,
41                                            const GrVkCaps* caps);
42 
43     ~GrVkAMDMemoryAllocator() override;
44 
45     VkResult allocateImageMemory(VkImage image, AllocationPropertyFlags flags,
46                                  GrVkBackendMemory*) override;
47 
48     VkResult allocateBufferMemory(VkBuffer buffer, BufferUsage usage,
49                                   AllocationPropertyFlags flags, GrVkBackendMemory*) override;
50 
51     void freeMemory(const GrVkBackendMemory&) override;
52 
53     void getAllocInfo(const GrVkBackendMemory&, GrVkAlloc*) const override;
54 
55     VkResult mapMemory(const GrVkBackendMemory&, void** data) override;
56     void unmapMemory(const GrVkBackendMemory&) override;
57 
58     VkResult flushMemory(const GrVkBackendMemory&, VkDeviceSize offset, VkDeviceSize size) override;
59     VkResult invalidateMemory(const GrVkBackendMemory&, VkDeviceSize offset,
60                               VkDeviceSize size) override;
61 
62     uint64_t totalUsedMemory() const override;
63     uint64_t totalAllocatedMemory() const override;
64 
65 private:
66     GrVkAMDMemoryAllocator(VmaAllocator allocator, sk_sp<const GrVkInterface> interface,
67                            bool mustUseCoherentHostVisibleMemory);
68 
69     VmaAllocator fAllocator;
70 
71     // If a future version of the AMD allocator has helper functions for flushing and invalidating
72     // memory, then we won't need to save the GrVkInterface here since we won't need to make direct
73     // vulkan calls.
74     sk_sp<const GrVkInterface> fInterface;
75 
76     // For host visible allocations do we require they are coherent or not. All devices are required
77     // to support a host visible and coherent memory type. This is used to work around bugs for
78     // devices that don't handle non coherent memory correctly.
79     bool fMustUseCoherentHostVisibleMemory;
80 
81     using INHERITED = GrVkMemoryAllocator;
82 };
83 
84 #endif // SK_USE_VMA
85 
86 #endif
87