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  kLast,
82 };
83 
84 //------------------------------------------------------------------------------
85 /// @brief A device extension enabled if available. Subsystems cannot
86 /// assume availability and must check if these extensions are
87 /// available.
88 ///
89 /// @see `CapabilitiesVK::HasExtension`.
90 ///
91 enum class OptionalDeviceExtensionVK : uint32_t {
92  //----------------------------------------------------------------------------
93  /// To instrument and profile PSO creation.
94  ///
95  /// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_EXT_pipeline_creation_feedback.html
96  ///
98 
99  //----------------------------------------------------------------------------
100  /// To enable context creation on MoltenVK. A non-conformant Vulkan
101  /// implementation.
102  ///
103  /// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_KHR_portability_subset.html
104  ///
106 
107  kLast,
108 };
109 
110 //------------------------------------------------------------------------------
111 /// @brief The Vulkan layers and extensions wrangler.
112 ///
113 class CapabilitiesVK final : public Capabilities,
114  public BackendCast<CapabilitiesVK, Capabilities> {
115  public:
116  explicit CapabilitiesVK(bool enable_validations);
117 
118  ~CapabilitiesVK();
119 
120  bool IsValid() const;
121 
122  bool AreValidationsEnabled() const;
123 
125 
127 
128  bool HasExtension(OptionalDeviceExtensionVK ext) const;
129 
130  std::optional<std::vector<std::string>> GetEnabledLayers() const;
131 
132  std::optional<std::vector<std::string>> GetEnabledInstanceExtensions() const;
133 
134  std::optional<std::vector<std::string>> GetEnabledDeviceExtensions(
135  const vk::PhysicalDevice& physical_device) const;
136 
137  using PhysicalDeviceFeatures =
138  vk::StructureChain<vk::PhysicalDeviceFeatures2,
139  vk::PhysicalDeviceSamplerYcbcrConversionFeaturesKHR>;
140 
141  std::optional<PhysicalDeviceFeatures> GetEnabledDeviceFeatures(
142  const vk::PhysicalDevice& physical_device) const;
143 
144  [[nodiscard]] bool SetPhysicalDevice(
145  const vk::PhysicalDevice& physical_device);
146 
147  const vk::PhysicalDeviceProperties& GetPhysicalDeviceProperties() const;
148 
149  void SetOffscreenFormat(PixelFormat pixel_format) const;
150 
151  // |Capabilities|
152  bool SupportsOffscreenMSAA() const override;
153 
154  // |Capabilities|
155  bool SupportsImplicitResolvingMSAA() const override;
156 
157  // |Capabilities|
158  bool SupportsSSBO() const override;
159 
160  // |Capabilities|
161  bool SupportsBufferToTextureBlits() const override;
162 
163  // |Capabilities|
164  bool SupportsTextureToTextureBlits() const override;
165 
166  // |Capabilities|
167  bool SupportsFramebufferFetch() const override;
168 
169  // |Capabilities|
170  bool SupportsCompute() const override;
171 
172  // |Capabilities|
173  bool SupportsComputeSubgroups() const override;
174 
175  // |Capabilities|
176  bool SupportsReadFromResolve() const override;
177 
178  // |Capabilities|
179  bool SupportsDecalSamplerAddressMode() const override;
180 
181  // |Capabilities|
182  bool SupportsDeviceTransientTextures() const override;
183 
184  // |Capabilities|
185  PixelFormat GetDefaultColorFormat() const override;
186 
187  // |Capabilities|
188  PixelFormat GetDefaultStencilFormat() const override;
189 
190  // |Capabilities|
191  PixelFormat GetDefaultDepthStencilFormat() const override;
192 
193  // |Capabilities|
194  PixelFormat GetDefaultGlyphAtlasFormat() const override;
195 
196  private:
197  bool validations_enabled_ = false;
198  std::map<std::string, std::set<std::string>> exts_;
199  std::set<RequiredCommonDeviceExtensionVK> required_common_device_extensions_;
200  std::set<RequiredAndroidDeviceExtensionVK>
201  required_android_device_extensions_;
202  std::set<OptionalDeviceExtensionVK> optional_device_extensions_;
203  mutable PixelFormat default_color_format_ = PixelFormat::kUnknown;
204  PixelFormat default_stencil_format_ = PixelFormat::kUnknown;
205  PixelFormat default_depth_stencil_format_ = PixelFormat::kUnknown;
206  vk::PhysicalDeviceProperties device_properties_;
207  bool supports_compute_subgroups_ = false;
208  bool supports_device_transient_textures_ = false;
209  bool is_valid_ = false;
210 
211  bool HasExtension(const std::string& ext) const;
212 
213  bool HasLayer(const std::string& layer) const;
214 
215  CapabilitiesVK(const CapabilitiesVK&) = delete;
216 
217  CapabilitiesVK& operator=(const CapabilitiesVK&) = delete;
218 };
219 
220 } // namespace impeller
221 
222 #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:91
impeller::CapabilitiesVK::SupportsDecalSamplerAddressMode
bool SupportsDecalSamplerAddressMode() const override
Whether the context backend supports SamplerAddressMode::Decal.
Definition: capabilities_vk.cc:542
impeller::RequiredCommonDeviceExtensionVK::kLast
@ kLast
impeller::CapabilitiesVK::SetOffscreenFormat
void SetOffscreenFormat(PixelFormat pixel_format) const
Definition: capabilities_vk.cc:410
impeller::CapabilitiesVK::GetEnabledInstanceExtensions
std::optional< std::vector< std::string > > GetEnabledInstanceExtensions() const
Definition: capabilities_vk.cc:78
impeller::CapabilitiesVK::IsValid
bool IsValid() const
Definition: capabilities_vk.cc:57
impeller::CapabilitiesVK::SupportsOffscreenMSAA
bool SupportsOffscreenMSAA() const override
Whether the context backend supports attaching offscreen MSAA color/stencil textures.
Definition: capabilities_vk.cc:496
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:521
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:557
impeller::CapabilitiesVK::GetEnabledLayers
std::optional< std::vector< std::string > > GetEnabledLayers() const
Definition: capabilities_vk.cc:65
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:516
impeller::CapabilitiesVK::GetDefaultGlyphAtlasFormat
PixelFormat GetDefaultGlyphAtlasFormat() const override
Returns the default pixel format for the alpha bitmap glyph atlas.
Definition: capabilities_vk.cc:571
impeller::CapabilitiesVK::SupportsComputeSubgroups
bool SupportsComputeSubgroups() const override
Whether the context backend supports configuring ComputePass command subgroups.
Definition: capabilities_vk.cc:532
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:538
vk.h
impeller::CapabilitiesVK::GetEnabledDeviceFeatures
std::optional< PhysicalDeviceFeatures > GetEnabledDeviceFeatures(const vk::PhysicalDevice &physical_device) const
Definition: capabilities_vk.cc:338
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:100
impeller::CapabilitiesVK::SetPhysicalDevice
bool SetPhysicalDevice(const vk::PhysicalDevice &physical_device)
Definition: capabilities_vk.cc:414
impeller::Capabilities
Definition: capabilities.h:15
impeller::CapabilitiesVK::~CapabilitiesVK
~CapabilitiesVK()
impeller::CapabilitiesVK::HasExtension
bool HasExtension(RequiredCommonDeviceExtensionVK ext) const
Definition: capabilities_vk.cc:575
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:552
impeller::RequiredAndroidDeviceExtensionVK::kKHRDedicatedAllocation
@ kKHRDedicatedAllocation
impeller::RequiredAndroidDeviceExtensionVK::kANDROIDExternalMemoryAndroidHardwareBuffer
@ kANDROIDExternalMemoryAndroidHardwareBuffer
impeller::RequiredAndroidDeviceExtensionVK::kKHRSamplerYcbcrConversion
@ kKHRSamplerYcbcrConversion
impeller::RequiredCommonDeviceExtensionVK::kKHRSwapchain
@ kKHRSwapchain
backend_cast.h
impeller::CapabilitiesVK::CapabilitiesVK
CapabilitiesVK(bool enable_validations)
Definition: capabilities_vk.cc:17
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:562
capabilities.h
impeller::CapabilitiesVK::SupportsBufferToTextureBlits
bool SupportsBufferToTextureBlits() const override
Whether the context backend supports blitting from a given DeviceBuffer view to a texture region (via...
Definition: capabilities_vk.cc:511
impeller::CapabilitiesVK::SupportsCompute
bool SupportsCompute() const override
Whether the context backend supports ComputePass.
Definition: capabilities_vk.cc:526
impeller::CapabilitiesVK
The Vulkan layers and extensions wrangler.
Definition: capabilities_vk.h:113
impeller::OptionalDeviceExtensionVK::kVKKHRPortabilitySubset
@ kVKKHRPortabilitySubset
impeller::PixelFormat::kUnknown
@ kUnknown
impeller::CapabilitiesVK::PhysicalDeviceFeatures
vk::StructureChain< vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceSamplerYcbcrConversionFeaturesKHR > PhysicalDeviceFeatures
Definition: capabilities_vk.h:139
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:547
impeller::CapabilitiesVK::GetPhysicalDeviceProperties
const vk::PhysicalDeviceProperties & GetPhysicalDeviceProperties() const
Definition: capabilities_vk.cc:567
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:506
impeller::CapabilitiesVK::AreValidationsEnabled
bool AreValidationsEnabled() const
Definition: capabilities_vk.cc:61
impeller::RequiredAndroidDeviceExtensionVK::kEXTQueueFamilyForeign
@ kEXTQueueFamilyForeign
impeller::CapabilitiesVK::GetEnabledDeviceExtensions
std::optional< std::vector< std::string > > GetEnabledDeviceExtensions(const vk::PhysicalDevice &physical_device) const
Definition: capabilities_vk.cc:225
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:501
impeller
Definition: aiks_blur_unittests.cc:20