Debian Codegraph @

tools/gpu/vk/VkTestMemoryAllocator.h

raw
1 /*
2 * Copyright 2024 Google LLC
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 VkTestMemoryAllocator_DEFINED
9 #define VkTestMemoryAllocator_DEFINED
10
11 #include "include/gpu/vk/VulkanMemoryAllocator.h"
12
13 #if defined(__clang__)
14 #pragma clang diagnostic push
15 #pragma clang diagnostic ignored "-Wc++98-compat-extra-semi"
16 #endif
17
18 #include <vk_mem_alloc.h>
19
20 #if defined(__clang__)
21 #pragma clang diagnostic pop
22 #endif
23
24 namespace skgpu {
25 class VulkanExtensions;
26 struct VulkanInterface;
27 } // namespace skgpu
28
29 namespace sk_gpu_test {
30
31 // A test-only Vulkan memory allocator. Based on
32 // https://skia.googlesource.com/skia/+/c3fbd20fbc7d3662dd31a0e4139226d2951d1ae4/src/gpu/vk/VulkanAMDMemoryAllocator.h.
33 class VkTestMemoryAllocator : public skgpu::VulkanMemoryAllocator {
34 public:
35 static sk_sp<VulkanMemoryAllocator> Make(VkInstance instance,
36 VkPhysicalDevice physicalDevice,
37 VkDevice device,
38 uint32_t physicalDeviceVersion,
39 const skgpu::VulkanExtensions* extensions,
40 const skgpu::VulkanInterface* interface);
41
42 ~VkTestMemoryAllocator() override;
43
44 VkResult allocateImageMemory(VkImage image,
45 uint32_t allocationPropertyFlags,
46 skgpu::VulkanBackendMemory*) override;
47
48 VkResult allocateBufferMemory(VkBuffer buffer,
49 BufferUsage usage,
50 uint32_t allocationPropertyFlags,
51 skgpu::VulkanBackendMemory*) override;
52
53 void freeMemory(const skgpu::VulkanBackendMemory&) override;
54
55 void getAllocInfo(const skgpu::VulkanBackendMemory&, skgpu::VulkanAlloc*) const override;
56
57 VkResult mapMemory(const skgpu::VulkanBackendMemory&, void** data) override;
58 void unmapMemory(const skgpu::VulkanBackendMemory&) override;
59
60 VkResult flushMemory(const skgpu::VulkanBackendMemory&,
61 VkDeviceSize offset,
62 VkDeviceSize size) override;
63 VkResult invalidateMemory(const skgpu::VulkanBackendMemory&,
64 VkDeviceSize offset,
65 VkDeviceSize size) override;
66
67 std::pair<uint64_t, uint64_t> totalAllocatedAndUsedMemory() const override;
68
69 private:
70 VkTestMemoryAllocator(VmaAllocator allocator);
71
72 VmaAllocator fAllocator;
73 };
74
75 } // namespace sk_gpu_test
76
77 #endif // VkTestMemoryAllocator_DEFINED