| Flutter Impeller |

vma.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_VMA_H_
6 #define FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_VMA_H_
7
8 #include "flutter/flutter_vma/flutter_vma.h"
9 #include "flutter/fml/trace_event.h"
10 #include "flutter/fml/unique_object.h"
11 #include "impeller/renderer/backend/vulkan/vk.h"
12
13 namespace impeller {
14
15 // -----------------------------------------------------------------------------
16 // Unique handles to VMA allocators.
17 // -----------------------------------------------------------------------------
18 struct AllocatorVMATraits {
19 static VmaAllocator InvalidValue() { return {}; }
20
21 static bool IsValid(const VmaAllocator& value) {
22 return value != InvalidValue();
23 }
24
25 static void Free(VmaAllocator allocator) {
26 TRACE_EVENT0("impeller", "DestroyAllocator");
27 ::vmaDestroyAllocator(allocator);
28 }
29 };
30
31 using UniqueAllocatorVMA = fml::UniqueObject<VmaAllocator, AllocatorVMATraits>;
32
33 // -----------------------------------------------------------------------------
34 // Unique handles to VMA pools.
35 // -----------------------------------------------------------------------------
36
37 struct PoolVMA {
38 VmaAllocator allocator = {};
39 VmaPool pool = {};
40
41 constexpr bool operator==(const PoolVMA& other) const = default;
42 };
43
44 struct PoolVMATraits {
45 static PoolVMA InvalidValue() { return {}; }
46
47 static bool IsValid(const PoolVMA& value) {
48 return value.allocator != VmaAllocator{};
49 }
50
51 static void Free(const PoolVMA& pool) {
52 TRACE_EVENT0("impeller", "DestroyPool");
53 ::vmaDestroyPool(pool.allocator, pool.pool);
54 }
55 };
56
57 using UniquePoolVMA = fml::UniqueObject<PoolVMA, PoolVMATraits>;
58
59 // -----------------------------------------------------------------------------
60 // Unique handles to VMA buffers.
61 // -----------------------------------------------------------------------------
62
63 struct BufferVMA {
64 VmaAllocator allocator = {};
65 VmaAllocation allocation = {};
66 vk::Buffer buffer = {};
67
68 constexpr bool operator==(const BufferVMA& other) const {
69 return allocator == other.allocator && allocation == other.allocation &&
70 buffer == other.buffer;
71 }
72
73 constexpr bool operator!=(const BufferVMA& other) const {
74 return !(*this == other);
75 }
76 };
77
78 struct BufferVMATraits {
79 static BufferVMA InvalidValue() { return {}; }
80
81 static bool IsValid(const BufferVMA& value) {
82 return value.allocator != VmaAllocator{};
83 }
84
85 static void Free(const BufferVMA& buffer) {
86 TRACE_EVENT0("impeller", "DestroyBuffer");
87 ::vmaDestroyBuffer(buffer.allocator, static_cast<VkBuffer>(buffer.buffer),
88 buffer.allocation);
89 }
90 };
91
92 using UniqueBufferVMA = fml::UniqueObject<BufferVMA, BufferVMATraits>;
93
94 // -----------------------------------------------------------------------------
95 // Unique handles to VMA images.
96 // -----------------------------------------------------------------------------
97
98 struct ImageVMA {
99 VmaAllocator allocator = {};
100 VmaAllocation allocation = {};
101 vk::Image image = {};
102
103 constexpr bool operator==(const ImageVMA& other) const {
104 return allocator == other.allocator && allocation == other.allocation &&
105 image == other.image;
106 }
107
108 constexpr bool operator!=(const ImageVMA& other) const {
109 return !(*this == other);
110 }
111 };
112
113 struct ImageVMATraits {
114 static ImageVMA InvalidValue() { return {}; }
115
116 static bool IsValid(const ImageVMA& value) {
117 return value.allocator != VmaAllocator{};
118 }
119
120 static void Free(const ImageVMA& image) {
121 TRACE_EVENT0("impeller", "DestroyImage");
122 ::vmaDestroyImage(image.allocator, static_cast<VkImage>(image.image),
123 image.allocation);
124 }
125 };
126
127 using UniqueImageVMA = fml::UniqueObject<ImageVMA, ImageVMATraits>;
128
129 } // namespace impeller
130
131 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_VMA_H_
value
int32_t value
Definition: dl_golden_unittests.cc:459
impeller
Definition: allocation.cc:12
impeller::UniqueAllocatorVMA
fml::UniqueObject< VmaAllocator, AllocatorVMATraits > UniqueAllocatorVMA
Definition: vma.h:31
impeller::UniquePoolVMA
fml::UniqueObject< PoolVMA, PoolVMATraits > UniquePoolVMA
Definition: vma.h:57
impeller::UniqueImageVMA
fml::UniqueObject< ImageVMA, ImageVMATraits > UniqueImageVMA
Definition: vma.h:127
impeller::UniqueBufferVMA
fml::UniqueObject< BufferVMA, BufferVMATraits > UniqueBufferVMA
Definition: vma.h:92
impeller::AllocatorVMATraits
Definition: vma.h:18
impeller::AllocatorVMATraits::InvalidValue
static VmaAllocator InvalidValue()
Definition: vma.h:19
impeller::AllocatorVMATraits::IsValid
static bool IsValid(const VmaAllocator &value)
Definition: vma.h:21
impeller::AllocatorVMATraits::Free
static void Free(VmaAllocator allocator)
Definition: vma.h:25
impeller::BufferVMA
Definition: vma.h:63
impeller::BufferVMA::operator==
constexpr bool operator==(const BufferVMA &other) const
Definition: vma.h:68
impeller::BufferVMA::allocator
VmaAllocator allocator
Definition: vma.h:64
impeller::BufferVMA::buffer
vk::Buffer buffer
Definition: vma.h:66
impeller::BufferVMA::allocation
VmaAllocation allocation
Definition: vma.h:65
impeller::BufferVMA::operator!=
constexpr bool operator!=(const BufferVMA &other) const
Definition: vma.h:73
impeller::BufferVMATraits
Definition: vma.h:78
impeller::BufferVMATraits::InvalidValue
static BufferVMA InvalidValue()
Definition: vma.h:79
impeller::BufferVMATraits::IsValid
static bool IsValid(const BufferVMA &value)
Definition: vma.h:81
impeller::BufferVMATraits::Free
static void Free(const BufferVMA &buffer)
Definition: vma.h:85
impeller::ImageVMA
Definition: vma.h:98
impeller::ImageVMA::allocator
VmaAllocator allocator
Definition: vma.h:99
impeller::ImageVMA::operator!=
constexpr bool operator!=(const ImageVMA &other) const
Definition: vma.h:108
impeller::ImageVMA::operator==
constexpr bool operator==(const ImageVMA &other) const
Definition: vma.h:103
impeller::ImageVMA::allocation
VmaAllocation allocation
Definition: vma.h:100
impeller::ImageVMA::image
vk::Image image
Definition: vma.h:101
impeller::ImageVMATraits
Definition: vma.h:113
impeller::ImageVMATraits::InvalidValue
static ImageVMA InvalidValue()
Definition: vma.h:114
impeller::ImageVMATraits::IsValid
static bool IsValid(const ImageVMA &value)
Definition: vma.h:116
impeller::ImageVMATraits::Free
static void Free(const ImageVMA &image)
Definition: vma.h:120
impeller::PoolVMA
Definition: vma.h:37
impeller::PoolVMA::allocator
VmaAllocator allocator
Definition: vma.h:38
impeller::PoolVMA::operator==
constexpr bool operator==(const PoolVMA &other) const =default
impeller::PoolVMA::pool
VmaPool pool
Definition: vma.h:39
impeller::PoolVMATraits
Definition: vma.h:44
impeller::PoolVMATraits::InvalidValue
static PoolVMA InvalidValue()
Definition: vma.h:45
impeller::PoolVMATraits::Free
static void Free(const PoolVMA &pool)
Definition: vma.h:51
impeller::PoolVMATraits::IsValid
static bool IsValid(const PoolVMA &value)
Definition: vma.h:47
vk.h