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 #include "VkConfig.h"
17
18 #include <cstring>
19
20 namespace vk
21 {
22
PhysicalDevice(const void *,void * mem)23 PhysicalDevice::PhysicalDevice(const void*, void* mem)
24 {
25 }
26
getFeatures() const27 const VkPhysicalDeviceFeatures& PhysicalDevice::getFeatures() const
28 {
29 static const VkPhysicalDeviceFeatures features
30 {
31 true, // robustBufferAccess
32 false, // fullDrawIndexUint32
33 false, // imageCubeArray
34 false, // independentBlend
35 false, // geometryShader
36 false, // tessellationShader
37 false, // sampleRateShading
38 false, // dualSrcBlend
39 false, // logicOp
40 false, // multiDrawIndirect
41 false, // drawIndirectFirstInstance
42 false, // depthClamp
43 false, // depthBiasClamp
44 false, // fillModeNonSolid
45 false, // depthBounds
46 false, // wideLines
47 false, // largePoints
48 false, // alphaToOne
49 false, // multiViewport
50 false, // samplerAnisotropy
51 true, // textureCompressionETC2
52 false, // textureCompressionASTC_LDR
53 false, // textureCompressionBC
54 false, // occlusionQueryPrecise
55 false, // pipelineStatisticsQuery
56 false, // vertexPipelineStoresAndAtomics
57 false, // fragmentStoresAndAtomics
58 false, // shaderTessellationAndGeometryPointSize
59 false, // shaderImageGatherExtended
60 false, // shaderStorageImageExtendedFormats
61 false, // shaderStorageImageMultisample
62 false, // shaderStorageImageReadWithoutFormat
63 false, // shaderStorageImageWriteWithoutFormat
64 false, // shaderUniformBufferArrayDynamicIndexing
65 false, // shaderSampledImageArrayDynamicIndexing
66 false, // shaderStorageBufferArrayDynamicIndexing
67 false, // shaderStorageImageArrayDynamicIndexing
68 false, // shaderClipDistance
69 false, // shaderCullDistance
70 false, // shaderFloat64
71 false, // shaderInt64
72 false, // shaderInt16
73 false, // shaderResourceResidency
74 false, // shaderResourceMinLod
75 false, // sparseBinding
76 false, // sparseResidencyBuffer
77 false, // sparseResidencyImage2D
78 false, // sparseResidencyImage3D
79 false, // sparseResidency2Samples
80 false, // sparseResidency4Samples
81 false, // sparseResidency8Samples
82 false, // sparseResidency16Samples
83 false, // sparseResidencyAliased
84 false, // variableMultisampleRate
85 false, // inheritedQueries
86 };
87
88 return features;
89 }
90
getFeatures(VkPhysicalDeviceSamplerYcbcrConversionFeatures * features) const91 void PhysicalDevice::getFeatures(VkPhysicalDeviceSamplerYcbcrConversionFeatures* features) const
92 {
93 features->samplerYcbcrConversion = VK_FALSE;
94 }
95
getFeatures(VkPhysicalDevice16BitStorageFeatures * features) const96 void PhysicalDevice::getFeatures(VkPhysicalDevice16BitStorageFeatures* features) const
97 {
98 features->storageBuffer16BitAccess = VK_FALSE;
99 features->storageInputOutput16 = VK_FALSE;
100 features->storagePushConstant16 = VK_FALSE;
101 features->uniformAndStorageBuffer16BitAccess = VK_FALSE;
102 }
103
getFeatures(VkPhysicalDeviceVariablePointerFeatures * features) const104 void PhysicalDevice::getFeatures(VkPhysicalDeviceVariablePointerFeatures* features) const
105 {
106 features->variablePointersStorageBuffer = VK_FALSE;
107 features->variablePointers = VK_FALSE;
108 }
109
getFeatures(VkPhysicalDevice8BitStorageFeaturesKHR * features) const110 void PhysicalDevice::getFeatures(VkPhysicalDevice8BitStorageFeaturesKHR* features) const
111 {
112 features->storageBuffer8BitAccess = VK_FALSE;
113 features->uniformAndStorageBuffer8BitAccess = VK_FALSE;
114 features->storagePushConstant8 = VK_FALSE;
115 }
116
getFeatures(VkPhysicalDeviceMultiviewFeatures * features) const117 void PhysicalDevice::getFeatures(VkPhysicalDeviceMultiviewFeatures* features) const
118 {
119 features->multiview = VK_FALSE;
120 features->multiviewGeometryShader = VK_FALSE;
121 features->multiviewTessellationShader = VK_FALSE;
122 }
123
getFeatures(VkPhysicalDeviceProtectedMemoryFeatures * features) const124 void PhysicalDevice::getFeatures(VkPhysicalDeviceProtectedMemoryFeatures* features) const
125 {
126 features->protectedMemory = VK_FALSE;
127 }
128
getSampleCounts() const129 VkSampleCountFlags PhysicalDevice::getSampleCounts() const
130 {
131 return VK_SAMPLE_COUNT_1_BIT | VK_SAMPLE_COUNT_4_BIT;
132 }
133
getLimits() const134 const VkPhysicalDeviceLimits& PhysicalDevice::getLimits() const
135 {
136 VkSampleCountFlags sampleCounts = getSampleCounts();
137
138 static const VkPhysicalDeviceLimits limits =
139 {
140 (1 << vk::MAX_IMAGE_LEVELS_1D), // maxImageDimension1D
141 (1 << vk::MAX_IMAGE_LEVELS_2D), // maxImageDimension2D
142 (1 << vk::MAX_IMAGE_LEVELS_3D), // maxImageDimension3D
143 (1 << vk::MAX_IMAGE_LEVELS_CUBE), // maxImageDimensionCube
144 (1 << vk::MAX_IMAGE_ARRAY_LAYERS), // maxImageArrayLayers
145 65536, // maxTexelBufferElements
146 16384, // maxUniformBufferRange
147 (1ul << 27), // maxStorageBufferRange
148 128, // maxPushConstantsSize
149 4096, // maxMemoryAllocationCount
150 4000, // maxSamplerAllocationCount
151 131072, // bufferImageGranularity
152 0, // sparseAddressSpaceSize (unsupported)
153 4, // maxBoundDescriptorSets
154 16, // maxPerStageDescriptorSamplers
155 12, // maxPerStageDescriptorUniformBuffers
156 4, // maxPerStageDescriptorStorageBuffers
157 16, // maxPerStageDescriptorSampledImages
158 4, // maxPerStageDescriptorStorageImages
159 4, // maxPerStageDescriptorInputAttachments
160 128, // maxPerStageResources
161 96, // maxDescriptorSetSamplers
162 72, // maxDescriptorSetUniformBuffers
163 8, // maxDescriptorSetUniformBuffersDynamic
164 24, // maxDescriptorSetStorageBuffers
165 4, // maxDescriptorSetStorageBuffersDynamic
166 96, // maxDescriptorSetSampledImages
167 24, // maxDescriptorSetStorageImages
168 4, // maxDescriptorSetInputAttachments
169 16, // maxVertexInputAttributes
170 vk::MAX_VERTEX_INPUT_BINDINGS, // maxVertexInputBindings
171 2047, // maxVertexInputAttributeOffset
172 2048, // maxVertexInputBindingStride
173 64, // maxVertexOutputComponents
174 0, // maxTessellationGenerationLevel (unsupported)
175 0, // maxTessellationPatchSize (unsupported)
176 0, // maxTessellationControlPerVertexInputComponents (unsupported)
177 0, // maxTessellationControlPerVertexOutputComponents (unsupported)
178 0, // maxTessellationControlPerPatchOutputComponents (unsupported)
179 0, // maxTessellationControlTotalOutputComponents (unsupported)
180 0, // maxTessellationEvaluationInputComponents (unsupported)
181 0, // maxTessellationEvaluationOutputComponents (unsupported)
182 0, // maxGeometryShaderInvocations (unsupported)
183 0, // maxGeometryInputComponents (unsupported)
184 0, // maxGeometryOutputComponents (unsupported)
185 0, // maxGeometryOutputVertices (unsupported)
186 0, // maxGeometryTotalOutputComponents (unsupported)
187 64, // maxFragmentInputComponents
188 4, // maxFragmentOutputAttachments
189 1, // maxFragmentDualSrcAttachments
190 4, // maxFragmentCombinedOutputResources
191 16384, // maxComputeSharedMemorySize
192 { 65535, 65535, 65535 }, // maxComputeWorkGroupCount[3]
193 128, // maxComputeWorkGroupInvocations
194 { 128, 128, 64, }, // maxComputeWorkGroupSize[3]
195 4, // subPixelPrecisionBits
196 4, // subTexelPrecisionBits
197 4, // mipmapPrecisionBits
198 UINT32_MAX, // maxDrawIndexedIndexValue
199 UINT32_MAX, // maxDrawIndirectCount
200 2, // maxSamplerLodBias
201 16, // maxSamplerAnisotropy
202 16, // maxViewports
203 { 4096, 4096 }, // maxViewportDimensions[2]
204 { -8192, 8191 }, // viewportBoundsRange[2]
205 0, // viewportSubPixelBits
206 64, // minMemoryMapAlignment
207 vk::MIN_TEXEL_BUFFER_OFFSET_ALIGNMENT, // minTexelBufferOffsetAlignment
208 vk::MIN_UNIFORM_BUFFER_OFFSET_ALIGNMENT, // minUniformBufferOffsetAlignment
209 vk::MIN_STORAGE_BUFFER_OFFSET_ALIGNMENT, // minStorageBufferOffsetAlignment
210 -8, // minTexelOffset
211 7, // maxTexelOffset
212 -8, // minTexelGatherOffset
213 7, // maxTexelGatherOffset
214 -0.5, // minInterpolationOffset
215 0.5, // maxInterpolationOffset
216 4, // subPixelInterpolationOffsetBits
217 4096, // maxFramebufferWidth
218 4096, // maxFramebufferHeight
219 256, // maxFramebufferLayers
220 sampleCounts, // framebufferColorSampleCounts
221 sampleCounts, // framebufferDepthSampleCounts
222 sampleCounts, // framebufferStencilSampleCounts
223 sampleCounts, // framebufferNoAttachmentsSampleCounts
224 4, // maxColorAttachments
225 sampleCounts, // sampledImageColorSampleCounts
226 VK_SAMPLE_COUNT_1_BIT, // sampledImageIntegerSampleCounts
227 sampleCounts, // sampledImageDepthSampleCounts
228 sampleCounts, // sampledImageStencilSampleCounts
229 VK_SAMPLE_COUNT_1_BIT, // storageImageSampleCounts (unsupported)
230 1, // maxSampleMaskWords
231 false, // timestampComputeAndGraphics
232 60, // timestampPeriod
233 8, // maxClipDistances
234 8, // maxCullDistances
235 8, // maxCombinedClipAndCullDistances
236 2, // discreteQueuePriorities
237 { 1.0, 64.0 }, // pointSizeRange[2]
238 { 1.0, 1.0 }, // lineWidthRange[2] (unsupported)
239 0.0, // pointSizeGranularity (unsupported)
240 0.0, // lineWidthGranularity (unsupported)
241 false, // strictLines
242 true, // standardSampleLocations
243 64, // optimalBufferCopyOffsetAlignment
244 64, // optimalBufferCopyRowPitchAlignment
245 256, // nonCoherentAtomSize
246 };
247
248 return limits;
249 }
250
getProperties() const251 const VkPhysicalDeviceProperties& PhysicalDevice::getProperties() const
252 {
253 static const VkPhysicalDeviceProperties properties
254 {
255 API_VERSION,
256 DRIVER_VERSION,
257 VENDOR_ID,
258 DEVICE_ID,
259 VK_PHYSICAL_DEVICE_TYPE_CPU, // deviceType
260 SWIFTSHADER_DEVICE_NAME, // deviceName
261 SWIFTSHADER_UUID, // pipelineCacheUUID
262 getLimits(), // limits
263 { 0 } // sparseProperties
264 };
265
266 return properties;
267 }
268
getProperties(VkPhysicalDeviceIDProperties * properties) const269 void PhysicalDevice::getProperties(VkPhysicalDeviceIDProperties* properties) const
270 {
271 memset(properties->deviceUUID, 0, VK_UUID_SIZE);
272 memset(properties->driverUUID, 0, VK_UUID_SIZE);
273 memset(properties->deviceLUID, 0, VK_LUID_SIZE);
274
275 memcpy(properties->deviceUUID, SWIFTSHADER_UUID, VK_UUID_SIZE);
276 *((uint64_t*)properties->driverUUID) = DRIVER_VERSION;
277
278 properties->deviceNodeMask = 0;
279 properties->deviceLUIDValid = VK_FALSE;
280 }
281
getProperties(VkPhysicalDeviceMaintenance3Properties * properties) const282 void PhysicalDevice::getProperties(VkPhysicalDeviceMaintenance3Properties* properties) const
283 {
284 properties->maxMemoryAllocationSize = 1 << 31;
285 properties->maxPerSetDescriptors = 1024;
286 }
287
getProperties(VkPhysicalDeviceMultiviewProperties * properties) const288 void PhysicalDevice::getProperties(VkPhysicalDeviceMultiviewProperties* properties) const
289 {
290 properties->maxMultiviewViewCount = 0;
291 properties->maxMultiviewInstanceIndex = 0;
292 }
293
getProperties(VkPhysicalDevicePointClippingProperties * properties) const294 void PhysicalDevice::getProperties(VkPhysicalDevicePointClippingProperties* properties) const
295 {
296 properties->pointClippingBehavior = VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES;
297 }
298
getProperties(VkPhysicalDeviceProtectedMemoryProperties * properties) const299 void PhysicalDevice::getProperties(VkPhysicalDeviceProtectedMemoryProperties* properties) const
300 {
301 properties->protectedNoFault = VK_FALSE;
302 }
303
getProperties(VkPhysicalDeviceSubgroupProperties * properties) const304 void PhysicalDevice::getProperties(VkPhysicalDeviceSubgroupProperties* properties) const
305 {
306 properties->subgroupSize = 1;
307 properties->supportedStages = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT | VK_SHADER_STAGE_COMPUTE_BIT;
308 properties->supportedOperations = VK_SUBGROUP_FEATURE_BASIC_BIT;
309 properties->quadOperationsInAllStages = VK_FALSE;
310 }
311
hasFeatures(const VkPhysicalDeviceFeatures & requestedFeatures) const312 bool PhysicalDevice::hasFeatures(const VkPhysicalDeviceFeatures& requestedFeatures) const
313 {
314 const VkPhysicalDeviceFeatures& supportedFeatures = getFeatures();
315 const VkBool32* supportedFeature = reinterpret_cast<const VkBool32*>(&supportedFeatures);
316 const VkBool32* requestedFeature = reinterpret_cast<const VkBool32*>(&requestedFeatures);
317 constexpr auto featureCount = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
318
319 for(unsigned int i = 0; i < featureCount; i++)
320 {
321 if((requestedFeature[i] == VK_TRUE) && (supportedFeature[i] != VK_TRUE))
322 {
323 return false;
324 }
325 }
326
327 return true;
328 }
329
getFormatProperties(VkFormat format,VkFormatProperties * pFormatProperties) const330 void PhysicalDevice::getFormatProperties(VkFormat format, VkFormatProperties* pFormatProperties) const
331 {
332 pFormatProperties->linearTilingFeatures = 0; // Unsupported format
333 pFormatProperties->optimalTilingFeatures = 0; // Unsupported format
334 pFormatProperties->bufferFeatures = 0; // Unsupported format
335
336 switch(format)
337 {
338 case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
339 case VK_FORMAT_R5G6B5_UNORM_PACK16:
340 case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
341 case VK_FORMAT_R8_UNORM:
342 case VK_FORMAT_R8_SNORM:
343 case VK_FORMAT_R8G8_UNORM:
344 case VK_FORMAT_R8G8_SNORM:
345 case VK_FORMAT_R8G8B8A8_UNORM:
346 case VK_FORMAT_R8G8B8A8_SNORM:
347 case VK_FORMAT_R8G8B8A8_SRGB:
348 case VK_FORMAT_B8G8R8A8_UNORM:
349 case VK_FORMAT_B8G8R8A8_SRGB:
350 case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
351 case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
352 case VK_FORMAT_A8B8G8R8_SRGB_PACK32:
353 case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
354 case VK_FORMAT_R16_SFLOAT:
355 case VK_FORMAT_R16G16_SFLOAT:
356 case VK_FORMAT_R16G16B16A16_SFLOAT:
357 case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
358 case VK_FORMAT_E5B9G9R9_UFLOAT_PACK32:
359 pFormatProperties->optimalTilingFeatures |=
360 VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT;
361 // Fall through
362 case VK_FORMAT_R8_UINT:
363 case VK_FORMAT_R8_SINT:
364 case VK_FORMAT_R8G8_UINT:
365 case VK_FORMAT_R8G8_SINT:
366 case VK_FORMAT_R8G8B8A8_UINT:
367 case VK_FORMAT_R8G8B8A8_SINT:
368 case VK_FORMAT_A8B8G8R8_UINT_PACK32:
369 case VK_FORMAT_A8B8G8R8_SINT_PACK32:
370 case VK_FORMAT_A2B10G10R10_UINT_PACK32:
371 case VK_FORMAT_R16_UINT:
372 case VK_FORMAT_R16_SINT:
373 case VK_FORMAT_R16G16_UINT:
374 case VK_FORMAT_R16G16_SINT:
375 case VK_FORMAT_R16G16B16A16_UINT:
376 case VK_FORMAT_R16G16B16A16_SINT:
377 case VK_FORMAT_R32_UINT:
378 case VK_FORMAT_R32_SINT:
379 case VK_FORMAT_R32_SFLOAT:
380 case VK_FORMAT_R32G32_UINT:
381 case VK_FORMAT_R32G32_SINT:
382 case VK_FORMAT_R32G32_SFLOAT:
383 case VK_FORMAT_R32G32B32A32_UINT:
384 case VK_FORMAT_R32G32B32A32_SINT:
385 case VK_FORMAT_R32G32B32A32_SFLOAT:
386 case VK_FORMAT_D16_UNORM:
387 case VK_FORMAT_D32_SFLOAT:
388 pFormatProperties->optimalTilingFeatures |=
389 VK_FORMAT_FEATURE_BLIT_SRC_BIT |
390 VK_FORMAT_FEATURE_TRANSFER_SRC_BIT |
391 VK_FORMAT_FEATURE_TRANSFER_DST_BIT;
392 // Fall through
393 case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
394 case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:
395 case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK:
396 case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:
397 case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK:
398 case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK:
399 case VK_FORMAT_EAC_R11_UNORM_BLOCK:
400 case VK_FORMAT_EAC_R11_SNORM_BLOCK:
401 case VK_FORMAT_EAC_R11G11_UNORM_BLOCK:
402 case VK_FORMAT_EAC_R11G11_SNORM_BLOCK:
403 pFormatProperties->optimalTilingFeatures |=
404 VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT;
405 break;
406 }
407
408 switch(format)
409 {
410 case VK_FORMAT_R32_UINT:
411 case VK_FORMAT_R32_SINT:
412 pFormatProperties->optimalTilingFeatures |=
413 VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT;
414 pFormatProperties->bufferFeatures |=
415 VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT;
416 // Fall through
417 case VK_FORMAT_R8G8B8A8_UNORM:
418 case VK_FORMAT_R8G8B8A8_SNORM:
419 case VK_FORMAT_R8G8B8A8_UINT:
420 case VK_FORMAT_R8G8B8A8_SINT:
421 case VK_FORMAT_R16G16B16A16_UINT:
422 case VK_FORMAT_R16G16B16A16_SINT:
423 case VK_FORMAT_R16G16B16A16_SFLOAT:
424 case VK_FORMAT_R32_SFLOAT:
425 case VK_FORMAT_R32G32_UINT:
426 case VK_FORMAT_R32G32_SINT:
427 case VK_FORMAT_R32G32_SFLOAT:
428 case VK_FORMAT_R32G32B32A32_UINT:
429 case VK_FORMAT_R32G32B32A32_SINT:
430 case VK_FORMAT_R32G32B32A32_SFLOAT:
431 pFormatProperties->optimalTilingFeatures |=
432 VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT;
433 // Fall through
434 case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
435 case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
436 case VK_FORMAT_A8B8G8R8_UINT_PACK32:
437 case VK_FORMAT_A8B8G8R8_SINT_PACK32:
438 pFormatProperties->bufferFeatures |=
439 VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT;
440 break;
441 }
442
443 switch(format)
444 {
445 case VK_FORMAT_R5G6B5_UNORM_PACK16:
446 case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
447 case VK_FORMAT_R8_UNORM:
448 case VK_FORMAT_R8G8_UNORM:
449 case VK_FORMAT_R8G8B8A8_UNORM:
450 case VK_FORMAT_R8G8B8A8_SRGB:
451 case VK_FORMAT_B8G8R8A8_UNORM:
452 case VK_FORMAT_B8G8R8A8_SRGB:
453 case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
454 case VK_FORMAT_A8B8G8R8_SRGB_PACK32:
455 case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
456 case VK_FORMAT_R16_SFLOAT:
457 case VK_FORMAT_R16G16_SFLOAT:
458 case VK_FORMAT_R16G16B16A16_SFLOAT:
459 pFormatProperties->optimalTilingFeatures |=
460 VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT;
461 // Fall through
462 case VK_FORMAT_R8_UINT:
463 case VK_FORMAT_R8_SINT:
464 case VK_FORMAT_R8G8_UINT:
465 case VK_FORMAT_R8G8_SINT:
466 case VK_FORMAT_R8G8B8A8_UINT:
467 case VK_FORMAT_R8G8B8A8_SINT:
468 case VK_FORMAT_A8B8G8R8_UINT_PACK32:
469 case VK_FORMAT_A8B8G8R8_SINT_PACK32:
470 case VK_FORMAT_A2B10G10R10_UINT_PACK32:
471 case VK_FORMAT_R16_UINT:
472 case VK_FORMAT_R16_SINT:
473 case VK_FORMAT_R16G16_UINT:
474 case VK_FORMAT_R16G16_SINT:
475 case VK_FORMAT_R16G16B16A16_UINT:
476 case VK_FORMAT_R16G16B16A16_SINT:
477 case VK_FORMAT_R32_UINT:
478 case VK_FORMAT_R32_SINT:
479 case VK_FORMAT_R32_SFLOAT:
480 case VK_FORMAT_R32G32_UINT:
481 case VK_FORMAT_R32G32_SINT:
482 case VK_FORMAT_R32G32_SFLOAT:
483 case VK_FORMAT_R32G32B32A32_UINT:
484 case VK_FORMAT_R32G32B32A32_SINT:
485 case VK_FORMAT_R32G32B32A32_SFLOAT:
486 pFormatProperties->optimalTilingFeatures |=
487 VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT |
488 VK_FORMAT_FEATURE_BLIT_DST_BIT;
489 break;
490 case VK_FORMAT_D16_UNORM:
491 case VK_FORMAT_D32_SFLOAT: // Note: either VK_FORMAT_D32_SFLOAT or VK_FORMAT_X8_D24_UNORM_PACK32 must be supported
492 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
493 pFormatProperties->optimalTilingFeatures |=
494 VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT;
495 break;
496 }
497
498 switch(format)
499 {
500 case VK_FORMAT_R8_UNORM:
501 case VK_FORMAT_R8_SNORM:
502 case VK_FORMAT_R8_UINT:
503 case VK_FORMAT_R8_SINT:
504 case VK_FORMAT_R8G8_UNORM:
505 case VK_FORMAT_R8G8_SNORM:
506 case VK_FORMAT_R8G8_UINT:
507 case VK_FORMAT_R8G8_SINT:
508 case VK_FORMAT_R8G8B8A8_UNORM:
509 case VK_FORMAT_R8G8B8A8_SNORM:
510 case VK_FORMAT_R8G8B8A8_UINT:
511 case VK_FORMAT_R8G8B8A8_SINT:
512 case VK_FORMAT_B8G8R8A8_UNORM:
513 case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
514 case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
515 case VK_FORMAT_A8B8G8R8_UINT_PACK32:
516 case VK_FORMAT_A8B8G8R8_SINT_PACK32:
517 case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
518 case VK_FORMAT_R16_UNORM:
519 case VK_FORMAT_R16_SNORM:
520 case VK_FORMAT_R16_UINT:
521 case VK_FORMAT_R16_SINT:
522 case VK_FORMAT_R16_SFLOAT:
523 case VK_FORMAT_R16G16_UNORM:
524 case VK_FORMAT_R16G16_SNORM:
525 case VK_FORMAT_R16G16_UINT:
526 case VK_FORMAT_R16G16_SINT:
527 case VK_FORMAT_R16G16_SFLOAT:
528 case VK_FORMAT_R16G16B16A16_UNORM:
529 case VK_FORMAT_R16G16B16A16_SNORM:
530 case VK_FORMAT_R16G16B16A16_UINT:
531 case VK_FORMAT_R16G16B16A16_SINT:
532 case VK_FORMAT_R16G16B16A16_SFLOAT:
533 case VK_FORMAT_R32_UINT:
534 case VK_FORMAT_R32_SINT:
535 case VK_FORMAT_R32_SFLOAT:
536 case VK_FORMAT_R32G32_UINT:
537 case VK_FORMAT_R32G32_SINT:
538 case VK_FORMAT_R32G32_SFLOAT:
539 case VK_FORMAT_R32G32B32_UINT:
540 case VK_FORMAT_R32G32B32_SINT:
541 case VK_FORMAT_R32G32B32_SFLOAT:
542 case VK_FORMAT_R32G32B32A32_UINT:
543 case VK_FORMAT_R32G32B32A32_SINT:
544 case VK_FORMAT_R32G32B32A32_SFLOAT:
545 pFormatProperties->bufferFeatures |=
546 VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT;
547 break;
548 }
549
550 switch(format)
551 {
552 case VK_FORMAT_R8_UNORM:
553 case VK_FORMAT_R8_SNORM:
554 case VK_FORMAT_R8_UINT:
555 case VK_FORMAT_R8_SINT:
556 case VK_FORMAT_R8G8_UNORM:
557 case VK_FORMAT_R8G8_SNORM:
558 case VK_FORMAT_R8G8_UINT:
559 case VK_FORMAT_R8G8_SINT:
560 case VK_FORMAT_R8G8B8A8_UNORM:
561 case VK_FORMAT_R8G8B8A8_SNORM:
562 case VK_FORMAT_R8G8B8A8_UINT:
563 case VK_FORMAT_R8G8B8A8_SINT:
564 case VK_FORMAT_B8G8R8A8_UNORM:
565 case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
566 case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
567 case VK_FORMAT_A8B8G8R8_UINT_PACK32:
568 case VK_FORMAT_A8B8G8R8_SINT_PACK32:
569 case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
570 case VK_FORMAT_A2B10G10R10_UINT_PACK32:
571 case VK_FORMAT_R16_UINT:
572 case VK_FORMAT_R16_SINT:
573 case VK_FORMAT_R16_SFLOAT:
574 case VK_FORMAT_R16G16_UINT:
575 case VK_FORMAT_R16G16_SINT:
576 case VK_FORMAT_R16G16_SFLOAT:
577 case VK_FORMAT_R16G16B16A16_UINT:
578 case VK_FORMAT_R16G16B16A16_SINT:
579 case VK_FORMAT_R16G16B16A16_SFLOAT:
580 case VK_FORMAT_R32_UINT:
581 case VK_FORMAT_R32_SINT:
582 case VK_FORMAT_R32_SFLOAT:
583 case VK_FORMAT_R32G32_UINT:
584 case VK_FORMAT_R32G32_SINT:
585 case VK_FORMAT_R32G32_SFLOAT:
586 case VK_FORMAT_R32G32B32A32_UINT:
587 case VK_FORMAT_R32G32B32A32_SINT:
588 case VK_FORMAT_R32G32B32A32_SFLOAT:
589 case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
590 pFormatProperties->bufferFeatures |=
591 VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT;
592 break;
593 }
594 }
595
getImageFormatProperties(VkFormat format,VkImageType type,VkImageTiling tiling,VkImageUsageFlags usage,VkImageCreateFlags flags,VkImageFormatProperties * pImageFormatProperties) const596 void PhysicalDevice::getImageFormatProperties(VkFormat format, VkImageType type, VkImageTiling tiling,
597 VkImageUsageFlags usage, VkImageCreateFlags flags,
598 VkImageFormatProperties* pImageFormatProperties) const
599 {
600 pImageFormatProperties->maxArrayLayers = 1 << vk::MAX_IMAGE_ARRAY_LAYERS;
601
602 switch(type)
603 {
604 case VK_IMAGE_TYPE_1D:
605 pImageFormatProperties->maxMipLevels = vk::MAX_IMAGE_LEVELS_1D;
606 pImageFormatProperties->maxExtent.width = 1 << vk::MAX_IMAGE_LEVELS_1D;
607 pImageFormatProperties->maxExtent.height = 1;
608 pImageFormatProperties->maxExtent.depth = 1;
609 break;
610 case VK_IMAGE_TYPE_2D:
611 if(flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT)
612 {
613 pImageFormatProperties->maxMipLevels = vk::MAX_IMAGE_LEVELS_CUBE;
614 pImageFormatProperties->maxExtent.width = 1 << vk::MAX_IMAGE_LEVELS_CUBE;
615 pImageFormatProperties->maxExtent.height = 1 << vk::MAX_IMAGE_LEVELS_CUBE;
616 pImageFormatProperties->maxExtent.depth = 1;
617 }
618 else
619 {
620 pImageFormatProperties->maxMipLevels = vk::MAX_IMAGE_LEVELS_2D;
621 pImageFormatProperties->maxExtent.width = 1 << vk::MAX_IMAGE_LEVELS_2D;
622 pImageFormatProperties->maxExtent.height = 1 << vk::MAX_IMAGE_LEVELS_2D;
623 pImageFormatProperties->maxExtent.depth = 1;
624 }
625 break;
626 case VK_IMAGE_TYPE_3D:
627 pImageFormatProperties->maxMipLevels = vk::MAX_IMAGE_LEVELS_3D;
628 pImageFormatProperties->maxExtent.width = 1 << vk::MAX_IMAGE_LEVELS_3D;
629 pImageFormatProperties->maxExtent.height = 1 << vk::MAX_IMAGE_LEVELS_3D;
630 pImageFormatProperties->maxExtent.depth = 1 << vk::MAX_IMAGE_LEVELS_3D;
631 break;
632 default:
633 UNREACHABLE(type);
634 break;
635 }
636
637 pImageFormatProperties->maxResourceSize = 1 << 31; // Minimum value for maxResourceSize
638 pImageFormatProperties->sampleCounts = getSampleCounts();
639
640 }
641
getQueueFamilyPropertyCount() const642 uint32_t PhysicalDevice::getQueueFamilyPropertyCount() const
643 {
644 return 1;
645 }
646
getQueueFamilyProperties(uint32_t pQueueFamilyPropertyCount,VkQueueFamilyProperties * pQueueFamilyProperties) const647 void PhysicalDevice::getQueueFamilyProperties(uint32_t pQueueFamilyPropertyCount,
648 VkQueueFamilyProperties* pQueueFamilyProperties) const
649 {
650 for(uint32_t i = 0; i < pQueueFamilyPropertyCount; i++)
651 {
652 pQueueFamilyProperties[i].minImageTransferGranularity.width = 1;
653 pQueueFamilyProperties[i].minImageTransferGranularity.height = 1;
654 pQueueFamilyProperties[i].minImageTransferGranularity.depth = 1;
655 pQueueFamilyProperties[i].queueCount = 1;
656 pQueueFamilyProperties[i].queueFlags = VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT;
657 pQueueFamilyProperties[i].timestampValidBits = 0; // No support for time stamps
658 }
659 }
660
getMemoryProperties() const661 const VkPhysicalDeviceMemoryProperties& PhysicalDevice::getMemoryProperties() const
662 {
663 static const VkPhysicalDeviceMemoryProperties properties
664 {
665 1, // memoryTypeCount
666 {
667 // vk::MEMORY_TYPE_GENERIC_BIT
668 {
669 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
670 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
671 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT |
672 VK_MEMORY_PROPERTY_HOST_CACHED_BIT, // propertyFlags
673 0 // heapIndex
674 },
675 },
676 1, // memoryHeapCount
677 {
678 {
679 1ull << 31, // size, FIXME(sugoi): This should be configurable based on available RAM
680 VK_MEMORY_HEAP_DEVICE_LOCAL_BIT // flags
681 },
682 }
683 };
684
685 return properties;
686 }
687
688 } // namespace vk
689