1 // Copyright 2018 The Amber Authors.
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 "src/vulkan/device.h"
16
17 #include <cstring>
18 #include <iomanip> // Vulkan wrappers: std::setw(), std::left/right
19 #include <iostream>
20 #include <memory>
21 #include <set>
22 #include <sstream>
23 #include <string>
24 #include <vector>
25
26 #include "src/make_unique.h"
27
28 namespace amber {
29 namespace vulkan {
30 namespace {
31
32 const char kVariablePointers[] = "VariablePointerFeatures.variablePointers";
33 const char kVariablePointersStorageBuffer[] =
34 "VariablePointerFeatures.variablePointersStorageBuffer";
35
36 struct BaseOutStructure {
37 VkStructureType sType;
38 void* pNext;
39 };
40
AreAllRequiredFeaturesSupported(const VkPhysicalDeviceFeatures & available_features,const std::vector<std::string> & required_features)41 bool AreAllRequiredFeaturesSupported(
42 const VkPhysicalDeviceFeatures& available_features,
43 const std::vector<std::string>& required_features) {
44 if (required_features.empty())
45 return true;
46
47 for (const auto& feature : required_features) {
48 if (feature == "robustBufferAccess") {
49 if (available_features.robustBufferAccess == VK_FALSE)
50 return false;
51 continue;
52 }
53 if (feature == "fullDrawIndexUint32") {
54 if (available_features.fullDrawIndexUint32 == VK_FALSE)
55 return false;
56 continue;
57 }
58 if (feature == "imageCubeArray") {
59 if (available_features.imageCubeArray == VK_FALSE)
60 return false;
61 continue;
62 }
63 if (feature == "independentBlend") {
64 if (available_features.independentBlend == VK_FALSE)
65 return false;
66 continue;
67 }
68 if (feature == "geometryShader") {
69 if (available_features.geometryShader == VK_FALSE)
70 return false;
71 continue;
72 }
73 if (feature == "tessellationShader") {
74 if (available_features.tessellationShader == VK_FALSE)
75 return false;
76 continue;
77 }
78 if (feature == "sampleRateShading") {
79 if (available_features.sampleRateShading == VK_FALSE)
80 return false;
81 continue;
82 }
83 if (feature == "dualSrcBlend") {
84 if (available_features.dualSrcBlend == VK_FALSE)
85 return false;
86 continue;
87 }
88 if (feature == "logicOp") {
89 if (available_features.logicOp == VK_FALSE)
90 return false;
91 continue;
92 }
93 if (feature == "multiDrawIndirect") {
94 if (available_features.multiDrawIndirect == VK_FALSE)
95 return false;
96 continue;
97 }
98 if (feature == "drawIndirectFirstInstance") {
99 if (available_features.drawIndirectFirstInstance == VK_FALSE)
100 return false;
101 continue;
102 }
103 if (feature == "depthClamp") {
104 if (available_features.depthClamp == VK_FALSE)
105 return false;
106 continue;
107 }
108 if (feature == "depthBiasClamp") {
109 if (available_features.depthBiasClamp == VK_FALSE)
110 return false;
111 continue;
112 }
113 if (feature == "fillModeNonSolid") {
114 if (available_features.fillModeNonSolid == VK_FALSE)
115 return false;
116 continue;
117 }
118 if (feature == "depthBounds") {
119 if (available_features.depthBounds == VK_FALSE)
120 return false;
121 continue;
122 }
123 if (feature == "wideLines") {
124 if (available_features.wideLines == VK_FALSE)
125 return false;
126 continue;
127 }
128 if (feature == "largePoints") {
129 if (available_features.largePoints == VK_FALSE)
130 return false;
131 continue;
132 }
133 if (feature == "alphaToOne") {
134 if (available_features.alphaToOne == VK_FALSE)
135 return false;
136 continue;
137 }
138 if (feature == "multiViewport") {
139 if (available_features.multiViewport == VK_FALSE)
140 return false;
141 continue;
142 }
143 if (feature == "samplerAnisotropy") {
144 if (available_features.samplerAnisotropy == VK_FALSE)
145 return false;
146 continue;
147 }
148 if (feature == "textureCompressionETC2") {
149 if (available_features.textureCompressionETC2 == VK_FALSE)
150 return false;
151 continue;
152 }
153 if (feature == "textureCompressionASTC_LDR") {
154 if (available_features.textureCompressionASTC_LDR == VK_FALSE)
155 return false;
156 continue;
157 }
158 if (feature == "textureCompressionBC") {
159 if (available_features.textureCompressionBC == VK_FALSE)
160 return false;
161 continue;
162 }
163 if (feature == "occlusionQueryPrecise") {
164 if (available_features.occlusionQueryPrecise == VK_FALSE)
165 return false;
166 continue;
167 }
168 if (feature == "pipelineStatisticsQuery") {
169 if (available_features.pipelineStatisticsQuery == VK_FALSE)
170 return false;
171 continue;
172 }
173 if (feature == "vertexPipelineStoresAndAtomics") {
174 if (available_features.vertexPipelineStoresAndAtomics == VK_FALSE)
175 return false;
176 continue;
177 }
178 if (feature == "fragmentStoresAndAtomics") {
179 if (available_features.fragmentStoresAndAtomics == VK_FALSE)
180 return false;
181 continue;
182 }
183 if (feature == "shaderTessellationAndGeometryPointSize") {
184 if (available_features.shaderTessellationAndGeometryPointSize == VK_FALSE)
185 return false;
186 continue;
187 }
188 if (feature == "shaderImageGatherExtended") {
189 if (available_features.shaderImageGatherExtended == VK_FALSE)
190 return false;
191 continue;
192 }
193 if (feature == "shaderStorageImageExtendedFormats") {
194 if (available_features.shaderStorageImageExtendedFormats == VK_FALSE)
195 return false;
196 continue;
197 }
198 if (feature == "shaderStorageImageMultisample") {
199 if (available_features.shaderStorageImageMultisample == VK_FALSE)
200 return false;
201 continue;
202 }
203 if (feature == "shaderStorageImageReadWithoutFormat") {
204 if (available_features.shaderStorageImageReadWithoutFormat == VK_FALSE)
205 return false;
206 continue;
207 }
208 if (feature == "shaderStorageImageWriteWithoutFormat") {
209 if (available_features.shaderStorageImageWriteWithoutFormat == VK_FALSE)
210 return false;
211 continue;
212 }
213 if (feature == "shaderUniformBufferArrayDynamicIndexing") {
214 if (available_features.shaderUniformBufferArrayDynamicIndexing ==
215 VK_FALSE)
216 return false;
217 continue;
218 }
219 if (feature == "shaderSampledImageArrayDynamicIndexing") {
220 if (available_features.shaderSampledImageArrayDynamicIndexing == VK_FALSE)
221 return false;
222 continue;
223 }
224 if (feature == "shaderStorageBufferArrayDynamicIndexing") {
225 if (available_features.shaderStorageBufferArrayDynamicIndexing ==
226 VK_FALSE)
227 return false;
228 continue;
229 }
230 if (feature == "shaderStorageImageArrayDynamicIndexing") {
231 if (available_features.shaderStorageImageArrayDynamicIndexing == VK_FALSE)
232 return false;
233 continue;
234 }
235 if (feature == "shaderClipDistance") {
236 if (available_features.shaderClipDistance == VK_FALSE)
237 return false;
238 continue;
239 }
240 if (feature == "shaderCullDistance") {
241 if (available_features.shaderCullDistance == VK_FALSE)
242 return false;
243 continue;
244 }
245 if (feature == "shaderFloat64") {
246 if (available_features.shaderFloat64 == VK_FALSE)
247 return false;
248 continue;
249 }
250 if (feature == "shaderInt64") {
251 if (available_features.shaderInt64 == VK_FALSE)
252 return false;
253 continue;
254 }
255 if (feature == "shaderInt16") {
256 if (available_features.shaderInt16 == VK_FALSE)
257 return false;
258 continue;
259 }
260 if (feature == "shaderResourceResidency") {
261 if (available_features.shaderResourceResidency == VK_FALSE)
262 return false;
263 continue;
264 }
265 if (feature == "shaderResourceMinLod") {
266 if (available_features.shaderResourceMinLod == VK_FALSE)
267 return false;
268 continue;
269 }
270 if (feature == "sparseBinding") {
271 if (available_features.sparseBinding == VK_FALSE)
272 return false;
273 continue;
274 }
275 if (feature == "sparseResidencyBuffer") {
276 if (available_features.sparseResidencyBuffer == VK_FALSE)
277 return false;
278 continue;
279 }
280 if (feature == "sparseResidencyImage2D") {
281 if (available_features.sparseResidencyImage2D == VK_FALSE)
282 return false;
283 continue;
284 }
285 if (feature == "sparseResidencyImage3D") {
286 if (available_features.sparseResidencyImage3D == VK_FALSE)
287 return false;
288 continue;
289 }
290 if (feature == "sparseResidency2Samples") {
291 if (available_features.sparseResidency2Samples == VK_FALSE)
292 return false;
293 continue;
294 }
295 if (feature == "sparseResidency4Samples") {
296 if (available_features.sparseResidency4Samples == VK_FALSE)
297 return false;
298 continue;
299 }
300 if (feature == "sparseResidency8Samples") {
301 if (available_features.sparseResidency8Samples == VK_FALSE)
302 return false;
303 continue;
304 }
305 if (feature == "sparseResidency16Samples") {
306 if (available_features.sparseResidency16Samples == VK_FALSE)
307 return false;
308 continue;
309 }
310 if (feature == "sparseResidencyAliased") {
311 if (available_features.sparseResidencyAliased == VK_FALSE)
312 return false;
313 continue;
314 }
315 if (feature == "variableMultisampleRate") {
316 if (available_features.variableMultisampleRate == VK_FALSE)
317 return false;
318 continue;
319 }
320 if (feature == "inheritedQueries") {
321 if (available_features.inheritedQueries == VK_FALSE)
322 return false;
323 continue;
324 }
325 }
326
327 return true;
328 }
329
AreAllExtensionsSupported(const std::vector<std::string> & available_extensions,const std::vector<std::string> & required_extensions)330 bool AreAllExtensionsSupported(
331 const std::vector<std::string>& available_extensions,
332 const std::vector<std::string>& required_extensions) {
333 if (required_extensions.empty())
334 return true;
335
336 std::set<std::string> required_extension_set(required_extensions.begin(),
337 required_extensions.end());
338 for (const auto& extension : available_extensions) {
339 required_extension_set.erase(extension);
340 }
341
342 return required_extension_set.empty();
343 }
344
345 } // namespace
346
Device(VkInstance instance,VkPhysicalDevice physical_device,uint32_t queue_family_index,VkDevice device,VkQueue queue)347 Device::Device(VkInstance instance,
348 VkPhysicalDevice physical_device,
349 uint32_t queue_family_index,
350 VkDevice device,
351 VkQueue queue)
352 : instance_(instance),
353 physical_device_(physical_device),
354 device_(device),
355 queue_(queue),
356 queue_family_index_(queue_family_index) {}
357
358 Device::~Device() = default;
359
LoadVulkanPointers(PFN_vkGetInstanceProcAddr getInstanceProcAddr,Delegate * delegate)360 Result Device::LoadVulkanPointers(PFN_vkGetInstanceProcAddr getInstanceProcAddr,
361 Delegate* delegate) {
362 // Note: logging Vulkan calls is done via the delegate rather than a Vulkan
363 // layer because we want such logging even when Amber is built as a native
364 // executable on Android, where Vulkan layers are usable only with APKs.
365 if (delegate && delegate->LogGraphicsCalls())
366 delegate->Log("Loading Vulkan Pointers");
367
368 #include "vk-wrappers.inc"
369
370 return {};
371 }
372
Initialize(PFN_vkGetInstanceProcAddr getInstanceProcAddr,Delegate * delegate,const std::vector<std::string> & required_features,const std::vector<std::string> & required_extensions,const VkPhysicalDeviceFeatures & available_features,const VkPhysicalDeviceFeatures2KHR & available_features2,const std::vector<std::string> & available_extensions)373 Result Device::Initialize(
374 PFN_vkGetInstanceProcAddr getInstanceProcAddr,
375 Delegate* delegate,
376 const std::vector<std::string>& required_features,
377 const std::vector<std::string>& required_extensions,
378 const VkPhysicalDeviceFeatures& available_features,
379 const VkPhysicalDeviceFeatures2KHR& available_features2,
380 const std::vector<std::string>& available_extensions) {
381 Result r = LoadVulkanPointers(getInstanceProcAddr, delegate);
382 if (!r.IsSuccess())
383 return r;
384
385 bool use_physical_device_features_2 = false;
386 // Determine if VkPhysicalDeviceProperties2KHR should be used
387 for (auto& ext : required_extensions) {
388 if (ext == "VK_KHR_get_physical_device_properties2") {
389 use_physical_device_features_2 = true;
390 }
391 }
392
393 VkPhysicalDeviceFeatures available_vulkan_features =
394 VkPhysicalDeviceFeatures();
395 if (use_physical_device_features_2) {
396 available_vulkan_features = available_features2.features;
397
398 VkPhysicalDeviceVariablePointerFeaturesKHR* var_ptrs = nullptr;
399 void* ptr = available_features2.pNext;
400 while (ptr != nullptr) {
401 BaseOutStructure* s = static_cast<BaseOutStructure*>(ptr);
402 if (s->sType ==
403 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR) {
404 var_ptrs =
405 static_cast<VkPhysicalDeviceVariablePointerFeaturesKHR*>(ptr);
406 break;
407 }
408 ptr = s->pNext;
409 }
410
411 std::vector<std::string> required_features1;
412 for (const auto& feature : required_features) {
413 // No dot means this is a features1 feature.
414 if (feature.find_first_of('.') == std::string::npos) {
415 required_features1.push_back(feature);
416 continue;
417 }
418
419 if ((feature == kVariablePointers ||
420 feature == kVariablePointersStorageBuffer) &&
421 var_ptrs == nullptr) {
422 return amber::Result(
423 "Variable pointers requested but feature not returned");
424 }
425
426 if (feature == kVariablePointers &&
427 var_ptrs->variablePointers != VK_TRUE) {
428 return amber::Result("Missing variable pointers feature");
429 }
430 if (feature == kVariablePointersStorageBuffer &&
431 var_ptrs->variablePointersStorageBuffer != VK_TRUE) {
432 return amber::Result(
433 "Missing variable pointers storage buffer feature");
434 }
435 }
436
437 } else {
438 available_vulkan_features = available_features;
439 }
440
441 if (!AreAllRequiredFeaturesSupported(available_vulkan_features,
442 required_features)) {
443 return Result(
444 "Vulkan: Device::Initialize given physical device does not support "
445 "required features");
446 }
447
448 if (!AreAllExtensionsSupported(available_extensions, required_extensions)) {
449 return Result(
450 "Vulkan: Device::Initialize given physical device does not support "
451 "required extensions");
452 }
453
454 ptrs_.vkGetPhysicalDeviceProperties(physical_device_,
455 &physical_device_properties_);
456
457 ptrs_.vkGetPhysicalDeviceMemoryProperties(physical_device_,
458 &physical_memory_properties_);
459
460 return {};
461 }
462
IsFormatSupportedByPhysicalDevice(const Format & format,Buffer * buffer)463 bool Device::IsFormatSupportedByPhysicalDevice(const Format& format,
464 Buffer* buffer) {
465 VkFormat vk_format = GetVkFormat(format);
466 VkFormatProperties properties = VkFormatProperties();
467 GetPtrs()->vkGetPhysicalDeviceFormatProperties(physical_device_, vk_format,
468 &properties);
469
470 VkFormatFeatureFlagBits flag = VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT;
471 bool is_buffer_type_image = false;
472 switch (buffer->GetBufferType()) {
473 case BufferType::kColor:
474 flag = VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT;
475 is_buffer_type_image = true;
476 break;
477 case BufferType::kDepth:
478 flag = VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT;
479 is_buffer_type_image = true;
480 break;
481 case BufferType::kSampled:
482 flag = VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT;
483 is_buffer_type_image = true;
484 break;
485 case BufferType::kVertex:
486 flag = VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT;
487 is_buffer_type_image = false;
488 break;
489 default:
490 return false;
491 }
492
493 return ((is_buffer_type_image ? properties.optimalTilingFeatures
494 : properties.bufferFeatures) &
495 flag) == flag;
496 }
497
HasMemoryFlags(uint32_t memory_type_index,const VkMemoryPropertyFlags flags) const498 bool Device::HasMemoryFlags(uint32_t memory_type_index,
499 const VkMemoryPropertyFlags flags) const {
500 return (physical_memory_properties_.memoryTypes[memory_type_index]
501 .propertyFlags &
502 flags) == flags;
503 }
504
IsMemoryHostAccessible(uint32_t memory_type_index) const505 bool Device::IsMemoryHostAccessible(uint32_t memory_type_index) const {
506 return HasMemoryFlags(memory_type_index, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
507 }
508
IsMemoryHostCoherent(uint32_t memory_type_index) const509 bool Device::IsMemoryHostCoherent(uint32_t memory_type_index) const {
510 return HasMemoryFlags(memory_type_index,
511 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
512 }
513
GetMaxPushConstants() const514 uint32_t Device::GetMaxPushConstants() const {
515 return physical_device_properties_.limits.maxPushConstantsSize;
516 }
517
IsDescriptorSetInBounds(uint32_t descriptor_set) const518 bool Device::IsDescriptorSetInBounds(uint32_t descriptor_set) const {
519 VkPhysicalDeviceProperties properties = VkPhysicalDeviceProperties();
520 GetPtrs()->vkGetPhysicalDeviceProperties(physical_device_, &properties);
521 return properties.limits.maxBoundDescriptorSets > descriptor_set;
522 }
523
GetVkFormat(const Format & format) const524 VkFormat Device::GetVkFormat(const Format& format) const {
525 VkFormat ret = VK_FORMAT_UNDEFINED;
526 switch (format.GetFormatType()) {
527 case FormatType::kUnknown:
528 ret = VK_FORMAT_UNDEFINED;
529 break;
530 case FormatType::kA1R5G5B5_UNORM_PACK16:
531 ret = VK_FORMAT_A1R5G5B5_UNORM_PACK16;
532 break;
533 case FormatType::kA2B10G10R10_SINT_PACK32:
534 ret = VK_FORMAT_A2B10G10R10_SINT_PACK32;
535 break;
536 case FormatType::kA2B10G10R10_SNORM_PACK32:
537 ret = VK_FORMAT_A2B10G10R10_SNORM_PACK32;
538 break;
539 case FormatType::kA2B10G10R10_SSCALED_PACK32:
540 ret = VK_FORMAT_A2B10G10R10_SSCALED_PACK32;
541 break;
542 case FormatType::kA2B10G10R10_UINT_PACK32:
543 ret = VK_FORMAT_A2B10G10R10_UINT_PACK32;
544 break;
545 case FormatType::kA2B10G10R10_UNORM_PACK32:
546 ret = VK_FORMAT_A2B10G10R10_UNORM_PACK32;
547 break;
548 case FormatType::kA2B10G10R10_USCALED_PACK32:
549 ret = VK_FORMAT_A2B10G10R10_USCALED_PACK32;
550 break;
551 case FormatType::kA2R10G10B10_SINT_PACK32:
552 ret = VK_FORMAT_A2R10G10B10_SINT_PACK32;
553 break;
554 case FormatType::kA2R10G10B10_SNORM_PACK32:
555 ret = VK_FORMAT_A2R10G10B10_SNORM_PACK32;
556 break;
557 case FormatType::kA2R10G10B10_SSCALED_PACK32:
558 ret = VK_FORMAT_A2R10G10B10_SSCALED_PACK32;
559 break;
560 case FormatType::kA2R10G10B10_UINT_PACK32:
561 ret = VK_FORMAT_A2R10G10B10_UINT_PACK32;
562 break;
563 case FormatType::kA2R10G10B10_UNORM_PACK32:
564 ret = VK_FORMAT_A2R10G10B10_UNORM_PACK32;
565 break;
566 case FormatType::kA2R10G10B10_USCALED_PACK32:
567 ret = VK_FORMAT_A2R10G10B10_USCALED_PACK32;
568 break;
569 case FormatType::kA8B8G8R8_SINT_PACK32:
570 ret = VK_FORMAT_A8B8G8R8_SINT_PACK32;
571 break;
572 case FormatType::kA8B8G8R8_SNORM_PACK32:
573 ret = VK_FORMAT_A8B8G8R8_SNORM_PACK32;
574 break;
575 case FormatType::kA8B8G8R8_SRGB_PACK32:
576 ret = VK_FORMAT_A8B8G8R8_SRGB_PACK32;
577 break;
578 case FormatType::kA8B8G8R8_SSCALED_PACK32:
579 ret = VK_FORMAT_A8B8G8R8_SSCALED_PACK32;
580 break;
581 case FormatType::kA8B8G8R8_UINT_PACK32:
582 ret = VK_FORMAT_A8B8G8R8_UINT_PACK32;
583 break;
584 case FormatType::kA8B8G8R8_UNORM_PACK32:
585 ret = VK_FORMAT_A8B8G8R8_UNORM_PACK32;
586 break;
587 case FormatType::kA8B8G8R8_USCALED_PACK32:
588 ret = VK_FORMAT_A8B8G8R8_USCALED_PACK32;
589 break;
590 case FormatType::kB10G11R11_UFLOAT_PACK32:
591 ret = VK_FORMAT_B10G11R11_UFLOAT_PACK32;
592 break;
593 case FormatType::kB4G4R4A4_UNORM_PACK16:
594 ret = VK_FORMAT_B4G4R4A4_UNORM_PACK16;
595 break;
596 case FormatType::kB5G5R5A1_UNORM_PACK16:
597 ret = VK_FORMAT_B5G5R5A1_UNORM_PACK16;
598 break;
599 case FormatType::kB5G6R5_UNORM_PACK16:
600 ret = VK_FORMAT_B5G6R5_UNORM_PACK16;
601 break;
602 case FormatType::kB8G8R8A8_SINT:
603 ret = VK_FORMAT_B8G8R8A8_SINT;
604 break;
605 case FormatType::kB8G8R8A8_SNORM:
606 ret = VK_FORMAT_B8G8R8A8_SNORM;
607 break;
608 case FormatType::kB8G8R8A8_SRGB:
609 ret = VK_FORMAT_B8G8R8A8_SRGB;
610 break;
611 case FormatType::kB8G8R8A8_SSCALED:
612 ret = VK_FORMAT_B8G8R8A8_SSCALED;
613 break;
614 case FormatType::kB8G8R8A8_UINT:
615 ret = VK_FORMAT_B8G8R8A8_UINT;
616 break;
617 case FormatType::kB8G8R8A8_UNORM:
618 ret = VK_FORMAT_B8G8R8A8_UNORM;
619 break;
620 case FormatType::kB8G8R8A8_USCALED:
621 ret = VK_FORMAT_B8G8R8A8_USCALED;
622 break;
623 case FormatType::kB8G8R8_SINT:
624 ret = VK_FORMAT_B8G8R8_SINT;
625 break;
626 case FormatType::kB8G8R8_SNORM:
627 ret = VK_FORMAT_B8G8R8_SNORM;
628 break;
629 case FormatType::kB8G8R8_SRGB:
630 ret = VK_FORMAT_B8G8R8_SRGB;
631 break;
632 case FormatType::kB8G8R8_SSCALED:
633 ret = VK_FORMAT_B8G8R8_SSCALED;
634 break;
635 case FormatType::kB8G8R8_UINT:
636 ret = VK_FORMAT_B8G8R8_UINT;
637 break;
638 case FormatType::kB8G8R8_UNORM:
639 ret = VK_FORMAT_B8G8R8_UNORM;
640 break;
641 case FormatType::kB8G8R8_USCALED:
642 ret = VK_FORMAT_B8G8R8_USCALED;
643 break;
644 case FormatType::kD16_UNORM:
645 ret = VK_FORMAT_D16_UNORM;
646 break;
647 case FormatType::kD16_UNORM_S8_UINT:
648 ret = VK_FORMAT_D16_UNORM_S8_UINT;
649 break;
650 case FormatType::kD24_UNORM_S8_UINT:
651 ret = VK_FORMAT_D24_UNORM_S8_UINT;
652 break;
653 case FormatType::kD32_SFLOAT:
654 ret = VK_FORMAT_D32_SFLOAT;
655 break;
656 case FormatType::kD32_SFLOAT_S8_UINT:
657 ret = VK_FORMAT_D32_SFLOAT_S8_UINT;
658 break;
659 case FormatType::kR16G16B16A16_SFLOAT:
660 ret = VK_FORMAT_R16G16B16A16_SFLOAT;
661 break;
662 case FormatType::kR16G16B16A16_SINT:
663 ret = VK_FORMAT_R16G16B16A16_SINT;
664 break;
665 case FormatType::kR16G16B16A16_SNORM:
666 ret = VK_FORMAT_R16G16B16A16_SNORM;
667 break;
668 case FormatType::kR16G16B16A16_SSCALED:
669 ret = VK_FORMAT_R16G16B16A16_SSCALED;
670 break;
671 case FormatType::kR16G16B16A16_UINT:
672 ret = VK_FORMAT_R16G16B16A16_UINT;
673 break;
674 case FormatType::kR16G16B16A16_UNORM:
675 ret = VK_FORMAT_R16G16B16A16_UNORM;
676 break;
677 case FormatType::kR16G16B16A16_USCALED:
678 ret = VK_FORMAT_R16G16B16A16_USCALED;
679 break;
680 case FormatType::kR16G16B16_SFLOAT:
681 ret = VK_FORMAT_R16G16B16_SFLOAT;
682 break;
683 case FormatType::kR16G16B16_SINT:
684 ret = VK_FORMAT_R16G16B16_SINT;
685 break;
686 case FormatType::kR16G16B16_SNORM:
687 ret = VK_FORMAT_R16G16B16_SNORM;
688 break;
689 case FormatType::kR16G16B16_SSCALED:
690 ret = VK_FORMAT_R16G16B16_SSCALED;
691 break;
692 case FormatType::kR16G16B16_UINT:
693 ret = VK_FORMAT_R16G16B16_UINT;
694 break;
695 case FormatType::kR16G16B16_UNORM:
696 ret = VK_FORMAT_R16G16B16_UNORM;
697 break;
698 case FormatType::kR16G16B16_USCALED:
699 ret = VK_FORMAT_R16G16B16_USCALED;
700 break;
701 case FormatType::kR16G16_SFLOAT:
702 ret = VK_FORMAT_R16G16_SFLOAT;
703 break;
704 case FormatType::kR16G16_SINT:
705 ret = VK_FORMAT_R16G16_SINT;
706 break;
707 case FormatType::kR16G16_SNORM:
708 ret = VK_FORMAT_R16G16_SNORM;
709 break;
710 case FormatType::kR16G16_SSCALED:
711 ret = VK_FORMAT_R16G16_SSCALED;
712 break;
713 case FormatType::kR16G16_UINT:
714 ret = VK_FORMAT_R16G16_UINT;
715 break;
716 case FormatType::kR16G16_UNORM:
717 ret = VK_FORMAT_R16G16_UNORM;
718 break;
719 case FormatType::kR16G16_USCALED:
720 ret = VK_FORMAT_R16G16_USCALED;
721 break;
722 case FormatType::kR16_SFLOAT:
723 ret = VK_FORMAT_R16_SFLOAT;
724 break;
725 case FormatType::kR16_SINT:
726 ret = VK_FORMAT_R16_SINT;
727 break;
728 case FormatType::kR16_SNORM:
729 ret = VK_FORMAT_R16_SNORM;
730 break;
731 case FormatType::kR16_SSCALED:
732 ret = VK_FORMAT_R16_SSCALED;
733 break;
734 case FormatType::kR16_UINT:
735 ret = VK_FORMAT_R16_UINT;
736 break;
737 case FormatType::kR16_UNORM:
738 ret = VK_FORMAT_R16_UNORM;
739 break;
740 case FormatType::kR16_USCALED:
741 ret = VK_FORMAT_R16_USCALED;
742 break;
743 case FormatType::kR32G32B32A32_SFLOAT:
744 ret = VK_FORMAT_R32G32B32A32_SFLOAT;
745 break;
746 case FormatType::kR32G32B32A32_SINT:
747 ret = VK_FORMAT_R32G32B32A32_SINT;
748 break;
749 case FormatType::kR32G32B32A32_UINT:
750 ret = VK_FORMAT_R32G32B32A32_UINT;
751 break;
752 case FormatType::kR32G32B32_SFLOAT:
753 ret = VK_FORMAT_R32G32B32_SFLOAT;
754 break;
755 case FormatType::kR32G32B32_SINT:
756 ret = VK_FORMAT_R32G32B32_SINT;
757 break;
758 case FormatType::kR32G32B32_UINT:
759 ret = VK_FORMAT_R32G32B32_UINT;
760 break;
761 case FormatType::kR32G32_SFLOAT:
762 ret = VK_FORMAT_R32G32_SFLOAT;
763 break;
764 case FormatType::kR32G32_SINT:
765 ret = VK_FORMAT_R32G32_SINT;
766 break;
767 case FormatType::kR32G32_UINT:
768 ret = VK_FORMAT_R32G32_UINT;
769 break;
770 case FormatType::kR32_SFLOAT:
771 ret = VK_FORMAT_R32_SFLOAT;
772 break;
773 case FormatType::kR32_SINT:
774 ret = VK_FORMAT_R32_SINT;
775 break;
776 case FormatType::kR32_UINT:
777 ret = VK_FORMAT_R32_UINT;
778 break;
779 case FormatType::kR4G4B4A4_UNORM_PACK16:
780 ret = VK_FORMAT_R4G4B4A4_UNORM_PACK16;
781 break;
782 case FormatType::kR4G4_UNORM_PACK8:
783 ret = VK_FORMAT_R4G4_UNORM_PACK8;
784 break;
785 case FormatType::kR5G5B5A1_UNORM_PACK16:
786 ret = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
787 break;
788 case FormatType::kR5G6B5_UNORM_PACK16:
789 ret = VK_FORMAT_R5G6B5_UNORM_PACK16;
790 break;
791 case FormatType::kR64G64B64A64_SFLOAT:
792 ret = VK_FORMAT_R64G64B64A64_SFLOAT;
793 break;
794 case FormatType::kR64G64B64A64_SINT:
795 ret = VK_FORMAT_R64G64B64A64_SINT;
796 break;
797 case FormatType::kR64G64B64A64_UINT:
798 ret = VK_FORMAT_R64G64B64A64_UINT;
799 break;
800 case FormatType::kR64G64B64_SFLOAT:
801 ret = VK_FORMAT_R64G64B64_SFLOAT;
802 break;
803 case FormatType::kR64G64B64_SINT:
804 ret = VK_FORMAT_R64G64B64_SINT;
805 break;
806 case FormatType::kR64G64B64_UINT:
807 ret = VK_FORMAT_R64G64B64_UINT;
808 break;
809 case FormatType::kR64G64_SFLOAT:
810 ret = VK_FORMAT_R64G64_SFLOAT;
811 break;
812 case FormatType::kR64G64_SINT:
813 ret = VK_FORMAT_R64G64_SINT;
814 break;
815 case FormatType::kR64G64_UINT:
816 ret = VK_FORMAT_R64G64_UINT;
817 break;
818 case FormatType::kR64_SFLOAT:
819 ret = VK_FORMAT_R64_SFLOAT;
820 break;
821 case FormatType::kR64_SINT:
822 ret = VK_FORMAT_R64_SINT;
823 break;
824 case FormatType::kR64_UINT:
825 ret = VK_FORMAT_R64_UINT;
826 break;
827 case FormatType::kR8G8B8A8_SINT:
828 ret = VK_FORMAT_R8G8B8A8_SINT;
829 break;
830 case FormatType::kR8G8B8A8_SNORM:
831 ret = VK_FORMAT_R8G8B8A8_SNORM;
832 break;
833 case FormatType::kR8G8B8A8_SRGB:
834 ret = VK_FORMAT_R8G8B8A8_SRGB;
835 break;
836 case FormatType::kR8G8B8A8_SSCALED:
837 ret = VK_FORMAT_R8G8B8A8_SSCALED;
838 break;
839 case FormatType::kR8G8B8A8_UINT:
840 ret = VK_FORMAT_R8G8B8A8_UINT;
841 break;
842 case FormatType::kR8G8B8A8_UNORM:
843 ret = VK_FORMAT_R8G8B8A8_UNORM;
844 break;
845 case FormatType::kR8G8B8A8_USCALED:
846 ret = VK_FORMAT_R8G8B8A8_USCALED;
847 break;
848 case FormatType::kR8G8B8_SINT:
849 ret = VK_FORMAT_R8G8B8_SINT;
850 break;
851 case FormatType::kR8G8B8_SNORM:
852 ret = VK_FORMAT_R8G8B8_SNORM;
853 break;
854 case FormatType::kR8G8B8_SRGB:
855 ret = VK_FORMAT_R8G8B8_SRGB;
856 break;
857 case FormatType::kR8G8B8_SSCALED:
858 ret = VK_FORMAT_R8G8B8_SSCALED;
859 break;
860 case FormatType::kR8G8B8_UINT:
861 ret = VK_FORMAT_R8G8B8_UINT;
862 break;
863 case FormatType::kR8G8B8_UNORM:
864 ret = VK_FORMAT_R8G8B8_UNORM;
865 break;
866 case FormatType::kR8G8B8_USCALED:
867 ret = VK_FORMAT_R8G8B8_USCALED;
868 break;
869 case FormatType::kR8G8_SINT:
870 ret = VK_FORMAT_R8G8_SINT;
871 break;
872 case FormatType::kR8G8_SNORM:
873 ret = VK_FORMAT_R8G8_SNORM;
874 break;
875 case FormatType::kR8G8_SRGB:
876 ret = VK_FORMAT_R8G8_SRGB;
877 break;
878 case FormatType::kR8G8_SSCALED:
879 ret = VK_FORMAT_R8G8_SSCALED;
880 break;
881 case FormatType::kR8G8_UINT:
882 ret = VK_FORMAT_R8G8_UINT;
883 break;
884 case FormatType::kR8G8_UNORM:
885 ret = VK_FORMAT_R8G8_UNORM;
886 break;
887 case FormatType::kR8G8_USCALED:
888 ret = VK_FORMAT_R8G8_USCALED;
889 break;
890 case FormatType::kR8_SINT:
891 ret = VK_FORMAT_R8_SINT;
892 break;
893 case FormatType::kR8_SNORM:
894 ret = VK_FORMAT_R8_SNORM;
895 break;
896 case FormatType::kR8_SRGB:
897 ret = VK_FORMAT_R8_SRGB;
898 break;
899 case FormatType::kR8_SSCALED:
900 ret = VK_FORMAT_R8_SSCALED;
901 break;
902 case FormatType::kR8_UINT:
903 ret = VK_FORMAT_R8_UINT;
904 break;
905 case FormatType::kR8_UNORM:
906 ret = VK_FORMAT_R8_UNORM;
907 break;
908 case FormatType::kR8_USCALED:
909 ret = VK_FORMAT_R8_USCALED;
910 break;
911 case FormatType::kS8_UINT:
912 ret = VK_FORMAT_S8_UINT;
913 break;
914 case FormatType::kX8_D24_UNORM_PACK32:
915 ret = VK_FORMAT_X8_D24_UNORM_PACK32;
916 break;
917 }
918 return ret;
919 }
920
921 } // namespace vulkan
922 } // namespace amber
923