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