Flutter Engine
The Flutter Engine
capabilities_vk.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_CAPABILITIES_VK_H_
6#define FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_CAPABILITIES_VK_H_
7
8#include <cstdint>
9#include <map>
10#include <set>
11#include <string>
12#include <vector>
13
17
18namespace impeller {
19
20class ContextVK;
21
22//------------------------------------------------------------------------------
23/// @brief A device extension available on all platforms. Without the
24/// presence of these extensions, context creation will fail.
25///
26enum class RequiredCommonDeviceExtensionVK : uint32_t {
27 //----------------------------------------------------------------------------
28 /// For displaying content in the window system.
29 ///
30 /// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_KHR_swapchain.html
31 ///
33
34 kLast,
35};
36
37//------------------------------------------------------------------------------
38/// @brief A device extension available on all Android platforms. Without
39/// the presence of these extensions on Android, context creation
40/// will fail.
41///
42/// Platform agnostic code can still check if these Android
43/// extensions are present.
44///
45enum class RequiredAndroidDeviceExtensionVK : uint32_t {
46 //----------------------------------------------------------------------------
47 /// For importing hardware buffers used in external texture composition.
48 ///
49 /// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_ANDROID_external_memory_android_hardware_buffer.html
50 ///
52
53 //----------------------------------------------------------------------------
54 /// Dependency of kANDROIDExternalMemoryAndroidHardwareBuffer.
55 ///
56 /// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_KHR_sampler_ycbcr_conversion.html
57 ///
59
60 //----------------------------------------------------------------------------
61 /// Dependency of kANDROIDExternalMemoryAndroidHardwareBuffer.
62 ///
63 /// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_KHR_external_memory.html
64 ///
66
67 //----------------------------------------------------------------------------
68 /// Dependency of kANDROIDExternalMemoryAndroidHardwareBuffer.
69 ///
70 /// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_EXT_queue_family_foreign.html
71 ///
73
74 //----------------------------------------------------------------------------
75 /// Dependency of kANDROIDExternalMemoryAndroidHardwareBuffer.
76 ///
77 /// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_KHR_dedicated_allocation.html
78 ///
80
81 //----------------------------------------------------------------------------
82 /// For exporting file descriptors from fences to interact with platform APIs.
83 ///
84 /// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_KHR_external_fence_fd.html
85 ///
87
88 //----------------------------------------------------------------------------
89 /// Dependency of kKHRExternalFenceFd.
90 ///
91 /// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_KHR_external_fence.html
92 ///
94
95 //----------------------------------------------------------------------------
96 /// For importing sync file descriptors as semaphores so the GPU can wait for
97 /// semaphore to be signaled.
98 ///
99 /// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_KHR_external_semaphore_fd.html
101
102 //----------------------------------------------------------------------------
103 /// Dependency of kKHRExternalSemaphoreFd
104 ///
105 /// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_KHR_external_semaphore.html
107
108 kLast,
109};
110
111//------------------------------------------------------------------------------
112/// @brief A device extension enabled if available. Subsystems cannot
113/// assume availability and must check if these extensions are
114/// available.
115///
116/// @see `CapabilitiesVK::HasExtension`.
117///
118enum class OptionalDeviceExtensionVK : uint32_t {
119 //----------------------------------------------------------------------------
120 /// To instrument and profile PSO creation.
121 ///
122 /// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_EXT_pipeline_creation_feedback.html
123 ///
125
126 //----------------------------------------------------------------------------
127 /// To enable context creation on MoltenVK. A non-conformant Vulkan
128 /// implementation.
129 ///
130 /// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_KHR_portability_subset.html
131 ///
133
134 kLast,
135};
136
137//------------------------------------------------------------------------------
138/// @brief The Vulkan layers and extensions wrangler.
139///
140class CapabilitiesVK final : public Capabilities,
141 public BackendCast<CapabilitiesVK, Capabilities> {
142 public:
143 explicit CapabilitiesVK(bool enable_validations,
144 bool fatal_missing_validations = false);
145
147
148 bool IsValid() const;
149
150 bool AreValidationsEnabled() const;
151
153
155
157
158 std::optional<std::vector<std::string>> GetEnabledLayers() const;
159
160 std::optional<std::vector<std::string>> GetEnabledInstanceExtensions() const;
161
162 std::optional<std::vector<std::string>> GetEnabledDeviceExtensions(
163 const vk::PhysicalDevice& physical_device) const;
164
166 vk::StructureChain<vk::PhysicalDeviceFeatures2,
167 vk::PhysicalDeviceSamplerYcbcrConversionFeaturesKHR,
168 vk::PhysicalDevice16BitStorageFeatures>;
169
170 std::optional<PhysicalDeviceFeatures> GetEnabledDeviceFeatures(
171 const vk::PhysicalDevice& physical_device) const;
172
173 [[nodiscard]] bool SetPhysicalDevice(
174 const vk::PhysicalDevice& physical_device);
175
176 const vk::PhysicalDeviceProperties& GetPhysicalDeviceProperties() const;
177
178 void SetOffscreenFormat(PixelFormat pixel_format) const;
179
180 // |Capabilities|
181 bool SupportsOffscreenMSAA() const override;
182
183 // |Capabilities|
184 bool SupportsImplicitResolvingMSAA() const override;
185
186 // |Capabilities|
187 bool SupportsSSBO() const override;
188
189 // |Capabilities|
190 bool SupportsTextureToTextureBlits() const override;
191
192 // |Capabilities|
193 bool SupportsFramebufferFetch() const override;
194
195 // |Capabilities|
196 bool SupportsCompute() const override;
197
198 // |Capabilities|
199 bool SupportsComputeSubgroups() const override;
200
201 // |Capabilities|
202 bool SupportsReadFromResolve() const override;
203
204 // |Capabilities|
205 bool SupportsDecalSamplerAddressMode() const override;
206
207 // |Capabilities|
208 bool SupportsDeviceTransientTextures() const override;
209
210 // |Capabilities|
211 PixelFormat GetDefaultColorFormat() const override;
212
213 // |Capabilities|
214 PixelFormat GetDefaultStencilFormat() const override;
215
216 // |Capabilities|
218
219 // |Capabilities|
221
222 private:
223 bool validations_enabled_ = false;
224 std::map<std::string, std::set<std::string>> exts_;
225 std::set<RequiredCommonDeviceExtensionVK> required_common_device_extensions_;
226 std::set<RequiredAndroidDeviceExtensionVK>
227 required_android_device_extensions_;
228 std::set<OptionalDeviceExtensionVK> optional_device_extensions_;
229 mutable PixelFormat default_color_format_ = PixelFormat::kUnknown;
230 PixelFormat default_stencil_format_ = PixelFormat::kUnknown;
231 PixelFormat default_depth_stencil_format_ = PixelFormat::kUnknown;
232 vk::PhysicalDeviceProperties device_properties_;
233 bool supports_compute_subgroups_ = false;
234 bool supports_device_transient_textures_ = false;
235 bool is_valid_ = false;
236
237 bool HasExtension(const std::string& ext) const;
238
239 bool HasLayer(const std::string& layer) const;
240
241 CapabilitiesVK(const CapabilitiesVK&) = delete;
242
243 CapabilitiesVK& operator=(const CapabilitiesVK&) = delete;
244};
245
246} // namespace impeller
247
248#endif // FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_CAPABILITIES_VK_H_
The Vulkan layers and extensions wrangler.
bool SupportsDeviceTransientTextures() const override
Whether the context backend supports allocating StorageMode::kDeviceTransient (aka "memoryless") text...
std::optional< std::vector< std::string > > GetEnabledInstanceExtensions() const
bool AreValidationsEnabled() const
bool SupportsSSBO() const override
Whether the context backend supports binding Shader Storage Buffer Objects (SSBOs) to pipelines.
bool SupportsFramebufferFetch() const override
Whether the context backend is able to support pipelines with shaders that read from the framebuffer ...
CapabilitiesVK(bool enable_validations, bool fatal_missing_validations=false)
vk::StructureChain< vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceSamplerYcbcrConversionFeaturesKHR, vk::PhysicalDevice16BitStorageFeatures > PhysicalDeviceFeatures
bool SupportsOffscreenMSAA() const override
Whether the context backend supports attaching offscreen MSAA color/stencil textures.
bool SupportsCompute() const override
Whether the context backend supports ComputePass.
bool HasExtension(RequiredCommonDeviceExtensionVK ext) const
void SetOffscreenFormat(PixelFormat pixel_format) const
PixelFormat GetDefaultStencilFormat() const override
Returns a supported PixelFormat for textures that store stencil information. May include a depth chan...
bool SetPhysicalDevice(const vk::PhysicalDevice &physical_device)
bool SupportsComputeSubgroups() const override
Whether the context backend supports configuring ComputePass command subgroups.
PixelFormat GetDefaultDepthStencilFormat() const override
Returns a supported PixelFormat for textures that store both a stencil and depth component....
bool SupportsTextureToTextureBlits() const override
Whether the context backend supports blitting from one texture region to another texture region (via ...
std::optional< std::vector< std::string > > GetEnabledDeviceExtensions(const vk::PhysicalDevice &physical_device) const
bool SupportsReadFromResolve() const override
Whether the context backend supports binding the current RenderPass attachments. This is supported if...
bool SupportsDecalSamplerAddressMode() const override
Whether the context backend supports SamplerAddressMode::Decal.
std::optional< std::vector< std::string > > GetEnabledLayers() const
PixelFormat GetDefaultGlyphAtlasFormat() const override
Returns the default pixel format for the alpha bitmap glyph atlas.
PixelFormat GetDefaultColorFormat() const override
Returns a supported PixelFormat for textures that store 4-channel colors (red/green/blue/alpha).
const vk::PhysicalDeviceProperties & GetPhysicalDeviceProperties() const
bool SupportsImplicitResolvingMSAA() const override
Whether the context backend supports multisampled rendering to the on-screen surface without requirin...
std::optional< PhysicalDeviceFeatures > GetEnabledDeviceFeatures(const vk::PhysicalDevice &physical_device) const
VkPhysicalDevice physical_device
Definition: main.cc:51
RequiredAndroidDeviceExtensionVK
A device extension available on all Android platforms. Without the presence of these extensions on An...
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition: formats.h:99
RequiredCommonDeviceExtensionVK
A device extension available on all platforms. Without the presence of these extensions,...
OptionalDeviceExtensionVK
A device extension enabled if available. Subsystems cannot assume availability and must check if thes...