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 
12 #include "include/gpu/vk/GrVkMemoryAllocator.h"
13 
14 #include "GrVulkanMemoryAllocator.h"
15 
16 struct GrVkInterface;
17 
18 class GrVkAMDMemoryAllocator : public GrVkMemoryAllocator {
19 public:
20     GrVkAMDMemoryAllocator(VkPhysicalDevice physicalDevice, VkDevice device,
21                            sk_sp<const GrVkInterface> interface);
22 
23     ~GrVkAMDMemoryAllocator() override;
24 
25     bool allocateMemoryForImage(VkImage image, AllocationPropertyFlags flags, GrVkBackendMemory*) override;
26 
27     bool allocateMemoryForBuffer(VkBuffer buffer, BufferUsage usage,
28                                  AllocationPropertyFlags flags, GrVkBackendMemory*) override;
29 
30     void freeMemory(const GrVkBackendMemory&) override;
31 
32     void getAllocInfo(const GrVkBackendMemory&, GrVkAlloc*) const override;
33 
34     void* mapMemory(const GrVkBackendMemory&) override;
35     void unmapMemory(const GrVkBackendMemory&) override;
36 
37     void flushMappedMemory(const GrVkBackendMemory&, VkDeviceSize offset,
38                            VkDeviceSize size) override;
39     void invalidateMappedMemory(const GrVkBackendMemory&, VkDeviceSize offset,
40                                 VkDeviceSize size) override;
41 
42     uint64_t totalUsedMemory() const override;
43     uint64_t totalAllocatedMemory() const override;
44 
45 private:
46     VmaAllocator fAllocator;
47 
48     // If a future version of the AMD allocator has helper functions for flushing and invalidating
49     // memory, then we won't need to save the GrVkInterface here since we won't need to make direct
50     // vulkan calls.
51     sk_sp<const GrVkInterface> fInterface;
52     VkDevice fDevice;
53 
54     typedef GrVkMemoryAllocator INHERITED;
55 };
56 
57 #endif
58