David Pinedo | eeca2a2 | 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 | 7a51d90 | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 40 | #include "vk_loader_platform.h" |
David Pinedo | eeca2a2 | 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 | 56d204a | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 43 | #include "vk_layer_config.h" |
David Pinedo | eeca2a2 | 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 | 7a51d90 | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 46 | #include "vk_loader_platform.h" |
Tobin Ehlis | 56d204a | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 47 | #include "vk_layer_table.h" |
Courtney Goeltzenleuchter | b96abfc | 2015-07-07 11:25:43 -0600 | [diff] [blame] | 48 | #include "vk_layer_extension_utils.h" |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 49 | |
David Pinedo | 8a4f556 | 2015-06-19 13:48:18 -0600 | [diff] [blame] | 50 | |
| 51 | struct devExts { |
Ian Elliott | b134e84 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 52 | bool wsi_enabled; |
David Pinedo | 8a4f556 | 2015-06-19 13:48:18 -0600 | [diff] [blame] | 53 | }; |
| 54 | static std::unordered_map<void *, struct devExts> deviceExtMap; |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 55 | static device_table_map screenshot_device_table_map; |
David Pinedo | eeca2a2 | 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 | 98fb22a | 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 | aa4d1da | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 61 | // list of images |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 62 | typedef struct |
| 63 | { |
| 64 | VkDevice device; |
| 65 | VkExtent2D imageExtent; |
| 66 | VkFormat format; |
David Pinedo | aa4d1da | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 67 | VkImage *imageList; |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 68 | } SwapchainMapStruct; |
David Pinedo | aa4d1da | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 69 | static unordered_map<uint64_t, SwapchainMapStruct *> swapchainMap; |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 70 | |
Cody Northrop | 98fb22a | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 71 | // unordered map: associates an image with a device, image extent, and format |
David Pinedo | eeca2a2 | 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 | aa4d1da | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 78 | static unordered_map<uint64_t, ImageMapStruct *> imageMap; |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 79 | |
Cody Northrop | 98fb22a | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 80 | // unordered map: associates a device with a queue, cmdPool, and physical device |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 81 | typedef struct |
| 82 | { |
| 83 | VkQueue queue; |
David Pinedo | aa4d1da | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 84 | VkCmdPool cmdPool; |
Cody Northrop | 98fb22a | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 85 | VkPhysicalDevice physicalDevice; |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 86 | } DeviceMapStruct; |
| 87 | static unordered_map<VkDevice, DeviceMapStruct *> deviceMap; |
| 88 | |
Cody Northrop | 98fb22a | 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 | eeca2a2 | 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 | 98fb22a | 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 | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 123 | static void init_screenshot() |
| 124 | { |
David Pinedo | eeca2a2 | 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 | aa4d1da | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 145 | VkDevice device = imageMap[image1.handle]->device; |
Cody Northrop | 98fb22a | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 146 | VkPhysicalDevice physicalDevice = deviceMap[device]->physicalDevice; |
| 147 | VkInstance instance = physDeviceMap[physicalDevice]->instance; |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 148 | VkQueue queue = deviceMap[device]->queue; |
David Pinedo | aa4d1da | 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 | eeca2a2 | 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 | eeca2a2 | 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 | 46d10d0 | 2015-09-01 11:47:50 -0600 | [diff] [blame] | 171 | 0 // memoryTypeIndex, queried later |
David Pinedo | eeca2a2 | 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 | aa4d1da | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 176 | deviceMap[device]->cmdPool, |
Chia-I Wu | 88eaa3b | 2015-06-26 15:34:39 +0800 | [diff] [blame] | 177 | VK_CMD_BUFFER_LEVEL_PRIMARY, |
David Pinedo | eeca2a2 | 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 | eeca2a2 | 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 | c325666 | 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 | 98fb22a | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 198 | VkLayerInstanceDispatchTable* pInstanceTable; |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 199 | VkLayerDispatchTable* pTableCmdBuffer; |
Cody Northrop | 98fb22a | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 200 | VkPhysicalDeviceMemoryProperties memory_properties; |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 201 | |
David Pinedo | aa4d1da | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 202 | if (imageMap.empty() || imageMap.find(image1.handle) == imageMap.end()) |
David Pinedo | eeca2a2 | 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 | aa4d1da | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 216 | err = pTableDevice->GetImageMemoryRequirements(device, image2, &memRequirements); |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 217 | assert(!err); |
| 218 | |
| 219 | memAllocInfo.allocationSize = memRequirements.size; |
Cody Northrop | 98fb22a | 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 | 46d10d0 | 2015-09-01 11:47:50 -0600 | [diff] [blame] | 226 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, |
Cody Northrop | 98fb22a | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 227 | &memAllocInfo.memoryTypeIndex); |
| 228 | assert(!err); |
| 229 | |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 230 | err = pTableDevice->AllocMemory(device, &memAllocInfo, &mem2); |
| 231 | assert(!err); |
| 232 | |
David Pinedo | aa4d1da | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 233 | err = pTableQueue->BindImageMemory(device, image2, mem2, 0); |
David Pinedo | eeca2a2 | 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 | 46d10d0 | 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 | eeca2a2 | 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 | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 261 | err = pTableDevice->GetImageSubresourceLayout(device, image2, &sr, &sr_layout); |
David Pinedo | eeca2a2 | 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 | aa4d1da | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 296 | // TODO: add support for additional formats |
David Pinedo | eeca2a2 | 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 |
Mark Lobodzinski | 67b42b7 | 2015-09-07 13:59:43 -0600 | [diff] [blame^] | 305 | pTableDevice->UnmapMemory(device, mem2); |
| 306 | pTableDevice->FreeMemory(device, mem2); |
| 307 | pTableDevice->DestroyCommandBuffer(device, cmdBuffer); |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | |
David Pinedo | 8a4f556 | 2015-06-19 13:48:18 -0600 | [diff] [blame] | 311 | static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device) |
| 312 | { |
Cody Northrop | 1684adb | 2015-08-05 11:15:02 -0600 | [diff] [blame] | 313 | uint32_t i; |
David Pinedo | 8a4f556 | 2015-06-19 13:48:18 -0600 | [diff] [blame] | 314 | VkLayerDispatchTable *pDisp = get_dispatch_table(screenshot_device_table_map, device); |
Ian Elliott | b134e84 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 315 | deviceExtMap[pDisp].wsi_enabled = false; |
David Pinedo | 8a4f556 | 2015-06-19 13:48:18 -0600 | [diff] [blame] | 316 | for (i = 0; i < pCreateInfo->extensionCount; i++) { |
Ian Elliott | 338dedb | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 317 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_EXT_KHR_DEVICE_SWAPCHAIN_EXTENSION_NAME) == 0) |
Ian Elliott | b134e84 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 318 | deviceExtMap[pDisp].wsi_enabled = true; |
David Pinedo | 8a4f556 | 2015-06-19 13:48:18 -0600 | [diff] [blame] | 319 | } |
| 320 | } |
| 321 | |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 322 | VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice( |
| 323 | VkPhysicalDevice gpu, |
| 324 | const VkDeviceCreateInfo *pCreateInfo, |
| 325 | VkDevice *pDevice) |
| 326 | { |
Courtney Goeltzenleuchter | be63799 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 327 | VkLayerDispatchTable *pDisp = get_dispatch_table(screenshot_device_table_map, *pDevice); |
| 328 | VkResult result = pDisp->CreateDevice(gpu, pCreateInfo, pDevice); |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 329 | |
David Pinedo | 8a4f556 | 2015-06-19 13:48:18 -0600 | [diff] [blame] | 330 | if (result == VK_SUCCESS) { |
Jon Ashburn | 59f3dfc | 2015-07-06 15:09:36 -0600 | [diff] [blame] | 331 | init_screenshot(); |
David Pinedo | 8a4f556 | 2015-06-19 13:48:18 -0600 | [diff] [blame] | 332 | createDeviceRegisterExtensions(pCreateInfo, *pDevice); |
Cody Northrop | 98fb22a | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 333 | // Create a mapping from a device to a physicalDevice |
| 334 | if (deviceMap[*pDevice] == NULL) |
| 335 | { |
| 336 | DeviceMapStruct *deviceMapElem = new DeviceMapStruct; |
| 337 | deviceMap[*pDevice] = deviceMapElem; |
| 338 | } |
| 339 | deviceMap[*pDevice]->physicalDevice = gpu; |
David Pinedo | 8a4f556 | 2015-06-19 13:48:18 -0600 | [diff] [blame] | 340 | } |
| 341 | |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 342 | return result; |
| 343 | } |
| 344 | |
Cody Northrop | 98fb22a | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 345 | VK_LAYER_EXPORT VkResult VKAPI vkEnumeratePhysicalDevices( |
| 346 | VkInstance instance, |
| 347 | uint32_t* pPhysicalDeviceCount, |
| 348 | VkPhysicalDevice* pPhysicalDevices) |
| 349 | { |
| 350 | VkResult result; |
| 351 | |
| 352 | VkLayerInstanceDispatchTable* pTable = instance_dispatch_table(instance); |
| 353 | result = pTable->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices); |
Tobin Ehlis | d8dd86b | 2015-09-08 08:59:48 -0600 | [diff] [blame] | 354 | if (result==VK_SUCCESS && *pPhysicalDeviceCount > 0 && pPhysicalDevices) |
Cody Northrop | 98fb22a | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 355 | { |
| 356 | for (uint32_t i=0; i<*pPhysicalDeviceCount ; i++) |
| 357 | { |
| 358 | // Create a mapping from a physicalDevice to an instance |
| 359 | if (physDeviceMap[pPhysicalDevices[i]] == NULL) |
| 360 | { |
| 361 | PhysDeviceMapStruct *physDeviceMapElem = new PhysDeviceMapStruct; |
| 362 | physDeviceMap[pPhysicalDevices[i]] = physDeviceMapElem; |
| 363 | } |
| 364 | physDeviceMap[pPhysicalDevices[i]]->instance = instance; |
| 365 | } |
| 366 | } |
| 367 | return result; |
| 368 | } |
| 369 | |
Courtney Goeltzenleuchter | be63799 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 370 | /* TODO: Probably need a DestroyDevice as well */ |
| 371 | |
Courtney Goeltzenleuchter | b96abfc | 2015-07-07 11:25:43 -0600 | [diff] [blame] | 372 | static const VkLayerProperties ss_device_layers[] = { |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 373 | { |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 374 | "ScreenShot", |
Courtney Goeltzenleuchter | b96abfc | 2015-07-07 11:25:43 -0600 | [diff] [blame] | 375 | VK_API_VERSION, |
| 376 | VK_MAKE_VERSION(0, 1, 0), |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 377 | "Layer: ScreenShot", |
David Pinedo | 8a4f556 | 2015-06-19 13:48:18 -0600 | [diff] [blame] | 378 | } |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 379 | }; |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 380 | |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 381 | VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionProperties( |
Courtney Goeltzenleuchter | b96abfc | 2015-07-07 11:25:43 -0600 | [diff] [blame] | 382 | const char *pLayerName, |
| 383 | uint32_t *pCount, |
| 384 | VkExtensionProperties* pProperties) |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 385 | { |
Courtney Goeltzenleuchter | b96abfc | 2015-07-07 11:25:43 -0600 | [diff] [blame] | 386 | /* ScreenShot does not have any global extensions */ |
| 387 | return util_GetExtensionProperties(0, NULL, pCount, pProperties); |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 388 | } |
Courtney Goeltzenleuchter | b96abfc | 2015-07-07 11:25:43 -0600 | [diff] [blame] | 389 | |
| 390 | VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalLayerProperties( |
| 391 | uint32_t *pCount, |
| 392 | VkLayerProperties* pProperties) |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 393 | { |
Courtney Goeltzenleuchter | b96abfc | 2015-07-07 11:25:43 -0600 | [diff] [blame] | 394 | /* ScreenShot does not have any global layers */ |
| 395 | return util_GetLayerProperties(0, NULL, |
| 396 | pCount, pProperties); |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceExtensionProperties( |
Courtney Goeltzenleuchter | b96abfc | 2015-07-07 11:25:43 -0600 | [diff] [blame] | 400 | VkPhysicalDevice physicalDevice, |
| 401 | const char* pLayerName, |
| 402 | uint32_t* pCount, |
| 403 | VkExtensionProperties* pProperties) |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 404 | { |
Courtney Goeltzenleuchter | b96abfc | 2015-07-07 11:25:43 -0600 | [diff] [blame] | 405 | /* ScreenShot does not have any physical device extensions */ |
| 406 | return util_GetExtensionProperties(0, NULL, pCount, pProperties); |
| 407 | } |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 408 | |
Courtney Goeltzenleuchter | b96abfc | 2015-07-07 11:25:43 -0600 | [diff] [blame] | 409 | VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceLayerProperties( |
| 410 | VkPhysicalDevice physicalDevice, |
| 411 | uint32_t* pCount, |
| 412 | VkLayerProperties* pProperties) |
| 413 | { |
| 414 | return util_GetLayerProperties(ARRAY_SIZE(ss_device_layers), |
| 415 | ss_device_layers, |
| 416 | pCount, pProperties); |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | VK_LAYER_EXPORT VkResult VKAPI vkGetDeviceQueue( |
| 420 | VkDevice device, |
| 421 | uint32_t queueNodeIndex, |
| 422 | uint32_t queueIndex, |
| 423 | VkQueue *pQueue) |
| 424 | { |
| 425 | VkLayerDispatchTable* pTable = screenshot_device_table_map[device]; |
| 426 | VkResult result = get_dispatch_table(screenshot_device_table_map, device)->GetDeviceQueue(device, queueNodeIndex, queueIndex, pQueue); |
| 427 | |
| 428 | loader_platform_thread_lock_mutex(&globalLock); |
| 429 | if (screenshotEnvQueried && screenshotFrames.empty()) { |
| 430 | // We are all done taking screenshots, so don't do anything else |
| 431 | loader_platform_thread_unlock_mutex(&globalLock); |
| 432 | return result; |
| 433 | } |
| 434 | |
| 435 | if (result == VK_SUCCESS) { |
| 436 | screenshot_device_table_map.emplace(*pQueue, pTable); |
| 437 | |
Cody Northrop | 98fb22a | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 438 | // Create a mapping from a device to a queue |
| 439 | if (deviceMap[device] == NULL) |
| 440 | { |
| 441 | DeviceMapStruct *deviceMapElem = new DeviceMapStruct; |
| 442 | deviceMap[device] = deviceMapElem; |
| 443 | } |
| 444 | deviceMap[device]->queue = *pQueue; |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 445 | } |
| 446 | loader_platform_thread_unlock_mutex(&globalLock); |
| 447 | return result; |
| 448 | } |
| 449 | |
David Pinedo | aa4d1da | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 450 | VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandPool( |
| 451 | VkDevice device, |
| 452 | const VkCmdPoolCreateInfo *pCreateInfo, |
| 453 | VkCmdPool *pCmdPool) |
| 454 | { |
| 455 | VkLayerDispatchTable* pTable = screenshot_device_table_map[device]; |
| 456 | VkResult result = get_dispatch_table(screenshot_device_table_map, device)->CreateCommandPool(device, pCreateInfo, pCmdPool); |
| 457 | |
| 458 | loader_platform_thread_lock_mutex(&globalLock); |
| 459 | if (screenshotEnvQueried && screenshotFrames.empty()) { |
| 460 | // We are all done taking screenshots, so don't do anything else |
| 461 | loader_platform_thread_unlock_mutex(&globalLock); |
| 462 | return result; |
| 463 | } |
| 464 | |
Cody Northrop | 98fb22a | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 465 | // Create a mapping from a device to a cmdPool |
| 466 | if (deviceMap[device] == NULL) |
| 467 | { |
| 468 | DeviceMapStruct *deviceMapElem = new DeviceMapStruct; |
| 469 | deviceMap[device] = deviceMapElem; |
| 470 | } |
David Pinedo | aa4d1da | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 471 | deviceMap[device]->cmdPool = *pCmdPool; |
| 472 | loader_platform_thread_unlock_mutex(&globalLock); |
| 473 | return result; |
| 474 | } |
| 475 | |
Ian Elliott | 338dedb | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 476 | VK_LAYER_EXPORT VkResult VKAPI vkCreateSwapchainKHR( |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 477 | VkDevice device, |
Ian Elliott | 338dedb | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 478 | const VkSwapchainCreateInfoKHR *pCreateInfo, |
| 479 | VkSwapchainKHR *pSwapchain) |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 480 | { |
| 481 | VkLayerDispatchTable* pTable = screenshot_device_table_map[device]; |
Ian Elliott | 338dedb | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 482 | VkResult result = get_dispatch_table(screenshot_device_table_map, device)->CreateSwapchainKHR(device, pCreateInfo, pSwapchain); |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 483 | |
| 484 | loader_platform_thread_lock_mutex(&globalLock); |
| 485 | if (screenshotEnvQueried && screenshotFrames.empty()) { |
| 486 | // We are all done taking screenshots, so don't do anything else |
| 487 | loader_platform_thread_unlock_mutex(&globalLock); |
| 488 | return result; |
| 489 | } |
| 490 | |
| 491 | if (result == VK_SUCCESS) |
| 492 | { |
| 493 | // Create a mapping for a swapchain to a device, image extent, and format |
| 494 | SwapchainMapStruct *swapchainMapElem = new SwapchainMapStruct; |
| 495 | swapchainMapElem->device = device; |
| 496 | swapchainMapElem->imageExtent = pCreateInfo->imageExtent; |
| 497 | swapchainMapElem->format = pCreateInfo->imageFormat; |
Ian Elliott | 338dedb | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 498 | swapchainMap.insert(make_pair(pSwapchain->handle, swapchainMapElem)); |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 499 | |
| 500 | // Create a mapping for the swapchain object into the dispatch table |
Ian Elliott | 338dedb | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 501 | screenshot_device_table_map.emplace((void *)pSwapchain->handle, pTable); |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 502 | } |
| 503 | loader_platform_thread_unlock_mutex(&globalLock); |
| 504 | |
| 505 | return result; |
| 506 | } |
| 507 | |
Ian Elliott | 338dedb | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 508 | VK_LAYER_EXPORT VkResult VKAPI vkGetSwapchainImagesKHR( |
Ian Elliott | b134e84 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 509 | VkDevice device, |
Ian Elliott | 338dedb | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 510 | VkSwapchainKHR swapchain, |
Ian Elliott | ccac023 | 2015-08-07 14:11:14 -0600 | [diff] [blame] | 511 | uint32_t* pCount, |
Ian Elliott | 338dedb | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 512 | VkImage* pSwapchainImages) |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 513 | { |
Ian Elliott | 338dedb | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 514 | VkResult result = get_dispatch_table(screenshot_device_table_map, device)->GetSwapchainImagesKHR(device, swapchain, pCount, pSwapchainImages); |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 515 | |
| 516 | loader_platform_thread_lock_mutex(&globalLock); |
| 517 | if (screenshotEnvQueried && screenshotFrames.empty()) { |
| 518 | // We are all done taking screenshots, so don't do anything else |
| 519 | loader_platform_thread_unlock_mutex(&globalLock); |
| 520 | return result; |
| 521 | } |
| 522 | |
| 523 | if (result == VK_SUCCESS && |
Ian Elliott | 338dedb | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 524 | pSwapchainImages && |
| 525 | !swapchainMap.empty() && swapchainMap.find(swapchain.handle) != swapchainMap.end()) |
Ian Elliott | ccac023 | 2015-08-07 14:11:14 -0600 | [diff] [blame] | 526 | { |
Cody Northrop | 46d92c0 | 2015-09-01 11:48:13 -0600 | [diff] [blame] | 527 | unsigned i; |
David Pinedo | aa4d1da | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 528 | |
Ian Elliott | ccac023 | 2015-08-07 14:11:14 -0600 | [diff] [blame] | 529 | for (i=0; i<*pCount; i++) |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 530 | { |
| 531 | // Create a mapping for an image to a device, image extent, and format |
Ian Elliott | 338dedb | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 532 | if (imageMap[pSwapchainImages[i].handle] == NULL) |
Cody Northrop | 98fb22a | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 533 | { |
| 534 | ImageMapStruct *imageMapElem = new ImageMapStruct; |
Ian Elliott | 338dedb | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 535 | imageMap[pSwapchainImages[i].handle] = imageMapElem; |
Cody Northrop | 98fb22a | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 536 | } |
Ian Elliott | 338dedb | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 537 | imageMap[pSwapchainImages[i].handle]->device = swapchainMap[swapchain.handle]->device; |
| 538 | imageMap[pSwapchainImages[i].handle]->imageExtent = swapchainMap[swapchain.handle]->imageExtent; |
| 539 | imageMap[pSwapchainImages[i].handle]->format = swapchainMap[swapchain.handle]->format; |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 540 | } |
David Pinedo | aa4d1da | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 541 | |
| 542 | // Add list of images to swapchain to image map |
Ian Elliott | 338dedb | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 543 | SwapchainMapStruct *swapchainMapElem = swapchainMap[swapchain.handle]; |
David Pinedo | aa4d1da | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 544 | if (i >= 1 && swapchainMapElem) |
| 545 | { |
| 546 | VkImage *imageList = new VkImage[i]; |
| 547 | swapchainMapElem->imageList = imageList; |
Cody Northrop | 46d92c0 | 2015-09-01 11:48:13 -0600 | [diff] [blame] | 548 | for (unsigned j=0; j<i; j++) |
David Pinedo | aa4d1da | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 549 | { |
Ian Elliott | 338dedb | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 550 | swapchainMapElem->imageList[j] = pSwapchainImages[j].handle; |
David Pinedo | aa4d1da | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 551 | } |
| 552 | } |
| 553 | |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 554 | } |
| 555 | loader_platform_thread_unlock_mutex(&globalLock); |
| 556 | return result; |
| 557 | } |
| 558 | |
Ian Elliott | 338dedb | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 559 | VK_LAYER_EXPORT VkResult VKAPI vkQueuePresentKHR(VkQueue queue, VkPresentInfoKHR* pPresentInfo) |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 560 | { |
| 561 | static int frameNumber = 0; |
David Pinedo | aa4d1da | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 562 | if (frameNumber == 10) {fflush(stdout); /* *((int*)0)=0; */ } |
Ian Elliott | 338dedb | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 563 | VkResult result = get_dispatch_table(screenshot_device_table_map, queue)->QueuePresentKHR(queue, pPresentInfo); |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 564 | |
| 565 | loader_platform_thread_lock_mutex(&globalLock); |
| 566 | |
| 567 | if (!screenshotEnvQueried) |
| 568 | { |
| 569 | const char *_vk_screenshot = getenv("_VK_SCREENSHOT"); |
| 570 | if (_vk_screenshot && *_vk_screenshot) |
| 571 | { |
| 572 | string spec(_vk_screenshot), word; |
| 573 | size_t start = 0, comma = 0; |
| 574 | |
| 575 | while (start < spec.size()) { |
| 576 | int frameToAdd; |
| 577 | comma = spec.find(',', start); |
| 578 | if (comma == string::npos) |
| 579 | word = string(spec, start); |
| 580 | else |
| 581 | word = string(spec, start, comma - start); |
| 582 | frameToAdd=atoi(word.c_str()); |
| 583 | // Add the frame number to list, but only do it if the word started with a digit and if |
| 584 | // it's not already in the list |
| 585 | if (*(word.c_str()) >= '0' && *(word.c_str()) <= '9' && |
| 586 | find(screenshotFrames.begin(), screenshotFrames.end(), frameToAdd) == screenshotFrames.end()) |
| 587 | { |
| 588 | screenshotFrames.push_back(frameToAdd); |
| 589 | } |
| 590 | if (comma == string::npos) |
| 591 | break; |
| 592 | start = comma + 1; |
| 593 | } |
| 594 | } |
| 595 | screenshotEnvQueried = true; |
| 596 | } |
| 597 | |
| 598 | |
| 599 | if (result == VK_SUCCESS && !screenshotFrames.empty()) |
| 600 | { |
| 601 | vector<int>::iterator it; |
| 602 | it = find(screenshotFrames.begin(), screenshotFrames.end(), frameNumber); |
| 603 | if (it != screenshotFrames.end()) |
| 604 | { |
| 605 | string fileName; |
| 606 | fileName = to_string(frameNumber) + ".ppm"; |
David Pinedo | aa4d1da | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 607 | |
| 608 | VkImage image; |
Ian Elliott | 338dedb | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 609 | uint64_t swapchain; |
David Pinedo | aa4d1da | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 610 | // We'll dump only one image: the first |
Ian Elliott | 338dedb | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 611 | swapchain = pPresentInfo->swapchains[0].handle; |
| 612 | image = swapchainMap[swapchain]->imageList[pPresentInfo->imageIndices[0]]; |
David Pinedo | aa4d1da | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 613 | writePPM(fileName.c_str(), image); |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 614 | screenshotFrames.erase(it); |
| 615 | |
| 616 | if (screenshotFrames.empty()) |
| 617 | { |
David Pinedo | aa4d1da | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 618 | // Free all our maps since we are done with them. |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 619 | for (auto it = swapchainMap.begin(); it != swapchainMap.end(); it++) |
| 620 | { |
| 621 | SwapchainMapStruct *swapchainMapElem = it->second; |
| 622 | delete swapchainMapElem; |
| 623 | } |
| 624 | for (auto it = imageMap.begin(); it != imageMap.end(); it++) |
| 625 | { |
| 626 | ImageMapStruct *imageMapElem = it->second; |
| 627 | delete imageMapElem; |
| 628 | } |
| 629 | for (auto it = deviceMap.begin(); it != deviceMap.end(); it++) |
| 630 | { |
| 631 | DeviceMapStruct *deviceMapElem = it->second; |
| 632 | delete deviceMapElem; |
| 633 | } |
Cody Northrop | 98fb22a | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 634 | for (auto it = physDeviceMap.begin(); it != physDeviceMap.end(); it++) |
| 635 | { |
| 636 | PhysDeviceMapStruct *physDeviceMapElem = it->second; |
| 637 | delete physDeviceMapElem; |
| 638 | } |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 639 | swapchainMap.clear(); |
| 640 | imageMap.clear(); |
| 641 | deviceMap.clear(); |
Cody Northrop | 98fb22a | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 642 | physDeviceMap.clear(); |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 643 | } |
| 644 | } |
| 645 | } |
| 646 | frameNumber++; |
| 647 | loader_platform_thread_unlock_mutex(&globalLock); |
| 648 | return result; |
| 649 | } |
| 650 | |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 651 | VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr( |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 652 | VkDevice dev, |
| 653 | const char *funcName) |
| 654 | { |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 655 | if (dev == NULL) { |
| 656 | return NULL; |
| 657 | } |
| 658 | |
| 659 | /* loader uses this to force layer initialization; device object is wrapped */ |
| 660 | if (!strcmp(funcName, "vkGetDeviceProcAddr")) { |
| 661 | initDeviceTable(screenshot_device_table_map, (const VkBaseLayerObject *) dev); |
David Pinedo | aa4d1da | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 662 | return (PFN_vkVoidFunction)vkGetDeviceProcAddr; |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 663 | } |
Courtney Goeltzenleuchter | be63799 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 664 | if (!strcmp(funcName, "vkCreateDevice")) |
David Pinedo | aa4d1da | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 665 | return (PFN_vkVoidFunction) vkCreateDevice; |
Courtney Goeltzenleuchter | be63799 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 666 | |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 667 | if (!strcmp(funcName, "vkGetDeviceQueue")) |
David Pinedo | aa4d1da | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 668 | return (PFN_vkVoidFunction) vkGetDeviceQueue; |
| 669 | |
| 670 | if (!strcmp(funcName, "vkCreateCommandPool")) |
| 671 | return (PFN_vkVoidFunction) vkCreateCommandPool; |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 672 | |
David Pinedo | 8a4f556 | 2015-06-19 13:48:18 -0600 | [diff] [blame] | 673 | VkLayerDispatchTable *pDisp = get_dispatch_table(screenshot_device_table_map, dev); |
Ian Elliott | b134e84 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 674 | if (deviceExtMap.size() == 0 || deviceExtMap[pDisp].wsi_enabled) |
David Pinedo | 8a4f556 | 2015-06-19 13:48:18 -0600 | [diff] [blame] | 675 | { |
Ian Elliott | 338dedb | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 676 | if (!strcmp(funcName, "vkCreateSwapchainKHR")) |
| 677 | return (PFN_vkVoidFunction) vkCreateSwapchainKHR; |
| 678 | if (!strcmp(funcName, "vkGetSwapchainImagesKHR")) |
| 679 | return (PFN_vkVoidFunction) vkGetSwapchainImagesKHR; |
| 680 | if (!strcmp(funcName, "vkQueuePresentKHR")) |
| 681 | return (PFN_vkVoidFunction) vkQueuePresentKHR; |
David Pinedo | 8a4f556 | 2015-06-19 13:48:18 -0600 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | if (pDisp->GetDeviceProcAddr == NULL) |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 685 | return NULL; |
David Pinedo | 8a4f556 | 2015-06-19 13:48:18 -0600 | [diff] [blame] | 686 | return pDisp->GetDeviceProcAddr(dev, funcName); |
David Pinedo | eeca2a2 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 687 | } |
David Pinedo | 07238d4 | 2015-07-09 16:23:44 -0600 | [diff] [blame] | 688 | |
| 689 | |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 690 | VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName) |
David Pinedo | 07238d4 | 2015-07-09 16:23:44 -0600 | [diff] [blame] | 691 | { |
David Pinedo | 07238d4 | 2015-07-09 16:23:44 -0600 | [diff] [blame] | 692 | if (instance == VK_NULL_HANDLE) { |
| 693 | return NULL; |
| 694 | } |
| 695 | |
| 696 | /* loader uses this to force layer initialization; instance object is wrapped */ |
| 697 | if (!strcmp("vkGetInstanceProcAddr", funcName)) { |
| 698 | initInstanceTable((const VkBaseLayerObject *) instance); |
David Pinedo | aa4d1da | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 699 | return (PFN_vkVoidFunction) vkGetInstanceProcAddr; |
David Pinedo | 07238d4 | 2015-07-09 16:23:44 -0600 | [diff] [blame] | 700 | } |
| 701 | |
Cody Northrop | 98fb22a | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 702 | if (!strcmp(funcName, "vkEnumeratePhysicalDevices")) |
| 703 | return (PFN_vkVoidFunction)vkEnumeratePhysicalDevices; |
| 704 | |
David Pinedo | 07238d4 | 2015-07-09 16:23:44 -0600 | [diff] [blame] | 705 | VkLayerInstanceDispatchTable* pTable = instance_dispatch_table(instance); |
| 706 | if (pTable->GetInstanceProcAddr == NULL) |
| 707 | return NULL; |
| 708 | return pTable->GetInstanceProcAddr(instance, funcName); |
David Pinedo | 07238d4 | 2015-07-09 16:23:44 -0600 | [diff] [blame] | 709 | } |