blob: a8bfaed081632ade0e74fbb0495d27adb8696c94 [file] [log] [blame]
Chris Forbesaab9d112015-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 Forbes67cc36f2015-04-13 12:14:52 +120027#include <map>
Chris Forbesaab9d112015-04-02 13:22:31 +130028#include <unordered_map>
Chris Forbesbb164b62015-04-08 10:19:16 +120029#include <map>
Chris Forbes4396ff52015-04-08 10:11:59 +120030#include <vector>
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -060031#include <string>
Tobin Ehlis7a51d902015-07-03 10:34:49 -060032#include "vk_loader_platform.h"
Chris Forbesaab9d112015-04-02 13:22:31 +130033#include "vk_dispatch_table_helper.h"
Tobin Ehlis2d1d9702015-07-03 09:42:57 -060034#include "vk_layer.h"
Tobin Ehlis56d204a2015-07-03 10:15:26 -060035#include "vk_layer_config.h"
36#include "vk_layer_msg.h"
37#include "vk_layer_table.h"
Chris Forbese20111c2015-07-03 13:50:24 +120038#include "vk_layer_logging.h"
Chris Forbes3317b382015-05-04 14:04:24 +120039#include "vk_enum_string_helper.h"
Chris Forbes5c75afe2015-04-17 10:13:28 +120040#include "shader_checker.h"
Chris Forbesaab9d112015-04-02 13:22:31 +130041// The following is #included again to catch certain OS-specific functions
42// being used:
Tobin Ehlis7a51d902015-07-03 10:34:49 -060043#include "vk_loader_platform.h"
Courtney Goeltzenleuchter7abf8e52015-07-07 10:05:05 -060044#include "vk_layer_extension_utils.h"
Chris Forbesaab9d112015-04-02 13:22:31 +130045
Chris Forbes32e3b462015-05-09 10:31:21 +120046#include "spirv/spirv.h"
Chris Forbesaab9d112015-04-02 13:22:31 +130047
Chris Forbesaab9d112015-04-02 13:22:31 +130048
Chris Forbese20111c2015-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 Forbes2b7c0002015-07-10 09:06:54 +120064debug_report_data *mdd(void *object)
Chris Forbese20111c2015-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 Forbes1b466bd2015-04-15 06:59:41 +120084static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
Chris Forbes1ed0f982015-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 Forbes4396ff52015-04-08 10:11:59 +120088
Chris Forbes1bb5a2e2015-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 Goeltzenleuchter2d034fd2015-06-28 13:01:17 -0600133struct shader_module {
Chris Forbes1bb5a2e2015-04-10 11:41:20 +1200134 /* the spirv image itself */
Chris Forbes4396ff52015-04-08 10:11:59 +1200135 std::vector<uint32_t> words;
Chris Forbes1bb5a2e2015-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 Forbes4453c772015-06-05 15:01:08 +1200140 bool is_spirv;
Chris Forbes4396ff52015-04-08 10:11:59 +1200141
Chris Forbese20111c2015-07-03 13:50:24 +1200142 shader_module(VkDevice dev, VkShaderModuleCreateInfo const *pCreateInfo) :
Chris Forbes4453c772015-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 Forbes2b7c0002015-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 Forbese20111c2015-07-03 13:50:24 +1200149 "Shader is not SPIR-V, most checks will not be possible");
Chris Forbes4453c772015-06-05 15:01:08 +1200150 is_spirv = false;
151 return;
152 }
153
Chris Forbes1bb5a2e2015-04-10 11:41:20 +1200154
155 build_type_def_index(words, type_def_index);
Chris Forbes4396ff52015-04-08 10:11:59 +1200156 }
157};
158
159
Chris Forbes2b7c0002015-07-10 09:06:54 +1200160static std::unordered_map<uint64_t, shader_module *> shader_module_map;
Courtney Goeltzenleuchter2d034fd2015-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 Forbes2b7c0002015-07-10 09:06:54 +1200168 module = shader_module_map[pCreateInfo->module.handle];
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -0600169 name = pCreateInfo->pName;
170 }
171};
Chris Forbes2b7c0002015-07-10 09:06:54 +1200172static std::unordered_map<uint64_t, shader_object *> shader_object_map;
Chris Forbes4396ff52015-04-08 10:11:59 +1200173
Chia-I Wuc278df82015-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 Forbes2b7c0002015-07-10 09:06:54 +1200199static std::unordered_map<uint64_t, render_pass *> render_pass_map;
Chia-I Wuc278df82015-07-07 11:50:03 +0800200
Chris Forbes4396ff52015-04-08 10:11:59 +1200201
Chris Forbes1b466bd2015-04-15 06:59:41 +1200202static void
Chris Forbese20111c2015-07-03 13:50:24 +1200203init_shader_checker(layer_data *my_data)
Chris Forbes1b466bd2015-04-15 06:59:41 +1200204{
Chris Forbese20111c2015-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 Forbes1b466bd2015-04-15 06:59:41 +1200209 // initialize ShaderChecker options
Chris Forbese20111c2015-07-03 13:50:24 +1200210 report_flags = getLayerOptionFlags("ShaderCheckerReportFlags", 0);
211 getLayerOptionEnum("ShaderCheckerDebugAction", (uint32_t *) &debug_action);
Chris Forbes1b466bd2015-04-15 06:59:41 +1200212
Chris Forbese20111c2015-07-03 13:50:24 +1200213 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
Chris Forbes1b466bd2015-04-15 06:59:41 +1200214 {
Chris Forbese20111c2015-07-03 13:50:24 +1200215 option_str = getLayerOption("ShaderCheckerLogFilename");
216 if (option_str)
Chris Forbes1b466bd2015-04-15 06:59:41 +1200217 {
Chris Forbese20111c2015-07-03 13:50:24 +1200218 log_output = fopen(option_str, "w");
Chris Forbes1b466bd2015-04-15 06:59:41 +1200219 }
Chris Forbese20111c2015-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 Forbes1b466bd2015-04-15 06:59:41 +1200235 }
236}
237
Courtney Goeltzenleuchter7abf8e52015-07-07 10:05:05 -0600238static const VkLayerProperties shader_checker_global_layers[] = {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600239 {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600240 "ShaderChecker",
Courtney Goeltzenleuchter7abf8e52015-07-07 10:05:05 -0600241 VK_API_VERSION,
242 VK_MAKE_VERSION(0, 1, 0),
243 "Validation layer: ShaderChecker",
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600244 }
Chris Forbesaab9d112015-04-02 13:22:31 +1300245};
246
Tony Barbour426b9052015-06-24 16:06:58 -0600247VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionProperties(
Courtney Goeltzenleuchter7abf8e52015-07-07 10:05:05 -0600248 const char *pLayerName,
249 uint32_t *pCount,
250 VkExtensionProperties* pProperties)
Chris Forbesaab9d112015-04-02 13:22:31 +1300251{
Courtney Goeltzenleuchter7abf8e52015-07-07 10:05:05 -0600252 /* shader checker does not have any global extensions */
253 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
Chris Forbesaab9d112015-04-02 13:22:31 +1300254}
255
Courtney Goeltzenleuchter7abf8e52015-07-07 10:05:05 -0600256VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalLayerProperties(
257 uint32_t *pCount,
258 VkLayerProperties* pProperties)
Tony Barbour426b9052015-06-24 16:06:58 -0600259{
Courtney Goeltzenleuchter7abf8e52015-07-07 10:05:05 -0600260 return util_GetLayerProperties(ARRAY_SIZE(shader_checker_global_layers),
261 shader_checker_global_layers,
262 pCount, pProperties);
Tony Barbour426b9052015-06-24 16:06:58 -0600263}
264
265VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceExtensionProperties(
Courtney Goeltzenleuchter7abf8e52015-07-07 10:05:05 -0600266 VkPhysicalDevice physicalDevice,
267 const char* pLayerName,
268 uint32_t* pCount,
269 VkExtensionProperties* pProperties)
Jon Ashburnade3bee2015-06-10 16:43:31 -0600270{
Courtney Goeltzenleuchter7abf8e52015-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 Ashburnade3bee2015-06-10 16:43:31 -0600274
Courtney Goeltzenleuchter7abf8e52015-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 Ashburnade3bee2015-06-10 16:43:31 -0600284}
Chris Forbesaab9d112015-04-02 13:22:31 +1300285
Chris Forbes1bb5a2e2015-04-10 11:41:20 +1200286static char const *
287storage_class_name(unsigned sc)
288{
289 switch (sc) {
Cody Northrop812b4612015-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 Forbes1bb5a2e2015-04-10 11:41:20 +1200301 default: return "unknown";
302 }
303}
304
305
306/* returns ptr to null terminator */
307static char *
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -0600308describe_type(char *dst, shader_module const *src, unsigned type)
Chris Forbes1bb5a2e2015-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 Elliottf21f14b2015-04-17 11:05:04 -0600341 for (unsigned i = 2; i < oplen; i++) {
Chris Forbes1bb5a2e2015-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 Goeltzenleuchter2d034fd2015-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 Forbes1bb5a2e2015-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 Forbes1bb5a2e2015-04-10 11:41:20 +1200360 return false;
361 }
362
363 if (b_type_def_it == b->type_def_index.end()) {
Chris Forbes1bb5a2e2015-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 Forbes0a94a372015-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 Forbes1bb5a2e2015-04-10 11:41:20 +1200379 if (a_opcode != b_opcode) {
Chris Forbes1bb5a2e2015-04-10 11:41:20 +1200380 return false;
381 }
382
383 switch (a_opcode) {
Chris Forbes0a94a372015-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 Forbes1bb5a2e2015-04-10 11:41:20 +1200385 case spv::OpTypeBool:
Chris Forbes0a94a372015-06-05 14:57:05 +1200386 return true && !b_arrayed;
Chris Forbes1bb5a2e2015-04-10 11:41:20 +1200387 case spv::OpTypeInt:
388 /* match on width, signedness */
Chris Forbes0a94a372015-06-05 14:57:05 +1200389 return a_code[2] == b_code[2] && a_code[3] == b_code[3] && !b_arrayed;
Chris Forbes1bb5a2e2015-04-10 11:41:20 +1200390 case spv::OpTypeFloat:
391 /* match on width */
Chris Forbes0a94a372015-06-05 14:57:05 +1200392 return a_code[2] == b_code[2] && !b_arrayed;
Chris Forbes1bb5a2e2015-04-10 11:41:20 +1200393 case spv::OpTypeVector:
394 case spv::OpTypeMatrix:
395 case spv::OpTypeArray:
Chris Forbes0a94a372015-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 Forbes1bb5a2e2015-04-10 11:41:20 +1200399 case spv::OpTypeStruct:
400 /* match on all element types */
401 {
Chris Forbes0a94a372015-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 Forbes1bb5a2e2015-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 Elliottf21f14b2015-04-17 11:05:04 -0600414 for (unsigned i = 2; i < a_len; i++) {
Chris Forbes0a94a372015-06-05 14:57:05 +1200415 if (!types_match(a, b, a_code[i], b_code[i], b_arrayed)) {
Chris Forbes1bb5a2e2015-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 Forbes0a94a372015-06-05 14:57:05 +1200424 return types_match(a, b, a_code[3], b_code[3], b_arrayed);
Chris Forbes1bb5a2e2015-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 Forbes67cc36f2015-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 Forbese20111c2015-07-03 13:50:24 +1200455collect_interface_by_location(VkDevice dev,
456 shader_module const *src, spv::StorageClass sinterface,
Chris Forbes67cc36f2015-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 Forbes67cc36f2015-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 Northrop812b4612015-04-20 14:09:40 -0600476 if (code[word+2] == spv::DecorationLocation) {
Chris Forbes67cc36f2015-04-13 12:14:52 +1200477 var_locations[code[word+1]] = code[word+3];
478 }
479
Cody Northrop812b4612015-04-20 14:09:40 -0600480 if (code[word+2] == spv::DecorationBuiltIn) {
Chris Forbes67cc36f2015-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 Elliottf21f14b2015-04-17 11:05:04 -0600489 if (opcode == spv::OpVariable && code[word+3] == sinterface) {
Chris Forbes67cc36f2015-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 Forbes2b7c0002015-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 Forbese20111c2015-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 Forbes67cc36f2015-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 Goeltzenleuchter2d034fd2015-06-28 13:01:17 -0600523VK_LAYER_EXPORT VkResult VKAPI vkCreateShaderModule(
524 VkDevice device,
525 const VkShaderModuleCreateInfo *pCreateInfo,
526 VkShaderModule *pShaderModule)
Chris Forbesaab9d112015-04-02 13:22:31 +1300527{
Chris Forbes1ed0f982015-05-29 14:55:18 +1200528 loader_platform_thread_lock_mutex(&globalLock);
Chris Forbese20111c2015-07-03 13:50:24 +1200529 VkResult res = get_dispatch_table(shader_checker_device_table_map, device)->CreateShaderModule(device, pCreateInfo, pShaderModule);
Chris Forbes4396ff52015-04-08 10:11:59 +1200530
Chris Forbes2b7c0002015-07-10 09:06:54 +1200531 shader_module_map[pShaderModule->handle] = new shader_module(device, pCreateInfo);
Chris Forbes1ed0f982015-05-29 14:55:18 +1200532 loader_platform_thread_unlock_mutex(&globalLock);
Chris Forbesaab9d112015-04-02 13:22:31 +1300533 return res;
534}
535
Courtney Goeltzenleuchter2d034fd2015-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 Forbese20111c2015-07-03 13:50:24 +1200542 VkResult res = get_dispatch_table(shader_checker_device_table_map, device)->CreateShader(device, pCreateInfo, pShader);
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -0600543
Chris Forbes2b7c0002015-07-10 09:06:54 +1200544 shader_object_map[pShader->handle] = new shader_object(pCreateInfo);
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -0600545 loader_platform_thread_unlock_mutex(&globalLock);
546 return res;
547}
Chris Forbesaab9d112015-04-02 13:22:31 +1300548
Chia-I Wuc278df82015-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 Forbes2b7c0002015-07-10 09:06:54 +1200557 render_pass_map[pRenderPass->handle] = new render_pass(pCreateInfo);
Chia-I Wuc278df82015-07-07 11:50:03 +0800558 loader_platform_thread_unlock_mutex(&globalLock);
559 return res;
560}
561
Chris Forbes5f362d02015-05-25 11:13:22 +1200562static bool
Chris Forbese20111c2015-07-03 13:50:24 +1200563validate_interface_between_stages(VkDevice dev,
564 shader_module const *producer, char const *producer_name,
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -0600565 shader_module const *consumer, char const *consumer_name,
Chris Forbes4453c772015-06-05 15:01:08 +1200566 bool consumer_arrayed_input)
Chris Forbesbb164b62015-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 Forbes5f362d02015-05-25 11:13:22 +1200574 bool pass = true;
Chris Forbesbb164b62015-04-08 10:19:16 +1200575
Chris Forbese20111c2015-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 Forbesbb164b62015-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 Pinedof5997ab2015-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 Forbes4cb97672015-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 Pinedof5997ab2015-04-27 16:36:17 -0600588
589 if (b_at_end || a_first < b_first) {
Chris Forbes2b7c0002015-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 Forbese20111c2015-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 Forbesbb164b62015-04-08 10:19:16 +1200592 a_it++;
593 }
David Pinedof5997ab2015-04-27 16:36:17 -0600594 else if (a_at_end || a_first > b_first) {
Chris Forbes2b7c0002015-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 Forbese20111c2015-07-03 13:50:24 +1200596 "%s consumes input location %d which is not written by %s", consumer_name, b_first, producer_name);
Chris Forbes5f362d02015-05-25 11:13:22 +1200597 pass = false;
Chris Forbesbb164b62015-04-08 10:19:16 +1200598 b_it++;
599 }
600 else {
Chris Forbes4453c772015-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 Forbes5c75afe2015-04-17 10:13:28 +1200602 /* OK! */
Chris Forbes1bb5a2e2015-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 Forbes2b7c0002015-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 Forbese20111c2015-07-03 13:50:24 +1200611 "Type mismatch on location %d: '%s' vs '%s'", a_it->first, producer_type, consumer_type);
Chris Forbes5f362d02015-05-25 11:13:22 +1200612 pass = false;
Chris Forbes1bb5a2e2015-04-10 11:41:20 +1200613 }
Chris Forbesbb164b62015-04-08 10:19:16 +1200614 a_it++;
615 b_it++;
616 }
617 }
Chris Forbes5f362d02015-05-25 11:13:22 +1200618
619 return pass;
Chris Forbesbb164b62015-04-08 10:19:16 +1200620}
621
622
Chris Forbes9b9f5fe2015-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 Wu6097f3a2015-04-17 02:00:54 +0800634 case VK_FORMAT_UNDEFINED:
Chris Forbes9b9f5fe2015-04-08 10:37:20 +1200635 return FORMAT_TYPE_UNDEFINED;
Chia-I Wu6097f3a2015-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 Forbes9b9f5fe2015-04-08 10:37:20 +1200652 return FORMAT_TYPE_SINT;
Chia-I Wu6097f3a2015-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 Forbes9b9f5fe2015-04-08 10:37:20 +1200669 return FORMAT_TYPE_UINT;
670 default:
671 return FORMAT_TYPE_FLOAT;
672 }
673}
674
675
Chris Forbes28c50882015-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 Goeltzenleuchter2d034fd2015-06-28 13:01:17 -0600679get_fundamental_type(shader_module const *src, unsigned type)
Chris Forbes28c50882015-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 Forbes5f362d02015-05-25 11:13:22 +1200708static bool
Chris Forbese20111c2015-07-03 13:50:24 +1200709validate_vi_consistency(VkDevice dev, VkPipelineVertexInputStateCreateInfo const *vi)
Chris Forbes0bf8fe12015-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 Forbes0bf8fe12015-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 Forbes2b7c0002015-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 Forbese20111c2015-07-03 13:50:24 +1200722 "Duplicate vertex input binding descriptions for binding %d", desc->binding);
Chris Forbes0bf8fe12015-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 Forbese20111c2015-07-03 13:50:24 +1200735validate_vi_against_vs_inputs(VkDevice dev, VkPipelineVertexInputStateCreateInfo const *vi, shader_module const *vs)
Chris Forbesfcd05f12015-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 Forbes5f362d02015-05-25 11:13:22 +1200742 bool pass = true;
Chris Forbesfcd05f12015-04-08 10:36:37 +1200743
Chris Forbese20111c2015-07-03 13:50:24 +1200744 collect_interface_by_location(dev, vs, spv::StorageClassInput, inputs, builtin_inputs);
Chris Forbesfcd05f12015-04-08 10:36:37 +1200745
746 /* Build index by location */
747 std::map<uint32_t, VkVertexInputAttributeDescription const *> attribs;
Chris Forbes6f2ab982015-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 Forbesfcd05f12015-04-08 10:36:37 +1200752
753 auto it_a = attribs.begin();
754 auto it_b = inputs.begin();
755
David Pinedof5997ab2015-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 Forbes4cb97672015-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 Pinedof5997ab2015-04-27 16:36:17 -0600761 if (b_at_end || a_first < b_first) {
Chris Forbes2b7c0002015-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 Forbese20111c2015-07-03 13:50:24 +1200763 "Vertex attribute at location %d not consumed by VS", a_first);
Chris Forbesfcd05f12015-04-08 10:36:37 +1200764 it_a++;
765 }
David Pinedof5997ab2015-04-27 16:36:17 -0600766 else if (a_at_end || b_first < a_first) {
Chris Forbes2b7c0002015-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 Forbese20111c2015-07-03 13:50:24 +1200768 "VS consumes input at location %d but not provided", b_first);
Chris Forbes5f362d02015-05-25 11:13:22 +1200769 pass = false;
Chris Forbesfcd05f12015-04-08 10:36:37 +1200770 it_b++;
771 }
772 else {
Chris Forbes3317b382015-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 Forbes2b7c0002015-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 Forbese20111c2015-07-03 13:50:24 +1200781 "Attribute type of `%s` at location %d does not match VS input type of `%s`",
Chris Forbes3317b382015-05-04 14:04:24 +1200782 string_VkFormat(it_a->second->format), a_first, vs_type);
Chris Forbes5f362d02015-05-25 11:13:22 +1200783 pass = false;
Chris Forbes3317b382015-05-04 14:04:24 +1200784 }
785
Chris Forbes5c75afe2015-04-17 10:13:28 +1200786 /* OK! */
Chris Forbesfcd05f12015-04-08 10:36:37 +1200787 it_a++;
788 it_b++;
789 }
790 }
Chris Forbes5f362d02015-05-25 11:13:22 +1200791
792 return pass;
Chris Forbesfcd05f12015-04-08 10:36:37 +1200793}
794
795
Chris Forbes5f362d02015-05-25 11:13:22 +1200796static bool
Chia-I Wuc278df82015-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 Forbes9b9f5fe2015-04-08 10:37:20 +1200798{
Chia-I Wuc278df82015-07-07 11:50:03 +0800799 const std::vector<VkFormat> &color_formats = rp->subpass_color_formats[subpass];
Chris Forbes9b9f5fe2015-04-08 10:37:20 +1200800 std::map<uint32_t, interface_var> outputs;
801 std::map<uint32_t, interface_var> builtin_outputs;
Chris Forbes5f362d02015-05-25 11:13:22 +1200802 bool pass = true;
Chris Forbes9b9f5fe2015-04-08 10:37:20 +1200803
804 /* TODO: dual source blend index (spv::DecIndex, zero if not provided) */
805
Chris Forbese20111c2015-07-03 13:50:24 +1200806 collect_interface_by_location(dev, fs, spv::StorageClassOutput, outputs, builtin_outputs);
Chris Forbes9b9f5fe2015-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 Forbes9b9f5fe2015-04-08 10:37:20 +1200812 if (outputs.size()) {
Chris Forbes2b7c0002015-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 Forbese20111c2015-07-03 13:50:24 +1200814 "Should not have user-defined FS outputs when using broadcast");
Chris Forbes5f362d02015-05-25 11:13:22 +1200815 pass = false;
Chris Forbes9b9f5fe2015-04-08 10:37:20 +1200816 }
817
Chia-I Wuc278df82015-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 Forbes9b9f5fe2015-04-08 10:37:20 +1200820 if (attachmentType == FORMAT_TYPE_SINT || attachmentType == FORMAT_TYPE_UINT) {
Chris Forbes2b7c0002015-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 Forbese20111c2015-07-03 13:50:24 +1200822 "CB format should not be SINT or UINT when using broadcast");
Chris Forbes5f362d02015-05-25 11:13:22 +1200823 pass = false;
Chris Forbes9b9f5fe2015-04-08 10:37:20 +1200824 }
825 }
826
Chris Forbes5f362d02015-05-25 11:13:22 +1200827 return pass;
Chris Forbes9b9f5fe2015-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 Forbes2b7c0002015-07-10 09:06:54 +1200837 /* TODO: Figure out compile error with cb->attachmentCount */
Chris Forbes768eead2015-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 Forbes2b7c0002015-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 Forbese20111c2015-07-03 13:50:24 +1200841 "FS writes to output location %d with no matching attachment", it->first);
Chris Forbes9b9f5fe2015-04-08 10:37:20 +1200842 it++;
843 }
844 else if (it == outputs.end() || it->first > attachment) {
Chris Forbes2b7c0002015-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 Forbese20111c2015-07-03 13:50:24 +1200846 "Attachment %d not written by FS", attachment);
Chris Forbes9b9f5fe2015-04-08 10:37:20 +1200847 attachment++;
Chris Forbes5f362d02015-05-25 11:13:22 +1200848 pass = false;
Chris Forbes9b9f5fe2015-04-08 10:37:20 +1200849 }
850 else {
Chris Forbes4b009002015-05-04 14:20:10 +1200851 unsigned output_type = get_fundamental_type(fs, it->second.type_id);
Chia-I Wuc278df82015-07-07 11:50:03 +0800852 unsigned att_type = get_format_type(color_formats[attachment]);
Chris Forbes4b009002015-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 Forbes2b7c0002015-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 Forbese20111c2015-07-03 13:50:24 +1200859 "Attachment %d of type `%s` does not match FS output type of `%s`",
Chia-I Wuc278df82015-07-07 11:50:03 +0800860 attachment, string_VkFormat(color_formats[attachment]), fs_type);
Chris Forbes5f362d02015-05-25 11:13:22 +1200861 pass = false;
Chris Forbes4b009002015-05-04 14:20:10 +1200862 }
863
Chris Forbes5c75afe2015-04-17 10:13:28 +1200864 /* OK! */
Chris Forbes9b9f5fe2015-04-08 10:37:20 +1200865 it++;
866 attachment++;
867 }
868 }
Chris Forbes5f362d02015-05-25 11:13:22 +1200869
870 return pass;
Chris Forbes9b9f5fe2015-04-08 10:37:20 +1200871}
872
873
Chris Forbes4453c772015-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
Chris Forbesf1060ca2015-06-04 20:23:00 +1200890static bool
Chris Forbesd8bde292015-07-24 13:53:47 +1200891validate_graphics_pipeline(VkDevice dev, VkGraphicsPipelineCreateInfo const *pCreateInfo)
Chris Forbes60540932015-04-08 10:15:35 +1200892{
Chris Forbes8f600932015-04-08 10:16:45 +1200893 /* We seem to allow pipeline stages to be specified out of order, so collect and identify them
894 * before trying to do anything more: */
895
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -0600896 shader_module const *shaders[VK_SHADER_STAGE_FRAGMENT + 1]; /* exclude CS */
Chris Forbes4453c772015-06-05 15:01:08 +1200897 memset(shaders, 0, sizeof(shaders));
Chia-I Wuc278df82015-07-07 11:50:03 +0800898 render_pass const *rp = 0;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600899 VkPipelineVertexInputStateCreateInfo const *vi = 0;
Chris Forbes5f362d02015-05-25 11:13:22 +1200900 bool pass = true;
Chris Forbes8f600932015-04-08 10:16:45 +1200901
Chris Forbes1ed0f982015-05-29 14:55:18 +1200902 loader_platform_thread_lock_mutex(&globalLock);
903
Tony Barbourb2cc40a2015-07-13 15:28:47 -0600904 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600905 VkPipelineShaderStageCreateInfo const *pStage = &pCreateInfo->pStages[i];
906 if (pStage->sType == VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO) {
Chris Forbes8f600932015-04-08 10:16:45 +1200907
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600908 if (pStage->stage < VK_SHADER_STAGE_VERTEX || pStage->stage > VK_SHADER_STAGE_FRAGMENT) {
Chris Forbes2b7c0002015-07-10 09:06:54 +1200909 log_msg(mdd(dev), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_DEVICE, /*dev*/0, 0, SHADER_CHECKER_UNKNOWN_STAGE, "SC",
Chris Forbese20111c2015-07-03 13:50:24 +1200910 "Unknown shader stage %d", pStage->stage);
Chris Forbes5c75afe2015-04-17 10:13:28 +1200911 }
Chris Forbes4453c772015-06-05 15:01:08 +1200912 else {
Chris Forbes2b7c0002015-07-10 09:06:54 +1200913 struct shader_object *shader = shader_object_map[pStage->shader.handle];
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -0600914 shaders[pStage->stage] = shader->module;
Chris Forbes4453c772015-06-05 15:01:08 +1200915 }
Chris Forbes8f600932015-04-08 10:16:45 +1200916 }
Chris Forbes8f600932015-04-08 10:16:45 +1200917 }
918
Chia-I Wuc278df82015-07-07 11:50:03 +0800919 if (pCreateInfo->renderPass != VK_NULL_HANDLE)
Chris Forbes2b7c0002015-07-10 09:06:54 +1200920 rp = render_pass_map[pCreateInfo->renderPass.handle];
Chia-I Wuc278df82015-07-07 11:50:03 +0800921
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600922 vi = pCreateInfo->pVertexInputState;
923
Chris Forbes0bf8fe12015-06-12 11:16:41 +1200924 if (vi) {
Chris Forbese20111c2015-07-03 13:50:24 +1200925 pass = validate_vi_consistency(dev, vi) && pass;
Chris Forbes0bf8fe12015-06-12 11:16:41 +1200926 }
927
Chris Forbes4453c772015-06-05 15:01:08 +1200928 if (shaders[VK_SHADER_STAGE_VERTEX] && shaders[VK_SHADER_STAGE_VERTEX]->is_spirv) {
Chris Forbese20111c2015-07-03 13:50:24 +1200929 pass = validate_vi_against_vs_inputs(dev, vi, shaders[VK_SHADER_STAGE_VERTEX]) && pass;
Chris Forbesfcd05f12015-04-08 10:36:37 +1200930 }
931
Chris Forbes4453c772015-06-05 15:01:08 +1200932 /* TODO: enforce rules about present combinations of shaders */
933 int producer = VK_SHADER_STAGE_VERTEX;
934 int consumer = VK_SHADER_STAGE_GEOMETRY;
935
936 while (!shaders[producer] && producer != VK_SHADER_STAGE_FRAGMENT) {
937 producer++;
938 consumer++;
Chris Forbesbb164b62015-04-08 10:19:16 +1200939 }
940
Tony Barbour4eb3cd12015-06-11 15:04:25 -0600941 for (; producer != VK_SHADER_STAGE_FRAGMENT && consumer <= VK_SHADER_STAGE_FRAGMENT; consumer++) {
Chris Forbes4453c772015-06-05 15:01:08 +1200942 assert(shaders[producer]);
943 if (shaders[consumer]) {
944 if (shaders[producer]->is_spirv && shaders[consumer]->is_spirv) {
Chris Forbese20111c2015-07-03 13:50:24 +1200945 pass = validate_interface_between_stages(dev,
946 shaders[producer], shader_stage_attribs[producer].name,
Chris Forbes4453c772015-06-05 15:01:08 +1200947 shaders[consumer], shader_stage_attribs[consumer].name,
948 shader_stage_attribs[consumer].arrayed_input) && pass;
949 }
950
951 producer = consumer;
952 }
953 }
954
Chia-I Wuc278df82015-07-07 11:50:03 +0800955 if (shaders[VK_SHADER_STAGE_FRAGMENT] && shaders[VK_SHADER_STAGE_FRAGMENT]->is_spirv && rp) {
956 pass = validate_fs_outputs_against_render_pass(dev, shaders[VK_SHADER_STAGE_FRAGMENT], rp, pCreateInfo->subpass) && pass;
Chris Forbes9b9f5fe2015-04-08 10:37:20 +1200957 }
958
Chris Forbes1ed0f982015-05-29 14:55:18 +1200959 loader_platform_thread_unlock_mutex(&globalLock);
Chris Forbesf1060ca2015-06-04 20:23:00 +1200960 return pass;
961}
962
Jon Ashburn0d60d272015-07-09 15:02:25 -0600963//TODO handle pipelineCache entry points
Chris Forbesd0f7f7c2015-06-04 20:27:09 +1200964VK_LAYER_EXPORT VkResult VKAPI
Jon Ashburn0d60d272015-07-09 15:02:25 -0600965vkCreateGraphicsPipelines(VkDevice device,
966 VkPipelineCache pipelineCache,
967 uint32_t count,
968 const VkGraphicsPipelineCreateInfo *pCreateInfos,
969 VkPipeline *pPipelines)
Chris Forbesf1060ca2015-06-04 20:23:00 +1200970{
Chris Forbesd8bde292015-07-24 13:53:47 +1200971 bool pass = true;
972 for (uint32_t i = 0; i < count; i++) {
973 pass = validate_graphics_pipeline(device, &pCreateInfos[i]) && pass;
974 }
Chris Forbes5f362d02015-05-25 11:13:22 +1200975
976 if (pass) {
977 /* The driver is allowed to crash if passed junk. Only actually create the
978 * pipeline if we didn't run into any showstoppers above.
979 */
Jon Ashburn0d60d272015-07-09 15:02:25 -0600980 return get_dispatch_table(shader_checker_device_table_map, device)->CreateGraphicsPipelines(device, pipelineCache, count, pCreateInfos, pPipelines);
Chris Forbes5f362d02015-05-25 11:13:22 +1200981 }
982 else {
983 return VK_ERROR_UNKNOWN;
984 }
Chris Forbes60540932015-04-08 10:15:35 +1200985}
986
987
Chris Forbese20111c2015-07-03 13:50:24 +1200988VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
989{
990 VkLayerDispatchTable *pDeviceTable = get_dispatch_table(shader_checker_device_table_map, *pDevice);
991 VkResult result = pDeviceTable->CreateDevice(gpu, pCreateInfo, pDevice);
992 if (result == VK_SUCCESS) {
993 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
994 VkLayerDispatchTable *pTable = get_dispatch_table(shader_checker_device_table_map, *pDevice);
995 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
996 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
997 }
998 return result;
999}
Chris Forbesd0f7f7c2015-06-04 20:27:09 +12001000
Jon Ashburn17f37372015-05-19 16:34:53 -06001001/* hook DextroyDevice to remove tableMap entry */
1002VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device)
1003{
Courtney Goeltzenleuchter9f171942015-06-13 21:22:12 -06001004 dispatch_key key = get_dispatch_key(device);
Chris Forbese20111c2015-07-03 13:50:24 +12001005 VkLayerDispatchTable *pDisp = get_dispatch_table(shader_checker_device_table_map, device);
1006 VkResult result = pDisp->DestroyDevice(device);
1007 shader_checker_device_table_map.erase(key);
1008 return result;
Jon Ashburn17f37372015-05-19 16:34:53 -06001009}
1010
Courtney Goeltzenleuchter6c813dc2015-06-01 14:46:33 -06001011VkResult VKAPI vkCreateInstance(
1012 const VkInstanceCreateInfo* pCreateInfo,
1013 VkInstance* pInstance)
1014{
Chris Forbese20111c2015-07-03 13:50:24 +12001015 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(shader_checker_instance_table_map,*pInstance);
Courtney Goeltzenleuchter6c813dc2015-06-01 14:46:33 -06001016 VkResult result = pTable->CreateInstance(pCreateInfo, pInstance);
1017
1018 if (result == VK_SUCCESS) {
Chris Forbese20111c2015-07-03 13:50:24 +12001019 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
1020 my_data->report_data = debug_report_create_instance(
1021 pTable,
1022 *pInstance,
1023 pCreateInfo->extensionCount,
1024 pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchterf4a2eba2015-06-08 14:58:39 -06001025
Chris Forbese20111c2015-07-03 13:50:24 +12001026 init_shader_checker(my_data);
Courtney Goeltzenleuchter6c813dc2015-06-01 14:46:33 -06001027 }
1028 return result;
1029}
1030
Jon Ashburn17f37372015-05-19 16:34:53 -06001031/* hook DestroyInstance to remove tableInstanceMap entry */
1032VK_LAYER_EXPORT VkResult VKAPI vkDestroyInstance(VkInstance instance)
1033{
Courtney Goeltzenleuchter9f171942015-06-13 21:22:12 -06001034 dispatch_key key = get_dispatch_key(instance);
Chris Forbese20111c2015-07-03 13:50:24 +12001035 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(shader_checker_instance_table_map, instance);
1036 VkResult res = pTable->DestroyInstance(instance);
1037
1038 // Clean up logging callback, if any
1039 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
1040 if (my_data->logging_callback) {
1041 layer_destroy_msg_callback(my_data->report_data, my_data->logging_callback);
1042 }
1043
1044 layer_debug_report_destroy_instance(my_data->report_data);
1045 layer_data_map.erase(pTable);
1046
1047 shader_checker_instance_table_map.erase(key);
Jon Ashburn17f37372015-05-19 16:34:53 -06001048 return res;
1049}
Chris Forbesb65ba352015-05-25 11:12:59 +12001050
Courtney Goeltzenleuchter6c813dc2015-06-01 14:46:33 -06001051VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
Chris Forbese20111c2015-07-03 13:50:24 +12001052 VkInstance instance,
1053 VkFlags msgFlags,
1054 const PFN_vkDbgMsgCallback pfnMsgCallback,
1055 void* pUserData,
1056 VkDbgMsgCallback* pMsgCallback)
Courtney Goeltzenleuchter6c813dc2015-06-01 14:46:33 -06001057{
Chris Forbese20111c2015-07-03 13:50:24 +12001058 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(shader_checker_instance_table_map, instance);
1059 VkResult res = pTable->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
1060 if (VK_SUCCESS == res) {
1061 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
1062 res = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
1063 }
1064 return res;
Courtney Goeltzenleuchter6c813dc2015-06-01 14:46:33 -06001065}
1066
1067VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
Chris Forbese20111c2015-07-03 13:50:24 +12001068 VkInstance instance,
1069 VkDbgMsgCallback msgCallback)
Courtney Goeltzenleuchter6c813dc2015-06-01 14:46:33 -06001070{
Chris Forbese20111c2015-07-03 13:50:24 +12001071 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(shader_checker_instance_table_map, instance);
1072 VkResult res = pTable->DbgDestroyMsgCallback(instance, msgCallback);
1073 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
1074 layer_destroy_msg_callback(my_data->report_data, msgCallback);
1075 return res;
Courtney Goeltzenleuchter6c813dc2015-06-01 14:46:33 -06001076}
1077
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06001078VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Chris Forbesaab9d112015-04-02 13:22:31 +13001079{
Chris Forbese20111c2015-07-03 13:50:24 +12001080 if (dev == NULL)
Chris Forbesaab9d112015-04-02 13:22:31 +13001081 return NULL;
1082
Jon Ashburn4f2575f2015-05-28 16:25:02 -06001083 /* loader uses this to force layer initialization; device object is wrapped */
Chris Forbese20111c2015-07-03 13:50:24 +12001084 if (!strcmp("vkGetDeviceProcAddr", funcName)) {
1085 initDeviceTable(shader_checker_device_table_map, (const VkBaseLayerObject *) dev);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06001086 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06001087 }
1088
Chris Forbesaab9d112015-04-02 13:22:31 +13001089#define ADD_HOOK(fn) \
Chris Forbese20111c2015-07-03 13:50:24 +12001090 if (!strncmp(#fn, funcName, sizeof(#fn))) \
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06001091 return (PFN_vkVoidFunction) fn
Chris Forbesaab9d112015-04-02 13:22:31 +13001092
Chris Forbese20111c2015-07-03 13:50:24 +12001093 ADD_HOOK(vkCreateDevice);
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001094 ADD_HOOK(vkCreateShaderModule);
Chris Forbesaab9d112015-04-02 13:22:31 +13001095 ADD_HOOK(vkCreateShader);
Chia-I Wuc278df82015-07-07 11:50:03 +08001096 ADD_HOOK(vkCreateRenderPass);
Jon Ashburn17f37372015-05-19 16:34:53 -06001097 ADD_HOOK(vkDestroyDevice);
Jon Ashburn0d60d272015-07-09 15:02:25 -06001098 ADD_HOOK(vkCreateGraphicsPipelines);
Jon Ashburn8198fd02015-05-18 09:08:41 -06001099#undef ADD_HOOK
Chris Forbese20111c2015-07-03 13:50:24 +12001100
1101 VkLayerDispatchTable* pTable = get_dispatch_table(shader_checker_device_table_map, dev);
1102 {
1103 if (pTable->GetDeviceProcAddr == NULL)
1104 return NULL;
1105 return pTable->GetDeviceProcAddr(dev, funcName);
1106 }
Jon Ashburn79b78ac2015-05-05 14:22:52 -06001107}
1108
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06001109VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06001110{
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06001111 PFN_vkVoidFunction fptr;
Courtney Goeltzenleuchter6c813dc2015-06-01 14:46:33 -06001112
Chris Forbese20111c2015-07-03 13:50:24 +12001113 if (instance == NULL)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06001114 return NULL;
1115
Chris Forbese20111c2015-07-03 13:50:24 +12001116 if (!strcmp("vkGetInstanceProcAddr", funcName)) {
1117 initInstanceTable(shader_checker_instance_table_map, (const VkBaseLayerObject *) instance);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06001118 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06001119 }
Jon Ashburn79b78ac2015-05-05 14:22:52 -06001120#define ADD_HOOK(fn) \
Chris Forbese20111c2015-07-03 13:50:24 +12001121 if (!strncmp(#fn, funcName, sizeof(#fn))) \
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06001122 return (PFN_vkVoidFunction) fn
Jon Ashburn79b78ac2015-05-05 14:22:52 -06001123
Courtney Goeltzenleuchter6c813dc2015-06-01 14:46:33 -06001124 ADD_HOOK(vkCreateInstance);
Jon Ashburn17f37372015-05-19 16:34:53 -06001125 ADD_HOOK(vkDestroyInstance);
Tony Barbour426b9052015-06-24 16:06:58 -06001126 ADD_HOOK(vkGetGlobalExtensionProperties);
Tony Barbour426b9052015-06-24 16:06:58 -06001127 ADD_HOOK(vkGetPhysicalDeviceExtensionProperties);
Courtney Goeltzenleuchter7abf8e52015-07-07 10:05:05 -06001128 ADD_HOOK(vkGetGlobalLayerProperties);
1129 ADD_HOOK(vkGetPhysicalDeviceLayerProperties);
Jon Ashburn8198fd02015-05-18 09:08:41 -06001130#undef ADD_HOOK
Jon Ashburn79b78ac2015-05-05 14:22:52 -06001131
Chris Forbese20111c2015-07-03 13:50:24 +12001132
1133 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
1134 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchter6c813dc2015-06-01 14:46:33 -06001135 if (fptr)
1136 return fptr;
1137
Chris Forbese20111c2015-07-03 13:50:24 +12001138 {
1139 VkLayerInstanceDispatchTable* pTable = get_dispatch_table(shader_checker_instance_table_map, instance);
1140 if (pTable->GetInstanceProcAddr == NULL)
1141 return NULL;
1142 return pTable->GetInstanceProcAddr(instance, funcName);
1143 }
Chris Forbesaab9d112015-04-02 13:22:31 +13001144}