blob: 94b3984516f0d7053fcc019fd1f54d0be73a7dbd [file] [log] [blame]
Chris Forbes2778f302015-04-02 13:22:31 +13001/*
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 Forbes06e8fc32015-04-13 12:14:52 +120027#include <map>
Chris Forbes2778f302015-04-02 13:22:31 +130028#include <unordered_map>
Chris Forbes41002452015-04-08 10:19:16 +120029#include <map>
Chris Forbes3b1c4212015-04-08 10:11:59 +120030#include <vector>
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -060031#include <string>
Tobin Ehlisb835d1b2015-07-03 10:34:49 -060032#include "vk_loader_platform.h"
Chris Forbes2778f302015-04-02 13:22:31 +130033#include "vk_dispatch_table_helper.h"
Tobin Ehlis0c6f9ee2015-07-03 09:42:57 -060034#include "vk_layer.h"
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -060035#include "vk_layer_config.h"
36#include "vk_layer_msg.h"
37#include "vk_layer_table.h"
Chris Forbesb1dee272015-07-03 13:50:24 +120038#include "vk_layer_logging.h"
Chris Forbes401784b2015-05-04 14:04:24 +120039#include "vk_enum_string_helper.h"
Chris Forbes6b2ead62015-04-17 10:13:28 +120040#include "shader_checker.h"
Chris Forbes2778f302015-04-02 13:22:31 +130041// The following is #included again to catch certain OS-specific functions
42// being used:
Tobin Ehlisb835d1b2015-07-03 10:34:49 -060043#include "vk_loader_platform.h"
Courtney Goeltzenleuchterda8adfe2015-07-07 10:05:05 -060044#include "vk_layer_extension_utils.h"
Chris Forbes2778f302015-04-02 13:22:31 +130045
Chris Forbes7f720542015-05-09 10:31:21 +120046#include "spirv/spirv.h"
Chris Forbes2778f302015-04-02 13:22:31 +130047
Chris Forbes2778f302015-04-02 13:22:31 +130048
Chris Forbesb1dee272015-07-03 13:50:24 +120049typedef struct _layer_data {
50 debug_report_data *report_data;
51 // TODO: put instance data here
52 VkDbgMsgCallback logging_callback;
53} layer_data;
54
55static std::unordered_map<void *, layer_data *> layer_data_map;
56static device_table_map shader_checker_device_table_map;
57static instance_table_map shader_checker_instance_table_map;
58
59
60template layer_data *get_my_data_ptr<layer_data>(
61 void *data_key,
62 std::unordered_map<void *, layer_data *> &data_map);
63
Chris Forbes9715d4a2015-07-10 09:06:54 +120064debug_report_data *mdd(void *object)
Chris Forbesb1dee272015-07-03 13:50:24 +120065{
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
74debug_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 Forbesb6b8c462015-04-15 06:59:41 +120084static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
Chris Forbes7f963832015-05-29 14:55:18 +120085// TODO : This can be much smarter, using separate locks for separate global data
86static int globalLockInitialized = 0;
87static loader_platform_thread_mutex globalLock;
Chris Forbes3b1c4212015-04-08 10:11:59 +120088
Chris Forbes3a5e99a2015-04-10 11:41:20 +120089
90static void
91build_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 Goeltzenleuchteree4027d2015-06-28 13:01:17 -0600133struct shader_module {
Chris Forbes3a5e99a2015-04-10 11:41:20 +1200134 /* the spirv image itself */
Chris Forbes3b1c4212015-04-08 10:11:59 +1200135 std::vector<uint32_t> words;
Chris Forbes3a5e99a2015-04-10 11:41:20 +1200136 /* 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 Forbesf044ec92015-06-05 15:01:08 +1200140 bool is_spirv;
Chris Forbes3b1c4212015-04-08 10:11:59 +1200141
Chris Forbesb1dee272015-07-03 13:50:24 +1200142 shader_module(VkDevice dev, VkShaderModuleCreateInfo const *pCreateInfo) :
Chris Forbesf044ec92015-06-05 15:01:08 +1200143 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 Forbes9715d4a2015-07-10 09:06:54 +1200148 log_msg(mdd(dev), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_DEVICE, /* dev */ 0, 0, SHADER_CHECKER_NON_SPIRV_SHADER, "SC",
Chris Forbesb1dee272015-07-03 13:50:24 +1200149 "Shader is not SPIR-V, most checks will not be possible");
Chris Forbesf044ec92015-06-05 15:01:08 +1200150 is_spirv = false;
151 return;
152 }
153
Chris Forbes3a5e99a2015-04-10 11:41:20 +1200154
155 build_type_def_index(words, type_def_index);
Chris Forbes3b1c4212015-04-08 10:11:59 +1200156 }
157};
158
159
Chris Forbes9715d4a2015-07-10 09:06:54 +1200160static std::unordered_map<uint64_t, shader_module *> shader_module_map;
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -0600161
162struct shader_object {
163 std::string name;
164 struct shader_module *module;
165
166 shader_object(VkShaderCreateInfo const *pCreateInfo)
167 {
Chris Forbes9715d4a2015-07-10 09:06:54 +1200168 module = shader_module_map[pCreateInfo->module.handle];
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -0600169 name = pCreateInfo->pName;
170 }
171};
Chris Forbes9715d4a2015-07-10 09:06:54 +1200172static std::unordered_map<uint64_t, shader_object *> shader_object_map;
Chris Forbes3b1c4212015-04-08 10:11:59 +1200173
Chia-I Wu08accc62015-07-07 11:50:03 +0800174struct 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 Forbes9715d4a2015-07-10 09:06:54 +1200199static std::unordered_map<uint64_t, render_pass *> render_pass_map;
Chia-I Wu08accc62015-07-07 11:50:03 +0800200
Chris Forbes3b1c4212015-04-08 10:11:59 +1200201
Chris Forbesb6b8c462015-04-15 06:59:41 +1200202static void
Chris Forbesb1dee272015-07-03 13:50:24 +1200203init_shader_checker(layer_data *my_data)
Chris Forbesb6b8c462015-04-15 06:59:41 +1200204{
Chris Forbesb1dee272015-07-03 13:50:24 +1200205 uint32_t report_flags = 0;
206 uint32_t debug_action = 0;
207 FILE *log_output = NULL;
208 const char *option_str;
Chris Forbesb6b8c462015-04-15 06:59:41 +1200209 // initialize ShaderChecker options
Chris Forbesb1dee272015-07-03 13:50:24 +1200210 report_flags = getLayerOptionFlags("ShaderCheckerReportFlags", 0);
211 getLayerOptionEnum("ShaderCheckerDebugAction", (uint32_t *) &debug_action);
Chris Forbesb6b8c462015-04-15 06:59:41 +1200212
Chris Forbesb1dee272015-07-03 13:50:24 +1200213 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
Chris Forbesb6b8c462015-04-15 06:59:41 +1200214 {
Chris Forbesb1dee272015-07-03 13:50:24 +1200215 option_str = getLayerOption("ShaderCheckerLogFilename");
216 if (option_str)
Chris Forbesb6b8c462015-04-15 06:59:41 +1200217 {
Chris Forbesb1dee272015-07-03 13:50:24 +1200218 log_output = fopen(option_str, "w");
Chris Forbesb6b8c462015-04-15 06:59:41 +1200219 }
Chris Forbesb1dee272015-07-03 13:50:24 +1200220 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 Forbesb6b8c462015-04-15 06:59:41 +1200235 }
236}
237
Courtney Goeltzenleuchterda8adfe2015-07-07 10:05:05 -0600238static const VkLayerProperties shader_checker_global_layers[] = {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600239 {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600240 "ShaderChecker",
Courtney Goeltzenleuchterda8adfe2015-07-07 10:05:05 -0600241 VK_API_VERSION,
242 VK_MAKE_VERSION(0, 1, 0),
243 "Validation layer: ShaderChecker",
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600244 }
Chris Forbes2778f302015-04-02 13:22:31 +1300245};
246
Tony Barbour59a47322015-06-24 16:06:58 -0600247VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionProperties(
Courtney Goeltzenleuchterda8adfe2015-07-07 10:05:05 -0600248 const char *pLayerName,
249 uint32_t *pCount,
250 VkExtensionProperties* pProperties)
Chris Forbes2778f302015-04-02 13:22:31 +1300251{
Courtney Goeltzenleuchterda8adfe2015-07-07 10:05:05 -0600252 /* shader checker does not have any global extensions */
253 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
Chris Forbes2778f302015-04-02 13:22:31 +1300254}
255
Courtney Goeltzenleuchterda8adfe2015-07-07 10:05:05 -0600256VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalLayerProperties(
257 uint32_t *pCount,
258 VkLayerProperties* pProperties)
Tony Barbour59a47322015-06-24 16:06:58 -0600259{
Courtney Goeltzenleuchterda8adfe2015-07-07 10:05:05 -0600260 return util_GetLayerProperties(ARRAY_SIZE(shader_checker_global_layers),
261 shader_checker_global_layers,
262 pCount, pProperties);
Tony Barbour59a47322015-06-24 16:06:58 -0600263}
264
265VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceExtensionProperties(
Courtney Goeltzenleuchterda8adfe2015-07-07 10:05:05 -0600266 VkPhysicalDevice physicalDevice,
267 const char* pLayerName,
268 uint32_t* pCount,
269 VkExtensionProperties* pProperties)
Jon Ashburn207a3af2015-06-10 16:43:31 -0600270{
Courtney Goeltzenleuchterda8adfe2015-07-07 10:05:05 -0600271 /* Shader checker does not have any physical device extensions */
272 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
273}
Jon Ashburn207a3af2015-06-10 16:43:31 -0600274
Courtney Goeltzenleuchterda8adfe2015-07-07 10:05:05 -0600275VK_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 Ashburn207a3af2015-06-10 16:43:31 -0600284}
Chris Forbes2778f302015-04-02 13:22:31 +1300285
Chris Forbes3a5e99a2015-04-10 11:41:20 +1200286static char const *
287storage_class_name(unsigned sc)
288{
289 switch (sc) {
Cody Northrop97e52d82015-04-20 14:09:40 -0600290 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 Forbes3a5e99a2015-04-10 11:41:20 +1200301 default: return "unknown";
302 }
303}
304
305
306/* returns ptr to null terminator */
307static char *
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -0600308describe_type(char *dst, shader_module const *src, unsigned type)
Chris Forbes3a5e99a2015-04-10 11:41:20 +1200309{
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 Elliott1cb62222015-04-17 11:05:04 -0600341 for (unsigned i = 2; i < oplen; i++) {
Chris Forbes3a5e99a2015-04-10 11:41:20 +1200342 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
353static bool
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -0600354types_match(shader_module const *a, shader_module const *b, unsigned a_type, unsigned b_type, bool b_arrayed)
Chris Forbes3a5e99a2015-04-10 11:41:20 +1200355{
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 Forbes3a5e99a2015-04-10 11:41:20 +1200360 return false;
361 }
362
363 if (b_type_def_it == b->type_def_index.end()) {
Chris Forbes3a5e99a2015-04-10 11:41:20 +1200364 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 Forbesf3fc0332015-06-05 14:57:05 +1200374 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 Forbes3a5e99a2015-04-10 11:41:20 +1200379 if (a_opcode != b_opcode) {
Chris Forbes3a5e99a2015-04-10 11:41:20 +1200380 return false;
381 }
382
383 switch (a_opcode) {
Chris Forbesf3fc0332015-06-05 14:57:05 +1200384 /* if b_arrayed and we hit a leaf type, then we can't match -- there's nowhere for the extra OpTypeArray to be! */
Chris Forbes3a5e99a2015-04-10 11:41:20 +1200385 case spv::OpTypeBool:
Chris Forbesf3fc0332015-06-05 14:57:05 +1200386 return true && !b_arrayed;
Chris Forbes3a5e99a2015-04-10 11:41:20 +1200387 case spv::OpTypeInt:
388 /* match on width, signedness */
Chris Forbesf3fc0332015-06-05 14:57:05 +1200389 return a_code[2] == b_code[2] && a_code[3] == b_code[3] && !b_arrayed;
Chris Forbes3a5e99a2015-04-10 11:41:20 +1200390 case spv::OpTypeFloat:
391 /* match on width */
Chris Forbesf3fc0332015-06-05 14:57:05 +1200392 return a_code[2] == b_code[2] && !b_arrayed;
Chris Forbes3a5e99a2015-04-10 11:41:20 +1200393 case spv::OpTypeVector:
394 case spv::OpTypeMatrix:
395 case spv::OpTypeArray:
Chris Forbesf3fc0332015-06-05 14:57:05 +1200396 /* 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 Forbes3a5e99a2015-04-10 11:41:20 +1200399 case spv::OpTypeStruct:
400 /* match on all element types */
401 {
Chris Forbesf3fc0332015-06-05 14:57:05 +1200402 if (b_arrayed) {
403 /* for the purposes of matching different levels of arrayness, structs are leaves. */
404 return false;
405 }
406
Chris Forbes3a5e99a2015-04-10 11:41:20 +1200407 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 Elliott1cb62222015-04-17 11:05:04 -0600414 for (unsigned i = 2; i < a_len; i++) {
Chris Forbesf3fc0332015-06-05 14:57:05 +1200415 if (!types_match(a, b, a_code[i], b_code[i], b_arrayed)) {
Chris Forbes3a5e99a2015-04-10 11:41:20 +1200416 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 Forbesf3fc0332015-06-05 14:57:05 +1200424 return types_match(a, b, a_code[3], b_code[3], b_arrayed);
Chris Forbes3a5e99a2015-04-10 11:41:20 +1200425
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 Forbes06e8fc32015-04-13 12:14:52 +1200436static int
437value_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
447struct 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
454static void
Chris Forbesb1dee272015-07-03 13:50:24 +1200455collect_interface_by_location(VkDevice dev,
456 shader_module const *src, spv::StorageClass sinterface,
Chris Forbes06e8fc32015-04-13 12:14:52 +1200457 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 Forbes06e8fc32015-04-13 12:14:52 +1200463 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 Northrop97e52d82015-04-20 14:09:40 -0600476 if (code[word+2] == spv::DecorationLocation) {
Chris Forbes06e8fc32015-04-13 12:14:52 +1200477 var_locations[code[word+1]] = code[word+3];
478 }
479
Cody Northrop97e52d82015-04-20 14:09:40 -0600480 if (code[word+2] == spv::DecorationBuiltIn) {
Chris Forbes06e8fc32015-04-13 12:14:52 +1200481 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 Elliott1cb62222015-04-17 11:05:04 -0600489 if (opcode == spv::OpVariable && code[word+3] == sinterface) {
Chris Forbes06e8fc32015-04-13 12:14:52 +1200490 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 Forbes9715d4a2015-07-10 09:06:54 +1200498 log_msg(mdd(dev), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_DEVICE, /*dev*/0, 0, SHADER_CHECKER_INCONSISTENT_SPIRV, "SC",
Chris Forbesb1dee272015-07-03 13:50:24 +1200499 "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 Forbes06e8fc32015-04-13 12:14:52 +1200501 }
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 Goeltzenleuchteree4027d2015-06-28 13:01:17 -0600523VK_LAYER_EXPORT VkResult VKAPI vkCreateShaderModule(
524 VkDevice device,
525 const VkShaderModuleCreateInfo *pCreateInfo,
526 VkShaderModule *pShaderModule)
Chris Forbes2778f302015-04-02 13:22:31 +1300527{
Chris Forbes7f963832015-05-29 14:55:18 +1200528 loader_platform_thread_lock_mutex(&globalLock);
Chris Forbesb1dee272015-07-03 13:50:24 +1200529 VkResult res = get_dispatch_table(shader_checker_device_table_map, device)->CreateShaderModule(device, pCreateInfo, pShaderModule);
Chris Forbes3b1c4212015-04-08 10:11:59 +1200530
Chris Forbes9715d4a2015-07-10 09:06:54 +1200531 shader_module_map[pShaderModule->handle] = new shader_module(device, pCreateInfo);
Chris Forbes7f963832015-05-29 14:55:18 +1200532 loader_platform_thread_unlock_mutex(&globalLock);
Chris Forbes2778f302015-04-02 13:22:31 +1300533 return res;
534}
535
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -0600536VK_LAYER_EXPORT VkResult VKAPI vkCreateShader(
537 VkDevice device,
538 const VkShaderCreateInfo *pCreateInfo,
539 VkShader *pShader)
540{
541 loader_platform_thread_lock_mutex(&globalLock);
Chris Forbesb1dee272015-07-03 13:50:24 +1200542 VkResult res = get_dispatch_table(shader_checker_device_table_map, device)->CreateShader(device, pCreateInfo, pShader);
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -0600543
Chris Forbes9715d4a2015-07-10 09:06:54 +1200544 shader_object_map[pShader->handle] = new shader_object(pCreateInfo);
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -0600545 loader_platform_thread_unlock_mutex(&globalLock);
546 return res;
547}
Chris Forbes2778f302015-04-02 13:22:31 +1300548
Chia-I Wu08accc62015-07-07 11:50:03 +0800549VK_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 Forbes9715d4a2015-07-10 09:06:54 +1200557 render_pass_map[pRenderPass->handle] = new render_pass(pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +0800558 loader_platform_thread_unlock_mutex(&globalLock);
559 return res;
560}
561
Chris Forbesee99b9b2015-05-25 11:13:22 +1200562static bool
Chris Forbesb1dee272015-07-03 13:50:24 +1200563validate_interface_between_stages(VkDevice dev,
564 shader_module const *producer, char const *producer_name,
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -0600565 shader_module const *consumer, char const *consumer_name,
Chris Forbesf044ec92015-06-05 15:01:08 +1200566 bool consumer_arrayed_input)
Chris Forbes41002452015-04-08 10:19:16 +1200567{
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 Forbesee99b9b2015-05-25 11:13:22 +1200574 bool pass = true;
Chris Forbes41002452015-04-08 10:19:16 +1200575
Chris Forbesb1dee272015-07-03 13:50:24 +1200576 collect_interface_by_location(dev, producer, spv::StorageClassOutput, outputs, builtin_outputs);
577 collect_interface_by_location(dev, consumer, spv::StorageClassInput, inputs, builtin_inputs);
Chris Forbes41002452015-04-08 10:19:16 +1200578
579 auto a_it = outputs.begin();
580 auto b_it = inputs.begin();
581
582 /* maps sorted by key (location); walk them together to find mismatches */
David Pinedod8f83d82015-04-27 16:36:17 -0600583 while ((outputs.size() > 0 && a_it != outputs.end()) || ( inputs.size() && b_it != inputs.end())) {
584 bool a_at_end = outputs.size() == 0 || a_it == outputs.end();
585 bool b_at_end = inputs.size() == 0 || b_it == inputs.end();
Chris Forbes62cc3fc2015-06-10 08:37:27 +1200586 auto a_first = a_at_end ? 0 : a_it->first;
587 auto b_first = b_at_end ? 0 : b_it->first;
David Pinedod8f83d82015-04-27 16:36:17 -0600588
589 if (b_at_end || a_first < b_first) {
Chris Forbes9715d4a2015-07-10 09:06:54 +1200590 log_msg(mdd(dev), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_DEVICE, /*dev*/0, 0, SHADER_CHECKER_OUTPUT_NOT_CONSUMED, "SC",
Chris Forbesb1dee272015-07-03 13:50:24 +1200591 "%s writes to output location %d which is not consumed by %s", producer_name, a_first, consumer_name);
Chris Forbes41002452015-04-08 10:19:16 +1200592 a_it++;
593 }
David Pinedod8f83d82015-04-27 16:36:17 -0600594 else if (a_at_end || a_first > b_first) {
Chris Forbes9715d4a2015-07-10 09:06:54 +1200595 log_msg(mdd(dev), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE, /*dev*/0, 0, SHADER_CHECKER_INPUT_NOT_PRODUCED, "SC",
Chris Forbesb1dee272015-07-03 13:50:24 +1200596 "%s consumes input location %d which is not written by %s", consumer_name, b_first, producer_name);
Chris Forbesee99b9b2015-05-25 11:13:22 +1200597 pass = false;
Chris Forbes41002452015-04-08 10:19:16 +1200598 b_it++;
599 }
600 else {
Chris Forbesf044ec92015-06-05 15:01:08 +1200601 if (types_match(producer, consumer, a_it->second.type_id, b_it->second.type_id, consumer_arrayed_input)) {
Chris Forbes6b2ead62015-04-17 10:13:28 +1200602 /* OK! */
Chris Forbes3a5e99a2015-04-10 11:41:20 +1200603 }
604 else {
605 char producer_type[1024];
606 char consumer_type[1024];
607 describe_type(producer_type, producer, a_it->second.type_id);
608 describe_type(consumer_type, consumer, b_it->second.type_id);
609
Chris Forbes9715d4a2015-07-10 09:06:54 +1200610 log_msg(mdd(dev), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE, /*dev*/0, 0, SHADER_CHECKER_INTERFACE_TYPE_MISMATCH, "SC",
Chris Forbesb1dee272015-07-03 13:50:24 +1200611 "Type mismatch on location %d: '%s' vs '%s'", a_it->first, producer_type, consumer_type);
Chris Forbesee99b9b2015-05-25 11:13:22 +1200612 pass = false;
Chris Forbes3a5e99a2015-04-10 11:41:20 +1200613 }
Chris Forbes41002452015-04-08 10:19:16 +1200614 a_it++;
615 b_it++;
616 }
617 }
Chris Forbesee99b9b2015-05-25 11:13:22 +1200618
619 return pass;
Chris Forbes41002452015-04-08 10:19:16 +1200620}
621
622
Chris Forbes3616b462015-04-08 10:37:20 +1200623enum FORMAT_TYPE {
624 FORMAT_TYPE_UNDEFINED,
625 FORMAT_TYPE_FLOAT, /* UNORM, SNORM, FLOAT, USCALED, SSCALED, SRGB -- anything we consider float in the shader */
626 FORMAT_TYPE_SINT,
627 FORMAT_TYPE_UINT,
628};
629
630
631static unsigned
632get_format_type(VkFormat fmt) {
633 switch (fmt) {
Chia-I Wua3b9a202015-04-17 02:00:54 +0800634 case VK_FORMAT_UNDEFINED:
Chris Forbes3616b462015-04-08 10:37:20 +1200635 return FORMAT_TYPE_UNDEFINED;
Chia-I Wua3b9a202015-04-17 02:00:54 +0800636 case VK_FORMAT_R8_SINT:
637 case VK_FORMAT_R8G8_SINT:
638 case VK_FORMAT_R8G8B8_SINT:
639 case VK_FORMAT_R8G8B8A8_SINT:
640 case VK_FORMAT_R16_SINT:
641 case VK_FORMAT_R16G16_SINT:
642 case VK_FORMAT_R16G16B16_SINT:
643 case VK_FORMAT_R16G16B16A16_SINT:
644 case VK_FORMAT_R32_SINT:
645 case VK_FORMAT_R32G32_SINT:
646 case VK_FORMAT_R32G32B32_SINT:
647 case VK_FORMAT_R32G32B32A32_SINT:
648 case VK_FORMAT_B8G8R8_SINT:
649 case VK_FORMAT_B8G8R8A8_SINT:
650 case VK_FORMAT_R10G10B10A2_SINT:
651 case VK_FORMAT_B10G10R10A2_SINT:
Chris Forbes3616b462015-04-08 10:37:20 +1200652 return FORMAT_TYPE_SINT;
Chia-I Wua3b9a202015-04-17 02:00:54 +0800653 case VK_FORMAT_R8_UINT:
654 case VK_FORMAT_R8G8_UINT:
655 case VK_FORMAT_R8G8B8_UINT:
656 case VK_FORMAT_R8G8B8A8_UINT:
657 case VK_FORMAT_R16_UINT:
658 case VK_FORMAT_R16G16_UINT:
659 case VK_FORMAT_R16G16B16_UINT:
660 case VK_FORMAT_R16G16B16A16_UINT:
661 case VK_FORMAT_R32_UINT:
662 case VK_FORMAT_R32G32_UINT:
663 case VK_FORMAT_R32G32B32_UINT:
664 case VK_FORMAT_R32G32B32A32_UINT:
665 case VK_FORMAT_B8G8R8_UINT:
666 case VK_FORMAT_B8G8R8A8_UINT:
667 case VK_FORMAT_R10G10B10A2_UINT:
668 case VK_FORMAT_B10G10R10A2_UINT:
Chris Forbes3616b462015-04-08 10:37:20 +1200669 return FORMAT_TYPE_UINT;
670 default:
671 return FORMAT_TYPE_FLOAT;
672 }
673}
674
675
Chris Forbes156a1162015-05-04 14:04:06 +1200676/* characterizes a SPIR-V type appearing in an interface to a FF stage,
677 * for comparison to a VkFormat's characterization above. */
678static unsigned
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -0600679get_fundamental_type(shader_module const *src, unsigned type)
Chris Forbes156a1162015-05-04 14:04:06 +1200680{
681 auto type_def_it = src->type_def_index.find(type);
682
683 if (type_def_it == src->type_def_index.end()) {
684 return FORMAT_TYPE_UNDEFINED;
685 }
686
687 unsigned int const *code = (unsigned int const *)&src->words[type_def_it->second];
688 unsigned opcode = code[0] & 0x0ffffu;
689 switch (opcode) {
690 case spv::OpTypeInt:
691 return code[3] ? FORMAT_TYPE_SINT : FORMAT_TYPE_UINT;
692 case spv::OpTypeFloat:
693 return FORMAT_TYPE_FLOAT;
694 case spv::OpTypeVector:
695 return get_fundamental_type(src, code[2]);
696 case spv::OpTypeMatrix:
697 return get_fundamental_type(src, code[2]);
698 case spv::OpTypeArray:
699 return get_fundamental_type(src, code[2]);
700 case spv::OpTypePointer:
701 return get_fundamental_type(src, code[3]);
702 default:
703 return FORMAT_TYPE_UNDEFINED;
704 }
705}
706
707
Chris Forbesee99b9b2015-05-25 11:13:22 +1200708static bool
Chris Forbesb1dee272015-07-03 13:50:24 +1200709validate_vi_consistency(VkDevice dev, VkPipelineVertexInputStateCreateInfo const *vi)
Chris Forbes280ba2c2015-06-12 11:16:41 +1200710{
711 /* walk the binding descriptions, which describe the step rate and stride of each vertex buffer.
712 * each binding should be specified only once.
713 */
714 std::unordered_map<uint32_t, VkVertexInputBindingDescription const *> bindings;
Chris Forbes280ba2c2015-06-12 11:16:41 +1200715 bool pass = true;
716
717 for (unsigned i = 0; i < vi->bindingCount; i++) {
718 auto desc = &vi->pVertexBindingDescriptions[i];
719 auto & binding = bindings[desc->binding];
720 if (binding) {
Chris Forbes9715d4a2015-07-10 09:06:54 +1200721 log_msg(mdd(dev), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE, /*dev*/0, 0, SHADER_CHECKER_INCONSISTENT_VI, "SC",
Chris Forbesb1dee272015-07-03 13:50:24 +1200722 "Duplicate vertex input binding descriptions for binding %d", desc->binding);
Chris Forbes280ba2c2015-06-12 11:16:41 +1200723 pass = false;
724 }
725 else {
726 binding = desc;
727 }
728 }
729
730 return pass;
731}
732
733
734static bool
Chris Forbesb1dee272015-07-03 13:50:24 +1200735validate_vi_against_vs_inputs(VkDevice dev, VkPipelineVertexInputStateCreateInfo const *vi, shader_module const *vs)
Chris Forbes772d03b2015-04-08 10:36:37 +1200736{
737 std::map<uint32_t, interface_var> inputs;
738 /* we collect builtin inputs, but they will never appear in the VI state --
739 * the vs builtin inputs are generated in the pipeline, not sourced from buffers (VertexID, etc)
740 */
741 std::map<uint32_t, interface_var> builtin_inputs;
Chris Forbesee99b9b2015-05-25 11:13:22 +1200742 bool pass = true;
Chris Forbes772d03b2015-04-08 10:36:37 +1200743
Chris Forbesb1dee272015-07-03 13:50:24 +1200744 collect_interface_by_location(dev, vs, spv::StorageClassInput, inputs, builtin_inputs);
Chris Forbes772d03b2015-04-08 10:36:37 +1200745
746 /* Build index by location */
747 std::map<uint32_t, VkVertexInputAttributeDescription const *> attribs;
Chris Forbes7191cd52015-05-25 11:13:24 +1200748 if (vi) {
749 for (unsigned i = 0; i < vi->attributeCount; i++)
750 attribs[vi->pVertexAttributeDescriptions[i].location] = &vi->pVertexAttributeDescriptions[i];
751 }
Chris Forbes772d03b2015-04-08 10:36:37 +1200752
753 auto it_a = attribs.begin();
754 auto it_b = inputs.begin();
755
David Pinedod8f83d82015-04-27 16:36:17 -0600756 while ((attribs.size() > 0 && it_a != attribs.end()) || (inputs.size() > 0 && it_b != inputs.end())) {
757 bool a_at_end = attribs.size() == 0 || it_a == attribs.end();
758 bool b_at_end = inputs.size() == 0 || it_b == inputs.end();
Chris Forbes62cc3fc2015-06-10 08:37:27 +1200759 auto a_first = a_at_end ? 0 : it_a->first;
760 auto b_first = b_at_end ? 0 : it_b->first;
David Pinedod8f83d82015-04-27 16:36:17 -0600761 if (b_at_end || a_first < b_first) {
Chris Forbes9715d4a2015-07-10 09:06:54 +1200762 log_msg(mdd(dev), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_DEVICE, /*dev*/0, 0, SHADER_CHECKER_OUTPUT_NOT_CONSUMED, "SC",
Chris Forbesb1dee272015-07-03 13:50:24 +1200763 "Vertex attribute at location %d not consumed by VS", a_first);
Chris Forbes772d03b2015-04-08 10:36:37 +1200764 it_a++;
765 }
David Pinedod8f83d82015-04-27 16:36:17 -0600766 else if (a_at_end || b_first < a_first) {
Chris Forbes9715d4a2015-07-10 09:06:54 +1200767 log_msg(mdd(dev), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE, /*dev*/0, 0, SHADER_CHECKER_INPUT_NOT_PRODUCED, "SC",
Chris Forbesb1dee272015-07-03 13:50:24 +1200768 "VS consumes input at location %d but not provided", b_first);
Chris Forbesee99b9b2015-05-25 11:13:22 +1200769 pass = false;
Chris Forbes772d03b2015-04-08 10:36:37 +1200770 it_b++;
771 }
772 else {
Chris Forbes401784b2015-05-04 14:04:24 +1200773 unsigned attrib_type = get_format_type(it_a->second->format);
774 unsigned input_type = get_fundamental_type(vs, it_b->second.type_id);
775
776 /* type checking */
777 if (attrib_type != FORMAT_TYPE_UNDEFINED && input_type != FORMAT_TYPE_UNDEFINED && attrib_type != input_type) {
778 char vs_type[1024];
779 describe_type(vs_type, vs, it_b->second.type_id);
Chris Forbes9715d4a2015-07-10 09:06:54 +1200780 log_msg(mdd(dev), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE, /*dev*/0, 0, SHADER_CHECKER_INTERFACE_TYPE_MISMATCH, "SC",
Chris Forbesb1dee272015-07-03 13:50:24 +1200781 "Attribute type of `%s` at location %d does not match VS input type of `%s`",
Chris Forbes401784b2015-05-04 14:04:24 +1200782 string_VkFormat(it_a->second->format), a_first, vs_type);
Chris Forbesee99b9b2015-05-25 11:13:22 +1200783 pass = false;
Chris Forbes401784b2015-05-04 14:04:24 +1200784 }
785
Chris Forbes6b2ead62015-04-17 10:13:28 +1200786 /* OK! */
Chris Forbes772d03b2015-04-08 10:36:37 +1200787 it_a++;
788 it_b++;
789 }
790 }
Chris Forbesee99b9b2015-05-25 11:13:22 +1200791
792 return pass;
Chris Forbes772d03b2015-04-08 10:36:37 +1200793}
794
795
Chris Forbesee99b9b2015-05-25 11:13:22 +1200796static bool
Chia-I Wu08accc62015-07-07 11:50:03 +0800797validate_fs_outputs_against_render_pass(VkDevice dev, shader_module const *fs, render_pass const *rp, uint32_t subpass)
Chris Forbes3616b462015-04-08 10:37:20 +1200798{
Chia-I Wu08accc62015-07-07 11:50:03 +0800799 const std::vector<VkFormat> &color_formats = rp->subpass_color_formats[subpass];
Chris Forbes3616b462015-04-08 10:37:20 +1200800 std::map<uint32_t, interface_var> outputs;
801 std::map<uint32_t, interface_var> builtin_outputs;
Chris Forbesee99b9b2015-05-25 11:13:22 +1200802 bool pass = true;
Chris Forbes3616b462015-04-08 10:37:20 +1200803
804 /* TODO: dual source blend index (spv::DecIndex, zero if not provided) */
805
Chris Forbesb1dee272015-07-03 13:50:24 +1200806 collect_interface_by_location(dev, fs, spv::StorageClassOutput, outputs, builtin_outputs);
Chris Forbes3616b462015-04-08 10:37:20 +1200807
808 /* Check for legacy gl_FragColor broadcast: In this case, we should have no user-defined outputs,
809 * and all color attachment should be UNORM/SNORM/FLOAT.
810 */
811 if (builtin_outputs.find(spv::BuiltInFragColor) != builtin_outputs.end()) {
Chris Forbes3616b462015-04-08 10:37:20 +1200812 if (outputs.size()) {
Chris Forbes9715d4a2015-07-10 09:06:54 +1200813 log_msg(mdd(dev), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE, /*dev*/0, 0, SHADER_CHECKER_FS_MIXED_BROADCAST, "SC",
Chris Forbesb1dee272015-07-03 13:50:24 +1200814 "Should not have user-defined FS outputs when using broadcast");
Chris Forbesee99b9b2015-05-25 11:13:22 +1200815 pass = false;
Chris Forbes3616b462015-04-08 10:37:20 +1200816 }
817
Chia-I Wu08accc62015-07-07 11:50:03 +0800818 for (unsigned i = 0; i < color_formats.size(); i++) {
819 unsigned attachmentType = get_format_type(color_formats[i]);
Chris Forbes3616b462015-04-08 10:37:20 +1200820 if (attachmentType == FORMAT_TYPE_SINT || attachmentType == FORMAT_TYPE_UINT) {
Chris Forbes9715d4a2015-07-10 09:06:54 +1200821 log_msg(mdd(dev), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE, /*dev*/0, 0, SHADER_CHECKER_INTERFACE_TYPE_MISMATCH, "SC",
Chris Forbesb1dee272015-07-03 13:50:24 +1200822 "CB format should not be SINT or UINT when using broadcast");
Chris Forbesee99b9b2015-05-25 11:13:22 +1200823 pass = false;
Chris Forbes3616b462015-04-08 10:37:20 +1200824 }
825 }
826
Chris Forbesee99b9b2015-05-25 11:13:22 +1200827 return pass;
Chris Forbes3616b462015-04-08 10:37:20 +1200828 }
829
830 auto it = outputs.begin();
831 uint32_t attachment = 0;
832
833 /* Walk attachment list and outputs together -- this is a little overpowered since attachments
834 * are currently dense, but the parallel with matching between shader stages is nice.
835 */
836
Chris Forbes9715d4a2015-07-10 09:06:54 +1200837 /* TODO: Figure out compile error with cb->attachmentCount */
Chris Forbesc2cbb0a2015-07-11 11:05:01 +1200838 while ((outputs.size() > 0 && it != outputs.end()) || attachment < color_formats.size()) {
839 if (attachment == color_formats.size() || ( it != outputs.end() && it->first < attachment)) {
Chris Forbes9715d4a2015-07-10 09:06:54 +1200840 log_msg(mdd(dev), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_DEVICE, /*dev*/0, 0, SHADER_CHECKER_OUTPUT_NOT_CONSUMED, "SC",
Chris Forbesb1dee272015-07-03 13:50:24 +1200841 "FS writes to output location %d with no matching attachment", it->first);
Chris Forbes3616b462015-04-08 10:37:20 +1200842 it++;
843 }
844 else if (it == outputs.end() || it->first > attachment) {
Chris Forbes9715d4a2015-07-10 09:06:54 +1200845 log_msg(mdd(dev), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE, /*dev*/0, 0, SHADER_CHECKER_INPUT_NOT_PRODUCED, "SC",
Chris Forbesb1dee272015-07-03 13:50:24 +1200846 "Attachment %d not written by FS", attachment);
Chris Forbes3616b462015-04-08 10:37:20 +1200847 attachment++;
Chris Forbesee99b9b2015-05-25 11:13:22 +1200848 pass = false;
Chris Forbes3616b462015-04-08 10:37:20 +1200849 }
850 else {
Chris Forbes46d31e52015-05-04 14:20:10 +1200851 unsigned output_type = get_fundamental_type(fs, it->second.type_id);
Chia-I Wu08accc62015-07-07 11:50:03 +0800852 unsigned att_type = get_format_type(color_formats[attachment]);
Chris Forbes46d31e52015-05-04 14:20:10 +1200853
854 /* type checking */
855 if (att_type != FORMAT_TYPE_UNDEFINED && output_type != FORMAT_TYPE_UNDEFINED && att_type != output_type) {
856 char fs_type[1024];
857 describe_type(fs_type, fs, it->second.type_id);
Chris Forbes9715d4a2015-07-10 09:06:54 +1200858 log_msg(mdd(dev), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE, /*dev*/0, 0, SHADER_CHECKER_INTERFACE_TYPE_MISMATCH, "SC",
Chris Forbesb1dee272015-07-03 13:50:24 +1200859 "Attachment %d of type `%s` does not match FS output type of `%s`",
Chia-I Wu08accc62015-07-07 11:50:03 +0800860 attachment, string_VkFormat(color_formats[attachment]), fs_type);
Chris Forbesee99b9b2015-05-25 11:13:22 +1200861 pass = false;
Chris Forbes46d31e52015-05-04 14:20:10 +1200862 }
863
Chris Forbes6b2ead62015-04-17 10:13:28 +1200864 /* OK! */
Chris Forbes3616b462015-04-08 10:37:20 +1200865 it++;
866 attachment++;
867 }
868 }
Chris Forbesee99b9b2015-05-25 11:13:22 +1200869
870 return pass;
Chris Forbes3616b462015-04-08 10:37:20 +1200871}
872
873
Chris Forbesf044ec92015-06-05 15:01:08 +1200874struct shader_stage_attributes {
875 char const * const name;
876 bool arrayed_input;
877};
878
879
880static shader_stage_attributes
881shader_stage_attribs[VK_SHADER_STAGE_FRAGMENT + 1] = {
882 { "vertex shader", false },
883 { "tessellation control shader", true },
884 { "tessellation evaluation shader", false },
885 { "geometry shader", true },
886 { "fragment shader", false },
887};
888
889
Jon Ashburnc669cc62015-07-09 15:02:25 -0600890//TODO handle count > 1
Chris Forbes81874ba2015-06-04 20:23:00 +1200891static bool
Jon Ashburnc669cc62015-07-09 15:02:25 -0600892validate_graphics_pipeline(VkDevice dev, uint32_t count, VkGraphicsPipelineCreateInfo const *pCreateInfo)
Chris Forbes4175e6f2015-04-08 10:15:35 +1200893{
Chris Forbesf6800b52015-04-08 10:16:45 +1200894 /* We seem to allow pipeline stages to be specified out of order, so collect and identify them
895 * before trying to do anything more: */
896
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -0600897 shader_module const *shaders[VK_SHADER_STAGE_FRAGMENT + 1]; /* exclude CS */
Chris Forbesf044ec92015-06-05 15:01:08 +1200898 memset(shaders, 0, sizeof(shaders));
Chia-I Wu08accc62015-07-07 11:50:03 +0800899 render_pass const *rp = 0;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600900 VkPipelineVertexInputStateCreateInfo const *vi = 0;
Chris Forbesee99b9b2015-05-25 11:13:22 +1200901 bool pass = true;
Chris Forbesf6800b52015-04-08 10:16:45 +1200902
Chris Forbes7f963832015-05-29 14:55:18 +1200903 loader_platform_thread_lock_mutex(&globalLock);
904
Tony Barbour92503c62015-07-13 15:28:47 -0600905 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600906 VkPipelineShaderStageCreateInfo const *pStage = &pCreateInfo->pStages[i];
907 if (pStage->sType == VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO) {
Chris Forbesf6800b52015-04-08 10:16:45 +1200908
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600909 if (pStage->stage < VK_SHADER_STAGE_VERTEX || pStage->stage > VK_SHADER_STAGE_FRAGMENT) {
Chris Forbes9715d4a2015-07-10 09:06:54 +1200910 log_msg(mdd(dev), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_DEVICE, /*dev*/0, 0, SHADER_CHECKER_UNKNOWN_STAGE, "SC",
Chris Forbesb1dee272015-07-03 13:50:24 +1200911 "Unknown shader stage %d", pStage->stage);
Chris Forbes6b2ead62015-04-17 10:13:28 +1200912 }
Chris Forbesf044ec92015-06-05 15:01:08 +1200913 else {
Chris Forbes9715d4a2015-07-10 09:06:54 +1200914 struct shader_object *shader = shader_object_map[pStage->shader.handle];
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -0600915 shaders[pStage->stage] = shader->module;
Chris Forbesf044ec92015-06-05 15:01:08 +1200916 }
Chris Forbesf6800b52015-04-08 10:16:45 +1200917 }
Chris Forbesf6800b52015-04-08 10:16:45 +1200918 }
919
Chia-I Wu08accc62015-07-07 11:50:03 +0800920 if (pCreateInfo->renderPass != VK_NULL_HANDLE)
Chris Forbes9715d4a2015-07-10 09:06:54 +1200921 rp = render_pass_map[pCreateInfo->renderPass.handle];
Chia-I Wu08accc62015-07-07 11:50:03 +0800922
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600923 vi = pCreateInfo->pVertexInputState;
924
Chris Forbes280ba2c2015-06-12 11:16:41 +1200925 if (vi) {
Chris Forbesb1dee272015-07-03 13:50:24 +1200926 pass = validate_vi_consistency(dev, vi) && pass;
Chris Forbes280ba2c2015-06-12 11:16:41 +1200927 }
928
Chris Forbesf044ec92015-06-05 15:01:08 +1200929 if (shaders[VK_SHADER_STAGE_VERTEX] && shaders[VK_SHADER_STAGE_VERTEX]->is_spirv) {
Chris Forbesb1dee272015-07-03 13:50:24 +1200930 pass = validate_vi_against_vs_inputs(dev, vi, shaders[VK_SHADER_STAGE_VERTEX]) && pass;
Chris Forbes772d03b2015-04-08 10:36:37 +1200931 }
932
Chris Forbesf044ec92015-06-05 15:01:08 +1200933 /* TODO: enforce rules about present combinations of shaders */
934 int producer = VK_SHADER_STAGE_VERTEX;
935 int consumer = VK_SHADER_STAGE_GEOMETRY;
936
937 while (!shaders[producer] && producer != VK_SHADER_STAGE_FRAGMENT) {
938 producer++;
939 consumer++;
Chris Forbes41002452015-04-08 10:19:16 +1200940 }
941
Tony Barbour0102a902015-06-11 15:04:25 -0600942 for (; producer != VK_SHADER_STAGE_FRAGMENT && consumer <= VK_SHADER_STAGE_FRAGMENT; consumer++) {
Chris Forbesf044ec92015-06-05 15:01:08 +1200943 assert(shaders[producer]);
944 if (shaders[consumer]) {
945 if (shaders[producer]->is_spirv && shaders[consumer]->is_spirv) {
Chris Forbesb1dee272015-07-03 13:50:24 +1200946 pass = validate_interface_between_stages(dev,
947 shaders[producer], shader_stage_attribs[producer].name,
Chris Forbesf044ec92015-06-05 15:01:08 +1200948 shaders[consumer], shader_stage_attribs[consumer].name,
949 shader_stage_attribs[consumer].arrayed_input) && pass;
950 }
951
952 producer = consumer;
953 }
954 }
955
Chia-I Wu08accc62015-07-07 11:50:03 +0800956 if (shaders[VK_SHADER_STAGE_FRAGMENT] && shaders[VK_SHADER_STAGE_FRAGMENT]->is_spirv && rp) {
957 pass = validate_fs_outputs_against_render_pass(dev, shaders[VK_SHADER_STAGE_FRAGMENT], rp, pCreateInfo->subpass) && pass;
Chris Forbes3616b462015-04-08 10:37:20 +1200958 }
959
Chris Forbes7f963832015-05-29 14:55:18 +1200960 loader_platform_thread_unlock_mutex(&globalLock);
Chris Forbes81874ba2015-06-04 20:23:00 +1200961 return pass;
962}
963
Jon Ashburnc669cc62015-07-09 15:02:25 -0600964//TODO handle pipelineCache entry points
Chris Forbes39d8d752015-06-04 20:27:09 +1200965VK_LAYER_EXPORT VkResult VKAPI
Jon Ashburnc669cc62015-07-09 15:02:25 -0600966vkCreateGraphicsPipelines(VkDevice device,
967 VkPipelineCache pipelineCache,
968 uint32_t count,
969 const VkGraphicsPipelineCreateInfo *pCreateInfos,
970 VkPipeline *pPipelines)
Chris Forbes81874ba2015-06-04 20:23:00 +1200971{
Jon Ashburnc669cc62015-07-09 15:02:25 -0600972 bool pass = validate_graphics_pipeline(device, count, pCreateInfos);
Chris Forbesee99b9b2015-05-25 11:13:22 +1200973
974 if (pass) {
975 /* The driver is allowed to crash if passed junk. Only actually create the
976 * pipeline if we didn't run into any showstoppers above.
977 */
Jon Ashburnc669cc62015-07-09 15:02:25 -0600978 return get_dispatch_table(shader_checker_device_table_map, device)->CreateGraphicsPipelines(device, pipelineCache, count, pCreateInfos, pPipelines);
Chris Forbesee99b9b2015-05-25 11:13:22 +1200979 }
980 else {
981 return VK_ERROR_UNKNOWN;
982 }
Chris Forbes4175e6f2015-04-08 10:15:35 +1200983}
984
985
Chris Forbesb1dee272015-07-03 13:50:24 +1200986VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
987{
988 VkLayerDispatchTable *pDeviceTable = get_dispatch_table(shader_checker_device_table_map, *pDevice);
989 VkResult result = pDeviceTable->CreateDevice(gpu, pCreateInfo, pDevice);
990 if (result == VK_SUCCESS) {
991 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
992 VkLayerDispatchTable *pTable = get_dispatch_table(shader_checker_device_table_map, *pDevice);
993 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
994 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
995 }
996 return result;
997}
Chris Forbes39d8d752015-06-04 20:27:09 +1200998
Jon Ashburn9a8a2e22015-05-19 16:34:53 -0600999/* hook DextroyDevice to remove tableMap entry */
1000VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device)
1001{
Courtney Goeltzenleuchter0daf2282015-06-13 21:22:12 -06001002 dispatch_key key = get_dispatch_key(device);
Chris Forbesb1dee272015-07-03 13:50:24 +12001003 VkLayerDispatchTable *pDisp = get_dispatch_table(shader_checker_device_table_map, device);
1004 VkResult result = pDisp->DestroyDevice(device);
1005 shader_checker_device_table_map.erase(key);
1006 return result;
Jon Ashburn9a8a2e22015-05-19 16:34:53 -06001007}
1008
Courtney Goeltzenleuchterbfd2c662015-06-01 14:46:33 -06001009VkResult VKAPI vkCreateInstance(
1010 const VkInstanceCreateInfo* pCreateInfo,
1011 VkInstance* pInstance)
1012{
Chris Forbesb1dee272015-07-03 13:50:24 +12001013 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(shader_checker_instance_table_map,*pInstance);
Courtney Goeltzenleuchterbfd2c662015-06-01 14:46:33 -06001014 VkResult result = pTable->CreateInstance(pCreateInfo, pInstance);
1015
1016 if (result == VK_SUCCESS) {
Chris Forbesb1dee272015-07-03 13:50:24 +12001017 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
1018 my_data->report_data = debug_report_create_instance(
1019 pTable,
1020 *pInstance,
1021 pCreateInfo->extensionCount,
1022 pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchterd02a9642015-06-08 14:58:39 -06001023
Chris Forbesb1dee272015-07-03 13:50:24 +12001024 init_shader_checker(my_data);
Courtney Goeltzenleuchterbfd2c662015-06-01 14:46:33 -06001025 }
1026 return result;
1027}
1028
Jon Ashburn9a8a2e22015-05-19 16:34:53 -06001029/* hook DestroyInstance to remove tableInstanceMap entry */
1030VK_LAYER_EXPORT VkResult VKAPI vkDestroyInstance(VkInstance instance)
1031{
Courtney Goeltzenleuchter0daf2282015-06-13 21:22:12 -06001032 dispatch_key key = get_dispatch_key(instance);
Chris Forbesb1dee272015-07-03 13:50:24 +12001033 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(shader_checker_instance_table_map, instance);
1034 VkResult res = pTable->DestroyInstance(instance);
1035
1036 // Clean up logging callback, if any
1037 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
1038 if (my_data->logging_callback) {
1039 layer_destroy_msg_callback(my_data->report_data, my_data->logging_callback);
1040 }
1041
1042 layer_debug_report_destroy_instance(my_data->report_data);
1043 layer_data_map.erase(pTable);
1044
1045 shader_checker_instance_table_map.erase(key);
Jon Ashburn9a8a2e22015-05-19 16:34:53 -06001046 return res;
1047}
Chris Forbesdb467bd2015-05-25 11:12:59 +12001048
Courtney Goeltzenleuchterbfd2c662015-06-01 14:46:33 -06001049VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
Chris Forbesb1dee272015-07-03 13:50:24 +12001050 VkInstance instance,
1051 VkFlags msgFlags,
1052 const PFN_vkDbgMsgCallback pfnMsgCallback,
1053 void* pUserData,
1054 VkDbgMsgCallback* pMsgCallback)
Courtney Goeltzenleuchterbfd2c662015-06-01 14:46:33 -06001055{
Chris Forbesb1dee272015-07-03 13:50:24 +12001056 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(shader_checker_instance_table_map, instance);
1057 VkResult res = pTable->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
1058 if (VK_SUCCESS == res) {
1059 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
1060 res = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
1061 }
1062 return res;
Courtney Goeltzenleuchterbfd2c662015-06-01 14:46:33 -06001063}
1064
1065VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
Chris Forbesb1dee272015-07-03 13:50:24 +12001066 VkInstance instance,
1067 VkDbgMsgCallback msgCallback)
Courtney Goeltzenleuchterbfd2c662015-06-01 14:46:33 -06001068{
Chris Forbesb1dee272015-07-03 13:50:24 +12001069 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(shader_checker_instance_table_map, instance);
1070 VkResult res = pTable->DbgDestroyMsgCallback(instance, msgCallback);
1071 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
1072 layer_destroy_msg_callback(my_data->report_data, msgCallback);
1073 return res;
Courtney Goeltzenleuchterbfd2c662015-06-01 14:46:33 -06001074}
1075
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06001076VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Chris Forbes2778f302015-04-02 13:22:31 +13001077{
Chris Forbesb1dee272015-07-03 13:50:24 +12001078 if (dev == NULL)
Chris Forbes2778f302015-04-02 13:22:31 +13001079 return NULL;
1080
Jon Ashburn8fd08252015-05-28 16:25:02 -06001081 /* loader uses this to force layer initialization; device object is wrapped */
Chris Forbesb1dee272015-07-03 13:50:24 +12001082 if (!strcmp("vkGetDeviceProcAddr", funcName)) {
1083 initDeviceTable(shader_checker_device_table_map, (const VkBaseLayerObject *) dev);
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06001084 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -06001085 }
1086
Chris Forbes2778f302015-04-02 13:22:31 +13001087#define ADD_HOOK(fn) \
Chris Forbesb1dee272015-07-03 13:50:24 +12001088 if (!strncmp(#fn, funcName, sizeof(#fn))) \
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06001089 return (PFN_vkVoidFunction) fn
Chris Forbes2778f302015-04-02 13:22:31 +13001090
Chris Forbesb1dee272015-07-03 13:50:24 +12001091 ADD_HOOK(vkCreateDevice);
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06001092 ADD_HOOK(vkCreateShaderModule);
Chris Forbes2778f302015-04-02 13:22:31 +13001093 ADD_HOOK(vkCreateShader);
Chia-I Wu08accc62015-07-07 11:50:03 +08001094 ADD_HOOK(vkCreateRenderPass);
Jon Ashburn9a8a2e22015-05-19 16:34:53 -06001095 ADD_HOOK(vkDestroyDevice);
Jon Ashburnc669cc62015-07-09 15:02:25 -06001096 ADD_HOOK(vkCreateGraphicsPipelines);
Jon Ashburne59f84f2015-05-18 09:08:41 -06001097#undef ADD_HOOK
Chris Forbesb1dee272015-07-03 13:50:24 +12001098
1099 VkLayerDispatchTable* pTable = get_dispatch_table(shader_checker_device_table_map, dev);
1100 {
1101 if (pTable->GetDeviceProcAddr == NULL)
1102 return NULL;
1103 return pTable->GetDeviceProcAddr(dev, funcName);
1104 }
Jon Ashburnf6b33db2015-05-05 14:22:52 -06001105}
1106
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06001107VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Jon Ashburnf6b33db2015-05-05 14:22:52 -06001108{
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06001109 PFN_vkVoidFunction fptr;
Courtney Goeltzenleuchterbfd2c662015-06-01 14:46:33 -06001110
Chris Forbesb1dee272015-07-03 13:50:24 +12001111 if (instance == NULL)
Jon Ashburnf6b33db2015-05-05 14:22:52 -06001112 return NULL;
1113
Chris Forbesb1dee272015-07-03 13:50:24 +12001114 if (!strcmp("vkGetInstanceProcAddr", funcName)) {
1115 initInstanceTable(shader_checker_instance_table_map, (const VkBaseLayerObject *) instance);
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06001116 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -06001117 }
Jon Ashburnf6b33db2015-05-05 14:22:52 -06001118#define ADD_HOOK(fn) \
Chris Forbesb1dee272015-07-03 13:50:24 +12001119 if (!strncmp(#fn, funcName, sizeof(#fn))) \
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06001120 return (PFN_vkVoidFunction) fn
Jon Ashburnf6b33db2015-05-05 14:22:52 -06001121
Courtney Goeltzenleuchterbfd2c662015-06-01 14:46:33 -06001122 ADD_HOOK(vkCreateInstance);
Jon Ashburn9a8a2e22015-05-19 16:34:53 -06001123 ADD_HOOK(vkDestroyInstance);
Tony Barbour59a47322015-06-24 16:06:58 -06001124 ADD_HOOK(vkGetGlobalExtensionProperties);
Tony Barbour59a47322015-06-24 16:06:58 -06001125 ADD_HOOK(vkGetPhysicalDeviceExtensionProperties);
Courtney Goeltzenleuchterda8adfe2015-07-07 10:05:05 -06001126 ADD_HOOK(vkGetGlobalLayerProperties);
1127 ADD_HOOK(vkGetPhysicalDeviceLayerProperties);
Jon Ashburne59f84f2015-05-18 09:08:41 -06001128#undef ADD_HOOK
Jon Ashburnf6b33db2015-05-05 14:22:52 -06001129
Chris Forbesb1dee272015-07-03 13:50:24 +12001130
1131 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
1132 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchterbfd2c662015-06-01 14:46:33 -06001133 if (fptr)
1134 return fptr;
1135
Chris Forbesb1dee272015-07-03 13:50:24 +12001136 {
1137 VkLayerInstanceDispatchTable* pTable = get_dispatch_table(shader_checker_instance_table_map, instance);
1138 if (pTable->GetInstanceProcAddr == NULL)
1139 return NULL;
1140 return pTable->GetInstanceProcAddr(instance, funcName);
1141 }
Chris Forbes2778f302015-04-02 13:22:31 +13001142}