unique_objects.h revision 491a3cd11793892b996a8b5771479cc539198f99
1/* Copyright (c) 2015-2016 The Khronos Group Inc.
2 * Copyright (c) 2015-2016 Valve Corporation
3 * Copyright (c) 2015-2016 LunarG, Inc.
4 * Copyright (C) 2015-2016 Google Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and/or associated documentation files (the "Materials"), to
8 * deal in the Materials without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Materials, and to permit persons to whom the Materials
11 * are furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice(s) and this permission notice shall be included
14 * in all copies or substantial portions of the Materials.
15 *
16 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 *
20 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE
23 * USE OR OTHER DEALINGS IN THE MATERIALS
24 *
25 * Author: Tobin Ehlis <tobine@google.com>
26 */
27
28#include <stdio.h>
29#include <stdlib.h>
30#include <string.h>
31#include <inttypes.h>
32
33#include "vulkan/vulkan.h"
34#include "vk_loader_platform.h"
35
36#include <vector>
37#include <unordered_map>
38
39#include "vulkan/vk_layer.h"
40#include "vk_layer_config.h"
41#include "vk_layer_table.h"
42#include "vk_layer_data.h"
43#include "vk_layer_logging.h"
44#include "vk_layer_extension_utils.h"
45#include "vk_safe_struct.h"
46
47struct layer_data {
48    bool wsi_enabled;
49
50    layer_data() : wsi_enabled(false){};
51};
52
53struct instExts {
54    bool wsi_enabled;
55    bool xlib_enabled;
56    bool xcb_enabled;
57    bool wayland_enabled;
58    bool mir_enabled;
59    bool android_enabled;
60    bool win32_enabled;
61};
62
63static std::unordered_map<void *, struct instExts> instanceExtMap;
64static std::unordered_map<void *, layer_data *> layer_data_map;
65static device_table_map unique_objects_device_table_map;
66static instance_table_map unique_objects_instance_table_map;
67// Structure to wrap returned non-dispatchable objects to guarantee they have unique handles
68//  address of struct will be used as the unique handle
69struct VkUniqueObject {
70    uint64_t actualObject;
71};
72
73// Handle CreateInstance
74static void createInstanceRegisterExtensions(const VkInstanceCreateInfo *pCreateInfo, VkInstance instance) {
75    uint32_t i;
76    VkLayerInstanceDispatchTable *pDisp = get_dispatch_table(unique_objects_instance_table_map, instance);
77    PFN_vkGetInstanceProcAddr gpa = pDisp->GetInstanceProcAddr;
78
79    pDisp->DestroySurfaceKHR = (PFN_vkDestroySurfaceKHR)gpa(instance, "vkDestroySurfaceKHR");
80    pDisp->GetPhysicalDeviceSurfaceSupportKHR =
81        (PFN_vkGetPhysicalDeviceSurfaceSupportKHR)gpa(instance, "vkGetPhysicalDeviceSurfaceSupportKHR");
82    pDisp->GetPhysicalDeviceSurfaceCapabilitiesKHR =
83        (PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR)gpa(instance, "vkGetPhysicalDeviceSurfaceCapabilitiesKHR");
84    pDisp->GetPhysicalDeviceSurfaceFormatsKHR =
85        (PFN_vkGetPhysicalDeviceSurfaceFormatsKHR)gpa(instance, "vkGetPhysicalDeviceSurfaceFormatsKHR");
86    pDisp->GetPhysicalDeviceSurfacePresentModesKHR =
87        (PFN_vkGetPhysicalDeviceSurfacePresentModesKHR)gpa(instance, "vkGetPhysicalDeviceSurfacePresentModesKHR");
88#ifdef VK_USE_PLATFORM_WIN32_KHR
89    pDisp->CreateWin32SurfaceKHR = (PFN_vkCreateWin32SurfaceKHR)gpa(instance, "vkCreateWin32SurfaceKHR");
90    pDisp->GetPhysicalDeviceWin32PresentationSupportKHR =
91        (PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR)gpa(instance, "vkGetPhysicalDeviceWin32PresentationSupportKHR");
92#endif // VK_USE_PLATFORM_WIN32_KHR
93#ifdef VK_USE_PLATFORM_XCB_KHR
94    pDisp->CreateXcbSurfaceKHR = (PFN_vkCreateXcbSurfaceKHR)gpa(instance, "vkCreateXcbSurfaceKHR");
95    pDisp->GetPhysicalDeviceXcbPresentationSupportKHR =
96        (PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR)gpa(instance, "vkGetPhysicalDeviceXcbPresentationSupportKHR");
97#endif // VK_USE_PLATFORM_XCB_KHR
98#ifdef VK_USE_PLATFORM_XLIB_KHR
99    pDisp->CreateXlibSurfaceKHR = (PFN_vkCreateXlibSurfaceKHR)gpa(instance, "vkCreateXlibSurfaceKHR");
100    pDisp->GetPhysicalDeviceXlibPresentationSupportKHR =
101        (PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR)gpa(instance, "vkGetPhysicalDeviceXlibPresentationSupportKHR");
102#endif // VK_USE_PLATFORM_XLIB_KHR
103#ifdef VK_USE_PLATFORM_MIR_KHR
104    pDisp->CreateMirSurfaceKHR = (PFN_vkCreateMirSurfaceKHR)gpa(instance, "vkCreateMirSurfaceKHR");
105    pDisp->GetPhysicalDeviceMirPresentationSupportKHR =
106        (PFN_vkGetPhysicalDeviceMirPresentationSupportKHR)gpa(instance, "vkGetPhysicalDeviceMirPresentationSupportKHR");
107#endif // VK_USE_PLATFORM_MIR_KHR
108#ifdef VK_USE_PLATFORM_WAYLAND_KHR
109    pDisp->CreateWaylandSurfaceKHR = (PFN_vkCreateWaylandSurfaceKHR)gpa(instance, "vkCreateWaylandSurfaceKHR");
110    pDisp->GetPhysicalDeviceWaylandPresentationSupportKHR =
111        (PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR)gpa(instance, "vkGetPhysicalDeviceWaylandPresentationSupportKHR");
112#endif //  VK_USE_PLATFORM_WAYLAND_KHR
113#ifdef VK_USE_PLATFORM_ANDROID_KHR
114    pDisp->CreateAndroidSurfaceKHR = (PFN_vkCreateAndroidSurfaceKHR)gpa(instance, "vkCreateAndroidSurfaceKHR");
115#endif // VK_USE_PLATFORM_ANDROID_KHR
116
117    instanceExtMap[pDisp] = {};
118    for (i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
119        if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SURFACE_EXTENSION_NAME) == 0)
120            instanceExtMap[pDisp].wsi_enabled = true;
121#ifdef VK_USE_PLATFORM_XLIB_KHR
122        if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_XLIB_SURFACE_EXTENSION_NAME) == 0)
123            instanceExtMap[pDisp].xlib_enabled = true;
124#endif
125#ifdef VK_USE_PLATFORM_XCB_KHR
126        if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_XCB_SURFACE_EXTENSION_NAME) == 0)
127            instanceExtMap[pDisp].xcb_enabled = true;
128#endif
129#ifdef VK_USE_PLATFORM_WAYLAND_KHR
130        if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME) == 0)
131            instanceExtMap[pDisp].wayland_enabled = true;
132#endif
133#ifdef VK_USE_PLATFORM_MIR_KHR
134        if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_MIR_SURFACE_EXTENSION_NAME) == 0)
135            instanceExtMap[pDisp].mir_enabled = true;
136#endif
137#ifdef VK_USE_PLATFORM_ANDROID_KHR
138        if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_ANDROID_SURFACE_EXTENSION_NAME) == 0)
139            instanceExtMap[pDisp].android_enabled = true;
140#endif
141#ifdef VK_USE_PLATFORM_WIN32_KHR
142        if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WIN32_SURFACE_EXTENSION_NAME) == 0)
143            instanceExtMap[pDisp].win32_enabled = true;
144#endif
145    }
146}
147
148VkResult explicit_CreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
149                                 VkInstance *pInstance) {
150    VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
151
152    assert(chain_info->u.pLayerInfo);
153    PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
154    PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance");
155    if (fpCreateInstance == NULL) {
156        return VK_ERROR_INITIALIZATION_FAILED;
157    }
158
159    // Advance the link info for the next element on the chain
160    chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
161
162    VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
163    if (result != VK_SUCCESS) {
164        return result;
165    }
166
167    initInstanceTable(*pInstance, fpGetInstanceProcAddr, unique_objects_instance_table_map);
168
169    createInstanceRegisterExtensions(pCreateInfo, *pInstance);
170
171    return result;
172}
173
174// Handle CreateDevice
175static void createDeviceRegisterExtensions(const VkDeviceCreateInfo *pCreateInfo, VkDevice device) {
176    layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
177    VkLayerDispatchTable *pDisp = get_dispatch_table(unique_objects_device_table_map, device);
178    PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr;
179    pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR)gpa(device, "vkCreateSwapchainKHR");
180    pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR)gpa(device, "vkDestroySwapchainKHR");
181    pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR)gpa(device, "vkGetSwapchainImagesKHR");
182    pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR)gpa(device, "vkAcquireNextImageKHR");
183    pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR)gpa(device, "vkQueuePresentKHR");
184    my_device_data->wsi_enabled = false;
185    for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
186        if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0)
187            my_device_data->wsi_enabled = true;
188    }
189}
190
191VkResult explicit_CreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
192                               VkDevice *pDevice) {
193    VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
194
195    assert(chain_info->u.pLayerInfo);
196    PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
197    PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr;
198    PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice)fpGetInstanceProcAddr(NULL, "vkCreateDevice");
199    if (fpCreateDevice == NULL) {
200        return VK_ERROR_INITIALIZATION_FAILED;
201    }
202
203    // Advance the link info for the next element on the chain
204    chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
205
206    VkResult result = fpCreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
207    if (result != VK_SUCCESS) {
208        return result;
209    }
210
211    // Setup layer's device dispatch table
212    initDeviceTable(*pDevice, fpGetDeviceProcAddr, unique_objects_device_table_map);
213
214    createDeviceRegisterExtensions(pCreateInfo, *pDevice);
215
216    return result;
217}
218
219VkResult explicit_QueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits, VkFence fence) {
220    // UNWRAP USES:
221    //  0 : fence,VkFence
222    if (VK_NULL_HANDLE != fence) {
223        fence = (VkFence)((VkUniqueObject *)fence)->actualObject;
224    }
225    //  waitSemaphoreCount : pSubmits[submitCount]->pWaitSemaphores,VkSemaphore
226    std::vector<VkSemaphore> original_pWaitSemaphores = {};
227    //  signalSemaphoreCount : pSubmits[submitCount]->pSignalSemaphores,VkSemaphore
228    std::vector<VkSemaphore> original_pSignalSemaphores = {};
229    if (pSubmits) {
230        for (uint32_t index0 = 0; index0 < submitCount; ++index0) {
231            if (pSubmits[index0].pWaitSemaphores) {
232                for (uint32_t index1 = 0; index1 < pSubmits[index0].waitSemaphoreCount; ++index1) {
233                    VkSemaphore **ppSemaphore = (VkSemaphore **)&(pSubmits[index0].pWaitSemaphores);
234                    original_pWaitSemaphores.push_back(pSubmits[index0].pWaitSemaphores[index1]);
235                    *(ppSemaphore[index1]) =
236                        (VkSemaphore)((VkUniqueObject *)pSubmits[index0].pWaitSemaphores[index1])->actualObject;
237                }
238            }
239            if (pSubmits[index0].pSignalSemaphores) {
240                for (uint32_t index1 = 0; index1 < pSubmits[index0].signalSemaphoreCount; ++index1) {
241                    VkSemaphore **ppSemaphore = (VkSemaphore **)&(pSubmits[index0].pSignalSemaphores);
242                    original_pSignalSemaphores.push_back(pSubmits[index0].pSignalSemaphores[index1]);
243                    *(ppSemaphore[index1]) =
244                        (VkSemaphore)((VkUniqueObject *)pSubmits[index0].pSignalSemaphores[index1])->actualObject;
245                }
246            }
247        }
248    }
249    VkResult result = get_dispatch_table(unique_objects_device_table_map, queue)->QueueSubmit(queue, submitCount, pSubmits, fence);
250    if (pSubmits) {
251        for (uint32_t index0 = 0; index0 < submitCount; ++index0) {
252            if (pSubmits[index0].pWaitSemaphores) {
253                for (uint32_t index1 = 0; index1 < pSubmits[index0].waitSemaphoreCount; ++index1) {
254                    VkSemaphore **ppSemaphore = (VkSemaphore **)&(pSubmits[index0].pWaitSemaphores);
255                    *(ppSemaphore[index1]) = original_pWaitSemaphores[index1];
256                }
257            }
258            if (pSubmits[index0].pSignalSemaphores) {
259                for (uint32_t index1 = 0; index1 < pSubmits[index0].signalSemaphoreCount; ++index1) {
260                    VkSemaphore **ppSemaphore = (VkSemaphore **)&(pSubmits[index0].pSignalSemaphores);
261                    *(ppSemaphore[index1]) = original_pSignalSemaphores[index1];
262                }
263            }
264        }
265    }
266    return result;
267}
268
269VkResult explicit_QueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo *pBindInfo, VkFence fence) {
270    // UNWRAP USES:
271    //  0 : pBindInfo[bindInfoCount]->pBufferBinds[bufferBindCount]->buffer,VkBuffer,
272    //  pBindInfo[bindInfoCount]->pBufferBinds[bufferBindCount]->pBinds[bindCount]->memory,VkDeviceMemory,
273    //  pBindInfo[bindInfoCount]->pImageOpaqueBinds[imageOpaqueBindCount]->image,VkImage,
274    //  pBindInfo[bindInfoCount]->pImageOpaqueBinds[imageOpaqueBindCount]->pBinds[bindCount]->memory,VkDeviceMemory,
275    //  pBindInfo[bindInfoCount]->pImageBinds[imageBindCount]->image,VkImage,
276    //  pBindInfo[bindInfoCount]->pImageBinds[imageBindCount]->pBinds[bindCount]->memory,VkDeviceMemory
277    std::vector<VkBuffer> original_buffer = {};
278    std::vector<VkDeviceMemory> original_memory1 = {};
279    std::vector<VkImage> original_image1 = {};
280    std::vector<VkDeviceMemory> original_memory2 = {};
281    std::vector<VkImage> original_image2 = {};
282    std::vector<VkDeviceMemory> original_memory3 = {};
283    std::vector<VkSemaphore> original_pWaitSemaphores = {};
284    std::vector<VkSemaphore> original_pSignalSemaphores = {};
285    if (pBindInfo) {
286        for (uint32_t index0 = 0; index0 < bindInfoCount; ++index0) {
287            if (pBindInfo[index0].pBufferBinds) {
288                for (uint32_t index1 = 0; index1 < pBindInfo[index0].bufferBindCount; ++index1) {
289                    if (pBindInfo[index0].pBufferBinds[index1].buffer) {
290                        VkBuffer *pBuffer = (VkBuffer *)&(pBindInfo[index0].pBufferBinds[index1].buffer);
291                        original_buffer.push_back(pBindInfo[index0].pBufferBinds[index1].buffer);
292                        *(pBuffer) = (VkBuffer)((VkUniqueObject *)pBindInfo[index0].pBufferBinds[index1].buffer)->actualObject;
293                    }
294                    if (pBindInfo[index0].pBufferBinds[index1].pBinds) {
295                        for (uint32_t index2 = 0; index2 < pBindInfo[index0].pBufferBinds[index1].bindCount; ++index2) {
296                            if (pBindInfo[index0].pBufferBinds[index1].pBinds[index2].memory) {
297                                VkDeviceMemory *pDeviceMemory =
298                                    (VkDeviceMemory *)&(pBindInfo[index0].pBufferBinds[index1].pBinds[index2].memory);
299                                original_memory1.push_back(pBindInfo[index0].pBufferBinds[index1].pBinds[index2].memory);
300                                *(pDeviceMemory) =
301                                    (VkDeviceMemory)((VkUniqueObject *)pBindInfo[index0].pBufferBinds[index1].pBinds[index2].memory)
302                                        ->actualObject;
303                            }
304                        }
305                    }
306                }
307            }
308            if (pBindInfo[index0].pImageOpaqueBinds) {
309                for (uint32_t index1 = 0; index1 < pBindInfo[index0].imageOpaqueBindCount; ++index1) {
310                    if (pBindInfo[index0].pImageOpaqueBinds[index1].image) {
311                        VkImage *pImage = (VkImage *)&(pBindInfo[index0].pImageOpaqueBinds[index1].image);
312                        original_image1.push_back(pBindInfo[index0].pImageOpaqueBinds[index1].image);
313                        *(pImage) = (VkImage)((VkUniqueObject *)pBindInfo[index0].pImageOpaqueBinds[index1].image)->actualObject;
314                    }
315                    if (pBindInfo[index0].pImageOpaqueBinds[index1].pBinds) {
316                        for (uint32_t index2 = 0; index2 < pBindInfo[index0].pImageOpaqueBinds[index1].bindCount; ++index2) {
317                            if (pBindInfo[index0].pImageOpaqueBinds[index1].pBinds[index2].memory) {
318                                VkDeviceMemory *pDeviceMemory =
319                                    (VkDeviceMemory *)&(pBindInfo[index0].pImageOpaqueBinds[index1].pBinds[index2].memory);
320                                original_memory2.push_back(pBindInfo[index0].pImageOpaqueBinds[index1].pBinds[index2].memory);
321                                *(pDeviceMemory) =
322                                    (VkDeviceMemory)(
323                                        (VkUniqueObject *)pBindInfo[index0].pImageOpaqueBinds[index1].pBinds[index2].memory)
324                                        ->actualObject;
325                            }
326                        }
327                    }
328                }
329            }
330            if (pBindInfo[index0].pImageBinds) {
331                for (uint32_t index1 = 0; index1 < pBindInfo[index0].imageBindCount; ++index1) {
332                    if (pBindInfo[index0].pImageBinds[index1].image) {
333                        VkImage *pImage = (VkImage *)&(pBindInfo[index0].pImageBinds[index1].image);
334                        original_image2.push_back(pBindInfo[index0].pImageBinds[index1].image);
335                        *(pImage) = (VkImage)((VkUniqueObject *)pBindInfo[index0].pImageBinds[index1].image)->actualObject;
336                    }
337                    if (pBindInfo[index0].pImageBinds[index1].pBinds) {
338                        for (uint32_t index2 = 0; index2 < pBindInfo[index0].pImageBinds[index1].bindCount; ++index2) {
339                            if (pBindInfo[index0].pImageBinds[index1].pBinds[index2].memory) {
340                                VkDeviceMemory *pDeviceMemory =
341                                    (VkDeviceMemory *)&(pBindInfo[index0].pImageBinds[index1].pBinds[index2].memory);
342                                original_memory3.push_back(pBindInfo[index0].pImageBinds[index1].pBinds[index2].memory);
343                                *(pDeviceMemory) =
344                                    (VkDeviceMemory)((VkUniqueObject *)pBindInfo[index0].pImageBinds[index1].pBinds[index2].memory)
345                                        ->actualObject;
346                            }
347                        }
348                    }
349                }
350            }
351            if (pBindInfo[index0].pWaitSemaphores) {
352                for (uint32_t index1 = 0; index1 < pBindInfo[index0].waitSemaphoreCount; ++index1) {
353                    VkSemaphore **ppSemaphore = (VkSemaphore **)&(pBindInfo[index0].pWaitSemaphores);
354                    original_pWaitSemaphores.push_back(pBindInfo[index0].pWaitSemaphores[index1]);
355                    *(ppSemaphore[index1]) =
356                        (VkSemaphore)((VkUniqueObject *)pBindInfo[index0].pWaitSemaphores[index1])->actualObject;
357                }
358            }
359            if (pBindInfo[index0].pSignalSemaphores) {
360                for (uint32_t index1 = 0; index1 < pBindInfo[index0].signalSemaphoreCount; ++index1) {
361                    VkSemaphore **ppSemaphore = (VkSemaphore **)&(pBindInfo[index0].pSignalSemaphores);
362                    original_pSignalSemaphores.push_back(pBindInfo[index0].pSignalSemaphores[index1]);
363                    *(ppSemaphore[index1]) =
364                        (VkSemaphore)((VkUniqueObject *)pBindInfo[index0].pSignalSemaphores[index1])->actualObject;
365                }
366            }
367        }
368    }
369    if (VK_NULL_HANDLE != fence) {
370        fence = (VkFence)((VkUniqueObject *)fence)->actualObject;
371    }
372    VkResult result =
373        get_dispatch_table(unique_objects_device_table_map, queue)->QueueBindSparse(queue, bindInfoCount, pBindInfo, fence);
374    if (pBindInfo) {
375        for (uint32_t index0 = 0; index0 < bindInfoCount; ++index0) {
376            if (pBindInfo[index0].pBufferBinds) {
377                for (uint32_t index1 = 0; index1 < pBindInfo[index0].bufferBindCount; ++index1) {
378                    if (pBindInfo[index0].pBufferBinds[index1].buffer) {
379                        VkBuffer *pBuffer = (VkBuffer *)&(pBindInfo[index0].pBufferBinds[index1].buffer);
380                        *(pBuffer) = original_buffer[index1];
381                    }
382                    if (pBindInfo[index0].pBufferBinds[index1].pBinds) {
383                        for (uint32_t index2 = 0; index2 < pBindInfo[index0].pBufferBinds[index1].bindCount; ++index2) {
384                            if (pBindInfo[index0].pBufferBinds[index1].pBinds[index2].memory) {
385                                VkDeviceMemory *pDeviceMemory =
386                                    (VkDeviceMemory *)&(pBindInfo[index0].pBufferBinds[index1].pBinds[index2].memory);
387                                *(pDeviceMemory) = original_memory1[index2];
388                            }
389                        }
390                    }
391                }
392            }
393            if (pBindInfo[index0].pImageOpaqueBinds) {
394                for (uint32_t index1 = 0; index1 < pBindInfo[index0].imageOpaqueBindCount; ++index1) {
395                    if (pBindInfo[index0].pImageOpaqueBinds[index1].image) {
396                        VkImage *pImage = (VkImage *)&(pBindInfo[index0].pImageOpaqueBinds[index1].image);
397                        *(pImage) = original_image1[index1];
398                    }
399                    if (pBindInfo[index0].pImageOpaqueBinds[index1].pBinds) {
400                        for (uint32_t index2 = 0; index2 < pBindInfo[index0].pImageOpaqueBinds[index1].bindCount; ++index2) {
401                            if (pBindInfo[index0].pImageOpaqueBinds[index1].pBinds[index2].memory) {
402                                VkDeviceMemory *pDeviceMemory =
403                                    (VkDeviceMemory *)&(pBindInfo[index0].pImageOpaqueBinds[index1].pBinds[index2].memory);
404                                *(pDeviceMemory) = original_memory2[index2];
405                            }
406                        }
407                    }
408                }
409            }
410            if (pBindInfo[index0].pImageBinds) {
411                for (uint32_t index1 = 0; index1 < pBindInfo[index0].imageBindCount; ++index1) {
412                    if (pBindInfo[index0].pImageBinds[index1].image) {
413                        VkImage *pImage = (VkImage *)&(pBindInfo[index0].pImageBinds[index1].image);
414                        *(pImage) = original_image2[index1];
415                    }
416                    if (pBindInfo[index0].pImageBinds[index1].pBinds) {
417                        for (uint32_t index2 = 0; index2 < pBindInfo[index0].pImageBinds[index1].bindCount; ++index2) {
418                            if (pBindInfo[index0].pImageBinds[index1].pBinds[index2].memory) {
419                                VkDeviceMemory *pDeviceMemory =
420                                    (VkDeviceMemory *)&(pBindInfo[index0].pImageBinds[index1].pBinds[index2].memory);
421                                *(pDeviceMemory) = original_memory3[index2];
422                            }
423                        }
424                    }
425                }
426            }
427            if (pBindInfo[index0].pWaitSemaphores) {
428                for (uint32_t index1 = 0; index1 < pBindInfo[index0].waitSemaphoreCount; ++index1) {
429                    VkSemaphore **ppSemaphore = (VkSemaphore **)&(pBindInfo[index0].pWaitSemaphores);
430                    *(ppSemaphore[index1]) = original_pWaitSemaphores[index1];
431                }
432            }
433            if (pBindInfo[index0].pSignalSemaphores) {
434                for (uint32_t index1 = 0; index1 < pBindInfo[index0].signalSemaphoreCount; ++index1) {
435                    VkSemaphore **ppSemaphore = (VkSemaphore **)&(pBindInfo[index0].pSignalSemaphores);
436                    *(ppSemaphore[index1]) = original_pSignalSemaphores[index1];
437                }
438            }
439        }
440    }
441    return result;
442}
443
444VkResult explicit_CreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
445                                         const VkComputePipelineCreateInfo *pCreateInfos, const VkAllocationCallbacks *pAllocator,
446                                         VkPipeline *pPipelines) {
447    // STRUCT USES:{'pipelineCache': 'VkPipelineCache', 'pCreateInfos[createInfoCount]': {'stage': {'module': 'VkShaderModule'},
448    // 'layout': 'VkPipelineLayout', 'basePipelineHandle': 'VkPipeline'}}
449    // LOCAL DECLS:{'pCreateInfos': 'VkComputePipelineCreateInfo*'}
450    safe_VkComputePipelineCreateInfo *local_pCreateInfos = NULL;
451    if (pCreateInfos) {
452        local_pCreateInfos = new safe_VkComputePipelineCreateInfo[createInfoCount];
453        for (uint32_t idx0 = 0; idx0 < createInfoCount; ++idx0) {
454            local_pCreateInfos[idx0].initialize(&pCreateInfos[idx0]);
455            if (pCreateInfos[idx0].basePipelineHandle) {
456                local_pCreateInfos[idx0].basePipelineHandle =
457                    (VkPipeline)((VkUniqueObject *)pCreateInfos[idx0].basePipelineHandle)->actualObject;
458            }
459            if (pCreateInfos[idx0].layout) {
460                local_pCreateInfos[idx0].layout = (VkPipelineLayout)((VkUniqueObject *)pCreateInfos[idx0].layout)->actualObject;
461            }
462            if (pCreateInfos[idx0].stage.module) {
463                local_pCreateInfos[idx0].stage.module =
464                    (VkShaderModule)((VkUniqueObject *)pCreateInfos[idx0].stage.module)->actualObject;
465            }
466        }
467    }
468    if (pipelineCache) {
469        pipelineCache = (VkPipelineCache)((VkUniqueObject *)pipelineCache)->actualObject;
470    }
471    // CODEGEN : file /usr/local/google/home/tobine/vulkan_work/LoaderAndTools/vk-layer-generate.py line #1671
472    VkResult result = get_dispatch_table(unique_objects_device_table_map, device)
473                          ->CreateComputePipelines(device, pipelineCache, createInfoCount,
474                                                   (const VkComputePipelineCreateInfo *)local_pCreateInfos, pAllocator, pPipelines);
475    delete[] local_pCreateInfos;
476    if (VK_SUCCESS == result) {
477        VkUniqueObject *pUO = NULL;
478        for (uint32_t i = 0; i < createInfoCount; ++i) {
479            pUO = new VkUniqueObject();
480            pUO->actualObject = (uint64_t)pPipelines[i];
481            pPipelines[i] = (VkPipeline)pUO;
482        }
483    }
484    return result;
485}
486
487VkResult explicit_CreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
488                                          const VkGraphicsPipelineCreateInfo *pCreateInfos, const VkAllocationCallbacks *pAllocator,
489                                          VkPipeline *pPipelines) {
490    // STRUCT USES:{'pipelineCache': 'VkPipelineCache', 'pCreateInfos[createInfoCount]': {'layout': 'VkPipelineLayout',
491    // 'pStages[stageCount]': {'module': 'VkShaderModule'}, 'renderPass': 'VkRenderPass', 'basePipelineHandle': 'VkPipeline'}}
492    // LOCAL DECLS:{'pCreateInfos': 'VkGraphicsPipelineCreateInfo*'}
493    safe_VkGraphicsPipelineCreateInfo *local_pCreateInfos = NULL;
494    if (pCreateInfos) {
495        local_pCreateInfos = new safe_VkGraphicsPipelineCreateInfo[createInfoCount];
496        for (uint32_t idx0 = 0; idx0 < createInfoCount; ++idx0) {
497            local_pCreateInfos[idx0].initialize(&pCreateInfos[idx0]);
498            if (pCreateInfos[idx0].basePipelineHandle) {
499                local_pCreateInfos[idx0].basePipelineHandle =
500                    (VkPipeline)((VkUniqueObject *)pCreateInfos[idx0].basePipelineHandle)->actualObject;
501            }
502            if (pCreateInfos[idx0].layout) {
503                local_pCreateInfos[idx0].layout = (VkPipelineLayout)((VkUniqueObject *)pCreateInfos[idx0].layout)->actualObject;
504            }
505            if (pCreateInfos[idx0].pStages) {
506                for (uint32_t idx1 = 0; idx1 < pCreateInfos[idx0].stageCount; ++idx1) {
507                    if (pCreateInfos[idx0].pStages[idx1].module) {
508                        local_pCreateInfos[idx0].pStages[idx1].module =
509                            (VkShaderModule)((VkUniqueObject *)pCreateInfos[idx0].pStages[idx1].module)->actualObject;
510                    }
511                }
512            }
513            if (pCreateInfos[idx0].renderPass) {
514                local_pCreateInfos[idx0].renderPass = (VkRenderPass)((VkUniqueObject *)pCreateInfos[idx0].renderPass)->actualObject;
515            }
516        }
517    }
518    if (pipelineCache) {
519        pipelineCache = (VkPipelineCache)((VkUniqueObject *)pipelineCache)->actualObject;
520    }
521    // CODEGEN : file /usr/local/google/home/tobine/vulkan_work/LoaderAndTools/vk-layer-generate.py line #1671
522    VkResult result =
523        get_dispatch_table(unique_objects_device_table_map, device)
524            ->CreateGraphicsPipelines(device, pipelineCache, createInfoCount,
525                                      (const VkGraphicsPipelineCreateInfo *)local_pCreateInfos, pAllocator, pPipelines);
526    delete[] local_pCreateInfos;
527    if (VK_SUCCESS == result) {
528        VkUniqueObject *pUO = NULL;
529        for (uint32_t i = 0; i < createInfoCount; ++i) {
530            pUO = new VkUniqueObject();
531            pUO->actualObject = (uint64_t)pPipelines[i];
532            pPipelines[i] = (VkPipeline)pUO;
533        }
534    }
535    return result;
536}
537
538VkResult explicit_GetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t *pSwapchainImageCount,
539                                        VkImage *pSwapchainImages) {
540    // UNWRAP USES:
541    //  0 : swapchain,VkSwapchainKHR, pSwapchainImages,VkImage
542    if (VK_NULL_HANDLE != swapchain) {
543        swapchain = (VkSwapchainKHR)((VkUniqueObject *)swapchain)->actualObject;
544    }
545    VkResult result = get_dispatch_table(unique_objects_device_table_map, device)
546                          ->GetSwapchainImagesKHR(device, swapchain, pSwapchainImageCount, pSwapchainImages);
547    // TODO : Need to add corresponding code to delete these images
548    if (VK_SUCCESS == result) {
549        if ((*pSwapchainImageCount > 0) && pSwapchainImages) {
550            std::vector<VkUniqueObject *> uniqueImages = {};
551            for (uint32_t i = 0; i < *pSwapchainImageCount; ++i) {
552                uniqueImages.push_back(new VkUniqueObject());
553                uniqueImages[i]->actualObject = (uint64_t)pSwapchainImages[i];
554                pSwapchainImages[i] = (VkImage)uniqueImages[i];
555            }
556        }
557    }
558    return result;
559}
560