Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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 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///
91enum 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///
113class CapabilitiesVK final : public Capabilities,
114 public BackendCast<CapabilitiesVK, Capabilities> {
115 public:
116 explicit CapabilitiesVK(bool enable_validations,
117 bool fatal_missing_validations = false);
118
120
121 bool IsValid() const;
122
123 bool AreValidationsEnabled() const;
124
126
128
130
131 std::optional<std::vector<std::string>> GetEnabledLayers() const;
132
133 std::optional<std::vector<std::string>> GetEnabledInstanceExtensions() const;
134
135 std::optional<std::vector<std::string>> GetEnabledDeviceExtensions(
136 const vk::PhysicalDevice& physical_device) const;
137
139 vk::StructureChain<vk::PhysicalDeviceFeatures2,
140 vk::PhysicalDeviceSamplerYcbcrConversionFeaturesKHR,
141 vk::PhysicalDevice16BitStorageFeatures>;
142
143 std::optional<PhysicalDeviceFeatures> GetEnabledDeviceFeatures(
144 const vk::PhysicalDevice& physical_device) const;
145
146 [[nodiscard]] bool SetPhysicalDevice(
147 const vk::PhysicalDevice& physical_device);
148
149 const vk::PhysicalDeviceProperties& GetPhysicalDeviceProperties() const;
150
151 void SetOffscreenFormat(PixelFormat pixel_format) const;
152
153 // |Capabilities|
154 bool SupportsOffscreenMSAA() const override;
155
156 // |Capabilities|
157 bool SupportsImplicitResolvingMSAA() const override;
158
159 // |Capabilities|
160 bool SupportsSSBO() const override;
161
162 // |Capabilities|
163 bool SupportsBufferToTextureBlits() const override;
164
165 // |Capabilities|
166 bool SupportsTextureToTextureBlits() const override;
167
168 // |Capabilities|
169 bool SupportsFramebufferFetch() const override;
170
171 // |Capabilities|
172 bool SupportsCompute() const override;
173
174 // |Capabilities|
175 bool SupportsComputeSubgroups() const override;
176
177 // |Capabilities|
178 bool SupportsReadFromResolve() const override;
179
180 // |Capabilities|
181 bool SupportsDecalSamplerAddressMode() const override;
182
183 // |Capabilities|
184 bool SupportsDeviceTransientTextures() const override;
185
186 // |Capabilities|
187 PixelFormat GetDefaultColorFormat() const override;
188
189 // |Capabilities|
190 PixelFormat GetDefaultStencilFormat() const override;
191
192 // |Capabilities|
194
195 // |Capabilities|
197
198 private:
199 bool validations_enabled_ = false;
200 std::map<std::string, std::set<std::string>> exts_;
201 std::set<RequiredCommonDeviceExtensionVK> required_common_device_extensions_;
202 std::set<RequiredAndroidDeviceExtensionVK>
203 required_android_device_extensions_;
204 std::set<OptionalDeviceExtensionVK> optional_device_extensions_;
205 mutable PixelFormat default_color_format_ = PixelFormat::kUnknown;
206 PixelFormat default_stencil_format_ = PixelFormat::kUnknown;
207 PixelFormat default_depth_stencil_format_ = PixelFormat::kUnknown;
208 vk::PhysicalDeviceProperties device_properties_;
209 bool supports_compute_subgroups_ = false;
210 bool supports_device_transient_textures_ = false;
211 bool is_valid_ = false;
212
213 bool HasExtension(const std::string& ext) const;
214
215 bool HasLayer(const std::string& layer) const;
216
217 CapabilitiesVK(const CapabilitiesVK&) = delete;
218
219 CapabilitiesVK& operator=(const CapabilitiesVK&) = delete;
220};
221
222} // namespace impeller
223
224#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 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 ...
vk::StructureChain< vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceSamplerYcbcrConversionFeaturesKHR, vk::PhysicalDevice16BitStorageFeatures > PhysicalDeviceFeatures
bool SupportsBufferToTextureBlits() const override
Whether the context backend supports blitting from a given DeviceBuffer view to a texture region (via...
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:100
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...