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 <set>
11 #include <string>
12 #include <vector>
13 
17 
18 namespace impeller {
19 
20 class ContextVK;
21 
22 //------------------------------------------------------------------------------
23 /// @brief A device extension available on all platforms. Without the
24 /// presence of these extensions, context creation will fail.
25 ///
26 enum 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 ///
45 enum 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 ///
118 enum 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 ///
140 class CapabilitiesVK final : public Capabilities,
141  public BackendCast<CapabilitiesVK, Capabilities> {
142  public:
143  explicit CapabilitiesVK(bool enable_validations,
144  bool fatal_missing_validations = false);
145 
146  ~CapabilitiesVK();
147 
148  bool IsValid() const;
149 
150  bool AreValidationsEnabled() const;
151 
153 
155 
156  bool HasExtension(OptionalDeviceExtensionVK ext) const;
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 
165  using PhysicalDeviceFeatures =
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|
217  PixelFormat GetDefaultDepthStencilFormat() const override;
218 
219  // |Capabilities|
220  PixelFormat GetDefaultGlyphAtlasFormat() const override;
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_
impeller::OptionalDeviceExtensionVK
OptionalDeviceExtensionVK
A device extension enabled if available. Subsystems cannot assume availability and must check if thes...
Definition: capabilities_vk.h:118
impeller::CapabilitiesVK::SupportsDecalSamplerAddressMode
bool SupportsDecalSamplerAddressMode() const override
Whether the context backend supports SamplerAddressMode::Decal.
Definition: capabilities_vk.cc:566
impeller::RequiredAndroidDeviceExtensionVK::kKHRExternalSemaphore
@ kKHRExternalSemaphore
impeller::RequiredCommonDeviceExtensionVK::kLast
@ kLast
impeller::CapabilitiesVK::SetOffscreenFormat
void SetOffscreenFormat(PixelFormat pixel_format) const
Definition: capabilities_vk.cc:433
impeller::RequiredAndroidDeviceExtensionVK::kKHRExternalSemaphoreFd
@ kKHRExternalSemaphoreFd
impeller::CapabilitiesVK::GetEnabledInstanceExtensions
std::optional< std::vector< std::string > > GetEnabledInstanceExtensions() const
Definition: capabilities_vk.cc:82
impeller::RequiredAndroidDeviceExtensionVK::kKHRExternalFence
@ kKHRExternalFence
impeller::CapabilitiesVK::IsValid
bool IsValid() const
Definition: capabilities_vk.cc:61
impeller::CapabilitiesVK::SupportsOffscreenMSAA
bool SupportsOffscreenMSAA() const override
Whether the context backend supports attaching offscreen MSAA color/stencil textures.
Definition: capabilities_vk.cc:525
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:545
impeller::RequiredAndroidDeviceExtensionVK::kLast
@ kLast
impeller::OptionalDeviceExtensionVK::kLast
@ kLast
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:581
impeller::CapabilitiesVK::GetEnabledLayers
std::optional< std::vector< std::string > > GetEnabledLayers() const
Definition: capabilities_vk.cc:69
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:540
impeller::CapabilitiesVK::GetDefaultGlyphAtlasFormat
PixelFormat GetDefaultGlyphAtlasFormat() const override
Returns the default pixel format for the alpha bitmap glyph atlas.
Definition: capabilities_vk.cc:595
impeller::CapabilitiesVK::SupportsComputeSubgroups
bool SupportsComputeSubgroups() const override
Whether the context backend supports configuring ComputePass command subgroups.
Definition: capabilities_vk.cc:556
impeller::CapabilitiesVK::CapabilitiesVK
CapabilitiesVK(bool enable_validations, bool fatal_missing_validations=false)
Definition: capabilities_vk.cc:17
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:562
vk.h
impeller::CapabilitiesVK::GetEnabledDeviceFeatures
std::optional< PhysicalDeviceFeatures > GetEnabledDeviceFeatures(const vk::PhysicalDevice &physical_device) const
Definition: capabilities_vk.cc:350
impeller::RequiredCommonDeviceExtensionVK
RequiredCommonDeviceExtensionVK
A device extension available on all platforms. Without the presence of these extensions,...
Definition: capabilities_vk.h:26
impeller::PixelFormat
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition: formats.h:99
impeller::CapabilitiesVK::SetPhysicalDevice
bool SetPhysicalDevice(const vk::PhysicalDevice &physical_device)
Definition: capabilities_vk.cc:437
impeller::RequiredAndroidDeviceExtensionVK::kKHRExternalFenceFd
@ kKHRExternalFenceFd
impeller::Capabilities
Definition: capabilities.h:14
impeller::CapabilitiesVK::~CapabilitiesVK
~CapabilitiesVK()
impeller::CapabilitiesVK::HasExtension
bool HasExtension(RequiredCommonDeviceExtensionVK ext) const
Definition: capabilities_vk.cc:599
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:576
impeller::RequiredAndroidDeviceExtensionVK::kKHRDedicatedAllocation
@ kKHRDedicatedAllocation
impeller::RequiredAndroidDeviceExtensionVK::kANDROIDExternalMemoryAndroidHardwareBuffer
@ kANDROIDExternalMemoryAndroidHardwareBuffer
impeller::RequiredAndroidDeviceExtensionVK::kKHRSamplerYcbcrConversion
@ kKHRSamplerYcbcrConversion
impeller::RequiredCommonDeviceExtensionVK::kKHRSwapchain
@ kKHRSwapchain
backend_cast.h
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:586
capabilities.h
impeller::CapabilitiesVK::SupportsCompute
bool SupportsCompute() const override
Whether the context backend supports ComputePass.
Definition: capabilities_vk.cc:550
impeller::CapabilitiesVK
The Vulkan layers and extensions wrangler.
Definition: capabilities_vk.h:140
impeller::OptionalDeviceExtensionVK::kVKKHRPortabilitySubset
@ kVKKHRPortabilitySubset
impeller::PixelFormat::kUnknown
@ kUnknown
impeller::CapabilitiesVK::PhysicalDeviceFeatures
vk::StructureChain< vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceSamplerYcbcrConversionFeaturesKHR, vk::PhysicalDevice16BitStorageFeatures > PhysicalDeviceFeatures
Definition: capabilities_vk.h:168
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:571
impeller::CapabilitiesVK::GetPhysicalDeviceProperties
const vk::PhysicalDeviceProperties & GetPhysicalDeviceProperties() const
Definition: capabilities_vk.cc:591
impeller::RequiredAndroidDeviceExtensionVK
RequiredAndroidDeviceExtensionVK
A device extension available on all Android platforms. Without the presence of these extensions on An...
Definition: capabilities_vk.h:45
impeller::CapabilitiesVK::SupportsSSBO
bool SupportsSSBO() const override
Whether the context backend supports binding Shader Storage Buffer Objects (SSBOs) to pipelines.
Definition: capabilities_vk.cc:535
impeller::CapabilitiesVK::AreValidationsEnabled
bool AreValidationsEnabled() const
Definition: capabilities_vk.cc:65
impeller::RequiredAndroidDeviceExtensionVK::kEXTQueueFamilyForeign
@ kEXTQueueFamilyForeign
impeller::CapabilitiesVK::GetEnabledDeviceExtensions
std::optional< std::vector< std::string > > GetEnabledDeviceExtensions(const vk::PhysicalDevice &physical_device) const
Definition: capabilities_vk.cc:237
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:530
impeller
Definition: aiks_blend_unittests.cc:18