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