blob: 12f3d45f3f698cad9429f472ac53607f5c3ddf41 [file] [log] [blame]
David Pinedoeeca2a22015-06-18 17:03:14 -06001/*
2 * Vulkan
3 *
4 * Copyright (C) 2015 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS 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. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25#include <inttypes.h>
26#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
29#include <assert.h>
30#include <unordered_map>
31#include <iostream>
32#include <algorithm>
33#include <list>
34#include <map>
35#include <vector>
36#include <fstream>
37
38using namespace std;
39
Tobin Ehlis7a51d902015-07-03 10:34:49 -060040#include "vk_loader_platform.h"
David Pinedoeeca2a22015-06-18 17:03:14 -060041#include "vk_dispatch_table_helper.h"
42#include "vk_struct_string_helper_cpp.h"
Tobin Ehlis56d204a2015-07-03 10:15:26 -060043#include "vk_layer_config.h"
David Pinedoeeca2a22015-06-18 17:03:14 -060044// The following is #included again to catch certain OS-specific functions
45// being used:
Tobin Ehlis7a51d902015-07-03 10:34:49 -060046#include "vk_loader_platform.h"
Tobin Ehlis56d204a2015-07-03 10:15:26 -060047#include "vk_layer_table.h"
David Pinedoeeca2a22015-06-18 17:03:14 -060048
David Pinedo8a4f5562015-06-19 13:48:18 -060049
50struct devExts {
51 bool wsi_lunarg_enabled;
52};
53static std::unordered_map<void *, struct devExts> deviceExtMap;
David Pinedoeeca2a22015-06-18 17:03:14 -060054static device_table_map screenshot_device_table_map;
David Pinedoeeca2a22015-06-18 17:03:14 -060055
56static int globalLockInitialized = 0;
57static loader_platform_thread_mutex globalLock;
58
59// unordered map, associates a swap chain with a device, image extent, and format
60typedef struct
61{
62 VkDevice device;
63 VkExtent2D imageExtent;
64 VkFormat format;
65} SwapchainMapStruct;
66static unordered_map<VkSwapChainWSI, SwapchainMapStruct *> swapchainMap;
67
68// unordered map, associates an image with a device, image extent, and format
69typedef struct
70{
71 VkDevice device;
72 VkExtent2D imageExtent;
73 VkFormat format;
74} ImageMapStruct;
75static unordered_map<VkImage, ImageMapStruct *> imageMap;
76
77// unordered map, associates a device with a queue
78typedef struct
79{
80 VkQueue queue;
81 uint32_t queueNodeIndex;
82 uint32_t queueIndex;
83} DeviceMapStruct;
84static unordered_map<VkDevice, DeviceMapStruct *> deviceMap;
85
86// List of frames to we will get a screenshot of
87static vector<int> screenshotFrames;
88
89// Flag indicating we have queried _VK_SCREENSHOT env var
90static bool screenshotEnvQueried = false;
91
92static void init_screenshot()
93{
David Pinedoeeca2a22015-06-18 17:03:14 -060094 if (!globalLockInitialized)
95 {
96 // TODO/TBD: Need to delete this mutex sometime. How??? One
97 // suggestion is to call this during vkCreateInstance(), and then we
98 // can clean it up during vkDestroyInstance(). However, that requires
99 // that the layer have per-instance locks. We need to come back and
100 // address this soon.
101 loader_platform_thread_create_mutex(&globalLock);
102 globalLockInitialized = 1;
103 }
104}
105
106static void writePPM( const char *filename, VkImage image1)
107{
108 VkImage image2;
109 VkResult err;
110 int x, y;
111 const char *ptr;
112 VkDeviceMemory mem2;
113 VkCmdBuffer cmdBuffer;
114 VkDevice device = imageMap[image1]->device;
115 VkQueue queue = deviceMap[device]->queue;
116 int width = imageMap[image1]->imageExtent.width;
117 int height = imageMap[image1]->imageExtent.height;
118 VkFormat format = imageMap[image1]->format;
119 const VkImageSubresource sr = {VK_IMAGE_ASPECT_COLOR, 0, 0};
120 VkSubresourceLayout sr_layout;
David Pinedoeeca2a22015-06-18 17:03:14 -0600121 const VkImageCreateInfo imgCreateInfo = {
122 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
123 NULL,
124 VK_IMAGE_TYPE_2D,
125 format,
126 {width, height, 1},
127 1,
128 1,
129 1,
130 VK_IMAGE_TILING_LINEAR,
131 (VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT|VK_IMAGE_USAGE_STORAGE_BIT),
132 0
133 };
134 VkMemoryAllocInfo memAllocInfo = {
135 VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO,
136 NULL,
137 0, // allocationSize, queried later
138 (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
139 VK_MEMORY_PROPERTY_HOST_UNCACHED_BIT |
Mark Lobodzinski99d272a2015-07-02 17:09:57 -0600140 VK_MEMORY_PROPERTY_HOST_WRITE_COMBINED_BIT)
David Pinedoeeca2a22015-06-18 17:03:14 -0600141 };
142 const VkCmdBufferCreateInfo createCommandBufferInfo = {
143 VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO,
144 NULL,
145 deviceMap[device]->queueNodeIndex,
Chia-I Wu88eaa3b2015-06-26 15:34:39 +0800146 VK_CMD_BUFFER_LEVEL_PRIMARY,
David Pinedoeeca2a22015-06-18 17:03:14 -0600147 0
148 };
149 const VkCmdBufferBeginInfo cmdBufferBeginInfo = {
150 VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO,
151 NULL,
152 VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
153 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT,
154 };
155 const VkImageCopy imageCopyRegion = {
156 {VK_IMAGE_ASPECT_COLOR, 0, 0},
157 {0, 0, 0},
158 {VK_IMAGE_ASPECT_COLOR, 0, 0},
159 {0, 0, 0},
160 {width, height, 1}
161 };
162 VkMemoryRequirements memRequirements;
David Pinedoeeca2a22015-06-18 17:03:14 -0600163 uint32_t num_allocations = 0;
164 size_t num_alloc_size = sizeof(num_allocations);
David Pinedoc3256662015-06-30 13:08:37 -0600165 VkLayerDispatchTable* pTableDevice = get_dispatch_table(screenshot_device_table_map, device);
166 VkLayerDispatchTable* pTableQueue = get_dispatch_table(screenshot_device_table_map, queue);
David Pinedoeeca2a22015-06-18 17:03:14 -0600167 VkLayerDispatchTable* pTableCmdBuffer;
168
169 if (imageMap.empty() || imageMap.find(image1) == imageMap.end())
170 return;
171
172 // The VkImage image1 we are going to dump may not be mappable,
173 // and/or it may have a tiling mode of optimal rather than linear.
174 // To make sure we have an image that we can map and read linearly, we:
175 // create image2 that is mappable and linear
176 // copy image1 to image2
177 // map image2
178 // read from image2's mapped memeory.
179
180 err = pTableDevice->CreateImage(device, &imgCreateInfo, &image2);
181 assert(!err);
182
Tony Barbour426b9052015-06-24 16:06:58 -0600183 err = pTableDevice->GetObjectMemoryRequirements(device,
David Pinedoeeca2a22015-06-18 17:03:14 -0600184 VK_OBJECT_TYPE_IMAGE, image2,
Tony Barbour426b9052015-06-24 16:06:58 -0600185 &memRequirements);
David Pinedoeeca2a22015-06-18 17:03:14 -0600186 assert(!err);
187
188 memAllocInfo.allocationSize = memRequirements.size;
189 err = pTableDevice->AllocMemory(device, &memAllocInfo, &mem2);
190 assert(!err);
191
192 err = pTableQueue->BindObjectMemory(device, VK_OBJECT_TYPE_IMAGE, image2, mem2, 0);
193 assert(!err);
194
195 err = pTableDevice->CreateCommandBuffer(device, &createCommandBufferInfo, &cmdBuffer);
196 assert(!err);
197
198 screenshot_device_table_map.emplace(cmdBuffer, pTableDevice);
199 pTableCmdBuffer = screenshot_device_table_map[cmdBuffer];
200
201 err = pTableCmdBuffer->BeginCommandBuffer(cmdBuffer, &cmdBufferBeginInfo);
202 assert(!err);
203
204 pTableCmdBuffer->CmdCopyImage(cmdBuffer, image1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
205 image2, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &imageCopyRegion);
206
207 err = pTableCmdBuffer->EndCommandBuffer(cmdBuffer);
208 assert(!err);
209
210 err = pTableQueue->QueueSubmit(queue, 1, &cmdBuffer, VK_NULL_HANDLE);
211 assert(!err);
212
213 err = pTableQueue->QueueWaitIdle(queue);
214 assert(!err);
215
216 err = pTableDevice->DeviceWaitIdle(device);
217 assert(!err);
218
Tony Barbour426b9052015-06-24 16:06:58 -0600219 err = pTableDevice->GetImageSubresourceLayout(device, image2, &sr, &sr_layout);
David Pinedoeeca2a22015-06-18 17:03:14 -0600220 assert(!err);
221
222 err = pTableDevice->MapMemory(device, mem2, 0, 0, 0, (void **) &ptr );
223 assert(!err);
224
225 ptr += sr_layout.offset;
226
227 ofstream file(filename, ios::binary);
228
229 file << "P6\n";
230 file << width << "\n";
231 file << height << "\n";
232 file << 255 << "\n";
233
234 for (y = 0; y < height; y++) {
235 const unsigned int *row = (const unsigned int*) ptr;
236 if (format == VK_FORMAT_B8G8R8A8_UNORM)
237 {
238 for (x = 0; x < width; x++) {
239 unsigned int swapped;
240 swapped = (*row & 0xff00ff00) | (*row & 0x000000ff) << 16 | (*row & 0x00ff0000) >> 16;
241 file.write((char *)&swapped, 3);
242 row++;
243 }
244 }
245 else if (format == VK_FORMAT_R8G8B8A8_UNORM)
246 {
247 for (x = 0; x < width; x++) {
248 file.write((char *)row, 3);
249 row++;
250 }
251 }
252 else
253 {
254 // TODO: add support for addition formats
255 printf("Unrecognized image format\n");
256 break;
257 }
258 ptr += sr_layout.rowPitch;
259 }
260 file.close();
261
262 // Clean up
263 err = pTableDevice->UnmapMemory(device, mem2);
264 assert(!err);
265 err = pTableDevice->FreeMemory(device, mem2);
266 assert(!err);
267 err = pTableDevice->DestroyObject(device, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer);
268 assert(!err);
269}
270
271
David Pinedo8a4f5562015-06-19 13:48:18 -0600272static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
273{
274 uint32_t i, ext_idx;
275 VkLayerDispatchTable *pDisp = get_dispatch_table(screenshot_device_table_map, device);
276 deviceExtMap[pDisp].wsi_lunarg_enabled = false;
277 for (i = 0; i < pCreateInfo->extensionCount; i++) {
278 if (strcmp(pCreateInfo->pEnabledExtensions[i].name, VK_WSI_LUNARG_EXTENSION_NAME) == 0)
279 deviceExtMap[pDisp].wsi_lunarg_enabled = true;
280 }
281}
282
David Pinedoeeca2a22015-06-18 17:03:14 -0600283VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(
284 VkPhysicalDevice gpu,
285 const VkDeviceCreateInfo *pCreateInfo,
286 VkDevice *pDevice)
287{
Courtney Goeltzenleuchterbe637992015-06-25 18:01:43 -0600288 VkLayerDispatchTable *pDisp = get_dispatch_table(screenshot_device_table_map, *pDevice);
289 VkResult result = pDisp->CreateDevice(gpu, pCreateInfo, pDevice);
David Pinedoeeca2a22015-06-18 17:03:14 -0600290
David Pinedo8a4f5562015-06-19 13:48:18 -0600291 if (result == VK_SUCCESS) {
Jon Ashburn59f3dfc2015-07-06 15:09:36 -0600292 init_screenshot();
David Pinedo8a4f5562015-06-19 13:48:18 -0600293 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
294 }
295
David Pinedoeeca2a22015-06-18 17:03:14 -0600296 return result;
297}
298
Courtney Goeltzenleuchterbe637992015-06-25 18:01:43 -0600299/* TODO: Probably need a DestroyDevice as well */
300
David Pinedo8a4f5562015-06-19 13:48:18 -0600301#define SCREENSHOT_LAYER_EXT_ARRAY_SIZE 2
302static const VkExtensionProperties ssExts[SCREENSHOT_LAYER_EXT_ARRAY_SIZE] = {
David Pinedoeeca2a22015-06-18 17:03:14 -0600303 {
304 VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES,
305 "ScreenShot",
306 0x10,
307 "Layer: ScreenShot",
David Pinedo8a4f5562015-06-19 13:48:18 -0600308 }
309
David Pinedoeeca2a22015-06-18 17:03:14 -0600310};
Tony Barbour426b9052015-06-24 16:06:58 -0600311VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionCount(
312 uint32_t* pCount)
David Pinedoeeca2a22015-06-18 17:03:14 -0600313{
Tony Barbour426b9052015-06-24 16:06:58 -0600314 *pCount = SCREENSHOT_LAYER_EXT_ARRAY_SIZE;
David Pinedoeeca2a22015-06-18 17:03:14 -0600315 return VK_SUCCESS;
316}
317
Tony Barbour426b9052015-06-24 16:06:58 -0600318VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionProperties(
319 uint32_t extensionIndex,
320 VkExtensionProperties* pProperties)
David Pinedoeeca2a22015-06-18 17:03:14 -0600321{
Tony Barbour426b9052015-06-24 16:06:58 -0600322 /* This entrypoint is NOT going to init it's own dispatch table since loader calls here early */
323 if (extensionIndex >= SCREENSHOT_LAYER_EXT_ARRAY_SIZE)
324 return VK_ERROR_INVALID_VALUE;
David Pinedoeeca2a22015-06-18 17:03:14 -0600325
Tony Barbour426b9052015-06-24 16:06:58 -0600326 memcpy(pProperties, &ssExts[extensionIndex], sizeof(VkExtensionProperties));
David Pinedoeeca2a22015-06-18 17:03:14 -0600327
Tony Barbour426b9052015-06-24 16:06:58 -0600328 return VK_SUCCESS;
329}
330VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceExtensionCount(
331 VkPhysicalDevice gpu,
332 uint32_t* pCount)
333{
334 *pCount = SCREENSHOT_LAYER_EXT_ARRAY_SIZE;
335 return VK_SUCCESS;
336}
337
338VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceExtensionProperties(
339 VkPhysicalDevice gpu,
340 uint32_t extensionIndex,
341 VkExtensionProperties* pProperties)
342{
343 /* This entrypoint is NOT going to init it's own dispatch table since loader calls here early */
344
345 if (extensionIndex >= SCREENSHOT_LAYER_EXT_ARRAY_SIZE)
346 return VK_ERROR_INVALID_VALUE;
347 memcpy(pProperties, &ssExts[extensionIndex], sizeof(VkExtensionProperties));
David Pinedoeeca2a22015-06-18 17:03:14 -0600348
349 return VK_SUCCESS;
350}
351
352VK_LAYER_EXPORT VkResult VKAPI vkGetDeviceQueue(
353 VkDevice device,
354 uint32_t queueNodeIndex,
355 uint32_t queueIndex,
356 VkQueue *pQueue)
357{
358 VkLayerDispatchTable* pTable = screenshot_device_table_map[device];
359 VkResult result = get_dispatch_table(screenshot_device_table_map, device)->GetDeviceQueue(device, queueNodeIndex, queueIndex, pQueue);
360
361 loader_platform_thread_lock_mutex(&globalLock);
362 if (screenshotEnvQueried && screenshotFrames.empty()) {
363 // We are all done taking screenshots, so don't do anything else
364 loader_platform_thread_unlock_mutex(&globalLock);
365 return result;
366 }
367
368 if (result == VK_SUCCESS) {
369 screenshot_device_table_map.emplace(*pQueue, pTable);
370
371 // Create a mapping for the swapchain object into the dispatch table
372 DeviceMapStruct *deviceMapElem = new DeviceMapStruct;
373 deviceMapElem->queue = *pQueue;
374 deviceMapElem->queueNodeIndex = queueNodeIndex;
375 deviceMapElem->queueIndex = queueIndex;
376 deviceMap.insert(make_pair(device, deviceMapElem));
377 }
378 loader_platform_thread_unlock_mutex(&globalLock);
379 return result;
380}
381
382VK_LAYER_EXPORT VkResult VKAPI vkCreateSwapChainWSI(
383 VkDevice device,
384 const VkSwapChainCreateInfoWSI *pCreateInfo,
385 VkSwapChainWSI *pSwapChain)
386{
387 VkLayerDispatchTable* pTable = screenshot_device_table_map[device];
388 VkResult result = get_dispatch_table(screenshot_device_table_map, device)->CreateSwapChainWSI(device, pCreateInfo, pSwapChain);
389
390 loader_platform_thread_lock_mutex(&globalLock);
391 if (screenshotEnvQueried && screenshotFrames.empty()) {
392 // We are all done taking screenshots, so don't do anything else
393 loader_platform_thread_unlock_mutex(&globalLock);
394 return result;
395 }
396
397 if (result == VK_SUCCESS)
398 {
399 // Create a mapping for a swapchain to a device, image extent, and format
400 SwapchainMapStruct *swapchainMapElem = new SwapchainMapStruct;
401 swapchainMapElem->device = device;
402 swapchainMapElem->imageExtent = pCreateInfo->imageExtent;
403 swapchainMapElem->format = pCreateInfo->imageFormat;
404 swapchainMap.insert(make_pair(*pSwapChain, swapchainMapElem));
405
406 // Create a mapping for the swapchain object into the dispatch table
407 screenshot_device_table_map.emplace(*pSwapChain, pTable);
408 }
409 loader_platform_thread_unlock_mutex(&globalLock);
410
411 return result;
412}
413
414VK_LAYER_EXPORT VkResult VKAPI vkGetSwapChainInfoWSI(
415 VkSwapChainWSI swapChain,
416 VkSwapChainInfoTypeWSI infoType,
417 size_t *pDataSize,
418 void *pData)
419{
420 VkResult result = get_dispatch_table(screenshot_device_table_map, swapChain)->GetSwapChainInfoWSI(swapChain, infoType, pDataSize, pData);
421
422 loader_platform_thread_lock_mutex(&globalLock);
423 if (screenshotEnvQueried && screenshotFrames.empty()) {
424 // We are all done taking screenshots, so don't do anything else
425 loader_platform_thread_unlock_mutex(&globalLock);
426 return result;
427 }
428
429 if (result == VK_SUCCESS &&
430 !swapchainMap.empty() && swapchainMap.find(swapChain) != swapchainMap.end())
431 {
432 VkSwapChainImageInfoWSI *swapChainImageInfo = (VkSwapChainImageInfoWSI *)pData;
433 for (int i=0; i<*pDataSize/sizeof(VkSwapChainImageInfoWSI); i++,swapChainImageInfo++)
434 {
435 // Create a mapping for an image to a device, image extent, and format
436 ImageMapStruct *imageMapElem = new ImageMapStruct;
437 imageMapElem->device = swapchainMap[swapChain]->device;
438 imageMapElem->imageExtent = swapchainMap[swapChain]->imageExtent;
439 imageMapElem->format = swapchainMap[swapChain]->format;
440 imageMap.insert(make_pair(swapChainImageInfo->image, imageMapElem));
441 }
442 }
443 loader_platform_thread_unlock_mutex(&globalLock);
444 return result;
445}
446
447VK_LAYER_EXPORT VkResult VKAPI vkQueuePresentWSI(VkQueue queue, const VkPresentInfoWSI* pPresentInfo)
448{
449 static int frameNumber = 0;
450 VkResult result = get_dispatch_table(screenshot_device_table_map, queue)->QueuePresentWSI(queue, pPresentInfo);
451
452 loader_platform_thread_lock_mutex(&globalLock);
453
454 if (!screenshotEnvQueried)
455 {
456 const char *_vk_screenshot = getenv("_VK_SCREENSHOT");
457 if (_vk_screenshot && *_vk_screenshot)
458 {
459 string spec(_vk_screenshot), word;
460 size_t start = 0, comma = 0;
461
462 while (start < spec.size()) {
463 int frameToAdd;
464 comma = spec.find(',', start);
465 if (comma == string::npos)
466 word = string(spec, start);
467 else
468 word = string(spec, start, comma - start);
469 frameToAdd=atoi(word.c_str());
470 // Add the frame number to list, but only do it if the word started with a digit and if
471 // it's not already in the list
472 if (*(word.c_str()) >= '0' && *(word.c_str()) <= '9' &&
473 find(screenshotFrames.begin(), screenshotFrames.end(), frameToAdd) == screenshotFrames.end())
474 {
475 screenshotFrames.push_back(frameToAdd);
476 }
477 if (comma == string::npos)
478 break;
479 start = comma + 1;
480 }
481 }
482 screenshotEnvQueried = true;
483 }
484
485
486 if (result == VK_SUCCESS && !screenshotFrames.empty())
487 {
488 vector<int>::iterator it;
489 it = find(screenshotFrames.begin(), screenshotFrames.end(), frameNumber);
490 if (it != screenshotFrames.end())
491 {
492 string fileName;
493 fileName = to_string(frameNumber) + ".ppm";
494 writePPM(fileName.c_str(), pPresentInfo->image);
495 screenshotFrames.erase(it);
496
497 if (screenshotFrames.empty())
498 {
499 // Free all our maps since we are done with them.
500 for (auto it = swapchainMap.begin(); it != swapchainMap.end(); it++)
501 {
502 SwapchainMapStruct *swapchainMapElem = it->second;
503 delete swapchainMapElem;
504 }
505 for (auto it = imageMap.begin(); it != imageMap.end(); it++)
506 {
507 ImageMapStruct *imageMapElem = it->second;
508 delete imageMapElem;
509 }
510 for (auto it = deviceMap.begin(); it != deviceMap.end(); it++)
511 {
512 DeviceMapStruct *deviceMapElem = it->second;
513 delete deviceMapElem;
514 }
515 swapchainMap.clear();
516 imageMap.clear();
517 deviceMap.clear();
518 }
519 }
520 }
521 frameNumber++;
522 loader_platform_thread_unlock_mutex(&globalLock);
523 return result;
524}
525
526VK_LAYER_EXPORT void* VKAPI vkGetDeviceProcAddr(
527 VkDevice dev,
528 const char *funcName)
529{
530 void *fptr;
531
532 if (dev == NULL) {
533 return NULL;
534 }
535
536 /* loader uses this to force layer initialization; device object is wrapped */
537 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
538 initDeviceTable(screenshot_device_table_map, (const VkBaseLayerObject *) dev);
539 return (void *) vkGetDeviceProcAddr;
540 }
Courtney Goeltzenleuchterbe637992015-06-25 18:01:43 -0600541 if (!strcmp(funcName, "vkCreateDevice"))
542 return (void*) vkCreateDevice;
543
David Pinedoeeca2a22015-06-18 17:03:14 -0600544 if (!strcmp(funcName, "vkGetDeviceQueue"))
545 return (void*) vkGetDeviceQueue;
David Pinedoeeca2a22015-06-18 17:03:14 -0600546
Tony Barbour426b9052015-06-24 16:06:58 -0600547 if (!strcmp(funcName, "vkGetGlobalExtensionCount"))
548 return (void*) vkGetGlobalExtensionCount;
549
550 if (!strcmp(funcName, "vkGetPhysicalDeviceExtensionCount"))
551 return (void*) vkGetPhysicalDeviceExtensionCount;
552
553 if (!strcmp(funcName, "vkGetGlobalExtensionProperties"))
554 return (void*) vkGetGlobalExtensionProperties;
555
556 if (!strcmp(funcName, "vkGetPhysicalDeviceExtensionProperties"))
557 return (void*) vkGetPhysicalDeviceExtensionProperties;
558
David Pinedo8a4f5562015-06-19 13:48:18 -0600559 VkLayerDispatchTable *pDisp = get_dispatch_table(screenshot_device_table_map, dev);
560 if (deviceExtMap.size() == 0 || deviceExtMap[pDisp].wsi_lunarg_enabled)
561 {
562 if (!strcmp(funcName, "vkCreateSwapChainWSI"))
563 return (void*) vkCreateSwapChainWSI;
564 if (!strcmp(funcName, "vkGetSwapChainInfoWSI"))
565 return (void*) vkGetSwapChainInfoWSI;
566 if (!strcmp(funcName, "vkQueuePresentWSI"))
567 return (void*) vkQueuePresentWSI;
568 }
569
570 if (pDisp->GetDeviceProcAddr == NULL)
David Pinedoeeca2a22015-06-18 17:03:14 -0600571 return NULL;
David Pinedo8a4f5562015-06-19 13:48:18 -0600572 return pDisp->GetDeviceProcAddr(dev, funcName);
David Pinedoeeca2a22015-06-18 17:03:14 -0600573}
574