blob: 25cd7ce6a2383096ba140cf0eec871a8a97603ff [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 Forbes6b2ead62015-04-17 10:13:28 +1200574 char str[1024];
Chris Forbesee99b9b2015-05-25 11:13:22 +1200575 bool pass = true;
Chris Forbes41002452015-04-08 10:19:16 +1200576
Chris Forbesb1dee272015-07-03 13:50:24 +1200577 collect_interface_by_location(dev, producer, spv::StorageClassOutput, outputs, builtin_outputs);
578 collect_interface_by_location(dev, consumer, spv::StorageClassInput, inputs, builtin_inputs);
Chris Forbes41002452015-04-08 10:19:16 +1200579
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 Pinedod8f83d82015-04-27 16:36:17 -0600584 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 Forbes62cc3fc2015-06-10 08:37:27 +1200587 auto a_first = a_at_end ? 0 : a_it->first;
588 auto b_first = b_at_end ? 0 : b_it->first;
David Pinedod8f83d82015-04-27 16:36:17 -0600589
590 if (b_at_end || a_first < b_first) {
Chris Forbes9715d4a2015-07-10 09:06:54 +1200591 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 +1200592 "%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 +1200593 a_it++;
594 }
David Pinedod8f83d82015-04-27 16:36:17 -0600595 else if (a_at_end || a_first > b_first) {
Chris Forbes9715d4a2015-07-10 09:06:54 +1200596 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 +1200597 "%s consumes input location %d which is not written by %s", consumer_name, b_first, producer_name);
Chris Forbesee99b9b2015-05-25 11:13:22 +1200598 pass = false;
Chris Forbes41002452015-04-08 10:19:16 +1200599 b_it++;
600 }
601 else {
Chris Forbesf044ec92015-06-05 15:01:08 +1200602 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 +1200603 /* OK! */
Chris Forbes3a5e99a2015-04-10 11:41:20 +1200604 }
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 Forbes9715d4a2015-07-10 09:06:54 +1200611 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 +1200612 "Type mismatch on location %d: '%s' vs '%s'", a_it->first, producer_type, consumer_type);
Chris Forbesee99b9b2015-05-25 11:13:22 +1200613 pass = false;
Chris Forbes3a5e99a2015-04-10 11:41:20 +1200614 }
Chris Forbes41002452015-04-08 10:19:16 +1200615 a_it++;
616 b_it++;
617 }
618 }
Chris Forbesee99b9b2015-05-25 11:13:22 +1200619
620 return pass;
Chris Forbes41002452015-04-08 10:19:16 +1200621}
622
623
Chris Forbes3616b462015-04-08 10:37:20 +1200624enum 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
632static unsigned
633get_format_type(VkFormat fmt) {
634 switch (fmt) {
Chia-I Wua3b9a202015-04-17 02:00:54 +0800635 case VK_FORMAT_UNDEFINED:
Chris Forbes3616b462015-04-08 10:37:20 +1200636 return FORMAT_TYPE_UNDEFINED;
Chia-I Wua3b9a202015-04-17 02:00:54 +0800637 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 Forbes3616b462015-04-08 10:37:20 +1200653 return FORMAT_TYPE_SINT;
Chia-I Wua3b9a202015-04-17 02:00:54 +0800654 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 Forbes3616b462015-04-08 10:37:20 +1200670 return FORMAT_TYPE_UINT;
671 default:
672 return FORMAT_TYPE_FLOAT;
673 }
674}
675
676
Chris Forbes156a1162015-05-04 14:04:06 +1200677/* characterizes a SPIR-V type appearing in an interface to a FF stage,
678 * for comparison to a VkFormat's characterization above. */
679static unsigned
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -0600680get_fundamental_type(shader_module const *src, unsigned type)
Chris Forbes156a1162015-05-04 14:04:06 +1200681{
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 Forbesee99b9b2015-05-25 11:13:22 +1200709static bool
Chris Forbesb1dee272015-07-03 13:50:24 +1200710validate_vi_consistency(VkDevice dev, VkPipelineVertexInputStateCreateInfo const *vi)
Chris Forbes280ba2c2015-06-12 11:16:41 +1200711{
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 Forbes280ba2c2015-06-12 11:16:41 +1200716 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 Forbes9715d4a2015-07-10 09:06:54 +1200722 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 +1200723 "Duplicate vertex input binding descriptions for binding %d", desc->binding);
Chris Forbes280ba2c2015-06-12 11:16:41 +1200724 pass = false;
725 }
726 else {
727 binding = desc;
728 }
729 }
730
731 return pass;
732}
733
734
735static bool
Chris Forbesb1dee272015-07-03 13:50:24 +1200736validate_vi_against_vs_inputs(VkDevice dev, VkPipelineVertexInputStateCreateInfo const *vi, shader_module const *vs)
Chris Forbes772d03b2015-04-08 10:36:37 +1200737{
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 Forbesee99b9b2015-05-25 11:13:22 +1200743 bool pass = true;
Chris Forbes772d03b2015-04-08 10:36:37 +1200744
Chris Forbesb1dee272015-07-03 13:50:24 +1200745 collect_interface_by_location(dev, vs, spv::StorageClassInput, inputs, builtin_inputs);
Chris Forbes772d03b2015-04-08 10:36:37 +1200746
747 /* Build index by location */
748 std::map<uint32_t, VkVertexInputAttributeDescription const *> attribs;
Chris Forbes7191cd52015-05-25 11:13:24 +1200749 if (vi) {
750 for (unsigned i = 0; i < vi->attributeCount; i++)
751 attribs[vi->pVertexAttributeDescriptions[i].location] = &vi->pVertexAttributeDescriptions[i];
752 }
Chris Forbes772d03b2015-04-08 10:36:37 +1200753
754 auto it_a = attribs.begin();
755 auto it_b = inputs.begin();
756
David Pinedod8f83d82015-04-27 16:36:17 -0600757 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 Forbes62cc3fc2015-06-10 08:37:27 +1200760 auto a_first = a_at_end ? 0 : it_a->first;
761 auto b_first = b_at_end ? 0 : it_b->first;
David Pinedod8f83d82015-04-27 16:36:17 -0600762 if (b_at_end || a_first < b_first) {
Chris Forbes9715d4a2015-07-10 09:06:54 +1200763 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 +1200764 "Vertex attribute at location %d not consumed by VS", a_first);
Chris Forbes772d03b2015-04-08 10:36:37 +1200765 it_a++;
766 }
David Pinedod8f83d82015-04-27 16:36:17 -0600767 else if (a_at_end || b_first < a_first) {
Chris Forbes9715d4a2015-07-10 09:06:54 +1200768 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 +1200769 "VS consumes input at location %d but not provided", b_first);
Chris Forbesee99b9b2015-05-25 11:13:22 +1200770 pass = false;
Chris Forbes772d03b2015-04-08 10:36:37 +1200771 it_b++;
772 }
773 else {
Chris Forbes401784b2015-05-04 14:04:24 +1200774 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 Forbes9715d4a2015-07-10 09:06:54 +1200781 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 +1200782 "Attribute type of `%s` at location %d does not match VS input type of `%s`",
Chris Forbes401784b2015-05-04 14:04:24 +1200783 string_VkFormat(it_a->second->format), a_first, vs_type);
Chris Forbesee99b9b2015-05-25 11:13:22 +1200784 pass = false;
Chris Forbes401784b2015-05-04 14:04:24 +1200785 }
786
Chris Forbes6b2ead62015-04-17 10:13:28 +1200787 /* OK! */
Chris Forbes772d03b2015-04-08 10:36:37 +1200788 it_a++;
789 it_b++;
790 }
791 }
Chris Forbesee99b9b2015-05-25 11:13:22 +1200792
793 return pass;
Chris Forbes772d03b2015-04-08 10:36:37 +1200794}
795
796
Chris Forbesee99b9b2015-05-25 11:13:22 +1200797static bool
Chia-I Wu08accc62015-07-07 11:50:03 +0800798validate_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 +1200799{
Chia-I Wu08accc62015-07-07 11:50:03 +0800800 const std::vector<VkFormat> &color_formats = rp->subpass_color_formats[subpass];
Chris Forbes3616b462015-04-08 10:37:20 +1200801 std::map<uint32_t, interface_var> outputs;
802 std::map<uint32_t, interface_var> builtin_outputs;
Chris Forbesee99b9b2015-05-25 11:13:22 +1200803 bool pass = true;
Chris Forbes3616b462015-04-08 10:37:20 +1200804
805 /* TODO: dual source blend index (spv::DecIndex, zero if not provided) */
806
Chris Forbesb1dee272015-07-03 13:50:24 +1200807 collect_interface_by_location(dev, fs, spv::StorageClassOutput, outputs, builtin_outputs);
Chris Forbes3616b462015-04-08 10:37:20 +1200808
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 Forbes3616b462015-04-08 10:37:20 +1200813 if (outputs.size()) {
Chris Forbes9715d4a2015-07-10 09:06:54 +1200814 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 +1200815 "Should not have user-defined FS outputs when using broadcast");
Chris Forbesee99b9b2015-05-25 11:13:22 +1200816 pass = false;
Chris Forbes3616b462015-04-08 10:37:20 +1200817 }
818
Chia-I Wu08accc62015-07-07 11:50:03 +0800819 for (unsigned i = 0; i < color_formats.size(); i++) {
820 unsigned attachmentType = get_format_type(color_formats[i]);
Chris Forbes3616b462015-04-08 10:37:20 +1200821 if (attachmentType == FORMAT_TYPE_SINT || attachmentType == FORMAT_TYPE_UINT) {
Chris Forbes9715d4a2015-07-10 09:06:54 +1200822 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 +1200823 "CB format should not be SINT or UINT when using broadcast");
Chris Forbesee99b9b2015-05-25 11:13:22 +1200824 pass = false;
Chris Forbes3616b462015-04-08 10:37:20 +1200825 }
826 }
827
Chris Forbesee99b9b2015-05-25 11:13:22 +1200828 return pass;
Chris Forbes3616b462015-04-08 10:37:20 +1200829 }
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 Forbes9715d4a2015-07-10 09:06:54 +1200838 /* TODO: Figure out compile error with cb->attachmentCount */
Chris Forbesc2cbb0a2015-07-11 11:05:01 +1200839 while ((outputs.size() > 0 && it != outputs.end()) || attachment < color_formats.size()) {
840 if (attachment == color_formats.size() || ( it != outputs.end() && it->first < attachment)) {
Chris Forbes9715d4a2015-07-10 09:06:54 +1200841 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 +1200842 "FS writes to output location %d with no matching attachment", it->first);
Chris Forbes3616b462015-04-08 10:37:20 +1200843 it++;
844 }
845 else if (it == outputs.end() || it->first > attachment) {
Chris Forbes9715d4a2015-07-10 09:06:54 +1200846 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 +1200847 "Attachment %d not written by FS", attachment);
Chris Forbes3616b462015-04-08 10:37:20 +1200848 attachment++;
Chris Forbesee99b9b2015-05-25 11:13:22 +1200849 pass = false;
Chris Forbes3616b462015-04-08 10:37:20 +1200850 }
851 else {
Chris Forbes46d31e52015-05-04 14:20:10 +1200852 unsigned output_type = get_fundamental_type(fs, it->second.type_id);
Chia-I Wu08accc62015-07-07 11:50:03 +0800853 unsigned att_type = get_format_type(color_formats[attachment]);
Chris Forbes46d31e52015-05-04 14:20:10 +1200854
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 Forbes9715d4a2015-07-10 09:06:54 +1200859 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 +1200860 "Attachment %d of type `%s` does not match FS output type of `%s`",
Chia-I Wu08accc62015-07-07 11:50:03 +0800861 attachment, string_VkFormat(color_formats[attachment]), fs_type);
Chris Forbesee99b9b2015-05-25 11:13:22 +1200862 pass = false;
Chris Forbes46d31e52015-05-04 14:20:10 +1200863 }
864
Chris Forbes6b2ead62015-04-17 10:13:28 +1200865 /* OK! */
Chris Forbes3616b462015-04-08 10:37:20 +1200866 it++;
867 attachment++;
868 }
869 }
Chris Forbesee99b9b2015-05-25 11:13:22 +1200870
871 return pass;
Chris Forbes3616b462015-04-08 10:37:20 +1200872}
873
874
Chris Forbesf044ec92015-06-05 15:01:08 +1200875struct shader_stage_attributes {
876 char const * const name;
877 bool arrayed_input;
878};
879
880
881static shader_stage_attributes
882shader_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 Ashburnc669cc62015-07-09 15:02:25 -0600891//TODO handle count > 1
Chris Forbes81874ba2015-06-04 20:23:00 +1200892static bool
Jon Ashburnc669cc62015-07-09 15:02:25 -0600893validate_graphics_pipeline(VkDevice dev, uint32_t count, VkGraphicsPipelineCreateInfo const *pCreateInfo)
Chris Forbes4175e6f2015-04-08 10:15:35 +1200894{
Chris Forbesf6800b52015-04-08 10:16:45 +1200895 /* 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 Goeltzenleuchteree4027d2015-06-28 13:01:17 -0600898 shader_module const *shaders[VK_SHADER_STAGE_FRAGMENT + 1]; /* exclude CS */
Chris Forbesf044ec92015-06-05 15:01:08 +1200899 memset(shaders, 0, sizeof(shaders));
Chia-I Wu08accc62015-07-07 11:50:03 +0800900 render_pass const *rp = 0;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600901 VkPipelineVertexInputStateCreateInfo const *vi = 0;
Chris Forbesee99b9b2015-05-25 11:13:22 +1200902 bool pass = true;
Chris Forbesf6800b52015-04-08 10:16:45 +1200903
Chris Forbes7f963832015-05-29 14:55:18 +1200904 loader_platform_thread_lock_mutex(&globalLock);
905
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600906 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 Forbesf6800b52015-04-08 10:16:45 +1200909
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600910 if (pStage->stage < VK_SHADER_STAGE_VERTEX || pStage->stage > VK_SHADER_STAGE_FRAGMENT) {
Chris Forbes9715d4a2015-07-10 09:06:54 +1200911 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 +1200912 "Unknown shader stage %d", pStage->stage);
Chris Forbes6b2ead62015-04-17 10:13:28 +1200913 }
Chris Forbesf044ec92015-06-05 15:01:08 +1200914 else {
Chris Forbes9715d4a2015-07-10 09:06:54 +1200915 struct shader_object *shader = shader_object_map[pStage->shader.handle];
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -0600916 shaders[pStage->stage] = shader->module;
Chris Forbesf044ec92015-06-05 15:01:08 +1200917 }
Chris Forbesf6800b52015-04-08 10:16:45 +1200918 }
Chris Forbesf6800b52015-04-08 10:16:45 +1200919 }
920
Chia-I Wu08accc62015-07-07 11:50:03 +0800921 if (pCreateInfo->renderPass != VK_NULL_HANDLE)
Chris Forbes9715d4a2015-07-10 09:06:54 +1200922 rp = render_pass_map[pCreateInfo->renderPass.handle];
Chia-I Wu08accc62015-07-07 11:50:03 +0800923
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600924 vi = pCreateInfo->pVertexInputState;
925
Chris Forbes280ba2c2015-06-12 11:16:41 +1200926 if (vi) {
Chris Forbesb1dee272015-07-03 13:50:24 +1200927 pass = validate_vi_consistency(dev, vi) && pass;
Chris Forbes280ba2c2015-06-12 11:16:41 +1200928 }
929
Chris Forbesf044ec92015-06-05 15:01:08 +1200930 if (shaders[VK_SHADER_STAGE_VERTEX] && shaders[VK_SHADER_STAGE_VERTEX]->is_spirv) {
Chris Forbesb1dee272015-07-03 13:50:24 +1200931 pass = validate_vi_against_vs_inputs(dev, vi, shaders[VK_SHADER_STAGE_VERTEX]) && pass;
Chris Forbes772d03b2015-04-08 10:36:37 +1200932 }
933
Chris Forbesf044ec92015-06-05 15:01:08 +1200934 /* 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 Forbes41002452015-04-08 10:19:16 +1200941 }
942
Tony Barbour0102a902015-06-11 15:04:25 -0600943 for (; producer != VK_SHADER_STAGE_FRAGMENT && consumer <= VK_SHADER_STAGE_FRAGMENT; consumer++) {
Chris Forbesf044ec92015-06-05 15:01:08 +1200944 assert(shaders[producer]);
945 if (shaders[consumer]) {
946 if (shaders[producer]->is_spirv && shaders[consumer]->is_spirv) {
Chris Forbesb1dee272015-07-03 13:50:24 +1200947 pass = validate_interface_between_stages(dev,
948 shaders[producer], shader_stage_attribs[producer].name,
Chris Forbesf044ec92015-06-05 15:01:08 +1200949 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 Wu08accc62015-07-07 11:50:03 +0800957 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 Forbes3616b462015-04-08 10:37:20 +1200959 }
960
Chris Forbes7f963832015-05-29 14:55:18 +1200961 loader_platform_thread_unlock_mutex(&globalLock);
Chris Forbes81874ba2015-06-04 20:23:00 +1200962 return pass;
963}
964
Jon Ashburnc669cc62015-07-09 15:02:25 -0600965//TODO handle pipelineCache entry points
Chris Forbes39d8d752015-06-04 20:27:09 +1200966VK_LAYER_EXPORT VkResult VKAPI
Jon Ashburnc669cc62015-07-09 15:02:25 -0600967vkCreateGraphicsPipelines(VkDevice device,
968 VkPipelineCache pipelineCache,
969 uint32_t count,
970 const VkGraphicsPipelineCreateInfo *pCreateInfos,
971 VkPipeline *pPipelines)
Chris Forbes81874ba2015-06-04 20:23:00 +1200972{
Jon Ashburnc669cc62015-07-09 15:02:25 -0600973 bool pass = validate_graphics_pipeline(device, count, pCreateInfos);
Chris Forbesee99b9b2015-05-25 11:13:22 +1200974
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 Ashburnc669cc62015-07-09 15:02:25 -0600979 return get_dispatch_table(shader_checker_device_table_map, device)->CreateGraphicsPipelines(device, pipelineCache, count, pCreateInfos, pPipelines);
Chris Forbesee99b9b2015-05-25 11:13:22 +1200980 }
981 else {
982 return VK_ERROR_UNKNOWN;
983 }
Chris Forbes4175e6f2015-04-08 10:15:35 +1200984}
985
986
Chris Forbesb1dee272015-07-03 13:50:24 +1200987VK_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 Forbes39d8d752015-06-04 20:27:09 +1200999
Jon Ashburn9a8a2e22015-05-19 16:34:53 -06001000/* hook DextroyDevice to remove tableMap entry */
1001VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device)
1002{
Courtney Goeltzenleuchter0daf2282015-06-13 21:22:12 -06001003 dispatch_key key = get_dispatch_key(device);
Chris Forbesb1dee272015-07-03 13:50:24 +12001004 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 Ashburn9a8a2e22015-05-19 16:34:53 -06001008}
1009
Courtney Goeltzenleuchterbfd2c662015-06-01 14:46:33 -06001010VkResult VKAPI vkCreateInstance(
1011 const VkInstanceCreateInfo* pCreateInfo,
1012 VkInstance* pInstance)
1013{
Chris Forbesb1dee272015-07-03 13:50:24 +12001014 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(shader_checker_instance_table_map,*pInstance);
Courtney Goeltzenleuchterbfd2c662015-06-01 14:46:33 -06001015 VkResult result = pTable->CreateInstance(pCreateInfo, pInstance);
1016
1017 if (result == VK_SUCCESS) {
Chris Forbesb1dee272015-07-03 13:50:24 +12001018 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 Goeltzenleuchterd02a9642015-06-08 14:58:39 -06001024
Chris Forbesb1dee272015-07-03 13:50:24 +12001025 init_shader_checker(my_data);
Courtney Goeltzenleuchterbfd2c662015-06-01 14:46:33 -06001026 }
1027 return result;
1028}
1029
Jon Ashburn9a8a2e22015-05-19 16:34:53 -06001030/* hook DestroyInstance to remove tableInstanceMap entry */
1031VK_LAYER_EXPORT VkResult VKAPI vkDestroyInstance(VkInstance instance)
1032{
Courtney Goeltzenleuchter0daf2282015-06-13 21:22:12 -06001033 dispatch_key key = get_dispatch_key(instance);
Chris Forbesb1dee272015-07-03 13:50:24 +12001034 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 Ashburn9a8a2e22015-05-19 16:34:53 -06001047 return res;
1048}
Chris Forbesdb467bd2015-05-25 11:12:59 +12001049
Courtney Goeltzenleuchterbfd2c662015-06-01 14:46:33 -06001050VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
Chris Forbesb1dee272015-07-03 13:50:24 +12001051 VkInstance instance,
1052 VkFlags msgFlags,
1053 const PFN_vkDbgMsgCallback pfnMsgCallback,
1054 void* pUserData,
1055 VkDbgMsgCallback* pMsgCallback)
Courtney Goeltzenleuchterbfd2c662015-06-01 14:46:33 -06001056{
Chris Forbesb1dee272015-07-03 13:50:24 +12001057 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 Goeltzenleuchterbfd2c662015-06-01 14:46:33 -06001064}
1065
1066VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
Chris Forbesb1dee272015-07-03 13:50:24 +12001067 VkInstance instance,
1068 VkDbgMsgCallback msgCallback)
Courtney Goeltzenleuchterbfd2c662015-06-01 14:46:33 -06001069{
Chris Forbesb1dee272015-07-03 13:50:24 +12001070 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 Goeltzenleuchterbfd2c662015-06-01 14:46:33 -06001075}
1076
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06001077VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Chris Forbes2778f302015-04-02 13:22:31 +13001078{
Chris Forbesb1dee272015-07-03 13:50:24 +12001079 if (dev == NULL)
Chris Forbes2778f302015-04-02 13:22:31 +13001080 return NULL;
1081
Jon Ashburn8fd08252015-05-28 16:25:02 -06001082 /* loader uses this to force layer initialization; device object is wrapped */
Chris Forbesb1dee272015-07-03 13:50:24 +12001083 if (!strcmp("vkGetDeviceProcAddr", funcName)) {
1084 initDeviceTable(shader_checker_device_table_map, (const VkBaseLayerObject *) dev);
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06001085 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -06001086 }
1087
Chris Forbes2778f302015-04-02 13:22:31 +13001088#define ADD_HOOK(fn) \
Chris Forbesb1dee272015-07-03 13:50:24 +12001089 if (!strncmp(#fn, funcName, sizeof(#fn))) \
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06001090 return (PFN_vkVoidFunction) fn
Chris Forbes2778f302015-04-02 13:22:31 +13001091
Chris Forbesb1dee272015-07-03 13:50:24 +12001092 ADD_HOOK(vkCreateDevice);
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06001093 ADD_HOOK(vkCreateShaderModule);
Chris Forbes2778f302015-04-02 13:22:31 +13001094 ADD_HOOK(vkCreateShader);
Chia-I Wu08accc62015-07-07 11:50:03 +08001095 ADD_HOOK(vkCreateRenderPass);
Jon Ashburn9a8a2e22015-05-19 16:34:53 -06001096 ADD_HOOK(vkDestroyDevice);
Jon Ashburnc669cc62015-07-09 15:02:25 -06001097 ADD_HOOK(vkCreateGraphicsPipelines);
Jon Ashburne59f84f2015-05-18 09:08:41 -06001098#undef ADD_HOOK
Chris Forbesb1dee272015-07-03 13:50:24 +12001099
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 Ashburnf6b33db2015-05-05 14:22:52 -06001106}
1107
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06001108VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Jon Ashburnf6b33db2015-05-05 14:22:52 -06001109{
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06001110 PFN_vkVoidFunction fptr;
Courtney Goeltzenleuchterbfd2c662015-06-01 14:46:33 -06001111
Chris Forbesb1dee272015-07-03 13:50:24 +12001112 if (instance == NULL)
Jon Ashburnf6b33db2015-05-05 14:22:52 -06001113 return NULL;
1114
Chris Forbesb1dee272015-07-03 13:50:24 +12001115 if (!strcmp("vkGetInstanceProcAddr", funcName)) {
1116 initInstanceTable(shader_checker_instance_table_map, (const VkBaseLayerObject *) instance);
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06001117 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -06001118 }
Jon Ashburnf6b33db2015-05-05 14:22:52 -06001119#define ADD_HOOK(fn) \
Chris Forbesb1dee272015-07-03 13:50:24 +12001120 if (!strncmp(#fn, funcName, sizeof(#fn))) \
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06001121 return (PFN_vkVoidFunction) fn
Jon Ashburnf6b33db2015-05-05 14:22:52 -06001122
Courtney Goeltzenleuchterbfd2c662015-06-01 14:46:33 -06001123 ADD_HOOK(vkCreateInstance);
Jon Ashburn9a8a2e22015-05-19 16:34:53 -06001124 ADD_HOOK(vkDestroyInstance);
Tony Barbour59a47322015-06-24 16:06:58 -06001125 ADD_HOOK(vkGetGlobalExtensionProperties);
Tony Barbour59a47322015-06-24 16:06:58 -06001126 ADD_HOOK(vkGetPhysicalDeviceExtensionProperties);
Courtney Goeltzenleuchterda8adfe2015-07-07 10:05:05 -06001127 ADD_HOOK(vkGetGlobalLayerProperties);
1128 ADD_HOOK(vkGetPhysicalDeviceLayerProperties);
Jon Ashburne59f84f2015-05-18 09:08:41 -06001129#undef ADD_HOOK
Jon Ashburnf6b33db2015-05-05 14:22:52 -06001130
Chris Forbesb1dee272015-07-03 13:50:24 +12001131
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 Goeltzenleuchterbfd2c662015-06-01 14:46:33 -06001134 if (fptr)
1135 return fptr;
1136
Chris Forbesb1dee272015-07-03 13:50:24 +12001137 {
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 Forbes2778f302015-04-02 13:22:31 +13001143}