blob: e3f822c1c918feb4400056548192c59540e6658d [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
GregF3aaa0882015-07-21 17:22:50 -060046#include "spirv/spirv.hpp"
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:
GregF3aaa0882015-07-21 17:22:50 -0600108 case spv::OpTypeImage:
Chris Forbes1bb5a2e2015-04-10 11:41:20 +1200109 case spv::OpTypeSampler:
GregF3aaa0882015-07-21 17:22:50 -0600110 case spv::OpTypeSampledImage:
Chris Forbes1bb5a2e2015-04-10 11:41:20 +1200111 case spv::OpTypeArray:
112 case spv::OpTypeRuntimeArray:
113 case spv::OpTypeStruct:
114 case spv::OpTypeOpaque:
115 case spv::OpTypePointer:
116 case spv::OpTypeFunction:
117 case spv::OpTypeEvent:
118 case spv::OpTypeDeviceEvent:
119 case spv::OpTypeReserveId:
120 case spv::OpTypeQueue:
121 case spv::OpTypePipe:
122 type_def_index[code[word+1]] = word;
123 break;
124
125 default:
126 /* We only care about type definitions */
127 break;
128 }
129
130 word += oplen;
131 }
132}
133
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -0600134struct shader_module {
Chris Forbes1bb5a2e2015-04-10 11:41:20 +1200135 /* the spirv image itself */
Chris Forbes4396ff52015-04-08 10:11:59 +1200136 std::vector<uint32_t> words;
Chris Forbes1bb5a2e2015-04-10 11:41:20 +1200137 /* a mapping of <id> to the first word of its def. this is useful because walking type
138 * trees requires jumping all over the instruction stream.
139 */
140 std::unordered_map<unsigned, unsigned> type_def_index;
Chris Forbes4453c772015-06-05 15:01:08 +1200141 bool is_spirv;
Chris Forbes4396ff52015-04-08 10:11:59 +1200142
Chris Forbese20111c2015-07-03 13:50:24 +1200143 shader_module(VkDevice dev, VkShaderModuleCreateInfo const *pCreateInfo) :
Chris Forbes4453c772015-06-05 15:01:08 +1200144 words((uint32_t *)pCreateInfo->pCode, (uint32_t *)pCreateInfo->pCode + pCreateInfo->codeSize / sizeof(uint32_t)),
145 type_def_index(),
146 is_spirv(true) {
147
148 if (words.size() < 5 || words[0] != spv::MagicNumber || words[1] != spv::Version) {
Chris Forbes2b7c0002015-07-10 09:06:54 +1200149 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 +1200150 "Shader is not SPIR-V, most checks will not be possible");
Chris Forbes4453c772015-06-05 15:01:08 +1200151 is_spirv = false;
152 return;
153 }
154
Chris Forbes1bb5a2e2015-04-10 11:41:20 +1200155
156 build_type_def_index(words, type_def_index);
Chris Forbes4396ff52015-04-08 10:11:59 +1200157 }
158};
159
160
Chris Forbes2b7c0002015-07-10 09:06:54 +1200161static std::unordered_map<uint64_t, shader_module *> shader_module_map;
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -0600162
163struct shader_object {
164 std::string name;
165 struct shader_module *module;
166
167 shader_object(VkShaderCreateInfo const *pCreateInfo)
168 {
Chris Forbes2b7c0002015-07-10 09:06:54 +1200169 module = shader_module_map[pCreateInfo->module.handle];
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -0600170 name = pCreateInfo->pName;
171 }
172};
Chris Forbes2b7c0002015-07-10 09:06:54 +1200173static std::unordered_map<uint64_t, shader_object *> shader_object_map;
Chris Forbes4396ff52015-04-08 10:11:59 +1200174
Chia-I Wuc278df82015-07-07 11:50:03 +0800175struct render_pass {
176 std::vector<std::vector<VkFormat>> subpass_color_formats;
177
178 render_pass(VkRenderPassCreateInfo const *pCreateInfo)
179 {
180 uint32_t i;
181
182 subpass_color_formats.reserve(pCreateInfo->subpassCount);
183 for (i = 0; i < pCreateInfo->subpassCount; i++) {
184 const VkSubpassDescription *subpass = &pCreateInfo->pSubpasses[i];
185 std::vector<VkFormat> color_formats;
186 uint32_t j;
187
188 color_formats.reserve(subpass->colorCount);
189 for (j = 0; j < subpass->colorCount; j++) {
Cody Northrop6de6b0b2015-08-04 11:16:41 -0600190 const uint32_t att = subpass->pColorAttachments[j].attachment;
Chia-I Wuc278df82015-07-07 11:50:03 +0800191 const VkFormat format = pCreateInfo->pAttachments[att].format;
192
193 color_formats.push_back(pCreateInfo->pAttachments[att].format);
194 }
195
196 subpass_color_formats.push_back(color_formats);
197 }
198 }
199};
Chris Forbes2b7c0002015-07-10 09:06:54 +1200200static std::unordered_map<uint64_t, render_pass *> render_pass_map;
Chia-I Wuc278df82015-07-07 11:50:03 +0800201
Chris Forbes4396ff52015-04-08 10:11:59 +1200202
Chris Forbes1b466bd2015-04-15 06:59:41 +1200203static void
Chris Forbese20111c2015-07-03 13:50:24 +1200204init_shader_checker(layer_data *my_data)
Chris Forbes1b466bd2015-04-15 06:59:41 +1200205{
Chris Forbese20111c2015-07-03 13:50:24 +1200206 uint32_t report_flags = 0;
207 uint32_t debug_action = 0;
208 FILE *log_output = NULL;
209 const char *option_str;
Chris Forbes1b466bd2015-04-15 06:59:41 +1200210 // initialize ShaderChecker options
Chris Forbese20111c2015-07-03 13:50:24 +1200211 report_flags = getLayerOptionFlags("ShaderCheckerReportFlags", 0);
212 getLayerOptionEnum("ShaderCheckerDebugAction", (uint32_t *) &debug_action);
Chris Forbes1b466bd2015-04-15 06:59:41 +1200213
Chris Forbese20111c2015-07-03 13:50:24 +1200214 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
Chris Forbes1b466bd2015-04-15 06:59:41 +1200215 {
Chris Forbese20111c2015-07-03 13:50:24 +1200216 option_str = getLayerOption("ShaderCheckerLogFilename");
217 if (option_str)
Chris Forbes1b466bd2015-04-15 06:59:41 +1200218 {
Chris Forbese20111c2015-07-03 13:50:24 +1200219 log_output = fopen(option_str, "w");
Chris Forbes1b466bd2015-04-15 06:59:41 +1200220 }
Chris Forbese20111c2015-07-03 13:50:24 +1200221 if (log_output == NULL)
222 log_output = stdout;
223
224 layer_create_msg_callback(my_data->report_data, report_flags, log_callback, (void *) log_output, &my_data->logging_callback);
225 }
226
227 if (!globalLockInitialized)
228 {
229 // TODO/TBD: Need to delete this mutex sometime. How??? One
230 // suggestion is to call this during vkCreateInstance(), and then we
231 // can clean it up during vkDestroyInstance(). However, that requires
232 // that the layer have per-instance locks. We need to come back and
233 // address this soon.
234 loader_platform_thread_create_mutex(&globalLock);
235 globalLockInitialized = 1;
Chris Forbes1b466bd2015-04-15 06:59:41 +1200236 }
237}
238
Courtney Goeltzenleuchter7abf8e52015-07-07 10:05:05 -0600239static const VkLayerProperties shader_checker_global_layers[] = {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600240 {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600241 "ShaderChecker",
Courtney Goeltzenleuchter7abf8e52015-07-07 10:05:05 -0600242 VK_API_VERSION,
243 VK_MAKE_VERSION(0, 1, 0),
244 "Validation layer: ShaderChecker",
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600245 }
Chris Forbesaab9d112015-04-02 13:22:31 +1300246};
247
Tony Barbour426b9052015-06-24 16:06:58 -0600248VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionProperties(
Courtney Goeltzenleuchter7abf8e52015-07-07 10:05:05 -0600249 const char *pLayerName,
250 uint32_t *pCount,
251 VkExtensionProperties* pProperties)
Chris Forbesaab9d112015-04-02 13:22:31 +1300252{
Courtney Goeltzenleuchter7abf8e52015-07-07 10:05:05 -0600253 /* shader checker does not have any global extensions */
254 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
Chris Forbesaab9d112015-04-02 13:22:31 +1300255}
256
Courtney Goeltzenleuchter7abf8e52015-07-07 10:05:05 -0600257VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalLayerProperties(
258 uint32_t *pCount,
259 VkLayerProperties* pProperties)
Tony Barbour426b9052015-06-24 16:06:58 -0600260{
Courtney Goeltzenleuchter7abf8e52015-07-07 10:05:05 -0600261 return util_GetLayerProperties(ARRAY_SIZE(shader_checker_global_layers),
262 shader_checker_global_layers,
263 pCount, pProperties);
Tony Barbour426b9052015-06-24 16:06:58 -0600264}
265
266VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceExtensionProperties(
Courtney Goeltzenleuchter7abf8e52015-07-07 10:05:05 -0600267 VkPhysicalDevice physicalDevice,
268 const char* pLayerName,
269 uint32_t* pCount,
270 VkExtensionProperties* pProperties)
Jon Ashburnade3bee2015-06-10 16:43:31 -0600271{
Courtney Goeltzenleuchter7abf8e52015-07-07 10:05:05 -0600272 /* Shader checker does not have any physical device extensions */
273 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
274}
Jon Ashburnade3bee2015-06-10 16:43:31 -0600275
Courtney Goeltzenleuchter7abf8e52015-07-07 10:05:05 -0600276VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceLayerProperties(
277 VkPhysicalDevice physicalDevice,
278 uint32_t* pCount,
279 VkLayerProperties* pProperties)
280{
281 /* Shader checker physical device layers are the same as global */
282 return util_GetLayerProperties(ARRAY_SIZE(shader_checker_global_layers),
283 shader_checker_global_layers,
284 pCount, pProperties);
Jon Ashburnade3bee2015-06-10 16:43:31 -0600285}
Chris Forbesaab9d112015-04-02 13:22:31 +1300286
Chris Forbes1bb5a2e2015-04-10 11:41:20 +1200287static char const *
288storage_class_name(unsigned sc)
289{
290 switch (sc) {
Cody Northrop812b4612015-04-20 14:09:40 -0600291 case spv::StorageClassInput: return "input";
292 case spv::StorageClassOutput: return "output";
293 case spv::StorageClassUniformConstant: return "const uniform";
294 case spv::StorageClassUniform: return "uniform";
295 case spv::StorageClassWorkgroupLocal: return "workgroup local";
296 case spv::StorageClassWorkgroupGlobal: return "workgroup global";
297 case spv::StorageClassPrivateGlobal: return "private global";
298 case spv::StorageClassFunction: return "function";
299 case spv::StorageClassGeneric: return "generic";
Cody Northrop812b4612015-04-20 14:09:40 -0600300 case spv::StorageClassAtomicCounter: return "atomic counter";
GregF3aaa0882015-07-21 17:22:50 -0600301 case spv::StorageClassImage: return "image";
Chris Forbes1bb5a2e2015-04-10 11:41:20 +1200302 default: return "unknown";
303 }
304}
305
306
307/* returns ptr to null terminator */
308static char *
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -0600309describe_type(char *dst, shader_module const *src, unsigned type)
Chris Forbes1bb5a2e2015-04-10 11:41:20 +1200310{
311 auto type_def_it = src->type_def_index.find(type);
312
313 if (type_def_it == src->type_def_index.end()) {
314 return dst + sprintf(dst, "undef");
315 }
316
317 unsigned int const *code = (unsigned int const *)&src->words[type_def_it->second];
318 unsigned opcode = code[0] & 0x0ffffu;
319 switch (opcode) {
320 case spv::OpTypeBool:
321 return dst + sprintf(dst, "bool");
322 case spv::OpTypeInt:
323 return dst + sprintf(dst, "%cint%d", code[3] ? 's' : 'u', code[2]);
324 case spv::OpTypeFloat:
325 return dst + sprintf(dst, "float%d", code[2]);
326 case spv::OpTypeVector:
327 dst += sprintf(dst, "vec%d of ", code[3]);
328 return describe_type(dst, src, code[2]);
329 case spv::OpTypeMatrix:
330 dst += sprintf(dst, "mat%d of ", code[3]);
331 return describe_type(dst, src, code[2]);
332 case spv::OpTypeArray:
333 dst += sprintf(dst, "arr[%d] of ", code[3]);
334 return describe_type(dst, src, code[2]);
335 case spv::OpTypePointer:
336 dst += sprintf(dst, "ptr to %s ", storage_class_name(code[2]));
337 return describe_type(dst, src, code[3]);
338 case spv::OpTypeStruct:
339 {
340 unsigned oplen = code[0] >> 16;
341 dst += sprintf(dst, "struct of (");
Ian Elliottf21f14b2015-04-17 11:05:04 -0600342 for (unsigned i = 2; i < oplen; i++) {
Chris Forbes1bb5a2e2015-04-10 11:41:20 +1200343 dst = describe_type(dst, src, code[i]);
344 dst += sprintf(dst, i == oplen-1 ? ")" : ", ");
345 }
346 return dst;
347 }
348 default:
349 return dst + sprintf(dst, "oddtype");
350 }
351}
352
353
354static bool
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -0600355types_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 +1200356{
357 auto a_type_def_it = a->type_def_index.find(a_type);
358 auto b_type_def_it = b->type_def_index.find(b_type);
359
360 if (a_type_def_it == a->type_def_index.end()) {
Chris Forbes1bb5a2e2015-04-10 11:41:20 +1200361 return false;
362 }
363
364 if (b_type_def_it == b->type_def_index.end()) {
Chris Forbes1bb5a2e2015-04-10 11:41:20 +1200365 return false;
366 }
367
368 /* walk two type trees together, and complain about differences */
369 unsigned int const *a_code = (unsigned int const *)&a->words[a_type_def_it->second];
370 unsigned int const *b_code = (unsigned int const *)&b->words[b_type_def_it->second];
371
372 unsigned a_opcode = a_code[0] & 0x0ffffu;
373 unsigned b_opcode = b_code[0] & 0x0ffffu;
374
Chris Forbes0a94a372015-06-05 14:57:05 +1200375 if (b_arrayed && b_opcode == spv::OpTypeArray) {
376 /* we probably just found the extra level of arrayness in b_type: compare the type inside it to a_type */
377 return types_match(a, b, a_type, b_code[2], false);
378 }
379
Chris Forbes1bb5a2e2015-04-10 11:41:20 +1200380 if (a_opcode != b_opcode) {
Chris Forbes1bb5a2e2015-04-10 11:41:20 +1200381 return false;
382 }
383
384 switch (a_opcode) {
Chris Forbes0a94a372015-06-05 14:57:05 +1200385 /* 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 +1200386 case spv::OpTypeBool:
Chris Forbes0a94a372015-06-05 14:57:05 +1200387 return true && !b_arrayed;
Chris Forbes1bb5a2e2015-04-10 11:41:20 +1200388 case spv::OpTypeInt:
389 /* match on width, signedness */
Chris Forbes0a94a372015-06-05 14:57:05 +1200390 return a_code[2] == b_code[2] && a_code[3] == b_code[3] && !b_arrayed;
Chris Forbes1bb5a2e2015-04-10 11:41:20 +1200391 case spv::OpTypeFloat:
392 /* match on width */
Chris Forbes0a94a372015-06-05 14:57:05 +1200393 return a_code[2] == b_code[2] && !b_arrayed;
Chris Forbes1bb5a2e2015-04-10 11:41:20 +1200394 case spv::OpTypeVector:
395 case spv::OpTypeMatrix:
396 case spv::OpTypeArray:
Chris Forbes0a94a372015-06-05 14:57:05 +1200397 /* match on element type, count. these all have the same layout. we don't get here if
398 * b_arrayed -- that is handled above. */
399 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 +1200400 case spv::OpTypeStruct:
401 /* match on all element types */
402 {
Chris Forbes0a94a372015-06-05 14:57:05 +1200403 if (b_arrayed) {
404 /* for the purposes of matching different levels of arrayness, structs are leaves. */
405 return false;
406 }
407
Chris Forbes1bb5a2e2015-04-10 11:41:20 +1200408 unsigned a_len = a_code[0] >> 16;
409 unsigned b_len = b_code[0] >> 16;
410
411 if (a_len != b_len) {
412 return false; /* structs cannot match if member counts differ */
413 }
414
Ian Elliottf21f14b2015-04-17 11:05:04 -0600415 for (unsigned i = 2; i < a_len; i++) {
Chris Forbes0a94a372015-06-05 14:57:05 +1200416 if (!types_match(a, b, a_code[i], b_code[i], b_arrayed)) {
Chris Forbes1bb5a2e2015-04-10 11:41:20 +1200417 return false;
418 }
419 }
420
421 return true;
422 }
423 case spv::OpTypePointer:
424 /* match on pointee type. storage class is expected to differ */
Chris Forbes0a94a372015-06-05 14:57:05 +1200425 return types_match(a, b, a_code[3], b_code[3], b_arrayed);
Chris Forbes1bb5a2e2015-04-10 11:41:20 +1200426
427 default:
428 /* remaining types are CLisms, or may not appear in the interfaces we
429 * are interested in. Just claim no match.
430 */
431 return false;
432
433 }
434}
435
436
Chris Forbes67cc36f2015-04-13 12:14:52 +1200437static int
438value_or_default(std::unordered_map<unsigned, unsigned> const &map, unsigned id, int def)
439{
440 auto it = map.find(id);
441 if (it == map.end())
442 return def;
443 else
444 return it->second;
445}
446
447
448struct interface_var {
449 uint32_t id;
450 uint32_t type_id;
451 /* TODO: collect the name, too? Isn't required to be present. */
452};
453
454
455static void
Chris Forbese20111c2015-07-03 13:50:24 +1200456collect_interface_by_location(VkDevice dev,
457 shader_module const *src, spv::StorageClass sinterface,
Chris Forbes67cc36f2015-04-13 12:14:52 +1200458 std::map<uint32_t, interface_var> &out,
459 std::map<uint32_t, interface_var> &builtins_out)
460{
461 unsigned int const *code = (unsigned int const *)&src->words[0];
462 size_t size = src->words.size();
463
Chris Forbes67cc36f2015-04-13 12:14:52 +1200464 std::unordered_map<unsigned, unsigned> var_locations;
465 std::unordered_map<unsigned, unsigned> var_builtins;
466
467 unsigned word = 5;
468 while (word < size) {
469
470 unsigned opcode = code[word] & 0x0ffffu;
471 unsigned oplen = (code[word] & 0xffff0000u) >> 16;
472
473 /* We consider two interface models: SSO rendezvous-by-location, and
474 * builtins. Complain about anything that fits neither model.
475 */
476 if (opcode == spv::OpDecorate) {
Cody Northrop812b4612015-04-20 14:09:40 -0600477 if (code[word+2] == spv::DecorationLocation) {
Chris Forbes67cc36f2015-04-13 12:14:52 +1200478 var_locations[code[word+1]] = code[word+3];
479 }
480
Cody Northrop812b4612015-04-20 14:09:40 -0600481 if (code[word+2] == spv::DecorationBuiltIn) {
Chris Forbes67cc36f2015-04-13 12:14:52 +1200482 var_builtins[code[word+1]] = code[word+3];
483 }
484 }
485
486 /* TODO: handle grouped decorations */
487 /* TODO: handle index=1 dual source outputs from FS -- two vars will
488 * have the same location, and we DONT want to clobber. */
489
Ian Elliottf21f14b2015-04-17 11:05:04 -0600490 if (opcode == spv::OpVariable && code[word+3] == sinterface) {
Chris Forbes67cc36f2015-04-13 12:14:52 +1200491 int location = value_or_default(var_locations, code[word+2], -1);
492 int builtin = value_or_default(var_builtins, code[word+2], -1);
493
494 if (location == -1 && builtin == -1) {
495 /* No location defined, and not bound to an API builtin.
496 * The spec says nothing about how this case works (or doesn't)
497 * for interface matching.
498 */
Chris Forbes2b7c0002015-07-10 09:06:54 +1200499 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 +1200500 "var %d (type %d) in %s interface has no Location or Builtin decoration",
501 code[word+2], code[word+1], storage_class_name(sinterface));
Chris Forbes67cc36f2015-04-13 12:14:52 +1200502 }
503 else if (location != -1) {
504 /* A user-defined interface variable, with a location. */
505 interface_var v;
506 v.id = code[word+2];
507 v.type_id = code[word+1];
508 out[location] = v;
509 }
510 else {
511 /* A builtin interface variable */
512 interface_var v;
513 v.id = code[word+2];
514 v.type_id = code[word+1];
515 builtins_out[builtin] = v;
516 }
517 }
518
519 word += oplen;
520 }
521}
522
523
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -0600524VK_LAYER_EXPORT VkResult VKAPI vkCreateShaderModule(
525 VkDevice device,
526 const VkShaderModuleCreateInfo *pCreateInfo,
527 VkShaderModule *pShaderModule)
Chris Forbesaab9d112015-04-02 13:22:31 +1300528{
Chris Forbes1ed0f982015-05-29 14:55:18 +1200529 loader_platform_thread_lock_mutex(&globalLock);
Chris Forbese20111c2015-07-03 13:50:24 +1200530 VkResult res = get_dispatch_table(shader_checker_device_table_map, device)->CreateShaderModule(device, pCreateInfo, pShaderModule);
Chris Forbes4396ff52015-04-08 10:11:59 +1200531
Chris Forbes2b7c0002015-07-10 09:06:54 +1200532 shader_module_map[pShaderModule->handle] = new shader_module(device, pCreateInfo);
Chris Forbes1ed0f982015-05-29 14:55:18 +1200533 loader_platform_thread_unlock_mutex(&globalLock);
Chris Forbesaab9d112015-04-02 13:22:31 +1300534 return res;
535}
536
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -0600537VK_LAYER_EXPORT VkResult VKAPI vkCreateShader(
538 VkDevice device,
539 const VkShaderCreateInfo *pCreateInfo,
540 VkShader *pShader)
541{
542 loader_platform_thread_lock_mutex(&globalLock);
Chris Forbese20111c2015-07-03 13:50:24 +1200543 VkResult res = get_dispatch_table(shader_checker_device_table_map, device)->CreateShader(device, pCreateInfo, pShader);
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -0600544
Chris Forbes2b7c0002015-07-10 09:06:54 +1200545 shader_object_map[pShader->handle] = new shader_object(pCreateInfo);
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -0600546 loader_platform_thread_unlock_mutex(&globalLock);
547 return res;
548}
Chris Forbesaab9d112015-04-02 13:22:31 +1300549
Chia-I Wuc278df82015-07-07 11:50:03 +0800550VK_LAYER_EXPORT VkResult VKAPI vkCreateRenderPass(
551 VkDevice device,
552 const VkRenderPassCreateInfo *pCreateInfo,
553 VkRenderPass *pRenderPass)
554{
555 loader_platform_thread_lock_mutex(&globalLock);
556 VkResult res = get_dispatch_table(shader_checker_device_table_map, device)->CreateRenderPass(device, pCreateInfo, pRenderPass);
557
Chris Forbes2b7c0002015-07-10 09:06:54 +1200558 render_pass_map[pRenderPass->handle] = new render_pass(pCreateInfo);
Chia-I Wuc278df82015-07-07 11:50:03 +0800559 loader_platform_thread_unlock_mutex(&globalLock);
560 return res;
561}
562
Chris Forbes5f362d02015-05-25 11:13:22 +1200563static bool
Chris Forbese20111c2015-07-03 13:50:24 +1200564validate_interface_between_stages(VkDevice dev,
565 shader_module const *producer, char const *producer_name,
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -0600566 shader_module const *consumer, char const *consumer_name,
Chris Forbes4453c772015-06-05 15:01:08 +1200567 bool consumer_arrayed_input)
Chris Forbesbb164b62015-04-08 10:19:16 +1200568{
569 std::map<uint32_t, interface_var> outputs;
570 std::map<uint32_t, interface_var> inputs;
571
572 std::map<uint32_t, interface_var> builtin_outputs;
573 std::map<uint32_t, interface_var> builtin_inputs;
574
Chris Forbes5f362d02015-05-25 11:13:22 +1200575 bool pass = true;
Chris Forbesbb164b62015-04-08 10:19:16 +1200576
Chris Forbese20111c2015-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 Forbesbb164b62015-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 Pinedof5997ab2015-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 Forbes4cb97672015-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 Pinedof5997ab2015-04-27 16:36:17 -0600589
590 if (b_at_end || a_first < b_first) {
Chris Forbes2b7c0002015-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 Forbese20111c2015-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 Forbesbb164b62015-04-08 10:19:16 +1200593 a_it++;
594 }
David Pinedof5997ab2015-04-27 16:36:17 -0600595 else if (a_at_end || a_first > b_first) {
Chris Forbes2b7c0002015-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 Forbese20111c2015-07-03 13:50:24 +1200597 "%s consumes input location %d which is not written by %s", consumer_name, b_first, producer_name);
Chris Forbes5f362d02015-05-25 11:13:22 +1200598 pass = false;
Chris Forbesbb164b62015-04-08 10:19:16 +1200599 b_it++;
600 }
601 else {
Chris Forbes4453c772015-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 Forbes5c75afe2015-04-17 10:13:28 +1200603 /* OK! */
Chris Forbes1bb5a2e2015-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 Forbes2b7c0002015-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 Forbese20111c2015-07-03 13:50:24 +1200612 "Type mismatch on location %d: '%s' vs '%s'", a_it->first, producer_type, consumer_type);
Chris Forbes5f362d02015-05-25 11:13:22 +1200613 pass = false;
Chris Forbes1bb5a2e2015-04-10 11:41:20 +1200614 }
Chris Forbesbb164b62015-04-08 10:19:16 +1200615 a_it++;
616 b_it++;
617 }
618 }
Chris Forbes5f362d02015-05-25 11:13:22 +1200619
620 return pass;
Chris Forbesbb164b62015-04-08 10:19:16 +1200621}
622
623
Chris Forbes9b9f5fe2015-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 Wu6097f3a2015-04-17 02:00:54 +0800635 case VK_FORMAT_UNDEFINED:
Chris Forbes9b9f5fe2015-04-08 10:37:20 +1200636 return FORMAT_TYPE_UNDEFINED;
Chia-I Wu6097f3a2015-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 Forbes9b9f5fe2015-04-08 10:37:20 +1200653 return FORMAT_TYPE_SINT;
Chia-I Wu6097f3a2015-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 Forbes9b9f5fe2015-04-08 10:37:20 +1200670 return FORMAT_TYPE_UINT;
671 default:
672 return FORMAT_TYPE_FLOAT;
673 }
674}
675
676
Chris Forbes28c50882015-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 Goeltzenleuchter2d034fd2015-06-28 13:01:17 -0600680get_fundamental_type(shader_module const *src, unsigned type)
Chris Forbes28c50882015-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 Forbes5f362d02015-05-25 11:13:22 +1200709static bool
Chris Forbese20111c2015-07-03 13:50:24 +1200710validate_vi_consistency(VkDevice dev, VkPipelineVertexInputStateCreateInfo const *vi)
Chris Forbes0bf8fe12015-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 Forbes0bf8fe12015-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 Forbes2b7c0002015-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 Forbese20111c2015-07-03 13:50:24 +1200723 "Duplicate vertex input binding descriptions for binding %d", desc->binding);
Chris Forbes0bf8fe12015-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 Forbese20111c2015-07-03 13:50:24 +1200736validate_vi_against_vs_inputs(VkDevice dev, VkPipelineVertexInputStateCreateInfo const *vi, shader_module const *vs)
Chris Forbesfcd05f12015-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 Forbes5f362d02015-05-25 11:13:22 +1200743 bool pass = true;
Chris Forbesfcd05f12015-04-08 10:36:37 +1200744
Chris Forbese20111c2015-07-03 13:50:24 +1200745 collect_interface_by_location(dev, vs, spv::StorageClassInput, inputs, builtin_inputs);
Chris Forbesfcd05f12015-04-08 10:36:37 +1200746
747 /* Build index by location */
748 std::map<uint32_t, VkVertexInputAttributeDescription const *> attribs;
Chris Forbes6f2ab982015-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 Forbesfcd05f12015-04-08 10:36:37 +1200753
754 auto it_a = attribs.begin();
755 auto it_b = inputs.begin();
756
David Pinedof5997ab2015-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 Forbes4cb97672015-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 Pinedof5997ab2015-04-27 16:36:17 -0600762 if (b_at_end || a_first < b_first) {
Chris Forbes2b7c0002015-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 Forbese20111c2015-07-03 13:50:24 +1200764 "Vertex attribute at location %d not consumed by VS", a_first);
Chris Forbesfcd05f12015-04-08 10:36:37 +1200765 it_a++;
766 }
David Pinedof5997ab2015-04-27 16:36:17 -0600767 else if (a_at_end || b_first < a_first) {
Chris Forbes2b7c0002015-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 Forbese20111c2015-07-03 13:50:24 +1200769 "VS consumes input at location %d but not provided", b_first);
Chris Forbes5f362d02015-05-25 11:13:22 +1200770 pass = false;
Chris Forbesfcd05f12015-04-08 10:36:37 +1200771 it_b++;
772 }
773 else {
Chris Forbes3317b382015-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 Forbes2b7c0002015-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 Forbese20111c2015-07-03 13:50:24 +1200782 "Attribute type of `%s` at location %d does not match VS input type of `%s`",
Chris Forbes3317b382015-05-04 14:04:24 +1200783 string_VkFormat(it_a->second->format), a_first, vs_type);
Chris Forbes5f362d02015-05-25 11:13:22 +1200784 pass = false;
Chris Forbes3317b382015-05-04 14:04:24 +1200785 }
786
Chris Forbes5c75afe2015-04-17 10:13:28 +1200787 /* OK! */
Chris Forbesfcd05f12015-04-08 10:36:37 +1200788 it_a++;
789 it_b++;
790 }
791 }
Chris Forbes5f362d02015-05-25 11:13:22 +1200792
793 return pass;
Chris Forbesfcd05f12015-04-08 10:36:37 +1200794}
795
796
Chris Forbes5f362d02015-05-25 11:13:22 +1200797static bool
Chia-I Wuc278df82015-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 Forbes9b9f5fe2015-04-08 10:37:20 +1200799{
Chia-I Wuc278df82015-07-07 11:50:03 +0800800 const std::vector<VkFormat> &color_formats = rp->subpass_color_formats[subpass];
Chris Forbes9b9f5fe2015-04-08 10:37:20 +1200801 std::map<uint32_t, interface_var> outputs;
802 std::map<uint32_t, interface_var> builtin_outputs;
Chris Forbes5f362d02015-05-25 11:13:22 +1200803 bool pass = true;
Chris Forbes9b9f5fe2015-04-08 10:37:20 +1200804
805 /* TODO: dual source blend index (spv::DecIndex, zero if not provided) */
806
Chris Forbese20111c2015-07-03 13:50:24 +1200807 collect_interface_by_location(dev, fs, spv::StorageClassOutput, outputs, builtin_outputs);
Chris Forbes9b9f5fe2015-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 Forbes9b9f5fe2015-04-08 10:37:20 +1200813 if (outputs.size()) {
Chris Forbes2b7c0002015-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 Forbese20111c2015-07-03 13:50:24 +1200815 "Should not have user-defined FS outputs when using broadcast");
Chris Forbes5f362d02015-05-25 11:13:22 +1200816 pass = false;
Chris Forbes9b9f5fe2015-04-08 10:37:20 +1200817 }
818
Chia-I Wuc278df82015-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 Forbes9b9f5fe2015-04-08 10:37:20 +1200821 if (attachmentType == FORMAT_TYPE_SINT || attachmentType == FORMAT_TYPE_UINT) {
Chris Forbes2b7c0002015-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 Forbese20111c2015-07-03 13:50:24 +1200823 "CB format should not be SINT or UINT when using broadcast");
Chris Forbes5f362d02015-05-25 11:13:22 +1200824 pass = false;
Chris Forbes9b9f5fe2015-04-08 10:37:20 +1200825 }
826 }
827
Chris Forbes5f362d02015-05-25 11:13:22 +1200828 return pass;
Chris Forbes9b9f5fe2015-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 Forbes2b7c0002015-07-10 09:06:54 +1200838 /* TODO: Figure out compile error with cb->attachmentCount */
Chris Forbes768eead2015-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 Forbes2b7c0002015-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 Forbese20111c2015-07-03 13:50:24 +1200842 "FS writes to output location %d with no matching attachment", it->first);
Chris Forbes9b9f5fe2015-04-08 10:37:20 +1200843 it++;
844 }
845 else if (it == outputs.end() || it->first > attachment) {
Chris Forbes2b7c0002015-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 Forbese20111c2015-07-03 13:50:24 +1200847 "Attachment %d not written by FS", attachment);
Chris Forbes9b9f5fe2015-04-08 10:37:20 +1200848 attachment++;
Chris Forbes5f362d02015-05-25 11:13:22 +1200849 pass = false;
Chris Forbes9b9f5fe2015-04-08 10:37:20 +1200850 }
851 else {
Chris Forbes4b009002015-05-04 14:20:10 +1200852 unsigned output_type = get_fundamental_type(fs, it->second.type_id);
Chia-I Wuc278df82015-07-07 11:50:03 +0800853 unsigned att_type = get_format_type(color_formats[attachment]);
Chris Forbes4b009002015-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 Forbes2b7c0002015-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 Forbese20111c2015-07-03 13:50:24 +1200860 "Attachment %d of type `%s` does not match FS output type of `%s`",
Chia-I Wuc278df82015-07-07 11:50:03 +0800861 attachment, string_VkFormat(color_formats[attachment]), fs_type);
Chris Forbes5f362d02015-05-25 11:13:22 +1200862 pass = false;
Chris Forbes4b009002015-05-04 14:20:10 +1200863 }
864
Chris Forbes5c75afe2015-04-17 10:13:28 +1200865 /* OK! */
Chris Forbes9b9f5fe2015-04-08 10:37:20 +1200866 it++;
867 attachment++;
868 }
869 }
Chris Forbes5f362d02015-05-25 11:13:22 +1200870
871 return pass;
Chris Forbes9b9f5fe2015-04-08 10:37:20 +1200872}
873
874
Chris Forbes4453c772015-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
Chris Forbesf1060ca2015-06-04 20:23:00 +1200891static bool
Chris Forbesd8bde292015-07-24 13:53:47 +1200892validate_graphics_pipeline(VkDevice dev, VkGraphicsPipelineCreateInfo const *pCreateInfo)
Chris Forbes60540932015-04-08 10:15:35 +1200893{
Chris Forbes8f600932015-04-08 10:16:45 +1200894 /* We seem to allow pipeline stages to be specified out of order, so collect and identify them
895 * before trying to do anything more: */
896
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -0600897 shader_module const *shaders[VK_SHADER_STAGE_FRAGMENT + 1]; /* exclude CS */
Chris Forbes4453c772015-06-05 15:01:08 +1200898 memset(shaders, 0, sizeof(shaders));
Chia-I Wuc278df82015-07-07 11:50:03 +0800899 render_pass const *rp = 0;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600900 VkPipelineVertexInputStateCreateInfo const *vi = 0;
Chris Forbes5f362d02015-05-25 11:13:22 +1200901 bool pass = true;
Chris Forbes8f600932015-04-08 10:16:45 +1200902
Chris Forbes1ed0f982015-05-29 14:55:18 +1200903 loader_platform_thread_lock_mutex(&globalLock);
904
Tony Barbourb2cc40a2015-07-13 15:28:47 -0600905 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600906 VkPipelineShaderStageCreateInfo const *pStage = &pCreateInfo->pStages[i];
907 if (pStage->sType == VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO) {
Chris Forbes8f600932015-04-08 10:16:45 +1200908
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600909 if (pStage->stage < VK_SHADER_STAGE_VERTEX || pStage->stage > VK_SHADER_STAGE_FRAGMENT) {
Chris Forbes2b7c0002015-07-10 09:06:54 +1200910 log_msg(mdd(dev), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_DEVICE, /*dev*/0, 0, SHADER_CHECKER_UNKNOWN_STAGE, "SC",
Chris Forbese20111c2015-07-03 13:50:24 +1200911 "Unknown shader stage %d", pStage->stage);
Chris Forbes5c75afe2015-04-17 10:13:28 +1200912 }
Chris Forbes4453c772015-06-05 15:01:08 +1200913 else {
Chris Forbes2b7c0002015-07-10 09:06:54 +1200914 struct shader_object *shader = shader_object_map[pStage->shader.handle];
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -0600915 shaders[pStage->stage] = shader->module;
Chris Forbes4453c772015-06-05 15:01:08 +1200916 }
Chris Forbes8f600932015-04-08 10:16:45 +1200917 }
Chris Forbes8f600932015-04-08 10:16:45 +1200918 }
919
Chia-I Wuc278df82015-07-07 11:50:03 +0800920 if (pCreateInfo->renderPass != VK_NULL_HANDLE)
Chris Forbes2b7c0002015-07-10 09:06:54 +1200921 rp = render_pass_map[pCreateInfo->renderPass.handle];
Chia-I Wuc278df82015-07-07 11:50:03 +0800922
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600923 vi = pCreateInfo->pVertexInputState;
924
Chris Forbes0bf8fe12015-06-12 11:16:41 +1200925 if (vi) {
Chris Forbese20111c2015-07-03 13:50:24 +1200926 pass = validate_vi_consistency(dev, vi) && pass;
Chris Forbes0bf8fe12015-06-12 11:16:41 +1200927 }
928
Chris Forbes4453c772015-06-05 15:01:08 +1200929 if (shaders[VK_SHADER_STAGE_VERTEX] && shaders[VK_SHADER_STAGE_VERTEX]->is_spirv) {
Chris Forbese20111c2015-07-03 13:50:24 +1200930 pass = validate_vi_against_vs_inputs(dev, vi, shaders[VK_SHADER_STAGE_VERTEX]) && pass;
Chris Forbesfcd05f12015-04-08 10:36:37 +1200931 }
932
Chris Forbes4453c772015-06-05 15:01:08 +1200933 /* TODO: enforce rules about present combinations of shaders */
934 int producer = VK_SHADER_STAGE_VERTEX;
935 int consumer = VK_SHADER_STAGE_GEOMETRY;
936
937 while (!shaders[producer] && producer != VK_SHADER_STAGE_FRAGMENT) {
938 producer++;
939 consumer++;
Chris Forbesbb164b62015-04-08 10:19:16 +1200940 }
941
Tony Barbour4eb3cd12015-06-11 15:04:25 -0600942 for (; producer != VK_SHADER_STAGE_FRAGMENT && consumer <= VK_SHADER_STAGE_FRAGMENT; consumer++) {
Chris Forbes4453c772015-06-05 15:01:08 +1200943 assert(shaders[producer]);
944 if (shaders[consumer]) {
945 if (shaders[producer]->is_spirv && shaders[consumer]->is_spirv) {
Chris Forbese20111c2015-07-03 13:50:24 +1200946 pass = validate_interface_between_stages(dev,
947 shaders[producer], shader_stage_attribs[producer].name,
Chris Forbes4453c772015-06-05 15:01:08 +1200948 shaders[consumer], shader_stage_attribs[consumer].name,
949 shader_stage_attribs[consumer].arrayed_input) && pass;
950 }
951
952 producer = consumer;
953 }
954 }
955
Chia-I Wuc278df82015-07-07 11:50:03 +0800956 if (shaders[VK_SHADER_STAGE_FRAGMENT] && shaders[VK_SHADER_STAGE_FRAGMENT]->is_spirv && rp) {
957 pass = validate_fs_outputs_against_render_pass(dev, shaders[VK_SHADER_STAGE_FRAGMENT], rp, pCreateInfo->subpass) && pass;
Chris Forbes9b9f5fe2015-04-08 10:37:20 +1200958 }
959
Chris Forbes1ed0f982015-05-29 14:55:18 +1200960 loader_platform_thread_unlock_mutex(&globalLock);
Chris Forbesf1060ca2015-06-04 20:23:00 +1200961 return pass;
962}
963
Jon Ashburn0d60d272015-07-09 15:02:25 -0600964//TODO handle pipelineCache entry points
Chris Forbesd0f7f7c2015-06-04 20:27:09 +1200965VK_LAYER_EXPORT VkResult VKAPI
Jon Ashburn0d60d272015-07-09 15:02:25 -0600966vkCreateGraphicsPipelines(VkDevice device,
967 VkPipelineCache pipelineCache,
968 uint32_t count,
969 const VkGraphicsPipelineCreateInfo *pCreateInfos,
970 VkPipeline *pPipelines)
Chris Forbesf1060ca2015-06-04 20:23:00 +1200971{
Chris Forbesd8bde292015-07-24 13:53:47 +1200972 bool pass = true;
973 for (uint32_t i = 0; i < count; i++) {
974 pass = validate_graphics_pipeline(device, &pCreateInfos[i]) && pass;
975 }
Chris Forbes5f362d02015-05-25 11:13:22 +1200976
977 if (pass) {
978 /* The driver is allowed to crash if passed junk. Only actually create the
979 * pipeline if we didn't run into any showstoppers above.
980 */
Jon Ashburn0d60d272015-07-09 15:02:25 -0600981 return get_dispatch_table(shader_checker_device_table_map, device)->CreateGraphicsPipelines(device, pipelineCache, count, pCreateInfos, pPipelines);
Chris Forbes5f362d02015-05-25 11:13:22 +1200982 }
983 else {
984 return VK_ERROR_UNKNOWN;
985 }
Chris Forbes60540932015-04-08 10:15:35 +1200986}
987
988
Chris Forbese20111c2015-07-03 13:50:24 +1200989VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
990{
991 VkLayerDispatchTable *pDeviceTable = get_dispatch_table(shader_checker_device_table_map, *pDevice);
992 VkResult result = pDeviceTable->CreateDevice(gpu, pCreateInfo, pDevice);
993 if (result == VK_SUCCESS) {
994 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
995 VkLayerDispatchTable *pTable = get_dispatch_table(shader_checker_device_table_map, *pDevice);
996 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
997 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
998 }
999 return result;
1000}
Chris Forbesd0f7f7c2015-06-04 20:27:09 +12001001
Jon Ashburn17f37372015-05-19 16:34:53 -06001002/* hook DextroyDevice to remove tableMap entry */
1003VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device)
1004{
Courtney Goeltzenleuchter9f171942015-06-13 21:22:12 -06001005 dispatch_key key = get_dispatch_key(device);
Chris Forbese20111c2015-07-03 13:50:24 +12001006 VkLayerDispatchTable *pDisp = get_dispatch_table(shader_checker_device_table_map, device);
1007 VkResult result = pDisp->DestroyDevice(device);
1008 shader_checker_device_table_map.erase(key);
1009 return result;
Jon Ashburn17f37372015-05-19 16:34:53 -06001010}
1011
Courtney Goeltzenleuchter6c813dc2015-06-01 14:46:33 -06001012VkResult VKAPI vkCreateInstance(
1013 const VkInstanceCreateInfo* pCreateInfo,
1014 VkInstance* pInstance)
1015{
Chris Forbese20111c2015-07-03 13:50:24 +12001016 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(shader_checker_instance_table_map,*pInstance);
Courtney Goeltzenleuchter6c813dc2015-06-01 14:46:33 -06001017 VkResult result = pTable->CreateInstance(pCreateInfo, pInstance);
1018
1019 if (result == VK_SUCCESS) {
Chris Forbese20111c2015-07-03 13:50:24 +12001020 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
1021 my_data->report_data = debug_report_create_instance(
1022 pTable,
1023 *pInstance,
1024 pCreateInfo->extensionCount,
1025 pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchterf4a2eba2015-06-08 14:58:39 -06001026
Chris Forbese20111c2015-07-03 13:50:24 +12001027 init_shader_checker(my_data);
Courtney Goeltzenleuchter6c813dc2015-06-01 14:46:33 -06001028 }
1029 return result;
1030}
1031
Jon Ashburn17f37372015-05-19 16:34:53 -06001032/* hook DestroyInstance to remove tableInstanceMap entry */
1033VK_LAYER_EXPORT VkResult VKAPI vkDestroyInstance(VkInstance instance)
1034{
Courtney Goeltzenleuchter9f171942015-06-13 21:22:12 -06001035 dispatch_key key = get_dispatch_key(instance);
Chris Forbese20111c2015-07-03 13:50:24 +12001036 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(shader_checker_instance_table_map, instance);
1037 VkResult res = pTable->DestroyInstance(instance);
1038
1039 // Clean up logging callback, if any
1040 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
1041 if (my_data->logging_callback) {
1042 layer_destroy_msg_callback(my_data->report_data, my_data->logging_callback);
1043 }
1044
1045 layer_debug_report_destroy_instance(my_data->report_data);
1046 layer_data_map.erase(pTable);
1047
1048 shader_checker_instance_table_map.erase(key);
Jon Ashburn17f37372015-05-19 16:34:53 -06001049 return res;
1050}
Chris Forbesb65ba352015-05-25 11:12:59 +12001051
Courtney Goeltzenleuchter6c813dc2015-06-01 14:46:33 -06001052VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
Chris Forbese20111c2015-07-03 13:50:24 +12001053 VkInstance instance,
1054 VkFlags msgFlags,
1055 const PFN_vkDbgMsgCallback pfnMsgCallback,
1056 void* pUserData,
1057 VkDbgMsgCallback* pMsgCallback)
Courtney Goeltzenleuchter6c813dc2015-06-01 14:46:33 -06001058{
Chris Forbese20111c2015-07-03 13:50:24 +12001059 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(shader_checker_instance_table_map, instance);
1060 VkResult res = pTable->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
1061 if (VK_SUCCESS == res) {
1062 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
1063 res = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
1064 }
1065 return res;
Courtney Goeltzenleuchter6c813dc2015-06-01 14:46:33 -06001066}
1067
1068VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
Chris Forbese20111c2015-07-03 13:50:24 +12001069 VkInstance instance,
1070 VkDbgMsgCallback msgCallback)
Courtney Goeltzenleuchter6c813dc2015-06-01 14:46:33 -06001071{
Chris Forbese20111c2015-07-03 13:50:24 +12001072 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(shader_checker_instance_table_map, instance);
1073 VkResult res = pTable->DbgDestroyMsgCallback(instance, msgCallback);
1074 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
1075 layer_destroy_msg_callback(my_data->report_data, msgCallback);
1076 return res;
Courtney Goeltzenleuchter6c813dc2015-06-01 14:46:33 -06001077}
1078
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06001079VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Chris Forbesaab9d112015-04-02 13:22:31 +13001080{
Chris Forbese20111c2015-07-03 13:50:24 +12001081 if (dev == NULL)
Chris Forbesaab9d112015-04-02 13:22:31 +13001082 return NULL;
1083
Jon Ashburn4f2575f2015-05-28 16:25:02 -06001084 /* loader uses this to force layer initialization; device object is wrapped */
Chris Forbese20111c2015-07-03 13:50:24 +12001085 if (!strcmp("vkGetDeviceProcAddr", funcName)) {
1086 initDeviceTable(shader_checker_device_table_map, (const VkBaseLayerObject *) dev);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06001087 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06001088 }
1089
Chris Forbesaab9d112015-04-02 13:22:31 +13001090#define ADD_HOOK(fn) \
Chris Forbese20111c2015-07-03 13:50:24 +12001091 if (!strncmp(#fn, funcName, sizeof(#fn))) \
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06001092 return (PFN_vkVoidFunction) fn
Chris Forbesaab9d112015-04-02 13:22:31 +13001093
Chris Forbese20111c2015-07-03 13:50:24 +12001094 ADD_HOOK(vkCreateDevice);
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001095 ADD_HOOK(vkCreateShaderModule);
Chris Forbesaab9d112015-04-02 13:22:31 +13001096 ADD_HOOK(vkCreateShader);
Chia-I Wuc278df82015-07-07 11:50:03 +08001097 ADD_HOOK(vkCreateRenderPass);
Jon Ashburn17f37372015-05-19 16:34:53 -06001098 ADD_HOOK(vkDestroyDevice);
Jon Ashburn0d60d272015-07-09 15:02:25 -06001099 ADD_HOOK(vkCreateGraphicsPipelines);
Jon Ashburn8198fd02015-05-18 09:08:41 -06001100#undef ADD_HOOK
Chris Forbese20111c2015-07-03 13:50:24 +12001101
1102 VkLayerDispatchTable* pTable = get_dispatch_table(shader_checker_device_table_map, dev);
1103 {
1104 if (pTable->GetDeviceProcAddr == NULL)
1105 return NULL;
1106 return pTable->GetDeviceProcAddr(dev, funcName);
1107 }
Jon Ashburn79b78ac2015-05-05 14:22:52 -06001108}
1109
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06001110VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06001111{
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06001112 PFN_vkVoidFunction fptr;
Courtney Goeltzenleuchter6c813dc2015-06-01 14:46:33 -06001113
Chris Forbese20111c2015-07-03 13:50:24 +12001114 if (instance == NULL)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06001115 return NULL;
1116
Chris Forbese20111c2015-07-03 13:50:24 +12001117 if (!strcmp("vkGetInstanceProcAddr", funcName)) {
1118 initInstanceTable(shader_checker_instance_table_map, (const VkBaseLayerObject *) instance);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06001119 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06001120 }
Jon Ashburn79b78ac2015-05-05 14:22:52 -06001121#define ADD_HOOK(fn) \
Chris Forbese20111c2015-07-03 13:50:24 +12001122 if (!strncmp(#fn, funcName, sizeof(#fn))) \
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06001123 return (PFN_vkVoidFunction) fn
Jon Ashburn79b78ac2015-05-05 14:22:52 -06001124
Courtney Goeltzenleuchter6c813dc2015-06-01 14:46:33 -06001125 ADD_HOOK(vkCreateInstance);
Jon Ashburn17f37372015-05-19 16:34:53 -06001126 ADD_HOOK(vkDestroyInstance);
Tony Barbour426b9052015-06-24 16:06:58 -06001127 ADD_HOOK(vkGetGlobalExtensionProperties);
Tony Barbour426b9052015-06-24 16:06:58 -06001128 ADD_HOOK(vkGetPhysicalDeviceExtensionProperties);
Courtney Goeltzenleuchter7abf8e52015-07-07 10:05:05 -06001129 ADD_HOOK(vkGetGlobalLayerProperties);
1130 ADD_HOOK(vkGetPhysicalDeviceLayerProperties);
Jon Ashburn8198fd02015-05-18 09:08:41 -06001131#undef ADD_HOOK
Jon Ashburn79b78ac2015-05-05 14:22:52 -06001132
Chris Forbese20111c2015-07-03 13:50:24 +12001133
1134 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
1135 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchter6c813dc2015-06-01 14:46:33 -06001136 if (fptr)
1137 return fptr;
1138
Chris Forbese20111c2015-07-03 13:50:24 +12001139 {
1140 VkLayerInstanceDispatchTable* pTable = get_dispatch_table(shader_checker_instance_table_map, instance);
1141 if (pTable->GetInstanceProcAddr == NULL)
1142 return NULL;
1143 return pTable->GetInstanceProcAddr(instance, funcName);
1144 }
Chris Forbesaab9d112015-04-02 13:22:31 +13001145}