1 // Copyright 2018 The SwiftShader Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "VkPhysicalDevice.hpp"
16
17 #include "VkConfig.hpp"
18 #include "VkStringify.hpp"
19 #include "Pipeline/SpirvShader.hpp" // sw::SIMD::Width
20 #include "Reactor/Reactor.hpp"
21
22 #include <cstring>
23 #include <limits>
24
25 #ifdef __ANDROID__
26 # include <android/hardware_buffer.h>
27 #endif
28
29 namespace vk {
30
PhysicalDevice(const void *,void * mem)31 PhysicalDevice::PhysicalDevice(const void *, void *mem)
32 {
33 }
34
getFeatures() const35 const VkPhysicalDeviceFeatures &PhysicalDevice::getFeatures() const
36 {
37 static const VkPhysicalDeviceFeatures features{
38 VK_TRUE, // robustBufferAccess
39 VK_TRUE, // fullDrawIndexUint32
40 VK_TRUE, // imageCubeArray
41 VK_TRUE, // independentBlend
42 VK_FALSE, // geometryShader
43 VK_FALSE, // tessellationShader
44 VK_TRUE, // sampleRateShading
45 VK_FALSE, // dualSrcBlend
46 VK_FALSE, // logicOp
47 VK_TRUE, // multiDrawIndirect
48 VK_TRUE, // drawIndirectFirstInstance
49 VK_TRUE, // depthClamp
50 VK_TRUE, // depthBiasClamp
51 VK_TRUE, // fillModeNonSolid
52 VK_TRUE, // depthBounds
53 VK_FALSE, // wideLines
54 VK_TRUE, // largePoints
55 VK_FALSE, // alphaToOne
56 VK_FALSE, // multiViewport
57 VK_TRUE, // samplerAnisotropy
58 VK_TRUE, // textureCompressionETC2
59 #ifdef SWIFTSHADER_ENABLE_ASTC
60 VK_TRUE, // textureCompressionASTC_LDR
61 #else
62 VK_FALSE, // textureCompressionASTC_LDR
63 #endif
64 VK_TRUE, // textureCompressionBC
65 VK_TRUE, // occlusionQueryPrecise
66 VK_FALSE, // pipelineStatisticsQuery
67 VK_TRUE, // vertexPipelineStoresAndAtomics
68 VK_TRUE, // fragmentStoresAndAtomics
69 VK_FALSE, // shaderTessellationAndGeometryPointSize
70 VK_FALSE, // shaderImageGatherExtended
71 VK_TRUE, // shaderStorageImageExtendedFormats
72 VK_TRUE, // shaderStorageImageMultisample
73 VK_FALSE, // shaderStorageImageReadWithoutFormat
74 VK_TRUE, // shaderStorageImageWriteWithoutFormat
75 VK_TRUE, // shaderUniformBufferArrayDynamicIndexing
76 VK_TRUE, // shaderSampledImageArrayDynamicIndexing
77 VK_TRUE, // shaderStorageBufferArrayDynamicIndexing
78 VK_TRUE, // shaderStorageImageArrayDynamicIndexing
79 VK_TRUE, // shaderClipDistance
80 VK_TRUE, // shaderCullDistance
81 VK_FALSE, // shaderFloat64
82 VK_FALSE, // shaderInt64
83 VK_FALSE, // shaderInt16
84 VK_FALSE, // shaderResourceResidency
85 VK_FALSE, // shaderResourceMinLod
86 VK_FALSE, // sparseBinding
87 VK_FALSE, // sparseResidencyBuffer
88 VK_FALSE, // sparseResidencyImage2D
89 VK_FALSE, // sparseResidencyImage3D
90 VK_FALSE, // sparseResidency2Samples
91 VK_FALSE, // sparseResidency4Samples
92 VK_FALSE, // sparseResidency8Samples
93 VK_FALSE, // sparseResidency16Samples
94 VK_FALSE, // sparseResidencyAliased
95 VK_TRUE, // variableMultisampleRate
96 VK_FALSE, // inheritedQueries
97 };
98
99 return features;
100 }
101
102 template<typename T>
getPhysicalDeviceSamplerYcbcrConversionFeatures(T * features)103 static void getPhysicalDeviceSamplerYcbcrConversionFeatures(T *features)
104 {
105 features->samplerYcbcrConversion = VK_TRUE;
106 }
107
108 template<typename T>
getPhysicalDevice16BitStorageFeatures(T * features)109 static void getPhysicalDevice16BitStorageFeatures(T *features)
110 {
111 features->storageBuffer16BitAccess = VK_FALSE;
112 features->storageInputOutput16 = VK_FALSE;
113 features->storagePushConstant16 = VK_FALSE;
114 features->uniformAndStorageBuffer16BitAccess = VK_FALSE;
115 }
116
117 template<typename T>
getPhysicalDeviceVariablePointersFeatures(T * features)118 static void getPhysicalDeviceVariablePointersFeatures(T *features)
119 {
120 features->variablePointersStorageBuffer = VK_FALSE;
121 features->variablePointers = VK_FALSE;
122 }
123
124 template<typename T>
getPhysicalDevice8BitStorageFeaturesKHR(T * features)125 static void getPhysicalDevice8BitStorageFeaturesKHR(T *features)
126 {
127 features->storageBuffer8BitAccess = VK_FALSE;
128 features->uniformAndStorageBuffer8BitAccess = VK_FALSE;
129 features->storagePushConstant8 = VK_FALSE;
130 }
131
132 template<typename T>
getPhysicalDeviceMultiviewFeatures(T * features)133 static void getPhysicalDeviceMultiviewFeatures(T *features)
134 {
135 features->multiview = VK_TRUE;
136 features->multiviewGeometryShader = VK_FALSE;
137 features->multiviewTessellationShader = VK_FALSE;
138 }
139
140 template<typename T>
getPhysicalDeviceProtectedMemoryFeatures(T * features)141 static void getPhysicalDeviceProtectedMemoryFeatures(T *features)
142 {
143 features->protectedMemory = VK_FALSE;
144 }
145
146 template<typename T>
getPhysicalDeviceShaderDrawParameterFeatures(T * features)147 static void getPhysicalDeviceShaderDrawParameterFeatures(T *features)
148 {
149 features->shaderDrawParameters = VK_FALSE;
150 }
151
152 template<typename T>
getPhysicalDeviceSeparateDepthStencilLayoutsFeaturesKHR(T * features)153 static void getPhysicalDeviceSeparateDepthStencilLayoutsFeaturesKHR(T *features)
154 {
155 features->separateDepthStencilLayouts = VK_TRUE;
156 }
157
158 template<typename T>
getPhysicalDeviceLineRasterizationFeaturesEXT(T * features)159 static void getPhysicalDeviceLineRasterizationFeaturesEXT(T *features)
160 {
161 features->rectangularLines = VK_TRUE;
162 features->bresenhamLines = VK_TRUE;
163 features->smoothLines = VK_FALSE;
164 features->stippledRectangularLines = VK_FALSE;
165 features->stippledBresenhamLines = VK_FALSE;
166 features->stippledSmoothLines = VK_FALSE;
167 }
168
169 template<typename T>
getPhysicalDeviceProvokingVertexFeaturesEXT(T * features)170 static void getPhysicalDeviceProvokingVertexFeaturesEXT(T *features)
171 {
172 features->provokingVertexLast = VK_TRUE;
173 features->transformFeedbackPreservesProvokingVertex = VK_FALSE;
174 }
175
176 template<typename T>
getPhysicalDeviceHostQueryResetFeatures(T * features)177 static void getPhysicalDeviceHostQueryResetFeatures(T *features)
178 {
179 features->hostQueryReset = VK_TRUE;
180 }
181
182 template<typename T>
getPhysicalDevicePipelineCreationCacheControlFeatures(T * features)183 static void getPhysicalDevicePipelineCreationCacheControlFeatures(T *features)
184 {
185 features->pipelineCreationCacheControl = VK_TRUE;
186 }
187
188 template<typename T>
getPhysicalDeviceImageRobustnessFeatures(T * features)189 static void getPhysicalDeviceImageRobustnessFeatures(T *features)
190 {
191 features->robustImageAccess = VK_TRUE;
192 }
193
194 template<typename T>
getPhysicalDeviceShaderDrawParametersFeatures(T * features)195 static void getPhysicalDeviceShaderDrawParametersFeatures(T *features)
196 {
197 features->shaderDrawParameters = VK_FALSE;
198 }
199
200 template<typename T>
getPhysicalDeviceVulkan11Features(T * features)201 static void getPhysicalDeviceVulkan11Features(T *features)
202 {
203 getPhysicalDevice16BitStorageFeatures(features);
204 getPhysicalDeviceMultiviewFeatures(features);
205 getPhysicalDeviceVariablePointersFeatures(features);
206 getPhysicalDeviceProtectedMemoryFeatures(features);
207 getPhysicalDeviceSamplerYcbcrConversionFeatures(features);
208 getPhysicalDeviceShaderDrawParametersFeatures(features);
209 }
210
211 template<typename T>
getPhysicalDeviceImagelessFramebufferFeatures(T * features)212 static void getPhysicalDeviceImagelessFramebufferFeatures(T *features)
213 {
214 features->imagelessFramebuffer = VK_TRUE;
215 }
216
217 template<typename T>
getPhysicalDeviceShaderSubgroupExtendedTypesFeatures(T * features)218 static void getPhysicalDeviceShaderSubgroupExtendedTypesFeatures(T *features)
219 {
220 features->shaderSubgroupExtendedTypes = VK_TRUE;
221 }
222
223 template<typename T>
getPhysicalDeviceScalarBlockLayoutFeatures(T * features)224 static void getPhysicalDeviceScalarBlockLayoutFeatures(T *features)
225 {
226 features->scalarBlockLayout = VK_TRUE;
227 }
228
229 #ifdef SWIFTSHADER_DEVICE_MEMORY_REPORT
230 template<typename T>
getPhysicalDeviceDeviceMemoryReportFeaturesEXT(T * features)231 static void getPhysicalDeviceDeviceMemoryReportFeaturesEXT(T *features)
232 {
233 features->deviceMemoryReport = VK_TRUE;
234 }
235 #endif // SWIFTSHADER_DEVICE_MEMORY_REPORT
236
237 template<typename T>
getPhysicalDeviceUniformBufferStandardLayoutFeatures(T * features)238 static void getPhysicalDeviceUniformBufferStandardLayoutFeatures(T *features)
239 {
240 features->uniformBufferStandardLayout = VK_TRUE;
241 }
242
243 template<typename T>
getPhysicalDeviceDescriptorIndexingFeatures(T * features)244 static void getPhysicalDeviceDescriptorIndexingFeatures(T *features)
245 {
246 features->shaderInputAttachmentArrayDynamicIndexing = VK_FALSE;
247 features->shaderUniformTexelBufferArrayDynamicIndexing = VK_FALSE;
248 features->shaderStorageTexelBufferArrayDynamicIndexing = VK_FALSE;
249 features->shaderUniformBufferArrayNonUniformIndexing = VK_FALSE;
250 features->shaderSampledImageArrayNonUniformIndexing = VK_FALSE;
251 features->shaderStorageBufferArrayNonUniformIndexing = VK_FALSE;
252 features->shaderStorageImageArrayNonUniformIndexing = VK_FALSE;
253 features->shaderInputAttachmentArrayNonUniformIndexing = VK_FALSE;
254 features->shaderUniformTexelBufferArrayNonUniformIndexing = VK_FALSE;
255 features->shaderStorageTexelBufferArrayNonUniformIndexing = VK_FALSE;
256 features->descriptorBindingUniformBufferUpdateAfterBind = VK_FALSE;
257 features->descriptorBindingSampledImageUpdateAfterBind = VK_FALSE;
258 features->descriptorBindingStorageImageUpdateAfterBind = VK_FALSE;
259 features->descriptorBindingStorageBufferUpdateAfterBind = VK_FALSE;
260 features->descriptorBindingUniformTexelBufferUpdateAfterBind = VK_FALSE;
261 features->descriptorBindingStorageTexelBufferUpdateAfterBind = VK_FALSE;
262 features->descriptorBindingUpdateUnusedWhilePending = VK_FALSE;
263 features->descriptorBindingPartiallyBound = VK_FALSE;
264 features->descriptorBindingVariableDescriptorCount = VK_FALSE;
265 features->runtimeDescriptorArray = VK_FALSE;
266 }
267
268 template<typename T>
getPhysicalDeviceVulkanMemoryModelFeatures(T * features)269 static void getPhysicalDeviceVulkanMemoryModelFeatures(T *features)
270 {
271 features->vulkanMemoryModel = VK_TRUE;
272 features->vulkanMemoryModelDeviceScope = VK_TRUE;
273 features->vulkanMemoryModelAvailabilityVisibilityChains = VK_TRUE;
274 }
275
276 template<typename T>
getPhysicalDeviceTimelineSemaphoreFeatures(T * features)277 static void getPhysicalDeviceTimelineSemaphoreFeatures(T *features)
278 {
279 features->timelineSemaphore = VK_TRUE;
280 }
281
282 template<typename T>
getPhysicalDeviceShaderAtomicInt64Features(T * features)283 static void getPhysicalDeviceShaderAtomicInt64Features(T *features)
284 {
285 features->shaderBufferInt64Atomics = VK_FALSE;
286 features->shaderSharedInt64Atomics = VK_FALSE;
287 }
288
289 template<typename T>
getPhysicalDeviceShaderFloat16Int8Features(T * features)290 static void getPhysicalDeviceShaderFloat16Int8Features(T *features)
291 {
292 features->shaderFloat16 = VK_FALSE;
293 features->shaderInt8 = VK_FALSE;
294 }
295
296 template<typename T>
getPhysicalDeviceBufferDeviceAddressFeatures(T * features)297 static void getPhysicalDeviceBufferDeviceAddressFeatures(T *features)
298 {
299 features->bufferDeviceAddress = VK_FALSE;
300 features->bufferDeviceAddressCaptureReplay = VK_FALSE;
301 features->bufferDeviceAddressMultiDevice = VK_FALSE;
302 }
303
304 template<typename T>
getPhysicalDeviceDynamicRenderingFeatures(T * features)305 static void getPhysicalDeviceDynamicRenderingFeatures(T *features)
306 {
307 features->dynamicRendering = VK_TRUE;
308 }
309
310 template<typename T>
getPhysicalDeviceInlineUniformBlockFeatures(T * features)311 static void getPhysicalDeviceInlineUniformBlockFeatures(T *features)
312 {
313 features->inlineUniformBlock = VK_TRUE;
314 features->descriptorBindingInlineUniformBlockUpdateAfterBind = VK_TRUE;
315 }
316
317 template<typename T>
getPhysicalDevicePrivateDataFeatures(T * features)318 static void getPhysicalDevicePrivateDataFeatures(T *features)
319 {
320 features->privateData = VK_TRUE;
321 }
322
323 template<typename T>
getPhysicalDeviceTextureCompressionASTCHDRFeatures(T * features)324 static void getPhysicalDeviceTextureCompressionASTCHDRFeatures(T *features)
325 {
326 features->textureCompressionASTC_HDR = VK_FALSE;
327 }
328
329 template<typename T>
getPhysicalDeviceShaderDemoteToHelperInvocationFeatures(T * features)330 static void getPhysicalDeviceShaderDemoteToHelperInvocationFeatures(T *features)
331 {
332 features->shaderDemoteToHelperInvocation = VK_TRUE;
333 }
334
335 template<typename T>
getPhysicalDeviceShaderTerminateInvocationFeatures(T * features)336 static void getPhysicalDeviceShaderTerminateInvocationFeatures(T *features)
337 {
338 features->shaderTerminateInvocation = VK_TRUE;
339 }
340
341 template<typename T>
getPhysicalDeviceSubgroupSizeControlFeatures(T * features)342 static void getPhysicalDeviceSubgroupSizeControlFeatures(T *features)
343 {
344 features->subgroupSizeControl = VK_TRUE;
345 features->computeFullSubgroups = VK_TRUE;
346 }
347
348 template<typename T>
getPhysicalDeviceSynchronization2Features(T * features)349 static void getPhysicalDeviceSynchronization2Features(T *features)
350 {
351 features->synchronization2 = VK_TRUE;
352 }
353
354 template<typename T>
getPhysicalDeviceShaderIntegerDotProductFeatures(T * features)355 static void getPhysicalDeviceShaderIntegerDotProductFeatures(T *features)
356 {
357 features->shaderIntegerDotProduct = VK_TRUE;
358 }
359
360 template<typename T>
getPhysicalDeviceZeroInitializeWorkgroupMemoryFeatures(T * features)361 static void getPhysicalDeviceZeroInitializeWorkgroupMemoryFeatures(T *features)
362 {
363 features->shaderZeroInitializeWorkgroupMemory = VK_TRUE;
364 }
365
366 template<typename T>
getPhysicalDeviceMaintenance4Features(T * features)367 static void getPhysicalDeviceMaintenance4Features(T *features)
368 {
369 features->maintenance4 = VK_TRUE;
370 }
371
372 template<typename T>
getPhysicalDeviceVulkan12Features(T * features)373 static void getPhysicalDeviceVulkan12Features(T *features)
374 {
375 features->samplerMirrorClampToEdge = VK_TRUE;
376 features->drawIndirectCount = VK_FALSE;
377 getPhysicalDevice8BitStorageFeaturesKHR(features);
378 getPhysicalDeviceShaderAtomicInt64Features(features);
379 getPhysicalDeviceShaderFloat16Int8Features(features);
380 features->descriptorIndexing = VK_FALSE;
381 getPhysicalDeviceDescriptorIndexingFeatures(features);
382 features->samplerFilterMinmax = VK_FALSE;
383 getPhysicalDeviceScalarBlockLayoutFeatures(features);
384 getPhysicalDeviceImagelessFramebufferFeatures(features);
385 getPhysicalDeviceUniformBufferStandardLayoutFeatures(features);
386 getPhysicalDeviceShaderSubgroupExtendedTypesFeatures(features);
387 getPhysicalDeviceSeparateDepthStencilLayoutsFeaturesKHR(features);
388 getPhysicalDeviceHostQueryResetFeatures(features);
389 getPhysicalDeviceTimelineSemaphoreFeatures(features);
390 getPhysicalDeviceBufferDeviceAddressFeatures(features);
391 getPhysicalDeviceVulkanMemoryModelFeatures(features);
392 features->shaderOutputViewportIndex = VK_FALSE;
393 features->shaderOutputLayer = VK_FALSE;
394 features->subgroupBroadcastDynamicId = VK_TRUE;
395 }
396
397 template<typename T>
getPhysicalDeviceDepthClipEnableFeaturesExt(T * features)398 static void getPhysicalDeviceDepthClipEnableFeaturesExt(T *features)
399 {
400 features->depthClipEnable = VK_TRUE;
401 }
402
403 template<typename T>
getPhysicalDeviceVulkan13Features(T * features)404 static void getPhysicalDeviceVulkan13Features(T *features)
405 {
406 getPhysicalDeviceImageRobustnessFeatures(features);
407 getPhysicalDeviceInlineUniformBlockFeatures(features);
408 getPhysicalDevicePipelineCreationCacheControlFeatures(features);
409 getPhysicalDevicePrivateDataFeatures(features);
410 getPhysicalDeviceShaderDemoteToHelperInvocationFeatures(features);
411 getPhysicalDeviceShaderTerminateInvocationFeatures(features);
412 getPhysicalDeviceSubgroupSizeControlFeatures(features);
413 getPhysicalDeviceSynchronization2Features(features);
414 getPhysicalDeviceTextureCompressionASTCHDRFeatures(features);
415 getPhysicalDeviceZeroInitializeWorkgroupMemoryFeatures(features);
416 getPhysicalDeviceDynamicRenderingFeatures(features);
417 getPhysicalDeviceShaderIntegerDotProductFeatures(features);
418 getPhysicalDeviceMaintenance4Features(features);
419 }
420
getPhysicalDeviceCustomBorderColorFeaturesExt(VkPhysicalDeviceCustomBorderColorFeaturesEXT * features)421 static void getPhysicalDeviceCustomBorderColorFeaturesExt(VkPhysicalDeviceCustomBorderColorFeaturesEXT *features)
422 {
423 features->customBorderColors = VK_TRUE;
424 features->customBorderColorWithoutFormat = VK_TRUE;
425 }
426
getPhysicalDeviceBlendOperationAdvancedFeaturesExt(VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT * features)427 static void getPhysicalDeviceBlendOperationAdvancedFeaturesExt(VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT *features)
428 {
429 features->advancedBlendCoherentOperations = VK_FALSE;
430 }
431
getPhysicalDeviceExtendedDynamicStateFeaturesExt(VkPhysicalDeviceExtendedDynamicStateFeaturesEXT * features)432 static void getPhysicalDeviceExtendedDynamicStateFeaturesExt(VkPhysicalDeviceExtendedDynamicStateFeaturesEXT *features)
433 {
434 features->extendedDynamicState = VK_TRUE;
435 }
436
getPhysicalDevice4444FormatsFeaturesExt(VkPhysicalDevice4444FormatsFeaturesEXT * features)437 static void getPhysicalDevice4444FormatsFeaturesExt(VkPhysicalDevice4444FormatsFeaturesEXT *features)
438 {
439 features->formatA4R4G4B4 = VK_TRUE;
440 features->formatA4B4G4R4 = VK_TRUE;
441 }
442
getFeatures2(VkPhysicalDeviceFeatures2 * features) const443 void PhysicalDevice::getFeatures2(VkPhysicalDeviceFeatures2 *features) const
444 {
445 features->features = getFeatures();
446 VkBaseOutStructure *curExtension = reinterpret_cast<VkBaseOutStructure *>(features->pNext);
447 while(curExtension != nullptr)
448 {
449 switch(curExtension->sType)
450 {
451 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES:
452 getPhysicalDeviceVulkan11Features(reinterpret_cast<VkPhysicalDeviceVulkan11Features *>(curExtension));
453 break;
454 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES:
455 getPhysicalDeviceVulkan12Features(reinterpret_cast<VkPhysicalDeviceVulkan12Features *>(curExtension));
456 break;
457 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES:
458 getPhysicalDeviceVulkan13Features(reinterpret_cast<VkPhysicalDeviceVulkan13Features *>(curExtension));
459 break;
460 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES:
461 getPhysicalDeviceMultiviewFeatures(reinterpret_cast<VkPhysicalDeviceMultiviewFeatures *>(curExtension));
462 break;
463 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES:
464 getPhysicalDeviceVariablePointersFeatures(reinterpret_cast<VkPhysicalDeviceVariablePointersFeatures *>(curExtension));
465 break;
466 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES:
467 getPhysicalDevice16BitStorageFeatures(reinterpret_cast<VkPhysicalDevice16BitStorageFeatures *>(curExtension));
468 break;
469 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES:
470 getPhysicalDeviceSamplerYcbcrConversionFeatures(reinterpret_cast<VkPhysicalDeviceSamplerYcbcrConversionFeatures *>(curExtension));
471 break;
472 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES:
473 getPhysicalDeviceProtectedMemoryFeatures(reinterpret_cast<VkPhysicalDeviceProtectedMemoryFeatures *>(curExtension));
474 break;
475 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETERS_FEATURES:
476 getPhysicalDeviceShaderDrawParameterFeatures(reinterpret_cast<VkPhysicalDeviceShaderDrawParameterFeatures *>(curExtension));
477 break;
478 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES:
479 getPhysicalDeviceHostQueryResetFeatures(reinterpret_cast<VkPhysicalDeviceHostQueryResetFeatures *>(curExtension));
480 break;
481 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_CREATION_CACHE_CONTROL_FEATURES:
482 getPhysicalDevicePipelineCreationCacheControlFeatures(reinterpret_cast<VkPhysicalDevicePipelineCreationCacheControlFeatures *>(curExtension));
483 break;
484 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_ROBUSTNESS_FEATURES:
485 getPhysicalDeviceImageRobustnessFeatures(reinterpret_cast<VkPhysicalDeviceImageRobustnessFeatures *>(curExtension));
486 break;
487 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_FEATURES_EXT:
488 getPhysicalDeviceLineRasterizationFeaturesEXT(reinterpret_cast<VkPhysicalDeviceLineRasterizationFeaturesEXT *>(curExtension));
489 break;
490 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SEPARATE_DEPTH_STENCIL_LAYOUTS_FEATURES:
491 getPhysicalDeviceSeparateDepthStencilLayoutsFeaturesKHR(reinterpret_cast<VkPhysicalDeviceSeparateDepthStencilLayoutsFeatures *>(curExtension));
492 break;
493 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES_KHR:
494 getPhysicalDevice8BitStorageFeaturesKHR(reinterpret_cast<VkPhysicalDevice8BitStorageFeaturesKHR *>(curExtension));
495 break;
496 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROVOKING_VERTEX_FEATURES_EXT:
497 getPhysicalDeviceProvokingVertexFeaturesEXT(reinterpret_cast<VkPhysicalDeviceProvokingVertexFeaturesEXT *>(curExtension));
498 break;
499 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES:
500 getPhysicalDeviceImagelessFramebufferFeatures(reinterpret_cast<VkPhysicalDeviceImagelessFramebufferFeatures *>(curExtension));
501 break;
502 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_SUBGROUP_EXTENDED_TYPES_FEATURES_KHR:
503 getPhysicalDeviceShaderSubgroupExtendedTypesFeatures(reinterpret_cast<VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures *>(curExtension));
504 break;
505 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES:
506 getPhysicalDeviceScalarBlockLayoutFeatures(reinterpret_cast<VkPhysicalDeviceScalarBlockLayoutFeatures *>(curExtension));
507 break;
508 #ifdef SWIFTSHADER_DEVICE_MEMORY_REPORT
509 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEVICE_MEMORY_REPORT_FEATURES_EXT:
510 getPhysicalDeviceDeviceMemoryReportFeaturesEXT(reinterpret_cast<VkPhysicalDeviceDeviceMemoryReportFeaturesEXT *>(curExtension));
511 break;
512 #endif // SWIFTSHADER_DEVICE_MEMORY_REPORT
513 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_UNIFORM_BUFFER_STANDARD_LAYOUT_FEATURES:
514 getPhysicalDeviceUniformBufferStandardLayoutFeatures(reinterpret_cast<VkPhysicalDeviceUniformBufferStandardLayoutFeatures *>(curExtension));
515 break;
516 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_MEMORY_MODEL_FEATURES:
517 getPhysicalDeviceVulkanMemoryModelFeatures(reinterpret_cast<VkPhysicalDeviceVulkanMemoryModelFeatures *>(curExtension));
518 break;
519 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TIMELINE_SEMAPHORE_FEATURES:
520 getPhysicalDeviceTimelineSemaphoreFeatures(reinterpret_cast<VkPhysicalDeviceTimelineSemaphoreFeatures *>(curExtension));
521 break;
522 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_INT64_FEATURES:
523 getPhysicalDeviceShaderAtomicInt64Features(reinterpret_cast<VkPhysicalDeviceShaderAtomicInt64Features *>(curExtension));
524 break;
525 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_FLOAT16_INT8_FEATURES:
526 getPhysicalDeviceShaderFloat16Int8Features(reinterpret_cast<VkPhysicalDeviceShaderFloat16Int8Features *>(curExtension));
527 break;
528 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES:
529 getPhysicalDeviceBufferDeviceAddressFeatures(reinterpret_cast<VkPhysicalDeviceBufferDeviceAddressFeatures *>(curExtension));
530 break;
531 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DYNAMIC_RENDERING_FEATURES:
532 getPhysicalDeviceDynamicRenderingFeatures(reinterpret_cast<VkPhysicalDeviceDynamicRenderingFeatures *>(curExtension));
533 break;
534 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES:
535 getPhysicalDeviceDescriptorIndexingFeatures(reinterpret_cast<VkPhysicalDeviceDescriptorIndexingFeatures *>(curExtension));
536 break;
537 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_ENABLE_FEATURES_EXT:
538 getPhysicalDeviceDepthClipEnableFeaturesExt(reinterpret_cast<VkPhysicalDeviceDepthClipEnableFeaturesEXT *>(curExtension));
539 break;
540 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ZERO_INITIALIZE_WORKGROUP_MEMORY_FEATURES:
541 getPhysicalDeviceZeroInitializeWorkgroupMemoryFeatures(reinterpret_cast<VkPhysicalDeviceZeroInitializeWorkgroupMemoryFeatures *>(curExtension));
542 break;
543 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_FEATURES_EXT:
544 getPhysicalDeviceCustomBorderColorFeaturesExt(reinterpret_cast<VkPhysicalDeviceCustomBorderColorFeaturesEXT *>(curExtension));
545 break;
546 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_FEATURES_EXT:
547 getPhysicalDeviceBlendOperationAdvancedFeaturesExt(reinterpret_cast<VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT *>(curExtension));
548 break;
549 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_FEATURES_EXT:
550 getPhysicalDeviceExtendedDynamicStateFeaturesExt(reinterpret_cast<VkPhysicalDeviceExtendedDynamicStateFeaturesEXT *>(curExtension));
551 break;
552 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRIVATE_DATA_FEATURES:
553 getPhysicalDevicePrivateDataFeatures(reinterpret_cast<VkPhysicalDevicePrivateDataFeatures *>(curExtension));
554 break;
555 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TEXTURE_COMPRESSION_ASTC_HDR_FEATURES:
556 getPhysicalDeviceTextureCompressionASTCHDRFeatures(reinterpret_cast<VkPhysicalDeviceTextureCompressionASTCHDRFeatures *>(curExtension));
557 break;
558 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DEMOTE_TO_HELPER_INVOCATION_FEATURES:
559 getPhysicalDeviceShaderDemoteToHelperInvocationFeatures(reinterpret_cast<VkPhysicalDeviceShaderDemoteToHelperInvocationFeatures *>(curExtension));
560 break;
561 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_TERMINATE_INVOCATION_FEATURES:
562 getPhysicalDeviceShaderTerminateInvocationFeatures(reinterpret_cast<VkPhysicalDeviceShaderTerminateInvocationFeatures *>(curExtension));
563 break;
564 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_FEATURES:
565 getPhysicalDeviceSubgroupSizeControlFeatures(reinterpret_cast<VkPhysicalDeviceSubgroupSizeControlFeatures *>(curExtension));
566 break;
567 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_FEATURES:
568 getPhysicalDeviceInlineUniformBlockFeatures(reinterpret_cast<VkPhysicalDeviceInlineUniformBlockFeatures *>(curExtension));
569 break;
570 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_4444_FORMATS_FEATURES_EXT:
571 getPhysicalDevice4444FormatsFeaturesExt(reinterpret_cast<struct VkPhysicalDevice4444FormatsFeaturesEXT *>(curExtension));
572 break;
573 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SYNCHRONIZATION_2_FEATURES:
574 getPhysicalDeviceSynchronization2Features(reinterpret_cast<struct VkPhysicalDeviceSynchronization2Features *>(curExtension));
575 break;
576 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_INTEGER_DOT_PRODUCT_FEATURES:
577 getPhysicalDeviceShaderIntegerDotProductFeatures(reinterpret_cast<struct VkPhysicalDeviceShaderIntegerDotProductFeatures *>(curExtension));
578 break;
579 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_4_FEATURES:
580 getPhysicalDeviceMaintenance4Features(reinterpret_cast<struct VkPhysicalDeviceMaintenance4Features *>(curExtension));
581 break;
582 case VK_STRUCTURE_TYPE_MAX_ENUM: // TODO(b/176893525): This may not be legal. dEQP tests that this value is ignored.
583 break;
584 // FIXME(b/228307968): VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RASTERIZATION_ORDER_ATTACHMENT_ACCESS_FEATURES_ARM
585 // is used by dEQP without checking if VK_ARM_rasterization_order_attachment_access is present
586 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RASTERIZATION_ORDER_ATTACHMENT_ACCESS_FEATURES_ARM:
587 break;
588 default:
589 UNSUPPORTED("curExtension->sType: %s", vk::Stringify(curExtension->sType).c_str());
590 break;
591 }
592 curExtension = reinterpret_cast<VkBaseOutStructure *>(curExtension->pNext);
593 }
594 }
595
getSampleCounts()596 VkSampleCountFlags PhysicalDevice::getSampleCounts()
597 {
598 return VK_SAMPLE_COUNT_1_BIT | VK_SAMPLE_COUNT_4_BIT;
599 }
600
getLimits()601 const VkPhysicalDeviceLimits &PhysicalDevice::getLimits()
602 {
603 VkSampleCountFlags sampleCounts = getSampleCounts();
604
605 static const VkPhysicalDeviceLimits limits = {
606 1 << (vk::MAX_IMAGE_LEVELS_1D - 1), // maxImageDimension1D
607 1 << (vk::MAX_IMAGE_LEVELS_2D - 1), // maxImageDimension2D
608 1 << (vk::MAX_IMAGE_LEVELS_3D - 1), // maxImageDimension3D
609 1 << (vk::MAX_IMAGE_LEVELS_CUBE - 1), // maxImageDimensionCube
610 vk::MAX_IMAGE_ARRAY_LAYERS, // maxImageArrayLayers
611 65536, // maxTexelBufferElements
612 65536, // maxUniformBufferRange
613 vk::MAX_MEMORY_ALLOCATION_SIZE, // maxStorageBufferRange
614 vk::MAX_PUSH_CONSTANT_SIZE, // maxPushConstantsSize
615 4096, // maxMemoryAllocationCount
616 vk::MAX_SAMPLER_ALLOCATION_COUNT, // maxSamplerAllocationCount
617 4096, // bufferImageGranularity
618 0, // sparseAddressSpaceSize (unsupported)
619 MAX_BOUND_DESCRIPTOR_SETS, // maxBoundDescriptorSets
620 64, // maxPerStageDescriptorSamplers
621 15, // maxPerStageDescriptorUniformBuffers
622 30, // maxPerStageDescriptorStorageBuffers
623 200, // maxPerStageDescriptorSampledImages
624 16, // maxPerStageDescriptorStorageImages
625 sw::MAX_COLOR_BUFFERS, // maxPerStageDescriptorInputAttachments
626 200, // maxPerStageResources
627 576, // maxDescriptorSetSamplers
628 90, // maxDescriptorSetUniformBuffers
629 MAX_DESCRIPTOR_SET_UNIFORM_BUFFERS_DYNAMIC, // maxDescriptorSetUniformBuffersDynamic
630 96, // maxDescriptorSetStorageBuffers
631 MAX_DESCRIPTOR_SET_STORAGE_BUFFERS_DYNAMIC, // maxDescriptorSetStorageBuffersDynamic
632 1800, // maxDescriptorSetSampledImages
633 144, // maxDescriptorSetStorageImages
634 sw::MAX_COLOR_BUFFERS, // maxDescriptorSetInputAttachments
635 16, // maxVertexInputAttributes
636 vk::MAX_VERTEX_INPUT_BINDINGS, // maxVertexInputBindings
637 2047, // maxVertexInputAttributeOffset
638 2048, // maxVertexInputBindingStride
639 sw::MAX_INTERFACE_COMPONENTS, // maxVertexOutputComponents
640 0, // maxTessellationGenerationLevel (unsupported)
641 0, // maxTessellationPatchSize (unsupported)
642 0, // maxTessellationControlPerVertexInputComponents (unsupported)
643 0, // maxTessellationControlPerVertexOutputComponents (unsupported)
644 0, // maxTessellationControlPerPatchOutputComponents (unsupported)
645 0, // maxTessellationControlTotalOutputComponents (unsupported)
646 0, // maxTessellationEvaluationInputComponents (unsupported)
647 0, // maxTessellationEvaluationOutputComponents (unsupported)
648 0, // maxGeometryShaderInvocations (unsupported)
649 0, // maxGeometryInputComponents (unsupported)
650 0, // maxGeometryOutputComponents (unsupported)
651 0, // maxGeometryOutputVertices (unsupported)
652 0, // maxGeometryTotalOutputComponents (unsupported)
653 sw::MAX_INTERFACE_COMPONENTS, // maxFragmentInputComponents
654 sw::MAX_COLOR_BUFFERS, // maxFragmentOutputAttachments
655 1, // maxFragmentDualSrcAttachments
656 28, // maxFragmentCombinedOutputResources
657 32768, // maxComputeSharedMemorySize
658 { 65535, 65535, 65535 }, // maxComputeWorkGroupCount[3]
659 vk::MAX_COMPUTE_WORKGROUP_INVOCATIONS, // maxComputeWorkGroupInvocations
660 { 256, 256, 64 }, // maxComputeWorkGroupSize[3]
661 vk::SUBPIXEL_PRECISION_BITS, // subPixelPrecisionBits
662 4, // subTexelPrecisionBits
663 4, // mipmapPrecisionBits
664 UINT32_MAX, // maxDrawIndexedIndexValue
665 UINT32_MAX, // maxDrawIndirectCount
666 vk::MAX_SAMPLER_LOD_BIAS, // maxSamplerLodBias
667 16, // maxSamplerAnisotropy
668 MAX_VIEWPORTS, // maxViewports
669 { sw::MAX_VIEWPORT_DIM,
670 sw::MAX_VIEWPORT_DIM }, // maxViewportDimensions[2]
671 { -2 * sw::MAX_VIEWPORT_DIM,
672 2 * sw::MAX_VIEWPORT_DIM - 1 }, // viewportBoundsRange[2]
673 0, // viewportSubPixelBits
674 64, // minMemoryMapAlignment
675 vk::MIN_TEXEL_BUFFER_OFFSET_ALIGNMENT, // minTexelBufferOffsetAlignment
676 vk::MIN_UNIFORM_BUFFER_OFFSET_ALIGNMENT, // minUniformBufferOffsetAlignment
677 vk::MIN_STORAGE_BUFFER_OFFSET_ALIGNMENT, // minStorageBufferOffsetAlignment
678 sw::MIN_TEXEL_OFFSET, // minTexelOffset
679 sw::MAX_TEXEL_OFFSET, // maxTexelOffset
680 sw::MIN_TEXEL_OFFSET, // minTexelGatherOffset
681 sw::MAX_TEXEL_OFFSET, // maxTexelGatherOffset
682 -0.5, // minInterpolationOffset
683 0.5, // maxInterpolationOffset
684 4, // subPixelInterpolationOffsetBits
685 sw::MAX_FRAMEBUFFER_DIM, // maxFramebufferWidth
686 sw::MAX_FRAMEBUFFER_DIM, // maxFramebufferHeight
687 256, // maxFramebufferLayers
688 sampleCounts, // framebufferColorSampleCounts
689 sampleCounts, // framebufferDepthSampleCounts
690 sampleCounts, // framebufferStencilSampleCounts
691 sampleCounts, // framebufferNoAttachmentsSampleCounts
692 sw::MAX_COLOR_BUFFERS, // maxColorAttachments
693 sampleCounts, // sampledImageColorSampleCounts
694 sampleCounts, // sampledImageIntegerSampleCounts
695 sampleCounts, // sampledImageDepthSampleCounts
696 sampleCounts, // sampledImageStencilSampleCounts
697 sampleCounts, // storageImageSampleCounts
698 1, // maxSampleMaskWords
699 VK_TRUE, // timestampComputeAndGraphics
700 1, // timestampPeriod
701 sw::MAX_CLIP_DISTANCES, // maxClipDistances
702 sw::MAX_CULL_DISTANCES, // maxCullDistances
703 sw::MAX_CLIP_DISTANCES + sw::MAX_CULL_DISTANCES, // maxCombinedClipAndCullDistances
704 2, // discreteQueuePriorities
705 { 1.0, vk::MAX_POINT_SIZE }, // pointSizeRange[2]
706 { 1.0, 1.0 }, // lineWidthRange[2] (unsupported)
707 0.0, // pointSizeGranularity (unsupported)
708 0.0, // lineWidthGranularity (unsupported)
709 VK_TRUE, // strictLines
710 VK_TRUE, // standardSampleLocations
711 64, // optimalBufferCopyOffsetAlignment
712 64, // optimalBufferCopyRowPitchAlignment
713 256, // nonCoherentAtomSize
714 };
715
716 return limits;
717 }
718
getProperties() const719 const VkPhysicalDeviceProperties &PhysicalDevice::getProperties() const
720 {
721 auto getProperties = [&]() -> VkPhysicalDeviceProperties {
722 VkPhysicalDeviceProperties properties = {
723 API_VERSION,
724 DRIVER_VERSION,
725 VENDOR_ID,
726 DEVICE_ID,
727 VK_PHYSICAL_DEVICE_TYPE_CPU, // deviceType
728 "", // deviceName
729 SWIFTSHADER_UUID, // pipelineCacheUUID
730 getLimits(), // limits
731 {} // sparseProperties
732 };
733
734 // Append Reactor JIT backend name and version
735 snprintf(properties.deviceName, VK_MAX_PHYSICAL_DEVICE_NAME_SIZE,
736 "%s (%s)", SWIFTSHADER_DEVICE_NAME, rr::Caps::backendName().c_str());
737
738 return properties;
739 };
740
741 static const VkPhysicalDeviceProperties properties = getProperties();
742 return properties;
743 }
744
745 template<typename T>
getIdProperties(T * properties)746 static void getIdProperties(T *properties)
747 {
748 memset(properties->deviceUUID, 0, VK_UUID_SIZE);
749 memset(properties->driverUUID, 0, VK_UUID_SIZE);
750 memset(properties->deviceLUID, 0, VK_LUID_SIZE);
751
752 memcpy(properties->deviceUUID, SWIFTSHADER_UUID, VK_UUID_SIZE);
753 *((uint64_t *)properties->driverUUID) = DRIVER_VERSION;
754
755 properties->deviceNodeMask = 0;
756 properties->deviceLUIDValid = VK_FALSE;
757 }
758
getProperties(VkPhysicalDeviceIDProperties * properties) const759 void PhysicalDevice::getProperties(VkPhysicalDeviceIDProperties *properties) const
760 {
761 getIdProperties(properties);
762 }
763
764 template<typename T>
getMaintenance3Properties(T * properties)765 static void getMaintenance3Properties(T *properties)
766 {
767 properties->maxMemoryAllocationSize = MAX_MEMORY_ALLOCATION_SIZE;
768 properties->maxPerSetDescriptors = 1024;
769 }
770
771 template<typename T>
getMaintenance4Properties(T * properties)772 static void getMaintenance4Properties(T *properties)
773 {
774 properties->maxBufferSize = MAX_MEMORY_ALLOCATION_SIZE;
775 }
776
getProperties(VkPhysicalDeviceMaintenance3Properties * properties) const777 void PhysicalDevice::getProperties(VkPhysicalDeviceMaintenance3Properties *properties) const
778 {
779 getMaintenance3Properties(properties);
780 }
781
getProperties(VkPhysicalDeviceMaintenance4Properties * properties) const782 void PhysicalDevice::getProperties(VkPhysicalDeviceMaintenance4Properties *properties) const
783 {
784 getMaintenance4Properties(properties);
785 }
786
787 template<typename T>
getMultiviewProperties(T * properties)788 static void getMultiviewProperties(T *properties)
789 {
790 properties->maxMultiviewViewCount = 6;
791 properties->maxMultiviewInstanceIndex = 1u << 27;
792 }
793
getProperties(VkPhysicalDeviceMultiviewProperties * properties) const794 void PhysicalDevice::getProperties(VkPhysicalDeviceMultiviewProperties *properties) const
795 {
796 getMultiviewProperties(properties);
797 }
798
799 template<typename T>
getPointClippingProperties(T * properties)800 static void getPointClippingProperties(T *properties)
801 {
802 properties->pointClippingBehavior = VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES;
803 }
804
getProperties(VkPhysicalDevicePointClippingProperties * properties) const805 void PhysicalDevice::getProperties(VkPhysicalDevicePointClippingProperties *properties) const
806 {
807 getPointClippingProperties(properties);
808 }
809
810 template<typename T>
getProtectedMemoryProperties(T * properties)811 static void getProtectedMemoryProperties(T *properties)
812 {
813 properties->protectedNoFault = VK_FALSE;
814 }
815
getProperties(VkPhysicalDeviceProtectedMemoryProperties * properties) const816 void PhysicalDevice::getProperties(VkPhysicalDeviceProtectedMemoryProperties *properties) const
817 {
818 getProtectedMemoryProperties(properties);
819 }
820
821 template<typename T>
getSubgroupProperties(T * properties)822 static void getSubgroupProperties(T *properties)
823 {
824 properties->subgroupSize = sw::SIMD::Width;
825 properties->supportedStages = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT | VK_SHADER_STAGE_COMPUTE_BIT;
826 properties->supportedOperations =
827 VK_SUBGROUP_FEATURE_BASIC_BIT |
828 VK_SUBGROUP_FEATURE_VOTE_BIT |
829 VK_SUBGROUP_FEATURE_ARITHMETIC_BIT |
830 VK_SUBGROUP_FEATURE_BALLOT_BIT |
831 VK_SUBGROUP_FEATURE_SHUFFLE_BIT |
832 VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT;
833 properties->quadOperationsInAllStages = VK_FALSE;
834 }
835
getProperties(VkPhysicalDeviceSubgroupProperties * properties) const836 void PhysicalDevice::getProperties(VkPhysicalDeviceSubgroupProperties *properties) const
837 {
838 getSubgroupProperties(properties);
839 }
840
getProperties(VkPhysicalDeviceVulkan11Properties * properties) const841 void PhysicalDevice::getProperties(VkPhysicalDeviceVulkan11Properties *properties) const
842 {
843 getIdProperties(properties);
844
845 // We can't use templated functions for Vulkan11 & subgroup properties. The names of the
846 // variables in VkPhysicalDeviceSubgroupProperties differ from the names in the Vulkan11
847 // struct.
848 VkPhysicalDeviceSubgroupProperties subgroupProperties = {};
849 getProperties(&subgroupProperties);
850 properties->subgroupSize = subgroupProperties.subgroupSize;
851 properties->subgroupSupportedStages = subgroupProperties.supportedStages;
852 properties->subgroupSupportedOperations = subgroupProperties.supportedOperations;
853 properties->subgroupQuadOperationsInAllStages = subgroupProperties.quadOperationsInAllStages;
854
855 getPointClippingProperties(properties);
856 getMultiviewProperties(properties);
857 getProtectedMemoryProperties(properties);
858 getMaintenance3Properties(properties);
859 }
860
getProperties(const VkExternalMemoryHandleTypeFlagBits * handleType,VkExternalImageFormatProperties * properties) const861 void PhysicalDevice::getProperties(const VkExternalMemoryHandleTypeFlagBits *handleType, VkExternalImageFormatProperties *properties) const
862 {
863 VkExternalMemoryProperties *extMemProperties = &properties->externalMemoryProperties;
864 #if SWIFTSHADER_EXTERNAL_MEMORY_OPAQUE_FD
865 if(*handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT)
866 {
867 extMemProperties->compatibleHandleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT;
868 extMemProperties->exportFromImportedHandleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT;
869 extMemProperties->externalMemoryFeatures = VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT | VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT;
870 return;
871 }
872 #endif
873 #if SWIFTSHADER_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER
874 if(*handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID)
875 {
876 extMemProperties->compatibleHandleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID;
877 extMemProperties->exportFromImportedHandleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID;
878 extMemProperties->externalMemoryFeatures = VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT | VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT | VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT;
879 return;
880 }
881 #endif
882 #if VK_USE_PLATFORM_FUCHSIA
883 if(*handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_ZIRCON_VMO_BIT_FUCHSIA)
884 {
885 extMemProperties->compatibleHandleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ZIRCON_VMO_BIT_FUCHSIA;
886 extMemProperties->exportFromImportedHandleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ZIRCON_VMO_BIT_FUCHSIA;
887 extMemProperties->externalMemoryFeatures = VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT | VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT;
888 return;
889 }
890 #endif
891 extMemProperties->compatibleHandleTypes = 0;
892 extMemProperties->exportFromImportedHandleTypes = 0;
893 extMemProperties->externalMemoryFeatures = 0;
894 }
895
getProperties(const VkExternalMemoryHandleTypeFlagBits * handleType,VkExternalBufferProperties * properties) const896 void PhysicalDevice::getProperties(const VkExternalMemoryHandleTypeFlagBits *handleType, VkExternalBufferProperties *properties) const
897 {
898 VkExternalMemoryProperties *extMemProperties = &properties->externalMemoryProperties;
899 #if SWIFTSHADER_EXTERNAL_MEMORY_OPAQUE_FD
900 if(*handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT)
901 {
902 extMemProperties->compatibleHandleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT;
903 extMemProperties->exportFromImportedHandleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT;
904 extMemProperties->externalMemoryFeatures = VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT | VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT;
905 return;
906 }
907 #endif
908 #if SWIFTSHADER_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER
909 if(*handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID)
910 {
911 extMemProperties->compatibleHandleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID;
912 extMemProperties->exportFromImportedHandleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID;
913 extMemProperties->externalMemoryFeatures = VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT | VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT;
914 return;
915 }
916 #endif
917 #if VK_USE_PLATFORM_FUCHSIA
918 if(*handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_ZIRCON_VMO_BIT_FUCHSIA)
919 {
920 extMemProperties->compatibleHandleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ZIRCON_VMO_BIT_FUCHSIA;
921 extMemProperties->exportFromImportedHandleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ZIRCON_VMO_BIT_FUCHSIA;
922 extMemProperties->externalMemoryFeatures = VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT | VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT;
923 return;
924 }
925 #endif
926 extMemProperties->compatibleHandleTypes = 0;
927 extMemProperties->exportFromImportedHandleTypes = 0;
928 extMemProperties->externalMemoryFeatures = 0;
929 }
930
getProperties(VkSamplerYcbcrConversionImageFormatProperties * properties) const931 void PhysicalDevice::getProperties(VkSamplerYcbcrConversionImageFormatProperties *properties) const
932 {
933 properties->combinedImageSamplerDescriptorCount = 1; // Need only one descriptor for YCbCr sampling.
934 }
935
936 #ifdef __ANDROID__
getProperties(VkPhysicalDevicePresentationPropertiesANDROID * properties) const937 void PhysicalDevice::getProperties(VkPhysicalDevicePresentationPropertiesANDROID *properties) const
938 {
939 properties->sharedImage = VK_FALSE;
940 }
941
getProperties(const VkPhysicalDeviceImageFormatInfo2 * pImageFormatInfo,VkAndroidHardwareBufferUsageANDROID * ahbProperties) const942 void PhysicalDevice::getProperties(const VkPhysicalDeviceImageFormatInfo2 *pImageFormatInfo, VkAndroidHardwareBufferUsageANDROID *ahbProperties) const
943 {
944 // Maps VkImageUsageFlags to AHB usage flags using this table from the Vulkan spec
945 // https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#memory-external-android-hardware-buffer-usage
946
947 // VK_IMAGE_CREATE_PROTECTED_BIT not currently supported.
948 ASSERT((pImageFormatInfo->flags & VK_IMAGE_CREATE_PROTECTED_BIT) == 0);
949
950 // "It must include at least one GPU usage flag (AHARDWAREBUFFER_USAGE_GPU_*), even if none of the corresponding Vulkan usages or flags are requested."
951 uint64_t ahbUsage = AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE;
952
953 // Already covered by the default GPU usage flag above.
954 //
955 // if ((vkUsageFlags & VK_IMAGE_USAGE_SAMPLED_BIT) || (vkUsageFlags & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT))
956 // {
957 // ahbUsage |= AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE;
958 // }
959
960 if((pImageFormatInfo->usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) || (pImageFormatInfo->usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT))
961 {
962 ahbUsage |= AHARDWAREBUFFER_USAGE_GPU_FRAMEBUFFER;
963 }
964
965 if(pImageFormatInfo->flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT)
966 {
967 ahbUsage |= AHARDWAREBUFFER_USAGE_GPU_CUBE_MAP;
968 }
969
970 if(pImageFormatInfo->flags & VK_IMAGE_CREATE_PROTECTED_BIT)
971 {
972 ahbUsage |= AHARDWAREBUFFER_USAGE_PROTECTED_CONTENT;
973 }
974
975 ahbProperties->androidHardwareBufferUsage = ahbUsage;
976 }
977 #endif
978
getProperties(const VkPhysicalDeviceExternalBufferInfo * pExternalBufferInfo,VkExternalBufferProperties * pExternalBufferProperties) const979 void PhysicalDevice::getProperties(const VkPhysicalDeviceExternalBufferInfo *pExternalBufferInfo, VkExternalBufferProperties *pExternalBufferProperties) const
980 {
981 VkExternalMemoryProperties *properties = &pExternalBufferProperties->externalMemoryProperties;
982
983 #if SWIFTSHADER_EXTERNAL_MEMORY_OPAQUE_FD || SWIFTSHADER_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER
984 const VkExternalMemoryHandleTypeFlagBits *handleType = &pExternalBufferInfo->handleType;
985 #endif
986
987 #if SWIFTSHADER_EXTERNAL_MEMORY_OPAQUE_FD
988 if(*handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT)
989 {
990 properties->compatibleHandleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT;
991 properties->exportFromImportedHandleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT;
992 properties->externalMemoryFeatures = VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT | VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT;
993 return;
994 }
995 #endif
996 #if SWIFTSHADER_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER
997 if(*handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID)
998 {
999 properties->compatibleHandleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID;
1000 properties->exportFromImportedHandleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID;
1001 properties->externalMemoryFeatures = VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT | VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT;
1002 return;
1003 }
1004 #endif
1005 properties->compatibleHandleTypes = 0;
1006 properties->exportFromImportedHandleTypes = 0;
1007 properties->externalMemoryFeatures = 0;
1008 }
1009
getProperties(const VkPhysicalDeviceExternalFenceInfo * pExternalFenceInfo,VkExternalFenceProperties * pExternalFenceProperties) const1010 void PhysicalDevice::getProperties(const VkPhysicalDeviceExternalFenceInfo *pExternalFenceInfo, VkExternalFenceProperties *pExternalFenceProperties) const
1011 {
1012 pExternalFenceProperties->compatibleHandleTypes = 0;
1013 pExternalFenceProperties->exportFromImportedHandleTypes = 0;
1014 pExternalFenceProperties->externalFenceFeatures = 0;
1015 }
1016
getProperties(const VkPhysicalDeviceExternalSemaphoreInfo * pExternalSemaphoreInfo,VkExternalSemaphoreProperties * pExternalSemaphoreProperties) const1017 void PhysicalDevice::getProperties(const VkPhysicalDeviceExternalSemaphoreInfo *pExternalSemaphoreInfo, VkExternalSemaphoreProperties *pExternalSemaphoreProperties) const
1018 {
1019 for(const auto *nextInfo = reinterpret_cast<const VkBaseInStructure *>(pExternalSemaphoreInfo->pNext);
1020 nextInfo != nullptr; nextInfo = nextInfo->pNext)
1021 {
1022 switch(nextInfo->sType)
1023 {
1024 case VK_STRUCTURE_TYPE_SEMAPHORE_TYPE_CREATE_INFO:
1025 {
1026 const auto *tlsInfo = reinterpret_cast<const VkSemaphoreTypeCreateInfo *>(nextInfo);
1027 // Timeline Semaphore does not support external semaphore
1028 if(tlsInfo->semaphoreType == VK_SEMAPHORE_TYPE_TIMELINE)
1029 {
1030 pExternalSemaphoreProperties->compatibleHandleTypes = 0;
1031 pExternalSemaphoreProperties->exportFromImportedHandleTypes = 0;
1032 pExternalSemaphoreProperties->externalSemaphoreFeatures = 0;
1033 return;
1034 }
1035 }
1036 break;
1037 default:
1038 WARN("nextInfo->sType = %s", vk::Stringify(nextInfo->sType).c_str());
1039 break;
1040 }
1041 }
1042
1043 #if SWIFTSHADER_EXTERNAL_SEMAPHORE_OPAQUE_FD
1044 if(pExternalSemaphoreInfo->handleType == VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT)
1045 {
1046 pExternalSemaphoreProperties->compatibleHandleTypes = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT;
1047 pExternalSemaphoreProperties->exportFromImportedHandleTypes = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT;
1048 pExternalSemaphoreProperties->externalSemaphoreFeatures = VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT | VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT;
1049 return;
1050 }
1051 #endif
1052 #if VK_USE_PLATFORM_FUCHSIA
1053 if(pExternalSemaphoreInfo->handleType == VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_ZIRCON_EVENT_BIT_FUCHSIA)
1054 {
1055 pExternalSemaphoreProperties->compatibleHandleTypes = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_ZIRCON_EVENT_BIT_FUCHSIA;
1056 pExternalSemaphoreProperties->exportFromImportedHandleTypes = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_ZIRCON_EVENT_BIT_FUCHSIA;
1057 pExternalSemaphoreProperties->externalSemaphoreFeatures = VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT | VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT;
1058 return;
1059 }
1060 #endif
1061 pExternalSemaphoreProperties->compatibleHandleTypes = 0;
1062 pExternalSemaphoreProperties->exportFromImportedHandleTypes = 0;
1063 pExternalSemaphoreProperties->externalSemaphoreFeatures = 0;
1064 }
1065
getProperties(VkPhysicalDeviceExternalMemoryHostPropertiesEXT * properties) const1066 void PhysicalDevice::getProperties(VkPhysicalDeviceExternalMemoryHostPropertiesEXT *properties) const
1067 {
1068 properties->minImportedHostPointerAlignment = REQUIRED_MEMORY_ALIGNMENT;
1069 }
1070
1071 template<typename T>
getDriverProperties(T * properties)1072 static void getDriverProperties(T *properties)
1073 {
1074 properties->driverID = VK_DRIVER_ID_GOOGLE_SWIFTSHADER_KHR;
1075 strcpy(properties->driverName, "SwiftShader driver");
1076 strcpy(properties->driverInfo, "");
1077 properties->conformanceVersion = { 1, 1, 3, 3 };
1078 }
1079
getProperties(VkPhysicalDeviceDriverProperties * properties) const1080 void PhysicalDevice::getProperties(VkPhysicalDeviceDriverProperties *properties) const
1081 {
1082 getDriverProperties(properties);
1083 }
1084
getProperties(VkPhysicalDeviceLineRasterizationPropertiesEXT * properties) const1085 void PhysicalDevice::getProperties(VkPhysicalDeviceLineRasterizationPropertiesEXT *properties) const
1086 {
1087 properties->lineSubPixelPrecisionBits = vk::SUBPIXEL_PRECISION_BITS;
1088 }
1089
getProperties(VkPhysicalDeviceProvokingVertexPropertiesEXT * properties) const1090 void PhysicalDevice::getProperties(VkPhysicalDeviceProvokingVertexPropertiesEXT *properties) const
1091 {
1092 properties->provokingVertexModePerPipeline = VK_TRUE;
1093 }
1094
1095 template<typename T>
getFloatControlsProperties(T * properties)1096 static void getFloatControlsProperties(T *properties)
1097 {
1098 // The spec states:
1099 // shaderSignedZeroInfNanPreserveFloat32 is a boolean value indicating whether
1100 // sign of a zero, Nans and +/-infinity can be preserved in 32-bit floating-point
1101 // computations. It also indicates whether the SignedZeroInfNanPreserve execution
1102 // mode can be used for 32-bit floating-point types.
1103 //
1104 // There are similar clauses for all the shader* bools present here.
1105 //
1106 // It does not state that an implementation must report its default behavior using
1107 // these variables. At this time SwiftShader does not expose any preserve, denormal,
1108 // or rounding controls.
1109 properties->denormBehaviorIndependence = VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_NONE;
1110 properties->roundingModeIndependence = VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_NONE;
1111 properties->shaderSignedZeroInfNanPreserveFloat16 = VK_FALSE;
1112 properties->shaderSignedZeroInfNanPreserveFloat32 = VK_FALSE;
1113 properties->shaderSignedZeroInfNanPreserveFloat64 = VK_FALSE;
1114 properties->shaderDenormPreserveFloat16 = VK_FALSE;
1115 properties->shaderDenormPreserveFloat32 = VK_FALSE;
1116 properties->shaderDenormPreserveFloat64 = VK_FALSE;
1117 properties->shaderDenormFlushToZeroFloat16 = VK_FALSE;
1118 properties->shaderDenormFlushToZeroFloat32 = VK_FALSE;
1119 properties->shaderDenormFlushToZeroFloat64 = VK_FALSE;
1120 properties->shaderRoundingModeRTZFloat16 = VK_FALSE;
1121 properties->shaderRoundingModeRTZFloat32 = VK_FALSE;
1122 properties->shaderRoundingModeRTZFloat64 = VK_FALSE;
1123 properties->shaderRoundingModeRTEFloat16 = VK_FALSE;
1124 properties->shaderRoundingModeRTEFloat32 = VK_FALSE;
1125 properties->shaderRoundingModeRTEFloat64 = VK_FALSE;
1126 }
1127
getProperties(VkPhysicalDeviceFloatControlsProperties * properties) const1128 void PhysicalDevice::getProperties(VkPhysicalDeviceFloatControlsProperties *properties) const
1129 {
1130 getFloatControlsProperties(properties);
1131 }
1132
1133 template<typename T>
getDescriptorIndexingProperties(T * properties)1134 static void getDescriptorIndexingProperties(T *properties)
1135 {
1136 // "The UpdateAfterBind descriptor limits must each be greater than or equal to
1137 // the corresponding non-UpdateAfterBind limit."
1138 const VkPhysicalDeviceLimits &limits = PhysicalDevice::getLimits();
1139
1140 properties->maxUpdateAfterBindDescriptorsInAllPools = 0;
1141 properties->shaderUniformBufferArrayNonUniformIndexingNative = VK_FALSE;
1142 properties->shaderSampledImageArrayNonUniformIndexingNative = VK_FALSE;
1143 properties->shaderStorageBufferArrayNonUniformIndexingNative = VK_FALSE;
1144 properties->shaderStorageImageArrayNonUniformIndexingNative = VK_FALSE;
1145 properties->shaderInputAttachmentArrayNonUniformIndexingNative = VK_FALSE;
1146 properties->robustBufferAccessUpdateAfterBind = VK_FALSE;
1147 properties->quadDivergentImplicitLod = VK_FALSE;
1148 properties->maxPerStageDescriptorUpdateAfterBindSamplers = limits.maxPerStageDescriptorSamplers;
1149 properties->maxPerStageDescriptorUpdateAfterBindUniformBuffers = limits.maxPerStageDescriptorUniformBuffers;
1150 properties->maxPerStageDescriptorUpdateAfterBindStorageBuffers = limits.maxPerStageDescriptorStorageBuffers;
1151 properties->maxPerStageDescriptorUpdateAfterBindSampledImages = limits.maxPerStageDescriptorSampledImages;
1152 properties->maxPerStageDescriptorUpdateAfterBindStorageImages = limits.maxPerStageDescriptorStorageImages;
1153 properties->maxPerStageDescriptorUpdateAfterBindInputAttachments = limits.maxPerStageDescriptorInputAttachments;
1154 properties->maxPerStageUpdateAfterBindResources = limits.maxPerStageResources;
1155 properties->maxDescriptorSetUpdateAfterBindSamplers = limits.maxDescriptorSetSamplers;
1156 properties->maxDescriptorSetUpdateAfterBindUniformBuffers = limits.maxDescriptorSetUniformBuffers;
1157 properties->maxDescriptorSetUpdateAfterBindUniformBuffersDynamic = limits.maxDescriptorSetUniformBuffersDynamic;
1158 properties->maxDescriptorSetUpdateAfterBindStorageBuffers = limits.maxDescriptorSetStorageBuffers;
1159 properties->maxDescriptorSetUpdateAfterBindStorageBuffersDynamic = limits.maxDescriptorSetStorageBuffersDynamic;
1160 properties->maxDescriptorSetUpdateAfterBindSampledImages = limits.maxDescriptorSetSampledImages;
1161 properties->maxDescriptorSetUpdateAfterBindStorageImages = limits.maxDescriptorSetStorageImages;
1162 properties->maxDescriptorSetUpdateAfterBindInputAttachments = limits.maxDescriptorSetInputAttachments;
1163 }
1164
getProperties(VkPhysicalDeviceDescriptorIndexingProperties * properties) const1165 void PhysicalDevice::getProperties(VkPhysicalDeviceDescriptorIndexingProperties *properties) const
1166 {
1167 getDescriptorIndexingProperties(properties);
1168 }
1169
1170 template<typename T>
getDepthStencilResolveProperties(T * properties)1171 static void getDepthStencilResolveProperties(T *properties)
1172 {
1173 properties->supportedDepthResolveModes = VK_RESOLVE_MODE_SAMPLE_ZERO_BIT | VK_RESOLVE_MODE_NONE;
1174 properties->supportedStencilResolveModes = VK_RESOLVE_MODE_SAMPLE_ZERO_BIT | VK_RESOLVE_MODE_NONE;
1175 properties->independentResolveNone = VK_TRUE;
1176 properties->independentResolve = VK_TRUE;
1177 }
1178
getProperties(VkPhysicalDeviceDepthStencilResolveProperties * properties) const1179 void PhysicalDevice::getProperties(VkPhysicalDeviceDepthStencilResolveProperties *properties) const
1180 {
1181 getDepthStencilResolveProperties(properties);
1182 }
1183
getProperties(VkPhysicalDeviceCustomBorderColorPropertiesEXT * properties) const1184 void PhysicalDevice::getProperties(VkPhysicalDeviceCustomBorderColorPropertiesEXT *properties) const
1185 {
1186 properties->maxCustomBorderColorSamplers = MAX_SAMPLER_ALLOCATION_COUNT;
1187 }
1188
getProperties(VkPhysicalDeviceBlendOperationAdvancedPropertiesEXT * properties) const1189 void PhysicalDevice::getProperties(VkPhysicalDeviceBlendOperationAdvancedPropertiesEXT *properties) const
1190 {
1191 properties->advancedBlendMaxColorAttachments = sw::MAX_COLOR_BUFFERS;
1192 properties->advancedBlendIndependentBlend = VK_FALSE;
1193 properties->advancedBlendNonPremultipliedSrcColor = VK_FALSE;
1194 properties->advancedBlendNonPremultipliedDstColor = VK_FALSE;
1195 properties->advancedBlendCorrelatedOverlap = VK_FALSE;
1196 properties->advancedBlendAllOperations = VK_FALSE;
1197 }
1198
1199 template<typename T>
getSubgroupSizeControlProperties(T * properties)1200 static void getSubgroupSizeControlProperties(T *properties)
1201 {
1202 VkPhysicalDeviceSubgroupProperties subgroupProperties = {};
1203 getSubgroupProperties(&subgroupProperties);
1204 properties->minSubgroupSize = subgroupProperties.subgroupSize;
1205 properties->maxSubgroupSize = subgroupProperties.subgroupSize;
1206 properties->maxComputeWorkgroupSubgroups = vk::MAX_COMPUTE_WORKGROUP_INVOCATIONS /
1207 properties->minSubgroupSize;
1208 properties->requiredSubgroupSizeStages = subgroupProperties.supportedStages;
1209 }
1210
getProperties(VkPhysicalDeviceSubgroupSizeControlProperties * properties) const1211 void PhysicalDevice::getProperties(VkPhysicalDeviceSubgroupSizeControlProperties *properties) const
1212 {
1213 getSubgroupSizeControlProperties(properties);
1214 }
1215
1216 template<typename T>
getInlineUniformBlockProperties(T * properties)1217 static void getInlineUniformBlockProperties(T *properties)
1218 {
1219 properties->maxInlineUniformBlockSize = MAX_INLINE_UNIFORM_BLOCK_SIZE;
1220 properties->maxPerStageDescriptorInlineUniformBlocks = 4;
1221 properties->maxPerStageDescriptorUpdateAfterBindInlineUniformBlocks = 4;
1222 properties->maxDescriptorSetInlineUniformBlocks = 4;
1223 properties->maxDescriptorSetUpdateAfterBindInlineUniformBlocks = 4;
1224 }
1225
getProperties(VkPhysicalDeviceInlineUniformBlockProperties * properties) const1226 void PhysicalDevice::getProperties(VkPhysicalDeviceInlineUniformBlockProperties *properties) const
1227 {
1228 getInlineUniformBlockProperties(properties);
1229 }
1230
1231 template<typename T>
getTexelBufferAlignmentProperties(T * properties)1232 static void getTexelBufferAlignmentProperties(T *properties)
1233 {
1234 properties->storageTexelBufferOffsetAlignmentBytes = vk::MIN_TEXEL_BUFFER_OFFSET_ALIGNMENT;
1235 properties->storageTexelBufferOffsetSingleTexelAlignment = VK_FALSE;
1236 properties->uniformTexelBufferOffsetAlignmentBytes = vk::MIN_TEXEL_BUFFER_OFFSET_ALIGNMENT;
1237 properties->uniformTexelBufferOffsetSingleTexelAlignment = VK_FALSE;
1238 }
1239
getProperties(VkPhysicalDeviceTexelBufferAlignmentProperties * properties) const1240 void PhysicalDevice::getProperties(VkPhysicalDeviceTexelBufferAlignmentProperties *properties) const
1241 {
1242 getTexelBufferAlignmentProperties(properties);
1243 }
1244
1245 template<typename T>
getShaderIntegerDotProductProperties(T * properties)1246 static void getShaderIntegerDotProductProperties(T *properties)
1247 {
1248 properties->integerDotProduct8BitUnsignedAccelerated = VK_FALSE;
1249 properties->integerDotProduct8BitSignedAccelerated = VK_FALSE;
1250 properties->integerDotProduct8BitMixedSignednessAccelerated = VK_FALSE;
1251 properties->integerDotProduct4x8BitPackedUnsignedAccelerated = VK_FALSE;
1252 properties->integerDotProduct4x8BitPackedSignedAccelerated = VK_FALSE;
1253 properties->integerDotProduct4x8BitPackedMixedSignednessAccelerated = VK_FALSE;
1254 properties->integerDotProduct16BitUnsignedAccelerated = VK_FALSE;
1255 properties->integerDotProduct16BitSignedAccelerated = VK_FALSE;
1256 properties->integerDotProduct16BitMixedSignednessAccelerated = VK_FALSE;
1257 properties->integerDotProduct32BitUnsignedAccelerated = VK_FALSE;
1258 properties->integerDotProduct32BitSignedAccelerated = VK_FALSE;
1259 properties->integerDotProduct32BitMixedSignednessAccelerated = VK_FALSE;
1260 properties->integerDotProduct64BitUnsignedAccelerated = VK_FALSE;
1261 properties->integerDotProduct64BitSignedAccelerated = VK_FALSE;
1262 properties->integerDotProduct64BitMixedSignednessAccelerated = VK_FALSE;
1263 properties->integerDotProductAccumulatingSaturating8BitUnsignedAccelerated = VK_FALSE;
1264 properties->integerDotProductAccumulatingSaturating8BitSignedAccelerated = VK_FALSE;
1265 properties->integerDotProductAccumulatingSaturating8BitMixedSignednessAccelerated = VK_FALSE;
1266 properties->integerDotProductAccumulatingSaturating4x8BitPackedUnsignedAccelerated = VK_FALSE;
1267 properties->integerDotProductAccumulatingSaturating4x8BitPackedSignedAccelerated = VK_FALSE;
1268 properties->integerDotProductAccumulatingSaturating4x8BitPackedMixedSignednessAccelerated = VK_FALSE;
1269 properties->integerDotProductAccumulatingSaturating16BitUnsignedAccelerated = VK_FALSE;
1270 properties->integerDotProductAccumulatingSaturating16BitSignedAccelerated = VK_FALSE;
1271 properties->integerDotProductAccumulatingSaturating16BitMixedSignednessAccelerated = VK_FALSE;
1272 properties->integerDotProductAccumulatingSaturating32BitUnsignedAccelerated = VK_FALSE;
1273 properties->integerDotProductAccumulatingSaturating32BitSignedAccelerated = VK_FALSE;
1274 properties->integerDotProductAccumulatingSaturating32BitMixedSignednessAccelerated = VK_FALSE;
1275 properties->integerDotProductAccumulatingSaturating64BitUnsignedAccelerated = VK_FALSE;
1276 properties->integerDotProductAccumulatingSaturating64BitSignedAccelerated = VK_FALSE;
1277 properties->integerDotProductAccumulatingSaturating64BitMixedSignednessAccelerated = VK_FALSE;
1278 }
1279
getProperties(VkPhysicalDeviceShaderIntegerDotProductProperties * properties) const1280 void PhysicalDevice::getProperties(VkPhysicalDeviceShaderIntegerDotProductProperties *properties) const
1281 {
1282 getShaderIntegerDotProductProperties(properties);
1283 }
1284
1285 template<typename T>
getSamplerFilterMinmaxProperties(T * properties)1286 static void getSamplerFilterMinmaxProperties(T *properties)
1287 {
1288 properties->filterMinmaxSingleComponentFormats = VK_FALSE;
1289 properties->filterMinmaxImageComponentMapping = VK_FALSE;
1290 }
1291
getProperties(VkPhysicalDeviceSamplerFilterMinmaxProperties * properties) const1292 void PhysicalDevice::getProperties(VkPhysicalDeviceSamplerFilterMinmaxProperties *properties) const
1293 {
1294 getSamplerFilterMinmaxProperties(properties);
1295 }
1296
1297 template<typename T>
getTimelineSemaphoreProperties(T * properties)1298 static void getTimelineSemaphoreProperties(T *properties)
1299 {
1300 // Our implementation of Timeline Semaphores allows the timeline to advance to any value from any value.
1301 properties->maxTimelineSemaphoreValueDifference = (uint64_t)-1;
1302 }
1303
getProperties(VkPhysicalDeviceTimelineSemaphoreProperties * properties) const1304 void PhysicalDevice::getProperties(VkPhysicalDeviceTimelineSemaphoreProperties *properties) const
1305 {
1306 getTimelineSemaphoreProperties(properties);
1307 }
1308
getProperties(VkPhysicalDeviceVulkan12Properties * properties) const1309 void PhysicalDevice::getProperties(VkPhysicalDeviceVulkan12Properties *properties) const
1310 {
1311 getDriverProperties(properties);
1312 getFloatControlsProperties(properties);
1313 getDescriptorIndexingProperties(properties);
1314 getDepthStencilResolveProperties(properties);
1315 getSamplerFilterMinmaxProperties(properties);
1316 getTimelineSemaphoreProperties(properties);
1317 properties->framebufferIntegerColorSampleCounts = VK_SAMPLE_COUNT_1_BIT;
1318 }
1319
getProperties(VkPhysicalDeviceVulkan13Properties * properties) const1320 void PhysicalDevice::getProperties(VkPhysicalDeviceVulkan13Properties *properties) const
1321 {
1322 getSubgroupSizeControlProperties(properties);
1323 getInlineUniformBlockProperties(properties);
1324 getShaderIntegerDotProductProperties(properties);
1325 getTexelBufferAlignmentProperties(properties);
1326 getMaintenance4Properties(properties);
1327 }
1328
hasFeatures(const VkPhysicalDeviceFeatures & requestedFeatures) const1329 bool PhysicalDevice::hasFeatures(const VkPhysicalDeviceFeatures &requestedFeatures) const
1330 {
1331 const VkPhysicalDeviceFeatures &supportedFeatures = getFeatures();
1332 const VkBool32 *supportedFeature = reinterpret_cast<const VkBool32 *>(&supportedFeatures);
1333 const VkBool32 *requestedFeature = reinterpret_cast<const VkBool32 *>(&requestedFeatures);
1334 constexpr auto featureCount = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
1335
1336 for(unsigned int i = 0; i < featureCount; i++)
1337 {
1338 if((requestedFeature[i] != VK_FALSE) && (supportedFeature[i] == VK_FALSE))
1339 {
1340 return false;
1341 }
1342 }
1343
1344 return true;
1345 }
1346
1347 // CheckFeature returns false if requested is asking for a feature that is not supported
1348 #define CheckFeature(requested, supported, feature) (requested->feature == VK_FALSE || supported.feature == VK_TRUE)
1349
1350 template<typename T>
getSupportedFeatures(const T * requested) const1351 T PhysicalDevice::getSupportedFeatures(const T *requested) const
1352 {
1353 VkPhysicalDeviceFeatures2 features;
1354 features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
1355 T supported;
1356 supported.sType = requested->sType;
1357 supported.pNext = nullptr;
1358 features.pNext = &supported;
1359 getFeatures2(&features);
1360 return supported;
1361 }
1362
hasExtendedFeatures(const VkPhysicalDeviceLineRasterizationFeaturesEXT * requested) const1363 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDeviceLineRasterizationFeaturesEXT *requested) const
1364 {
1365 auto supported = getSupportedFeatures(requested);
1366
1367 return CheckFeature(requested, supported, rectangularLines) &&
1368 CheckFeature(requested, supported, bresenhamLines) &&
1369 CheckFeature(requested, supported, smoothLines) &&
1370 CheckFeature(requested, supported, stippledRectangularLines) &&
1371 CheckFeature(requested, supported, stippledBresenhamLines) &&
1372 CheckFeature(requested, supported, stippledSmoothLines);
1373 }
1374
hasExtendedFeatures(const VkPhysicalDeviceProvokingVertexFeaturesEXT * requested) const1375 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDeviceProvokingVertexFeaturesEXT *requested) const
1376 {
1377 auto supported = getSupportedFeatures(requested);
1378
1379 return CheckFeature(requested, supported, provokingVertexLast) &&
1380 CheckFeature(requested, supported, transformFeedbackPreservesProvokingVertex);
1381 }
1382
hasExtendedFeatures(const VkPhysicalDeviceVulkan11Features * requested) const1383 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDeviceVulkan11Features *requested) const
1384 {
1385 auto supported = getSupportedFeatures(requested);
1386
1387 return CheckFeature(requested, supported, storageBuffer16BitAccess) &&
1388 CheckFeature(requested, supported, uniformAndStorageBuffer16BitAccess) &&
1389 CheckFeature(requested, supported, storagePushConstant16) &&
1390 CheckFeature(requested, supported, storageInputOutput16) &&
1391 CheckFeature(requested, supported, multiview) &&
1392 CheckFeature(requested, supported, multiviewGeometryShader) &&
1393 CheckFeature(requested, supported, multiviewTessellationShader) &&
1394 CheckFeature(requested, supported, variablePointersStorageBuffer) &&
1395 CheckFeature(requested, supported, variablePointers) &&
1396 CheckFeature(requested, supported, protectedMemory) &&
1397 CheckFeature(requested, supported, samplerYcbcrConversion) &&
1398 CheckFeature(requested, supported, shaderDrawParameters);
1399 }
1400
hasExtendedFeatures(const VkPhysicalDeviceVulkan12Features * requested) const1401 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDeviceVulkan12Features *requested) const
1402 {
1403 auto supported = getSupportedFeatures(requested);
1404
1405 return CheckFeature(requested, supported, samplerMirrorClampToEdge) &&
1406 CheckFeature(requested, supported, drawIndirectCount) &&
1407 CheckFeature(requested, supported, storageBuffer8BitAccess) &&
1408 CheckFeature(requested, supported, uniformAndStorageBuffer8BitAccess) &&
1409 CheckFeature(requested, supported, storagePushConstant8) &&
1410 CheckFeature(requested, supported, shaderBufferInt64Atomics) &&
1411 CheckFeature(requested, supported, shaderSharedInt64Atomics) &&
1412 CheckFeature(requested, supported, shaderFloat16) &&
1413 CheckFeature(requested, supported, shaderInt8) &&
1414 CheckFeature(requested, supported, descriptorIndexing) &&
1415 CheckFeature(requested, supported, shaderInputAttachmentArrayDynamicIndexing) &&
1416 CheckFeature(requested, supported, shaderUniformTexelBufferArrayDynamicIndexing) &&
1417 CheckFeature(requested, supported, shaderStorageTexelBufferArrayDynamicIndexing) &&
1418 CheckFeature(requested, supported, shaderUniformBufferArrayNonUniformIndexing) &&
1419 CheckFeature(requested, supported, shaderSampledImageArrayNonUniformIndexing) &&
1420 CheckFeature(requested, supported, shaderStorageBufferArrayNonUniformIndexing) &&
1421 CheckFeature(requested, supported, shaderStorageImageArrayNonUniformIndexing) &&
1422 CheckFeature(requested, supported, shaderInputAttachmentArrayNonUniformIndexing) &&
1423 CheckFeature(requested, supported, shaderUniformTexelBufferArrayNonUniformIndexing) &&
1424 CheckFeature(requested, supported, shaderStorageTexelBufferArrayNonUniformIndexing) &&
1425 CheckFeature(requested, supported, descriptorBindingUniformBufferUpdateAfterBind) &&
1426 CheckFeature(requested, supported, descriptorBindingSampledImageUpdateAfterBind) &&
1427 CheckFeature(requested, supported, descriptorBindingStorageImageUpdateAfterBind) &&
1428 CheckFeature(requested, supported, descriptorBindingStorageBufferUpdateAfterBind) &&
1429 CheckFeature(requested, supported, descriptorBindingUniformTexelBufferUpdateAfterBind) &&
1430 CheckFeature(requested, supported, descriptorBindingStorageTexelBufferUpdateAfterBind) &&
1431 CheckFeature(requested, supported, descriptorBindingUpdateUnusedWhilePending) &&
1432 CheckFeature(requested, supported, descriptorBindingPartiallyBound) &&
1433 CheckFeature(requested, supported, descriptorBindingVariableDescriptorCount) &&
1434 CheckFeature(requested, supported, runtimeDescriptorArray) &&
1435 CheckFeature(requested, supported, samplerFilterMinmax) &&
1436 CheckFeature(requested, supported, scalarBlockLayout) &&
1437 CheckFeature(requested, supported, imagelessFramebuffer) &&
1438 CheckFeature(requested, supported, uniformBufferStandardLayout) &&
1439 CheckFeature(requested, supported, shaderSubgroupExtendedTypes) &&
1440 CheckFeature(requested, supported, separateDepthStencilLayouts) &&
1441 CheckFeature(requested, supported, hostQueryReset) &&
1442 CheckFeature(requested, supported, timelineSemaphore) &&
1443 CheckFeature(requested, supported, bufferDeviceAddress) &&
1444 CheckFeature(requested, supported, bufferDeviceAddressCaptureReplay) &&
1445 CheckFeature(requested, supported, bufferDeviceAddressMultiDevice) &&
1446 CheckFeature(requested, supported, vulkanMemoryModel) &&
1447 CheckFeature(requested, supported, vulkanMemoryModelDeviceScope) &&
1448 CheckFeature(requested, supported, vulkanMemoryModelAvailabilityVisibilityChains) &&
1449 CheckFeature(requested, supported, shaderOutputViewportIndex) &&
1450 CheckFeature(requested, supported, shaderOutputLayer) &&
1451 CheckFeature(requested, supported, subgroupBroadcastDynamicId);
1452 }
1453
hasExtendedFeatures(const VkPhysicalDeviceVulkan13Features * requested) const1454 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDeviceVulkan13Features *requested) const
1455 {
1456 auto supported = getSupportedFeatures(requested);
1457
1458 return CheckFeature(requested, supported, robustImageAccess) &&
1459 CheckFeature(requested, supported, inlineUniformBlock) &&
1460 CheckFeature(requested, supported, descriptorBindingInlineUniformBlockUpdateAfterBind) &&
1461 CheckFeature(requested, supported, pipelineCreationCacheControl) &&
1462 CheckFeature(requested, supported, privateData) &&
1463 CheckFeature(requested, supported, shaderDemoteToHelperInvocation) &&
1464 CheckFeature(requested, supported, shaderTerminateInvocation) &&
1465 CheckFeature(requested, supported, subgroupSizeControl) &&
1466 CheckFeature(requested, supported, computeFullSubgroups) &&
1467 CheckFeature(requested, supported, synchronization2) &&
1468 CheckFeature(requested, supported, textureCompressionASTC_HDR) &&
1469 CheckFeature(requested, supported, shaderZeroInitializeWorkgroupMemory) &&
1470 CheckFeature(requested, supported, dynamicRendering) &&
1471 CheckFeature(requested, supported, shaderIntegerDotProduct) &&
1472 CheckFeature(requested, supported, maintenance4);
1473 }
1474
hasExtendedFeatures(const VkPhysicalDeviceDepthClipEnableFeaturesEXT * requested) const1475 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDeviceDepthClipEnableFeaturesEXT *requested) const
1476 {
1477 auto supported = getSupportedFeatures(requested);
1478
1479 return CheckFeature(requested, supported, depthClipEnable);
1480 }
1481
hasExtendedFeatures(const VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT * requested) const1482 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT *requested) const
1483 {
1484 auto supported = getSupportedFeatures(requested);
1485
1486 return CheckFeature(requested, supported, advancedBlendCoherentOperations);
1487 }
1488
hasExtendedFeatures(const VkPhysicalDeviceInlineUniformBlockFeatures * requested) const1489 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDeviceInlineUniformBlockFeatures *requested) const
1490 {
1491 auto supported = getSupportedFeatures(requested);
1492
1493 return CheckFeature(requested, supported, inlineUniformBlock) &&
1494 CheckFeature(requested, supported, descriptorBindingInlineUniformBlockUpdateAfterBind);
1495 }
1496
hasExtendedFeatures(const VkPhysicalDeviceShaderIntegerDotProductFeatures * requested) const1497 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDeviceShaderIntegerDotProductFeatures *requested) const
1498 {
1499 auto supported = getSupportedFeatures(requested);
1500
1501 return CheckFeature(requested, supported, shaderIntegerDotProduct);
1502 }
1503
hasExtendedFeatures(const VkPhysicalDeviceExtendedDynamicStateFeaturesEXT * requested) const1504 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDeviceExtendedDynamicStateFeaturesEXT *requested) const
1505 {
1506 auto supported = getSupportedFeatures(requested);
1507
1508 return CheckFeature(requested, supported, extendedDynamicState);
1509 }
1510
hasExtendedFeatures(const VkPhysicalDevicePrivateDataFeatures * requested) const1511 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDevicePrivateDataFeatures *requested) const
1512 {
1513 auto supported = getSupportedFeatures(requested);
1514
1515 return CheckFeature(requested, supported, privateData);
1516 }
1517
hasExtendedFeatures(const VkPhysicalDeviceTextureCompressionASTCHDRFeatures * requested) const1518 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDeviceTextureCompressionASTCHDRFeatures *requested) const
1519 {
1520 auto supported = getSupportedFeatures(requested);
1521
1522 return CheckFeature(requested, supported, textureCompressionASTC_HDR);
1523 }
1524
hasExtendedFeatures(const VkPhysicalDeviceShaderDemoteToHelperInvocationFeatures * requested) const1525 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDeviceShaderDemoteToHelperInvocationFeatures *requested) const
1526 {
1527 auto supported = getSupportedFeatures(requested);
1528
1529 return CheckFeature(requested, supported, shaderDemoteToHelperInvocation);
1530 }
1531
hasExtendedFeatures(const VkPhysicalDeviceShaderTerminateInvocationFeatures * requested) const1532 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDeviceShaderTerminateInvocationFeatures *requested) const
1533 {
1534 auto supported = getSupportedFeatures(requested);
1535
1536 return CheckFeature(requested, supported, shaderTerminateInvocation);
1537 }
1538
hasExtendedFeatures(const VkPhysicalDeviceSubgroupSizeControlFeatures * requested) const1539 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDeviceSubgroupSizeControlFeatures *requested) const
1540 {
1541 auto supported = getSupportedFeatures(requested);
1542
1543 return CheckFeature(requested, supported, subgroupSizeControl) &&
1544 CheckFeature(requested, supported, computeFullSubgroups);
1545 }
1546
hasExtendedFeatures(const VkPhysicalDeviceZeroInitializeWorkgroupMemoryFeatures * requested) const1547 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDeviceZeroInitializeWorkgroupMemoryFeatures *requested) const
1548 {
1549 auto supported = getSupportedFeatures(requested);
1550
1551 return CheckFeature(requested, supported, shaderZeroInitializeWorkgroupMemory);
1552 }
1553 #undef CheckFeature
1554
GetFormatProperties(Format format,VkFormatProperties * pFormatProperties)1555 void PhysicalDevice::GetFormatProperties(Format format, VkFormatProperties *pFormatProperties)
1556 {
1557 VkFormatProperties3 formatProperties3 = {};
1558 GetFormatProperties(format, &formatProperties3);
1559
1560 // VkFormatFeatureFlags2KHR is a 64-bit extension of the 32-bit VkFormatFeatureFlags,
1561 // so when querying the legacy flags just return the lower 32-bit portion.
1562 pFormatProperties->linearTilingFeatures = static_cast<VkFormatFeatureFlags>(formatProperties3.linearTilingFeatures);
1563 pFormatProperties->optimalTilingFeatures = static_cast<VkFormatFeatureFlags>(formatProperties3.optimalTilingFeatures);
1564 pFormatProperties->bufferFeatures = static_cast<VkFormatFeatureFlags>(formatProperties3.bufferFeatures);
1565 }
1566
GetFormatProperties(Format format,VkFormatProperties3 * pFormatProperties)1567 void PhysicalDevice::GetFormatProperties(Format format, VkFormatProperties3 *pFormatProperties)
1568 {
1569 pFormatProperties->linearTilingFeatures = 0; // Unsupported format
1570 pFormatProperties->optimalTilingFeatures = 0; // Unsupported format
1571 pFormatProperties->bufferFeatures = 0; // Unsupported format
1572
1573 switch(format)
1574 {
1575 // Formats which can be sampled *and* filtered
1576 case VK_FORMAT_R4G4B4A4_UNORM_PACK16:
1577 case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
1578 case VK_FORMAT_A4R4G4B4_UNORM_PACK16:
1579 case VK_FORMAT_A4B4G4R4_UNORM_PACK16:
1580 case VK_FORMAT_R5G6B5_UNORM_PACK16:
1581 case VK_FORMAT_B5G6R5_UNORM_PACK16:
1582 case VK_FORMAT_R5G5B5A1_UNORM_PACK16:
1583 case VK_FORMAT_B5G5R5A1_UNORM_PACK16:
1584 case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
1585 case VK_FORMAT_R8_UNORM:
1586 case VK_FORMAT_R8_SRGB:
1587 case VK_FORMAT_R8_SNORM:
1588 case VK_FORMAT_R8G8_UNORM:
1589 case VK_FORMAT_R8G8_SRGB:
1590 case VK_FORMAT_R8G8_SNORM:
1591 case VK_FORMAT_R8G8B8A8_UNORM:
1592 case VK_FORMAT_R8G8B8A8_SNORM:
1593 case VK_FORMAT_R8G8B8A8_SRGB:
1594 case VK_FORMAT_B8G8R8A8_UNORM:
1595 case VK_FORMAT_B8G8R8A8_SRGB:
1596 case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
1597 case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
1598 case VK_FORMAT_A8B8G8R8_SRGB_PACK32:
1599 case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
1600 case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
1601 case VK_FORMAT_R16_UNORM:
1602 case VK_FORMAT_R16_SNORM:
1603 case VK_FORMAT_R16_SFLOAT:
1604 case VK_FORMAT_R16G16_UNORM:
1605 case VK_FORMAT_R16G16_SNORM:
1606 case VK_FORMAT_R16G16_SFLOAT:
1607 case VK_FORMAT_R16G16B16A16_UNORM:
1608 case VK_FORMAT_R16G16B16A16_SNORM:
1609 case VK_FORMAT_R16G16B16A16_SFLOAT:
1610 case VK_FORMAT_R32_SFLOAT:
1611 case VK_FORMAT_R32G32_SFLOAT:
1612 case VK_FORMAT_R32G32B32A32_SFLOAT:
1613 case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
1614 case VK_FORMAT_E5B9G9R9_UFLOAT_PACK32:
1615 case VK_FORMAT_BC1_RGB_UNORM_BLOCK:
1616 case VK_FORMAT_BC1_RGB_SRGB_BLOCK:
1617 case VK_FORMAT_BC1_RGBA_UNORM_BLOCK:
1618 case VK_FORMAT_BC1_RGBA_SRGB_BLOCK:
1619 case VK_FORMAT_BC2_UNORM_BLOCK:
1620 case VK_FORMAT_BC2_SRGB_BLOCK:
1621 case VK_FORMAT_BC3_UNORM_BLOCK:
1622 case VK_FORMAT_BC3_SRGB_BLOCK:
1623 case VK_FORMAT_BC4_UNORM_BLOCK:
1624 case VK_FORMAT_BC4_SNORM_BLOCK:
1625 case VK_FORMAT_BC5_UNORM_BLOCK:
1626 case VK_FORMAT_BC5_SNORM_BLOCK:
1627 case VK_FORMAT_BC6H_UFLOAT_BLOCK:
1628 case VK_FORMAT_BC6H_SFLOAT_BLOCK:
1629 case VK_FORMAT_BC7_UNORM_BLOCK:
1630 case VK_FORMAT_BC7_SRGB_BLOCK:
1631 case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
1632 case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:
1633 case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK:
1634 case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:
1635 case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK:
1636 case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK:
1637 case VK_FORMAT_EAC_R11_UNORM_BLOCK:
1638 case VK_FORMAT_EAC_R11_SNORM_BLOCK:
1639 case VK_FORMAT_EAC_R11G11_UNORM_BLOCK:
1640 case VK_FORMAT_EAC_R11G11_SNORM_BLOCK:
1641 #ifdef SWIFTSHADER_ENABLE_ASTC
1642 case VK_FORMAT_ASTC_4x4_UNORM_BLOCK:
1643 case VK_FORMAT_ASTC_5x4_UNORM_BLOCK:
1644 case VK_FORMAT_ASTC_5x5_UNORM_BLOCK:
1645 case VK_FORMAT_ASTC_6x5_UNORM_BLOCK:
1646 case VK_FORMAT_ASTC_6x6_UNORM_BLOCK:
1647 case VK_FORMAT_ASTC_8x5_UNORM_BLOCK:
1648 case VK_FORMAT_ASTC_8x6_UNORM_BLOCK:
1649 case VK_FORMAT_ASTC_8x8_UNORM_BLOCK:
1650 case VK_FORMAT_ASTC_10x5_UNORM_BLOCK:
1651 case VK_FORMAT_ASTC_10x6_UNORM_BLOCK:
1652 case VK_FORMAT_ASTC_10x8_UNORM_BLOCK:
1653 case VK_FORMAT_ASTC_10x10_UNORM_BLOCK:
1654 case VK_FORMAT_ASTC_12x10_UNORM_BLOCK:
1655 case VK_FORMAT_ASTC_12x12_UNORM_BLOCK:
1656 case VK_FORMAT_ASTC_4x4_SRGB_BLOCK:
1657 case VK_FORMAT_ASTC_5x4_SRGB_BLOCK:
1658 case VK_FORMAT_ASTC_5x5_SRGB_BLOCK:
1659 case VK_FORMAT_ASTC_6x5_SRGB_BLOCK:
1660 case VK_FORMAT_ASTC_6x6_SRGB_BLOCK:
1661 case VK_FORMAT_ASTC_8x5_SRGB_BLOCK:
1662 case VK_FORMAT_ASTC_8x6_SRGB_BLOCK:
1663 case VK_FORMAT_ASTC_8x8_SRGB_BLOCK:
1664 case VK_FORMAT_ASTC_10x5_SRGB_BLOCK:
1665 case VK_FORMAT_ASTC_10x6_SRGB_BLOCK:
1666 case VK_FORMAT_ASTC_10x8_SRGB_BLOCK:
1667 case VK_FORMAT_ASTC_10x10_SRGB_BLOCK:
1668 case VK_FORMAT_ASTC_12x10_SRGB_BLOCK:
1669 case VK_FORMAT_ASTC_12x12_SRGB_BLOCK:
1670 #endif
1671 case VK_FORMAT_D16_UNORM:
1672 case VK_FORMAT_D32_SFLOAT:
1673 case VK_FORMAT_D32_SFLOAT_S8_UINT:
1674 pFormatProperties->optimalTilingFeatures |=
1675 VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT;
1676 // [[fallthrough]]
1677
1678 // Formats which can be sampled, but don't support filtering
1679 case VK_FORMAT_R8_UINT:
1680 case VK_FORMAT_R8_SINT:
1681 case VK_FORMAT_R8G8_UINT:
1682 case VK_FORMAT_R8G8_SINT:
1683 case VK_FORMAT_R8G8B8A8_UINT:
1684 case VK_FORMAT_R8G8B8A8_SINT:
1685 case VK_FORMAT_A8B8G8R8_UINT_PACK32:
1686 case VK_FORMAT_A8B8G8R8_SINT_PACK32:
1687 case VK_FORMAT_A2B10G10R10_UINT_PACK32:
1688 case VK_FORMAT_A2R10G10B10_UINT_PACK32:
1689 case VK_FORMAT_R16_UINT:
1690 case VK_FORMAT_R16_SINT:
1691 case VK_FORMAT_R16G16_UINT:
1692 case VK_FORMAT_R16G16_SINT:
1693 case VK_FORMAT_R16G16B16A16_UINT:
1694 case VK_FORMAT_R16G16B16A16_SINT:
1695 case VK_FORMAT_R32_UINT:
1696 case VK_FORMAT_R32_SINT:
1697 case VK_FORMAT_R32G32_UINT:
1698 case VK_FORMAT_R32G32_SINT:
1699 case VK_FORMAT_R32G32B32A32_UINT:
1700 case VK_FORMAT_R32G32B32A32_SINT:
1701 case VK_FORMAT_S8_UINT:
1702 pFormatProperties->optimalTilingFeatures |=
1703 VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT |
1704 VK_FORMAT_FEATURE_BLIT_SRC_BIT |
1705 VK_FORMAT_FEATURE_TRANSFER_SRC_BIT |
1706 VK_FORMAT_FEATURE_TRANSFER_DST_BIT;
1707 break;
1708
1709 // YCbCr formats:
1710 case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM:
1711 case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM:
1712 case VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16:
1713 pFormatProperties->optimalTilingFeatures |=
1714 VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT |
1715 VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT |
1716 VK_FORMAT_FEATURE_TRANSFER_SRC_BIT |
1717 VK_FORMAT_FEATURE_TRANSFER_DST_BIT |
1718 VK_FORMAT_FEATURE_COSITED_CHROMA_SAMPLES_BIT;
1719 break;
1720 default:
1721 break;
1722 }
1723
1724 switch(format)
1725 {
1726 // Vulkan 1.0 mandatory storage image formats supporting atomic operations
1727 case VK_FORMAT_R32_UINT:
1728 case VK_FORMAT_R32_SINT:
1729 pFormatProperties->optimalTilingFeatures |=
1730 VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT;
1731 pFormatProperties->bufferFeatures |=
1732 VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT;
1733 // [[fallthrough]]
1734 // Vulkan 1.0 mandatory storage image formats
1735 case VK_FORMAT_R8G8B8A8_UNORM:
1736 case VK_FORMAT_R8G8B8A8_SNORM:
1737 case VK_FORMAT_R8G8B8A8_UINT:
1738 case VK_FORMAT_R8G8B8A8_SINT:
1739 case VK_FORMAT_R16G16B16A16_UINT:
1740 case VK_FORMAT_R16G16B16A16_SINT:
1741 case VK_FORMAT_R16G16B16A16_SFLOAT:
1742 case VK_FORMAT_R32_SFLOAT:
1743 case VK_FORMAT_R32G32_UINT:
1744 case VK_FORMAT_R32G32_SINT:
1745 case VK_FORMAT_R32G32_SFLOAT:
1746 case VK_FORMAT_R32G32B32A32_UINT:
1747 case VK_FORMAT_R32G32B32A32_SINT:
1748 case VK_FORMAT_R32G32B32A32_SFLOAT:
1749 case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
1750 case VK_FORMAT_A2B10G10R10_UINT_PACK32:
1751 // Vulkan 1.0 shaderStorageImageExtendedFormats
1752 case VK_FORMAT_R16G16_SFLOAT:
1753 case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
1754 case VK_FORMAT_R16_SFLOAT:
1755 case VK_FORMAT_R16G16B16A16_UNORM:
1756 case VK_FORMAT_R16G16_UNORM:
1757 case VK_FORMAT_R8G8_UNORM:
1758 case VK_FORMAT_R16_UNORM:
1759 case VK_FORMAT_R8_UNORM:
1760 case VK_FORMAT_R16G16B16A16_SNORM:
1761 case VK_FORMAT_R16G16_SNORM:
1762 case VK_FORMAT_R8G8_SNORM:
1763 case VK_FORMAT_R16_SNORM:
1764 case VK_FORMAT_R8_SNORM:
1765 case VK_FORMAT_R16G16_SINT:
1766 case VK_FORMAT_R8G8_SINT:
1767 case VK_FORMAT_R16_SINT:
1768 case VK_FORMAT_R8_SINT:
1769 case VK_FORMAT_R16G16_UINT:
1770 case VK_FORMAT_R8G8_UINT:
1771 case VK_FORMAT_R16_UINT:
1772 case VK_FORMAT_R8_UINT:
1773 // Additional formats not listed under "Formats without shader storage format"
1774 case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
1775 case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
1776 case VK_FORMAT_A8B8G8R8_UINT_PACK32:
1777 case VK_FORMAT_A8B8G8R8_SINT_PACK32:
1778 case VK_FORMAT_B8G8R8A8_UNORM:
1779 case VK_FORMAT_B8G8R8A8_SRGB:
1780 pFormatProperties->optimalTilingFeatures |=
1781 VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT |
1782 VK_FORMAT_FEATURE_2_STORAGE_WRITE_WITHOUT_FORMAT_BIT;
1783 pFormatProperties->bufferFeatures |=
1784 VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT;
1785 break;
1786 default:
1787 break;
1788 }
1789
1790 switch(format)
1791 {
1792 case VK_FORMAT_R5G6B5_UNORM_PACK16:
1793 case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
1794 case VK_FORMAT_R4G4B4A4_UNORM_PACK16:
1795 case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
1796 case VK_FORMAT_A4R4G4B4_UNORM_PACK16:
1797 case VK_FORMAT_A4B4G4R4_UNORM_PACK16:
1798 case VK_FORMAT_B5G6R5_UNORM_PACK16:
1799 case VK_FORMAT_R5G5B5A1_UNORM_PACK16:
1800 case VK_FORMAT_B5G5R5A1_UNORM_PACK16:
1801 case VK_FORMAT_R8_UNORM:
1802 case VK_FORMAT_R8G8_UNORM:
1803 case VK_FORMAT_R8G8B8A8_UNORM:
1804 case VK_FORMAT_R8G8B8A8_SRGB:
1805 case VK_FORMAT_B8G8R8A8_UNORM:
1806 case VK_FORMAT_B8G8R8A8_SRGB:
1807 case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
1808 case VK_FORMAT_A8B8G8R8_SRGB_PACK32:
1809 case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
1810 case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
1811 case VK_FORMAT_R16_SFLOAT:
1812 case VK_FORMAT_R16G16_SFLOAT:
1813 case VK_FORMAT_R16G16B16A16_SFLOAT:
1814 case VK_FORMAT_R32_SFLOAT:
1815 case VK_FORMAT_R32G32_SFLOAT:
1816 case VK_FORMAT_R32G32B32A32_SFLOAT:
1817 case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
1818 case VK_FORMAT_R8_UINT:
1819 case VK_FORMAT_R8_SINT:
1820 case VK_FORMAT_R8G8_UINT:
1821 case VK_FORMAT_R8G8_SINT:
1822 case VK_FORMAT_R8G8B8A8_UINT:
1823 case VK_FORMAT_R8G8B8A8_SINT:
1824 case VK_FORMAT_A8B8G8R8_UINT_PACK32:
1825 case VK_FORMAT_A8B8G8R8_SINT_PACK32:
1826 case VK_FORMAT_A2B10G10R10_UINT_PACK32:
1827 case VK_FORMAT_A2R10G10B10_UINT_PACK32:
1828 case VK_FORMAT_R16_UNORM:
1829 case VK_FORMAT_R16_UINT:
1830 case VK_FORMAT_R16_SINT:
1831 case VK_FORMAT_R16G16_UNORM:
1832 case VK_FORMAT_R16G16_UINT:
1833 case VK_FORMAT_R16G16_SINT:
1834 case VK_FORMAT_R16G16B16A16_UNORM:
1835 case VK_FORMAT_R16G16B16A16_UINT:
1836 case VK_FORMAT_R16G16B16A16_SINT:
1837 case VK_FORMAT_R32_UINT:
1838 case VK_FORMAT_R32_SINT:
1839 case VK_FORMAT_R32G32_UINT:
1840 case VK_FORMAT_R32G32_SINT:
1841 case VK_FORMAT_R32G32B32A32_UINT:
1842 case VK_FORMAT_R32G32B32A32_SINT:
1843 pFormatProperties->optimalTilingFeatures |=
1844 VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT |
1845 VK_FORMAT_FEATURE_BLIT_DST_BIT;
1846 break;
1847 case VK_FORMAT_S8_UINT:
1848 case VK_FORMAT_D16_UNORM:
1849 case VK_FORMAT_D32_SFLOAT: // Note: either VK_FORMAT_D32_SFLOAT or VK_FORMAT_X8_D24_UNORM_PACK32 must be supported
1850 case VK_FORMAT_D32_SFLOAT_S8_UINT: // Note: either VK_FORMAT_D24_UNORM_S8_UINT or VK_FORMAT_D32_SFLOAT_S8_UINT must be supported
1851 pFormatProperties->optimalTilingFeatures |=
1852 VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT;
1853 break;
1854 default:
1855 break;
1856 }
1857
1858 switch(format)
1859 {
1860 case VK_FORMAT_D16_UNORM:
1861 case VK_FORMAT_D32_SFLOAT: // Note: either VK_FORMAT_D32_SFLOAT or VK_FORMAT_X8_D24_UNORM_PACK32 must be supported
1862 case VK_FORMAT_D32_SFLOAT_S8_UINT: // Note: either VK_FORMAT_D24_UNORM_S8_UINT or VK_FORMAT_D32_SFLOAT_S8_UINT must be supported
1863 pFormatProperties->linearTilingFeatures |=
1864 VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_DEPTH_COMPARISON_BIT_KHR;
1865 pFormatProperties->optimalTilingFeatures |=
1866 VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_DEPTH_COMPARISON_BIT_KHR;
1867 break;
1868 default:
1869 break;
1870 }
1871
1872 if(format.supportsColorAttachmentBlend())
1873 {
1874 pFormatProperties->optimalTilingFeatures |=
1875 VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT;
1876 }
1877
1878 switch(format)
1879 {
1880 case VK_FORMAT_R8_UNORM:
1881 case VK_FORMAT_R8_SNORM:
1882 case VK_FORMAT_R8_USCALED:
1883 case VK_FORMAT_R8_SSCALED:
1884 case VK_FORMAT_R8_UINT:
1885 case VK_FORMAT_R8_SINT:
1886 case VK_FORMAT_R8G8_UNORM:
1887 case VK_FORMAT_R8G8_SNORM:
1888 case VK_FORMAT_R8G8_USCALED:
1889 case VK_FORMAT_R8G8_SSCALED:
1890 case VK_FORMAT_R8G8_UINT:
1891 case VK_FORMAT_R8G8_SINT:
1892 case VK_FORMAT_R8G8B8A8_UNORM:
1893 case VK_FORMAT_R8G8B8A8_SNORM:
1894 case VK_FORMAT_R8G8B8A8_USCALED:
1895 case VK_FORMAT_R8G8B8A8_SSCALED:
1896 case VK_FORMAT_R8G8B8A8_UINT:
1897 case VK_FORMAT_R8G8B8A8_SINT:
1898 case VK_FORMAT_B8G8R8A8_UNORM:
1899 case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
1900 case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
1901 case VK_FORMAT_A8B8G8R8_USCALED_PACK32:
1902 case VK_FORMAT_A8B8G8R8_SSCALED_PACK32:
1903 case VK_FORMAT_A8B8G8R8_UINT_PACK32:
1904 case VK_FORMAT_A8B8G8R8_SINT_PACK32:
1905 case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
1906 case VK_FORMAT_A2R10G10B10_SNORM_PACK32:
1907 case VK_FORMAT_A2R10G10B10_UINT_PACK32:
1908 case VK_FORMAT_A2R10G10B10_SINT_PACK32:
1909 case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
1910 case VK_FORMAT_A2B10G10R10_SNORM_PACK32:
1911 case VK_FORMAT_A2B10G10R10_UINT_PACK32:
1912 case VK_FORMAT_A2B10G10R10_SINT_PACK32:
1913 case VK_FORMAT_R16_UNORM:
1914 case VK_FORMAT_R16_SNORM:
1915 case VK_FORMAT_R16_USCALED:
1916 case VK_FORMAT_R16_SSCALED:
1917 case VK_FORMAT_R16_UINT:
1918 case VK_FORMAT_R16_SINT:
1919 case VK_FORMAT_R16_SFLOAT:
1920 case VK_FORMAT_R16G16_UNORM:
1921 case VK_FORMAT_R16G16_SNORM:
1922 case VK_FORMAT_R16G16_USCALED:
1923 case VK_FORMAT_R16G16_SSCALED:
1924 case VK_FORMAT_R16G16_UINT:
1925 case VK_FORMAT_R16G16_SINT:
1926 case VK_FORMAT_R16G16_SFLOAT:
1927 case VK_FORMAT_R16G16B16A16_UNORM:
1928 case VK_FORMAT_R16G16B16A16_SNORM:
1929 case VK_FORMAT_R16G16B16A16_USCALED:
1930 case VK_FORMAT_R16G16B16A16_SSCALED:
1931 case VK_FORMAT_R16G16B16A16_UINT:
1932 case VK_FORMAT_R16G16B16A16_SINT:
1933 case VK_FORMAT_R16G16B16A16_SFLOAT:
1934 case VK_FORMAT_R32_UINT:
1935 case VK_FORMAT_R32_SINT:
1936 case VK_FORMAT_R32_SFLOAT:
1937 case VK_FORMAT_R32G32_UINT:
1938 case VK_FORMAT_R32G32_SINT:
1939 case VK_FORMAT_R32G32_SFLOAT:
1940 case VK_FORMAT_R32G32B32_UINT:
1941 case VK_FORMAT_R32G32B32_SINT:
1942 case VK_FORMAT_R32G32B32_SFLOAT:
1943 case VK_FORMAT_R32G32B32A32_UINT:
1944 case VK_FORMAT_R32G32B32A32_SINT:
1945 case VK_FORMAT_R32G32B32A32_SFLOAT:
1946 pFormatProperties->bufferFeatures |=
1947 VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT;
1948 break;
1949 default:
1950 break;
1951 }
1952
1953 switch(format)
1954 {
1955 // Vulkan 1.1 mandatory
1956 case VK_FORMAT_R8_UNORM:
1957 case VK_FORMAT_R8_SNORM:
1958 case VK_FORMAT_R8_UINT:
1959 case VK_FORMAT_R8_SINT:
1960 case VK_FORMAT_R8G8_UNORM:
1961 case VK_FORMAT_R8G8_SNORM:
1962 case VK_FORMAT_R8G8_UINT:
1963 case VK_FORMAT_R8G8_SINT:
1964 case VK_FORMAT_R8G8B8A8_UNORM:
1965 case VK_FORMAT_R8G8B8A8_SNORM:
1966 case VK_FORMAT_R8G8B8A8_UINT:
1967 case VK_FORMAT_R8G8B8A8_SINT:
1968 case VK_FORMAT_B8G8R8A8_UNORM:
1969 case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
1970 case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
1971 case VK_FORMAT_A8B8G8R8_UINT_PACK32:
1972 case VK_FORMAT_A8B8G8R8_SINT_PACK32:
1973 case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
1974 case VK_FORMAT_A2B10G10R10_UINT_PACK32:
1975 case VK_FORMAT_R16_UINT:
1976 case VK_FORMAT_R16_SINT:
1977 case VK_FORMAT_R16_SFLOAT:
1978 case VK_FORMAT_R16G16_UINT:
1979 case VK_FORMAT_R16G16_SINT:
1980 case VK_FORMAT_R16G16_SFLOAT:
1981 case VK_FORMAT_R16G16B16A16_UINT:
1982 case VK_FORMAT_R16G16B16A16_SINT:
1983 case VK_FORMAT_R16G16B16A16_SFLOAT:
1984 case VK_FORMAT_R32_UINT:
1985 case VK_FORMAT_R32_SINT:
1986 case VK_FORMAT_R32_SFLOAT:
1987 case VK_FORMAT_R32G32_UINT:
1988 case VK_FORMAT_R32G32_SINT:
1989 case VK_FORMAT_R32G32_SFLOAT:
1990 case VK_FORMAT_R32G32B32A32_UINT:
1991 case VK_FORMAT_R32G32B32A32_SINT:
1992 case VK_FORMAT_R32G32B32A32_SFLOAT:
1993 case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
1994 // Optional
1995 case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
1996 case VK_FORMAT_A2R10G10B10_UINT_PACK32:
1997 pFormatProperties->bufferFeatures |=
1998 VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT;
1999 break;
2000 default:
2001 break;
2002 }
2003
2004 if(pFormatProperties->optimalTilingFeatures)
2005 {
2006 pFormatProperties->linearTilingFeatures |= VK_FORMAT_FEATURE_TRANSFER_SRC_BIT |
2007 VK_FORMAT_FEATURE_TRANSFER_DST_BIT;
2008
2009 if(!format.isCompressed())
2010 {
2011 if(pFormatProperties->optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)
2012 {
2013 pFormatProperties->linearTilingFeatures |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT;
2014 }
2015 if(pFormatProperties->optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT)
2016 {
2017 pFormatProperties->linearTilingFeatures |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT;
2018 }
2019 }
2020 }
2021 }
2022
getImageFormatProperties(Format format,VkImageType type,VkImageTiling tiling,VkImageUsageFlags usage,VkImageCreateFlags flags,VkImageFormatProperties * pImageFormatProperties) const2023 void PhysicalDevice::getImageFormatProperties(Format format, VkImageType type, VkImageTiling tiling,
2024 VkImageUsageFlags usage, VkImageCreateFlags flags,
2025 VkImageFormatProperties *pImageFormatProperties) const
2026 {
2027 pImageFormatProperties->sampleCounts = VK_SAMPLE_COUNT_1_BIT;
2028 pImageFormatProperties->maxArrayLayers = vk::MAX_IMAGE_ARRAY_LAYERS;
2029 pImageFormatProperties->maxExtent.depth = 1;
2030
2031 switch(type)
2032 {
2033 case VK_IMAGE_TYPE_1D:
2034 pImageFormatProperties->maxMipLevels = vk::MAX_IMAGE_LEVELS_1D;
2035 pImageFormatProperties->maxExtent.width = 1 << (vk::MAX_IMAGE_LEVELS_1D - 1);
2036 pImageFormatProperties->maxExtent.height = 1;
2037 break;
2038 case VK_IMAGE_TYPE_2D:
2039 if(flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT)
2040 {
2041 pImageFormatProperties->maxMipLevels = vk::MAX_IMAGE_LEVELS_CUBE;
2042 pImageFormatProperties->maxExtent.width = 1 << (vk::MAX_IMAGE_LEVELS_CUBE - 1);
2043 pImageFormatProperties->maxExtent.height = 1 << (vk::MAX_IMAGE_LEVELS_CUBE - 1);
2044 }
2045 else
2046 {
2047 pImageFormatProperties->maxMipLevels = vk::MAX_IMAGE_LEVELS_2D;
2048 pImageFormatProperties->maxExtent.width = 1 << (vk::MAX_IMAGE_LEVELS_2D - 1);
2049 pImageFormatProperties->maxExtent.height = 1 << (vk::MAX_IMAGE_LEVELS_2D - 1);
2050
2051 VkFormatProperties props;
2052 GetFormatProperties(format, &props);
2053 auto features = tiling == VK_IMAGE_TILING_LINEAR ? props.linearTilingFeatures : props.optimalTilingFeatures;
2054 if(features & (VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT | VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT))
2055 {
2056 // Only renderable formats make sense for multisample
2057 pImageFormatProperties->sampleCounts = getSampleCounts();
2058 }
2059 }
2060 break;
2061 case VK_IMAGE_TYPE_3D:
2062 pImageFormatProperties->maxMipLevels = vk::MAX_IMAGE_LEVELS_3D;
2063 pImageFormatProperties->maxExtent.width = 1 << (vk::MAX_IMAGE_LEVELS_3D - 1);
2064 pImageFormatProperties->maxExtent.height = 1 << (vk::MAX_IMAGE_LEVELS_3D - 1);
2065 pImageFormatProperties->maxExtent.depth = 1 << (vk::MAX_IMAGE_LEVELS_3D - 1);
2066 pImageFormatProperties->maxArrayLayers = 1; // no 3D + layers
2067 break;
2068 default:
2069 UNREACHABLE("VkImageType: %d", int(type));
2070 break;
2071 }
2072
2073 pImageFormatProperties->maxResourceSize = 1u << 31; // Minimum value for maxResourceSize
2074
2075 // "Images created with tiling equal to VK_IMAGE_TILING_LINEAR have further restrictions on their limits and capabilities
2076 // compared to images created with tiling equal to VK_IMAGE_TILING_OPTIMAL."
2077 if(tiling == VK_IMAGE_TILING_LINEAR)
2078 {
2079 pImageFormatProperties->maxMipLevels = 1;
2080 pImageFormatProperties->maxArrayLayers = 1;
2081 pImageFormatProperties->sampleCounts = VK_SAMPLE_COUNT_1_BIT;
2082 }
2083
2084 // "Images created with a format from one of those listed in Formats requiring sampler Y'CbCr conversion for VK_IMAGE_ASPECT_COLOR_BIT image views
2085 // have further restrictions on their limits and capabilities compared to images created with other formats."
2086 if(format.isYcbcrFormat())
2087 {
2088 pImageFormatProperties->maxMipLevels = 1; // TODO(b/151263485): This is relied on by the sampler to disable mipmapping for Y'CbCr image sampling.
2089 pImageFormatProperties->maxArrayLayers = 1;
2090 pImageFormatProperties->sampleCounts = VK_SAMPLE_COUNT_1_BIT;
2091 }
2092 }
2093
getQueueFamilyPropertyCount() const2094 uint32_t PhysicalDevice::getQueueFamilyPropertyCount() const
2095 {
2096 return 1;
2097 }
2098
getQueueFamilyProperties() const2099 VkQueueFamilyProperties PhysicalDevice::getQueueFamilyProperties() const
2100 {
2101 VkQueueFamilyProperties properties = {};
2102 properties.minImageTransferGranularity.width = 1;
2103 properties.minImageTransferGranularity.height = 1;
2104 properties.minImageTransferGranularity.depth = 1;
2105 properties.queueCount = 1;
2106 properties.queueFlags = VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT;
2107 properties.timestampValidBits = 64;
2108
2109 return properties;
2110 }
2111
getQueueFamilyProperties(uint32_t pQueueFamilyPropertyCount,VkQueueFamilyProperties * pQueueFamilyProperties) const2112 void PhysicalDevice::getQueueFamilyProperties(uint32_t pQueueFamilyPropertyCount,
2113 VkQueueFamilyProperties *pQueueFamilyProperties) const
2114 {
2115 for(uint32_t i = 0; i < pQueueFamilyPropertyCount; i++)
2116 {
2117 pQueueFamilyProperties[i] = getQueueFamilyProperties();
2118 }
2119 }
2120
getQueueFamilyProperties(uint32_t pQueueFamilyPropertyCount,VkQueueFamilyProperties2 * pQueueFamilyProperties) const2121 void PhysicalDevice::getQueueFamilyProperties(uint32_t pQueueFamilyPropertyCount,
2122 VkQueueFamilyProperties2 *pQueueFamilyProperties) const
2123 {
2124 for(uint32_t i = 0; i < pQueueFamilyPropertyCount; i++)
2125 {
2126 pQueueFamilyProperties[i].queueFamilyProperties = getQueueFamilyProperties();
2127 }
2128 }
2129
GetMemoryProperties()2130 const VkPhysicalDeviceMemoryProperties &PhysicalDevice::GetMemoryProperties()
2131 {
2132 static const VkPhysicalDeviceMemoryProperties properties{
2133 1, // memoryTypeCount
2134 {
2135 // vk::MEMORY_TYPE_GENERIC_BIT
2136 {
2137 (VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
2138 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
2139 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT |
2140 VK_MEMORY_PROPERTY_HOST_CACHED_BIT), // propertyFlags
2141 0 // heapIndex
2142 },
2143 },
2144 1, // memoryHeapCount
2145 {
2146 {
2147 vk::PHYSICAL_DEVICE_HEAP_SIZE, // size
2148 VK_MEMORY_HEAP_DEVICE_LOCAL_BIT // flags
2149 },
2150 }
2151 };
2152
2153 return properties;
2154 }
2155
2156 } // namespace vk
2157