| 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 {
42 return allocator == other.allocator && pool == other.pool;
43 }
44
45 constexpr bool operator!=(const PoolVMA& other) const {
46 return !(*this == other);
47 }
48 };
49
50 struct PoolVMATraits {
51 static PoolVMA InvalidValue() { return {}; }
52
53 static bool IsValid(const PoolVMA& value) {
54 return value.allocator != VmaAllocator{};
55 }
56
57 static void Free(const PoolVMA& pool) {
58 TRACE_EVENT0("impeller", "DestroyPool");
59 ::vmaDestroyPool(pool.allocator, pool.pool);
60 }
61 };
62
63 using UniquePoolVMA = fml::UniqueObject<PoolVMA, PoolVMATraits>;
64
65 // -----------------------------------------------------------------------------
66 // Unique handles to VMA buffers.
67 // -----------------------------------------------------------------------------
68
69 struct BufferVMA {
70 VmaAllocator allocator = {};
71 VmaAllocation allocation = {};
72 vk::Buffer buffer = {};
73
74 constexpr bool operator==(const BufferVMA& other) const {
75 return allocator == other.allocator && allocation == other.allocation &&
76 buffer == other.buffer;
77 }
78
79 constexpr bool operator!=(const BufferVMA& other) const {
80 return !(*this == other);
81 }
82 };
83
84 struct BufferVMATraits {
85 static BufferVMA InvalidValue() { return {}; }
86
87 static bool IsValid(const BufferVMA& value) {
88 return value.allocator != VmaAllocator{};
89 }
90
91 static void Free(const BufferVMA& buffer) {
92 TRACE_EVENT0("impeller", "DestroyBuffer");
93 ::vmaDestroyBuffer(buffer.allocator, static_cast<VkBuffer>(buffer.buffer),
94 buffer.allocation);
95 }
96 };
97
98 using UniqueBufferVMA = fml::UniqueObject<BufferVMA, BufferVMATraits>;
99
100 // -----------------------------------------------------------------------------
101 // Unique handles to VMA images.
102 // -----------------------------------------------------------------------------
103
104 struct ImageVMA {
105 VmaAllocator allocator = {};
106 VmaAllocation allocation = {};
107 vk::Image image = {};
108
109 constexpr bool operator==(const ImageVMA& other) const {
110 return allocator == other.allocator && allocation == other.allocation &&
111 image == other.image;
112 }
113
114 constexpr bool operator!=(const ImageVMA& other) const {
115 return !(*this == other);
116 }
117 };
118
119 struct ImageVMATraits {
120 static ImageVMA InvalidValue() { return {}; }
121
122 static bool IsValid(const ImageVMA& value) {
123 return value.allocator != VmaAllocator{};
124 }
125
126 static void Free(const ImageVMA& image) {
127 TRACE_EVENT0("impeller", "DestroyImage");
128 ::vmaDestroyImage(image.allocator, static_cast<VkImage>(image.image),
129 image.allocation);
130 }
131 };
132
133 using UniqueImageVMA = fml::UniqueObject<ImageVMA, ImageVMATraits>;
134
135 } // namespace impeller
136
137 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_VMA_H_
impeller::BufferVMA::buffer
vk::Buffer buffer
Definition: vma.h:72
impeller::ImageVMA::operator!=
constexpr bool operator!=(const ImageVMA &other) const
Definition: vma.h:114
impeller::ImageVMATraits::IsValid
static bool IsValid(const ImageVMA &value)
Definition: vma.h:122
impeller::PoolVMATraits::Free
static void Free(const PoolVMA &pool)
Definition: vma.h:57
impeller::ImageVMA::image
vk::Image image
Definition: vma.h:107
impeller::AllocatorVMATraits
Definition: vma.h:18
impeller::PoolVMA::allocator
VmaAllocator allocator
Definition: vma.h:38
impeller::AllocatorVMATraits::InvalidValue
static VmaAllocator InvalidValue()
Definition: vma.h:19
impeller::UniquePoolVMA
fml::UniqueObject< PoolVMA, PoolVMATraits > UniquePoolVMA
Definition: vma.h:63
impeller::BufferVMA::operator==
constexpr bool operator==(const BufferVMA &other) const
Definition: vma.h:74
impeller::PoolVMA
Definition: vma.h:37
impeller::ImageVMA::allocation
VmaAllocation allocation
Definition: vma.h:106
impeller::ImageVMATraits::InvalidValue
static ImageVMA InvalidValue()
Definition: vma.h:120
impeller::PoolVMA::operator==
constexpr bool operator==(const PoolVMA &other) const
Definition: vma.h:41
impeller::BufferVMATraits::InvalidValue
static BufferVMA InvalidValue()
Definition: vma.h:85
impeller::AllocatorVMATraits::IsValid
static bool IsValid(const VmaAllocator &value)
Definition: vma.h:21
vk.h
impeller::ImageVMA
Definition: vma.h:104
impeller::BufferVMA
Definition: vma.h:69
impeller::BufferVMA::allocator
VmaAllocator allocator
Definition: vma.h:70
impeller::PoolVMA::operator!=
constexpr bool operator!=(const PoolVMA &other) const
Definition: vma.h:45
impeller::BufferVMATraits
Definition: vma.h:84
impeller::ImageVMATraits::Free
static void Free(const ImageVMA &image)
Definition: vma.h:126
impeller::ImageVMATraits
Definition: vma.h:119
impeller::PoolVMATraits::InvalidValue
static PoolVMA InvalidValue()
Definition: vma.h:51
impeller::PoolVMA::pool
VmaPool pool
Definition: vma.h:39
impeller::BufferVMA::operator!=
constexpr bool operator!=(const BufferVMA &other) const
Definition: vma.h:79
impeller::UniqueAllocatorVMA
fml::UniqueObject< VmaAllocator, AllocatorVMATraits > UniqueAllocatorVMA
Definition: vma.h:31
impeller::ImageVMA::operator==
constexpr bool operator==(const ImageVMA &other) const
Definition: vma.h:109
impeller::ImageVMA::allocator
VmaAllocator allocator
Definition: vma.h:105
impeller::AllocatorVMATraits::Free
static void Free(VmaAllocator allocator)
Definition: vma.h:25
impeller::BufferVMATraits::Free
static void Free(const BufferVMA &buffer)
Definition: vma.h:91
impeller::UniqueBufferVMA
fml::UniqueObject< BufferVMA, BufferVMATraits > UniqueBufferVMA
Definition: vma.h:98
impeller::BufferVMATraits::IsValid
static bool IsValid(const BufferVMA &value)
Definition: vma.h:87
impeller::BufferVMA::allocation
VmaAllocation allocation
Definition: vma.h:71
impeller
Definition: allocation.cc:12
impeller::PoolVMATraits
Definition: vma.h:50
impeller::PoolVMATraits::IsValid
static bool IsValid(const PoolVMA &value)
Definition: vma.h:53
impeller::UniqueImageVMA
fml::UniqueObject< ImageVMA, ImageVMATraits > UniqueImageVMA
Definition: vma.h:133