| Flutter Impeller |

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 <optional>
11 #include <set>
12 #include <string>
13 #include <vector>
14
15 #include "impeller/base/backend_cast.h"
16 #include "impeller/core/texture_descriptor.h"
17 #include "impeller/renderer/backend/vulkan/vk.h"
18 #include "impeller/renderer/backend/vulkan/workarounds_vk.h"
19 #include "impeller/renderer/capabilities.h"
20
21 namespace impeller {
22
23 class ContextVK;
24
25 //------------------------------------------------------------------------------
26 /// @brief A device extension available on all platforms. Without the
27 /// presence of these extensions, context creation will fail.
28 ///
29 enum class RequiredCommonDeviceExtensionVK : uint32_t {
30 //----------------------------------------------------------------------------
31 /// For displaying content in the window system.
32 ///
33 /// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_KHR_swapchain.html
34 ///
35 kKHRSwapchain,
36
37 kLast,
38 };
39
40 //------------------------------------------------------------------------------
41 /// @brief A device extension available on all Android platforms. Without
42 /// the presence of these extensions on Android, context creation
43 /// will fail.
44 ///
45 /// Platform agnostic code can still check if these Android
46 /// extensions are present.
47 ///
48 enum class RequiredAndroidDeviceExtensionVK : uint32_t {
49 //----------------------------------------------------------------------------
50 /// For importing hardware buffers used in external texture composition.
51 ///
52 /// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_ANDROID_external_memory_android_hardware_buffer.html
53 ///
54 kANDROIDExternalMemoryAndroidHardwareBuffer,
55
56 //----------------------------------------------------------------------------
57 /// Dependency of kANDROIDExternalMemoryAndroidHardwareBuffer.
58 ///
59 /// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_KHR_sampler_ycbcr_conversion.html
60 ///
61 kKHRSamplerYcbcrConversion,
62
63 //----------------------------------------------------------------------------
64 /// Dependency of kANDROIDExternalMemoryAndroidHardwareBuffer.
65 ///
66 /// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_KHR_external_memory.html
67 ///
68 kKHRExternalMemory,
69
70 //----------------------------------------------------------------------------
71 /// Dependency of kANDROIDExternalMemoryAndroidHardwareBuffer.
72 ///
73 /// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_EXT_queue_family_foreign.html
74 ///
75 kEXTQueueFamilyForeign,
76
77 //----------------------------------------------------------------------------
78 /// Dependency of kANDROIDExternalMemoryAndroidHardwareBuffer.
79 ///
80 /// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_KHR_dedicated_allocation.html
81 ///
82 kKHRDedicatedAllocation,
83
84 //----------------------------------------------------------------------------
85 /// For exporting file descriptors from fences to interact with platform APIs.
86 ///
87 /// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_KHR_external_fence_fd.html
88 ///
89 kKHRExternalFenceFd,
90
91 //----------------------------------------------------------------------------
92 /// Dependency of kKHRExternalFenceFd.
93 ///
94 /// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_KHR_external_fence.html
95 ///
96 kKHRExternalFence,
97
98 //----------------------------------------------------------------------------
99 /// For importing sync file descriptors as semaphores so the GPU can wait for
100 /// semaphore to be signaled.
101 ///
102 /// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_KHR_external_semaphore_fd.html
103 kKHRExternalSemaphoreFd,
104
105 //----------------------------------------------------------------------------
106 /// Dependency of kKHRExternalSemaphoreFd
107 ///
108 /// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_KHR_external_semaphore.html
109 kKHRExternalSemaphore,
110
111 kLast,
112 };
113
114 //------------------------------------------------------------------------------
115 /// @brief A device extension enabled if available. Subsystems cannot
116 /// assume availability and must check if these extensions are
117 /// available.
118 ///
119 /// @see `CapabilitiesVK::HasExtension`.
120 ///
121 enum class OptionalDeviceExtensionVK : uint32_t {
122 //----------------------------------------------------------------------------
123 /// To instrument and profile PSO creation.
124 ///
125 /// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_EXT_pipeline_creation_feedback.html
126 ///
127 kEXTPipelineCreationFeedback,
128
129 //----------------------------------------------------------------------------
130 /// To enable context creation on MoltenVK. A non-conformant Vulkan
131 /// implementation.
132 ///
133 /// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_KHR_portability_subset.html
134 ///
135 kVKKHRPortabilitySubset,
136
137 //----------------------------------------------------------------------------
138 /// For fixed-rate compression of images.
139 ///
140 /// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_EXT_image_compression_control.html
141 ///
142 kEXTImageCompressionControl,
143
144 kLast,
145 };
146
147 //------------------------------------------------------------------------------
148 /// @brief A pixel format and usage that is sufficient to check if images
149 /// of that format and usage are suitable for use with fixed-rate
150 /// compression.
151 ///
152 struct FRCFormatDescriptor {
153 vk::Format format = vk::Format::eUndefined;
154 vk::ImageType type = {};
155 vk::ImageTiling tiling = {};
156 vk::ImageUsageFlags usage = {};
157 vk::ImageCreateFlags flags = {};
158
159 explicit FRCFormatDescriptor(const vk::ImageCreateInfo& image_info)
160 : format(image_info.format),
161 type(image_info.imageType),
162 tiling(image_info.tiling),
163 usage(image_info.usage),
164 flags(image_info.flags) {}
165 };
166
167 //------------------------------------------------------------------------------
168 /// @brief The Vulkan layers and extensions wrangler.
169 ///
170 class CapabilitiesVK final : public Capabilities,
171 public BackendCast<CapabilitiesVK, Capabilities> {
172 public:
173 explicit CapabilitiesVK(bool enable_validations,
174 bool fatal_missing_validations = false,
175 bool use_embedder_extensions = false,
176 std::vector<std::string> instance_extensions = {},
177 std::vector<std::string> device_extensions = {});
178
179 ~CapabilitiesVK();
180
181 bool IsValid() const;
182
183 bool AreValidationsEnabled() const;
184
185 bool HasExtension(RequiredCommonDeviceExtensionVK ext) const;
186
187 bool HasExtension(RequiredAndroidDeviceExtensionVK ext) const;
188
189 bool HasExtension(OptionalDeviceExtensionVK ext) const;
190
191 std::optional<std::vector<std::string>> GetEnabledLayers() const;
192
193 std::optional<std::vector<std::string>> GetEnabledInstanceExtensions() const;
194
195 std::optional<std::vector<std::string>> GetEnabledDeviceExtensions(
196 const vk::PhysicalDevice& physical_device) const;
197
198 using PhysicalDeviceFeatures =
199 vk::StructureChain<vk::PhysicalDeviceFeatures2,
200 vk::PhysicalDeviceSamplerYcbcrConversionFeaturesKHR,
201 vk::PhysicalDevice16BitStorageFeatures,
202 vk::PhysicalDeviceImageCompressionControlFeaturesEXT>;
203
204 std::optional<PhysicalDeviceFeatures> GetEnabledDeviceFeatures(
205 const vk::PhysicalDevice& physical_device) const;
206
207 [[nodiscard]] bool SetPhysicalDevice(
208 const vk::PhysicalDevice& physical_device,
209 const PhysicalDeviceFeatures& enabled_features);
210
211 const vk::PhysicalDeviceProperties& GetPhysicalDeviceProperties() const;
212
213 void SetOffscreenFormat(PixelFormat pixel_format) const;
214
215 // |Capabilities|
216 bool SupportsOffscreenMSAA() const override;
217
218 // |Capabilities|
219 bool SupportsImplicitResolvingMSAA() const override;
220
221 // |Capabilities|
222 bool SupportsSSBO() const override;
223
224 // |Capabilities|
225 bool SupportsTextureToTextureBlits() const override;
226
227 // |Capabilities|
228 bool SupportsFramebufferFetch() const override;
229
230 // |Capabilities|
231 bool SupportsCompute() const override;
232
233 // |Capabilities|
234 bool SupportsComputeSubgroups() const override;
235
236 // |Capabilities|
237 bool SupportsReadFromResolve() const override;
238
239 // |Capabilities|
240 bool SupportsDecalSamplerAddressMode() const override;
241
242 // |Capabilities|
243 bool SupportsDeviceTransientTextures() const override;
244
245 // |Capabilities|
246 bool SupportsTriangleFan() const override;
247
248 // |Capabilities|
249 bool SupportsPrimitiveRestart() const override;
250
251 // |Capabilities|
252 PixelFormat GetDefaultColorFormat() const override;
253
254 // |Capabilities|
255 PixelFormat GetDefaultStencilFormat() const override;
256
257 // |Capabilities|
258 PixelFormat GetDefaultDepthStencilFormat() const override;
259
260 // |Capabilities|
261 PixelFormat GetDefaultGlyphAtlasFormat() const override;
262
263 // |Capabilities|
264 ISize GetMaximumRenderPassAttachmentSize() const override;
265
266 //----------------------------------------------------------------------------
267 /// @return If fixed-rate compression for non-onscreen surfaces is
268 /// supported.
269 ///
270 bool SupportsTextureFixedRateCompression() const;
271
272 //----------------------------------------------------------------------------
273 /// @brief Get the fixed compression rate supported by the context for
274 /// the given format and usage.
275 ///
276 /// @param[in] compression_type The compression type.
277 /// @param[in] desc The format and usage of the image.
278 ///
279 /// @return The supported fixed compression rate.
280 ///
281 std::optional<vk::ImageCompressionFixedRateFlagBitsEXT> GetSupportedFRCRate(
282 CompressionType compression_type,
283 const FRCFormatDescriptor& desc) const;
284
285 //----------------------------------------------------------------------------
286 /// @brief Update capabilities for the given set of workarounds.
287 void ApplyWorkarounds(const WorkaroundsVK& workarounds);
288
289 private:
290 bool validations_enabled_ = false;
291 std::map<std::string, std::set<std::string>> exts_;
292 std::set<RequiredCommonDeviceExtensionVK> required_common_device_extensions_;
293 std::set<RequiredAndroidDeviceExtensionVK>
294 required_android_device_extensions_;
295 std::set<OptionalDeviceExtensionVK> optional_device_extensions_;
296 mutable PixelFormat default_color_format_ = PixelFormat::kUnknown;
297 PixelFormat default_stencil_format_ = PixelFormat::kUnknown;
298 PixelFormat default_depth_stencil_format_ = PixelFormat::kUnknown;
299 vk::PhysicalDevice physical_device_;
300 vk::PhysicalDeviceProperties device_properties_;
301 bool supports_compute_subgroups_ = false;
302 bool supports_device_transient_textures_ = false;
303 bool supports_texture_fixed_rate_compression_ = false;
304 ISize max_render_pass_attachment_size_ = ISize{0, 0};
305 bool has_triangle_fans_ = true;
306 bool has_primitive_restart_ = true;
307 bool has_framebuffer_fetch_ = true;
308 bool is_valid_ = false;
309
310 // The embedder.h API is responsible for providing the instance and device
311 // extensions.
312 bool use_embedder_extensions_ = false;
313 std::vector<std::string> embedder_instance_extensions_;
314 std::vector<std::string> embedder_device_extensions_;
315
316 bool HasExtension(const std::string& ext) const;
317
318 bool HasLayer(const std::string& layer) const;
319
320 CapabilitiesVK(const CapabilitiesVK&) = delete;
321
322 CapabilitiesVK& operator=(const CapabilitiesVK&) = delete;
323 };
324
325 } // namespace impeller
326
327 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_CAPABILITIES_VK_H_
backend_cast.h
capabilities.h
impeller::BackendCast
Definition: backend_cast.h:11
impeller::Capabilities
Definition: capabilities.h:14
impeller::CapabilitiesVK
The Vulkan layers and extensions wrangler.
Definition: capabilities_vk.h:171
impeller::CapabilitiesVK::SupportsTriangleFan
bool SupportsTriangleFan() const override
Whether the primitive type TriangleFan is supported by the backend.
Definition: capabilities_vk.cc:755
impeller::CapabilitiesVK::SupportsDeviceTransientTextures
bool SupportsDeviceTransientTextures() const override
Whether the context backend supports allocating StorageMode::kDeviceTransient (aka "memoryless") text...
Definition: capabilities_vk.cc:655
impeller::CapabilitiesVK::GetEnabledInstanceExtensions
std::optional< std::vector< std::string > > GetEnabledInstanceExtensions() const
Definition: capabilities_vk.cc:96
impeller::CapabilitiesVK::AreValidationsEnabled
bool AreValidationsEnabled() const
Definition: capabilities_vk.cc:79
impeller::CapabilitiesVK::SetPhysicalDevice
bool SetPhysicalDevice(const vk::PhysicalDevice &physical_device, const PhysicalDeviceFeatures &enabled_features)
Definition: capabilities_vk.cc:493
impeller::CapabilitiesVK::GetMaximumRenderPassAttachmentSize
ISize GetMaximumRenderPassAttachmentSize() const override
Return the maximum size of a render pass attachment.
Definition: capabilities_vk.cc:759
impeller::CapabilitiesVK::SupportsSSBO
bool SupportsSSBO() const override
Whether the context backend supports binding Shader Storage Buffer Objects (SSBOs) to pipelines.
Definition: capabilities_vk.cc:619
impeller::CapabilitiesVK::SupportsFramebufferFetch
bool SupportsFramebufferFetch() const override
Whether the context backend is able to support pipelines with shaders that read from the framebuffer ...
Definition: capabilities_vk.cc:629
impeller::CapabilitiesVK::CapabilitiesVK
CapabilitiesVK(bool enable_validations, bool fatal_missing_validations=false, bool use_embedder_extensions=false, std::vector< std::string > instance_extensions={}, std::vector< std::string > device_extensions={})
Definition: capabilities_vk.cc:19
impeller::CapabilitiesVK::~CapabilitiesVK
~CapabilitiesVK()
impeller::CapabilitiesVK::SupportsOffscreenMSAA
bool SupportsOffscreenMSAA() const override
Whether the context backend supports attaching offscreen MSAA color/stencil textures.
Definition: capabilities_vk.cc:609
impeller::CapabilitiesVK::SupportsCompute
bool SupportsCompute() const override
Whether the context backend supports ComputePass.
Definition: capabilities_vk.cc:634
impeller::CapabilitiesVK::HasExtension
bool HasExtension(RequiredCommonDeviceExtensionVK ext) const
Definition: capabilities_vk.cc:683
impeller::CapabilitiesVK::GetSupportedFRCRate
std::optional< vk::ImageCompressionFixedRateFlagBitsEXT > GetSupportedFRCRate(CompressionType compression_type, const FRCFormatDescriptor &desc) const
Get the fixed compression rate supported by the context for the given format and usage.
Definition: capabilities_vk.cc:703
impeller::CapabilitiesVK::SetOffscreenFormat
void SetOffscreenFormat(PixelFormat pixel_format) const
Definition: capabilities_vk.cc:489
impeller::CapabilitiesVK::GetDefaultStencilFormat
PixelFormat GetDefaultStencilFormat() const override
Returns a supported PixelFormat for textures that store stencil information. May include a depth chan...
Definition: capabilities_vk.cc:665
impeller::CapabilitiesVK::ApplyWorkarounds
void ApplyWorkarounds(const WorkaroundsVK &workarounds)
Update capabilities for the given set of workarounds.
Definition: capabilities_vk.cc:763
impeller::CapabilitiesVK::IsValid
bool IsValid() const
Definition: capabilities_vk.cc:75
impeller::CapabilitiesVK::PhysicalDeviceFeatures
vk::StructureChain< vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceSamplerYcbcrConversionFeaturesKHR, vk::PhysicalDevice16BitStorageFeatures, vk::PhysicalDeviceImageCompressionControlFeaturesEXT > PhysicalDeviceFeatures
Definition: capabilities_vk.h:202
impeller::CapabilitiesVK::SupportsComputeSubgroups
bool SupportsComputeSubgroups() const override
Whether the context backend supports configuring ComputePass command subgroups.
Definition: capabilities_vk.cc:640
impeller::CapabilitiesVK::GetDefaultDepthStencilFormat
PixelFormat GetDefaultDepthStencilFormat() const override
Returns a supported PixelFormat for textures that store both a stencil and depth component....
Definition: capabilities_vk.cc:670
impeller::CapabilitiesVK::SupportsTextureToTextureBlits
bool SupportsTextureToTextureBlits() const override
Whether the context backend supports blitting from one texture region to another texture region (via ...
Definition: capabilities_vk.cc:624
impeller::CapabilitiesVK::GetEnabledDeviceExtensions
std::optional< std::vector< std::string > > GetEnabledDeviceExtensions(const vk::PhysicalDevice &physical_device) const
Definition: capabilities_vk.cc:253
impeller::CapabilitiesVK::SupportsReadFromResolve
bool SupportsReadFromResolve() const override
Whether the context backend supports binding the current RenderPass attachments. This is supported if...
Definition: capabilities_vk.cc:646
impeller::CapabilitiesVK::SupportsDecalSamplerAddressMode
bool SupportsDecalSamplerAddressMode() const override
Whether the context backend supports SamplerAddressMode::Decal.
Definition: capabilities_vk.cc:650
impeller::CapabilitiesVK::SupportsPrimitiveRestart
bool SupportsPrimitiveRestart() const override
Whether primitive restart is supported.
Definition: capabilities_vk.cc:485
impeller::CapabilitiesVK::GetEnabledLayers
std::optional< std::vector< std::string > > GetEnabledLayers() const
Definition: capabilities_vk.cc:83
impeller::CapabilitiesVK::SupportsTextureFixedRateCompression
bool SupportsTextureFixedRateCompression() const
Definition: capabilities_vk.cc:698
impeller::CapabilitiesVK::GetDefaultGlyphAtlasFormat
PixelFormat GetDefaultGlyphAtlasFormat() const override
Returns the default pixel format for the alpha bitmap glyph atlas.
Definition: capabilities_vk.cc:679
impeller::CapabilitiesVK::GetDefaultColorFormat
PixelFormat GetDefaultColorFormat() const override
Returns a supported PixelFormat for textures that store 4-channel colors (red/green/blue/alpha).
Definition: capabilities_vk.cc:660
impeller::CapabilitiesVK::GetPhysicalDeviceProperties
const vk::PhysicalDeviceProperties & GetPhysicalDeviceProperties() const
Definition: capabilities_vk.cc:675
impeller::CapabilitiesVK::SupportsImplicitResolvingMSAA
bool SupportsImplicitResolvingMSAA() const override
Whether the context backend supports multisampled rendering to the on-screen surface without requirin...
Definition: capabilities_vk.cc:614
impeller::CapabilitiesVK::GetEnabledDeviceFeatures
std::optional< PhysicalDeviceFeatures > GetEnabledDeviceFeatures(const vk::PhysicalDevice &physical_device) const
Definition: capabilities_vk.cc:374
impeller
Definition: allocation.cc:12
impeller::RequiredAndroidDeviceExtensionVK
RequiredAndroidDeviceExtensionVK
A device extension available on all Android platforms. Without the presence of these extensions on An...
Definition: capabilities_vk.h:48
impeller::RequiredAndroidDeviceExtensionVK::kKHRExternalMemory
@ kKHRExternalMemory
impeller::RequiredAndroidDeviceExtensionVK::kKHRExternalFenceFd
@ kKHRExternalFenceFd
impeller::RequiredAndroidDeviceExtensionVK::kKHRSamplerYcbcrConversion
@ kKHRSamplerYcbcrConversion
impeller::RequiredAndroidDeviceExtensionVK::kKHRExternalSemaphore
@ kKHRExternalSemaphore
impeller::RequiredAndroidDeviceExtensionVK::kKHRExternalFence
@ kKHRExternalFence
impeller::RequiredAndroidDeviceExtensionVK::kKHRDedicatedAllocation
@ kKHRDedicatedAllocation
impeller::RequiredAndroidDeviceExtensionVK::kKHRExternalSemaphoreFd
@ kKHRExternalSemaphoreFd
impeller::RequiredAndroidDeviceExtensionVK::kLast
@ kLast
impeller::RequiredAndroidDeviceExtensionVK::kEXTQueueFamilyForeign
@ kEXTQueueFamilyForeign
impeller::RequiredAndroidDeviceExtensionVK::kANDROIDExternalMemoryAndroidHardwareBuffer
@ kANDROIDExternalMemoryAndroidHardwareBuffer
impeller::PixelFormat
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition: formats.h:99
impeller::PixelFormat::kUnknown
@ kUnknown
impeller::RequiredCommonDeviceExtensionVK
RequiredCommonDeviceExtensionVK
A device extension available on all platforms. Without the presence of these extensions,...
Definition: capabilities_vk.h:29
impeller::RequiredCommonDeviceExtensionVK::kKHRSwapchain
@ kKHRSwapchain
impeller::RequiredCommonDeviceExtensionVK::kLast
@ kLast
impeller::CompressionType
CompressionType
Additional compression to apply to a texture. This value is ignored on platforms which do not support...
Definition: texture_descriptor.h:19
impeller::OptionalDeviceExtensionVK
OptionalDeviceExtensionVK
A device extension enabled if available. Subsystems cannot assume availability and must check if thes...
Definition: capabilities_vk.h:121
impeller::OptionalDeviceExtensionVK::kEXTImageCompressionControl
@ kEXTImageCompressionControl
impeller::OptionalDeviceExtensionVK::kLast
@ kLast
impeller::OptionalDeviceExtensionVK::kVKKHRPortabilitySubset
@ kVKKHRPortabilitySubset
impeller::OptionalDeviceExtensionVK::kEXTPipelineCreationFeedback
@ kEXTPipelineCreationFeedback
impeller::FRCFormatDescriptor
A pixel format and usage that is sufficient to check if images of that format and usage are suitable ...
Definition: capabilities_vk.h:152
impeller::FRCFormatDescriptor::tiling
vk::ImageTiling tiling
Definition: capabilities_vk.h:155
impeller::FRCFormatDescriptor::usage
vk::ImageUsageFlags usage
Definition: capabilities_vk.h:156
impeller::FRCFormatDescriptor::flags
vk::ImageCreateFlags flags
Definition: capabilities_vk.h:157
impeller::FRCFormatDescriptor::type
vk::ImageType type
Definition: capabilities_vk.h:154
impeller::FRCFormatDescriptor::format
vk::Format format
Definition: capabilities_vk.h:153
impeller::FRCFormatDescriptor::FRCFormatDescriptor
FRCFormatDescriptor(const vk::ImageCreateInfo &image_info)
Definition: capabilities_vk.h:159
impeller::TSize
Definition: size.h:25
impeller::WorkaroundsVK
A non-exhaustive set of driver specific workarounds.
Definition: workarounds_vk.h:13
texture_descriptor.h
vk.h
workarounds_vk.h