OSDN Git Service

Disable surface and swapchain support for Android
[android-x86/external-swiftshader.git] / src / Vulkan / libVulkan.cpp
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 "VkBuffer.hpp"
16 #include "VkBufferView.hpp"
17 #include "VkCommandBuffer.hpp"
18 #include "VkCommandPool.hpp"
19 #include "VkConfig.h"
20 #include "VkDebug.hpp"
21 #include "VkDescriptorPool.hpp"
22 #include "VkDescriptorSetLayout.hpp"
23 #include "VkDescriptorUpdateTemplate.hpp"
24 #include "VkDestroy.h"
25 #include "VkDevice.hpp"
26 #include "VkDeviceMemory.hpp"
27 #include "VkEvent.hpp"
28 #include "VkFence.hpp"
29 #include "VkFramebuffer.hpp"
30 #include "VkGetProcAddress.h"
31 #include "VkImage.hpp"
32 #include "VkImageView.hpp"
33 #include "VkInstance.hpp"
34 #include "VkPhysicalDevice.hpp"
35 #include "VkPipeline.hpp"
36 #include "VkPipelineCache.hpp"
37 #include "VkPipelineLayout.hpp"
38 #include "VkQueryPool.hpp"
39 #include "VkQueue.hpp"
40 #include "VkSampler.hpp"
41 #include "VkSemaphore.hpp"
42 #include "VkShaderModule.hpp"
43 #include "VkRenderPass.hpp"
44
45 #ifdef VK_USE_PLATFORM_XLIB_KHR
46 #include "WSI/XlibSurfaceKHR.hpp"
47 #endif
48
49 #include "WSI/VkSwapchainKHR.hpp"
50
51 #include <algorithm>
52 #include <cstring>
53 #include <string>
54
55 namespace
56 {
57
58 bool HasExtensionProperty(const char* extensionName, const VkExtensionProperties* extensionProperties, uint32_t extensionPropertiesCount)
59 {
60         for(uint32_t j = 0; j < extensionPropertiesCount; ++j)
61         {
62                 if(strcmp(extensionName, extensionProperties[j].extensionName) == 0)
63                 {
64                         return true;
65                 }
66         }
67
68         return false;
69 }
70
71 }
72
73 extern "C"
74 {
75 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetInstanceProcAddr(VkInstance instance, const char* pName)
76 {
77         TRACE("(VkInstance instance = 0x%X, const char* pName = 0x%X)", instance, pName);
78
79         return vk::GetInstanceProcAddr(instance, pName);
80 }
81
82 VKAPI_ATTR VkResult VKAPI_CALL vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion)
83 {
84         *pSupportedVersion = 3;
85         return VK_SUCCESS;
86 }
87
88 static const VkExtensionProperties instanceExtensionProperties[] =
89 {
90         { VK_KHR_DEVICE_GROUP_CREATION_EXTENSION_NAME, VK_KHR_DEVICE_GROUP_CREATION_SPEC_VERSION },
91         { VK_KHR_EXTERNAL_FENCE_CAPABILITIES_EXTENSION_NAME, VK_KHR_EXTERNAL_FENCE_CAPABILITIES_SPEC_VERSION },
92         { VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME, VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_SPEC_VERSION },
93         { VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME, VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_SPEC_VERSION },
94         { VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_SPEC_VERSION },
95 #ifndef __ANDROID__
96         { VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_SURFACE_SPEC_VERSION },
97 #endif
98 #ifdef VK_USE_PLATFORM_XLIB_KHR
99         { VK_KHR_XLIB_SURFACE_EXTENSION_NAME, VK_KHR_XLIB_SURFACE_SPEC_VERSION },
100 #endif
101 };
102
103 static const VkExtensionProperties deviceExtensionProperties[] =
104 {
105         { VK_KHR_16BIT_STORAGE_EXTENSION_NAME, VK_KHR_16BIT_STORAGE_SPEC_VERSION },
106         { VK_KHR_BIND_MEMORY_2_EXTENSION_NAME, VK_KHR_BIND_MEMORY_2_SPEC_VERSION },
107         { VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME, VK_KHR_DEDICATED_ALLOCATION_SPEC_VERSION },
108         { VK_KHR_DESCRIPTOR_UPDATE_TEMPLATE_EXTENSION_NAME, VK_KHR_DESCRIPTOR_UPDATE_TEMPLATE_SPEC_VERSION },
109         { VK_KHR_DEVICE_GROUP_EXTENSION_NAME,  VK_KHR_DEVICE_GROUP_SPEC_VERSION },
110         { VK_KHR_EXTERNAL_FENCE_EXTENSION_NAME, VK_KHR_EXTERNAL_FENCE_SPEC_VERSION },
111         { VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME, VK_KHR_EXTERNAL_MEMORY_SPEC_VERSION },
112         { VK_KHR_EXTERNAL_SEMAPHORE_EXTENSION_NAME, VK_KHR_EXTERNAL_SEMAPHORE_SPEC_VERSION },
113         { VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME, VK_KHR_GET_MEMORY_REQUIREMENTS_2_SPEC_VERSION },
114         { VK_KHR_MAINTENANCE1_EXTENSION_NAME, VK_KHR_MAINTENANCE1_SPEC_VERSION },
115         { VK_KHR_MAINTENANCE2_EXTENSION_NAME, VK_KHR_MAINTENANCE2_SPEC_VERSION },
116         { VK_KHR_MAINTENANCE3_EXTENSION_NAME, VK_KHR_MAINTENANCE3_SPEC_VERSION },
117         { VK_KHR_MULTIVIEW_EXTENSION_NAME, VK_KHR_MULTIVIEW_SPEC_VERSION },
118         { VK_KHR_RELAXED_BLOCK_LAYOUT_EXTENSION_NAME, VK_KHR_RELAXED_BLOCK_LAYOUT_SPEC_VERSION },
119         { VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME, VK_KHR_SAMPLER_YCBCR_CONVERSION_SPEC_VERSION },
120         { VK_KHR_SHADER_DRAW_PARAMETERS_EXTENSION_NAME, VK_KHR_SHADER_DRAW_PARAMETERS_SPEC_VERSION },
121         { VK_KHR_STORAGE_BUFFER_STORAGE_CLASS_EXTENSION_NAME, VK_KHR_STORAGE_BUFFER_STORAGE_CLASS_SPEC_VERSION },
122         { VK_KHR_VARIABLE_POINTERS_EXTENSION_NAME, VK_KHR_VARIABLE_POINTERS_SPEC_VERSION },
123 #ifndef __ANDROID__
124         { VK_KHR_SWAPCHAIN_EXTENSION_NAME, VK_KHR_SWAPCHAIN_SPEC_VERSION },
125 #endif
126 };
127
128 VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance)
129 {
130         TRACE("(const VkInstanceCreateInfo* pCreateInfo = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X, VkInstance* pInstance = 0x%X)",
131                         pCreateInfo, pAllocator, pInstance);
132
133         if(pCreateInfo->enabledLayerCount)
134         {
135                 UNIMPLEMENTED("pCreateInfo->enabledLayerCount");
136         }
137
138         uint32_t extensionPropertiesCount = sizeof(instanceExtensionProperties) / sizeof(instanceExtensionProperties[0]);
139         for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; ++i)
140         {
141                 if (!HasExtensionProperty(pCreateInfo->ppEnabledExtensionNames[i], instanceExtensionProperties, extensionPropertiesCount))
142                 {
143                         return VK_ERROR_EXTENSION_NOT_PRESENT;
144                 }
145         }
146
147         if(pCreateInfo->pNext)
148         {
149                 switch(*reinterpret_cast<const VkStructureType*>(pCreateInfo->pNext))
150                 {
151                 case VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO:
152                         // According to the Vulkan spec, section 2.7.2. Implicit Valid Usage:
153                         // "The values VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO and
154                         //  VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO are reserved for
155                         //  internal use by the loader, and do not have corresponding
156                         //  Vulkan structures in this Specification."
157                         break;
158                 default:
159                         UNIMPLEMENTED("pCreateInfo->pNext");
160                 }
161         }
162
163         *pInstance = VK_NULL_HANDLE;
164         VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
165
166         VkResult result = vk::DispatchablePhysicalDevice::Create(pAllocator, pCreateInfo, &physicalDevice);
167         if(result != VK_SUCCESS)
168         {
169                 return result;
170         }
171
172         vk::Instance::CreateInfo info =
173         {
174                 pCreateInfo,
175                 physicalDevice
176         };
177
178         result = vk::DispatchableInstance::Create(pAllocator, &info, pInstance);
179         if(result != VK_SUCCESS)
180         {
181                 vk::destroy(physicalDevice, pAllocator);
182                 return result;
183         }
184
185         return result;
186 }
187
188 VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator)
189 {
190         TRACE("(VkInstance instance = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X)", instance, pAllocator);
191
192         vk::destroy(instance, pAllocator);
193 }
194
195 VKAPI_ATTR VkResult VKAPI_CALL vkEnumeratePhysicalDevices(VkInstance instance, uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices)
196 {
197         TRACE("(VkInstance instance = 0x%X, uint32_t* pPhysicalDeviceCount = 0x%X, VkPhysicalDevice* pPhysicalDevices = 0x%X)",
198                     instance, pPhysicalDeviceCount, pPhysicalDevices);
199
200         if(!pPhysicalDevices)
201         {
202                 *pPhysicalDeviceCount = vk::Cast(instance)->getPhysicalDeviceCount();
203         }
204         else
205         {
206                 vk::Cast(instance)->getPhysicalDevices(*pPhysicalDeviceCount, pPhysicalDevices);
207         }
208
209         return VK_SUCCESS;
210 }
211
212 VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures* pFeatures)
213 {
214         TRACE("(VkPhysicalDevice physicalDevice = 0x%X, VkPhysicalDeviceFeatures* pFeatures = 0x%X)",
215                         physicalDevice, pFeatures);
216
217         *pFeatures = vk::Cast(physicalDevice)->getFeatures();
218 }
219
220 VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkFormatProperties* pFormatProperties)
221 {
222         TRACE("GetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice = 0x%X, VkFormat format = %d, VkFormatProperties* pFormatProperties = 0x%X)",
223                         physicalDevice, (int)format, pFormatProperties);
224
225         vk::Cast(physicalDevice)->getFormatProperties(format, pFormatProperties);
226 }
227
228 VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, VkImageFormatProperties* pImageFormatProperties)
229 {
230         TRACE("(VkPhysicalDevice physicalDevice = 0x%X, VkFormat format = %d, VkImageType type = %d, VkImageTiling tiling = %d, VkImageUsageFlags usage = %d, VkImageCreateFlags flags = %d, VkImageFormatProperties* pImageFormatProperties = 0x%X)",
231                         physicalDevice, (int)format, (int)type, (int)tiling, usage, flags, pImageFormatProperties);
232
233         VkFormatProperties properties;
234         vk::Cast(physicalDevice)->getFormatProperties(format, &properties);
235
236         switch (tiling)
237         {
238         case VK_IMAGE_TILING_LINEAR:
239                 if (properties.linearTilingFeatures == 0) return VK_ERROR_FORMAT_NOT_SUPPORTED;
240                 break;
241
242         case VK_IMAGE_TILING_OPTIMAL:
243                 if (properties.optimalTilingFeatures == 0) return VK_ERROR_FORMAT_NOT_SUPPORTED;
244                 break;
245
246         default:
247                 UNIMPLEMENTED("tiling");
248         }
249
250         vk::Cast(physicalDevice)->getImageFormatProperties(format, type, tiling, usage, flags, pImageFormatProperties);
251
252         return VK_SUCCESS;
253 }
254
255 VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties* pProperties)
256 {
257         TRACE("(VkPhysicalDevice physicalDevice = 0x%X, VkPhysicalDeviceProperties* pProperties = 0x%X)",
258                     physicalDevice, pProperties);
259
260         *pProperties = vk::Cast(physicalDevice)->getProperties();
261 }
262
263 VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, uint32_t* pQueueFamilyPropertyCount, VkQueueFamilyProperties* pQueueFamilyProperties)
264 {
265         TRACE("(VkPhysicalDevice physicalDevice = 0x%X, uint32_t* pQueueFamilyPropertyCount = 0x%X, VkQueueFamilyProperties* pQueueFamilyProperties = 0x%X))", physicalDevice, pQueueFamilyPropertyCount, pQueueFamilyProperties);
266
267         if(!pQueueFamilyProperties)
268         {
269                 *pQueueFamilyPropertyCount = vk::Cast(physicalDevice)->getQueueFamilyPropertyCount();
270         }
271         else
272         {
273                 vk::Cast(physicalDevice)->getQueueFamilyProperties(*pQueueFamilyPropertyCount, pQueueFamilyProperties);
274         }
275 }
276
277 VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceMemoryProperties* pMemoryProperties)
278 {
279         TRACE("(VkPhysicalDevice physicalDevice = 0x%X, VkPhysicalDeviceMemoryProperties* pMemoryProperties = 0x%X)", physicalDevice, pMemoryProperties);
280
281         *pMemoryProperties = vk::Cast(physicalDevice)->getMemoryProperties();
282 }
283
284 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* pName)
285 {
286         TRACE("(VkInstance instance = 0x%X, const char* pName = 0x%X)", instance, pName);
287
288         return vk::GetInstanceProcAddr(instance, pName);
289 }
290
291 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice device, const char* pName)
292 {
293         TRACE("(VkDevice device = 0x%X, const char* pName = 0x%X)", device, pName);
294
295         return vk::GetDeviceProcAddr(device, pName);
296 }
297
298 VKAPI_ATTR VkResult VKAPI_CALL vkCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDevice* pDevice)
299 {
300         TRACE("(VkPhysicalDevice physicalDevice = 0x%X, const VkDeviceCreateInfo* pCreateInfo = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X, VkDevice* pDevice = 0x%X)",
301                 physicalDevice, pCreateInfo, pAllocator, pDevice);
302
303         if(pCreateInfo->enabledLayerCount)
304         {
305                 // "The ppEnabledLayerNames and enabledLayerCount members of VkDeviceCreateInfo are deprecated and their values must be ignored by implementations."
306                 UNIMPLEMENTED("pCreateInfo->enabledLayerCount");   // TODO(b/119321052): UNIMPLEMENTED() should be used only for features that must still be implemented. Use a more informational macro here.
307         }
308
309         uint32_t extensionPropertiesCount = sizeof(deviceExtensionProperties) / sizeof(deviceExtensionProperties[0]);
310         for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; ++i)
311         {
312                 if (!HasExtensionProperty(pCreateInfo->ppEnabledExtensionNames[i], deviceExtensionProperties, extensionPropertiesCount))
313                 {
314                         return VK_ERROR_EXTENSION_NOT_PRESENT;
315                 }
316         }
317
318         const VkBaseInStructure* extensionCreateInfo = reinterpret_cast<const VkBaseInStructure*>(pCreateInfo->pNext);
319
320         while(extensionCreateInfo)
321         {
322                 switch(extensionCreateInfo->sType)
323                 {
324                 case VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO:
325                         // According to the Vulkan spec, section 2.7.2. Implicit Valid Usage:
326                         // "The values VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO and
327                         //  VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO are reserved for
328                         //  internal use by the loader, and do not have corresponding
329                         //  Vulkan structures in this Specification."
330                         break;
331                 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2:
332                         {
333                                 ASSERT(!pCreateInfo->pEnabledFeatures);   // "If the pNext chain includes a VkPhysicalDeviceFeatures2 structure, then pEnabledFeatures must be NULL"
334
335                                 const VkPhysicalDeviceFeatures2* physicalDeviceFeatures2 = reinterpret_cast<const VkPhysicalDeviceFeatures2*>(extensionCreateInfo);
336
337                                 if(!vk::Cast(physicalDevice)->hasFeatures(physicalDeviceFeatures2->features))
338                                 {
339                                         return VK_ERROR_FEATURE_NOT_PRESENT;
340                                 }
341                         }
342                         break;
343                 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES:
344                         {
345                                 const VkPhysicalDeviceSamplerYcbcrConversionFeatures* samplerYcbcrConversionFeatures = reinterpret_cast<const VkPhysicalDeviceSamplerYcbcrConversionFeatures*>(extensionCreateInfo);
346
347                                 if(samplerYcbcrConversionFeatures->samplerYcbcrConversion == VK_TRUE)
348                                 {
349                                         return VK_ERROR_FEATURE_NOT_PRESENT;
350                                 }
351                         }
352                         break;
353                 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES:
354                         {
355                                 const VkPhysicalDevice16BitStorageFeatures* storage16BitFeatures = reinterpret_cast<const VkPhysicalDevice16BitStorageFeatures*>(extensionCreateInfo);
356
357                                 if(storage16BitFeatures->storageBuffer16BitAccess == VK_TRUE ||
358                                    storage16BitFeatures->uniformAndStorageBuffer16BitAccess == VK_TRUE ||
359                                    storage16BitFeatures->storagePushConstant16 == VK_TRUE ||
360                                    storage16BitFeatures->storageInputOutput16 == VK_TRUE)
361                                 {
362                                         return VK_ERROR_FEATURE_NOT_PRESENT;
363                                 }
364                         }
365                         break;
366                 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES:
367                         {
368                                 const VkPhysicalDeviceVariablePointerFeatures* variablePointerFeatures = reinterpret_cast<const VkPhysicalDeviceVariablePointerFeatures*>(extensionCreateInfo);
369
370                                 if(variablePointerFeatures->variablePointersStorageBuffer == VK_TRUE ||
371                                    variablePointerFeatures->variablePointers == VK_TRUE)
372                                 {
373                                         return VK_ERROR_FEATURE_NOT_PRESENT;
374                                 }
375                         }
376                         break;
377                 case VK_STRUCTURE_TYPE_DEVICE_GROUP_DEVICE_CREATE_INFO:
378                         {
379                                 const VkDeviceGroupDeviceCreateInfo* groupDeviceCreateInfo = reinterpret_cast<const VkDeviceGroupDeviceCreateInfo*>(extensionCreateInfo);
380
381                                 if((groupDeviceCreateInfo->physicalDeviceCount != 1) ||
382                                    (groupDeviceCreateInfo->pPhysicalDevices[0] != physicalDevice))
383                                 {
384                                         return VK_ERROR_FEATURE_NOT_PRESENT;
385                                 }
386                         }
387                         break;
388                 default:
389                         // "the [driver] must skip over, without processing (other than reading the sType and pNext members) any structures in the chain with sType values not defined by [supported extenions]"
390                         UNIMPLEMENTED("extensionCreateInfo->sType");   // TODO(b/119321052): UNIMPLEMENTED() should be used only for features that must still be implemented. Use a more informational macro here.
391                         break;
392                 }
393
394                 extensionCreateInfo = extensionCreateInfo->pNext;
395         }
396
397         ASSERT(pCreateInfo->queueCreateInfoCount > 0);
398
399         if(pCreateInfo->pEnabledFeatures)
400         {
401                 if(!vk::Cast(physicalDevice)->hasFeatures(*(pCreateInfo->pEnabledFeatures)))
402                 {
403                         UNIMPLEMENTED("pCreateInfo->pEnabledFeatures");
404                         return VK_ERROR_FEATURE_NOT_PRESENT;
405                 }
406         }
407
408         uint32_t queueFamilyPropertyCount = vk::Cast(physicalDevice)->getQueueFamilyPropertyCount();
409
410         for(uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; i++)
411         {
412                 const VkDeviceQueueCreateInfo& queueCreateInfo = pCreateInfo->pQueueCreateInfos[i];
413                 if(queueCreateInfo.pNext || queueCreateInfo.flags)
414                 {
415                         UNIMPLEMENTED("queueCreateInfo.pNext || queueCreateInfo.flags");
416                 }
417
418                 ASSERT(queueCreateInfo.queueFamilyIndex < queueFamilyPropertyCount);
419                 (void)queueFamilyPropertyCount; // Silence unused variable warning
420         }
421
422         vk::Device::CreateInfo deviceCreateInfo =
423         {
424                 pCreateInfo,
425                 physicalDevice
426         };
427
428         return vk::DispatchableDevice::Create(pAllocator, &deviceCreateInfo, pDevice);
429 }
430
431 VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator)
432 {
433         TRACE("(VkDevice device = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X)", device, pAllocator);
434
435         vk::destroy(device, pAllocator);
436 }
437
438 VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char* pLayerName, uint32_t* pPropertyCount, VkExtensionProperties* pProperties)
439 {
440         TRACE("(const char* pLayerName = 0x%X, uint32_t* pPropertyCount = 0x%X, VkExtensionProperties* pProperties = 0x%X)",
441               pLayerName, pPropertyCount, pProperties);
442
443         uint32_t extensionPropertiesCount = sizeof(instanceExtensionProperties) / sizeof(instanceExtensionProperties[0]);
444
445         if(!pProperties)
446         {
447                 *pPropertyCount = extensionPropertiesCount;
448                 return VK_SUCCESS;
449         }
450
451         for(uint32_t i = 0; i < std::min(*pPropertyCount, extensionPropertiesCount); i++)
452         {
453                 pProperties[i] = instanceExtensionProperties[i];
454         }
455
456         return (*pPropertyCount < extensionPropertiesCount) ? VK_INCOMPLETE : VK_SUCCESS;
457 }
458
459 VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char* pLayerName, uint32_t* pPropertyCount, VkExtensionProperties* pProperties)
460 {
461         TRACE("(VkPhysicalDevice physicalDevice = 0x%X, const char* pLayerName, uint32_t* pPropertyCount = 0x%X, VkExtensionProperties* pProperties = 0x%X)", physicalDevice, pPropertyCount, pProperties);
462
463         uint32_t extensionPropertiesCount = sizeof(deviceExtensionProperties) / sizeof(deviceExtensionProperties[0]);
464
465         if(!pProperties)
466         {
467                 *pPropertyCount = extensionPropertiesCount;
468                 return VK_SUCCESS;
469         }
470
471         for(uint32_t i = 0; i < std::min(*pPropertyCount, extensionPropertiesCount); i++)
472         {
473                 pProperties[i] = deviceExtensionProperties[i];
474         }
475
476         return (*pPropertyCount < extensionPropertiesCount) ? VK_INCOMPLETE : VK_SUCCESS;
477 }
478
479 VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t* pPropertyCount, VkLayerProperties* pProperties)
480 {
481         TRACE("(uint32_t* pPropertyCount = 0x%X, VkLayerProperties* pProperties = 0x%X)", pPropertyCount, pProperties);
482
483         if(!pProperties)
484         {
485                 *pPropertyCount = 0;
486                 return VK_SUCCESS;
487         }
488
489         return VK_SUCCESS;
490 }
491
492 VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t* pPropertyCount, VkLayerProperties* pProperties)
493 {
494         TRACE("(VkPhysicalDevice physicalDevice = 0x%X, uint32_t* pPropertyCount = 0x%X, VkLayerProperties* pProperties = 0x%X)", physicalDevice, pPropertyCount, pProperties);
495
496         if(!pProperties)
497         {
498                 *pPropertyCount = 0;
499                 return VK_SUCCESS;
500         }
501
502         return VK_SUCCESS;
503 }
504
505 VKAPI_ATTR void VKAPI_CALL vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue* pQueue)
506 {
507         TRACE("(VkDevice device = 0x%X, uint32_t queueFamilyIndex = %d, uint32_t queueIndex = %d, VkQueue* pQueue = 0x%X)",
508                     device, queueFamilyIndex, queueIndex, pQueue);
509
510         *pQueue = vk::Cast(device)->getQueue(queueFamilyIndex, queueIndex);
511 }
512
513 VKAPI_ATTR VkResult VKAPI_CALL vkQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence fence)
514 {
515         TRACE("(VkQueue queue = 0x%X, uint32_t submitCount = %d, const VkSubmitInfo* pSubmits = 0x%X, VkFence fence = 0x%X)",
516               queue, submitCount, pSubmits, fence);
517
518         vk::Cast(queue)->submit(submitCount, pSubmits, fence);
519
520         return VK_SUCCESS;
521 }
522
523 VKAPI_ATTR VkResult VKAPI_CALL vkQueueWaitIdle(VkQueue queue)
524 {
525         TRACE("(VkQueue queue = 0x%X)", queue);
526
527         vk::Cast(queue)->waitIdle();
528
529         return VK_SUCCESS;
530 }
531
532 VKAPI_ATTR VkResult VKAPI_CALL vkDeviceWaitIdle(VkDevice device)
533 {
534         TRACE("(VkDevice device = 0x%X)", device);
535
536         vk::Cast(device)->waitIdle();
537
538         return VK_SUCCESS;
539 }
540
541 VKAPI_ATTR VkResult VKAPI_CALL vkAllocateMemory(VkDevice device, const VkMemoryAllocateInfo* pAllocateInfo, const VkAllocationCallbacks* pAllocator, VkDeviceMemory* pMemory)
542 {
543         TRACE("(VkDevice device = 0x%X, const VkMemoryAllocateInfo* pAllocateInfo = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X, VkDeviceMemory* pMemory = 0x%X)",
544                     device, pAllocateInfo, pAllocator, pMemory);
545
546         const VkBaseOutStructure* allocationInfo = reinterpret_cast<const VkBaseOutStructure*>(pAllocateInfo->pNext);
547         while(allocationInfo)
548         {
549                 switch(allocationInfo->sType)
550                 {
551                 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO:
552                         // This can safely be ignored, as the Vulkan spec mentions:
553                         // "If the pNext chain includes a VkMemoryDedicatedAllocateInfo structure, then that structure
554                         //  includes a handle of the sole buffer or image resource that the memory *can* be bound to."
555                         break;
556                 default:
557                         UNIMPLEMENTED("allocationInfo->sType");
558                         break;
559                 }
560
561                 allocationInfo = allocationInfo->pNext;
562         }
563
564         VkResult result = vk::DeviceMemory::Create(pAllocator, pAllocateInfo, pMemory);
565         if(result != VK_SUCCESS)
566         {
567                 return result;
568         }
569
570         // Make sure the memory allocation is done now so that OOM errors can be checked now
571         result = vk::Cast(*pMemory)->allocate();
572         if(result != VK_SUCCESS)
573         {
574                 vk::destroy(*pMemory, pAllocator);
575                 *pMemory = VK_NULL_HANDLE;
576         }
577
578         return result;
579 }
580
581 VKAPI_ATTR void VKAPI_CALL vkFreeMemory(VkDevice device, VkDeviceMemory memory, const VkAllocationCallbacks* pAllocator)
582 {
583         TRACE("(VkDevice device = 0x%X, VkDeviceMemory memory = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X)",
584                     device, memory, pAllocator);
585
586         vk::destroy(memory, pAllocator);
587 }
588
589 VKAPI_ATTR VkResult VKAPI_CALL vkMapMemory(VkDevice device, VkDeviceMemory memory, VkDeviceSize offset, VkDeviceSize size, VkMemoryMapFlags flags, void** ppData)
590 {
591         TRACE("(VkDevice device = 0x%X, VkDeviceMemory memory = 0x%X, VkDeviceSize offset = %d, VkDeviceSize size = %d, VkMemoryMapFlags flags = 0x%X, void** ppData = 0x%X)",
592                     device, memory, offset, size, flags, ppData);
593
594         return vk::Cast(memory)->map(offset, size, ppData);
595 }
596
597 VKAPI_ATTR void VKAPI_CALL vkUnmapMemory(VkDevice device, VkDeviceMemory memory)
598 {
599         TRACE("(VkDevice device = 0x%X, VkDeviceMemory memory = 0x%X)", device, memory);
600
601         // Noop, memory will be released when the DeviceMemory object is released
602 }
603
604 VKAPI_ATTR VkResult VKAPI_CALL vkFlushMappedMemoryRanges(VkDevice device, uint32_t memoryRangeCount, const VkMappedMemoryRange* pMemoryRanges)
605 {
606         TRACE("(VkDevice device = 0x%X, uint32_t memoryRangeCount = %d, const VkMappedMemoryRange* pMemoryRanges = 0x%X)",
607                     device, memoryRangeCount, pMemoryRanges);
608
609         // Noop, host and device memory are the same to SwiftShader
610
611         return VK_SUCCESS;
612 }
613
614 VKAPI_ATTR VkResult VKAPI_CALL vkInvalidateMappedMemoryRanges(VkDevice device, uint32_t memoryRangeCount, const VkMappedMemoryRange* pMemoryRanges)
615 {
616         TRACE("(VkDevice device = 0x%X, uint32_t memoryRangeCount = %d, const VkMappedMemoryRange* pMemoryRanges = 0x%X)",
617                     device, memoryRangeCount, pMemoryRanges);
618
619         // Noop, host and device memory are the same to SwiftShader
620
621         return VK_SUCCESS;
622 }
623
624 VKAPI_ATTR void VKAPI_CALL vkGetDeviceMemoryCommitment(VkDevice pDevice, VkDeviceMemory pMemory, VkDeviceSize* pCommittedMemoryInBytes)
625 {
626         TRACE("(VkDevice device = 0x%X, VkDeviceMemory memory = 0x%X, VkDeviceSize* pCommittedMemoryInBytes = 0x%X)",
627               pDevice, pMemory, pCommittedMemoryInBytes);
628
629         auto memory = vk::Cast(pMemory);
630
631 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
632         const auto& memoryProperties = vk::Cast(vk::Cast(pDevice)->getPhysicalDevice())->getMemoryProperties();
633         uint32_t typeIndex = memory->getMemoryTypeIndex();
634         ASSERT(typeIndex < memoryProperties.memoryTypeCount);
635         ASSERT(memoryProperties.memoryTypes[typeIndex].propertyFlags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT);
636 #endif
637
638         *pCommittedMemoryInBytes = memory->getCommittedMemoryInBytes();
639 }
640
641 VKAPI_ATTR VkResult VKAPI_CALL vkBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory memory, VkDeviceSize memoryOffset)
642 {
643         TRACE("(VkDevice device = 0x%X, VkBuffer buffer = 0x%X, VkDeviceMemory memory = 0x%X, VkDeviceSize memoryOffset = %d)",
644                     device, buffer, memory, memoryOffset);
645
646         vk::Cast(buffer)->bind(memory, memoryOffset);
647
648         return VK_SUCCESS;
649 }
650
651 VKAPI_ATTR VkResult VKAPI_CALL vkBindImageMemory(VkDevice device, VkImage image, VkDeviceMemory memory, VkDeviceSize memoryOffset)
652 {
653         TRACE("(VkDevice device = 0x%X, VkImage image = 0x%X, VkDeviceMemory memory = 0x%X, VkDeviceSize memoryOffset = %d)",
654                     device, image, memory, memoryOffset);
655
656         vk::Cast(image)->bind(memory, memoryOffset);
657
658         return VK_SUCCESS;
659 }
660
661 VKAPI_ATTR void VKAPI_CALL vkGetBufferMemoryRequirements(VkDevice device, VkBuffer buffer, VkMemoryRequirements* pMemoryRequirements)
662 {
663         TRACE("(VkDevice device = 0x%X, VkBuffer buffer = 0x%X, VkMemoryRequirements* pMemoryRequirements = 0x%X)",
664                     device, buffer, pMemoryRequirements);
665
666         *pMemoryRequirements = vk::Cast(buffer)->getMemoryRequirements();
667 }
668
669 VKAPI_ATTR void VKAPI_CALL vkGetImageMemoryRequirements(VkDevice device, VkImage image, VkMemoryRequirements* pMemoryRequirements)
670 {
671         TRACE("(VkDevice device = 0x%X, VkImage image = 0x%X, VkMemoryRequirements* pMemoryRequirements = 0x%X)",
672                     device, image, pMemoryRequirements);
673
674         *pMemoryRequirements = vk::Cast(image)->getMemoryRequirements();
675 }
676
677 VKAPI_ATTR void VKAPI_CALL vkGetImageSparseMemoryRequirements(VkDevice device, VkImage image, uint32_t* pSparseMemoryRequirementCount, VkSparseImageMemoryRequirements* pSparseMemoryRequirements)
678 {
679         TRACE("(VkDevice device, VkImage image, uint32_t* pSparseMemoryRequirementCount, VkSparseImageMemoryRequirements* pSparseMemoryRequirements)",
680               device, image, pSparseMemoryRequirementCount, pSparseMemoryRequirements);
681
682         // The 'sparseBinding' feature is not supported, so images can not be created with the VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT flag.
683         // "If the image was not created with VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT then pSparseMemoryRequirementCount will be set to zero and pSparseMemoryRequirements will not be written to."
684         *pSparseMemoryRequirementCount = 0;
685 }
686
687 VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceSparseImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkSampleCountFlagBits samples, VkImageUsageFlags usage, VkImageTiling tiling, uint32_t* pPropertyCount, VkSparseImageFormatProperties* pProperties)
688 {
689         TRACE("(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkSampleCountFlagBits samples, VkImageUsageFlags usage, VkImageTiling tiling, uint32_t* pPropertyCount, VkSparseImageFormatProperties* pProperties)",
690                         physicalDevice, format, type, samples, usage, tiling, pPropertyCount, pProperties);
691
692         // We do not support sparse images.
693         *pPropertyCount = 0;
694 }
695
696 VKAPI_ATTR VkResult VKAPI_CALL vkQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo* pBindInfo, VkFence fence)
697 {
698         TRACE("()");
699         UNIMPLEMENTED("vkQueueBindSparse");
700         return VK_SUCCESS;
701 }
702
703 VKAPI_ATTR VkResult VKAPI_CALL vkCreateFence(VkDevice device, const VkFenceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkFence* pFence)
704 {
705         TRACE("(VkDevice device = 0x%X, const VkFenceCreateInfo* pCreateInfo = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X, VkFence* pFence = 0x%X)",
706                     device, pCreateInfo, pAllocator, pFence);
707
708         if(pCreateInfo->pNext)
709         {
710                 UNIMPLEMENTED("pCreateInfo->pNext");
711         }
712
713         return vk::Fence::Create(pAllocator, pCreateInfo, pFence);
714 }
715
716 VKAPI_ATTR void VKAPI_CALL vkDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks* pAllocator)
717 {
718         TRACE("(VkDevice device = 0x%X, VkFence fence = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X)",
719                     device, fence, pAllocator);
720
721
722         vk::destroy(fence, pAllocator);
723 }
724
725 VKAPI_ATTR VkResult VKAPI_CALL vkResetFences(VkDevice device, uint32_t fenceCount, const VkFence* pFences)
726 {
727         TRACE("(VkDevice device = 0x%X, uint32_t fenceCount = %d, const VkFence* pFences = 0x%X)",
728               device, fenceCount, pFences);
729
730         for(uint32_t i = 0; i < fenceCount; i++)
731         {
732                 vk::Cast(pFences[i])->reset();
733         }
734
735         return VK_SUCCESS;
736 }
737
738 VKAPI_ATTR VkResult VKAPI_CALL vkGetFenceStatus(VkDevice device, VkFence fence)
739 {
740         TRACE("(VkDevice device = 0x%X, VkFence fence = 0x%X)", device, fence);
741
742         return vk::Cast(fence)->getStatus();
743 }
744
745 VKAPI_ATTR VkResult VKAPI_CALL vkWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence* pFences, VkBool32 waitAll, uint64_t timeout)
746 {
747         TRACE("(VkDevice device = 0x%X, uint32_t fenceCount = %d, const VkFence* pFences = 0x%X, VkBool32 waitAll = %d, uint64_t timeout = %d)",
748                 device, fenceCount, pFences, waitAll, timeout);
749
750         vk::Cast(device)->waitForFences(fenceCount, pFences, waitAll, timeout);
751
752         return VK_SUCCESS;
753 }
754
755 VKAPI_ATTR VkResult VKAPI_CALL vkCreateSemaphore(VkDevice device, const VkSemaphoreCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSemaphore* pSemaphore)
756 {
757         TRACE("(VkDevice device = 0x%X, const VkSemaphoreCreateInfo* pCreateInfo = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X, VkSemaphore* pSemaphore = 0x%X)",
758               device, pCreateInfo, pAllocator, pSemaphore);
759
760         if(pCreateInfo->pNext || pCreateInfo->flags)
761         {
762                 UNIMPLEMENTED("pCreateInfo->pNext || pCreateInfo->flags");
763         }
764
765         return vk::Semaphore::Create(pAllocator, pCreateInfo, pSemaphore);
766 }
767
768 VKAPI_ATTR void VKAPI_CALL vkDestroySemaphore(VkDevice device, VkSemaphore semaphore, const VkAllocationCallbacks* pAllocator)
769 {
770         TRACE("(VkDevice device = 0x%X, VkSemaphore semaphore = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X)",
771               device, semaphore, pAllocator);
772
773         vk::destroy(semaphore, pAllocator);
774 }
775
776 VKAPI_ATTR VkResult VKAPI_CALL vkCreateEvent(VkDevice device, const VkEventCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkEvent* pEvent)
777 {
778         TRACE("(VkDevice device = 0x%X, const VkEventCreateInfo* pCreateInfo = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X, VkEvent* pEvent = 0x%X)",
779               device, pCreateInfo, pAllocator, pEvent);
780
781         if(pCreateInfo->pNext || pCreateInfo->flags)
782         {
783                 UNIMPLEMENTED("pCreateInfo->pNext || pCreateInfo->flags");
784         }
785
786         return vk::Event::Create(pAllocator, pCreateInfo, pEvent);
787 }
788
789 VKAPI_ATTR void VKAPI_CALL vkDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks* pAllocator)
790 {
791         TRACE("(VkDevice device = 0x%X, VkEvent event = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X)",
792               device, event, pAllocator);
793
794         vk::destroy(event, pAllocator);
795 }
796
797 VKAPI_ATTR VkResult VKAPI_CALL vkGetEventStatus(VkDevice device, VkEvent event)
798 {
799         TRACE("(VkDevice device = 0x%X, VkEvent event = 0x%X)", device, event);
800
801         return vk::Cast(event)->getStatus();
802 }
803
804 VKAPI_ATTR VkResult VKAPI_CALL vkSetEvent(VkDevice device, VkEvent event)
805 {
806         TRACE("(VkDevice device = 0x%X, VkEvent event = 0x%X)", device, event);
807
808         vk::Cast(event)->signal();
809
810         return VK_SUCCESS;
811 }
812
813 VKAPI_ATTR VkResult VKAPI_CALL vkResetEvent(VkDevice device, VkEvent event)
814 {
815         TRACE("(VkDevice device = 0x%X, VkEvent event = 0x%X)", device, event);
816
817         vk::Cast(event)->reset();
818
819         return VK_SUCCESS;
820 }
821
822 VKAPI_ATTR VkResult VKAPI_CALL vkCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkQueryPool* pQueryPool)
823 {
824         TRACE("(VkDevice device = 0x%X, const VkQueryPoolCreateInfo* pCreateInfo = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X, VkQueryPool* pQueryPool = 0x%X)",
825               device, pCreateInfo, pAllocator, pQueryPool);
826
827         if(pCreateInfo->pNext || pCreateInfo->flags)
828         {
829                 UNIMPLEMENTED("pCreateInfo->pNext || pCreateInfo->flags");
830         }
831
832         return vk::QueryPool::Create(pAllocator, pCreateInfo, pQueryPool);
833 }
834
835 VKAPI_ATTR void VKAPI_CALL vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool, const VkAllocationCallbacks* pAllocator)
836 {
837         TRACE("(VkDevice device = 0x%X, VkQueryPool queryPool = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X)",
838               device, queryPool, pAllocator);
839
840         vk::destroy(queryPool, pAllocator);
841 }
842
843 VKAPI_ATTR VkResult VKAPI_CALL vkGetQueryPoolResults(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount, size_t dataSize, void* pData, VkDeviceSize stride, VkQueryResultFlags flags)
844 {
845         TRACE("(VkDevice device = 0x%X, VkQueryPool queryPool = 0x%X, uint32_t firstQuery = %d, uint32_t queryCount = %d, size_t dataSize = %d, void* pData = 0x%X, VkDeviceSize stride = 0x%X, VkQueryResultFlags flags = %d)",
846               device, queryPool, firstQuery, queryCount, dataSize, pData, stride, flags);
847
848         vk::Cast(queryPool)->getResults(firstQuery, queryCount, dataSize, pData, stride, flags);
849
850         return VK_SUCCESS;
851 }
852
853 VKAPI_ATTR VkResult VKAPI_CALL vkCreateBuffer(VkDevice device, const VkBufferCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkBuffer* pBuffer)
854 {
855         TRACE("(VkDevice device = 0x%X, const VkBufferCreateInfo* pCreateInfo = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X, VkBuffer* pBuffer = 0x%X)",
856                     device, pCreateInfo, pAllocator, pBuffer);
857
858         if(pCreateInfo->pNext)
859         {
860                 UNIMPLEMENTED("pCreateInfo->pNext");
861         }
862
863         return vk::Buffer::Create(pAllocator, pCreateInfo, pBuffer);
864 }
865
866 VKAPI_ATTR void VKAPI_CALL vkDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks* pAllocator)
867 {
868         TRACE("(VkDevice device = 0x%X, VkBuffer buffer = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X)",
869                     device, buffer, pAllocator);
870
871         vk::destroy(buffer, pAllocator);
872 }
873
874 VKAPI_ATTR VkResult VKAPI_CALL vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkBufferView* pView)
875 {
876         TRACE("(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkBufferView* pView)",
877                 device, pCreateInfo, pAllocator, pView);
878
879         if(pCreateInfo->pNext || pCreateInfo->flags)
880         {
881                 UNIMPLEMENTED("pCreateInfo->pNext || pCreateInfo->flags");
882         }
883
884         return vk::BufferView::Create(pAllocator, pCreateInfo, pView);
885 }
886
887 VKAPI_ATTR void VKAPI_CALL vkDestroyBufferView(VkDevice device, VkBufferView bufferView, const VkAllocationCallbacks* pAllocator)
888 {
889         TRACE("(VkDevice device, VkBufferView bufferView, const VkAllocationCallbacks* pAllocator)",
890               device, bufferView, pAllocator);
891
892         vk::destroy(bufferView, pAllocator);
893 }
894
895 VKAPI_ATTR VkResult VKAPI_CALL vkCreateImage(VkDevice device, const VkImageCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkImage* pImage)
896 {
897         TRACE("(VkDevice device = 0x%X, const VkImageCreateInfo* pCreateInfo = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X, VkImage* pImage = 0x%X)",
898                     device, pCreateInfo, pAllocator, pImage);
899
900         if(pCreateInfo->pNext)
901         {
902                 UNIMPLEMENTED("pCreateInfo->pNext");
903         }
904
905         vk::Image::CreateInfo imageCreateInfo =
906         {
907                 pCreateInfo,
908                 device
909         };
910
911         return vk::Image::Create(pAllocator, &imageCreateInfo, pImage);
912 }
913
914 VKAPI_ATTR void VKAPI_CALL vkDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks* pAllocator)
915 {
916         TRACE("(VkDevice device = 0x%X, VkImage image = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X)",
917                     device, image, pAllocator);
918
919         vk::destroy(image, pAllocator);
920 }
921
922 VKAPI_ATTR void VKAPI_CALL vkGetImageSubresourceLayout(VkDevice device, VkImage image, const VkImageSubresource* pSubresource, VkSubresourceLayout* pLayout)
923 {
924         TRACE("(VkDevice device, VkImage image, const VkImageSubresource* pSubresource, VkSubresourceLayout* pLayout)",
925                 device, image, pSubresource, pLayout);
926
927         vk::Cast(image)->getSubresourceLayout(pSubresource, pLayout);
928 }
929
930 VKAPI_ATTR VkResult VKAPI_CALL vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkImageView* pView)
931 {
932         TRACE("(VkDevice device = 0x%X, const VkImageViewCreateInfo* pCreateInfo = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X, VkImageView* pView = 0x%X)",
933                     device, pCreateInfo, pAllocator, pView);
934
935         if(pCreateInfo->flags)
936         {
937                 UNIMPLEMENTED("pCreateInfo->flags");
938         }
939
940         const VkBaseInStructure* extensionCreateInfo = reinterpret_cast<const VkBaseInStructure*>(pCreateInfo->pNext);
941
942         while(extensionCreateInfo)
943         {
944                 switch(extensionCreateInfo->sType)
945                 {
946                 case VK_STRUCTURE_TYPE_IMAGE_VIEW_USAGE_CREATE_INFO_KHR:
947                 {
948                         const VkImageViewUsageCreateInfo* multiviewCreateInfo = reinterpret_cast<const VkImageViewUsageCreateInfo*>(extensionCreateInfo);
949                         ASSERT(!(~vk::Cast(pCreateInfo->image)->getUsage() & multiviewCreateInfo->usage));
950                 }
951                 break;
952                 case VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO:
953                 {
954                         const VkSamplerYcbcrConversionInfo* ycbcrConversionInfo = reinterpret_cast<const VkSamplerYcbcrConversionInfo*>(extensionCreateInfo);
955                         if(ycbcrConversionInfo->conversion != VK_NULL_HANDLE)
956                         {
957                                 ASSERT((pCreateInfo->components.r == VK_COMPONENT_SWIZZLE_IDENTITY) &&
958                                        (pCreateInfo->components.g == VK_COMPONENT_SWIZZLE_IDENTITY) &&
959                                        (pCreateInfo->components.b == VK_COMPONENT_SWIZZLE_IDENTITY) &&
960                                        (pCreateInfo->components.a == VK_COMPONENT_SWIZZLE_IDENTITY));
961                         }
962                 }
963                 break;
964                 default:
965                         UNIMPLEMENTED("extensionCreateInfo->sType");
966                         break;
967                 }
968
969                 extensionCreateInfo = extensionCreateInfo->pNext;
970         }
971
972         return vk::ImageView::Create(pAllocator, pCreateInfo, pView);
973 }
974
975 VKAPI_ATTR void VKAPI_CALL vkDestroyImageView(VkDevice device, VkImageView imageView, const VkAllocationCallbacks* pAllocator)
976 {
977         TRACE("(VkDevice device = 0x%X, VkImageView imageView = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X)",
978               device, imageView, pAllocator);
979
980         vk::destroy(imageView, pAllocator);
981 }
982
983 VKAPI_ATTR VkResult VKAPI_CALL vkCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkShaderModule* pShaderModule)
984 {
985         TRACE("(VkDevice device = 0x%X, const VkShaderModuleCreateInfo* pCreateInfo = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X, VkShaderModule* pShaderModule = 0x%X)",
986                     device, pCreateInfo, pAllocator, pShaderModule);
987
988         if(pCreateInfo->pNext || pCreateInfo->flags)
989         {
990                 UNIMPLEMENTED("pCreateInfo->pNext || pCreateInfo->flags");
991         }
992
993         return vk::ShaderModule::Create(pAllocator, pCreateInfo, pShaderModule);
994 }
995
996 VKAPI_ATTR void VKAPI_CALL vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule, const VkAllocationCallbacks* pAllocator)
997 {
998         TRACE("(VkDevice device = 0x%X, VkShaderModule shaderModule = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X)",
999                     device, shaderModule, pAllocator);
1000
1001         vk::destroy(shaderModule, pAllocator);
1002 }
1003
1004 VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineCache(VkDevice device, const VkPipelineCacheCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkPipelineCache* pPipelineCache)
1005 {
1006         TRACE("(VkDevice device, const VkPipelineCacheCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkPipelineCache* pPipelineCache)",
1007               device, pCreateInfo, pAllocator, pPipelineCache);
1008
1009         if(pCreateInfo->pNext || pCreateInfo->flags)
1010         {
1011                 UNIMPLEMENTED("pCreateInfo->pNext || pCreateInfo->flags");
1012         }
1013
1014         return vk::PipelineCache::Create(pAllocator, pCreateInfo, pPipelineCache);
1015 }
1016
1017 VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineCache(VkDevice device, VkPipelineCache pipelineCache, const VkAllocationCallbacks* pAllocator)
1018 {
1019         TRACE("(VkDevice device, VkPipelineCache pipelineCache, const VkAllocationCallbacks* pAllocator)",
1020               device, pipelineCache, pAllocator);
1021
1022         vk::destroy(pipelineCache, pAllocator);
1023 }
1024
1025 VKAPI_ATTR VkResult VKAPI_CALL vkGetPipelineCacheData(VkDevice device, VkPipelineCache pipelineCache, size_t* pDataSize, void* pData)
1026 {
1027         TRACE("()");
1028         UNIMPLEMENTED("vkGetPipelineCacheData");
1029         return VK_SUCCESS;
1030 }
1031
1032 VKAPI_ATTR VkResult VKAPI_CALL vkMergePipelineCaches(VkDevice device, VkPipelineCache dstCache, uint32_t srcCacheCount, const VkPipelineCache* pSrcCaches)
1033 {
1034         TRACE("()");
1035         UNIMPLEMENTED("vkMergePipelineCaches");
1036         return VK_SUCCESS;
1037 }
1038
1039 VKAPI_ATTR VkResult VKAPI_CALL vkCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount, const VkGraphicsPipelineCreateInfo* pCreateInfos, const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines)
1040 {
1041         TRACE("(VkDevice device = 0x%X, VkPipelineCache pipelineCache = 0x%X, uint32_t createInfoCount = %d, const VkGraphicsPipelineCreateInfo* pCreateInfos, const VkAllocationCallbacks* pAllocator = 0x%X, VkPipeline* pPipelines = 0x%X)",
1042                     device, pipelineCache, createInfoCount, pCreateInfos, pAllocator, pPipelines);
1043
1044         // TODO (b/123588002): Optimize based on pipelineCache.
1045
1046         VkResult errorResult = VK_SUCCESS;
1047         for(uint32_t i = 0; i < createInfoCount; i++)
1048         {
1049                 VkResult result = vk::GraphicsPipeline::Create(pAllocator, &pCreateInfos[i], &pPipelines[i]);
1050                 if(result == VK_SUCCESS)
1051                 {
1052                         static_cast<vk::GraphicsPipeline*>(vk::Cast(pPipelines[i]))->compileShaders(pAllocator, &pCreateInfos[i]);
1053                 }
1054                 else
1055                 {
1056                         // According to the Vulkan spec, section 9.4. Multiple Pipeline Creation
1057                         // "When an application attempts to create many pipelines in a single command,
1058                         //  it is possible that some subset may fail creation. In that case, the
1059                         //  corresponding entries in the pPipelines output array will be filled with
1060                         //  VK_NULL_HANDLE values. If any pipeline fails creation (for example, due to
1061                         //  out of memory errors), the vkCreate*Pipelines commands will return an
1062                         //  error code. The implementation will attempt to create all pipelines, and
1063                         //  only return VK_NULL_HANDLE values for those that actually failed."
1064                         pPipelines[i] = VK_NULL_HANDLE;
1065                         errorResult = result;
1066                 }
1067         }
1068
1069         return errorResult;
1070 }
1071
1072 VKAPI_ATTR VkResult VKAPI_CALL vkCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount, const VkComputePipelineCreateInfo* pCreateInfos, const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines)
1073 {
1074         TRACE("(VkDevice device = 0x%X, VkPipelineCache pipelineCache = 0x%X, uint32_t createInfoCount = %d, const VkComputePipelineCreateInfo* pCreateInfos, const VkAllocationCallbacks* pAllocator = 0x%X, VkPipeline* pPipelines = 0x%X)",
1075                 device, pipelineCache, createInfoCount, pCreateInfos, pAllocator, pPipelines);
1076
1077         // TODO (b/123588002): Optimize based on pipelineCache.
1078
1079         VkResult errorResult = VK_SUCCESS;
1080         for(uint32_t i = 0; i < createInfoCount; i++)
1081         {
1082                 VkResult result = vk::ComputePipeline::Create(pAllocator, &pCreateInfos[i], &pPipelines[i]);
1083                 if(result == VK_SUCCESS)
1084                 {
1085                         static_cast<vk::ComputePipeline*>(vk::Cast(pPipelines[i]))->compileShaders(pAllocator, &pCreateInfos[i]);
1086                 }
1087                 else
1088                 {
1089                         // According to the Vulkan spec, section 9.4. Multiple Pipeline Creation
1090                         // "When an application attempts to create many pipelines in a single command,
1091                         //  it is possible that some subset may fail creation. In that case, the
1092                         //  corresponding entries in the pPipelines output array will be filled with
1093                         //  VK_NULL_HANDLE values. If any pipeline fails creation (for example, due to
1094                         //  out of memory errors), the vkCreate*Pipelines commands will return an
1095                         //  error code. The implementation will attempt to create all pipelines, and
1096                         //  only return VK_NULL_HANDLE values for those that actually failed."
1097                         pPipelines[i] = VK_NULL_HANDLE;
1098                         errorResult = result;
1099                 }
1100         }
1101
1102         return errorResult;
1103 }
1104
1105 VKAPI_ATTR void VKAPI_CALL vkDestroyPipeline(VkDevice device, VkPipeline pipeline, const VkAllocationCallbacks* pAllocator)
1106 {
1107         TRACE("(VkDevice device = 0x%X, VkPipeline pipeline = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X)",
1108                     device, pipeline, pAllocator);
1109
1110         vk::destroy(pipeline, pAllocator);
1111 }
1112
1113 VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkPipelineLayout* pPipelineLayout)
1114 {
1115         TRACE("(VkDevice device = 0x%X, const VkPipelineLayoutCreateInfo* pCreateInfo = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X, VkPipelineLayout* pPipelineLayout = 0x%X)",
1116                     device, pCreateInfo, pAllocator, pPipelineLayout);
1117
1118         if(pCreateInfo->pNext || pCreateInfo->flags)
1119         {
1120                 UNIMPLEMENTED("pCreateInfo->pNext || pCreateInfo->flags");
1121         }
1122
1123         return vk::PipelineLayout::Create(pAllocator, pCreateInfo, pPipelineLayout);
1124 }
1125
1126 VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout, const VkAllocationCallbacks* pAllocator)
1127 {
1128         TRACE("(VkDevice device = 0x%X, VkPipelineLayout pipelineLayout = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X)",
1129                     device, pipelineLayout, pAllocator);
1130
1131         vk::destroy(pipelineLayout, pAllocator);
1132 }
1133
1134 VKAPI_ATTR VkResult VKAPI_CALL vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSampler* pSampler)
1135 {
1136         TRACE("(VkDevice device = 0x%X, const VkSamplerCreateInfo* pCreateInfo = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X, VkSampler* pSampler = 0x%X)",
1137                     device, pCreateInfo, pAllocator, pSampler);
1138
1139         if(pCreateInfo->pNext || pCreateInfo->flags)
1140         {
1141                 UNIMPLEMENTED("pCreateInfo->pNext || pCreateInfo->flags");
1142         }
1143
1144         return vk::Sampler::Create(pAllocator, pCreateInfo, pSampler);
1145 }
1146
1147 VKAPI_ATTR void VKAPI_CALL vkDestroySampler(VkDevice device, VkSampler sampler, const VkAllocationCallbacks* pAllocator)
1148 {
1149         TRACE("(VkDevice device = 0x%X, VkSampler sampler = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X)",
1150                     device, sampler, pAllocator);
1151
1152         vk::destroy(sampler, pAllocator);
1153 }
1154
1155 VKAPI_ATTR VkResult VKAPI_CALL vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDescriptorSetLayout* pSetLayout)
1156 {
1157         TRACE("(VkDevice device = 0x%X, const VkDescriptorSetLayoutCreateInfo* pCreateInfo = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X, VkDescriptorSetLayout* pSetLayout = 0x%X)",
1158               device, pCreateInfo, pAllocator, pSetLayout);
1159
1160         if(pCreateInfo->pNext)
1161         {
1162                 UNIMPLEMENTED("pCreateInfo->pNext");
1163         }
1164
1165         return vk::DescriptorSetLayout::Create(pAllocator, pCreateInfo, pSetLayout);
1166 }
1167
1168 VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout, const VkAllocationCallbacks* pAllocator)
1169 {
1170         TRACE("(VkDevice device = 0x%X, VkDescriptorSetLayout descriptorSetLayout = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X)",
1171               device, descriptorSetLayout, pAllocator);
1172
1173         vk::destroy(descriptorSetLayout, pAllocator);
1174 }
1175
1176 VKAPI_ATTR VkResult VKAPI_CALL vkCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDescriptorPool* pDescriptorPool)
1177 {
1178         TRACE("(VkDevice device = 0x%X, const VkDescriptorPoolCreateInfo* pCreateInfo = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X, VkDescriptorPool* pDescriptorPool = 0x%X)",
1179               device, pCreateInfo, pAllocator, pDescriptorPool);
1180
1181         if(pCreateInfo->pNext)
1182         {
1183                 UNIMPLEMENTED("pCreateInfo->pNext");
1184         }
1185
1186         return vk::DescriptorPool::Create(pAllocator, pCreateInfo, pDescriptorPool);
1187 }
1188
1189 VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, const VkAllocationCallbacks* pAllocator)
1190 {
1191         TRACE("(VkDevice device = 0x%X, VkDescriptorPool descriptorPool = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X)",
1192               device, descriptorPool, pAllocator);
1193
1194         vk::destroy(descriptorPool, pAllocator);
1195 }
1196
1197 VKAPI_ATTR VkResult VKAPI_CALL vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorPoolResetFlags flags)
1198 {
1199         TRACE("(VkDevice device = 0x%X, VkDescriptorPool descriptorPool = 0x%X, VkDescriptorPoolResetFlags flags = 0x%X)",
1200                 device, descriptorPool, flags);
1201
1202         if(flags)
1203         {
1204                 UNIMPLEMENTED("flags");
1205         }
1206
1207         return vk::Cast(descriptorPool)->reset();
1208 }
1209
1210 VKAPI_ATTR VkResult VKAPI_CALL vkAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo* pAllocateInfo, VkDescriptorSet* pDescriptorSets)
1211 {
1212         TRACE("(VkDevice device = 0x%X, const VkDescriptorSetAllocateInfo* pAllocateInfo = 0x%X, VkDescriptorSet* pDescriptorSets = 0x%X)",
1213                 device, pAllocateInfo, pDescriptorSets);
1214
1215         if(pAllocateInfo->pNext)
1216         {
1217                 UNIMPLEMENTED("pAllocateInfo->pNext");
1218         }
1219
1220         return vk::Cast(pAllocateInfo->descriptorPool)->allocateSets(
1221                 pAllocateInfo->descriptorSetCount, pAllocateInfo->pSetLayouts, pDescriptorSets);
1222 }
1223
1224 VKAPI_ATTR VkResult VKAPI_CALL vkFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t descriptorSetCount, const VkDescriptorSet* pDescriptorSets)
1225 {
1226         TRACE("(VkDevice device = 0x%X, VkDescriptorPool descriptorPool = 0x%X, uint32_t descriptorSetCount = %d, const VkDescriptorSet* pDescriptorSets = 0x%X)",
1227                 device, descriptorPool, descriptorSetCount, pDescriptorSets);
1228
1229         vk::Cast(descriptorPool)->freeSets(descriptorSetCount, pDescriptorSets);
1230
1231         return VK_SUCCESS;
1232 }
1233
1234 VKAPI_ATTR void VKAPI_CALL vkUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount, const VkWriteDescriptorSet* pDescriptorWrites, uint32_t descriptorCopyCount, const VkCopyDescriptorSet* pDescriptorCopies)
1235 {
1236         TRACE("(VkDevice device = 0x%X, uint32_t descriptorWriteCount = %d, const VkWriteDescriptorSet* pDescriptorWrites = 0x%X, uint32_t descriptorCopyCount = %d, const VkCopyDescriptorSet* pDescriptorCopies = 0x%X)",
1237               device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies);
1238
1239         vk::Cast(device)->updateDescriptorSets(descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies);
1240 }
1241
1242 VKAPI_ATTR VkResult VKAPI_CALL vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkFramebuffer* pFramebuffer)
1243 {
1244         TRACE("(VkDevice device = 0x%X, const VkFramebufferCreateInfo* pCreateInfo = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X, VkFramebuffer* pFramebuffer = 0x%X)",
1245                     device, pCreateInfo, pAllocator, pFramebuffer);
1246
1247         if(pCreateInfo->pNext || pCreateInfo->flags)
1248         {
1249                 UNIMPLEMENTED("pCreateInfo->pNext || pCreateInfo->flags");
1250         }
1251
1252         return vk::Framebuffer::Create(pAllocator, pCreateInfo, pFramebuffer);
1253 }
1254
1255 VKAPI_ATTR void VKAPI_CALL vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer, const VkAllocationCallbacks* pAllocator)
1256 {
1257         TRACE("(VkDevice device = 0x%X, VkFramebuffer framebuffer = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X)");
1258
1259         vk::destroy(framebuffer, pAllocator);
1260 }
1261
1262 VKAPI_ATTR VkResult VKAPI_CALL vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkRenderPass* pRenderPass)
1263 {
1264         TRACE("(VkDevice device = 0x%X, const VkRenderPassCreateInfo* pCreateInfo = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X, VkRenderPass* pRenderPass = 0x%X)",
1265                     device, pCreateInfo, pAllocator, pRenderPass);
1266
1267         if(pCreateInfo->flags)
1268         {
1269                 UNIMPLEMENTED("pCreateInfo->flags");
1270         }
1271
1272         const VkBaseInStructure* extensionCreateInfo = reinterpret_cast<const VkBaseInStructure*>(pCreateInfo->pNext);
1273
1274         while(extensionCreateInfo)
1275         {
1276                 switch(extensionCreateInfo->sType)
1277                 {
1278                 case VK_STRUCTURE_TYPE_RENDER_PASS_INPUT_ATTACHMENT_ASPECT_CREATE_INFO:
1279                 {
1280                         const VkRenderPassInputAttachmentAspectCreateInfo* inputAttachmentAspectCreateInfo = reinterpret_cast<const VkRenderPassInputAttachmentAspectCreateInfo*>(extensionCreateInfo);
1281
1282                         for(uint32_t i = 0; i < inputAttachmentAspectCreateInfo->aspectReferenceCount; i++)
1283                         {
1284                                 const VkInputAttachmentAspectReference& aspectReference = inputAttachmentAspectCreateInfo->pAspectReferences[i];
1285                                 ASSERT(aspectReference.subpass < pCreateInfo->subpassCount);
1286                                 const VkSubpassDescription& subpassDescription = pCreateInfo->pSubpasses[aspectReference.subpass];
1287                                 ASSERT(aspectReference.inputAttachmentIndex < subpassDescription.inputAttachmentCount);
1288                                 const VkAttachmentReference& attachmentReference = subpassDescription.pInputAttachments[aspectReference.inputAttachmentIndex];
1289                                 if(attachmentReference.attachment != VK_ATTACHMENT_UNUSED)
1290                                 {
1291                                         // If the pNext chain includes an instance of VkRenderPassInputAttachmentAspectCreateInfo, for any
1292                                         // element of the pInputAttachments member of any element of pSubpasses where the attachment member
1293                                         // is not VK_ATTACHMENT_UNUSED, the aspectMask member of the corresponding element of
1294                                         // VkRenderPassInputAttachmentAspectCreateInfo::pAspectReferences must only include aspects that are
1295                                         // present in images of the format specified by the element of pAttachments at attachment
1296                                         vk::Format format(pCreateInfo->pAttachments[attachmentReference.attachment].format);
1297                                         bool isDepth = format.isDepth();
1298                                         bool isStencil = format.isStencil();
1299                                         ASSERT(!(aspectReference.aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) || (!isDepth && !isStencil));
1300                                         ASSERT(!(aspectReference.aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) || isDepth);
1301                                         ASSERT(!(aspectReference.aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) || isStencil);
1302                                 }
1303                         }
1304                 }
1305                 break;
1306                 case VK_STRUCTURE_TYPE_RENDER_PASS_MULTIVIEW_CREATE_INFO:
1307                 {
1308                         const VkRenderPassMultiviewCreateInfo* multiviewCreateInfo = reinterpret_cast<const VkRenderPassMultiviewCreateInfo*>(extensionCreateInfo);
1309                         ASSERT((multiviewCreateInfo->subpassCount == 0) || (multiviewCreateInfo->subpassCount == pCreateInfo->subpassCount));
1310                         ASSERT((multiviewCreateInfo->dependencyCount == 0) || (multiviewCreateInfo->dependencyCount == pCreateInfo->dependencyCount));
1311
1312                         bool zeroMask = (multiviewCreateInfo->pViewMasks[0] == 0);
1313                         for(uint32_t i = 1; i < multiviewCreateInfo->subpassCount; i++)
1314                         {
1315                                 ASSERT((multiviewCreateInfo->pViewMasks[i] == 0) == zeroMask);
1316                         }
1317
1318                         if(zeroMask)
1319                         {
1320                                 ASSERT(multiviewCreateInfo->correlationMaskCount == 0);
1321                         }
1322
1323                         for(uint32_t i = 0; i < multiviewCreateInfo->dependencyCount; i++)
1324                         {
1325                                 const VkSubpassDependency &dependency = pCreateInfo->pDependencies[i];
1326                                 if(multiviewCreateInfo->pViewOffsets[i] != 0)
1327                                 {
1328                                         ASSERT(dependency.srcSubpass != dependency.dstSubpass);
1329                                         ASSERT(dependency.dependencyFlags & VK_DEPENDENCY_VIEW_LOCAL_BIT);
1330                                 }
1331                                 if(zeroMask)
1332                                 {
1333                                         ASSERT(!(dependency.dependencyFlags & VK_DEPENDENCY_VIEW_LOCAL_BIT));
1334                                 }
1335                         }
1336
1337                         // If the pNext chain includes an instance of VkRenderPassMultiviewCreateInfo,
1338                         // each element of its pViewMask member must not include a bit at a position
1339                         // greater than the value of VkPhysicalDeviceLimits::maxFramebufferLayers
1340                         // pViewMask is a 32 bit value. If maxFramebufferLayers > 32, it's impossible
1341                         // for pViewMask to contain a bit at an illegal position
1342                         // Note: Verify pViewMask values instead if we hit this assert
1343                         ASSERT(vk::Cast(vk::Cast(device)->getPhysicalDevice())->getProperties().limits.maxFramebufferLayers >= 32);
1344                 }
1345                 break;
1346                 default:
1347                         UNIMPLEMENTED("extensionCreateInfo->sType");
1348                         break;
1349                 }
1350
1351                 extensionCreateInfo = extensionCreateInfo->pNext;
1352         }
1353
1354         return vk::RenderPass::Create(pAllocator, pCreateInfo, pRenderPass);
1355 }
1356
1357 VKAPI_ATTR void VKAPI_CALL vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass, const VkAllocationCallbacks* pAllocator)
1358 {
1359         TRACE("(VkDevice device = 0x%X, VkRenderPass renderPass = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X)",
1360                     device, renderPass, pAllocator);
1361
1362         vk::destroy(renderPass, pAllocator);
1363 }
1364
1365 VKAPI_ATTR void VKAPI_CALL vkGetRenderAreaGranularity(VkDevice device, VkRenderPass renderPass, VkExtent2D* pGranularity)
1366 {
1367         TRACE("(VkDevice device = 0x%X, VkRenderPass renderPass = 0x%X, VkExtent2D* pGranularity = 0x%X)",
1368               device, renderPass, pGranularity);
1369
1370         vk::Cast(renderPass)->getRenderAreaGranularity(pGranularity);
1371 }
1372
1373 VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkCommandPool* pCommandPool)
1374 {
1375         TRACE("(VkDevice device = 0x%X, const VkCommandPoolCreateInfo* pCreateInfo = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X, VkCommandPool* pCommandPool = 0x%X)",
1376                     device, pCreateInfo, pAllocator, pCommandPool);
1377
1378         if(pCreateInfo->pNext)
1379         {
1380                 UNIMPLEMENTED("pCreateInfo->pNext");
1381         }
1382
1383         return vk::CommandPool::Create(pAllocator, pCreateInfo, pCommandPool);
1384 }
1385
1386 VKAPI_ATTR void VKAPI_CALL vkDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks* pAllocator)
1387 {
1388         TRACE("(VkDevice device = 0x%X, VkCommandPool commandPool = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X)",
1389                     device, commandPool, pAllocator);
1390
1391         vk::destroy(commandPool, pAllocator);
1392 }
1393
1394 VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandPool(VkDevice device, VkCommandPool commandPool, VkCommandPoolResetFlags flags)
1395 {
1396         TRACE("(VkDevice device = 0x%X, VkCommandPool commandPool = 0x%X, VkCommandPoolResetFlags flags = %d )",
1397                 device, commandPool, flags);
1398
1399         return vk::Cast(commandPool)->reset(flags);
1400 }
1401
1402 VKAPI_ATTR VkResult VKAPI_CALL vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo* pAllocateInfo, VkCommandBuffer* pCommandBuffers)
1403 {
1404         TRACE("(VkDevice device = 0x%X, const VkCommandBufferAllocateInfo* pAllocateInfo = 0x%X, VkCommandBuffer* pCommandBuffers = 0x%X)",
1405                     device, pAllocateInfo, pCommandBuffers);
1406
1407         if(pAllocateInfo->pNext)
1408         {
1409                 UNIMPLEMENTED("pAllocateInfo->pNext");
1410         }
1411
1412         return vk::Cast(pAllocateInfo->commandPool)->allocateCommandBuffers(
1413                 pAllocateInfo->level, pAllocateInfo->commandBufferCount, pCommandBuffers);
1414 }
1415
1416 VKAPI_ATTR void VKAPI_CALL vkFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount, const VkCommandBuffer* pCommandBuffers)
1417 {
1418         TRACE("(VkDevice device = 0x%X, VkCommandPool commandPool = 0x%X, uint32_t commandBufferCount = %d, const VkCommandBuffer* pCommandBuffers = 0x%X)",
1419                     device, commandPool, commandBufferCount, pCommandBuffers);
1420
1421         vk::Cast(commandPool)->freeCommandBuffers(commandBufferCount, pCommandBuffers);
1422 }
1423
1424 VKAPI_ATTR VkResult VKAPI_CALL vkBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo* pBeginInfo)
1425 {
1426         TRACE("(VkCommandBuffer commandBuffer = 0x%X, const VkCommandBufferBeginInfo* pBeginInfo = 0x%X)",
1427                     commandBuffer, pBeginInfo);
1428
1429         if(pBeginInfo->pNext)
1430         {
1431                 UNIMPLEMENTED("pBeginInfo->pNext");
1432         }
1433
1434         return vk::Cast(commandBuffer)->begin(pBeginInfo->flags, pBeginInfo->pInheritanceInfo);
1435 }
1436
1437 VKAPI_ATTR VkResult VKAPI_CALL vkEndCommandBuffer(VkCommandBuffer commandBuffer)
1438 {
1439         TRACE("(VkCommandBuffer commandBuffer = 0x%X)", commandBuffer);
1440
1441         return vk::Cast(commandBuffer)->end();
1442 }
1443
1444 VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags)
1445 {
1446         TRACE("VkCommandBuffer commandBuffer = 0x%X, VkCommandBufferResetFlags flags = %d", commandBuffer, flags);
1447
1448         return vk::Cast(commandBuffer)->reset(flags);
1449 }
1450
1451 VKAPI_ATTR void VKAPI_CALL vkCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
1452 {
1453         TRACE("(VkCommandBuffer commandBuffer = 0x%X, VkPipelineBindPoint pipelineBindPoint = %d, VkPipeline pipeline = 0x%X)",
1454                     commandBuffer, pipelineBindPoint, pipeline);
1455
1456         vk::Cast(commandBuffer)->bindPipeline(pipelineBindPoint, pipeline);
1457 }
1458
1459 VKAPI_ATTR void VKAPI_CALL vkCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport, uint32_t viewportCount, const VkViewport* pViewports)
1460 {
1461         TRACE("(VkCommandBuffer commandBuffer = 0x%X, uint32_t firstViewport = %d, uint32_t viewportCount = %d, const VkViewport* pViewports = 0x%X)",
1462               commandBuffer, firstViewport, viewportCount, pViewports);
1463
1464         vk::Cast(commandBuffer)->setViewport(firstViewport, viewportCount, pViewports);
1465 }
1466
1467 VKAPI_ATTR void VKAPI_CALL vkCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount, const VkRect2D* pScissors)
1468 {
1469         TRACE("(VkCommandBuffer commandBuffer = 0x%X, uint32_t firstScissor = %d, uint32_t scissorCount = %d, const VkRect2D* pScissors = 0x%X)",
1470               commandBuffer, firstScissor, scissorCount, pScissors);
1471
1472         vk::Cast(commandBuffer)->setScissor(firstScissor, scissorCount, pScissors);
1473 }
1474
1475 VKAPI_ATTR void VKAPI_CALL vkCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth)
1476 {
1477         TRACE("(VkCommandBuffer commandBuffer = 0x%X, float lineWidth = %f)", commandBuffer, lineWidth);
1478
1479         vk::Cast(commandBuffer)->setLineWidth(lineWidth);
1480 }
1481
1482 VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBias(VkCommandBuffer commandBuffer, float depthBiasConstantFactor, float depthBiasClamp, float depthBiasSlopeFactor)
1483 {
1484         TRACE("(VkCommandBuffer commandBuffer = 0x%X, float depthBiasConstantFactor = %f, float depthBiasClamp = %f, float depthBiasSlopeFactor = %f)",
1485               commandBuffer, depthBiasConstantFactor, depthBiasClamp, depthBiasSlopeFactor);
1486
1487         vk::Cast(commandBuffer)->setDepthBias(depthBiasConstantFactor, depthBiasClamp, depthBiasSlopeFactor);
1488 }
1489
1490 VKAPI_ATTR void VKAPI_CALL vkCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4])
1491 {
1492         TRACE("(VkCommandBuffer commandBuffer = 0x%X, const float blendConstants[4] = {%f, %f, %f, %f})",
1493               commandBuffer, blendConstants[0], blendConstants[1], blendConstants[2], blendConstants[3]);
1494
1495         vk::Cast(commandBuffer)->setBlendConstants(blendConstants);
1496 }
1497
1498 VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBounds(VkCommandBuffer commandBuffer, float minDepthBounds, float maxDepthBounds)
1499 {
1500         TRACE("(VkCommandBuffer commandBuffer = 0x%X, float minDepthBounds = %f, float maxDepthBounds = %f)",
1501               commandBuffer, minDepthBounds, maxDepthBounds);
1502
1503         vk::Cast(commandBuffer)->setDepthBounds(minDepthBounds, maxDepthBounds);
1504 }
1505
1506 VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilCompareMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask, uint32_t compareMask)
1507 {
1508         TRACE("(VkCommandBuffer commandBuffer = 0x%X, VkStencilFaceFlags faceMask = %d, uint32_t compareMask = %d)",
1509               commandBuffer, faceMask, compareMask);
1510
1511         vk::Cast(commandBuffer)->setStencilCompareMask(faceMask, compareMask);
1512 }
1513
1514 VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilWriteMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask, uint32_t writeMask)
1515 {
1516         TRACE("(VkCommandBuffer commandBuffer = 0x%X, VkStencilFaceFlags faceMask = %d, uint32_t writeMask = %d)",
1517               commandBuffer, faceMask, writeMask);
1518
1519         vk::Cast(commandBuffer)->setStencilWriteMask(faceMask, writeMask);
1520 }
1521
1522 VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilReference(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask, uint32_t reference)
1523 {
1524         TRACE("(VkCommandBuffer commandBuffer = 0x%X, VkStencilFaceFlags faceMask = %d, uint32_t reference = %d)",
1525               commandBuffer, faceMask, reference);
1526
1527         vk::Cast(commandBuffer)->setStencilReference(faceMask, reference);
1528 }
1529
1530 VKAPI_ATTR void VKAPI_CALL vkCmdBindDescriptorSets(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, uint32_t firstSet, uint32_t descriptorSetCount, const VkDescriptorSet* pDescriptorSets, uint32_t dynamicOffsetCount, const uint32_t* pDynamicOffsets)
1531 {
1532         TRACE("(VkCommandBuffer commandBuffer = 0x%X, VkPipelineBindPoint pipelineBindPoint = %d, VkPipelineLayout layout = 0x%X, uint32_t firstSet = %d, uint32_t descriptorSetCount = %d, const VkDescriptorSet* pDescriptorSets = 0x%X, uint32_t dynamicOffsetCount = %d, const uint32_t* pDynamicOffsets = 0x%X)",
1533               commandBuffer, pipelineBindPoint, layout, firstSet, descriptorSetCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
1534
1535         vk::Cast(commandBuffer)->bindDescriptorSets(pipelineBindPoint, layout, firstSet, descriptorSetCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
1536 }
1537
1538 VKAPI_ATTR void VKAPI_CALL vkCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
1539 {
1540         TRACE("(VkCommandBuffer commandBuffer = 0x%X, VkBuffer buffer = 0x%X, VkDeviceSize offset = %d, VkIndexType indexType = %d)",
1541               commandBuffer, buffer, offset, indexType);
1542
1543         vk::Cast(commandBuffer)->bindIndexBuffer(buffer, offset, indexType);
1544 }
1545
1546 VKAPI_ATTR void VKAPI_CALL vkCmdBindVertexBuffers(VkCommandBuffer commandBuffer, uint32_t firstBinding, uint32_t bindingCount, const VkBuffer* pBuffers, const VkDeviceSize* pOffsets)
1547 {
1548         TRACE("(VkCommandBuffer commandBuffer = 0x%X, uint32_t firstBinding = %d, uint32_t bindingCount = %d, const VkBuffer* pBuffers = 0x%X, const VkDeviceSize* pOffsets = 0x%X)",
1549                     commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets);
1550
1551         vk::Cast(commandBuffer)->bindVertexBuffers(firstBinding, bindingCount, pBuffers, pOffsets);
1552 }
1553
1554 VKAPI_ATTR void VKAPI_CALL vkCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance)
1555 {
1556         TRACE("(VkCommandBuffer commandBuffer = 0x%X, uint32_t vertexCount = %d, uint32_t instanceCount = %d, uint32_t firstVertex = %d, uint32_t firstInstance = %d)",
1557                     commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance);
1558
1559         vk::Cast(commandBuffer)->draw(vertexCount, instanceCount, firstVertex, firstInstance);
1560 }
1561
1562 VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance)
1563 {
1564         TRACE("(VkCommandBuffer commandBuffer = 0x%X, uint32_t indexCount = %d, uint32_t instanceCount = %d, uint32_t firstIndex = %d, int32_t vertexOffset = %d, uint32_t firstInstance = %d)",
1565                     commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
1566
1567         vk::Cast(commandBuffer)->drawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
1568 }
1569
1570 VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t drawCount, uint32_t stride)
1571 {
1572         TRACE("(VkCommandBuffer commandBuffer = 0x%X, VkBuffer buffer = 0x%X, VkDeviceSize offset = %d, uint32_t drawCount = %d, uint32_t stride = %d)",
1573                     commandBuffer, buffer, offset, drawCount, stride);
1574
1575         vk::Cast(commandBuffer)->drawIndirect(buffer, offset, drawCount, stride);
1576 }
1577
1578 VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t drawCount, uint32_t stride)
1579 {
1580         TRACE("(VkCommandBuffer commandBuffer = 0x%X, VkBuffer buffer = 0x%X, VkDeviceSize offset = %d, uint32_t drawCount = %d, uint32_t stride = %d)",
1581                     commandBuffer, buffer, offset, drawCount, stride);
1582
1583         vk::Cast(commandBuffer)->drawIndexedIndirect(buffer, offset, drawCount, stride);
1584 }
1585
1586 VKAPI_ATTR void VKAPI_CALL vkCmdDispatch(VkCommandBuffer commandBuffer, uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ)
1587 {
1588         TRACE("(VkCommandBuffer commandBuffer = 0x%X, uint32_t groupCountX = %d, uint32_t groupCountY = %d, uint32_t groupCountZ = %d)",
1589               commandBuffer, groupCountX, groupCountY, groupCountZ);
1590
1591         vk::Cast(commandBuffer)->dispatch(groupCountX, groupCountY, groupCountZ);
1592 }
1593
1594 VKAPI_ATTR void VKAPI_CALL vkCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset)
1595 {
1596         TRACE("(VkCommandBuffer commandBuffer = 0x%X, VkBuffer buffer = 0x%X, VkDeviceSize offset = %d)",
1597               commandBuffer, buffer, offset);
1598
1599         vk::Cast(commandBuffer)->dispatchIndirect(buffer, offset);
1600 }
1601
1602 VKAPI_ATTR void VKAPI_CALL vkCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
1603 {
1604         TRACE("(VkCommandBuffer commandBuffer = 0x%X, VkBuffer srcBuffer = 0x%X, VkBuffer dstBuffer = 0x%X, uint32_t regionCount = %d, const VkBufferCopy* pRegions = 0x%X)",
1605               commandBuffer, srcBuffer, dstBuffer, regionCount, pRegions);
1606
1607         vk::Cast(commandBuffer)->copyBuffer(srcBuffer, dstBuffer, regionCount, pRegions);
1608 }
1609
1610 VKAPI_ATTR void VKAPI_CALL vkCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageCopy* pRegions)
1611 {
1612         TRACE("(VkCommandBuffer commandBuffer = 0x%X, VkImage srcImage = 0x%X, VkImageLayout srcImageLayout = %d, VkImage dstImage = 0x%X, VkImageLayout dstImageLayout = %d, uint32_t regionCount = %d, const VkImageCopy* pRegions = 0x%X)",
1613               commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
1614
1615         vk::Cast(commandBuffer)->copyImage(srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
1616 }
1617
1618 VKAPI_ATTR void VKAPI_CALL vkCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageBlit* pRegions, VkFilter filter)
1619 {
1620         TRACE("(VkCommandBuffer commandBuffer = 0x%X, VkImage srcImage = 0x%X, VkImageLayout srcImageLayout = %d, VkImage dstImage = 0x%X, VkImageLayout dstImageLayout = %d, uint32_t regionCount = %d, const VkImageBlit* pRegions = 0x%X, VkFilter filter = %d)",
1621               commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter);
1622
1623         vk::Cast(commandBuffer)->blitImage(srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter);
1624 }
1625
1626 VKAPI_ATTR void VKAPI_CALL vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, const VkBufferImageCopy* pRegions)
1627 {
1628         TRACE("(VkCommandBuffer commandBuffer = 0x%X, VkBuffer srcBuffer = 0x%X, VkImage dstImage = 0x%X, VkImageLayout dstImageLayout = %d, uint32_t regionCount = %d, const VkBufferImageCopy* pRegions = 0x%X)",
1629               commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions);
1630
1631         vk::Cast(commandBuffer)->copyBufferToImage(srcBuffer, dstImage, dstImageLayout, regionCount, pRegions);
1632 }
1633
1634 VKAPI_ATTR void VKAPI_CALL vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkBuffer dstBuffer, uint32_t regionCount, const VkBufferImageCopy* pRegions)
1635 {
1636         TRACE("(VkCommandBuffer commandBuffer = 0x%X, VkImage srcImage = 0x%X, VkImageLayout srcImageLayout = %d, VkBuffer dstBuffer = 0x%X, uint32_t regionCount = %d, const VkBufferImageCopy* pRegions = 0x%X)",
1637                     commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions);
1638
1639         vk::Cast(commandBuffer)->copyImageToBuffer(srcImage, srcImageLayout, dstBuffer, regionCount, pRegions);
1640 }
1641
1642 VKAPI_ATTR void VKAPI_CALL vkCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize dataSize, const void* pData)
1643 {
1644         TRACE("(VkCommandBuffer commandBuffer = 0x%X, VkBuffer dstBuffer = 0x%X, VkDeviceSize dstOffset = %d, VkDeviceSize dataSize = %d, const void* pData = 0x%X)",
1645               commandBuffer, dstBuffer, dstOffset, dataSize, pData);
1646
1647         vk::Cast(commandBuffer)->updateBuffer(dstBuffer, dstOffset, dataSize, pData);
1648 }
1649
1650 VKAPI_ATTR void VKAPI_CALL vkCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize size, uint32_t data)
1651 {
1652         TRACE("(VkCommandBuffer commandBuffer = 0x%X, VkBuffer dstBuffer = 0x%X, VkDeviceSize dstOffset = %d, VkDeviceSize size = %d, uint32_t data = %d)",
1653               commandBuffer, dstBuffer, dstOffset, size, data);
1654
1655         vk::Cast(commandBuffer)->fillBuffer(dstBuffer, dstOffset, size, data);
1656 }
1657
1658 VKAPI_ATTR void VKAPI_CALL vkCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, const VkClearColorValue* pColor, uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
1659 {
1660         TRACE("(VkCommandBuffer commandBuffer = 0x%X, VkImage image = 0x%X, VkImageLayout imageLayout = %d, const VkClearColorValue* pColor = 0x%X, uint32_t rangeCount = %d, const VkImageSubresourceRange* pRanges = 0x%X)",
1661               commandBuffer, image, imageLayout, pColor, rangeCount, pRanges);
1662
1663         vk::Cast(commandBuffer)->clearColorImage(image, imageLayout, pColor, rangeCount, pRanges);
1664 }
1665
1666 VKAPI_ATTR void VKAPI_CALL vkCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, const VkClearDepthStencilValue* pDepthStencil, uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
1667 {
1668         TRACE("(VkCommandBuffer commandBuffer = 0x%X, VkImage image = 0x%X, VkImageLayout imageLayout = %d, const VkClearDepthStencilValue* pDepthStencil = 0x%X, uint32_t rangeCount = %d, const VkImageSubresourceRange* pRanges = 0x%X)",
1669               commandBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges);
1670
1671         vk::Cast(commandBuffer)->clearDepthStencilImage(image, imageLayout, pDepthStencil, rangeCount, pRanges);
1672 }
1673
1674 VKAPI_ATTR void VKAPI_CALL vkCmdClearAttachments(VkCommandBuffer commandBuffer, uint32_t attachmentCount, const VkClearAttachment* pAttachments, uint32_t rectCount, const VkClearRect* pRects)
1675 {
1676         TRACE("(VkCommandBuffer commandBuffer = 0x%X, uint32_t attachmentCount = %d, const VkClearAttachment* pAttachments = 0x%X, uint32_t rectCount = %d, const VkClearRect* pRects = 0x%X)",
1677               commandBuffer, attachmentCount, pAttachments, rectCount,  pRects);
1678
1679         vk::Cast(commandBuffer)->clearAttachments(attachmentCount, pAttachments, rectCount, pRects);
1680 }
1681
1682 VKAPI_ATTR void VKAPI_CALL vkCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageResolve* pRegions)
1683 {
1684         TRACE("(VkCommandBuffer commandBuffer = 0x%X, VkImage srcImage = 0x%X, VkImageLayout srcImageLayout = %d, VkImage dstImage = 0x%X, VkImageLayout dstImageLayout = %d, uint32_t regionCount = %d, const VkImageResolve* pRegions = 0x%X)",
1685               commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
1686
1687         vk::Cast(commandBuffer)->resolveImage(srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
1688 }
1689
1690 VKAPI_ATTR void VKAPI_CALL vkCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
1691 {
1692         TRACE("(VkCommandBuffer commandBuffer = 0x%X, VkEvent event = 0x%X, VkPipelineStageFlags stageMask = %d)",
1693               commandBuffer, event, stageMask);
1694
1695         vk::Cast(commandBuffer)->setEvent(event, stageMask);
1696 }
1697
1698 VKAPI_ATTR void VKAPI_CALL vkCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
1699 {
1700         TRACE("(VkCommandBuffer commandBuffer = 0x%X, VkEvent event = 0x%X, VkPipelineStageFlags stageMask = %d)",
1701               commandBuffer, event, stageMask);
1702
1703         vk::Cast(commandBuffer)->resetEvent(event, stageMask);
1704 }
1705
1706 VKAPI_ATTR void VKAPI_CALL vkCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent* pEvents, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers, uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers)
1707 {
1708         TRACE("(VkCommandBuffer commandBuffer = 0x%X, uint32_t eventCount = %d, const VkEvent* pEvents = 0x%X, VkPipelineStageFlags srcStageMask = %d, VkPipelineStageFlags dstStageMask = %d, uint32_t memoryBarrierCount = %d, const VkMemoryBarrier* pMemoryBarriers = 0x%X, uint32_t bufferMemoryBarrierCount = %d, const VkBufferMemoryBarrier* pBufferMemoryBarriers = 0x%X, uint32_t imageMemoryBarrierCount = %d, const VkImageMemoryBarrier* pImageMemoryBarriers = 0x%X)",
1709               commandBuffer, eventCount, pEvents, srcStageMask, dstStageMask, memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers);
1710
1711         vk::Cast(commandBuffer)->waitEvents(eventCount, pEvents, srcStageMask, dstStageMask, memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers);
1712 }
1713
1714 VKAPI_ATTR void VKAPI_CALL vkCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers, uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers)
1715 {
1716         TRACE("(VkCommandBuffer commandBuffer = 0x%X, VkPipelineStageFlags srcStageMask = 0x%X, VkPipelineStageFlags dstStageMask = 0x%X, VkDependencyFlags dependencyFlags = %d, uint32_t memoryBarrierCount = %d, onst VkMemoryBarrier* pMemoryBarriers = 0x%X,"
1717               " uint32_t bufferMemoryBarrierCount = %d, const VkBufferMemoryBarrier* pBufferMemoryBarriers = 0x%X, uint32_t imageMemoryBarrierCount = %d, const VkImageMemoryBarrier* pImageMemoryBarriers = 0x%X)",
1718               commandBuffer, srcStageMask, dstStageMask, dependencyFlags, memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers);
1719
1720         vk::Cast(commandBuffer)->pipelineBarrier(srcStageMask, dstStageMask, dependencyFlags,
1721                                                  memoryBarrierCount, pMemoryBarriers,
1722                                                  bufferMemoryBarrierCount, pBufferMemoryBarriers,
1723                                                  imageMemoryBarrierCount, pImageMemoryBarriers);
1724 }
1725
1726 VKAPI_ATTR void VKAPI_CALL vkCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t query, VkQueryControlFlags flags)
1727 {
1728         TRACE("(VkCommandBuffer commandBuffer = 0x%X, VkQueryPool queryPool = 0x%X, uint32_t query = %d, VkQueryControlFlags flags = %d)",
1729               commandBuffer, queryPool, query, flags);
1730
1731         vk::Cast(commandBuffer)->beginQuery(queryPool, query, flags);
1732 }
1733
1734 VKAPI_ATTR void VKAPI_CALL vkCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t query)
1735 {
1736         TRACE("(VkCommandBuffer commandBuffer = 0x%X, VkQueryPool queryPool = 0x%X, uint32_t query = %d)",
1737               commandBuffer, queryPool, query);
1738
1739         vk::Cast(commandBuffer)->endQuery(queryPool, query);
1740 }
1741
1742 VKAPI_ATTR void VKAPI_CALL vkCmdResetQueryPool(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount)
1743 {
1744         TRACE("(VkCommandBuffer commandBuffer = 0x%X, VkQueryPool queryPool = 0x%X, uint32_t firstQuery = %d, uint32_t queryCount = %d)",
1745               commandBuffer, queryPool, firstQuery, queryCount);
1746
1747         vk::Cast(commandBuffer)->resetQueryPool(queryPool, firstQuery, queryCount);
1748 }
1749
1750 VKAPI_ATTR void VKAPI_CALL vkCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, VkQueryPool queryPool, uint32_t query)
1751 {
1752         TRACE("(VkCommandBuffer commandBuffer = 0x%X, VkPipelineStageFlagBits pipelineStage = %d, VkQueryPool queryPool = 0x%X, uint32_t query = %d)",
1753               commandBuffer, pipelineStage, queryPool, query);
1754
1755         vk::Cast(commandBuffer)->writeTimestamp(pipelineStage, queryPool, query);
1756 }
1757
1758 VKAPI_ATTR void VKAPI_CALL vkCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize stride, VkQueryResultFlags flags)
1759 {
1760         TRACE("(VkCommandBuffer commandBuffer = 0x%X, VkQueryPool queryPool = 0x%X, uint32_t firstQuery = %d, uint32_t queryCount = %d, VkBuffer dstBuffer = 0x%X, VkDeviceSize dstOffset = %d, VkDeviceSize stride = %d, VkQueryResultFlags flags = %d)",
1761               commandBuffer, queryPool, firstQuery, queryCount, dstBuffer, dstOffset, stride, flags);
1762
1763         vk::Cast(commandBuffer)->copyQueryPoolResults(queryPool, firstQuery, queryCount, dstBuffer, dstOffset, stride, flags);
1764 }
1765
1766 VKAPI_ATTR void VKAPI_CALL vkCmdPushConstants(VkCommandBuffer commandBuffer, VkPipelineLayout layout, VkShaderStageFlags stageFlags, uint32_t offset, uint32_t size, const void* pValues)
1767 {
1768         TRACE("(VkCommandBuffer commandBuffer = 0x%X, VkPipelineLayout layout = 0x%X, VkShaderStageFlags stageFlags = %d, uint32_t offset = %d, uint32_t size = %d, const void* pValues = 0x%X)",
1769               commandBuffer, layout, stageFlags, offset, size, pValues);
1770
1771         vk::Cast(commandBuffer)->pushConstants(layout, stageFlags, offset, size, pValues);
1772 }
1773
1774 VKAPI_ATTR void VKAPI_CALL vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, VkSubpassContents contents)
1775 {
1776         TRACE("(VkCommandBuffer commandBuffer = 0x%X, const VkRenderPassBeginInfo* pRenderPassBegin = 0x%X, VkSubpassContents contents = %d)",
1777               commandBuffer, pRenderPassBegin, contents);
1778
1779         if(pRenderPassBegin->pNext)
1780         {
1781                 UNIMPLEMENTED("pRenderPassBegin->pNext");
1782         }
1783
1784         vk::Cast(commandBuffer)->beginRenderPass(pRenderPassBegin->renderPass, pRenderPassBegin->framebuffer,
1785                                                  pRenderPassBegin->renderArea, pRenderPassBegin->clearValueCount,
1786                                                  pRenderPassBegin->pClearValues, contents);
1787 }
1788
1789 VKAPI_ATTR void VKAPI_CALL vkCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents)
1790 {
1791         TRACE("(VkCommandBuffer commandBuffer = 0x%X, VkSubpassContents contents = %d)",
1792               commandBuffer, contents);
1793
1794         vk::Cast(commandBuffer)->nextSubpass(contents);
1795 }
1796
1797 VKAPI_ATTR void VKAPI_CALL vkCmdEndRenderPass(VkCommandBuffer commandBuffer)
1798 {
1799         TRACE("(VkCommandBuffer commandBuffer = 0x%X)", commandBuffer);
1800
1801         vk::Cast(commandBuffer)->endRenderPass();
1802 }
1803
1804 VKAPI_ATTR void VKAPI_CALL vkCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBufferCount, const VkCommandBuffer* pCommandBuffers)
1805 {
1806         TRACE("(VkCommandBuffer commandBuffer = 0x%X, uint32_t commandBufferCount = %d, const VkCommandBuffer* pCommandBuffers = 0x%X)",
1807               commandBuffer, commandBufferCount, pCommandBuffers);
1808
1809         vk::Cast(commandBuffer)->executeCommands(commandBufferCount, pCommandBuffers);
1810 }
1811
1812 VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceVersion(uint32_t* pApiVersion)
1813 {
1814         TRACE("(uint32_t* pApiVersion = 0x%X)", pApiVersion);
1815         *pApiVersion = vk::API_VERSION;
1816         return VK_SUCCESS;
1817 }
1818
1819 VKAPI_ATTR VkResult VKAPI_CALL vkBindBufferMemory2(VkDevice device, uint32_t bindInfoCount, const VkBindBufferMemoryInfo* pBindInfos)
1820 {
1821         TRACE("(VkDevice device = 0x%X, uint32_t bindInfoCount = %d, const VkBindBufferMemoryInfo* pBindInfos = 0x%X)",
1822               device, bindInfoCount, pBindInfos);
1823
1824         for(uint32_t i = 0; i < bindInfoCount; i++)
1825         {
1826                 if(pBindInfos[i].pNext)
1827                 {
1828                         UNIMPLEMENTED("pBindInfos[%d].pNext", i);
1829                 }
1830
1831                 vk::Cast(pBindInfos[i].buffer)->bind(pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1832         }
1833
1834         return VK_SUCCESS;
1835 }
1836
1837 VKAPI_ATTR VkResult VKAPI_CALL vkBindImageMemory2(VkDevice device, uint32_t bindInfoCount, const VkBindImageMemoryInfo* pBindInfos)
1838 {
1839         TRACE("()");
1840         UNIMPLEMENTED("vkBindImageMemory2");
1841         return VK_SUCCESS;
1842 }
1843
1844 VKAPI_ATTR void VKAPI_CALL vkGetDeviceGroupPeerMemoryFeatures(VkDevice device, uint32_t heapIndex, uint32_t localDeviceIndex, uint32_t remoteDeviceIndex, VkPeerMemoryFeatureFlags* pPeerMemoryFeatures)
1845 {
1846         TRACE("(VkDevice device = 0x%X, uint32_t heapIndex = %d, uint32_t localDeviceIndex = %d, uint32_t remoteDeviceIndex = %d, VkPeerMemoryFeatureFlags* pPeerMemoryFeatures = 0x%X)",
1847               device, heapIndex, localDeviceIndex, remoteDeviceIndex, pPeerMemoryFeatures);
1848
1849         ASSERT(localDeviceIndex != remoteDeviceIndex); // "localDeviceIndex must not equal remoteDeviceIndex"
1850         UNREACHABLE("remoteDeviceIndex: %d", int(remoteDeviceIndex));   // Only one physical device is supported, and since the device indexes can't be equal, this should never be called.
1851 }
1852
1853 VKAPI_ATTR void VKAPI_CALL vkCmdSetDeviceMask(VkCommandBuffer commandBuffer, uint32_t deviceMask)
1854 {
1855         TRACE("()");
1856         UNIMPLEMENTED("vkCmdSetDeviceMask");
1857 }
1858
1859 VKAPI_ATTR void VKAPI_CALL vkCmdDispatchBase(VkCommandBuffer commandBuffer, uint32_t baseGroupX, uint32_t baseGroupY, uint32_t baseGroupZ, uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ)
1860 {
1861         TRACE("()");
1862         UNIMPLEMENTED("vkCmdDispatchBase");
1863 }
1864
1865 VKAPI_ATTR VkResult VKAPI_CALL vkEnumeratePhysicalDeviceGroups(VkInstance instance, uint32_t* pPhysicalDeviceGroupCount, VkPhysicalDeviceGroupProperties* pPhysicalDeviceGroupProperties)
1866 {
1867         TRACE("VkInstance instance = 0x%X, uint32_t* pPhysicalDeviceGroupCount = 0x%X, VkPhysicalDeviceGroupProperties* pPhysicalDeviceGroupProperties = 0x%X",
1868               instance, pPhysicalDeviceGroupCount, pPhysicalDeviceGroupProperties);
1869
1870         if(!pPhysicalDeviceGroupProperties)
1871         {
1872                 *pPhysicalDeviceGroupCount = vk::Cast(instance)->getPhysicalDeviceGroupCount();
1873         }
1874         else
1875         {
1876                 vk::Cast(instance)->getPhysicalDeviceGroups(*pPhysicalDeviceGroupCount, pPhysicalDeviceGroupProperties);
1877         }
1878
1879         return VK_SUCCESS;
1880 }
1881
1882 VKAPI_ATTR void VKAPI_CALL vkGetImageMemoryRequirements2(VkDevice device, const VkImageMemoryRequirementsInfo2* pInfo, VkMemoryRequirements2* pMemoryRequirements)
1883 {
1884         TRACE("(VkDevice device = 0x%X, const VkImageMemoryRequirementsInfo2* pInfo = 0x%X, VkMemoryRequirements2* pMemoryRequirements = 0x%X)",
1885               device, pInfo, pMemoryRequirements);
1886
1887         if(pInfo->pNext || pMemoryRequirements->pNext)
1888         {
1889                 UNIMPLEMENTED("pInfo->pNext || pMemoryRequirements->pNext");
1890         }
1891
1892         vkGetImageMemoryRequirements(device, pInfo->image, &(pMemoryRequirements->memoryRequirements));
1893 }
1894
1895 VKAPI_ATTR void VKAPI_CALL vkGetBufferMemoryRequirements2(VkDevice device, const VkBufferMemoryRequirementsInfo2* pInfo, VkMemoryRequirements2* pMemoryRequirements)
1896 {
1897         TRACE("(VkDevice device = 0x%X, const VkBufferMemoryRequirementsInfo2* pInfo = 0x%X, VkMemoryRequirements2* pMemoryRequirements = 0x%X)",
1898               device, pInfo, pMemoryRequirements);
1899
1900         if(pInfo->pNext)
1901         {
1902                 UNIMPLEMENTED("pInfo->pNext");
1903         }
1904
1905         VkBaseOutStructure* extensionRequirements = reinterpret_cast<VkBaseOutStructure*>(pMemoryRequirements->pNext);
1906         while(extensionRequirements)
1907         {
1908                 switch(extensionRequirements->sType)
1909                 {
1910                 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS:
1911                         {
1912                                 auto& requirements = *reinterpret_cast<VkMemoryDedicatedRequirements*>(extensionRequirements);
1913                                 requirements.prefersDedicatedAllocation = VK_FALSE;
1914                                 requirements.requiresDedicatedAllocation = VK_FALSE;
1915                         }
1916                         break;
1917                 default:
1918                         UNIMPLEMENTED("extensionRequirements->sType");
1919                         break;
1920                 }
1921
1922                 extensionRequirements = extensionRequirements->pNext;
1923         }
1924
1925         vkGetBufferMemoryRequirements(device, pInfo->buffer, &(pMemoryRequirements->memoryRequirements));
1926 }
1927
1928 VKAPI_ATTR void VKAPI_CALL vkGetImageSparseMemoryRequirements2(VkDevice device, const VkImageSparseMemoryRequirementsInfo2* pInfo, uint32_t* pSparseMemoryRequirementCount, VkSparseImageMemoryRequirements2* pSparseMemoryRequirements)
1929 {
1930         TRACE("(VkDevice device = 0x%X, const VkImageSparseMemoryRequirementsInfo2* pInfo = 0x%X, uint32_t* pSparseMemoryRequirementCount = 0x%X, VkSparseImageMemoryRequirements2* pSparseMemoryRequirements = 0x%X)",
1931               device, pInfo, pSparseMemoryRequirementCount, pSparseMemoryRequirements);
1932
1933         if(pInfo->pNext || pSparseMemoryRequirements->pNext)
1934         {
1935                 UNIMPLEMENTED("pInfo->pNext || pSparseMemoryRequirements->pNext");
1936         }
1937
1938         vkGetImageSparseMemoryRequirements(device, pInfo->image, pSparseMemoryRequirementCount, &(pSparseMemoryRequirements->memoryRequirements));
1939 }
1940
1941 VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceFeatures2(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures2* pFeatures)
1942 {
1943         TRACE("(VkPhysicalDevice physicalDevice = 0x%X, VkPhysicalDeviceFeatures2* pFeatures = 0x%X)", physicalDevice, pFeatures);
1944
1945         VkBaseOutStructure* extensionFeatures = reinterpret_cast<VkBaseOutStructure*>(pFeatures->pNext);
1946         while(extensionFeatures)
1947         {
1948                 switch(extensionFeatures->sType)
1949                 {
1950                 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES:
1951                         {
1952                                 auto& features = *reinterpret_cast<VkPhysicalDeviceSamplerYcbcrConversionFeatures*>(extensionFeatures);
1953                                 vk::Cast(physicalDevice)->getFeatures(&features);
1954                         }
1955                         break;
1956                 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES:
1957                         {
1958                                 auto& features = *reinterpret_cast<VkPhysicalDevice16BitStorageFeatures*>(extensionFeatures);
1959                                 vk::Cast(physicalDevice)->getFeatures(&features);
1960                         }
1961                         break;
1962                 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES:
1963                         {
1964                                 auto& features = *reinterpret_cast<VkPhysicalDeviceVariablePointerFeatures*>(extensionFeatures);
1965                                 vk::Cast(physicalDevice)->getFeatures(&features);
1966                         }
1967                         break;
1968                 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES_KHR:
1969                         {
1970                                 auto& features = *reinterpret_cast<VkPhysicalDevice8BitStorageFeaturesKHR*>(extensionFeatures);
1971                                 vk::Cast(physicalDevice)->getFeatures(&features);
1972                         }
1973                         break;
1974                 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES:
1975                         {
1976                                 auto& features = *reinterpret_cast<VkPhysicalDeviceMultiviewFeatures*>(extensionFeatures);
1977                                 vk::Cast(physicalDevice)->getFeatures(&features);
1978                         }
1979                         break;
1980                 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES:
1981                         {
1982                                 auto& features = *reinterpret_cast<VkPhysicalDeviceProtectedMemoryFeatures*>(extensionFeatures);
1983                                 vk::Cast(physicalDevice)->getFeatures(&features);
1984                         }
1985                         break;
1986                 default:
1987                         // "the [driver] must skip over, without processing (other than reading the sType and pNext members) any structures in the chain with sType values not defined by [supported extenions]"
1988                         UNIMPLEMENTED("extensionFeatures->sType");   // TODO(b/119321052): UNIMPLEMENTED() should be used only for features that must still be implemented. Use a more informational macro here.
1989                         break;
1990                 }
1991
1992                 extensionFeatures = extensionFeatures->pNext;
1993         }
1994
1995         vkGetPhysicalDeviceFeatures(physicalDevice, &(pFeatures->features));
1996 }
1997
1998 VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties2* pProperties)
1999 {
2000         TRACE("(VkPhysicalDevice physicalDevice = 0x%X, VkPhysicalDeviceProperties2* pProperties = 0x%X)", physicalDevice, pProperties);
2001
2002         VkBaseOutStructure* extensionProperties = reinterpret_cast<VkBaseOutStructure*>(pProperties->pNext);
2003         while(extensionProperties)
2004         {
2005                 switch(extensionProperties->sType)
2006                 {
2007                 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES:
2008                         {
2009                                 auto& properties = *reinterpret_cast<VkPhysicalDeviceIDProperties*>(extensionProperties);
2010                                 vk::Cast(physicalDevice)->getProperties(&properties);
2011                         }
2012                         break;
2013                 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES:
2014                         {
2015                                 auto& properties = *reinterpret_cast<VkPhysicalDeviceMaintenance3Properties*>(extensionProperties);
2016                                 vk::Cast(physicalDevice)->getProperties(&properties);
2017                         }
2018                         break;
2019                 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES:
2020                         {
2021                                 auto& properties = *reinterpret_cast<VkPhysicalDeviceMultiviewProperties*>(extensionProperties);
2022                                 vk::Cast(physicalDevice)->getProperties(&properties);
2023                         }
2024                         break;
2025                 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES:
2026                         {
2027                                 auto& properties = *reinterpret_cast<VkPhysicalDevicePointClippingProperties*>(extensionProperties);
2028                                 vk::Cast(physicalDevice)->getProperties(&properties);
2029                         }
2030                         break;
2031                 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_PROPERTIES:
2032                         {
2033                                 auto& properties = *reinterpret_cast<VkPhysicalDeviceProtectedMemoryProperties*>(extensionProperties);
2034                                 vk::Cast(physicalDevice)->getProperties(&properties);
2035                         }
2036                         break;
2037                 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES:
2038                         {
2039                                 auto& properties = *reinterpret_cast<VkPhysicalDeviceSubgroupProperties*>(extensionProperties);
2040                                 vk::Cast(physicalDevice)->getProperties(&properties);
2041                         }
2042                         break;
2043                 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLE_LOCATIONS_PROPERTIES_EXT:
2044                         // Explicitly ignored, since VK_EXT_sample_locations is not supported
2045                         ASSERT(!HasExtensionProperty(VK_EXT_SAMPLE_LOCATIONS_EXTENSION_NAME, deviceExtensionProperties,
2046                                                      sizeof(deviceExtensionProperties) / sizeof(deviceExtensionProperties[0])));
2047                         break;
2048                 default:
2049                         // "the [driver] must skip over, without processing (other than reading the sType and pNext members) any structures in the chain with sType values not defined by [supported extenions]"
2050                         UNIMPLEMENTED("extensionProperties->sType");   // TODO(b/119321052): UNIMPLEMENTED() should be used only for features that must still be implemented. Use a more informational macro here.
2051                         break;
2052                 }
2053
2054                 extensionProperties = extensionProperties->pNext;
2055         }
2056
2057         vkGetPhysicalDeviceProperties(physicalDevice, &(pProperties->properties));
2058 }
2059
2060 VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceFormatProperties2(VkPhysicalDevice physicalDevice, VkFormat format, VkFormatProperties2* pFormatProperties)
2061 {
2062         TRACE("(VkPhysicalDevice physicalDevice = 0x%X, VkFormat format = %d, VkFormatProperties2* pFormatProperties = 0x%X)",
2063                     physicalDevice, format, pFormatProperties);
2064
2065         if(pFormatProperties->pNext)
2066         {
2067                 UNIMPLEMENTED("pFormatProperties->pNext");
2068         }
2069
2070         vkGetPhysicalDeviceFormatProperties(physicalDevice, format, &(pFormatProperties->formatProperties));
2071 }
2072
2073 VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceImageFormatProperties2(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceImageFormatInfo2* pImageFormatInfo, VkImageFormatProperties2* pImageFormatProperties)
2074 {
2075         TRACE("(VkPhysicalDevice physicalDevice = 0x%X, const VkPhysicalDeviceImageFormatInfo2* pImageFormatInfo = 0x%X, VkImageFormatProperties2* pImageFormatProperties = 0x%X)",
2076                     physicalDevice, pImageFormatInfo, pImageFormatProperties);
2077
2078         if(pImageFormatInfo->pNext || pImageFormatProperties->pNext)
2079         {
2080                 UNIMPLEMENTED("pImageFormatInfo->pNext || pImageFormatProperties->pNext");
2081         }
2082
2083         return vkGetPhysicalDeviceImageFormatProperties(physicalDevice,
2084                                                             pImageFormatInfo->format,
2085                                                             pImageFormatInfo->type,
2086                                                             pImageFormatInfo->tiling,
2087                                                             pImageFormatInfo->usage,
2088                                                             pImageFormatInfo->flags,
2089                                                             &(pImageFormatProperties->imageFormatProperties));
2090 }
2091
2092 VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceQueueFamilyProperties2(VkPhysicalDevice physicalDevice, uint32_t* pQueueFamilyPropertyCount, VkQueueFamilyProperties2* pQueueFamilyProperties)
2093 {
2094         TRACE("(VkPhysicalDevice physicalDevice = 0x%X, uint32_t* pQueueFamilyPropertyCount = 0x%X, VkQueueFamilyProperties2* pQueueFamilyProperties = 0x%X)",
2095                 physicalDevice, pQueueFamilyPropertyCount, pQueueFamilyProperties);
2096
2097         if(pQueueFamilyProperties && pQueueFamilyProperties->pNext)
2098         {
2099                 UNIMPLEMENTED("pQueueFamilyProperties->pNext");
2100         }
2101
2102         vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, pQueueFamilyPropertyCount,
2103                 pQueueFamilyProperties ? &(pQueueFamilyProperties->queueFamilyProperties) : nullptr);
2104 }
2105
2106 VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceMemoryProperties2(VkPhysicalDevice physicalDevice, VkPhysicalDeviceMemoryProperties2* pMemoryProperties)
2107 {
2108         TRACE("(VkPhysicalDevice physicalDevice = 0x%X, VkPhysicalDeviceMemoryProperties2* pMemoryProperties = 0x%X)", physicalDevice, pMemoryProperties);
2109
2110         if(pMemoryProperties->pNext)
2111         {
2112                 UNIMPLEMENTED("pMemoryProperties->pNext");
2113         }
2114
2115         vkGetPhysicalDeviceMemoryProperties(physicalDevice, &(pMemoryProperties->memoryProperties));
2116 }
2117
2118 VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceSparseImageFormatProperties2(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSparseImageFormatInfo2* pFormatInfo, uint32_t* pPropertyCount, VkSparseImageFormatProperties2* pProperties)
2119 {
2120         TRACE("(VkPhysicalDevice physicalDevice = 0x%X, const VkPhysicalDeviceSparseImageFormatInfo2* pFormatInfo = 0x%X, uint32_t* pPropertyCount = 0x%X, VkSparseImageFormatProperties2* pProperties = 0x%X)",
2121              physicalDevice, pFormatInfo, pPropertyCount, pProperties);
2122
2123         if(pProperties && pProperties->pNext)
2124         {
2125                 UNIMPLEMENTED("pProperties->pNext");
2126         }
2127
2128         vkGetPhysicalDeviceSparseImageFormatProperties(physicalDevice, pFormatInfo->format, pFormatInfo->type,
2129                                                        pFormatInfo->samples, pFormatInfo->usage, pFormatInfo->tiling,
2130                                                        pPropertyCount, pProperties ? &(pProperties->properties) : nullptr);
2131 }
2132
2133 VKAPI_ATTR void VKAPI_CALL vkTrimCommandPool(VkDevice device, VkCommandPool commandPool, VkCommandPoolTrimFlags flags)
2134 {
2135         TRACE("(VkDevice device = 0x%X, VkCommandPool commandPool = 0x%X, VkCommandPoolTrimFlags flags = %d)",
2136               device, commandPool, flags);
2137
2138         vk::Cast(commandPool)->trim(flags);
2139 }
2140
2141 VKAPI_ATTR void VKAPI_CALL vkGetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2* pQueueInfo, VkQueue* pQueue)
2142 {
2143         TRACE("(VkDevice device = 0x%X, const VkDeviceQueueInfo2* pQueueInfo = 0x%X, VkQueue* pQueue = 0x%X)",
2144               device, pQueueInfo, pQueue);
2145
2146         if(pQueueInfo->pNext)
2147         {
2148                 UNIMPLEMENTED("pQueueInfo->pNext");
2149         }
2150
2151         // The only flag that can be set here is VK_DEVICE_QUEUE_CREATE_PROTECTED_BIT
2152         // According to the Vulkan spec, 4.3.1. Queue Family Properties:
2153         // "VK_DEVICE_QUEUE_CREATE_PROTECTED_BIT specifies that the device queue is a
2154         //  protected-capable queue. If the protected memory feature is not enabled,
2155         //  the VK_DEVICE_QUEUE_CREATE_PROTECTED_BIT bit of flags must not be set."
2156         if(pQueueInfo->flags)
2157         {
2158                 *pQueue = VK_NULL_HANDLE;
2159         }
2160         else
2161         {
2162                 vkGetDeviceQueue(device, pQueueInfo->queueFamilyIndex, pQueueInfo->queueIndex, pQueue);
2163         }
2164 }
2165
2166 VKAPI_ATTR VkResult VKAPI_CALL vkCreateSamplerYcbcrConversion(VkDevice device, const VkSamplerYcbcrConversionCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSamplerYcbcrConversion* pYcbcrConversion)
2167 {
2168         TRACE("()");
2169         UNIMPLEMENTED("vkCreateSamplerYcbcrConversion");
2170         return VK_SUCCESS;
2171 }
2172
2173 VKAPI_ATTR void VKAPI_CALL vkDestroySamplerYcbcrConversion(VkDevice device, VkSamplerYcbcrConversion ycbcrConversion, const VkAllocationCallbacks* pAllocator)
2174 {
2175         TRACE("()");
2176         UNIMPLEMENTED("vkDestroySamplerYcbcrConversion");
2177 }
2178
2179 VKAPI_ATTR VkResult VKAPI_CALL vkCreateDescriptorUpdateTemplate(VkDevice device, const VkDescriptorUpdateTemplateCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDescriptorUpdateTemplate* pDescriptorUpdateTemplate)
2180 {
2181         TRACE("(VkDevice device = 0x%X, const VkDescriptorUpdateTemplateCreateInfo* pCreateInfo = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X, VkDescriptorUpdateTemplate* pDescriptorUpdateTemplate = 0x%X)",
2182               device, pCreateInfo, pAllocator, pDescriptorUpdateTemplate);
2183
2184         if(pCreateInfo->pNext || pCreateInfo->flags || (pCreateInfo->templateType != VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET))
2185         {
2186                 UNIMPLEMENTED("pCreateInfo->pNext || pCreateInfo->flags || (pCreateInfo->templateType != VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET)");
2187         }
2188
2189         return vk::DescriptorUpdateTemplate::Create(pAllocator, pCreateInfo, pDescriptorUpdateTemplate);
2190 }
2191
2192 VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorUpdateTemplate(VkDevice device, VkDescriptorUpdateTemplate descriptorUpdateTemplate, const VkAllocationCallbacks* pAllocator)
2193 {
2194         TRACE("(VkDevice device = 0x%X, VkDescriptorUpdateTemplate descriptorUpdateTemplate = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X)",
2195               device, descriptorUpdateTemplate, pAllocator);
2196
2197         vk::destroy(descriptorUpdateTemplate, pAllocator);
2198 }
2199
2200 VKAPI_ATTR void VKAPI_CALL vkUpdateDescriptorSetWithTemplate(VkDevice device, VkDescriptorSet descriptorSet, VkDescriptorUpdateTemplate descriptorUpdateTemplate, const void* pData)
2201 {
2202         TRACE("(VkDevice device = 0x%X, VkDescriptorSet descriptorSet = 0x%X, VkDescriptorUpdateTemplate descriptorUpdateTemplate = 0x%X, const void* pData = 0x%X)",
2203               device, descriptorSet, descriptorUpdateTemplate, pData);
2204
2205         vk::Cast(descriptorUpdateTemplate)->updateDescriptorSet(descriptorSet, pData);
2206 }
2207
2208 VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceExternalBufferProperties(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalBufferInfo* pExternalBufferInfo, VkExternalBufferProperties* pExternalBufferProperties)
2209 {
2210         TRACE("(VkPhysicalDevice physicalDevice = 0x%X, const VkPhysicalDeviceExternalBufferInfo* pExternalBufferInfo = 0x%X, VkExternalBufferProperties* pExternalBufferProperties = 0x%X)",
2211               physicalDevice, pExternalBufferInfo, pExternalBufferProperties);
2212
2213         UNIMPLEMENTED("vkGetPhysicalDeviceExternalBufferProperties");
2214 }
2215
2216 VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceExternalFenceProperties(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalFenceInfo* pExternalFenceInfo, VkExternalFenceProperties* pExternalFenceProperties)
2217 {
2218         TRACE("(VkPhysicalDevice physicalDevice = 0x%X, const VkPhysicalDeviceExternalFenceInfo* pExternalFenceInfo = 0x%X, VkExternalFenceProperties* pExternalFenceProperties = 0x%X)",
2219               physicalDevice, pExternalFenceInfo, pExternalFenceProperties);
2220
2221         UNIMPLEMENTED("vkGetPhysicalDeviceExternalFenceProperties");
2222 }
2223
2224 VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceExternalSemaphoreProperties(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalSemaphoreInfo* pExternalSemaphoreInfo, VkExternalSemaphoreProperties* pExternalSemaphoreProperties)
2225 {
2226         TRACE("(VkPhysicalDevice physicalDevice = 0x%X, const VkPhysicalDeviceExternalSemaphoreInfo* pExternalSemaphoreInfo = 0x%X, VkExternalSemaphoreProperties* pExternalSemaphoreProperties = 0x%X)",
2227               physicalDevice, pExternalSemaphoreInfo, pExternalSemaphoreProperties);
2228
2229         UNIMPLEMENTED("vkGetPhysicalDeviceExternalSemaphoreProperties");
2230 }
2231
2232 VKAPI_ATTR void VKAPI_CALL vkGetDescriptorSetLayoutSupport(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, VkDescriptorSetLayoutSupport* pSupport)
2233 {
2234         TRACE("(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, VkDescriptorSetLayoutSupport* pSupport)",
2235               device, pCreateInfo, pSupport);
2236
2237         vk::Cast(device)->getDescriptorSetLayoutSupport(pCreateInfo, pSupport);
2238 }
2239
2240 #ifdef VK_USE_PLATFORM_XLIB_KHR
2241 VKAPI_ATTR VkResult VKAPI_CALL vkCreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface)
2242 {
2243         TRACE("(VkInstance instance = 0x%X, VkXlibSurfaceCreateInfoKHR* pCreateInfo = 0x%X, VkAllocationCallbacks* pAllocator = 0x%X, VkSurface* pSurface = 0x%X)",
2244                         instance, pCreateInfo, pAllocator, pSurface);
2245
2246         return vk::XlibSurfaceKHR::Create(pAllocator, pCreateInfo, pSurface);
2247 }
2248 #endif
2249
2250 #ifndef __ANDROID__
2251 VKAPI_ATTR void VKAPI_CALL vkDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface, const VkAllocationCallbacks* pAllocator)
2252 {
2253     TRACE("(VkInstance instance = 0x%X, VkSurfaceKHR surface = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X)",
2254             instance, surface, pAllocator);
2255
2256     vk::destroy(surface, pAllocator);
2257 }
2258
2259 VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, VkSurfaceKHR surface, VkBool32* pSupported)
2260 {
2261         TRACE("(VkPhysicalDevice physicalDevice = 0x%X, uint32_t queueFamilyIndex = 0x%X, VkSurface surface = 0x%X, VKBool32* pSupported = 0x%X)",
2262                         physicalDevice, queueFamilyIndex, surface, pSupported);
2263
2264         *pSupported =  VK_TRUE;
2265         return VK_SUCCESS;
2266 }
2267
2268
2269 VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, VkSurfaceCapabilitiesKHR* pSurfaceCapabilities)
2270 {
2271         TRACE("(VkPhysicalDevice physicalDevice = 0x%X, VkSurfaceKHR surface = 0x%X, VkSurfaceCapabilitiesKHR* pSurfaceCapabilities = 0x%X)",
2272                         physicalDevice, surface, pSurfaceCapabilities);
2273
2274         vk::Cast(surface)->getSurfaceCapabilities(pSurfaceCapabilities);
2275         return VK_SUCCESS;
2276 }
2277
2278 VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, uint32_t* pSurfaceFormatCount, VkSurfaceFormatKHR* pSurfaceFormats)
2279 {
2280         TRACE("(VkPhysicalDevice physicalDevice = 0x%X, VkSurfaceKHR surface = 0x%X. uint32_t* pSurfaceFormatCount = 0x%X, VkSurfaceFormatKHR* pSurfaceFormats)",
2281                         physicalDevice, surface, pSurfaceFormatCount, pSurfaceFormats);
2282
2283         if(!pSurfaceFormats)
2284         {
2285                 *pSurfaceFormatCount = vk::Cast(surface)->getSurfaceFormatsCount();
2286                 return VK_SUCCESS;
2287         }
2288
2289         return vk::Cast(surface)->getSurfaceFormats(pSurfaceFormatCount, pSurfaceFormats);
2290 }
2291
2292 VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, uint32_t* pPresentModeCount, VkPresentModeKHR* pPresentModes)
2293 {
2294         TRACE("(VkPhysicalDevice physicalDevice = 0x%X, VkSurfaceKHR surface = 0x%X uint32_t* pPresentModeCount = 0x%X, VkPresentModeKHR* pPresentModes = 0x%X)",
2295                         physicalDevice, surface, pPresentModeCount, pPresentModes);
2296
2297         if(!pPresentModes)
2298         {
2299                 *pPresentModeCount = vk::Cast(surface)->getPresentModeCount();
2300                 return VK_SUCCESS;
2301         }
2302
2303         return vk::Cast(surface)->getPresentModes(pPresentModeCount, pPresentModes);
2304 }
2305
2306 VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSwapchainKHR* pSwapchain)
2307 {
2308         TRACE("(VkDevice device = 0x%X, const VkSwapchainCreateInfoKHR* pCreateInfo = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X, VkSwapchainKHR* pSwapchain = 0x%X)",
2309                         device, pCreateInfo, pAllocator, pSwapchain);
2310
2311         if(pCreateInfo->oldSwapchain)
2312         {
2313                 vk::Cast(pCreateInfo->oldSwapchain)->retire();
2314         }
2315
2316         if(vk::Cast(pCreateInfo->surface)->getAssociatedSwapchain() != VK_NULL_HANDLE)
2317         {
2318                 return VK_ERROR_NATIVE_WINDOW_IN_USE_KHR;
2319         }
2320
2321         VkResult status = vk::SwapchainKHR::Create(pAllocator, pCreateInfo, pSwapchain);
2322
2323         if(status != VK_SUCCESS)
2324         {
2325                 return status;
2326         }
2327
2328         status = vk::Cast(*pSwapchain)->createImages(device);
2329
2330         if(status != VK_SUCCESS)
2331         {
2332                 vk::destroy(*pSwapchain, pAllocator);
2333                 return status;
2334         }
2335
2336         vk::Cast(pCreateInfo->surface)->associateSwapchain(*pSwapchain);
2337
2338         return VK_SUCCESS;
2339 }
2340
2341 VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain, const VkAllocationCallbacks* pAllocator)
2342 {
2343         TRACE("(VkDevice device = 0x%X, VkSwapchainKHR swapchain = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X)",
2344                         device, swapchain, pAllocator);
2345
2346         vk::destroy(swapchain, pAllocator);
2347 }
2348
2349 VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t* pSwapchainImageCount, VkImage* pSwapchainImages)
2350 {
2351         TRACE("(VkDevice device = 0x%X, VkSwapchainKHR swapchain = 0x%X, uint32_t* pSwapchainImageCount = 0x%X, VkImage* pSwapchainImages = 0x%X)",
2352                         device, swapchain, pSwapchainImageCount, pSwapchainImages);
2353
2354         if(!pSwapchainImages)
2355         {
2356                 *pSwapchainImageCount = vk::Cast(swapchain)->getImageCount();
2357                 return VK_SUCCESS;
2358         }
2359
2360         return vk::Cast(swapchain)->getImages(pSwapchainImageCount, pSwapchainImages);
2361 }
2362
2363 VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout, VkSemaphore semaphore, VkFence fence, uint32_t* pImageIndex)
2364 {
2365         TRACE("(VkDevice device = 0x%X, VkSwapchainKHR swapchain = 0x%X, uint64_t timeout = 0x%X, VkSemaphore semaphore = 0x%X, VkFence fence = 0x%X, uint32_t* pImageIndex = 0x%X)",
2366                         device, swapchain, timeout, semaphore, fence, pImageIndex);
2367
2368         return vk::Cast(swapchain)->getNextImage(timeout, semaphore, fence, pImageIndex);
2369 }
2370
2371 VKAPI_ATTR VkResult VKAPI_CALL vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo)
2372 {
2373         TRACE("(VkQueue queue = 0x%X, const VkPresentInfoKHR* pPresentInfo = 0x%X)",
2374                         queue, pPresentInfo);
2375
2376         vk::Cast(queue)->present(pPresentInfo);
2377
2378         return VK_SUCCESS;
2379 }
2380 #endif    // ! __ANDROID__
2381
2382 }