Debian Codegraph @

src/gpu/vk/VulkanPreferredFeatures.cpp

raw
1 /*
2 * Copyright 2025 Google Inc.
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 #include "include/gpu/vk/VulkanPreferredFeatures.h"
9
10 #include "include/private/base/SkAssert.h"
11 #include "include/private/base/SkDebug.h"
12 #include "src/gpu/vk/VulkanUtilsPriv.h"
13
14 #include <cstdint>
15 #include <cstring>
16 #include <vector>
17
18 namespace skgpu {
19
20 /*
21 * # Overview
22 *
23 * Skia requires the application to create the Vulkan instance and device. This operation involves
24 * enabling extensions and device features that the application would like to take advantage of.
25 * However, the application is not necessarily aware of all the extensions and features that _Skia_
26 * would like to use (and it's too onerous to require them to keep up). If the application does not
27 * enable some extensions, Skia's performance may degrade.
28 *
29 * VulkanPreferredFeatures is used to let Skia modify the list of extensions and device features
30 * before the application creates the device. The application thus never needs to worry about what
31 * Skia might or might not use.
32 *
33 * # How It Works
34 *
35 * There are three main operations:
36 *
37 * - Add instance extensions. Before creating the Vulkan instance, Skia could add more extensions to
38 * enable.
39 * - Add device features to query. This lets Skia discover what features are available.
40 * - Enable device features.
41 *
42 * Device features and extensions are where the complexity is. In particular, there is:
43 *
44 * - The list of _available_ extensions. When adding features to query, this information is
45 * assembled in DeviceExtensions for faster look up.
46 * - The list of _enabled_ extensions. When enabling features, this information is also assembled in
47 * DeviceExtensions.
48 * - The list of device features. This is a chain of VkPhysicalDeviceFooFeatures structs, starting
49 * with VkPhysicalDeviceFeatures2. FeaturesToAdd is used to track whether any of these feature
50 * structs need to be chained or not. The choice of feature structs depends on the API version
51 * used by the application, following the extension promotions to core.
52 *
53 * See addFeaturesToQuery() for details of how feature structs are chosen and chained to be queried
54 * in addition to the application's own set of feature structs.
55 *
56 * See addFeaturesToEnable() for details of how the application-provided chain of feature structs is
57 * manipulated to include the previously-queried features. Based on Vulkan rules, some structs are
58 * mutually exclusive, which is handled by this function as well.
59 *
60 * # How to Add Support for New Extensions
61 *
62 * When adding a new extension, the following changes must be made:
63 *
64 * - Add a flag corresponding to the extension to DeviceExtensions
65 * - Detect the extension and set it in mark_device_extensions().
66 * - Add the extensions's feature struct to VulkanPreferredFeatures. This provides storage for the
67 * struct so it lives long enough (and not go out of scope too early).
68 * - Add a flag corresponding to the feature struct to FeaturesToAdd.
69 * - In addFeaturesToQuery(), initalize the sType of the feature struct based on the flag in
70 * DeviceExtensions. If extension is promoted to core in the API version used by the
71 * application, the VkPhysicalDeviceVulkan??Features struct should be used for the same feature
72 * instead, if available.
73 * - In get_features_to_add(), if the extension is promoted to a core version, set the
74 * FeaturesToAdd flag to false as the VkPhysicalDeviceVulkan??Features struct would be used to
75 * query the same feature.
76 * - In get_features_to_add() additionally, set the FeaturesToAdd flag to false if the application
77 * has already included the corresponding feature struct in its own chain.
78 * - Back in addFeaturesToQuery(), chain the feature struct if the FeaturesToAdd flag is set.
79 * - In addFeaturesToEnable():
80 * - Set the FeaturesToAdd flag to true iff the sType of the feature struct is set.
81 * - If the extension is not enabled by the app but the FeaturesToAdd flag is set, add the
82 * extension to appExtensions.
83 * - Disable optional features in the struct if not going to be used by Skia. Note that this
84 * modifies the struct owned by VulkanPreferredFeatures; if that's the one that's chained, the
85 * application didn't care about these features. If the application has chained its own struct
86 * of this type, it's unaffected by this operation.
87 * - Detect the struct in the big switch. If promoted to core, make sure to drop the struct. If
88 * not, chain it if the extension is enabled.
89 * - In the end, chain the feature struct if still needed to be added.
90 * - Make sure to update the existing tests in tests/VkPreferredFeaturesTest.cpp to make sure the
91 * extension and its feature is enabled appropropriately.
92 *
93 * # How to Add Support for New Vulkan Versions
94 *
95 * When adding a support for a new Vulkan version, the following changes must be made:
96 *
97 * - Add the VkPhysicalDeviceVulkan??Features struct to VulkanPreferredFeatures, and a flag for it
98 * in FeaturesToAdd.
99 * - In get_features_to_add(), check for the Vulkan version and decided if that struct should be
100 * used, or the individual feature structs from extensions that were promoted to core in that
101 * version.
102 * - Check in the same function if the application has already included
103 * VkPhysicalDeviceVulkan??Features.
104 * - In addFeaturesToQuery(), similarly check for the Vulkan version and set the sType of either the
105 * VkPhysicalDeviceVulkan??Features struct or the individual feature structs from promoted
106 * extensions.
107 * - Chain the VkPhysicalDeviceVulkan??Features struct if the FeaturesToAdd flag is set.
108 * - In addFeaturesToEnable():
109 * - Set the FeaturesToAdd flag to true iff the sType of the feature struct is set.
110 * - Disable optional features in the struct if not going to be used by Skia.
111 * - Detect the struct in the big switch. If pointer does not point to VulkanPreferredFeatures's
112 * own struct, copy the application-enabled features to VulkanPreferredFeatures's struct. Note
113 * that for simplicity, Skia always chains its own instance of VkPhysicalDeviceVulkan??Features.
114 * - Based on valid usage that forbids including VkPhysicalDeviceVulkan??Features and feature
115 * structs from promoted extensions, detect the latter structs in the big switch, copy their
116 * features to VkPhysicalDeviceVulkan??Features and drop them from the chain.
117 * - In the end, chain the VkPhysicalDeviceVulkan??Features feature struct.
118 * - Make sure to update tests/VkPreferredFeaturesTest.cpp with a new test that ensures the
119 * promotion rules were followed.
120 */
121
122 namespace {
123 struct DeviceExtensions {
124 // Extensions that Skia may benefit from enabling if available.
125 bool fRasterizationOrderAttachmentAccessARM = false;
126 bool fRasterizationOrderAttachmentAccessEXT = false;
127 bool fBlendOperationAdvancedEXT = false;
128 bool fExtendedDynamicStateEXT = false;
129 bool fExtendedDynamicState2EXT = false;
130 bool fVertexInputDynamicStateEXT = false;
131 bool fGraphicsPipelineLibraryEXT = false;
132 bool fSamplerYcbcrConversionKHR = false;
133 bool fRGBA10x6FormatsEXT = false;
134 bool fSynchronization2KHR = false;
135 bool fDynamicRenderingKHR = false;
136 bool fDynamicRenderingLocalReadKHR = false;
137 bool fMultisampledRenderToSingleSampledEXT = false;
138 bool fHostImageCopyEXT = false;
139 bool fPipelineCreationCacheControlEXT = false;
140 bool fDriverPropertiesKHR = false;
141 bool fCreateRenderpass2KHR = false;
142 bool fLoadStoreOpNoneEXT = false;
143 bool fLoadStoreOpNoneKHR = false;
144 bool fConservativeRasterizationEXT = false;
145 #if defined(SK_BUILD_FOR_ANDROID)
146 bool fExternalMemoryAHardwareBufferEXT = false;
147 #endif
148 bool fPipelineLibraryKHR = false;
149 bool fCopyCommands2KHR = false;
150 bool fFormatFeatureFlags2KHR = false;
151 bool fDepthStencilResolveKHR = false;
152 #if defined(SK_BUILD_FOR_ANDROID)
153 bool fQueueFamilyForeignEXT = false;
154 #endif
155
156 // Featureless extensions that the application may have enabled and that Skia may need to enable
157 // via a VkPhysicalDeviceVulkanNNFeatures struct. See "Table 1. Extension Feature Aliases" in
158 // the Features chapter of the spec:
159 //
160 // Extension: Features on promotion to core:
161 // VK_KHR_shader_draw_parameters shaderDrawParameters
162 // VK_KHR_draw_indirect_count drawIndirectCount
163 // VK_KHR_sampler_mirror_clamp_to_edge samplerMirrorClampToEdge
164 // VK_EXT_descriptor_indexing descriptorIndexing
165 // VK_EXT_sampler_filter_minmax samplerFilterMinmax
166 // VK_EXT_shader_viewport_index_layer shaderOutputViewportIndex, shaderOutputLayer
167 // VK_KHR_push_descriptor pushDescriptor
168 // VK_EXT_frame_boundary frameBoundaryEXT
169 bool fShaderDrawParametersKHR = false;
170 bool fDrawIndirectCountKHR = false;
171 bool fSamplerMirrorClampToEdgeKHR = false;
172 bool fDescriptorIndexingEXT = false;
173 bool fSamplerFilterMinmaxEXT = false;
174 bool fShaderViewportIndexLayerEXT = false;
175 bool fPushDescriptorKHR = false;
176 bool fFrameBoundaryEXT = false;
177 };
178
179 void mark_device_extensions(DeviceExtensions& exts, const char* name) {
180 if (strcmp(name, VK_ARM_RASTERIZATION_ORDER_ATTACHMENT_ACCESS_EXTENSION_NAME) == 0) {
181 exts.fRasterizationOrderAttachmentAccessARM = true;
182 } else if (strcmp(name, VK_EXT_RASTERIZATION_ORDER_ATTACHMENT_ACCESS_EXTENSION_NAME) == 0) {
183 exts.fRasterizationOrderAttachmentAccessEXT = true;
184 } else if (strcmp(name, VK_EXT_BLEND_OPERATION_ADVANCED_EXTENSION_NAME) == 0) {
185 exts.fBlendOperationAdvancedEXT = true;
186 } else if (strcmp(name, VK_EXT_EXTENDED_DYNAMIC_STATE_EXTENSION_NAME) == 0) {
187 exts.fExtendedDynamicStateEXT = true;
188 } else if (strcmp(name, VK_EXT_EXTENDED_DYNAMIC_STATE_2_EXTENSION_NAME) == 0) {
189 exts.fExtendedDynamicState2EXT = true;
190 } else if (strcmp(name, VK_EXT_VERTEX_INPUT_DYNAMIC_STATE_EXTENSION_NAME) == 0) {
191 exts.fVertexInputDynamicStateEXT = true;
192 } else if (strcmp(name, VK_EXT_GRAPHICS_PIPELINE_LIBRARY_EXTENSION_NAME) == 0) {
193 exts.fGraphicsPipelineLibraryEXT = true;
194 } else if (strcmp(name, VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME) == 0) {
195 exts.fSamplerYcbcrConversionKHR = true;
196 } else if (strcmp(name, VK_EXT_RGBA10X6_FORMATS_EXTENSION_NAME) == 0) {
197 exts.fRGBA10x6FormatsEXT = true;
198 } else if (strcmp(name, VK_KHR_SYNCHRONIZATION_2_EXTENSION_NAME) == 0) {
199 exts.fSynchronization2KHR = true;
200 } else if (strcmp(name, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME) == 0) {
201 exts.fDynamicRenderingKHR = true;
202 } else if (strcmp(name, VK_KHR_DYNAMIC_RENDERING_LOCAL_READ_EXTENSION_NAME) == 0) {
203 exts.fDynamicRenderingLocalReadKHR = true;
204 } else if (strcmp(name, VK_EXT_MULTISAMPLED_RENDER_TO_SINGLE_SAMPLED_EXTENSION_NAME) == 0) {
205 exts.fMultisampledRenderToSingleSampledEXT = true;
206 } else if (strcmp(name, VK_EXT_HOST_IMAGE_COPY_EXTENSION_NAME) == 0) {
207 exts.fHostImageCopyEXT = true;
208 } else if (strcmp(name, VK_EXT_PIPELINE_CREATION_CACHE_CONTROL_EXTENSION_NAME) == 0) {
209 exts.fPipelineCreationCacheControlEXT = true;
210 } else if (strcmp(name, VK_KHR_DRIVER_PROPERTIES_EXTENSION_NAME) == 0) {
211 exts.fDriverPropertiesKHR = true;
212 } else if (strcmp(name, VK_KHR_CREATE_RENDERPASS_2_EXTENSION_NAME) == 0) {
213 exts.fCreateRenderpass2KHR = true;
214 } else if (strcmp(name, VK_EXT_LOAD_STORE_OP_NONE_EXTENSION_NAME) == 0) {
215 exts.fLoadStoreOpNoneEXT = true;
216 } else if (strcmp(name, VK_KHR_LOAD_STORE_OP_NONE_EXTENSION_NAME) == 0) {
217 exts.fLoadStoreOpNoneKHR = true;
218 } else if (strcmp(name, VK_EXT_CONSERVATIVE_RASTERIZATION_EXTENSION_NAME) == 0) {
219 exts.fConservativeRasterizationEXT = true;
220 #if defined(SK_BUILD_FOR_ANDROID)
221 } else if (
222 strcmp(name, VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_EXTENSION_NAME) == 0) {
223 exts.fExternalMemoryAHardwareBufferEXT = true;
224 #endif
225 } else if (strcmp(name, VK_KHR_PIPELINE_LIBRARY_EXTENSION_NAME) == 0) {
226 exts.fPipelineLibraryKHR = true;
227 } else if (strcmp(name, VK_KHR_COPY_COMMANDS_2_EXTENSION_NAME) == 0) {
228 exts.fCopyCommands2KHR = true;
229 } else if (strcmp(name, VK_KHR_FORMAT_FEATURE_FLAGS_2_EXTENSION_NAME) == 0) {
230 exts.fFormatFeatureFlags2KHR = true;
231 } else if (strcmp(name, VK_KHR_DEPTH_STENCIL_RESOLVE_EXTENSION_NAME) == 0) {
232 exts.fDepthStencilResolveKHR = true;
233 #if defined(SK_BUILD_FOR_ANDROID)
234 } else if (strcmp(name, VK_EXT_QUEUE_FAMILY_FOREIGN_EXTENSION_NAME) == 0) {
235 exts.fQueueFamilyForeignEXT = true;
236 #endif
237 } else if (strcmp(name, VK_KHR_SHADER_DRAW_PARAMETERS_EXTENSION_NAME) == 0) {
238 exts.fShaderDrawParametersKHR = true;
239 } else if (strcmp(name, VK_KHR_DRAW_INDIRECT_COUNT_EXTENSION_NAME) == 0) {
240 exts.fDrawIndirectCountKHR = true;
241 } else if (strcmp(name, VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_EXTENSION_NAME) == 0) {
242 exts.fSamplerMirrorClampToEdgeKHR = true;
243 } else if (strcmp(name, VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME) == 0) {
244 exts.fDescriptorIndexingEXT = true;
245 } else if (strcmp(name, VK_EXT_SAMPLER_FILTER_MINMAX_EXTENSION_NAME) == 0) {
246 exts.fSamplerFilterMinmaxEXT = true;
247 } else if (strcmp(name, VK_EXT_SHADER_VIEWPORT_INDEX_LAYER_EXTENSION_NAME) == 0) {
248 exts.fShaderViewportIndexLayerEXT = true;
249 } else if (strcmp(name, VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME) == 0) {
250 exts.fPushDescriptorKHR = true;
251 } else if (strcmp(name, VK_EXT_FRAME_BOUNDARY_EXTENSION_NAME) == 0) {
252 exts.fFrameBoundaryEXT = true;
253 }
254 }
255
256 DeviceExtensions get_supported_device_extensions(const VkExtensionProperties* deviceExtensions,
257 size_t deviceExtensionCount) {
258 DeviceExtensions exts;
259
260 for (size_t i = 0; i < deviceExtensionCount; ++i) {
261 mark_device_extensions(exts, deviceExtensions[i].extensionName);
262 }
263
264 return exts;
265 }
266
267 struct FeaturesToAdd {
268 bool fVulkan11 = true;
269 bool fVulkan12 = true;
270 bool fVulkan13 = true;
271 bool fVulkan14 = true;
272 bool fRasterizationOrderAttachmentAccess = true;
273 bool fBlendOperationAdvanced = true;
274 bool fExtendedDynamicState = true;
275 bool fExtendedDynamicState2 = true;
276 bool fVertexInputDynamicState = true;
277 bool fGraphicsPipelineLibrary = true;
278 bool fSamplerYcbcrConversion = true;
279 bool fRGBA10x6Formats = true;
280 bool fSynchronization2 = true;
281 bool fDynamicRendering = true;
282 bool fDynamicRenderingLocalRead = true;
283 bool fMultisampledRenderToSingleSampled = true;
284 bool fHostImageCopy = true;
285 bool fPipelineCreationCacheControl = true;
286 bool fFrameBoundary = true;
287 };
288
289 FeaturesToAdd get_features_to_add(uint32_t apiVersion,
290 const DeviceExtensions& exts,
291 const VkPhysicalDeviceFeatures2& appFeatures) {
292 FeaturesToAdd toAdd;
293
294 // First, exclude feature structs that are not available / are unnecessary based on apiVersion
295 // and available extensions.
296 if (apiVersion >= VK_API_VERSION_1_4) {
297 // VK_KHR_dynamic_rendering_local_read's feature is included in
298 // VkPhysicalDeviceVulkan14Features
299 toAdd.fDynamicRenderingLocalRead = false;
300 // VK_EXT_host_image_copy's feature is included in VkPhysicalDeviceVulkan14Features
301 toAdd.fHostImageCopy = false;
302 } else {
303 toAdd.fVulkan14 = false;
304 // Check for support via individual extensions' feature structs
305 toAdd.fDynamicRenderingLocalRead = exts.fDynamicRenderingLocalReadKHR;
306 toAdd.fHostImageCopy = exts.fHostImageCopyEXT;
307 }
308 if (apiVersion >= VK_API_VERSION_1_3) {
309 // VK_KHR_synchronization2's feature is included in VkPhysicalDeviceVulkan13Features
310 toAdd.fSynchronization2 = false;
311 // VK_KHR_dynamic_rendering's feature is included in VkPhysicalDeviceVulkan13Features
312 toAdd.fDynamicRendering = false;
313 // VK_EXT_pipeline_creation_cache_control's feature is included in
314 // VkPhysicalDeviceVulkan13Features
315 toAdd.fPipelineCreationCacheControl = false;
316 // VK_EXT_extended_dynamic_state is core in Vulkan 1.3, but no feature for it is present in
317 // VkPhysicalDeviceVulkan13Features; it's assumed supported / enabled.
318 toAdd.fExtendedDynamicState = false;
319 // Note: VK_EXT_extended_dynamic_state2 was partially promoted to Vulkan 1.3. Only dynamic
320 // state from the main feature is used by Skia, so it's ok to rely on Vulkan 1.3 to provide
321 // them, but if the optional features of this extension are needed, the extension struct
322 // should still be used to query and enable those features.
323 toAdd.fExtendedDynamicState2 = false;
324 } else {
325 toAdd.fVulkan13 = false;
326 // Check for support via individual extensions' feature structs
327 toAdd.fSynchronization2 = exts.fSynchronization2KHR;
328 toAdd.fDynamicRendering = exts.fDynamicRenderingKHR;
329 toAdd.fPipelineCreationCacheControl = exts.fPipelineCreationCacheControlEXT;
330 toAdd.fExtendedDynamicState = exts.fExtendedDynamicStateEXT;
331 toAdd.fExtendedDynamicState2 = exts.fExtendedDynamicState2EXT;
332 }
333 if (apiVersion >= VK_API_VERSION_1_2) {
334 // VK_KHR_sampler_ycbcr_conversion's feature is included in
335 // VkPhysicalDeviceVulkan11Features. Note that this struct was introduced in Vulkan 1.2.
336 toAdd.fSamplerYcbcrConversion = false;
337 // No feature from VkPhysicalDeviceVulkan12Features is used by Skia currently.
338 } else {
339 toAdd.fVulkan12 = false;
340 toAdd.fVulkan11 = false;
341 // Check for support via individual extensions' feature structs
342 toAdd.fSamplerYcbcrConversion = exts.fSamplerYcbcrConversionKHR;
343 }
344 // Check for support via individual extensions' feature structs (none of which have been
345 // promoted to core).
346 toAdd.fRasterizationOrderAttachmentAccess = exts.fRasterizationOrderAttachmentAccessARM ||
347 exts.fRasterizationOrderAttachmentAccessEXT;
348 toAdd.fBlendOperationAdvanced = exts.fBlendOperationAdvancedEXT;
349 toAdd.fVertexInputDynamicState = exts.fVertexInputDynamicStateEXT;
350 toAdd.fGraphicsPipelineLibrary = exts.fGraphicsPipelineLibraryEXT;
351 toAdd.fRGBA10x6Formats = exts.fRGBA10x6FormatsEXT;
352 toAdd.fMultisampledRenderToSingleSampled = exts.fMultisampledRenderToSingleSampledEXT;
353 toAdd.fFrameBoundary = exts.fFrameBoundaryEXT;
354
355 // Then, go over appFeatures::pNext and exclude features that are already being queried by the
356 // app.
357 const VkBaseInStructure* pNext = static_cast<const VkBaseInStructure*>(appFeatures.pNext);
358 while (pNext) {
359 switch (pNext->sType) {
360 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES:
361 toAdd.fVulkan11 = false;
362 break;
363 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES:
364 toAdd.fVulkan12 = false;
365 break;
366 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES:
367 toAdd.fVulkan13 = false;
368 break;
369 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_4_FEATURES:
370 toAdd.fVulkan14 = false;
371 break;
372 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RASTERIZATION_ORDER_ATTACHMENT_ACCESS_FEATURES_EXT:
373 toAdd.fRasterizationOrderAttachmentAccess = false;
374 break;
375 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_FEATURES_EXT:
376 toAdd.fBlendOperationAdvanced = false;
377 break;
378 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_FEATURES_EXT:
379 toAdd.fExtendedDynamicState = false;
380 break;
381 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_2_FEATURES_EXT:
382 toAdd.fExtendedDynamicState2 = false;
383 break;
384 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_INPUT_DYNAMIC_STATE_FEATURES_EXT:
385 toAdd.fVertexInputDynamicState = false;
386 break;
387 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GRAPHICS_PIPELINE_LIBRARY_FEATURES_EXT:
388 toAdd.fGraphicsPipelineLibrary = false;
389 break;
390 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES:
391 toAdd.fSamplerYcbcrConversion = false;
392 break;
393 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RGBA10X6_FORMATS_FEATURES_EXT:
394 toAdd.fRGBA10x6Formats = false;
395 break;
396 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SYNCHRONIZATION_2_FEATURES:
397 toAdd.fSynchronization2 = false;
398 break;
399 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DYNAMIC_RENDERING_FEATURES:
400 toAdd.fDynamicRendering = false;
401 break;
402 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DYNAMIC_RENDERING_LOCAL_READ_FEATURES:
403 toAdd.fDynamicRenderingLocalRead = false;
404 break;
405 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTISAMPLED_RENDER_TO_SINGLE_SAMPLED_FEATURES_EXT:
406 toAdd.fMultisampledRenderToSingleSampled = false;
407 break;
408 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_IMAGE_COPY_FEATURES:
409 toAdd.fHostImageCopy = false;
410 break;
411 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_CREATION_CACHE_CONTROL_FEATURES:
412 toAdd.fPipelineCreationCacheControl = false;
413 break;
414 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAME_BOUNDARY_FEATURES_EXT:
415 toAdd.fFrameBoundary = false;
416 break;
417 default:
418 break;
419 }
420
421 pNext = pNext->pNext;
422 }
423
424 return toAdd;
425 }
426
427 template <typename VulkanStruct> void chain(void**& chainEnd, VulkanStruct* toAdd) {
428 *chainEnd = toAdd;
429 chainEnd = (void**)&toAdd->pNext;
430 }
431 } // anonymous namespace
432
433 VulkanPreferredFeatures::~VulkanPreferredFeatures() {
434 if (fHasAddedToInstanceExtensions && !fHasAddedFeaturesToQuery) {
435 SkDebugf("WARNING: VulkanPreferredFeatures::addFeaturesToQuery() was not called\n");
436 }
437 if (fHasAddedToInstanceExtensions && !fHasAddedFeaturesToEnable) {
438 SkDebugf("WARNING: VulkanPreferredFeatures::addFeaturesToEnable() was not called\n");
439 }
440 }
441
442 void VulkanPreferredFeatures::init(uint32_t appAPIVersion) {
443 fAPIVersion = appAPIVersion;
444
445 // Minimum required version is Vulkan 1.1
446 SkASSERT(fAPIVersion >= VK_API_VERSION_1_1);
447 // This class does not understand Vulkan versions higher than 1.4
448 SkASSERT(fAPIVersion <= VK_API_VERSION_1_4);
449 }
450
451 void VulkanPreferredFeatures::addToInstanceExtensions(
452 const VkExtensionProperties* instanceExtensions,
453 size_t instanceExtensionCount,
454 std::vector<const char*>& appExtensions) {
455 // Nothing to do, currently Skia does not take advantage of any additional instance extensions.
456 fHasAddedToInstanceExtensions = true;
457 }
458
459 void VulkanPreferredFeatures::addFeaturesToQuery(const VkExtensionProperties* deviceExtensions,
460 size_t deviceExtensionCount,
461 VkPhysicalDeviceFeatures2& appFeatures) {
462 // First, inspect the list of device extensions and note which are available.
463 DeviceExtensions exts =
464 get_supported_device_extensions(deviceExtensions, deviceExtensionCount);
465
466 // For now, pretend these extensions are not supported. This de-risks using this API by users
467 // who didn't previously enable them. Those already in use by Skia will be re-enabled shortly
468 // after. Those not yet in use by Skia will be enabled in the future when they start to get
469 // used.
470 #if defined(SK_DISABLE_GRAPHICS_PIPELINE_LIBRARY)
471 exts.fPipelineLibraryKHR = false;
472 exts.fGraphicsPipelineLibraryEXT = false;
473 #endif
474 exts.fSynchronization2KHR = false;
475 exts.fDynamicRenderingKHR = false;
476 exts.fDynamicRenderingLocalReadKHR = false;
477 #if defined(SK_DISABLE_HOST_IMAGE_COPY)
478 exts.fHostImageCopyEXT = false;
479 exts.fCopyCommands2KHR = false;
480 #endif
481 exts.fShaderDrawParametersKHR = false;
482 exts.fDrawIndirectCountKHR = false;
483 exts.fSamplerMirrorClampToEdgeKHR = false;
484 exts.fDescriptorIndexingEXT = false;
485 exts.fSamplerFilterMinmaxEXT = false;
486 exts.fShaderViewportIndexLayerEXT = false;
487 exts.fPushDescriptorKHR = false;
488
489 // Set the sType and extensions to enable. Later in addFeaturesToEnable, the availability of
490 // device extensions is inferred from this. This is done irrespective of FeaturesToAdd
491 // calculated below, because if an app includes a feature struct that has a desirable feature
492 // disabled we can enable it later in addFeaturesToEnable. This is only possible if we know the
493 // feature is supported (inferred from the sType being set here) and the feature is required by
494 // the spec to be supported when the extension is available.
495 if (fAPIVersion >= VK_API_VERSION_1_4) {
496 fVulkan14.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_4_FEATURES;
497 } else {
498 if (exts.fDynamicRenderingLocalReadKHR) {
499 fDynamicRenderingLocalRead.sType =
500 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DYNAMIC_RENDERING_LOCAL_READ_FEATURES;
501 }
502 if (exts.fHostImageCopyEXT) {
503 fHostImageCopy.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_IMAGE_COPY_FEATURES;
504 }
505 if (exts.fLoadStoreOpNoneKHR) {
506 fLoadStoreOpNoneExtension = VK_KHR_LOAD_STORE_OP_NONE_EXTENSION_NAME;
507 } else if (exts.fLoadStoreOpNoneEXT) {
508 fLoadStoreOpNoneExtension = VK_EXT_LOAD_STORE_OP_NONE_EXTENSION_NAME;
509 }
510 }
511 if (fAPIVersion >= VK_API_VERSION_1_3) {
512 fVulkan13.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES;
513 } else {
514 if (exts.fSynchronization2KHR) {
515 fSynchronization2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SYNCHRONIZATION_2_FEATURES;
516 }
517 if (exts.fDynamicRenderingKHR) {
518 fDynamicRendering.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DYNAMIC_RENDERING_FEATURES;
519 }
520 if (exts.fPipelineCreationCacheControlEXT) {
521 fPipelineCreationCacheControl.sType =
522 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_CREATION_CACHE_CONTROL_FEATURES;
523 }
524 if (exts.fExtendedDynamicStateEXT) {
525 fExtendedDynamicState.sType =
526 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_FEATURES_EXT;
527 }
528 if (exts.fExtendedDynamicState2EXT) {
529 fExtendedDynamicState2.sType =
530 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_2_FEATURES_EXT;
531 }
532 if (exts.fCopyCommands2KHR) {
533 fCopyCommands2Extension = VK_KHR_COPY_COMMANDS_2_EXTENSION_NAME;
534 }
535 if (exts.fFormatFeatureFlags2KHR) {
536 fFormatFeatureFlags2Extension = VK_KHR_FORMAT_FEATURE_FLAGS_2_EXTENSION_NAME;
537 }
538 }
539 if (fAPIVersion >= VK_API_VERSION_1_2) {
540 fVulkan11.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES;
541 fVulkan12.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES;
542 } else {
543 if (exts.fSamplerYcbcrConversionKHR) {
544 fSamplerYcbcrConversion.sType =
545 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES;
546 }
547 if (exts.fDriverPropertiesKHR) {
548 fDriverPropertiesExtension = VK_KHR_DRIVER_PROPERTIES_EXTENSION_NAME;
549 }
550 if (exts.fCreateRenderpass2KHR) {
551 fCreateRenderpass2Extension = VK_KHR_CREATE_RENDERPASS_2_EXTENSION_NAME;
552 }
553 if (exts.fDepthStencilResolveKHR) {
554 fDepthStencilResolveExtension = VK_KHR_DEPTH_STENCIL_RESOLVE_EXTENSION_NAME;
555 }
556 }
557 SkASSERT(fAPIVersion >= VK_API_VERSION_1_1);
558
559 if (exts.fRasterizationOrderAttachmentAccessARM) {
560 fRasterizationOrderAttachmentAccess.sType =
561 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RASTERIZATION_ORDER_ATTACHMENT_ACCESS_FEATURES_ARM;
562 fRasterizationOrderAttachmentAccessExtension =
563 VK_ARM_RASTERIZATION_ORDER_ATTACHMENT_ACCESS_EXTENSION_NAME;
564 }
565 if (exts.fRasterizationOrderAttachmentAccessEXT) {
566 fRasterizationOrderAttachmentAccess.sType =
567 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RASTERIZATION_ORDER_ATTACHMENT_ACCESS_FEATURES_EXT;
568 fRasterizationOrderAttachmentAccessExtension =
569 VK_EXT_RASTERIZATION_ORDER_ATTACHMENT_ACCESS_EXTENSION_NAME;
570 }
571 if (exts.fBlendOperationAdvancedEXT) {
572 fBlendOperationAdvanced.sType =
573 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_FEATURES_EXT;
574 }
575 if (exts.fVertexInputDynamicStateEXT) {
576 fVertexInputDynamicState.sType =
577 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_INPUT_DYNAMIC_STATE_FEATURES_EXT;
578 }
579 if (exts.fGraphicsPipelineLibraryEXT) {
580 fGraphicsPipelineLibrary.sType =
581 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GRAPHICS_PIPELINE_LIBRARY_FEATURES_EXT;
582 // Depends on VK_KHR_pipeline_library
583 fPipelineLibraryExtension = VK_KHR_PIPELINE_LIBRARY_EXTENSION_NAME;
584 }
585 if (exts.fRGBA10x6FormatsEXT) {
586 fRGBA10x6Formats.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RGBA10X6_FORMATS_FEATURES_EXT;
587 }
588 if (exts.fMultisampledRenderToSingleSampledEXT) {
589 fMultisampledRenderToSingleSampled.sType =
590 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTISAMPLED_RENDER_TO_SINGLE_SAMPLED_FEATURES_EXT;
591 }
592 if (exts.fConservativeRasterizationEXT) {
593 fConservativeRasterizationExtension = VK_EXT_CONSERVATIVE_RASTERIZATION_EXTENSION_NAME;
594 }
595 #if defined(SK_BUILD_FOR_ANDROID)
596 if (exts.fExternalMemoryAHardwareBufferEXT) {
597 fExternalMemoryAHardwareBufferExtension =
598 VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_EXTENSION_NAME;
599 }
600 #endif
601 if (exts.fFrameBoundaryEXT) {
602 fFrameBoundary.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAME_BOUNDARY_FEATURES_EXT;
603 }
604
605 // Inspect the list of features the app has already included and decide on which features to
606 // add.
607 const FeaturesToAdd toAdd = get_features_to_add(fAPIVersion, exts, appFeatures);
608
609 // Chain any new features we'd like to query.
610 if (toAdd.fVulkan11) {
611 SkASSERT(fVulkan11.sType != 0);
612 AddToPNextChain(&appFeatures, &fVulkan11);
613 }
614 if (toAdd.fVulkan12) {
615 SkASSERT(fVulkan12.sType != 0);
616 AddToPNextChain(&appFeatures, &fVulkan12);
617 }
618 if (toAdd.fVulkan13) {
619 SkASSERT(fVulkan13.sType != 0);
620 AddToPNextChain(&appFeatures, &fVulkan13);
621 }
622 if (toAdd.fVulkan14) {
623 SkASSERT(fVulkan14.sType != 0);
624 AddToPNextChain(&appFeatures, &fVulkan14);
625 }
626 if (toAdd.fRasterizationOrderAttachmentAccess) {
627 SkASSERT(fRasterizationOrderAttachmentAccess.sType != 0);
628 AddToPNextChain(&appFeatures, &fRasterizationOrderAttachmentAccess);
629 }
630 if (toAdd.fBlendOperationAdvanced) {
631 SkASSERT(fBlendOperationAdvanced.sType != 0);
632 AddToPNextChain(&appFeatures, &fBlendOperationAdvanced);
633 }
634 if (toAdd.fExtendedDynamicState) {
635 SkASSERT(fExtendedDynamicState.sType != 0);
636 AddToPNextChain(&appFeatures, &fExtendedDynamicState);
637 }
638 if (toAdd.fExtendedDynamicState2) {
639 SkASSERT(fExtendedDynamicState2.sType != 0);
640 AddToPNextChain(&appFeatures, &fExtendedDynamicState2);
641 }
642 if (toAdd.fVertexInputDynamicState) {
643 SkASSERT(fVertexInputDynamicState.sType != 0);
644 AddToPNextChain(&appFeatures, &fVertexInputDynamicState);
645 }
646 if (toAdd.fGraphicsPipelineLibrary) {
647 SkASSERT(fGraphicsPipelineLibrary.sType != 0);
648 AddToPNextChain(&appFeatures, &fGraphicsPipelineLibrary);
649 }
650 if (toAdd.fSamplerYcbcrConversion) {
651 SkASSERT(fSamplerYcbcrConversion.sType != 0);
652 AddToPNextChain(&appFeatures, &fSamplerYcbcrConversion);
653 }
654 if (toAdd.fRGBA10x6Formats) {
655 SkASSERT(fRGBA10x6Formats.sType != 0);
656 AddToPNextChain(&appFeatures, &fRGBA10x6Formats);
657 }
658 if (toAdd.fSynchronization2) {
659 SkASSERT(fSynchronization2.sType != 0);
660 AddToPNextChain(&appFeatures, &fSynchronization2);
661 }
662 if (toAdd.fDynamicRendering) {
663 SkASSERT(fDynamicRendering.sType != 0);
664 AddToPNextChain(&appFeatures, &fDynamicRendering);
665 }
666 if (toAdd.fDynamicRenderingLocalRead) {
667 SkASSERT(fDynamicRenderingLocalRead.sType != 0);
668 AddToPNextChain(&appFeatures, &fDynamicRenderingLocalRead);
669 }
670 if (toAdd.fMultisampledRenderToSingleSampled) {
671 SkASSERT(fMultisampledRenderToSingleSampled.sType != 0);
672 AddToPNextChain(&appFeatures, &fMultisampledRenderToSingleSampled);
673 }
674 if (toAdd.fHostImageCopy) {
675 SkASSERT(fHostImageCopy.sType != 0);
676 AddToPNextChain(&appFeatures, &fHostImageCopy);
677 }
678 if (toAdd.fPipelineCreationCacheControl) {
679 SkASSERT(fPipelineCreationCacheControl.sType != 0);
680 AddToPNextChain(&appFeatures, &fPipelineCreationCacheControl);
681 }
682 if (toAdd.fFrameBoundary) {
683 SkASSERT(fFrameBoundary.sType != 0);
684 AddToPNextChain(&appFeatures, &fFrameBoundary);
685 }
686
687 fHasAddedFeaturesToQuery = true;
688 }
689
690 void VulkanPreferredFeatures::addFeaturesToEnable(std::vector<const char*>& appExtensions,
691 VkPhysicalDeviceFeatures2& appFeatures) {
692 if (!fHasAddedFeaturesToQuery) {
693 SkDebugf(
694 "WARNING: VulkanPreferredFeatures::addFeaturesToQuery() was not called before "
695 "addFeaturesToEnable, performance may degrade\n");
696 }
697 SkASSERT(fHasAddedFeaturesToQuery);
698
699 FeaturesToAdd toAdd;
700 toAdd.fVulkan11 = fVulkan11.sType != 0;
701 toAdd.fVulkan12 = fVulkan12.sType != 0;
702 toAdd.fVulkan13 = fVulkan13.sType != 0;
703 toAdd.fVulkan14 = fVulkan14.sType != 0;
704 toAdd.fRasterizationOrderAttachmentAccess = fRasterizationOrderAttachmentAccess.sType != 0;
705 toAdd.fBlendOperationAdvanced = fBlendOperationAdvanced.sType != 0;
706 toAdd.fExtendedDynamicState = fExtendedDynamicState.sType != 0;
707 toAdd.fExtendedDynamicState2 = fExtendedDynamicState2.sType != 0;
708 toAdd.fVertexInputDynamicState = fVertexInputDynamicState.sType != 0;
709 toAdd.fGraphicsPipelineLibrary = fGraphicsPipelineLibrary.sType != 0;
710 toAdd.fSamplerYcbcrConversion = fSamplerYcbcrConversion.sType != 0;
711 toAdd.fRGBA10x6Formats = fRGBA10x6Formats.sType != 0;
712 toAdd.fSynchronization2 = fSynchronization2.sType != 0;
713 toAdd.fDynamicRendering = fDynamicRendering.sType != 0;
714 toAdd.fDynamicRenderingLocalRead = fDynamicRenderingLocalRead.sType != 0;
715 toAdd.fMultisampledRenderToSingleSampled = fMultisampledRenderToSingleSampled.sType != 0;
716 toAdd.fHostImageCopy = fHostImageCopy.sType != 0;
717 toAdd.fPipelineCreationCacheControl = fPipelineCreationCacheControl.sType != 0;
718 toAdd.fFrameBoundary = fFrameBoundary.sType != 0;
719
720 // Check which extensions are already enabled by the application.
721 DeviceExtensions exts;
722 for (const char* name : appExtensions) {
723 mark_device_extensions(exts, name);
724 }
725
726 // Add extensions that are not enabled by the app.
727 if (!exts.fRasterizationOrderAttachmentAccessARM &&
728 !exts.fRasterizationOrderAttachmentAccessEXT && toAdd.fRasterizationOrderAttachmentAccess) {
729 appExtensions.push_back(fRasterizationOrderAttachmentAccessExtension);
730 exts.fRasterizationOrderAttachmentAccessEXT = true;
731 }
732 if (!exts.fBlendOperationAdvancedEXT && toAdd.fBlendOperationAdvanced) {
733 appExtensions.push_back(VK_EXT_BLEND_OPERATION_ADVANCED_EXTENSION_NAME);
734 exts.fBlendOperationAdvancedEXT = true;
735 }
736 if (!exts.fExtendedDynamicStateEXT && toAdd.fExtendedDynamicState) {
737 appExtensions.push_back(VK_EXT_EXTENDED_DYNAMIC_STATE_EXTENSION_NAME);
738 exts.fExtendedDynamicStateEXT = true;
739 }
740 if (!exts.fExtendedDynamicState2EXT && toAdd.fExtendedDynamicState2) {
741 appExtensions.push_back(VK_EXT_EXTENDED_DYNAMIC_STATE_2_EXTENSION_NAME);
742 exts.fExtendedDynamicState2EXT = true;
743 }
744 if (!exts.fVertexInputDynamicStateEXT && toAdd.fVertexInputDynamicState) {
745 appExtensions.push_back(VK_EXT_VERTEX_INPUT_DYNAMIC_STATE_EXTENSION_NAME);
746 exts.fVertexInputDynamicStateEXT = true;
747 }
748 if (!exts.fGraphicsPipelineLibraryEXT && toAdd.fGraphicsPipelineLibrary) {
749 appExtensions.push_back(VK_EXT_GRAPHICS_PIPELINE_LIBRARY_EXTENSION_NAME);
750 exts.fGraphicsPipelineLibraryEXT = true;
751 }
752 if (!exts.fSamplerYcbcrConversionKHR && toAdd.fSamplerYcbcrConversion) {
753 appExtensions.push_back(VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME);
754 exts.fSamplerYcbcrConversionKHR = true;
755 }
756 if (!exts.fRGBA10x6FormatsEXT && toAdd.fRGBA10x6Formats) {
757 appExtensions.push_back(VK_EXT_RGBA10X6_FORMATS_EXTENSION_NAME);
758 exts.fRGBA10x6FormatsEXT = true;
759 }
760 if (!exts.fSynchronization2KHR && toAdd.fSynchronization2) {
761 appExtensions.push_back(VK_KHR_SYNCHRONIZATION_2_EXTENSION_NAME);
762 exts.fSynchronization2KHR = true;
763 }
764 if (!exts.fDynamicRenderingKHR && toAdd.fDynamicRendering) {
765 appExtensions.push_back(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
766 exts.fDynamicRenderingKHR = true;
767 }
768 if (!exts.fDynamicRenderingLocalReadKHR && toAdd.fDynamicRenderingLocalRead) {
769 appExtensions.push_back(VK_KHR_DYNAMIC_RENDERING_LOCAL_READ_EXTENSION_NAME);
770 exts.fDynamicRenderingLocalReadKHR = true;
771 }
772 if (!exts.fMultisampledRenderToSingleSampledEXT && toAdd.fMultisampledRenderToSingleSampled) {
773 appExtensions.push_back(VK_EXT_MULTISAMPLED_RENDER_TO_SINGLE_SAMPLED_EXTENSION_NAME);
774 exts.fMultisampledRenderToSingleSampledEXT = true;
775 }
776 if (!exts.fHostImageCopyEXT && toAdd.fHostImageCopy) {
777 appExtensions.push_back(VK_EXT_HOST_IMAGE_COPY_EXTENSION_NAME);
778 exts.fHostImageCopyEXT = true;
779 }
780 if (!exts.fPipelineCreationCacheControlEXT && toAdd.fPipelineCreationCacheControl) {
781 appExtensions.push_back(VK_EXT_PIPELINE_CREATION_CACHE_CONTROL_EXTENSION_NAME);
782 exts.fPipelineCreationCacheControlEXT = true;
783 }
784 if (!exts.fFrameBoundaryEXT && toAdd.fFrameBoundary) {
785 appExtensions.push_back(VK_EXT_FRAME_BOUNDARY_EXTENSION_NAME);
786 exts.fFrameBoundaryEXT = true;
787 }
788 if (!exts.fDriverPropertiesKHR && fDriverPropertiesExtension != nullptr) {
789 appExtensions.push_back(fDriverPropertiesExtension);
790 exts.fDriverPropertiesKHR = true;
791 }
792 if (!exts.fCreateRenderpass2KHR && fCreateRenderpass2Extension != nullptr) {
793 appExtensions.push_back(fCreateRenderpass2Extension);
794 exts.fCreateRenderpass2KHR = true;
795 }
796 if (!exts.fLoadStoreOpNoneKHR && !exts.fLoadStoreOpNoneEXT &&
797 fLoadStoreOpNoneExtension != nullptr) {
798 appExtensions.push_back(fLoadStoreOpNoneExtension);
799 exts.fCreateRenderpass2KHR = true;
800 }
801 if (!exts.fConservativeRasterizationEXT && fConservativeRasterizationExtension != nullptr) {
802 appExtensions.push_back(fConservativeRasterizationExtension);
803 exts.fConservativeRasterizationEXT = true;
804 }
805 #if defined(SK_BUILD_FOR_ANDROID)
806 if (!exts.fExternalMemoryAHardwareBufferEXT &&
807 fExternalMemoryAHardwareBufferExtension != nullptr) {
808 appExtensions.push_back(fExternalMemoryAHardwareBufferExtension);
809 exts.fExternalMemoryAHardwareBufferEXT = true;
810 }
811 #endif
812 if (!exts.fPipelineLibraryKHR && fPipelineLibraryExtension != nullptr) {
813 appExtensions.push_back(fPipelineLibraryExtension);
814 exts.fPipelineLibraryKHR = true;
815 }
816 if (!exts.fCopyCommands2KHR && fCopyCommands2Extension != nullptr) {
817 appExtensions.push_back(fCopyCommands2Extension);
818 exts.fCopyCommands2KHR = true;
819 }
820 if (!exts.fFormatFeatureFlags2KHR && fFormatFeatureFlags2Extension != nullptr) {
821 appExtensions.push_back(fFormatFeatureFlags2Extension);
822 exts.fFormatFeatureFlags2KHR = true;
823 }
824 if (!exts.fDepthStencilResolveKHR && fDepthStencilResolveExtension != nullptr) {
825 appExtensions.push_back(fDepthStencilResolveExtension);
826 exts.fDepthStencilResolveKHR = true;
827 }
828 #if defined(SK_BUILD_FOR_ANDROID)
829 if (!exts.fQueueFamilyForeignEXT && fQueueFamilyForeignExtension != nullptr) {
830 appExtensions.push_back(fQueueFamilyForeignExtension);
831 exts.fQueueFamilyForeignEXT = true;
832 }
833 #endif
834
835 // Go over the app features. There are a couple of possibilities:
836 //
837 // - A struct is included by the app: In this case, if there is a feature Skia wants that
838 // is required to be supported when the extension is present, that feature is enabled.
839 // If an optional feature is supported but disabled by the app, Skia has no visibility into it
840 // right now, but no such feature is used by Skia currently.
841 // - A struct is included byFeaturesToQuery: In this case, if there are features that Skia
842 // doesn't need, they are disabled since the app wasn't relying on those features.
843 // - If a Vulkan1X feature struct needs to be chained, then the individual feature structs that
844 // it subsumes are removed from the chain and their features are enabled in the Vulkan1X
845 // struct instead.
846 //
847 // Note that chaining the Vulkan1X feature struct is preferred where possible, because a 1.X
848 // driver is not obliged to also expose the extensions that are promoted to core in that
849 // version. As such, features are aggregated in Vulkan1X structs when possible and the
850 // individual extension-specific structs are dropped. If Skia requires that Vulkan1X structs be
851 // used when possible, the feature aggregation code below becomes unnecessary.
852 //
853 // In the following, if an extension of interest is enabled, its spec-required main feature is
854 // enabled. Normally this is not needed, as the feature query would return VK_TRUE for that
855 // feature. However, this is done to protect against the app having turned the feature off after
856 // query.
857
858 // Create a new chain of structs. AddToPNextChain is not used because the structs being chained
859 // may already be present in appFeatures' pNext chain.
860 void* newChainStart = nullptr;
861 void** newChainEnd = &newChainStart;
862
863 if (toAdd.fVulkan11) {
864 // Disable all features not used by Skia
865 fVulkan11.storageBuffer16BitAccess = VK_FALSE;
866 fVulkan11.uniformAndStorageBuffer16BitAccess = VK_FALSE;
867 fVulkan11.storagePushConstant16 = VK_FALSE;
868 fVulkan11.storageInputOutput16 = VK_FALSE;
869 fVulkan11.multiview = VK_FALSE;
870 fVulkan11.multiviewGeometryShader = VK_FALSE;
871 fVulkan11.multiviewTessellationShader = VK_FALSE;
872 fVulkan11.variablePointersStorageBuffer = VK_FALSE;
873 fVulkan11.variablePointers = VK_FALSE;
874 fVulkan11.protectedMemory = VK_FALSE;
875 fVulkan11.shaderDrawParameters = VK_FALSE;
876
877 // samplerYcbcrConversion is required since Version 1.4.
878 if (fAPIVersion >= VK_API_VERSION_1_4) {
879 fVulkan11.samplerYcbcrConversion = VK_TRUE;
880 }
881
882 // The following are features from promoted extensions, where the original extension did not
883 // have a feature.
884 if (exts.fShaderDrawParametersKHR) {
885 fVulkan11.shaderDrawParameters = VK_TRUE;
886 }
887 }
888 if (toAdd.fVulkan12) {
889 // Disable all features not used by Skia
890 fVulkan12.samplerMirrorClampToEdge = VK_FALSE;
891 fVulkan12.drawIndirectCount = VK_FALSE;
892 fVulkan12.storageBuffer8BitAccess = VK_FALSE;
893 fVulkan12.uniformAndStorageBuffer8BitAccess = VK_FALSE;
894 fVulkan12.storagePushConstant8 = VK_FALSE;
895 fVulkan12.shaderBufferInt64Atomics = VK_FALSE;
896 fVulkan12.shaderSharedInt64Atomics = VK_FALSE;
897 fVulkan12.shaderFloat16 = VK_FALSE;
898 fVulkan12.shaderInt8 = VK_FALSE;
899 fVulkan12.descriptorIndexing = VK_FALSE;
900 fVulkan12.shaderInputAttachmentArrayDynamicIndexing = VK_FALSE;
901 fVulkan12.shaderUniformTexelBufferArrayDynamicIndexing = VK_FALSE;
902 fVulkan12.shaderStorageTexelBufferArrayDynamicIndexing = VK_FALSE;
903 fVulkan12.shaderUniformBufferArrayNonUniformIndexing = VK_FALSE;
904 fVulkan12.shaderSampledImageArrayNonUniformIndexing = VK_FALSE;
905 fVulkan12.shaderStorageBufferArrayNonUniformIndexing = VK_FALSE;
906 fVulkan12.shaderStorageImageArrayNonUniformIndexing = VK_FALSE;
907 fVulkan12.shaderInputAttachmentArrayNonUniformIndexing = VK_FALSE;
908 fVulkan12.shaderUniformTexelBufferArrayNonUniformIndexing = VK_FALSE;
909 fVulkan12.shaderStorageTexelBufferArrayNonUniformIndexing = VK_FALSE;
910 fVulkan12.descriptorBindingUniformBufferUpdateAfterBind = VK_FALSE;
911 fVulkan12.descriptorBindingSampledImageUpdateAfterBind = VK_FALSE;
912 fVulkan12.descriptorBindingStorageImageUpdateAfterBind = VK_FALSE;
913 fVulkan12.descriptorBindingStorageBufferUpdateAfterBind = VK_FALSE;
914 fVulkan12.descriptorBindingUniformTexelBufferUpdateAfterBind = VK_FALSE;
915 fVulkan12.descriptorBindingStorageTexelBufferUpdateAfterBind = VK_FALSE;
916 fVulkan12.descriptorBindingUpdateUnusedWhilePending = VK_FALSE;
917 fVulkan12.descriptorBindingPartiallyBound = VK_FALSE;
918 fVulkan12.descriptorBindingVariableDescriptorCount = VK_FALSE;
919 fVulkan12.runtimeDescriptorArray = VK_FALSE;
920 fVulkan12.samplerFilterMinmax = VK_FALSE;
921 fVulkan12.scalarBlockLayout = VK_FALSE;
922 fVulkan12.imagelessFramebuffer = VK_FALSE;
923 fVulkan12.uniformBufferStandardLayout = VK_FALSE;
924 fVulkan12.shaderSubgroupExtendedTypes = VK_FALSE;
925 fVulkan12.separateDepthStencilLayouts = VK_FALSE;
926 fVulkan12.hostQueryReset = VK_FALSE;
927 fVulkan12.timelineSemaphore = VK_FALSE;
928 fVulkan12.bufferDeviceAddress = VK_FALSE;
929 fVulkan12.bufferDeviceAddressCaptureReplay = VK_FALSE;
930 fVulkan12.bufferDeviceAddressMultiDevice = VK_FALSE;
931 fVulkan12.vulkanMemoryModel = VK_FALSE;
932 fVulkan12.vulkanMemoryModelDeviceScope = VK_FALSE;
933 fVulkan12.vulkanMemoryModelAvailabilityVisibilityChains = VK_FALSE;
934 fVulkan12.shaderOutputViewportIndex = VK_FALSE;
935 fVulkan12.shaderOutputLayer = VK_FALSE;
936 fVulkan12.subgroupBroadcastDynamicId = VK_FALSE;
937
938 // No required feature of Vulkan 1.2 is currently needed. The imagelessFramebuffer feature
939 // is a candidate, but likely better to not bother and go directly with dynamic rendering.
940
941 // The following are features from promoted extensions, where the original extension did not
942 // have a feature.
943 if (exts.fDrawIndirectCountKHR) {
944 fVulkan12.drawIndirectCount = VK_TRUE;
945 }
946 if (exts.fSamplerMirrorClampToEdgeKHR) {
947 fVulkan12.samplerMirrorClampToEdge = VK_TRUE;
948 }
949 if (exts.fDescriptorIndexingEXT) {
950 fVulkan12.descriptorIndexing = VK_TRUE;
951 }
952 if (exts.fSamplerFilterMinmaxEXT) {
953 fVulkan12.samplerFilterMinmax = VK_TRUE;
954 }
955 if (exts.fShaderViewportIndexLayerEXT) {
956 fVulkan12.shaderOutputViewportIndex = VK_TRUE;
957 fVulkan12.shaderOutputLayer = VK_TRUE;
958 }
959 }
960 if (toAdd.fVulkan13) {
961 // Disable all features not used by Skia
962 fVulkan13.robustImageAccess = VK_FALSE;
963 fVulkan13.inlineUniformBlock = VK_FALSE;
964 fVulkan13.descriptorBindingInlineUniformBlockUpdateAfterBind = VK_FALSE;
965 fVulkan13.privateData = VK_FALSE;
966 fVulkan13.shaderDemoteToHelperInvocation = VK_FALSE;
967 fVulkan13.shaderTerminateInvocation = VK_FALSE;
968 fVulkan13.subgroupSizeControl = VK_FALSE;
969 fVulkan13.computeFullSubgroups = VK_FALSE;
970 fVulkan13.textureCompressionASTC_HDR = VK_FALSE;
971 fVulkan13.shaderZeroInitializeWorkgroupMemory = VK_FALSE;
972 fVulkan13.shaderIntegerDotProduct = VK_FALSE;
973 fVulkan13.maintenance4 = VK_FALSE;
974
975 // synchronization2, dynamicRendering and pipelineCreationCacheControl are required features
976 // of Vulkan 1.3.
977 fVulkan13.synchronization2 = VK_TRUE;
978 fVulkan13.dynamicRendering = VK_TRUE;
979 fVulkan13.pipelineCreationCacheControl = VK_TRUE;
980 }
981 if (toAdd.fVulkan14) {
982 // Disable all features not used by Skia
983 fVulkan14.globalPriorityQuery = VK_FALSE;
984 fVulkan14.shaderSubgroupRotate = VK_FALSE;
985 fVulkan14.shaderSubgroupRotateClustered = VK_FALSE;
986 fVulkan14.shaderFloatControls2 = VK_FALSE;
987 fVulkan14.shaderExpectAssume = VK_FALSE;
988 fVulkan14.rectangularLines = VK_FALSE;
989 fVulkan14.bresenhamLines = VK_FALSE;
990 fVulkan14.smoothLines = VK_FALSE;
991 fVulkan14.stippledRectangularLines = VK_FALSE;
992 fVulkan14.stippledBresenhamLines = VK_FALSE;
993 fVulkan14.stippledSmoothLines = VK_FALSE;
994 fVulkan14.vertexAttributeInstanceRateDivisor = VK_FALSE;
995 fVulkan14.vertexAttributeInstanceRateZeroDivisor = VK_FALSE;
996 fVulkan14.indexTypeUint8 = VK_FALSE;
997 fVulkan14.maintenance5 = VK_FALSE;
998 fVulkan14.maintenance6 = VK_FALSE;
999 fVulkan14.pipelineProtectedAccess = VK_FALSE;
1000 fVulkan14.pipelineRobustness = VK_FALSE;
1001 fVulkan14.pushDescriptor = VK_FALSE;
1002
1003 // dynamicRenderingLocalRead is a required feature of Vulkan 1.4.
1004 fVulkan14.dynamicRenderingLocalRead = VK_TRUE;
1005
1006 // The following are features from promoted extensions, where the original extension did not
1007 // have a feature.
1008 if (exts.fPushDescriptorKHR) {
1009 fVulkan14.pushDescriptor = VK_TRUE;
1010 }
1011 }
1012
1013 bool hasVulkan11Features = toAdd.fVulkan11;
1014 bool hasVulkan12Features = toAdd.fVulkan12;
1015 bool hasVulkan13Features = toAdd.fVulkan13;
1016 bool hasVulkan14Features = toAdd.fVulkan14;
1017
1018 // If chained by Skia, disable depth/stencil coherence even if supported, in case it comes with
1019 // a perf cost.
1020 fRasterizationOrderAttachmentAccess.rasterizationOrderDepthAttachmentAccess = VK_FALSE;
1021 fRasterizationOrderAttachmentAccess.rasterizationOrderStencilAttachmentAccess = VK_FALSE;
1022
1023 // If chained by Skia, disable dynamic state that is unused by Skia.
1024 fExtendedDynamicState2.extendedDynamicState2LogicOp = VK_FALSE;
1025 fExtendedDynamicState2.extendedDynamicState2PatchControlPoints = VK_FALSE;
1026
1027 // Helper to enable a feature in the feature aggregate struct if it's enabled in the
1028 // extension-specific struct. It reduces code verbosity but more importantly ensures the feature
1029 // name is identical and reduces chance of copy-paste mistakes.
1030 #define DUP_INTO(aggregate, feature) aggregate.feature |= features->feature
1031
1032 VkBaseOutStructure* pNext = static_cast<VkBaseOutStructure*>(appFeatures.pNext);
1033 while (pNext) {
1034 switch (pNext->sType) {
1035 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES: {
1036 auto* features = reinterpret_cast<VkPhysicalDeviceVulkan11Features*>(pNext);
1037 // If this struct is not chained by Skia, copy enabled features.
1038 if (features != &fVulkan11) {
1039 DUP_INTO(fVulkan11, storageBuffer16BitAccess);
1040 DUP_INTO(fVulkan11, uniformAndStorageBuffer16BitAccess);
1041 DUP_INTO(fVulkan11, storagePushConstant16);
1042 DUP_INTO(fVulkan11, storageInputOutput16);
1043 DUP_INTO(fVulkan11, multiview);
1044 DUP_INTO(fVulkan11, multiviewGeometryShader);
1045 DUP_INTO(fVulkan11, multiviewTessellationShader);
1046 DUP_INTO(fVulkan11, variablePointersStorageBuffer);
1047 DUP_INTO(fVulkan11, variablePointers);
1048 DUP_INTO(fVulkan11, protectedMemory);
1049 DUP_INTO(fVulkan11, samplerYcbcrConversion);
1050 DUP_INTO(fVulkan11, shaderDrawParameters);
1051 }
1052 break;
1053 }
1054 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES: {
1055 auto* features = reinterpret_cast<VkPhysicalDeviceVulkan12Features*>(pNext);
1056 // If this struct is not chained by Skia, copy enabled features.
1057 if (features != &fVulkan12) {
1058 DUP_INTO(fVulkan12, samplerMirrorClampToEdge);
1059 DUP_INTO(fVulkan12, drawIndirectCount);
1060 DUP_INTO(fVulkan12, storageBuffer8BitAccess);
1061 DUP_INTO(fVulkan12, uniformAndStorageBuffer8BitAccess);
1062 DUP_INTO(fVulkan12, storagePushConstant8);
1063 DUP_INTO(fVulkan12, shaderBufferInt64Atomics);
1064 DUP_INTO(fVulkan12, shaderSharedInt64Atomics);
1065 DUP_INTO(fVulkan12, shaderFloat16);
1066 DUP_INTO(fVulkan12, shaderInt8);
1067 DUP_INTO(fVulkan12, descriptorIndexing);
1068 DUP_INTO(fVulkan12, shaderInputAttachmentArrayDynamicIndexing);
1069 DUP_INTO(fVulkan12, shaderUniformTexelBufferArrayDynamicIndexing);
1070 DUP_INTO(fVulkan12, shaderStorageTexelBufferArrayDynamicIndexing);
1071 DUP_INTO(fVulkan12, shaderUniformBufferArrayNonUniformIndexing);
1072 DUP_INTO(fVulkan12, shaderSampledImageArrayNonUniformIndexing);
1073 DUP_INTO(fVulkan12, shaderStorageBufferArrayNonUniformIndexing);
1074 DUP_INTO(fVulkan12, shaderStorageImageArrayNonUniformIndexing);
1075 DUP_INTO(fVulkan12, shaderInputAttachmentArrayNonUniformIndexing);
1076 DUP_INTO(fVulkan12, shaderUniformTexelBufferArrayNonUniformIndexing);
1077 DUP_INTO(fVulkan12, shaderStorageTexelBufferArrayNonUniformIndexing);
1078 DUP_INTO(fVulkan12, descriptorBindingUniformBufferUpdateAfterBind);
1079 DUP_INTO(fVulkan12, descriptorBindingSampledImageUpdateAfterBind);
1080 DUP_INTO(fVulkan12, descriptorBindingStorageImageUpdateAfterBind);
1081 DUP_INTO(fVulkan12, descriptorBindingStorageBufferUpdateAfterBind);
1082 DUP_INTO(fVulkan12, descriptorBindingUniformTexelBufferUpdateAfterBind);
1083 DUP_INTO(fVulkan12, descriptorBindingStorageTexelBufferUpdateAfterBind);
1084 DUP_INTO(fVulkan12, descriptorBindingUpdateUnusedWhilePending);
1085 DUP_INTO(fVulkan12, descriptorBindingPartiallyBound);
1086 DUP_INTO(fVulkan12, descriptorBindingVariableDescriptorCount);
1087 DUP_INTO(fVulkan12, runtimeDescriptorArray);
1088 DUP_INTO(fVulkan12, samplerFilterMinmax);
1089 DUP_INTO(fVulkan12, scalarBlockLayout);
1090 DUP_INTO(fVulkan12, imagelessFramebuffer);
1091 DUP_INTO(fVulkan12, uniformBufferStandardLayout);
1092 DUP_INTO(fVulkan12, shaderSubgroupExtendedTypes);
1093 DUP_INTO(fVulkan12, separateDepthStencilLayouts);
1094 DUP_INTO(fVulkan12, hostQueryReset);
1095 DUP_INTO(fVulkan12, timelineSemaphore);
1096 DUP_INTO(fVulkan12, bufferDeviceAddress);
1097 DUP_INTO(fVulkan12, bufferDeviceAddressCaptureReplay);
1098 DUP_INTO(fVulkan12, bufferDeviceAddressMultiDevice);
1099 DUP_INTO(fVulkan12, vulkanMemoryModel);
1100 DUP_INTO(fVulkan12, vulkanMemoryModelDeviceScope);
1101 DUP_INTO(fVulkan12, vulkanMemoryModelAvailabilityVisibilityChains);
1102 DUP_INTO(fVulkan12, shaderOutputViewportIndex);
1103 DUP_INTO(fVulkan12, shaderOutputLayer);
1104 DUP_INTO(fVulkan12, subgroupBroadcastDynamicId);
1105 }
1106 break;
1107 }
1108 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES: {
1109 auto* features = reinterpret_cast<VkPhysicalDeviceVulkan13Features*>(pNext);
1110 // If this struct is not chained by Skia, copy enabled features.
1111 if (features != &fVulkan13) {
1112 DUP_INTO(fVulkan13, robustImageAccess);
1113 DUP_INTO(fVulkan13, inlineUniformBlock);
1114 DUP_INTO(fVulkan13, descriptorBindingInlineUniformBlockUpdateAfterBind);
1115 DUP_INTO(fVulkan13, pipelineCreationCacheControl);
1116 DUP_INTO(fVulkan13, privateData);
1117 DUP_INTO(fVulkan13, shaderDemoteToHelperInvocation);
1118 DUP_INTO(fVulkan13, shaderTerminateInvocation);
1119 DUP_INTO(fVulkan13, subgroupSizeControl);
1120 DUP_INTO(fVulkan13, computeFullSubgroups);
1121 DUP_INTO(fVulkan13, synchronization2);
1122 DUP_INTO(fVulkan13, textureCompressionASTC_HDR);
1123 DUP_INTO(fVulkan13, shaderZeroInitializeWorkgroupMemory);
1124 DUP_INTO(fVulkan13, dynamicRendering);
1125 DUP_INTO(fVulkan13, shaderIntegerDotProduct);
1126 DUP_INTO(fVulkan13, maintenance4);
1127 }
1128 break;
1129 }
1130 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_4_FEATURES: {
1131 auto* features = reinterpret_cast<VkPhysicalDeviceVulkan14Features*>(pNext);
1132 // If this struct is not chained by Skia, copy enabled features.
1133 if (features != &fVulkan14) {
1134 DUP_INTO(fVulkan14, globalPriorityQuery);
1135 DUP_INTO(fVulkan14, shaderSubgroupRotate);
1136 DUP_INTO(fVulkan14, shaderSubgroupRotateClustered);
1137 DUP_INTO(fVulkan14, shaderFloatControls2);
1138 DUP_INTO(fVulkan14, shaderExpectAssume);
1139 DUP_INTO(fVulkan14, rectangularLines);
1140 DUP_INTO(fVulkan14, bresenhamLines);
1141 DUP_INTO(fVulkan14, smoothLines);
1142 DUP_INTO(fVulkan14, stippledRectangularLines);
1143 DUP_INTO(fVulkan14, stippledBresenhamLines);
1144 DUP_INTO(fVulkan14, stippledSmoothLines);
1145 DUP_INTO(fVulkan14, vertexAttributeInstanceRateDivisor);
1146 DUP_INTO(fVulkan14, vertexAttributeInstanceRateZeroDivisor);
1147 DUP_INTO(fVulkan14, indexTypeUint8);
1148 DUP_INTO(fVulkan14, dynamicRenderingLocalRead);
1149 DUP_INTO(fVulkan14, maintenance5);
1150 DUP_INTO(fVulkan14, maintenance6);
1151 DUP_INTO(fVulkan14, pipelineProtectedAccess);
1152 DUP_INTO(fVulkan14, pipelineRobustness);
1153 DUP_INTO(fVulkan14, hostImageCopy);
1154 DUP_INTO(fVulkan14, pushDescriptor);
1155 }
1156 break;
1157 }
1158 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RASTERIZATION_ORDER_ATTACHMENT_ACCESS_FEATURES_EXT: {
1159 chain(newChainEnd, pNext);
1160 toAdd.fRasterizationOrderAttachmentAccess = false;
1161 break;
1162 }
1163 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_FEATURES_EXT: {
1164 chain(newChainEnd, pNext);
1165 toAdd.fBlendOperationAdvanced = false;
1166 break;
1167 }
1168 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_FEATURES_EXT: {
1169 // Drop this struct if Vulkan 1.3 is enabled
1170 if (!hasVulkan13Features) {
1171 chain(newChainEnd, pNext);
1172
1173 // Enable the main feature
1174 if (exts.fExtendedDynamicStateEXT) {
1175 auto* features =
1176 reinterpret_cast<VkPhysicalDeviceExtendedDynamicStateFeaturesEXT*>(
1177 pNext);
1178 features->extendedDynamicState = VK_TRUE;
1179 }
1180 }
1181 toAdd.fExtendedDynamicState = false;
1182 break;
1183 }
1184 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_2_FEATURES_EXT: {
1185 // Drop this struct if Vulkan 1.3 is enabled and the extension's optional features
1186 // are not (they are not promoted to 1.3).
1187 auto* features =
1188 reinterpret_cast<VkPhysicalDeviceExtendedDynamicState2FeaturesEXT*>(pNext);
1189 if (!hasVulkan13Features && !features->extendedDynamicState2LogicOp &&
1190 !features->extendedDynamicState2PatchControlPoints) {
1191 chain(newChainEnd, pNext);
1192
1193 // Enable the main feature
1194 if (exts.fExtendedDynamicState2EXT) {
1195 features->extendedDynamicState2 = VK_TRUE;
1196 }
1197 }
1198 toAdd.fExtendedDynamicState2 = false;
1199 break;
1200 }
1201 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_INPUT_DYNAMIC_STATE_FEATURES_EXT: {
1202 chain(newChainEnd, pNext);
1203 // Enable the main feature
1204 if (exts.fVertexInputDynamicStateEXT) {
1205 auto* features =
1206 reinterpret_cast<VkPhysicalDeviceVertexInputDynamicStateFeaturesEXT*>(
1207 pNext);
1208 features->vertexInputDynamicState = VK_TRUE;
1209 }
1210 toAdd.fVertexInputDynamicState = false;
1211 break;
1212 }
1213 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GRAPHICS_PIPELINE_LIBRARY_FEATURES_EXT: {
1214 chain(newChainEnd, pNext);
1215 // Enable the main feature
1216 if (exts.fGraphicsPipelineLibraryEXT) {
1217 auto* features =
1218 reinterpret_cast<VkPhysicalDeviceGraphicsPipelineLibraryFeaturesEXT*>(
1219 pNext);
1220 features->graphicsPipelineLibrary = VK_TRUE;
1221 }
1222 toAdd.fGraphicsPipelineLibrary = false;
1223 break;
1224 }
1225 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES: {
1226 // Drop this struct if using the Vulkan 1.1 feature struct
1227 if (!hasVulkan11Features) {
1228 chain(newChainEnd, pNext);
1229
1230 // Enable the main feature
1231 if (exts.fSamplerYcbcrConversionKHR) {
1232 auto* features =
1233 reinterpret_cast<VkPhysicalDeviceSamplerYcbcrConversionFeatures*>(
1234 pNext);
1235 features->samplerYcbcrConversion = VK_TRUE;
1236 }
1237 }
1238 toAdd.fSamplerYcbcrConversion = false;
1239 break;
1240 }
1241 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RGBA10X6_FORMATS_FEATURES_EXT: {
1242 chain(newChainEnd, pNext);
1243 toAdd.fRGBA10x6Formats = false;
1244 break;
1245 }
1246 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SYNCHRONIZATION_2_FEATURES: {
1247 // Drop this struct if Vulkan 1.3 is enabled
1248 if (!hasVulkan13Features) {
1249 chain(newChainEnd, pNext);
1250 // Enable the main feature
1251 if (exts.fSynchronization2KHR) {
1252 auto* features =
1253 reinterpret_cast<VkPhysicalDeviceSynchronization2Features*>(pNext);
1254 features->synchronization2 = VK_TRUE;
1255 }
1256 }
1257 toAdd.fSynchronization2 = false;
1258 break;
1259 }
1260 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DYNAMIC_RENDERING_FEATURES: {
1261 // Drop this struct if Vulkan 1.3 is enabled
1262 if (!hasVulkan13Features) {
1263 chain(newChainEnd, pNext);
1264 // Enable the main feature
1265 if (exts.fDynamicRenderingKHR) {
1266 auto* features =
1267 reinterpret_cast<VkPhysicalDeviceDynamicRenderingFeatures*>(pNext);
1268 features->dynamicRendering = VK_TRUE;
1269 }
1270 }
1271 toAdd.fDynamicRendering = false;
1272 break;
1273 }
1274 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DYNAMIC_RENDERING_LOCAL_READ_FEATURES: {
1275 // Drop this struct if Vulkan 1.4 is enabled
1276 if (!hasVulkan14Features) {
1277 chain(newChainEnd, pNext);
1278 // Enable the main feature
1279 if (exts.fDynamicRenderingLocalReadKHR) {
1280 auto* features = reinterpret_cast<
1281 VkPhysicalDeviceDynamicRenderingLocalReadFeatures*>(pNext);
1282 features->dynamicRenderingLocalRead = VK_TRUE;
1283 }
1284 toAdd.fDynamicRenderingLocalRead = false;
1285 }
1286 break;
1287 }
1288 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTISAMPLED_RENDER_TO_SINGLE_SAMPLED_FEATURES_EXT: {
1289 chain(newChainEnd, pNext);
1290 // Enable the main feature
1291 if (exts.fMultisampledRenderToSingleSampledEXT) {
1292 auto* features = reinterpret_cast<
1293 VkPhysicalDeviceMultisampledRenderToSingleSampledFeaturesEXT*>(pNext);
1294 features->multisampledRenderToSingleSampled = VK_TRUE;
1295 }
1296 toAdd.fMultisampledRenderToSingleSampled = false;
1297 break;
1298 }
1299 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_IMAGE_COPY_FEATURES: {
1300 // Drop this struct if Vulkan 1.4 is enabled
1301 if (!hasVulkan14Features) {
1302 chain(newChainEnd, pNext);
1303 // Enable the main feature
1304 if (exts.fHostImageCopyEXT) {
1305 auto* features =
1306 reinterpret_cast<VkPhysicalDeviceHostImageCopyFeatures*>(pNext);
1307 features->hostImageCopy = VK_TRUE;
1308 }
1309 }
1310 toAdd.fHostImageCopy = false;
1311 break;
1312 }
1313 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_CREATION_CACHE_CONTROL_FEATURES: {
1314 // Drop this struct if Vulkan 1.3 is enabled
1315 if (!hasVulkan13Features) {
1316 chain(newChainEnd, pNext);
1317 // Enable the main feature
1318 if (exts.fPipelineCreationCacheControlEXT) {
1319 auto* features = reinterpret_cast<
1320 VkPhysicalDevicePipelineCreationCacheControlFeatures*>(pNext);
1321 features->pipelineCreationCacheControl = VK_TRUE;
1322 }
1323 }
1324 toAdd.fPipelineCreationCacheControl = false;
1325 break;
1326 }
1327 // Gather features promoted to Vulkan 1.1 and drop their structs per the following valid
1328 // usage statement:
1329 //
1330 // If the pNext chain includes a VkPhysicalDeviceVulkan11Features structure, then it
1331 // must not include a VkPhysicalDevice16BitStorageFeatures,
1332 // VkPhysicalDeviceMultiviewFeatures, VkPhysicalDeviceVariablePointersFeatures,
1333 // VkPhysicalDeviceProtectedMemoryFeatures,
1334 // VkPhysicalDeviceSamplerYcbcrConversionFeatures, or
1335 // VkPhysicalDeviceShaderDrawParametersFeatures structure
1336 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES: {
1337 if (hasVulkan11Features) {
1338 auto* features = reinterpret_cast<VkPhysicalDevice16BitStorageFeatures*>(pNext);
1339 DUP_INTO(fVulkan11, storageBuffer16BitAccess);
1340 DUP_INTO(fVulkan11, uniformAndStorageBuffer16BitAccess);
1341 DUP_INTO(fVulkan11, storagePushConstant16);
1342 DUP_INTO(fVulkan11, storageInputOutput16);
1343 } else {
1344 chain(newChainEnd, pNext);
1345 }
1346 break;
1347 }
1348 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES: {
1349 if (hasVulkan11Features) {
1350 auto* features = reinterpret_cast<VkPhysicalDeviceMultiviewFeatures*>(pNext);
1351 DUP_INTO(fVulkan11, multiview);
1352 DUP_INTO(fVulkan11, multiviewGeometryShader);
1353 DUP_INTO(fVulkan11, multiviewTessellationShader);
1354 } else {
1355 chain(newChainEnd, pNext);
1356 }
1357 break;
1358 }
1359 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES: {
1360 if (hasVulkan11Features) {
1361 auto* features =
1362 reinterpret_cast<VkPhysicalDeviceVariablePointersFeatures*>(pNext);
1363 DUP_INTO(fVulkan11, variablePointersStorageBuffer);
1364 DUP_INTO(fVulkan11, variablePointers);
1365 } else {
1366 chain(newChainEnd, pNext);
1367 }
1368 break;
1369 }
1370 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES: {
1371 if (hasVulkan11Features) {
1372 auto* features =
1373 reinterpret_cast<VkPhysicalDeviceProtectedMemoryFeatures*>(pNext);
1374 DUP_INTO(fVulkan11, protectedMemory);
1375 } else {
1376 chain(newChainEnd, pNext);
1377 }
1378 break;
1379 }
1380 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETERS_FEATURES: {
1381 if (hasVulkan11Features) {
1382 auto* features =
1383 reinterpret_cast<VkPhysicalDeviceShaderDrawParametersFeatures*>(pNext);
1384 DUP_INTO(fVulkan11, shaderDrawParameters);
1385 } else {
1386 chain(newChainEnd, pNext);
1387 }
1388 break;
1389 }
1390
1391 // Gather features promoted to Vulkan 1.2 and drop their structs per the following valid
1392 // usage statement:
1393 //
1394 // If the pNext chain includes a VkPhysicalDeviceVulkan12Features structure, then it
1395 // must not include a VkPhysicalDevice8BitStorageFeatures,
1396 // VkPhysicalDeviceShaderAtomicInt64Features, VkPhysicalDeviceShaderFloat16Int8Features,
1397 // VkPhysicalDeviceDescriptorIndexingFeatures,
1398 // VkPhysicalDeviceScalarBlockLayoutFeatures,
1399 // VkPhysicalDeviceImagelessFramebufferFeatures,
1400 // VkPhysicalDeviceUniformBufferStandardLayoutFeatures,
1401 // VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures,
1402 // VkPhysicalDeviceSeparateDepthStencilLayoutsFeatures,
1403 // VkPhysicalDeviceHostQueryResetFeatures, VkPhysicalDeviceTimelineSemaphoreFeatures,
1404 // VkPhysicalDeviceBufferDeviceAddressFeatures, or
1405 // VkPhysicalDeviceVulkanMemoryModelFeatures structure
1406 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES: {
1407 if (hasVulkan12Features) {
1408 auto* features = reinterpret_cast<VkPhysicalDevice8BitStorageFeatures*>(pNext);
1409 DUP_INTO(fVulkan12, storageBuffer8BitAccess);
1410 DUP_INTO(fVulkan12, uniformAndStorageBuffer8BitAccess);
1411 DUP_INTO(fVulkan12, storagePushConstant8);
1412 } else {
1413 chain(newChainEnd, pNext);
1414 }
1415 break;
1416 }
1417 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_INT64_FEATURES: {
1418 if (hasVulkan12Features) {
1419 auto* features =
1420 reinterpret_cast<VkPhysicalDeviceShaderAtomicInt64Features*>(pNext);
1421 DUP_INTO(fVulkan12, shaderBufferInt64Atomics);
1422 DUP_INTO(fVulkan12, shaderSharedInt64Atomics);
1423 } else {
1424 chain(newChainEnd, pNext);
1425 }
1426 break;
1427 }
1428 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_FLOAT16_INT8_FEATURES: {
1429 if (hasVulkan12Features) {
1430 auto* features =
1431 reinterpret_cast<VkPhysicalDeviceShaderFloat16Int8Features*>(pNext);
1432 DUP_INTO(fVulkan12, shaderFloat16);
1433 DUP_INTO(fVulkan12, shaderInt8);
1434 } else {
1435 chain(newChainEnd, pNext);
1436 }
1437 break;
1438 }
1439 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES: {
1440 if (hasVulkan12Features) {
1441 auto* features =
1442 reinterpret_cast<VkPhysicalDeviceDescriptorIndexingFeatures*>(pNext);
1443 DUP_INTO(fVulkan12, shaderInputAttachmentArrayDynamicIndexing);
1444 DUP_INTO(fVulkan12, shaderUniformTexelBufferArrayDynamicIndexing);
1445 DUP_INTO(fVulkan12, shaderStorageTexelBufferArrayDynamicIndexing);
1446 DUP_INTO(fVulkan12, shaderUniformBufferArrayNonUniformIndexing);
1447 DUP_INTO(fVulkan12, shaderSampledImageArrayNonUniformIndexing);
1448 DUP_INTO(fVulkan12, shaderStorageBufferArrayNonUniformIndexing);
1449 DUP_INTO(fVulkan12, shaderStorageImageArrayNonUniformIndexing);
1450 DUP_INTO(fVulkan12, shaderInputAttachmentArrayNonUniformIndexing);
1451 DUP_INTO(fVulkan12, shaderUniformTexelBufferArrayNonUniformIndexing);
1452 DUP_INTO(fVulkan12, shaderStorageTexelBufferArrayNonUniformIndexing);
1453 DUP_INTO(fVulkan12, descriptorBindingUniformBufferUpdateAfterBind);
1454 DUP_INTO(fVulkan12, descriptorBindingSampledImageUpdateAfterBind);
1455 DUP_INTO(fVulkan12, descriptorBindingStorageImageUpdateAfterBind);
1456 DUP_INTO(fVulkan12, descriptorBindingStorageBufferUpdateAfterBind);
1457 DUP_INTO(fVulkan12, descriptorBindingUniformTexelBufferUpdateAfterBind);
1458 DUP_INTO(fVulkan12, descriptorBindingStorageTexelBufferUpdateAfterBind);
1459 DUP_INTO(fVulkan12, descriptorBindingUpdateUnusedWhilePending);
1460 DUP_INTO(fVulkan12, descriptorBindingPartiallyBound);
1461 DUP_INTO(fVulkan12, descriptorBindingVariableDescriptorCount);
1462 DUP_INTO(fVulkan12, runtimeDescriptorArray);
1463 } else {
1464 chain(newChainEnd, pNext);
1465 }
1466 break;
1467 }
1468 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES: {
1469 if (hasVulkan12Features) {
1470 auto* features =
1471 reinterpret_cast<VkPhysicalDeviceScalarBlockLayoutFeatures*>(pNext);
1472 DUP_INTO(fVulkan12, scalarBlockLayout);
1473 } else {
1474 chain(newChainEnd, pNext);
1475 }
1476 break;
1477 }
1478 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES: {
1479 if (hasVulkan12Features) {
1480 auto* features =
1481 reinterpret_cast<VkPhysicalDeviceImagelessFramebufferFeatures*>(pNext);
1482 DUP_INTO(fVulkan12, imagelessFramebuffer);
1483 } else {
1484 chain(newChainEnd, pNext);
1485 }
1486 break;
1487 }
1488 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_UNIFORM_BUFFER_STANDARD_LAYOUT_FEATURES: {
1489 if (hasVulkan12Features) {
1490 auto* features =
1491 reinterpret_cast<VkPhysicalDeviceUniformBufferStandardLayoutFeatures*>(
1492 pNext);
1493 DUP_INTO(fVulkan12, uniformBufferStandardLayout);
1494 } else {
1495 chain(newChainEnd, pNext);
1496 }
1497 break;
1498 }
1499 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_SUBGROUP_EXTENDED_TYPES_FEATURES: {
1500 if (hasVulkan12Features) {
1501 auto* features =
1502 reinterpret_cast<VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures*>(
1503 pNext);
1504 DUP_INTO(fVulkan12, shaderSubgroupExtendedTypes);
1505 } else {
1506 chain(newChainEnd, pNext);
1507 }
1508 break;
1509 }
1510 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SEPARATE_DEPTH_STENCIL_LAYOUTS_FEATURES: {
1511 if (hasVulkan12Features) {
1512 auto* features =
1513 reinterpret_cast<VkPhysicalDeviceSeparateDepthStencilLayoutsFeatures*>(
1514 pNext);
1515 DUP_INTO(fVulkan12, separateDepthStencilLayouts);
1516 } else {
1517 chain(newChainEnd, pNext);
1518 }
1519 break;
1520 }
1521 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES: {
1522 if (hasVulkan12Features) {
1523 auto* features =
1524 reinterpret_cast<VkPhysicalDeviceHostQueryResetFeatures*>(pNext);
1525 DUP_INTO(fVulkan12, hostQueryReset);
1526 } else {
1527 chain(newChainEnd, pNext);
1528 }
1529 break;
1530 }
1531 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TIMELINE_SEMAPHORE_FEATURES: {
1532 if (hasVulkan12Features) {
1533 auto* features =
1534 reinterpret_cast<VkPhysicalDeviceTimelineSemaphoreFeatures*>(pNext);
1535 DUP_INTO(fVulkan12, timelineSemaphore);
1536 } else {
1537 chain(newChainEnd, pNext);
1538 }
1539 break;
1540 }
1541 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES: {
1542 if (hasVulkan12Features) {
1543 auto* features =
1544 reinterpret_cast<VkPhysicalDeviceBufferDeviceAddressFeatures*>(pNext);
1545 DUP_INTO(fVulkan12, bufferDeviceAddress);
1546 DUP_INTO(fVulkan12, bufferDeviceAddressCaptureReplay);
1547 DUP_INTO(fVulkan12, bufferDeviceAddressMultiDevice);
1548 } else {
1549 chain(newChainEnd, pNext);
1550 }
1551 break;
1552 }
1553 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_MEMORY_MODEL_FEATURES: {
1554 if (hasVulkan12Features) {
1555 auto* features =
1556 reinterpret_cast<VkPhysicalDeviceVulkanMemoryModelFeatures*>(pNext);
1557 DUP_INTO(fVulkan12, vulkanMemoryModel);
1558 DUP_INTO(fVulkan12, vulkanMemoryModelDeviceScope);
1559 DUP_INTO(fVulkan12, vulkanMemoryModelAvailabilityVisibilityChains);
1560 } else {
1561 chain(newChainEnd, pNext);
1562 }
1563 break;
1564 }
1565
1566 // Gather features promoted to Vulkan 1.3 and drop their structs per the following valid
1567 // usage statement:
1568 //
1569 // If the pNext chain includes a VkPhysicalDeviceVulkan13Features structure, then it
1570 // must not include a VkPhysicalDeviceDynamicRenderingFeatures,
1571 // VkPhysicalDeviceImageRobustnessFeatures, VkPhysicalDeviceInlineUniformBlockFeatures,
1572 // VkPhysicalDeviceMaintenance4Features,
1573 // VkPhysicalDevicePipelineCreationCacheControlFeatures,
1574 // VkPhysicalDevicePrivateDataFeatures,
1575 // VkPhysicalDeviceShaderDemoteToHelperInvocationFeatures,
1576 // VkPhysicalDeviceShaderIntegerDotProductFeatures,
1577 // VkPhysicalDeviceShaderTerminateInvocationFeatures,
1578 // VkPhysicalDeviceSubgroupSizeControlFeatures,
1579 // VkPhysicalDeviceSynchronization2Features,
1580 // VkPhysicalDeviceTextureCompressionASTCHDRFeatures, or
1581 // VkPhysicalDeviceZeroInitializeWorkgroupMemoryFeatures structure
1582 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_ROBUSTNESS_FEATURES: {
1583 if (hasVulkan13Features) {
1584 auto* features =
1585 reinterpret_cast<VkPhysicalDeviceImageRobustnessFeatures*>(pNext);
1586 DUP_INTO(fVulkan13, robustImageAccess);
1587 } else {
1588 chain(newChainEnd, pNext);
1589 }
1590 break;
1591 }
1592 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_FEATURES: {
1593 if (hasVulkan13Features) {
1594 auto* features =
1595 reinterpret_cast<VkPhysicalDeviceInlineUniformBlockFeatures*>(pNext);
1596 DUP_INTO(fVulkan13, inlineUniformBlock);
1597 DUP_INTO(fVulkan13, descriptorBindingInlineUniformBlockUpdateAfterBind);
1598 } else {
1599 chain(newChainEnd, pNext);
1600 }
1601 break;
1602 }
1603 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_4_FEATURES: {
1604 if (hasVulkan13Features) {
1605 auto* features = reinterpret_cast<VkPhysicalDeviceMaintenance4Features*>(pNext);
1606 DUP_INTO(fVulkan13, maintenance4);
1607 } else {
1608 chain(newChainEnd, pNext);
1609 }
1610 break;
1611 }
1612 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRIVATE_DATA_FEATURES: {
1613 if (hasVulkan13Features) {
1614 auto* features = reinterpret_cast<VkPhysicalDevicePrivateDataFeatures*>(pNext);
1615 DUP_INTO(fVulkan13, privateData);
1616 } else {
1617 chain(newChainEnd, pNext);
1618 }
1619 break;
1620 }
1621 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DEMOTE_TO_HELPER_INVOCATION_FEATURES: {
1622 if (hasVulkan13Features) {
1623 auto* features = reinterpret_cast<
1624 VkPhysicalDeviceShaderDemoteToHelperInvocationFeatures*>(pNext);
1625 DUP_INTO(fVulkan13, shaderDemoteToHelperInvocation);
1626 } else {
1627 chain(newChainEnd, pNext);
1628 }
1629 break;
1630 }
1631 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_INTEGER_DOT_PRODUCT_FEATURES: {
1632 if (hasVulkan13Features) {
1633 auto* features =
1634 reinterpret_cast<VkPhysicalDeviceShaderIntegerDotProductFeatures*>(
1635 pNext);
1636 DUP_INTO(fVulkan13, shaderIntegerDotProduct);
1637 } else {
1638 chain(newChainEnd, pNext);
1639 }
1640 break;
1641 }
1642 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_TERMINATE_INVOCATION_FEATURES: {
1643 if (hasVulkan13Features) {
1644 auto* features =
1645 reinterpret_cast<VkPhysicalDeviceShaderTerminateInvocationFeatures*>(
1646 pNext);
1647 DUP_INTO(fVulkan13, shaderTerminateInvocation);
1648 } else {
1649 chain(newChainEnd, pNext);
1650 }
1651 break;
1652 }
1653 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_FEATURES: {
1654 if (hasVulkan13Features) {
1655 auto* features =
1656 reinterpret_cast<VkPhysicalDeviceSubgroupSizeControlFeatures*>(pNext);
1657 DUP_INTO(fVulkan13, subgroupSizeControl);
1658 DUP_INTO(fVulkan13, computeFullSubgroups);
1659 } else {
1660 chain(newChainEnd, pNext);
1661 }
1662 break;
1663 }
1664 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TEXTURE_COMPRESSION_ASTC_HDR_FEATURES: {
1665 if (hasVulkan13Features) {
1666 auto* features =
1667 reinterpret_cast<VkPhysicalDeviceTextureCompressionASTCHDRFeatures*>(
1668 pNext);
1669 DUP_INTO(fVulkan13, textureCompressionASTC_HDR);
1670 } else {
1671 chain(newChainEnd, pNext);
1672 }
1673 break;
1674 }
1675 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ZERO_INITIALIZE_WORKGROUP_MEMORY_FEATURES: {
1676 if (hasVulkan13Features) {
1677 auto* features = reinterpret_cast<
1678 VkPhysicalDeviceZeroInitializeWorkgroupMemoryFeatures*>(pNext);
1679 DUP_INTO(fVulkan13, shaderZeroInitializeWorkgroupMemory);
1680 } else {
1681 chain(newChainEnd, pNext);
1682 }
1683 break;
1684 }
1685
1686 // Gather features promoted to Vulkan 1.4 and drop their structs per the following valid
1687 // usage statement:
1688 //
1689 // If the pNext chain includes a VkPhysicalDeviceVulkan14Features structure, then it
1690 // must not include a VkPhysicalDeviceGlobalPriorityQueryFeatures,
1691 // VkPhysicalDeviceShaderSubgroupRotateFeatures,
1692 // VkPhysicalDeviceShaderFloatControls2Features,
1693 // VkPhysicalDeviceShaderExpectAssumeFeatures,
1694 // VkPhysicalDeviceLineRasterizationFeatures,
1695 // VkPhysicalDeviceVertexAttributeDivisorFeatures,
1696 // VkPhysicalDeviceIndexTypeUint8Features,
1697 // VkPhysicalDeviceDynamicRenderingLocalReadFeatures,
1698 // VkPhysicalDeviceMaintenance5Features, VkPhysicalDeviceMaintenance6Features,
1699 // VkPhysicalDevicePipelineProtectedAccessFeatures,
1700 // VkPhysicalDevicePipelineRobustnessFeatures, or VkPhysicalDeviceHostImageCopyFeatures
1701 // structure
1702 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GLOBAL_PRIORITY_QUERY_FEATURES: {
1703 if (hasVulkan14Features) {
1704 auto* features =
1705 reinterpret_cast<VkPhysicalDeviceGlobalPriorityQueryFeatures*>(pNext);
1706 DUP_INTO(fVulkan14, globalPriorityQuery);
1707 } else {
1708 chain(newChainEnd, pNext);
1709 }
1710 break;
1711 }
1712 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_SUBGROUP_ROTATE_FEATURES: {
1713 if (hasVulkan14Features) {
1714 auto* features =
1715 reinterpret_cast<VkPhysicalDeviceShaderSubgroupRotateFeatures*>(pNext);
1716 DUP_INTO(fVulkan14, shaderSubgroupRotate);
1717 DUP_INTO(fVulkan14, shaderSubgroupRotateClustered);
1718 } else {
1719 chain(newChainEnd, pNext);
1720 }
1721 break;
1722 }
1723 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_FLOAT_CONTROLS_2_FEATURES: {
1724 if (hasVulkan14Features) {
1725 auto* features =
1726 reinterpret_cast<VkPhysicalDeviceShaderFloatControls2Features*>(pNext);
1727 DUP_INTO(fVulkan14, shaderFloatControls2);
1728 } else {
1729 chain(newChainEnd, pNext);
1730 }
1731 break;
1732 }
1733 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_EXPECT_ASSUME_FEATURES: {
1734 if (hasVulkan14Features) {
1735 auto* features =
1736 reinterpret_cast<VkPhysicalDeviceShaderExpectAssumeFeatures*>(pNext);
1737 DUP_INTO(fVulkan14, shaderExpectAssume);
1738 } else {
1739 chain(newChainEnd, pNext);
1740 }
1741 break;
1742 }
1743 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_FEATURES: {
1744 if (hasVulkan14Features) {
1745 auto* features =
1746 reinterpret_cast<VkPhysicalDeviceLineRasterizationFeatures*>(pNext);
1747 DUP_INTO(fVulkan14, rectangularLines);
1748 DUP_INTO(fVulkan14, bresenhamLines);
1749 DUP_INTO(fVulkan14, smoothLines);
1750 DUP_INTO(fVulkan14, stippledRectangularLines);
1751 DUP_INTO(fVulkan14, stippledBresenhamLines);
1752 DUP_INTO(fVulkan14, stippledSmoothLines);
1753 } else {
1754 chain(newChainEnd, pNext);
1755 }
1756 break;
1757 }
1758 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES: {
1759 if (hasVulkan14Features) {
1760 auto* features =
1761 reinterpret_cast<VkPhysicalDeviceVertexAttributeDivisorFeatures*>(
1762 pNext);
1763 DUP_INTO(fVulkan14, vertexAttributeInstanceRateDivisor);
1764 DUP_INTO(fVulkan14, vertexAttributeInstanceRateZeroDivisor);
1765 } else {
1766 chain(newChainEnd, pNext);
1767 }
1768 break;
1769 }
1770 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES: {
1771 if (hasVulkan14Features) {
1772 auto* features =
1773 reinterpret_cast<VkPhysicalDeviceIndexTypeUint8Features*>(pNext);
1774 DUP_INTO(fVulkan14, indexTypeUint8);
1775 } else {
1776 chain(newChainEnd, pNext);
1777 }
1778 break;
1779 }
1780 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_5_FEATURES: {
1781 if (hasVulkan14Features) {
1782 auto* features = reinterpret_cast<VkPhysicalDeviceMaintenance5Features*>(pNext);
1783 DUP_INTO(fVulkan14, maintenance5);
1784 } else {
1785 chain(newChainEnd, pNext);
1786 }
1787 break;
1788 }
1789 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_6_FEATURES: {
1790 if (hasVulkan14Features) {
1791 auto* features = reinterpret_cast<VkPhysicalDeviceMaintenance6Features*>(pNext);
1792 DUP_INTO(fVulkan14, maintenance6);
1793 } else {
1794 chain(newChainEnd, pNext);
1795 }
1796 break;
1797 }
1798 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_PROTECTED_ACCESS_FEATURES: {
1799 if (hasVulkan14Features) {
1800 auto* features =
1801 reinterpret_cast<VkPhysicalDevicePipelineProtectedAccessFeatures*>(
1802 pNext);
1803 DUP_INTO(fVulkan14, pipelineProtectedAccess);
1804 } else {
1805 chain(newChainEnd, pNext);
1806 }
1807 break;
1808 }
1809 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_ROBUSTNESS_FEATURES: {
1810 if (hasVulkan14Features) {
1811 auto* features =
1812 reinterpret_cast<VkPhysicalDevicePipelineRobustnessFeatures*>(pNext);
1813 DUP_INTO(fVulkan14, pipelineRobustness);
1814 } else {
1815 chain(newChainEnd, pNext);
1816 }
1817 break;
1818 }
1819 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAME_BOUNDARY_FEATURES_EXT: {
1820 chain(newChainEnd, pNext);
1821 if (exts.fFrameBoundaryEXT) {
1822 auto* features =
1823 reinterpret_cast<VkPhysicalDeviceFrameBoundaryFeaturesEXT*>(
1824 pNext);
1825 features->frameBoundary = VK_TRUE;
1826 }
1827 toAdd.fFrameBoundary = false;
1828 break;
1829 }
1830
1831 default:
1832 // Retain everything else that's chained.
1833 chain(newChainEnd, pNext);
1834 break;
1835 }
1836
1837 pNext = pNext->pNext;
1838 }
1839 #undef DUP_INTO
1840
1841 // Chain any struct that was not found in appFeatures.
1842 if (hasVulkan11Features) {
1843 chain(newChainEnd, &fVulkan11);
1844 }
1845 if (hasVulkan12Features) {
1846 chain(newChainEnd, &fVulkan12);
1847 }
1848 if (hasVulkan13Features) {
1849 chain(newChainEnd, &fVulkan13);
1850 }
1851 if (hasVulkan14Features) {
1852 chain(newChainEnd, &fVulkan14);
1853 }
1854 if (toAdd.fRasterizationOrderAttachmentAccess) {
1855 chain(newChainEnd, &fRasterizationOrderAttachmentAccess);
1856 }
1857 if (toAdd.fBlendOperationAdvanced) {
1858 chain(newChainEnd, &fBlendOperationAdvanced);
1859 }
1860 if (toAdd.fExtendedDynamicState) {
1861 chain(newChainEnd, &fExtendedDynamicState);
1862 }
1863 if (toAdd.fExtendedDynamicState2) {
1864 chain(newChainEnd, &fExtendedDynamicState2);
1865 }
1866 if (toAdd.fVertexInputDynamicState) {
1867 chain(newChainEnd, &fVertexInputDynamicState);
1868 }
1869 if (toAdd.fGraphicsPipelineLibrary) {
1870 chain(newChainEnd, &fGraphicsPipelineLibrary);
1871 }
1872 if (toAdd.fSamplerYcbcrConversion) {
1873 chain(newChainEnd, &fSamplerYcbcrConversion);
1874 }
1875 if (toAdd.fRGBA10x6Formats) {
1876 chain(newChainEnd, &fRGBA10x6Formats);
1877 }
1878 if (toAdd.fSynchronization2) {
1879 chain(newChainEnd, &fSynchronization2);
1880 }
1881 if (toAdd.fDynamicRendering) {
1882 chain(newChainEnd, &fDynamicRendering);
1883 }
1884 if (toAdd.fDynamicRenderingLocalRead) {
1885 chain(newChainEnd, &fDynamicRenderingLocalRead);
1886 }
1887 if (toAdd.fMultisampledRenderToSingleSampled) {
1888 chain(newChainEnd, &fMultisampledRenderToSingleSampled);
1889 }
1890 if (toAdd.fHostImageCopy) {
1891 chain(newChainEnd, &fHostImageCopy);
1892 }
1893 if (toAdd.fPipelineCreationCacheControl) {
1894 chain(newChainEnd, &fPipelineCreationCacheControl);
1895 }
1896 if (toAdd.fFrameBoundary) {
1897 chain(newChainEnd, &fFrameBoundary);
1898 }
1899
1900 // Replace appFeatures' pNext with the new chain.
1901 *newChainEnd = nullptr;
1902 appFeatures.pNext = newChainStart;
1903
1904 fHasAddedFeaturesToEnable = true;
1905 }
1906
1907 } // namespace skgpu