blob: 40dad1b6173f2b88a0f972b3f748b08d731350c9 [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>
Chris Forbesaab9d112015-04-02 13:22:31 +130031#include "loader_platform.h"
32#include "vk_dispatch_table_helper.h"
33#include "vkLayer.h"
Chris Forbes1b466bd2015-04-15 06:59:41 +120034#include "layers_config.h"
35#include "layers_msg.h"
Chris Forbes3317b382015-05-04 14:04:24 +120036#include "vk_enum_string_helper.h"
Chris Forbes5c75afe2015-04-17 10:13:28 +120037#include "shader_checker.h"
Chris Forbesaab9d112015-04-02 13:22:31 +130038// The following is #included again to catch certain OS-specific functions
39// being used:
40#include "loader_platform.h"
41
Chris Forbes32e3b462015-05-09 10:31:21 +120042#include "spirv/spirv.h"
Chris Forbesaab9d112015-04-02 13:22:31 +130043
Chris Forbesaab9d112015-04-02 13:22:31 +130044
Chris Forbes1b466bd2015-04-15 06:59:41 +120045static std::unordered_map<void *, VkLayerDispatchTable *> tableMap;
Chris Forbes1ed0f982015-05-29 14:55:18 +120046static VkBaseLayerObject *pCurObj;
Chris Forbes1b466bd2015-04-15 06:59:41 +120047static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
Chris Forbes1ed0f982015-05-29 14:55:18 +120048// TODO : This can be much smarter, using separate locks for separate global data
49static int globalLockInitialized = 0;
50static loader_platform_thread_mutex globalLock;
Chris Forbes4396ff52015-04-08 10:11:59 +120051
Chris Forbes1bb5a2e2015-04-10 11:41:20 +120052
53static void
54build_type_def_index(std::vector<unsigned> const &words, std::unordered_map<unsigned, unsigned> &type_def_index)
55{
56 unsigned int const *code = (unsigned int const *)&words[0];
57 size_t size = words.size();
58
59 unsigned word = 5;
60 while (word < size) {
61 unsigned opcode = code[word] & 0x0ffffu;
62 unsigned oplen = (code[word] & 0xffff0000u) >> 16;
63
64 switch (opcode) {
65 case spv::OpTypeVoid:
66 case spv::OpTypeBool:
67 case spv::OpTypeInt:
68 case spv::OpTypeFloat:
69 case spv::OpTypeVector:
70 case spv::OpTypeMatrix:
71 case spv::OpTypeSampler:
72 case spv::OpTypeFilter:
73 case spv::OpTypeArray:
74 case spv::OpTypeRuntimeArray:
75 case spv::OpTypeStruct:
76 case spv::OpTypeOpaque:
77 case spv::OpTypePointer:
78 case spv::OpTypeFunction:
79 case spv::OpTypeEvent:
80 case spv::OpTypeDeviceEvent:
81 case spv::OpTypeReserveId:
82 case spv::OpTypeQueue:
83 case spv::OpTypePipe:
84 type_def_index[code[word+1]] = word;
85 break;
86
87 default:
88 /* We only care about type definitions */
89 break;
90 }
91
92 word += oplen;
93 }
94}
95
Chris Forbes4396ff52015-04-08 10:11:59 +120096struct shader_source {
Chris Forbes1bb5a2e2015-04-10 11:41:20 +120097 /* the spirv image itself */
Chris Forbes4396ff52015-04-08 10:11:59 +120098 std::vector<uint32_t> words;
Chris Forbes1bb5a2e2015-04-10 11:41:20 +120099 /* a mapping of <id> to the first word of its def. this is useful because walking type
100 * trees requires jumping all over the instruction stream.
101 */
102 std::unordered_map<unsigned, unsigned> type_def_index;
Chris Forbes4396ff52015-04-08 10:11:59 +1200103
104 shader_source(VkShaderCreateInfo const *pCreateInfo) :
105 words((uint32_t *)pCreateInfo->pCode, (uint32_t *)pCreateInfo->pCode + pCreateInfo->codeSize / sizeof(uint32_t)) {
Chris Forbes1bb5a2e2015-04-10 11:41:20 +1200106
107 build_type_def_index(words, type_def_index);
Chris Forbes4396ff52015-04-08 10:11:59 +1200108 }
109};
110
111
112static std::unordered_map<void *, shader_source *> shader_map;
113
114
Chris Forbes1b466bd2015-04-15 06:59:41 +1200115static void
116initLayer()
117{
118 const char *strOpt;
119 // initialize ShaderChecker options
120 getLayerOptionEnum("ShaderCheckerReportLevel", (uint32_t *) &g_reportingLevel);
121 g_actionIsDefault = getLayerOptionEnum("ShaderCheckerDebugAction", (uint32_t *) &g_debugAction);
122
123 if (g_debugAction & VK_DBG_LAYER_ACTION_LOG_MSG)
124 {
125 strOpt = getLayerOption("ShaderCheckerLogFilename");
126 if (strOpt)
127 {
128 g_logFile = fopen(strOpt, "w");
129 }
130 if (g_logFile == NULL)
131 g_logFile = stdout;
132 }
133}
134
135
Chris Forbesaab9d112015-04-02 13:22:31 +1300136static VkLayerDispatchTable * initLayerTable(const VkBaseLayerObject *gpuw)
137{
138 VkLayerDispatchTable *pTable;
139
140 assert(gpuw);
141 std::unordered_map<void *, VkLayerDispatchTable *>::const_iterator it = tableMap.find((void *) gpuw->baseObject);
142 if (it == tableMap.end())
143 {
144 pTable = new VkLayerDispatchTable;
145 tableMap[(void *) gpuw->baseObject] = pTable;
146 } else
147 {
148 return it->second;
149 }
150
Chia-I Wu6097f3a2015-04-17 02:00:54 +0800151 layer_initialize_dispatch_table(pTable, gpuw->pGPA, (VkPhysicalDevice) gpuw->nextObject);
Chris Forbes1ed0f982015-05-29 14:55:18 +1200152 pCurObj = (VkBaseLayerObject *)gpuw->baseObject;
Chris Forbesaab9d112015-04-02 13:22:31 +1300153
154 return pTable;
155}
156
157
Chia-I Wu6097f3a2015-04-17 02:00:54 +0800158VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Chris Forbesaab9d112015-04-02 13:22:31 +1300159{
160 VkLayerDispatchTable* pTable = tableMap[gpu];
161 VkResult result = pTable->CreateDevice(gpu, pCreateInfo, pDevice);
Chris Forbes1b466bd2015-04-15 06:59:41 +1200162
163 loader_platform_thread_once(&g_initOnce, initLayer);
Chris Forbesaab9d112015-04-02 13:22:31 +1300164 // create a mapping for the device object into the dispatch table
165 tableMap.emplace(*pDevice, pTable);
Chris Forbes1ed0f982015-05-29 14:55:18 +1200166 pCurObj = (VkBaseLayerObject *) *pDevice;
Chris Forbesaab9d112015-04-02 13:22:31 +1300167 return result;
168}
169
170
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -0600171VK_LAYER_EXPORT VkResult VKAPI vkEnumerateLayers(VkPhysicalDevice physicalDevice, size_t maxStringSize, size_t* pLayerCount, char* const* pOutLayers, void* pReserved)
Chris Forbesaab9d112015-04-02 13:22:31 +1300172{
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -0600173 if (pLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL || pOutLayers[1] == NULL || pReserved == NULL)
Chris Forbesaab9d112015-04-02 13:22:31 +1300174 return VK_ERROR_INVALID_POINTER;
175
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -0600176 if (*pLayerCount < 1)
Chris Forbesaab9d112015-04-02 13:22:31 +1300177 return VK_ERROR_INITIALIZATION_FAILED;
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -0600178 *pLayerCount = 1;
Chris Forbesaab9d112015-04-02 13:22:31 +1300179 strncpy((char *) pOutLayers[0], "ShaderChecker", maxStringSize);
180 return VK_SUCCESS;
181}
182
183
184struct extProps {
185 uint32_t version;
186 const char * const name;
187};
Tobin Ehlis432a9ba2015-04-17 08:55:13 -0600188#define SHADER_CHECKER_LAYER_EXT_ARRAY_SIZE 2
Chris Forbesaab9d112015-04-02 13:22:31 +1300189static const struct extProps shaderCheckerExts[SHADER_CHECKER_LAYER_EXT_ARRAY_SIZE] = {
190 // TODO what is the version?
191 0x10, "ShaderChecker",
Tobin Ehlis432a9ba2015-04-17 08:55:13 -0600192 0x10, "Validation",
Chris Forbesaab9d112015-04-02 13:22:31 +1300193};
194
Chris Forbesaab9d112015-04-02 13:22:31 +1300195VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo(
196 VkExtensionInfoType infoType,
197 uint32_t extensionIndex,
198 size_t* pDataSize,
199 void* pData)
200{
Chris Forbesaab9d112015-04-02 13:22:31 +1300201 /* This entrypoint is NOT going to init it's own dispatch table since loader calls here early */
202 VkExtensionProperties *ext_props;
203 uint32_t *count;
204
205 if (pDataSize == NULL)
206 return VK_ERROR_INVALID_POINTER;
207
208 switch (infoType) {
209 case VK_EXTENSION_INFO_TYPE_COUNT:
210 *pDataSize = sizeof(uint32_t);
211 if (pData == NULL)
212 return VK_SUCCESS;
213 count = (uint32_t *) pData;
214 *count = SHADER_CHECKER_LAYER_EXT_ARRAY_SIZE;
215 break;
216 case VK_EXTENSION_INFO_TYPE_PROPERTIES:
217 *pDataSize = sizeof(VkExtensionProperties);
218 if (pData == NULL)
219 return VK_SUCCESS;
220 if (extensionIndex >= SHADER_CHECKER_LAYER_EXT_ARRAY_SIZE)
221 return VK_ERROR_INVALID_VALUE;
222 ext_props = (VkExtensionProperties *) pData;
223 ext_props->version = shaderCheckerExts[extensionIndex].version;
224 strncpy(ext_props->extName, shaderCheckerExts[extensionIndex].name,
225 VK_MAX_EXTENSION_NAME);
226 ext_props->extName[VK_MAX_EXTENSION_NAME - 1] = '\0';
227 break;
228 default:
229 return VK_ERROR_INVALID_VALUE;
230 };
231
232 return VK_SUCCESS;
233}
234
235
Chris Forbes1bb5a2e2015-04-10 11:41:20 +1200236static char const *
237storage_class_name(unsigned sc)
238{
239 switch (sc) {
Cody Northrop812b4612015-04-20 14:09:40 -0600240 case spv::StorageClassInput: return "input";
241 case spv::StorageClassOutput: return "output";
242 case spv::StorageClassUniformConstant: return "const uniform";
243 case spv::StorageClassUniform: return "uniform";
244 case spv::StorageClassWorkgroupLocal: return "workgroup local";
245 case spv::StorageClassWorkgroupGlobal: return "workgroup global";
246 case spv::StorageClassPrivateGlobal: return "private global";
247 case spv::StorageClassFunction: return "function";
248 case spv::StorageClassGeneric: return "generic";
249 case spv::StorageClassPrivate: return "private";
250 case spv::StorageClassAtomicCounter: return "atomic counter";
Chris Forbes1bb5a2e2015-04-10 11:41:20 +1200251 default: return "unknown";
252 }
253}
254
255
256/* returns ptr to null terminator */
257static char *
258describe_type(char *dst, shader_source const *src, unsigned type)
259{
260 auto type_def_it = src->type_def_index.find(type);
261
262 if (type_def_it == src->type_def_index.end()) {
263 return dst + sprintf(dst, "undef");
264 }
265
266 unsigned int const *code = (unsigned int const *)&src->words[type_def_it->second];
267 unsigned opcode = code[0] & 0x0ffffu;
268 switch (opcode) {
269 case spv::OpTypeBool:
270 return dst + sprintf(dst, "bool");
271 case spv::OpTypeInt:
272 return dst + sprintf(dst, "%cint%d", code[3] ? 's' : 'u', code[2]);
273 case spv::OpTypeFloat:
274 return dst + sprintf(dst, "float%d", code[2]);
275 case spv::OpTypeVector:
276 dst += sprintf(dst, "vec%d of ", code[3]);
277 return describe_type(dst, src, code[2]);
278 case spv::OpTypeMatrix:
279 dst += sprintf(dst, "mat%d of ", code[3]);
280 return describe_type(dst, src, code[2]);
281 case spv::OpTypeArray:
282 dst += sprintf(dst, "arr[%d] of ", code[3]);
283 return describe_type(dst, src, code[2]);
284 case spv::OpTypePointer:
285 dst += sprintf(dst, "ptr to %s ", storage_class_name(code[2]));
286 return describe_type(dst, src, code[3]);
287 case spv::OpTypeStruct:
288 {
289 unsigned oplen = code[0] >> 16;
290 dst += sprintf(dst, "struct of (");
Ian Elliottf21f14b2015-04-17 11:05:04 -0600291 for (unsigned i = 2; i < oplen; i++) {
Chris Forbes1bb5a2e2015-04-10 11:41:20 +1200292 dst = describe_type(dst, src, code[i]);
293 dst += sprintf(dst, i == oplen-1 ? ")" : ", ");
294 }
295 return dst;
296 }
297 default:
298 return dst + sprintf(dst, "oddtype");
299 }
300}
301
302
303static bool
304types_match(shader_source const *a, shader_source const *b, unsigned a_type, unsigned b_type)
305{
306 auto a_type_def_it = a->type_def_index.find(a_type);
307 auto b_type_def_it = b->type_def_index.find(b_type);
308
309 if (a_type_def_it == a->type_def_index.end()) {
310 printf("ERR: can't find def for type %d in producing shader %p; SPIRV probably invalid.\n",
311 a_type, a);
312 return false;
313 }
314
315 if (b_type_def_it == b->type_def_index.end()) {
316 printf("ERR: can't find def for type %d in consuming shader %p; SPIRV probably invalid.\n",
317 b_type, b);
318 return false;
319 }
320
321 /* walk two type trees together, and complain about differences */
322 unsigned int const *a_code = (unsigned int const *)&a->words[a_type_def_it->second];
323 unsigned int const *b_code = (unsigned int const *)&b->words[b_type_def_it->second];
324
325 unsigned a_opcode = a_code[0] & 0x0ffffu;
326 unsigned b_opcode = b_code[0] & 0x0ffffu;
327
328 if (a_opcode != b_opcode) {
329 printf(" - FAIL: type def opcodes differ: %d vs %d\n", a_opcode, b_opcode);
330 return false;
331 }
332
333 switch (a_opcode) {
334 case spv::OpTypeBool:
335 return true;
336 case spv::OpTypeInt:
337 /* match on width, signedness */
338 return a_code[2] == b_code[2] && a_code[3] == b_code[3];
339 case spv::OpTypeFloat:
340 /* match on width */
341 return a_code[2] == b_code[2];
342 case spv::OpTypeVector:
343 case spv::OpTypeMatrix:
344 case spv::OpTypeArray:
345 /* match on element type, count. these all have the same layout */
346 return types_match(a, b, a_code[2], b_code[2]) && a_code[3] == b_code[3];
347 case spv::OpTypeStruct:
348 /* match on all element types */
349 {
350 unsigned a_len = a_code[0] >> 16;
351 unsigned b_len = b_code[0] >> 16;
352
353 if (a_len != b_len) {
354 return false; /* structs cannot match if member counts differ */
355 }
356
Ian Elliottf21f14b2015-04-17 11:05:04 -0600357 for (unsigned i = 2; i < a_len; i++) {
Chris Forbes1bb5a2e2015-04-10 11:41:20 +1200358 if (!types_match(a, b, a_code[i], b_code[i])) {
359 return false;
360 }
361 }
362
363 return true;
364 }
365 case spv::OpTypePointer:
366 /* match on pointee type. storage class is expected to differ */
367 return types_match(a, b, a_code[3], b_code[3]);
368
369 default:
370 /* remaining types are CLisms, or may not appear in the interfaces we
371 * are interested in. Just claim no match.
372 */
373 return false;
374
375 }
376}
377
378
Chris Forbes67cc36f2015-04-13 12:14:52 +1200379static int
380value_or_default(std::unordered_map<unsigned, unsigned> const &map, unsigned id, int def)
381{
382 auto it = map.find(id);
383 if (it == map.end())
384 return def;
385 else
386 return it->second;
387}
388
389
390struct interface_var {
391 uint32_t id;
392 uint32_t type_id;
393 /* TODO: collect the name, too? Isn't required to be present. */
394};
395
396
397static void
Ian Elliottf21f14b2015-04-17 11:05:04 -0600398collect_interface_by_location(shader_source const *src, spv::StorageClass sinterface,
Chris Forbes67cc36f2015-04-13 12:14:52 +1200399 std::map<uint32_t, interface_var> &out,
400 std::map<uint32_t, interface_var> &builtins_out)
401{
402 unsigned int const *code = (unsigned int const *)&src->words[0];
403 size_t size = src->words.size();
404
405 if (code[0] != spv::MagicNumber) {
Chris Forbes5c75afe2015-04-17 10:13:28 +1200406 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, SHADER_CHECKER_NON_SPIRV_SHADER, "SC",
407 "Shader is not SPIR-V, unable to extract interface");
Chris Forbes67cc36f2015-04-13 12:14:52 +1200408 return;
409 }
410
411 std::unordered_map<unsigned, unsigned> var_locations;
412 std::unordered_map<unsigned, unsigned> var_builtins;
413
414 unsigned word = 5;
415 while (word < size) {
416
417 unsigned opcode = code[word] & 0x0ffffu;
418 unsigned oplen = (code[word] & 0xffff0000u) >> 16;
419
420 /* We consider two interface models: SSO rendezvous-by-location, and
421 * builtins. Complain about anything that fits neither model.
422 */
423 if (opcode == spv::OpDecorate) {
Cody Northrop812b4612015-04-20 14:09:40 -0600424 if (code[word+2] == spv::DecorationLocation) {
Chris Forbes67cc36f2015-04-13 12:14:52 +1200425 var_locations[code[word+1]] = code[word+3];
426 }
427
Cody Northrop812b4612015-04-20 14:09:40 -0600428 if (code[word+2] == spv::DecorationBuiltIn) {
Chris Forbes67cc36f2015-04-13 12:14:52 +1200429 var_builtins[code[word+1]] = code[word+3];
430 }
431 }
432
433 /* TODO: handle grouped decorations */
434 /* TODO: handle index=1 dual source outputs from FS -- two vars will
435 * have the same location, and we DONT want to clobber. */
436
Ian Elliottf21f14b2015-04-17 11:05:04 -0600437 if (opcode == spv::OpVariable && code[word+3] == sinterface) {
Chris Forbes67cc36f2015-04-13 12:14:52 +1200438 int location = value_or_default(var_locations, code[word+2], -1);
439 int builtin = value_or_default(var_builtins, code[word+2], -1);
440
441 if (location == -1 && builtin == -1) {
442 /* No location defined, and not bound to an API builtin.
443 * The spec says nothing about how this case works (or doesn't)
444 * for interface matching.
445 */
Chris Forbes5c75afe2015-04-17 10:13:28 +1200446 char str[1024];
447 sprintf(str, "var %d (type %d) in %s interface has no Location or Builtin decoration\n",
Ian Elliottf21f14b2015-04-17 11:05:04 -0600448 code[word+2], code[word+1], storage_class_name(sinterface));
Chris Forbes5c75afe2015-04-17 10:13:28 +1200449 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, SHADER_CHECKER_INCONSISTENT_SPIRV, "SC", str);
Chris Forbes67cc36f2015-04-13 12:14:52 +1200450 }
451 else if (location != -1) {
452 /* A user-defined interface variable, with a location. */
453 interface_var v;
454 v.id = code[word+2];
455 v.type_id = code[word+1];
456 out[location] = v;
457 }
458 else {
459 /* A builtin interface variable */
460 interface_var v;
461 v.id = code[word+2];
462 v.type_id = code[word+1];
463 builtins_out[builtin] = v;
464 }
465 }
466
467 word += oplen;
468 }
469}
470
471
Chris Forbesaab9d112015-04-02 13:22:31 +1300472VK_LAYER_EXPORT VkResult VKAPI vkCreateShader(VkDevice device, const VkShaderCreateInfo *pCreateInfo,
473 VkShader *pShader)
474{
Chris Forbes1ed0f982015-05-29 14:55:18 +1200475 loader_platform_thread_lock_mutex(&globalLock);
Chris Forbesaab9d112015-04-02 13:22:31 +1300476 VkLayerDispatchTable* pTable = tableMap[(VkBaseLayerObject *)device];
477 VkResult res = pTable->CreateShader(device, pCreateInfo, pShader);
Chris Forbes4396ff52015-04-08 10:11:59 +1200478
479 shader_map[(VkBaseLayerObject *) *pShader] = new shader_source(pCreateInfo);
Chris Forbes1ed0f982015-05-29 14:55:18 +1200480 loader_platform_thread_unlock_mutex(&globalLock);
Chris Forbesaab9d112015-04-02 13:22:31 +1300481 return res;
482}
483
484
Chris Forbesbb164b62015-04-08 10:19:16 +1200485static void
486validate_interface_between_stages(shader_source const *producer, char const *producer_name,
487 shader_source const *consumer, char const *consumer_name)
488{
489 std::map<uint32_t, interface_var> outputs;
490 std::map<uint32_t, interface_var> inputs;
491
492 std::map<uint32_t, interface_var> builtin_outputs;
493 std::map<uint32_t, interface_var> builtin_inputs;
494
Chris Forbes5c75afe2015-04-17 10:13:28 +1200495 char str[1024];
Chris Forbesbb164b62015-04-08 10:19:16 +1200496
Cody Northrop812b4612015-04-20 14:09:40 -0600497 collect_interface_by_location(producer, spv::StorageClassOutput, outputs, builtin_outputs);
498 collect_interface_by_location(consumer, spv::StorageClassInput, inputs, builtin_inputs);
Chris Forbesbb164b62015-04-08 10:19:16 +1200499
500 auto a_it = outputs.begin();
501 auto b_it = inputs.begin();
502
503 /* maps sorted by key (location); walk them together to find mismatches */
David Pinedof5997ab2015-04-27 16:36:17 -0600504 while ((outputs.size() > 0 && a_it != outputs.end()) || ( inputs.size() && b_it != inputs.end())) {
505 bool a_at_end = outputs.size() == 0 || a_it == outputs.end();
506 bool b_at_end = inputs.size() == 0 || b_it == inputs.end();
507 auto a_first = (outputs.size() > 0 ? a_it->first : 0);
508 auto b_first = (inputs.size() > 0 ? b_it->first : 0);
509
510 if (b_at_end || a_first < b_first) {
Chris Forbes5c75afe2015-04-17 10:13:28 +1200511 sprintf(str, "%s writes to output location %d which is not consumed by %s\n",
David Pinedof5997ab2015-04-27 16:36:17 -0600512 producer_name, a_first, consumer_name);
Chris Forbes5c75afe2015-04-17 10:13:28 +1200513 layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, NULL, 0, SHADER_CHECKER_OUTPUT_NOT_CONSUMED, "SC", str);
Chris Forbesbb164b62015-04-08 10:19:16 +1200514 a_it++;
515 }
David Pinedof5997ab2015-04-27 16:36:17 -0600516 else if (a_at_end || a_first > b_first) {
Chris Forbes5c75afe2015-04-17 10:13:28 +1200517 sprintf(str, "%s consumes input location %d which is not written by %s\n",
David Pinedof5997ab2015-04-27 16:36:17 -0600518 consumer_name, b_first, producer_name);
Chris Forbes5c75afe2015-04-17 10:13:28 +1200519 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, SHADER_CHECKER_OUTPUT_NOT_CONSUMED, "SC", str);
Chris Forbesbb164b62015-04-08 10:19:16 +1200520 b_it++;
521 }
522 else {
Chris Forbes1bb5a2e2015-04-10 11:41:20 +1200523 if (types_match(producer, consumer, a_it->second.type_id, b_it->second.type_id)) {
Chris Forbes5c75afe2015-04-17 10:13:28 +1200524 /* OK! */
Chris Forbes1bb5a2e2015-04-10 11:41:20 +1200525 }
526 else {
527 char producer_type[1024];
528 char consumer_type[1024];
529 describe_type(producer_type, producer, a_it->second.type_id);
530 describe_type(consumer_type, consumer, b_it->second.type_id);
531
Chris Forbes5c75afe2015-04-17 10:13:28 +1200532 sprintf(str, "Type mismatch on location %d: '%s' vs '%s'\n", a_it->first,
Chris Forbes1bb5a2e2015-04-10 11:41:20 +1200533 producer_type, consumer_type);
Chris Forbes5c75afe2015-04-17 10:13:28 +1200534 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, SHADER_CHECKER_INTERFACE_TYPE_MISMATCH, "SC", str);
Chris Forbes1bb5a2e2015-04-10 11:41:20 +1200535 }
Chris Forbesbb164b62015-04-08 10:19:16 +1200536 a_it++;
537 b_it++;
538 }
539 }
Chris Forbesbb164b62015-04-08 10:19:16 +1200540}
541
542
Chris Forbes9b9f5fe2015-04-08 10:37:20 +1200543enum FORMAT_TYPE {
544 FORMAT_TYPE_UNDEFINED,
545 FORMAT_TYPE_FLOAT, /* UNORM, SNORM, FLOAT, USCALED, SSCALED, SRGB -- anything we consider float in the shader */
546 FORMAT_TYPE_SINT,
547 FORMAT_TYPE_UINT,
548};
549
550
551static unsigned
552get_format_type(VkFormat fmt) {
553 switch (fmt) {
Chia-I Wu6097f3a2015-04-17 02:00:54 +0800554 case VK_FORMAT_UNDEFINED:
Chris Forbes9b9f5fe2015-04-08 10:37:20 +1200555 return FORMAT_TYPE_UNDEFINED;
Chia-I Wu6097f3a2015-04-17 02:00:54 +0800556 case VK_FORMAT_R8_SINT:
557 case VK_FORMAT_R8G8_SINT:
558 case VK_FORMAT_R8G8B8_SINT:
559 case VK_FORMAT_R8G8B8A8_SINT:
560 case VK_FORMAT_R16_SINT:
561 case VK_FORMAT_R16G16_SINT:
562 case VK_FORMAT_R16G16B16_SINT:
563 case VK_FORMAT_R16G16B16A16_SINT:
564 case VK_FORMAT_R32_SINT:
565 case VK_FORMAT_R32G32_SINT:
566 case VK_FORMAT_R32G32B32_SINT:
567 case VK_FORMAT_R32G32B32A32_SINT:
568 case VK_FORMAT_B8G8R8_SINT:
569 case VK_FORMAT_B8G8R8A8_SINT:
570 case VK_FORMAT_R10G10B10A2_SINT:
571 case VK_FORMAT_B10G10R10A2_SINT:
Chris Forbes9b9f5fe2015-04-08 10:37:20 +1200572 return FORMAT_TYPE_SINT;
Chia-I Wu6097f3a2015-04-17 02:00:54 +0800573 case VK_FORMAT_R8_UINT:
574 case VK_FORMAT_R8G8_UINT:
575 case VK_FORMAT_R8G8B8_UINT:
576 case VK_FORMAT_R8G8B8A8_UINT:
577 case VK_FORMAT_R16_UINT:
578 case VK_FORMAT_R16G16_UINT:
579 case VK_FORMAT_R16G16B16_UINT:
580 case VK_FORMAT_R16G16B16A16_UINT:
581 case VK_FORMAT_R32_UINT:
582 case VK_FORMAT_R32G32_UINT:
583 case VK_FORMAT_R32G32B32_UINT:
584 case VK_FORMAT_R32G32B32A32_UINT:
585 case VK_FORMAT_B8G8R8_UINT:
586 case VK_FORMAT_B8G8R8A8_UINT:
587 case VK_FORMAT_R10G10B10A2_UINT:
588 case VK_FORMAT_B10G10R10A2_UINT:
Chris Forbes9b9f5fe2015-04-08 10:37:20 +1200589 return FORMAT_TYPE_UINT;
590 default:
591 return FORMAT_TYPE_FLOAT;
592 }
593}
594
595
Chris Forbes28c50882015-05-04 14:04:06 +1200596/* characterizes a SPIR-V type appearing in an interface to a FF stage,
597 * for comparison to a VkFormat's characterization above. */
598static unsigned
599get_fundamental_type(shader_source const *src, unsigned type)
600{
601 auto type_def_it = src->type_def_index.find(type);
602
603 if (type_def_it == src->type_def_index.end()) {
604 return FORMAT_TYPE_UNDEFINED;
605 }
606
607 unsigned int const *code = (unsigned int const *)&src->words[type_def_it->second];
608 unsigned opcode = code[0] & 0x0ffffu;
609 switch (opcode) {
610 case spv::OpTypeInt:
611 return code[3] ? FORMAT_TYPE_SINT : FORMAT_TYPE_UINT;
612 case spv::OpTypeFloat:
613 return FORMAT_TYPE_FLOAT;
614 case spv::OpTypeVector:
615 return get_fundamental_type(src, code[2]);
616 case spv::OpTypeMatrix:
617 return get_fundamental_type(src, code[2]);
618 case spv::OpTypeArray:
619 return get_fundamental_type(src, code[2]);
620 case spv::OpTypePointer:
621 return get_fundamental_type(src, code[3]);
622 default:
623 return FORMAT_TYPE_UNDEFINED;
624 }
625}
626
627
Chris Forbesfcd05f12015-04-08 10:36:37 +1200628static void
629validate_vi_against_vs_inputs(VkPipelineVertexInputCreateInfo const *vi, shader_source const *vs)
630{
631 std::map<uint32_t, interface_var> inputs;
632 /* we collect builtin inputs, but they will never appear in the VI state --
633 * the vs builtin inputs are generated in the pipeline, not sourced from buffers (VertexID, etc)
634 */
635 std::map<uint32_t, interface_var> builtin_inputs;
Chris Forbes5c75afe2015-04-17 10:13:28 +1200636 char str[1024];
Chris Forbesfcd05f12015-04-08 10:36:37 +1200637
Cody Northrop812b4612015-04-20 14:09:40 -0600638 collect_interface_by_location(vs, spv::StorageClassInput, inputs, builtin_inputs);
Chris Forbesfcd05f12015-04-08 10:36:37 +1200639
640 /* Build index by location */
641 std::map<uint32_t, VkVertexInputAttributeDescription const *> attribs;
Ian Elliottf21f14b2015-04-17 11:05:04 -0600642 for (unsigned i = 0; i < vi->attributeCount; i++)
Chris Forbesfcd05f12015-04-08 10:36:37 +1200643 attribs[vi->pVertexAttributeDescriptions[i].location] = &vi->pVertexAttributeDescriptions[i];
644
645 auto it_a = attribs.begin();
646 auto it_b = inputs.begin();
647
David Pinedof5997ab2015-04-27 16:36:17 -0600648 while ((attribs.size() > 0 && it_a != attribs.end()) || (inputs.size() > 0 && it_b != inputs.end())) {
649 bool a_at_end = attribs.size() == 0 || it_a == attribs.end();
650 bool b_at_end = inputs.size() == 0 || it_b == inputs.end();
651 auto a_first = (attribs.size() > 0 ? it_a->first : 0);
652 auto b_first = (inputs.size() > 0 ? it_b->first : 0);
653 if (b_at_end || a_first < b_first) {
654 sprintf(str, "Vertex attribute at location %d not consumed by VS", a_first);
Chris Forbes5c75afe2015-04-17 10:13:28 +1200655 layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, NULL, 0, SHADER_CHECKER_OUTPUT_NOT_CONSUMED, "SC", str);
Chris Forbesfcd05f12015-04-08 10:36:37 +1200656 it_a++;
657 }
David Pinedof5997ab2015-04-27 16:36:17 -0600658 else if (a_at_end || b_first < a_first) {
659 sprintf(str, "VS consumes input at location %d but not provided", b_first);
Chris Forbes5c75afe2015-04-17 10:13:28 +1200660 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, SHADER_CHECKER_INPUT_NOT_PRODUCED, "SC", str);
Chris Forbesfcd05f12015-04-08 10:36:37 +1200661 it_b++;
662 }
663 else {
Chris Forbes3317b382015-05-04 14:04:24 +1200664 unsigned attrib_type = get_format_type(it_a->second->format);
665 unsigned input_type = get_fundamental_type(vs, it_b->second.type_id);
666
667 /* type checking */
668 if (attrib_type != FORMAT_TYPE_UNDEFINED && input_type != FORMAT_TYPE_UNDEFINED && attrib_type != input_type) {
669 char vs_type[1024];
670 describe_type(vs_type, vs, it_b->second.type_id);
671 sprintf(str, "Attribute type of `%s` at location %d does not match VS input type of `%s`",
672 string_VkFormat(it_a->second->format), a_first, vs_type);
673 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, SHADER_CHECKER_INTERFACE_TYPE_MISMATCH, "SC", str);
674 }
675
Chris Forbes5c75afe2015-04-17 10:13:28 +1200676 /* OK! */
Chris Forbesfcd05f12015-04-08 10:36:37 +1200677 it_a++;
678 it_b++;
679 }
680 }
Chris Forbesfcd05f12015-04-08 10:36:37 +1200681}
682
683
Chris Forbes9b9f5fe2015-04-08 10:37:20 +1200684static void
685validate_fs_outputs_against_cb(shader_source const *fs, VkPipelineCbStateCreateInfo const *cb)
686{
687 std::map<uint32_t, interface_var> outputs;
688 std::map<uint32_t, interface_var> builtin_outputs;
Chris Forbes5c75afe2015-04-17 10:13:28 +1200689 char str[1024];
Chris Forbes9b9f5fe2015-04-08 10:37:20 +1200690
691 /* TODO: dual source blend index (spv::DecIndex, zero if not provided) */
692
Cody Northrop812b4612015-04-20 14:09:40 -0600693 collect_interface_by_location(fs, spv::StorageClassOutput, outputs, builtin_outputs);
Chris Forbes9b9f5fe2015-04-08 10:37:20 +1200694
695 /* Check for legacy gl_FragColor broadcast: In this case, we should have no user-defined outputs,
696 * and all color attachment should be UNORM/SNORM/FLOAT.
697 */
698 if (builtin_outputs.find(spv::BuiltInFragColor) != builtin_outputs.end()) {
699 bool broadcast_err = false;
700 if (outputs.size()) {
Chris Forbes5c75afe2015-04-17 10:13:28 +1200701 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, SHADER_CHECKER_FS_MIXED_BROADCAST, "SC",
702 "Should not have user-defined FS outputs when using broadcast");
Chris Forbes9b9f5fe2015-04-08 10:37:20 +1200703 broadcast_err = true;
704 }
705
Ian Elliottf21f14b2015-04-17 11:05:04 -0600706 for (unsigned i = 0; i < cb->attachmentCount; i++) {
Chris Forbes9b9f5fe2015-04-08 10:37:20 +1200707 unsigned attachmentType = get_format_type(cb->pAttachments[i].format);
708 if (attachmentType == FORMAT_TYPE_SINT || attachmentType == FORMAT_TYPE_UINT) {
Chris Forbes5c75afe2015-04-17 10:13:28 +1200709 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, SHADER_CHECKER_INTERFACE_TYPE_MISMATCH, "SC",
710 "CB format should not be SINT or UINT when using broadcast");
Chris Forbes9b9f5fe2015-04-08 10:37:20 +1200711 broadcast_err = true;
712 }
713 }
714
Chris Forbes9b9f5fe2015-04-08 10:37:20 +1200715 return;
716 }
717
718 auto it = outputs.begin();
719 uint32_t attachment = 0;
720
721 /* Walk attachment list and outputs together -- this is a little overpowered since attachments
722 * are currently dense, but the parallel with matching between shader stages is nice.
723 */
724
Chris Forbes8802c992015-05-05 11:34:14 +1200725 while ((outputs.size() > 0 && it != outputs.end()) || attachment < cb->attachmentCount) {
scygan7a62cbe2015-06-01 19:48:11 +0200726 if (attachment == cb->attachmentCount || ( it != outputs.end() && it->first < attachment)) {
Chris Forbes5c75afe2015-04-17 10:13:28 +1200727 sprintf(str, "FS writes to output location %d with no matching attachment", it->first);
728 layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, NULL, 0, SHADER_CHECKER_OUTPUT_NOT_CONSUMED, "SC", str);
Chris Forbes9b9f5fe2015-04-08 10:37:20 +1200729 it++;
730 }
731 else if (it == outputs.end() || it->first > attachment) {
Chris Forbes5c75afe2015-04-17 10:13:28 +1200732 sprintf(str, "Attachment %d not written by FS", attachment);
733 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, SHADER_CHECKER_INPUT_NOT_PRODUCED, "SC", str);
Chris Forbes9b9f5fe2015-04-08 10:37:20 +1200734 attachment++;
735 }
736 else {
Chris Forbes4b009002015-05-04 14:20:10 +1200737 unsigned output_type = get_fundamental_type(fs, it->second.type_id);
738 unsigned att_type = get_format_type(cb->pAttachments[attachment].format);
739
740 /* type checking */
741 if (att_type != FORMAT_TYPE_UNDEFINED && output_type != FORMAT_TYPE_UNDEFINED && att_type != output_type) {
742 char fs_type[1024];
743 describe_type(fs_type, fs, it->second.type_id);
744 sprintf(str, "Attachment %d of type `%s` does not match FS output type of `%s`",
745 attachment, string_VkFormat(cb->pAttachments[attachment].format), fs_type);
746 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, SHADER_CHECKER_INTERFACE_TYPE_MISMATCH, "SC", str);
747 }
748
Chris Forbes5c75afe2015-04-17 10:13:28 +1200749 /* OK! */
Chris Forbes9b9f5fe2015-04-08 10:37:20 +1200750 it++;
751 attachment++;
752 }
753 }
Chris Forbes9b9f5fe2015-04-08 10:37:20 +1200754}
755
756
Chris Forbes60540932015-04-08 10:15:35 +1200757VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipeline(VkDevice device,
758 const VkGraphicsPipelineCreateInfo *pCreateInfo,
759 VkPipeline *pPipeline)
760{
Chris Forbes5c75afe2015-04-17 10:13:28 +1200761 /* TODO: run cross-stage validation for GS, TCS, TES stages */
Chris Forbes60540932015-04-08 10:15:35 +1200762
Chris Forbes8f600932015-04-08 10:16:45 +1200763 /* We seem to allow pipeline stages to be specified out of order, so collect and identify them
764 * before trying to do anything more: */
765
766 shader_source const *vs_source = 0;
767 shader_source const *fs_source = 0;
768 VkPipelineCbStateCreateInfo const *cb = 0;
769 VkPipelineVertexInputCreateInfo const *vi = 0;
Chris Forbes5c75afe2015-04-17 10:13:28 +1200770 char str[1024];
Chris Forbes8f600932015-04-08 10:16:45 +1200771
Chris Forbes1ed0f982015-05-29 14:55:18 +1200772 loader_platform_thread_lock_mutex(&globalLock);
773
Chris Forbes8f600932015-04-08 10:16:45 +1200774 for (auto stage = pCreateInfo; stage; stage = (decltype(stage))stage->pNext) {
775 if (stage->sType == VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO) {
776 auto shader_stage = (VkPipelineShaderStageCreateInfo const *)stage;
777
Chris Forbes5c75afe2015-04-17 10:13:28 +1200778 if (shader_stage->shader.stage == VK_SHADER_STAGE_VERTEX) {
Chris Forbes8f600932015-04-08 10:16:45 +1200779 vs_source = shader_map[(void *)(shader_stage->shader.shader)];
Chris Forbes5c75afe2015-04-17 10:13:28 +1200780 }
781 else if (shader_stage->shader.stage == VK_SHADER_STAGE_FRAGMENT) {
Chris Forbes8f600932015-04-08 10:16:45 +1200782 fs_source = shader_map[(void *)(shader_stage->shader.shader)];
Chris Forbes5c75afe2015-04-17 10:13:28 +1200783 }
784 else {
785 sprintf(str, "Unknown shader stage %d\n", shader_stage->shader.stage);
786 layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, NULL, 0, SHADER_CHECKER_UNKNOWN_STAGE, "SC", str);
787 }
Chris Forbes8f600932015-04-08 10:16:45 +1200788 }
789 else if (stage->sType == VK_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO) {
790 cb = (VkPipelineCbStateCreateInfo const *)stage;
791 }
792 else if (stage->sType == VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO) {
793 vi = (VkPipelineVertexInputCreateInfo const *)stage;
794 }
795 }
796
Chris Forbes5c75afe2015-04-17 10:13:28 +1200797 sprintf(str, "Pipeline: vi=%p vs=%p fs=%p cb=%p\n", vi, vs_source, fs_source, cb);
798 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, SHADER_CHECKER_NONE, "SC", str);
Chris Forbes8f600932015-04-08 10:16:45 +1200799
Chris Forbesfcd05f12015-04-08 10:36:37 +1200800 if (vi && vs_source) {
801 validate_vi_against_vs_inputs(vi, vs_source);
802 }
803
Chris Forbesbb164b62015-04-08 10:19:16 +1200804 if (vs_source && fs_source) {
805 validate_interface_between_stages(vs_source, "vertex shader",
806 fs_source, "fragment shader");
807 }
808
Chris Forbes9b9f5fe2015-04-08 10:37:20 +1200809 if (fs_source && cb) {
810 validate_fs_outputs_against_cb(fs_source, cb);
811 }
812
Chris Forbes60540932015-04-08 10:15:35 +1200813 VkLayerDispatchTable *pTable = tableMap[(VkBaseLayerObject *)device];
814 VkResult res = pTable->CreateGraphicsPipeline(device, pCreateInfo, pPipeline);
Chris Forbes1ed0f982015-05-29 14:55:18 +1200815
816 loader_platform_thread_unlock_mutex(&globalLock);
Chris Forbes60540932015-04-08 10:15:35 +1200817 return res;
818}
819
820
Chris Forbesb65ba352015-05-25 11:12:59 +1200821VK_LAYER_EXPORT VkResult VKAPI vkDbgRegisterMsgCallback(
822 VkInstance instance,
823 VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback,
824 void *pUserData)
825{
826 // This layer intercepts callbacks
827 VK_LAYER_DBG_FUNCTION_NODE *pNewDbgFuncNode = (VK_LAYER_DBG_FUNCTION_NODE*)malloc(sizeof(VK_LAYER_DBG_FUNCTION_NODE));
828 if (!pNewDbgFuncNode)
829 return VK_ERROR_OUT_OF_HOST_MEMORY;
830 pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;
831 pNewDbgFuncNode->pUserData = pUserData;
832 pNewDbgFuncNode->pNext = g_pDbgFunctionHead;
833 g_pDbgFunctionHead = pNewDbgFuncNode;
834 // force callbacks if DebugAction hasn't been set already other than initial value
835 if (g_actionIsDefault) {
836 g_debugAction = VK_DBG_LAYER_ACTION_CALLBACK;
837 }
Chris Forbes1ed0f982015-05-29 14:55:18 +1200838 // NOT CORRECT WITH MULTIPLE DEVICES OR INSTANCES, BUT THIS IS ALL GOING AWAY SOON ANYWAY
839 VkLayerDispatchTable *pTable = tableMap[pCurObj];
840 VkResult result = pTable->DbgRegisterMsgCallback(instance, pfnMsgCallback, pUserData);
Chris Forbesb65ba352015-05-25 11:12:59 +1200841 return result;
842}
843
844VK_LAYER_EXPORT VkResult VKAPI vkDbgUnregisterMsgCallback(
845 VkInstance instance,
846 VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback)
847{
848 VK_LAYER_DBG_FUNCTION_NODE *pInfo = g_pDbgFunctionHead;
849 VK_LAYER_DBG_FUNCTION_NODE *pPrev = pInfo;
850 while (pInfo) {
851 if (pInfo->pfnMsgCallback == pfnMsgCallback) {
852 pPrev->pNext = pInfo->pNext;
853 if (g_pDbgFunctionHead == pInfo) {
854 g_pDbgFunctionHead = pInfo->pNext;
855 }
856 free(pInfo);
857 break;
858 }
859 pPrev = pInfo;
860 pInfo = pInfo->pNext;
861 }
862 if (g_pDbgFunctionHead == NULL) {
863 if (g_actionIsDefault) {
864 g_debugAction = VK_DBG_LAYER_ACTION_LOG_MSG;
865 } else {
866 g_debugAction = (VK_LAYER_DBG_ACTION)(g_debugAction & ~((uint32_t)VK_DBG_LAYER_ACTION_CALLBACK));
867 }
868 }
Chris Forbes1ed0f982015-05-29 14:55:18 +1200869 // NOT CORRECT WITH MULTIPLE DEVICES OR INSTANCES, BUT THIS IS ALL GOING AWAY SOON ANYWAY
870 VkLayerDispatchTable *pTable = tableMap[pCurObj];
871 VkResult result = pTable->DbgUnregisterMsgCallback(instance, pfnMsgCallback);
Chris Forbesb65ba352015-05-25 11:12:59 +1200872 return result;
873}
874
875
Chia-I Wu6097f3a2015-04-17 02:00:54 +0800876VK_LAYER_EXPORT void * VKAPI vkGetProcAddr(VkPhysicalDevice gpu, const char* pName)
Chris Forbesaab9d112015-04-02 13:22:31 +1300877{
878 if (gpu == NULL)
879 return NULL;
880
881 initLayerTable((const VkBaseLayerObject *) gpu);
882
Chris Forbes1b466bd2015-04-15 06:59:41 +1200883 loader_platform_thread_once(&g_initOnce, initLayer);
884
Chris Forbesaab9d112015-04-02 13:22:31 +1300885#define ADD_HOOK(fn) \
886 if (!strncmp(#fn, pName, sizeof(#fn))) \
887 return (void *) fn
888
889 ADD_HOOK(vkGetProcAddr);
890 ADD_HOOK(vkEnumerateLayers);
891 ADD_HOOK(vkCreateDevice);
892 ADD_HOOK(vkCreateShader);
Chris Forbes60540932015-04-08 10:15:35 +1200893 ADD_HOOK(vkCreateGraphicsPipeline);
Chris Forbesb65ba352015-05-25 11:12:59 +1200894 ADD_HOOK(vkDbgRegisterMsgCallback);
895 ADD_HOOK(vkDbgUnregisterMsgCallback);
Chris Forbesaab9d112015-04-02 13:22:31 +1300896
897 VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu;
898 if (gpuw->pGPA == NULL)
899 return NULL;
Chia-I Wu6097f3a2015-04-17 02:00:54 +0800900 return gpuw->pGPA((VkPhysicalDevice) gpuw->nextObject, pName);
Chris Forbesaab9d112015-04-02 13:22:31 +1300901}