1 /*
2 * Vulkan
3 *
4 * Copyright (C) 2015 Valve, Inc.
5 * Copyright (C) 2016 Google, Inc.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <unordered_map>
23 #include <list>
24
25 #include "vk_loader_platform.h"
26 #include "vulkan/vk_layer.h"
27 #include "vk_layer_config.h"
28 #include "vk_layer_extension_utils.h"
29 #include "vk_layer_utils.h"
30 #include "vk_layer_table.h"
31 #include "vk_layer_logging.h"
32 #include "threading.h"
33 #include "vk_dispatch_table_helper.h"
34 #include "vk_enum_string_helper.h"
35 #include "vk_layer_data.h"
36 #include "vk_layer_utils.h"
37
38 #include "thread_check.h"
39
40 namespace threading {
41
42 static uint32_t loader_layer_if_version = CURRENT_LOADER_LAYER_INTERFACE_VERSION;
43
initThreading(layer_data * my_data,const VkAllocationCallbacks * pAllocator)44 static void initThreading(layer_data *my_data, const VkAllocationCallbacks *pAllocator) {
45 layer_debug_actions(my_data->report_data, my_data->logging_callback, pAllocator, "google_threading");
46 }
47
CreateInstance(const VkInstanceCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkInstance * pInstance)48 VKAPI_ATTR VkResult VKAPI_CALL CreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
49 VkInstance *pInstance) {
50 VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
51
52 assert(chain_info->u.pLayerInfo);
53 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
54 PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance");
55 if (fpCreateInstance == NULL) {
56 return VK_ERROR_INITIALIZATION_FAILED;
57 }
58
59 // Advance the link info for the next element on the chain
60 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
61
62 VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
63 if (result != VK_SUCCESS) return result;
64
65 layer_data *my_data = GetLayerDataPtr(get_dispatch_key(*pInstance), layer_data_map);
66 my_data->instance = *pInstance;
67 my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
68 layer_init_instance_dispatch_table(*pInstance, my_data->instance_dispatch_table, fpGetInstanceProcAddr);
69
70 my_data->report_data = debug_report_create_instance(my_data->instance_dispatch_table, *pInstance,
71 pCreateInfo->enabledExtensionCount, pCreateInfo->ppEnabledExtensionNames);
72 initThreading(my_data, pAllocator);
73
74 // Look for one or more debug report create info structures, and copy the
75 // callback(s) for each one found (for use by vkDestroyInstance)
76 layer_copy_tmp_callbacks(pCreateInfo->pNext, &my_data->num_tmp_callbacks, &my_data->tmp_dbg_create_infos,
77 &my_data->tmp_callbacks);
78 return result;
79 }
80
DestroyInstance(VkInstance instance,const VkAllocationCallbacks * pAllocator)81 VKAPI_ATTR void VKAPI_CALL DestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) {
82 dispatch_key key = get_dispatch_key(instance);
83 layer_data *my_data = GetLayerDataPtr(key, layer_data_map);
84 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
85
86 // Enable the temporary callback(s) here to catch cleanup issues:
87 bool callback_setup = false;
88 if (my_data->num_tmp_callbacks > 0) {
89 if (!layer_enable_tmp_callbacks(my_data->report_data, my_data->num_tmp_callbacks, my_data->tmp_dbg_create_infos,
90 my_data->tmp_callbacks)) {
91 callback_setup = true;
92 }
93 }
94
95 bool threadChecks = startMultiThread();
96 if (threadChecks) {
97 startWriteObject(my_data, instance);
98 }
99 pTable->DestroyInstance(instance, pAllocator);
100 if (threadChecks) {
101 finishWriteObject(my_data, instance);
102 } else {
103 finishMultiThread();
104 }
105
106 // Disable and cleanup the temporary callback(s):
107 if (callback_setup) {
108 layer_disable_tmp_callbacks(my_data->report_data, my_data->num_tmp_callbacks, my_data->tmp_callbacks);
109 }
110 if (my_data->num_tmp_callbacks > 0) {
111 layer_free_tmp_callbacks(my_data->tmp_dbg_create_infos, my_data->tmp_callbacks);
112 my_data->num_tmp_callbacks = 0;
113 }
114
115 // Clean up logging callback, if any
116 while (my_data->logging_callback.size() > 0) {
117 VkDebugReportCallbackEXT callback = my_data->logging_callback.back();
118 layer_destroy_msg_callback(my_data->report_data, callback, pAllocator);
119 my_data->logging_callback.pop_back();
120 }
121
122 layer_debug_report_destroy_instance(my_data->report_data);
123 delete my_data->instance_dispatch_table;
124 FreeLayerDataPtr(key, layer_data_map);
125 }
126
CreateDevice(VkPhysicalDevice gpu,const VkDeviceCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkDevice * pDevice)127 VKAPI_ATTR VkResult VKAPI_CALL CreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo,
128 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice) {
129 layer_data *my_instance_data = GetLayerDataPtr(get_dispatch_key(gpu), layer_data_map);
130 VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
131
132 assert(chain_info->u.pLayerInfo);
133 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
134 PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr;
135 PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice)fpGetInstanceProcAddr(my_instance_data->instance, "vkCreateDevice");
136 if (fpCreateDevice == NULL) {
137 return VK_ERROR_INITIALIZATION_FAILED;
138 }
139
140 // Advance the link info for the next element on the chain
141 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
142
143 VkResult result = fpCreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
144 if (result != VK_SUCCESS) {
145 return result;
146 }
147
148 layer_data *my_device_data = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map);
149
150 // Setup device dispatch table
151 my_device_data->device_dispatch_table = new VkLayerDispatchTable;
152 layer_init_device_dispatch_table(*pDevice, my_device_data->device_dispatch_table, fpGetDeviceProcAddr);
153
154 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
155 return result;
156 }
157
DestroyDevice(VkDevice device,const VkAllocationCallbacks * pAllocator)158 VKAPI_ATTR void VKAPI_CALL DestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
159 dispatch_key key = get_dispatch_key(device);
160 layer_data *dev_data = GetLayerDataPtr(key, layer_data_map);
161 bool threadChecks = startMultiThread();
162 if (threadChecks) {
163 startWriteObject(dev_data, device);
164 }
165 dev_data->device_dispatch_table->DestroyDevice(device, pAllocator);
166 if (threadChecks) {
167 finishWriteObject(dev_data, device);
168 } else {
169 finishMultiThread();
170 }
171
172 delete dev_data->device_dispatch_table;
173 FreeLayerDataPtr(key, layer_data_map);
174 }
175
GetSwapchainImagesKHR(VkDevice device,VkSwapchainKHR swapchain,uint32_t * pSwapchainImageCount,VkImage * pSwapchainImages)176 VKAPI_ATTR VkResult VKAPI_CALL GetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t *pSwapchainImageCount,
177 VkImage *pSwapchainImages) {
178 dispatch_key key = get_dispatch_key(device);
179 layer_data *my_data = GetLayerDataPtr(key, layer_data_map);
180 VkLayerDispatchTable *pTable = my_data->device_dispatch_table;
181 VkResult result;
182 bool threadChecks = startMultiThread();
183 if (threadChecks) {
184 startReadObject(my_data, device);
185 startReadObject(my_data, swapchain);
186 }
187 result = pTable->GetSwapchainImagesKHR(device, swapchain, pSwapchainImageCount, pSwapchainImages);
188 if (threadChecks) {
189 finishReadObject(my_data, device);
190 finishReadObject(my_data, swapchain);
191 } else {
192 finishMultiThread();
193 }
194 return result;
195 }
196
197 static const VkExtensionProperties threading_extensions[] = {
198 {VK_EXT_DEBUG_REPORT_EXTENSION_NAME, VK_EXT_DEBUG_REPORT_SPEC_VERSION}};
199
200 static const VkLayerProperties layerProps = {
201 "VK_LAYER_GOOGLE_threading",
202 VK_LAYER_API_VERSION, // specVersion
203 1,
204 "Google Validation Layer",
205 };
206
EnumerateInstanceLayerProperties(uint32_t * pCount,VkLayerProperties * pProperties)207 VKAPI_ATTR VkResult VKAPI_CALL EnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties *pProperties) {
208 return util_GetLayerProperties(1, &layerProps, pCount, pProperties);
209 }
210
EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice,uint32_t * pCount,VkLayerProperties * pProperties)211 VKAPI_ATTR VkResult VKAPI_CALL EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount,
212 VkLayerProperties *pProperties) {
213 return util_GetLayerProperties(1, &layerProps, pCount, pProperties);
214 }
215
EnumerateInstanceExtensionProperties(const char * pLayerName,uint32_t * pCount,VkExtensionProperties * pProperties)216 VKAPI_ATTR VkResult VKAPI_CALL EnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount,
217 VkExtensionProperties *pProperties) {
218 if (pLayerName && !strcmp(pLayerName, layerProps.layerName))
219 return util_GetExtensionProperties(1, threading_extensions, pCount, pProperties);
220
221 return VK_ERROR_LAYER_NOT_PRESENT;
222 }
223
EnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice,const char * pLayerName,uint32_t * pCount,VkExtensionProperties * pProperties)224 VKAPI_ATTR VkResult VKAPI_CALL EnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char *pLayerName,
225 uint32_t *pCount, VkExtensionProperties *pProperties) {
226 // Threading layer does not have any device extensions
227 if (pLayerName && !strcmp(pLayerName, layerProps.layerName))
228 return util_GetExtensionProperties(0, nullptr, pCount, pProperties);
229
230 assert(physicalDevice);
231
232 dispatch_key key = get_dispatch_key(physicalDevice);
233 layer_data *my_data = GetLayerDataPtr(key, layer_data_map);
234 return my_data->instance_dispatch_table->EnumerateDeviceExtensionProperties(physicalDevice, NULL, pCount, pProperties);
235 }
236
237 // Need to prototype this call because it's internal and does not show up in vk.xml
238 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetPhysicalDeviceProcAddr(VkInstance instance, const char *funcName);
239
GetDeviceProcAddr(VkDevice device,const char * funcName)240 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetDeviceProcAddr(VkDevice device, const char *funcName) {
241 const auto item = name_to_funcptr_map.find(funcName);
242 if (item != name_to_funcptr_map.end()) {
243 return reinterpret_cast<PFN_vkVoidFunction>(item->second);
244 }
245
246 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
247 auto &table = device_data->device_dispatch_table;
248 if (!table->GetDeviceProcAddr) return nullptr;
249 return table->GetDeviceProcAddr(device, funcName);
250 }
251
GetInstanceProcAddr(VkInstance instance,const char * funcName)252 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetInstanceProcAddr(VkInstance instance, const char *funcName) {
253 const auto item = name_to_funcptr_map.find(funcName);
254 if (item != name_to_funcptr_map.end()) {
255 return reinterpret_cast<PFN_vkVoidFunction>(item->second);
256 }
257
258 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map);
259 auto &table = instance_data->instance_dispatch_table;
260 if (!table->GetInstanceProcAddr) return nullptr;
261 return table->GetInstanceProcAddr(instance, funcName);
262 }
263
GetPhysicalDeviceProcAddr(VkInstance instance,const char * funcName)264 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetPhysicalDeviceProcAddr(VkInstance instance, const char *funcName) {
265 assert(instance);
266
267 layer_data *my_data;
268 my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map);
269 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
270
271 if (pTable->GetPhysicalDeviceProcAddr == NULL) return NULL;
272 return pTable->GetPhysicalDeviceProcAddr(instance, funcName);
273 }
274
CreateDebugReportCallbackEXT(VkInstance instance,const VkDebugReportCallbackCreateInfoEXT * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkDebugReportCallbackEXT * pMsgCallback)275 VKAPI_ATTR VkResult VKAPI_CALL CreateDebugReportCallbackEXT(VkInstance instance,
276 const VkDebugReportCallbackCreateInfoEXT *pCreateInfo,
277 const VkAllocationCallbacks *pAllocator,
278 VkDebugReportCallbackEXT *pMsgCallback) {
279 layer_data *my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map);
280 bool threadChecks = startMultiThread();
281 if (threadChecks) {
282 startReadObject(my_data, instance);
283 }
284 VkResult result =
285 my_data->instance_dispatch_table->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
286 if (VK_SUCCESS == result) {
287 result = layer_create_msg_callback(my_data->report_data, false, pCreateInfo, pAllocator, pMsgCallback);
288 }
289 if (threadChecks) {
290 finishReadObject(my_data, instance);
291 } else {
292 finishMultiThread();
293 }
294 return result;
295 }
296
DestroyDebugReportCallbackEXT(VkInstance instance,VkDebugReportCallbackEXT callback,const VkAllocationCallbacks * pAllocator)297 VKAPI_ATTR void VKAPI_CALL DestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT callback,
298 const VkAllocationCallbacks *pAllocator) {
299 layer_data *my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map);
300 bool threadChecks = startMultiThread();
301 if (threadChecks) {
302 startReadObject(my_data, instance);
303 startWriteObject(my_data, callback);
304 }
305 my_data->instance_dispatch_table->DestroyDebugReportCallbackEXT(instance, callback, pAllocator);
306 layer_destroy_msg_callback(my_data->report_data, callback, pAllocator);
307 if (threadChecks) {
308 finishReadObject(my_data, instance);
309 finishWriteObject(my_data, callback);
310 } else {
311 finishMultiThread();
312 }
313 }
314
AllocateCommandBuffers(VkDevice device,const VkCommandBufferAllocateInfo * pAllocateInfo,VkCommandBuffer * pCommandBuffers)315 VKAPI_ATTR VkResult VKAPI_CALL AllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pAllocateInfo,
316 VkCommandBuffer *pCommandBuffers) {
317 dispatch_key key = get_dispatch_key(device);
318 layer_data *my_data = GetLayerDataPtr(key, layer_data_map);
319 VkLayerDispatchTable *pTable = my_data->device_dispatch_table;
320 VkResult result;
321 bool threadChecks = startMultiThread();
322 if (threadChecks) {
323 startReadObject(my_data, device);
324 startWriteObject(my_data, pAllocateInfo->commandPool);
325 }
326
327 result = pTable->AllocateCommandBuffers(device, pAllocateInfo, pCommandBuffers);
328 if (threadChecks) {
329 finishReadObject(my_data, device);
330 finishWriteObject(my_data, pAllocateInfo->commandPool);
331 } else {
332 finishMultiThread();
333 }
334
335 // Record mapping from command buffer to command pool
336 if (VK_SUCCESS == result) {
337 for (uint32_t index = 0; index < pAllocateInfo->commandBufferCount; index++) {
338 std::lock_guard<std::mutex> lock(command_pool_lock);
339 command_pool_map[pCommandBuffers[index]] = pAllocateInfo->commandPool;
340 }
341 }
342
343 return result;
344 }
345
AllocateDescriptorSets(VkDevice device,const VkDescriptorSetAllocateInfo * pAllocateInfo,VkDescriptorSet * pDescriptorSets)346 VKAPI_ATTR VkResult VKAPI_CALL AllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo,
347 VkDescriptorSet *pDescriptorSets) {
348 dispatch_key key = get_dispatch_key(device);
349 layer_data *my_data = GetLayerDataPtr(key, layer_data_map);
350 VkLayerDispatchTable *pTable = my_data->device_dispatch_table;
351 VkResult result;
352 bool threadChecks = startMultiThread();
353 if (threadChecks) {
354 startReadObject(my_data, device);
355 startWriteObject(my_data, pAllocateInfo->descriptorPool);
356 // Host access to pAllocateInfo::descriptorPool must be externally synchronized
357 }
358 result = pTable->AllocateDescriptorSets(device, pAllocateInfo, pDescriptorSets);
359 if (threadChecks) {
360 finishReadObject(my_data, device);
361 finishWriteObject(my_data, pAllocateInfo->descriptorPool);
362 // Host access to pAllocateInfo::descriptorPool must be externally synchronized
363 } else {
364 finishMultiThread();
365 }
366 return result;
367 }
368
FreeCommandBuffers(VkDevice device,VkCommandPool commandPool,uint32_t commandBufferCount,const VkCommandBuffer * pCommandBuffers)369 VKAPI_ATTR void VKAPI_CALL FreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount,
370 const VkCommandBuffer *pCommandBuffers) {
371 dispatch_key key = get_dispatch_key(device);
372 layer_data *my_data = GetLayerDataPtr(key, layer_data_map);
373 VkLayerDispatchTable *pTable = my_data->device_dispatch_table;
374 const bool lockCommandPool = false; // pool is already directly locked
375 bool threadChecks = startMultiThread();
376 if (threadChecks) {
377 startReadObject(my_data, device);
378 startWriteObject(my_data, commandPool);
379 for (uint32_t index = 0; index < commandBufferCount; index++) {
380 startWriteObject(my_data, pCommandBuffers[index], lockCommandPool);
381 }
382 // The driver may immediately reuse command buffers in another thread.
383 // These updates need to be done before calling down to the driver.
384 for (uint32_t index = 0; index < commandBufferCount; index++) {
385 finishWriteObject(my_data, pCommandBuffers[index], lockCommandPool);
386 std::lock_guard<std::mutex> lock(command_pool_lock);
387 command_pool_map.erase(pCommandBuffers[index]);
388 }
389 }
390
391 pTable->FreeCommandBuffers(device, commandPool, commandBufferCount, pCommandBuffers);
392 if (threadChecks) {
393 finishReadObject(my_data, device);
394 finishWriteObject(my_data, commandPool);
395 } else {
396 finishMultiThread();
397 }
398 }
399
400 } // namespace threading
401
402 // vk_layer_logging.h expects these to be defined
403
vkCreateDebugReportCallbackEXT(VkInstance instance,const VkDebugReportCallbackCreateInfoEXT * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkDebugReportCallbackEXT * pMsgCallback)404 VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(VkInstance instance,
405 const VkDebugReportCallbackCreateInfoEXT *pCreateInfo,
406 const VkAllocationCallbacks *pAllocator,
407 VkDebugReportCallbackEXT *pMsgCallback) {
408 return threading::CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
409 }
410
vkDestroyDebugReportCallbackEXT(VkInstance instance,VkDebugReportCallbackEXT msgCallback,const VkAllocationCallbacks * pAllocator)411 VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT msgCallback,
412 const VkAllocationCallbacks *pAllocator) {
413 threading::DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
414 }
415
vkDebugReportMessageEXT(VkInstance instance,VkDebugReportFlagsEXT flags,VkDebugReportObjectTypeEXT objType,uint64_t object,size_t location,int32_t msgCode,const char * pLayerPrefix,const char * pMsg)416 VKAPI_ATTR void VKAPI_CALL vkDebugReportMessageEXT(VkInstance instance, VkDebugReportFlagsEXT flags,
417 VkDebugReportObjectTypeEXT objType, uint64_t object, size_t location,
418 int32_t msgCode, const char *pLayerPrefix, const char *pMsg) {
419 threading::DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg);
420 }
421
422 // loader-layer interface v0, just wrappers since there is only a layer
423
vkEnumerateInstanceExtensionProperties(const char * pLayerName,uint32_t * pCount,VkExtensionProperties * pProperties)424 VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount,
425 VkExtensionProperties *pProperties) {
426 return threading::EnumerateInstanceExtensionProperties(pLayerName, pCount, pProperties);
427 }
428
vkEnumerateInstanceLayerProperties(uint32_t * pCount,VkLayerProperties * pProperties)429 VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount,
430 VkLayerProperties *pProperties) {
431 return threading::EnumerateInstanceLayerProperties(pCount, pProperties);
432 }
433
vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice,uint32_t * pCount,VkLayerProperties * pProperties)434 VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount,
435 VkLayerProperties *pProperties) {
436 // the layer command handles VK_NULL_HANDLE just fine internally
437 assert(physicalDevice == VK_NULL_HANDLE);
438 return threading::EnumerateDeviceLayerProperties(VK_NULL_HANDLE, pCount, pProperties);
439 }
440
vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice,const char * pLayerName,uint32_t * pCount,VkExtensionProperties * pProperties)441 VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice,
442 const char *pLayerName, uint32_t *pCount,
443 VkExtensionProperties *pProperties) {
444 // the layer command handles VK_NULL_HANDLE just fine internally
445 assert(physicalDevice == VK_NULL_HANDLE);
446 return threading::EnumerateDeviceExtensionProperties(VK_NULL_HANDLE, pLayerName, pCount, pProperties);
447 }
448
vkGetDeviceProcAddr(VkDevice dev,const char * funcName)449 VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char *funcName) {
450 return threading::GetDeviceProcAddr(dev, funcName);
451 }
452
vkGetInstanceProcAddr(VkInstance instance,const char * funcName)453 VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) {
454 return threading::GetInstanceProcAddr(instance, funcName);
455 }
456
vk_layerGetPhysicalDeviceProcAddr(VkInstance instance,const char * funcName)457 VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_layerGetPhysicalDeviceProcAddr(VkInstance instance,
458 const char *funcName) {
459 return threading::GetPhysicalDeviceProcAddr(instance, funcName);
460 }
461
vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface * pVersionStruct)462 VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface *pVersionStruct) {
463 assert(pVersionStruct != NULL);
464 assert(pVersionStruct->sType == LAYER_NEGOTIATE_INTERFACE_STRUCT);
465
466 // Fill in the function pointers if our version is at least capable of having the structure contain them.
467 if (pVersionStruct->loaderLayerInterfaceVersion >= 2) {
468 pVersionStruct->pfnGetInstanceProcAddr = vkGetInstanceProcAddr;
469 pVersionStruct->pfnGetDeviceProcAddr = vkGetDeviceProcAddr;
470 pVersionStruct->pfnGetPhysicalDeviceProcAddr = vk_layerGetPhysicalDeviceProcAddr;
471 }
472
473 if (pVersionStruct->loaderLayerInterfaceVersion < CURRENT_LOADER_LAYER_INTERFACE_VERSION) {
474 threading::loader_layer_if_version = pVersionStruct->loaderLayerInterfaceVersion;
475 } else if (pVersionStruct->loaderLayerInterfaceVersion > CURRENT_LOADER_LAYER_INTERFACE_VERSION) {
476 pVersionStruct->loaderLayerInterfaceVersion = CURRENT_LOADER_LAYER_INTERFACE_VERSION;
477 }
478
479 return VK_SUCCESS;
480 }
481