blob: 6a85aeb5cff294a86df99560207e278364106815 [file] [log] [blame]
David Pinedofb5b5382015-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 Ehlisb835d1b2015-07-03 10:34:49 -060040#include "vk_loader_platform.h"
David Pinedofb5b5382015-06-18 17:03:14 -060041#include "vk_dispatch_table_helper.h"
42#include "vk_struct_string_helper_cpp.h"
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -060043#include "vk_layer_config.h"
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -060044#include "vk_layer_table.h"
Courtney Goeltzenleuchtera6db3462015-07-07 11:25:43 -060045#include "vk_layer_extension_utils.h"
David Pinedofb5b5382015-06-18 17:03:14 -060046
David Pinedobcd0e792015-06-19 13:48:18 -060047
48struct devExts {
Ian Elliott1064fe32015-07-06 14:31:32 -060049 bool wsi_enabled;
David Pinedobcd0e792015-06-19 13:48:18 -060050};
51static std::unordered_map<void *, struct devExts> deviceExtMap;
David Pinedofb5b5382015-06-18 17:03:14 -060052static device_table_map screenshot_device_table_map;
David Pinedofb5b5382015-06-18 17:03:14 -060053
54static int globalLockInitialized = 0;
55static loader_platform_thread_mutex globalLock;
56
Cody Northrop49f885c2015-09-01 10:18:45 -060057// unordered map: associates a swap chain with a device, image extent, format, and
David Pinedo8897e192015-07-31 10:56:20 -060058// list of images
David Pinedofb5b5382015-06-18 17:03:14 -060059typedef struct
60{
61 VkDevice device;
62 VkExtent2D imageExtent;
63 VkFormat format;
David Pinedo8897e192015-07-31 10:56:20 -060064 VkImage *imageList;
David Pinedofb5b5382015-06-18 17:03:14 -060065} SwapchainMapStruct;
Chia-I Wue2fc5522015-10-26 20:04:44 +080066static unordered_map<VkSwapchainKHR, SwapchainMapStruct *> swapchainMap;
David Pinedofb5b5382015-06-18 17:03:14 -060067
Cody Northrop49f885c2015-09-01 10:18:45 -060068// unordered map: associates an image with a device, image extent, and format
David Pinedofb5b5382015-06-18 17:03:14 -060069typedef struct
70{
71 VkDevice device;
72 VkExtent2D imageExtent;
73 VkFormat format;
74} ImageMapStruct;
Chia-I Wue2fc5522015-10-26 20:04:44 +080075static unordered_map<VkImage, ImageMapStruct *> imageMap;
David Pinedofb5b5382015-06-18 17:03:14 -060076
Chia-I Wu3432a0c2015-10-27 18:04:07 +080077// unordered map: associates a device with a queue, commandPool, and physical device
David Pinedofb5b5382015-06-18 17:03:14 -060078typedef struct
79{
80 VkQueue queue;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080081 VkCommandPool commandPool;
Cody Northrop49f885c2015-09-01 10:18:45 -060082 VkPhysicalDevice physicalDevice;
David Pinedofb5b5382015-06-18 17:03:14 -060083} DeviceMapStruct;
84static unordered_map<VkDevice, DeviceMapStruct *> deviceMap;
85
Cody Northrop49f885c2015-09-01 10:18:45 -060086// unordered map: associates a physical device with an instance
87typedef struct
88{
89 VkInstance instance;
90} PhysDeviceMapStruct;
91static unordered_map<VkPhysicalDevice, PhysDeviceMapStruct *> physDeviceMap;
92
David Pinedofb5b5382015-06-18 17:03:14 -060093// List of frames to we will get a screenshot of
94static vector<int> screenshotFrames;
95
96// Flag indicating we have queried _VK_SCREENSHOT env var
97static bool screenshotEnvQueried = false;
98
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060099static bool memory_type_from_properties(
Cody Northrop49f885c2015-09-01 10:18:45 -0600100 VkPhysicalDeviceMemoryProperties *memory_properties,
101 uint32_t typeBits,
Tony Barbouraf392d02015-10-15 12:42:56 -0600102 VkFlags requirements_mask,
Cody Northrop49f885c2015-09-01 10:18:45 -0600103 uint32_t *typeIndex)
104{
105 // Search memtypes to find first index with those properties
106 for (uint32_t i = 0; i < 32; i++) {
107 if ((typeBits & 1) == 1) {
108 // Type is available, does it match user properties?
Tony Barbouraf392d02015-10-15 12:42:56 -0600109 if ((memory_properties->memoryTypes[i].propertyFlags & requirements_mask) == requirements_mask) {
Cody Northrop49f885c2015-09-01 10:18:45 -0600110 *typeIndex = i;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600111 return true;
Cody Northrop49f885c2015-09-01 10:18:45 -0600112 }
113 }
114 typeBits >>= 1;
115 }
116 // No memory types matched, return failure
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600117 return false;
Cody Northrop49f885c2015-09-01 10:18:45 -0600118}
119
David Pinedofb5b5382015-06-18 17:03:14 -0600120static void init_screenshot()
121{
David Pinedofb5b5382015-06-18 17:03:14 -0600122 if (!globalLockInitialized)
123 {
124 // TODO/TBD: Need to delete this mutex sometime. How??? One
125 // suggestion is to call this during vkCreateInstance(), and then we
126 // can clean it up during vkDestroyInstance(). However, that requires
127 // that the layer have per-instance locks. We need to come back and
128 // address this soon.
129 loader_platform_thread_create_mutex(&globalLock);
130 globalLockInitialized = 1;
131 }
132}
133
134static void writePPM( const char *filename, VkImage image1)
135{
136 VkImage image2;
137 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600138 bool pass;
David Pinedofb5b5382015-06-18 17:03:14 -0600139 int x, y;
140 const char *ptr;
141 VkDeviceMemory mem2;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800142 VkCommandBuffer commandBuffer;
Chia-I Wue2fc5522015-10-26 20:04:44 +0800143 VkDevice device = imageMap[image1]->device;
Cody Northrop49f885c2015-09-01 10:18:45 -0600144 VkPhysicalDevice physicalDevice = deviceMap[device]->physicalDevice;
145 VkInstance instance = physDeviceMap[physicalDevice]->instance;
David Pinedofb5b5382015-06-18 17:03:14 -0600146 VkQueue queue = deviceMap[device]->queue;
Chia-I Wue2fc5522015-10-26 20:04:44 +0800147 int width = imageMap[image1]->imageExtent.width;
148 int height = imageMap[image1]->imageExtent.height;
149 VkFormat format = imageMap[image1]->format;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -0600150 const VkImageSubresource sr = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0};
David Pinedofb5b5382015-06-18 17:03:14 -0600151 VkSubresourceLayout sr_layout;
David Pinedofb5b5382015-06-18 17:03:14 -0600152 const VkImageCreateInfo imgCreateInfo = {
153 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
154 NULL,
Chia-I Wu439c0772015-10-26 17:00:46 +0800155 0,
David Pinedofb5b5382015-06-18 17:03:14 -0600156 VK_IMAGE_TYPE_2D,
157 format,
158 {width, height, 1},
159 1,
160 1,
161 1,
162 VK_IMAGE_TILING_LINEAR,
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800163 (VK_IMAGE_USAGE_TRANSFER_DST_BIT|VK_IMAGE_USAGE_STORAGE_BIT),
David Pinedofb5b5382015-06-18 17:03:14 -0600164 };
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800165 VkMemoryAllocateInfo memAllocInfo = {
David Pinedofb5b5382015-06-18 17:03:14 -0600166 VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO,
167 NULL,
168 0, // allocationSize, queried later
Cody Northrop488f5472015-09-01 11:47:50 -0600169 0 // memoryTypeIndex, queried later
David Pinedofb5b5382015-06-18 17:03:14 -0600170 };
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800171 const VkCommandBufferAllocateInfo allocCommandBufferInfo = {
172 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOC_INFO,
David Pinedofb5b5382015-06-18 17:03:14 -0600173 NULL,
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800174 deviceMap[device]->commandPool,
175 VK_COMMAND_BUFFER_LEVEL_PRIMARY,
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -0600176 1
David Pinedofb5b5382015-06-18 17:03:14 -0600177 };
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800178 const VkCommandBufferBeginInfo commandBufferBeginInfo = {
179 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
David Pinedofb5b5382015-06-18 17:03:14 -0600180 NULL,
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800181 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,
David Pinedofb5b5382015-06-18 17:03:14 -0600182 };
183 const VkImageCopy imageCopyRegion = {
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -0600184 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0},
David Pinedofb5b5382015-06-18 17:03:14 -0600185 {0, 0, 0},
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -0600186 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0},
David Pinedofb5b5382015-06-18 17:03:14 -0600187 {0, 0, 0},
188 {width, height, 1}
189 };
190 VkMemoryRequirements memRequirements;
David Pinedofb5b5382015-06-18 17:03:14 -0600191 uint32_t num_allocations = 0;
192 size_t num_alloc_size = sizeof(num_allocations);
David Pinedo68295872015-06-30 13:08:37 -0600193 VkLayerDispatchTable* pTableDevice = get_dispatch_table(screenshot_device_table_map, device);
194 VkLayerDispatchTable* pTableQueue = get_dispatch_table(screenshot_device_table_map, queue);
Cody Northrop49f885c2015-09-01 10:18:45 -0600195 VkLayerInstanceDispatchTable* pInstanceTable;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800196 VkLayerDispatchTable* pTableCommandBuffer;
Cody Northrop49f885c2015-09-01 10:18:45 -0600197 VkPhysicalDeviceMemoryProperties memory_properties;
David Pinedofb5b5382015-06-18 17:03:14 -0600198
Chia-I Wue2fc5522015-10-26 20:04:44 +0800199 if (imageMap.empty() || imageMap.find(image1) == imageMap.end())
David Pinedofb5b5382015-06-18 17:03:14 -0600200 return;
201
202 // The VkImage image1 we are going to dump may not be mappable,
203 // and/or it may have a tiling mode of optimal rather than linear.
204 // To make sure we have an image that we can map and read linearly, we:
205 // create image2 that is mappable and linear
206 // copy image1 to image2
207 // map image2
208 // read from image2's mapped memeory.
209
Chia-I Wuf7458c52015-10-26 21:10:41 +0800210 err = pTableDevice->CreateImage(device, &imgCreateInfo, NULL, &image2);
David Pinedofb5b5382015-06-18 17:03:14 -0600211 assert(!err);
212
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600213 pTableDevice->GetImageMemoryRequirements(device, image2, &memRequirements);
David Pinedofb5b5382015-06-18 17:03:14 -0600214
215 memAllocInfo.allocationSize = memRequirements.size;
Cody Northrop49f885c2015-09-01 10:18:45 -0600216 pInstanceTable = instance_dispatch_table(instance);
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600217 pInstanceTable->GetPhysicalDeviceMemoryProperties(physicalDevice, &memory_properties);
Cody Northrop49f885c2015-09-01 10:18:45 -0600218
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600219 pass = memory_type_from_properties(&memory_properties,
Cody Northrop49f885c2015-09-01 10:18:45 -0600220 memRequirements.memoryTypeBits,
Cody Northrop488f5472015-09-01 11:47:50 -0600221 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
Cody Northrop49f885c2015-09-01 10:18:45 -0600222 &memAllocInfo.memoryTypeIndex);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600223 assert(pass);
Cody Northrop49f885c2015-09-01 10:18:45 -0600224
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800225 err = pTableDevice->AllocateMemory(device, &memAllocInfo, NULL, &mem2);
David Pinedofb5b5382015-06-18 17:03:14 -0600226 assert(!err);
227
David Pinedo8897e192015-07-31 10:56:20 -0600228 err = pTableQueue->BindImageMemory(device, image2, mem2, 0);
David Pinedofb5b5382015-06-18 17:03:14 -0600229 assert(!err);
230
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800231 err = pTableDevice->AllocateCommandBuffers(device, &allocCommandBufferInfo, &commandBuffer);
David Pinedofb5b5382015-06-18 17:03:14 -0600232 assert(!err);
233
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800234 screenshot_device_table_map.emplace(commandBuffer, pTableDevice);
235 pTableCommandBuffer = screenshot_device_table_map[commandBuffer];
David Pinedofb5b5382015-06-18 17:03:14 -0600236
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800237 err = pTableCommandBuffer->BeginCommandBuffer(commandBuffer, &commandBufferBeginInfo);
David Pinedofb5b5382015-06-18 17:03:14 -0600238 assert(!err);
239
Cody Northrop488f5472015-09-01 11:47:50 -0600240 // TODO: We need to transition images to match these layouts, then restore the original layouts
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800241 pTableCommandBuffer->CmdCopyImage(commandBuffer, image1, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
242 image2, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &imageCopyRegion);
David Pinedofb5b5382015-06-18 17:03:14 -0600243
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800244 err = pTableCommandBuffer->EndCommandBuffer(commandBuffer);
David Pinedofb5b5382015-06-18 17:03:14 -0600245 assert(!err);
246
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -0600247 VkFence nullFence = { VK_NULL_HANDLE };
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600248 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +0800249 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
250 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800251 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600252 submit_info.pWaitSemaphores = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800253 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800254 submit_info.pCommandBuffers = &commandBuffer;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800255 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600256 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -0600257
258 err = pTableQueue->QueueSubmit(queue, 1, &submit_info, nullFence);
David Pinedofb5b5382015-06-18 17:03:14 -0600259 assert(!err);
260
261 err = pTableQueue->QueueWaitIdle(queue);
262 assert(!err);
263
264 err = pTableDevice->DeviceWaitIdle(device);
265 assert(!err);
266
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600267 pTableDevice->GetImageSubresourceLayout(device, image2, &sr, &sr_layout);
David Pinedofb5b5382015-06-18 17:03:14 -0600268
269 err = pTableDevice->MapMemory(device, mem2, 0, 0, 0, (void **) &ptr );
270 assert(!err);
271
272 ptr += sr_layout.offset;
273
274 ofstream file(filename, ios::binary);
275
276 file << "P6\n";
277 file << width << "\n";
278 file << height << "\n";
279 file << 255 << "\n";
280
281 for (y = 0; y < height; y++) {
282 const unsigned int *row = (const unsigned int*) ptr;
283 if (format == VK_FORMAT_B8G8R8A8_UNORM)
284 {
285 for (x = 0; x < width; x++) {
286 unsigned int swapped;
287 swapped = (*row & 0xff00ff00) | (*row & 0x000000ff) << 16 | (*row & 0x00ff0000) >> 16;
288 file.write((char *)&swapped, 3);
289 row++;
290 }
291 }
292 else if (format == VK_FORMAT_R8G8B8A8_UNORM)
293 {
294 for (x = 0; x < width; x++) {
295 file.write((char *)row, 3);
296 row++;
297 }
298 }
299 else
300 {
David Pinedo8897e192015-07-31 10:56:20 -0600301 // TODO: add support for additional formats
David Pinedofb5b5382015-06-18 17:03:14 -0600302 printf("Unrecognized image format\n");
303 break;
304 }
305 ptr += sr_layout.rowPitch;
306 }
307 file.close();
308
309 // Clean up
Mark Lobodzinski2141f652015-09-07 13:59:43 -0600310 pTableDevice->UnmapMemory(device, mem2);
Chia-I Wuf7458c52015-10-26 21:10:41 +0800311 pTableDevice->FreeMemory(device, mem2, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800312 pTableDevice->FreeCommandBuffers(device, deviceMap[device]->commandPool, 1, &commandBuffer);
David Pinedofb5b5382015-06-18 17:03:14 -0600313}
314
315
David Pinedobcd0e792015-06-19 13:48:18 -0600316static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
317{
Cody Northropd2ad0342015-08-05 11:15:02 -0600318 uint32_t i;
David Pinedobcd0e792015-06-19 13:48:18 -0600319 VkLayerDispatchTable *pDisp = get_dispatch_table(screenshot_device_table_map, device);
Jon Ashburn8acd2332015-09-16 18:08:32 -0600320 PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr;
321 pDisp->GetSurfacePropertiesKHR = (PFN_vkGetSurfacePropertiesKHR) gpa(device, "vkGetSurfacePropertiesKHR");
322 pDisp->GetSurfaceFormatsKHR = (PFN_vkGetSurfaceFormatsKHR) gpa(device, "vkGetSurfaceFormatsKHR");
323 pDisp->GetSurfacePresentModesKHR = (PFN_vkGetSurfacePresentModesKHR) gpa(device, "vkGetSurfacePresentModesKHR");
324 pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR) gpa(device, "vkCreateSwapchainKHR");
325 pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR) gpa(device, "vkDestroySwapchainKHR");
326 pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR) gpa(device, "vkGetSwapchainImagesKHR");
327 pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR) gpa(device, "vkAcquireNextImageKHR");
328 pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR) gpa(device, "vkQueuePresentKHR");
Ian Elliott1064fe32015-07-06 14:31:32 -0600329 deviceExtMap[pDisp].wsi_enabled = false;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800330 for (i = 0; i < pCreateInfo->enabledExtensionNameCount; i++) {
Ian Elliott7e40db92015-08-21 15:09:33 -0600331 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_EXT_KHR_DEVICE_SWAPCHAIN_EXTENSION_NAME) == 0)
Ian Elliott1064fe32015-07-06 14:31:32 -0600332 deviceExtMap[pDisp].wsi_enabled = true;
David Pinedobcd0e792015-06-19 13:48:18 -0600333 }
334}
335
David Pinedofb5b5382015-06-18 17:03:14 -0600336VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(
337 VkPhysicalDevice gpu,
338 const VkDeviceCreateInfo *pCreateInfo,
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800339 const VkAllocationCallbacks* pAllocator,
David Pinedofb5b5382015-06-18 17:03:14 -0600340 VkDevice *pDevice)
341{
Courtney Goeltzenleuchterca173b82015-06-25 18:01:43 -0600342 VkLayerDispatchTable *pDisp = get_dispatch_table(screenshot_device_table_map, *pDevice);
Chia-I Wuf7458c52015-10-26 21:10:41 +0800343 VkResult result = pDisp->CreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
David Pinedofb5b5382015-06-18 17:03:14 -0600344
David Pinedobcd0e792015-06-19 13:48:18 -0600345 if (result == VK_SUCCESS) {
Jon Ashburnec105332015-07-06 15:09:36 -0600346 init_screenshot();
David Pinedobcd0e792015-06-19 13:48:18 -0600347 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Cody Northrop49f885c2015-09-01 10:18:45 -0600348 // Create a mapping from a device to a physicalDevice
349 if (deviceMap[*pDevice] == NULL)
350 {
351 DeviceMapStruct *deviceMapElem = new DeviceMapStruct;
352 deviceMap[*pDevice] = deviceMapElem;
353 }
354 deviceMap[*pDevice]->physicalDevice = gpu;
David Pinedobcd0e792015-06-19 13:48:18 -0600355 }
356
David Pinedofb5b5382015-06-18 17:03:14 -0600357 return result;
358}
359
Cody Northrop49f885c2015-09-01 10:18:45 -0600360VK_LAYER_EXPORT VkResult VKAPI vkEnumeratePhysicalDevices(
361 VkInstance instance,
362 uint32_t* pPhysicalDeviceCount,
363 VkPhysicalDevice* pPhysicalDevices)
364{
365 VkResult result;
366
367 VkLayerInstanceDispatchTable* pTable = instance_dispatch_table(instance);
368 result = pTable->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
Tobin Ehlisbe427742015-09-08 08:59:48 -0600369 if (result==VK_SUCCESS && *pPhysicalDeviceCount > 0 && pPhysicalDevices)
Cody Northrop49f885c2015-09-01 10:18:45 -0600370 {
371 for (uint32_t i=0; i<*pPhysicalDeviceCount ; i++)
372 {
373 // Create a mapping from a physicalDevice to an instance
374 if (physDeviceMap[pPhysicalDevices[i]] == NULL)
375 {
376 PhysDeviceMapStruct *physDeviceMapElem = new PhysDeviceMapStruct;
377 physDeviceMap[pPhysicalDevices[i]] = physDeviceMapElem;
378 }
379 physDeviceMap[pPhysicalDevices[i]]->instance = instance;
380 }
381 }
382 return result;
383}
384
Courtney Goeltzenleuchterca173b82015-06-25 18:01:43 -0600385/* TODO: Probably need a DestroyDevice as well */
386
Courtney Goeltzenleuchtera6db3462015-07-07 11:25:43 -0600387static const VkLayerProperties ss_device_layers[] = {
David Pinedofb5b5382015-06-18 17:03:14 -0600388 {
David Pinedofb5b5382015-06-18 17:03:14 -0600389 "ScreenShot",
Courtney Goeltzenleuchtera6db3462015-07-07 11:25:43 -0600390 VK_API_VERSION,
391 VK_MAKE_VERSION(0, 1, 0),
David Pinedofb5b5382015-06-18 17:03:14 -0600392 "Layer: ScreenShot",
David Pinedobcd0e792015-06-19 13:48:18 -0600393 }
David Pinedofb5b5382015-06-18 17:03:14 -0600394};
David Pinedofb5b5382015-06-18 17:03:14 -0600395
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -0600396VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceExtensionProperties(
Courtney Goeltzenleuchtera6db3462015-07-07 11:25:43 -0600397 const char *pLayerName,
398 uint32_t *pCount,
399 VkExtensionProperties* pProperties)
David Pinedofb5b5382015-06-18 17:03:14 -0600400{
Courtney Goeltzenleuchtera6db3462015-07-07 11:25:43 -0600401 /* ScreenShot does not have any global extensions */
402 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
Tony Barbour59a47322015-06-24 16:06:58 -0600403}
Courtney Goeltzenleuchtera6db3462015-07-07 11:25:43 -0600404
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -0600405VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceLayerProperties(
Courtney Goeltzenleuchtera6db3462015-07-07 11:25:43 -0600406 uint32_t *pCount,
407 VkLayerProperties* pProperties)
Tony Barbour59a47322015-06-24 16:06:58 -0600408{
Courtney Goeltzenleuchtera6db3462015-07-07 11:25:43 -0600409 /* ScreenShot does not have any global layers */
410 return util_GetLayerProperties(0, NULL,
411 pCount, pProperties);
Tony Barbour59a47322015-06-24 16:06:58 -0600412}
413
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -0600414VK_LAYER_EXPORT VkResult VKAPI vkEnumerateDeviceExtensionProperties(
Courtney Goeltzenleuchtera6db3462015-07-07 11:25:43 -0600415 VkPhysicalDevice physicalDevice,
416 const char* pLayerName,
417 uint32_t* pCount,
418 VkExtensionProperties* pProperties)
Tony Barbour59a47322015-06-24 16:06:58 -0600419{
Courtney Goeltzenleuchtera6db3462015-07-07 11:25:43 -0600420 /* ScreenShot does not have any physical device extensions */
421 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
422}
Tony Barbour59a47322015-06-24 16:06:58 -0600423
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -0600424VK_LAYER_EXPORT VkResult VKAPI vkEnumerateDeviceLayerProperties(
Courtney Goeltzenleuchtera6db3462015-07-07 11:25:43 -0600425 VkPhysicalDevice physicalDevice,
426 uint32_t* pCount,
427 VkLayerProperties* pProperties)
428{
429 return util_GetLayerProperties(ARRAY_SIZE(ss_device_layers),
430 ss_device_layers,
431 pCount, pProperties);
David Pinedofb5b5382015-06-18 17:03:14 -0600432}
433
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600434VK_LAYER_EXPORT void VKAPI vkGetDeviceQueue(
David Pinedofb5b5382015-06-18 17:03:14 -0600435 VkDevice device,
436 uint32_t queueNodeIndex,
437 uint32_t queueIndex,
438 VkQueue *pQueue)
439{
440 VkLayerDispatchTable* pTable = screenshot_device_table_map[device];
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600441 get_dispatch_table(screenshot_device_table_map, device)->GetDeviceQueue(device, queueNodeIndex, queueIndex, pQueue);
David Pinedofb5b5382015-06-18 17:03:14 -0600442
443 loader_platform_thread_lock_mutex(&globalLock);
444 if (screenshotEnvQueried && screenshotFrames.empty()) {
445 // We are all done taking screenshots, so don't do anything else
446 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600447 return;
David Pinedofb5b5382015-06-18 17:03:14 -0600448 }
449
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600450 screenshot_device_table_map.emplace(*pQueue, pTable);
David Pinedofb5b5382015-06-18 17:03:14 -0600451
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600452 // Create a mapping from a device to a queue
453 if (deviceMap[device] == NULL)
454 {
455 DeviceMapStruct *deviceMapElem = new DeviceMapStruct;
456 deviceMap[device] = deviceMapElem;
David Pinedofb5b5382015-06-18 17:03:14 -0600457 }
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600458 deviceMap[device]->queue = *pQueue;
David Pinedofb5b5382015-06-18 17:03:14 -0600459 loader_platform_thread_unlock_mutex(&globalLock);
David Pinedofb5b5382015-06-18 17:03:14 -0600460}
461
David Pinedo8897e192015-07-31 10:56:20 -0600462VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandPool(
463 VkDevice device,
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800464 const VkCommandPoolCreateInfo *pCreateInfo,
465 const VkAllocationCallbacks* pAllocator,
466 VkCommandPool *pCommandPool)
David Pinedo8897e192015-07-31 10:56:20 -0600467{
468 VkLayerDispatchTable* pTable = screenshot_device_table_map[device];
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800469 VkResult result = get_dispatch_table(screenshot_device_table_map, device)->CreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
David Pinedo8897e192015-07-31 10:56:20 -0600470
471 loader_platform_thread_lock_mutex(&globalLock);
472 if (screenshotEnvQueried && screenshotFrames.empty()) {
473 // We are all done taking screenshots, so don't do anything else
474 loader_platform_thread_unlock_mutex(&globalLock);
475 return result;
476 }
477
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800478 // Create a mapping from a device to a commandPool
Cody Northrop49f885c2015-09-01 10:18:45 -0600479 if (deviceMap[device] == NULL)
480 {
481 DeviceMapStruct *deviceMapElem = new DeviceMapStruct;
482 deviceMap[device] = deviceMapElem;
483 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800484 deviceMap[device]->commandPool = *pCommandPool;
David Pinedo8897e192015-07-31 10:56:20 -0600485 loader_platform_thread_unlock_mutex(&globalLock);
486 return result;
487}
488
Ian Elliott7e40db92015-08-21 15:09:33 -0600489VK_LAYER_EXPORT VkResult VKAPI vkCreateSwapchainKHR(
David Pinedofb5b5382015-06-18 17:03:14 -0600490 VkDevice device,
Ian Elliott7e40db92015-08-21 15:09:33 -0600491 const VkSwapchainCreateInfoKHR *pCreateInfo,
492 VkSwapchainKHR *pSwapchain)
David Pinedofb5b5382015-06-18 17:03:14 -0600493{
494 VkLayerDispatchTable* pTable = screenshot_device_table_map[device];
Ian Elliott7e40db92015-08-21 15:09:33 -0600495 VkResult result = get_dispatch_table(screenshot_device_table_map, device)->CreateSwapchainKHR(device, pCreateInfo, pSwapchain);
David Pinedofb5b5382015-06-18 17:03:14 -0600496
497 loader_platform_thread_lock_mutex(&globalLock);
498 if (screenshotEnvQueried && screenshotFrames.empty()) {
499 // We are all done taking screenshots, so don't do anything else
500 loader_platform_thread_unlock_mutex(&globalLock);
501 return result;
502 }
503
504 if (result == VK_SUCCESS)
505 {
506 // Create a mapping for a swapchain to a device, image extent, and format
507 SwapchainMapStruct *swapchainMapElem = new SwapchainMapStruct;
508 swapchainMapElem->device = device;
509 swapchainMapElem->imageExtent = pCreateInfo->imageExtent;
510 swapchainMapElem->format = pCreateInfo->imageFormat;
Chia-I Wue2fc5522015-10-26 20:04:44 +0800511 swapchainMap.insert(make_pair(*pSwapchain, swapchainMapElem));
David Pinedofb5b5382015-06-18 17:03:14 -0600512
513 // Create a mapping for the swapchain object into the dispatch table
Chia-I Wue2fc5522015-10-26 20:04:44 +0800514 screenshot_device_table_map.emplace((void *)pSwapchain, pTable);
David Pinedofb5b5382015-06-18 17:03:14 -0600515 }
516 loader_platform_thread_unlock_mutex(&globalLock);
517
518 return result;
519}
520
Ian Elliott7e40db92015-08-21 15:09:33 -0600521VK_LAYER_EXPORT VkResult VKAPI vkGetSwapchainImagesKHR(
Ian Elliott1064fe32015-07-06 14:31:32 -0600522 VkDevice device,
Ian Elliott7e40db92015-08-21 15:09:33 -0600523 VkSwapchainKHR swapchain,
Ian Elliott2b6b68a2015-08-07 14:11:14 -0600524 uint32_t* pCount,
Ian Elliott7e40db92015-08-21 15:09:33 -0600525 VkImage* pSwapchainImages)
David Pinedofb5b5382015-06-18 17:03:14 -0600526{
Ian Elliott7e40db92015-08-21 15:09:33 -0600527 VkResult result = get_dispatch_table(screenshot_device_table_map, device)->GetSwapchainImagesKHR(device, swapchain, pCount, pSwapchainImages);
David Pinedofb5b5382015-06-18 17:03:14 -0600528
529 loader_platform_thread_lock_mutex(&globalLock);
530 if (screenshotEnvQueried && screenshotFrames.empty()) {
531 // We are all done taking screenshots, so don't do anything else
532 loader_platform_thread_unlock_mutex(&globalLock);
533 return result;
534 }
535
536 if (result == VK_SUCCESS &&
Ian Elliott7e40db92015-08-21 15:09:33 -0600537 pSwapchainImages &&
Chia-I Wue2fc5522015-10-26 20:04:44 +0800538 !swapchainMap.empty() && swapchainMap.find(swapchain) != swapchainMap.end())
Ian Elliott2b6b68a2015-08-07 14:11:14 -0600539 {
Cody Northropbf065822015-09-01 11:48:13 -0600540 unsigned i;
David Pinedo8897e192015-07-31 10:56:20 -0600541
Ian Elliott2b6b68a2015-08-07 14:11:14 -0600542 for (i=0; i<*pCount; i++)
David Pinedofb5b5382015-06-18 17:03:14 -0600543 {
544 // Create a mapping for an image to a device, image extent, and format
Chia-I Wue2fc5522015-10-26 20:04:44 +0800545 if (imageMap[pSwapchainImages[i]] == NULL)
Cody Northrop49f885c2015-09-01 10:18:45 -0600546 {
547 ImageMapStruct *imageMapElem = new ImageMapStruct;
Chia-I Wue2fc5522015-10-26 20:04:44 +0800548 imageMap[pSwapchainImages[i]] = imageMapElem;
Cody Northrop49f885c2015-09-01 10:18:45 -0600549 }
Chia-I Wue2fc5522015-10-26 20:04:44 +0800550 imageMap[pSwapchainImages[i]]->device = swapchainMap[swapchain]->device;
551 imageMap[pSwapchainImages[i]]->imageExtent = swapchainMap[swapchain]->imageExtent;
552 imageMap[pSwapchainImages[i]]->format = swapchainMap[swapchain]->format;
David Pinedofb5b5382015-06-18 17:03:14 -0600553 }
David Pinedo8897e192015-07-31 10:56:20 -0600554
555 // Add list of images to swapchain to image map
Chia-I Wue2fc5522015-10-26 20:04:44 +0800556 SwapchainMapStruct *swapchainMapElem = swapchainMap[swapchain];
David Pinedo8897e192015-07-31 10:56:20 -0600557 if (i >= 1 && swapchainMapElem)
558 {
559 VkImage *imageList = new VkImage[i];
560 swapchainMapElem->imageList = imageList;
Cody Northropbf065822015-09-01 11:48:13 -0600561 for (unsigned j=0; j<i; j++)
David Pinedo8897e192015-07-31 10:56:20 -0600562 {
Chia-I Wue2fc5522015-10-26 20:04:44 +0800563 swapchainMapElem->imageList[j] = pSwapchainImages[j];
David Pinedo8897e192015-07-31 10:56:20 -0600564 }
565 }
566
David Pinedofb5b5382015-06-18 17:03:14 -0600567 }
568 loader_platform_thread_unlock_mutex(&globalLock);
569 return result;
570}
571
Ian Elliott7e40db92015-08-21 15:09:33 -0600572VK_LAYER_EXPORT VkResult VKAPI vkQueuePresentKHR(VkQueue queue, VkPresentInfoKHR* pPresentInfo)
David Pinedofb5b5382015-06-18 17:03:14 -0600573{
574 static int frameNumber = 0;
David Pinedo8897e192015-07-31 10:56:20 -0600575 if (frameNumber == 10) {fflush(stdout); /* *((int*)0)=0; */ }
Ian Elliott7e40db92015-08-21 15:09:33 -0600576 VkResult result = get_dispatch_table(screenshot_device_table_map, queue)->QueuePresentKHR(queue, pPresentInfo);
David Pinedofb5b5382015-06-18 17:03:14 -0600577
578 loader_platform_thread_lock_mutex(&globalLock);
579
580 if (!screenshotEnvQueried)
581 {
582 const char *_vk_screenshot = getenv("_VK_SCREENSHOT");
583 if (_vk_screenshot && *_vk_screenshot)
584 {
585 string spec(_vk_screenshot), word;
586 size_t start = 0, comma = 0;
587
588 while (start < spec.size()) {
589 int frameToAdd;
590 comma = spec.find(',', start);
591 if (comma == string::npos)
592 word = string(spec, start);
593 else
594 word = string(spec, start, comma - start);
595 frameToAdd=atoi(word.c_str());
596 // Add the frame number to list, but only do it if the word started with a digit and if
597 // it's not already in the list
598 if (*(word.c_str()) >= '0' && *(word.c_str()) <= '9' &&
599 find(screenshotFrames.begin(), screenshotFrames.end(), frameToAdd) == screenshotFrames.end())
600 {
601 screenshotFrames.push_back(frameToAdd);
602 }
603 if (comma == string::npos)
604 break;
605 start = comma + 1;
606 }
607 }
608 screenshotEnvQueried = true;
609 }
610
611
612 if (result == VK_SUCCESS && !screenshotFrames.empty())
613 {
614 vector<int>::iterator it;
615 it = find(screenshotFrames.begin(), screenshotFrames.end(), frameNumber);
616 if (it != screenshotFrames.end())
617 {
618 string fileName;
619 fileName = to_string(frameNumber) + ".ppm";
David Pinedo8897e192015-07-31 10:56:20 -0600620
621 VkImage image;
Chia-I Wue2fc5522015-10-26 20:04:44 +0800622 VkSwapchainKHR swapchain;
David Pinedo8897e192015-07-31 10:56:20 -0600623 // We'll dump only one image: the first
Chia-I Wue2fc5522015-10-26 20:04:44 +0800624 swapchain = pPresentInfo->swapchains[0];
Ian Elliott7e40db92015-08-21 15:09:33 -0600625 image = swapchainMap[swapchain]->imageList[pPresentInfo->imageIndices[0]];
David Pinedo8897e192015-07-31 10:56:20 -0600626 writePPM(fileName.c_str(), image);
David Pinedofb5b5382015-06-18 17:03:14 -0600627 screenshotFrames.erase(it);
628
629 if (screenshotFrames.empty())
630 {
David Pinedo8897e192015-07-31 10:56:20 -0600631 // Free all our maps since we are done with them.
David Pinedofb5b5382015-06-18 17:03:14 -0600632 for (auto it = swapchainMap.begin(); it != swapchainMap.end(); it++)
633 {
634 SwapchainMapStruct *swapchainMapElem = it->second;
635 delete swapchainMapElem;
636 }
637 for (auto it = imageMap.begin(); it != imageMap.end(); it++)
638 {
639 ImageMapStruct *imageMapElem = it->second;
640 delete imageMapElem;
641 }
642 for (auto it = deviceMap.begin(); it != deviceMap.end(); it++)
643 {
644 DeviceMapStruct *deviceMapElem = it->second;
645 delete deviceMapElem;
646 }
Cody Northrop49f885c2015-09-01 10:18:45 -0600647 for (auto it = physDeviceMap.begin(); it != physDeviceMap.end(); it++)
648 {
649 PhysDeviceMapStruct *physDeviceMapElem = it->second;
650 delete physDeviceMapElem;
651 }
David Pinedofb5b5382015-06-18 17:03:14 -0600652 swapchainMap.clear();
653 imageMap.clear();
654 deviceMap.clear();
Cody Northrop49f885c2015-09-01 10:18:45 -0600655 physDeviceMap.clear();
David Pinedofb5b5382015-06-18 17:03:14 -0600656 }
657 }
658 }
659 frameNumber++;
660 loader_platform_thread_unlock_mutex(&globalLock);
661 return result;
662}
663
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -0600664VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(
David Pinedofb5b5382015-06-18 17:03:14 -0600665 VkDevice dev,
666 const char *funcName)
667{
David Pinedofb5b5382015-06-18 17:03:14 -0600668 if (dev == NULL) {
669 return NULL;
670 }
671
672 /* loader uses this to force layer initialization; device object is wrapped */
673 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
674 initDeviceTable(screenshot_device_table_map, (const VkBaseLayerObject *) dev);
David Pinedo8897e192015-07-31 10:56:20 -0600675 return (PFN_vkVoidFunction)vkGetDeviceProcAddr;
David Pinedofb5b5382015-06-18 17:03:14 -0600676 }
Courtney Goeltzenleuchterca173b82015-06-25 18:01:43 -0600677 if (!strcmp(funcName, "vkCreateDevice"))
David Pinedo8897e192015-07-31 10:56:20 -0600678 return (PFN_vkVoidFunction) vkCreateDevice;
Courtney Goeltzenleuchterca173b82015-06-25 18:01:43 -0600679
David Pinedofb5b5382015-06-18 17:03:14 -0600680 if (!strcmp(funcName, "vkGetDeviceQueue"))
David Pinedo8897e192015-07-31 10:56:20 -0600681 return (PFN_vkVoidFunction) vkGetDeviceQueue;
682
683 if (!strcmp(funcName, "vkCreateCommandPool"))
684 return (PFN_vkVoidFunction) vkCreateCommandPool;
David Pinedofb5b5382015-06-18 17:03:14 -0600685
David Pinedobcd0e792015-06-19 13:48:18 -0600686 VkLayerDispatchTable *pDisp = get_dispatch_table(screenshot_device_table_map, dev);
Jon Ashburn8acd2332015-09-16 18:08:32 -0600687 if (deviceExtMap.size() != 0 && deviceExtMap[pDisp].wsi_enabled)
David Pinedobcd0e792015-06-19 13:48:18 -0600688 {
Ian Elliott7e40db92015-08-21 15:09:33 -0600689 if (!strcmp(funcName, "vkCreateSwapchainKHR"))
690 return (PFN_vkVoidFunction) vkCreateSwapchainKHR;
691 if (!strcmp(funcName, "vkGetSwapchainImagesKHR"))
692 return (PFN_vkVoidFunction) vkGetSwapchainImagesKHR;
693 if (!strcmp(funcName, "vkQueuePresentKHR"))
694 return (PFN_vkVoidFunction) vkQueuePresentKHR;
David Pinedobcd0e792015-06-19 13:48:18 -0600695 }
696
697 if (pDisp->GetDeviceProcAddr == NULL)
David Pinedofb5b5382015-06-18 17:03:14 -0600698 return NULL;
David Pinedobcd0e792015-06-19 13:48:18 -0600699 return pDisp->GetDeviceProcAddr(dev, funcName);
David Pinedofb5b5382015-06-18 17:03:14 -0600700}
David Pinedo38310942015-07-09 16:23:44 -0600701
702
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -0600703VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
David Pinedo38310942015-07-09 16:23:44 -0600704{
David Pinedo38310942015-07-09 16:23:44 -0600705 if (instance == VK_NULL_HANDLE) {
706 return NULL;
707 }
708
709 /* loader uses this to force layer initialization; instance object is wrapped */
710 if (!strcmp("vkGetInstanceProcAddr", funcName)) {
711 initInstanceTable((const VkBaseLayerObject *) instance);
David Pinedo8897e192015-07-31 10:56:20 -0600712 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
David Pinedo38310942015-07-09 16:23:44 -0600713 }
714
Cody Northrop49f885c2015-09-01 10:18:45 -0600715 if (!strcmp(funcName, "vkEnumeratePhysicalDevices"))
716 return (PFN_vkVoidFunction)vkEnumeratePhysicalDevices;
717
David Pinedo38310942015-07-09 16:23:44 -0600718 VkLayerInstanceDispatchTable* pTable = instance_dispatch_table(instance);
719 if (pTable->GetInstanceProcAddr == NULL)
720 return NULL;
721 return pTable->GetInstanceProcAddr(instance, funcName);
David Pinedo38310942015-07-09 16:23:44 -0600722}