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