blob: e4d769829054043ab3df0ec06009d52c98d94dca [file] [log] [blame]
Alexis Hetud73b8712018-09-21 15:14:43 -04001// 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
Alexis Hetu38ff8302018-10-18 15:08:13 -040015#include "VkBuffer.hpp"
16#include "VkBufferView.hpp"
Alexis Hetu767b41b2018-09-26 11:25:46 -040017#include "VkCommandBuffer.hpp"
Alexis Hetu9c4ecae2018-11-20 16:26:10 -050018#include "VkCommandPool.hpp"
Alexis Hetu000df8b2018-10-24 15:22:41 -040019#include "VkConfig.h"
Alexis Hetud73b8712018-09-21 15:14:43 -040020#include "VkDebug.hpp"
Alexis Hetuc8176632019-01-22 17:01:28 -050021#include "VkDescriptorPool.hpp"
22#include "VkDescriptorSetLayout.hpp"
Alexis Hetuf705cec2019-01-29 14:09:36 -050023#include "VkDescriptorUpdateTemplate.hpp"
Alexis Hetue70c3512018-10-17 13:18:04 -040024#include "VkDestroy.h"
Alexis Hetu767b41b2018-09-26 11:25:46 -040025#include "VkDevice.hpp"
Alexis Hetu38ff8302018-10-18 15:08:13 -040026#include "VkDeviceMemory.hpp"
Alexis Hetu1f23d8c2018-10-16 14:40:19 -040027#include "VkEvent.hpp"
28#include "VkFence.hpp"
Alexis Hetu8f631c82018-11-15 15:11:36 -050029#include "VkFramebuffer.hpp"
Alexis Hetud73b8712018-09-21 15:14:43 -040030#include "VkGetProcAddress.h"
Alexis Hetuf62f3752018-11-15 14:51:15 -050031#include "VkImage.hpp"
Alexis Hetu9fbaf692018-11-19 11:30:43 -050032#include "VkImageView.hpp"
Alexis Hetu767b41b2018-09-26 11:25:46 -040033#include "VkInstance.hpp"
34#include "VkPhysicalDevice.hpp"
Alexis Hetu000df8b2018-10-24 15:22:41 -040035#include "VkPipeline.hpp"
Alexis Hetu18a84252018-11-19 11:30:43 -050036#include "VkPipelineCache.hpp"
Alexis Hetu000df8b2018-10-24 15:22:41 -040037#include "VkPipelineLayout.hpp"
Alexis Hetu86f8bdb2019-01-22 12:07:24 -050038#include "VkQueryPool.hpp"
Alexis Hetu767b41b2018-09-26 11:25:46 -040039#include "VkQueue.hpp"
Alexis Hetu5174c572018-11-19 11:30:43 -050040#include "VkSampler.hpp"
Alexis Hetu1f23d8c2018-10-16 14:40:19 -040041#include "VkSemaphore.hpp"
Alexis Hetu259ad3d2018-11-15 13:44:31 -050042#include "VkShaderModule.hpp"
Alexis Hetub16f9892018-11-15 15:18:41 -050043#include "VkRenderPass.hpp"
Nicolas Capens50b10592018-10-26 10:34:20 -040044
Alexis Hetu0662a4a2019-07-08 15:06:40 -040045#ifdef VK_USE_PLATFORM_MACOS_MVK
46#include "WSI/MacOSSurfaceMVK.h"
47#endif
48
Hernan Liatisc6eb41b2019-02-22 11:12:59 -080049#ifdef VK_USE_PLATFORM_XLIB_KHR
50#include "WSI/XlibSurfaceKHR.hpp"
51#endif
52
Nicolas Capensd3545372019-08-09 13:59:18 -040053#ifdef VK_USE_PLATFORM_WIN32_KHR
54#include "WSI/Win32SurfaceKHR.hpp"
55#endif
56
Hernan Liatis8a91a352019-04-29 17:14:06 -070057#ifdef __ANDROID__
58#include <vulkan/vk_android_native_buffer.h>
Hernan Liatis628604e2019-05-07 15:30:18 -070059#include "System/GrallocAndroid.hpp"
Chris Forbes93ad3b82019-06-03 08:02:47 -070060#include <sync/sync.h>
Hernan Liatis8a91a352019-04-29 17:14:06 -070061#endif
62
Hernan Liatisc7943e92019-02-25 19:29:54 -080063#include "WSI/VkSwapchainKHR.hpp"
64
Ben Clayton056d6922019-07-04 12:41:13 +010065#include "Reactor/Nucleus.hpp"
66
Ben Claytond6c61362019-08-14 18:16:01 +010067#include "Yarn/Scheduler.hpp"
68#include "Yarn/Thread.hpp"
69
70#include "System/CPUID.hpp"
71
Alexis Hetu000df8b2018-10-24 15:22:41 -040072#include <algorithm>
Chris Forbes3d27f2e2018-09-26 09:24:39 -070073#include <cstring>
Alexis Hetu767b41b2018-09-26 11:25:46 -040074#include <string>
Hernan Liatis628604e2019-05-07 15:30:18 -070075#include <map>
Alexis Hetud73b8712018-09-21 15:14:43 -040076
Alexis Hetud6fae382019-04-05 13:19:46 -040077namespace
78{
79
80bool HasExtensionProperty(const char* extensionName, const VkExtensionProperties* extensionProperties, uint32_t extensionPropertiesCount)
81{
82 for(uint32_t j = 0; j < extensionPropertiesCount; ++j)
83 {
84 if(strcmp(extensionName, extensionProperties[j].extensionName) == 0)
85 {
86 return true;
87 }
88 }
89
90 return false;
91}
92
Ben Clayton056d6922019-07-04 12:41:13 +010093// setReactorDefaultConfig() sets the default configuration for Vulkan's use of
94// Reactor.
95void setReactorDefaultConfig()
96{
97 auto cfg = rr::Config::Edit()
Ben Claytonfc7bb8f2019-07-10 00:50:49 +010098 .set(rr::Optimization::Level::Default)
99 .clearOptimizationPasses()
100 .add(rr::Optimization::Pass::ScalarReplAggregates)
101 .add(rr::Optimization::Pass::SCCP)
102 .add(rr::Optimization::Pass::CFGSimplification)
103 .add(rr::Optimization::Pass::EarlyCSEPass)
104 .add(rr::Optimization::Pass::CFGSimplification)
105 .add(rr::Optimization::Pass::InstructionCombining);
Ben Clayton056d6922019-07-04 12:41:13 +0100106
107 rr::Nucleus::adjustDefaultConfig(cfg);
108}
109
Ben Claytond6c61362019-08-14 18:16:01 +0100110void setCPUDefaults()
111{
112 sw::CPUID::setEnableSSE4_1(true);
113 sw::CPUID::setEnableSSSE3(true);
114 sw::CPUID::setEnableSSE3(true);
115 sw::CPUID::setEnableSSE2(true);
116 sw::CPUID::setEnableSSE(true);
117}
118
119yarn::Scheduler* getOrCreateScheduler()
120{
121 static auto scheduler = std::unique_ptr<yarn::Scheduler>(new yarn::Scheduler());
122 scheduler->setThreadInitializer([] {
123 sw::CPUID::setFlushToZero(true);
124 sw::CPUID::setDenormalsAreZero(true);
125 });
126 scheduler->setWorkerThreadCount(std::min<size_t>(yarn::Thread::numLogicalCPUs(), 16));
127 return scheduler.get();
128}
129
Ben Clayton056d6922019-07-04 12:41:13 +0100130// initializeLibrary() is called by vkCreateInstance() to perform one-off global
131// initialization of the swiftshader driver.
132void initializeLibrary()
133{
134 static bool doOnce = [] {
135 setReactorDefaultConfig();
Ben Claytond6c61362019-08-14 18:16:01 +0100136 setCPUDefaults();
Ben Clayton056d6922019-07-04 12:41:13 +0100137 return true;
138 }();
139 (void)doOnce;
140}
141
Alexis Hetud6fae382019-04-05 13:19:46 -0400142}
143
Alexis Hetud73b8712018-09-21 15:14:43 -0400144extern "C"
145{
David 'Digit' Turnere7256192019-06-19 07:08:04 +0200146VK_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetInstanceProcAddr(VkInstance instance, const char* pName)
Alexis Hetud73b8712018-09-21 15:14:43 -0400147{
Ben Claytonfb280672019-04-25 11:16:15 +0100148 TRACE("(VkInstance instance = %p, const char* pName = %p)", instance, pName);
Nicolas Capensdc853642018-11-19 15:50:18 -0500149
Alexis Hetu7d96f512019-06-13 18:23:56 -0400150 return vk::GetInstanceProcAddr(vk::Cast(instance), pName);
Alexis Hetud73b8712018-09-21 15:14:43 -0400151}
152
David 'Digit' Turnere7256192019-06-19 07:08:04 +0200153VK_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion)
Hernan Liatisb2841fe2019-02-21 12:57:52 -0800154{
155 *pSupportedVersion = 3;
156 return VK_SUCCESS;
157}
158
Hernan Liatis2bb08642019-02-08 14:08:21 -0800159static const VkExtensionProperties instanceExtensionProperties[] =
160{
161 { VK_KHR_DEVICE_GROUP_CREATION_EXTENSION_NAME, VK_KHR_DEVICE_GROUP_CREATION_SPEC_VERSION },
162 { VK_KHR_EXTERNAL_FENCE_CAPABILITIES_EXTENSION_NAME, VK_KHR_EXTERNAL_FENCE_CAPABILITIES_SPEC_VERSION },
163 { VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME, VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_SPEC_VERSION },
164 { VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME, VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_SPEC_VERSION },
165 { VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_SPEC_VERSION },
Chris Forbes1d667d62019-04-05 08:25:18 -0700166#ifndef __ANDROID__
Hernan Liatis2bb08642019-02-08 14:08:21 -0800167 { VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_SURFACE_SPEC_VERSION },
Chris Forbes1d667d62019-04-05 08:25:18 -0700168#endif
Hernan Liatis2bb08642019-02-08 14:08:21 -0800169#ifdef VK_USE_PLATFORM_XLIB_KHR
170 { VK_KHR_XLIB_SURFACE_EXTENSION_NAME, VK_KHR_XLIB_SURFACE_SPEC_VERSION },
171#endif
Alexis Hetu0662a4a2019-07-08 15:06:40 -0400172#ifdef VK_USE_PLATFORM_MACOS_MVK
173 { VK_MVK_MACOS_SURFACE_EXTENSION_NAME, VK_MVK_MACOS_SURFACE_SPEC_VERSION },
174#endif
Nicolas Capensd3545372019-08-09 13:59:18 -0400175#ifdef VK_USE_PLATFORM_WIN32_KHR
176 { VK_KHR_WIN32_SURFACE_EXTENSION_NAME, VK_KHR_WIN32_SURFACE_SPEC_VERSION },
177#endif
Hernan Liatis2bb08642019-02-08 14:08:21 -0800178};
179
180static const VkExtensionProperties deviceExtensionProperties[] =
181{
182 { VK_KHR_16BIT_STORAGE_EXTENSION_NAME, VK_KHR_16BIT_STORAGE_SPEC_VERSION },
183 { VK_KHR_BIND_MEMORY_2_EXTENSION_NAME, VK_KHR_BIND_MEMORY_2_SPEC_VERSION },
184 { VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME, VK_KHR_DEDICATED_ALLOCATION_SPEC_VERSION },
185 { VK_KHR_DESCRIPTOR_UPDATE_TEMPLATE_EXTENSION_NAME, VK_KHR_DESCRIPTOR_UPDATE_TEMPLATE_SPEC_VERSION },
186 { VK_KHR_DEVICE_GROUP_EXTENSION_NAME, VK_KHR_DEVICE_GROUP_SPEC_VERSION },
187 { VK_KHR_EXTERNAL_FENCE_EXTENSION_NAME, VK_KHR_EXTERNAL_FENCE_SPEC_VERSION },
188 { VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME, VK_KHR_EXTERNAL_MEMORY_SPEC_VERSION },
189 { VK_KHR_EXTERNAL_SEMAPHORE_EXTENSION_NAME, VK_KHR_EXTERNAL_SEMAPHORE_SPEC_VERSION },
190 { VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME, VK_KHR_GET_MEMORY_REQUIREMENTS_2_SPEC_VERSION },
191 { VK_KHR_MAINTENANCE1_EXTENSION_NAME, VK_KHR_MAINTENANCE1_SPEC_VERSION },
192 { VK_KHR_MAINTENANCE2_EXTENSION_NAME, VK_KHR_MAINTENANCE2_SPEC_VERSION },
193 { VK_KHR_MAINTENANCE3_EXTENSION_NAME, VK_KHR_MAINTENANCE3_SPEC_VERSION },
194 { VK_KHR_MULTIVIEW_EXTENSION_NAME, VK_KHR_MULTIVIEW_SPEC_VERSION },
195 { VK_KHR_RELAXED_BLOCK_LAYOUT_EXTENSION_NAME, VK_KHR_RELAXED_BLOCK_LAYOUT_SPEC_VERSION },
196 { VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME, VK_KHR_SAMPLER_YCBCR_CONVERSION_SPEC_VERSION },
Chris Forbes83cdd252019-08-26 09:29:27 -0700197 // Only 1.1 core version of this is supported. The extension has additional requirements
198 //{ VK_KHR_SHADER_DRAW_PARAMETERS_EXTENSION_NAME, VK_KHR_SHADER_DRAW_PARAMETERS_SPEC_VERSION },
Hernan Liatis2bb08642019-02-08 14:08:21 -0800199 { VK_KHR_STORAGE_BUFFER_STORAGE_CLASS_EXTENSION_NAME, VK_KHR_STORAGE_BUFFER_STORAGE_CLASS_SPEC_VERSION },
Chris Forbes83cdd252019-08-26 09:29:27 -0700200 // Only 1.1 core version of this is supported. The extension has additional requirements
201 //{ VK_KHR_VARIABLE_POINTERS_EXTENSION_NAME, VK_KHR_VARIABLE_POINTERS_SPEC_VERSION },
Chris Forbes1d667d62019-04-05 08:25:18 -0700202#ifndef __ANDROID__
Hernan Liatiscff8c002019-02-25 15:56:36 -0800203 { VK_KHR_SWAPCHAIN_EXTENSION_NAME, VK_KHR_SWAPCHAIN_SPEC_VERSION },
Hernan Liatis8a91a352019-04-29 17:14:06 -0700204#else
205 { VK_ANDROID_NATIVE_BUFFER_EXTENSION_NAME, VK_ANDROID_NATIVE_BUFFER_SPEC_VERSION },
Chris Forbes1d667d62019-04-05 08:25:18 -0700206#endif
Hernan Liatis2bb08642019-02-08 14:08:21 -0800207};
208
Alexis Hetud73b8712018-09-21 15:14:43 -0400209VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance)
210{
Ben Claytonfb280672019-04-25 11:16:15 +0100211 TRACE("(const VkInstanceCreateInfo* pCreateInfo = %p, const VkAllocationCallbacks* pAllocator = %p, VkInstance* pInstance = %p)",
Alexis Hetud73b8712018-09-21 15:14:43 -0400212 pCreateInfo, pAllocator, pInstance);
213
Ben Clayton056d6922019-07-04 12:41:13 +0100214 initializeLibrary();
215
Alexis Hetu767b41b2018-09-26 11:25:46 -0400216 if(pCreateInfo->enabledLayerCount)
217 {
Ben Clayton00424c12019-03-17 17:29:30 +0000218 UNIMPLEMENTED("pCreateInfo->enabledLayerCount");
Alexis Hetu767b41b2018-09-26 11:25:46 -0400219 }
Alexis Hetud73b8712018-09-21 15:14:43 -0400220
Alexis Hetud6fae382019-04-05 13:19:46 -0400221 uint32_t extensionPropertiesCount = sizeof(instanceExtensionProperties) / sizeof(instanceExtensionProperties[0]);
Hernan Liatis2bb08642019-02-08 14:08:21 -0800222 for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; ++i)
Alexis Hetu767b41b2018-09-26 11:25:46 -0400223 {
Alexis Hetud6fae382019-04-05 13:19:46 -0400224 if (!HasExtensionProperty(pCreateInfo->ppEnabledExtensionNames[i], instanceExtensionProperties, extensionPropertiesCount))
Hernan Liatis2bb08642019-02-08 14:08:21 -0800225 {
226 return VK_ERROR_EXTENSION_NOT_PRESENT;
227 }
Alexis Hetu767b41b2018-09-26 11:25:46 -0400228 }
229
230 if(pCreateInfo->pNext)
231 {
232 switch(*reinterpret_cast<const VkStructureType*>(pCreateInfo->pNext))
233 {
234 case VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO:
235 // According to the Vulkan spec, section 2.7.2. Implicit Valid Usage:
236 // "The values VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO and
237 // VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO are reserved for
238 // internal use by the loader, and do not have corresponding
239 // Vulkan structures in this Specification."
240 break;
241 default:
Ben Clayton00424c12019-03-17 17:29:30 +0000242 UNIMPLEMENTED("pCreateInfo->pNext");
Alexis Hetu767b41b2018-09-26 11:25:46 -0400243 }
244 }
245
246 *pInstance = VK_NULL_HANDLE;
247 VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
248
249 VkResult result = vk::DispatchablePhysicalDevice::Create(pAllocator, pCreateInfo, &physicalDevice);
250 if(result != VK_SUCCESS)
251 {
252 return result;
253 }
254
Nicolas Capens0c736802019-05-27 12:53:31 -0400255 result = vk::DispatchableInstance::Create(pAllocator, pCreateInfo, pInstance, physicalDevice);
Alexis Hetu767b41b2018-09-26 11:25:46 -0400256 if(result != VK_SUCCESS)
257 {
258 vk::destroy(physicalDevice, pAllocator);
259 return result;
260 }
261
262 return result;
Alexis Hetud73b8712018-09-21 15:14:43 -0400263}
264
265VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator)
266{
Ben Claytonfb280672019-04-25 11:16:15 +0100267 TRACE("(VkInstance instance = %p, const VkAllocationCallbacks* pAllocator = %p)", instance, pAllocator);
Alexis Hetud73b8712018-09-21 15:14:43 -0400268
Alexis Hetu767b41b2018-09-26 11:25:46 -0400269 vk::destroy(instance, pAllocator);
Alexis Hetud73b8712018-09-21 15:14:43 -0400270}
271
272VKAPI_ATTR VkResult VKAPI_CALL vkEnumeratePhysicalDevices(VkInstance instance, uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices)
273{
Ben Claytonfb280672019-04-25 11:16:15 +0100274 TRACE("(VkInstance instance = %p, uint32_t* pPhysicalDeviceCount = %p, VkPhysicalDevice* pPhysicalDevices = %p)",
Alexis Hetud73b8712018-09-21 15:14:43 -0400275 instance, pPhysicalDeviceCount, pPhysicalDevices);
276
Chris Forbesdf84b942019-06-12 11:28:09 -0700277 return vk::Cast(instance)->getPhysicalDevices(pPhysicalDeviceCount, pPhysicalDevices);
Alexis Hetud73b8712018-09-21 15:14:43 -0400278}
279
280VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures* pFeatures)
281{
Ben Claytonfb280672019-04-25 11:16:15 +0100282 TRACE("(VkPhysicalDevice physicalDevice = %p, VkPhysicalDeviceFeatures* pFeatures = %p)",
Alexis Hetud73b8712018-09-21 15:14:43 -0400283 physicalDevice, pFeatures);
284
Alexis Hetu767b41b2018-09-26 11:25:46 -0400285 *pFeatures = vk::Cast(physicalDevice)->getFeatures();
Alexis Hetud73b8712018-09-21 15:14:43 -0400286}
287
288VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkFormatProperties* pFormatProperties)
289{
Ben Claytonfb280672019-04-25 11:16:15 +0100290 TRACE("GetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice = %p, VkFormat format = %d, VkFormatProperties* pFormatProperties = %p)",
Alexis Hetud73b8712018-09-21 15:14:43 -0400291 physicalDevice, (int)format, pFormatProperties);
292
Alexis Hetu767b41b2018-09-26 11:25:46 -0400293 vk::Cast(physicalDevice)->getFormatProperties(format, pFormatProperties);
Alexis Hetud73b8712018-09-21 15:14:43 -0400294}
295
296VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, VkImageFormatProperties* pImageFormatProperties)
297{
Ben Claytonfb280672019-04-25 11:16:15 +0100298 TRACE("(VkPhysicalDevice physicalDevice = %p, VkFormat format = %d, VkImageType type = %d, VkImageTiling tiling = %d, VkImageUsageFlags usage = %d, VkImageCreateFlags flags = %d, VkImageFormatProperties* pImageFormatProperties = %p)",
Alexis Hetud73b8712018-09-21 15:14:43 -0400299 physicalDevice, (int)format, (int)type, (int)tiling, usage, flags, pImageFormatProperties);
300
Nicolas Capens7e01e4e2019-05-18 08:19:07 -0400301 // "If the combination of parameters to vkGetPhysicalDeviceImageFormatProperties is not supported by the implementation
302 // for use in vkCreateImage, then all members of VkImageFormatProperties will be filled with zero."
303 memset(pImageFormatProperties, 0, sizeof(VkImageFormatProperties));
304
Chris Forbes57378332019-01-16 15:17:24 -0800305 VkFormatProperties properties;
306 vk::Cast(physicalDevice)->getFormatProperties(format, &properties);
307
Chris Forbes1bc77312019-05-09 14:02:26 -0700308 VkFormatFeatureFlags features;
Chris Forbes57378332019-01-16 15:17:24 -0800309 switch (tiling)
310 {
311 case VK_IMAGE_TILING_LINEAR:
Chris Forbes1bc77312019-05-09 14:02:26 -0700312 features = properties.linearTilingFeatures;
Chris Forbes57378332019-01-16 15:17:24 -0800313 break;
314
315 case VK_IMAGE_TILING_OPTIMAL:
Chris Forbes1bc77312019-05-09 14:02:26 -0700316 features = properties.optimalTilingFeatures;
Chris Forbes57378332019-01-16 15:17:24 -0800317 break;
318
319 default:
Ben Clayton00424c12019-03-17 17:29:30 +0000320 UNIMPLEMENTED("tiling");
Chris Forbes1bc77312019-05-09 14:02:26 -0700321 features = 0;
322 }
323
324 if (features == 0)
325 {
326 return VK_ERROR_FORMAT_NOT_SUPPORTED;
327 }
328
329 // Check for usage conflict with features
330 if ((usage & VK_IMAGE_USAGE_SAMPLED_BIT) && !(features & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT))
331 {
332 return VK_ERROR_FORMAT_NOT_SUPPORTED;
Chris Forbes57378332019-01-16 15:17:24 -0800333 }
334
Chris Forbes0559bc42019-05-11 10:47:11 -0700335 if ((usage & VK_IMAGE_USAGE_STORAGE_BIT) && !(features & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT))
336 {
337 return VK_ERROR_FORMAT_NOT_SUPPORTED;
338 }
339
340 if ((usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) && !(features & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT))
341 {
342 return VK_ERROR_FORMAT_NOT_SUPPORTED;
343 }
344
345 if ((usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) && !(features & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT))
346 {
347 return VK_ERROR_FORMAT_NOT_SUPPORTED;
348 }
349
350 if ((usage & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT) && !(features & (VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT | VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)))
351 {
352 return VK_ERROR_FORMAT_NOT_SUPPORTED;
353 }
354
355 if ((usage & VK_IMAGE_USAGE_TRANSFER_SRC_BIT) && !(features & VK_FORMAT_FEATURE_TRANSFER_SRC_BIT))
356 {
357 return VK_ERROR_FORMAT_NOT_SUPPORTED;
358 }
359
360 if ((usage & VK_IMAGE_USAGE_TRANSFER_DST_BIT) && !(features & VK_FORMAT_FEATURE_TRANSFER_DST_BIT))
361 {
362 return VK_ERROR_FORMAT_NOT_SUPPORTED;
363 }
364
365 auto allRecognizedUsageBits = VK_IMAGE_USAGE_SAMPLED_BIT |
366 VK_IMAGE_USAGE_STORAGE_BIT |
367 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
368 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
369 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT |
370 VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
371 VK_IMAGE_USAGE_TRANSFER_DST_BIT |
372 VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT;
373 ASSERT(!(usage & ~(allRecognizedUsageBits)));
374
Nicolas Capens7e01e4e2019-05-18 08:19:07 -0400375 // "Images created with tiling equal to VK_IMAGE_TILING_LINEAR have further restrictions on their limits and capabilities
376 // compared to images created with tiling equal to VK_IMAGE_TILING_OPTIMAL."
377 if(tiling == VK_IMAGE_TILING_LINEAR)
378 {
379 if(type != VK_IMAGE_TYPE_2D)
380 {
381 return VK_ERROR_FORMAT_NOT_SUPPORTED;
382 }
383
384 if(vk::Format(format).isDepth() || vk::Format(format).isStencil())
385 {
386 return VK_ERROR_FORMAT_NOT_SUPPORTED;
387 }
388 }
389
Hernan Liatisbd18d582019-05-29 15:38:58 -0700390 // "Images created with a format from one of those listed in Formats requiring sampler Y'CBCR conversion for VK_IMAGE_ASPECT_COLOR_BIT image views
Nicolas Capens7e01e4e2019-05-18 08:19:07 -0400391 // have further restrictions on their limits and capabilities compared to images created with other formats."
392 if(vk::Format(format).isYcbcrFormat())
393 {
394 if(type != VK_IMAGE_TYPE_2D)
395 {
396 return VK_ERROR_FORMAT_NOT_SUPPORTED;
397 }
398 }
399
Alexis Hetu767b41b2018-09-26 11:25:46 -0400400 vk::Cast(physicalDevice)->getImageFormatProperties(format, type, tiling, usage, flags, pImageFormatProperties);
Alexis Hetud73b8712018-09-21 15:14:43 -0400401
402 return VK_SUCCESS;
403}
404
405VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties* pProperties)
406{
Ben Claytonfb280672019-04-25 11:16:15 +0100407 TRACE("(VkPhysicalDevice physicalDevice = %p, VkPhysicalDeviceProperties* pProperties = %p)",
Alexis Hetud73b8712018-09-21 15:14:43 -0400408 physicalDevice, pProperties);
409
Alexis Hetu767b41b2018-09-26 11:25:46 -0400410 *pProperties = vk::Cast(physicalDevice)->getProperties();
Alexis Hetud73b8712018-09-21 15:14:43 -0400411}
412
413VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, uint32_t* pQueueFamilyPropertyCount, VkQueueFamilyProperties* pQueueFamilyProperties)
414{
Ben Claytonfb280672019-04-25 11:16:15 +0100415 TRACE("(VkPhysicalDevice physicalDevice = %p, uint32_t* pQueueFamilyPropertyCount = %p, VkQueueFamilyProperties* pQueueFamilyProperties = %p))", physicalDevice, pQueueFamilyPropertyCount, pQueueFamilyProperties);
Alexis Hetud73b8712018-09-21 15:14:43 -0400416
Alexis Hetu767b41b2018-09-26 11:25:46 -0400417 if(!pQueueFamilyProperties)
418 {
419 *pQueueFamilyPropertyCount = vk::Cast(physicalDevice)->getQueueFamilyPropertyCount();
420 }
421 else
422 {
423 vk::Cast(physicalDevice)->getQueueFamilyProperties(*pQueueFamilyPropertyCount, pQueueFamilyProperties);
424 }
Alexis Hetud73b8712018-09-21 15:14:43 -0400425}
426
427VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceMemoryProperties* pMemoryProperties)
428{
Ben Claytonfb280672019-04-25 11:16:15 +0100429 TRACE("(VkPhysicalDevice physicalDevice = %p, VkPhysicalDeviceMemoryProperties* pMemoryProperties = %p)", physicalDevice, pMemoryProperties);
Alexis Hetud73b8712018-09-21 15:14:43 -0400430
Alexis Hetu767b41b2018-09-26 11:25:46 -0400431 *pMemoryProperties = vk::Cast(physicalDevice)->getMemoryProperties();
Alexis Hetud73b8712018-09-21 15:14:43 -0400432}
433
Saman Samif4d2a442019-05-21 15:04:41 -0400434VK_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* pName)
Alexis Hetud73b8712018-09-21 15:14:43 -0400435{
Ben Claytonfb280672019-04-25 11:16:15 +0100436 TRACE("(VkInstance instance = %p, const char* pName = %p)", instance, pName);
Nicolas Capensdc853642018-11-19 15:50:18 -0500437
Alexis Hetu7d96f512019-06-13 18:23:56 -0400438 return vk::GetInstanceProcAddr(vk::Cast(instance), pName);
Alexis Hetud73b8712018-09-21 15:14:43 -0400439}
440
441VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice device, const char* pName)
442{
Ben Claytonfb280672019-04-25 11:16:15 +0100443 TRACE("(VkDevice device = %p, const char* pName = %p)", device, pName);
Nicolas Capensdc853642018-11-19 15:50:18 -0500444
Alexis Hetu7d96f512019-06-13 18:23:56 -0400445 return vk::GetDeviceProcAddr(vk::Cast(device), pName);
Alexis Hetud73b8712018-09-21 15:14:43 -0400446}
447
448VKAPI_ATTR VkResult VKAPI_CALL vkCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDevice* pDevice)
449{
Ben Claytonfb280672019-04-25 11:16:15 +0100450 TRACE("(VkPhysicalDevice physicalDevice = %p, const VkDeviceCreateInfo* pCreateInfo = %p, const VkAllocationCallbacks* pAllocator = %p, VkDevice* pDevice = %p)",
Alexis Hetud73b8712018-09-21 15:14:43 -0400451 physicalDevice, pCreateInfo, pAllocator, pDevice);
452
Nicolas Capensd689d1c2018-11-19 16:02:36 -0500453 if(pCreateInfo->enabledLayerCount)
Alexis Hetu767b41b2018-09-26 11:25:46 -0400454 {
Nicolas Capensd689d1c2018-11-19 16:02:36 -0500455 // "The ppEnabledLayerNames and enabledLayerCount members of VkDeviceCreateInfo are deprecated and their values must be ignored by implementations."
Ben Clayton00424c12019-03-17 17:29:30 +0000456 UNIMPLEMENTED("pCreateInfo->enabledLayerCount"); // TODO(b/119321052): UNIMPLEMENTED() should be used only for features that must still be implemented. Use a more informational macro here.
Alexis Hetu767b41b2018-09-26 11:25:46 -0400457 }
Alexis Hetud73b8712018-09-21 15:14:43 -0400458
Alexis Hetud6fae382019-04-05 13:19:46 -0400459 uint32_t extensionPropertiesCount = sizeof(deviceExtensionProperties) / sizeof(deviceExtensionProperties[0]);
Hernan Liatiscff8c002019-02-25 15:56:36 -0800460 for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; ++i)
461 {
Alexis Hetud6fae382019-04-05 13:19:46 -0400462 if (!HasExtensionProperty(pCreateInfo->ppEnabledExtensionNames[i], deviceExtensionProperties, extensionPropertiesCount))
Hernan Liatiscff8c002019-02-25 15:56:36 -0800463 {
464 return VK_ERROR_EXTENSION_NOT_PRESENT;
465 }
466 }
467
Nicolas Capensd689d1c2018-11-19 16:02:36 -0500468 const VkBaseInStructure* extensionCreateInfo = reinterpret_cast<const VkBaseInStructure*>(pCreateInfo->pNext);
469
Nicolas Capensa29aa772019-06-26 00:36:28 -0400470 const VkPhysicalDeviceFeatures *enabledFeatures = pCreateInfo->pEnabledFeatures;
471
Nicolas Capensd689d1c2018-11-19 16:02:36 -0500472 while(extensionCreateInfo)
Alexis Hetu767b41b2018-09-26 11:25:46 -0400473 {
Nicolas Capensd689d1c2018-11-19 16:02:36 -0500474 switch(extensionCreateInfo->sType)
Alexis Hetu767b41b2018-09-26 11:25:46 -0400475 {
476 case VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO:
477 // According to the Vulkan spec, section 2.7.2. Implicit Valid Usage:
478 // "The values VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO and
479 // VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO are reserved for
480 // internal use by the loader, and do not have corresponding
481 // Vulkan structures in this Specification."
482 break;
Nicolas Capensd689d1c2018-11-19 16:02:36 -0500483 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2:
484 {
485 ASSERT(!pCreateInfo->pEnabledFeatures); // "If the pNext chain includes a VkPhysicalDeviceFeatures2 structure, then pEnabledFeatures must be NULL"
486
487 const VkPhysicalDeviceFeatures2* physicalDeviceFeatures2 = reinterpret_cast<const VkPhysicalDeviceFeatures2*>(extensionCreateInfo);
488
Nicolas Capensa29aa772019-06-26 00:36:28 -0400489 enabledFeatures = &physicalDeviceFeatures2->features;
Nicolas Capensd689d1c2018-11-19 16:02:36 -0500490 }
491 break;
492 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES:
493 {
494 const VkPhysicalDeviceSamplerYcbcrConversionFeatures* samplerYcbcrConversionFeatures = reinterpret_cast<const VkPhysicalDeviceSamplerYcbcrConversionFeatures*>(extensionCreateInfo);
495
Nicolas Capense2f5da42019-05-16 11:01:31 -0400496 // YCbCr conversion is supported.
497 // samplerYcbcrConversionFeatures->samplerYcbcrConversion can be VK_TRUE or VK_FALSE.
498 // No action needs to be taken on our end in either case; it's the apps responsibility that
Hernan Liatisbd18d582019-05-29 15:38:58 -0700499 // "To create a sampler Y'CbCr conversion, the samplerYcbcrConversion feature must be enabled."
Nicolas Capense2f5da42019-05-16 11:01:31 -0400500 (void)samplerYcbcrConversionFeatures->samplerYcbcrConversion;
Nicolas Capensd689d1c2018-11-19 16:02:36 -0500501 }
502 break;
503 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES:
504 {
505 const VkPhysicalDevice16BitStorageFeatures* storage16BitFeatures = reinterpret_cast<const VkPhysicalDevice16BitStorageFeatures*>(extensionCreateInfo);
506
507 if(storage16BitFeatures->storageBuffer16BitAccess == VK_TRUE ||
508 storage16BitFeatures->uniformAndStorageBuffer16BitAccess == VK_TRUE ||
509 storage16BitFeatures->storagePushConstant16 == VK_TRUE ||
510 storage16BitFeatures->storageInputOutput16 == VK_TRUE)
511 {
512 return VK_ERROR_FEATURE_NOT_PRESENT;
513 }
514 }
515 break;
516 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES:
517 {
518 const VkPhysicalDeviceVariablePointerFeatures* variablePointerFeatures = reinterpret_cast<const VkPhysicalDeviceVariablePointerFeatures*>(extensionCreateInfo);
519
520 if(variablePointerFeatures->variablePointersStorageBuffer == VK_TRUE ||
521 variablePointerFeatures->variablePointers == VK_TRUE)
522 {
523 return VK_ERROR_FEATURE_NOT_PRESENT;
524 }
525 }
526 break;
Alexis Hetu5ebd2c02019-01-22 17:17:27 -0500527 case VK_STRUCTURE_TYPE_DEVICE_GROUP_DEVICE_CREATE_INFO:
528 {
529 const VkDeviceGroupDeviceCreateInfo* groupDeviceCreateInfo = reinterpret_cast<const VkDeviceGroupDeviceCreateInfo*>(extensionCreateInfo);
530
531 if((groupDeviceCreateInfo->physicalDeviceCount != 1) ||
532 (groupDeviceCreateInfo->pPhysicalDevices[0] != physicalDevice))
533 {
534 return VK_ERROR_FEATURE_NOT_PRESENT;
535 }
536 }
537 break;
Chris Forbesaad8cfc2019-08-15 19:09:16 -0700538 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES:
539 {
540 const VkPhysicalDeviceMultiviewFeatures* multiviewFeatures = reinterpret_cast<const VkPhysicalDeviceMultiviewFeatures*>(extensionCreateInfo);
541
Chris Forbes02d4c0d2019-08-21 12:04:34 -0700542 if (multiviewFeatures->multiviewGeometryShader ||
Chris Forbesaad8cfc2019-08-15 19:09:16 -0700543 multiviewFeatures->multiviewTessellationShader)
544 {
545 return VK_ERROR_FEATURE_NOT_PRESENT;
546 }
547 }
548 break;
Chris Forbesd3353022019-08-15 19:21:55 -0700549 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETERS_FEATURES:
550 {
551 const VkPhysicalDeviceShaderDrawParametersFeatures* shaderDrawParametersFeatures = reinterpret_cast<const VkPhysicalDeviceShaderDrawParametersFeatures*>(extensionCreateInfo);
552
553 if (shaderDrawParametersFeatures->shaderDrawParameters)
554 {
555 return VK_ERROR_FEATURE_NOT_PRESENT;
556 }
557 }
558 break;
Alexis Hetu767b41b2018-09-26 11:25:46 -0400559 default:
Nicolas Capensd689d1c2018-11-19 16:02:36 -0500560 // "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]"
Nicolas Capens6b63c802019-05-16 11:10:34 -0400561 UNIMPLEMENTED("extensionCreateInfo->sType %d", int(extensionCreateInfo->sType)); // TODO(b/119321052): UNIMPLEMENTED() should be used only for features that must still be implemented. Use a more informational macro here.
Nicolas Capensd689d1c2018-11-19 16:02:36 -0500562 break;
Alexis Hetu767b41b2018-09-26 11:25:46 -0400563 }
Nicolas Capensd689d1c2018-11-19 16:02:36 -0500564
565 extensionCreateInfo = extensionCreateInfo->pNext;
Alexis Hetu767b41b2018-09-26 11:25:46 -0400566 }
567
568 ASSERT(pCreateInfo->queueCreateInfoCount > 0);
569
Nicolas Capensa29aa772019-06-26 00:36:28 -0400570 if(enabledFeatures)
Alexis Hetu767b41b2018-09-26 11:25:46 -0400571 {
Nicolas Capensa29aa772019-06-26 00:36:28 -0400572 if(!vk::Cast(physicalDevice)->hasFeatures(*enabledFeatures))
Nicolas Capensd5f14892018-11-13 14:06:37 -0500573 {
574 return VK_ERROR_FEATURE_NOT_PRESENT;
575 }
Alexis Hetu767b41b2018-09-26 11:25:46 -0400576 }
577
578 uint32_t queueFamilyPropertyCount = vk::Cast(physicalDevice)->getQueueFamilyPropertyCount();
579
580 for(uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; i++)
581 {
582 const VkDeviceQueueCreateInfo& queueCreateInfo = pCreateInfo->pQueueCreateInfos[i];
583 if(queueCreateInfo.pNext || queueCreateInfo.flags)
584 {
Ben Clayton00424c12019-03-17 17:29:30 +0000585 UNIMPLEMENTED("queueCreateInfo.pNext || queueCreateInfo.flags");
Alexis Hetu767b41b2018-09-26 11:25:46 -0400586 }
587
588 ASSERT(queueCreateInfo.queueFamilyIndex < queueFamilyPropertyCount);
Nicolas Capensd689d1c2018-11-19 16:02:36 -0500589 (void)queueFamilyPropertyCount; // Silence unused variable warning
Alexis Hetu767b41b2018-09-26 11:25:46 -0400590 }
591
Ben Claytond6c61362019-08-14 18:16:01 +0100592 auto scheduler = getOrCreateScheduler();
593 return vk::DispatchableDevice::Create(pAllocator, pCreateInfo, pDevice, vk::Cast(physicalDevice), enabledFeatures, scheduler);
Alexis Hetud73b8712018-09-21 15:14:43 -0400594}
595
596VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator)
597{
Ben Claytonfb280672019-04-25 11:16:15 +0100598 TRACE("(VkDevice device = %p, const VkAllocationCallbacks* pAllocator = %p)", device, pAllocator);
Alexis Hetud73b8712018-09-21 15:14:43 -0400599
Alexis Hetu767b41b2018-09-26 11:25:46 -0400600 vk::destroy(device, pAllocator);
Alexis Hetud73b8712018-09-21 15:14:43 -0400601}
602
603VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char* pLayerName, uint32_t* pPropertyCount, VkExtensionProperties* pProperties)
604{
Ben Claytonfb280672019-04-25 11:16:15 +0100605 TRACE("(const char* pLayerName = %p, uint32_t* pPropertyCount = %p, VkExtensionProperties* pProperties = %p)",
Alexis Hetud73b8712018-09-21 15:14:43 -0400606 pLayerName, pPropertyCount, pProperties);
607
Hernan Liatis2bb08642019-02-08 14:08:21 -0800608 uint32_t extensionPropertiesCount = sizeof(instanceExtensionProperties) / sizeof(instanceExtensionProperties[0]);
Chris Forbes59781502018-10-25 11:19:54 -0700609
Alexis Hetud73b8712018-09-21 15:14:43 -0400610 if(!pProperties)
611 {
Chris Forbes59781502018-10-25 11:19:54 -0700612 *pPropertyCount = extensionPropertiesCount;
Alexis Hetud73b8712018-09-21 15:14:43 -0400613 return VK_SUCCESS;
614 }
615
Chris Forbesdf84b942019-06-12 11:28:09 -0700616 auto toCopy = std::min(*pPropertyCount, extensionPropertiesCount);
617 for(uint32_t i = 0; i < toCopy; i++)
Alexis Hetud73b8712018-09-21 15:14:43 -0400618 {
Hernan Liatis2bb08642019-02-08 14:08:21 -0800619 pProperties[i] = instanceExtensionProperties[i];
Alexis Hetud73b8712018-09-21 15:14:43 -0400620 }
621
Chris Forbesdf84b942019-06-12 11:28:09 -0700622 *pPropertyCount = toCopy;
623 return (toCopy < extensionPropertiesCount) ? VK_INCOMPLETE : VK_SUCCESS;
Alexis Hetud73b8712018-09-21 15:14:43 -0400624}
625
626VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char* pLayerName, uint32_t* pPropertyCount, VkExtensionProperties* pProperties)
627{
Ben Claytonfb280672019-04-25 11:16:15 +0100628 TRACE("(VkPhysicalDevice physicalDevice = %p, const char* pLayerName, uint32_t* pPropertyCount = %p, VkExtensionProperties* pProperties = %p)", physicalDevice, pPropertyCount, pProperties);
Alexis Hetud73b8712018-09-21 15:14:43 -0400629
Hernan Liatis2bb08642019-02-08 14:08:21 -0800630 uint32_t extensionPropertiesCount = sizeof(deviceExtensionProperties) / sizeof(deviceExtensionProperties[0]);
Chris Forbes59781502018-10-25 11:19:54 -0700631
Alexis Hetu767b41b2018-09-26 11:25:46 -0400632 if(!pProperties)
633 {
Chris Forbes59781502018-10-25 11:19:54 -0700634 *pPropertyCount = extensionPropertiesCount;
Alexis Hetu767b41b2018-09-26 11:25:46 -0400635 return VK_SUCCESS;
636 }
Alexis Hetud73b8712018-09-21 15:14:43 -0400637
Chris Forbesdf84b942019-06-12 11:28:09 -0700638 auto toCopy = std::min(*pPropertyCount, extensionPropertiesCount);
639 for(uint32_t i = 0; i < toCopy; i++)
Chris Forbes59781502018-10-25 11:19:54 -0700640 {
Hernan Liatis2bb08642019-02-08 14:08:21 -0800641 pProperties[i] = deviceExtensionProperties[i];
Chris Forbes59781502018-10-25 11:19:54 -0700642 }
643
Chris Forbesdf84b942019-06-12 11:28:09 -0700644 *pPropertyCount = toCopy;
645 return (toCopy < extensionPropertiesCount) ? VK_INCOMPLETE : VK_SUCCESS;
Alexis Hetud73b8712018-09-21 15:14:43 -0400646}
647
648VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t* pPropertyCount, VkLayerProperties* pProperties)
649{
Ben Claytonfb280672019-04-25 11:16:15 +0100650 TRACE("(uint32_t* pPropertyCount = %p, VkLayerProperties* pProperties = %p)", pPropertyCount, pProperties);
Alexis Hetud73b8712018-09-21 15:14:43 -0400651
Alexis Hetu767b41b2018-09-26 11:25:46 -0400652 if(!pProperties)
653 {
654 *pPropertyCount = 0;
655 return VK_SUCCESS;
656 }
Alexis Hetud73b8712018-09-21 15:14:43 -0400657
658 return VK_SUCCESS;
659}
660
661VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t* pPropertyCount, VkLayerProperties* pProperties)
662{
Ben Claytonfb280672019-04-25 11:16:15 +0100663 TRACE("(VkPhysicalDevice physicalDevice = %p, uint32_t* pPropertyCount = %p, VkLayerProperties* pProperties = %p)", physicalDevice, pPropertyCount, pProperties);
Alexis Hetud73b8712018-09-21 15:14:43 -0400664
Alexis Hetu767b41b2018-09-26 11:25:46 -0400665 if(!pProperties)
666 {
667 *pPropertyCount = 0;
668 return VK_SUCCESS;
669 }
Alexis Hetud73b8712018-09-21 15:14:43 -0400670
671 return VK_SUCCESS;
672}
673
674VKAPI_ATTR void VKAPI_CALL vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue* pQueue)
675{
Ben Claytonfb280672019-04-25 11:16:15 +0100676 TRACE("(VkDevice device = %p, uint32_t queueFamilyIndex = %d, uint32_t queueIndex = %d, VkQueue* pQueue = %p)",
Alexis Hetud73b8712018-09-21 15:14:43 -0400677 device, queueFamilyIndex, queueIndex, pQueue);
678
Alexis Hetu767b41b2018-09-26 11:25:46 -0400679 *pQueue = vk::Cast(device)->getQueue(queueFamilyIndex, queueIndex);
Alexis Hetud73b8712018-09-21 15:14:43 -0400680}
681
682VKAPI_ATTR VkResult VKAPI_CALL vkQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence fence)
683{
Ben Claytonfb280672019-04-25 11:16:15 +0100684 TRACE("(VkQueue queue = %p, uint32_t submitCount = %d, const VkSubmitInfo* pSubmits = %p, VkFence fence = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -0400685 queue, submitCount, pSubmits, static_cast<void*>(fence));
Alexis Hetu072dc0d2018-10-31 11:41:25 -0400686
Alexis Hetu7d96f512019-06-13 18:23:56 -0400687 return vk::Cast(queue)->submit(submitCount, pSubmits, vk::Cast(fence));
Alexis Hetud73b8712018-09-21 15:14:43 -0400688}
689
Nicolas Capensde16f322019-02-12 00:32:31 -0500690VKAPI_ATTR VkResult VKAPI_CALL vkQueueWaitIdle(VkQueue queue)
691{
Ben Claytonfb280672019-04-25 11:16:15 +0100692 TRACE("(VkQueue queue = %p)", queue);
Nicolas Capensde16f322019-02-12 00:32:31 -0500693
Alexis Hetue1f51b92019-04-23 15:34:34 -0400694 return vk::Cast(queue)->waitIdle();
Nicolas Capensde16f322019-02-12 00:32:31 -0500695}
696
697VKAPI_ATTR VkResult VKAPI_CALL vkDeviceWaitIdle(VkDevice device)
698{
Ben Claytonfb280672019-04-25 11:16:15 +0100699 TRACE("(VkDevice device = %p)", device);
Nicolas Capensde16f322019-02-12 00:32:31 -0500700
Alexis Hetue1f51b92019-04-23 15:34:34 -0400701 return vk::Cast(device)->waitIdle();
Alexis Hetud73b8712018-09-21 15:14:43 -0400702}
703
704VKAPI_ATTR VkResult VKAPI_CALL vkAllocateMemory(VkDevice device, const VkMemoryAllocateInfo* pAllocateInfo, const VkAllocationCallbacks* pAllocator, VkDeviceMemory* pMemory)
705{
Ben Claytonfb280672019-04-25 11:16:15 +0100706 TRACE("(VkDevice device = %p, const VkMemoryAllocateInfo* pAllocateInfo = %p, const VkAllocationCallbacks* pAllocator = %p, VkDeviceMemory* pMemory = %p)",
Alexis Hetud73b8712018-09-21 15:14:43 -0400707 device, pAllocateInfo, pAllocator, pMemory);
708
Alexis Hetu00835732019-04-10 16:36:31 -0400709 const VkBaseInStructure* allocationInfo = reinterpret_cast<const VkBaseInStructure*>(pAllocateInfo->pNext);
Alexis Hetu7ca9f4a2019-01-17 14:51:43 -0500710 while(allocationInfo)
Alexis Hetu38ff8302018-10-18 15:08:13 -0400711 {
Alexis Hetu7ca9f4a2019-01-17 14:51:43 -0500712 switch(allocationInfo->sType)
713 {
714 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO:
715 // This can safely be ignored, as the Vulkan spec mentions:
716 // "If the pNext chain includes a VkMemoryDedicatedAllocateInfo structure, then that structure
717 // includes a handle of the sole buffer or image resource that the memory *can* be bound to."
718 break;
Alexis Hetu026ceef2019-05-07 17:35:11 -0400719 case VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_FLAGS_INFO:
720 // This extension controls on which physical devices the memory gets allocated.
721 // SwiftShader only has a single physical device, so this extension does nothing in this case.
722 break;
Alexis Hetu7ca9f4a2019-01-17 14:51:43 -0500723 default:
Ben Clayton00424c12019-03-17 17:29:30 +0000724 UNIMPLEMENTED("allocationInfo->sType");
Alexis Hetu7ca9f4a2019-01-17 14:51:43 -0500725 break;
726 }
727
728 allocationInfo = allocationInfo->pNext;
Alexis Hetu38ff8302018-10-18 15:08:13 -0400729 }
Alexis Hetud73b8712018-09-21 15:14:43 -0400730
Alexis Hetu38ff8302018-10-18 15:08:13 -0400731 VkResult result = vk::DeviceMemory::Create(pAllocator, pAllocateInfo, pMemory);
732 if(result != VK_SUCCESS)
733 {
734 return result;
735 }
736
737 // Make sure the memory allocation is done now so that OOM errors can be checked now
738 result = vk::Cast(*pMemory)->allocate();
739 if(result != VK_SUCCESS)
740 {
741 vk::destroy(*pMemory, pAllocator);
742 *pMemory = VK_NULL_HANDLE;
743 }
744
745 return result;
Alexis Hetud73b8712018-09-21 15:14:43 -0400746}
747
748VKAPI_ATTR void VKAPI_CALL vkFreeMemory(VkDevice device, VkDeviceMemory memory, const VkAllocationCallbacks* pAllocator)
749{
Ben Claytonfb280672019-04-25 11:16:15 +0100750 TRACE("(VkDevice device = %p, VkDeviceMemory memory = %p, const VkAllocationCallbacks* pAllocator = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -0400751 device, static_cast<void*>(memory), pAllocator);
Alexis Hetud73b8712018-09-21 15:14:43 -0400752
Alexis Hetu38ff8302018-10-18 15:08:13 -0400753 vk::destroy(memory, pAllocator);
Alexis Hetud73b8712018-09-21 15:14:43 -0400754}
755
756VKAPI_ATTR VkResult VKAPI_CALL vkMapMemory(VkDevice device, VkDeviceMemory memory, VkDeviceSize offset, VkDeviceSize size, VkMemoryMapFlags flags, void** ppData)
757{
Ben Claytonfb280672019-04-25 11:16:15 +0100758 TRACE("(VkDevice device = %p, VkDeviceMemory memory = %p, VkDeviceSize offset = %d, VkDeviceSize size = %d, VkMemoryMapFlags flags = %d, void** ppData = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -0400759 device, static_cast<void*>(memory), int(offset), int(size), flags, ppData);
Alexis Hetud73b8712018-09-21 15:14:43 -0400760
Alexis Hetu38ff8302018-10-18 15:08:13 -0400761 return vk::Cast(memory)->map(offset, size, ppData);
Alexis Hetud73b8712018-09-21 15:14:43 -0400762}
763
764VKAPI_ATTR void VKAPI_CALL vkUnmapMemory(VkDevice device, VkDeviceMemory memory)
765{
Alexis Hetu2d77aea2019-06-17 13:43:50 -0400766 TRACE("(VkDevice device = %p, VkDeviceMemory memory = %p)", device, static_cast<void*>(memory));
Alexis Hetud73b8712018-09-21 15:14:43 -0400767
Alexis Hetu38ff8302018-10-18 15:08:13 -0400768 // Noop, memory will be released when the DeviceMemory object is released
Alexis Hetud73b8712018-09-21 15:14:43 -0400769}
770
771VKAPI_ATTR VkResult VKAPI_CALL vkFlushMappedMemoryRanges(VkDevice device, uint32_t memoryRangeCount, const VkMappedMemoryRange* pMemoryRanges)
772{
Ben Claytonfb280672019-04-25 11:16:15 +0100773 TRACE("(VkDevice device = %p, uint32_t memoryRangeCount = %d, const VkMappedMemoryRange* pMemoryRanges = %p)",
Alexis Hetud73b8712018-09-21 15:14:43 -0400774 device, memoryRangeCount, pMemoryRanges);
775
Alexis Hetu38ff8302018-10-18 15:08:13 -0400776 // Noop, host and device memory are the same to SwiftShader
Alexis Hetud73b8712018-09-21 15:14:43 -0400777
778 return VK_SUCCESS;
779}
780
781VKAPI_ATTR VkResult VKAPI_CALL vkInvalidateMappedMemoryRanges(VkDevice device, uint32_t memoryRangeCount, const VkMappedMemoryRange* pMemoryRanges)
782{
Ben Claytonfb280672019-04-25 11:16:15 +0100783 TRACE("(VkDevice device = %p, uint32_t memoryRangeCount = %d, const VkMappedMemoryRange* pMemoryRanges = %p)",
Alexis Hetud73b8712018-09-21 15:14:43 -0400784 device, memoryRangeCount, pMemoryRanges);
785
Alexis Hetu38ff8302018-10-18 15:08:13 -0400786 // Noop, host and device memory are the same to SwiftShader
Alexis Hetud73b8712018-09-21 15:14:43 -0400787
788 return VK_SUCCESS;
789}
790
Alexis Hetu38ff8302018-10-18 15:08:13 -0400791VKAPI_ATTR void VKAPI_CALL vkGetDeviceMemoryCommitment(VkDevice pDevice, VkDeviceMemory pMemory, VkDeviceSize* pCommittedMemoryInBytes)
Alexis Hetud73b8712018-09-21 15:14:43 -0400792{
Ben Claytonfb280672019-04-25 11:16:15 +0100793 TRACE("(VkDevice device = %p, VkDeviceMemory memory = %p, VkDeviceSize* pCommittedMemoryInBytes = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -0400794 pDevice, static_cast<void*>(pMemory), pCommittedMemoryInBytes);
Alexis Hetu38ff8302018-10-18 15:08:13 -0400795
796 auto memory = vk::Cast(pMemory);
797
798#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
Nicolas Capens0c736802019-05-27 12:53:31 -0400799 const auto& memoryProperties = vk::Cast(pDevice)->getPhysicalDevice()->getMemoryProperties();
Alexis Hetu38ff8302018-10-18 15:08:13 -0400800 uint32_t typeIndex = memory->getMemoryTypeIndex();
801 ASSERT(typeIndex < memoryProperties.memoryTypeCount);
802 ASSERT(memoryProperties.memoryTypes[typeIndex].propertyFlags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT);
803#endif
804
805 *pCommittedMemoryInBytes = memory->getCommittedMemoryInBytes();
Alexis Hetud73b8712018-09-21 15:14:43 -0400806}
807
808VKAPI_ATTR VkResult VKAPI_CALL vkBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory memory, VkDeviceSize memoryOffset)
809{
Ben Claytonfb280672019-04-25 11:16:15 +0100810 TRACE("(VkDevice device = %p, VkBuffer buffer = %p, VkDeviceMemory memory = %p, VkDeviceSize memoryOffset = %d)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -0400811 device, static_cast<void*>(buffer), static_cast<void*>(memory), int(memoryOffset));
Alexis Hetud73b8712018-09-21 15:14:43 -0400812
Alexis Hetu7d96f512019-06-13 18:23:56 -0400813 vk::Cast(buffer)->bind(vk::Cast(memory), memoryOffset);
Alexis Hetud73b8712018-09-21 15:14:43 -0400814
815 return VK_SUCCESS;
816}
817
818VKAPI_ATTR VkResult VKAPI_CALL vkBindImageMemory(VkDevice device, VkImage image, VkDeviceMemory memory, VkDeviceSize memoryOffset)
819{
Ben Claytonfb280672019-04-25 11:16:15 +0100820 TRACE("(VkDevice device = %p, VkImage image = %p, VkDeviceMemory memory = %p, VkDeviceSize memoryOffset = %d)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -0400821 device, static_cast<void*>(image), static_cast<void*>(memory), int(memoryOffset));
Alexis Hetud73b8712018-09-21 15:14:43 -0400822
Alexis Hetu7d96f512019-06-13 18:23:56 -0400823 vk::Cast(image)->bind(vk::Cast(memory), memoryOffset);
Alexis Hetud73b8712018-09-21 15:14:43 -0400824
825 return VK_SUCCESS;
826}
827
828VKAPI_ATTR void VKAPI_CALL vkGetBufferMemoryRequirements(VkDevice device, VkBuffer buffer, VkMemoryRequirements* pMemoryRequirements)
829{
Ben Claytonfb280672019-04-25 11:16:15 +0100830 TRACE("(VkDevice device = %p, VkBuffer buffer = %p, VkMemoryRequirements* pMemoryRequirements = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -0400831 device, static_cast<void*>(buffer), pMemoryRequirements);
Alexis Hetud73b8712018-09-21 15:14:43 -0400832
Alexis Hetu38ff8302018-10-18 15:08:13 -0400833 *pMemoryRequirements = vk::Cast(buffer)->getMemoryRequirements();
Alexis Hetud73b8712018-09-21 15:14:43 -0400834}
835
836VKAPI_ATTR void VKAPI_CALL vkGetImageMemoryRequirements(VkDevice device, VkImage image, VkMemoryRequirements* pMemoryRequirements)
837{
Ben Claytonfb280672019-04-25 11:16:15 +0100838 TRACE("(VkDevice device = %p, VkImage image = %p, VkMemoryRequirements* pMemoryRequirements = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -0400839 device, static_cast<void*>(image), pMemoryRequirements);
Alexis Hetud73b8712018-09-21 15:14:43 -0400840
Alexis Hetua233cea2018-12-07 11:53:19 -0500841 *pMemoryRequirements = vk::Cast(image)->getMemoryRequirements();
Alexis Hetud73b8712018-09-21 15:14:43 -0400842}
843
844VKAPI_ATTR void VKAPI_CALL vkGetImageSparseMemoryRequirements(VkDevice device, VkImage image, uint32_t* pSparseMemoryRequirementCount, VkSparseImageMemoryRequirements* pSparseMemoryRequirements)
845{
Ben Claytonfb280672019-04-25 11:16:15 +0100846 TRACE("(VkDevice device = %p, VkImage image = %p, uint32_t* pSparseMemoryRequirementCount = %p, VkSparseImageMemoryRequirements* pSparseMemoryRequirements = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -0400847 device, static_cast<void*>(image), pSparseMemoryRequirementCount, pSparseMemoryRequirements);
Alexis Hetu9e4d0402018-10-16 15:44:12 -0400848
Nicolas Capens5028a582018-11-13 15:03:35 -0500849 // The 'sparseBinding' feature is not supported, so images can not be created with the VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT flag.
850 // "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."
851 *pSparseMemoryRequirementCount = 0;
Alexis Hetud73b8712018-09-21 15:14:43 -0400852}
853
854VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceSparseImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkSampleCountFlagBits samples, VkImageUsageFlags usage, VkImageTiling tiling, uint32_t* pPropertyCount, VkSparseImageFormatProperties* pProperties)
855{
Ben Claytonfb280672019-04-25 11:16:15 +0100856 TRACE("(VkPhysicalDevice physicalDevice = %p, VkFormat format = %d, VkImageType type = %d, VkSampleCountFlagBits samples = %d, VkImageUsageFlags usage = %d, VkImageTiling tiling = %d, uint32_t* pPropertyCount = %p, VkSparseImageFormatProperties* pProperties = %p)",
Chris Forbes2c25b142019-03-05 14:47:16 -0800857 physicalDevice, format, type, samples, usage, tiling, pPropertyCount, pProperties);
858
859 // We do not support sparse images.
860 *pPropertyCount = 0;
Alexis Hetud73b8712018-09-21 15:14:43 -0400861}
862
863VKAPI_ATTR VkResult VKAPI_CALL vkQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo* pBindInfo, VkFence fence)
864{
865 TRACE("()");
Ben Clayton00424c12019-03-17 17:29:30 +0000866 UNIMPLEMENTED("vkQueueBindSparse");
Alexis Hetud73b8712018-09-21 15:14:43 -0400867 return VK_SUCCESS;
868}
869
870VKAPI_ATTR VkResult VKAPI_CALL vkCreateFence(VkDevice device, const VkFenceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkFence* pFence)
871{
Ben Claytonfb280672019-04-25 11:16:15 +0100872 TRACE("(VkDevice device = %p, const VkFenceCreateInfo* pCreateInfo = %p, const VkAllocationCallbacks* pAllocator = %p, VkFence* pFence = %p)",
Alexis Hetud73b8712018-09-21 15:14:43 -0400873 device, pCreateInfo, pAllocator, pFence);
874
Alexis Hetu1f23d8c2018-10-16 14:40:19 -0400875 if(pCreateInfo->pNext)
876 {
Ben Clayton00424c12019-03-17 17:29:30 +0000877 UNIMPLEMENTED("pCreateInfo->pNext");
Alexis Hetu1f23d8c2018-10-16 14:40:19 -0400878 }
Alexis Hetud73b8712018-09-21 15:14:43 -0400879
Alexis Hetu1f23d8c2018-10-16 14:40:19 -0400880 return vk::Fence::Create(pAllocator, pCreateInfo, pFence);
Alexis Hetud73b8712018-09-21 15:14:43 -0400881}
882
883VKAPI_ATTR void VKAPI_CALL vkDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks* pAllocator)
884{
Ben Claytonfb280672019-04-25 11:16:15 +0100885 TRACE("(VkDevice device = %p, VkFence fence = %p, const VkAllocationCallbacks* pAllocator = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -0400886 device, static_cast<void*>(fence), pAllocator);
Alexis Hetu767b41b2018-09-26 11:25:46 -0400887
Alexis Hetu1f23d8c2018-10-16 14:40:19 -0400888 vk::destroy(fence, pAllocator);
Alexis Hetud73b8712018-09-21 15:14:43 -0400889}
890
891VKAPI_ATTR VkResult VKAPI_CALL vkResetFences(VkDevice device, uint32_t fenceCount, const VkFence* pFences)
892{
Ben Claytonfb280672019-04-25 11:16:15 +0100893 TRACE("(VkDevice device = %p, uint32_t fenceCount = %d, const VkFence* pFences = %p)",
Alexis Hetu1f23d8c2018-10-16 14:40:19 -0400894 device, fenceCount, pFences);
895
896 for(uint32_t i = 0; i < fenceCount; i++)
897 {
898 vk::Cast(pFences[i])->reset();
899 }
900
Alexis Hetud73b8712018-09-21 15:14:43 -0400901 return VK_SUCCESS;
902}
903
904VKAPI_ATTR VkResult VKAPI_CALL vkGetFenceStatus(VkDevice device, VkFence fence)
905{
Alexis Hetu2d77aea2019-06-17 13:43:50 -0400906 TRACE("(VkDevice device = %p, VkFence fence = %p)", device, static_cast<void*>(fence));
Alexis Hetu1f23d8c2018-10-16 14:40:19 -0400907
908 return vk::Cast(fence)->getStatus();
Alexis Hetud73b8712018-09-21 15:14:43 -0400909}
910
911VKAPI_ATTR VkResult VKAPI_CALL vkWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence* pFences, VkBool32 waitAll, uint64_t timeout)
912{
Ben Claytonfb280672019-04-25 11:16:15 +0100913 TRACE("(VkDevice device = %p, uint32_t fenceCount = %d, const VkFence* pFences = %p, VkBool32 waitAll = %d, uint64_t timeout = %d)",
914 device, int(fenceCount), pFences, int(waitAll), int(timeout));
Alexis Hetuc4bd9df2018-12-07 11:28:40 -0500915
Alexis Hetue1f51b92019-04-23 15:34:34 -0400916 return vk::Cast(device)->waitForFences(fenceCount, pFences, waitAll, timeout);
Alexis Hetud73b8712018-09-21 15:14:43 -0400917}
918
919VKAPI_ATTR VkResult VKAPI_CALL vkCreateSemaphore(VkDevice device, const VkSemaphoreCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSemaphore* pSemaphore)
920{
Ben Claytonfb280672019-04-25 11:16:15 +0100921 TRACE("(VkDevice device = %p, const VkSemaphoreCreateInfo* pCreateInfo = %p, const VkAllocationCallbacks* pAllocator = %p, VkSemaphore* pSemaphore = %p)",
Alexis Hetu1f23d8c2018-10-16 14:40:19 -0400922 device, pCreateInfo, pAllocator, pSemaphore);
923
924 if(pCreateInfo->pNext || pCreateInfo->flags)
925 {
Ben Clayton00424c12019-03-17 17:29:30 +0000926 UNIMPLEMENTED("pCreateInfo->pNext || pCreateInfo->flags");
Alexis Hetu1f23d8c2018-10-16 14:40:19 -0400927 }
928
929 return vk::Semaphore::Create(pAllocator, pCreateInfo, pSemaphore);
Alexis Hetud73b8712018-09-21 15:14:43 -0400930}
931
932VKAPI_ATTR void VKAPI_CALL vkDestroySemaphore(VkDevice device, VkSemaphore semaphore, const VkAllocationCallbacks* pAllocator)
933{
Ben Claytonfb280672019-04-25 11:16:15 +0100934 TRACE("(VkDevice device = %p, VkSemaphore semaphore = %p, const VkAllocationCallbacks* pAllocator = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -0400935 device, static_cast<void*>(semaphore), pAllocator);
Alexis Hetu1f23d8c2018-10-16 14:40:19 -0400936
937 vk::destroy(semaphore, pAllocator);
Alexis Hetud73b8712018-09-21 15:14:43 -0400938}
939
940VKAPI_ATTR VkResult VKAPI_CALL vkCreateEvent(VkDevice device, const VkEventCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkEvent* pEvent)
941{
Ben Claytonfb280672019-04-25 11:16:15 +0100942 TRACE("(VkDevice device = %p, const VkEventCreateInfo* pCreateInfo = %p, const VkAllocationCallbacks* pAllocator = %p, VkEvent* pEvent = %p)",
Alexis Hetu1f23d8c2018-10-16 14:40:19 -0400943 device, pCreateInfo, pAllocator, pEvent);
944
945 if(pCreateInfo->pNext || pCreateInfo->flags)
946 {
Ben Clayton00424c12019-03-17 17:29:30 +0000947 UNIMPLEMENTED("pCreateInfo->pNext || pCreateInfo->flags");
Alexis Hetu1f23d8c2018-10-16 14:40:19 -0400948 }
949
950 return vk::Event::Create(pAllocator, pCreateInfo, pEvent);
Alexis Hetud73b8712018-09-21 15:14:43 -0400951}
952
953VKAPI_ATTR void VKAPI_CALL vkDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks* pAllocator)
954{
Ben Claytonfb280672019-04-25 11:16:15 +0100955 TRACE("(VkDevice device = %p, VkEvent event = %p, const VkAllocationCallbacks* pAllocator = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -0400956 device, static_cast<void*>(event), pAllocator);
Alexis Hetu1f23d8c2018-10-16 14:40:19 -0400957
958 vk::destroy(event, pAllocator);
Alexis Hetud73b8712018-09-21 15:14:43 -0400959}
960
961VKAPI_ATTR VkResult VKAPI_CALL vkGetEventStatus(VkDevice device, VkEvent event)
962{
Alexis Hetu2d77aea2019-06-17 13:43:50 -0400963 TRACE("(VkDevice device = %p, VkEvent event = %p)", device, static_cast<void*>(event));
Alexis Hetu1f23d8c2018-10-16 14:40:19 -0400964
965 return vk::Cast(event)->getStatus();
Alexis Hetud73b8712018-09-21 15:14:43 -0400966}
967
968VKAPI_ATTR VkResult VKAPI_CALL vkSetEvent(VkDevice device, VkEvent event)
969{
Alexis Hetu2d77aea2019-06-17 13:43:50 -0400970 TRACE("(VkDevice device = %p, VkEvent event = %p)", device, static_cast<void*>(event));
Alexis Hetu1f23d8c2018-10-16 14:40:19 -0400971
972 vk::Cast(event)->signal();
973
Alexis Hetud73b8712018-09-21 15:14:43 -0400974 return VK_SUCCESS;
975}
976
977VKAPI_ATTR VkResult VKAPI_CALL vkResetEvent(VkDevice device, VkEvent event)
978{
Alexis Hetu2d77aea2019-06-17 13:43:50 -0400979 TRACE("(VkDevice device = %p, VkEvent event = %p)", device, static_cast<void*>(event));
Alexis Hetu1f23d8c2018-10-16 14:40:19 -0400980
981 vk::Cast(event)->reset();
982
Alexis Hetud73b8712018-09-21 15:14:43 -0400983 return VK_SUCCESS;
984}
985
986VKAPI_ATTR VkResult VKAPI_CALL vkCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkQueryPool* pQueryPool)
987{
Ben Claytonfb280672019-04-25 11:16:15 +0100988 TRACE("(VkDevice device = %p, const VkQueryPoolCreateInfo* pCreateInfo = %p, const VkAllocationCallbacks* pAllocator = %p, VkQueryPool* pQueryPool = %p)",
Alexis Hetu86f8bdb2019-01-22 12:07:24 -0500989 device, pCreateInfo, pAllocator, pQueryPool);
990
991 if(pCreateInfo->pNext || pCreateInfo->flags)
992 {
Ben Clayton00424c12019-03-17 17:29:30 +0000993 UNIMPLEMENTED("pCreateInfo->pNext || pCreateInfo->flags");
Alexis Hetu86f8bdb2019-01-22 12:07:24 -0500994 }
995
996 return vk::QueryPool::Create(pAllocator, pCreateInfo, pQueryPool);
Alexis Hetud73b8712018-09-21 15:14:43 -0400997}
998
999VKAPI_ATTR void VKAPI_CALL vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool, const VkAllocationCallbacks* pAllocator)
1000{
Ben Claytonfb280672019-04-25 11:16:15 +01001001 TRACE("(VkDevice device = %p, VkQueryPool queryPool = %p, const VkAllocationCallbacks* pAllocator = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001002 device, static_cast<void*>(queryPool), pAllocator);
Alexis Hetu86f8bdb2019-01-22 12:07:24 -05001003
1004 vk::destroy(queryPool, pAllocator);
Alexis Hetud73b8712018-09-21 15:14:43 -04001005}
1006
1007VKAPI_ATTR VkResult VKAPI_CALL vkGetQueryPoolResults(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount, size_t dataSize, void* pData, VkDeviceSize stride, VkQueryResultFlags flags)
1008{
Ben Claytonfb280672019-04-25 11:16:15 +01001009 TRACE("(VkDevice device = %p, VkQueryPool queryPool = %p, uint32_t firstQuery = %d, uint32_t queryCount = %d, size_t dataSize = %d, void* pData = %p, VkDeviceSize stride = %d, VkQueryResultFlags flags = %d)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001010 device, static_cast<void*>(queryPool), int(firstQuery), int(queryCount), int(dataSize), pData, int(stride), flags);
Alexis Hetu86f8bdb2019-01-22 12:07:24 -05001011
Alexis Hetuf0aa9d52019-04-01 17:06:47 -04001012 return vk::Cast(queryPool)->getResults(firstQuery, queryCount, dataSize, pData, stride, flags);
Alexis Hetud73b8712018-09-21 15:14:43 -04001013}
1014
1015VKAPI_ATTR VkResult VKAPI_CALL vkCreateBuffer(VkDevice device, const VkBufferCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkBuffer* pBuffer)
1016{
Ben Claytonfb280672019-04-25 11:16:15 +01001017 TRACE("(VkDevice device = %p, const VkBufferCreateInfo* pCreateInfo = %p, const VkAllocationCallbacks* pAllocator = %p, VkBuffer* pBuffer = %p)",
Alexis Hetud73b8712018-09-21 15:14:43 -04001018 device, pCreateInfo, pAllocator, pBuffer);
1019
Alexis Hetu38ff8302018-10-18 15:08:13 -04001020 if(pCreateInfo->pNext)
1021 {
Ben Clayton00424c12019-03-17 17:29:30 +00001022 UNIMPLEMENTED("pCreateInfo->pNext");
Alexis Hetu38ff8302018-10-18 15:08:13 -04001023 }
Alexis Hetud73b8712018-09-21 15:14:43 -04001024
Alexis Hetu38ff8302018-10-18 15:08:13 -04001025 return vk::Buffer::Create(pAllocator, pCreateInfo, pBuffer);
Alexis Hetud73b8712018-09-21 15:14:43 -04001026}
1027
1028VKAPI_ATTR void VKAPI_CALL vkDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks* pAllocator)
1029{
Ben Claytonfb280672019-04-25 11:16:15 +01001030 TRACE("(VkDevice device = %p, VkBuffer buffer = %p, const VkAllocationCallbacks* pAllocator = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001031 device, static_cast<void*>(buffer), pAllocator);
Alexis Hetud73b8712018-09-21 15:14:43 -04001032
Alexis Hetu38ff8302018-10-18 15:08:13 -04001033 vk::destroy(buffer, pAllocator);
Alexis Hetud73b8712018-09-21 15:14:43 -04001034}
1035
1036VKAPI_ATTR VkResult VKAPI_CALL vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkBufferView* pView)
1037{
Ben Claytonfb280672019-04-25 11:16:15 +01001038 TRACE("(VkDevice device = %p, const VkBufferViewCreateInfo* pCreateInfo = %p, const VkAllocationCallbacks* pAllocator = %p, VkBufferView* pView = %p)",
Alexis Hetu1424ef62019-04-05 18:03:53 -04001039 device, pCreateInfo, pAllocator, pView);
Alexis Hetu38ff8302018-10-18 15:08:13 -04001040
1041 if(pCreateInfo->pNext || pCreateInfo->flags)
1042 {
Ben Clayton00424c12019-03-17 17:29:30 +00001043 UNIMPLEMENTED("pCreateInfo->pNext || pCreateInfo->flags");
Alexis Hetu38ff8302018-10-18 15:08:13 -04001044 }
1045
1046 return vk::BufferView::Create(pAllocator, pCreateInfo, pView);
Alexis Hetud73b8712018-09-21 15:14:43 -04001047}
1048
1049VKAPI_ATTR void VKAPI_CALL vkDestroyBufferView(VkDevice device, VkBufferView bufferView, const VkAllocationCallbacks* pAllocator)
1050{
Ben Claytonfb280672019-04-25 11:16:15 +01001051 TRACE("(VkDevice device = %p, VkBufferView bufferView = %p, const VkAllocationCallbacks* pAllocator = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001052 device, static_cast<void*>(bufferView), pAllocator);
Alexis Hetu38ff8302018-10-18 15:08:13 -04001053
1054 vk::destroy(bufferView, pAllocator);
Alexis Hetud73b8712018-09-21 15:14:43 -04001055}
1056
Hernan Liatis628604e2019-05-07 15:30:18 -07001057#ifdef __ANDROID__
1058struct BackingMemory {
1059 buffer_handle_t nativeHandle;
1060 int stride;
Hernan Liatis3c735072019-06-10 15:07:18 -07001061 vk::DeviceMemory* imageMemory;
Hernan Liatis628604e2019-05-07 15:30:18 -07001062 VkSwapchainImageUsageFlagsANDROID androidUsage;
1063};
1064
1065static std::map<VkImage, BackingMemory> androidSwapchainMap;
1066#endif
1067
Alexis Hetud73b8712018-09-21 15:14:43 -04001068VKAPI_ATTR VkResult VKAPI_CALL vkCreateImage(VkDevice device, const VkImageCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkImage* pImage)
1069{
Ben Claytonfb280672019-04-25 11:16:15 +01001070 TRACE("(VkDevice device = %p, const VkImageCreateInfo* pCreateInfo = %p, const VkAllocationCallbacks* pAllocator = %p, VkImage* pImage = %p)",
Alexis Hetud73b8712018-09-21 15:14:43 -04001071 device, pCreateInfo, pAllocator, pImage);
1072
Hernan Liatis628604e2019-05-07 15:30:18 -07001073 const VkBaseInStructure* extensionCreateInfo = reinterpret_cast<const VkBaseInStructure*>(pCreateInfo->pNext);
1074
1075#ifdef __ANDROID__
1076 BackingMemory backmem;
1077 bool swapchainImage = false;
1078#endif
1079
1080 while(extensionCreateInfo)
Alexis Hetuf62f3752018-11-15 14:51:15 -05001081 {
Hernan Liatis628604e2019-05-07 15:30:18 -07001082 switch((long)(extensionCreateInfo->sType))
1083 {
1084#ifdef __ANDROID__
1085 case VK_STRUCTURE_TYPE_SWAPCHAIN_IMAGE_CREATE_INFO_ANDROID:
1086 {
1087 const VkSwapchainImageCreateInfoANDROID* swapImageCreateInfo = reinterpret_cast<const VkSwapchainImageCreateInfoANDROID*>(extensionCreateInfo);
1088 backmem.androidUsage = swapImageCreateInfo->usage;
1089 }
1090 break;
1091 case VK_STRUCTURE_TYPE_NATIVE_BUFFER_ANDROID:
1092 {
1093 const VkNativeBufferANDROID* nativeBufferInfo = reinterpret_cast<const VkNativeBufferANDROID*>(extensionCreateInfo);
1094 backmem.nativeHandle = nativeBufferInfo->handle;
1095 backmem.stride = nativeBufferInfo->stride;
Hernan Liatiscae8cde2019-05-22 14:24:45 -07001096 swapchainImage = true;
Hernan Liatis628604e2019-05-07 15:30:18 -07001097 }
1098 break;
1099#endif
1100 default:
1101 // "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]"
1102 UNIMPLEMENTED("extensionCreateInfo->sType"); // TODO(b/119321052): UNIMPLEMENTED() should be used only for features that must still be implemented. Use a more informational macro here.
1103 break;
1104 }
1105
1106 extensionCreateInfo = extensionCreateInfo->pNext;
Alexis Hetuf62f3752018-11-15 14:51:15 -05001107 }
Alexis Hetud73b8712018-09-21 15:14:43 -04001108
Nicolas Capens0c736802019-05-27 12:53:31 -04001109 VkResult result = vk::Image::Create(pAllocator, pCreateInfo, pImage, vk::Cast(device));
Hernan Liatis628604e2019-05-07 15:30:18 -07001110
1111#ifdef __ANDROID__
1112 if (swapchainImage)
1113 {
1114 if (result != VK_SUCCESS)
1115 {
1116 return result;
1117 }
1118
1119 VkMemoryRequirements memRequirements = vk::Cast(*pImage)->getMemoryRequirements();
1120
1121 VkMemoryAllocateInfo allocInfo = {};
1122 allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1123 allocInfo.allocationSize = memRequirements.size;
1124 allocInfo.memoryTypeIndex = 0;
1125
Alexis Hetu82feec72019-06-19 12:42:38 -04001126 VkDeviceMemory devmem = { VK_NULL_HANDLE };
Hernan Liatis3c735072019-06-10 15:07:18 -07001127 result = vkAllocateMemory(device, &allocInfo, nullptr, &devmem);
Hernan Liatis628604e2019-05-07 15:30:18 -07001128 if(result != VK_SUCCESS)
1129 {
1130 return result;
1131 }
1132
Hernan Liatis3c735072019-06-10 15:07:18 -07001133 backmem.imageMemory = vk::Cast(devmem);
1134 vkBindImageMemory(device, *pImage, devmem, 0);
1135
Hernan Liatis628604e2019-05-07 15:30:18 -07001136 androidSwapchainMap[*pImage] = backmem;
1137 }
1138#endif
1139
1140 return result;
Alexis Hetud73b8712018-09-21 15:14:43 -04001141}
1142
1143VKAPI_ATTR void VKAPI_CALL vkDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks* pAllocator)
1144{
Ben Claytonfb280672019-04-25 11:16:15 +01001145 TRACE("(VkDevice device = %p, VkImage image = %p, const VkAllocationCallbacks* pAllocator = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001146 device, static_cast<void*>(image), pAllocator);
Alexis Hetud73b8712018-09-21 15:14:43 -04001147
Alexis Hetuf62f3752018-11-15 14:51:15 -05001148 vk::destroy(image, pAllocator);
Hernan Liatisf988cb52019-05-22 15:06:19 -07001149
1150#ifdef __ANDROID__
1151 auto it = androidSwapchainMap.find(image);
1152
1153 if (it != androidSwapchainMap.end())
1154 {
Hernan Liatis3c735072019-06-10 15:07:18 -07001155 vk::destroy(static_cast<VkDeviceMemory>(*((it->second).imageMemory)), nullptr);
Hernan Liatisf988cb52019-05-22 15:06:19 -07001156 androidSwapchainMap.erase(it);
1157 }
1158#endif
Alexis Hetud73b8712018-09-21 15:14:43 -04001159}
1160
1161VKAPI_ATTR void VKAPI_CALL vkGetImageSubresourceLayout(VkDevice device, VkImage image, const VkImageSubresource* pSubresource, VkSubresourceLayout* pLayout)
1162{
Ben Claytonfb280672019-04-25 11:16:15 +01001163 TRACE("(VkDevice device = %p, VkImage image = %p, const VkImageSubresource* pSubresource = %p, VkSubresourceLayout* pLayout = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001164 device, static_cast<void*>(image), pSubresource, pLayout);
Alexis Hetu6ab37b02019-01-24 17:02:45 -05001165
1166 vk::Cast(image)->getSubresourceLayout(pSubresource, pLayout);
Alexis Hetud73b8712018-09-21 15:14:43 -04001167}
1168
1169VKAPI_ATTR VkResult VKAPI_CALL vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkImageView* pView)
1170{
Ben Claytonfb280672019-04-25 11:16:15 +01001171 TRACE("(VkDevice device = %p, const VkImageViewCreateInfo* pCreateInfo = %p, const VkAllocationCallbacks* pAllocator = %p, VkImageView* pView = %p)",
Alexis Hetud73b8712018-09-21 15:14:43 -04001172 device, pCreateInfo, pAllocator, pView);
1173
Alexis Hetu60da1582019-04-05 16:34:38 -04001174 if(pCreateInfo->flags)
Alexis Hetu9fbaf692018-11-19 11:30:43 -05001175 {
Alexis Hetu60da1582019-04-05 16:34:38 -04001176 UNIMPLEMENTED("pCreateInfo->flags");
1177 }
1178
1179 const VkBaseInStructure* extensionCreateInfo = reinterpret_cast<const VkBaseInStructure*>(pCreateInfo->pNext);
Nicolas Capens6b63c802019-05-16 11:10:34 -04001180 const vk::SamplerYcbcrConversion *ycbcrConversion = nullptr;
Alexis Hetu60da1582019-04-05 16:34:38 -04001181
1182 while(extensionCreateInfo)
1183 {
1184 switch(extensionCreateInfo->sType)
1185 {
1186 case VK_STRUCTURE_TYPE_IMAGE_VIEW_USAGE_CREATE_INFO_KHR:
1187 {
1188 const VkImageViewUsageCreateInfo* multiviewCreateInfo = reinterpret_cast<const VkImageViewUsageCreateInfo*>(extensionCreateInfo);
1189 ASSERT(!(~vk::Cast(pCreateInfo->image)->getUsage() & multiviewCreateInfo->usage));
1190 }
1191 break;
1192 case VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO:
1193 {
Nicolas Capens6b63c802019-05-16 11:10:34 -04001194 const VkSamplerYcbcrConversionInfo* samplerYcbcrConversionInfo = reinterpret_cast<const VkSamplerYcbcrConversionInfo*>(extensionCreateInfo);
1195 ycbcrConversion = vk::Cast(samplerYcbcrConversionInfo->conversion);
1196
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001197 if(ycbcrConversion)
Alexis Hetu60da1582019-04-05 16:34:38 -04001198 {
1199 ASSERT((pCreateInfo->components.r == VK_COMPONENT_SWIZZLE_IDENTITY) &&
1200 (pCreateInfo->components.g == VK_COMPONENT_SWIZZLE_IDENTITY) &&
1201 (pCreateInfo->components.b == VK_COMPONENT_SWIZZLE_IDENTITY) &&
1202 (pCreateInfo->components.a == VK_COMPONENT_SWIZZLE_IDENTITY));
1203 }
1204 }
1205 break;
1206 default:
Nicolas Capens6b63c802019-05-16 11:10:34 -04001207 UNIMPLEMENTED("extensionCreateInfo->sType %d", int(extensionCreateInfo->sType));
Alexis Hetu60da1582019-04-05 16:34:38 -04001208 break;
1209 }
1210
1211 extensionCreateInfo = extensionCreateInfo->pNext;
Alexis Hetu9fbaf692018-11-19 11:30:43 -05001212 }
Alexis Hetud73b8712018-09-21 15:14:43 -04001213
Nicolas Capens6b63c802019-05-16 11:10:34 -04001214 return vk::ImageView::Create(pAllocator, pCreateInfo, pView, ycbcrConversion);
Alexis Hetud73b8712018-09-21 15:14:43 -04001215}
1216
1217VKAPI_ATTR void VKAPI_CALL vkDestroyImageView(VkDevice device, VkImageView imageView, const VkAllocationCallbacks* pAllocator)
1218{
Ben Claytonfb280672019-04-25 11:16:15 +01001219 TRACE("(VkDevice device = %p, VkImageView imageView = %p, const VkAllocationCallbacks* pAllocator = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001220 device, static_cast<void*>(imageView), pAllocator);
Alexis Hetu9fbaf692018-11-19 11:30:43 -05001221
1222 vk::destroy(imageView, pAllocator);
Alexis Hetud73b8712018-09-21 15:14:43 -04001223}
1224
1225VKAPI_ATTR VkResult VKAPI_CALL vkCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkShaderModule* pShaderModule)
1226{
Ben Claytonfb280672019-04-25 11:16:15 +01001227 TRACE("(VkDevice device = %p, const VkShaderModuleCreateInfo* pCreateInfo = %p, const VkAllocationCallbacks* pAllocator = %p, VkShaderModule* pShaderModule = %p)",
Alexis Hetu9fbaf692018-11-19 11:30:43 -05001228 device, pCreateInfo, pAllocator, pShaderModule);
Alexis Hetud73b8712018-09-21 15:14:43 -04001229
Alexis Hetu259ad3d2018-11-15 13:44:31 -05001230 if(pCreateInfo->pNext || pCreateInfo->flags)
1231 {
Ben Clayton00424c12019-03-17 17:29:30 +00001232 UNIMPLEMENTED("pCreateInfo->pNext || pCreateInfo->flags");
Alexis Hetu259ad3d2018-11-15 13:44:31 -05001233 }
Alexis Hetud73b8712018-09-21 15:14:43 -04001234
Alexis Hetu259ad3d2018-11-15 13:44:31 -05001235 return vk::ShaderModule::Create(pAllocator, pCreateInfo, pShaderModule);
Alexis Hetud73b8712018-09-21 15:14:43 -04001236}
1237
1238VKAPI_ATTR void VKAPI_CALL vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule, const VkAllocationCallbacks* pAllocator)
1239{
Ben Claytonfb280672019-04-25 11:16:15 +01001240 TRACE("(VkDevice device = %p, VkShaderModule shaderModule = %p, const VkAllocationCallbacks* pAllocator = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001241 device, static_cast<void*>(shaderModule), pAllocator);
Alexis Hetud73b8712018-09-21 15:14:43 -04001242
Alexis Hetu259ad3d2018-11-15 13:44:31 -05001243 vk::destroy(shaderModule, pAllocator);
Alexis Hetud73b8712018-09-21 15:14:43 -04001244}
1245
1246VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineCache(VkDevice device, const VkPipelineCacheCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkPipelineCache* pPipelineCache)
1247{
Ben Claytonfb280672019-04-25 11:16:15 +01001248 TRACE("(VkDevice device = %p, const VkPipelineCacheCreateInfo* pCreateInfo = %p, const VkAllocationCallbacks* pAllocator = %p, VkPipelineCache* pPipelineCache = %p)",
Alexis Hetu1424ef62019-04-05 18:03:53 -04001249 device, pCreateInfo, pAllocator, pPipelineCache);
Alexis Hetu18a84252018-11-19 11:30:43 -05001250
1251 if(pCreateInfo->pNext || pCreateInfo->flags)
1252 {
Ben Clayton00424c12019-03-17 17:29:30 +00001253 UNIMPLEMENTED("pCreateInfo->pNext || pCreateInfo->flags");
Alexis Hetu18a84252018-11-19 11:30:43 -05001254 }
1255
1256 return vk::PipelineCache::Create(pAllocator, pCreateInfo, pPipelineCache);
Alexis Hetud73b8712018-09-21 15:14:43 -04001257}
1258
1259VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineCache(VkDevice device, VkPipelineCache pipelineCache, const VkAllocationCallbacks* pAllocator)
1260{
Ben Claytonfb280672019-04-25 11:16:15 +01001261 TRACE("(VkDevice device = %p, VkPipelineCache pipelineCache = %p, const VkAllocationCallbacks* pAllocator = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001262 device, static_cast<void*>(pipelineCache), pAllocator);
Alexis Hetu18a84252018-11-19 11:30:43 -05001263
1264 vk::destroy(pipelineCache, pAllocator);
Alexis Hetud73b8712018-09-21 15:14:43 -04001265}
1266
1267VKAPI_ATTR VkResult VKAPI_CALL vkGetPipelineCacheData(VkDevice device, VkPipelineCache pipelineCache, size_t* pDataSize, void* pData)
1268{
Ben Claytonfb280672019-04-25 11:16:15 +01001269 TRACE("(VkDevice device = %p, VkPipelineCache pipelineCache = %p, size_t* pDataSize = %p, void* pData = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001270 device, static_cast<void*>(pipelineCache), pDataSize, pData);
Alexis Hetu1424ef62019-04-05 18:03:53 -04001271
1272 return vk::Cast(pipelineCache)->getData(pDataSize, pData);
Alexis Hetud73b8712018-09-21 15:14:43 -04001273}
1274
1275VKAPI_ATTR VkResult VKAPI_CALL vkMergePipelineCaches(VkDevice device, VkPipelineCache dstCache, uint32_t srcCacheCount, const VkPipelineCache* pSrcCaches)
1276{
Ben Claytonfb280672019-04-25 11:16:15 +01001277 TRACE("(VkDevice device = %p, VkPipelineCache dstCache = %p, uint32_t srcCacheCount = %d, const VkPipelineCache* pSrcCaches = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001278 device, static_cast<void*>(dstCache), int(srcCacheCount), pSrcCaches);
Alexis Hetu1424ef62019-04-05 18:03:53 -04001279
1280 return vk::Cast(dstCache)->merge(srcCacheCount, pSrcCaches);
Alexis Hetud73b8712018-09-21 15:14:43 -04001281}
1282
1283VKAPI_ATTR VkResult VKAPI_CALL vkCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount, const VkGraphicsPipelineCreateInfo* pCreateInfos, const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines)
1284{
Ben Claytonfb280672019-04-25 11:16:15 +01001285 TRACE("(VkDevice device = %p, VkPipelineCache pipelineCache = %p, uint32_t createInfoCount = %d, const VkGraphicsPipelineCreateInfo* pCreateInfos = %p, const VkAllocationCallbacks* pAllocator = %p, VkPipeline* pPipelines = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001286 device, static_cast<void*>(pipelineCache), int(createInfoCount), pCreateInfos, pAllocator, pPipelines);
Alexis Hetud73b8712018-09-21 15:14:43 -04001287
Alexis Hetu000df8b2018-10-24 15:22:41 -04001288 VkResult errorResult = VK_SUCCESS;
1289 for(uint32_t i = 0; i < createInfoCount; i++)
1290 {
Nicolas Capensa29aa772019-06-26 00:36:28 -04001291 VkResult result = vk::GraphicsPipeline::Create(pAllocator, &pCreateInfos[i], &pPipelines[i], vk::Cast(device));
1292
Ben Claytonf2be26a2019-03-08 12:02:05 +00001293 if(result == VK_SUCCESS)
1294 {
Alexis Hetu52edb172019-06-26 10:17:18 -04001295 static_cast<vk::GraphicsPipeline*>(vk::Cast(pPipelines[i]))->compileShaders(pAllocator, &pCreateInfos[i], vk::Cast(pipelineCache));
Ben Claytonf2be26a2019-03-08 12:02:05 +00001296 }
1297 else
Alexis Hetu000df8b2018-10-24 15:22:41 -04001298 {
1299 // According to the Vulkan spec, section 9.4. Multiple Pipeline Creation
1300 // "When an application attempts to create many pipelines in a single command,
1301 // it is possible that some subset may fail creation. In that case, the
1302 // corresponding entries in the pPipelines output array will be filled with
1303 // VK_NULL_HANDLE values. If any pipeline fails creation (for example, due to
1304 // out of memory errors), the vkCreate*Pipelines commands will return an
1305 // error code. The implementation will attempt to create all pipelines, and
1306 // only return VK_NULL_HANDLE values for those that actually failed."
1307 pPipelines[i] = VK_NULL_HANDLE;
1308 errorResult = result;
1309 }
1310 }
1311
1312 return errorResult;
Alexis Hetud73b8712018-09-21 15:14:43 -04001313}
1314
1315VKAPI_ATTR VkResult VKAPI_CALL vkCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount, const VkComputePipelineCreateInfo* pCreateInfos, const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines)
1316{
Ben Claytonfb280672019-04-25 11:16:15 +01001317 TRACE("(VkDevice device = %p, VkPipelineCache pipelineCache = %p, uint32_t createInfoCount = %d, const VkComputePipelineCreateInfo* pCreateInfos = %p, const VkAllocationCallbacks* pAllocator = %p, VkPipeline* pPipelines = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001318 device, static_cast<void*>(pipelineCache), int(createInfoCount), pCreateInfos, pAllocator, pPipelines);
Alexis Hetud73b8712018-09-21 15:14:43 -04001319
Alexis Hetu000df8b2018-10-24 15:22:41 -04001320 VkResult errorResult = VK_SUCCESS;
1321 for(uint32_t i = 0; i < createInfoCount; i++)
1322 {
Nicolas Capensa29aa772019-06-26 00:36:28 -04001323 VkResult result = vk::ComputePipeline::Create(pAllocator, &pCreateInfos[i], &pPipelines[i], vk::Cast(device));
1324
Ben Claytonf2be26a2019-03-08 12:02:05 +00001325 if(result == VK_SUCCESS)
1326 {
Alexis Hetu52edb172019-06-26 10:17:18 -04001327 static_cast<vk::ComputePipeline*>(vk::Cast(pPipelines[i]))->compileShaders(pAllocator, &pCreateInfos[i], vk::Cast(pipelineCache));
Ben Claytonf2be26a2019-03-08 12:02:05 +00001328 }
1329 else
Alexis Hetu000df8b2018-10-24 15:22:41 -04001330 {
1331 // According to the Vulkan spec, section 9.4. Multiple Pipeline Creation
1332 // "When an application attempts to create many pipelines in a single command,
1333 // it is possible that some subset may fail creation. In that case, the
1334 // corresponding entries in the pPipelines output array will be filled with
1335 // VK_NULL_HANDLE values. If any pipeline fails creation (for example, due to
1336 // out of memory errors), the vkCreate*Pipelines commands will return an
1337 // error code. The implementation will attempt to create all pipelines, and
1338 // only return VK_NULL_HANDLE values for those that actually failed."
1339 pPipelines[i] = VK_NULL_HANDLE;
1340 errorResult = result;
1341 }
1342 }
1343
1344 return errorResult;
Alexis Hetud73b8712018-09-21 15:14:43 -04001345}
1346
1347VKAPI_ATTR void VKAPI_CALL vkDestroyPipeline(VkDevice device, VkPipeline pipeline, const VkAllocationCallbacks* pAllocator)
1348{
Ben Claytonfb280672019-04-25 11:16:15 +01001349 TRACE("(VkDevice device = %p, VkPipeline pipeline = %p, const VkAllocationCallbacks* pAllocator = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001350 device, static_cast<void*>(pipeline), pAllocator);
Alexis Hetud73b8712018-09-21 15:14:43 -04001351
Alexis Hetu000df8b2018-10-24 15:22:41 -04001352 vk::destroy(pipeline, pAllocator);
Alexis Hetud73b8712018-09-21 15:14:43 -04001353}
1354
1355VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkPipelineLayout* pPipelineLayout)
1356{
Ben Claytonfb280672019-04-25 11:16:15 +01001357 TRACE("(VkDevice device = %p, const VkPipelineLayoutCreateInfo* pCreateInfo = %p, const VkAllocationCallbacks* pAllocator = %p, VkPipelineLayout* pPipelineLayout = %p)",
Alexis Hetud73b8712018-09-21 15:14:43 -04001358 device, pCreateInfo, pAllocator, pPipelineLayout);
1359
Alexis Hetu000df8b2018-10-24 15:22:41 -04001360 if(pCreateInfo->pNext || pCreateInfo->flags)
1361 {
Ben Clayton00424c12019-03-17 17:29:30 +00001362 UNIMPLEMENTED("pCreateInfo->pNext || pCreateInfo->flags");
Alexis Hetu000df8b2018-10-24 15:22:41 -04001363 }
Alexis Hetud73b8712018-09-21 15:14:43 -04001364
Alexis Hetu000df8b2018-10-24 15:22:41 -04001365 return vk::PipelineLayout::Create(pAllocator, pCreateInfo, pPipelineLayout);
Alexis Hetud73b8712018-09-21 15:14:43 -04001366}
1367
1368VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout, const VkAllocationCallbacks* pAllocator)
1369{
Ben Claytonfb280672019-04-25 11:16:15 +01001370 TRACE("(VkDevice device = %p, VkPipelineLayout pipelineLayout = %p, const VkAllocationCallbacks* pAllocator = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001371 device, static_cast<void*>(pipelineLayout), pAllocator);
Alexis Hetud73b8712018-09-21 15:14:43 -04001372
Alexis Hetu000df8b2018-10-24 15:22:41 -04001373 vk::destroy(pipelineLayout, pAllocator);
Alexis Hetud73b8712018-09-21 15:14:43 -04001374}
1375
1376VKAPI_ATTR VkResult VKAPI_CALL vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSampler* pSampler)
1377{
Ben Claytonfb280672019-04-25 11:16:15 +01001378 TRACE("(VkDevice device = %p, const VkSamplerCreateInfo* pCreateInfo = %p, const VkAllocationCallbacks* pAllocator = %p, VkSampler* pSampler = %p)",
Alexis Hetud73b8712018-09-21 15:14:43 -04001379 device, pCreateInfo, pAllocator, pSampler);
1380
Nicolas Capens6b63c802019-05-16 11:10:34 -04001381 if(pCreateInfo->flags)
Alexis Hetu5174c572018-11-19 11:30:43 -05001382 {
Ben Clayton00424c12019-03-17 17:29:30 +00001383 UNIMPLEMENTED("pCreateInfo->pNext || pCreateInfo->flags");
Alexis Hetu5174c572018-11-19 11:30:43 -05001384 }
Alexis Hetud73b8712018-09-21 15:14:43 -04001385
Nicolas Capens6b63c802019-05-16 11:10:34 -04001386 const VkBaseInStructure* extensionCreateInfo = reinterpret_cast<const VkBaseInStructure*>(pCreateInfo->pNext);
1387 const vk::SamplerYcbcrConversion *ycbcrConversion = nullptr;
1388
1389 while(extensionCreateInfo)
1390 {
1391 switch(extensionCreateInfo->sType)
1392 {
1393 case VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO:
1394 {
1395 const VkSamplerYcbcrConversionInfo* samplerYcbcrConversionInfo = reinterpret_cast<const VkSamplerYcbcrConversionInfo*>(extensionCreateInfo);
1396 ycbcrConversion = vk::Cast(samplerYcbcrConversionInfo->conversion);
1397 }
1398 break;
1399 default:
1400 UNIMPLEMENTED("extensionCreateInfo->sType %d", int(extensionCreateInfo->sType));
1401 break;
1402 }
1403
1404 extensionCreateInfo = extensionCreateInfo->pNext;
1405 }
1406
1407 return vk::Sampler::Create(pAllocator, pCreateInfo, pSampler, ycbcrConversion);
Alexis Hetud73b8712018-09-21 15:14:43 -04001408}
1409
1410VKAPI_ATTR void VKAPI_CALL vkDestroySampler(VkDevice device, VkSampler sampler, const VkAllocationCallbacks* pAllocator)
1411{
Ben Claytonfb280672019-04-25 11:16:15 +01001412 TRACE("(VkDevice device = %p, VkSampler sampler = %p, const VkAllocationCallbacks* pAllocator = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001413 device, static_cast<void*>(sampler), pAllocator);
Alexis Hetud73b8712018-09-21 15:14:43 -04001414
Alexis Hetu5174c572018-11-19 11:30:43 -05001415 vk::destroy(sampler, pAllocator);
Alexis Hetud73b8712018-09-21 15:14:43 -04001416}
1417
1418VKAPI_ATTR VkResult VKAPI_CALL vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDescriptorSetLayout* pSetLayout)
1419{
Ben Claytonfb280672019-04-25 11:16:15 +01001420 TRACE("(VkDevice device = %p, const VkDescriptorSetLayoutCreateInfo* pCreateInfo = %p, const VkAllocationCallbacks* pAllocator = %p, VkDescriptorSetLayout* pSetLayout = %p)",
Alexis Hetuc8176632019-01-22 17:01:28 -05001421 device, pCreateInfo, pAllocator, pSetLayout);
1422
Alexis Hetu1300ba12019-05-07 15:47:11 -04001423 const VkBaseInStructure* extensionCreateInfo = reinterpret_cast<const VkBaseInStructure*>(pCreateInfo->pNext);
1424
1425 while(extensionCreateInfo)
Alexis Hetuc8176632019-01-22 17:01:28 -05001426 {
Alexis Hetu1300ba12019-05-07 15:47:11 -04001427 switch(extensionCreateInfo->sType)
1428 {
1429 case VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO_EXT:
Alexis Hetu352791e2019-05-17 16:42:34 -04001430 ASSERT(!vk::Cast(device)->hasExtension(VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME));
Alexis Hetu1300ba12019-05-07 15:47:11 -04001431 break;
1432 default:
Nicolas Capens6b63c802019-05-16 11:10:34 -04001433 UNIMPLEMENTED("extensionCreateInfo->sType %d", int(extensionCreateInfo->sType));
Alexis Hetu1300ba12019-05-07 15:47:11 -04001434 break;
1435 }
1436
1437 extensionCreateInfo = extensionCreateInfo->pNext;
Alexis Hetuc8176632019-01-22 17:01:28 -05001438 }
1439
1440 return vk::DescriptorSetLayout::Create(pAllocator, pCreateInfo, pSetLayout);
Alexis Hetud73b8712018-09-21 15:14:43 -04001441}
1442
1443VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout, const VkAllocationCallbacks* pAllocator)
1444{
Ben Claytonfb280672019-04-25 11:16:15 +01001445 TRACE("(VkDevice device = %p, VkDescriptorSetLayout descriptorSetLayout = %p, const VkAllocationCallbacks* pAllocator = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001446 device, static_cast<void*>(descriptorSetLayout), pAllocator);
Alexis Hetuc8176632019-01-22 17:01:28 -05001447
1448 vk::destroy(descriptorSetLayout, pAllocator);
Alexis Hetud73b8712018-09-21 15:14:43 -04001449}
1450
1451VKAPI_ATTR VkResult VKAPI_CALL vkCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDescriptorPool* pDescriptorPool)
1452{
Ben Claytonfb280672019-04-25 11:16:15 +01001453 TRACE("(VkDevice device = %p, const VkDescriptorPoolCreateInfo* pCreateInfo = %p, const VkAllocationCallbacks* pAllocator = %p, VkDescriptorPool* pDescriptorPool = %p)",
Alexis Hetuc8176632019-01-22 17:01:28 -05001454 device, pCreateInfo, pAllocator, pDescriptorPool);
1455
1456 if(pCreateInfo->pNext)
1457 {
Ben Clayton00424c12019-03-17 17:29:30 +00001458 UNIMPLEMENTED("pCreateInfo->pNext");
Alexis Hetuc8176632019-01-22 17:01:28 -05001459 }
1460
1461 return vk::DescriptorPool::Create(pAllocator, pCreateInfo, pDescriptorPool);
Alexis Hetud73b8712018-09-21 15:14:43 -04001462}
1463
1464VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, const VkAllocationCallbacks* pAllocator)
1465{
Ben Claytonfb280672019-04-25 11:16:15 +01001466 TRACE("(VkDevice device = %p, VkDescriptorPool descriptorPool = %p, const VkAllocationCallbacks* pAllocator = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001467 device, static_cast<void*>(descriptorPool), pAllocator);
Alexis Hetuc8176632019-01-22 17:01:28 -05001468
1469 vk::destroy(descriptorPool, pAllocator);
Alexis Hetud73b8712018-09-21 15:14:43 -04001470}
1471
1472VKAPI_ATTR VkResult VKAPI_CALL vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorPoolResetFlags flags)
1473{
Ben Claytonfb280672019-04-25 11:16:15 +01001474 TRACE("(VkDevice device = %p, VkDescriptorPool descriptorPool = %p, VkDescriptorPoolResetFlags flags = 0x%x)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001475 device, static_cast<void*>(descriptorPool), int(flags));
Alexis Hetuc8176632019-01-22 17:01:28 -05001476
1477 if(flags)
1478 {
Ben Clayton00424c12019-03-17 17:29:30 +00001479 UNIMPLEMENTED("flags");
Alexis Hetuc8176632019-01-22 17:01:28 -05001480 }
1481
1482 return vk::Cast(descriptorPool)->reset();
Alexis Hetud73b8712018-09-21 15:14:43 -04001483}
1484
1485VKAPI_ATTR VkResult VKAPI_CALL vkAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo* pAllocateInfo, VkDescriptorSet* pDescriptorSets)
1486{
Ben Claytonfb280672019-04-25 11:16:15 +01001487 TRACE("(VkDevice device = %p, const VkDescriptorSetAllocateInfo* pAllocateInfo = %p, VkDescriptorSet* pDescriptorSets = %p)",
Alexis Hetuc8176632019-01-22 17:01:28 -05001488 device, pAllocateInfo, pDescriptorSets);
1489
1490 if(pAllocateInfo->pNext)
1491 {
Ben Clayton00424c12019-03-17 17:29:30 +00001492 UNIMPLEMENTED("pAllocateInfo->pNext");
Alexis Hetuc8176632019-01-22 17:01:28 -05001493 }
1494
1495 return vk::Cast(pAllocateInfo->descriptorPool)->allocateSets(
1496 pAllocateInfo->descriptorSetCount, pAllocateInfo->pSetLayouts, pDescriptorSets);
Alexis Hetud73b8712018-09-21 15:14:43 -04001497}
1498
1499VKAPI_ATTR VkResult VKAPI_CALL vkFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t descriptorSetCount, const VkDescriptorSet* pDescriptorSets)
1500{
Ben Claytonfb280672019-04-25 11:16:15 +01001501 TRACE("(VkDevice device = %p, VkDescriptorPool descriptorPool = %p, uint32_t descriptorSetCount = %d, const VkDescriptorSet* pDescriptorSets = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001502 device, static_cast<void*>(descriptorPool), descriptorSetCount, pDescriptorSets);
Alexis Hetuc8176632019-01-22 17:01:28 -05001503
1504 vk::Cast(descriptorPool)->freeSets(descriptorSetCount, pDescriptorSets);
1505
Alexis Hetud73b8712018-09-21 15:14:43 -04001506 return VK_SUCCESS;
1507}
1508
1509VKAPI_ATTR void VKAPI_CALL vkUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount, const VkWriteDescriptorSet* pDescriptorWrites, uint32_t descriptorCopyCount, const VkCopyDescriptorSet* pDescriptorCopies)
1510{
Ben Claytonfb280672019-04-25 11:16:15 +01001511 TRACE("(VkDevice device = %p, uint32_t descriptorWriteCount = %d, const VkWriteDescriptorSet* pDescriptorWrites = %p, uint32_t descriptorCopyCount = %d, const VkCopyDescriptorSet* pDescriptorCopies = %p)",
Alexis Hetu048974f2019-02-15 15:28:37 -05001512 device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies);
1513
1514 vk::Cast(device)->updateDescriptorSets(descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies);
Alexis Hetud73b8712018-09-21 15:14:43 -04001515}
1516
1517VKAPI_ATTR VkResult VKAPI_CALL vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkFramebuffer* pFramebuffer)
1518{
Ben Claytonfb280672019-04-25 11:16:15 +01001519 TRACE("(VkDevice device = %p, const VkFramebufferCreateInfo* pCreateInfo = %p, const VkAllocationCallbacks* pAllocator = %p, VkFramebuffer* pFramebuffer = %p)",
Alexis Hetud73b8712018-09-21 15:14:43 -04001520 device, pCreateInfo, pAllocator, pFramebuffer);
1521
Alexis Hetu8f631c82018-11-15 15:11:36 -05001522 if(pCreateInfo->pNext || pCreateInfo->flags)
1523 {
Ben Clayton00424c12019-03-17 17:29:30 +00001524 UNIMPLEMENTED("pCreateInfo->pNext || pCreateInfo->flags");
Alexis Hetu8f631c82018-11-15 15:11:36 -05001525 }
Alexis Hetud73b8712018-09-21 15:14:43 -04001526
Alexis Hetu8f631c82018-11-15 15:11:36 -05001527 return vk::Framebuffer::Create(pAllocator, pCreateInfo, pFramebuffer);
Alexis Hetud73b8712018-09-21 15:14:43 -04001528}
1529
1530VKAPI_ATTR void VKAPI_CALL vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer, const VkAllocationCallbacks* pAllocator)
1531{
Ben Claytonfb280672019-04-25 11:16:15 +01001532 TRACE("(VkDevice device = %p, VkFramebuffer framebuffer = %p, const VkAllocationCallbacks* pAllocator = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001533 device, static_cast<void*>(framebuffer), pAllocator);
Alexis Hetud73b8712018-09-21 15:14:43 -04001534
Alexis Hetu8f631c82018-11-15 15:11:36 -05001535 vk::destroy(framebuffer, pAllocator);
Alexis Hetud73b8712018-09-21 15:14:43 -04001536}
1537
1538VKAPI_ATTR VkResult VKAPI_CALL vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkRenderPass* pRenderPass)
1539{
Ben Claytonfb280672019-04-25 11:16:15 +01001540 TRACE("(VkDevice device = %p, const VkRenderPassCreateInfo* pCreateInfo = %p, const VkAllocationCallbacks* pAllocator = %p, VkRenderPass* pRenderPass = %p)",
Alexis Hetud73b8712018-09-21 15:14:43 -04001541 device, pCreateInfo, pAllocator, pRenderPass);
1542
Alexis Hetu67806a12019-04-05 14:12:27 -04001543 if(pCreateInfo->flags)
Alexis Hetub16f9892018-11-15 15:18:41 -05001544 {
Alexis Hetu67806a12019-04-05 14:12:27 -04001545 UNIMPLEMENTED("pCreateInfo->flags");
1546 }
1547
1548 const VkBaseInStructure* extensionCreateInfo = reinterpret_cast<const VkBaseInStructure*>(pCreateInfo->pNext);
1549
1550 while(extensionCreateInfo)
1551 {
1552 switch(extensionCreateInfo->sType)
1553 {
1554 case VK_STRUCTURE_TYPE_RENDER_PASS_INPUT_ATTACHMENT_ASPECT_CREATE_INFO:
1555 {
1556 const VkRenderPassInputAttachmentAspectCreateInfo* inputAttachmentAspectCreateInfo = reinterpret_cast<const VkRenderPassInputAttachmentAspectCreateInfo*>(extensionCreateInfo);
1557
1558 for(uint32_t i = 0; i < inputAttachmentAspectCreateInfo->aspectReferenceCount; i++)
1559 {
1560 const VkInputAttachmentAspectReference& aspectReference = inputAttachmentAspectCreateInfo->pAspectReferences[i];
1561 ASSERT(aspectReference.subpass < pCreateInfo->subpassCount);
1562 const VkSubpassDescription& subpassDescription = pCreateInfo->pSubpasses[aspectReference.subpass];
1563 ASSERT(aspectReference.inputAttachmentIndex < subpassDescription.inputAttachmentCount);
1564 const VkAttachmentReference& attachmentReference = subpassDescription.pInputAttachments[aspectReference.inputAttachmentIndex];
1565 if(attachmentReference.attachment != VK_ATTACHMENT_UNUSED)
1566 {
1567 // If the pNext chain includes an instance of VkRenderPassInputAttachmentAspectCreateInfo, for any
1568 // element of the pInputAttachments member of any element of pSubpasses where the attachment member
1569 // is not VK_ATTACHMENT_UNUSED, the aspectMask member of the corresponding element of
1570 // VkRenderPassInputAttachmentAspectCreateInfo::pAspectReferences must only include aspects that are
1571 // present in images of the format specified by the element of pAttachments at attachment
1572 vk::Format format(pCreateInfo->pAttachments[attachmentReference.attachment].format);
1573 bool isDepth = format.isDepth();
1574 bool isStencil = format.isStencil();
1575 ASSERT(!(aspectReference.aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) || (!isDepth && !isStencil));
1576 ASSERT(!(aspectReference.aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) || isDepth);
1577 ASSERT(!(aspectReference.aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) || isStencil);
1578 }
1579 }
1580 }
1581 break;
1582 case VK_STRUCTURE_TYPE_RENDER_PASS_MULTIVIEW_CREATE_INFO:
1583 {
1584 const VkRenderPassMultiviewCreateInfo* multiviewCreateInfo = reinterpret_cast<const VkRenderPassMultiviewCreateInfo*>(extensionCreateInfo);
1585 ASSERT((multiviewCreateInfo->subpassCount == 0) || (multiviewCreateInfo->subpassCount == pCreateInfo->subpassCount));
1586 ASSERT((multiviewCreateInfo->dependencyCount == 0) || (multiviewCreateInfo->dependencyCount == pCreateInfo->dependencyCount));
1587
1588 bool zeroMask = (multiviewCreateInfo->pViewMasks[0] == 0);
1589 for(uint32_t i = 1; i < multiviewCreateInfo->subpassCount; i++)
1590 {
1591 ASSERT((multiviewCreateInfo->pViewMasks[i] == 0) == zeroMask);
1592 }
1593
1594 if(zeroMask)
1595 {
1596 ASSERT(multiviewCreateInfo->correlationMaskCount == 0);
1597 }
1598
1599 for(uint32_t i = 0; i < multiviewCreateInfo->dependencyCount; i++)
1600 {
1601 const VkSubpassDependency &dependency = pCreateInfo->pDependencies[i];
1602 if(multiviewCreateInfo->pViewOffsets[i] != 0)
1603 {
1604 ASSERT(dependency.srcSubpass != dependency.dstSubpass);
1605 ASSERT(dependency.dependencyFlags & VK_DEPENDENCY_VIEW_LOCAL_BIT);
1606 }
1607 if(zeroMask)
1608 {
1609 ASSERT(!(dependency.dependencyFlags & VK_DEPENDENCY_VIEW_LOCAL_BIT));
1610 }
1611 }
1612
1613 // If the pNext chain includes an instance of VkRenderPassMultiviewCreateInfo,
1614 // each element of its pViewMask member must not include a bit at a position
1615 // greater than the value of VkPhysicalDeviceLimits::maxFramebufferLayers
1616 // pViewMask is a 32 bit value. If maxFramebufferLayers > 32, it's impossible
1617 // for pViewMask to contain a bit at an illegal position
1618 // Note: Verify pViewMask values instead if we hit this assert
Nicolas Capens0c736802019-05-27 12:53:31 -04001619 ASSERT(vk::Cast(device)->getPhysicalDevice()->getProperties().limits.maxFramebufferLayers >= 32);
Alexis Hetu67806a12019-04-05 14:12:27 -04001620 }
1621 break;
1622 default:
Nicolas Capens6b63c802019-05-16 11:10:34 -04001623 UNIMPLEMENTED("extensionCreateInfo->sType %d", int(extensionCreateInfo->sType));
Alexis Hetu67806a12019-04-05 14:12:27 -04001624 break;
1625 }
1626
1627 extensionCreateInfo = extensionCreateInfo->pNext;
Alexis Hetub16f9892018-11-15 15:18:41 -05001628 }
Alexis Hetud73b8712018-09-21 15:14:43 -04001629
Alexis Hetub16f9892018-11-15 15:18:41 -05001630 return vk::RenderPass::Create(pAllocator, pCreateInfo, pRenderPass);
Alexis Hetud73b8712018-09-21 15:14:43 -04001631}
1632
1633VKAPI_ATTR void VKAPI_CALL vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass, const VkAllocationCallbacks* pAllocator)
1634{
Ben Claytonfb280672019-04-25 11:16:15 +01001635 TRACE("(VkDevice device = %p, VkRenderPass renderPass = %p, const VkAllocationCallbacks* pAllocator = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001636 device, static_cast<void*>(renderPass), pAllocator);
Alexis Hetud73b8712018-09-21 15:14:43 -04001637
Alexis Hetub16f9892018-11-15 15:18:41 -05001638 vk::destroy(renderPass, pAllocator);
Alexis Hetud73b8712018-09-21 15:14:43 -04001639}
1640
1641VKAPI_ATTR void VKAPI_CALL vkGetRenderAreaGranularity(VkDevice device, VkRenderPass renderPass, VkExtent2D* pGranularity)
1642{
Ben Claytonfb280672019-04-25 11:16:15 +01001643 TRACE("(VkDevice device = %p, VkRenderPass renderPass = %p, VkExtent2D* pGranularity = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001644 device, static_cast<void*>(renderPass), pGranularity);
Hernan Liatisc7943e92019-02-25 19:29:54 -08001645
Alexis Hetu6d74ab82019-02-15 14:42:38 -05001646 vk::Cast(renderPass)->getRenderAreaGranularity(pGranularity);
Alexis Hetud73b8712018-09-21 15:14:43 -04001647}
1648
1649VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkCommandPool* pCommandPool)
1650{
Ben Claytonfb280672019-04-25 11:16:15 +01001651 TRACE("(VkDevice device = %p, const VkCommandPoolCreateInfo* pCreateInfo = %p, const VkAllocationCallbacks* pAllocator = %p, VkCommandPool* pCommandPool = %p)",
Alexis Hetud73b8712018-09-21 15:14:43 -04001652 device, pCreateInfo, pAllocator, pCommandPool);
1653
Alexis Hetu9c4ecae2018-11-20 16:26:10 -05001654 if(pCreateInfo->pNext)
1655 {
Ben Clayton00424c12019-03-17 17:29:30 +00001656 UNIMPLEMENTED("pCreateInfo->pNext");
Alexis Hetu9c4ecae2018-11-20 16:26:10 -05001657 }
Alexis Hetud73b8712018-09-21 15:14:43 -04001658
Alexis Hetu9c4ecae2018-11-20 16:26:10 -05001659 return vk::CommandPool::Create(pAllocator, pCreateInfo, pCommandPool);
Alexis Hetud73b8712018-09-21 15:14:43 -04001660}
1661
1662VKAPI_ATTR void VKAPI_CALL vkDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks* pAllocator)
1663{
Ben Claytonfb280672019-04-25 11:16:15 +01001664 TRACE("(VkDevice device = %p, VkCommandPool commandPool = %p, const VkAllocationCallbacks* pAllocator = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001665 device, static_cast<void*>(commandPool), pAllocator);
Alexis Hetud73b8712018-09-21 15:14:43 -04001666
Alexis Hetu9c4ecae2018-11-20 16:26:10 -05001667 vk::destroy(commandPool, pAllocator);
Alexis Hetud73b8712018-09-21 15:14:43 -04001668}
1669
1670VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandPool(VkDevice device, VkCommandPool commandPool, VkCommandPoolResetFlags flags)
1671{
Ben Claytonfb280672019-04-25 11:16:15 +01001672 TRACE("(VkDevice device = %p, VkCommandPool commandPool = %p, VkCommandPoolResetFlags flags = %d)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001673 device, static_cast<void*>(commandPool), int(flags));
Alexis Hetucd610c92019-02-01 16:47:51 -05001674
1675 return vk::Cast(commandPool)->reset(flags);
Alexis Hetud73b8712018-09-21 15:14:43 -04001676}
1677
1678VKAPI_ATTR VkResult VKAPI_CALL vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo* pAllocateInfo, VkCommandBuffer* pCommandBuffers)
1679{
Ben Claytonfb280672019-04-25 11:16:15 +01001680 TRACE("(VkDevice device = %p, const VkCommandBufferAllocateInfo* pAllocateInfo = %p, VkCommandBuffer* pCommandBuffers = %p)",
Alexis Hetud73b8712018-09-21 15:14:43 -04001681 device, pAllocateInfo, pCommandBuffers);
1682
Alexis Hetubffee5e2018-11-19 11:30:43 -05001683 if(pAllocateInfo->pNext)
1684 {
Ben Clayton00424c12019-03-17 17:29:30 +00001685 UNIMPLEMENTED("pAllocateInfo->pNext");
Alexis Hetubffee5e2018-11-19 11:30:43 -05001686 }
Alexis Hetud73b8712018-09-21 15:14:43 -04001687
Alexis Hetubffee5e2018-11-19 11:30:43 -05001688 return vk::Cast(pAllocateInfo->commandPool)->allocateCommandBuffers(
1689 pAllocateInfo->level, pAllocateInfo->commandBufferCount, pCommandBuffers);
Alexis Hetud73b8712018-09-21 15:14:43 -04001690}
1691
1692VKAPI_ATTR void VKAPI_CALL vkFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount, const VkCommandBuffer* pCommandBuffers)
1693{
Ben Claytonfb280672019-04-25 11:16:15 +01001694 TRACE("(VkDevice device = %p, VkCommandPool commandPool = %p, uint32_t commandBufferCount = %d, const VkCommandBuffer* pCommandBuffers = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001695 device, static_cast<void*>(commandPool), int(commandBufferCount), pCommandBuffers);
Alexis Hetud73b8712018-09-21 15:14:43 -04001696
Alexis Hetubffee5e2018-11-19 11:30:43 -05001697 vk::Cast(commandPool)->freeCommandBuffers(commandBufferCount, pCommandBuffers);
Alexis Hetud73b8712018-09-21 15:14:43 -04001698}
1699
1700VKAPI_ATTR VkResult VKAPI_CALL vkBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo* pBeginInfo)
1701{
Ben Claytonfb280672019-04-25 11:16:15 +01001702 TRACE("(VkCommandBuffer commandBuffer = %p, const VkCommandBufferBeginInfo* pBeginInfo = %p)",
Alexis Hetud73b8712018-09-21 15:14:43 -04001703 commandBuffer, pBeginInfo);
1704
Alexis Hetua9999ce2018-10-17 08:00:43 -04001705 if(pBeginInfo->pNext)
1706 {
Ben Clayton00424c12019-03-17 17:29:30 +00001707 UNIMPLEMENTED("pBeginInfo->pNext");
Alexis Hetua9999ce2018-10-17 08:00:43 -04001708 }
Alexis Hetud73b8712018-09-21 15:14:43 -04001709
Alexis Hetua9999ce2018-10-17 08:00:43 -04001710 return vk::Cast(commandBuffer)->begin(pBeginInfo->flags, pBeginInfo->pInheritanceInfo);
Alexis Hetud73b8712018-09-21 15:14:43 -04001711}
1712
1713VKAPI_ATTR VkResult VKAPI_CALL vkEndCommandBuffer(VkCommandBuffer commandBuffer)
1714{
Ben Claytonfb280672019-04-25 11:16:15 +01001715 TRACE("(VkCommandBuffer commandBuffer = %p)", commandBuffer);
Alexis Hetud73b8712018-09-21 15:14:43 -04001716
Alexis Hetua9999ce2018-10-17 08:00:43 -04001717 return vk::Cast(commandBuffer)->end();
Alexis Hetud73b8712018-09-21 15:14:43 -04001718}
1719
1720VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags)
1721{
Ben Claytonfb280672019-04-25 11:16:15 +01001722 TRACE("VkCommandBuffer commandBuffer = %p, VkCommandBufferResetFlags flags = %d", commandBuffer, int(flags));
Alexis Hetua9999ce2018-10-17 08:00:43 -04001723
1724 return vk::Cast(commandBuffer)->reset(flags);
Alexis Hetud73b8712018-09-21 15:14:43 -04001725}
1726
1727VKAPI_ATTR void VKAPI_CALL vkCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
1728{
Ben Claytonfb280672019-04-25 11:16:15 +01001729 TRACE("(VkCommandBuffer commandBuffer = %p, VkPipelineBindPoint pipelineBindPoint = %d, VkPipeline pipeline = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001730 commandBuffer, int(pipelineBindPoint), static_cast<void*>(pipeline));
Alexis Hetud73b8712018-09-21 15:14:43 -04001731
Alexis Hetu7d96f512019-06-13 18:23:56 -04001732 vk::Cast(commandBuffer)->bindPipeline(pipelineBindPoint, vk::Cast(pipeline));
Alexis Hetud73b8712018-09-21 15:14:43 -04001733}
1734
1735VKAPI_ATTR void VKAPI_CALL vkCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport, uint32_t viewportCount, const VkViewport* pViewports)
1736{
Ben Claytonfb280672019-04-25 11:16:15 +01001737 TRACE("(VkCommandBuffer commandBuffer = %p, uint32_t firstViewport = %d, uint32_t viewportCount = %d, const VkViewport* pViewports = %p)",
1738 commandBuffer, int(firstViewport), int(viewportCount), pViewports);
Alexis Hetua9999ce2018-10-17 08:00:43 -04001739
1740 vk::Cast(commandBuffer)->setViewport(firstViewport, viewportCount, pViewports);
Alexis Hetud73b8712018-09-21 15:14:43 -04001741}
1742
1743VKAPI_ATTR void VKAPI_CALL vkCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount, const VkRect2D* pScissors)
1744{
Ben Claytonfb280672019-04-25 11:16:15 +01001745 TRACE("(VkCommandBuffer commandBuffer = %p, uint32_t firstScissor = %d, uint32_t scissorCount = %d, const VkRect2D* pScissors = %p)",
1746 commandBuffer, int(firstScissor), int(scissorCount), pScissors);
Alexis Hetua9999ce2018-10-17 08:00:43 -04001747
1748 vk::Cast(commandBuffer)->setScissor(firstScissor, scissorCount, pScissors);
Alexis Hetud73b8712018-09-21 15:14:43 -04001749}
1750
1751VKAPI_ATTR void VKAPI_CALL vkCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth)
1752{
Ben Claytonfb280672019-04-25 11:16:15 +01001753 TRACE("(VkCommandBuffer commandBuffer = %p, float lineWidth = %f)", commandBuffer, lineWidth);
Alexis Hetua9999ce2018-10-17 08:00:43 -04001754
1755 vk::Cast(commandBuffer)->setLineWidth(lineWidth);
Alexis Hetud73b8712018-09-21 15:14:43 -04001756}
1757
1758VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBias(VkCommandBuffer commandBuffer, float depthBiasConstantFactor, float depthBiasClamp, float depthBiasSlopeFactor)
1759{
Ben Claytonfb280672019-04-25 11:16:15 +01001760 TRACE("(VkCommandBuffer commandBuffer = %p, float depthBiasConstantFactor = %f, float depthBiasClamp = %f, float depthBiasSlopeFactor = %f)",
Alexis Hetua9999ce2018-10-17 08:00:43 -04001761 commandBuffer, depthBiasConstantFactor, depthBiasClamp, depthBiasSlopeFactor);
1762
1763 vk::Cast(commandBuffer)->setDepthBias(depthBiasConstantFactor, depthBiasClamp, depthBiasSlopeFactor);
Alexis Hetud73b8712018-09-21 15:14:43 -04001764}
1765
1766VKAPI_ATTR void VKAPI_CALL vkCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4])
1767{
Ben Claytonfb280672019-04-25 11:16:15 +01001768 TRACE("(VkCommandBuffer commandBuffer = %p, const float blendConstants[4] = {%f, %f, %f, %f})",
Alexis Hetua9999ce2018-10-17 08:00:43 -04001769 commandBuffer, blendConstants[0], blendConstants[1], blendConstants[2], blendConstants[3]);
1770
1771 vk::Cast(commandBuffer)->setBlendConstants(blendConstants);
Alexis Hetud73b8712018-09-21 15:14:43 -04001772}
1773
1774VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBounds(VkCommandBuffer commandBuffer, float minDepthBounds, float maxDepthBounds)
1775{
Ben Claytonfb280672019-04-25 11:16:15 +01001776 TRACE("(VkCommandBuffer commandBuffer = %p, float minDepthBounds = %f, float maxDepthBounds = %f)",
Alexis Hetua9999ce2018-10-17 08:00:43 -04001777 commandBuffer, minDepthBounds, maxDepthBounds);
1778
1779 vk::Cast(commandBuffer)->setDepthBounds(minDepthBounds, maxDepthBounds);
Alexis Hetud73b8712018-09-21 15:14:43 -04001780}
1781
1782VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilCompareMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask, uint32_t compareMask)
1783{
Ben Claytonfb280672019-04-25 11:16:15 +01001784 TRACE("(VkCommandBuffer commandBuffer = %p, VkStencilFaceFlags faceMask = %d, uint32_t compareMask = %d)",
1785 commandBuffer, int(faceMask), int(compareMask));
Alexis Hetua9999ce2018-10-17 08:00:43 -04001786
1787 vk::Cast(commandBuffer)->setStencilCompareMask(faceMask, compareMask);
Alexis Hetud73b8712018-09-21 15:14:43 -04001788}
1789
1790VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilWriteMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask, uint32_t writeMask)
1791{
Ben Claytonfb280672019-04-25 11:16:15 +01001792 TRACE("(VkCommandBuffer commandBuffer = %p, VkStencilFaceFlags faceMask = %d, uint32_t writeMask = %d)",
1793 commandBuffer, int(faceMask), int(writeMask));
Alexis Hetua9999ce2018-10-17 08:00:43 -04001794
1795 vk::Cast(commandBuffer)->setStencilWriteMask(faceMask, writeMask);
Alexis Hetud73b8712018-09-21 15:14:43 -04001796}
1797
1798VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilReference(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask, uint32_t reference)
1799{
Ben Claytonfb280672019-04-25 11:16:15 +01001800 TRACE("(VkCommandBuffer commandBuffer = %p, VkStencilFaceFlags faceMask = %d, uint32_t reference = %d)",
1801 commandBuffer, int(faceMask), int(reference));
Alexis Hetua9999ce2018-10-17 08:00:43 -04001802
1803 vk::Cast(commandBuffer)->setStencilReference(faceMask, reference);
Alexis Hetud73b8712018-09-21 15:14:43 -04001804}
1805
1806VKAPI_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)
1807{
Ben Claytonfb280672019-04-25 11:16:15 +01001808 TRACE("(VkCommandBuffer commandBuffer = %p, VkPipelineBindPoint pipelineBindPoint = %d, VkPipelineLayout layout = %p, uint32_t firstSet = %d, uint32_t descriptorSetCount = %d, const VkDescriptorSet* pDescriptorSets = %p, uint32_t dynamicOffsetCount = %d, const uint32_t* pDynamicOffsets = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001809 commandBuffer, int(pipelineBindPoint), static_cast<void*>(layout), int(firstSet), int(descriptorSetCount), pDescriptorSets, int(dynamicOffsetCount), pDynamicOffsets);
Alexis Hetua9999ce2018-10-17 08:00:43 -04001810
Alexis Hetu7d96f512019-06-13 18:23:56 -04001811 vk::Cast(commandBuffer)->bindDescriptorSets(pipelineBindPoint, vk::Cast(layout), firstSet, descriptorSetCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Alexis Hetud73b8712018-09-21 15:14:43 -04001812}
1813
1814VKAPI_ATTR void VKAPI_CALL vkCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
1815{
Ben Claytonfb280672019-04-25 11:16:15 +01001816 TRACE("(VkCommandBuffer commandBuffer = %p, VkBuffer buffer = %p, VkDeviceSize offset = %d, VkIndexType indexType = %d)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001817 commandBuffer, static_cast<void*>(buffer), int(offset), int(indexType));
Alexis Hetua9999ce2018-10-17 08:00:43 -04001818
Alexis Hetu7d96f512019-06-13 18:23:56 -04001819 vk::Cast(commandBuffer)->bindIndexBuffer(vk::Cast(buffer), offset, indexType);
Alexis Hetud73b8712018-09-21 15:14:43 -04001820}
1821
1822VKAPI_ATTR void VKAPI_CALL vkCmdBindVertexBuffers(VkCommandBuffer commandBuffer, uint32_t firstBinding, uint32_t bindingCount, const VkBuffer* pBuffers, const VkDeviceSize* pOffsets)
1823{
Ben Claytonfb280672019-04-25 11:16:15 +01001824 TRACE("(VkCommandBuffer commandBuffer = %p, uint32_t firstBinding = %d, uint32_t bindingCount = %d, const VkBuffer* pBuffers = %p, const VkDeviceSize* pOffsets = %p)",
1825 commandBuffer, int(firstBinding), int(bindingCount), pBuffers, pOffsets);
Alexis Hetud73b8712018-09-21 15:14:43 -04001826
Alexis Hetua9999ce2018-10-17 08:00:43 -04001827 vk::Cast(commandBuffer)->bindVertexBuffers(firstBinding, bindingCount, pBuffers, pOffsets);
Alexis Hetud73b8712018-09-21 15:14:43 -04001828}
1829
1830VKAPI_ATTR void VKAPI_CALL vkCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance)
1831{
Ben Claytonfb280672019-04-25 11:16:15 +01001832 TRACE("(VkCommandBuffer commandBuffer = %p, uint32_t vertexCount = %d, uint32_t instanceCount = %d, uint32_t firstVertex = %d, uint32_t firstInstance = %d)",
1833 commandBuffer, int(vertexCount), int(instanceCount), int(firstVertex), int(firstInstance));
Alexis Hetud73b8712018-09-21 15:14:43 -04001834
Alexis Hetua9999ce2018-10-17 08:00:43 -04001835 vk::Cast(commandBuffer)->draw(vertexCount, instanceCount, firstVertex, firstInstance);
Alexis Hetud73b8712018-09-21 15:14:43 -04001836}
1837
1838VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance)
1839{
Ben Claytonfb280672019-04-25 11:16:15 +01001840 TRACE("(VkCommandBuffer commandBuffer = %p, uint32_t indexCount = %d, uint32_t instanceCount = %d, uint32_t firstIndex = %d, int32_t vertexOffset = %d, uint32_t firstInstance = %d)",
1841 commandBuffer, int(indexCount), int(instanceCount), int(firstIndex), int(vertexOffset), int(firstInstance));
Alexis Hetud73b8712018-09-21 15:14:43 -04001842
Alexis Hetua9999ce2018-10-17 08:00:43 -04001843 vk::Cast(commandBuffer)->drawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Alexis Hetud73b8712018-09-21 15:14:43 -04001844}
1845
1846VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t drawCount, uint32_t stride)
1847{
Ben Claytonfb280672019-04-25 11:16:15 +01001848 TRACE("(VkCommandBuffer commandBuffer = %p, VkBuffer buffer = %p, VkDeviceSize offset = %d, uint32_t drawCount = %d, uint32_t stride = %d)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001849 commandBuffer, static_cast<void*>(buffer), int(offset), int(drawCount), int(stride));
Alexis Hetud73b8712018-09-21 15:14:43 -04001850
Alexis Hetu7d96f512019-06-13 18:23:56 -04001851 vk::Cast(commandBuffer)->drawIndirect(vk::Cast(buffer), offset, drawCount, stride);
Alexis Hetud73b8712018-09-21 15:14:43 -04001852}
1853
1854VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t drawCount, uint32_t stride)
1855{
Ben Claytonfb280672019-04-25 11:16:15 +01001856 TRACE("(VkCommandBuffer commandBuffer = %p, VkBuffer buffer = %p, VkDeviceSize offset = %d, uint32_t drawCount = %d, uint32_t stride = %d)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001857 commandBuffer, static_cast<void*>(buffer), int(offset), int(drawCount), int(stride));
Alexis Hetud73b8712018-09-21 15:14:43 -04001858
Alexis Hetu7d96f512019-06-13 18:23:56 -04001859 vk::Cast(commandBuffer)->drawIndexedIndirect(vk::Cast(buffer), offset, drawCount, stride);
Alexis Hetud73b8712018-09-21 15:14:43 -04001860}
1861
1862VKAPI_ATTR void VKAPI_CALL vkCmdDispatch(VkCommandBuffer commandBuffer, uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ)
1863{
Ben Claytonfb280672019-04-25 11:16:15 +01001864 TRACE("(VkCommandBuffer commandBuffer = %p, uint32_t groupCountX = %d, uint32_t groupCountY = %d, uint32_t groupCountZ = %d)",
1865 commandBuffer, int(groupCountX), int(groupCountY), int(groupCountZ));
Alexis Hetua9999ce2018-10-17 08:00:43 -04001866
1867 vk::Cast(commandBuffer)->dispatch(groupCountX, groupCountY, groupCountZ);
Alexis Hetud73b8712018-09-21 15:14:43 -04001868}
1869
1870VKAPI_ATTR void VKAPI_CALL vkCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset)
1871{
Ben Claytonfb280672019-04-25 11:16:15 +01001872 TRACE("(VkCommandBuffer commandBuffer = %p, VkBuffer buffer = %p, VkDeviceSize offset = %d)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001873 commandBuffer, static_cast<void*>(buffer), int(offset));
Alexis Hetua9999ce2018-10-17 08:00:43 -04001874
Alexis Hetu7d96f512019-06-13 18:23:56 -04001875 vk::Cast(commandBuffer)->dispatchIndirect(vk::Cast(buffer), offset);
Alexis Hetud73b8712018-09-21 15:14:43 -04001876}
1877
1878VKAPI_ATTR void VKAPI_CALL vkCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
1879{
Ben Claytonfb280672019-04-25 11:16:15 +01001880 TRACE("(VkCommandBuffer commandBuffer = %p, VkBuffer srcBuffer = %p, VkBuffer dstBuffer = %p, uint32_t regionCount = %d, const VkBufferCopy* pRegions = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001881 commandBuffer, static_cast<void*>(srcBuffer), static_cast<void*>(dstBuffer), int(regionCount), pRegions);
Alexis Hetua9999ce2018-10-17 08:00:43 -04001882
Alexis Hetu7d96f512019-06-13 18:23:56 -04001883 vk::Cast(commandBuffer)->copyBuffer(vk::Cast(srcBuffer), vk::Cast(dstBuffer), regionCount, pRegions);
Alexis Hetud73b8712018-09-21 15:14:43 -04001884}
1885
1886VKAPI_ATTR void VKAPI_CALL vkCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageCopy* pRegions)
1887{
Ben Claytonfb280672019-04-25 11:16:15 +01001888 TRACE("(VkCommandBuffer commandBuffer = %p, VkImage srcImage = %p, VkImageLayout srcImageLayout = %d, VkImage dstImage = %p, VkImageLayout dstImageLayout = %d, uint32_t regionCount = %d, const VkImageCopy* pRegions = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001889 commandBuffer, static_cast<void*>(srcImage), srcImageLayout, static_cast<void*>(dstImage), dstImageLayout, int(regionCount), pRegions);
Alexis Hetua9999ce2018-10-17 08:00:43 -04001890
Alexis Hetu7d96f512019-06-13 18:23:56 -04001891 vk::Cast(commandBuffer)->copyImage(vk::Cast(srcImage), srcImageLayout, vk::Cast(dstImage), dstImageLayout, regionCount, pRegions);
Alexis Hetud73b8712018-09-21 15:14:43 -04001892}
1893
1894VKAPI_ATTR void VKAPI_CALL vkCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageBlit* pRegions, VkFilter filter)
1895{
Ben Claytonfb280672019-04-25 11:16:15 +01001896 TRACE("(VkCommandBuffer commandBuffer = %p, VkImage srcImage = %p, VkImageLayout srcImageLayout = %d, VkImage dstImage = %p, VkImageLayout dstImageLayout = %d, uint32_t regionCount = %d, const VkImageBlit* pRegions = %p, VkFilter filter = %d)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001897 commandBuffer, static_cast<void*>(srcImage), srcImageLayout, static_cast<void*>(dstImage), dstImageLayout, int(regionCount), pRegions, filter);
Alexis Hetua9999ce2018-10-17 08:00:43 -04001898
Alexis Hetu7d96f512019-06-13 18:23:56 -04001899 vk::Cast(commandBuffer)->blitImage(vk::Cast(srcImage), srcImageLayout, vk::Cast(dstImage), dstImageLayout, regionCount, pRegions, filter);
Alexis Hetud73b8712018-09-21 15:14:43 -04001900}
1901
1902VKAPI_ATTR void VKAPI_CALL vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, const VkBufferImageCopy* pRegions)
1903{
Ben Claytonfb280672019-04-25 11:16:15 +01001904 TRACE("(VkCommandBuffer commandBuffer = %p, VkBuffer srcBuffer = %p, VkImage dstImage = %p, VkImageLayout dstImageLayout = %d, uint32_t regionCount = %d, const VkBufferImageCopy* pRegions = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001905 commandBuffer, static_cast<void*>(srcBuffer), static_cast<void*>(dstImage), dstImageLayout, int(regionCount), pRegions);
Alexis Hetua9999ce2018-10-17 08:00:43 -04001906
Alexis Hetu7d96f512019-06-13 18:23:56 -04001907 vk::Cast(commandBuffer)->copyBufferToImage(vk::Cast(srcBuffer), vk::Cast(dstImage), dstImageLayout, regionCount, pRegions);
Alexis Hetud73b8712018-09-21 15:14:43 -04001908}
1909
1910VKAPI_ATTR void VKAPI_CALL vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkBuffer dstBuffer, uint32_t regionCount, const VkBufferImageCopy* pRegions)
1911{
Ben Claytonfb280672019-04-25 11:16:15 +01001912 TRACE("(VkCommandBuffer commandBuffer = %p, VkImage srcImage = %p, VkImageLayout srcImageLayout = %d, VkBuffer dstBuffer = %p, uint32_t regionCount = %d, const VkBufferImageCopy* pRegions = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001913 commandBuffer, static_cast<void*>(srcImage), int(srcImageLayout), static_cast<void*>(dstBuffer), int(regionCount), pRegions);
Alexis Hetud73b8712018-09-21 15:14:43 -04001914
Alexis Hetu7d96f512019-06-13 18:23:56 -04001915 vk::Cast(commandBuffer)->copyImageToBuffer(vk::Cast(srcImage), srcImageLayout, vk::Cast(dstBuffer), regionCount, pRegions);
Alexis Hetud73b8712018-09-21 15:14:43 -04001916}
1917
1918VKAPI_ATTR void VKAPI_CALL vkCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize dataSize, const void* pData)
1919{
Ben Claytonfb280672019-04-25 11:16:15 +01001920 TRACE("(VkCommandBuffer commandBuffer = %p, VkBuffer dstBuffer = %p, VkDeviceSize dstOffset = %d, VkDeviceSize dataSize = %d, const void* pData = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001921 commandBuffer, static_cast<void*>(dstBuffer), int(dstOffset), int(dataSize), pData);
Alexis Hetua9999ce2018-10-17 08:00:43 -04001922
Alexis Hetu7d96f512019-06-13 18:23:56 -04001923 vk::Cast(commandBuffer)->updateBuffer(vk::Cast(dstBuffer), dstOffset, dataSize, pData);
Alexis Hetud73b8712018-09-21 15:14:43 -04001924}
1925
1926VKAPI_ATTR void VKAPI_CALL vkCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize size, uint32_t data)
1927{
Ben Claytonfb280672019-04-25 11:16:15 +01001928 TRACE("(VkCommandBuffer commandBuffer = %p, VkBuffer dstBuffer = %p, VkDeviceSize dstOffset = %d, VkDeviceSize size = %d, uint32_t data = %d)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001929 commandBuffer, static_cast<void*>(dstBuffer), int(dstOffset), int(size), data);
Alexis Hetua9999ce2018-10-17 08:00:43 -04001930
Alexis Hetu7d96f512019-06-13 18:23:56 -04001931 vk::Cast(commandBuffer)->fillBuffer(vk::Cast(dstBuffer), dstOffset, size, data);
Alexis Hetud73b8712018-09-21 15:14:43 -04001932}
1933
1934VKAPI_ATTR void VKAPI_CALL vkCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, const VkClearColorValue* pColor, uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
1935{
Ben Claytonfb280672019-04-25 11:16:15 +01001936 TRACE("(VkCommandBuffer commandBuffer = %p, VkImage image = %p, VkImageLayout imageLayout = %d, const VkClearColorValue* pColor = %p, uint32_t rangeCount = %d, const VkImageSubresourceRange* pRanges = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001937 commandBuffer, static_cast<void*>(image), int(imageLayout), pColor, int(rangeCount), pRanges);
Alexis Hetua9999ce2018-10-17 08:00:43 -04001938
Alexis Hetu7d96f512019-06-13 18:23:56 -04001939 vk::Cast(commandBuffer)->clearColorImage(vk::Cast(image), imageLayout, pColor, rangeCount, pRanges);
Alexis Hetud73b8712018-09-21 15:14:43 -04001940}
1941
1942VKAPI_ATTR void VKAPI_CALL vkCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, const VkClearDepthStencilValue* pDepthStencil, uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
1943{
Ben Claytonfb280672019-04-25 11:16:15 +01001944 TRACE("(VkCommandBuffer commandBuffer = %p, VkImage image = %p, VkImageLayout imageLayout = %d, const VkClearDepthStencilValue* pDepthStencil = %p, uint32_t rangeCount = %d, const VkImageSubresourceRange* pRanges = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001945 commandBuffer, static_cast<void*>(image), int(imageLayout), pDepthStencil, int(rangeCount), pRanges);
Alexis Hetua9999ce2018-10-17 08:00:43 -04001946
Alexis Hetu7d96f512019-06-13 18:23:56 -04001947 vk::Cast(commandBuffer)->clearDepthStencilImage(vk::Cast(image), imageLayout, pDepthStencil, rangeCount, pRanges);
Alexis Hetud73b8712018-09-21 15:14:43 -04001948}
1949
1950VKAPI_ATTR void VKAPI_CALL vkCmdClearAttachments(VkCommandBuffer commandBuffer, uint32_t attachmentCount, const VkClearAttachment* pAttachments, uint32_t rectCount, const VkClearRect* pRects)
1951{
Ben Claytonfb280672019-04-25 11:16:15 +01001952 TRACE("(VkCommandBuffer commandBuffer = %p, uint32_t attachmentCount = %d, const VkClearAttachment* pAttachments = %p, uint32_t rectCount = %d, const VkClearRect* pRects = %p)",
1953 commandBuffer, int(attachmentCount), pAttachments, int(rectCount), pRects);
Alexis Hetua9999ce2018-10-17 08:00:43 -04001954
1955 vk::Cast(commandBuffer)->clearAttachments(attachmentCount, pAttachments, rectCount, pRects);
Alexis Hetud73b8712018-09-21 15:14:43 -04001956}
1957
1958VKAPI_ATTR void VKAPI_CALL vkCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageResolve* pRegions)
1959{
Ben Claytonfb280672019-04-25 11:16:15 +01001960 TRACE("(VkCommandBuffer commandBuffer = %p, VkImage srcImage = %p, VkImageLayout srcImageLayout = %d, VkImage dstImage = %p, VkImageLayout dstImageLayout = %d, uint32_t regionCount = %d, const VkImageResolve* pRegions = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001961 commandBuffer, static_cast<void*>(srcImage), int(srcImageLayout), static_cast<void*>(dstImage), int(dstImageLayout), regionCount, pRegions);
Alexis Hetua9999ce2018-10-17 08:00:43 -04001962
Alexis Hetu7d96f512019-06-13 18:23:56 -04001963 vk::Cast(commandBuffer)->resolveImage(vk::Cast(srcImage), srcImageLayout, vk::Cast(dstImage), dstImageLayout, regionCount, pRegions);
Alexis Hetud73b8712018-09-21 15:14:43 -04001964}
1965
1966VKAPI_ATTR void VKAPI_CALL vkCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
1967{
Ben Claytonfb280672019-04-25 11:16:15 +01001968 TRACE("(VkCommandBuffer commandBuffer = %p, VkEvent event = %p, VkPipelineStageFlags stageMask = %d)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001969 commandBuffer, static_cast<void*>(event), int(stageMask));
Alexis Hetua9999ce2018-10-17 08:00:43 -04001970
Alexis Hetu7d96f512019-06-13 18:23:56 -04001971 vk::Cast(commandBuffer)->setEvent(vk::Cast(event), stageMask);
Alexis Hetud73b8712018-09-21 15:14:43 -04001972}
1973
1974VKAPI_ATTR void VKAPI_CALL vkCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
1975{
Ben Claytonfb280672019-04-25 11:16:15 +01001976 TRACE("(VkCommandBuffer commandBuffer = %p, VkEvent event = %p, VkPipelineStageFlags stageMask = %d)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04001977 commandBuffer, static_cast<void*>(event), int(stageMask));
Alexis Hetua9999ce2018-10-17 08:00:43 -04001978
Alexis Hetu7d96f512019-06-13 18:23:56 -04001979 vk::Cast(commandBuffer)->resetEvent(vk::Cast(event), stageMask);
Alexis Hetud73b8712018-09-21 15:14:43 -04001980}
1981
1982VKAPI_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)
1983{
Ben Claytonfb280672019-04-25 11:16:15 +01001984 TRACE("(VkCommandBuffer commandBuffer = %p, uint32_t eventCount = %d, const VkEvent* pEvents = %p, VkPipelineStageFlags srcStageMask = 0x%x, VkPipelineStageFlags dstStageMask = 0x%x, uint32_t memoryBarrierCount = %d, const VkMemoryBarrier* pMemoryBarriers = %p, uint32_t bufferMemoryBarrierCount = %d, const VkBufferMemoryBarrier* pBufferMemoryBarriers = %p, uint32_t imageMemoryBarrierCount = %d, const VkImageMemoryBarrier* pImageMemoryBarriers = %p)",
1985 commandBuffer, int(eventCount), pEvents, int(srcStageMask), int(dstStageMask), int(memoryBarrierCount), pMemoryBarriers, int(bufferMemoryBarrierCount), pBufferMemoryBarriers, int(imageMemoryBarrierCount), pImageMemoryBarriers);
Alexis Hetua9999ce2018-10-17 08:00:43 -04001986
1987 vk::Cast(commandBuffer)->waitEvents(eventCount, pEvents, srcStageMask, dstStageMask, memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers);
Alexis Hetud73b8712018-09-21 15:14:43 -04001988}
1989
1990VKAPI_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)
1991{
Ben Claytonfb280672019-04-25 11:16:15 +01001992 TRACE("(VkCommandBuffer commandBuffer = %p, VkPipelineStageFlags srcStageMask = 0x%x, VkPipelineStageFlags dstStageMask = 0x%x, VkDependencyFlags dependencyFlags = %d, uint32_t memoryBarrierCount = %d, onst VkMemoryBarrier* pMemoryBarriers = %p,"
1993 " uint32_t bufferMemoryBarrierCount = %d, const VkBufferMemoryBarrier* pBufferMemoryBarriers = %p, uint32_t imageMemoryBarrierCount = %d, const VkImageMemoryBarrier* pImageMemoryBarriers = %p)",
1994 commandBuffer, int(srcStageMask), int(dstStageMask), dependencyFlags, int(memoryBarrierCount), pMemoryBarriers, int(bufferMemoryBarrierCount), pBufferMemoryBarriers, int(imageMemoryBarrierCount), pImageMemoryBarriers);
Alexis Hetud73b8712018-09-21 15:14:43 -04001995
Alexis Hetua9999ce2018-10-17 08:00:43 -04001996 vk::Cast(commandBuffer)->pipelineBarrier(srcStageMask, dstStageMask, dependencyFlags,
1997 memoryBarrierCount, pMemoryBarriers,
1998 bufferMemoryBarrierCount, pBufferMemoryBarriers,
1999 imageMemoryBarrierCount, pImageMemoryBarriers);
Alexis Hetud73b8712018-09-21 15:14:43 -04002000}
2001
2002VKAPI_ATTR void VKAPI_CALL vkCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t query, VkQueryControlFlags flags)
2003{
Ben Claytonfb280672019-04-25 11:16:15 +01002004 TRACE("(VkCommandBuffer commandBuffer = %p, VkQueryPool queryPool = %p, uint32_t query = %d, VkQueryControlFlags flags = %d)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04002005 commandBuffer, static_cast<void*>(queryPool), query, int(flags));
Alexis Hetua9999ce2018-10-17 08:00:43 -04002006
Alexis Hetu7d96f512019-06-13 18:23:56 -04002007 vk::Cast(commandBuffer)->beginQuery(vk::Cast(queryPool), query, flags);
Alexis Hetud73b8712018-09-21 15:14:43 -04002008}
2009
2010VKAPI_ATTR void VKAPI_CALL vkCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t query)
2011{
Ben Claytonfb280672019-04-25 11:16:15 +01002012 TRACE("(VkCommandBuffer commandBuffer = %p, VkQueryPool queryPool = %p, uint32_t query = %d)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04002013 commandBuffer, static_cast<void*>(queryPool), int(query));
Alexis Hetua9999ce2018-10-17 08:00:43 -04002014
Alexis Hetu7d96f512019-06-13 18:23:56 -04002015 vk::Cast(commandBuffer)->endQuery(vk::Cast(queryPool), query);
Alexis Hetud73b8712018-09-21 15:14:43 -04002016}
2017
2018VKAPI_ATTR void VKAPI_CALL vkCmdResetQueryPool(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount)
2019{
Ben Claytonfb280672019-04-25 11:16:15 +01002020 TRACE("(VkCommandBuffer commandBuffer = %p, VkQueryPool queryPool = %p, uint32_t firstQuery = %d, uint32_t queryCount = %d)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04002021 commandBuffer, static_cast<void*>(queryPool), int(firstQuery), int(queryCount));
Alexis Hetua9999ce2018-10-17 08:00:43 -04002022
Alexis Hetu7d96f512019-06-13 18:23:56 -04002023 vk::Cast(commandBuffer)->resetQueryPool(vk::Cast(queryPool), firstQuery, queryCount);
Alexis Hetud73b8712018-09-21 15:14:43 -04002024}
2025
2026VKAPI_ATTR void VKAPI_CALL vkCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, VkQueryPool queryPool, uint32_t query)
2027{
Ben Claytonfb280672019-04-25 11:16:15 +01002028 TRACE("(VkCommandBuffer commandBuffer = %p, VkPipelineStageFlagBits pipelineStage = %d, VkQueryPool queryPool = %p, uint32_t query = %d)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04002029 commandBuffer, int(pipelineStage), static_cast<void*>(queryPool), int(query));
Alexis Hetua9999ce2018-10-17 08:00:43 -04002030
Alexis Hetu7d96f512019-06-13 18:23:56 -04002031 vk::Cast(commandBuffer)->writeTimestamp(pipelineStage, vk::Cast(queryPool), query);
Alexis Hetud73b8712018-09-21 15:14:43 -04002032}
2033
2034VKAPI_ATTR void VKAPI_CALL vkCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize stride, VkQueryResultFlags flags)
2035{
Ben Claytonfb280672019-04-25 11:16:15 +01002036 TRACE("(VkCommandBuffer commandBuffer = %p, VkQueryPool queryPool = %p, uint32_t firstQuery = %d, uint32_t queryCount = %d, VkBuffer dstBuffer = %p, VkDeviceSize dstOffset = %d, VkDeviceSize stride = %d, VkQueryResultFlags flags = %d)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04002037 commandBuffer, static_cast<void*>(queryPool), int(firstQuery), int(queryCount), static_cast<void*>(dstBuffer), int(dstOffset), int(stride), int(flags));
Alexis Hetua9999ce2018-10-17 08:00:43 -04002038
Alexis Hetu7d96f512019-06-13 18:23:56 -04002039 vk::Cast(commandBuffer)->copyQueryPoolResults(vk::Cast(queryPool), firstQuery, queryCount, vk::Cast(dstBuffer), dstOffset, stride, flags);
Alexis Hetud73b8712018-09-21 15:14:43 -04002040}
2041
2042VKAPI_ATTR void VKAPI_CALL vkCmdPushConstants(VkCommandBuffer commandBuffer, VkPipelineLayout layout, VkShaderStageFlags stageFlags, uint32_t offset, uint32_t size, const void* pValues)
2043{
Ben Claytonfb280672019-04-25 11:16:15 +01002044 TRACE("(VkCommandBuffer commandBuffer = %p, VkPipelineLayout layout = %p, VkShaderStageFlags stageFlags = %d, uint32_t offset = %d, uint32_t size = %d, const void* pValues = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04002045 commandBuffer, static_cast<void*>(layout), stageFlags, offset, size, pValues);
Alexis Hetua9999ce2018-10-17 08:00:43 -04002046
Alexis Hetu7d96f512019-06-13 18:23:56 -04002047 vk::Cast(commandBuffer)->pushConstants(vk::Cast(layout), stageFlags, offset, size, pValues);
Alexis Hetud73b8712018-09-21 15:14:43 -04002048}
2049
2050VKAPI_ATTR void VKAPI_CALL vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, VkSubpassContents contents)
2051{
Ben Claytonfb280672019-04-25 11:16:15 +01002052 TRACE("(VkCommandBuffer commandBuffer = %p, const VkRenderPassBeginInfo* pRenderPassBegin = %p, VkSubpassContents contents = %d)",
Alexis Hetu38ff8302018-10-18 15:08:13 -04002053 commandBuffer, pRenderPassBegin, contents);
Alexis Hetud73b8712018-09-21 15:14:43 -04002054
Alexis Hetu026ceef2019-05-07 17:35:11 -04002055 const VkBaseInStructure* renderPassBeginInfo = reinterpret_cast<const VkBaseInStructure*>(pRenderPassBegin->pNext);
2056 while(renderPassBeginInfo)
Alexis Hetua9999ce2018-10-17 08:00:43 -04002057 {
Alexis Hetu026ceef2019-05-07 17:35:11 -04002058 switch(renderPassBeginInfo->sType)
2059 {
2060 case VK_STRUCTURE_TYPE_DEVICE_GROUP_RENDER_PASS_BEGIN_INFO:
Chris Forbes3e511442019-05-09 08:38:59 -07002061 // This extension controls which render area is used on which physical device,
2062 // in order to distribute rendering between multiple physical devices.
Alexis Hetu026ceef2019-05-07 17:35:11 -04002063 // SwiftShader only has a single physical device, so this extension does nothing in this case.
2064 break;
2065 default:
2066 UNIMPLEMENTED("renderPassBeginInfo->sType");
2067 break;
2068 }
2069
2070 renderPassBeginInfo = renderPassBeginInfo->pNext;
Alexis Hetua9999ce2018-10-17 08:00:43 -04002071 }
2072
Alexis Hetu7d96f512019-06-13 18:23:56 -04002073 vk::Cast(commandBuffer)->beginRenderPass(vk::Cast(pRenderPassBegin->renderPass), vk::Cast(pRenderPassBegin->framebuffer),
Alexis Hetua9999ce2018-10-17 08:00:43 -04002074 pRenderPassBegin->renderArea, pRenderPassBegin->clearValueCount,
2075 pRenderPassBegin->pClearValues, contents);
Alexis Hetud73b8712018-09-21 15:14:43 -04002076}
2077
2078VKAPI_ATTR void VKAPI_CALL vkCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents)
2079{
Ben Claytonfb280672019-04-25 11:16:15 +01002080 TRACE("(VkCommandBuffer commandBuffer = %p, VkSubpassContents contents = %d)",
Alexis Hetua9999ce2018-10-17 08:00:43 -04002081 commandBuffer, contents);
2082
2083 vk::Cast(commandBuffer)->nextSubpass(contents);
Alexis Hetud73b8712018-09-21 15:14:43 -04002084}
2085
2086VKAPI_ATTR void VKAPI_CALL vkCmdEndRenderPass(VkCommandBuffer commandBuffer)
2087{
Ben Claytonfb280672019-04-25 11:16:15 +01002088 TRACE("(VkCommandBuffer commandBuffer = %p)", commandBuffer);
Alexis Hetud73b8712018-09-21 15:14:43 -04002089
Alexis Hetua9999ce2018-10-17 08:00:43 -04002090 vk::Cast(commandBuffer)->endRenderPass();
Alexis Hetud73b8712018-09-21 15:14:43 -04002091}
2092
2093VKAPI_ATTR void VKAPI_CALL vkCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBufferCount, const VkCommandBuffer* pCommandBuffers)
2094{
Ben Claytonfb280672019-04-25 11:16:15 +01002095 TRACE("(VkCommandBuffer commandBuffer = %p, uint32_t commandBufferCount = %d, const VkCommandBuffer* pCommandBuffers = %p)",
Alexis Hetua9999ce2018-10-17 08:00:43 -04002096 commandBuffer, commandBufferCount, pCommandBuffers);
2097
2098 vk::Cast(commandBuffer)->executeCommands(commandBufferCount, pCommandBuffers);
Alexis Hetud73b8712018-09-21 15:14:43 -04002099}
2100
2101VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceVersion(uint32_t* pApiVersion)
2102{
Ben Claytonfb280672019-04-25 11:16:15 +01002103 TRACE("(uint32_t* pApiVersion = %p)", pApiVersion);
Nicolas Capensee841c52018-11-13 14:18:26 -05002104 *pApiVersion = vk::API_VERSION;
Alexis Hetud73b8712018-09-21 15:14:43 -04002105 return VK_SUCCESS;
2106}
2107
2108VKAPI_ATTR VkResult VKAPI_CALL vkBindBufferMemory2(VkDevice device, uint32_t bindInfoCount, const VkBindBufferMemoryInfo* pBindInfos)
2109{
Ben Claytonfb280672019-04-25 11:16:15 +01002110 TRACE("(VkDevice device = %p, uint32_t bindInfoCount = %d, const VkBindBufferMemoryInfo* pBindInfos = %p)",
Alexis Hetu38ff8302018-10-18 15:08:13 -04002111 device, bindInfoCount, pBindInfos);
2112
2113 for(uint32_t i = 0; i < bindInfoCount; i++)
2114 {
2115 if(pBindInfos[i].pNext)
2116 {
Ben Clayton00424c12019-03-17 17:29:30 +00002117 UNIMPLEMENTED("pBindInfos[%d].pNext", i);
Alexis Hetu38ff8302018-10-18 15:08:13 -04002118 }
2119
Alexis Hetu7d96f512019-06-13 18:23:56 -04002120 vk::Cast(pBindInfos[i].buffer)->bind(vk::Cast(pBindInfos[i].memory), pBindInfos[i].memoryOffset);
Alexis Hetu38ff8302018-10-18 15:08:13 -04002121 }
2122
Alexis Hetud73b8712018-09-21 15:14:43 -04002123 return VK_SUCCESS;
2124}
2125
2126VKAPI_ATTR VkResult VKAPI_CALL vkBindImageMemory2(VkDevice device, uint32_t bindInfoCount, const VkBindImageMemoryInfo* pBindInfos)
2127{
Alexis Hetuf18f0c12019-05-07 14:34:15 -04002128 TRACE("(VkDevice device = %p, uint32_t bindInfoCount = %d, const VkBindImageMemoryInfo* pBindInfos = %p)",
2129 device, bindInfoCount, pBindInfos);
Nicolas Capens71c012b2019-05-22 13:31:52 -04002130
Alexis Hetuf18f0c12019-05-07 14:34:15 -04002131 for(uint32_t i = 0; i < bindInfoCount; i++)
2132 {
2133 if(pBindInfos[i].pNext)
2134 {
2135 UNIMPLEMENTED("pBindInfos[%d].pNext", i);
2136 }
2137
Alexis Hetu7d96f512019-06-13 18:23:56 -04002138 vk::Cast(pBindInfos[i].image)->bind(vk::Cast(pBindInfos[i].memory), pBindInfos[i].memoryOffset);
Alexis Hetuf18f0c12019-05-07 14:34:15 -04002139 }
2140
Alexis Hetud73b8712018-09-21 15:14:43 -04002141 return VK_SUCCESS;
2142}
2143
2144VKAPI_ATTR void VKAPI_CALL vkGetDeviceGroupPeerMemoryFeatures(VkDevice device, uint32_t heapIndex, uint32_t localDeviceIndex, uint32_t remoteDeviceIndex, VkPeerMemoryFeatureFlags* pPeerMemoryFeatures)
2145{
Ben Claytonfb280672019-04-25 11:16:15 +01002146 TRACE("(VkDevice device = %p, uint32_t heapIndex = %d, uint32_t localDeviceIndex = %d, uint32_t remoteDeviceIndex = %d, VkPeerMemoryFeatureFlags* pPeerMemoryFeatures = %p)",
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002147 device, heapIndex, localDeviceIndex, remoteDeviceIndex, pPeerMemoryFeatures);
2148
Nicolas Capens5028a582018-11-13 15:03:35 -05002149 ASSERT(localDeviceIndex != remoteDeviceIndex); // "localDeviceIndex must not equal remoteDeviceIndex"
Ben Clayton00424c12019-03-17 17:29:30 +00002150 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.
Alexis Hetud73b8712018-09-21 15:14:43 -04002151}
2152
2153VKAPI_ATTR void VKAPI_CALL vkCmdSetDeviceMask(VkCommandBuffer commandBuffer, uint32_t deviceMask)
2154{
Alexis Hetu026ceef2019-05-07 17:35:11 -04002155 TRACE("(VkCommandBuffer commandBuffer = %p, uint32_t deviceMask = %d", commandBuffer, deviceMask);
2156
2157 vk::Cast(commandBuffer)->setDeviceMask(deviceMask);
Alexis Hetud73b8712018-09-21 15:14:43 -04002158}
2159
2160VKAPI_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)
2161{
Chris Forbes4a4c2592019-05-13 08:53:36 -07002162 TRACE("(VkCommandBuffer commandBuffer = %p, baseGroupX = %u, baseGroupY = %u, baseGroupZ = %u, groupCountX = %u, groupCountY = %u, groupCountZ = %u)",
2163 commandBuffer, baseGroupX, baseGroupY, baseGroupZ, groupCountX, groupCountY, groupCountZ);
2164
2165 vk::Cast(commandBuffer)->dispatchBase(baseGroupX, baseGroupY, baseGroupZ, groupCountX, groupCountY, groupCountZ);
Alexis Hetud73b8712018-09-21 15:14:43 -04002166}
2167
2168VKAPI_ATTR VkResult VKAPI_CALL vkEnumeratePhysicalDeviceGroups(VkInstance instance, uint32_t* pPhysicalDeviceGroupCount, VkPhysicalDeviceGroupProperties* pPhysicalDeviceGroupProperties)
2169{
Ben Claytonfb280672019-04-25 11:16:15 +01002170 TRACE("VkInstance instance = %p, uint32_t* pPhysicalDeviceGroupCount = %p, VkPhysicalDeviceGroupProperties* pPhysicalDeviceGroupProperties = %p",
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002171 instance, pPhysicalDeviceGroupCount, pPhysicalDeviceGroupProperties);
2172
Chris Forbesdf84b942019-06-12 11:28:09 -07002173 return vk::Cast(instance)->getPhysicalDeviceGroups(pPhysicalDeviceGroupCount, pPhysicalDeviceGroupProperties);
Alexis Hetud73b8712018-09-21 15:14:43 -04002174}
2175
2176VKAPI_ATTR void VKAPI_CALL vkGetImageMemoryRequirements2(VkDevice device, const VkImageMemoryRequirementsInfo2* pInfo, VkMemoryRequirements2* pMemoryRequirements)
2177{
Ben Claytonfb280672019-04-25 11:16:15 +01002178 TRACE("(VkDevice device = %p, const VkImageMemoryRequirementsInfo2* pInfo = %p, VkMemoryRequirements2* pMemoryRequirements = %p)",
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002179 device, pInfo, pMemoryRequirements);
2180
Alexis Hetu42761d22019-04-08 11:25:59 -04002181 if(pInfo->pNext)
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002182 {
Alexis Hetu42761d22019-04-08 11:25:59 -04002183 UNIMPLEMENTED("pInfo->pNext");
2184 }
2185
2186 VkBaseOutStructure* extensionRequirements = reinterpret_cast<VkBaseOutStructure*>(pMemoryRequirements->pNext);
2187 while(extensionRequirements)
2188 {
2189 switch(extensionRequirements->sType)
2190 {
2191 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS:
2192 {
2193 auto& requirements = *reinterpret_cast<VkMemoryDedicatedRequirements*>(extensionRequirements);
2194 requirements.prefersDedicatedAllocation = VK_FALSE;
2195 requirements.requiresDedicatedAllocation = VK_FALSE;
2196 }
2197 break;
2198 default:
2199 UNIMPLEMENTED("extensionRequirements->sType");
2200 break;
2201 }
2202
2203 extensionRequirements = extensionRequirements->pNext;
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002204 }
2205
2206 vkGetImageMemoryRequirements(device, pInfo->image, &(pMemoryRequirements->memoryRequirements));
Alexis Hetud73b8712018-09-21 15:14:43 -04002207}
2208
2209VKAPI_ATTR void VKAPI_CALL vkGetBufferMemoryRequirements2(VkDevice device, const VkBufferMemoryRequirementsInfo2* pInfo, VkMemoryRequirements2* pMemoryRequirements)
2210{
Ben Claytonfb280672019-04-25 11:16:15 +01002211 TRACE("(VkDevice device = %p, const VkBufferMemoryRequirementsInfo2* pInfo = %p, VkMemoryRequirements2* pMemoryRequirements = %p)",
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002212 device, pInfo, pMemoryRequirements);
2213
Alexis Hetu1e6a9892019-03-15 12:12:00 -04002214 if(pInfo->pNext)
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002215 {
Ben Clayton00424c12019-03-17 17:29:30 +00002216 UNIMPLEMENTED("pInfo->pNext");
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002217 }
2218
Alexis Hetu1e6a9892019-03-15 12:12:00 -04002219 VkBaseOutStructure* extensionRequirements = reinterpret_cast<VkBaseOutStructure*>(pMemoryRequirements->pNext);
2220 while(extensionRequirements)
2221 {
2222 switch(extensionRequirements->sType)
2223 {
2224 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS:
2225 {
2226 auto& requirements = *reinterpret_cast<VkMemoryDedicatedRequirements*>(extensionRequirements);
2227 requirements.prefersDedicatedAllocation = VK_FALSE;
2228 requirements.requiresDedicatedAllocation = VK_FALSE;
2229 }
2230 break;
2231 default:
Ben Clayton00424c12019-03-17 17:29:30 +00002232 UNIMPLEMENTED("extensionRequirements->sType");
Alexis Hetu1e6a9892019-03-15 12:12:00 -04002233 break;
2234 }
2235
2236 extensionRequirements = extensionRequirements->pNext;
2237 }
2238
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002239 vkGetBufferMemoryRequirements(device, pInfo->buffer, &(pMemoryRequirements->memoryRequirements));
Alexis Hetud73b8712018-09-21 15:14:43 -04002240}
2241
2242VKAPI_ATTR void VKAPI_CALL vkGetImageSparseMemoryRequirements2(VkDevice device, const VkImageSparseMemoryRequirementsInfo2* pInfo, uint32_t* pSparseMemoryRequirementCount, VkSparseImageMemoryRequirements2* pSparseMemoryRequirements)
2243{
Ben Claytonfb280672019-04-25 11:16:15 +01002244 TRACE("(VkDevice device = %p, const VkImageSparseMemoryRequirementsInfo2* pInfo = %p, uint32_t* pSparseMemoryRequirementCount = %p, VkSparseImageMemoryRequirements2* pSparseMemoryRequirements = %p)",
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002245 device, pInfo, pSparseMemoryRequirementCount, pSparseMemoryRequirements);
2246
2247 if(pInfo->pNext || pSparseMemoryRequirements->pNext)
2248 {
Ben Clayton00424c12019-03-17 17:29:30 +00002249 UNIMPLEMENTED("pInfo->pNext || pSparseMemoryRequirements->pNext");
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002250 }
2251
2252 vkGetImageSparseMemoryRequirements(device, pInfo->image, pSparseMemoryRequirementCount, &(pSparseMemoryRequirements->memoryRequirements));
Alexis Hetud73b8712018-09-21 15:14:43 -04002253}
2254
2255VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceFeatures2(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures2* pFeatures)
2256{
Ben Claytonfb280672019-04-25 11:16:15 +01002257 TRACE("(VkPhysicalDevice physicalDevice = %p, VkPhysicalDeviceFeatures2* pFeatures = %p)", physicalDevice, pFeatures);
Alexis Hetud73b8712018-09-21 15:14:43 -04002258
Nicolas Capensae8d4642018-11-13 15:17:16 -05002259 VkBaseOutStructure* extensionFeatures = reinterpret_cast<VkBaseOutStructure*>(pFeatures->pNext);
2260 while(extensionFeatures)
Alexis Hetu767b41b2018-09-26 11:25:46 -04002261 {
Nicolas Capensae8d4642018-11-13 15:17:16 -05002262 switch(extensionFeatures->sType)
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002263 {
2264 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES:
2265 {
Nicolas Capensae8d4642018-11-13 15:17:16 -05002266 auto& features = *reinterpret_cast<VkPhysicalDeviceSamplerYcbcrConversionFeatures*>(extensionFeatures);
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002267 vk::Cast(physicalDevice)->getFeatures(&features);
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002268 }
2269 break;
2270 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES:
2271 {
Nicolas Capensae8d4642018-11-13 15:17:16 -05002272 auto& features = *reinterpret_cast<VkPhysicalDevice16BitStorageFeatures*>(extensionFeatures);
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002273 vk::Cast(physicalDevice)->getFeatures(&features);
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002274 }
2275 break;
2276 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES:
2277 {
Nicolas Capensae8d4642018-11-13 15:17:16 -05002278 auto& features = *reinterpret_cast<VkPhysicalDeviceVariablePointerFeatures*>(extensionFeatures);
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002279 vk::Cast(physicalDevice)->getFeatures(&features);
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002280 }
2281 break;
2282 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES_KHR:
2283 {
Nicolas Capensae8d4642018-11-13 15:17:16 -05002284 auto& features = *reinterpret_cast<VkPhysicalDevice8BitStorageFeaturesKHR*>(extensionFeatures);
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002285 vk::Cast(physicalDevice)->getFeatures(&features);
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002286 }
2287 break;
2288 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES:
2289 {
Nicolas Capensae8d4642018-11-13 15:17:16 -05002290 auto& features = *reinterpret_cast<VkPhysicalDeviceMultiviewFeatures*>(extensionFeatures);
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002291 vk::Cast(physicalDevice)->getFeatures(&features);
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002292 }
2293 break;
2294 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES:
2295 {
Nicolas Capensae8d4642018-11-13 15:17:16 -05002296 auto& features = *reinterpret_cast<VkPhysicalDeviceProtectedMemoryFeatures*>(extensionFeatures);
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002297 vk::Cast(physicalDevice)->getFeatures(&features);
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002298 }
2299 break;
Chris Forbes6408c552019-04-15 12:59:34 -07002300 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETER_FEATURES:
2301 {
2302 auto& features = *reinterpret_cast<VkPhysicalDeviceShaderDrawParameterFeatures*>(extensionFeatures);
2303 vk::Cast(physicalDevice)->getFeatures(&features);
2304 }
2305 break;
Chris Forbesc0c6ccf2019-05-17 17:38:19 -07002306 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONDITIONAL_RENDERING_FEATURES_EXT:
2307 ASSERT(!HasExtensionProperty(VK_EXT_CONDITIONAL_RENDERING_EXTENSION_NAME, deviceExtensionProperties,
2308 sizeof(deviceExtensionProperties) / sizeof(deviceExtensionProperties[0])));
2309 break;
2310 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES_EXT:
2311 ASSERT(!HasExtensionProperty(VK_EXT_SCALAR_BLOCK_LAYOUT_EXTENSION_NAME, deviceExtensionProperties,
2312 sizeof(deviceExtensionProperties) / sizeof(deviceExtensionProperties[0])));
2313 break;
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002314 default:
Nicolas Capensae8d4642018-11-13 15:17:16 -05002315 // "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]"
Ben Clayton00424c12019-03-17 17:29:30 +00002316 UNIMPLEMENTED("extensionFeatures->sType"); // TODO(b/119321052): UNIMPLEMENTED() should be used only for features that must still be implemented. Use a more informational macro here.
Nicolas Capensae8d4642018-11-13 15:17:16 -05002317 break;
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002318 }
Nicolas Capensae8d4642018-11-13 15:17:16 -05002319
2320 extensionFeatures = extensionFeatures->pNext;
Alexis Hetu767b41b2018-09-26 11:25:46 -04002321 }
2322
2323 vkGetPhysicalDeviceFeatures(physicalDevice, &(pFeatures->features));
Alexis Hetud73b8712018-09-21 15:14:43 -04002324}
2325
2326VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties2* pProperties)
2327{
Ben Claytonfb280672019-04-25 11:16:15 +01002328 TRACE("(VkPhysicalDevice physicalDevice = %p, VkPhysicalDeviceProperties2* pProperties = %p)", physicalDevice, pProperties);
Alexis Hetud73b8712018-09-21 15:14:43 -04002329
Nicolas Capensae8d4642018-11-13 15:17:16 -05002330 VkBaseOutStructure* extensionProperties = reinterpret_cast<VkBaseOutStructure*>(pProperties->pNext);
2331 while(extensionProperties)
Alexis Hetu767b41b2018-09-26 11:25:46 -04002332 {
Hernan Liatis83a3eb42019-04-29 17:16:10 -07002333 // Casting to a long since some structures, such as VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENTATION_PROPERTIES_ANDROID
2334 // are not enumerated in the official Vulkan header
2335 switch((long)(extensionProperties->sType))
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002336 {
2337 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES:
2338 {
Nicolas Capensae8d4642018-11-13 15:17:16 -05002339 auto& properties = *reinterpret_cast<VkPhysicalDeviceIDProperties*>(extensionProperties);
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002340 vk::Cast(physicalDevice)->getProperties(&properties);
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002341 }
2342 break;
2343 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES:
2344 {
Nicolas Capensae8d4642018-11-13 15:17:16 -05002345 auto& properties = *reinterpret_cast<VkPhysicalDeviceMaintenance3Properties*>(extensionProperties);
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002346 vk::Cast(physicalDevice)->getProperties(&properties);
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002347 }
2348 break;
2349 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES:
2350 {
Nicolas Capensae8d4642018-11-13 15:17:16 -05002351 auto& properties = *reinterpret_cast<VkPhysicalDeviceMultiviewProperties*>(extensionProperties);
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002352 vk::Cast(physicalDevice)->getProperties(&properties);
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002353 }
2354 break;
2355 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES:
2356 {
Nicolas Capensae8d4642018-11-13 15:17:16 -05002357 auto& properties = *reinterpret_cast<VkPhysicalDevicePointClippingProperties*>(extensionProperties);
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002358 vk::Cast(physicalDevice)->getProperties(&properties);
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002359 }
2360 break;
2361 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_PROPERTIES:
2362 {
Nicolas Capensae8d4642018-11-13 15:17:16 -05002363 auto& properties = *reinterpret_cast<VkPhysicalDeviceProtectedMemoryProperties*>(extensionProperties);
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002364 vk::Cast(physicalDevice)->getProperties(&properties);
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002365 }
2366 break;
2367 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES:
2368 {
Nicolas Capensae8d4642018-11-13 15:17:16 -05002369 auto& properties = *reinterpret_cast<VkPhysicalDeviceSubgroupProperties*>(extensionProperties);
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002370 vk::Cast(physicalDevice)->getProperties(&properties);
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002371 }
2372 break;
Alexis Hetud6fae382019-04-05 13:19:46 -04002373 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLE_LOCATIONS_PROPERTIES_EXT:
2374 // Explicitly ignored, since VK_EXT_sample_locations is not supported
2375 ASSERT(!HasExtensionProperty(VK_EXT_SAMPLE_LOCATIONS_EXTENSION_NAME, deviceExtensionProperties,
2376 sizeof(deviceExtensionProperties) / sizeof(deviceExtensionProperties[0])));
2377 break;
Alexis Hetud5ed0a32019-05-07 16:07:34 -04002378 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT:
2379 ASSERT(!HasExtensionProperty(VK_EXT_EXTERNAL_MEMORY_HOST_EXTENSION_NAME, deviceExtensionProperties,
2380 sizeof(deviceExtensionProperties) / sizeof(deviceExtensionProperties[0])));
2381 break;
Hernan Liatis83a3eb42019-04-29 17:16:10 -07002382#ifdef __ANDROID__
2383 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENTATION_PROPERTIES_ANDROID:
2384 {
2385 auto& properties = *reinterpret_cast<VkPhysicalDevicePresentationPropertiesANDROID*>(extensionProperties);
2386 vk::Cast(physicalDevice)->getProperties(&properties);
2387 }
2388 break;
2389#endif
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002390 default:
Nicolas Capensae8d4642018-11-13 15:17:16 -05002391 // "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]"
Ben Clayton00424c12019-03-17 17:29:30 +00002392 UNIMPLEMENTED("extensionProperties->sType"); // TODO(b/119321052): UNIMPLEMENTED() should be used only for features that must still be implemented. Use a more informational macro here.
Nicolas Capensae8d4642018-11-13 15:17:16 -05002393 break;
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002394 }
Nicolas Capensae8d4642018-11-13 15:17:16 -05002395
2396 extensionProperties = extensionProperties->pNext;
Alexis Hetu767b41b2018-09-26 11:25:46 -04002397 }
2398
2399 vkGetPhysicalDeviceProperties(physicalDevice, &(pProperties->properties));
Alexis Hetud73b8712018-09-21 15:14:43 -04002400}
2401
2402VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceFormatProperties2(VkPhysicalDevice physicalDevice, VkFormat format, VkFormatProperties2* pFormatProperties)
2403{
Ben Claytonfb280672019-04-25 11:16:15 +01002404 TRACE("(VkPhysicalDevice physicalDevice = %p, VkFormat format = %d, VkFormatProperties2* pFormatProperties = %p)",
Alexis Hetud73b8712018-09-21 15:14:43 -04002405 physicalDevice, format, pFormatProperties);
2406
Alexis Hetu767b41b2018-09-26 11:25:46 -04002407 if(pFormatProperties->pNext)
2408 {
Ben Clayton00424c12019-03-17 17:29:30 +00002409 UNIMPLEMENTED("pFormatProperties->pNext");
Alexis Hetu767b41b2018-09-26 11:25:46 -04002410 }
2411
2412 vkGetPhysicalDeviceFormatProperties(physicalDevice, format, &(pFormatProperties->formatProperties));
Alexis Hetud73b8712018-09-21 15:14:43 -04002413}
2414
2415VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceImageFormatProperties2(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceImageFormatInfo2* pImageFormatInfo, VkImageFormatProperties2* pImageFormatProperties)
2416{
Ben Claytonfb280672019-04-25 11:16:15 +01002417 TRACE("(VkPhysicalDevice physicalDevice = %p, const VkPhysicalDeviceImageFormatInfo2* pImageFormatInfo = %p, VkImageFormatProperties2* pImageFormatProperties = %p)",
Alexis Hetud73b8712018-09-21 15:14:43 -04002418 physicalDevice, pImageFormatInfo, pImageFormatProperties);
2419
Alexis Hetu00835732019-04-10 16:36:31 -04002420 const VkBaseInStructure* extensionFormatInfo = reinterpret_cast<const VkBaseInStructure*>(pImageFormatInfo->pNext);
2421
2422 const VkExternalMemoryHandleTypeFlagBits* handleType = nullptr;
2423 while(extensionFormatInfo)
Alexis Hetu767b41b2018-09-26 11:25:46 -04002424 {
Alexis Hetu00835732019-04-10 16:36:31 -04002425 switch(extensionFormatInfo->sType)
2426 {
2427 case VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO_KHR:
2428 {
2429 // Explicitly ignored, since VK_KHR_image_format_list is not supported
2430 ASSERT(!HasExtensionProperty(VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME, deviceExtensionProperties,
2431 sizeof(deviceExtensionProperties) / sizeof(deviceExtensionProperties[0])));
2432 }
2433 break;
2434 case VK_STRUCTURE_TYPE_IMAGE_STENCIL_USAGE_CREATE_INFO_EXT:
2435 {
2436 // Explicitly ignored, since VK_EXT_separate_stencil_usage is not supported
2437 ASSERT(!HasExtensionProperty(VK_EXT_SEPARATE_STENCIL_USAGE_EXTENSION_NAME, deviceExtensionProperties,
2438 sizeof(deviceExtensionProperties) / sizeof(deviceExtensionProperties[0])));
2439 }
2440 break;
2441 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO:
2442 {
2443 const VkPhysicalDeviceExternalImageFormatInfo* imageFormatInfo = reinterpret_cast<const VkPhysicalDeviceExternalImageFormatInfo*>(extensionFormatInfo);
2444 handleType = &(imageFormatInfo->handleType);
2445 }
2446 break;
2447 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_DRM_FORMAT_MODIFIER_INFO_EXT:
2448 {
2449 // Explicitly ignored, since VK_EXT_image_drm_format_modifier is not supported
2450 ASSERT(!HasExtensionProperty(VK_EXT_IMAGE_DRM_FORMAT_MODIFIER_EXTENSION_NAME, deviceExtensionProperties,
2451 sizeof(deviceExtensionProperties) / sizeof(deviceExtensionProperties[0])));
2452 }
2453 break;
2454 default:
2455 UNIMPLEMENTED("extensionFormatInfo->sType");
2456 break;
2457 }
2458
2459 extensionFormatInfo = extensionFormatInfo->pNext;
2460 }
2461
2462 VkBaseOutStructure* extensionProperties = reinterpret_cast<VkBaseOutStructure*>(pImageFormatProperties->pNext);
2463
2464 while(extensionProperties)
2465 {
2466 switch(extensionProperties->sType)
2467 {
2468 case VK_STRUCTURE_TYPE_EXTERNAL_IMAGE_FORMAT_PROPERTIES:
2469 {
2470 auto& properties = *reinterpret_cast<VkExternalImageFormatProperties*>(extensionProperties);
2471 vk::Cast(physicalDevice)->getProperties(handleType, &properties);
2472 }
2473 break;
2474 case VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_IMAGE_FORMAT_PROPERTIES:
2475 {
2476 auto& properties = *reinterpret_cast<VkSamplerYcbcrConversionImageFormatProperties*>(extensionProperties);
2477 vk::Cast(physicalDevice)->getProperties(&properties);
2478 }
2479 break;
2480 case VK_STRUCTURE_TYPE_TEXTURE_LOD_GATHER_FORMAT_PROPERTIES_AMD:
2481 {
2482 // Explicitly ignored, since VK_AMD_texture_gather_bias_lod is not supported
2483 ASSERT(!HasExtensionProperty(VK_AMD_TEXTURE_GATHER_BIAS_LOD_EXTENSION_NAME, deviceExtensionProperties,
2484 sizeof(deviceExtensionProperties) / sizeof(deviceExtensionProperties[0])));
2485 }
2486 break;
2487 default:
2488 UNIMPLEMENTED("extensionProperties->sType");
2489 break;
2490 }
2491
2492 extensionProperties = extensionProperties->pNext;
Alexis Hetu767b41b2018-09-26 11:25:46 -04002493 }
Alexis Hetud73b8712018-09-21 15:14:43 -04002494
Alexis Hetu767b41b2018-09-26 11:25:46 -04002495 return vkGetPhysicalDeviceImageFormatProperties(physicalDevice,
2496 pImageFormatInfo->format,
2497 pImageFormatInfo->type,
2498 pImageFormatInfo->tiling,
2499 pImageFormatInfo->usage,
2500 pImageFormatInfo->flags,
2501 &(pImageFormatProperties->imageFormatProperties));
Alexis Hetud73b8712018-09-21 15:14:43 -04002502}
2503
2504VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceQueueFamilyProperties2(VkPhysicalDevice physicalDevice, uint32_t* pQueueFamilyPropertyCount, VkQueueFamilyProperties2* pQueueFamilyProperties)
2505{
Ben Claytonfb280672019-04-25 11:16:15 +01002506 TRACE("(VkPhysicalDevice physicalDevice = %p, uint32_t* pQueueFamilyPropertyCount = %p, VkQueueFamilyProperties2* pQueueFamilyProperties = %p)",
Alexis Hetud73b8712018-09-21 15:14:43 -04002507 physicalDevice, pQueueFamilyPropertyCount, pQueueFamilyProperties);
2508
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002509 if(pQueueFamilyProperties && pQueueFamilyProperties->pNext)
Alexis Hetu767b41b2018-09-26 11:25:46 -04002510 {
Ben Clayton00424c12019-03-17 17:29:30 +00002511 UNIMPLEMENTED("pQueueFamilyProperties->pNext");
Alexis Hetu767b41b2018-09-26 11:25:46 -04002512 }
Alexis Hetu767b41b2018-09-26 11:25:46 -04002513
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002514 vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, pQueueFamilyPropertyCount,
2515 pQueueFamilyProperties ? &(pQueueFamilyProperties->queueFamilyProperties) : nullptr);
Alexis Hetud73b8712018-09-21 15:14:43 -04002516}
2517
2518VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceMemoryProperties2(VkPhysicalDevice physicalDevice, VkPhysicalDeviceMemoryProperties2* pMemoryProperties)
2519{
Ben Claytonfb280672019-04-25 11:16:15 +01002520 TRACE("(VkPhysicalDevice physicalDevice = %p, VkPhysicalDeviceMemoryProperties2* pMemoryProperties = %p)", physicalDevice, pMemoryProperties);
Alexis Hetud73b8712018-09-21 15:14:43 -04002521
Alexis Hetu767b41b2018-09-26 11:25:46 -04002522 if(pMemoryProperties->pNext)
2523 {
Ben Clayton00424c12019-03-17 17:29:30 +00002524 UNIMPLEMENTED("pMemoryProperties->pNext");
Alexis Hetu767b41b2018-09-26 11:25:46 -04002525 }
2526
2527 vkGetPhysicalDeviceMemoryProperties(physicalDevice, &(pMemoryProperties->memoryProperties));
Alexis Hetud73b8712018-09-21 15:14:43 -04002528}
2529
2530VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceSparseImageFormatProperties2(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSparseImageFormatInfo2* pFormatInfo, uint32_t* pPropertyCount, VkSparseImageFormatProperties2* pProperties)
2531{
Ben Claytonfb280672019-04-25 11:16:15 +01002532 TRACE("(VkPhysicalDevice physicalDevice = %p, const VkPhysicalDeviceSparseImageFormatInfo2* pFormatInfo = %p, uint32_t* pPropertyCount = %p, VkSparseImageFormatProperties2* pProperties = %p)",
Alexis Hetu767b41b2018-09-26 11:25:46 -04002533 physicalDevice, pFormatInfo, pPropertyCount, pProperties);
2534
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002535 if(pProperties && pProperties->pNext)
Alexis Hetu767b41b2018-09-26 11:25:46 -04002536 {
Ben Clayton00424c12019-03-17 17:29:30 +00002537 UNIMPLEMENTED("pProperties->pNext");
Alexis Hetu767b41b2018-09-26 11:25:46 -04002538 }
Alexis Hetu767b41b2018-09-26 11:25:46 -04002539
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002540 vkGetPhysicalDeviceSparseImageFormatProperties(physicalDevice, pFormatInfo->format, pFormatInfo->type,
2541 pFormatInfo->samples, pFormatInfo->usage, pFormatInfo->tiling,
2542 pPropertyCount, pProperties ? &(pProperties->properties) : nullptr);
Alexis Hetud73b8712018-09-21 15:14:43 -04002543}
2544
2545VKAPI_ATTR void VKAPI_CALL vkTrimCommandPool(VkDevice device, VkCommandPool commandPool, VkCommandPoolTrimFlags flags)
2546{
Ben Claytonfb280672019-04-25 11:16:15 +01002547 TRACE("(VkDevice device = %p, VkCommandPool commandPool = %p, VkCommandPoolTrimFlags flags = %d)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04002548 device, static_cast<void*>(commandPool), flags);
Nicolas Capensde16f322019-02-12 00:32:31 -05002549
Alexis Hetucd610c92019-02-01 16:47:51 -05002550 vk::Cast(commandPool)->trim(flags);
Alexis Hetud73b8712018-09-21 15:14:43 -04002551}
2552
2553VKAPI_ATTR void VKAPI_CALL vkGetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2* pQueueInfo, VkQueue* pQueue)
2554{
Ben Claytonfb280672019-04-25 11:16:15 +01002555 TRACE("(VkDevice device = %p, const VkDeviceQueueInfo2* pQueueInfo = %p, VkQueue* pQueue = %p)",
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002556 device, pQueueInfo, pQueue);
2557
2558 if(pQueueInfo->pNext)
2559 {
Ben Clayton00424c12019-03-17 17:29:30 +00002560 UNIMPLEMENTED("pQueueInfo->pNext");
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002561 }
2562
Nicolas Capens50b10592018-10-26 10:34:20 -04002563 // The only flag that can be set here is VK_DEVICE_QUEUE_CREATE_PROTECTED_BIT
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002564 // According to the Vulkan spec, 4.3.1. Queue Family Properties:
2565 // "VK_DEVICE_QUEUE_CREATE_PROTECTED_BIT specifies that the device queue is a
2566 // protected-capable queue. If the protected memory feature is not enabled,
2567 // the VK_DEVICE_QUEUE_CREATE_PROTECTED_BIT bit of flags must not be set."
2568 if(pQueueInfo->flags)
2569 {
2570 *pQueue = VK_NULL_HANDLE;
2571 }
2572 else
2573 {
2574 vkGetDeviceQueue(device, pQueueInfo->queueFamilyIndex, pQueueInfo->queueIndex, pQueue);
2575 }
Alexis Hetud73b8712018-09-21 15:14:43 -04002576}
2577
2578VKAPI_ATTR VkResult VKAPI_CALL vkCreateSamplerYcbcrConversion(VkDevice device, const VkSamplerYcbcrConversionCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSamplerYcbcrConversion* pYcbcrConversion)
2579{
Nicolas Capens6b63c802019-05-16 11:10:34 -04002580 TRACE("(VkDevice device = %p, const VkSamplerYcbcrConversionCreateInfo* pCreateInfo = %p, const VkAllocationCallbacks* pAllocator = %p, VkSamplerYcbcrConversion* pYcbcrConversion = %p)",
2581 device, pCreateInfo, pAllocator, pYcbcrConversion);
2582
2583 if(pCreateInfo->pNext)
2584 {
2585 UNIMPLEMENTED("pCreateInfo->pNext");
2586 }
2587
2588 return vk::SamplerYcbcrConversion::Create(pAllocator, pCreateInfo, pYcbcrConversion);
Alexis Hetud73b8712018-09-21 15:14:43 -04002589}
2590
2591VKAPI_ATTR void VKAPI_CALL vkDestroySamplerYcbcrConversion(VkDevice device, VkSamplerYcbcrConversion ycbcrConversion, const VkAllocationCallbacks* pAllocator)
2592{
Nicolas Capens6b63c802019-05-16 11:10:34 -04002593 TRACE("(VkDevice device = %p, VkSamplerYcbcrConversion ycbcrConversion = %p, const VkAllocationCallbacks* pAllocator = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04002594 device, static_cast<void*>(ycbcrConversion), pAllocator);
Nicolas Capens6b63c802019-05-16 11:10:34 -04002595
2596 vk::destroy(ycbcrConversion, pAllocator);
Alexis Hetud73b8712018-09-21 15:14:43 -04002597}
2598
2599VKAPI_ATTR VkResult VKAPI_CALL vkCreateDescriptorUpdateTemplate(VkDevice device, const VkDescriptorUpdateTemplateCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDescriptorUpdateTemplate* pDescriptorUpdateTemplate)
2600{
Ben Claytonfb280672019-04-25 11:16:15 +01002601 TRACE("(VkDevice device = %p, const VkDescriptorUpdateTemplateCreateInfo* pCreateInfo = %p, const VkAllocationCallbacks* pAllocator = %p, VkDescriptorUpdateTemplate* pDescriptorUpdateTemplate = %p)",
Alexis Hetuf705cec2019-01-29 14:09:36 -05002602 device, pCreateInfo, pAllocator, pDescriptorUpdateTemplate);
2603
2604 if(pCreateInfo->pNext || pCreateInfo->flags || (pCreateInfo->templateType != VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET))
2605 {
Ben Clayton00424c12019-03-17 17:29:30 +00002606 UNIMPLEMENTED("pCreateInfo->pNext || pCreateInfo->flags || (pCreateInfo->templateType != VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET)");
Alexis Hetuf705cec2019-01-29 14:09:36 -05002607 }
2608
2609 return vk::DescriptorUpdateTemplate::Create(pAllocator, pCreateInfo, pDescriptorUpdateTemplate);
Alexis Hetud73b8712018-09-21 15:14:43 -04002610}
2611
2612VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorUpdateTemplate(VkDevice device, VkDescriptorUpdateTemplate descriptorUpdateTemplate, const VkAllocationCallbacks* pAllocator)
2613{
Ben Claytonfb280672019-04-25 11:16:15 +01002614 TRACE("(VkDevice device = %p, VkDescriptorUpdateTemplate descriptorUpdateTemplate = %p, const VkAllocationCallbacks* pAllocator = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04002615 device, static_cast<void*>(descriptorUpdateTemplate), pAllocator);
Alexis Hetuf705cec2019-01-29 14:09:36 -05002616
2617 vk::destroy(descriptorUpdateTemplate, pAllocator);
Alexis Hetud73b8712018-09-21 15:14:43 -04002618}
2619
2620VKAPI_ATTR void VKAPI_CALL vkUpdateDescriptorSetWithTemplate(VkDevice device, VkDescriptorSet descriptorSet, VkDescriptorUpdateTemplate descriptorUpdateTemplate, const void* pData)
2621{
Ben Claytonfb280672019-04-25 11:16:15 +01002622 TRACE("(VkDevice device = %p, VkDescriptorSet descriptorSet = %p, VkDescriptorUpdateTemplate descriptorUpdateTemplate = %p, const void* pData = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04002623 device, static_cast<void*>(descriptorSet), static_cast<void*>(descriptorUpdateTemplate), pData);
Alexis Hetuf705cec2019-01-29 14:09:36 -05002624
Alexis Hetu6448bd62019-06-11 15:58:59 -04002625 vk::Cast(descriptorUpdateTemplate)->updateDescriptorSet(vk::Cast(device), descriptorSet, pData);
Alexis Hetud73b8712018-09-21 15:14:43 -04002626}
2627
2628VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceExternalBufferProperties(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalBufferInfo* pExternalBufferInfo, VkExternalBufferProperties* pExternalBufferProperties)
2629{
Ben Claytonfb280672019-04-25 11:16:15 +01002630 TRACE("(VkPhysicalDevice physicalDevice = %p, const VkPhysicalDeviceExternalBufferInfo* pExternalBufferInfo = %p, VkExternalBufferProperties* pExternalBufferProperties = %p)",
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002631 physicalDevice, pExternalBufferInfo, pExternalBufferProperties);
2632
Alexis Hetu00835732019-04-10 16:36:31 -04002633 vk::Cast(physicalDevice)->getProperties(pExternalBufferInfo, pExternalBufferProperties);
Alexis Hetud73b8712018-09-21 15:14:43 -04002634}
2635
2636VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceExternalFenceProperties(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalFenceInfo* pExternalFenceInfo, VkExternalFenceProperties* pExternalFenceProperties)
2637{
Ben Claytonfb280672019-04-25 11:16:15 +01002638 TRACE("(VkPhysicalDevice physicalDevice = %p, const VkPhysicalDeviceExternalFenceInfo* pExternalFenceInfo = %p, VkExternalFenceProperties* pExternalFenceProperties = %p)",
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002639 physicalDevice, pExternalFenceInfo, pExternalFenceProperties);
2640
Alexis Hetu00835732019-04-10 16:36:31 -04002641 vk::Cast(physicalDevice)->getProperties(pExternalFenceInfo, pExternalFenceProperties);
Alexis Hetud73b8712018-09-21 15:14:43 -04002642}
2643
2644VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceExternalSemaphoreProperties(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalSemaphoreInfo* pExternalSemaphoreInfo, VkExternalSemaphoreProperties* pExternalSemaphoreProperties)
2645{
Ben Claytonfb280672019-04-25 11:16:15 +01002646 TRACE("(VkPhysicalDevice physicalDevice = %p, const VkPhysicalDeviceExternalSemaphoreInfo* pExternalSemaphoreInfo = %p, VkExternalSemaphoreProperties* pExternalSemaphoreProperties = %p)",
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002647 physicalDevice, pExternalSemaphoreInfo, pExternalSemaphoreProperties);
2648
Alexis Hetu00835732019-04-10 16:36:31 -04002649 vk::Cast(physicalDevice)->getProperties(pExternalSemaphoreInfo, pExternalSemaphoreProperties);
Alexis Hetud73b8712018-09-21 15:14:43 -04002650}
2651
2652VKAPI_ATTR void VKAPI_CALL vkGetDescriptorSetLayoutSupport(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, VkDescriptorSetLayoutSupport* pSupport)
2653{
Ben Claytonfb280672019-04-25 11:16:15 +01002654 TRACE("(VkDevice device = %p, const VkDescriptorSetLayoutCreateInfo* pCreateInfo = %p, VkDescriptorSetLayoutSupport* pSupport = %p)",
Alexis Hetu1424ef62019-04-05 18:03:53 -04002655 device, pCreateInfo, pSupport);
Alexis Hetu9e4d0402018-10-16 15:44:12 -04002656
2657 vk::Cast(device)->getDescriptorSetLayoutSupport(pCreateInfo, pSupport);
Alexis Hetud73b8712018-09-21 15:14:43 -04002658}
2659
Hernan Liatisc6eb41b2019-02-22 11:12:59 -08002660#ifdef VK_USE_PLATFORM_XLIB_KHR
2661VKAPI_ATTR VkResult VKAPI_CALL vkCreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface)
2662{
Ben Claytonfb280672019-04-25 11:16:15 +01002663 TRACE("(VkInstance instance = %p, VkXlibSurfaceCreateInfoKHR* pCreateInfo = %p, VkAllocationCallbacks* pAllocator = %p, VkSurface* pSurface = %p)",
Hernan Liatisc6eb41b2019-02-22 11:12:59 -08002664 instance, pCreateInfo, pAllocator, pSurface);
2665
2666 return vk::XlibSurfaceKHR::Create(pAllocator, pCreateInfo, pSurface);
2667}
Hernan Liatisbd18d582019-05-29 15:38:58 -07002668
2669VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXlibPresentationSupportKHR(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, Display* dpy, VisualID visualID)
2670{
2671 TRACE("(VkPhysicalDevice physicalDevice = %p, uint32_t queueFamilyIndex = %d, Display* dpy = %p, VisualID visualID = %lu)",
2672 physicalDevice, int(queueFamilyIndex), dpy, visualID);
2673
2674 return VK_TRUE;
2675}
Hernan Liatisc6eb41b2019-02-22 11:12:59 -08002676#endif
2677
Alexis Hetu0662a4a2019-07-08 15:06:40 -04002678#ifdef VK_USE_PLATFORM_MACOS_MVK
2679VKAPI_ATTR VkResult VKAPI_CALL vkCreateMacOSSurfaceMVK(VkInstance instance, const VkMacOSSurfaceCreateInfoMVK* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface)
2680{
2681 TRACE("(VkInstance instance = %p, VkMacOSSurfaceCreateInfoMVK* pCreateInfo = %p, VkAllocationCallbacks* pAllocator = %p, VkSurface* pSurface = %p)",
2682 instance, pCreateInfo, pAllocator, pSurface);
2683
2684 return vk::MacOSSurfaceMVK::Create(pAllocator, pCreateInfo, pSurface);
2685}
2686#endif
2687
Nicolas Capensd3545372019-08-09 13:59:18 -04002688#ifdef VK_USE_PLATFORM_WIN32_KHR
2689VKAPI_ATTR VkResult VKAPI_CALL vkCreateWin32SurfaceKHR(VkInstance instance, const VkWin32SurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface)
2690{
2691 TRACE("(VkInstance instance = %p, VkWin32SurfaceCreateInfoKHR* pCreateInfo = %p, VkAllocationCallbacks* pAllocator = %p, VkSurface* pSurface = %p)",
2692 instance, pCreateInfo, pAllocator, pSurface);
2693
2694 return vk::Win32SurfaceKHR::Create(pAllocator, pCreateInfo, pSurface);
2695}
2696#endif
2697
Chris Forbes1d667d62019-04-05 08:25:18 -07002698#ifndef __ANDROID__
2699VKAPI_ATTR void VKAPI_CALL vkDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface, const VkAllocationCallbacks* pAllocator)
2700{
Ben Claytonfb280672019-04-25 11:16:15 +01002701 TRACE("(VkInstance instance = %p, VkSurfaceKHR surface = %p, const VkAllocationCallbacks* pAllocator = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04002702 instance, static_cast<void*>(surface), pAllocator);
Chris Forbes1d667d62019-04-05 08:25:18 -07002703
2704 vk::destroy(surface, pAllocator);
2705}
2706
Hernan Liatisc6eb41b2019-02-22 11:12:59 -08002707VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, VkSurfaceKHR surface, VkBool32* pSupported)
2708{
Ben Claytonfb280672019-04-25 11:16:15 +01002709 TRACE("(VkPhysicalDevice physicalDevice = %p, uint32_t queueFamilyIndex = %d, VkSurface surface = %p, VKBool32* pSupported = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04002710 physicalDevice, int(queueFamilyIndex), static_cast<void*>(surface), pSupported);
Hernan Liatisc6eb41b2019-02-22 11:12:59 -08002711
2712 *pSupported = VK_TRUE;
2713 return VK_SUCCESS;
2714}
2715
Hernan Liatisc6eb41b2019-02-22 11:12:59 -08002716VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, VkSurfaceCapabilitiesKHR* pSurfaceCapabilities)
2717{
Ben Claytonfb280672019-04-25 11:16:15 +01002718 TRACE("(VkPhysicalDevice physicalDevice = %p, VkSurfaceKHR surface = %p, VkSurfaceCapabilitiesKHR* pSurfaceCapabilities = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04002719 physicalDevice, static_cast<void*>(surface), pSurfaceCapabilities);
Hernan Liatisc6eb41b2019-02-22 11:12:59 -08002720
2721 vk::Cast(surface)->getSurfaceCapabilities(pSurfaceCapabilities);
2722 return VK_SUCCESS;
2723}
2724
2725VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, uint32_t* pSurfaceFormatCount, VkSurfaceFormatKHR* pSurfaceFormats)
2726{
Ben Claytonfb280672019-04-25 11:16:15 +01002727 TRACE("(VkPhysicalDevice physicalDevice = %p, VkSurfaceKHR surface = %p. uint32_t* pSurfaceFormatCount = %p, VkSurfaceFormatKHR* pSurfaceFormats = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04002728 physicalDevice, static_cast<void*>(surface), pSurfaceFormatCount, pSurfaceFormats);
Hernan Liatisc6eb41b2019-02-22 11:12:59 -08002729
2730 if(!pSurfaceFormats)
2731 {
2732 *pSurfaceFormatCount = vk::Cast(surface)->getSurfaceFormatsCount();
2733 return VK_SUCCESS;
2734 }
2735
2736 return vk::Cast(surface)->getSurfaceFormats(pSurfaceFormatCount, pSurfaceFormats);
2737}
2738
2739VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, uint32_t* pPresentModeCount, VkPresentModeKHR* pPresentModes)
2740{
Ben Claytonfb280672019-04-25 11:16:15 +01002741 TRACE("(VkPhysicalDevice physicalDevice = %p, VkSurfaceKHR surface = %p uint32_t* pPresentModeCount = %p, VkPresentModeKHR* pPresentModes = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04002742 physicalDevice, static_cast<void*>(surface), pPresentModeCount, pPresentModes);
Hernan Liatisc6eb41b2019-02-22 11:12:59 -08002743
2744 if(!pPresentModes)
2745 {
2746 *pPresentModeCount = vk::Cast(surface)->getPresentModeCount();
2747 return VK_SUCCESS;
2748 }
2749
2750 return vk::Cast(surface)->getPresentModes(pPresentModeCount, pPresentModes);
2751}
2752
Hernan Liatisc7943e92019-02-25 19:29:54 -08002753VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSwapchainKHR* pSwapchain)
2754{
Ben Claytonfb280672019-04-25 11:16:15 +01002755 TRACE("(VkDevice device = %p, const VkSwapchainCreateInfoKHR* pCreateInfo = %p, const VkAllocationCallbacks* pAllocator = %p, VkSwapchainKHR* pSwapchain = %p)",
Hernan Liatisc7943e92019-02-25 19:29:54 -08002756 device, pCreateInfo, pAllocator, pSwapchain);
2757
Hernan Liatis43be7162019-03-08 17:57:41 -08002758 if(pCreateInfo->oldSwapchain)
2759 {
2760 vk::Cast(pCreateInfo->oldSwapchain)->retire();
2761 }
2762
Alexis Hetu63ae9242019-06-06 13:52:15 -04002763 if(vk::Cast(pCreateInfo->surface)->hasAssociatedSwapchain())
Hernan Liatis43be7162019-03-08 17:57:41 -08002764 {
2765 return VK_ERROR_NATIVE_WINDOW_IN_USE_KHR;
2766 }
2767
Hernan Liatisc7943e92019-02-25 19:29:54 -08002768 VkResult status = vk::SwapchainKHR::Create(pAllocator, pCreateInfo, pSwapchain);
2769
2770 if(status != VK_SUCCESS)
2771 {
2772 return status;
2773 }
2774
Alexis Hetu7d96f512019-06-13 18:23:56 -04002775 auto swapchain = vk::Cast(*pSwapchain);
2776 status = swapchain->createImages(device, pCreateInfo);
Hernan Liatisc7943e92019-02-25 19:29:54 -08002777
2778 if(status != VK_SUCCESS)
2779 {
2780 vk::destroy(*pSwapchain, pAllocator);
2781 return status;
2782 }
2783
Alexis Hetu7d96f512019-06-13 18:23:56 -04002784 vk::Cast(pCreateInfo->surface)->associateSwapchain(swapchain);
Hernan Liatis43be7162019-03-08 17:57:41 -08002785
Hernan Liatisc7943e92019-02-25 19:29:54 -08002786 return VK_SUCCESS;
2787}
2788
2789VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain, const VkAllocationCallbacks* pAllocator)
2790{
Ben Claytonfb280672019-04-25 11:16:15 +01002791 TRACE("(VkDevice device = %p, VkSwapchainKHR swapchain = %p, const VkAllocationCallbacks* pAllocator = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04002792 device, static_cast<void*>(swapchain), pAllocator);
Hernan Liatisc7943e92019-02-25 19:29:54 -08002793
2794 vk::destroy(swapchain, pAllocator);
2795}
2796
Hernan Liatisd00375a2019-02-26 11:19:27 -08002797VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t* pSwapchainImageCount, VkImage* pSwapchainImages)
2798{
Ben Claytonfb280672019-04-25 11:16:15 +01002799 TRACE("(VkDevice device = %p, VkSwapchainKHR swapchain = %p, uint32_t* pSwapchainImageCount = %p, VkImage* pSwapchainImages = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04002800 device, static_cast<void*>(swapchain), pSwapchainImageCount, pSwapchainImages);
Hernan Liatisd00375a2019-02-26 11:19:27 -08002801
2802 if(!pSwapchainImages)
2803 {
2804 *pSwapchainImageCount = vk::Cast(swapchain)->getImageCount();
2805 return VK_SUCCESS;
2806 }
2807
2808 return vk::Cast(swapchain)->getImages(pSwapchainImageCount, pSwapchainImages);
2809}
2810
Hernan Liatis6b12a502019-03-01 15:06:13 -08002811VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout, VkSemaphore semaphore, VkFence fence, uint32_t* pImageIndex)
2812{
Ben Claytonfb280672019-04-25 11:16:15 +01002813 TRACE("(VkDevice device = %p, VkSwapchainKHR swapchain = %p, uint64_t timeout = %d, VkSemaphore semaphore = %p, VkFence fence = %p, uint32_t* pImageIndex = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04002814 device, static_cast<void*>(swapchain), int(timeout), static_cast<void*>(semaphore), static_cast<void*>(fence), pImageIndex);
Hernan Liatis6b12a502019-03-01 15:06:13 -08002815
Alexis Hetu7d96f512019-06-13 18:23:56 -04002816 return vk::Cast(swapchain)->getNextImage(timeout, vk::Cast(semaphore), vk::Cast(fence), pImageIndex);
Hernan Liatis6b12a502019-03-01 15:06:13 -08002817}
2818
2819VKAPI_ATTR VkResult VKAPI_CALL vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo)
2820{
Ben Claytonfb280672019-04-25 11:16:15 +01002821 TRACE("(VkQueue queue = %p, const VkPresentInfoKHR* pPresentInfo = %p)",
Hernan Liatis6b12a502019-03-01 15:06:13 -08002822 queue, pPresentInfo);
2823
2824 vk::Cast(queue)->present(pPresentInfo);
2825
2826 return VK_SUCCESS;
2827}
Chris Forbesf993de32019-04-15 09:45:34 -07002828
2829VKAPI_ATTR VkResult VKAPI_CALL vkGetDeviceGroupPresentCapabilitiesKHR(VkDevice device, VkDeviceGroupPresentCapabilitiesKHR *pDeviceGroupPresentCapabilities)
2830{
Ben Claytonfb280672019-04-25 11:16:15 +01002831 TRACE("(VkDevice device = %p, VkDeviceGroupPresentCapabilitiesKHR* pDeviceGroupPresentCapabilities = %p)",
Chris Forbesf993de32019-04-15 09:45:34 -07002832 device, pDeviceGroupPresentCapabilities);
2833
2834 for (int i = 0; i < VK_MAX_DEVICE_GROUP_SIZE; i++)
2835 {
2836 // The only real physical device in the presentation group is device 0,
2837 // and it can present to itself.
2838 pDeviceGroupPresentCapabilities->presentMask[i] = (i == 0) ? 1 : 0;
2839 }
2840
2841 pDeviceGroupPresentCapabilities->modes = VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR;
2842
2843 return VK_SUCCESS;
2844}
2845
2846VKAPI_ATTR VkResult VKAPI_CALL vkGetDeviceGroupSurfacePresentModesKHR(VkDevice device, VkSurfaceKHR surface, VkDeviceGroupPresentModeFlagsKHR *pModes)
2847{
Ben Claytonfb280672019-04-25 11:16:15 +01002848 TRACE("(VkDevice device = %p, VkSurfaceKHR surface = %p, VkDeviceGroupPresentModeFlagsKHR *pModes = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04002849 device, static_cast<void*>(surface), pModes);
Chris Forbesf993de32019-04-15 09:45:34 -07002850
2851 *pModes = VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR;
2852 return VK_SUCCESS;
2853}
2854
Chris Forbesb52384b2019-08-28 12:01:29 -07002855VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDevicePresentRectanglesKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, uint32_t* pRectCount, VkRect2D* pRects)
2856{
2857 TRACE("(VkPhysicalDevice physicalDevice = %p, VkSurfaceKHR surface = %p, uint32_t* pRectCount = %p, VkRect2D* pRects = %p)",
2858 physicalDevice, static_cast<void*>(surface), pRectCount, pRects);
2859
2860 return vk::Cast(surface)->getPresentRectangles(pRectCount, pRects);
2861}
2862
2863
Chris Forbes1d667d62019-04-05 08:25:18 -07002864#endif // ! __ANDROID__
Hernan Liatis6b12a502019-03-01 15:06:13 -08002865
Hernan Liatis8a91a352019-04-29 17:14:06 -07002866#ifdef __ANDROID__
2867
2868VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainGrallocUsage2ANDROID(VkDevice device, VkFormat format, VkImageUsageFlags imageUsage, VkSwapchainImageUsageFlagsANDROID swapchainUsage, uint64_t* grallocConsumerUsage, uint64_t* grallocProducerUsage)
2869{
Hernan Liatis628604e2019-05-07 15:30:18 -07002870 TRACE("(VkDevice device = %p, VkFormat format = %d, VkImageUsageFlags imageUsage = %d, VkSwapchainImageUsageFlagsANDROID swapchainUsage = %d, uint64_t* grallocConsumerUsage = %p, uin64_t* grallocProducerUsage = %p)",
Hernan Liatis8a91a352019-04-29 17:14:06 -07002871 device, format, imageUsage, swapchainUsage, grallocConsumerUsage, grallocProducerUsage);
2872
Hernan Liatis788ea9f2019-05-01 11:10:36 -07002873 *grallocConsumerUsage = 0;
2874 *grallocProducerUsage = GRALLOC1_PRODUCER_USAGE_CPU_WRITE_OFTEN;
2875
Hernan Liatis8a91a352019-04-29 17:14:06 -07002876 return VK_SUCCESS;
2877}
2878
2879VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainGrallocUsageANDROID(VkDevice device, VkFormat format, VkImageUsageFlags imageUsage, int* grallocUsage)
2880{
Hernan Liatis628604e2019-05-07 15:30:18 -07002881 TRACE("(VkDevice device = %p, VkFormat format = %d, VkImageUsageFlags imageUsage = %d, int* grallocUsage = %p)",
Hernan Liatis8a91a352019-04-29 17:14:06 -07002882 device, format, imageUsage, grallocUsage);
2883
Hernan Liatis3429bb52019-05-29 18:42:11 -07002884 *grallocUsage = GRALLOC_USAGE_SW_WRITE_OFTEN;
2885
Hernan Liatis8a91a352019-04-29 17:14:06 -07002886 return VK_SUCCESS;
2887}
2888
2889VKAPI_ATTR VkResult VKAPI_CALL vkAcquireImageANDROID(VkDevice device, VkImage image, int nativeFenceFd, VkSemaphore semaphore, VkFence fence)
2890{
Hernan Liatis628604e2019-05-07 15:30:18 -07002891 TRACE("(VkDevice device = %p, VkImage image = %p, int nativeFenceFd = %d, VkSemaphore semaphore = %p, VkFence fence = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04002892 device, static_cast<void*>(image), nativeFenceFd, static_cast<void*>(semaphore), static_cast<void*>(fence));
Hernan Liatis8a91a352019-04-29 17:14:06 -07002893
Hernan Liatisd5f462c2019-05-24 15:45:05 -07002894 if(nativeFenceFd >= 0)
2895 {
2896 sync_wait(nativeFenceFd, -1);
2897 close(nativeFenceFd);
2898 }
2899
2900 if(fence != VK_NULL_HANDLE)
2901 {
2902 vk::Cast(fence)->complete();
2903 }
2904
2905 if(semaphore != VK_NULL_HANDLE)
2906 {
2907 vk::Cast(semaphore)->signal();
2908 }
2909
Hernan Liatis8a91a352019-04-29 17:14:06 -07002910 return VK_SUCCESS;
2911}
2912
2913VKAPI_ATTR VkResult VKAPI_CALL vkQueueSignalReleaseImageANDROID(VkQueue queue, uint32_t waitSemaphoreCount, const VkSemaphore* pWaitSemaphores, VkImage image, int* pNativeFenceFd)
2914{
Hernan Liatis628604e2019-05-07 15:30:18 -07002915 TRACE("(VkQueue queue = %p, uint32_t waitSemaphoreCount = %d, const VkSemaphore* pWaitSemaphores = %p, VkImage image = %p, int* pNativeFenceFd = %p)",
Alexis Hetu2d77aea2019-06-17 13:43:50 -04002916 queue, waitSemaphoreCount, pWaitSemaphores, static_cast<void*>(image), pNativeFenceFd);
Hernan Liatis8a91a352019-04-29 17:14:06 -07002917
Hernan Liatisd61595f2019-05-10 16:30:07 -07002918 // This is a hack to deal with screen tearing for now.
2919 // Need to correctly implement threading using VkSemaphore
2920 // to get rid of it. b/132458423
2921 vkQueueWaitIdle(queue);
2922
Hernan Liatis628604e2019-05-07 15:30:18 -07002923 GrallocModule* grallocMod = GrallocModule::getInstance();
2924 void* nativeBuffer;
2925
2926 auto it = androidSwapchainMap.find(image);
2927
2928 if (it == androidSwapchainMap.end())
2929 ABORT("ANDROID: Swapchain image not found");
2930
2931 BackingMemory backmem = it->second;
2932
Chris Forbes4963b952019-05-29 14:37:57 -07002933 VkExtent3D extent = vk::Cast(image)->getMipLevelExtent(VK_IMAGE_ASPECT_COLOR_BIT, 0);
Hernan Liatis628604e2019-05-07 15:30:18 -07002934 grallocMod->lock(backmem.nativeHandle, GRALLOC_USAGE_SW_WRITE_OFTEN, 0, 0, extent.width, extent.height, &nativeBuffer);
2935
Hernan Liatis3c735072019-06-10 15:07:18 -07002936 char* buffer = static_cast<char*>(backmem.imageMemory->getOffsetPointer(0));
Hernan Liatis628604e2019-05-07 15:30:18 -07002937 int imageRowBytes = vk::Cast(image)->rowPitchBytes(VK_IMAGE_ASPECT_COLOR_BIT, 0);
2938 int colorBytes = vk::Cast(image)->getFormat().bytes();
2939
2940 for(int i = 0; i < extent.height; i++)
2941 {
2942 memcpy((void*)((char*)nativeBuffer + (i * backmem.stride * colorBytes)), buffer + (i * imageRowBytes), imageRowBytes);
2943 }
2944
Hernan Liatis8a91a352019-04-29 17:14:06 -07002945 return VK_SUCCESS;
2946}
2947#endif // __ANDROID__
2948
Chris Forbes3d27f2e2018-09-26 09:24:39 -07002949}