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