David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 1 | /* |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 2 | * |
Courtney Goeltzenleuchter | fcbe16f | 2015-10-29 13:50:34 -0600 | [diff] [blame] | 3 | * Copyright (C) 2015 Valve Corporation |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 6 | * copy of this software and associated documentation files (the "Software"), |
| 7 | * to deal in the Software without restriction, including without limitation |
| 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 | * and/or sell copies of the Software, and to permit persons to whom the |
| 10 | * Software is furnished to do so, subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice shall be included |
| 13 | * in all copies or substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 | * DEALINGS IN THE SOFTWARE. |
Courtney Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 22 | * |
| 23 | * Author: Cody Northrop <cody@lunarg.com> |
| 24 | * Author: David Pinedo <david@lunarg.com> |
Jon Ashburn | 0f1a533 | 2016-01-20 08:52:40 -0700 | [diff] [blame] | 25 | * Author: Jon Ashburn <jon@lunarg.com> |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 26 | */ |
| 27 | |
| 28 | #include <inttypes.h> |
| 29 | #include <stdio.h> |
| 30 | #include <stdlib.h> |
| 31 | #include <string.h> |
| 32 | #include <assert.h> |
| 33 | #include <unordered_map> |
| 34 | #include <iostream> |
| 35 | #include <algorithm> |
| 36 | #include <list> |
| 37 | #include <map> |
| 38 | #include <vector> |
| 39 | #include <fstream> |
| 40 | |
| 41 | using namespace std; |
| 42 | |
Tobin Ehlis | b835d1b | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 43 | #include "vk_loader_platform.h" |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 44 | #include "vk_dispatch_table_helper.h" |
| 45 | #include "vk_struct_string_helper_cpp.h" |
Tobin Ehlis | a0cb02e | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 46 | #include "vk_layer_config.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; |
Jon Ashburn | 0f1a533 | 2016-01-20 08:52:40 -0700 | [diff] [blame] | 56 | //TODO convert over to the new interface using locally defiend maps |
| 57 | //static instance_table_map screenshot_instance_table_map; |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 58 | |
| 59 | static int globalLockInitialized = 0; |
| 60 | static loader_platform_thread_mutex globalLock; |
| 61 | |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 62 | // 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] | 63 | // list of images |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 64 | typedef struct |
| 65 | { |
| 66 | VkDevice device; |
| 67 | VkExtent2D imageExtent; |
| 68 | VkFormat format; |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 69 | VkImage *imageList; |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 70 | } SwapchainMapStruct; |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 71 | static unordered_map<VkSwapchainKHR, SwapchainMapStruct *> swapchainMap; |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 72 | |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 73 | // unordered map: associates an image with a device, image extent, and format |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 74 | typedef struct |
| 75 | { |
| 76 | VkDevice device; |
| 77 | VkExtent2D imageExtent; |
| 78 | VkFormat format; |
| 79 | } ImageMapStruct; |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 80 | static unordered_map<VkImage, ImageMapStruct *> imageMap; |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 81 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 82 | // unordered map: associates a device with a queue, commandPool, and physical device |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 83 | typedef struct |
| 84 | { |
| 85 | VkQueue queue; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 86 | VkCommandPool commandPool; |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 87 | VkPhysicalDevice physicalDevice; |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 88 | } DeviceMapStruct; |
| 89 | static unordered_map<VkDevice, DeviceMapStruct *> deviceMap; |
| 90 | |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 91 | // unordered map: associates a physical device with an instance |
| 92 | typedef struct |
| 93 | { |
| 94 | VkInstance instance; |
| 95 | } PhysDeviceMapStruct; |
| 96 | static unordered_map<VkPhysicalDevice, PhysDeviceMapStruct *> physDeviceMap; |
| 97 | |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 98 | // List of frames to we will get a screenshot of |
| 99 | static vector<int> screenshotFrames; |
| 100 | |
| 101 | // Flag indicating we have queried _VK_SCREENSHOT env var |
| 102 | static bool screenshotEnvQueried = false; |
| 103 | |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 104 | static bool memory_type_from_properties( |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 105 | VkPhysicalDeviceMemoryProperties *memory_properties, |
| 106 | uint32_t typeBits, |
Tony Barbour | af392d0 | 2015-10-15 12:42:56 -0600 | [diff] [blame] | 107 | VkFlags requirements_mask, |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 108 | uint32_t *typeIndex) |
| 109 | { |
| 110 | // Search memtypes to find first index with those properties |
| 111 | for (uint32_t i = 0; i < 32; i++) { |
| 112 | if ((typeBits & 1) == 1) { |
| 113 | // Type is available, does it match user properties? |
Tony Barbour | af392d0 | 2015-10-15 12:42:56 -0600 | [diff] [blame] | 114 | if ((memory_properties->memoryTypes[i].propertyFlags & requirements_mask) == requirements_mask) { |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 115 | *typeIndex = i; |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 116 | return true; |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 117 | } |
| 118 | } |
| 119 | typeBits >>= 1; |
| 120 | } |
| 121 | // No memory types matched, return failure |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 122 | return false; |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 123 | } |
| 124 | |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 125 | static void init_screenshot() |
| 126 | { |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 127 | if (!globalLockInitialized) |
| 128 | { |
| 129 | // TODO/TBD: Need to delete this mutex sometime. How??? One |
| 130 | // suggestion is to call this during vkCreateInstance(), and then we |
| 131 | // can clean it up during vkDestroyInstance(). However, that requires |
| 132 | // that the layer have per-instance locks. We need to come back and |
| 133 | // address this soon. |
| 134 | loader_platform_thread_create_mutex(&globalLock); |
| 135 | globalLockInitialized = 1; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | static void writePPM( const char *filename, VkImage image1) |
| 140 | { |
| 141 | VkImage image2; |
| 142 | VkResult err; |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 143 | bool pass; |
Mark Young | 93ecb1d | 2016-01-13 13:47:16 -0700 | [diff] [blame^] | 144 | uint32_t x, y; |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 145 | const char *ptr; |
| 146 | VkDeviceMemory mem2; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 147 | VkCommandBuffer commandBuffer; |
Karl Schultz | c643fb4 | 2016-01-19 09:56:56 -0700 | [diff] [blame] | 148 | |
| 149 | if (imageMap.empty() || imageMap.find(image1) == imageMap.end()) |
| 150 | return; |
| 151 | |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 152 | VkDevice device = imageMap[image1]->device; |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 153 | VkPhysicalDevice physicalDevice = deviceMap[device]->physicalDevice; |
| 154 | VkInstance instance = physDeviceMap[physicalDevice]->instance; |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 155 | VkQueue queue = deviceMap[device]->queue; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 156 | uint32_t width = imageMap[image1]->imageExtent.width; |
| 157 | uint32_t height = imageMap[image1]->imageExtent.height; |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 158 | VkFormat format = imageMap[image1]->format; |
Courtney Goeltzenleuchter | 908e767 | 2015-10-21 17:00:51 -0600 | [diff] [blame] | 159 | const VkImageSubresource sr = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0}; |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 160 | VkSubresourceLayout sr_layout; |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 161 | const VkImageCreateInfo imgCreateInfo = { |
| 162 | VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, |
| 163 | NULL, |
Chia-I Wu | 439c077 | 2015-10-26 17:00:46 +0800 | [diff] [blame] | 164 | 0, |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 165 | VK_IMAGE_TYPE_2D, |
| 166 | format, |
| 167 | {width, height, 1}, |
| 168 | 1, |
| 169 | 1, |
Chia-I Wu | 5c17c96 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 170 | VK_SAMPLE_COUNT_1_BIT, |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 171 | VK_IMAGE_TILING_LINEAR, |
Karl Schultz | c643fb4 | 2016-01-19 09:56:56 -0700 | [diff] [blame] | 172 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 173 | VK_SHARING_MODE_EXCLUSIVE, |
| 174 | 0, |
| 175 | NULL, |
| 176 | VK_IMAGE_LAYOUT_UNDEFINED, |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 177 | }; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 178 | VkMemoryAllocateInfo memAllocInfo = { |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 179 | VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 180 | NULL, |
| 181 | 0, // allocationSize, queried later |
Cody Northrop | 488f547 | 2015-09-01 11:47:50 -0600 | [diff] [blame] | 182 | 0 // memoryTypeIndex, queried later |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 183 | }; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 184 | const VkCommandBufferAllocateInfo allocCommandBufferInfo = { |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 185 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 186 | NULL, |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 187 | deviceMap[device]->commandPool, |
| 188 | VK_COMMAND_BUFFER_LEVEL_PRIMARY, |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 189 | 1 |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 190 | }; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 191 | const VkCommandBufferBeginInfo commandBufferBeginInfo = { |
| 192 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 193 | NULL, |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 194 | VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 195 | }; |
| 196 | const VkImageCopy imageCopyRegion = { |
Karl Schultz | c643fb4 | 2016-01-19 09:56:56 -0700 | [diff] [blame] | 197 | {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}, |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 198 | {0, 0, 0}, |
Karl Schultz | c643fb4 | 2016-01-19 09:56:56 -0700 | [diff] [blame] | 199 | {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}, |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 200 | {0, 0, 0}, |
| 201 | {width, height, 1} |
| 202 | }; |
| 203 | VkMemoryRequirements memRequirements; |
David Pinedo | 6829587 | 2015-06-30 13:08:37 -0600 | [diff] [blame] | 204 | VkLayerDispatchTable* pTableDevice = get_dispatch_table(screenshot_device_table_map, device); |
| 205 | VkLayerDispatchTable* pTableQueue = get_dispatch_table(screenshot_device_table_map, queue); |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 206 | VkLayerInstanceDispatchTable* pInstanceTable; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 207 | VkLayerDispatchTable* pTableCommandBuffer; |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 208 | VkPhysicalDeviceMemoryProperties memory_properties; |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 209 | |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 210 | // The VkImage image1 we are going to dump may not be mappable, |
| 211 | // and/or it may have a tiling mode of optimal rather than linear. |
| 212 | // To make sure we have an image that we can map and read linearly, we: |
| 213 | // create image2 that is mappable and linear |
| 214 | // copy image1 to image2 |
| 215 | // map image2 |
Karl Schultz | c643fb4 | 2016-01-19 09:56:56 -0700 | [diff] [blame] | 216 | // read from image2's mapped memory. |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 217 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 218 | err = pTableDevice->CreateImage(device, &imgCreateInfo, NULL, &image2); |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 219 | assert(!err); |
| 220 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 221 | pTableDevice->GetImageMemoryRequirements(device, image2, &memRequirements); |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 222 | |
| 223 | memAllocInfo.allocationSize = memRequirements.size; |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 224 | pInstanceTable = instance_dispatch_table(instance); |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 225 | pInstanceTable->GetPhysicalDeviceMemoryProperties(physicalDevice, &memory_properties); |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 226 | |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 227 | pass = memory_type_from_properties(&memory_properties, |
Karl Schultz | c643fb4 | 2016-01-19 09:56:56 -0700 | [diff] [blame] | 228 | memRequirements.memoryTypeBits, |
| 229 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, |
| 230 | &memAllocInfo.memoryTypeIndex); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 231 | assert(pass); |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 232 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 233 | err = pTableDevice->AllocateMemory(device, &memAllocInfo, NULL, &mem2); |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 234 | assert(!err); |
| 235 | |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 236 | err = pTableQueue->BindImageMemory(device, image2, mem2, 0); |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 237 | assert(!err); |
| 238 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 239 | err = pTableDevice->AllocateCommandBuffers(device, &allocCommandBufferInfo, &commandBuffer); |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 240 | assert(!err); |
| 241 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 242 | screenshot_device_table_map.emplace(commandBuffer, pTableDevice); |
| 243 | pTableCommandBuffer = screenshot_device_table_map[commandBuffer]; |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 244 | |
Karl Schultz | c643fb4 | 2016-01-19 09:56:56 -0700 | [diff] [blame] | 245 | // We have just created a dispatchable object, but the dispatch table has not been placed |
| 246 | // in the object yet. When a "normal" application creates a command buffer, the dispatch |
| 247 | // table is installed by the top-level api binding (trampoline.c). |
| 248 | // But here, we have to do it ourselves. |
| 249 | *((const void**)commandBuffer) = *(void**)device; |
| 250 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 251 | err = pTableCommandBuffer->BeginCommandBuffer(commandBuffer, &commandBufferBeginInfo); |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 252 | assert(!err); |
| 253 | |
Karl Schultz | c643fb4 | 2016-01-19 09:56:56 -0700 | [diff] [blame] | 254 | // Transition the source image layout to prepare it for the copy. |
| 255 | |
| 256 | VkImageMemoryBarrier image1_memory_barrier = { |
| 257 | VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, |
| 258 | NULL, |
| 259 | 0, |
| 260 | VK_ACCESS_TRANSFER_READ_BIT, |
| 261 | VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, |
| 262 | VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, |
| 263 | 0, |
| 264 | 0, |
| 265 | image1, |
| 266 | { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } |
| 267 | }; |
| 268 | |
| 269 | VkImageMemoryBarrier image2_memory_barrier = { |
| 270 | VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, |
| 271 | NULL, |
| 272 | 0, |
| 273 | VK_ACCESS_TRANSFER_READ_BIT, |
| 274 | VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 275 | VK_IMAGE_LAYOUT_GENERAL, |
| 276 | 0, |
| 277 | 0, |
| 278 | image2, |
| 279 | { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } |
| 280 | }; |
| 281 | |
| 282 | VkPipelineStageFlags src_stages = VK_PIPELINE_STAGE_TRANSFER_BIT; |
| 283 | VkPipelineStageFlags dst_stages = VK_PIPELINE_STAGE_TRANSFER_BIT; |
| 284 | |
| 285 | pTableCommandBuffer->CmdPipelineBarrier(commandBuffer, src_stages, dst_stages, |
| 286 | 0, 0, NULL, 0, NULL, 1, &image1_memory_barrier); |
| 287 | |
| 288 | pTableCommandBuffer->CmdCopyImage(commandBuffer, |
| 289 | image1, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, |
| 290 | image2, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 291 | 1, &imageCopyRegion); |
| 292 | |
| 293 | pTableCommandBuffer->CmdPipelineBarrier(commandBuffer, src_stages, dst_stages, |
| 294 | 0, 0, NULL, 0, NULL, 1, &image2_memory_barrier); |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 295 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 296 | err = pTableCommandBuffer->EndCommandBuffer(commandBuffer); |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 297 | assert(!err); |
| 298 | |
Courtney Goeltzenleuchter | 646b907 | 2015-10-20 18:04:07 -0600 | [diff] [blame] | 299 | VkFence nullFence = { VK_NULL_HANDLE }; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 300 | VkSubmitInfo submit_info; |
Chia-I Wu | f9be13c | 2015-10-26 20:37:06 +0800 | [diff] [blame] | 301 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 302 | submit_info.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 303 | submit_info.waitSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 304 | submit_info.pWaitSemaphores = NULL; |
Jon Ashburn | 7f9716c | 2015-12-30 16:42:50 -0700 | [diff] [blame] | 305 | submit_info.pWaitDstStageMask = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 306 | submit_info.commandBufferCount = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 307 | submit_info.pCommandBuffers = &commandBuffer; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 308 | submit_info.signalSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 309 | submit_info.pSignalSemaphores = NULL; |
Courtney Goeltzenleuchter | 646b907 | 2015-10-20 18:04:07 -0600 | [diff] [blame] | 310 | |
| 311 | err = pTableQueue->QueueSubmit(queue, 1, &submit_info, nullFence); |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 312 | assert(!err); |
| 313 | |
| 314 | err = pTableQueue->QueueWaitIdle(queue); |
| 315 | assert(!err); |
| 316 | |
| 317 | err = pTableDevice->DeviceWaitIdle(device); |
| 318 | assert(!err); |
| 319 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 320 | pTableDevice->GetImageSubresourceLayout(device, image2, &sr, &sr_layout); |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 321 | |
| 322 | err = pTableDevice->MapMemory(device, mem2, 0, 0, 0, (void **) &ptr ); |
| 323 | assert(!err); |
| 324 | |
| 325 | ptr += sr_layout.offset; |
| 326 | |
| 327 | ofstream file(filename, ios::binary); |
| 328 | |
| 329 | file << "P6\n"; |
| 330 | file << width << "\n"; |
| 331 | file << height << "\n"; |
| 332 | file << 255 << "\n"; |
| 333 | |
| 334 | for (y = 0; y < height; y++) { |
| 335 | const unsigned int *row = (const unsigned int*) ptr; |
| 336 | if (format == VK_FORMAT_B8G8R8A8_UNORM) |
| 337 | { |
| 338 | for (x = 0; x < width; x++) { |
| 339 | unsigned int swapped; |
| 340 | swapped = (*row & 0xff00ff00) | (*row & 0x000000ff) << 16 | (*row & 0x00ff0000) >> 16; |
| 341 | file.write((char *)&swapped, 3); |
| 342 | row++; |
| 343 | } |
| 344 | } |
| 345 | else if (format == VK_FORMAT_R8G8B8A8_UNORM) |
| 346 | { |
| 347 | for (x = 0; x < width; x++) { |
| 348 | file.write((char *)row, 3); |
| 349 | row++; |
| 350 | } |
| 351 | } |
| 352 | else |
| 353 | { |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 354 | // TODO: add support for additional formats |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 355 | printf("Unrecognized image format\n"); |
| 356 | break; |
| 357 | } |
| 358 | ptr += sr_layout.rowPitch; |
| 359 | } |
| 360 | file.close(); |
Karl Schultz | c643fb4 | 2016-01-19 09:56:56 -0700 | [diff] [blame] | 361 | pTableDevice->UnmapMemory(device, mem2); |
| 362 | |
| 363 | // Restore the swap chain image layout to what it was before. |
| 364 | // This may not be strictly needed, but it is generally good to restore things to original state. |
| 365 | err = pTableCommandBuffer->BeginCommandBuffer(commandBuffer, &commandBufferBeginInfo); |
| 366 | assert(!err); |
| 367 | image1_memory_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 368 | image1_memory_barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; |
| 369 | |
| 370 | pTableCommandBuffer->CmdPipelineBarrier(commandBuffer, src_stages, dst_stages, |
| 371 | 0, 0, NULL, 0, NULL, 1, &image1_memory_barrier); |
| 372 | err = pTableCommandBuffer->EndCommandBuffer(commandBuffer); |
| 373 | assert(!err); |
| 374 | |
| 375 | err = pTableQueue->QueueSubmit(queue, 1, &submit_info, nullFence); |
| 376 | assert(!err); |
| 377 | |
| 378 | err = pTableQueue->QueueWaitIdle(queue); |
| 379 | assert(!err); |
| 380 | |
| 381 | err = pTableDevice->DeviceWaitIdle(device); |
| 382 | assert(!err); |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 383 | |
| 384 | // Clean up |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 385 | pTableDevice->FreeMemory(device, mem2, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 386 | pTableDevice->FreeCommandBuffers(device, deviceMap[device]->commandPool, 1, &commandBuffer); |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 387 | } |
| 388 | |
Jon Ashburn | 0f1a533 | 2016-01-20 08:52:40 -0700 | [diff] [blame] | 389 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance( |
| 390 | const VkInstanceCreateInfo* pCreateInfo, |
| 391 | const VkAllocationCallbacks* pAllocator, |
| 392 | VkInstance* pInstance) |
| 393 | { |
| 394 | VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); |
| 395 | |
| 396 | assert(chain_info->u.pLayerInfo); |
| 397 | PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr; |
| 398 | assert(fpGetInstanceProcAddr); |
| 399 | PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance) fpGetInstanceProcAddr(*pInstance, "vkCreateInstance"); |
| 400 | if (fpCreateInstance == NULL) { |
| 401 | return VK_ERROR_INITIALIZATION_FAILED; |
| 402 | } |
| 403 | |
| 404 | // Advance the link info for the next element on the chain |
| 405 | chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext; |
| 406 | |
| 407 | VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance); |
| 408 | if (result != VK_SUCCESS) |
| 409 | return result; |
| 410 | |
| 411 | initInstanceTable(*pInstance, fpGetInstanceProcAddr); |
| 412 | |
| 413 | init_screenshot(); |
| 414 | |
| 415 | return result; |
| 416 | } |
| 417 | |
| 418 | //TODO hook DestroyInstance to cleanup |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 419 | |
David Pinedo | bcd0e79 | 2015-06-19 13:48:18 -0600 | [diff] [blame] | 420 | static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device) |
| 421 | { |
Cody Northrop | d2ad034 | 2015-08-05 11:15:02 -0600 | [diff] [blame] | 422 | uint32_t i; |
David Pinedo | bcd0e79 | 2015-06-19 13:48:18 -0600 | [diff] [blame] | 423 | VkLayerDispatchTable *pDisp = get_dispatch_table(screenshot_device_table_map, device); |
Jon Ashburn | 8acd233 | 2015-09-16 18:08:32 -0600 | [diff] [blame] | 424 | PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr; |
Jon Ashburn | 8acd233 | 2015-09-16 18:08:32 -0600 | [diff] [blame] | 425 | pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR) gpa(device, "vkCreateSwapchainKHR"); |
Jon Ashburn | 8acd233 | 2015-09-16 18:08:32 -0600 | [diff] [blame] | 426 | pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR) gpa(device, "vkGetSwapchainImagesKHR"); |
| 427 | pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR) gpa(device, "vkAcquireNextImageKHR"); |
| 428 | pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR) gpa(device, "vkQueuePresentKHR"); |
Ian Elliott | 1064fe3 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 429 | deviceExtMap[pDisp].wsi_enabled = false; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 430 | for (i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
Ian Elliott | 0584606 | 2015-11-20 14:13:17 -0700 | [diff] [blame] | 431 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) |
Ian Elliott | 1064fe3 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 432 | deviceExtMap[pDisp].wsi_enabled = true; |
David Pinedo | bcd0e79 | 2015-06-19 13:48:18 -0600 | [diff] [blame] | 433 | } |
| 434 | } |
| 435 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 436 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDevice( |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 437 | VkPhysicalDevice gpu, |
| 438 | const VkDeviceCreateInfo *pCreateInfo, |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 439 | const VkAllocationCallbacks* pAllocator, |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 440 | VkDevice *pDevice) |
| 441 | { |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 442 | VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 443 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 444 | assert(chain_info->u.pLayerInfo); |
| 445 | PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr; |
| 446 | PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr; |
| 447 | PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice) fpGetInstanceProcAddr(NULL, "vkCreateDevice"); |
| 448 | if (fpCreateDevice == NULL) { |
| 449 | return VK_ERROR_INITIALIZATION_FAILED; |
David Pinedo | bcd0e79 | 2015-06-19 13:48:18 -0600 | [diff] [blame] | 450 | } |
| 451 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 452 | // Advance the link info for the next element on the chain |
| 453 | chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext; |
| 454 | |
| 455 | VkResult result = fpCreateDevice(gpu, pCreateInfo, pAllocator, pDevice); |
| 456 | if (result != VK_SUCCESS) { |
| 457 | return result; |
| 458 | } |
| 459 | |
| 460 | initDeviceTable(*pDevice, fpGetDeviceProcAddr, screenshot_device_table_map); |
| 461 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 462 | createDeviceRegisterExtensions(pCreateInfo, *pDevice); |
| 463 | // Create a mapping from a device to a physicalDevice |
| 464 | if (deviceMap[*pDevice] == NULL) |
| 465 | { |
| 466 | DeviceMapStruct *deviceMapElem = new DeviceMapStruct; |
| 467 | deviceMap[*pDevice] = deviceMapElem; |
| 468 | } |
| 469 | deviceMap[*pDevice]->physicalDevice = gpu; |
| 470 | |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 471 | return result; |
| 472 | } |
| 473 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 474 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumeratePhysicalDevices( |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 475 | VkInstance instance, |
| 476 | uint32_t* pPhysicalDeviceCount, |
| 477 | VkPhysicalDevice* pPhysicalDevices) |
| 478 | { |
| 479 | VkResult result; |
| 480 | |
| 481 | VkLayerInstanceDispatchTable* pTable = instance_dispatch_table(instance); |
| 482 | result = pTable->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices); |
Tobin Ehlis | be42774 | 2015-09-08 08:59:48 -0600 | [diff] [blame] | 483 | if (result==VK_SUCCESS && *pPhysicalDeviceCount > 0 && pPhysicalDevices) |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 484 | { |
| 485 | for (uint32_t i=0; i<*pPhysicalDeviceCount ; i++) |
| 486 | { |
| 487 | // Create a mapping from a physicalDevice to an instance |
| 488 | if (physDeviceMap[pPhysicalDevices[i]] == NULL) |
| 489 | { |
| 490 | PhysDeviceMapStruct *physDeviceMapElem = new PhysDeviceMapStruct; |
| 491 | physDeviceMap[pPhysicalDevices[i]] = physDeviceMapElem; |
| 492 | } |
| 493 | physDeviceMap[pPhysicalDevices[i]]->instance = instance; |
| 494 | } |
| 495 | } |
| 496 | return result; |
| 497 | } |
| 498 | |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 499 | /* TODO: Probably need a DestroyDevice as well */ |
| 500 | |
Courtney Goeltzenleuchter | a6db346 | 2015-07-07 11:25:43 -0600 | [diff] [blame] | 501 | static const VkLayerProperties ss_device_layers[] = { |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 502 | { |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 503 | "screenshot", |
Courtney Goeltzenleuchter | a6db346 | 2015-07-07 11:25:43 -0600 | [diff] [blame] | 504 | VK_API_VERSION, |
| 505 | VK_MAKE_VERSION(0, 1, 0), |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 506 | "Layer: screenshot", |
David Pinedo | bcd0e79 | 2015-06-19 13:48:18 -0600 | [diff] [blame] | 507 | } |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 508 | }; |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 509 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 510 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties( |
Courtney Goeltzenleuchter | a6db346 | 2015-07-07 11:25:43 -0600 | [diff] [blame] | 511 | const char *pLayerName, |
| 512 | uint32_t *pCount, |
| 513 | VkExtensionProperties* pProperties) |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 514 | { |
Courtney Goeltzenleuchter | a6db346 | 2015-07-07 11:25:43 -0600 | [diff] [blame] | 515 | /* ScreenShot does not have any global extensions */ |
| 516 | return util_GetExtensionProperties(0, NULL, pCount, pProperties); |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 517 | } |
Courtney Goeltzenleuchter | a6db346 | 2015-07-07 11:25:43 -0600 | [diff] [blame] | 518 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 519 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties( |
Courtney Goeltzenleuchter | a6db346 | 2015-07-07 11:25:43 -0600 | [diff] [blame] | 520 | uint32_t *pCount, |
| 521 | VkLayerProperties* pProperties) |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 522 | { |
Courtney Goeltzenleuchter | a6db346 | 2015-07-07 11:25:43 -0600 | [diff] [blame] | 523 | /* ScreenShot does not have any global layers */ |
| 524 | return util_GetLayerProperties(0, NULL, |
| 525 | pCount, pProperties); |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 526 | } |
| 527 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 528 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties( |
Courtney Goeltzenleuchter | a6db346 | 2015-07-07 11:25:43 -0600 | [diff] [blame] | 529 | VkPhysicalDevice physicalDevice, |
| 530 | const char* pLayerName, |
| 531 | uint32_t* pCount, |
| 532 | VkExtensionProperties* pProperties) |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 533 | { |
Courtney Goeltzenleuchter | a6db346 | 2015-07-07 11:25:43 -0600 | [diff] [blame] | 534 | /* ScreenShot does not have any physical device extensions */ |
Jon Ashburn | 751c484 | 2015-11-02 17:37:20 -0700 | [diff] [blame] | 535 | if (pLayerName == NULL) { |
| 536 | VkLayerInstanceDispatchTable* pTable = instance_dispatch_table(physicalDevice); |
| 537 | return pTable->EnumerateDeviceExtensionProperties( |
| 538 | physicalDevice, |
| 539 | NULL, |
| 540 | pCount, |
| 541 | pProperties); |
| 542 | } else { |
| 543 | return util_GetExtensionProperties(0, NULL, pCount, pProperties); |
| 544 | } |
Courtney Goeltzenleuchter | a6db346 | 2015-07-07 11:25:43 -0600 | [diff] [blame] | 545 | } |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 546 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 547 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties( |
Courtney Goeltzenleuchter | a6db346 | 2015-07-07 11:25:43 -0600 | [diff] [blame] | 548 | VkPhysicalDevice physicalDevice, |
| 549 | uint32_t* pCount, |
| 550 | VkLayerProperties* pProperties) |
| 551 | { |
| 552 | return util_GetLayerProperties(ARRAY_SIZE(ss_device_layers), |
| 553 | ss_device_layers, |
| 554 | pCount, pProperties); |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 555 | } |
| 556 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 557 | VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetDeviceQueue( |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 558 | VkDevice device, |
| 559 | uint32_t queueNodeIndex, |
| 560 | uint32_t queueIndex, |
| 561 | VkQueue *pQueue) |
| 562 | { |
| 563 | VkLayerDispatchTable* pTable = screenshot_device_table_map[device]; |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 564 | get_dispatch_table(screenshot_device_table_map, device)->GetDeviceQueue(device, queueNodeIndex, queueIndex, pQueue); |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 565 | |
| 566 | loader_platform_thread_lock_mutex(&globalLock); |
| 567 | if (screenshotEnvQueried && screenshotFrames.empty()) { |
| 568 | // We are all done taking screenshots, so don't do anything else |
| 569 | loader_platform_thread_unlock_mutex(&globalLock); |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 570 | return; |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 571 | } |
| 572 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 573 | screenshot_device_table_map.emplace(*pQueue, pTable); |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 574 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 575 | // Create a mapping from a device to a queue |
| 576 | if (deviceMap[device] == NULL) |
| 577 | { |
| 578 | DeviceMapStruct *deviceMapElem = new DeviceMapStruct; |
| 579 | deviceMap[device] = deviceMapElem; |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 580 | } |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 581 | deviceMap[device]->queue = *pQueue; |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 582 | loader_platform_thread_unlock_mutex(&globalLock); |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 583 | } |
| 584 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 585 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool( |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 586 | VkDevice device, |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 587 | const VkCommandPoolCreateInfo *pCreateInfo, |
| 588 | const VkAllocationCallbacks* pAllocator, |
| 589 | VkCommandPool *pCommandPool) |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 590 | { |
| 591 | VkLayerDispatchTable* pTable = screenshot_device_table_map[device]; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 592 | VkResult result = get_dispatch_table(screenshot_device_table_map, device)->CreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool); |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 593 | |
| 594 | loader_platform_thread_lock_mutex(&globalLock); |
| 595 | if (screenshotEnvQueried && screenshotFrames.empty()) { |
| 596 | // We are all done taking screenshots, so don't do anything else |
| 597 | loader_platform_thread_unlock_mutex(&globalLock); |
| 598 | return result; |
| 599 | } |
| 600 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 601 | // Create a mapping from a device to a commandPool |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 602 | if (deviceMap[device] == NULL) |
| 603 | { |
| 604 | DeviceMapStruct *deviceMapElem = new DeviceMapStruct; |
| 605 | deviceMap[device] = deviceMapElem; |
| 606 | } |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 607 | deviceMap[device]->commandPool = *pCommandPool; |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 608 | loader_platform_thread_unlock_mutex(&globalLock); |
| 609 | return result; |
| 610 | } |
| 611 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 612 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR( |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 613 | VkDevice device, |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 614 | const VkSwapchainCreateInfoKHR *pCreateInfo, |
Ian Elliott | 0584606 | 2015-11-20 14:13:17 -0700 | [diff] [blame] | 615 | const VkAllocationCallbacks *pAllocator, |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 616 | VkSwapchainKHR *pSwapchain) |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 617 | { |
| 618 | VkLayerDispatchTable* pTable = screenshot_device_table_map[device]; |
Ian Elliott | 0584606 | 2015-11-20 14:13:17 -0700 | [diff] [blame] | 619 | VkResult result = get_dispatch_table(screenshot_device_table_map, device)->CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain); |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 620 | |
| 621 | loader_platform_thread_lock_mutex(&globalLock); |
| 622 | if (screenshotEnvQueried && screenshotFrames.empty()) { |
| 623 | // We are all done taking screenshots, so don't do anything else |
| 624 | loader_platform_thread_unlock_mutex(&globalLock); |
| 625 | return result; |
| 626 | } |
| 627 | |
| 628 | if (result == VK_SUCCESS) |
| 629 | { |
| 630 | // Create a mapping for a swapchain to a device, image extent, and format |
| 631 | SwapchainMapStruct *swapchainMapElem = new SwapchainMapStruct; |
| 632 | swapchainMapElem->device = device; |
| 633 | swapchainMapElem->imageExtent = pCreateInfo->imageExtent; |
| 634 | swapchainMapElem->format = pCreateInfo->imageFormat; |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 635 | swapchainMap.insert(make_pair(*pSwapchain, swapchainMapElem)); |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 636 | |
| 637 | // Create a mapping for the swapchain object into the dispatch table |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 638 | screenshot_device_table_map.emplace((void *)pSwapchain, pTable); |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 639 | } |
| 640 | loader_platform_thread_unlock_mutex(&globalLock); |
| 641 | |
| 642 | return result; |
| 643 | } |
| 644 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 645 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR( |
Ian Elliott | 1064fe3 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 646 | VkDevice device, |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 647 | VkSwapchainKHR swapchain, |
Ian Elliott | 2b6b68a | 2015-08-07 14:11:14 -0600 | [diff] [blame] | 648 | uint32_t* pCount, |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 649 | VkImage* pSwapchainImages) |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 650 | { |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 651 | 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] | 652 | |
| 653 | loader_platform_thread_lock_mutex(&globalLock); |
| 654 | if (screenshotEnvQueried && screenshotFrames.empty()) { |
| 655 | // We are all done taking screenshots, so don't do anything else |
| 656 | loader_platform_thread_unlock_mutex(&globalLock); |
| 657 | return result; |
| 658 | } |
| 659 | |
| 660 | if (result == VK_SUCCESS && |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 661 | pSwapchainImages && |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 662 | !swapchainMap.empty() && swapchainMap.find(swapchain) != swapchainMap.end()) |
Ian Elliott | 2b6b68a | 2015-08-07 14:11:14 -0600 | [diff] [blame] | 663 | { |
Cody Northrop | bf06582 | 2015-09-01 11:48:13 -0600 | [diff] [blame] | 664 | unsigned i; |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 665 | |
Ian Elliott | 2b6b68a | 2015-08-07 14:11:14 -0600 | [diff] [blame] | 666 | for (i=0; i<*pCount; i++) |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 667 | { |
| 668 | // Create a mapping for an image to a device, image extent, and format |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 669 | if (imageMap[pSwapchainImages[i]] == NULL) |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 670 | { |
| 671 | ImageMapStruct *imageMapElem = new ImageMapStruct; |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 672 | imageMap[pSwapchainImages[i]] = imageMapElem; |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 673 | } |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 674 | imageMap[pSwapchainImages[i]]->device = swapchainMap[swapchain]->device; |
| 675 | imageMap[pSwapchainImages[i]]->imageExtent = swapchainMap[swapchain]->imageExtent; |
| 676 | imageMap[pSwapchainImages[i]]->format = swapchainMap[swapchain]->format; |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 677 | } |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 678 | |
| 679 | // Add list of images to swapchain to image map |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 680 | SwapchainMapStruct *swapchainMapElem = swapchainMap[swapchain]; |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 681 | if (i >= 1 && swapchainMapElem) |
| 682 | { |
| 683 | VkImage *imageList = new VkImage[i]; |
| 684 | swapchainMapElem->imageList = imageList; |
Cody Northrop | bf06582 | 2015-09-01 11:48:13 -0600 | [diff] [blame] | 685 | for (unsigned j=0; j<i; j++) |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 686 | { |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 687 | swapchainMapElem->imageList[j] = pSwapchainImages[j]; |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 688 | } |
| 689 | } |
| 690 | |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 691 | } |
| 692 | loader_platform_thread_unlock_mutex(&globalLock); |
| 693 | return result; |
| 694 | } |
| 695 | |
Ian Elliott | 0584606 | 2015-11-20 14:13:17 -0700 | [diff] [blame] | 696 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo) |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 697 | { |
| 698 | static int frameNumber = 0; |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 699 | if (frameNumber == 10) {fflush(stdout); /* *((int*)0)=0; */ } |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 700 | 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] | 701 | |
| 702 | loader_platform_thread_lock_mutex(&globalLock); |
| 703 | |
| 704 | if (!screenshotEnvQueried) |
| 705 | { |
Jon Ashburn | 38a497f | 2016-01-04 14:01:38 -0700 | [diff] [blame] | 706 | const char *_vk_screenshot = loader_getenv("_VK_SCREENSHOT"); |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 707 | if (_vk_screenshot && *_vk_screenshot) |
| 708 | { |
| 709 | string spec(_vk_screenshot), word; |
| 710 | size_t start = 0, comma = 0; |
| 711 | |
| 712 | while (start < spec.size()) { |
| 713 | int frameToAdd; |
| 714 | comma = spec.find(',', start); |
| 715 | if (comma == string::npos) |
| 716 | word = string(spec, start); |
| 717 | else |
| 718 | word = string(spec, start, comma - start); |
| 719 | frameToAdd=atoi(word.c_str()); |
| 720 | // Add the frame number to list, but only do it if the word started with a digit and if |
| 721 | // it's not already in the list |
| 722 | if (*(word.c_str()) >= '0' && *(word.c_str()) <= '9' && |
| 723 | find(screenshotFrames.begin(), screenshotFrames.end(), frameToAdd) == screenshotFrames.end()) |
| 724 | { |
| 725 | screenshotFrames.push_back(frameToAdd); |
| 726 | } |
| 727 | if (comma == string::npos) |
| 728 | break; |
| 729 | start = comma + 1; |
| 730 | } |
| 731 | } |
Jon Ashburn | 38a497f | 2016-01-04 14:01:38 -0700 | [diff] [blame] | 732 | loader_free_getenv(_vk_screenshot); |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 733 | screenshotEnvQueried = true; |
| 734 | } |
| 735 | |
| 736 | |
| 737 | if (result == VK_SUCCESS && !screenshotFrames.empty()) |
| 738 | { |
| 739 | vector<int>::iterator it; |
| 740 | it = find(screenshotFrames.begin(), screenshotFrames.end(), frameNumber); |
| 741 | if (it != screenshotFrames.end()) |
| 742 | { |
| 743 | string fileName; |
| 744 | fileName = to_string(frameNumber) + ".ppm"; |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 745 | |
| 746 | VkImage image; |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 747 | VkSwapchainKHR swapchain; |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 748 | // We'll dump only one image: the first |
Ian Elliott | 0584606 | 2015-11-20 14:13:17 -0700 | [diff] [blame] | 749 | swapchain = pPresentInfo->pSwapchains[0]; |
| 750 | image = swapchainMap[swapchain]->imageList[pPresentInfo->pImageIndices[0]]; |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 751 | writePPM(fileName.c_str(), image); |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 752 | screenshotFrames.erase(it); |
| 753 | |
| 754 | if (screenshotFrames.empty()) |
| 755 | { |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 756 | // Free all our maps since we are done with them. |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 757 | for (auto it = swapchainMap.begin(); it != swapchainMap.end(); it++) |
| 758 | { |
| 759 | SwapchainMapStruct *swapchainMapElem = it->second; |
| 760 | delete swapchainMapElem; |
| 761 | } |
| 762 | for (auto it = imageMap.begin(); it != imageMap.end(); it++) |
| 763 | { |
| 764 | ImageMapStruct *imageMapElem = it->second; |
| 765 | delete imageMapElem; |
| 766 | } |
| 767 | for (auto it = deviceMap.begin(); it != deviceMap.end(); it++) |
| 768 | { |
| 769 | DeviceMapStruct *deviceMapElem = it->second; |
| 770 | delete deviceMapElem; |
| 771 | } |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 772 | for (auto it = physDeviceMap.begin(); it != physDeviceMap.end(); it++) |
| 773 | { |
| 774 | PhysDeviceMapStruct *physDeviceMapElem = it->second; |
| 775 | delete physDeviceMapElem; |
| 776 | } |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 777 | swapchainMap.clear(); |
| 778 | imageMap.clear(); |
| 779 | deviceMap.clear(); |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 780 | physDeviceMap.clear(); |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 781 | } |
| 782 | } |
| 783 | } |
| 784 | frameNumber++; |
| 785 | loader_platform_thread_unlock_mutex(&globalLock); |
| 786 | return result; |
| 787 | } |
| 788 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 789 | VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr( |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 790 | VkDevice dev, |
| 791 | const char *funcName) |
| 792 | { |
Jon Ashburn | 0f1a533 | 2016-01-20 08:52:40 -0700 | [diff] [blame] | 793 | if (!strcmp(funcName, "vkGetDeviceProcAddr")) |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 794 | return (PFN_vkVoidFunction)vkGetDeviceProcAddr; |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 795 | if (!strcmp(funcName, "vkGetDeviceQueue")) |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 796 | return (PFN_vkVoidFunction) vkGetDeviceQueue; |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 797 | if (!strcmp(funcName, "vkCreateCommandPool")) |
| 798 | return (PFN_vkVoidFunction) vkCreateCommandPool; |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 799 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 800 | if (dev == NULL) { |
| 801 | return NULL; |
| 802 | } |
| 803 | |
David Pinedo | bcd0e79 | 2015-06-19 13:48:18 -0600 | [diff] [blame] | 804 | VkLayerDispatchTable *pDisp = get_dispatch_table(screenshot_device_table_map, dev); |
Jon Ashburn | 8acd233 | 2015-09-16 18:08:32 -0600 | [diff] [blame] | 805 | if (deviceExtMap.size() != 0 && deviceExtMap[pDisp].wsi_enabled) |
David Pinedo | bcd0e79 | 2015-06-19 13:48:18 -0600 | [diff] [blame] | 806 | { |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 807 | if (!strcmp(funcName, "vkCreateSwapchainKHR")) |
| 808 | return (PFN_vkVoidFunction) vkCreateSwapchainKHR; |
| 809 | if (!strcmp(funcName, "vkGetSwapchainImagesKHR")) |
| 810 | return (PFN_vkVoidFunction) vkGetSwapchainImagesKHR; |
| 811 | if (!strcmp(funcName, "vkQueuePresentKHR")) |
| 812 | return (PFN_vkVoidFunction) vkQueuePresentKHR; |
David Pinedo | bcd0e79 | 2015-06-19 13:48:18 -0600 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | if (pDisp->GetDeviceProcAddr == NULL) |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 816 | return NULL; |
David Pinedo | bcd0e79 | 2015-06-19 13:48:18 -0600 | [diff] [blame] | 817 | return pDisp->GetDeviceProcAddr(dev, funcName); |
David Pinedo | fb5b538 | 2015-06-18 17:03:14 -0600 | [diff] [blame] | 818 | } |
David Pinedo | 3831094 | 2015-07-09 16:23:44 -0600 | [diff] [blame] | 819 | |
| 820 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 821 | VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* funcName) |
David Pinedo | 3831094 | 2015-07-09 16:23:44 -0600 | [diff] [blame] | 822 | { |
Jon Ashburn | 0f1a533 | 2016-01-20 08:52:40 -0700 | [diff] [blame] | 823 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 824 | if (!strcmp("vkGetInstanceProcAddr", funcName)) |
David Pinedo | 8897e19 | 2015-07-31 10:56:20 -0600 | [diff] [blame] | 825 | return (PFN_vkVoidFunction) vkGetInstanceProcAddr; |
Jon Ashburn | 0f1a533 | 2016-01-20 08:52:40 -0700 | [diff] [blame] | 826 | if (!strcmp(funcName, "vkCreateInstance")) |
| 827 | return (PFN_vkVoidFunction) vkCreateInstance; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 828 | if (!strcmp(funcName, "vkCreateDevice")) |
| 829 | return (PFN_vkVoidFunction) vkCreateDevice; |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 830 | if (!strcmp(funcName, "vkEnumeratePhysicalDevices")) |
| 831 | return (PFN_vkVoidFunction)vkEnumeratePhysicalDevices; |
Jon Ashburn | 751c484 | 2015-11-02 17:37:20 -0700 | [diff] [blame] | 832 | if (!strcmp(funcName, "vkEnumerateDeviceExtensionProperties")) |
| 833 | return (PFN_vkVoidFunction)vkEnumerateDeviceExtensionProperties; |
Cody Northrop | 49f885c | 2015-09-01 10:18:45 -0600 | [diff] [blame] | 834 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 835 | if (instance == VK_NULL_HANDLE) { |
| 836 | return NULL; |
| 837 | } |
David Pinedo | 3831094 | 2015-07-09 16:23:44 -0600 | [diff] [blame] | 838 | VkLayerInstanceDispatchTable* pTable = instance_dispatch_table(instance); |
| 839 | if (pTable->GetInstanceProcAddr == NULL) |
| 840 | return NULL; |
| 841 | return pTable->GetInstanceProcAddr(instance, funcName); |
David Pinedo | 3831094 | 2015-07-09 16:23:44 -0600 | [diff] [blame] | 842 | } |