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