David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 1 | /* |
| 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 | |
| 38 | using namespace std; |
| 39 | |
Tobin Ehlis | b835d1b | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 40 | #include "vk_loader_platform.h" |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 41 | #include "vk_dispatch_table_helper.h" |
| 42 | #include "vk_struct_string_helper_cpp.h" |
Tobin Ehlis | a0cb02e | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 43 | #include "vk_layer_config.h" |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 44 | // The following is #included again to catch certain OS-specific functions |
| 45 | // being used: |
Tobin Ehlis | b835d1b | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 46 | #include "vk_loader_platform.h" |
Tobin Ehlis | a0cb02e | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 47 | #include "vk_layer_table.h" |
Courtney Goeltzenleuchter | a6db346 | 2015-07-07 11:25:43 -0600 | [diff] [blame] | 48 | #include "vk_layer_extension_utils.h" |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 49 | |
David Pinedo | bcd0e79 | 2015-06-19 13:48:18 -0600 | [diff] [blame] | 50 | |
| 51 | struct devExts { |
Ian Elliott | 1064fe3 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 52 | bool wsi_enabled; |
David Pinedo | bcd0e79 | 2015-06-19 13:48:18 -0600 | [diff] [blame] | 53 | }; |
| 54 | static std::unordered_map<void *, struct devExts> deviceExtMap; |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 55 | static device_table_map screenshot_device_table_map; |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 56 | |
| 57 | static int globalLockInitialized = 0; |
| 58 | static loader_platform_thread_mutex globalLock; |
| 59 | |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 60 | // unordered map: associates a swap chain with a device, image extent, format, and |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 61 | // list of images |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 62 | typedef struct |
| 63 | { |
| 64 | VkDevice device; |
| 65 | VkExtent2D imageExtent; |
| 66 | VkFormat format; |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 67 | VkImage *imageList; |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 68 | } SwapchainMapStruct; |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 69 | static unordered_map<uint64_t, SwapchainMapStruct *> swapchainMap; |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 70 | |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 71 | // unordered map: associates an image with a device, image extent, and format |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 72 | typedef struct |
| 73 | { |
| 74 | VkDevice device; |
| 75 | VkExtent2D imageExtent; |
| 76 | VkFormat format; |
| 77 | } ImageMapStruct; |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 78 | static unordered_map<uint64_t, ImageMapStruct *> imageMap; |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 79 | |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 80 | // unordered map: associates a device with a queue, cmdPool, and physical device |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 81 | typedef struct |
| 82 | { |
| 83 | VkQueue queue; |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 84 | VkCmdPool cmdPool; |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 85 | VkPhysicalDevice physicalDevice; |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 86 | } DeviceMapStruct; |
| 87 | static unordered_map<VkDevice, DeviceMapStruct *> deviceMap; |
| 88 | |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 89 | // unordered map: associates a physical device with an instance |
| 90 | typedef struct |
| 91 | { |
| 92 | VkInstance instance; |
| 93 | } PhysDeviceMapStruct; |
| 94 | static unordered_map<VkPhysicalDevice, PhysDeviceMapStruct *> physDeviceMap; |
| 95 | |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 96 | // List of frames to we will get a screenshot of |
| 97 | static vector<int> screenshotFrames; |
| 98 | |
| 99 | // Flag indicating we have queried _VK_SCREENSHOT env var |
| 100 | static bool screenshotEnvQueried = false; |
| 101 | |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 102 | static VkResult memory_type_from_properties( |
| 103 | VkPhysicalDeviceMemoryProperties *memory_properties, |
| 104 | uint32_t typeBits, |
| 105 | VkFlags properties, |
| 106 | uint32_t *typeIndex) |
| 107 | { |
| 108 | // Search memtypes to find first index with those properties |
| 109 | for (uint32_t i = 0; i < 32; i++) { |
| 110 | if ((typeBits & 1) == 1) { |
| 111 | // Type is available, does it match user properties? |
| 112 | if ((memory_properties->memoryTypes[i].propertyFlags & properties) == properties) { |
| 113 | *typeIndex = i; |
| 114 | return VK_SUCCESS; |
| 115 | } |
| 116 | } |
| 117 | typeBits >>= 1; |
| 118 | } |
| 119 | // No memory types matched, return failure |
| 120 | return VK_UNSUPPORTED; |
| 121 | } |
| 122 | |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 123 | static void init_screenshot() |
| 124 | { |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 125 | if (!globalLockInitialized) |
| 126 | { |
| 127 | // TODO/TBD: Need to delete this mutex sometime. How??? One |
| 128 | // suggestion is to call this during vkCreateInstance(), and then we |
| 129 | // can clean it up during vkDestroyInstance(). However, that requires |
| 130 | // that the layer have per-instance locks. We need to come back and |
| 131 | // address this soon. |
| 132 | loader_platform_thread_create_mutex(&globalLock); |
| 133 | globalLockInitialized = 1; |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | static void writePPM( const char *filename, VkImage image1) |
| 138 | { |
| 139 | VkImage image2; |
| 140 | VkResult err; |
| 141 | int x, y; |
| 142 | const char *ptr; |
| 143 | VkDeviceMemory mem2; |
| 144 | VkCmdBuffer cmdBuffer; |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 145 | VkDevice device = imageMap[image1.handle]->device; |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 146 | VkPhysicalDevice physicalDevice = deviceMap[device]->physicalDevice; |
| 147 | VkInstance instance = physDeviceMap[physicalDevice]->instance; |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 148 | VkQueue queue = deviceMap[device]->queue; |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 149 | int width = imageMap[image1.handle]->imageExtent.width; |
| 150 | int height = imageMap[image1.handle]->imageExtent.height; |
| 151 | VkFormat format = imageMap[image1.handle]->format; |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 152 | const VkImageSubresource sr = {VK_IMAGE_ASPECT_COLOR, 0, 0}; |
| 153 | VkSubresourceLayout sr_layout; |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 154 | const VkImageCreateInfo imgCreateInfo = { |
| 155 | VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, |
| 156 | NULL, |
| 157 | VK_IMAGE_TYPE_2D, |
| 158 | format, |
| 159 | {width, height, 1}, |
| 160 | 1, |
| 161 | 1, |
| 162 | 1, |
| 163 | VK_IMAGE_TILING_LINEAR, |
| 164 | (VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT|VK_IMAGE_USAGE_STORAGE_BIT), |
| 165 | 0 |
| 166 | }; |
| 167 | VkMemoryAllocInfo memAllocInfo = { |
| 168 | VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO, |
| 169 | NULL, |
| 170 | 0, // allocationSize, queried later |
Cody Northrop | 488f547 | 2015-09-01 11:47:50 -0600 | [diff] [blame] | 171 | 0 // memoryTypeIndex, queried later |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 172 | }; |
| 173 | const VkCmdBufferCreateInfo createCommandBufferInfo = { |
| 174 | VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO, |
| 175 | NULL, |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 176 | deviceMap[device]->cmdPool, |
Chia-I Wu | 0b50a1c | 2015-06-26 15:34:39 +0800 | [diff] [blame] | 177 | VK_CMD_BUFFER_LEVEL_PRIMARY, |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 178 | 0 |
| 179 | }; |
| 180 | const VkCmdBufferBeginInfo cmdBufferBeginInfo = { |
| 181 | VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO, |
| 182 | NULL, |
| 183 | VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT | |
| 184 | VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT, |
| 185 | }; |
| 186 | const VkImageCopy imageCopyRegion = { |
| 187 | {VK_IMAGE_ASPECT_COLOR, 0, 0}, |
| 188 | {0, 0, 0}, |
| 189 | {VK_IMAGE_ASPECT_COLOR, 0, 0}, |
| 190 | {0, 0, 0}, |
| 191 | {width, height, 1} |
| 192 | }; |
| 193 | VkMemoryRequirements memRequirements; |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 194 | uint32_t num_allocations = 0; |
| 195 | size_t num_alloc_size = sizeof(num_allocations); |
David Pinedo | 6829587 | 2015-06-30 13:08:37 -0600 | [diff] [blame] | 196 | VkLayerDispatchTable* pTableDevice = get_dispatch_table(screenshot_device_table_map, device); |
| 197 | VkLayerDispatchTable* pTableQueue = get_dispatch_table(screenshot_device_table_map, queue); |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 198 | VkLayerInstanceDispatchTable* pInstanceTable; |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 199 | VkLayerDispatchTable* pTableCmdBuffer; |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 200 | VkPhysicalDeviceMemoryProperties memory_properties; |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 201 | |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 202 | if (imageMap.empty() || imageMap.find(image1.handle) == imageMap.end()) |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 203 | return; |
| 204 | |
| 205 | // The VkImage image1 we are going to dump may not be mappable, |
| 206 | // and/or it may have a tiling mode of optimal rather than linear. |
| 207 | // To make sure we have an image that we can map and read linearly, we: |
| 208 | // create image2 that is mappable and linear |
| 209 | // copy image1 to image2 |
| 210 | // map image2 |
| 211 | // read from image2's mapped memeory. |
| 212 | |
| 213 | err = pTableDevice->CreateImage(device, &imgCreateInfo, &image2); |
| 214 | assert(!err); |
| 215 | |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 216 | err = pTableDevice->GetImageMemoryRequirements(device, image2, &memRequirements); |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 217 | assert(!err); |
| 218 | |
| 219 | memAllocInfo.allocationSize = memRequirements.size; |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 220 | pInstanceTable = instance_dispatch_table(instance); |
| 221 | err = pInstanceTable->GetPhysicalDeviceMemoryProperties(physicalDevice, &memory_properties); |
| 222 | assert(!err); |
| 223 | |
| 224 | err = memory_type_from_properties(&memory_properties, |
| 225 | memRequirements.memoryTypeBits, |
Cody Northrop | 488f547 | 2015-09-01 11:47:50 -0600 | [diff] [blame] | 226 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 227 | &memAllocInfo.memoryTypeIndex); |
| 228 | assert(!err); |
| 229 | |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 230 | err = pTableDevice->AllocMemory(device, &memAllocInfo, &mem2); |
| 231 | assert(!err); |
| 232 | |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 233 | err = pTableQueue->BindImageMemory(device, image2, mem2, 0); |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 234 | assert(!err); |
| 235 | |
| 236 | err = pTableDevice->CreateCommandBuffer(device, &createCommandBufferInfo, &cmdBuffer); |
| 237 | assert(!err); |
| 238 | |
| 239 | screenshot_device_table_map.emplace(cmdBuffer, pTableDevice); |
| 240 | pTableCmdBuffer = screenshot_device_table_map[cmdBuffer]; |
| 241 | |
| 242 | err = pTableCmdBuffer->BeginCommandBuffer(cmdBuffer, &cmdBufferBeginInfo); |
| 243 | assert(!err); |
| 244 | |
Cody Northrop | 488f547 | 2015-09-01 11:47:50 -0600 | [diff] [blame] | 245 | // TODO: We need to transition images to match these layouts, then restore the original layouts |
| 246 | pTableCmdBuffer->CmdCopyImage(cmdBuffer, image1, VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL, |
| 247 | image2, VK_IMAGE_LAYOUT_TRANSFER_DESTINATION_OPTIMAL, 1, &imageCopyRegion); |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 248 | |
| 249 | err = pTableCmdBuffer->EndCommandBuffer(cmdBuffer); |
| 250 | assert(!err); |
| 251 | |
| 252 | err = pTableQueue->QueueSubmit(queue, 1, &cmdBuffer, VK_NULL_HANDLE); |
| 253 | assert(!err); |
| 254 | |
| 255 | err = pTableQueue->QueueWaitIdle(queue); |
| 256 | assert(!err); |
| 257 | |
| 258 | err = pTableDevice->DeviceWaitIdle(device); |
| 259 | assert(!err); |
| 260 | |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 261 | err = pTableDevice->GetImageSubresourceLayout(device, image2, &sr, &sr_layout); |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 262 | assert(!err); |
| 263 | |
| 264 | err = pTableDevice->MapMemory(device, mem2, 0, 0, 0, (void **) &ptr ); |
| 265 | assert(!err); |
| 266 | |
| 267 | ptr += sr_layout.offset; |
| 268 | |
| 269 | ofstream file(filename, ios::binary); |
| 270 | |
| 271 | file << "P6\n"; |
| 272 | file << width << "\n"; |
| 273 | file << height << "\n"; |
| 274 | file << 255 << "\n"; |
| 275 | |
| 276 | for (y = 0; y < height; y++) { |
| 277 | const unsigned int *row = (const unsigned int*) ptr; |
| 278 | if (format == VK_FORMAT_B8G8R8A8_UNORM) |
| 279 | { |
| 280 | for (x = 0; x < width; x++) { |
| 281 | unsigned int swapped; |
| 282 | swapped = (*row & 0xff00ff00) | (*row & 0x000000ff) << 16 | (*row & 0x00ff0000) >> 16; |
| 283 | file.write((char *)&swapped, 3); |
| 284 | row++; |
| 285 | } |
| 286 | } |
| 287 | else if (format == VK_FORMAT_R8G8B8A8_UNORM) |
| 288 | { |
| 289 | for (x = 0; x < width; x++) { |
| 290 | file.write((char *)row, 3); |
| 291 | row++; |
| 292 | } |
| 293 | } |
| 294 | else |
| 295 | { |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 296 | // TODO: add support for additional formats |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 297 | printf("Unrecognized image format\n"); |
| 298 | break; |
| 299 | } |
| 300 | ptr += sr_layout.rowPitch; |
| 301 | } |
| 302 | file.close(); |
| 303 | |
| 304 | // Clean up |
| 305 | err = pTableDevice->UnmapMemory(device, mem2); |
| 306 | assert(!err); |
| 307 | err = pTableDevice->FreeMemory(device, mem2); |
| 308 | assert(!err); |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 309 | err = pTableDevice->DestroyCommandBuffer(device, cmdBuffer); |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 310 | assert(!err); |
| 311 | } |
| 312 | |
| 313 | |
David Pinedo | bcd0e79 | 2015-06-19 13:48:18 -0600 | [diff] [blame] | 314 | static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device) |
| 315 | { |
Cody Northrop | d2ad034 | 2015-08-05 11:15:02 -0600 | [diff] [blame] | 316 | uint32_t i; |
David Pinedo | bcd0e79 | 2015-06-19 13:48:18 -0600 | [diff] [blame] | 317 | VkLayerDispatchTable *pDisp = get_dispatch_table(screenshot_device_table_map, device); |
Ian Elliott | 1064fe3 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 318 | deviceExtMap[pDisp].wsi_enabled = false; |
David Pinedo | bcd0e79 | 2015-06-19 13:48:18 -0600 | [diff] [blame] | 319 | for (i = 0; i < pCreateInfo->extensionCount; i++) { |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame^] | 320 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_EXT_KHR_DEVICE_SWAPCHAIN_EXTENSION_NAME) == 0) |
Ian Elliott | 1064fe3 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 321 | deviceExtMap[pDisp].wsi_enabled = true; |
David Pinedo | bcd0e79 | 2015-06-19 13:48:18 -0600 | [diff] [blame] | 322 | } |
| 323 | } |
| 324 | |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 325 | VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice( |
| 326 | VkPhysicalDevice gpu, |
| 327 | const VkDeviceCreateInfo *pCreateInfo, |
| 328 | VkDevice *pDevice) |
| 329 | { |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 330 | VkLayerDispatchTable *pDisp = get_dispatch_table(screenshot_device_table_map, *pDevice); |
| 331 | VkResult result = pDisp->CreateDevice(gpu, pCreateInfo, pDevice); |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 332 | |
David Pinedo | bcd0e79 | 2015-06-19 13:48:18 -0600 | [diff] [blame] | 333 | if (result == VK_SUCCESS) { |
Jon Ashburn | ec10533 | 2015-07-06 15:09:36 -0600 | [diff] [blame] | 334 | init_screenshot(); |
David Pinedo | bcd0e79 | 2015-06-19 13:48:18 -0600 | [diff] [blame] | 335 | createDeviceRegisterExtensions(pCreateInfo, *pDevice); |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 336 | // Create a mapping from a device to a physicalDevice |
| 337 | if (deviceMap[*pDevice] == NULL) |
| 338 | { |
| 339 | DeviceMapStruct *deviceMapElem = new DeviceMapStruct; |
| 340 | deviceMap[*pDevice] = deviceMapElem; |
| 341 | } |
| 342 | deviceMap[*pDevice]->physicalDevice = gpu; |
David Pinedo | bcd0e79 | 2015-06-19 13:48:18 -0600 | [diff] [blame] | 343 | } |
| 344 | |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 345 | return result; |
| 346 | } |
| 347 | |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 348 | VK_LAYER_EXPORT VkResult VKAPI vkEnumeratePhysicalDevices( |
| 349 | VkInstance instance, |
| 350 | uint32_t* pPhysicalDeviceCount, |
| 351 | VkPhysicalDevice* pPhysicalDevices) |
| 352 | { |
| 353 | VkResult result; |
| 354 | |
| 355 | VkLayerInstanceDispatchTable* pTable = instance_dispatch_table(instance); |
| 356 | result = pTable->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices); |
| 357 | if (result==VK_SUCCESS && *pPhysicalDeviceCount > 0) |
| 358 | { |
| 359 | for (uint32_t i=0; i<*pPhysicalDeviceCount ; i++) |
| 360 | { |
| 361 | // Create a mapping from a physicalDevice to an instance |
| 362 | if (physDeviceMap[pPhysicalDevices[i]] == NULL) |
| 363 | { |
| 364 | PhysDeviceMapStruct *physDeviceMapElem = new PhysDeviceMapStruct; |
| 365 | physDeviceMap[pPhysicalDevices[i]] = physDeviceMapElem; |
| 366 | } |
| 367 | physDeviceMap[pPhysicalDevices[i]]->instance = instance; |
| 368 | } |
| 369 | } |
| 370 | return result; |
| 371 | } |
| 372 | |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 373 | /* TODO: Probably need a DestroyDevice as well */ |
| 374 | |
Courtney Goeltzenleuchter | a6db346 | 2015-07-07 11:25:43 -0600 | [diff] [blame] | 375 | static const VkLayerProperties ss_device_layers[] = { |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 376 | { |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 377 | "ScreenShot", |
Courtney Goeltzenleuchter | a6db346 | 2015-07-07 11:25:43 -0600 | [diff] [blame] | 378 | VK_API_VERSION, |
| 379 | VK_MAKE_VERSION(0, 1, 0), |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 380 | "Layer: ScreenShot", |
David Pinedo | bcd0e79 | 2015-06-19 13:48:18 -0600 | [diff] [blame] | 381 | } |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 382 | }; |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 383 | |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 384 | VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionProperties( |
Courtney Goeltzenleuchter | a6db346 | 2015-07-07 11:25:43 -0600 | [diff] [blame] | 385 | const char *pLayerName, |
| 386 | uint32_t *pCount, |
| 387 | VkExtensionProperties* pProperties) |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 388 | { |
Courtney Goeltzenleuchter | a6db346 | 2015-07-07 11:25:43 -0600 | [diff] [blame] | 389 | /* ScreenShot does not have any global extensions */ |
| 390 | return util_GetExtensionProperties(0, NULL, pCount, pProperties); |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 391 | } |
Courtney Goeltzenleuchter | a6db346 | 2015-07-07 11:25:43 -0600 | [diff] [blame] | 392 | |
| 393 | VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalLayerProperties( |
| 394 | uint32_t *pCount, |
| 395 | VkLayerProperties* pProperties) |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 396 | { |
Courtney Goeltzenleuchter | a6db346 | 2015-07-07 11:25:43 -0600 | [diff] [blame] | 397 | /* ScreenShot does not have any global layers */ |
| 398 | return util_GetLayerProperties(0, NULL, |
| 399 | pCount, pProperties); |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceExtensionProperties( |
Courtney Goeltzenleuchter | a6db346 | 2015-07-07 11:25:43 -0600 | [diff] [blame] | 403 | VkPhysicalDevice physicalDevice, |
| 404 | const char* pLayerName, |
| 405 | uint32_t* pCount, |
| 406 | VkExtensionProperties* pProperties) |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 407 | { |
Courtney Goeltzenleuchter | a6db346 | 2015-07-07 11:25:43 -0600 | [diff] [blame] | 408 | /* ScreenShot does not have any physical device extensions */ |
| 409 | return util_GetExtensionProperties(0, NULL, pCount, pProperties); |
| 410 | } |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 411 | |
Courtney Goeltzenleuchter | a6db346 | 2015-07-07 11:25:43 -0600 | [diff] [blame] | 412 | VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceLayerProperties( |
| 413 | VkPhysicalDevice physicalDevice, |
| 414 | uint32_t* pCount, |
| 415 | VkLayerProperties* pProperties) |
| 416 | { |
| 417 | return util_GetLayerProperties(ARRAY_SIZE(ss_device_layers), |
| 418 | ss_device_layers, |
| 419 | pCount, pProperties); |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | VK_LAYER_EXPORT VkResult VKAPI vkGetDeviceQueue( |
| 423 | VkDevice device, |
| 424 | uint32_t queueNodeIndex, |
| 425 | uint32_t queueIndex, |
| 426 | VkQueue *pQueue) |
| 427 | { |
| 428 | VkLayerDispatchTable* pTable = screenshot_device_table_map[device]; |
| 429 | VkResult result = get_dispatch_table(screenshot_device_table_map, device)->GetDeviceQueue(device, queueNodeIndex, queueIndex, pQueue); |
| 430 | |
| 431 | loader_platform_thread_lock_mutex(&globalLock); |
| 432 | if (screenshotEnvQueried && screenshotFrames.empty()) { |
| 433 | // We are all done taking screenshots, so don't do anything else |
| 434 | loader_platform_thread_unlock_mutex(&globalLock); |
| 435 | return result; |
| 436 | } |
| 437 | |
| 438 | if (result == VK_SUCCESS) { |
| 439 | screenshot_device_table_map.emplace(*pQueue, pTable); |
| 440 | |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 441 | // Create a mapping from a device to a queue |
| 442 | if (deviceMap[device] == NULL) |
| 443 | { |
| 444 | DeviceMapStruct *deviceMapElem = new DeviceMapStruct; |
| 445 | deviceMap[device] = deviceMapElem; |
| 446 | } |
| 447 | deviceMap[device]->queue = *pQueue; |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 448 | } |
| 449 | loader_platform_thread_unlock_mutex(&globalLock); |
| 450 | return result; |
| 451 | } |
| 452 | |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 453 | VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandPool( |
| 454 | VkDevice device, |
| 455 | const VkCmdPoolCreateInfo *pCreateInfo, |
| 456 | VkCmdPool *pCmdPool) |
| 457 | { |
| 458 | VkLayerDispatchTable* pTable = screenshot_device_table_map[device]; |
| 459 | VkResult result = get_dispatch_table(screenshot_device_table_map, device)->CreateCommandPool(device, pCreateInfo, pCmdPool); |
| 460 | |
| 461 | loader_platform_thread_lock_mutex(&globalLock); |
| 462 | if (screenshotEnvQueried && screenshotFrames.empty()) { |
| 463 | // We are all done taking screenshots, so don't do anything else |
| 464 | loader_platform_thread_unlock_mutex(&globalLock); |
| 465 | return result; |
| 466 | } |
| 467 | |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 468 | // Create a mapping from a device to a cmdPool |
| 469 | if (deviceMap[device] == NULL) |
| 470 | { |
| 471 | DeviceMapStruct *deviceMapElem = new DeviceMapStruct; |
| 472 | deviceMap[device] = deviceMapElem; |
| 473 | } |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 474 | deviceMap[device]->cmdPool = *pCmdPool; |
| 475 | loader_platform_thread_unlock_mutex(&globalLock); |
| 476 | return result; |
| 477 | } |
| 478 | |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame^] | 479 | VK_LAYER_EXPORT VkResult VKAPI vkCreateSwapchainKHR( |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 480 | VkDevice device, |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame^] | 481 | const VkSwapchainCreateInfoKHR *pCreateInfo, |
| 482 | VkSwapchainKHR *pSwapchain) |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 483 | { |
| 484 | VkLayerDispatchTable* pTable = screenshot_device_table_map[device]; |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame^] | 485 | VkResult result = get_dispatch_table(screenshot_device_table_map, device)->CreateSwapchainKHR(device, pCreateInfo, pSwapchain); |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 486 | |
| 487 | loader_platform_thread_lock_mutex(&globalLock); |
| 488 | if (screenshotEnvQueried && screenshotFrames.empty()) { |
| 489 | // We are all done taking screenshots, so don't do anything else |
| 490 | loader_platform_thread_unlock_mutex(&globalLock); |
| 491 | return result; |
| 492 | } |
| 493 | |
| 494 | if (result == VK_SUCCESS) |
| 495 | { |
| 496 | // Create a mapping for a swapchain to a device, image extent, and format |
| 497 | SwapchainMapStruct *swapchainMapElem = new SwapchainMapStruct; |
| 498 | swapchainMapElem->device = device; |
| 499 | swapchainMapElem->imageExtent = pCreateInfo->imageExtent; |
| 500 | swapchainMapElem->format = pCreateInfo->imageFormat; |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame^] | 501 | swapchainMap.insert(make_pair(pSwapchain->handle, swapchainMapElem)); |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 502 | |
| 503 | // Create a mapping for the swapchain object into the dispatch table |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame^] | 504 | screenshot_device_table_map.emplace((void *)pSwapchain->handle, pTable); |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 505 | } |
| 506 | loader_platform_thread_unlock_mutex(&globalLock); |
| 507 | |
| 508 | return result; |
| 509 | } |
| 510 | |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame^] | 511 | VK_LAYER_EXPORT VkResult VKAPI vkGetSwapchainImagesKHR( |
Ian Elliott | 1064fe3 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 512 | VkDevice device, |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame^] | 513 | VkSwapchainKHR swapchain, |
Ian Elliott | 2b6b68a | 2015-08-07 14:11:14 -0600 | [diff] [blame] | 514 | uint32_t* pCount, |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame^] | 515 | VkImage* pSwapchainImages) |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 516 | { |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame^] | 517 | VkResult result = get_dispatch_table(screenshot_device_table_map, device)->GetSwapchainImagesKHR(device, swapchain, pCount, pSwapchainImages); |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 518 | |
| 519 | loader_platform_thread_lock_mutex(&globalLock); |
| 520 | if (screenshotEnvQueried && screenshotFrames.empty()) { |
| 521 | // We are all done taking screenshots, so don't do anything else |
| 522 | loader_platform_thread_unlock_mutex(&globalLock); |
| 523 | return result; |
| 524 | } |
| 525 | |
| 526 | if (result == VK_SUCCESS && |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame^] | 527 | pSwapchainImages && |
| 528 | !swapchainMap.empty() && swapchainMap.find(swapchain.handle) != swapchainMap.end()) |
Ian Elliott | 2b6b68a | 2015-08-07 14:11:14 -0600 | [diff] [blame] | 529 | { |
Cody Northrop | bf06582 | 2015-09-01 11:48:13 -0600 | [diff] [blame] | 530 | unsigned i; |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 531 | |
Ian Elliott | 2b6b68a | 2015-08-07 14:11:14 -0600 | [diff] [blame] | 532 | for (i=0; i<*pCount; i++) |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 533 | { |
| 534 | // Create a mapping for an image to a device, image extent, and format |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame^] | 535 | if (imageMap[pSwapchainImages[i].handle] == NULL) |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 536 | { |
| 537 | ImageMapStruct *imageMapElem = new ImageMapStruct; |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame^] | 538 | imageMap[pSwapchainImages[i].handle] = imageMapElem; |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 539 | } |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame^] | 540 | imageMap[pSwapchainImages[i].handle]->device = swapchainMap[swapchain.handle]->device; |
| 541 | imageMap[pSwapchainImages[i].handle]->imageExtent = swapchainMap[swapchain.handle]->imageExtent; |
| 542 | imageMap[pSwapchainImages[i].handle]->format = swapchainMap[swapchain.handle]->format; |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 543 | } |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 544 | |
| 545 | // Add list of images to swapchain to image map |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame^] | 546 | SwapchainMapStruct *swapchainMapElem = swapchainMap[swapchain.handle]; |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 547 | if (i >= 1 && swapchainMapElem) |
| 548 | { |
| 549 | VkImage *imageList = new VkImage[i]; |
| 550 | swapchainMapElem->imageList = imageList; |
Cody Northrop | bf06582 | 2015-09-01 11:48:13 -0600 | [diff] [blame] | 551 | for (unsigned j=0; j<i; j++) |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 552 | { |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame^] | 553 | swapchainMapElem->imageList[j] = pSwapchainImages[j].handle; |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 554 | } |
| 555 | } |
| 556 | |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 557 | } |
| 558 | loader_platform_thread_unlock_mutex(&globalLock); |
| 559 | return result; |
| 560 | } |
| 561 | |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame^] | 562 | VK_LAYER_EXPORT VkResult VKAPI vkQueuePresentKHR(VkQueue queue, VkPresentInfoKHR* pPresentInfo) |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 563 | { |
| 564 | static int frameNumber = 0; |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 565 | if (frameNumber == 10) {fflush(stdout); /* *((int*)0)=0; */ } |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame^] | 566 | VkResult result = get_dispatch_table(screenshot_device_table_map, queue)->QueuePresentKHR(queue, pPresentInfo); |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 567 | |
| 568 | loader_platform_thread_lock_mutex(&globalLock); |
| 569 | |
| 570 | if (!screenshotEnvQueried) |
| 571 | { |
| 572 | const char *_vk_screenshot = getenv("_VK_SCREENSHOT"); |
| 573 | if (_vk_screenshot && *_vk_screenshot) |
| 574 | { |
| 575 | string spec(_vk_screenshot), word; |
| 576 | size_t start = 0, comma = 0; |
| 577 | |
| 578 | while (start < spec.size()) { |
| 579 | int frameToAdd; |
| 580 | comma = spec.find(',', start); |
| 581 | if (comma == string::npos) |
| 582 | word = string(spec, start); |
| 583 | else |
| 584 | word = string(spec, start, comma - start); |
| 585 | frameToAdd=atoi(word.c_str()); |
| 586 | // Add the frame number to list, but only do it if the word started with a digit and if |
| 587 | // it's not already in the list |
| 588 | if (*(word.c_str()) >= '0' && *(word.c_str()) <= '9' && |
| 589 | find(screenshotFrames.begin(), screenshotFrames.end(), frameToAdd) == screenshotFrames.end()) |
| 590 | { |
| 591 | screenshotFrames.push_back(frameToAdd); |
| 592 | } |
| 593 | if (comma == string::npos) |
| 594 | break; |
| 595 | start = comma + 1; |
| 596 | } |
| 597 | } |
| 598 | screenshotEnvQueried = true; |
| 599 | } |
| 600 | |
| 601 | |
| 602 | if (result == VK_SUCCESS && !screenshotFrames.empty()) |
| 603 | { |
| 604 | vector<int>::iterator it; |
| 605 | it = find(screenshotFrames.begin(), screenshotFrames.end(), frameNumber); |
| 606 | if (it != screenshotFrames.end()) |
| 607 | { |
| 608 | string fileName; |
| 609 | fileName = to_string(frameNumber) + ".ppm"; |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 610 | |
| 611 | VkImage image; |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame^] | 612 | uint64_t swapchain; |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 613 | // We'll dump only one image: the first |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame^] | 614 | swapchain = pPresentInfo->swapchains[0].handle; |
| 615 | image = swapchainMap[swapchain]->imageList[pPresentInfo->imageIndices[0]]; |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 616 | writePPM(fileName.c_str(), image); |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 617 | screenshotFrames.erase(it); |
| 618 | |
| 619 | if (screenshotFrames.empty()) |
| 620 | { |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 621 | // Free all our maps since we are done with them. |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 622 | for (auto it = swapchainMap.begin(); it != swapchainMap.end(); it++) |
| 623 | { |
| 624 | SwapchainMapStruct *swapchainMapElem = it->second; |
| 625 | delete swapchainMapElem; |
| 626 | } |
| 627 | for (auto it = imageMap.begin(); it != imageMap.end(); it++) |
| 628 | { |
| 629 | ImageMapStruct *imageMapElem = it->second; |
| 630 | delete imageMapElem; |
| 631 | } |
| 632 | for (auto it = deviceMap.begin(); it != deviceMap.end(); it++) |
| 633 | { |
| 634 | DeviceMapStruct *deviceMapElem = it->second; |
| 635 | delete deviceMapElem; |
| 636 | } |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 637 | for (auto it = physDeviceMap.begin(); it != physDeviceMap.end(); it++) |
| 638 | { |
| 639 | PhysDeviceMapStruct *physDeviceMapElem = it->second; |
| 640 | delete physDeviceMapElem; |
| 641 | } |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 642 | swapchainMap.clear(); |
| 643 | imageMap.clear(); |
| 644 | deviceMap.clear(); |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 645 | physDeviceMap.clear(); |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 646 | } |
| 647 | } |
| 648 | } |
| 649 | frameNumber++; |
| 650 | loader_platform_thread_unlock_mutex(&globalLock); |
| 651 | return result; |
| 652 | } |
| 653 | |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 654 | VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr( |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 655 | VkDevice dev, |
| 656 | const char *funcName) |
| 657 | { |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 658 | if (dev == NULL) { |
| 659 | return NULL; |
| 660 | } |
| 661 | |
| 662 | /* loader uses this to force layer initialization; device object is wrapped */ |
| 663 | if (!strcmp(funcName, "vkGetDeviceProcAddr")) { |
| 664 | initDeviceTable(screenshot_device_table_map, (const VkBaseLayerObject *) dev); |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 665 | return (PFN_vkVoidFunction)vkGetDeviceProcAddr; |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 666 | } |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 667 | if (!strcmp(funcName, "vkCreateDevice")) |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 668 | return (PFN_vkVoidFunction) vkCreateDevice; |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 669 | |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 670 | if (!strcmp(funcName, "vkGetDeviceQueue")) |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 671 | return (PFN_vkVoidFunction) vkGetDeviceQueue; |
| 672 | |
| 673 | if (!strcmp(funcName, "vkCreateCommandPool")) |
| 674 | return (PFN_vkVoidFunction) vkCreateCommandPool; |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 675 | |
David Pinedo | bcd0e79 | 2015-06-19 13:48:18 -0600 | [diff] [blame] | 676 | VkLayerDispatchTable *pDisp = get_dispatch_table(screenshot_device_table_map, dev); |
Ian Elliott | 1064fe3 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 677 | if (deviceExtMap.size() == 0 || deviceExtMap[pDisp].wsi_enabled) |
David Pinedo | bcd0e79 | 2015-06-19 13:48:18 -0600 | [diff] [blame] | 678 | { |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame^] | 679 | if (!strcmp(funcName, "vkCreateSwapchainKHR")) |
| 680 | return (PFN_vkVoidFunction) vkCreateSwapchainKHR; |
| 681 | if (!strcmp(funcName, "vkGetSwapchainImagesKHR")) |
| 682 | return (PFN_vkVoidFunction) vkGetSwapchainImagesKHR; |
| 683 | if (!strcmp(funcName, "vkQueuePresentKHR")) |
| 684 | return (PFN_vkVoidFunction) vkQueuePresentKHR; |
David Pinedo | bcd0e79 | 2015-06-19 13:48:18 -0600 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | if (pDisp->GetDeviceProcAddr == NULL) |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 688 | return NULL; |
David Pinedo | bcd0e79 | 2015-06-19 13:48:18 -0600 | [diff] [blame] | 689 | return pDisp->GetDeviceProcAddr(dev, funcName); |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 690 | } |
David Pinedo | 3831094 | 2015-07-09 16:23:44 -0600 | [diff] [blame] | 691 | |
| 692 | |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 693 | VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName) |
David Pinedo | 3831094 | 2015-07-09 16:23:44 -0600 | [diff] [blame] | 694 | { |
David Pinedo | 3831094 | 2015-07-09 16:23:44 -0600 | [diff] [blame] | 695 | if (instance == VK_NULL_HANDLE) { |
| 696 | return NULL; |
| 697 | } |
| 698 | |
| 699 | /* loader uses this to force layer initialization; instance object is wrapped */ |
| 700 | if (!strcmp("vkGetInstanceProcAddr", funcName)) { |
| 701 | initInstanceTable((const VkBaseLayerObject *) instance); |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 702 | return (PFN_vkVoidFunction) vkGetInstanceProcAddr; |
David Pinedo | 3831094 | 2015-07-09 16:23:44 -0600 | [diff] [blame] | 703 | } |
| 704 | |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 705 | if (!strcmp(funcName, "vkEnumeratePhysicalDevices")) |
| 706 | return (PFN_vkVoidFunction)vkEnumeratePhysicalDevices; |
| 707 | |
David Pinedo | 3831094 | 2015-07-09 16:23:44 -0600 | [diff] [blame] | 708 | VkLayerInstanceDispatchTable* pTable = instance_dispatch_table(instance); |
| 709 | if (pTable->GetInstanceProcAddr == NULL) |
| 710 | return NULL; |
| 711 | return pTable->GetInstanceProcAddr(instance, funcName); |
David Pinedo | 3831094 | 2015-07-09 16:23:44 -0600 | [diff] [blame] | 712 | } |