blob: 734e7195bb3abd354d223ae83c9905bace59418a [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,
Chia-I Wu5c17c962015-10-31 00:31:16 +0800161 VK_SAMPLE_COUNT_1_BIT,
David Pinedofb5b5382015-06-18 17:03:14 -0600162 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 */
Jon Ashburn751c4842015-11-02 17:37:20 -0700421 if (pLayerName == NULL) {
422 VkLayerInstanceDispatchTable* pTable = instance_dispatch_table(physicalDevice);
423 return pTable->EnumerateDeviceExtensionProperties(
424 physicalDevice,
425 NULL,
426 pCount,
427 pProperties);
428 } else {
429 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
430 }
Courtney Goeltzenleuchtera6db3462015-07-07 11:25:43 -0600431}
Tony Barbour59a47322015-06-24 16:06:58 -0600432
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -0600433VK_LAYER_EXPORT VkResult VKAPI vkEnumerateDeviceLayerProperties(
Courtney Goeltzenleuchtera6db3462015-07-07 11:25:43 -0600434 VkPhysicalDevice physicalDevice,
435 uint32_t* pCount,
436 VkLayerProperties* pProperties)
437{
438 return util_GetLayerProperties(ARRAY_SIZE(ss_device_layers),
439 ss_device_layers,
440 pCount, pProperties);
David Pinedofb5b5382015-06-18 17:03:14 -0600441}
442
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600443VK_LAYER_EXPORT void VKAPI vkGetDeviceQueue(
David Pinedofb5b5382015-06-18 17:03:14 -0600444 VkDevice device,
445 uint32_t queueNodeIndex,
446 uint32_t queueIndex,
447 VkQueue *pQueue)
448{
449 VkLayerDispatchTable* pTable = screenshot_device_table_map[device];
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600450 get_dispatch_table(screenshot_device_table_map, device)->GetDeviceQueue(device, queueNodeIndex, queueIndex, pQueue);
David Pinedofb5b5382015-06-18 17:03:14 -0600451
452 loader_platform_thread_lock_mutex(&globalLock);
453 if (screenshotEnvQueried && screenshotFrames.empty()) {
454 // We are all done taking screenshots, so don't do anything else
455 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600456 return;
David Pinedofb5b5382015-06-18 17:03:14 -0600457 }
458
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600459 screenshot_device_table_map.emplace(*pQueue, pTable);
David Pinedofb5b5382015-06-18 17:03:14 -0600460
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600461 // Create a mapping from a device to a queue
462 if (deviceMap[device] == NULL)
463 {
464 DeviceMapStruct *deviceMapElem = new DeviceMapStruct;
465 deviceMap[device] = deviceMapElem;
David Pinedofb5b5382015-06-18 17:03:14 -0600466 }
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600467 deviceMap[device]->queue = *pQueue;
David Pinedofb5b5382015-06-18 17:03:14 -0600468 loader_platform_thread_unlock_mutex(&globalLock);
David Pinedofb5b5382015-06-18 17:03:14 -0600469}
470
David Pinedo8897e192015-07-31 10:56:20 -0600471VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandPool(
472 VkDevice device,
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800473 const VkCommandPoolCreateInfo *pCreateInfo,
474 const VkAllocationCallbacks* pAllocator,
475 VkCommandPool *pCommandPool)
David Pinedo8897e192015-07-31 10:56:20 -0600476{
477 VkLayerDispatchTable* pTable = screenshot_device_table_map[device];
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800478 VkResult result = get_dispatch_table(screenshot_device_table_map, device)->CreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
David Pinedo8897e192015-07-31 10:56:20 -0600479
480 loader_platform_thread_lock_mutex(&globalLock);
481 if (screenshotEnvQueried && screenshotFrames.empty()) {
482 // We are all done taking screenshots, so don't do anything else
483 loader_platform_thread_unlock_mutex(&globalLock);
484 return result;
485 }
486
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800487 // Create a mapping from a device to a commandPool
Cody Northrop49f885c2015-09-01 10:18:45 -0600488 if (deviceMap[device] == NULL)
489 {
490 DeviceMapStruct *deviceMapElem = new DeviceMapStruct;
491 deviceMap[device] = deviceMapElem;
492 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800493 deviceMap[device]->commandPool = *pCommandPool;
David Pinedo8897e192015-07-31 10:56:20 -0600494 loader_platform_thread_unlock_mutex(&globalLock);
495 return result;
496}
497
Ian Elliott7e40db92015-08-21 15:09:33 -0600498VK_LAYER_EXPORT VkResult VKAPI vkCreateSwapchainKHR(
David Pinedofb5b5382015-06-18 17:03:14 -0600499 VkDevice device,
Ian Elliott7e40db92015-08-21 15:09:33 -0600500 const VkSwapchainCreateInfoKHR *pCreateInfo,
501 VkSwapchainKHR *pSwapchain)
David Pinedofb5b5382015-06-18 17:03:14 -0600502{
503 VkLayerDispatchTable* pTable = screenshot_device_table_map[device];
Ian Elliott7e40db92015-08-21 15:09:33 -0600504 VkResult result = get_dispatch_table(screenshot_device_table_map, device)->CreateSwapchainKHR(device, pCreateInfo, pSwapchain);
David Pinedofb5b5382015-06-18 17:03:14 -0600505
506 loader_platform_thread_lock_mutex(&globalLock);
507 if (screenshotEnvQueried && screenshotFrames.empty()) {
508 // We are all done taking screenshots, so don't do anything else
509 loader_platform_thread_unlock_mutex(&globalLock);
510 return result;
511 }
512
513 if (result == VK_SUCCESS)
514 {
515 // Create a mapping for a swapchain to a device, image extent, and format
516 SwapchainMapStruct *swapchainMapElem = new SwapchainMapStruct;
517 swapchainMapElem->device = device;
518 swapchainMapElem->imageExtent = pCreateInfo->imageExtent;
519 swapchainMapElem->format = pCreateInfo->imageFormat;
Chia-I Wue2fc5522015-10-26 20:04:44 +0800520 swapchainMap.insert(make_pair(*pSwapchain, swapchainMapElem));
David Pinedofb5b5382015-06-18 17:03:14 -0600521
522 // Create a mapping for the swapchain object into the dispatch table
Chia-I Wue2fc5522015-10-26 20:04:44 +0800523 screenshot_device_table_map.emplace((void *)pSwapchain, pTable);
David Pinedofb5b5382015-06-18 17:03:14 -0600524 }
525 loader_platform_thread_unlock_mutex(&globalLock);
526
527 return result;
528}
529
Ian Elliott7e40db92015-08-21 15:09:33 -0600530VK_LAYER_EXPORT VkResult VKAPI vkGetSwapchainImagesKHR(
Ian Elliott1064fe32015-07-06 14:31:32 -0600531 VkDevice device,
Ian Elliott7e40db92015-08-21 15:09:33 -0600532 VkSwapchainKHR swapchain,
Ian Elliott2b6b68a2015-08-07 14:11:14 -0600533 uint32_t* pCount,
Ian Elliott7e40db92015-08-21 15:09:33 -0600534 VkImage* pSwapchainImages)
David Pinedofb5b5382015-06-18 17:03:14 -0600535{
Ian Elliott7e40db92015-08-21 15:09:33 -0600536 VkResult result = get_dispatch_table(screenshot_device_table_map, device)->GetSwapchainImagesKHR(device, swapchain, pCount, pSwapchainImages);
David Pinedofb5b5382015-06-18 17:03:14 -0600537
538 loader_platform_thread_lock_mutex(&globalLock);
539 if (screenshotEnvQueried && screenshotFrames.empty()) {
540 // We are all done taking screenshots, so don't do anything else
541 loader_platform_thread_unlock_mutex(&globalLock);
542 return result;
543 }
544
545 if (result == VK_SUCCESS &&
Ian Elliott7e40db92015-08-21 15:09:33 -0600546 pSwapchainImages &&
Chia-I Wue2fc5522015-10-26 20:04:44 +0800547 !swapchainMap.empty() && swapchainMap.find(swapchain) != swapchainMap.end())
Ian Elliott2b6b68a2015-08-07 14:11:14 -0600548 {
Cody Northropbf065822015-09-01 11:48:13 -0600549 unsigned i;
David Pinedo8897e192015-07-31 10:56:20 -0600550
Ian Elliott2b6b68a2015-08-07 14:11:14 -0600551 for (i=0; i<*pCount; i++)
David Pinedofb5b5382015-06-18 17:03:14 -0600552 {
553 // Create a mapping for an image to a device, image extent, and format
Chia-I Wue2fc5522015-10-26 20:04:44 +0800554 if (imageMap[pSwapchainImages[i]] == NULL)
Cody Northrop49f885c2015-09-01 10:18:45 -0600555 {
556 ImageMapStruct *imageMapElem = new ImageMapStruct;
Chia-I Wue2fc5522015-10-26 20:04:44 +0800557 imageMap[pSwapchainImages[i]] = imageMapElem;
Cody Northrop49f885c2015-09-01 10:18:45 -0600558 }
Chia-I Wue2fc5522015-10-26 20:04:44 +0800559 imageMap[pSwapchainImages[i]]->device = swapchainMap[swapchain]->device;
560 imageMap[pSwapchainImages[i]]->imageExtent = swapchainMap[swapchain]->imageExtent;
561 imageMap[pSwapchainImages[i]]->format = swapchainMap[swapchain]->format;
David Pinedofb5b5382015-06-18 17:03:14 -0600562 }
David Pinedo8897e192015-07-31 10:56:20 -0600563
564 // Add list of images to swapchain to image map
Chia-I Wue2fc5522015-10-26 20:04:44 +0800565 SwapchainMapStruct *swapchainMapElem = swapchainMap[swapchain];
David Pinedo8897e192015-07-31 10:56:20 -0600566 if (i >= 1 && swapchainMapElem)
567 {
568 VkImage *imageList = new VkImage[i];
569 swapchainMapElem->imageList = imageList;
Cody Northropbf065822015-09-01 11:48:13 -0600570 for (unsigned j=0; j<i; j++)
David Pinedo8897e192015-07-31 10:56:20 -0600571 {
Chia-I Wue2fc5522015-10-26 20:04:44 +0800572 swapchainMapElem->imageList[j] = pSwapchainImages[j];
David Pinedo8897e192015-07-31 10:56:20 -0600573 }
574 }
575
David Pinedofb5b5382015-06-18 17:03:14 -0600576 }
577 loader_platform_thread_unlock_mutex(&globalLock);
578 return result;
579}
580
Ian Elliott7e40db92015-08-21 15:09:33 -0600581VK_LAYER_EXPORT VkResult VKAPI vkQueuePresentKHR(VkQueue queue, VkPresentInfoKHR* pPresentInfo)
David Pinedofb5b5382015-06-18 17:03:14 -0600582{
583 static int frameNumber = 0;
David Pinedo8897e192015-07-31 10:56:20 -0600584 if (frameNumber == 10) {fflush(stdout); /* *((int*)0)=0; */ }
Ian Elliott7e40db92015-08-21 15:09:33 -0600585 VkResult result = get_dispatch_table(screenshot_device_table_map, queue)->QueuePresentKHR(queue, pPresentInfo);
David Pinedofb5b5382015-06-18 17:03:14 -0600586
587 loader_platform_thread_lock_mutex(&globalLock);
588
589 if (!screenshotEnvQueried)
590 {
591 const char *_vk_screenshot = getenv("_VK_SCREENSHOT");
592 if (_vk_screenshot && *_vk_screenshot)
593 {
594 string spec(_vk_screenshot), word;
595 size_t start = 0, comma = 0;
596
597 while (start < spec.size()) {
598 int frameToAdd;
599 comma = spec.find(',', start);
600 if (comma == string::npos)
601 word = string(spec, start);
602 else
603 word = string(spec, start, comma - start);
604 frameToAdd=atoi(word.c_str());
605 // Add the frame number to list, but only do it if the word started with a digit and if
606 // it's not already in the list
607 if (*(word.c_str()) >= '0' && *(word.c_str()) <= '9' &&
608 find(screenshotFrames.begin(), screenshotFrames.end(), frameToAdd) == screenshotFrames.end())
609 {
610 screenshotFrames.push_back(frameToAdd);
611 }
612 if (comma == string::npos)
613 break;
614 start = comma + 1;
615 }
616 }
617 screenshotEnvQueried = true;
618 }
619
620
621 if (result == VK_SUCCESS && !screenshotFrames.empty())
622 {
623 vector<int>::iterator it;
624 it = find(screenshotFrames.begin(), screenshotFrames.end(), frameNumber);
625 if (it != screenshotFrames.end())
626 {
627 string fileName;
628 fileName = to_string(frameNumber) + ".ppm";
David Pinedo8897e192015-07-31 10:56:20 -0600629
630 VkImage image;
Chia-I Wue2fc5522015-10-26 20:04:44 +0800631 VkSwapchainKHR swapchain;
David Pinedo8897e192015-07-31 10:56:20 -0600632 // We'll dump only one image: the first
Chia-I Wue2fc5522015-10-26 20:04:44 +0800633 swapchain = pPresentInfo->swapchains[0];
Ian Elliott7e40db92015-08-21 15:09:33 -0600634 image = swapchainMap[swapchain]->imageList[pPresentInfo->imageIndices[0]];
David Pinedo8897e192015-07-31 10:56:20 -0600635 writePPM(fileName.c_str(), image);
David Pinedofb5b5382015-06-18 17:03:14 -0600636 screenshotFrames.erase(it);
637
638 if (screenshotFrames.empty())
639 {
David Pinedo8897e192015-07-31 10:56:20 -0600640 // Free all our maps since we are done with them.
David Pinedofb5b5382015-06-18 17:03:14 -0600641 for (auto it = swapchainMap.begin(); it != swapchainMap.end(); it++)
642 {
643 SwapchainMapStruct *swapchainMapElem = it->second;
644 delete swapchainMapElem;
645 }
646 for (auto it = imageMap.begin(); it != imageMap.end(); it++)
647 {
648 ImageMapStruct *imageMapElem = it->second;
649 delete imageMapElem;
650 }
651 for (auto it = deviceMap.begin(); it != deviceMap.end(); it++)
652 {
653 DeviceMapStruct *deviceMapElem = it->second;
654 delete deviceMapElem;
655 }
Cody Northrop49f885c2015-09-01 10:18:45 -0600656 for (auto it = physDeviceMap.begin(); it != physDeviceMap.end(); it++)
657 {
658 PhysDeviceMapStruct *physDeviceMapElem = it->second;
659 delete physDeviceMapElem;
660 }
David Pinedofb5b5382015-06-18 17:03:14 -0600661 swapchainMap.clear();
662 imageMap.clear();
663 deviceMap.clear();
Cody Northrop49f885c2015-09-01 10:18:45 -0600664 physDeviceMap.clear();
David Pinedofb5b5382015-06-18 17:03:14 -0600665 }
666 }
667 }
668 frameNumber++;
669 loader_platform_thread_unlock_mutex(&globalLock);
670 return result;
671}
672
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -0600673VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(
David Pinedofb5b5382015-06-18 17:03:14 -0600674 VkDevice dev,
675 const char *funcName)
676{
David Pinedofb5b5382015-06-18 17:03:14 -0600677 if (dev == NULL) {
678 return NULL;
679 }
680
681 /* loader uses this to force layer initialization; device object is wrapped */
682 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
683 initDeviceTable(screenshot_device_table_map, (const VkBaseLayerObject *) dev);
David Pinedo8897e192015-07-31 10:56:20 -0600684 return (PFN_vkVoidFunction)vkGetDeviceProcAddr;
David Pinedofb5b5382015-06-18 17:03:14 -0600685 }
Courtney Goeltzenleuchterca173b82015-06-25 18:01:43 -0600686 if (!strcmp(funcName, "vkCreateDevice"))
David Pinedo8897e192015-07-31 10:56:20 -0600687 return (PFN_vkVoidFunction) vkCreateDevice;
Courtney Goeltzenleuchterca173b82015-06-25 18:01:43 -0600688
David Pinedofb5b5382015-06-18 17:03:14 -0600689 if (!strcmp(funcName, "vkGetDeviceQueue"))
David Pinedo8897e192015-07-31 10:56:20 -0600690 return (PFN_vkVoidFunction) vkGetDeviceQueue;
691
692 if (!strcmp(funcName, "vkCreateCommandPool"))
693 return (PFN_vkVoidFunction) vkCreateCommandPool;
David Pinedofb5b5382015-06-18 17:03:14 -0600694
David Pinedobcd0e792015-06-19 13:48:18 -0600695 VkLayerDispatchTable *pDisp = get_dispatch_table(screenshot_device_table_map, dev);
Jon Ashburn8acd2332015-09-16 18:08:32 -0600696 if (deviceExtMap.size() != 0 && deviceExtMap[pDisp].wsi_enabled)
David Pinedobcd0e792015-06-19 13:48:18 -0600697 {
Ian Elliott7e40db92015-08-21 15:09:33 -0600698 if (!strcmp(funcName, "vkCreateSwapchainKHR"))
699 return (PFN_vkVoidFunction) vkCreateSwapchainKHR;
700 if (!strcmp(funcName, "vkGetSwapchainImagesKHR"))
701 return (PFN_vkVoidFunction) vkGetSwapchainImagesKHR;
702 if (!strcmp(funcName, "vkQueuePresentKHR"))
703 return (PFN_vkVoidFunction) vkQueuePresentKHR;
David Pinedobcd0e792015-06-19 13:48:18 -0600704 }
705
706 if (pDisp->GetDeviceProcAddr == NULL)
David Pinedofb5b5382015-06-18 17:03:14 -0600707 return NULL;
David Pinedobcd0e792015-06-19 13:48:18 -0600708 return pDisp->GetDeviceProcAddr(dev, funcName);
David Pinedofb5b5382015-06-18 17:03:14 -0600709}
David Pinedo38310942015-07-09 16:23:44 -0600710
711
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -0600712VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
David Pinedo38310942015-07-09 16:23:44 -0600713{
David Pinedo38310942015-07-09 16:23:44 -0600714 if (instance == VK_NULL_HANDLE) {
715 return NULL;
716 }
717
718 /* loader uses this to force layer initialization; instance object is wrapped */
719 if (!strcmp("vkGetInstanceProcAddr", funcName)) {
720 initInstanceTable((const VkBaseLayerObject *) instance);
David Pinedo8897e192015-07-31 10:56:20 -0600721 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
David Pinedo38310942015-07-09 16:23:44 -0600722 }
723
Cody Northrop49f885c2015-09-01 10:18:45 -0600724 if (!strcmp(funcName, "vkEnumeratePhysicalDevices"))
725 return (PFN_vkVoidFunction)vkEnumeratePhysicalDevices;
Jon Ashburn751c4842015-11-02 17:37:20 -0700726 if (!strcmp(funcName, "vkEnumerateDeviceExtensionProperties"))
727 return (PFN_vkVoidFunction)vkEnumerateDeviceExtensionProperties;
Cody Northrop49f885c2015-09-01 10:18:45 -0600728
David Pinedo38310942015-07-09 16:23:44 -0600729 VkLayerInstanceDispatchTable* pTable = instance_dispatch_table(instance);
730 if (pTable->GetInstanceProcAddr == NULL)
731 return NULL;
732 return pTable->GetInstanceProcAddr(instance, funcName);
David Pinedo38310942015-07-09 16:23:44 -0600733}