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