Debian Codegraph @

include/gpu/vk/VulkanPreferredFeatures.h

raw
1 /*
2 * Copyright 2025 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef skgpu_VulkanPreferredFeatures_DEFINED
9 #define skgpu_VulkanPreferredFeatures_DEFINED
10
11 #include "include/private/base/SkAPI.h"
12 #include "include/private/gpu/vk/SkiaVulkan.h"
13
14 #include <cstddef>
15 #include <cstdint>
16 #include <vector>
17
18 namespace skgpu {
19
20 class SK_API VulkanPreferredFeatures {
21 public:
22 ~VulkanPreferredFeatures();
23
24 /*
25 * VulkanPreferredFeatures is used by Skia to add extensions and features on top of what the app
26 * wants to enable. The flow of Vulkan initialization for an app that wants to use Skia would
27 * be:
28 *
29 * ```
30 * // Query the loader for instance information, decide on API version to use
31 *
32 * // Prepare for Skia-enabled extensions and features
33 * skgpu::VulkanPreferredFeatures skiaFeatures;
34 * skiaFeatures.init(apiVersion);
35 *
36 * // Decide on instance extensions to use in the app.
37 *
38 * // Allow Skia to add to the instance extension list.
39 * skiaFeatures.addToInstanceExtensions(...);
40 *
41 * // Create the instance, choose physical device, query available extensions, decide on
42 * // device features to query
43 *
44 * // Allow Skia to add to the feature query list.
45 * skiaFeatures.addFeaturesToQuery(...);
46 *
47 * // Query features, decide on extensions and features to enable.
48 *
49 * // Allow Skia to add to the device extension and feature list.
50 * skiaFeatures.addFeaturesToEnable(...);
51 *
52 * // Create the Vulkan device.
53 * ```
54 *
55 * Parameters:
56 *
57 * * appAPIVersion: The API version the app has specified in VkApplicationInfo::apiVersion (and
58 * will later provide in VulkanBackendContext::fMaxAPIVersion). The minimum supported version
59 * is VK_API_VERSION_1_1, maximum is VK_API_VERSION_1_4.
60 */
61 void init(uint32_t appAPIVersion);
62
63 /*
64 * Before creating a Vulkan instance, call addToInstanceExtensions to give Skia a chance to add
65 * instance extensions it may take advantage of. Extensions are only added to appExtensions if
66 * caller hasn't already included them to be enabled.
67 *
68 * Parameters:
69 *
70 * * instanceExtensions, instanceExtensionCount: The list of available instance extensions as
71 * queried from the loader.
72 * * appExtensions: The list of extensions to be enabled on the instance; more extensions may be
73 * added to this list by this call.
74 */
75 void addToInstanceExtensions(const VkExtensionProperties* instanceExtensions,
76 size_t instanceExtensionCount,
77 std::vector<const char*>& appExtensions);
78
79 /*
80 * Before querying Vulkan device features, call addFeaturesToQuery to give Skia a chance to add
81 * device extension features it may take advantage of to the query. Features are only added to
82 * appFeatures if caller hasn't already included them in the query.
83 *
84 * Beware that the structs that get chained to appFeatures are member variables of this class,
85 * so this object must not leave scope until feature query and device creation is complete.
86 *
87 * Parameters:
88 *
89 * * deviceExtensions, deviceExtensionCount: The list of available device extensions as queried
90 * from the physical device.
91 * * appFeatures: The features to be queried from the physical device; more features may be
92 * added to the pNext chain by this call.
93 */
94 void addFeaturesToQuery(const VkExtensionProperties* deviceExtensions,
95 size_t deviceExtensionCount,
96 VkPhysicalDeviceFeatures2& appFeatures);
97
98 /*
99 * Before creating the Vulkan device, call addFeaturesToEnable to give Skia a chance to add
100 * device extensions and features it may take advantage of. Extensions and features are only
101 * added to appExtensions and appFeatures respectively if caller hasn't already included them to
102 * be enabled. This function may replace chained features with VkPhysicalDeviceVulkanNNFeatures
103 * structs instead in order to add features. Features that are already enabled by the
104 * application are retained in that case in the new struct.
105 *
106 * Parameters:
107 *
108 * * appExtensions: The list of extensions to be enabled on the device; more extensions may be
109 * added to this list by this call.
110 * * appFeatures: The features to be enabled on the device; more features may be
111 * added to the pNext chain by this call.
112 */
113 void addFeaturesToEnable(std::vector<const char*>& appExtensions,
114 VkPhysicalDeviceFeatures2& appFeatures);
115
116 private:
117 uint32_t fAPIVersion = 0;
118 // Track what the application did, so warnings can be generated if the class is not
119 // fully/correctly used.
120 bool fHasAddedToInstanceExtensions = false;
121 bool fHasAddedFeaturesToQuery = false;
122 bool fHasAddedFeaturesToEnable = false;
123
124 // The list of device features Skia is interested in. If any are included in
125 // VkPhysicalDeviceFeatures2::pNext by the app, it is not included again by Skia. However, to
126 // take best advantage of the Vulkan API, the app should not intentionally include these feature
127 // structs only to forcefully disable the feature - this blocks Skia from leveraging it.
128 //
129 // When ambiguous, the extension name is included to determine which extension a feature struct
130 // has come from. This is usually needed when addFeaturesToQuery has included a feature struct
131 // that is present in multiple extensions (e.g. due to extension promotion). It is later used by
132 // addFeaturesToEnable to know which extension to enable.
133
134 // Available since Vulkan 1.2
135 VkPhysicalDeviceVulkan11Features fVulkan11 = {};
136
137 // Available since Vulkan 1.2
138 VkPhysicalDeviceVulkan12Features fVulkan12 = {};
139
140 // Available since Vulkan 1.3
141 VkPhysicalDeviceVulkan13Features fVulkan13 = {};
142
143 // Available since Vulkan 1.4
144 VkPhysicalDeviceVulkan14Features fVulkan14 = {};
145
146 // Feature of VK_EXT_rasterization_order_attachment_access or
147 // VK_ARM_rasterization_order_attachment_access.
148 VkPhysicalDeviceRasterizationOrderAttachmentAccessFeaturesEXT
149 fRasterizationOrderAttachmentAccess = {};
150 const char* fRasterizationOrderAttachmentAccessExtension = nullptr;
151
152 // Feature of VK_EXT_blend_operation_advanced
153 VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT fBlendOperationAdvanced = {};
154
155 // Feature of VK_EXT_extended_dynamic_state
156 VkPhysicalDeviceExtendedDynamicStateFeaturesEXT fExtendedDynamicState = {};
157
158 // Feature of VK_EXT_extended_dynamic_state2
159 VkPhysicalDeviceExtendedDynamicState2FeaturesEXT fExtendedDynamicState2 = {};
160
161 // Feature of VK_EXT_vertex_input_dynamic_state
162 VkPhysicalDeviceVertexInputDynamicStateFeaturesEXT fVertexInputDynamicState = {};
163
164 // Feature of VK_EXT_graphics_pipeline_library
165 VkPhysicalDeviceGraphicsPipelineLibraryFeaturesEXT fGraphicsPipelineLibrary = {};
166
167 // Feature of VK_KHR_sampler_ycbcr_conversion or Vulkan 1.1
168 VkPhysicalDeviceSamplerYcbcrConversionFeatures fSamplerYcbcrConversion = {};
169
170 // Feature of VK_EXT_rgba10x6_formats
171 VkPhysicalDeviceRGBA10X6FormatsFeaturesEXT fRGBA10x6Formats = {};
172
173 // Feature of VK_KHR_synchronization2 or Vulkan 1.3
174 VkPhysicalDeviceDynamicRenderingFeatures fSynchronization2 = {};
175
176 // Feature of VK_KHR_dynamic_rendering or Vulkan 1.3
177 VkPhysicalDeviceDynamicRenderingFeatures fDynamicRendering = {};
178
179 // Feature of VK_KHR_dynamic_rendering_local_read or Vulkan 1.4
180 VkPhysicalDeviceDynamicRenderingLocalReadFeatures fDynamicRenderingLocalRead = {};
181
182 // Feature of VK_EXT_multisampled_render_to_single_sampled
183 VkPhysicalDeviceMultisampledRenderToSingleSampledFeaturesEXT
184 fMultisampledRenderToSingleSampled = {};
185
186 // Feature of VK_EXT_host_image_copy or Vulkan 1.4
187 VkPhysicalDeviceHostImageCopyFeatures fHostImageCopy = {};
188
189 // Feature of VK_EXT_pipeline_creation_cache_control or Vulkan 1.3
190 VkPhysicalDevicePipelineCreationCacheControlFeatures fPipelineCreationCacheControl = {};
191
192 // Feature of VK_EXT_frame_boundary
193 VkPhysicalDeviceFrameBoundaryFeaturesEXT fFrameBoundary = {};
194
195 // Extensions that don't have a feature:
196 // VK_KHR_driver_properties or Vulkan 1.2
197 const char* fDriverPropertiesExtension = nullptr;
198 // VK_KHR_create_renderpass2 or Vulkan 1.2
199 const char* fCreateRenderpass2Extension = nullptr;
200 // VK_EXT_load_store_op_none, VK_KHR_load_store_op_none or Vulkan 1.4
201 const char* fLoadStoreOpNoneExtension = nullptr;
202 // VK_EXT_conservative_rasterization
203 const char* fConservativeRasterizationExtension = nullptr;
204 #if defined(SK_BUILD_FOR_ANDROID)
205 // VK_ANDROID_external_memory_android_hardware_buffer
206 const char* fExternalMemoryAHardwareBufferExtension = nullptr;
207 #endif
208
209 // Extensions that the other extensions above depend on:
210 // Dependency of VK_EXT_graphics_pipeline_library: VK_KHR_pipeline_library
211 const char* fPipelineLibraryExtension = nullptr;
212 // Dependencies of VK_EXT_host_image_copy: VK_KHR_copy_commands2, VK_KHR_format_feature_flags2
213 const char* fCopyCommands2Extension = nullptr;
214 const char* fFormatFeatureFlags2Extension = nullptr;
215 // Dependency of VK_EXT_multisampled_render_to_single_sampled: VK_KHR_depth_stencil_resolve
216 const char* fDepthStencilResolveExtension = nullptr;
217 #if defined(SK_BUILD_FOR_ANDROID)
218 // Dependency of VK_ANDROID_external_memory_android_hardware_buffer: VK_EXT_queue_family_foreign
219 const char* fQueueFamilyForeignExtension = nullptr;
220 #endif
221 };
222
223 } // namespace skgpu
224
225 #endif // skgpu_VulkanPreferredFeatures_DEFINED