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