• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_TRUE;
248 	features->shaderStorageTexelBufferArrayDynamicIndexing = VK_TRUE;
249 	features->shaderUniformBufferArrayNonUniformIndexing = VK_TRUE;
250 	features->shaderSampledImageArrayNonUniformIndexing = VK_TRUE;
251 	features->shaderStorageBufferArrayNonUniformIndexing = VK_TRUE;
252 	features->shaderStorageImageArrayNonUniformIndexing = VK_TRUE;
253 	features->shaderInputAttachmentArrayNonUniformIndexing = VK_FALSE;
254 	features->shaderUniformTexelBufferArrayNonUniformIndexing = VK_TRUE;
255 	features->shaderStorageTexelBufferArrayNonUniformIndexing = VK_TRUE;
256 	features->descriptorBindingUniformBufferUpdateAfterBind = VK_FALSE;
257 	features->descriptorBindingSampledImageUpdateAfterBind = VK_TRUE;
258 	features->descriptorBindingStorageImageUpdateAfterBind = VK_TRUE;
259 	features->descriptorBindingStorageBufferUpdateAfterBind = VK_TRUE;
260 	features->descriptorBindingUniformTexelBufferUpdateAfterBind = VK_TRUE;
261 	features->descriptorBindingStorageTexelBufferUpdateAfterBind = VK_TRUE;
262 	features->descriptorBindingUpdateUnusedWhilePending = VK_TRUE;
263 	features->descriptorBindingPartiallyBound = VK_TRUE;
264 	features->descriptorBindingVariableDescriptorCount = VK_TRUE;
265 	features->runtimeDescriptorArray = VK_TRUE;
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_TRUE;
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>
getPhysicalDeviceDynamicRenderingLocalReadFeatures(T * features)311 static void getPhysicalDeviceDynamicRenderingLocalReadFeatures(T *features)
312 {
313 	features->dynamicRenderingLocalRead = VK_TRUE;
314 }
315 
316 template<typename T>
getPhysicalDeviceInlineUniformBlockFeatures(T * features)317 static void getPhysicalDeviceInlineUniformBlockFeatures(T *features)
318 {
319 	features->inlineUniformBlock = VK_TRUE;
320 	features->descriptorBindingInlineUniformBlockUpdateAfterBind = VK_TRUE;
321 }
322 
323 template<typename T>
getPhysicalDevicePrivateDataFeatures(T * features)324 static void getPhysicalDevicePrivateDataFeatures(T *features)
325 {
326 	features->privateData = VK_TRUE;
327 }
328 
329 template<typename T>
getPhysicalDeviceTextureCompressionASTCHDRFeatures(T * features)330 static void getPhysicalDeviceTextureCompressionASTCHDRFeatures(T *features)
331 {
332 	features->textureCompressionASTC_HDR = VK_FALSE;
333 }
334 
335 template<typename T>
getPhysicalDeviceShaderDemoteToHelperInvocationFeatures(T * features)336 static void getPhysicalDeviceShaderDemoteToHelperInvocationFeatures(T *features)
337 {
338 	features->shaderDemoteToHelperInvocation = VK_TRUE;
339 }
340 
341 template<typename T>
getPhysicalDeviceShaderTerminateInvocationFeatures(T * features)342 static void getPhysicalDeviceShaderTerminateInvocationFeatures(T *features)
343 {
344 	features->shaderTerminateInvocation = VK_TRUE;
345 }
346 
347 template<typename T>
getPhysicalDeviceSubgroupSizeControlFeatures(T * features)348 static void getPhysicalDeviceSubgroupSizeControlFeatures(T *features)
349 {
350 	features->subgroupSizeControl = VK_TRUE;
351 	features->computeFullSubgroups = VK_TRUE;
352 }
353 
354 template<typename T>
getPhysicalDeviceSynchronization2Features(T * features)355 static void getPhysicalDeviceSynchronization2Features(T *features)
356 {
357 	features->synchronization2 = VK_TRUE;
358 }
359 
360 template<typename T>
getPhysicalDeviceShaderIntegerDotProductFeatures(T * features)361 static void getPhysicalDeviceShaderIntegerDotProductFeatures(T *features)
362 {
363 	features->shaderIntegerDotProduct = VK_TRUE;
364 }
365 
366 template<typename T>
getPhysicalDeviceZeroInitializeWorkgroupMemoryFeatures(T * features)367 static void getPhysicalDeviceZeroInitializeWorkgroupMemoryFeatures(T *features)
368 {
369 	features->shaderZeroInitializeWorkgroupMemory = VK_TRUE;
370 }
371 
372 template<typename T>
getPhysicalDeviceMaintenance4Features(T * features)373 static void getPhysicalDeviceMaintenance4Features(T *features)
374 {
375 	features->maintenance4 = VK_TRUE;
376 }
377 
378 template<typename T>
getPhysicalDevicePrimitiveTopologyListRestartFeatures(T * features)379 static void getPhysicalDevicePrimitiveTopologyListRestartFeatures(T *features)
380 {
381 	features->primitiveTopologyListRestart = VK_TRUE;
382 	features->primitiveTopologyPatchListRestart = VK_FALSE;
383 }
384 
385 template<typename T>
getPhysicalDevicePipelineRobustnessFeatures(T * features)386 static void getPhysicalDevicePipelineRobustnessFeatures(T *features)
387 {
388 	features->pipelineRobustness = VK_TRUE;
389 }
390 
391 template<typename T>
getPhysicalDeviceGraphicsPipelineLibraryFeatures(T * features)392 static void getPhysicalDeviceGraphicsPipelineLibraryFeatures(T *features)
393 {
394 	features->graphicsPipelineLibrary = VK_TRUE;
395 }
396 
397 template<typename T>
getPhysicalDeviceGlobalPriorityQueryFeatures(T * features)398 static void getPhysicalDeviceGlobalPriorityQueryFeatures(T *features)
399 {
400 	features->globalPriorityQuery = VK_TRUE;
401 }
402 
403 template<typename T>
getPhysicalDeviceSwapchainMaintenance1FeaturesKHR(T * features)404 static void getPhysicalDeviceSwapchainMaintenance1FeaturesKHR(T *features)
405 {
406 	features->swapchainMaintenance1 = VK_TRUE;
407 }
408 
409 template<typename T>
getPhysicalDeviceHostImageCopyFeatures(T * features)410 static void getPhysicalDeviceHostImageCopyFeatures(T *features)
411 {
412 	features->hostImageCopy = VK_TRUE;
413 }
414 
415 template<typename T>
getPhysicalDeviceIndexTypeUint8Features(T * features)416 static void getPhysicalDeviceIndexTypeUint8Features(T *features)
417 {
418 	features->indexTypeUint8 = VK_TRUE;
419 }
420 
421 template<typename T>
getPhysicalDeviceVulkan12Features(T * features)422 static void getPhysicalDeviceVulkan12Features(T *features)
423 {
424 	features->samplerMirrorClampToEdge = VK_TRUE;
425 	features->drawIndirectCount = VK_FALSE;
426 	getPhysicalDevice8BitStorageFeaturesKHR(features);
427 	getPhysicalDeviceShaderAtomicInt64Features(features);
428 	getPhysicalDeviceShaderFloat16Int8Features(features);
429 	features->descriptorIndexing = VK_TRUE;
430 	getPhysicalDeviceDescriptorIndexingFeatures(features);
431 	features->samplerFilterMinmax = VK_FALSE;
432 	getPhysicalDeviceScalarBlockLayoutFeatures(features);
433 	getPhysicalDeviceImagelessFramebufferFeatures(features);
434 	getPhysicalDeviceUniformBufferStandardLayoutFeatures(features);
435 	getPhysicalDeviceShaderSubgroupExtendedTypesFeatures(features);
436 	getPhysicalDeviceSeparateDepthStencilLayoutsFeaturesKHR(features);
437 	getPhysicalDeviceHostQueryResetFeatures(features);
438 	getPhysicalDeviceTimelineSemaphoreFeatures(features);
439 	getPhysicalDeviceBufferDeviceAddressFeatures(features);
440 	getPhysicalDeviceVulkanMemoryModelFeatures(features);
441 	features->shaderOutputViewportIndex = VK_FALSE;
442 	features->shaderOutputLayer = VK_FALSE;
443 	features->subgroupBroadcastDynamicId = VK_TRUE;
444 }
445 
446 template<typename T>
getPhysicalDeviceDepthClipEnableFeaturesEXT(T * features)447 static void getPhysicalDeviceDepthClipEnableFeaturesEXT(T *features)
448 {
449 	features->depthClipEnable = VK_TRUE;
450 }
451 
452 template<typename T>
getPhysicalDeviceVulkan13Features(T * features)453 static void getPhysicalDeviceVulkan13Features(T *features)
454 {
455 	getPhysicalDeviceImageRobustnessFeatures(features);
456 	getPhysicalDeviceInlineUniformBlockFeatures(features);
457 	getPhysicalDevicePipelineCreationCacheControlFeatures(features);
458 	getPhysicalDevicePrivateDataFeatures(features);
459 	getPhysicalDeviceShaderDemoteToHelperInvocationFeatures(features);
460 	getPhysicalDeviceShaderTerminateInvocationFeatures(features);
461 	getPhysicalDeviceSubgroupSizeControlFeatures(features);
462 	getPhysicalDeviceSynchronization2Features(features);
463 	getPhysicalDeviceTextureCompressionASTCHDRFeatures(features);
464 	getPhysicalDeviceZeroInitializeWorkgroupMemoryFeatures(features);
465 	getPhysicalDeviceDynamicRenderingFeatures(features);
466 	getPhysicalDeviceShaderIntegerDotProductFeatures(features);
467 	getPhysicalDeviceMaintenance4Features(features);
468 }
469 
getPhysicalDeviceCustomBorderColorFeaturesEXT(VkPhysicalDeviceCustomBorderColorFeaturesEXT * features)470 static void getPhysicalDeviceCustomBorderColorFeaturesEXT(VkPhysicalDeviceCustomBorderColorFeaturesEXT *features)
471 {
472 	features->customBorderColors = VK_TRUE;
473 	features->customBorderColorWithoutFormat = VK_TRUE;
474 }
475 
getPhysicalDeviceBlendOperationAdvancedFeaturesEXT(VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT * features)476 static void getPhysicalDeviceBlendOperationAdvancedFeaturesEXT(VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT *features)
477 {
478 	features->advancedBlendCoherentOperations = VK_FALSE;
479 }
480 
getPhysicalDeviceExtendedDynamicStateFeaturesEXT(VkPhysicalDeviceExtendedDynamicStateFeaturesEXT * features)481 static void getPhysicalDeviceExtendedDynamicStateFeaturesEXT(VkPhysicalDeviceExtendedDynamicStateFeaturesEXT *features)
482 {
483 	features->extendedDynamicState = VK_TRUE;
484 }
485 
getPhysicalDeviceVertexInputDynamicStateFeaturesEXT(VkPhysicalDeviceVertexInputDynamicStateFeaturesEXT * features)486 static void getPhysicalDeviceVertexInputDynamicStateFeaturesEXT(VkPhysicalDeviceVertexInputDynamicStateFeaturesEXT *features)
487 {
488 	features->vertexInputDynamicState = VK_TRUE;
489 }
490 
getPhysicalDevice4444FormatsFeaturesEXT(VkPhysicalDevice4444FormatsFeaturesEXT * features)491 static void getPhysicalDevice4444FormatsFeaturesEXT(VkPhysicalDevice4444FormatsFeaturesEXT *features)
492 {
493 	features->formatA4R4G4B4 = VK_TRUE;
494 	features->formatA4B4G4R4 = VK_TRUE;
495 }
496 
getPhysicalDeviceRasterizationOrderAttachmentAccessFeaturesEXT(VkPhysicalDeviceRasterizationOrderAttachmentAccessFeaturesEXT * features)497 static void getPhysicalDeviceRasterizationOrderAttachmentAccessFeaturesEXT(VkPhysicalDeviceRasterizationOrderAttachmentAccessFeaturesEXT *features)
498 {
499 	features->rasterizationOrderColorAttachmentAccess = VK_TRUE;
500 	features->rasterizationOrderDepthAttachmentAccess = VK_TRUE;
501 	features->rasterizationOrderStencilAttachmentAccess = VK_TRUE;
502 }
503 
getPhysicalDeviceDepthClipControlFeaturesExt(VkPhysicalDeviceDepthClipControlFeaturesEXT * features)504 static void getPhysicalDeviceDepthClipControlFeaturesExt(VkPhysicalDeviceDepthClipControlFeaturesEXT *features)
505 {
506 	features->depthClipControl = VK_TRUE;
507 }
508 
getFeatures2(VkPhysicalDeviceFeatures2 * features) const509 void PhysicalDevice::getFeatures2(VkPhysicalDeviceFeatures2 *features) const
510 {
511 	features->features = getFeatures();
512 	VkBaseOutStructure *curExtension = reinterpret_cast<VkBaseOutStructure *>(features->pNext);
513 	while(curExtension != nullptr)
514 	{
515 		switch(curExtension->sType)
516 		{
517 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES:
518 			getPhysicalDeviceVulkan11Features(reinterpret_cast<VkPhysicalDeviceVulkan11Features *>(curExtension));
519 			break;
520 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES:
521 			getPhysicalDeviceVulkan12Features(reinterpret_cast<VkPhysicalDeviceVulkan12Features *>(curExtension));
522 			break;
523 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES:
524 			getPhysicalDeviceVulkan13Features(reinterpret_cast<VkPhysicalDeviceVulkan13Features *>(curExtension));
525 			break;
526 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES:
527 			getPhysicalDeviceMultiviewFeatures(reinterpret_cast<VkPhysicalDeviceMultiviewFeatures *>(curExtension));
528 			break;
529 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES:
530 			getPhysicalDeviceVariablePointersFeatures(reinterpret_cast<VkPhysicalDeviceVariablePointersFeatures *>(curExtension));
531 			break;
532 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES:
533 			getPhysicalDevice16BitStorageFeatures(reinterpret_cast<VkPhysicalDevice16BitStorageFeatures *>(curExtension));
534 			break;
535 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES:
536 			getPhysicalDeviceSamplerYcbcrConversionFeatures(reinterpret_cast<VkPhysicalDeviceSamplerYcbcrConversionFeatures *>(curExtension));
537 			break;
538 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES:
539 			getPhysicalDeviceProtectedMemoryFeatures(reinterpret_cast<VkPhysicalDeviceProtectedMemoryFeatures *>(curExtension));
540 			break;
541 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETERS_FEATURES:
542 			getPhysicalDeviceShaderDrawParameterFeatures(reinterpret_cast<VkPhysicalDeviceShaderDrawParameterFeatures *>(curExtension));
543 			break;
544 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES:
545 			getPhysicalDeviceHostQueryResetFeatures(reinterpret_cast<VkPhysicalDeviceHostQueryResetFeatures *>(curExtension));
546 			break;
547 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_CREATION_CACHE_CONTROL_FEATURES:
548 			getPhysicalDevicePipelineCreationCacheControlFeatures(reinterpret_cast<VkPhysicalDevicePipelineCreationCacheControlFeatures *>(curExtension));
549 			break;
550 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_ROBUSTNESS_FEATURES:
551 			getPhysicalDeviceImageRobustnessFeatures(reinterpret_cast<VkPhysicalDeviceImageRobustnessFeatures *>(curExtension));
552 			break;
553 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_FEATURES_EXT:
554 			getPhysicalDeviceLineRasterizationFeaturesEXT(reinterpret_cast<VkPhysicalDeviceLineRasterizationFeaturesEXT *>(curExtension));
555 			break;
556 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SEPARATE_DEPTH_STENCIL_LAYOUTS_FEATURES:
557 			getPhysicalDeviceSeparateDepthStencilLayoutsFeaturesKHR(reinterpret_cast<VkPhysicalDeviceSeparateDepthStencilLayoutsFeatures *>(curExtension));
558 			break;
559 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES:
560 			getPhysicalDevice8BitStorageFeaturesKHR(reinterpret_cast<VkPhysicalDevice8BitStorageFeaturesKHR *>(curExtension));
561 			break;
562 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROVOKING_VERTEX_FEATURES_EXT:
563 			getPhysicalDeviceProvokingVertexFeaturesEXT(reinterpret_cast<VkPhysicalDeviceProvokingVertexFeaturesEXT *>(curExtension));
564 			break;
565 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES:
566 			getPhysicalDeviceImagelessFramebufferFeatures(reinterpret_cast<VkPhysicalDeviceImagelessFramebufferFeatures *>(curExtension));
567 			break;
568 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_SUBGROUP_EXTENDED_TYPES_FEATURES:
569 			getPhysicalDeviceShaderSubgroupExtendedTypesFeatures(reinterpret_cast<VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures *>(curExtension));
570 			break;
571 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES:
572 			getPhysicalDeviceScalarBlockLayoutFeatures(reinterpret_cast<VkPhysicalDeviceScalarBlockLayoutFeatures *>(curExtension));
573 			break;
574 #ifdef SWIFTSHADER_DEVICE_MEMORY_REPORT
575 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEVICE_MEMORY_REPORT_FEATURES_EXT:
576 			getPhysicalDeviceDeviceMemoryReportFeaturesEXT(reinterpret_cast<VkPhysicalDeviceDeviceMemoryReportFeaturesEXT *>(curExtension));
577 			break;
578 #endif  // SWIFTSHADER_DEVICE_MEMORY_REPORT
579 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_UNIFORM_BUFFER_STANDARD_LAYOUT_FEATURES:
580 			getPhysicalDeviceUniformBufferStandardLayoutFeatures(reinterpret_cast<VkPhysicalDeviceUniformBufferStandardLayoutFeatures *>(curExtension));
581 			break;
582 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_MEMORY_MODEL_FEATURES:
583 			getPhysicalDeviceVulkanMemoryModelFeatures(reinterpret_cast<VkPhysicalDeviceVulkanMemoryModelFeatures *>(curExtension));
584 			break;
585 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TIMELINE_SEMAPHORE_FEATURES:
586 			getPhysicalDeviceTimelineSemaphoreFeatures(reinterpret_cast<VkPhysicalDeviceTimelineSemaphoreFeatures *>(curExtension));
587 			break;
588 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_INT64_FEATURES:
589 			getPhysicalDeviceShaderAtomicInt64Features(reinterpret_cast<VkPhysicalDeviceShaderAtomicInt64Features *>(curExtension));
590 			break;
591 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_FLOAT16_INT8_FEATURES:
592 			getPhysicalDeviceShaderFloat16Int8Features(reinterpret_cast<VkPhysicalDeviceShaderFloat16Int8Features *>(curExtension));
593 			break;
594 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES:
595 			getPhysicalDeviceBufferDeviceAddressFeatures(reinterpret_cast<VkPhysicalDeviceBufferDeviceAddressFeatures *>(curExtension));
596 			break;
597 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DYNAMIC_RENDERING_FEATURES:
598 			getPhysicalDeviceDynamicRenderingFeatures(reinterpret_cast<VkPhysicalDeviceDynamicRenderingFeatures *>(curExtension));
599 			break;
600 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DYNAMIC_RENDERING_LOCAL_READ_FEATURES_KHR:
601 			getPhysicalDeviceDynamicRenderingLocalReadFeatures(reinterpret_cast<VkPhysicalDeviceDynamicRenderingLocalReadFeaturesKHR *>(curExtension));
602 			break;
603 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES:
604 			getPhysicalDeviceDescriptorIndexingFeatures(reinterpret_cast<VkPhysicalDeviceDescriptorIndexingFeatures *>(curExtension));
605 			break;
606 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_ENABLE_FEATURES_EXT:
607 			getPhysicalDeviceDepthClipEnableFeaturesEXT(reinterpret_cast<VkPhysicalDeviceDepthClipEnableFeaturesEXT *>(curExtension));
608 			break;
609 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ZERO_INITIALIZE_WORKGROUP_MEMORY_FEATURES:
610 			getPhysicalDeviceZeroInitializeWorkgroupMemoryFeatures(reinterpret_cast<VkPhysicalDeviceZeroInitializeWorkgroupMemoryFeatures *>(curExtension));
611 			break;
612 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_FEATURES_EXT:
613 			getPhysicalDeviceCustomBorderColorFeaturesEXT(reinterpret_cast<VkPhysicalDeviceCustomBorderColorFeaturesEXT *>(curExtension));
614 			break;
615 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_FEATURES_EXT:
616 			getPhysicalDeviceBlendOperationAdvancedFeaturesEXT(reinterpret_cast<VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT *>(curExtension));
617 			break;
618 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_FEATURES_EXT:
619 			getPhysicalDeviceExtendedDynamicStateFeaturesEXT(reinterpret_cast<VkPhysicalDeviceExtendedDynamicStateFeaturesEXT *>(curExtension));
620 			break;
621 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_INPUT_DYNAMIC_STATE_FEATURES_EXT:
622 			getPhysicalDeviceVertexInputDynamicStateFeaturesEXT(reinterpret_cast<VkPhysicalDeviceVertexInputDynamicStateFeaturesEXT *>(curExtension));
623 			break;
624 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRIVATE_DATA_FEATURES:
625 			getPhysicalDevicePrivateDataFeatures(reinterpret_cast<VkPhysicalDevicePrivateDataFeatures *>(curExtension));
626 			break;
627 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TEXTURE_COMPRESSION_ASTC_HDR_FEATURES:
628 			getPhysicalDeviceTextureCompressionASTCHDRFeatures(reinterpret_cast<VkPhysicalDeviceTextureCompressionASTCHDRFeatures *>(curExtension));
629 			break;
630 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DEMOTE_TO_HELPER_INVOCATION_FEATURES:
631 			getPhysicalDeviceShaderDemoteToHelperInvocationFeatures(reinterpret_cast<VkPhysicalDeviceShaderDemoteToHelperInvocationFeatures *>(curExtension));
632 			break;
633 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_TERMINATE_INVOCATION_FEATURES:
634 			getPhysicalDeviceShaderTerminateInvocationFeatures(reinterpret_cast<VkPhysicalDeviceShaderTerminateInvocationFeatures *>(curExtension));
635 			break;
636 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_FEATURES:
637 			getPhysicalDeviceSubgroupSizeControlFeatures(reinterpret_cast<VkPhysicalDeviceSubgroupSizeControlFeatures *>(curExtension));
638 			break;
639 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_FEATURES:
640 			getPhysicalDeviceInlineUniformBlockFeatures(reinterpret_cast<VkPhysicalDeviceInlineUniformBlockFeatures *>(curExtension));
641 			break;
642 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_4444_FORMATS_FEATURES_EXT:
643 			getPhysicalDevice4444FormatsFeaturesEXT(reinterpret_cast<struct VkPhysicalDevice4444FormatsFeaturesEXT *>(curExtension));
644 			break;
645 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SYNCHRONIZATION_2_FEATURES:
646 			getPhysicalDeviceSynchronization2Features(reinterpret_cast<struct VkPhysicalDeviceSynchronization2Features *>(curExtension));
647 			break;
648 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_INTEGER_DOT_PRODUCT_FEATURES:
649 			getPhysicalDeviceShaderIntegerDotProductFeatures(reinterpret_cast<struct VkPhysicalDeviceShaderIntegerDotProductFeatures *>(curExtension));
650 			break;
651 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_4_FEATURES:
652 			getPhysicalDeviceMaintenance4Features(reinterpret_cast<struct VkPhysicalDeviceMaintenance4Features *>(curExtension));
653 			break;
654 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRIMITIVE_TOPOLOGY_LIST_RESTART_FEATURES_EXT:
655 			getPhysicalDevicePrimitiveTopologyListRestartFeatures(reinterpret_cast<struct VkPhysicalDevicePrimitiveTopologyListRestartFeaturesEXT *>(curExtension));
656 			break;
657 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_ROBUSTNESS_FEATURES_EXT:
658 			getPhysicalDevicePipelineRobustnessFeatures(reinterpret_cast<struct VkPhysicalDevicePipelineRobustnessFeaturesEXT *>(curExtension));
659 			break;
660 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RASTERIZATION_ORDER_ATTACHMENT_ACCESS_FEATURES_EXT:
661 			getPhysicalDeviceRasterizationOrderAttachmentAccessFeaturesEXT(reinterpret_cast<struct VkPhysicalDeviceRasterizationOrderAttachmentAccessFeaturesEXT *>(curExtension));
662 			break;
663 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GLOBAL_PRIORITY_QUERY_FEATURES_KHR:
664 			getPhysicalDeviceGlobalPriorityQueryFeatures(reinterpret_cast<struct VkPhysicalDeviceGlobalPriorityQueryFeaturesKHR *>(curExtension));
665 			break;
666 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_CONTROL_FEATURES_EXT:
667 			getPhysicalDeviceDepthClipControlFeaturesExt(reinterpret_cast<struct VkPhysicalDeviceDepthClipControlFeaturesEXT *>(curExtension));
668 			break;
669 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GRAPHICS_PIPELINE_LIBRARY_FEATURES_EXT:
670 			getPhysicalDeviceGraphicsPipelineLibraryFeatures(reinterpret_cast<struct VkPhysicalDeviceGraphicsPipelineLibraryFeaturesEXT *>(curExtension));
671 			break;
672 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SWAPCHAIN_MAINTENANCE_1_FEATURES_EXT:
673 			getPhysicalDeviceSwapchainMaintenance1FeaturesKHR(reinterpret_cast<struct VkPhysicalDeviceSwapchainMaintenance1FeaturesEXT *>(curExtension));
674 			break;
675 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_IMAGE_COPY_FEATURES_EXT:
676 			getPhysicalDeviceHostImageCopyFeatures(reinterpret_cast<struct VkPhysicalDeviceHostImageCopyFeaturesEXT *>(curExtension));
677 			break;
678 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT:
679 			getPhysicalDeviceIndexTypeUint8Features(reinterpret_cast<VkPhysicalDeviceIndexTypeUint8FeaturesEXT *>(curExtension));
680 			break;
681 		case VK_STRUCTURE_TYPE_MAX_ENUM:  // TODO(b/176893525): This may not be legal. dEQP tests that this value is ignored.
682 			break;
683 		default:
684 			UNSUPPORTED("curExtension->sType: %s", vk::Stringify(curExtension->sType).c_str());
685 			break;
686 		}
687 		curExtension = reinterpret_cast<VkBaseOutStructure *>(curExtension->pNext);
688 	}
689 }
690 
getSampleCounts()691 VkSampleCountFlags PhysicalDevice::getSampleCounts()
692 {
693 	return VK_SAMPLE_COUNT_1_BIT | VK_SAMPLE_COUNT_4_BIT;
694 }
695 
getLimits()696 const VkPhysicalDeviceLimits &PhysicalDevice::getLimits()
697 {
698 	VkSampleCountFlags sampleCounts = getSampleCounts();
699 
700 	static const VkPhysicalDeviceLimits limits = {
701 		1 << (vk::MAX_IMAGE_LEVELS_1D - 1),          // maxImageDimension1D
702 		1 << (vk::MAX_IMAGE_LEVELS_2D - 1),          // maxImageDimension2D
703 		1 << (vk::MAX_IMAGE_LEVELS_3D - 1),          // maxImageDimension3D
704 		1 << (vk::MAX_IMAGE_LEVELS_CUBE - 1),        // maxImageDimensionCube
705 		vk::MAX_IMAGE_ARRAY_LAYERS,                  // maxImageArrayLayers
706 		65536,                                       // maxTexelBufferElements
707 		65536,                                       // maxUniformBufferRange
708 		vk::MAX_MEMORY_ALLOCATION_SIZE,              // maxStorageBufferRange
709 		vk::MAX_PUSH_CONSTANT_SIZE,                  // maxPushConstantsSize
710 		4096,                                        // maxMemoryAllocationCount
711 		vk::MAX_SAMPLER_ALLOCATION_COUNT,            // maxSamplerAllocationCount
712 		4096,                                        // bufferImageGranularity
713 		0,                                           // sparseAddressSpaceSize (unsupported)
714 		MAX_BOUND_DESCRIPTOR_SETS,                   // maxBoundDescriptorSets
715 		64,                                          // maxPerStageDescriptorSamplers
716 		15,                                          // maxPerStageDescriptorUniformBuffers
717 		30,                                          // maxPerStageDescriptorStorageBuffers
718 		200,                                         // maxPerStageDescriptorSampledImages
719 		16,                                          // maxPerStageDescriptorStorageImages
720 		sw::MAX_COLOR_BUFFERS,                       // maxPerStageDescriptorInputAttachments
721 		200,                                         // maxPerStageResources
722 		576,                                         // maxDescriptorSetSamplers
723 		90,                                          // maxDescriptorSetUniformBuffers
724 		MAX_DESCRIPTOR_SET_UNIFORM_BUFFERS_DYNAMIC,  // maxDescriptorSetUniformBuffersDynamic
725 		96,                                          // maxDescriptorSetStorageBuffers
726 		MAX_DESCRIPTOR_SET_STORAGE_BUFFERS_DYNAMIC,  // maxDescriptorSetStorageBuffersDynamic
727 		1800,                                        // maxDescriptorSetSampledImages
728 		144,                                         // maxDescriptorSetStorageImages
729 		sw::MAX_COLOR_BUFFERS,                       // maxDescriptorSetInputAttachments
730 		16,                                          // maxVertexInputAttributes
731 		vk::MAX_VERTEX_INPUT_BINDINGS,               // maxVertexInputBindings
732 		2047,                                        // maxVertexInputAttributeOffset
733 		2048,                                        // maxVertexInputBindingStride
734 		sw::MAX_INTERFACE_COMPONENTS,                // maxVertexOutputComponents
735 		0,                                           // maxTessellationGenerationLevel (unsupported)
736 		0,                                           // maxTessellationPatchSize (unsupported)
737 		0,                                           // maxTessellationControlPerVertexInputComponents (unsupported)
738 		0,                                           // maxTessellationControlPerVertexOutputComponents (unsupported)
739 		0,                                           // maxTessellationControlPerPatchOutputComponents (unsupported)
740 		0,                                           // maxTessellationControlTotalOutputComponents (unsupported)
741 		0,                                           // maxTessellationEvaluationInputComponents (unsupported)
742 		0,                                           // maxTessellationEvaluationOutputComponents (unsupported)
743 		0,                                           // maxGeometryShaderInvocations (unsupported)
744 		0,                                           // maxGeometryInputComponents (unsupported)
745 		0,                                           // maxGeometryOutputComponents (unsupported)
746 		0,                                           // maxGeometryOutputVertices (unsupported)
747 		0,                                           // maxGeometryTotalOutputComponents (unsupported)
748 		sw::MAX_INTERFACE_COMPONENTS,                // maxFragmentInputComponents
749 		sw::MAX_COLOR_BUFFERS,                       // maxFragmentOutputAttachments
750 		1,                                           // maxFragmentDualSrcAttachments
751 		28,                                          // maxFragmentCombinedOutputResources
752 		32768,                                       // maxComputeSharedMemorySize
753 		{ 65535, 65535, 65535 },                     // maxComputeWorkGroupCount[3]
754 		vk::MAX_COMPUTE_WORKGROUP_INVOCATIONS,       // maxComputeWorkGroupInvocations
755 		{ 256, 256, 64 },                            // maxComputeWorkGroupSize[3]
756 		vk::SUBPIXEL_PRECISION_BITS,                 // subPixelPrecisionBits
757 		8,                                           // subTexelPrecisionBits
758 		6,                                           // mipmapPrecisionBits
759 		UINT32_MAX,                                  // maxDrawIndexedIndexValue
760 		UINT32_MAX,                                  // maxDrawIndirectCount
761 		vk::MAX_SAMPLER_LOD_BIAS,                    // maxSamplerLodBias
762 		16,                                          // maxSamplerAnisotropy
763 		MAX_VIEWPORTS,                               // maxViewports
764 		{ sw::MAX_VIEWPORT_DIM,
765 		  sw::MAX_VIEWPORT_DIM },  // maxViewportDimensions[2]
766 		{ -2 * sw::MAX_VIEWPORT_DIM,
767 		  2 * sw::MAX_VIEWPORT_DIM - 1 },                 // viewportBoundsRange[2]
768 		0,                                                // viewportSubPixelBits
769 		vk::MIN_MEMORY_MAP_ALIGNMENT,                     // minMemoryMapAlignment
770 		vk::MIN_TEXEL_BUFFER_OFFSET_ALIGNMENT,            // minTexelBufferOffsetAlignment
771 		vk::MIN_UNIFORM_BUFFER_OFFSET_ALIGNMENT,          // minUniformBufferOffsetAlignment
772 		vk::MIN_STORAGE_BUFFER_OFFSET_ALIGNMENT,          // minStorageBufferOffsetAlignment
773 		sw::MIN_TEXEL_OFFSET,                             // minTexelOffset
774 		sw::MAX_TEXEL_OFFSET,                             // maxTexelOffset
775 		sw::MIN_TEXEL_OFFSET,                             // minTexelGatherOffset
776 		sw::MAX_TEXEL_OFFSET,                             // maxTexelGatherOffset
777 		-0.5,                                             // minInterpolationOffset
778 		0.5,                                              // maxInterpolationOffset
779 		4,                                                // subPixelInterpolationOffsetBits
780 		sw::MAX_FRAMEBUFFER_DIM,                          // maxFramebufferWidth
781 		sw::MAX_FRAMEBUFFER_DIM,                          // maxFramebufferHeight
782 		256,                                              // maxFramebufferLayers
783 		sampleCounts,                                     // framebufferColorSampleCounts
784 		sampleCounts,                                     // framebufferDepthSampleCounts
785 		sampleCounts,                                     // framebufferStencilSampleCounts
786 		sampleCounts,                                     // framebufferNoAttachmentsSampleCounts
787 		sw::MAX_COLOR_BUFFERS,                            // maxColorAttachments
788 		sampleCounts,                                     // sampledImageColorSampleCounts
789 		sampleCounts,                                     // sampledImageIntegerSampleCounts
790 		sampleCounts,                                     // sampledImageDepthSampleCounts
791 		sampleCounts,                                     // sampledImageStencilSampleCounts
792 		sampleCounts,                                     // storageImageSampleCounts
793 		1,                                                // maxSampleMaskWords
794 		VK_TRUE,                                          // timestampComputeAndGraphics
795 		1,                                                // timestampPeriod
796 		sw::MAX_CLIP_DISTANCES,                           // maxClipDistances
797 		sw::MAX_CULL_DISTANCES,                           // maxCullDistances
798 		sw::MAX_CLIP_DISTANCES + sw::MAX_CULL_DISTANCES,  // maxCombinedClipAndCullDistances
799 		2,                                                // discreteQueuePriorities
800 		{ 1.0, vk::MAX_POINT_SIZE },                      // pointSizeRange[2]
801 		{ 1.0, 1.0 },                                     // lineWidthRange[2] (unsupported)
802 		0.0,                                              // pointSizeGranularity (unsupported)
803 		0.0,                                              // lineWidthGranularity (unsupported)
804 		VK_TRUE,                                          // strictLines
805 		VK_TRUE,                                          // standardSampleLocations
806 		64,                                               // optimalBufferCopyOffsetAlignment
807 		64,                                               // optimalBufferCopyRowPitchAlignment
808 		256,                                              // nonCoherentAtomSize
809 	};
810 
811 	return limits;
812 }
813 
getProperties() const814 const VkPhysicalDeviceProperties &PhysicalDevice::getProperties() const
815 {
816 	auto getProperties = [&]() -> VkPhysicalDeviceProperties {
817 		VkPhysicalDeviceProperties properties = {
818 			API_VERSION,
819 			DRIVER_VERSION,
820 			VENDOR_ID,
821 			DEVICE_ID,
822 			VK_PHYSICAL_DEVICE_TYPE_CPU,  // deviceType
823 			"",                           // deviceName
824 			SWIFTSHADER_UUID,             // pipelineCacheUUID
825 			getLimits(),                  // limits
826 			{}                            // sparseProperties
827 		};
828 
829 		// Append Reactor JIT backend name and version
830 		snprintf(properties.deviceName, VK_MAX_PHYSICAL_DEVICE_NAME_SIZE,
831 		         "%s (%s)", SWIFTSHADER_DEVICE_NAME, rr::Caps::backendName().c_str());
832 
833 		return properties;
834 	};
835 
836 	static const VkPhysicalDeviceProperties properties = getProperties();
837 	return properties;
838 }
839 
840 template<typename T>
getIdProperties(T * properties)841 static void getIdProperties(T *properties)
842 {
843 	memset(properties->deviceUUID, 0, VK_UUID_SIZE);
844 	memset(properties->driverUUID, 0, VK_UUID_SIZE);
845 	memset(properties->deviceLUID, 0, VK_LUID_SIZE);
846 
847 	memcpy(properties->deviceUUID, SWIFTSHADER_UUID, VK_UUID_SIZE);
848 	*((uint64_t *)properties->driverUUID) = DRIVER_VERSION;
849 
850 	properties->deviceNodeMask = 0;
851 	properties->deviceLUIDValid = VK_FALSE;
852 }
853 
getProperties(VkPhysicalDeviceIDProperties * properties) const854 void PhysicalDevice::getProperties(VkPhysicalDeviceIDProperties *properties) const
855 {
856 	getIdProperties(properties);
857 }
858 
859 template<typename T>
getMaintenance3Properties(T * properties)860 static void getMaintenance3Properties(T *properties)
861 {
862 	properties->maxMemoryAllocationSize = MAX_MEMORY_ALLOCATION_SIZE;
863 	properties->maxPerSetDescriptors = 1024;
864 }
865 
866 template<typename T>
getMaintenance4Properties(T * properties)867 static void getMaintenance4Properties(T *properties)
868 {
869 	properties->maxBufferSize = MAX_MEMORY_ALLOCATION_SIZE;
870 }
871 
getProperties(VkPhysicalDeviceMaintenance3Properties * properties) const872 void PhysicalDevice::getProperties(VkPhysicalDeviceMaintenance3Properties *properties) const
873 {
874 	getMaintenance3Properties(properties);
875 }
876 
getProperties(VkPhysicalDeviceMaintenance4Properties * properties) const877 void PhysicalDevice::getProperties(VkPhysicalDeviceMaintenance4Properties *properties) const
878 {
879 	getMaintenance4Properties(properties);
880 }
881 
882 template<typename T>
getMultiviewProperties(T * properties)883 static void getMultiviewProperties(T *properties)
884 {
885 	properties->maxMultiviewViewCount = 6;
886 	properties->maxMultiviewInstanceIndex = 1u << 27;
887 }
888 
getProperties(VkPhysicalDeviceMultiviewProperties * properties) const889 void PhysicalDevice::getProperties(VkPhysicalDeviceMultiviewProperties *properties) const
890 {
891 	getMultiviewProperties(properties);
892 }
893 
894 template<typename T>
getPointClippingProperties(T * properties)895 static void getPointClippingProperties(T *properties)
896 {
897 	properties->pointClippingBehavior = VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES;
898 }
899 
getProperties(VkPhysicalDevicePointClippingProperties * properties) const900 void PhysicalDevice::getProperties(VkPhysicalDevicePointClippingProperties *properties) const
901 {
902 	getPointClippingProperties(properties);
903 }
904 
905 template<typename T>
getProtectedMemoryProperties(T * properties)906 static void getProtectedMemoryProperties(T *properties)
907 {
908 	properties->protectedNoFault = VK_FALSE;
909 }
910 
getProperties(VkPhysicalDeviceProtectedMemoryProperties * properties) const911 void PhysicalDevice::getProperties(VkPhysicalDeviceProtectedMemoryProperties *properties) const
912 {
913 	getProtectedMemoryProperties(properties);
914 }
915 
916 template<typename T>
getSubgroupProperties(T * properties)917 static void getSubgroupProperties(T *properties)
918 {
919 	properties->subgroupSize = sw::SIMD::Width;
920 	properties->supportedStages = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT | VK_SHADER_STAGE_COMPUTE_BIT;
921 	properties->supportedOperations =
922 	    VK_SUBGROUP_FEATURE_BASIC_BIT |
923 	    VK_SUBGROUP_FEATURE_VOTE_BIT |
924 	    VK_SUBGROUP_FEATURE_ARITHMETIC_BIT |
925 	    VK_SUBGROUP_FEATURE_BALLOT_BIT |
926 	    VK_SUBGROUP_FEATURE_SHUFFLE_BIT |
927 	    VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT |
928 	    VK_SUBGROUP_FEATURE_QUAD_BIT;
929 	properties->quadOperationsInAllStages = VK_FALSE;
930 }
931 
getProperties(VkPhysicalDeviceSubgroupProperties * properties) const932 void PhysicalDevice::getProperties(VkPhysicalDeviceSubgroupProperties *properties) const
933 {
934 	getSubgroupProperties(properties);
935 }
936 
getProperties(VkPhysicalDeviceVulkan11Properties * properties) const937 void PhysicalDevice::getProperties(VkPhysicalDeviceVulkan11Properties *properties) const
938 {
939 	getIdProperties(properties);
940 
941 	// We can't use templated functions for Vulkan11 & subgroup properties. The names of the
942 	// variables in VkPhysicalDeviceSubgroupProperties differ from the names in the Vulkan11
943 	// struct.
944 	VkPhysicalDeviceSubgroupProperties subgroupProperties = {};
945 	getProperties(&subgroupProperties);
946 	properties->subgroupSize = subgroupProperties.subgroupSize;
947 	properties->subgroupSupportedStages = subgroupProperties.supportedStages;
948 	properties->subgroupSupportedOperations = subgroupProperties.supportedOperations;
949 	properties->subgroupQuadOperationsInAllStages = subgroupProperties.quadOperationsInAllStages;
950 
951 	getPointClippingProperties(properties);
952 	getMultiviewProperties(properties);
953 	getProtectedMemoryProperties(properties);
954 	getMaintenance3Properties(properties);
955 }
956 
getProperties(const VkExternalMemoryHandleTypeFlagBits * handleType,VkExternalImageFormatProperties * properties) const957 void PhysicalDevice::getProperties(const VkExternalMemoryHandleTypeFlagBits *handleType, VkExternalImageFormatProperties *properties) const
958 {
959 	VkExternalMemoryProperties *extMemProperties = &properties->externalMemoryProperties;
960 #if SWIFTSHADER_EXTERNAL_MEMORY_OPAQUE_FD
961 	if(*handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT)
962 	{
963 		extMemProperties->compatibleHandleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT;
964 		extMemProperties->exportFromImportedHandleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT;
965 		extMemProperties->externalMemoryFeatures = VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT | VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT;
966 		return;
967 	}
968 #endif
969 #if SWIFTSHADER_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER
970 	if(*handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID)
971 	{
972 		extMemProperties->compatibleHandleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID;
973 		extMemProperties->exportFromImportedHandleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID;
974 		extMemProperties->externalMemoryFeatures = VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT | VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT | VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT;
975 		return;
976 	}
977 #endif
978 #if VK_USE_PLATFORM_FUCHSIA
979 	if(*handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_ZIRCON_VMO_BIT_FUCHSIA)
980 	{
981 		extMemProperties->compatibleHandleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ZIRCON_VMO_BIT_FUCHSIA;
982 		extMemProperties->exportFromImportedHandleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ZIRCON_VMO_BIT_FUCHSIA;
983 		extMemProperties->externalMemoryFeatures = VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT | VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT;
984 		return;
985 	}
986 #endif
987 	extMemProperties->compatibleHandleTypes = 0;
988 	extMemProperties->exportFromImportedHandleTypes = 0;
989 	extMemProperties->externalMemoryFeatures = 0;
990 }
991 
getProperties(const VkExternalMemoryHandleTypeFlagBits * handleType,VkExternalBufferProperties * properties) const992 void PhysicalDevice::getProperties(const VkExternalMemoryHandleTypeFlagBits *handleType, VkExternalBufferProperties *properties) const
993 {
994 	VkExternalMemoryProperties *extMemProperties = &properties->externalMemoryProperties;
995 #if SWIFTSHADER_EXTERNAL_MEMORY_OPAQUE_FD
996 	if(*handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT)
997 	{
998 		extMemProperties->compatibleHandleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT;
999 		extMemProperties->exportFromImportedHandleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT;
1000 		extMemProperties->externalMemoryFeatures = VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT | VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT;
1001 		return;
1002 	}
1003 #endif
1004 #if SWIFTSHADER_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER
1005 	if(*handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID)
1006 	{
1007 		extMemProperties->compatibleHandleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID;
1008 		extMemProperties->exportFromImportedHandleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID;
1009 		extMemProperties->externalMemoryFeatures = VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT | VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT;
1010 		return;
1011 	}
1012 #endif
1013 #if VK_USE_PLATFORM_FUCHSIA
1014 	if(*handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_ZIRCON_VMO_BIT_FUCHSIA)
1015 	{
1016 		extMemProperties->compatibleHandleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ZIRCON_VMO_BIT_FUCHSIA;
1017 		extMemProperties->exportFromImportedHandleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ZIRCON_VMO_BIT_FUCHSIA;
1018 		extMemProperties->externalMemoryFeatures = VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT | VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT;
1019 		return;
1020 	}
1021 #endif
1022 	extMemProperties->compatibleHandleTypes = 0;
1023 	extMemProperties->exportFromImportedHandleTypes = 0;
1024 	extMemProperties->externalMemoryFeatures = 0;
1025 }
1026 
getProperties(VkSamplerYcbcrConversionImageFormatProperties * properties) const1027 void PhysicalDevice::getProperties(VkSamplerYcbcrConversionImageFormatProperties *properties) const
1028 {
1029 	properties->combinedImageSamplerDescriptorCount = 1;  // Need only one descriptor for YCbCr sampling.
1030 }
1031 
1032 #ifdef __ANDROID__
getProperties(VkPhysicalDevicePresentationPropertiesANDROID * properties) const1033 void PhysicalDevice::getProperties(VkPhysicalDevicePresentationPropertiesANDROID *properties) const
1034 {
1035 	properties->sharedImage = VK_FALSE;
1036 }
1037 
getProperties(const VkPhysicalDeviceImageFormatInfo2 * pImageFormatInfo,VkAndroidHardwareBufferUsageANDROID * ahbProperties) const1038 void PhysicalDevice::getProperties(const VkPhysicalDeviceImageFormatInfo2 *pImageFormatInfo, VkAndroidHardwareBufferUsageANDROID *ahbProperties) const
1039 {
1040 	// Maps VkImageUsageFlags to AHB usage flags using this table from the Vulkan spec
1041 	// https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#memory-external-android-hardware-buffer-usage
1042 
1043 	// VK_IMAGE_CREATE_PROTECTED_BIT not currently supported.
1044 	ASSERT((pImageFormatInfo->flags & VK_IMAGE_CREATE_PROTECTED_BIT) == 0);
1045 
1046 	// "It must include at least one GPU usage flag (AHARDWAREBUFFER_USAGE_GPU_*), even if none of the corresponding Vulkan usages or flags are requested."
1047 	uint64_t ahbUsage = AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE;
1048 
1049 	// Already covered by the default GPU usage flag above.
1050 	//
1051 	// if ((vkUsageFlags & VK_IMAGE_USAGE_SAMPLED_BIT) || (vkUsageFlags & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT))
1052 	// {
1053 	// 	 ahbUsage |= AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE;
1054 	// }
1055 
1056 	if((pImageFormatInfo->usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) || (pImageFormatInfo->usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT))
1057 	{
1058 		ahbUsage |= AHARDWAREBUFFER_USAGE_GPU_FRAMEBUFFER;
1059 	}
1060 
1061 	if(pImageFormatInfo->flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT)
1062 	{
1063 		ahbUsage |= AHARDWAREBUFFER_USAGE_GPU_CUBE_MAP;
1064 	}
1065 
1066 	if(pImageFormatInfo->flags & VK_IMAGE_CREATE_PROTECTED_BIT)
1067 	{
1068 		ahbUsage |= AHARDWAREBUFFER_USAGE_PROTECTED_CONTENT;
1069 	}
1070 
1071 	ahbProperties->androidHardwareBufferUsage = ahbUsage;
1072 }
1073 #endif
1074 
getProperties(const VkPhysicalDeviceExternalBufferInfo * pExternalBufferInfo,VkExternalBufferProperties * pExternalBufferProperties) const1075 void PhysicalDevice::getProperties(const VkPhysicalDeviceExternalBufferInfo *pExternalBufferInfo, VkExternalBufferProperties *pExternalBufferProperties) const
1076 {
1077 	VkExternalMemoryProperties *properties = &pExternalBufferProperties->externalMemoryProperties;
1078 
1079 #if SWIFTSHADER_EXTERNAL_MEMORY_OPAQUE_FD || SWIFTSHADER_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER
1080 	const VkExternalMemoryHandleTypeFlagBits *handleType = &pExternalBufferInfo->handleType;
1081 #endif
1082 
1083 #if SWIFTSHADER_EXTERNAL_MEMORY_OPAQUE_FD
1084 	if(*handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT)
1085 	{
1086 		properties->compatibleHandleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT;
1087 		properties->exportFromImportedHandleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT;
1088 		properties->externalMemoryFeatures = VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT | VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT;
1089 		return;
1090 	}
1091 #endif
1092 #if SWIFTSHADER_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER
1093 	if(*handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID)
1094 	{
1095 		properties->compatibleHandleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID;
1096 		properties->exportFromImportedHandleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID;
1097 		properties->externalMemoryFeatures = VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT | VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT;
1098 		return;
1099 	}
1100 #endif
1101 	properties->compatibleHandleTypes = 0;
1102 	properties->exportFromImportedHandleTypes = 0;
1103 	properties->externalMemoryFeatures = 0;
1104 }
1105 
getProperties(const VkPhysicalDeviceExternalFenceInfo * pExternalFenceInfo,VkExternalFenceProperties * pExternalFenceProperties) const1106 void PhysicalDevice::getProperties(const VkPhysicalDeviceExternalFenceInfo *pExternalFenceInfo, VkExternalFenceProperties *pExternalFenceProperties) const
1107 {
1108 	pExternalFenceProperties->compatibleHandleTypes = 0;
1109 	pExternalFenceProperties->exportFromImportedHandleTypes = 0;
1110 	pExternalFenceProperties->externalFenceFeatures = 0;
1111 }
1112 
getProperties(const VkPhysicalDeviceExternalSemaphoreInfo * pExternalSemaphoreInfo,VkExternalSemaphoreProperties * pExternalSemaphoreProperties) const1113 void PhysicalDevice::getProperties(const VkPhysicalDeviceExternalSemaphoreInfo *pExternalSemaphoreInfo, VkExternalSemaphoreProperties *pExternalSemaphoreProperties) const
1114 {
1115 	for(const auto *nextInfo = reinterpret_cast<const VkBaseInStructure *>(pExternalSemaphoreInfo->pNext);
1116 	    nextInfo != nullptr; nextInfo = nextInfo->pNext)
1117 	{
1118 		switch(nextInfo->sType)
1119 		{
1120 		case VK_STRUCTURE_TYPE_SEMAPHORE_TYPE_CREATE_INFO:
1121 			{
1122 				const auto *tlsInfo = reinterpret_cast<const VkSemaphoreTypeCreateInfo *>(nextInfo);
1123 				// Timeline Semaphore does not support external semaphore
1124 				if(tlsInfo->semaphoreType == VK_SEMAPHORE_TYPE_TIMELINE)
1125 				{
1126 					pExternalSemaphoreProperties->compatibleHandleTypes = 0;
1127 					pExternalSemaphoreProperties->exportFromImportedHandleTypes = 0;
1128 					pExternalSemaphoreProperties->externalSemaphoreFeatures = 0;
1129 					return;
1130 				}
1131 			}
1132 			break;
1133 		default:
1134 			WARN("nextInfo->sType = %s", vk::Stringify(nextInfo->sType).c_str());
1135 			break;
1136 		}
1137 	}
1138 
1139 #if SWIFTSHADER_EXTERNAL_SEMAPHORE_OPAQUE_FD
1140 	if(pExternalSemaphoreInfo->handleType == VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT)
1141 	{
1142 		pExternalSemaphoreProperties->compatibleHandleTypes = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT;
1143 		pExternalSemaphoreProperties->exportFromImportedHandleTypes = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT;
1144 		pExternalSemaphoreProperties->externalSemaphoreFeatures = VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT | VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT;
1145 		return;
1146 	}
1147 #endif
1148 #if VK_USE_PLATFORM_FUCHSIA
1149 	if(pExternalSemaphoreInfo->handleType == VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_ZIRCON_EVENT_BIT_FUCHSIA)
1150 	{
1151 		pExternalSemaphoreProperties->compatibleHandleTypes = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_ZIRCON_EVENT_BIT_FUCHSIA;
1152 		pExternalSemaphoreProperties->exportFromImportedHandleTypes = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_ZIRCON_EVENT_BIT_FUCHSIA;
1153 		pExternalSemaphoreProperties->externalSemaphoreFeatures = VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT | VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT;
1154 		return;
1155 	}
1156 #endif
1157 	pExternalSemaphoreProperties->compatibleHandleTypes = 0;
1158 	pExternalSemaphoreProperties->exportFromImportedHandleTypes = 0;
1159 	pExternalSemaphoreProperties->externalSemaphoreFeatures = 0;
1160 }
1161 
getProperties(VkPhysicalDeviceExternalMemoryHostPropertiesEXT * properties) const1162 void PhysicalDevice::getProperties(VkPhysicalDeviceExternalMemoryHostPropertiesEXT *properties) const
1163 {
1164 	properties->minImportedHostPointerAlignment = vk::MIN_IMPORTED_HOST_POINTER_ALIGNMENT;
1165 }
1166 
1167 template<typename T>
getDriverProperties(T * properties)1168 static void getDriverProperties(T *properties)
1169 {
1170 	properties->driverID = VK_DRIVER_ID_GOOGLE_SWIFTSHADER_KHR;
1171 	strcpy(properties->driverName, "SwiftShader driver");
1172 	strcpy(properties->driverInfo, "");
1173 	properties->conformanceVersion = { 1, 3, 3, 1 };
1174 }
1175 
getProperties(VkPhysicalDeviceDriverProperties * properties) const1176 void PhysicalDevice::getProperties(VkPhysicalDeviceDriverProperties *properties) const
1177 {
1178 	getDriverProperties(properties);
1179 }
1180 
getProperties(VkPhysicalDeviceLineRasterizationPropertiesEXT * properties) const1181 void PhysicalDevice::getProperties(VkPhysicalDeviceLineRasterizationPropertiesEXT *properties) const
1182 {
1183 	properties->lineSubPixelPrecisionBits = vk::SUBPIXEL_PRECISION_BITS;
1184 }
1185 
getProperties(VkPhysicalDeviceProvokingVertexPropertiesEXT * properties) const1186 void PhysicalDevice::getProperties(VkPhysicalDeviceProvokingVertexPropertiesEXT *properties) const
1187 {
1188 	properties->provokingVertexModePerPipeline = VK_TRUE;
1189 }
1190 
1191 template<typename T>
getFloatControlsProperties(T * properties)1192 static void getFloatControlsProperties(T *properties)
1193 {
1194 	// The spec states:
1195 	// shaderSignedZeroInfNanPreserveFloat32 is a boolean value indicating whether
1196 	// sign of a zero, Nans and +/-infinity can be preserved in 32-bit floating-point
1197 	// computations. It also indicates whether the SignedZeroInfNanPreserve execution
1198 	// mode can be used for 32-bit floating-point types.
1199 	//
1200 	// There are similar clauses for all the shader* bools present here.
1201 	//
1202 	// It does not state that an implementation must report its default behavior using
1203 	// these variables. At this time SwiftShader does not expose any preserve, denormal,
1204 	// or rounding controls.
1205 	properties->denormBehaviorIndependence = VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_NONE;
1206 	properties->roundingModeIndependence = VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_NONE;
1207 	properties->shaderSignedZeroInfNanPreserveFloat16 = VK_TRUE;
1208 	properties->shaderSignedZeroInfNanPreserveFloat32 = VK_TRUE;
1209 	properties->shaderSignedZeroInfNanPreserveFloat64 = VK_TRUE;
1210 	properties->shaderDenormPreserveFloat16 = VK_FALSE;
1211 	properties->shaderDenormPreserveFloat32 = VK_FALSE;
1212 	properties->shaderDenormPreserveFloat64 = VK_FALSE;
1213 	properties->shaderDenormFlushToZeroFloat16 = VK_FALSE;
1214 	properties->shaderDenormFlushToZeroFloat32 = VK_FALSE;
1215 	properties->shaderDenormFlushToZeroFloat64 = VK_FALSE;
1216 	properties->shaderRoundingModeRTZFloat16 = VK_FALSE;
1217 	properties->shaderRoundingModeRTZFloat32 = VK_FALSE;
1218 	properties->shaderRoundingModeRTZFloat64 = VK_FALSE;
1219 	properties->shaderRoundingModeRTEFloat16 = VK_FALSE;
1220 	properties->shaderRoundingModeRTEFloat32 = VK_FALSE;
1221 	properties->shaderRoundingModeRTEFloat64 = VK_FALSE;
1222 }
1223 
getProperties(VkPhysicalDeviceFloatControlsProperties * properties) const1224 void PhysicalDevice::getProperties(VkPhysicalDeviceFloatControlsProperties *properties) const
1225 {
1226 	getFloatControlsProperties(properties);
1227 }
1228 
1229 template<typename T>
getDescriptorIndexingProperties(T * properties)1230 static void getDescriptorIndexingProperties(T *properties)
1231 {
1232 	// "The UpdateAfterBind descriptor limits must each be greater than or equal to
1233 	//  the corresponding non-UpdateAfterBind limit."
1234 	const VkPhysicalDeviceLimits &limits = PhysicalDevice::getLimits();
1235 
1236 	// Limits from:
1237 	// https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#limits-minmax
1238 	// Table 53. Required Limits
1239 	properties->maxUpdateAfterBindDescriptorsInAllPools = vk::MAX_UPDATE_AFTER_BIND_DESCRIPTORS;
1240 	properties->shaderUniformBufferArrayNonUniformIndexingNative = VK_FALSE;
1241 	properties->shaderSampledImageArrayNonUniformIndexingNative = VK_FALSE;
1242 	properties->shaderStorageBufferArrayNonUniformIndexingNative = VK_FALSE;
1243 	properties->shaderStorageImageArrayNonUniformIndexingNative = VK_FALSE;
1244 	properties->shaderInputAttachmentArrayNonUniformIndexingNative = VK_FALSE;
1245 	properties->robustBufferAccessUpdateAfterBind = VK_FALSE;
1246 	properties->quadDivergentImplicitLod = VK_FALSE;
1247 	properties->maxPerStageDescriptorUpdateAfterBindSamplers = vk::MAX_UPDATE_AFTER_BIND_DESCRIPTORS;
1248 	properties->maxPerStageDescriptorUpdateAfterBindUniformBuffers = limits.maxPerStageDescriptorUniformBuffers;
1249 	properties->maxPerStageDescriptorUpdateAfterBindStorageBuffers = vk::MAX_UPDATE_AFTER_BIND_DESCRIPTORS;
1250 	properties->maxPerStageDescriptorUpdateAfterBindSampledImages = vk::MAX_UPDATE_AFTER_BIND_DESCRIPTORS;
1251 	properties->maxPerStageDescriptorUpdateAfterBindStorageImages = vk::MAX_UPDATE_AFTER_BIND_DESCRIPTORS;
1252 	properties->maxPerStageDescriptorUpdateAfterBindInputAttachments = limits.maxPerStageDescriptorInputAttachments;
1253 	properties->maxPerStageUpdateAfterBindResources = vk::MAX_UPDATE_AFTER_BIND_DESCRIPTORS;
1254 	properties->maxDescriptorSetUpdateAfterBindSamplers = vk::MAX_UPDATE_AFTER_BIND_DESCRIPTORS;
1255 	properties->maxDescriptorSetUpdateAfterBindUniformBuffers = limits.maxDescriptorSetUniformBuffers;
1256 	properties->maxDescriptorSetUpdateAfterBindUniformBuffersDynamic = limits.maxDescriptorSetUniformBuffersDynamic;
1257 	properties->maxDescriptorSetUpdateAfterBindStorageBuffers = vk::MAX_UPDATE_AFTER_BIND_DESCRIPTORS;
1258 	properties->maxDescriptorSetUpdateAfterBindStorageBuffersDynamic = limits.maxDescriptorSetStorageBuffersDynamic;
1259 	properties->maxDescriptorSetUpdateAfterBindSampledImages = vk::MAX_UPDATE_AFTER_BIND_DESCRIPTORS;
1260 	properties->maxDescriptorSetUpdateAfterBindStorageImages = vk::MAX_UPDATE_AFTER_BIND_DESCRIPTORS;
1261 	properties->maxDescriptorSetUpdateAfterBindInputAttachments = limits.maxDescriptorSetInputAttachments;
1262 }
1263 
getProperties(VkPhysicalDeviceDescriptorIndexingProperties * properties) const1264 void PhysicalDevice::getProperties(VkPhysicalDeviceDescriptorIndexingProperties *properties) const
1265 {
1266 	getDescriptorIndexingProperties(properties);
1267 }
1268 
1269 template<typename T>
getDepthStencilResolveProperties(T * properties)1270 static void getDepthStencilResolveProperties(T *properties)
1271 {
1272 	properties->supportedDepthResolveModes = VK_RESOLVE_MODE_SAMPLE_ZERO_BIT | VK_RESOLVE_MODE_NONE;
1273 	properties->supportedStencilResolveModes = VK_RESOLVE_MODE_SAMPLE_ZERO_BIT | VK_RESOLVE_MODE_NONE;
1274 	properties->independentResolveNone = VK_TRUE;
1275 	properties->independentResolve = VK_TRUE;
1276 }
1277 
getProperties(VkPhysicalDeviceDepthStencilResolveProperties * properties) const1278 void PhysicalDevice::getProperties(VkPhysicalDeviceDepthStencilResolveProperties *properties) const
1279 {
1280 	getDepthStencilResolveProperties(properties);
1281 }
1282 
getProperties(VkPhysicalDeviceCustomBorderColorPropertiesEXT * properties) const1283 void PhysicalDevice::getProperties(VkPhysicalDeviceCustomBorderColorPropertiesEXT *properties) const
1284 {
1285 	properties->maxCustomBorderColorSamplers = MAX_SAMPLER_ALLOCATION_COUNT;
1286 }
1287 
getProperties(VkPhysicalDeviceBlendOperationAdvancedPropertiesEXT * properties) const1288 void PhysicalDevice::getProperties(VkPhysicalDeviceBlendOperationAdvancedPropertiesEXT *properties) const
1289 {
1290 	properties->advancedBlendMaxColorAttachments = sw::MAX_COLOR_BUFFERS;
1291 	properties->advancedBlendIndependentBlend = VK_FALSE;
1292 	properties->advancedBlendNonPremultipliedSrcColor = VK_FALSE;
1293 	properties->advancedBlendNonPremultipliedDstColor = VK_FALSE;
1294 	properties->advancedBlendCorrelatedOverlap = VK_FALSE;
1295 	properties->advancedBlendAllOperations = VK_FALSE;
1296 }
1297 
1298 template<typename T>
getSubgroupSizeControlProperties(T * properties)1299 static void getSubgroupSizeControlProperties(T *properties)
1300 {
1301 	VkPhysicalDeviceSubgroupProperties subgroupProperties = {};
1302 	getSubgroupProperties(&subgroupProperties);
1303 	properties->minSubgroupSize = subgroupProperties.subgroupSize;
1304 	properties->maxSubgroupSize = subgroupProperties.subgroupSize;
1305 	properties->maxComputeWorkgroupSubgroups = vk::MAX_COMPUTE_WORKGROUP_INVOCATIONS /
1306 	                                           properties->minSubgroupSize;
1307 	properties->requiredSubgroupSizeStages = subgroupProperties.supportedStages;
1308 }
1309 
getProperties(VkPhysicalDeviceSubgroupSizeControlProperties * properties) const1310 void PhysicalDevice::getProperties(VkPhysicalDeviceSubgroupSizeControlProperties *properties) const
1311 {
1312 	getSubgroupSizeControlProperties(properties);
1313 }
1314 
1315 template<typename T>
getInlineUniformBlockProperties(T * properties)1316 static void getInlineUniformBlockProperties(T *properties)
1317 {
1318 	properties->maxInlineUniformBlockSize = MAX_INLINE_UNIFORM_BLOCK_SIZE;
1319 	properties->maxPerStageDescriptorInlineUniformBlocks = 4;
1320 	properties->maxPerStageDescriptorUpdateAfterBindInlineUniformBlocks = 4;
1321 	properties->maxDescriptorSetInlineUniformBlocks = 4;
1322 	properties->maxDescriptorSetUpdateAfterBindInlineUniformBlocks = 4;
1323 }
1324 
getProperties(VkPhysicalDeviceInlineUniformBlockProperties * properties) const1325 void PhysicalDevice::getProperties(VkPhysicalDeviceInlineUniformBlockProperties *properties) const
1326 {
1327 	getInlineUniformBlockProperties(properties);
1328 }
1329 
1330 template<typename T>
getTexelBufferAlignmentProperties(T * properties)1331 static void getTexelBufferAlignmentProperties(T *properties)
1332 {
1333 	properties->storageTexelBufferOffsetAlignmentBytes = vk::MIN_TEXEL_BUFFER_OFFSET_ALIGNMENT;
1334 	properties->storageTexelBufferOffsetSingleTexelAlignment = VK_FALSE;
1335 	properties->uniformTexelBufferOffsetAlignmentBytes = vk::MIN_TEXEL_BUFFER_OFFSET_ALIGNMENT;
1336 	properties->uniformTexelBufferOffsetSingleTexelAlignment = VK_FALSE;
1337 }
1338 
getProperties(VkPhysicalDeviceTexelBufferAlignmentProperties * properties) const1339 void PhysicalDevice::getProperties(VkPhysicalDeviceTexelBufferAlignmentProperties *properties) const
1340 {
1341 	getTexelBufferAlignmentProperties(properties);
1342 }
1343 
1344 template<typename T>
getShaderIntegerDotProductProperties(T * properties)1345 static void getShaderIntegerDotProductProperties(T *properties)
1346 {
1347 	properties->integerDotProduct8BitUnsignedAccelerated = VK_FALSE;
1348 	properties->integerDotProduct8BitSignedAccelerated = VK_FALSE;
1349 	properties->integerDotProduct8BitMixedSignednessAccelerated = VK_FALSE;
1350 	properties->integerDotProduct4x8BitPackedUnsignedAccelerated = VK_FALSE;
1351 	properties->integerDotProduct4x8BitPackedSignedAccelerated = VK_FALSE;
1352 	properties->integerDotProduct4x8BitPackedMixedSignednessAccelerated = VK_FALSE;
1353 	properties->integerDotProduct16BitUnsignedAccelerated = VK_FALSE;
1354 	properties->integerDotProduct16BitSignedAccelerated = VK_FALSE;
1355 	properties->integerDotProduct16BitMixedSignednessAccelerated = VK_FALSE;
1356 	properties->integerDotProduct32BitUnsignedAccelerated = VK_FALSE;
1357 	properties->integerDotProduct32BitSignedAccelerated = VK_FALSE;
1358 	properties->integerDotProduct32BitMixedSignednessAccelerated = VK_FALSE;
1359 	properties->integerDotProduct64BitUnsignedAccelerated = VK_FALSE;
1360 	properties->integerDotProduct64BitSignedAccelerated = VK_FALSE;
1361 	properties->integerDotProduct64BitMixedSignednessAccelerated = VK_FALSE;
1362 	properties->integerDotProductAccumulatingSaturating8BitUnsignedAccelerated = VK_FALSE;
1363 	properties->integerDotProductAccumulatingSaturating8BitSignedAccelerated = VK_FALSE;
1364 	properties->integerDotProductAccumulatingSaturating8BitMixedSignednessAccelerated = VK_FALSE;
1365 	properties->integerDotProductAccumulatingSaturating4x8BitPackedUnsignedAccelerated = VK_FALSE;
1366 	properties->integerDotProductAccumulatingSaturating4x8BitPackedSignedAccelerated = VK_FALSE;
1367 	properties->integerDotProductAccumulatingSaturating4x8BitPackedMixedSignednessAccelerated = VK_FALSE;
1368 	properties->integerDotProductAccumulatingSaturating16BitUnsignedAccelerated = VK_FALSE;
1369 	properties->integerDotProductAccumulatingSaturating16BitSignedAccelerated = VK_FALSE;
1370 	properties->integerDotProductAccumulatingSaturating16BitMixedSignednessAccelerated = VK_FALSE;
1371 	properties->integerDotProductAccumulatingSaturating32BitUnsignedAccelerated = VK_FALSE;
1372 	properties->integerDotProductAccumulatingSaturating32BitSignedAccelerated = VK_FALSE;
1373 	properties->integerDotProductAccumulatingSaturating32BitMixedSignednessAccelerated = VK_FALSE;
1374 	properties->integerDotProductAccumulatingSaturating64BitUnsignedAccelerated = VK_FALSE;
1375 	properties->integerDotProductAccumulatingSaturating64BitSignedAccelerated = VK_FALSE;
1376 	properties->integerDotProductAccumulatingSaturating64BitMixedSignednessAccelerated = VK_FALSE;
1377 }
1378 
getProperties(VkPhysicalDeviceShaderIntegerDotProductProperties * properties) const1379 void PhysicalDevice::getProperties(VkPhysicalDeviceShaderIntegerDotProductProperties *properties) const
1380 {
1381 	getShaderIntegerDotProductProperties(properties);
1382 }
1383 
1384 template<typename T>
getGraphicsPipelineLibraryProperties(T * properties)1385 static void getGraphicsPipelineLibraryProperties(T *properties)
1386 {
1387 	// Library linking is currently fast in SwiftShader, because all the pipeline creation cost
1388 	// is actually paid at draw time.
1389 	properties->graphicsPipelineLibraryFastLinking = VK_TRUE;
1390 	// TODO: check this
1391 	properties->graphicsPipelineLibraryIndependentInterpolationDecoration = VK_FALSE;
1392 }
1393 
getProperties(VkPhysicalDeviceGraphicsPipelineLibraryPropertiesEXT * properties) const1394 void PhysicalDevice::getProperties(VkPhysicalDeviceGraphicsPipelineLibraryPropertiesEXT *properties) const
1395 {
1396 	getGraphicsPipelineLibraryProperties(properties);
1397 }
1398 
1399 template<typename T>
getSamplerFilterMinmaxProperties(T * properties)1400 static void getSamplerFilterMinmaxProperties(T *properties)
1401 {
1402 	properties->filterMinmaxSingleComponentFormats = VK_FALSE;
1403 	properties->filterMinmaxImageComponentMapping = VK_FALSE;
1404 }
1405 
getProperties(VkPhysicalDeviceSamplerFilterMinmaxProperties * properties) const1406 void PhysicalDevice::getProperties(VkPhysicalDeviceSamplerFilterMinmaxProperties *properties) const
1407 {
1408 	getSamplerFilterMinmaxProperties(properties);
1409 }
1410 
1411 template<typename T>
getTimelineSemaphoreProperties(T * properties)1412 static void getTimelineSemaphoreProperties(T *properties)
1413 {
1414 	// Our implementation of Timeline Semaphores allows the timeline to advance to any value from any value.
1415 	properties->maxTimelineSemaphoreValueDifference = (uint64_t)-1;
1416 }
1417 
getProperties(VkPhysicalDeviceTimelineSemaphoreProperties * properties) const1418 void PhysicalDevice::getProperties(VkPhysicalDeviceTimelineSemaphoreProperties *properties) const
1419 {
1420 	getTimelineSemaphoreProperties(properties);
1421 }
1422 
1423 template<typename T>
getPipelineRobustnessProperties(T * properties)1424 static void getPipelineRobustnessProperties(T *properties)
1425 {
1426 	// Buffer access is not robust by default.
1427 	properties->defaultRobustnessStorageBuffers = VK_PIPELINE_ROBUSTNESS_BUFFER_BEHAVIOR_DISABLED_EXT;
1428 	properties->defaultRobustnessUniformBuffers = VK_PIPELINE_ROBUSTNESS_BUFFER_BEHAVIOR_DISABLED_EXT;
1429 	properties->defaultRobustnessVertexInputs = VK_PIPELINE_ROBUSTNESS_BUFFER_BEHAVIOR_DISABLED_EXT;
1430 	// SwiftShader currently provides robustImageAccess robustness unconditionally.
1431 	// robustImageAccess2 is not supported.
1432 	// TODO(b/162327166): Only provide robustness when requested.
1433 	properties->defaultRobustnessImages = VK_PIPELINE_ROBUSTNESS_IMAGE_BEHAVIOR_ROBUST_IMAGE_ACCESS_EXT;
1434 }
1435 
getProperties(VkPhysicalDevicePipelineRobustnessPropertiesEXT * properties) const1436 void PhysicalDevice::getProperties(VkPhysicalDevicePipelineRobustnessPropertiesEXT *properties) const
1437 {
1438 	getPipelineRobustnessProperties(properties);
1439 }
1440 
1441 template<typename T>
getHostImageCopyProperties(T * properties)1442 static void getHostImageCopyProperties(T *properties)
1443 {
1444 	// There are no image layouts in SwiftShader, so support all layouts for host image copy
1445 	constexpr VkImageLayout kAllLayouts[] = {
1446 		VK_IMAGE_LAYOUT_GENERAL,
1447 		VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
1448 		VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
1449 		VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL,
1450 		VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
1451 		VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
1452 		VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
1453 		VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL,
1454 		VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL,
1455 		VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL,
1456 		VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_OPTIMAL,
1457 		VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL,
1458 		VK_IMAGE_LAYOUT_STENCIL_READ_ONLY_OPTIMAL,
1459 		VK_IMAGE_LAYOUT_READ_ONLY_OPTIMAL,
1460 		VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL,
1461 		VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
1462 		VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR,
1463 	};
1464 	constexpr uint32_t kAllLayoutsCount = std::size(kAllLayouts);
1465 
1466 	if(properties->pCopySrcLayouts == nullptr)
1467 	{
1468 		properties->copySrcLayoutCount = kAllLayoutsCount;
1469 	}
1470 	else
1471 	{
1472 		properties->copySrcLayoutCount = std::min(properties->copySrcLayoutCount, kAllLayoutsCount);
1473 		memcpy(properties->pCopySrcLayouts, kAllLayouts, properties->copySrcLayoutCount * sizeof(*properties->pCopySrcLayouts));
1474 	}
1475 
1476 	if(properties->pCopyDstLayouts == nullptr)
1477 	{
1478 		properties->copyDstLayoutCount = kAllLayoutsCount;
1479 	}
1480 	else
1481 	{
1482 		properties->copyDstLayoutCount = std::min(properties->copyDstLayoutCount, kAllLayoutsCount);
1483 		memcpy(properties->pCopyDstLayouts, kAllLayouts, properties->copyDstLayoutCount * sizeof(*properties->pCopyDstLayouts));
1484 	}
1485 
1486 	memcpy(properties->optimalTilingLayoutUUID, SWIFTSHADER_UUID, VK_UUID_SIZE);
1487 	properties->identicalMemoryTypeRequirements = VK_TRUE;
1488 }
1489 
getProperties(VkPhysicalDeviceHostImageCopyPropertiesEXT * properties) const1490 void PhysicalDevice::getProperties(VkPhysicalDeviceHostImageCopyPropertiesEXT *properties) const
1491 {
1492 	getHostImageCopyProperties(properties);
1493 }
1494 
getProperties(VkPhysicalDeviceVulkan12Properties * properties) const1495 void PhysicalDevice::getProperties(VkPhysicalDeviceVulkan12Properties *properties) const
1496 {
1497 	getDriverProperties(properties);
1498 	getFloatControlsProperties(properties);
1499 	getDescriptorIndexingProperties(properties);
1500 	getDepthStencilResolveProperties(properties);
1501 	getSamplerFilterMinmaxProperties(properties);
1502 	getTimelineSemaphoreProperties(properties);
1503 	properties->framebufferIntegerColorSampleCounts = VK_SAMPLE_COUNT_1_BIT;
1504 }
1505 
getProperties(VkPhysicalDeviceVulkan13Properties * properties) const1506 void PhysicalDevice::getProperties(VkPhysicalDeviceVulkan13Properties *properties) const
1507 {
1508 	getSubgroupSizeControlProperties(properties);
1509 	getInlineUniformBlockProperties(properties);
1510 	properties->maxInlineUniformTotalSize = properties->maxInlineUniformBlockSize *
1511 	                                        properties->maxDescriptorSetInlineUniformBlocks;
1512 	getShaderIntegerDotProductProperties(properties);
1513 	getTexelBufferAlignmentProperties(properties);
1514 	getMaintenance4Properties(properties);
1515 }
1516 
hasFeatures(const VkPhysicalDeviceFeatures & requestedFeatures) const1517 bool PhysicalDevice::hasFeatures(const VkPhysicalDeviceFeatures &requestedFeatures) const
1518 {
1519 	const VkPhysicalDeviceFeatures &supportedFeatures = getFeatures();
1520 	const VkBool32 *supportedFeature = reinterpret_cast<const VkBool32 *>(&supportedFeatures);
1521 	const VkBool32 *requestedFeature = reinterpret_cast<const VkBool32 *>(&requestedFeatures);
1522 	constexpr auto featureCount = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
1523 
1524 	for(unsigned int i = 0; i < featureCount; i++)
1525 	{
1526 		if((requestedFeature[i] != VK_FALSE) && (supportedFeature[i] == VK_FALSE))
1527 		{
1528 			return false;
1529 		}
1530 	}
1531 
1532 	return true;
1533 }
1534 
1535 // CheckFeature returns false if requested is asking for a feature that is not supported
1536 #define CheckFeature(requested, supported, feature) (requested->feature == VK_FALSE || supported.feature == VK_TRUE)
1537 
1538 template<typename T>
getSupportedFeatures(const T * requested) const1539 T PhysicalDevice::getSupportedFeatures(const T *requested) const
1540 {
1541 	VkPhysicalDeviceFeatures2 features;
1542 	features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
1543 	T supported;
1544 	supported.sType = requested->sType;
1545 	supported.pNext = nullptr;
1546 	features.pNext = &supported;
1547 	getFeatures2(&features);
1548 	return supported;
1549 }
1550 
hasExtendedFeatures(const VkPhysicalDeviceLineRasterizationFeaturesEXT * requested) const1551 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDeviceLineRasterizationFeaturesEXT *requested) const
1552 {
1553 	auto supported = getSupportedFeatures(requested);
1554 
1555 	return CheckFeature(requested, supported, rectangularLines) &&
1556 	       CheckFeature(requested, supported, bresenhamLines) &&
1557 	       CheckFeature(requested, supported, smoothLines) &&
1558 	       CheckFeature(requested, supported, stippledRectangularLines) &&
1559 	       CheckFeature(requested, supported, stippledBresenhamLines) &&
1560 	       CheckFeature(requested, supported, stippledSmoothLines);
1561 }
1562 
hasExtendedFeatures(const VkPhysicalDeviceProvokingVertexFeaturesEXT * requested) const1563 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDeviceProvokingVertexFeaturesEXT *requested) const
1564 {
1565 	auto supported = getSupportedFeatures(requested);
1566 
1567 	return CheckFeature(requested, supported, provokingVertexLast) &&
1568 	       CheckFeature(requested, supported, transformFeedbackPreservesProvokingVertex);
1569 }
1570 
hasExtendedFeatures(const VkPhysicalDeviceVulkan11Features * requested) const1571 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDeviceVulkan11Features *requested) const
1572 {
1573 	auto supported = getSupportedFeatures(requested);
1574 
1575 	return CheckFeature(requested, supported, storageBuffer16BitAccess) &&
1576 	       CheckFeature(requested, supported, uniformAndStorageBuffer16BitAccess) &&
1577 	       CheckFeature(requested, supported, storagePushConstant16) &&
1578 	       CheckFeature(requested, supported, storageInputOutput16) &&
1579 	       CheckFeature(requested, supported, multiview) &&
1580 	       CheckFeature(requested, supported, multiviewGeometryShader) &&
1581 	       CheckFeature(requested, supported, multiviewTessellationShader) &&
1582 	       CheckFeature(requested, supported, variablePointersStorageBuffer) &&
1583 	       CheckFeature(requested, supported, variablePointers) &&
1584 	       CheckFeature(requested, supported, protectedMemory) &&
1585 	       CheckFeature(requested, supported, samplerYcbcrConversion) &&
1586 	       CheckFeature(requested, supported, shaderDrawParameters);
1587 }
1588 
hasExtendedFeatures(const VkPhysicalDeviceVulkan12Features * requested) const1589 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDeviceVulkan12Features *requested) const
1590 {
1591 	auto supported = getSupportedFeatures(requested);
1592 
1593 	return CheckFeature(requested, supported, samplerMirrorClampToEdge) &&
1594 	       CheckFeature(requested, supported, drawIndirectCount) &&
1595 	       CheckFeature(requested, supported, storageBuffer8BitAccess) &&
1596 	       CheckFeature(requested, supported, uniformAndStorageBuffer8BitAccess) &&
1597 	       CheckFeature(requested, supported, storagePushConstant8) &&
1598 	       CheckFeature(requested, supported, shaderBufferInt64Atomics) &&
1599 	       CheckFeature(requested, supported, shaderSharedInt64Atomics) &&
1600 	       CheckFeature(requested, supported, shaderFloat16) &&
1601 	       CheckFeature(requested, supported, shaderInt8) &&
1602 	       CheckFeature(requested, supported, descriptorIndexing) &&
1603 	       CheckFeature(requested, supported, shaderInputAttachmentArrayDynamicIndexing) &&
1604 	       CheckFeature(requested, supported, shaderUniformTexelBufferArrayDynamicIndexing) &&
1605 	       CheckFeature(requested, supported, shaderStorageTexelBufferArrayDynamicIndexing) &&
1606 	       CheckFeature(requested, supported, shaderUniformBufferArrayNonUniformIndexing) &&
1607 	       CheckFeature(requested, supported, shaderSampledImageArrayNonUniformIndexing) &&
1608 	       CheckFeature(requested, supported, shaderStorageBufferArrayNonUniformIndexing) &&
1609 	       CheckFeature(requested, supported, shaderStorageImageArrayNonUniformIndexing) &&
1610 	       CheckFeature(requested, supported, shaderInputAttachmentArrayNonUniformIndexing) &&
1611 	       CheckFeature(requested, supported, shaderUniformTexelBufferArrayNonUniformIndexing) &&
1612 	       CheckFeature(requested, supported, shaderStorageTexelBufferArrayNonUniformIndexing) &&
1613 	       CheckFeature(requested, supported, descriptorBindingUniformBufferUpdateAfterBind) &&
1614 	       CheckFeature(requested, supported, descriptorBindingSampledImageUpdateAfterBind) &&
1615 	       CheckFeature(requested, supported, descriptorBindingStorageImageUpdateAfterBind) &&
1616 	       CheckFeature(requested, supported, descriptorBindingStorageBufferUpdateAfterBind) &&
1617 	       CheckFeature(requested, supported, descriptorBindingUniformTexelBufferUpdateAfterBind) &&
1618 	       CheckFeature(requested, supported, descriptorBindingStorageTexelBufferUpdateAfterBind) &&
1619 	       CheckFeature(requested, supported, descriptorBindingUpdateUnusedWhilePending) &&
1620 	       CheckFeature(requested, supported, descriptorBindingPartiallyBound) &&
1621 	       CheckFeature(requested, supported, descriptorBindingVariableDescriptorCount) &&
1622 	       CheckFeature(requested, supported, runtimeDescriptorArray) &&
1623 	       CheckFeature(requested, supported, samplerFilterMinmax) &&
1624 	       CheckFeature(requested, supported, scalarBlockLayout) &&
1625 	       CheckFeature(requested, supported, imagelessFramebuffer) &&
1626 	       CheckFeature(requested, supported, uniformBufferStandardLayout) &&
1627 	       CheckFeature(requested, supported, shaderSubgroupExtendedTypes) &&
1628 	       CheckFeature(requested, supported, separateDepthStencilLayouts) &&
1629 	       CheckFeature(requested, supported, hostQueryReset) &&
1630 	       CheckFeature(requested, supported, timelineSemaphore) &&
1631 	       CheckFeature(requested, supported, bufferDeviceAddress) &&
1632 	       CheckFeature(requested, supported, bufferDeviceAddressCaptureReplay) &&
1633 	       CheckFeature(requested, supported, bufferDeviceAddressMultiDevice) &&
1634 	       CheckFeature(requested, supported, vulkanMemoryModel) &&
1635 	       CheckFeature(requested, supported, vulkanMemoryModelDeviceScope) &&
1636 	       CheckFeature(requested, supported, vulkanMemoryModelAvailabilityVisibilityChains) &&
1637 	       CheckFeature(requested, supported, shaderOutputViewportIndex) &&
1638 	       CheckFeature(requested, supported, shaderOutputLayer) &&
1639 	       CheckFeature(requested, supported, subgroupBroadcastDynamicId);
1640 }
1641 
hasExtendedFeatures(const VkPhysicalDeviceVulkan13Features * requested) const1642 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDeviceVulkan13Features *requested) const
1643 {
1644 	auto supported = getSupportedFeatures(requested);
1645 
1646 	return CheckFeature(requested, supported, robustImageAccess) &&
1647 	       CheckFeature(requested, supported, inlineUniformBlock) &&
1648 	       CheckFeature(requested, supported, descriptorBindingInlineUniformBlockUpdateAfterBind) &&
1649 	       CheckFeature(requested, supported, pipelineCreationCacheControl) &&
1650 	       CheckFeature(requested, supported, privateData) &&
1651 	       CheckFeature(requested, supported, shaderDemoteToHelperInvocation) &&
1652 	       CheckFeature(requested, supported, shaderTerminateInvocation) &&
1653 	       CheckFeature(requested, supported, subgroupSizeControl) &&
1654 	       CheckFeature(requested, supported, computeFullSubgroups) &&
1655 	       CheckFeature(requested, supported, synchronization2) &&
1656 	       CheckFeature(requested, supported, textureCompressionASTC_HDR) &&
1657 	       CheckFeature(requested, supported, shaderZeroInitializeWorkgroupMemory) &&
1658 	       CheckFeature(requested, supported, dynamicRendering) &&
1659 	       CheckFeature(requested, supported, shaderIntegerDotProduct) &&
1660 	       CheckFeature(requested, supported, maintenance4);
1661 }
1662 
hasExtendedFeatures(const VkPhysicalDeviceDepthClipEnableFeaturesEXT * requested) const1663 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDeviceDepthClipEnableFeaturesEXT *requested) const
1664 {
1665 	auto supported = getSupportedFeatures(requested);
1666 
1667 	return CheckFeature(requested, supported, depthClipEnable);
1668 }
1669 
hasExtendedFeatures(const VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT * requested) const1670 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT *requested) const
1671 {
1672 	auto supported = getSupportedFeatures(requested);
1673 
1674 	return CheckFeature(requested, supported, advancedBlendCoherentOperations);
1675 }
1676 
hasExtendedFeatures(const VkPhysicalDeviceInlineUniformBlockFeatures * requested) const1677 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDeviceInlineUniformBlockFeatures *requested) const
1678 {
1679 	auto supported = getSupportedFeatures(requested);
1680 
1681 	return CheckFeature(requested, supported, inlineUniformBlock) &&
1682 	       CheckFeature(requested, supported, descriptorBindingInlineUniformBlockUpdateAfterBind);
1683 }
1684 
hasExtendedFeatures(const VkPhysicalDeviceShaderIntegerDotProductFeatures * requested) const1685 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDeviceShaderIntegerDotProductFeatures *requested) const
1686 {
1687 	auto supported = getSupportedFeatures(requested);
1688 
1689 	return CheckFeature(requested, supported, shaderIntegerDotProduct);
1690 }
1691 
hasExtendedFeatures(const VkPhysicalDeviceExtendedDynamicStateFeaturesEXT * requested) const1692 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDeviceExtendedDynamicStateFeaturesEXT *requested) const
1693 {
1694 	auto supported = getSupportedFeatures(requested);
1695 
1696 	return CheckFeature(requested, supported, extendedDynamicState);
1697 }
1698 
hasExtendedFeatures(const VkPhysicalDeviceVertexInputDynamicStateFeaturesEXT * requested) const1699 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDeviceVertexInputDynamicStateFeaturesEXT *requested) const
1700 {
1701 	auto supported = getSupportedFeatures(requested);
1702 
1703 	return CheckFeature(requested, supported, vertexInputDynamicState);
1704 }
1705 
hasExtendedFeatures(const VkPhysicalDevicePrivateDataFeatures * requested) const1706 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDevicePrivateDataFeatures *requested) const
1707 {
1708 	auto supported = getSupportedFeatures(requested);
1709 
1710 	return CheckFeature(requested, supported, privateData);
1711 }
1712 
hasExtendedFeatures(const VkPhysicalDeviceTextureCompressionASTCHDRFeatures * requested) const1713 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDeviceTextureCompressionASTCHDRFeatures *requested) const
1714 {
1715 	auto supported = getSupportedFeatures(requested);
1716 
1717 	return CheckFeature(requested, supported, textureCompressionASTC_HDR);
1718 }
1719 
hasExtendedFeatures(const VkPhysicalDeviceShaderDemoteToHelperInvocationFeatures * requested) const1720 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDeviceShaderDemoteToHelperInvocationFeatures *requested) const
1721 {
1722 	auto supported = getSupportedFeatures(requested);
1723 
1724 	return CheckFeature(requested, supported, shaderDemoteToHelperInvocation);
1725 }
1726 
hasExtendedFeatures(const VkPhysicalDeviceShaderTerminateInvocationFeatures * requested) const1727 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDeviceShaderTerminateInvocationFeatures *requested) const
1728 {
1729 	auto supported = getSupportedFeatures(requested);
1730 
1731 	return CheckFeature(requested, supported, shaderTerminateInvocation);
1732 }
1733 
hasExtendedFeatures(const VkPhysicalDeviceSubgroupSizeControlFeatures * requested) const1734 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDeviceSubgroupSizeControlFeatures *requested) const
1735 {
1736 	auto supported = getSupportedFeatures(requested);
1737 
1738 	return CheckFeature(requested, supported, subgroupSizeControl) &&
1739 	       CheckFeature(requested, supported, computeFullSubgroups);
1740 }
1741 
hasExtendedFeatures(const VkPhysicalDeviceZeroInitializeWorkgroupMemoryFeatures * requested) const1742 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDeviceZeroInitializeWorkgroupMemoryFeatures *requested) const
1743 {
1744 	auto supported = getSupportedFeatures(requested);
1745 
1746 	return CheckFeature(requested, supported, shaderZeroInitializeWorkgroupMemory);
1747 }
1748 
hasExtendedFeatures(const VkPhysicalDevicePrimitiveTopologyListRestartFeaturesEXT * requested) const1749 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDevicePrimitiveTopologyListRestartFeaturesEXT *requested) const
1750 {
1751 	auto supported = getSupportedFeatures(requested);
1752 
1753 	return CheckFeature(requested, supported, primitiveTopologyListRestart) &&
1754 	       CheckFeature(requested, supported, primitiveTopologyPatchListRestart);
1755 }
1756 
hasExtendedFeatures(const VkPhysicalDeviceGraphicsPipelineLibraryFeaturesEXT * requested) const1757 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDeviceGraphicsPipelineLibraryFeaturesEXT *requested) const
1758 {
1759 	auto supported = getSupportedFeatures(requested);
1760 
1761 	return CheckFeature(requested, supported, graphicsPipelineLibrary);
1762 }
1763 
hasExtendedFeatures(const VkPhysicalDeviceSwapchainMaintenance1FeaturesEXT * requested) const1764 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDeviceSwapchainMaintenance1FeaturesEXT *requested) const
1765 {
1766 	auto supported = getSupportedFeatures(requested);
1767 
1768 	return CheckFeature(requested, supported, swapchainMaintenance1);
1769 }
1770 
hasExtendedFeatures(const VkPhysicalDeviceHostImageCopyFeaturesEXT * requested) const1771 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDeviceHostImageCopyFeaturesEXT *requested) const
1772 {
1773 	auto supported = getSupportedFeatures(requested);
1774 
1775 	return CheckFeature(requested, supported, hostImageCopy);
1776 }
1777 
hasExtendedFeatures(const VkPhysicalDeviceIndexTypeUint8FeaturesEXT * requested) const1778 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDeviceIndexTypeUint8FeaturesEXT *requested) const
1779 {
1780 	auto supported = getSupportedFeatures(requested);
1781 
1782 	return CheckFeature(requested, supported, indexTypeUint8);
1783 }
1784 
hasExtendedFeatures(const VkPhysicalDeviceDescriptorIndexingFeatures * requested) const1785 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDeviceDescriptorIndexingFeatures *requested) const
1786 {
1787 	auto supported = getSupportedFeatures(requested);
1788 
1789 	return CheckFeature(requested, supported, shaderInputAttachmentArrayDynamicIndexing) &&
1790 	       CheckFeature(requested, supported, shaderUniformTexelBufferArrayDynamicIndexing) &&
1791 	       CheckFeature(requested, supported, shaderStorageTexelBufferArrayDynamicIndexing) &&
1792 	       CheckFeature(requested, supported, shaderUniformBufferArrayNonUniformIndexing) &&
1793 	       CheckFeature(requested, supported, shaderSampledImageArrayNonUniformIndexing) &&
1794 	       CheckFeature(requested, supported, shaderStorageBufferArrayNonUniformIndexing) &&
1795 	       CheckFeature(requested, supported, shaderStorageImageArrayNonUniformIndexing) &&
1796 	       CheckFeature(requested, supported, shaderInputAttachmentArrayNonUniformIndexing) &&
1797 	       CheckFeature(requested, supported, shaderUniformTexelBufferArrayNonUniformIndexing) &&
1798 	       CheckFeature(requested, supported, shaderStorageTexelBufferArrayNonUniformIndexing) &&
1799 	       CheckFeature(requested, supported, descriptorBindingUniformBufferUpdateAfterBind) &&
1800 	       CheckFeature(requested, supported, descriptorBindingSampledImageUpdateAfterBind) &&
1801 	       CheckFeature(requested, supported, descriptorBindingStorageImageUpdateAfterBind) &&
1802 	       CheckFeature(requested, supported, descriptorBindingStorageBufferUpdateAfterBind) &&
1803 	       CheckFeature(requested, supported, descriptorBindingUniformTexelBufferUpdateAfterBind) &&
1804 	       CheckFeature(requested, supported, descriptorBindingStorageTexelBufferUpdateAfterBind) &&
1805 	       CheckFeature(requested, supported, descriptorBindingUpdateUnusedWhilePending) &&
1806 	       CheckFeature(requested, supported, descriptorBindingPartiallyBound) &&
1807 	       CheckFeature(requested, supported, descriptorBindingVariableDescriptorCount) &&
1808 	       CheckFeature(requested, supported, runtimeDescriptorArray);
1809 }
1810 
hasExtendedFeatures(const VkPhysicalDevicePipelineRobustnessFeaturesEXT * requested) const1811 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDevicePipelineRobustnessFeaturesEXT *requested) const
1812 {
1813 	auto supported = getSupportedFeatures(requested);
1814 
1815 	return CheckFeature(requested, supported, pipelineRobustness);
1816 }
1817 
hasExtendedFeatures(const VkPhysicalDeviceProtectedMemoryFeatures * requested) const1818 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDeviceProtectedMemoryFeatures *requested) const
1819 {
1820 	auto supported = getSupportedFeatures(requested);
1821 
1822 	return CheckFeature(requested, supported, protectedMemory);
1823 }
1824 
hasExtendedFeatures(const VkPhysicalDeviceBufferDeviceAddressFeatures * requested) const1825 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDeviceBufferDeviceAddressFeatures *requested) const
1826 {
1827 	auto supported = getSupportedFeatures(requested);
1828 
1829 	return CheckFeature(requested, supported, bufferDeviceAddress) &&
1830 	       CheckFeature(requested, supported, bufferDeviceAddressCaptureReplay) &&
1831 	       CheckFeature(requested, supported, bufferDeviceAddressMultiDevice);
1832 }
1833 
hasExtendedFeatures(const VkPhysicalDeviceGlobalPriorityQueryFeaturesKHR * requested) const1834 bool PhysicalDevice::hasExtendedFeatures(const VkPhysicalDeviceGlobalPriorityQueryFeaturesKHR *requested) const
1835 {
1836 	auto supported = getSupportedFeatures(requested);
1837 
1838 	return CheckFeature(requested, supported, globalPriorityQuery);
1839 }
1840 #undef CheckFeature
1841 
checkFormatUsage(VkImageUsageFlags usage,VkFormatFeatureFlags2KHR features)1842 static bool checkFormatUsage(VkImageUsageFlags usage, VkFormatFeatureFlags2KHR features)
1843 {
1844 	// Check for usage conflict with features
1845 	if((usage & VK_IMAGE_USAGE_SAMPLED_BIT) && !(features & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT))
1846 	{
1847 		return false;
1848 	}
1849 
1850 	if((usage & VK_IMAGE_USAGE_STORAGE_BIT) && !(features & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT))
1851 	{
1852 		return false;
1853 	}
1854 
1855 	if((usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) && !(features & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT))
1856 	{
1857 		return false;
1858 	}
1859 
1860 	if((usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) && !(features & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT))
1861 	{
1862 		return false;
1863 	}
1864 
1865 	if((usage & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT) && !(features & (VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT | VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)))
1866 	{
1867 		return false;
1868 	}
1869 
1870 	if((usage & VK_IMAGE_USAGE_TRANSFER_SRC_BIT) && !(features & VK_FORMAT_FEATURE_TRANSFER_SRC_BIT))
1871 	{
1872 		return false;
1873 	}
1874 
1875 	if((usage & VK_IMAGE_USAGE_TRANSFER_DST_BIT) && !(features & VK_FORMAT_FEATURE_TRANSFER_DST_BIT))
1876 	{
1877 		return false;
1878 	}
1879 
1880 	if((usage & VK_IMAGE_USAGE_HOST_TRANSFER_BIT_EXT) && !(features & VK_FORMAT_FEATURE_2_HOST_IMAGE_TRANSFER_BIT_EXT))
1881 	{
1882 		return false;
1883 	}
1884 
1885 	return true;
1886 }
1887 
isFormatSupported(vk::Format format,VkImageType type,VkImageTiling tiling,VkImageUsageFlags usage,VkImageUsageFlags stencilUsage,VkImageCreateFlags flags)1888 bool vk::PhysicalDevice::isFormatSupported(vk::Format format, VkImageType type, VkImageTiling tiling,
1889                                            VkImageUsageFlags usage, VkImageUsageFlags stencilUsage, VkImageCreateFlags flags)
1890 {
1891 	VkFormatProperties3 properties = {};
1892 	vk::PhysicalDevice::GetFormatProperties(format, &properties);
1893 
1894 	if(flags & VK_IMAGE_CREATE_EXTENDED_USAGE_BIT)
1895 	{
1896 		for(vk::Format f : format.getCompatibleFormats())
1897 		{
1898 			VkFormatProperties extendedProperties = {};
1899 			vk::PhysicalDevice::GetFormatProperties(f, &extendedProperties);
1900 			properties.linearTilingFeatures |= extendedProperties.linearTilingFeatures;
1901 			properties.optimalTilingFeatures |= extendedProperties.optimalTilingFeatures;
1902 			properties.bufferFeatures |= extendedProperties.bufferFeatures;
1903 		}
1904 	}
1905 
1906 	VkFormatFeatureFlags2KHR features;
1907 	switch(tiling)
1908 	{
1909 	case VK_IMAGE_TILING_LINEAR:
1910 		features = properties.linearTilingFeatures;
1911 		break;
1912 
1913 	case VK_IMAGE_TILING_OPTIMAL:
1914 		features = properties.optimalTilingFeatures;
1915 		break;
1916 
1917 	default:
1918 		UNSUPPORTED("VkImageTiling %d", int(tiling));
1919 		features = 0;
1920 	}
1921 
1922 	if(features == 0)
1923 	{
1924 		return false;
1925 	}
1926 
1927 	// Reject any usage or separate stencil usage that is not compatible with the specified format.
1928 	if(!checkFormatUsage(usage, features))
1929 	{
1930 		return false;
1931 	}
1932 	// If stencilUsage is 0 then no separate usage was provided and it takes on the same value as usage,
1933 	// which has already been checked. So only check non-zero stencilUsage.
1934 	if(stencilUsage != 0 && !checkFormatUsage(stencilUsage, features))
1935 	{
1936 		return false;
1937 	}
1938 
1939 	auto allRecognizedUsageBits = VK_IMAGE_USAGE_SAMPLED_BIT |
1940 	                              VK_IMAGE_USAGE_STORAGE_BIT |
1941 	                              VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
1942 	                              VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
1943 	                              VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT |
1944 	                              VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
1945 	                              VK_IMAGE_USAGE_TRANSFER_DST_BIT |
1946 	                              VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT |
1947 	                              VK_IMAGE_USAGE_HOST_TRANSFER_BIT_EXT;
1948 	ASSERT(!(usage & ~(allRecognizedUsageBits)));
1949 
1950 	if(usage & VK_IMAGE_USAGE_SAMPLED_BIT)
1951 	{
1952 		if(tiling == VK_IMAGE_TILING_LINEAR)
1953 		{
1954 			// TODO(b/171299814): Compressed formats and cube maps are not supported for sampling using VK_IMAGE_TILING_LINEAR; otherwise, sampling
1955 			// in linear tiling is always supported as long as it can be sampled when using VK_IMAGE_TILING_OPTIMAL.
1956 			if(!(properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) ||
1957 			   vk::Format(format).isCompressed() ||
1958 			   (flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT))
1959 			{
1960 				return false;
1961 			}
1962 		}
1963 		else if(!(features & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT))
1964 		{
1965 			return false;
1966 		}
1967 	}
1968 
1969 	// "Images created with tiling equal to VK_IMAGE_TILING_LINEAR have further restrictions on their limits and capabilities
1970 	//  compared to images created with tiling equal to VK_IMAGE_TILING_OPTIMAL."
1971 	if(tiling == VK_IMAGE_TILING_LINEAR)
1972 	{
1973 		if(type != VK_IMAGE_TYPE_2D)
1974 		{
1975 			return false;
1976 		}
1977 
1978 		if(vk::Format(format).isDepth() || vk::Format(format).isStencil())
1979 		{
1980 			return false;
1981 		}
1982 	}
1983 
1984 	// "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
1985 	//  have further restrictions on their limits and capabilities compared to images created with other formats."
1986 	if(vk::Format(format).isYcbcrFormat())
1987 	{
1988 		if(type != VK_IMAGE_TYPE_2D)
1989 		{
1990 			return false;
1991 		}
1992 	}
1993 
1994 	return true;
1995 }
1996 
GetFormatProperties(Format format,VkFormatProperties * pFormatProperties)1997 void PhysicalDevice::GetFormatProperties(Format format, VkFormatProperties *pFormatProperties)
1998 {
1999 	VkFormatProperties3 formatProperties3 = {};
2000 	GetFormatProperties(format, &formatProperties3);
2001 
2002 	// VkFormatFeatureFlags2KHR is a 64-bit extension of the 32-bit VkFormatFeatureFlags,
2003 	// so when querying the legacy flags just return the lower 32-bit portion.
2004 	pFormatProperties->linearTilingFeatures = static_cast<VkFormatFeatureFlags>(formatProperties3.linearTilingFeatures);
2005 	pFormatProperties->optimalTilingFeatures = static_cast<VkFormatFeatureFlags>(formatProperties3.optimalTilingFeatures);
2006 	pFormatProperties->bufferFeatures = static_cast<VkFormatFeatureFlags>(formatProperties3.bufferFeatures);
2007 }
2008 
GetFormatProperties(Format format,VkFormatProperties3 * pFormatProperties)2009 void PhysicalDevice::GetFormatProperties(Format format, VkFormatProperties3 *pFormatProperties)
2010 {
2011 	pFormatProperties->linearTilingFeatures = 0;   // Unsupported format
2012 	pFormatProperties->optimalTilingFeatures = 0;  // Unsupported format
2013 	pFormatProperties->bufferFeatures = 0;         // Unsupported format
2014 
2015 	switch(format)
2016 	{
2017 	// Formats which can be sampled *and* filtered
2018 	case VK_FORMAT_R4G4B4A4_UNORM_PACK16:
2019 	case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
2020 	case VK_FORMAT_A4R4G4B4_UNORM_PACK16:
2021 	case VK_FORMAT_A4B4G4R4_UNORM_PACK16:
2022 	case VK_FORMAT_R5G6B5_UNORM_PACK16:
2023 	case VK_FORMAT_B5G6R5_UNORM_PACK16:
2024 	case VK_FORMAT_R5G5B5A1_UNORM_PACK16:
2025 	case VK_FORMAT_B5G5R5A1_UNORM_PACK16:
2026 	case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
2027 	case VK_FORMAT_R8_UNORM:
2028 	case VK_FORMAT_R8_SRGB:
2029 	case VK_FORMAT_R8_SNORM:
2030 	case VK_FORMAT_R8G8_UNORM:
2031 	case VK_FORMAT_R8G8_SRGB:
2032 	case VK_FORMAT_R8G8_SNORM:
2033 	case VK_FORMAT_R8G8B8A8_UNORM:
2034 	case VK_FORMAT_R8G8B8A8_SNORM:
2035 	case VK_FORMAT_R8G8B8A8_SRGB:
2036 	case VK_FORMAT_B8G8R8A8_UNORM:
2037 	case VK_FORMAT_B8G8R8A8_SRGB:
2038 	case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
2039 	case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
2040 	case VK_FORMAT_A8B8G8R8_SRGB_PACK32:
2041 	case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
2042 	case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
2043 	case VK_FORMAT_R16_UNORM:
2044 	case VK_FORMAT_R16_SNORM:
2045 	case VK_FORMAT_R16_SFLOAT:
2046 	case VK_FORMAT_R16G16_UNORM:
2047 	case VK_FORMAT_R16G16_SNORM:
2048 	case VK_FORMAT_R16G16_SFLOAT:
2049 	case VK_FORMAT_R16G16B16A16_UNORM:
2050 	case VK_FORMAT_R16G16B16A16_SNORM:
2051 	case VK_FORMAT_R16G16B16A16_SFLOAT:
2052 	case VK_FORMAT_R32_SFLOAT:
2053 	case VK_FORMAT_R32G32_SFLOAT:
2054 	case VK_FORMAT_R32G32B32A32_SFLOAT:
2055 	case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
2056 	case VK_FORMAT_E5B9G9R9_UFLOAT_PACK32:
2057 	case VK_FORMAT_BC1_RGB_UNORM_BLOCK:
2058 	case VK_FORMAT_BC1_RGB_SRGB_BLOCK:
2059 	case VK_FORMAT_BC1_RGBA_UNORM_BLOCK:
2060 	case VK_FORMAT_BC1_RGBA_SRGB_BLOCK:
2061 	case VK_FORMAT_BC2_UNORM_BLOCK:
2062 	case VK_FORMAT_BC2_SRGB_BLOCK:
2063 	case VK_FORMAT_BC3_UNORM_BLOCK:
2064 	case VK_FORMAT_BC3_SRGB_BLOCK:
2065 	case VK_FORMAT_BC4_UNORM_BLOCK:
2066 	case VK_FORMAT_BC4_SNORM_BLOCK:
2067 	case VK_FORMAT_BC5_UNORM_BLOCK:
2068 	case VK_FORMAT_BC5_SNORM_BLOCK:
2069 	case VK_FORMAT_BC6H_UFLOAT_BLOCK:
2070 	case VK_FORMAT_BC6H_SFLOAT_BLOCK:
2071 	case VK_FORMAT_BC7_UNORM_BLOCK:
2072 	case VK_FORMAT_BC7_SRGB_BLOCK:
2073 	case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
2074 	case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:
2075 	case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK:
2076 	case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:
2077 	case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK:
2078 	case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK:
2079 	case VK_FORMAT_EAC_R11_UNORM_BLOCK:
2080 	case VK_FORMAT_EAC_R11_SNORM_BLOCK:
2081 	case VK_FORMAT_EAC_R11G11_UNORM_BLOCK:
2082 	case VK_FORMAT_EAC_R11G11_SNORM_BLOCK:
2083 #ifdef SWIFTSHADER_ENABLE_ASTC
2084 	case VK_FORMAT_ASTC_4x4_UNORM_BLOCK:
2085 	case VK_FORMAT_ASTC_5x4_UNORM_BLOCK:
2086 	case VK_FORMAT_ASTC_5x5_UNORM_BLOCK:
2087 	case VK_FORMAT_ASTC_6x5_UNORM_BLOCK:
2088 	case VK_FORMAT_ASTC_6x6_UNORM_BLOCK:
2089 	case VK_FORMAT_ASTC_8x5_UNORM_BLOCK:
2090 	case VK_FORMAT_ASTC_8x6_UNORM_BLOCK:
2091 	case VK_FORMAT_ASTC_8x8_UNORM_BLOCK:
2092 	case VK_FORMAT_ASTC_10x5_UNORM_BLOCK:
2093 	case VK_FORMAT_ASTC_10x6_UNORM_BLOCK:
2094 	case VK_FORMAT_ASTC_10x8_UNORM_BLOCK:
2095 	case VK_FORMAT_ASTC_10x10_UNORM_BLOCK:
2096 	case VK_FORMAT_ASTC_12x10_UNORM_BLOCK:
2097 	case VK_FORMAT_ASTC_12x12_UNORM_BLOCK:
2098 	case VK_FORMAT_ASTC_4x4_SRGB_BLOCK:
2099 	case VK_FORMAT_ASTC_5x4_SRGB_BLOCK:
2100 	case VK_FORMAT_ASTC_5x5_SRGB_BLOCK:
2101 	case VK_FORMAT_ASTC_6x5_SRGB_BLOCK:
2102 	case VK_FORMAT_ASTC_6x6_SRGB_BLOCK:
2103 	case VK_FORMAT_ASTC_8x5_SRGB_BLOCK:
2104 	case VK_FORMAT_ASTC_8x6_SRGB_BLOCK:
2105 	case VK_FORMAT_ASTC_8x8_SRGB_BLOCK:
2106 	case VK_FORMAT_ASTC_10x5_SRGB_BLOCK:
2107 	case VK_FORMAT_ASTC_10x6_SRGB_BLOCK:
2108 	case VK_FORMAT_ASTC_10x8_SRGB_BLOCK:
2109 	case VK_FORMAT_ASTC_10x10_SRGB_BLOCK:
2110 	case VK_FORMAT_ASTC_12x10_SRGB_BLOCK:
2111 	case VK_FORMAT_ASTC_12x12_SRGB_BLOCK:
2112 #endif
2113 	case VK_FORMAT_D16_UNORM:
2114 	case VK_FORMAT_D32_SFLOAT:
2115 	case VK_FORMAT_D32_SFLOAT_S8_UINT:
2116 		pFormatProperties->optimalTilingFeatures |=
2117 		    VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT;
2118 		// [[fallthrough]]
2119 
2120 	// Formats which can be sampled, but don't support filtering
2121 	case VK_FORMAT_R8_UINT:
2122 	case VK_FORMAT_R8_SINT:
2123 	case VK_FORMAT_R8G8_UINT:
2124 	case VK_FORMAT_R8G8_SINT:
2125 	case VK_FORMAT_R8G8B8A8_UINT:
2126 	case VK_FORMAT_R8G8B8A8_SINT:
2127 	case VK_FORMAT_A8B8G8R8_UINT_PACK32:
2128 	case VK_FORMAT_A8B8G8R8_SINT_PACK32:
2129 	case VK_FORMAT_A2B10G10R10_UINT_PACK32:
2130 	case VK_FORMAT_A2R10G10B10_UINT_PACK32:
2131 	case VK_FORMAT_R16_UINT:
2132 	case VK_FORMAT_R16_SINT:
2133 	case VK_FORMAT_R16G16_UINT:
2134 	case VK_FORMAT_R16G16_SINT:
2135 	case VK_FORMAT_R16G16B16A16_UINT:
2136 	case VK_FORMAT_R16G16B16A16_SINT:
2137 	case VK_FORMAT_R32_UINT:
2138 	case VK_FORMAT_R32_SINT:
2139 	case VK_FORMAT_R32G32_UINT:
2140 	case VK_FORMAT_R32G32_SINT:
2141 	case VK_FORMAT_R32G32B32A32_UINT:
2142 	case VK_FORMAT_R32G32B32A32_SINT:
2143 	case VK_FORMAT_S8_UINT:
2144 		pFormatProperties->optimalTilingFeatures |=
2145 		    VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT |
2146 		    VK_FORMAT_FEATURE_BLIT_SRC_BIT |
2147 		    VK_FORMAT_FEATURE_TRANSFER_SRC_BIT |
2148 		    VK_FORMAT_FEATURE_TRANSFER_DST_BIT |
2149 		    VK_FORMAT_FEATURE_2_HOST_IMAGE_TRANSFER_BIT_EXT;
2150 		break;
2151 
2152 	// YCbCr formats:
2153 	case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM:
2154 	case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM:
2155 	case VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16:
2156 		pFormatProperties->optimalTilingFeatures |=
2157 		    VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT |
2158 		    VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT |
2159 		    VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_LINEAR_FILTER_BIT |
2160 		    VK_FORMAT_FEATURE_TRANSFER_SRC_BIT |
2161 		    VK_FORMAT_FEATURE_TRANSFER_DST_BIT |
2162 		    VK_FORMAT_FEATURE_COSITED_CHROMA_SAMPLES_BIT |
2163 		    VK_FORMAT_FEATURE_2_HOST_IMAGE_TRANSFER_BIT_EXT;
2164 		break;
2165 	default:
2166 		break;
2167 	}
2168 
2169 	switch(format)
2170 	{
2171 	// Vulkan 1.0 mandatory storage image formats supporting atomic operations
2172 	case VK_FORMAT_R32_UINT:
2173 	case VK_FORMAT_R32_SINT:
2174 		pFormatProperties->optimalTilingFeatures |=
2175 		    VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT;
2176 		pFormatProperties->bufferFeatures |=
2177 		    VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT;
2178 		// [[fallthrough]]
2179 	// Vulkan 1.0 mandatory storage image formats
2180 	case VK_FORMAT_R8G8B8A8_UNORM:
2181 	case VK_FORMAT_R8G8B8A8_SNORM:
2182 	case VK_FORMAT_R8G8B8A8_UINT:
2183 	case VK_FORMAT_R8G8B8A8_SINT:
2184 	case VK_FORMAT_R16G16B16A16_UINT:
2185 	case VK_FORMAT_R16G16B16A16_SINT:
2186 	case VK_FORMAT_R16G16B16A16_SFLOAT:
2187 	case VK_FORMAT_R32_SFLOAT:
2188 	case VK_FORMAT_R32G32_UINT:
2189 	case VK_FORMAT_R32G32_SINT:
2190 	case VK_FORMAT_R32G32_SFLOAT:
2191 	case VK_FORMAT_R32G32B32A32_UINT:
2192 	case VK_FORMAT_R32G32B32A32_SINT:
2193 	case VK_FORMAT_R32G32B32A32_SFLOAT:
2194 	case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
2195 	case VK_FORMAT_A2B10G10R10_UINT_PACK32:
2196 	// Vulkan 1.0 shaderStorageImageExtendedFormats
2197 	case VK_FORMAT_R16G16_SFLOAT:
2198 	case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
2199 	case VK_FORMAT_R16_SFLOAT:
2200 	case VK_FORMAT_R16G16B16A16_UNORM:
2201 	case VK_FORMAT_R16G16_UNORM:
2202 	case VK_FORMAT_R8G8_UNORM:
2203 	case VK_FORMAT_R16_UNORM:
2204 	case VK_FORMAT_R8_UNORM:
2205 	case VK_FORMAT_R16G16B16A16_SNORM:
2206 	case VK_FORMAT_R16G16_SNORM:
2207 	case VK_FORMAT_R8G8_SNORM:
2208 	case VK_FORMAT_R16_SNORM:
2209 	case VK_FORMAT_R8_SNORM:
2210 	case VK_FORMAT_R16G16_SINT:
2211 	case VK_FORMAT_R8G8_SINT:
2212 	case VK_FORMAT_R16_SINT:
2213 	case VK_FORMAT_R8_SINT:
2214 	case VK_FORMAT_R16G16_UINT:
2215 	case VK_FORMAT_R8G8_UINT:
2216 	case VK_FORMAT_R16_UINT:
2217 	case VK_FORMAT_R8_UINT:
2218 	// Additional formats not listed under "Formats without shader storage format"
2219 	case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
2220 	case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
2221 	case VK_FORMAT_A8B8G8R8_UINT_PACK32:
2222 	case VK_FORMAT_A8B8G8R8_SINT_PACK32:
2223 	case VK_FORMAT_B8G8R8A8_UNORM:
2224 	case VK_FORMAT_B8G8R8A8_SRGB:
2225 		pFormatProperties->optimalTilingFeatures |=
2226 		    VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT |
2227 		    VK_FORMAT_FEATURE_2_STORAGE_WRITE_WITHOUT_FORMAT_BIT;
2228 		pFormatProperties->bufferFeatures |=
2229 		    VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT;
2230 		break;
2231 	default:
2232 		break;
2233 	}
2234 
2235 	switch(format)
2236 	{
2237 	case VK_FORMAT_R5G6B5_UNORM_PACK16:
2238 	case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
2239 	case VK_FORMAT_R4G4B4A4_UNORM_PACK16:
2240 	case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
2241 	case VK_FORMAT_A4R4G4B4_UNORM_PACK16:
2242 	case VK_FORMAT_A4B4G4R4_UNORM_PACK16:
2243 	case VK_FORMAT_B5G6R5_UNORM_PACK16:
2244 	case VK_FORMAT_R5G5B5A1_UNORM_PACK16:
2245 	case VK_FORMAT_B5G5R5A1_UNORM_PACK16:
2246 	case VK_FORMAT_R8_UNORM:
2247 	case VK_FORMAT_R8G8_UNORM:
2248 	case VK_FORMAT_R8G8B8A8_UNORM:
2249 	case VK_FORMAT_R8G8B8A8_SRGB:
2250 	case VK_FORMAT_B8G8R8A8_UNORM:
2251 	case VK_FORMAT_B8G8R8A8_SRGB:
2252 	case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
2253 	case VK_FORMAT_A8B8G8R8_SRGB_PACK32:
2254 	case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
2255 	case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
2256 	case VK_FORMAT_R16_SFLOAT:
2257 	case VK_FORMAT_R16G16_SFLOAT:
2258 	case VK_FORMAT_R16G16B16A16_SFLOAT:
2259 	case VK_FORMAT_R32_SFLOAT:
2260 	case VK_FORMAT_R32G32_SFLOAT:
2261 	case VK_FORMAT_R32G32B32A32_SFLOAT:
2262 	case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
2263 	case VK_FORMAT_R8_UINT:
2264 	case VK_FORMAT_R8_SINT:
2265 	case VK_FORMAT_R8G8_UINT:
2266 	case VK_FORMAT_R8G8_SINT:
2267 	case VK_FORMAT_R8G8B8A8_UINT:
2268 	case VK_FORMAT_R8G8B8A8_SINT:
2269 	case VK_FORMAT_A8B8G8R8_UINT_PACK32:
2270 	case VK_FORMAT_A8B8G8R8_SINT_PACK32:
2271 	case VK_FORMAT_A2B10G10R10_UINT_PACK32:
2272 	case VK_FORMAT_A2R10G10B10_UINT_PACK32:
2273 	case VK_FORMAT_R16_UNORM:
2274 	case VK_FORMAT_R16_UINT:
2275 	case VK_FORMAT_R16_SINT:
2276 	case VK_FORMAT_R16G16_UNORM:
2277 	case VK_FORMAT_R16G16_UINT:
2278 	case VK_FORMAT_R16G16_SINT:
2279 	case VK_FORMAT_R16G16B16A16_UNORM:
2280 	case VK_FORMAT_R16G16B16A16_UINT:
2281 	case VK_FORMAT_R16G16B16A16_SINT:
2282 	case VK_FORMAT_R32_UINT:
2283 	case VK_FORMAT_R32_SINT:
2284 	case VK_FORMAT_R32G32_UINT:
2285 	case VK_FORMAT_R32G32_SINT:
2286 	case VK_FORMAT_R32G32B32A32_UINT:
2287 	case VK_FORMAT_R32G32B32A32_SINT:
2288 		pFormatProperties->optimalTilingFeatures |=
2289 		    VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT |
2290 		    VK_FORMAT_FEATURE_BLIT_DST_BIT;
2291 		break;
2292 	case VK_FORMAT_S8_UINT:
2293 	case VK_FORMAT_D16_UNORM:
2294 	case VK_FORMAT_D32_SFLOAT:          // Note: either VK_FORMAT_D32_SFLOAT or VK_FORMAT_X8_D24_UNORM_PACK32 must be supported
2295 	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
2296 		pFormatProperties->optimalTilingFeatures |=
2297 		    VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT;
2298 		break;
2299 	default:
2300 		break;
2301 	}
2302 
2303 	switch(format)
2304 	{
2305 	case VK_FORMAT_D16_UNORM:
2306 	case VK_FORMAT_D32_SFLOAT:          // Note: either VK_FORMAT_D32_SFLOAT or VK_FORMAT_X8_D24_UNORM_PACK32 must be supported
2307 	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
2308 		pFormatProperties->optimalTilingFeatures |=
2309 		    VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_DEPTH_COMPARISON_BIT_KHR;
2310 		break;
2311 	default:
2312 		break;
2313 	}
2314 
2315 	if(format.supportsColorAttachmentBlend())
2316 	{
2317 		pFormatProperties->optimalTilingFeatures |=
2318 		    VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT;
2319 	}
2320 
2321 	switch(format)
2322 	{
2323 	case VK_FORMAT_R8_UNORM:
2324 	case VK_FORMAT_R8_SNORM:
2325 	case VK_FORMAT_R8_USCALED:
2326 	case VK_FORMAT_R8_SSCALED:
2327 	case VK_FORMAT_R8_UINT:
2328 	case VK_FORMAT_R8_SINT:
2329 	case VK_FORMAT_R8G8_UNORM:
2330 	case VK_FORMAT_R8G8_SNORM:
2331 	case VK_FORMAT_R8G8_USCALED:
2332 	case VK_FORMAT_R8G8_SSCALED:
2333 	case VK_FORMAT_R8G8_UINT:
2334 	case VK_FORMAT_R8G8_SINT:
2335 	case VK_FORMAT_R8G8B8A8_UNORM:
2336 	case VK_FORMAT_R8G8B8A8_SNORM:
2337 	case VK_FORMAT_R8G8B8A8_USCALED:
2338 	case VK_FORMAT_R8G8B8A8_SSCALED:
2339 	case VK_FORMAT_R8G8B8A8_UINT:
2340 	case VK_FORMAT_R8G8B8A8_SINT:
2341 	case VK_FORMAT_B8G8R8A8_UNORM:
2342 	case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
2343 	case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
2344 	case VK_FORMAT_A8B8G8R8_USCALED_PACK32:
2345 	case VK_FORMAT_A8B8G8R8_SSCALED_PACK32:
2346 	case VK_FORMAT_A8B8G8R8_UINT_PACK32:
2347 	case VK_FORMAT_A8B8G8R8_SINT_PACK32:
2348 	case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
2349 	case VK_FORMAT_A2R10G10B10_SNORM_PACK32:
2350 	case VK_FORMAT_A2R10G10B10_UINT_PACK32:
2351 	case VK_FORMAT_A2R10G10B10_SINT_PACK32:
2352 	case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
2353 	case VK_FORMAT_A2B10G10R10_SNORM_PACK32:
2354 	case VK_FORMAT_A2B10G10R10_UINT_PACK32:
2355 	case VK_FORMAT_A2B10G10R10_SINT_PACK32:
2356 	case VK_FORMAT_R16_UNORM:
2357 	case VK_FORMAT_R16_SNORM:
2358 	case VK_FORMAT_R16_USCALED:
2359 	case VK_FORMAT_R16_SSCALED:
2360 	case VK_FORMAT_R16_UINT:
2361 	case VK_FORMAT_R16_SINT:
2362 	case VK_FORMAT_R16_SFLOAT:
2363 	case VK_FORMAT_R16G16_UNORM:
2364 	case VK_FORMAT_R16G16_SNORM:
2365 	case VK_FORMAT_R16G16_USCALED:
2366 	case VK_FORMAT_R16G16_SSCALED:
2367 	case VK_FORMAT_R16G16_UINT:
2368 	case VK_FORMAT_R16G16_SINT:
2369 	case VK_FORMAT_R16G16_SFLOAT:
2370 	case VK_FORMAT_R16G16B16A16_UNORM:
2371 	case VK_FORMAT_R16G16B16A16_SNORM:
2372 	case VK_FORMAT_R16G16B16A16_USCALED:
2373 	case VK_FORMAT_R16G16B16A16_SSCALED:
2374 	case VK_FORMAT_R16G16B16A16_UINT:
2375 	case VK_FORMAT_R16G16B16A16_SINT:
2376 	case VK_FORMAT_R16G16B16A16_SFLOAT:
2377 	case VK_FORMAT_R32_UINT:
2378 	case VK_FORMAT_R32_SINT:
2379 	case VK_FORMAT_R32_SFLOAT:
2380 	case VK_FORMAT_R32G32_UINT:
2381 	case VK_FORMAT_R32G32_SINT:
2382 	case VK_FORMAT_R32G32_SFLOAT:
2383 	case VK_FORMAT_R32G32B32_UINT:
2384 	case VK_FORMAT_R32G32B32_SINT:
2385 	case VK_FORMAT_R32G32B32_SFLOAT:
2386 	case VK_FORMAT_R32G32B32A32_UINT:
2387 	case VK_FORMAT_R32G32B32A32_SINT:
2388 	case VK_FORMAT_R32G32B32A32_SFLOAT:
2389 		pFormatProperties->bufferFeatures |=
2390 		    VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT;
2391 		break;
2392 	default:
2393 		break;
2394 	}
2395 
2396 	switch(format)
2397 	{
2398 	// Vulkan 1.1 mandatory
2399 	case VK_FORMAT_R8_UNORM:
2400 	case VK_FORMAT_R8_SNORM:
2401 	case VK_FORMAT_R8_UINT:
2402 	case VK_FORMAT_R8_SINT:
2403 	case VK_FORMAT_R8G8_UNORM:
2404 	case VK_FORMAT_R8G8_SNORM:
2405 	case VK_FORMAT_R8G8_UINT:
2406 	case VK_FORMAT_R8G8_SINT:
2407 	case VK_FORMAT_R8G8B8A8_UNORM:
2408 	case VK_FORMAT_R8G8B8A8_SNORM:
2409 	case VK_FORMAT_R8G8B8A8_UINT:
2410 	case VK_FORMAT_R8G8B8A8_SINT:
2411 	case VK_FORMAT_B8G8R8A8_UNORM:
2412 	case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
2413 	case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
2414 	case VK_FORMAT_A8B8G8R8_UINT_PACK32:
2415 	case VK_FORMAT_A8B8G8R8_SINT_PACK32:
2416 	case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
2417 	case VK_FORMAT_A2B10G10R10_UINT_PACK32:
2418 	case VK_FORMAT_R16_UINT:
2419 	case VK_FORMAT_R16_SINT:
2420 	case VK_FORMAT_R16_SFLOAT:
2421 	case VK_FORMAT_R16G16_UINT:
2422 	case VK_FORMAT_R16G16_SINT:
2423 	case VK_FORMAT_R16G16_SFLOAT:
2424 	case VK_FORMAT_R16G16B16A16_UINT:
2425 	case VK_FORMAT_R16G16B16A16_SINT:
2426 	case VK_FORMAT_R16G16B16A16_SFLOAT:
2427 	case VK_FORMAT_R32_UINT:
2428 	case VK_FORMAT_R32_SINT:
2429 	case VK_FORMAT_R32_SFLOAT:
2430 	case VK_FORMAT_R32G32_UINT:
2431 	case VK_FORMAT_R32G32_SINT:
2432 	case VK_FORMAT_R32G32_SFLOAT:
2433 	case VK_FORMAT_R32G32B32A32_UINT:
2434 	case VK_FORMAT_R32G32B32A32_SINT:
2435 	case VK_FORMAT_R32G32B32A32_SFLOAT:
2436 	case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
2437 	// Optional
2438 	case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
2439 	case VK_FORMAT_A2R10G10B10_UINT_PACK32:
2440 		pFormatProperties->bufferFeatures |=
2441 		    VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT;
2442 		break;
2443 	default:
2444 		break;
2445 	}
2446 
2447 	if(pFormatProperties->optimalTilingFeatures)
2448 	{
2449 		// "Formats that are required to support VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT must also support
2450 		//  VK_FORMAT_FEATURE_TRANSFER_SRC_BIT and VK_FORMAT_FEATURE_TRANSFER_DST_BIT."
2451 		//
2452 		//  Additionally:
2453 		//  "If VK_EXT_host_image_copy is supported and VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT is supported
2454 		//  in optimalTilingFeatures or linearTilingFeatures for a color format,
2455 		//  VK_FORMAT_FEATURE_2_HOST_IMAGE_TRANSFER_BIT_EXT must also be supported in optimalTilingFeatures
2456 		//  or linearTilingFeatures respectively."
2457 
2458 		pFormatProperties->linearTilingFeatures |= VK_FORMAT_FEATURE_TRANSFER_SRC_BIT |
2459 		                                           VK_FORMAT_FEATURE_TRANSFER_DST_BIT |
2460 		                                           VK_FORMAT_FEATURE_2_HOST_IMAGE_TRANSFER_BIT_EXT;
2461 
2462 		if(!format.isCompressed())
2463 		{
2464 			VkFormatFeatureFlagBits2KHR transferableFeatureBits = VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT |
2465 			                                                      VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT |
2466 			                                                      VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_DEPTH_COMPARISON_BIT_KHR;
2467 
2468 			pFormatProperties->linearTilingFeatures |= (pFormatProperties->optimalTilingFeatures & transferableFeatureBits);
2469 		}
2470 	}
2471 }
2472 
getImageFormatProperties(Format format,VkImageType type,VkImageTiling tiling,VkImageUsageFlags usage,VkImageCreateFlags flags,VkImageFormatProperties * pImageFormatProperties) const2473 void PhysicalDevice::getImageFormatProperties(Format format, VkImageType type, VkImageTiling tiling,
2474                                               VkImageUsageFlags usage, VkImageCreateFlags flags,
2475                                               VkImageFormatProperties *pImageFormatProperties) const
2476 {
2477 	pImageFormatProperties->sampleCounts = VK_SAMPLE_COUNT_1_BIT;
2478 	pImageFormatProperties->maxArrayLayers = vk::MAX_IMAGE_ARRAY_LAYERS;
2479 	pImageFormatProperties->maxExtent.depth = 1;
2480 
2481 	switch(type)
2482 	{
2483 	case VK_IMAGE_TYPE_1D:
2484 		pImageFormatProperties->maxMipLevels = vk::MAX_IMAGE_LEVELS_1D;
2485 		pImageFormatProperties->maxExtent.width = 1 << (vk::MAX_IMAGE_LEVELS_1D - 1);
2486 		pImageFormatProperties->maxExtent.height = 1;
2487 		break;
2488 	case VK_IMAGE_TYPE_2D:
2489 		if(flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT)
2490 		{
2491 			pImageFormatProperties->maxMipLevels = vk::MAX_IMAGE_LEVELS_CUBE;
2492 			pImageFormatProperties->maxExtent.width = 1 << (vk::MAX_IMAGE_LEVELS_CUBE - 1);
2493 			pImageFormatProperties->maxExtent.height = 1 << (vk::MAX_IMAGE_LEVELS_CUBE - 1);
2494 		}
2495 		else
2496 		{
2497 			pImageFormatProperties->maxMipLevels = vk::MAX_IMAGE_LEVELS_2D;
2498 			pImageFormatProperties->maxExtent.width = 1 << (vk::MAX_IMAGE_LEVELS_2D - 1);
2499 			pImageFormatProperties->maxExtent.height = 1 << (vk::MAX_IMAGE_LEVELS_2D - 1);
2500 
2501 			VkFormatProperties props;
2502 			GetFormatProperties(format, &props);
2503 			auto features = tiling == VK_IMAGE_TILING_LINEAR ? props.linearTilingFeatures : props.optimalTilingFeatures;
2504 			if(features & (VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT | VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT))
2505 			{
2506 				// Only renderable formats make sense for multisample
2507 				pImageFormatProperties->sampleCounts = getSampleCounts();
2508 			}
2509 		}
2510 		break;
2511 	case VK_IMAGE_TYPE_3D:
2512 		pImageFormatProperties->maxMipLevels = vk::MAX_IMAGE_LEVELS_3D;
2513 		pImageFormatProperties->maxExtent.width = 1 << (vk::MAX_IMAGE_LEVELS_3D - 1);
2514 		pImageFormatProperties->maxExtent.height = 1 << (vk::MAX_IMAGE_LEVELS_3D - 1);
2515 		pImageFormatProperties->maxExtent.depth = 1 << (vk::MAX_IMAGE_LEVELS_3D - 1);
2516 		pImageFormatProperties->maxArrayLayers = 1;  // no 3D + layers
2517 		break;
2518 	default:
2519 		UNREACHABLE("VkImageType: %d", int(type));
2520 		break;
2521 	}
2522 
2523 	pImageFormatProperties->maxResourceSize = 1u << 31;  // Minimum value for maxResourceSize
2524 
2525 	// "Images created with tiling equal to VK_IMAGE_TILING_LINEAR have further restrictions on their limits and capabilities
2526 	//  compared to images created with tiling equal to VK_IMAGE_TILING_OPTIMAL."
2527 	if(tiling == VK_IMAGE_TILING_LINEAR)
2528 	{
2529 		pImageFormatProperties->maxMipLevels = 1;
2530 		pImageFormatProperties->maxArrayLayers = 1;
2531 		pImageFormatProperties->sampleCounts = VK_SAMPLE_COUNT_1_BIT;
2532 	}
2533 
2534 	// "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
2535 	//  have further restrictions on their limits and capabilities compared to images created with other formats."
2536 	if(format.isYcbcrFormat())
2537 	{
2538 		pImageFormatProperties->maxMipLevels = 1;  // TODO(b/151263485): This is relied on by the sampler to disable mipmapping for Y'CbCr image sampling.
2539 		pImageFormatProperties->maxArrayLayers = 1;
2540 		pImageFormatProperties->sampleCounts = VK_SAMPLE_COUNT_1_BIT;
2541 	}
2542 }
2543 
getQueueFamilyPropertyCount() const2544 uint32_t PhysicalDevice::getQueueFamilyPropertyCount() const
2545 {
2546 	return 1;
2547 }
2548 
getQueueFamilyProperties() const2549 VkQueueFamilyProperties PhysicalDevice::getQueueFamilyProperties() const
2550 {
2551 	VkQueueFamilyProperties properties = {};
2552 	properties.minImageTransferGranularity.width = 1;
2553 	properties.minImageTransferGranularity.height = 1;
2554 	properties.minImageTransferGranularity.depth = 1;
2555 	properties.queueCount = 1;
2556 	properties.queueFlags = VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT;
2557 	properties.timestampValidBits = 64;
2558 
2559 	return properties;
2560 }
2561 
getQueueFamilyProperties(uint32_t pQueueFamilyPropertyCount,VkQueueFamilyProperties * pQueueFamilyProperties) const2562 void PhysicalDevice::getQueueFamilyProperties(uint32_t pQueueFamilyPropertyCount,
2563                                               VkQueueFamilyProperties *pQueueFamilyProperties) const
2564 {
2565 	for(uint32_t i = 0; i < pQueueFamilyPropertyCount; i++)
2566 	{
2567 		pQueueFamilyProperties[i] = getQueueFamilyProperties();
2568 	}
2569 }
2570 
getQueueFamilyGlobalPriorityProperties(VkQueueFamilyGlobalPriorityPropertiesKHR * pQueueFamilyGlobalPriorityProperties) const2571 void PhysicalDevice::getQueueFamilyGlobalPriorityProperties(VkQueueFamilyGlobalPriorityPropertiesKHR *pQueueFamilyGlobalPriorityProperties) const
2572 {
2573 	pQueueFamilyGlobalPriorityProperties->priorityCount = 1;
2574 	pQueueFamilyGlobalPriorityProperties->priorities[0] = VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_KHR;
2575 }
2576 
validateQueueGlobalPriority(VkQueueGlobalPriorityKHR queueGlobalPriority) const2577 bool PhysicalDevice::validateQueueGlobalPriority(VkQueueGlobalPriorityKHR queueGlobalPriority) const
2578 {
2579 	VkQueueFamilyGlobalPriorityPropertiesKHR queueFamilyGlobalPriorityProperties;
2580 	getQueueFamilyGlobalPriorityProperties(&queueFamilyGlobalPriorityProperties);
2581 
2582 	for(uint32_t i = 0; i < queueFamilyGlobalPriorityProperties.priorityCount; ++i)
2583 	{
2584 		if(queueGlobalPriority == queueFamilyGlobalPriorityProperties.priorities[i])
2585 		{
2586 			return true;
2587 		}
2588 	}
2589 
2590 	return false;
2591 }
2592 
getQueueFamilyProperties(uint32_t pQueueFamilyPropertyCount,VkQueueFamilyProperties2 * pQueueFamilyProperties) const2593 void PhysicalDevice::getQueueFamilyProperties(uint32_t pQueueFamilyPropertyCount,
2594                                               VkQueueFamilyProperties2 *pQueueFamilyProperties) const
2595 {
2596 	for(uint32_t i = 0; i < pQueueFamilyPropertyCount; i++)
2597 	{
2598 		pQueueFamilyProperties[i].queueFamilyProperties = getQueueFamilyProperties();
2599 
2600 		VkBaseOutStructure *extInfo = reinterpret_cast<VkBaseOutStructure *>(pQueueFamilyProperties[i].pNext);
2601 		while(extInfo)
2602 		{
2603 			switch(extInfo->sType)
2604 			{
2605 			case VK_STRUCTURE_TYPE_QUEUE_FAMILY_GLOBAL_PRIORITY_PROPERTIES_KHR:
2606 				getQueueFamilyGlobalPriorityProperties(reinterpret_cast<VkQueueFamilyGlobalPriorityPropertiesKHR *>(extInfo));
2607 				break;
2608 			default:
2609 				UNSUPPORTED("pQueueFamilyProperties->pNext sType = %s", vk::Stringify(extInfo->sType).c_str());
2610 				break;
2611 			}
2612 
2613 			extInfo = extInfo->pNext;
2614 		}
2615 	}
2616 }
2617 
GetMemoryProperties()2618 const VkPhysicalDeviceMemoryProperties &PhysicalDevice::GetMemoryProperties()
2619 {
2620 	static const VkPhysicalDeviceMemoryProperties properties{
2621 		1,  // memoryTypeCount
2622 		{
2623 		    // vk::MEMORY_TYPE_GENERIC_BIT
2624 		    {
2625 		        (VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
2626 		         VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
2627 		         VK_MEMORY_PROPERTY_HOST_COHERENT_BIT |
2628 		         VK_MEMORY_PROPERTY_HOST_CACHED_BIT),  // propertyFlags
2629 		        0                                      // heapIndex
2630 		    },
2631 		},
2632 		1,  // memoryHeapCount
2633 		{
2634 		    {
2635 		        vk::PHYSICAL_DEVICE_HEAP_SIZE,   // size
2636 		        VK_MEMORY_HEAP_DEVICE_LOCAL_BIT  // flags
2637 		    },
2638 		}
2639 	};
2640 
2641 	return properties;
2642 }
2643 
2644 }  // namespace vk
2645