Chris Forbes | 2778f30 | 2015-04-02 13:22:31 +1300 | [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 | #include <string.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <assert.h> |
Chris Forbes | 06e8fc3 | 2015-04-13 12:14:52 +1200 | [diff] [blame] | 27 | #include <map> |
Chris Forbes | 2778f30 | 2015-04-02 13:22:31 +1300 | [diff] [blame] | 28 | #include <unordered_map> |
Chia-I Wu | d46e6ae | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 29 | #include <unordered_set> |
Chris Forbes | 4100245 | 2015-04-08 10:19:16 +1200 | [diff] [blame] | 30 | #include <map> |
Chris Forbes | 3b1c421 | 2015-04-08 10:11:59 +1200 | [diff] [blame] | 31 | #include <vector> |
Courtney Goeltzenleuchter | ee4027d | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 32 | #include <string> |
Tobin Ehlis | b80b425 | 2015-09-01 11:59:36 -0600 | [diff] [blame] | 33 | #include <iostream> |
Tobin Ehlis | b835d1b | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 34 | #include "vk_loader_platform.h" |
Chris Forbes | 2778f30 | 2015-04-02 13:22:31 +1300 | [diff] [blame] | 35 | #include "vk_dispatch_table_helper.h" |
Tobin Ehlis | 0c6f9ee | 2015-07-03 09:42:57 -0600 | [diff] [blame] | 36 | #include "vk_layer.h" |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 37 | #include "vk_layer_utils.h" |
Tobin Ehlis | a0cb02e | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 38 | #include "vk_layer_config.h" |
Tobin Ehlis | a0cb02e | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 39 | #include "vk_layer_table.h" |
Chris Forbes | 401784b | 2015-05-04 14:04:24 +1200 | [diff] [blame] | 40 | #include "vk_enum_string_helper.h" |
Chris Forbes | 6b2ead6 | 2015-04-17 10:13:28 +1200 | [diff] [blame] | 41 | #include "shader_checker.h" |
Courtney Goeltzenleuchter | da8adfe | 2015-07-07 10:05:05 -0600 | [diff] [blame] | 42 | #include "vk_layer_extension_utils.h" |
Chris Forbes | 2778f30 | 2015-04-02 13:22:31 +1300 | [diff] [blame] | 43 | |
GregF | 7c45bed | 2015-07-21 17:22:50 -0600 | [diff] [blame] | 44 | #include "spirv/spirv.hpp" |
Chris Forbes | 2778f30 | 2015-04-02 13:22:31 +1300 | [diff] [blame] | 45 | |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 46 | // fwd decls |
| 47 | struct shader_module; |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 48 | struct render_pass; |
Chris Forbes | 2778f30 | 2015-04-02 13:22:31 +1300 | [diff] [blame] | 49 | |
Cody Northrop | 55443ef | 2015-09-28 15:09:32 -0600 | [diff] [blame] | 50 | struct layer_data { |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 51 | debug_report_data *report_data; |
Courtney Goeltzenleuchter | ed12e71 | 2015-10-05 15:59:58 -0600 | [diff] [blame] | 52 | std::vector<VkDbgMsgCallback> logging_callback; |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 53 | VkLayerDispatchTable* device_dispatch_table; |
| 54 | VkLayerInstanceDispatchTable* instance_dispatch_table; |
| 55 | |
| 56 | std::unordered_map<VkShaderModule, shader_module *> shader_module_map; |
Chia-I Wu | d46e6ae | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 57 | std::unordered_map<VkDescriptorSetLayout, std::unordered_set<uint32_t>*> descriptor_set_layout_map; |
| 58 | std::unordered_map<VkPipelineLayout, std::vector<std::unordered_set<uint32_t>*>*> pipeline_layout_map; |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 59 | std::unordered_map<VkRenderPass, render_pass *> render_pass_map; |
Cody Northrop | 55443ef | 2015-09-28 15:09:32 -0600 | [diff] [blame] | 60 | |
| 61 | layer_data() : |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 62 | report_data(nullptr), |
| 63 | device_dispatch_table(nullptr), |
| 64 | instance_dispatch_table(nullptr) |
Cody Northrop | 55443ef | 2015-09-28 15:09:32 -0600 | [diff] [blame] | 65 | {}; |
| 66 | }; |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 67 | |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 68 | static void |
| 69 | build_type_def_index(std::vector<unsigned> const &words, std::unordered_map<unsigned, unsigned> &type_def_index); |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 70 | |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 71 | struct shader_module { |
| 72 | /* the spirv image itself */ |
| 73 | std::vector<uint32_t> words; |
| 74 | /* a mapping of <id> to the first word of its def. this is useful because walking type |
| 75 | * trees requires jumping all over the instruction stream. |
| 76 | */ |
| 77 | std::unordered_map<unsigned, unsigned> type_def_index; |
| 78 | |
| 79 | shader_module(VkShaderModuleCreateInfo const *pCreateInfo) : |
| 80 | words((uint32_t *)pCreateInfo->pCode, (uint32_t *)pCreateInfo->pCode + pCreateInfo->codeSize / sizeof(uint32_t)), |
| 81 | type_def_index() { |
| 82 | |
| 83 | build_type_def_index(words, type_def_index); |
| 84 | } |
| 85 | }; |
| 86 | |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 87 | struct render_pass { |
| 88 | std::vector<std::vector<VkFormat>> subpass_color_formats; |
| 89 | |
| 90 | render_pass(VkRenderPassCreateInfo const *pCreateInfo) |
| 91 | { |
| 92 | uint32_t i; |
| 93 | |
| 94 | subpass_color_formats.reserve(pCreateInfo->subpassCount); |
| 95 | for (i = 0; i < pCreateInfo->subpassCount; i++) { |
| 96 | const VkSubpassDescription *subpass = &pCreateInfo->pSubpasses[i]; |
| 97 | std::vector<VkFormat> color_formats; |
| 98 | uint32_t j; |
| 99 | |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 100 | color_formats.reserve(subpass->colorAttachmentCount); |
| 101 | for (j = 0; j < subpass->colorAttachmentCount; j++) { |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 102 | const uint32_t att = subpass->pColorAttachments[j].attachment; |
| 103 | const VkFormat format = pCreateInfo->pAttachments[att].format; |
| 104 | |
| 105 | color_formats.push_back(pCreateInfo->pAttachments[att].format); |
| 106 | } |
| 107 | |
| 108 | subpass_color_formats.push_back(color_formats); |
| 109 | } |
| 110 | } |
| 111 | }; |
| 112 | |
| 113 | static std::unordered_map<void *, layer_data *> layer_data_map; |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 114 | |
| 115 | template layer_data *get_my_data_ptr<layer_data>( |
| 116 | void *data_key, |
| 117 | std::unordered_map<void *, layer_data *> &data_map); |
| 118 | |
Chris Forbes | b6b8c46 | 2015-04-15 06:59:41 +1200 | [diff] [blame] | 119 | static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce); |
Chris Forbes | 7f96383 | 2015-05-29 14:55:18 +1200 | [diff] [blame] | 120 | // TODO : This can be much smarter, using separate locks for separate global data |
| 121 | static int globalLockInitialized = 0; |
| 122 | static loader_platform_thread_mutex globalLock; |
Chris Forbes | 3b1c421 | 2015-04-08 10:11:59 +1200 | [diff] [blame] | 123 | |
Chris Forbes | 2b8493a | 2015-08-12 15:03:22 +1200 | [diff] [blame] | 124 | VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorSetLayout( |
| 125 | VkDevice device, |
| 126 | const VkDescriptorSetLayoutCreateInfo* pCreateInfo, |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 127 | const VkAllocationCallbacks* pAllocator, |
Chris Forbes | 2b8493a | 2015-08-12 15:03:22 +1200 | [diff] [blame] | 128 | VkDescriptorSetLayout* pSetLayout) |
| 129 | { |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 130 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
Chris Forbes | 2b8493a | 2015-08-12 15:03:22 +1200 | [diff] [blame] | 131 | /* stash a copy of the layout bindings */ |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 132 | VkResult result = my_data->device_dispatch_table->CreateDescriptorSetLayout(device, pCreateInfo, pAllocator, pSetLayout); |
Chris Forbes | 2b8493a | 2015-08-12 15:03:22 +1200 | [diff] [blame] | 133 | |
| 134 | if (VK_SUCCESS == result) { |
| 135 | loader_platform_thread_lock_mutex(&globalLock); |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 136 | auto& bindings = my_data->descriptor_set_layout_map[*pSetLayout]; |
Chia-I Wu | d46e6ae | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 137 | bindings = new std::unordered_set<uint32_t>(); |
| 138 | bindings->reserve(pCreateInfo->bindingCount); |
| 139 | for (uint32_t i = 0; i < pCreateInfo->bindingCount; i++) |
| 140 | bindings->insert(pCreateInfo->pBinding[i].binding); |
| 141 | |
Chris Forbes | 2b8493a | 2015-08-12 15:03:22 +1200 | [diff] [blame] | 142 | loader_platform_thread_unlock_mutex(&globalLock); |
| 143 | } |
| 144 | |
| 145 | return result; |
| 146 | } |
| 147 | |
Chris Forbes | 2b8493a | 2015-08-12 15:03:22 +1200 | [diff] [blame] | 148 | VK_LAYER_EXPORT VkResult VKAPI vkCreatePipelineLayout( |
| 149 | VkDevice device, |
| 150 | const VkPipelineLayoutCreateInfo* pCreateInfo, |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 151 | const VkAllocationCallbacks* pAllocator, |
Chris Forbes | 2b8493a | 2015-08-12 15:03:22 +1200 | [diff] [blame] | 152 | VkPipelineLayout* pPipelineLayout) |
| 153 | { |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 154 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 155 | VkResult result = my_data->device_dispatch_table->CreatePipelineLayout(device, pCreateInfo, pAllocator, pPipelineLayout); |
Chris Forbes | 2b8493a | 2015-08-12 15:03:22 +1200 | [diff] [blame] | 156 | |
| 157 | if (VK_SUCCESS == result) { |
| 158 | loader_platform_thread_lock_mutex(&globalLock); |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 159 | auto& layouts = my_data->pipeline_layout_map[*pPipelineLayout]; |
Chia-I Wu | d46e6ae | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 160 | layouts = new std::vector<std::unordered_set<uint32_t>*>(); |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 161 | layouts->reserve(pCreateInfo->setLayoutCount); |
| 162 | for (unsigned i = 0; i < pCreateInfo->setLayoutCount; i++) { |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 163 | layouts->push_back(my_data->descriptor_set_layout_map[pCreateInfo->pSetLayouts[i]]); |
Chris Forbes | 2b8493a | 2015-08-12 15:03:22 +1200 | [diff] [blame] | 164 | } |
| 165 | loader_platform_thread_unlock_mutex(&globalLock); |
| 166 | } |
| 167 | |
| 168 | return result; |
| 169 | } |
| 170 | |
Chris Forbes | 3a5e99a | 2015-04-10 11:41:20 +1200 | [diff] [blame] | 171 | static void |
| 172 | build_type_def_index(std::vector<unsigned> const &words, std::unordered_map<unsigned, unsigned> &type_def_index) |
| 173 | { |
| 174 | unsigned int const *code = (unsigned int const *)&words[0]; |
| 175 | size_t size = words.size(); |
| 176 | |
| 177 | unsigned word = 5; |
| 178 | while (word < size) { |
| 179 | unsigned opcode = code[word] & 0x0ffffu; |
| 180 | unsigned oplen = (code[word] & 0xffff0000u) >> 16; |
| 181 | |
| 182 | switch (opcode) { |
| 183 | case spv::OpTypeVoid: |
| 184 | case spv::OpTypeBool: |
| 185 | case spv::OpTypeInt: |
| 186 | case spv::OpTypeFloat: |
| 187 | case spv::OpTypeVector: |
| 188 | case spv::OpTypeMatrix: |
GregF | 7c45bed | 2015-07-21 17:22:50 -0600 | [diff] [blame] | 189 | case spv::OpTypeImage: |
Chris Forbes | 3a5e99a | 2015-04-10 11:41:20 +1200 | [diff] [blame] | 190 | case spv::OpTypeSampler: |
GregF | 7c45bed | 2015-07-21 17:22:50 -0600 | [diff] [blame] | 191 | case spv::OpTypeSampledImage: |
Chris Forbes | 3a5e99a | 2015-04-10 11:41:20 +1200 | [diff] [blame] | 192 | case spv::OpTypeArray: |
| 193 | case spv::OpTypeRuntimeArray: |
| 194 | case spv::OpTypeStruct: |
| 195 | case spv::OpTypeOpaque: |
| 196 | case spv::OpTypePointer: |
| 197 | case spv::OpTypeFunction: |
| 198 | case spv::OpTypeEvent: |
| 199 | case spv::OpTypeDeviceEvent: |
| 200 | case spv::OpTypeReserveId: |
| 201 | case spv::OpTypeQueue: |
| 202 | case spv::OpTypePipe: |
| 203 | type_def_index[code[word+1]] = word; |
| 204 | break; |
| 205 | |
| 206 | default: |
| 207 | /* We only care about type definitions */ |
| 208 | break; |
| 209 | } |
| 210 | |
| 211 | word += oplen; |
| 212 | } |
| 213 | } |
| 214 | |
Chris Forbes | 46794b8 | 2015-09-18 11:40:23 +1200 | [diff] [blame] | 215 | bool |
| 216 | shader_is_spirv(VkShaderModuleCreateInfo const *pCreateInfo) |
| 217 | { |
| 218 | uint32_t *words = (uint32_t *)pCreateInfo->pCode; |
Courtney Goeltzenleuchter | 8f8367e | 2015-10-07 08:38:30 -0600 | [diff] [blame] | 219 | size_t sizeInWords = pCreateInfo->codeSize / sizeof(uint32_t); |
Chris Forbes | 46794b8 | 2015-09-18 11:40:23 +1200 | [diff] [blame] | 220 | |
| 221 | /* Just validate that the header makes sense. */ |
| 222 | return sizeInWords >= 5 && words[0] == spv::MagicNumber && words[1] == spv::Version; |
| 223 | } |
| 224 | |
Chris Forbes | b6b8c46 | 2015-04-15 06:59:41 +1200 | [diff] [blame] | 225 | static void |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 226 | init_shader_checker(layer_data *my_data) |
Chris Forbes | b6b8c46 | 2015-04-15 06:59:41 +1200 | [diff] [blame] | 227 | { |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 228 | uint32_t report_flags = 0; |
| 229 | uint32_t debug_action = 0; |
| 230 | FILE *log_output = NULL; |
| 231 | const char *option_str; |
Courtney Goeltzenleuchter | ed12e71 | 2015-10-05 15:59:58 -0600 | [diff] [blame] | 232 | VkDbgMsgCallback callback; |
Chris Forbes | b6b8c46 | 2015-04-15 06:59:41 +1200 | [diff] [blame] | 233 | // initialize ShaderChecker options |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 234 | report_flags = getLayerOptionFlags("ShaderCheckerReportFlags", 0); |
| 235 | getLayerOptionEnum("ShaderCheckerDebugAction", (uint32_t *) &debug_action); |
Chris Forbes | b6b8c46 | 2015-04-15 06:59:41 +1200 | [diff] [blame] | 236 | |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 237 | if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG) |
Chris Forbes | b6b8c46 | 2015-04-15 06:59:41 +1200 | [diff] [blame] | 238 | { |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 239 | option_str = getLayerOption("ShaderCheckerLogFilename"); |
Tobin Ehlis | b1df55e | 2015-09-15 09:55:54 -0600 | [diff] [blame] | 240 | log_output = getLayerLogOutput(option_str, "ShaderChecker"); |
Courtney Goeltzenleuchter | ed12e71 | 2015-10-05 15:59:58 -0600 | [diff] [blame] | 241 | layer_create_msg_callback(my_data->report_data, report_flags, log_callback, (void *) log_output, &callback); |
| 242 | my_data->logging_callback.push_back(callback); |
| 243 | } |
| 244 | |
| 245 | if (debug_action & VK_DBG_LAYER_ACTION_DEBUG_OUTPUT) { |
| 246 | layer_create_msg_callback(my_data->report_data, report_flags, win32_debug_output_msg, NULL, &callback); |
| 247 | my_data->logging_callback.push_back(callback); |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | if (!globalLockInitialized) |
| 251 | { |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 252 | loader_platform_thread_create_mutex(&globalLock); |
| 253 | globalLockInitialized = 1; |
Chris Forbes | b6b8c46 | 2015-04-15 06:59:41 +1200 | [diff] [blame] | 254 | } |
| 255 | } |
| 256 | |
Courtney Goeltzenleuchter | da8adfe | 2015-07-07 10:05:05 -0600 | [diff] [blame] | 257 | static const VkLayerProperties shader_checker_global_layers[] = { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 258 | { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 259 | "ShaderChecker", |
Courtney Goeltzenleuchter | da8adfe | 2015-07-07 10:05:05 -0600 | [diff] [blame] | 260 | VK_API_VERSION, |
| 261 | VK_MAKE_VERSION(0, 1, 0), |
| 262 | "Validation layer: ShaderChecker", |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 263 | } |
Chris Forbes | 2778f30 | 2015-04-02 13:22:31 +1300 | [diff] [blame] | 264 | }; |
| 265 | |
Courtney Goeltzenleuchter | 35985f6 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 266 | VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceExtensionProperties( |
Courtney Goeltzenleuchter | da8adfe | 2015-07-07 10:05:05 -0600 | [diff] [blame] | 267 | const char *pLayerName, |
| 268 | uint32_t *pCount, |
| 269 | VkExtensionProperties* pProperties) |
Chris Forbes | 2778f30 | 2015-04-02 13:22:31 +1300 | [diff] [blame] | 270 | { |
Courtney Goeltzenleuchter | da8adfe | 2015-07-07 10:05:05 -0600 | [diff] [blame] | 271 | /* shader checker does not have any global extensions */ |
| 272 | return util_GetExtensionProperties(0, NULL, pCount, pProperties); |
Chris Forbes | 2778f30 | 2015-04-02 13:22:31 +1300 | [diff] [blame] | 273 | } |
| 274 | |
Courtney Goeltzenleuchter | 35985f6 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 275 | VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceLayerProperties( |
Courtney Goeltzenleuchter | da8adfe | 2015-07-07 10:05:05 -0600 | [diff] [blame] | 276 | uint32_t *pCount, |
| 277 | VkLayerProperties* pProperties) |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 278 | { |
Courtney Goeltzenleuchter | da8adfe | 2015-07-07 10:05:05 -0600 | [diff] [blame] | 279 | return util_GetLayerProperties(ARRAY_SIZE(shader_checker_global_layers), |
| 280 | shader_checker_global_layers, |
| 281 | pCount, pProperties); |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 282 | } |
| 283 | |
Courtney Goeltzenleuchter | 35985f6 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 284 | VK_LAYER_EXPORT VkResult VKAPI vkEnumerateDeviceExtensionProperties( |
Courtney Goeltzenleuchter | da8adfe | 2015-07-07 10:05:05 -0600 | [diff] [blame] | 285 | VkPhysicalDevice physicalDevice, |
| 286 | const char* pLayerName, |
| 287 | uint32_t* pCount, |
| 288 | VkExtensionProperties* pProperties) |
Jon Ashburn | 207a3af | 2015-06-10 16:43:31 -0600 | [diff] [blame] | 289 | { |
Courtney Goeltzenleuchter | da8adfe | 2015-07-07 10:05:05 -0600 | [diff] [blame] | 290 | /* Shader checker does not have any physical device extensions */ |
Jon Ashburn | 751c484 | 2015-11-02 17:37:20 -0700 | [diff] [blame] | 291 | if (pLayerName == NULL) { |
| 292 | dispatch_key key = get_dispatch_key(physicalDevice); |
| 293 | layer_data *my_data = get_my_data_ptr(key, layer_data_map); |
Courtney Goeltzenleuchter | 6ed5dc2 | 2015-11-03 15:41:43 -0700 | [diff] [blame] | 294 | return my_data->instance_dispatch_table->EnumerateDeviceExtensionProperties( |
Jon Ashburn | 751c484 | 2015-11-02 17:37:20 -0700 | [diff] [blame] | 295 | physicalDevice, |
| 296 | NULL, |
| 297 | pCount, |
| 298 | pProperties); |
| 299 | } else { |
| 300 | return util_GetExtensionProperties(0, NULL, pCount, pProperties); |
| 301 | } |
Courtney Goeltzenleuchter | da8adfe | 2015-07-07 10:05:05 -0600 | [diff] [blame] | 302 | } |
Jon Ashburn | 207a3af | 2015-06-10 16:43:31 -0600 | [diff] [blame] | 303 | |
Courtney Goeltzenleuchter | 35985f6 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 304 | VK_LAYER_EXPORT VkResult VKAPI vkEnumerateDeviceLayerProperties( |
Courtney Goeltzenleuchter | da8adfe | 2015-07-07 10:05:05 -0600 | [diff] [blame] | 305 | VkPhysicalDevice physicalDevice, |
| 306 | uint32_t* pCount, |
| 307 | VkLayerProperties* pProperties) |
| 308 | { |
| 309 | /* Shader checker physical device layers are the same as global */ |
| 310 | return util_GetLayerProperties(ARRAY_SIZE(shader_checker_global_layers), |
| 311 | shader_checker_global_layers, |
| 312 | pCount, pProperties); |
Jon Ashburn | 207a3af | 2015-06-10 16:43:31 -0600 | [diff] [blame] | 313 | } |
Chris Forbes | 2778f30 | 2015-04-02 13:22:31 +1300 | [diff] [blame] | 314 | |
Chris Forbes | 3a5e99a | 2015-04-10 11:41:20 +1200 | [diff] [blame] | 315 | static char const * |
| 316 | storage_class_name(unsigned sc) |
| 317 | { |
| 318 | switch (sc) { |
Cody Northrop | 97e52d8 | 2015-04-20 14:09:40 -0600 | [diff] [blame] | 319 | case spv::StorageClassInput: return "input"; |
| 320 | case spv::StorageClassOutput: return "output"; |
| 321 | case spv::StorageClassUniformConstant: return "const uniform"; |
| 322 | case spv::StorageClassUniform: return "uniform"; |
| 323 | case spv::StorageClassWorkgroupLocal: return "workgroup local"; |
| 324 | case spv::StorageClassWorkgroupGlobal: return "workgroup global"; |
| 325 | case spv::StorageClassPrivateGlobal: return "private global"; |
| 326 | case spv::StorageClassFunction: return "function"; |
| 327 | case spv::StorageClassGeneric: return "generic"; |
Cody Northrop | 97e52d8 | 2015-04-20 14:09:40 -0600 | [diff] [blame] | 328 | case spv::StorageClassAtomicCounter: return "atomic counter"; |
GregF | 7c45bed | 2015-07-21 17:22:50 -0600 | [diff] [blame] | 329 | case spv::StorageClassImage: return "image"; |
Chris Forbes | 3a5e99a | 2015-04-10 11:41:20 +1200 | [diff] [blame] | 330 | default: return "unknown"; |
| 331 | } |
| 332 | } |
| 333 | |
Chris Forbes | 3a5e99a | 2015-04-10 11:41:20 +1200 | [diff] [blame] | 334 | /* returns ptr to null terminator */ |
| 335 | static char * |
Courtney Goeltzenleuchter | ee4027d | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 336 | describe_type(char *dst, shader_module const *src, unsigned type) |
Chris Forbes | 3a5e99a | 2015-04-10 11:41:20 +1200 | [diff] [blame] | 337 | { |
| 338 | auto type_def_it = src->type_def_index.find(type); |
| 339 | |
| 340 | if (type_def_it == src->type_def_index.end()) { |
| 341 | return dst + sprintf(dst, "undef"); |
| 342 | } |
| 343 | |
| 344 | unsigned int const *code = (unsigned int const *)&src->words[type_def_it->second]; |
| 345 | unsigned opcode = code[0] & 0x0ffffu; |
| 346 | switch (opcode) { |
| 347 | case spv::OpTypeBool: |
| 348 | return dst + sprintf(dst, "bool"); |
| 349 | case spv::OpTypeInt: |
| 350 | return dst + sprintf(dst, "%cint%d", code[3] ? 's' : 'u', code[2]); |
| 351 | case spv::OpTypeFloat: |
| 352 | return dst + sprintf(dst, "float%d", code[2]); |
| 353 | case spv::OpTypeVector: |
| 354 | dst += sprintf(dst, "vec%d of ", code[3]); |
| 355 | return describe_type(dst, src, code[2]); |
| 356 | case spv::OpTypeMatrix: |
| 357 | dst += sprintf(dst, "mat%d of ", code[3]); |
| 358 | return describe_type(dst, src, code[2]); |
| 359 | case spv::OpTypeArray: |
| 360 | dst += sprintf(dst, "arr[%d] of ", code[3]); |
| 361 | return describe_type(dst, src, code[2]); |
| 362 | case spv::OpTypePointer: |
| 363 | dst += sprintf(dst, "ptr to %s ", storage_class_name(code[2])); |
| 364 | return describe_type(dst, src, code[3]); |
| 365 | case spv::OpTypeStruct: |
| 366 | { |
| 367 | unsigned oplen = code[0] >> 16; |
| 368 | dst += sprintf(dst, "struct of ("); |
Ian Elliott | 1cb6222 | 2015-04-17 11:05:04 -0600 | [diff] [blame] | 369 | for (unsigned i = 2; i < oplen; i++) { |
Chris Forbes | 3a5e99a | 2015-04-10 11:41:20 +1200 | [diff] [blame] | 370 | dst = describe_type(dst, src, code[i]); |
| 371 | dst += sprintf(dst, i == oplen-1 ? ")" : ", "); |
| 372 | } |
| 373 | return dst; |
| 374 | } |
Chris Forbes | 0ae1580 | 2015-08-14 12:04:39 +1200 | [diff] [blame] | 375 | case spv::OpTypeSampler: |
| 376 | return dst + sprintf(dst, "sampler"); |
Chris Forbes | 3a5e99a | 2015-04-10 11:41:20 +1200 | [diff] [blame] | 377 | default: |
| 378 | return dst + sprintf(dst, "oddtype"); |
| 379 | } |
| 380 | } |
| 381 | |
Chris Forbes | 3a5e99a | 2015-04-10 11:41:20 +1200 | [diff] [blame] | 382 | static bool |
Courtney Goeltzenleuchter | ee4027d | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 383 | types_match(shader_module const *a, shader_module const *b, unsigned a_type, unsigned b_type, bool b_arrayed) |
Chris Forbes | 3a5e99a | 2015-04-10 11:41:20 +1200 | [diff] [blame] | 384 | { |
| 385 | auto a_type_def_it = a->type_def_index.find(a_type); |
| 386 | auto b_type_def_it = b->type_def_index.find(b_type); |
| 387 | |
| 388 | if (a_type_def_it == a->type_def_index.end()) { |
Chris Forbes | 3a5e99a | 2015-04-10 11:41:20 +1200 | [diff] [blame] | 389 | return false; |
| 390 | } |
| 391 | |
| 392 | if (b_type_def_it == b->type_def_index.end()) { |
Chris Forbes | 3a5e99a | 2015-04-10 11:41:20 +1200 | [diff] [blame] | 393 | return false; |
| 394 | } |
| 395 | |
| 396 | /* walk two type trees together, and complain about differences */ |
| 397 | unsigned int const *a_code = (unsigned int const *)&a->words[a_type_def_it->second]; |
| 398 | unsigned int const *b_code = (unsigned int const *)&b->words[b_type_def_it->second]; |
| 399 | |
| 400 | unsigned a_opcode = a_code[0] & 0x0ffffu; |
| 401 | unsigned b_opcode = b_code[0] & 0x0ffffu; |
| 402 | |
Chris Forbes | f3fc033 | 2015-06-05 14:57:05 +1200 | [diff] [blame] | 403 | if (b_arrayed && b_opcode == spv::OpTypeArray) { |
| 404 | /* we probably just found the extra level of arrayness in b_type: compare the type inside it to a_type */ |
| 405 | return types_match(a, b, a_type, b_code[2], false); |
| 406 | } |
| 407 | |
Chris Forbes | 3a5e99a | 2015-04-10 11:41:20 +1200 | [diff] [blame] | 408 | if (a_opcode != b_opcode) { |
Chris Forbes | 3a5e99a | 2015-04-10 11:41:20 +1200 | [diff] [blame] | 409 | return false; |
| 410 | } |
| 411 | |
| 412 | switch (a_opcode) { |
Chris Forbes | f3fc033 | 2015-06-05 14:57:05 +1200 | [diff] [blame] | 413 | /* if b_arrayed and we hit a leaf type, then we can't match -- there's nowhere for the extra OpTypeArray to be! */ |
Chris Forbes | 3a5e99a | 2015-04-10 11:41:20 +1200 | [diff] [blame] | 414 | case spv::OpTypeBool: |
Chris Forbes | f3fc033 | 2015-06-05 14:57:05 +1200 | [diff] [blame] | 415 | return true && !b_arrayed; |
Chris Forbes | 3a5e99a | 2015-04-10 11:41:20 +1200 | [diff] [blame] | 416 | case spv::OpTypeInt: |
| 417 | /* match on width, signedness */ |
Chris Forbes | f3fc033 | 2015-06-05 14:57:05 +1200 | [diff] [blame] | 418 | return a_code[2] == b_code[2] && a_code[3] == b_code[3] && !b_arrayed; |
Chris Forbes | 3a5e99a | 2015-04-10 11:41:20 +1200 | [diff] [blame] | 419 | case spv::OpTypeFloat: |
| 420 | /* match on width */ |
Chris Forbes | f3fc033 | 2015-06-05 14:57:05 +1200 | [diff] [blame] | 421 | return a_code[2] == b_code[2] && !b_arrayed; |
Chris Forbes | 3a5e99a | 2015-04-10 11:41:20 +1200 | [diff] [blame] | 422 | case spv::OpTypeVector: |
| 423 | case spv::OpTypeMatrix: |
| 424 | case spv::OpTypeArray: |
Chris Forbes | f3fc033 | 2015-06-05 14:57:05 +1200 | [diff] [blame] | 425 | /* match on element type, count. these all have the same layout. we don't get here if |
| 426 | * b_arrayed -- that is handled above. */ |
| 427 | return !b_arrayed && types_match(a, b, a_code[2], b_code[2], b_arrayed) && a_code[3] == b_code[3]; |
Chris Forbes | 3a5e99a | 2015-04-10 11:41:20 +1200 | [diff] [blame] | 428 | case spv::OpTypeStruct: |
| 429 | /* match on all element types */ |
| 430 | { |
Chris Forbes | f3fc033 | 2015-06-05 14:57:05 +1200 | [diff] [blame] | 431 | if (b_arrayed) { |
| 432 | /* for the purposes of matching different levels of arrayness, structs are leaves. */ |
| 433 | return false; |
| 434 | } |
| 435 | |
Chris Forbes | 3a5e99a | 2015-04-10 11:41:20 +1200 | [diff] [blame] | 436 | unsigned a_len = a_code[0] >> 16; |
| 437 | unsigned b_len = b_code[0] >> 16; |
| 438 | |
| 439 | if (a_len != b_len) { |
| 440 | return false; /* structs cannot match if member counts differ */ |
| 441 | } |
| 442 | |
Ian Elliott | 1cb6222 | 2015-04-17 11:05:04 -0600 | [diff] [blame] | 443 | for (unsigned i = 2; i < a_len; i++) { |
Chris Forbes | f3fc033 | 2015-06-05 14:57:05 +1200 | [diff] [blame] | 444 | if (!types_match(a, b, a_code[i], b_code[i], b_arrayed)) { |
Chris Forbes | 3a5e99a | 2015-04-10 11:41:20 +1200 | [diff] [blame] | 445 | return false; |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | return true; |
| 450 | } |
| 451 | case spv::OpTypePointer: |
| 452 | /* match on pointee type. storage class is expected to differ */ |
Chris Forbes | f3fc033 | 2015-06-05 14:57:05 +1200 | [diff] [blame] | 453 | return types_match(a, b, a_code[3], b_code[3], b_arrayed); |
Chris Forbes | 3a5e99a | 2015-04-10 11:41:20 +1200 | [diff] [blame] | 454 | |
| 455 | default: |
| 456 | /* remaining types are CLisms, or may not appear in the interfaces we |
| 457 | * are interested in. Just claim no match. |
| 458 | */ |
| 459 | return false; |
| 460 | |
| 461 | } |
| 462 | } |
| 463 | |
Chris Forbes | 06e8fc3 | 2015-04-13 12:14:52 +1200 | [diff] [blame] | 464 | static int |
| 465 | value_or_default(std::unordered_map<unsigned, unsigned> const &map, unsigned id, int def) |
| 466 | { |
| 467 | auto it = map.find(id); |
| 468 | if (it == map.end()) |
| 469 | return def; |
| 470 | else |
| 471 | return it->second; |
| 472 | } |
| 473 | |
Chris Forbes | 06e8fc3 | 2015-04-13 12:14:52 +1200 | [diff] [blame] | 474 | struct interface_var { |
| 475 | uint32_t id; |
| 476 | uint32_t type_id; |
| 477 | /* TODO: collect the name, too? Isn't required to be present. */ |
| 478 | }; |
| 479 | |
Chris Forbes | 06e8fc3 | 2015-04-13 12:14:52 +1200 | [diff] [blame] | 480 | static void |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 481 | collect_interface_by_location(layer_data *my_data, VkDevice dev, |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 482 | shader_module const *src, spv::StorageClass sinterface, |
Chris Forbes | 06e8fc3 | 2015-04-13 12:14:52 +1200 | [diff] [blame] | 483 | std::map<uint32_t, interface_var> &out, |
| 484 | std::map<uint32_t, interface_var> &builtins_out) |
| 485 | { |
| 486 | unsigned int const *code = (unsigned int const *)&src->words[0]; |
| 487 | size_t size = src->words.size(); |
| 488 | |
Chris Forbes | 06e8fc3 | 2015-04-13 12:14:52 +1200 | [diff] [blame] | 489 | std::unordered_map<unsigned, unsigned> var_locations; |
| 490 | std::unordered_map<unsigned, unsigned> var_builtins; |
| 491 | |
| 492 | unsigned word = 5; |
| 493 | while (word < size) { |
| 494 | |
| 495 | unsigned opcode = code[word] & 0x0ffffu; |
| 496 | unsigned oplen = (code[word] & 0xffff0000u) >> 16; |
| 497 | |
| 498 | /* We consider two interface models: SSO rendezvous-by-location, and |
| 499 | * builtins. Complain about anything that fits neither model. |
| 500 | */ |
| 501 | if (opcode == spv::OpDecorate) { |
Cody Northrop | 97e52d8 | 2015-04-20 14:09:40 -0600 | [diff] [blame] | 502 | if (code[word+2] == spv::DecorationLocation) { |
Chris Forbes | 06e8fc3 | 2015-04-13 12:14:52 +1200 | [diff] [blame] | 503 | var_locations[code[word+1]] = code[word+3]; |
| 504 | } |
| 505 | |
Cody Northrop | 97e52d8 | 2015-04-20 14:09:40 -0600 | [diff] [blame] | 506 | if (code[word+2] == spv::DecorationBuiltIn) { |
Chris Forbes | 06e8fc3 | 2015-04-13 12:14:52 +1200 | [diff] [blame] | 507 | var_builtins[code[word+1]] = code[word+3]; |
| 508 | } |
| 509 | } |
| 510 | |
| 511 | /* TODO: handle grouped decorations */ |
| 512 | /* TODO: handle index=1 dual source outputs from FS -- two vars will |
| 513 | * have the same location, and we DONT want to clobber. */ |
| 514 | |
Ian Elliott | 1cb6222 | 2015-04-17 11:05:04 -0600 | [diff] [blame] | 515 | if (opcode == spv::OpVariable && code[word+3] == sinterface) { |
Chris Forbes | 06e8fc3 | 2015-04-13 12:14:52 +1200 | [diff] [blame] | 516 | int location = value_or_default(var_locations, code[word+2], -1); |
| 517 | int builtin = value_or_default(var_builtins, code[word+2], -1); |
| 518 | |
| 519 | if (location == -1 && builtin == -1) { |
| 520 | /* No location defined, and not bound to an API builtin. |
| 521 | * The spec says nothing about how this case works (or doesn't) |
| 522 | * for interface matching. |
| 523 | */ |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 524 | log_msg(my_data->report_data, VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_DEVICE, /*dev*/0, 0, SHADER_CHECKER_INCONSISTENT_SPIRV, "SC", |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 525 | "var %d (type %d) in %s interface has no Location or Builtin decoration", |
| 526 | code[word+2], code[word+1], storage_class_name(sinterface)); |
Chris Forbes | 06e8fc3 | 2015-04-13 12:14:52 +1200 | [diff] [blame] | 527 | } |
| 528 | else if (location != -1) { |
| 529 | /* A user-defined interface variable, with a location. */ |
| 530 | interface_var v; |
| 531 | v.id = code[word+2]; |
| 532 | v.type_id = code[word+1]; |
| 533 | out[location] = v; |
| 534 | } |
| 535 | else { |
| 536 | /* A builtin interface variable */ |
| 537 | interface_var v; |
| 538 | v.id = code[word+2]; |
| 539 | v.type_id = code[word+1]; |
| 540 | builtins_out[builtin] = v; |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | word += oplen; |
| 545 | } |
| 546 | } |
| 547 | |
Chris Forbes | 0ae1580 | 2015-08-14 12:04:39 +1200 | [diff] [blame] | 548 | static void |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 549 | collect_interface_by_descriptor_slot(layer_data *my_data, VkDevice dev, |
Chris Forbes | 0ae1580 | 2015-08-14 12:04:39 +1200 | [diff] [blame] | 550 | shader_module const *src, spv::StorageClass sinterface, |
| 551 | std::map<std::pair<unsigned, unsigned>, interface_var> &out) |
| 552 | { |
| 553 | unsigned int const *code = (unsigned int const *)&src->words[0]; |
| 554 | size_t size = src->words.size(); |
| 555 | |
| 556 | std::unordered_map<unsigned, unsigned> var_sets; |
| 557 | std::unordered_map<unsigned, unsigned> var_bindings; |
| 558 | |
| 559 | unsigned word = 5; |
| 560 | while (word < size) { |
| 561 | |
| 562 | unsigned opcode = code[word] & 0x0ffffu; |
| 563 | unsigned oplen = (code[word] & 0xffff0000u) >> 16; |
| 564 | |
| 565 | /* We consider two interface models: SSO rendezvous-by-location, and |
| 566 | * builtins. Complain about anything that fits neither model. |
| 567 | */ |
| 568 | if (opcode == spv::OpDecorate) { |
| 569 | if (code[word+2] == spv::DecorationDescriptorSet) { |
| 570 | var_sets[code[word+1]] = code[word+3]; |
| 571 | } |
| 572 | |
| 573 | if (code[word+2] == spv::DecorationBinding) { |
| 574 | var_bindings[code[word+1]] = code[word+3]; |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | if (opcode == spv::OpVariable && (code[word+3] == spv::StorageClassUniform || |
| 579 | code[word+3] == spv::StorageClassUniformConstant)) { |
| 580 | unsigned set = value_or_default(var_sets, code[word+2], 0); |
| 581 | unsigned binding = value_or_default(var_bindings, code[word+2], 0); |
| 582 | |
| 583 | auto existing_it = out.find(std::make_pair(set, binding)); |
| 584 | if (existing_it != out.end()) { |
| 585 | /* conflict within spv image */ |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 586 | log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE, /*dev*/0, 0, |
Chris Forbes | 0ae1580 | 2015-08-14 12:04:39 +1200 | [diff] [blame] | 587 | SHADER_CHECKER_INCONSISTENT_SPIRV, "SC", |
| 588 | "var %d (type %d) in %s interface in descriptor slot (%u,%u) conflicts with existing definition", |
| 589 | code[word+2], code[word+1], storage_class_name(sinterface), |
| 590 | existing_it->first.first, existing_it->first.second); |
| 591 | } |
| 592 | |
| 593 | interface_var v; |
| 594 | v.id = code[word+2]; |
| 595 | v.type_id = code[word+1]; |
| 596 | out[std::make_pair(set, binding)] = v; |
| 597 | } |
| 598 | |
| 599 | word += oplen; |
| 600 | } |
| 601 | } |
| 602 | |
Courtney Goeltzenleuchter | ee4027d | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 603 | VK_LAYER_EXPORT VkResult VKAPI vkCreateShaderModule( |
| 604 | VkDevice device, |
| 605 | const VkShaderModuleCreateInfo *pCreateInfo, |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 606 | const VkAllocationCallbacks* pAllocator, |
Courtney Goeltzenleuchter | ee4027d | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 607 | VkShaderModule *pShaderModule) |
Chris Forbes | 2778f30 | 2015-04-02 13:22:31 +1300 | [diff] [blame] | 608 | { |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 609 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
Michael Lentine | 8ea2996 | 2015-11-03 16:18:46 -0800 | [diff] [blame^] | 610 | bool skip_call = false; |
Chris Forbes | 46794b8 | 2015-09-18 11:40:23 +1200 | [diff] [blame] | 611 | if (!shader_is_spirv(pCreateInfo)) { |
Michael Lentine | 8ea2996 | 2015-11-03 16:18:46 -0800 | [diff] [blame^] | 612 | skip_call |= log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE, |
Chris Forbes | 46794b8 | 2015-09-18 11:40:23 +1200 | [diff] [blame] | 613 | /* dev */ 0, 0, SHADER_CHECKER_NON_SPIRV_SHADER, "SC", |
| 614 | "Shader is not SPIR-V"); |
Chris Forbes | 46794b8 | 2015-09-18 11:40:23 +1200 | [diff] [blame] | 615 | } |
| 616 | |
Michael Lentine | 8ea2996 | 2015-11-03 16:18:46 -0800 | [diff] [blame^] | 617 | if (skip_call) |
| 618 | return VK_ERROR_VALIDATION_FAILED; |
| 619 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 620 | VkResult res = my_data->device_dispatch_table->CreateShaderModule(device, pCreateInfo, pAllocator, pShaderModule); |
Chris Forbes | 3b1c421 | 2015-04-08 10:11:59 +1200 | [diff] [blame] | 621 | |
Courtney Goeltzenleuchter | b5afdbf | 2015-09-16 12:57:55 -0600 | [diff] [blame] | 622 | if (res == VK_SUCCESS) { |
| 623 | loader_platform_thread_lock_mutex(&globalLock); |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 624 | my_data->shader_module_map[*pShaderModule] = new shader_module(pCreateInfo); |
Courtney Goeltzenleuchter | b5afdbf | 2015-09-16 12:57:55 -0600 | [diff] [blame] | 625 | loader_platform_thread_unlock_mutex(&globalLock); |
| 626 | } |
Chris Forbes | 2778f30 | 2015-04-02 13:22:31 +1300 | [diff] [blame] | 627 | return res; |
| 628 | } |
| 629 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 630 | VK_LAYER_EXPORT VkResult VKAPI vkCreateRenderPass( |
| 631 | VkDevice device, |
| 632 | const VkRenderPassCreateInfo *pCreateInfo, |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 633 | const VkAllocationCallbacks* pAllocator, |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 634 | VkRenderPass *pRenderPass) |
| 635 | { |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 636 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 637 | VkResult res = my_data->device_dispatch_table->CreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 638 | |
Courtney Goeltzenleuchter | b5afdbf | 2015-09-16 12:57:55 -0600 | [diff] [blame] | 639 | loader_platform_thread_lock_mutex(&globalLock); |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 640 | my_data->render_pass_map[*pRenderPass] = new render_pass(pCreateInfo); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 641 | loader_platform_thread_unlock_mutex(&globalLock); |
| 642 | return res; |
| 643 | } |
| 644 | |
Chris Forbes | ee99b9b | 2015-05-25 11:13:22 +1200 | [diff] [blame] | 645 | static bool |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 646 | validate_interface_between_stages(layer_data *my_data, VkDevice dev, |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 647 | shader_module const *producer, char const *producer_name, |
Courtney Goeltzenleuchter | ee4027d | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 648 | shader_module const *consumer, char const *consumer_name, |
Chris Forbes | f044ec9 | 2015-06-05 15:01:08 +1200 | [diff] [blame] | 649 | bool consumer_arrayed_input) |
Chris Forbes | 4100245 | 2015-04-08 10:19:16 +1200 | [diff] [blame] | 650 | { |
| 651 | std::map<uint32_t, interface_var> outputs; |
| 652 | std::map<uint32_t, interface_var> inputs; |
| 653 | |
| 654 | std::map<uint32_t, interface_var> builtin_outputs; |
| 655 | std::map<uint32_t, interface_var> builtin_inputs; |
| 656 | |
Chris Forbes | ee99b9b | 2015-05-25 11:13:22 +1200 | [diff] [blame] | 657 | bool pass = true; |
Chris Forbes | 4100245 | 2015-04-08 10:19:16 +1200 | [diff] [blame] | 658 | |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 659 | collect_interface_by_location(my_data, dev, producer, spv::StorageClassOutput, outputs, builtin_outputs); |
| 660 | collect_interface_by_location(my_data, dev, consumer, spv::StorageClassInput, inputs, builtin_inputs); |
Chris Forbes | 4100245 | 2015-04-08 10:19:16 +1200 | [diff] [blame] | 661 | |
| 662 | auto a_it = outputs.begin(); |
| 663 | auto b_it = inputs.begin(); |
| 664 | |
| 665 | /* maps sorted by key (location); walk them together to find mismatches */ |
David Pinedo | d8f83d8 | 2015-04-27 16:36:17 -0600 | [diff] [blame] | 666 | while ((outputs.size() > 0 && a_it != outputs.end()) || ( inputs.size() && b_it != inputs.end())) { |
| 667 | bool a_at_end = outputs.size() == 0 || a_it == outputs.end(); |
| 668 | bool b_at_end = inputs.size() == 0 || b_it == inputs.end(); |
Chris Forbes | 62cc3fc | 2015-06-10 08:37:27 +1200 | [diff] [blame] | 669 | auto a_first = a_at_end ? 0 : a_it->first; |
| 670 | auto b_first = b_at_end ? 0 : b_it->first; |
David Pinedo | d8f83d8 | 2015-04-27 16:36:17 -0600 | [diff] [blame] | 671 | |
Mike Stroyan | 19a6de2 | 2015-09-10 14:10:25 -0600 | [diff] [blame] | 672 | if (b_at_end || ((!a_at_end) && (a_first < b_first))) { |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 673 | if (log_msg(my_data->report_data, VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_DEVICE, /*dev*/0, 0, SHADER_CHECKER_OUTPUT_NOT_CONSUMED, "SC", |
Mike Stroyan | 830368a | 2015-09-10 14:12:01 -0600 | [diff] [blame] | 674 | "%s writes to output location %d which is not consumed by %s", producer_name, a_first, consumer_name)) { |
| 675 | pass = false; |
| 676 | } |
Chris Forbes | 4100245 | 2015-04-08 10:19:16 +1200 | [diff] [blame] | 677 | a_it++; |
| 678 | } |
David Pinedo | d8f83d8 | 2015-04-27 16:36:17 -0600 | [diff] [blame] | 679 | else if (a_at_end || a_first > b_first) { |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 680 | if (log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE, /*dev*/0, 0, SHADER_CHECKER_INPUT_NOT_PRODUCED, "SC", |
Mike Stroyan | 830368a | 2015-09-10 14:12:01 -0600 | [diff] [blame] | 681 | "%s consumes input location %d which is not written by %s", consumer_name, b_first, producer_name)) { |
| 682 | pass = false; |
| 683 | } |
Chris Forbes | 4100245 | 2015-04-08 10:19:16 +1200 | [diff] [blame] | 684 | b_it++; |
| 685 | } |
| 686 | else { |
Chris Forbes | f044ec9 | 2015-06-05 15:01:08 +1200 | [diff] [blame] | 687 | if (types_match(producer, consumer, a_it->second.type_id, b_it->second.type_id, consumer_arrayed_input)) { |
Chris Forbes | 6b2ead6 | 2015-04-17 10:13:28 +1200 | [diff] [blame] | 688 | /* OK! */ |
Chris Forbes | 3a5e99a | 2015-04-10 11:41:20 +1200 | [diff] [blame] | 689 | } |
| 690 | else { |
| 691 | char producer_type[1024]; |
| 692 | char consumer_type[1024]; |
| 693 | describe_type(producer_type, producer, a_it->second.type_id); |
| 694 | describe_type(consumer_type, consumer, b_it->second.type_id); |
| 695 | |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 696 | if (log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE, /*dev*/0, 0, SHADER_CHECKER_INTERFACE_TYPE_MISMATCH, "SC", |
Mike Stroyan | 830368a | 2015-09-10 14:12:01 -0600 | [diff] [blame] | 697 | "Type mismatch on location %d: '%s' vs '%s'", a_it->first, producer_type, consumer_type)) { |
Chris Forbes | ee99b9b | 2015-05-25 11:13:22 +1200 | [diff] [blame] | 698 | pass = false; |
Mike Stroyan | 830368a | 2015-09-10 14:12:01 -0600 | [diff] [blame] | 699 | } |
Chris Forbes | 3a5e99a | 2015-04-10 11:41:20 +1200 | [diff] [blame] | 700 | } |
Chris Forbes | 4100245 | 2015-04-08 10:19:16 +1200 | [diff] [blame] | 701 | a_it++; |
| 702 | b_it++; |
| 703 | } |
| 704 | } |
Chris Forbes | ee99b9b | 2015-05-25 11:13:22 +1200 | [diff] [blame] | 705 | |
| 706 | return pass; |
Chris Forbes | 4100245 | 2015-04-08 10:19:16 +1200 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | |
Chris Forbes | 3616b46 | 2015-04-08 10:37:20 +1200 | [diff] [blame] | 710 | enum FORMAT_TYPE { |
| 711 | FORMAT_TYPE_UNDEFINED, |
| 712 | FORMAT_TYPE_FLOAT, /* UNORM, SNORM, FLOAT, USCALED, SSCALED, SRGB -- anything we consider float in the shader */ |
| 713 | FORMAT_TYPE_SINT, |
| 714 | FORMAT_TYPE_UINT, |
| 715 | }; |
| 716 | |
| 717 | |
| 718 | static unsigned |
| 719 | get_format_type(VkFormat fmt) { |
| 720 | switch (fmt) { |
Chia-I Wu | a3b9a20 | 2015-04-17 02:00:54 +0800 | [diff] [blame] | 721 | case VK_FORMAT_UNDEFINED: |
Chris Forbes | 3616b46 | 2015-04-08 10:37:20 +1200 | [diff] [blame] | 722 | return FORMAT_TYPE_UNDEFINED; |
Chia-I Wu | a3b9a20 | 2015-04-17 02:00:54 +0800 | [diff] [blame] | 723 | case VK_FORMAT_R8_SINT: |
| 724 | case VK_FORMAT_R8G8_SINT: |
| 725 | case VK_FORMAT_R8G8B8_SINT: |
| 726 | case VK_FORMAT_R8G8B8A8_SINT: |
| 727 | case VK_FORMAT_R16_SINT: |
| 728 | case VK_FORMAT_R16G16_SINT: |
| 729 | case VK_FORMAT_R16G16B16_SINT: |
| 730 | case VK_FORMAT_R16G16B16A16_SINT: |
| 731 | case VK_FORMAT_R32_SINT: |
| 732 | case VK_FORMAT_R32G32_SINT: |
| 733 | case VK_FORMAT_R32G32B32_SINT: |
| 734 | case VK_FORMAT_R32G32B32A32_SINT: |
| 735 | case VK_FORMAT_B8G8R8_SINT: |
| 736 | case VK_FORMAT_B8G8R8A8_SINT: |
| 737 | case VK_FORMAT_R10G10B10A2_SINT: |
| 738 | case VK_FORMAT_B10G10R10A2_SINT: |
Chris Forbes | 3616b46 | 2015-04-08 10:37:20 +1200 | [diff] [blame] | 739 | return FORMAT_TYPE_SINT; |
Chia-I Wu | a3b9a20 | 2015-04-17 02:00:54 +0800 | [diff] [blame] | 740 | case VK_FORMAT_R8_UINT: |
| 741 | case VK_FORMAT_R8G8_UINT: |
| 742 | case VK_FORMAT_R8G8B8_UINT: |
| 743 | case VK_FORMAT_R8G8B8A8_UINT: |
| 744 | case VK_FORMAT_R16_UINT: |
| 745 | case VK_FORMAT_R16G16_UINT: |
| 746 | case VK_FORMAT_R16G16B16_UINT: |
| 747 | case VK_FORMAT_R16G16B16A16_UINT: |
| 748 | case VK_FORMAT_R32_UINT: |
| 749 | case VK_FORMAT_R32G32_UINT: |
| 750 | case VK_FORMAT_R32G32B32_UINT: |
| 751 | case VK_FORMAT_R32G32B32A32_UINT: |
| 752 | case VK_FORMAT_B8G8R8_UINT: |
| 753 | case VK_FORMAT_B8G8R8A8_UINT: |
| 754 | case VK_FORMAT_R10G10B10A2_UINT: |
| 755 | case VK_FORMAT_B10G10R10A2_UINT: |
Chris Forbes | 3616b46 | 2015-04-08 10:37:20 +1200 | [diff] [blame] | 756 | return FORMAT_TYPE_UINT; |
| 757 | default: |
| 758 | return FORMAT_TYPE_FLOAT; |
| 759 | } |
| 760 | } |
| 761 | |
| 762 | |
Chris Forbes | 156a116 | 2015-05-04 14:04:06 +1200 | [diff] [blame] | 763 | /* characterizes a SPIR-V type appearing in an interface to a FF stage, |
| 764 | * for comparison to a VkFormat's characterization above. */ |
| 765 | static unsigned |
Courtney Goeltzenleuchter | ee4027d | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 766 | get_fundamental_type(shader_module const *src, unsigned type) |
Chris Forbes | 156a116 | 2015-05-04 14:04:06 +1200 | [diff] [blame] | 767 | { |
| 768 | auto type_def_it = src->type_def_index.find(type); |
| 769 | |
| 770 | if (type_def_it == src->type_def_index.end()) { |
| 771 | return FORMAT_TYPE_UNDEFINED; |
| 772 | } |
| 773 | |
| 774 | unsigned int const *code = (unsigned int const *)&src->words[type_def_it->second]; |
| 775 | unsigned opcode = code[0] & 0x0ffffu; |
| 776 | switch (opcode) { |
| 777 | case spv::OpTypeInt: |
| 778 | return code[3] ? FORMAT_TYPE_SINT : FORMAT_TYPE_UINT; |
| 779 | case spv::OpTypeFloat: |
| 780 | return FORMAT_TYPE_FLOAT; |
| 781 | case spv::OpTypeVector: |
| 782 | return get_fundamental_type(src, code[2]); |
| 783 | case spv::OpTypeMatrix: |
| 784 | return get_fundamental_type(src, code[2]); |
| 785 | case spv::OpTypeArray: |
| 786 | return get_fundamental_type(src, code[2]); |
| 787 | case spv::OpTypePointer: |
| 788 | return get_fundamental_type(src, code[3]); |
| 789 | default: |
| 790 | return FORMAT_TYPE_UNDEFINED; |
| 791 | } |
| 792 | } |
| 793 | |
| 794 | |
Chris Forbes | ee99b9b | 2015-05-25 11:13:22 +1200 | [diff] [blame] | 795 | static bool |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 796 | validate_vi_consistency(layer_data *my_data, VkDevice dev, VkPipelineVertexInputStateCreateInfo const *vi) |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 797 | { |
| 798 | /* walk the binding descriptions, which describe the step rate and stride of each vertex buffer. |
| 799 | * each binding should be specified only once. |
| 800 | */ |
| 801 | std::unordered_map<uint32_t, VkVertexInputBindingDescription const *> bindings; |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 802 | bool pass = true; |
| 803 | |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 804 | for (unsigned i = 0; i < vi->vertexBindingDescriptionCount; i++) { |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 805 | auto desc = &vi->pVertexBindingDescriptions[i]; |
| 806 | auto & binding = bindings[desc->binding]; |
| 807 | if (binding) { |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 808 | if (log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE, /*dev*/0, 0, SHADER_CHECKER_INCONSISTENT_VI, "SC", |
Mike Stroyan | 830368a | 2015-09-10 14:12:01 -0600 | [diff] [blame] | 809 | "Duplicate vertex input binding descriptions for binding %d", desc->binding)) { |
| 810 | pass = false; |
| 811 | } |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 812 | } |
| 813 | else { |
| 814 | binding = desc; |
| 815 | } |
| 816 | } |
| 817 | |
| 818 | return pass; |
| 819 | } |
| 820 | |
| 821 | |
| 822 | static bool |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 823 | validate_vi_against_vs_inputs(layer_data *my_data, VkDevice dev, VkPipelineVertexInputStateCreateInfo const *vi, shader_module const *vs) |
Chris Forbes | 772d03b | 2015-04-08 10:36:37 +1200 | [diff] [blame] | 824 | { |
| 825 | std::map<uint32_t, interface_var> inputs; |
| 826 | /* we collect builtin inputs, but they will never appear in the VI state -- |
| 827 | * the vs builtin inputs are generated in the pipeline, not sourced from buffers (VertexID, etc) |
| 828 | */ |
| 829 | std::map<uint32_t, interface_var> builtin_inputs; |
Chris Forbes | ee99b9b | 2015-05-25 11:13:22 +1200 | [diff] [blame] | 830 | bool pass = true; |
Chris Forbes | 772d03b | 2015-04-08 10:36:37 +1200 | [diff] [blame] | 831 | |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 832 | collect_interface_by_location(my_data, dev, vs, spv::StorageClassInput, inputs, builtin_inputs); |
Chris Forbes | 772d03b | 2015-04-08 10:36:37 +1200 | [diff] [blame] | 833 | |
| 834 | /* Build index by location */ |
| 835 | std::map<uint32_t, VkVertexInputAttributeDescription const *> attribs; |
Chris Forbes | 7191cd5 | 2015-05-25 11:13:24 +1200 | [diff] [blame] | 836 | if (vi) { |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 837 | for (unsigned i = 0; i < vi->vertexAttributeDescriptionCount; i++) |
Chris Forbes | 7191cd5 | 2015-05-25 11:13:24 +1200 | [diff] [blame] | 838 | attribs[vi->pVertexAttributeDescriptions[i].location] = &vi->pVertexAttributeDescriptions[i]; |
| 839 | } |
Chris Forbes | 772d03b | 2015-04-08 10:36:37 +1200 | [diff] [blame] | 840 | |
| 841 | auto it_a = attribs.begin(); |
| 842 | auto it_b = inputs.begin(); |
| 843 | |
David Pinedo | d8f83d8 | 2015-04-27 16:36:17 -0600 | [diff] [blame] | 844 | while ((attribs.size() > 0 && it_a != attribs.end()) || (inputs.size() > 0 && it_b != inputs.end())) { |
| 845 | bool a_at_end = attribs.size() == 0 || it_a == attribs.end(); |
| 846 | bool b_at_end = inputs.size() == 0 || it_b == inputs.end(); |
Chris Forbes | 62cc3fc | 2015-06-10 08:37:27 +1200 | [diff] [blame] | 847 | auto a_first = a_at_end ? 0 : it_a->first; |
| 848 | auto b_first = b_at_end ? 0 : it_b->first; |
David Pinedo | d8f83d8 | 2015-04-27 16:36:17 -0600 | [diff] [blame] | 849 | if (b_at_end || a_first < b_first) { |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 850 | if (log_msg(my_data->report_data, VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_DEVICE, /*dev*/0, 0, SHADER_CHECKER_OUTPUT_NOT_CONSUMED, "SC", |
Mike Stroyan | 830368a | 2015-09-10 14:12:01 -0600 | [diff] [blame] | 851 | "Vertex attribute at location %d not consumed by VS", a_first)) { |
| 852 | pass = false; |
| 853 | } |
Chris Forbes | 772d03b | 2015-04-08 10:36:37 +1200 | [diff] [blame] | 854 | it_a++; |
| 855 | } |
David Pinedo | d8f83d8 | 2015-04-27 16:36:17 -0600 | [diff] [blame] | 856 | else if (a_at_end || b_first < a_first) { |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 857 | if (log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE, /*dev*/0, 0, SHADER_CHECKER_INPUT_NOT_PRODUCED, "SC", |
Mike Stroyan | 830368a | 2015-09-10 14:12:01 -0600 | [diff] [blame] | 858 | "VS consumes input at location %d but not provided", b_first)) { |
| 859 | pass = false; |
| 860 | } |
Chris Forbes | 772d03b | 2015-04-08 10:36:37 +1200 | [diff] [blame] | 861 | it_b++; |
| 862 | } |
| 863 | else { |
Chris Forbes | 401784b | 2015-05-04 14:04:24 +1200 | [diff] [blame] | 864 | unsigned attrib_type = get_format_type(it_a->second->format); |
| 865 | unsigned input_type = get_fundamental_type(vs, it_b->second.type_id); |
| 866 | |
| 867 | /* type checking */ |
| 868 | if (attrib_type != FORMAT_TYPE_UNDEFINED && input_type != FORMAT_TYPE_UNDEFINED && attrib_type != input_type) { |
| 869 | char vs_type[1024]; |
| 870 | describe_type(vs_type, vs, it_b->second.type_id); |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 871 | if (log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE, /*dev*/0, 0, SHADER_CHECKER_INTERFACE_TYPE_MISMATCH, "SC", |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 872 | "Attribute type of `%s` at location %d does not match VS input type of `%s`", |
Mike Stroyan | 830368a | 2015-09-10 14:12:01 -0600 | [diff] [blame] | 873 | string_VkFormat(it_a->second->format), a_first, vs_type)) { |
| 874 | pass = false; |
| 875 | } |
Chris Forbes | 401784b | 2015-05-04 14:04:24 +1200 | [diff] [blame] | 876 | } |
| 877 | |
Chris Forbes | 6b2ead6 | 2015-04-17 10:13:28 +1200 | [diff] [blame] | 878 | /* OK! */ |
Chris Forbes | 772d03b | 2015-04-08 10:36:37 +1200 | [diff] [blame] | 879 | it_a++; |
| 880 | it_b++; |
| 881 | } |
| 882 | } |
Chris Forbes | ee99b9b | 2015-05-25 11:13:22 +1200 | [diff] [blame] | 883 | |
| 884 | return pass; |
Chris Forbes | 772d03b | 2015-04-08 10:36:37 +1200 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | |
Chris Forbes | ee99b9b | 2015-05-25 11:13:22 +1200 | [diff] [blame] | 888 | static bool |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 889 | validate_fs_outputs_against_render_pass(layer_data *my_data, VkDevice dev, shader_module const *fs, render_pass const *rp, uint32_t subpass) |
Chris Forbes | 3616b46 | 2015-04-08 10:37:20 +1200 | [diff] [blame] | 890 | { |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 891 | const std::vector<VkFormat> &color_formats = rp->subpass_color_formats[subpass]; |
Chris Forbes | 3616b46 | 2015-04-08 10:37:20 +1200 | [diff] [blame] | 892 | std::map<uint32_t, interface_var> outputs; |
| 893 | std::map<uint32_t, interface_var> builtin_outputs; |
Chris Forbes | ee99b9b | 2015-05-25 11:13:22 +1200 | [diff] [blame] | 894 | bool pass = true; |
Chris Forbes | 3616b46 | 2015-04-08 10:37:20 +1200 | [diff] [blame] | 895 | |
| 896 | /* TODO: dual source blend index (spv::DecIndex, zero if not provided) */ |
| 897 | |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 898 | collect_interface_by_location(my_data, dev, fs, spv::StorageClassOutput, outputs, builtin_outputs); |
Chris Forbes | 3616b46 | 2015-04-08 10:37:20 +1200 | [diff] [blame] | 899 | |
| 900 | /* Check for legacy gl_FragColor broadcast: In this case, we should have no user-defined outputs, |
| 901 | * and all color attachment should be UNORM/SNORM/FLOAT. |
| 902 | */ |
| 903 | if (builtin_outputs.find(spv::BuiltInFragColor) != builtin_outputs.end()) { |
Chris Forbes | 3616b46 | 2015-04-08 10:37:20 +1200 | [diff] [blame] | 904 | if (outputs.size()) { |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 905 | if (log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE, /*dev*/0, 0, SHADER_CHECKER_FS_MIXED_BROADCAST, "SC", |
Mike Stroyan | 830368a | 2015-09-10 14:12:01 -0600 | [diff] [blame] | 906 | "Should not have user-defined FS outputs when using broadcast")) { |
| 907 | pass = false; |
| 908 | } |
Chris Forbes | 3616b46 | 2015-04-08 10:37:20 +1200 | [diff] [blame] | 909 | } |
| 910 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 911 | for (unsigned i = 0; i < color_formats.size(); i++) { |
| 912 | unsigned attachmentType = get_format_type(color_formats[i]); |
Chris Forbes | 3616b46 | 2015-04-08 10:37:20 +1200 | [diff] [blame] | 913 | if (attachmentType == FORMAT_TYPE_SINT || attachmentType == FORMAT_TYPE_UINT) { |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 914 | if (log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE, /*dev*/0, 0, SHADER_CHECKER_INTERFACE_TYPE_MISMATCH, "SC", |
Mike Stroyan | 830368a | 2015-09-10 14:12:01 -0600 | [diff] [blame] | 915 | "CB format should not be SINT or UINT when using broadcast")) { |
| 916 | pass = false; |
| 917 | } |
Chris Forbes | 3616b46 | 2015-04-08 10:37:20 +1200 | [diff] [blame] | 918 | } |
| 919 | } |
| 920 | |
Chris Forbes | ee99b9b | 2015-05-25 11:13:22 +1200 | [diff] [blame] | 921 | return pass; |
Chris Forbes | 3616b46 | 2015-04-08 10:37:20 +1200 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | auto it = outputs.begin(); |
| 925 | uint32_t attachment = 0; |
| 926 | |
| 927 | /* Walk attachment list and outputs together -- this is a little overpowered since attachments |
| 928 | * are currently dense, but the parallel with matching between shader stages is nice. |
| 929 | */ |
| 930 | |
Chris Forbes | 9715d4a | 2015-07-10 09:06:54 +1200 | [diff] [blame] | 931 | /* TODO: Figure out compile error with cb->attachmentCount */ |
Chris Forbes | c2cbb0a | 2015-07-11 11:05:01 +1200 | [diff] [blame] | 932 | while ((outputs.size() > 0 && it != outputs.end()) || attachment < color_formats.size()) { |
| 933 | if (attachment == color_formats.size() || ( it != outputs.end() && it->first < attachment)) { |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 934 | if (log_msg(my_data->report_data, VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_DEVICE, /*dev*/0, 0, SHADER_CHECKER_OUTPUT_NOT_CONSUMED, "SC", |
Mike Stroyan | 830368a | 2015-09-10 14:12:01 -0600 | [diff] [blame] | 935 | "FS writes to output location %d with no matching attachment", it->first)) { |
| 936 | pass = false; |
| 937 | } |
Chris Forbes | 3616b46 | 2015-04-08 10:37:20 +1200 | [diff] [blame] | 938 | it++; |
| 939 | } |
| 940 | else if (it == outputs.end() || it->first > attachment) { |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 941 | if (log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE, /*dev*/0, 0, SHADER_CHECKER_INPUT_NOT_PRODUCED, "SC", |
Mike Stroyan | 830368a | 2015-09-10 14:12:01 -0600 | [diff] [blame] | 942 | "Attachment %d not written by FS", attachment)) { |
| 943 | pass = false; |
| 944 | } |
Chris Forbes | 3616b46 | 2015-04-08 10:37:20 +1200 | [diff] [blame] | 945 | attachment++; |
| 946 | } |
| 947 | else { |
Chris Forbes | 46d31e5 | 2015-05-04 14:20:10 +1200 | [diff] [blame] | 948 | unsigned output_type = get_fundamental_type(fs, it->second.type_id); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 949 | unsigned att_type = get_format_type(color_formats[attachment]); |
Chris Forbes | 46d31e5 | 2015-05-04 14:20:10 +1200 | [diff] [blame] | 950 | |
| 951 | /* type checking */ |
| 952 | if (att_type != FORMAT_TYPE_UNDEFINED && output_type != FORMAT_TYPE_UNDEFINED && att_type != output_type) { |
| 953 | char fs_type[1024]; |
| 954 | describe_type(fs_type, fs, it->second.type_id); |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 955 | if (log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE, /*dev*/0, 0, SHADER_CHECKER_INTERFACE_TYPE_MISMATCH, "SC", |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 956 | "Attachment %d of type `%s` does not match FS output type of `%s`", |
Mike Stroyan | 830368a | 2015-09-10 14:12:01 -0600 | [diff] [blame] | 957 | attachment, string_VkFormat(color_formats[attachment]), fs_type)) { |
| 958 | pass = false; |
| 959 | } |
Chris Forbes | 46d31e5 | 2015-05-04 14:20:10 +1200 | [diff] [blame] | 960 | } |
| 961 | |
Chris Forbes | 6b2ead6 | 2015-04-17 10:13:28 +1200 | [diff] [blame] | 962 | /* OK! */ |
Chris Forbes | 3616b46 | 2015-04-08 10:37:20 +1200 | [diff] [blame] | 963 | it++; |
| 964 | attachment++; |
| 965 | } |
| 966 | } |
Chris Forbes | ee99b9b | 2015-05-25 11:13:22 +1200 | [diff] [blame] | 967 | |
| 968 | return pass; |
Chris Forbes | 3616b46 | 2015-04-08 10:37:20 +1200 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | |
Chris Forbes | f044ec9 | 2015-06-05 15:01:08 +1200 | [diff] [blame] | 972 | struct shader_stage_attributes { |
| 973 | char const * const name; |
| 974 | bool arrayed_input; |
| 975 | }; |
| 976 | |
| 977 | |
| 978 | static shader_stage_attributes |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 979 | shader_stage_attribs[] = { |
Chris Forbes | f044ec9 | 2015-06-05 15:01:08 +1200 | [diff] [blame] | 980 | { "vertex shader", false }, |
| 981 | { "tessellation control shader", true }, |
| 982 | { "tessellation evaluation shader", false }, |
| 983 | { "geometry shader", true }, |
| 984 | { "fragment shader", false }, |
| 985 | }; |
| 986 | |
| 987 | |
Chia-I Wu | d46e6ae | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 988 | static bool |
| 989 | has_descriptor_binding(std::vector<std::unordered_set<uint32_t>*>* layout, |
| 990 | std::pair<unsigned, unsigned> slot) |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 991 | { |
| 992 | if (!layout) |
Chia-I Wu | d46e6ae | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 993 | return false; |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 994 | |
| 995 | if (slot.first >= layout->size()) |
Chia-I Wu | d46e6ae | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 996 | return false; |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 997 | |
| 998 | auto set = (*layout)[slot.first]; |
| 999 | |
Chia-I Wu | d46e6ae | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 1000 | return (set->find(slot.second) != set->end()); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 1001 | } |
| 1002 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 1003 | static uint32_t get_shader_stage_id(VkShaderStageFlagBits stage) |
| 1004 | { |
| 1005 | uint32_t bit_pos = u_ffs(stage); |
| 1006 | return bit_pos-1; |
| 1007 | } |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 1008 | |
Chris Forbes | 81874ba | 2015-06-04 20:23:00 +1200 | [diff] [blame] | 1009 | static bool |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 1010 | validate_graphics_pipeline(layer_data *my_data, VkDevice dev, VkGraphicsPipelineCreateInfo const *pCreateInfo) |
Chris Forbes | 4175e6f | 2015-04-08 10:15:35 +1200 | [diff] [blame] | 1011 | { |
Chris Forbes | f6800b5 | 2015-04-08 10:16:45 +1200 | [diff] [blame] | 1012 | /* We seem to allow pipeline stages to be specified out of order, so collect and identify them |
| 1013 | * before trying to do anything more: */ |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 1014 | int vertex_stage = get_shader_stage_id(VK_SHADER_STAGE_VERTEX_BIT); |
| 1015 | int geometry_stage = get_shader_stage_id(VK_SHADER_STAGE_GEOMETRY_BIT); |
| 1016 | int fragment_stage = get_shader_stage_id(VK_SHADER_STAGE_FRAGMENT_BIT); |
Chris Forbes | f6800b5 | 2015-04-08 10:16:45 +1200 | [diff] [blame] | 1017 | |
Courtney Goeltzenleuchter | bbf6608 | 2015-10-27 11:32:31 -0600 | [diff] [blame] | 1018 | shader_module **shaders = new shader_module*[fragment_stage + 1]; /* exclude CS */ |
| 1019 | memset(shaders, 0, sizeof(shader_module *) * (fragment_stage +1)); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 1020 | render_pass const *rp = 0; |
Mark Lobodzinski | d5732f3 | 2015-06-23 15:11:57 -0600 | [diff] [blame] | 1021 | VkPipelineVertexInputStateCreateInfo const *vi = 0; |
Chris Forbes | ee99b9b | 2015-05-25 11:13:22 +1200 | [diff] [blame] | 1022 | bool pass = true; |
Chris Forbes | f6800b5 | 2015-04-08 10:16:45 +1200 | [diff] [blame] | 1023 | |
Chris Forbes | 7f96383 | 2015-05-29 14:55:18 +1200 | [diff] [blame] | 1024 | loader_platform_thread_lock_mutex(&globalLock); |
| 1025 | |
Tony Barbour | 92503c6 | 2015-07-13 15:28:47 -0600 | [diff] [blame] | 1026 | for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) { |
Mark Lobodzinski | d5732f3 | 2015-06-23 15:11:57 -0600 | [diff] [blame] | 1027 | VkPipelineShaderStageCreateInfo const *pStage = &pCreateInfo->pStages[i]; |
| 1028 | if (pStage->sType == VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO) { |
Chris Forbes | f6800b5 | 2015-04-08 10:16:45 +1200 | [diff] [blame] | 1029 | |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 1030 | if ((pStage->stage & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_GEOMETRY_BIT | VK_SHADER_STAGE_FRAGMENT_BIT |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 1031 | | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT)) == 0) { |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 1032 | if (log_msg(my_data->report_data, VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_DEVICE, /*dev*/0, 0, SHADER_CHECKER_UNKNOWN_STAGE, "SC", |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 1033 | "Unknown shader stage %d", pStage->stage)) { |
Mike Stroyan | 830368a | 2015-09-10 14:12:01 -0600 | [diff] [blame] | 1034 | pass = false; |
| 1035 | } |
Chris Forbes | 6b2ead6 | 2015-04-17 10:13:28 +1200 | [diff] [blame] | 1036 | } |
Chris Forbes | f044ec9 | 2015-06-05 15:01:08 +1200 | [diff] [blame] | 1037 | else { |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 1038 | shader_module *module = my_data->shader_module_map[pStage->module]; |
| 1039 | shaders[get_shader_stage_id(pStage->stage)] = module; |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 1040 | |
| 1041 | /* validate descriptor set layout against what the spirv module actually uses */ |
Chris Forbes | 46794b8 | 2015-09-18 11:40:23 +1200 | [diff] [blame] | 1042 | std::map<std::pair<unsigned, unsigned>, interface_var> descriptor_uses; |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 1043 | collect_interface_by_descriptor_slot(my_data, dev, module, spv::StorageClassUniform, |
Chris Forbes | 46794b8 | 2015-09-18 11:40:23 +1200 | [diff] [blame] | 1044 | descriptor_uses); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 1045 | |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 1046 | auto layout = pCreateInfo->layout != VK_NULL_HANDLE ? |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 1047 | my_data->pipeline_layout_map[pCreateInfo->layout] : nullptr; |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 1048 | |
Chris Forbes | 46794b8 | 2015-09-18 11:40:23 +1200 | [diff] [blame] | 1049 | for (auto it = descriptor_uses.begin(); it != descriptor_uses.end(); it++) { |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 1050 | |
Chris Forbes | 46794b8 | 2015-09-18 11:40:23 +1200 | [diff] [blame] | 1051 | /* find the matching binding */ |
Chia-I Wu | d46e6ae | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 1052 | auto found = has_descriptor_binding(layout, it->first); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 1053 | |
Chia-I Wu | d46e6ae | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 1054 | if (!found) { |
Chris Forbes | 46794b8 | 2015-09-18 11:40:23 +1200 | [diff] [blame] | 1055 | char type_name[1024]; |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 1056 | describe_type(type_name, module, it->second.type_id); |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 1057 | if (log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE, /*dev*/0, 0, |
Chris Forbes | 46794b8 | 2015-09-18 11:40:23 +1200 | [diff] [blame] | 1058 | SHADER_CHECKER_MISSING_DESCRIPTOR, "SC", |
| 1059 | "Shader uses descriptor slot %u.%u (used as type `%s`) but not declared in pipeline layout", |
Mike Stroyan | 830368a | 2015-09-10 14:12:01 -0600 | [diff] [blame] | 1060 | it->first.first, it->first.second, type_name)) { |
| 1061 | pass = false; |
| 1062 | } |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 1063 | } |
| 1064 | } |
Chris Forbes | f044ec9 | 2015-06-05 15:01:08 +1200 | [diff] [blame] | 1065 | } |
Chris Forbes | f6800b5 | 2015-04-08 10:16:45 +1200 | [diff] [blame] | 1066 | } |
Chris Forbes | f6800b5 | 2015-04-08 10:16:45 +1200 | [diff] [blame] | 1067 | } |
| 1068 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 1069 | if (pCreateInfo->renderPass != VK_NULL_HANDLE) |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 1070 | rp = my_data->render_pass_map[pCreateInfo->renderPass]; |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 1071 | |
Mark Lobodzinski | d5732f3 | 2015-06-23 15:11:57 -0600 | [diff] [blame] | 1072 | vi = pCreateInfo->pVertexInputState; |
| 1073 | |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 1074 | if (vi) { |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 1075 | pass = validate_vi_consistency(my_data, dev, vi) && pass; |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 1076 | } |
| 1077 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 1078 | if (shaders[vertex_stage]) { |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 1079 | pass = validate_vi_against_vs_inputs(my_data, dev, vi, shaders[vertex_stage]) && pass; |
Chris Forbes | 772d03b | 2015-04-08 10:36:37 +1200 | [diff] [blame] | 1080 | } |
| 1081 | |
Chris Forbes | f044ec9 | 2015-06-05 15:01:08 +1200 | [diff] [blame] | 1082 | /* TODO: enforce rules about present combinations of shaders */ |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 1083 | int producer = get_shader_stage_id(VK_SHADER_STAGE_VERTEX_BIT); |
| 1084 | int consumer = get_shader_stage_id(VK_SHADER_STAGE_GEOMETRY_BIT); |
Chris Forbes | f044ec9 | 2015-06-05 15:01:08 +1200 | [diff] [blame] | 1085 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 1086 | while (!shaders[producer] && producer != fragment_stage) { |
Chris Forbes | f044ec9 | 2015-06-05 15:01:08 +1200 | [diff] [blame] | 1087 | producer++; |
| 1088 | consumer++; |
Chris Forbes | 4100245 | 2015-04-08 10:19:16 +1200 | [diff] [blame] | 1089 | } |
| 1090 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 1091 | for (; producer != fragment_stage && consumer <= fragment_stage; consumer++) { |
Chris Forbes | f044ec9 | 2015-06-05 15:01:08 +1200 | [diff] [blame] | 1092 | assert(shaders[producer]); |
| 1093 | if (shaders[consumer]) { |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 1094 | pass = validate_interface_between_stages(my_data, dev, |
Chris Forbes | 46794b8 | 2015-09-18 11:40:23 +1200 | [diff] [blame] | 1095 | shaders[producer], shader_stage_attribs[producer].name, |
| 1096 | shaders[consumer], shader_stage_attribs[consumer].name, |
| 1097 | shader_stage_attribs[consumer].arrayed_input) && pass; |
Chris Forbes | f044ec9 | 2015-06-05 15:01:08 +1200 | [diff] [blame] | 1098 | |
| 1099 | producer = consumer; |
| 1100 | } |
| 1101 | } |
| 1102 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 1103 | if (shaders[fragment_stage] && rp) { |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 1104 | pass = validate_fs_outputs_against_render_pass(my_data, dev, shaders[fragment_stage], rp, pCreateInfo->subpass) && pass; |
Chris Forbes | 3616b46 | 2015-04-08 10:37:20 +1200 | [diff] [blame] | 1105 | } |
| 1106 | |
Courtney Goeltzenleuchter | bbf6608 | 2015-10-27 11:32:31 -0600 | [diff] [blame] | 1107 | delete shaders; |
| 1108 | |
Chris Forbes | 7f96383 | 2015-05-29 14:55:18 +1200 | [diff] [blame] | 1109 | loader_platform_thread_unlock_mutex(&globalLock); |
Chris Forbes | 81874ba | 2015-06-04 20:23:00 +1200 | [diff] [blame] | 1110 | return pass; |
| 1111 | } |
| 1112 | |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 1113 | //TODO handle pipelineCache entry points |
Chris Forbes | 39d8d75 | 2015-06-04 20:27:09 +1200 | [diff] [blame] | 1114 | VK_LAYER_EXPORT VkResult VKAPI |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 1115 | vkCreateGraphicsPipelines(VkDevice device, |
| 1116 | VkPipelineCache pipelineCache, |
| 1117 | uint32_t count, |
| 1118 | const VkGraphicsPipelineCreateInfo *pCreateInfos, |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1119 | const VkAllocationCallbacks* pAllocator, |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 1120 | VkPipeline *pPipelines) |
Chris Forbes | 81874ba | 2015-06-04 20:23:00 +1200 | [diff] [blame] | 1121 | { |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 1122 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
Chris Forbes | 36a372f | 2015-07-24 13:53:47 +1200 | [diff] [blame] | 1123 | bool pass = true; |
| 1124 | for (uint32_t i = 0; i < count; i++) { |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 1125 | pass = validate_graphics_pipeline(my_data, device, &pCreateInfos[i]) && pass; |
Chris Forbes | 36a372f | 2015-07-24 13:53:47 +1200 | [diff] [blame] | 1126 | } |
Chris Forbes | ee99b9b | 2015-05-25 11:13:22 +1200 | [diff] [blame] | 1127 | |
| 1128 | if (pass) { |
| 1129 | /* The driver is allowed to crash if passed junk. Only actually create the |
| 1130 | * pipeline if we didn't run into any showstoppers above. |
| 1131 | */ |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 1132 | return my_data->device_dispatch_table->CreateGraphicsPipelines(device, pipelineCache, count, pCreateInfos, pAllocator, pPipelines); |
Chris Forbes | ee99b9b | 2015-05-25 11:13:22 +1200 | [diff] [blame] | 1133 | } |
| 1134 | else { |
Courtney Goeltzenleuchter | 55659b7 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 1135 | return VK_ERROR_VALIDATION_FAILED; |
Chris Forbes | ee99b9b | 2015-05-25 11:13:22 +1200 | [diff] [blame] | 1136 | } |
Chris Forbes | 4175e6f | 2015-04-08 10:15:35 +1200 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1140 | VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDevice* pDevice) |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 1141 | { |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 1142 | layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 1143 | VkResult result = my_device_data->device_dispatch_table->CreateDevice(gpu, pCreateInfo, pAllocator, pDevice); |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 1144 | if (result == VK_SUCCESS) { |
| 1145 | layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map); |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 1146 | my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice); |
| 1147 | } |
| 1148 | return result; |
| 1149 | } |
Chris Forbes | 39d8d75 | 2015-06-04 20:27:09 +1200 | [diff] [blame] | 1150 | |
Jon Ashburn | 9a8a2e2 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 1151 | /* hook DextroyDevice to remove tableMap entry */ |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1152 | VK_LAYER_EXPORT void VKAPI vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator) |
Jon Ashburn | 9a8a2e2 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 1153 | { |
Courtney Goeltzenleuchter | 0daf228 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 1154 | dispatch_key key = get_dispatch_key(device); |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 1155 | layer_data *my_device_data = get_my_data_ptr(key, layer_data_map); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 1156 | my_device_data->device_dispatch_table->DestroyDevice(device, pAllocator); |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 1157 | delete my_device_data->device_dispatch_table; |
| 1158 | layer_data_map.erase(key); |
Jon Ashburn | 9a8a2e2 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 1159 | } |
| 1160 | |
Courtney Goeltzenleuchter | bfd2c66 | 2015-06-01 14:46:33 -0600 | [diff] [blame] | 1161 | VkResult VKAPI vkCreateInstance( |
| 1162 | const VkInstanceCreateInfo* pCreateInfo, |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1163 | const VkAllocationCallbacks* pAllocator, |
Courtney Goeltzenleuchter | bfd2c66 | 2015-06-01 14:46:33 -0600 | [diff] [blame] | 1164 | VkInstance* pInstance) |
| 1165 | { |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 1166 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map); |
| 1167 | VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 1168 | VkResult result = pTable->CreateInstance(pCreateInfo, pAllocator, pInstance); |
Courtney Goeltzenleuchter | bfd2c66 | 2015-06-01 14:46:33 -0600 | [diff] [blame] | 1169 | |
| 1170 | if (result == VK_SUCCESS) { |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 1171 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map); |
| 1172 | my_data->report_data = debug_report_create_instance( |
| 1173 | pTable, |
| 1174 | *pInstance, |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1175 | pCreateInfo->enabledExtensionNameCount, |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 1176 | pCreateInfo->ppEnabledExtensionNames); |
Courtney Goeltzenleuchter | d02a964 | 2015-06-08 14:58:39 -0600 | [diff] [blame] | 1177 | |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 1178 | init_shader_checker(my_data); |
Courtney Goeltzenleuchter | bfd2c66 | 2015-06-01 14:46:33 -0600 | [diff] [blame] | 1179 | } |
| 1180 | return result; |
| 1181 | } |
| 1182 | |
Jon Ashburn | 9a8a2e2 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 1183 | /* hook DestroyInstance to remove tableInstanceMap entry */ |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1184 | VK_LAYER_EXPORT void VKAPI vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator) |
Jon Ashburn | 9a8a2e2 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 1185 | { |
Courtney Goeltzenleuchter | 0daf228 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 1186 | dispatch_key key = get_dispatch_key(instance); |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 1187 | layer_data *my_data = get_my_data_ptr(key, layer_data_map); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 1188 | my_data->instance_dispatch_table->DestroyInstance(instance, pAllocator); |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 1189 | |
| 1190 | // Clean up logging callback, if any |
Courtney Goeltzenleuchter | ed12e71 | 2015-10-05 15:59:58 -0600 | [diff] [blame] | 1191 | while (my_data->logging_callback.size() > 0) { |
| 1192 | VkDbgMsgCallback callback = my_data->logging_callback.back(); |
| 1193 | layer_destroy_msg_callback(my_data->report_data, callback); |
| 1194 | my_data->logging_callback.pop_back(); |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 1195 | } |
| 1196 | |
| 1197 | layer_debug_report_destroy_instance(my_data->report_data); |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 1198 | delete my_data->instance_dispatch_table; |
| 1199 | layer_data_map.erase(key); |
| 1200 | if (layer_data_map.empty()) { |
| 1201 | // Release mutex when destroying last instance. |
| 1202 | loader_platform_thread_delete_mutex(&globalLock); |
| 1203 | globalLockInitialized = 0; |
| 1204 | } |
Jon Ashburn | 9a8a2e2 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 1205 | } |
Chris Forbes | db467bd | 2015-05-25 11:12:59 +1200 | [diff] [blame] | 1206 | |
Courtney Goeltzenleuchter | bfd2c66 | 2015-06-01 14:46:33 -0600 | [diff] [blame] | 1207 | VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback( |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 1208 | VkInstance instance, |
| 1209 | VkFlags msgFlags, |
| 1210 | const PFN_vkDbgMsgCallback pfnMsgCallback, |
| 1211 | void* pUserData, |
| 1212 | VkDbgMsgCallback* pMsgCallback) |
Courtney Goeltzenleuchter | bfd2c66 | 2015-06-01 14:46:33 -0600 | [diff] [blame] | 1213 | { |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 1214 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
| 1215 | VkResult res = my_data->instance_dispatch_table->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback); |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 1216 | if (VK_SUCCESS == res) { |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 1217 | res = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback); |
| 1218 | } |
| 1219 | return res; |
Courtney Goeltzenleuchter | bfd2c66 | 2015-06-01 14:46:33 -0600 | [diff] [blame] | 1220 | } |
| 1221 | |
| 1222 | VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback( |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 1223 | VkInstance instance, |
| 1224 | VkDbgMsgCallback msgCallback) |
Courtney Goeltzenleuchter | bfd2c66 | 2015-06-01 14:46:33 -0600 | [diff] [blame] | 1225 | { |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 1226 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 1227 | VkResult res = my_data->instance_dispatch_table->DbgDestroyMsgCallback(instance, msgCallback); |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 1228 | layer_destroy_msg_callback(my_data->report_data, msgCallback); |
| 1229 | return res; |
Courtney Goeltzenleuchter | bfd2c66 | 2015-06-01 14:46:33 -0600 | [diff] [blame] | 1230 | } |
| 1231 | |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 1232 | VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName) |
Chris Forbes | 2778f30 | 2015-04-02 13:22:31 +1300 | [diff] [blame] | 1233 | { |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 1234 | if (dev == NULL) |
Chris Forbes | 2778f30 | 2015-04-02 13:22:31 +1300 | [diff] [blame] | 1235 | return NULL; |
| 1236 | |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 1237 | layer_data *my_data; |
Jon Ashburn | 8fd0825 | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 1238 | /* loader uses this to force layer initialization; device object is wrapped */ |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 1239 | if (!strcmp("vkGetDeviceProcAddr", funcName)) { |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 1240 | VkBaseLayerObject* wrapped_dev = (VkBaseLayerObject*) dev; |
| 1241 | my_data = get_my_data_ptr(get_dispatch_key(wrapped_dev->baseObject), layer_data_map); |
| 1242 | my_data->device_dispatch_table = new VkLayerDispatchTable; |
| 1243 | layer_initialize_dispatch_table(my_data->device_dispatch_table, wrapped_dev); |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 1244 | return (PFN_vkVoidFunction) vkGetDeviceProcAddr; |
Jon Ashburn | 8fd0825 | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 1245 | } |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 1246 | my_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map); |
Jon Ashburn | 8fd0825 | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 1247 | |
Chris Forbes | 2778f30 | 2015-04-02 13:22:31 +1300 | [diff] [blame] | 1248 | #define ADD_HOOK(fn) \ |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 1249 | if (!strncmp(#fn, funcName, sizeof(#fn))) \ |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 1250 | return (PFN_vkVoidFunction) fn |
Chris Forbes | 2778f30 | 2015-04-02 13:22:31 +1300 | [diff] [blame] | 1251 | |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 1252 | ADD_HOOK(vkCreateDevice); |
Courtney Goeltzenleuchter | ee4027d | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 1253 | ADD_HOOK(vkCreateShaderModule); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 1254 | ADD_HOOK(vkCreateRenderPass); |
Jon Ashburn | 9a8a2e2 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 1255 | ADD_HOOK(vkDestroyDevice); |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 1256 | ADD_HOOK(vkCreateGraphicsPipelines); |
Chris Forbes | 2b8493a | 2015-08-12 15:03:22 +1200 | [diff] [blame] | 1257 | ADD_HOOK(vkCreateDescriptorSetLayout); |
| 1258 | ADD_HOOK(vkCreatePipelineLayout); |
Jon Ashburn | e59f84f | 2015-05-18 09:08:41 -0600 | [diff] [blame] | 1259 | #undef ADD_HOOK |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 1260 | |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 1261 | VkLayerDispatchTable* pTable = my_data->device_dispatch_table; |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 1262 | { |
| 1263 | if (pTable->GetDeviceProcAddr == NULL) |
| 1264 | return NULL; |
| 1265 | return pTable->GetDeviceProcAddr(dev, funcName); |
| 1266 | } |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 1267 | } |
| 1268 | |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 1269 | VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName) |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 1270 | { |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 1271 | PFN_vkVoidFunction fptr; |
Courtney Goeltzenleuchter | bfd2c66 | 2015-06-01 14:46:33 -0600 | [diff] [blame] | 1272 | |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 1273 | if (instance == NULL) |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 1274 | return NULL; |
| 1275 | |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 1276 | layer_data *my_data; |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 1277 | if (!strcmp("vkGetInstanceProcAddr", funcName)) { |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 1278 | VkBaseLayerObject* wrapped_inst = (VkBaseLayerObject*) instance; |
| 1279 | my_data = get_my_data_ptr(get_dispatch_key(wrapped_inst->baseObject), layer_data_map); |
| 1280 | my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable; |
| 1281 | layer_init_instance_dispatch_table(my_data->instance_dispatch_table, wrapped_inst); |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 1282 | return (PFN_vkVoidFunction) vkGetInstanceProcAddr; |
Jon Ashburn | 8fd0825 | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 1283 | } |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 1284 | #define ADD_HOOK(fn) \ |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 1285 | if (!strncmp(#fn, funcName, sizeof(#fn))) \ |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 1286 | return (PFN_vkVoidFunction) fn |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 1287 | |
Courtney Goeltzenleuchter | bfd2c66 | 2015-06-01 14:46:33 -0600 | [diff] [blame] | 1288 | ADD_HOOK(vkCreateInstance); |
Jon Ashburn | 9a8a2e2 | 2015-05-19 16:34:53 -0600 | [diff] [blame] | 1289 | ADD_HOOK(vkDestroyInstance); |
Courtney Goeltzenleuchter | 35985f6 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 1290 | ADD_HOOK(vkEnumerateInstanceExtensionProperties); |
| 1291 | ADD_HOOK(vkEnumerateDeviceExtensionProperties); |
| 1292 | ADD_HOOK(vkEnumerateInstanceLayerProperties); |
| 1293 | ADD_HOOK(vkEnumerateDeviceLayerProperties); |
Jon Ashburn | e59f84f | 2015-05-18 09:08:41 -0600 | [diff] [blame] | 1294 | #undef ADD_HOOK |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 1295 | |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 1296 | |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 1297 | my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 1298 | fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName); |
Courtney Goeltzenleuchter | bfd2c66 | 2015-06-01 14:46:33 -0600 | [diff] [blame] | 1299 | if (fptr) |
| 1300 | return fptr; |
| 1301 | |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 1302 | { |
Tobin Ehlis | 3c6f2e5 | 2015-10-29 11:11:53 -0600 | [diff] [blame] | 1303 | VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table; |
Chris Forbes | b1dee27 | 2015-07-03 13:50:24 +1200 | [diff] [blame] | 1304 | if (pTable->GetInstanceProcAddr == NULL) |
| 1305 | return NULL; |
| 1306 | return pTable->GetInstanceProcAddr(instance, funcName); |
| 1307 | } |
Chris Forbes | 2778f30 | 2015-04-02 13:22:31 +1300 | [diff] [blame] | 1308 | } |