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