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