blob: 5f64e1ff2d55cfeeb74179c0a9f6dedbba0a0104 [file] [log] [blame]
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001/*
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002 *
Courtney Goeltzenleuchter8a17da52015-10-29 13:50:34 -06003 * Copyright (C) 2015 Valve Corporation
Michael Lentine329697b2015-10-06 14:56:18 -07004 * Copyright (C) 2015 Google, Inc.
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005 *
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.
Courtney Goeltzenleuchter96cd7952015-10-30 11:14:30 -060023 *
Tobin Ehlisd17c28c2015-12-03 09:40:56 -070024 * Author: Cody Northrop <cnorthrop@google.com>
Courtney Goeltzenleuchter96cd7952015-10-30 11:14:30 -060025 * Author: Michael Lentine <mlentine@google.com>
Tobin Ehlisd17c28c2015-12-03 09:40:56 -070026 * Author: Tobin Ehlis <tobine@google.com>
27 * Author: Chia-I Wu <olv@google.com>
Tobin Ehlis32479352015-12-01 09:48:58 -070028 * Author: Chris Forbes <chrisf@ijw.co.nz>
Tobin Ehlis63bb9482015-03-17 16:24:32 -060029 */
30
31#include <stdio.h>
32#include <stdlib.h>
33#include <string.h>
Tobin Ehlis32479352015-12-01 09:48:58 -070034#include <assert.h>
Tobin Ehlis63bb9482015-03-17 16:24:32 -060035#include <unordered_map>
Michael Lentine329697b2015-10-06 14:56:18 -070036#include <unordered_set>
Tobin Ehlis32479352015-12-01 09:48:58 -070037#include <map>
38#include <string>
39#include <iostream>
40#include <algorithm>
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -070041#include <list>
Tobin Ehlis32479352015-12-01 09:48:58 -070042#include <spirv.hpp>
Tobin Ehlisd17c28c2015-12-03 09:40:56 -070043#include <set>
Tobin Ehlis63bb9482015-03-17 16:24:32 -060044
Tobin Ehlis7a51d902015-07-03 10:34:49 -060045#include "vk_loader_platform.h"
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060046#include "vk_dispatch_table_helper.h"
47#include "vk_struct_string_helper_cpp.h"
Tony Barboura938abb2015-04-22 11:36:22 -060048#if defined(__GNUC__)
Tobin Ehlis63bb9482015-03-17 16:24:32 -060049#pragma GCC diagnostic ignored "-Wwrite-strings"
Tony Barboura938abb2015-04-22 11:36:22 -060050#endif
Tony Barboura938abb2015-04-22 11:36:22 -060051#if defined(__GNUC__)
Tobin Ehlis63bb9482015-03-17 16:24:32 -060052#pragma GCC diagnostic warning "-Wwrite-strings"
Tony Barboura938abb2015-04-22 11:36:22 -060053#endif
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060054#include "vk_struct_size_helper.h"
Tobin Ehlis63bb9482015-03-17 16:24:32 -060055#include "draw_state.h"
Tobin Ehlis56d204a2015-07-03 10:15:26 -060056#include "vk_layer_config.h"
Michael Lentine8469dd62015-11-20 09:48:52 -080057#include "vulkan/vk_debug_marker_layer.h"
Tobin Ehlis56d204a2015-07-03 10:15:26 -060058#include "vk_layer_table.h"
59#include "vk_layer_debug_marker_table.h"
60#include "vk_layer_data.h"
61#include "vk_layer_logging.h"
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -060062#include "vk_layer_extension_utils.h"
Tobin Ehlisb46be812015-10-23 16:00:08 -060063#include "vk_layer_utils.h"
Tobin Ehlis63bb9482015-03-17 16:24:32 -060064
Mark Lobodzinski78940a42015-11-30 16:48:53 -070065// This definition controls whether image layout transitions are enabled/disabled.
66// disable until corner cases are fixed
67#define DISABLE_IMAGE_LAYOUT_VALIDATION
68
Tobin Ehlis32479352015-12-01 09:48:58 -070069using std::unordered_map;
70using std::unordered_set;
71
Tobin Ehlis4c8381e2015-12-14 13:46:38 -070072// Track command pools and their command buffers
73struct CMD_POOL_INFO {
74 VkCommandPoolCreateFlags createFlags;
75 list<VkCommandBuffer> commandBuffers; // list container of cmd buffers allocated from this pool
76};
77
Tobin Ehlise6ab55a2015-10-07 09:38:40 -060078struct devExts {
Courtney Goeltzenleuchterf2bca902015-11-03 15:41:43 -070079 VkBool32 debug_marker_enabled;
Michael Lentine27b0f902015-10-12 11:30:14 -050080 VkBool32 wsi_enabled;
81 unordered_map<VkSwapchainKHR, SWAPCHAIN_NODE*> swapchainMap;
Tobin Ehlise6ab55a2015-10-07 09:38:40 -060082};
83
Tobin Ehlis32479352015-12-01 09:48:58 -070084// fwd decls
85struct shader_module;
86struct render_pass;
87
Cody Northrop73bb6572015-09-28 15:09:32 -060088struct layer_data {
Tobin Ehlisad61de42015-12-02 13:53:34 -070089 debug_report_data* report_data;
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -070090 std::vector<VkDebugReportCallbackEXT> logging_callback;
Tobin Ehlise6ab55a2015-10-07 09:38:40 -060091 VkLayerDispatchTable* device_dispatch_table;
92 VkLayerInstanceDispatchTable* instance_dispatch_table;
93 devExts device_extensions;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -060094 // Layer specific data
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -070095 unordered_map<VkSampler, unique_ptr<SAMPLER_NODE>> sampleMap;
96 unordered_map<VkImageView, unique_ptr<VkImageViewCreateInfo>> imageViewMap;
97 unordered_map<VkImage, unique_ptr<VkImageCreateInfo>> imageMap;
98 unordered_map<VkBufferView, unique_ptr<VkBufferViewCreateInfo>> bufferViewMap;
99 unordered_map<VkBuffer, unique_ptr<VkBufferCreateInfo>> bufferMap;
100 unordered_map<VkPipeline, PIPELINE_NODE*> pipelineMap;
Tobin Ehlis4c8381e2015-12-14 13:46:38 -0700101 unordered_map<VkCommandPool, CMD_POOL_INFO> commandPoolMap;
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -0700102 unordered_map<VkDescriptorPool, DESCRIPTOR_POOL_NODE*> descriptorPoolMap;
103 unordered_map<VkDescriptorSet, SET_NODE*> setMap;
Tobin Ehlisad61de42015-12-02 13:53:34 -0700104 unordered_map<VkDescriptorSetLayout, LAYOUT_NODE*> descriptorSetLayoutMap;
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -0700105 unordered_map<VkPipelineLayout, PIPELINE_LAYOUT_NODE> pipelineLayoutMap;
106 unordered_map<VkDeviceMemory, VkImage> memImageMap;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -0600107 // Map for layout chains
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -0700108 unordered_map<void*, GLOBAL_CB_NODE*> commandBufferMap;
109 unordered_map<VkFramebuffer, VkFramebufferCreateInfo*> frameBufferMap;
110 unordered_map<VkImage, IMAGE_NODE*> imageLayoutMap;
111 unordered_map<VkRenderPass, RENDER_PASS_NODE*> renderPassMap;
Tobin Ehlisad61de42015-12-02 13:53:34 -0700112 unordered_map<VkShaderModule, shader_module*> shaderModuleMap;
Michael Lentine27b0f902015-10-12 11:30:14 -0500113 // Current render pass
114 VkRenderPassBeginInfo renderPassBeginInfo;
115 uint32_t currentSubpass;
Cody Northrop73bb6572015-09-28 15:09:32 -0600116
117 layer_data() :
118 report_data(nullptr),
Tobin Ehlise6ab55a2015-10-07 09:38:40 -0600119 device_dispatch_table(nullptr),
120 instance_dispatch_table(nullptr),
121 device_extensions()
Cody Northrop73bb6572015-09-28 15:09:32 -0600122 {};
123};
Tobin Ehlis32479352015-12-01 09:48:58 -0700124// Code imported from ShaderChecker
125static void
126build_type_def_index(std::vector<unsigned> const &words, std::unordered_map<unsigned, unsigned> &type_def_index);
127
128struct shader_module {
129 /* the spirv image itself */
130 vector<uint32_t> words;
131 /* a mapping of <id> to the first word of its def. this is useful because walking type
132 * trees requires jumping all over the instruction stream.
133 */
134 unordered_map<unsigned, unsigned> type_def_index;
135
136 shader_module(VkShaderModuleCreateInfo const *pCreateInfo) :
137 words((uint32_t *)pCreateInfo->pCode, (uint32_t *)pCreateInfo->pCode + pCreateInfo->codeSize / sizeof(uint32_t)),
138 type_def_index() {
139
140 build_type_def_index(words, type_def_index);
141 }
142};
143
Tobin Ehlisd04ccab2015-10-07 15:40:22 -0600144// TODO : Do we need to guard access to layer_data_map w/ lock?
Tobin Ehlisad61de42015-12-02 13:53:34 -0700145static unordered_map<void*, layer_data*> layer_data_map;
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -0600146
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600147static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
148// TODO : This can be much smarter, using separate locks for separate global data
149static int globalLockInitialized = 0;
150static loader_platform_thread_mutex globalLock;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600151#define MAX_TID 513
152static loader_platform_thread_id g_tidMapping[MAX_TID] = {0};
153static uint32_t g_maxTID = 0;
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600154
155template layer_data *get_my_data_ptr<layer_data>(
156 void *data_key,
157 std::unordered_map<void *, layer_data *> &data_map);
158
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600159// Map actual TID to an index value and return that index
160// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs
161static uint32_t getTIDIndex() {
162 loader_platform_thread_id tid = loader_platform_get_thread_id();
163 for (uint32_t i = 0; i < g_maxTID; i++) {
164 if (tid == g_tidMapping[i])
165 return i;
166 }
167 // Don't yet have mapping, set it and return newly set index
168 uint32_t retVal = (uint32_t) g_maxTID;
169 g_tidMapping[g_maxTID++] = tid;
170 assert(g_maxTID < MAX_TID);
171 return retVal;
172}
Tobin Ehlis982099b2015-11-05 09:52:49 -0700173
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600174// Return a string representation of CMD_TYPE enum
175static string cmdTypeToString(CMD_TYPE cmd)
176{
177 switch (cmd)
178 {
179 case CMD_BINDPIPELINE:
180 return "CMD_BINDPIPELINE";
181 case CMD_BINDPIPELINEDELTA:
182 return "CMD_BINDPIPELINEDELTA";
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600183 case CMD_SETVIEWPORTSTATE:
184 return "CMD_SETVIEWPORTSTATE";
185 case CMD_SETLINEWIDTHSTATE:
186 return "CMD_SETLINEWIDTHSTATE";
187 case CMD_SETDEPTHBIASSTATE:
188 return "CMD_SETDEPTHBIASSTATE";
189 case CMD_SETBLENDSTATE:
190 return "CMD_SETBLENDSTATE";
191 case CMD_SETDEPTHBOUNDSSTATE:
192 return "CMD_SETDEPTHBOUNDSSTATE";
193 case CMD_SETSTENCILREADMASKSTATE:
194 return "CMD_SETSTENCILREADMASKSTATE";
195 case CMD_SETSTENCILWRITEMASKSTATE:
196 return "CMD_SETSTENCILWRITEMASKSTATE";
197 case CMD_SETSTENCILREFERENCESTATE:
198 return "CMD_SETSTENCILREFERENCESTATE";
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600199 case CMD_BINDDESCRIPTORSETS:
200 return "CMD_BINDDESCRIPTORSETS";
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600201 case CMD_BINDINDEXBUFFER:
202 return "CMD_BINDINDEXBUFFER";
203 case CMD_BINDVERTEXBUFFER:
204 return "CMD_BINDVERTEXBUFFER";
205 case CMD_DRAW:
206 return "CMD_DRAW";
207 case CMD_DRAWINDEXED:
208 return "CMD_DRAWINDEXED";
209 case CMD_DRAWINDIRECT:
210 return "CMD_DRAWINDIRECT";
211 case CMD_DRAWINDEXEDINDIRECT:
212 return "CMD_DRAWINDEXEDINDIRECT";
213 case CMD_DISPATCH:
214 return "CMD_DISPATCH";
215 case CMD_DISPATCHINDIRECT:
216 return "CMD_DISPATCHINDIRECT";
217 case CMD_COPYBUFFER:
218 return "CMD_COPYBUFFER";
219 case CMD_COPYIMAGE:
220 return "CMD_COPYIMAGE";
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600221 case CMD_BLITIMAGE:
222 return "CMD_BLITIMAGE";
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600223 case CMD_COPYBUFFERTOIMAGE:
224 return "CMD_COPYBUFFERTOIMAGE";
225 case CMD_COPYIMAGETOBUFFER:
226 return "CMD_COPYIMAGETOBUFFER";
227 case CMD_CLONEIMAGEDATA:
228 return "CMD_CLONEIMAGEDATA";
229 case CMD_UPDATEBUFFER:
230 return "CMD_UPDATEBUFFER";
231 case CMD_FILLBUFFER:
232 return "CMD_FILLBUFFER";
233 case CMD_CLEARCOLORIMAGE:
234 return "CMD_CLEARCOLORIMAGE";
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -0600235 case CMD_CLEARATTACHMENTS:
Tobin Ehlis8cd650e2015-07-01 16:46:13 -0600236 return "CMD_CLEARCOLORATTACHMENT";
237 case CMD_CLEARDEPTHSTENCILIMAGE:
238 return "CMD_CLEARDEPTHSTENCILIMAGE";
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600239 case CMD_RESOLVEIMAGE:
240 return "CMD_RESOLVEIMAGE";
241 case CMD_SETEVENT:
242 return "CMD_SETEVENT";
243 case CMD_RESETEVENT:
244 return "CMD_RESETEVENT";
245 case CMD_WAITEVENTS:
246 return "CMD_WAITEVENTS";
247 case CMD_PIPELINEBARRIER:
248 return "CMD_PIPELINEBARRIER";
249 case CMD_BEGINQUERY:
250 return "CMD_BEGINQUERY";
251 case CMD_ENDQUERY:
252 return "CMD_ENDQUERY";
253 case CMD_RESETQUERYPOOL:
254 return "CMD_RESETQUERYPOOL";
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -0600255 case CMD_COPYQUERYPOOLRESULTS:
256 return "CMD_COPYQUERYPOOLRESULTS";
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600257 case CMD_WRITETIMESTAMP:
258 return "CMD_WRITETIMESTAMP";
259 case CMD_INITATOMICCOUNTERS:
260 return "CMD_INITATOMICCOUNTERS";
261 case CMD_LOADATOMICCOUNTERS:
262 return "CMD_LOADATOMICCOUNTERS";
263 case CMD_SAVEATOMICCOUNTERS:
264 return "CMD_SAVEATOMICCOUNTERS";
265 case CMD_BEGINRENDERPASS:
266 return "CMD_BEGINRENDERPASS";
267 case CMD_ENDRENDERPASS:
268 return "CMD_ENDRENDERPASS";
269 case CMD_DBGMARKERBEGIN:
270 return "CMD_DBGMARKERBEGIN";
271 case CMD_DBGMARKEREND:
272 return "CMD_DBGMARKEREND";
273 default:
274 return "UNKNOWN";
275 }
276}
Tobin Ehlis32479352015-12-01 09:48:58 -0700277
278// SPIRV utility functions
279static void
280build_type_def_index(std::vector<unsigned> const &words, std::unordered_map<unsigned, unsigned> &type_def_index)
281{
282 unsigned int const *code = (unsigned int const *)&words[0];
283 size_t size = words.size();
284
285 unsigned word = 5;
286 while (word < size) {
287 unsigned opcode = code[word] & 0x0ffffu;
288 unsigned oplen = (code[word] & 0xffff0000u) >> 16;
289
290 switch (opcode) {
291 case spv::OpTypeVoid:
292 case spv::OpTypeBool:
293 case spv::OpTypeInt:
294 case spv::OpTypeFloat:
295 case spv::OpTypeVector:
296 case spv::OpTypeMatrix:
297 case spv::OpTypeImage:
298 case spv::OpTypeSampler:
299 case spv::OpTypeSampledImage:
300 case spv::OpTypeArray:
301 case spv::OpTypeRuntimeArray:
302 case spv::OpTypeStruct:
303 case spv::OpTypeOpaque:
304 case spv::OpTypePointer:
305 case spv::OpTypeFunction:
306 case spv::OpTypeEvent:
307 case spv::OpTypeDeviceEvent:
308 case spv::OpTypeReserveId:
309 case spv::OpTypeQueue:
310 case spv::OpTypePipe:
311 type_def_index[code[word+1]] = word;
312 break;
313
314 default:
315 /* We only care about type definitions */
316 break;
317 }
318
319 word += oplen;
320 }
321}
322
323bool
324shader_is_spirv(VkShaderModuleCreateInfo const *pCreateInfo)
325{
326 uint32_t *words = (uint32_t *)pCreateInfo->pCode;
327 size_t sizeInWords = pCreateInfo->codeSize / sizeof(uint32_t);
328
329 /* Just validate that the header makes sense. */
330 return sizeInWords >= 5 && words[0] == spv::MagicNumber && words[1] == spv::Version;
331}
332
333static char const *
334storage_class_name(unsigned sc)
335{
336 switch (sc) {
337 case spv::StorageClassInput: return "input";
338 case spv::StorageClassOutput: return "output";
339 case spv::StorageClassUniformConstant: return "const uniform";
340 case spv::StorageClassUniform: return "uniform";
341 case spv::StorageClassWorkgroup: return "workgroup local";
342 case spv::StorageClassCrossWorkgroup: return "workgroup global";
343 case spv::StorageClassPrivate: return "private global";
344 case spv::StorageClassFunction: return "function";
345 case spv::StorageClassGeneric: return "generic";
346 case spv::StorageClassAtomicCounter: return "atomic counter";
347 case spv::StorageClassImage: return "image";
348 default: return "unknown";
349 }
350}
351
352/* returns ptr to null terminator */
353static char *
354describe_type(char *dst, shader_module const *src, unsigned type)
355{
356 auto type_def_it = src->type_def_index.find(type);
357
358 if (type_def_it == src->type_def_index.end()) {
359 return dst + sprintf(dst, "undef");
360 }
361
362 unsigned int const *code = (unsigned int const *)&src->words[type_def_it->second];
363 unsigned opcode = code[0] & 0x0ffffu;
364 switch (opcode) {
365 case spv::OpTypeBool:
366 return dst + sprintf(dst, "bool");
367 case spv::OpTypeInt:
368 return dst + sprintf(dst, "%cint%d", code[3] ? 's' : 'u', code[2]);
369 case spv::OpTypeFloat:
370 return dst + sprintf(dst, "float%d", code[2]);
371 case spv::OpTypeVector:
372 dst += sprintf(dst, "vec%d of ", code[3]);
373 return describe_type(dst, src, code[2]);
374 case spv::OpTypeMatrix:
375 dst += sprintf(dst, "mat%d of ", code[3]);
376 return describe_type(dst, src, code[2]);
377 case spv::OpTypeArray:
378 dst += sprintf(dst, "arr[%d] of ", code[3]);
379 return describe_type(dst, src, code[2]);
380 case spv::OpTypePointer:
381 dst += sprintf(dst, "ptr to %s ", storage_class_name(code[2]));
382 return describe_type(dst, src, code[3]);
383 case spv::OpTypeStruct:
384 {
385 unsigned oplen = code[0] >> 16;
386 dst += sprintf(dst, "struct of (");
387 for (unsigned i = 2; i < oplen; i++) {
388 dst = describe_type(dst, src, code[i]);
389 dst += sprintf(dst, i == oplen-1 ? ")" : ", ");
390 }
391 return dst;
392 }
393 case spv::OpTypeSampler:
394 return dst + sprintf(dst, "sampler");
395 default:
396 return dst + sprintf(dst, "oddtype");
397 }
398}
399
400static bool
401types_match(shader_module const *a, shader_module const *b, unsigned a_type, unsigned b_type, bool b_arrayed)
402{
403 auto a_type_def_it = a->type_def_index.find(a_type);
404 auto b_type_def_it = b->type_def_index.find(b_type);
405
406 if (a_type_def_it == a->type_def_index.end()) {
407 return false;
408 }
409
410 if (b_type_def_it == b->type_def_index.end()) {
411 return false;
412 }
413
414 /* walk two type trees together, and complain about differences */
415 unsigned int const *a_code = (unsigned int const *)&a->words[a_type_def_it->second];
416 unsigned int const *b_code = (unsigned int const *)&b->words[b_type_def_it->second];
417
418 unsigned a_opcode = a_code[0] & 0x0ffffu;
419 unsigned b_opcode = b_code[0] & 0x0ffffu;
420
421 if (b_arrayed && b_opcode == spv::OpTypeArray) {
422 /* we probably just found the extra level of arrayness in b_type: compare the type inside it to a_type */
423 return types_match(a, b, a_type, b_code[2], false);
424 }
425
426 if (a_opcode != b_opcode) {
427 return false;
428 }
429
430 switch (a_opcode) {
431 /* if b_arrayed and we hit a leaf type, then we can't match -- there's nowhere for the extra OpTypeArray to be! */
432 case spv::OpTypeBool:
433 return true && !b_arrayed;
434 case spv::OpTypeInt:
435 /* match on width, signedness */
436 return a_code[2] == b_code[2] && a_code[3] == b_code[3] && !b_arrayed;
437 case spv::OpTypeFloat:
438 /* match on width */
439 return a_code[2] == b_code[2] && !b_arrayed;
440 case spv::OpTypeVector:
441 case spv::OpTypeMatrix:
442 case spv::OpTypeArray:
443 /* match on element type, count. these all have the same layout. we don't get here if
444 * b_arrayed -- that is handled above. */
445 return !b_arrayed && types_match(a, b, a_code[2], b_code[2], b_arrayed) && a_code[3] == b_code[3];
446 case spv::OpTypeStruct:
447 /* match on all element types */
448 {
449 if (b_arrayed) {
450 /* for the purposes of matching different levels of arrayness, structs are leaves. */
451 return false;
452 }
453
454 unsigned a_len = a_code[0] >> 16;
455 unsigned b_len = b_code[0] >> 16;
456
457 if (a_len != b_len) {
458 return false; /* structs cannot match if member counts differ */
459 }
460
461 for (unsigned i = 2; i < a_len; i++) {
462 if (!types_match(a, b, a_code[i], b_code[i], b_arrayed)) {
463 return false;
464 }
465 }
466
467 return true;
468 }
469 case spv::OpTypePointer:
470 /* match on pointee type. storage class is expected to differ */
471 return types_match(a, b, a_code[3], b_code[3], b_arrayed);
472
473 default:
474 /* remaining types are CLisms, or may not appear in the interfaces we
475 * are interested in. Just claim no match.
476 */
477 return false;
478
479 }
480}
481
482static int
483value_or_default(std::unordered_map<unsigned, unsigned> const &map, unsigned id, int def)
484{
485 auto it = map.find(id);
486 if (it == map.end())
487 return def;
488 else
489 return it->second;
490}
491
492
493static unsigned
494get_locations_consumed_by_type(shader_module const *src, unsigned type, bool strip_array_level)
495{
496 auto type_def_it = src->type_def_index.find(type);
497
498 if (type_def_it == src->type_def_index.end()) {
499 return 1; /* This is actually broken SPIR-V... */
500 }
501
502 unsigned int const *code = (unsigned int const *)&src->words[type_def_it->second];
503 unsigned opcode = code[0] & 0x0ffffu;
504
505 switch (opcode) {
506 case spv::OpTypePointer:
507 /* see through the ptr -- this is only ever at the toplevel for graphics shaders;
508 * we're never actually passing pointers around. */
509 return get_locations_consumed_by_type(src, code[3], strip_array_level);
510 case spv::OpTypeArray:
511 if (strip_array_level) {
512 return get_locations_consumed_by_type(src, code[2], false);
513 }
514 else {
515 return code[3] * get_locations_consumed_by_type(src, code[2], false);
516 }
517 case spv::OpTypeMatrix:
518 /* num locations is the dimension * element size */
519 return code[3] * get_locations_consumed_by_type(src, code[2], false);
520 default:
521 /* everything else is just 1. */
522 return 1;
523
524 /* TODO: extend to handle 64bit scalar types, whose vectors may need
525 * multiple locations. */
526 }
527}
528
529
530struct interface_var {
531 uint32_t id;
532 uint32_t type_id;
533 uint32_t offset;
534 /* TODO: collect the name, too? Isn't required to be present. */
535};
536
537static void
538collect_interface_by_location(layer_data *my_data, VkDevice dev,
539 shader_module const *src, spv::StorageClass sinterface,
540 std::map<uint32_t, interface_var> &out,
541 std::map<uint32_t, interface_var> &builtins_out,
542 bool is_array_of_verts)
543{
544 unsigned int const *code = (unsigned int const *)&src->words[0];
545 size_t size = src->words.size();
546
547 std::unordered_map<unsigned, unsigned> var_locations;
548 std::unordered_map<unsigned, unsigned> var_builtins;
549
550 unsigned word = 5;
551 while (word < size) {
552
553 unsigned opcode = code[word] & 0x0ffffu;
554 unsigned oplen = (code[word] & 0xffff0000u) >> 16;
555
556 /* We consider two interface models: SSO rendezvous-by-location, and
557 * builtins. Complain about anything that fits neither model.
558 */
559 if (opcode == spv::OpDecorate) {
560 if (code[word+2] == spv::DecorationLocation) {
561 var_locations[code[word+1]] = code[word+3];
562 }
563
564 if (code[word+2] == spv::DecorationBuiltIn) {
565 var_builtins[code[word+1]] = code[word+3];
566 }
567 }
568
569 /* TODO: handle grouped decorations */
570 /* TODO: handle index=1 dual source outputs from FS -- two vars will
571 * have the same location, and we DONT want to clobber. */
572
573 if (opcode == spv::OpVariable && code[word+3] == sinterface) {
574 unsigned id = code[word+2];
575 unsigned type = code[word+1];
576
577 int location = value_or_default(var_locations, code[word+2], -1);
578 int builtin = value_or_default(var_builtins, code[word+2], -1);
579
580 if (location == -1 && builtin == -1) {
581 /* No location defined, and not bound to an API builtin.
582 * The spec says nothing about how this case works (or doesn't)
583 * for interface matching.
584 */
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -0700585 log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, 0, SHADER_CHECKER_INCONSISTENT_SPIRV, "SC",
Tobin Ehlis32479352015-12-01 09:48:58 -0700586 "var %d (type %d) in %s interface has no Location or Builtin decoration",
587 code[word+2], code[word+1], storage_class_name(sinterface));
588 }
589 else if (location != -1) {
590 /* A user-defined interface variable, with a location. Where a variable
591 * occupied multiple locations, emit one result for each. */
592 unsigned num_locations = get_locations_consumed_by_type(src, type,
593 is_array_of_verts);
Courtney Goeltzenleuchter740451a2015-12-16 16:06:06 -0700594 for (unsigned int offset = 0; offset < num_locations; offset++) {
Tobin Ehlis32479352015-12-01 09:48:58 -0700595 interface_var v;
596 v.id = id;
597 v.type_id = type;
598 v.offset = offset;
599 out[location + offset] = v;
600 }
601 }
602 else {
603 /* A builtin interface variable */
604 /* Note that since builtin interface variables do not consume numbered
605 * locations, there is no larger-than-vec4 consideration as above
606 */
607 interface_var v;
608 v.id = id;
609 v.type_id = type;
610 v.offset = 0;
611 builtins_out[builtin] = v;
612 }
613 }
614
615 word += oplen;
616 }
617}
618
619static void
620collect_interface_by_descriptor_slot(layer_data *my_data, VkDevice dev,
621 shader_module const *src, spv::StorageClass sinterface,
622 std::map<std::pair<unsigned, unsigned>, interface_var> &out)
623{
624 unsigned int const *code = (unsigned int const *)&src->words[0];
625 size_t size = src->words.size();
626
627 std::unordered_map<unsigned, unsigned> var_sets;
628 std::unordered_map<unsigned, unsigned> var_bindings;
629
630 unsigned word = 5;
631 while (word < size) {
632
633 unsigned opcode = code[word] & 0x0ffffu;
634 unsigned oplen = (code[word] & 0xffff0000u) >> 16;
635
636 /* All variables in the Uniform or UniformConstant storage classes are required to be decorated with both
637 * DecorationDescriptorSet and DecorationBinding.
638 */
639 if (opcode == spv::OpDecorate) {
640 if (code[word+2] == spv::DecorationDescriptorSet) {
641 var_sets[code[word+1]] = code[word+3];
642 }
643
644 if (code[word+2] == spv::DecorationBinding) {
645 var_bindings[code[word+1]] = code[word+3];
646 }
647 }
648
649 if (opcode == spv::OpVariable && (code[word+3] == spv::StorageClassUniform ||
650 code[word+3] == spv::StorageClassUniformConstant)) {
651 unsigned set = value_or_default(var_sets, code[word+2], 0);
652 unsigned binding = value_or_default(var_bindings, code[word+2], 0);
653
654 auto existing_it = out.find(std::make_pair(set, binding));
655 if (existing_it != out.end()) {
656 /* conflict within spv image */
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -0700657 log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, 0,
Tobin Ehlis32479352015-12-01 09:48:58 -0700658 SHADER_CHECKER_INCONSISTENT_SPIRV, "SC",
659 "var %d (type %d) in %s interface in descriptor slot (%u,%u) conflicts with existing definition",
660 code[word+2], code[word+1], storage_class_name(sinterface),
661 existing_it->first.first, existing_it->first.second);
662 }
663
664 interface_var v;
665 v.id = code[word+2];
666 v.type_id = code[word+1];
667 out[std::make_pair(set, binding)] = v;
668 }
669
670 word += oplen;
671 }
672}
673
674static bool
675validate_interface_between_stages(layer_data *my_data, VkDevice dev,
676 shader_module const *producer, char const *producer_name,
677 shader_module const *consumer, char const *consumer_name,
678 bool consumer_arrayed_input)
679{
680 std::map<uint32_t, interface_var> outputs;
681 std::map<uint32_t, interface_var> inputs;
682
683 std::map<uint32_t, interface_var> builtin_outputs;
684 std::map<uint32_t, interface_var> builtin_inputs;
685
686 bool pass = true;
687
688 collect_interface_by_location(my_data, dev, producer, spv::StorageClassOutput, outputs, builtin_outputs, false);
689 collect_interface_by_location(my_data, dev, consumer, spv::StorageClassInput, inputs, builtin_inputs,
690 consumer_arrayed_input);
691
692 auto a_it = outputs.begin();
693 auto b_it = inputs.begin();
694
695 /* maps sorted by key (location); walk them together to find mismatches */
696 while ((outputs.size() > 0 && a_it != outputs.end()) || ( inputs.size() && b_it != inputs.end())) {
697 bool a_at_end = outputs.size() == 0 || a_it == outputs.end();
698 bool b_at_end = inputs.size() == 0 || b_it == inputs.end();
699 auto a_first = a_at_end ? 0 : a_it->first;
700 auto b_first = b_at_end ? 0 : b_it->first;
701
702 if (b_at_end || ((!a_at_end) && (a_first < b_first))) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -0700703 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, 0, SHADER_CHECKER_OUTPUT_NOT_CONSUMED, "SC",
Tobin Ehlis32479352015-12-01 09:48:58 -0700704 "%s writes to output location %d which is not consumed by %s", producer_name, a_first, consumer_name)) {
705 pass = false;
706 }
707 a_it++;
708 }
709 else if (a_at_end || a_first > b_first) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -0700710 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, 0, SHADER_CHECKER_INPUT_NOT_PRODUCED, "SC",
Tobin Ehlis32479352015-12-01 09:48:58 -0700711 "%s consumes input location %d which is not written by %s", consumer_name, b_first, producer_name)) {
712 pass = false;
713 }
714 b_it++;
715 }
716 else {
717 if (types_match(producer, consumer, a_it->second.type_id, b_it->second.type_id, consumer_arrayed_input)) {
718 /* OK! */
719 }
720 else {
721 char producer_type[1024];
722 char consumer_type[1024];
723 describe_type(producer_type, producer, a_it->second.type_id);
724 describe_type(consumer_type, consumer, b_it->second.type_id);
725
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -0700726 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, 0, SHADER_CHECKER_INTERFACE_TYPE_MISMATCH, "SC",
Tobin Ehlis32479352015-12-01 09:48:58 -0700727 "Type mismatch on location %d: '%s' vs '%s'", a_it->first, producer_type, consumer_type)) {
728 pass = false;
729 }
730 }
731 a_it++;
732 b_it++;
733 }
734 }
735
736 return pass;
737}
738
739enum FORMAT_TYPE {
740 FORMAT_TYPE_UNDEFINED,
741 FORMAT_TYPE_FLOAT, /* UNORM, SNORM, FLOAT, USCALED, SSCALED, SRGB -- anything we consider float in the shader */
742 FORMAT_TYPE_SINT,
743 FORMAT_TYPE_UINT,
744};
745
746static unsigned
747get_format_type(VkFormat fmt) {
748 switch (fmt) {
749 case VK_FORMAT_UNDEFINED:
750 return FORMAT_TYPE_UNDEFINED;
751 case VK_FORMAT_R8_SINT:
752 case VK_FORMAT_R8G8_SINT:
753 case VK_FORMAT_R8G8B8_SINT:
754 case VK_FORMAT_R8G8B8A8_SINT:
755 case VK_FORMAT_R16_SINT:
756 case VK_FORMAT_R16G16_SINT:
757 case VK_FORMAT_R16G16B16_SINT:
758 case VK_FORMAT_R16G16B16A16_SINT:
759 case VK_FORMAT_R32_SINT:
760 case VK_FORMAT_R32G32_SINT:
761 case VK_FORMAT_R32G32B32_SINT:
762 case VK_FORMAT_R32G32B32A32_SINT:
763 case VK_FORMAT_B8G8R8_SINT:
764 case VK_FORMAT_B8G8R8A8_SINT:
765 case VK_FORMAT_A2B10G10R10_SINT_PACK32:
766 case VK_FORMAT_A2R10G10B10_SINT_PACK32:
767 return FORMAT_TYPE_SINT;
768 case VK_FORMAT_R8_UINT:
769 case VK_FORMAT_R8G8_UINT:
770 case VK_FORMAT_R8G8B8_UINT:
771 case VK_FORMAT_R8G8B8A8_UINT:
772 case VK_FORMAT_R16_UINT:
773 case VK_FORMAT_R16G16_UINT:
774 case VK_FORMAT_R16G16B16_UINT:
775 case VK_FORMAT_R16G16B16A16_UINT:
776 case VK_FORMAT_R32_UINT:
777 case VK_FORMAT_R32G32_UINT:
778 case VK_FORMAT_R32G32B32_UINT:
779 case VK_FORMAT_R32G32B32A32_UINT:
780 case VK_FORMAT_B8G8R8_UINT:
781 case VK_FORMAT_B8G8R8A8_UINT:
782 case VK_FORMAT_A2B10G10R10_UINT_PACK32:
783 case VK_FORMAT_A2R10G10B10_UINT_PACK32:
784 return FORMAT_TYPE_UINT;
785 default:
786 return FORMAT_TYPE_FLOAT;
787 }
788}
789
790/* characterizes a SPIR-V type appearing in an interface to a FF stage,
791 * for comparison to a VkFormat's characterization above. */
792static unsigned
793get_fundamental_type(shader_module const *src, unsigned type)
794{
795 auto type_def_it = src->type_def_index.find(type);
796
797 if (type_def_it == src->type_def_index.end()) {
798 return FORMAT_TYPE_UNDEFINED;
799 }
800
801 unsigned int const *code = (unsigned int const *)&src->words[type_def_it->second];
802 unsigned opcode = code[0] & 0x0ffffu;
803 switch (opcode) {
804 case spv::OpTypeInt:
805 return code[3] ? FORMAT_TYPE_SINT : FORMAT_TYPE_UINT;
806 case spv::OpTypeFloat:
807 return FORMAT_TYPE_FLOAT;
808 case spv::OpTypeVector:
809 return get_fundamental_type(src, code[2]);
810 case spv::OpTypeMatrix:
811 return get_fundamental_type(src, code[2]);
812 case spv::OpTypeArray:
813 return get_fundamental_type(src, code[2]);
814 case spv::OpTypePointer:
815 return get_fundamental_type(src, code[3]);
816 default:
817 return FORMAT_TYPE_UNDEFINED;
818 }
819}
820
821static bool
822validate_vi_consistency(layer_data *my_data, VkDevice dev, VkPipelineVertexInputStateCreateInfo const *vi)
823{
824 /* walk the binding descriptions, which describe the step rate and stride of each vertex buffer.
825 * each binding should be specified only once.
826 */
827 std::unordered_map<uint32_t, VkVertexInputBindingDescription const *> bindings;
828 bool pass = true;
829
830 for (unsigned i = 0; i < vi->vertexBindingDescriptionCount; i++) {
831 auto desc = &vi->pVertexBindingDescriptions[i];
832 auto & binding = bindings[desc->binding];
833 if (binding) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -0700834 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, 0, SHADER_CHECKER_INCONSISTENT_VI, "SC",
Tobin Ehlis32479352015-12-01 09:48:58 -0700835 "Duplicate vertex input binding descriptions for binding %d", desc->binding)) {
836 pass = false;
837 }
838 }
839 else {
840 binding = desc;
841 }
842 }
843
844 return pass;
845}
846
847static bool
848validate_vi_against_vs_inputs(layer_data *my_data, VkDevice dev, VkPipelineVertexInputStateCreateInfo const *vi, shader_module const *vs)
849{
850 std::map<uint32_t, interface_var> inputs;
851 /* we collect builtin inputs, but they will never appear in the VI state --
852 * the vs builtin inputs are generated in the pipeline, not sourced from buffers (VertexID, etc)
853 */
854 std::map<uint32_t, interface_var> builtin_inputs;
855 bool pass = true;
856
857 collect_interface_by_location(my_data, dev, vs, spv::StorageClassInput, inputs, builtin_inputs, false);
858
859 /* Build index by location */
860 std::map<uint32_t, VkVertexInputAttributeDescription const *> attribs;
861 if (vi) {
862 for (unsigned i = 0; i < vi->vertexAttributeDescriptionCount; i++)
863 attribs[vi->pVertexAttributeDescriptions[i].location] = &vi->pVertexAttributeDescriptions[i];
864 }
865
866 auto it_a = attribs.begin();
867 auto it_b = inputs.begin();
868
869 while ((attribs.size() > 0 && it_a != attribs.end()) || (inputs.size() > 0 && it_b != inputs.end())) {
870 bool a_at_end = attribs.size() == 0 || it_a == attribs.end();
871 bool b_at_end = inputs.size() == 0 || it_b == inputs.end();
872 auto a_first = a_at_end ? 0 : it_a->first;
873 auto b_first = b_at_end ? 0 : it_b->first;
874 if (b_at_end || a_first < b_first) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -0700875 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, 0, SHADER_CHECKER_OUTPUT_NOT_CONSUMED, "SC",
Tobin Ehlis32479352015-12-01 09:48:58 -0700876 "Vertex attribute at location %d not consumed by VS", a_first)) {
877 pass = false;
878 }
879 it_a++;
880 }
881 else if (a_at_end || b_first < a_first) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -0700882 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, 0, SHADER_CHECKER_INPUT_NOT_PRODUCED, "SC",
Tobin Ehlis32479352015-12-01 09:48:58 -0700883 "VS consumes input at location %d but not provided", b_first)) {
884 pass = false;
885 }
886 it_b++;
887 }
888 else {
889 unsigned attrib_type = get_format_type(it_a->second->format);
890 unsigned input_type = get_fundamental_type(vs, it_b->second.type_id);
891
892 /* type checking */
893 if (attrib_type != FORMAT_TYPE_UNDEFINED && input_type != FORMAT_TYPE_UNDEFINED && attrib_type != input_type) {
894 char vs_type[1024];
895 describe_type(vs_type, vs, it_b->second.type_id);
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -0700896 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, 0, SHADER_CHECKER_INTERFACE_TYPE_MISMATCH, "SC",
Tobin Ehlis32479352015-12-01 09:48:58 -0700897 "Attribute type of `%s` at location %d does not match VS input type of `%s`",
898 string_VkFormat(it_a->second->format), a_first, vs_type)) {
899 pass = false;
900 }
901 }
902
903 /* OK! */
904 it_a++;
905 it_b++;
906 }
907 }
908
909 return pass;
910}
911
912static bool
Tobin Ehlisad61de42015-12-02 13:53:34 -0700913validate_fs_outputs_against_render_pass(layer_data *my_data, VkDevice dev, shader_module const *fs, RENDER_PASS_NODE const *rp, uint32_t subpass)
Tobin Ehlis32479352015-12-01 09:48:58 -0700914{
Tobin Ehlisad61de42015-12-02 13:53:34 -0700915 const std::vector<VkFormat> &color_formats = rp->subpassColorFormats[subpass];
Tobin Ehlis32479352015-12-01 09:48:58 -0700916 std::map<uint32_t, interface_var> outputs;
917 std::map<uint32_t, interface_var> builtin_outputs;
918 bool pass = true;
919
920 /* TODO: dual source blend index (spv::DecIndex, zero if not provided) */
921
922 collect_interface_by_location(my_data, dev, fs, spv::StorageClassOutput, outputs, builtin_outputs, false);
923
924 auto it = outputs.begin();
925 uint32_t attachment = 0;
926
927 /* Walk attachment list and outputs together -- this is a little overpowered since attachments
928 * are currently dense, but the parallel with matching between shader stages is nice.
929 */
930
931 /* TODO: Figure out compile error with cb->attachmentCount */
932 while ((outputs.size() > 0 && it != outputs.end()) || attachment < color_formats.size()) {
933 if (attachment == color_formats.size() || ( it != outputs.end() && it->first < attachment)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -0700934 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, 0, SHADER_CHECKER_OUTPUT_NOT_CONSUMED, "SC",
Tobin Ehlis32479352015-12-01 09:48:58 -0700935 "FS writes to output location %d with no matching attachment", it->first)) {
936 pass = false;
937 }
938 it++;
939 }
940 else if (it == outputs.end() || it->first > attachment) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -0700941 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, 0, SHADER_CHECKER_INPUT_NOT_PRODUCED, "SC",
Tobin Ehlis32479352015-12-01 09:48:58 -0700942 "Attachment %d not written by FS", attachment)) {
943 pass = false;
944 }
945 attachment++;
946 }
947 else {
948 unsigned output_type = get_fundamental_type(fs, it->second.type_id);
949 unsigned att_type = get_format_type(color_formats[attachment]);
950
951 /* type checking */
952 if (att_type != FORMAT_TYPE_UNDEFINED && output_type != FORMAT_TYPE_UNDEFINED && att_type != output_type) {
953 char fs_type[1024];
954 describe_type(fs_type, fs, it->second.type_id);
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -0700955 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, 0, SHADER_CHECKER_INTERFACE_TYPE_MISMATCH, "SC",
Tobin Ehlis32479352015-12-01 09:48:58 -0700956 "Attachment %d of type `%s` does not match FS output type of `%s`",
957 attachment, string_VkFormat(color_formats[attachment]), fs_type)) {
958 pass = false;
959 }
960 }
961
962 /* OK! */
963 it++;
964 attachment++;
965 }
966 }
967
968 return pass;
969}
970
971
972struct shader_stage_attributes {
973 char const * const name;
974 bool arrayed_input;
975};
976
977
978static shader_stage_attributes
979shader_stage_attribs[] = {
980 { "vertex shader", false },
981 { "tessellation control shader", true },
982 { "tessellation evaluation shader", false },
983 { "geometry shader", true },
984 { "fragment shader", false },
985};
986
Tobin Ehlisad61de42015-12-02 13:53:34 -0700987// For given pipelineLayout verify that the setLayout at slot.first
988// has the requested binding at slot.second
Tobin Ehlis32479352015-12-01 09:48:58 -0700989static bool
Tobin Ehlisad61de42015-12-02 13:53:34 -0700990has_descriptor_binding(layer_data* my_data,
991 vector<VkDescriptorSetLayout>* pipelineLayout,
Tobin Ehlis32479352015-12-01 09:48:58 -0700992 std::pair<unsigned, unsigned> slot)
993{
Tobin Ehlisad61de42015-12-02 13:53:34 -0700994 if (!pipelineLayout)
Tobin Ehlis32479352015-12-01 09:48:58 -0700995 return false;
996
Tobin Ehlisad61de42015-12-02 13:53:34 -0700997 if (slot.first >= pipelineLayout->size())
Tobin Ehlis32479352015-12-01 09:48:58 -0700998 return false;
999
Tobin Ehlisad61de42015-12-02 13:53:34 -07001000 auto set = my_data->descriptorSetLayoutMap[(*pipelineLayout)[slot.first]]->bindings;
Tobin Ehlis32479352015-12-01 09:48:58 -07001001
Tobin Ehlisad61de42015-12-02 13:53:34 -07001002 return (set.find(slot.second) != set.end());
Tobin Ehlis32479352015-12-01 09:48:58 -07001003}
1004
1005static uint32_t get_shader_stage_id(VkShaderStageFlagBits stage)
1006{
1007 uint32_t bit_pos = u_ffs(stage);
1008 return bit_pos-1;
1009}
1010
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001011// Block of code at start here for managing/tracking Pipeline state that this layer cares about
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001012
1013static uint64_t g_drawCount[NUM_DRAW_TYPES] = {0, 0, 0, 0};
1014
Chia-I Wu1f851912015-10-27 18:04:07 +08001015// TODO : Should be tracking lastBound per commandBuffer and when draws occur, report based on that cmd buffer lastBound
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001016// Then need to synchronize the accesses based on cmd buffer so that if I'm reading state on one cmd buffer, updates
1017// to that same cmd buffer by separate thread are not changing state from underneath us
1018// Track the last cmd buffer touched by this thread
Tobin Ehlis32479352015-12-01 09:48:58 -07001019
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001020#define MAX_BINDING 0xFFFFFFFF // Default vtxBinding value in CB Node to identify if no vtxBinding set
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06001021// prototype
Chia-I Wu1f851912015-10-27 18:04:07 +08001022static GLOBAL_CB_NODE* getCBNode(layer_data*, const VkCommandBuffer);
Tobin Ehlis982099b2015-11-05 09:52:49 -07001023
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -06001024static VkBool32 hasDrawCmd(GLOBAL_CB_NODE* pCB)
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001025{
1026 for (uint32_t i=0; i<NUM_DRAW_TYPES; i++) {
1027 if (pCB->drawCount[i])
1028 return VK_TRUE;
1029 }
1030 return VK_FALSE;
1031}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001032
Tobin Ehlis97866202015-06-10 12:57:07 -06001033// Check object status for selected flag state
Tobin Ehlis42d440c2015-10-20 17:06:16 -06001034static VkBool32 validate_status(layer_data* my_data, GLOBAL_CB_NODE* pNode, CBStatusFlags enable_mask, CBStatusFlags status_mask, CBStatusFlags status_flag, VkFlags msg_flags, DRAW_STATE_ERROR error_code, const char* fail_msg)
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001035{
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06001036 // If non-zero enable mask is present, check it against status but if enable_mask
1037 // is 0 then no enable required so we should always just check status
1038 if ((!enable_mask) || (enable_mask & pNode->status)) {
1039 if ((pNode->status & status_mask) != status_flag) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001040 // TODO : How to pass dispatchable objects as srcObject? Here src obj should be cmd buffer
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001041 return log_msg(my_data->report_data, msg_flags, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, 0, error_code, "DS",
Chia-I Wu1f851912015-10-27 18:04:07 +08001042 "CB object %#" PRIxLEAST64 ": %s", reinterpret_cast<uint64_t>(pNode->commandBuffer), fail_msg);
Tobin Ehlis97866202015-06-10 12:57:07 -06001043 }
Tobin Ehlis97866202015-06-10 12:57:07 -06001044 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001045 return VK_FALSE;
Tobin Ehlis97866202015-06-10 12:57:07 -06001046}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001047
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001048// Retrieve pipeline node ptr for given pipeline object
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06001049static PIPELINE_NODE* getPipeline(layer_data* my_data, const VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001050{
1051 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue420a332015-10-26 20:04:44 +08001052 if (my_data->pipelineMap.find(pipeline) == my_data->pipelineMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001053 loader_platform_thread_unlock_mutex(&globalLock);
1054 return NULL;
1055 }
1056 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wue420a332015-10-26 20:04:44 +08001057 return my_data->pipelineMap[pipeline];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001058}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001059
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06001060// Return VK_TRUE if for a given PSO, the given state enum is dynamic, else return VK_FALSE
1061static VkBool32 isDynamic(const PIPELINE_NODE* pPipeline, const VkDynamicState state)
1062{
1063 if (pPipeline && pPipeline->graphicsPipelineCI.pDynamicState) {
1064 for (uint32_t i=0; i<pPipeline->graphicsPipelineCI.pDynamicState->dynamicStateCount; i++) {
1065 if (state == pPipeline->graphicsPipelineCI.pDynamicState->pDynamicStates[i])
1066 return VK_TRUE;
1067 }
1068 }
1069 return VK_FALSE;
1070}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001071
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06001072// Validate state stored as flags at time of draw call
Tobin Ehlis42d440c2015-10-20 17:06:16 -06001073static VkBool32 validate_draw_state_flags(layer_data* my_data, GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -06001074 VkBool32 result;
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001075 result = validate_status(my_data, pCB, CBSTATUS_NONE, CBSTATUS_VIEWPORT_SET, CBSTATUS_VIEWPORT_SET, VK_DEBUG_REPORT_ERROR_BIT_EXT, DRAWSTATE_VIEWPORT_NOT_BOUND, "Dynamic viewport state not set for this command buffer");
1076 result |= validate_status(my_data, pCB, CBSTATUS_NONE, CBSTATUS_SCISSOR_SET, CBSTATUS_SCISSOR_SET, VK_DEBUG_REPORT_ERROR_BIT_EXT, DRAWSTATE_SCISSOR_NOT_BOUND, "Dynamic scissor state not set for this command buffer");
1077 result |= validate_status(my_data, pCB, CBSTATUS_NONE, CBSTATUS_LINE_WIDTH_SET, CBSTATUS_LINE_WIDTH_SET, VK_DEBUG_REPORT_ERROR_BIT_EXT, DRAWSTATE_LINE_WIDTH_NOT_BOUND, "Dynamic line width state not set for this command buffer");
1078 result |= validate_status(my_data, pCB, CBSTATUS_NONE, CBSTATUS_DEPTH_BIAS_SET, CBSTATUS_DEPTH_BIAS_SET, VK_DEBUG_REPORT_ERROR_BIT_EXT, DRAWSTATE_DEPTH_BIAS_NOT_BOUND, "Dynamic depth bias state not set for this command buffer");
1079 result |= validate_status(my_data, pCB, CBSTATUS_COLOR_BLEND_WRITE_ENABLE, CBSTATUS_BLEND_SET, CBSTATUS_BLEND_SET, VK_DEBUG_REPORT_ERROR_BIT_EXT, DRAWSTATE_BLEND_NOT_BOUND, "Dynamic blend object state not set for this command buffer");
1080 result |= validate_status(my_data, pCB, CBSTATUS_DEPTH_WRITE_ENABLE, CBSTATUS_DEPTH_BOUNDS_SET, CBSTATUS_DEPTH_BOUNDS_SET, VK_DEBUG_REPORT_ERROR_BIT_EXT, DRAWSTATE_DEPTH_BOUNDS_NOT_BOUND, "Dynamic depth bounds state not set for this command buffer");
1081 result |= validate_status(my_data, pCB, CBSTATUS_STENCIL_TEST_ENABLE, CBSTATUS_STENCIL_READ_MASK_SET, CBSTATUS_STENCIL_READ_MASK_SET, VK_DEBUG_REPORT_ERROR_BIT_EXT, DRAWSTATE_STENCIL_NOT_BOUND, "Dynamic stencil read mask state not set for this command buffer");
1082 result |= validate_status(my_data, pCB, CBSTATUS_STENCIL_TEST_ENABLE, CBSTATUS_STENCIL_WRITE_MASK_SET, CBSTATUS_STENCIL_WRITE_MASK_SET, VK_DEBUG_REPORT_ERROR_BIT_EXT, DRAWSTATE_STENCIL_NOT_BOUND, "Dynamic stencil write mask state not set for this command buffer");
1083 result |= validate_status(my_data, pCB, CBSTATUS_STENCIL_TEST_ENABLE, CBSTATUS_STENCIL_REFERENCE_SET, CBSTATUS_STENCIL_REFERENCE_SET, VK_DEBUG_REPORT_ERROR_BIT_EXT, DRAWSTATE_STENCIL_NOT_BOUND, "Dynamic stencil reference state not set for this command buffer");
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06001084 if (indexedDraw)
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001085 result |= validate_status(my_data, pCB, CBSTATUS_NONE, CBSTATUS_INDEX_BUFFER_BOUND, CBSTATUS_INDEX_BUFFER_BOUND, VK_DEBUG_REPORT_ERROR_BIT_EXT, DRAWSTATE_INDEX_BUFFER_NOT_BOUND, "Index buffer object not bound to this command buffer when Indexed Draw attempted");
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06001086 return result;
1087}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001088
Tobin Ehlis9185b0a2015-12-16 05:01:22 -07001089// Verify attachment reference compatibility according to spec
1090// If one array is larger, treat missing elements of shorter array as VK_ATTACHMENT_UNUSED & other array much match this
1091// If both AttachmentReference arrays have requested index, check their corresponding AttachementDescriptions
1092// to make sure that format and samples counts match.
1093// If not, they are not compatible.
1094static bool attachment_references_compatible(const uint32_t index, const VkAttachmentReference* pPrimary, const uint32_t primaryCount, const VkAttachmentDescription* pPrimaryAttachments,
1095 const VkAttachmentReference* pSecondary, const uint32_t secondaryCount, const VkAttachmentDescription* pSecondaryAttachments)
1096{
1097 if (index >= primaryCount) { // Check secondary as if primary is VK_ATTACHMENT_UNUSED
1098 if (VK_ATTACHMENT_UNUSED != pSecondary[index].attachment)
1099 return false;
1100 } else if (index >= secondaryCount) { // Check primary as if secondary is VK_ATTACHMENT_UNUSED
1101 if (VK_ATTACHMENT_UNUSED != pPrimary[index].attachment)
1102 return false;
1103 } else { // format and sample count must match
1104 if ((pPrimaryAttachments[pPrimary[index].attachment].format == pSecondaryAttachments[pSecondary[index].attachment].format) &&
1105 (pPrimaryAttachments[pPrimary[index].attachment].samples == pSecondaryAttachments[pSecondary[index].attachment].samples))
1106 return true;
1107 }
1108 // Format and sample counts didn't match
1109 return false;
1110}
1111
1112// For give primary and secondary RenderPass objects, verify that they're compatible
1113static bool verify_renderpass_compatibility(layer_data* my_data, const VkRenderPass primaryRP, const VkRenderPass secondaryRP, string& errorMsg)
1114{
1115 stringstream errorStr;
1116 if (my_data->renderPassMap.find(primaryRP) == my_data->renderPassMap.end()) {
1117 errorStr << "invalid VkRenderPass (" << primaryRP << ")";
1118 errorMsg = errorStr.str();
1119 return false;
1120 } else if (my_data->renderPassMap.find(secondaryRP) == my_data->renderPassMap.end()) {
1121 errorStr << "invalid VkRenderPass (" << secondaryRP << ")";
1122 errorMsg = errorStr.str();
1123 return false;
1124 }
1125 // Trivial pass case is exact same RP
1126 if (primaryRP == secondaryRP)
1127 return true;
1128 const VkRenderPassCreateInfo* primaryRPCI = my_data->renderPassMap[primaryRP]->pCreateInfo;
1129 const VkRenderPassCreateInfo* secondaryRPCI = my_data->renderPassMap[secondaryRP]->pCreateInfo;
1130 if (primaryRPCI->subpassCount != secondaryRPCI->subpassCount) {
1131 errorStr << "RenderPass for primary cmdBuffer has " << primaryRPCI->subpassCount << " subpasses but renderPass for secondary cmdBuffer has " << secondaryRPCI->subpassCount << " subpasses.";
1132 errorMsg = errorStr.str();
1133 return false;
1134 }
1135 uint32_t spIndex = 0;
1136 for (spIndex = 0; spIndex < primaryRPCI->subpassCount; ++spIndex) {
1137 // For each subpass, verify that corresponding color, input, resolve & depth/stencil attachment references are compatible
1138 uint32_t primaryColorCount = primaryRPCI->pSubpasses[spIndex].colorAttachmentCount;
1139 uint32_t secondaryColorCount = secondaryRPCI->pSubpasses[spIndex].colorAttachmentCount;
1140 uint32_t colorMax = std::max(primaryColorCount, secondaryColorCount);
1141 for (uint32_t cIdx = 0; cIdx < colorMax; ++cIdx) {
1142 if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pColorAttachments, primaryColorCount, primaryRPCI->pAttachments,
1143 secondaryRPCI->pSubpasses[spIndex].pColorAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1144 errorStr << "color attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
1145 errorMsg = errorStr.str();
1146 return false;
1147 } else if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pResolveAttachments, primaryColorCount, primaryRPCI->pAttachments,
1148 secondaryRPCI->pSubpasses[spIndex].pResolveAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1149 errorStr << "resolve attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
1150 errorMsg = errorStr.str();
1151 return false;
1152 } else if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pDepthStencilAttachment, primaryColorCount, primaryRPCI->pAttachments,
1153 secondaryRPCI->pSubpasses[spIndex].pDepthStencilAttachment, secondaryColorCount, secondaryRPCI->pAttachments)) {
1154 errorStr << "depth/stencil attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
1155 errorMsg = errorStr.str();
1156 return false;
1157 }
1158 }
1159 uint32_t primaryInputCount = primaryRPCI->pSubpasses[spIndex].inputAttachmentCount;
1160 uint32_t secondaryInputCount = secondaryRPCI->pSubpasses[spIndex].inputAttachmentCount;
1161 uint32_t inputMax = std::max(primaryInputCount, secondaryInputCount);
1162 for (uint32_t i = 0; i < inputMax; ++i) {
1163 if (!attachment_references_compatible(i, primaryRPCI->pSubpasses[spIndex].pInputAttachments, primaryColorCount, primaryRPCI->pAttachments,
1164 secondaryRPCI->pSubpasses[spIndex].pInputAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1165 errorStr << "input attachments at index " << i << " of subpass index " << spIndex << " are not compatible.";
1166 errorMsg = errorStr.str();
1167 return false;
1168 }
1169 }
1170 }
1171 return true;
1172}
1173
Tobin Ehlis982099b2015-11-05 09:52:49 -07001174// For give SET_NODE, verify that its Set is compatible w/ the setLayout corresponding to pipelineLayout[layoutIndex]
1175static bool verify_set_layout_compatibility(layer_data* my_data, const SET_NODE* pSet, const VkPipelineLayout layout, const uint32_t layoutIndex, string& errorMsg)
1176{
Tobin Ehliscb085292015-12-01 09:57:09 -07001177 stringstream errorStr;
Tobin Ehlis982099b2015-11-05 09:52:49 -07001178 if (my_data->pipelineLayoutMap.find(layout) == my_data->pipelineLayoutMap.end()) {
Tobin Ehliscb085292015-12-01 09:57:09 -07001179 errorStr << "invalid VkPipelineLayout (" << layout << ")";
1180 errorMsg = errorStr.str();
Tobin Ehlis982099b2015-11-05 09:52:49 -07001181 return false;
1182 }
1183 PIPELINE_LAYOUT_NODE pl = my_data->pipelineLayoutMap[layout];
1184 if (layoutIndex >= pl.descriptorSetLayouts.size()) {
Tobin Ehliscb085292015-12-01 09:57:09 -07001185 errorStr << "VkPipelineLayout (" << layout << ") only contains " << pl.descriptorSetLayouts.size() << " setLayouts corresponding to sets 0-" << pl.descriptorSetLayouts.size()-1 << ", but you're attempting to bind set to index " << layoutIndex;
1186 errorMsg = errorStr.str();
Tobin Ehlis982099b2015-11-05 09:52:49 -07001187 return false;
1188 }
1189 // Get the specific setLayout from PipelineLayout that overlaps this set
Tobin Ehlisad61de42015-12-02 13:53:34 -07001190 LAYOUT_NODE* pLayoutNode = my_data->descriptorSetLayoutMap[pl.descriptorSetLayouts[layoutIndex]];
Tobin Ehlis982099b2015-11-05 09:52:49 -07001191 if (pLayoutNode->layout == pSet->pLayout->layout) { // trivial pass case
1192 return true;
1193 }
Courtney Goeltzenleuchter740451a2015-12-16 16:06:06 -07001194 size_t descriptorCount = pLayoutNode->descriptorTypes.size();
Tobin Ehlis982099b2015-11-05 09:52:49 -07001195 if (descriptorCount != pSet->pLayout->descriptorTypes.size()) {
Tobin Ehliscb085292015-12-01 09:57:09 -07001196 errorStr << "setLayout " << layoutIndex << " from pipelineLayout " << layout << " has " << descriptorCount << " descriptors, but corresponding set being bound has " << pSet->pLayout->descriptorTypes.size() << " descriptors.";
1197 errorMsg = errorStr.str();
Tobin Ehlis982099b2015-11-05 09:52:49 -07001198 return false; // trivial fail case
1199 }
1200 // Now need to check set against corresponding pipelineLayout to verify compatibility
Courtney Goeltzenleuchter740451a2015-12-16 16:06:06 -07001201 for (size_t i=0; i<descriptorCount; ++i) {
Tobin Ehlis982099b2015-11-05 09:52:49 -07001202 // Need to verify that layouts are identically defined
1203 // TODO : Is below sufficient? Making sure that types & stageFlags match per descriptor
1204 // do we also need to check immutable samplers?
1205 if (pLayoutNode->descriptorTypes[i] != pSet->pLayout->descriptorTypes[i]) {
Tobin Ehliscb085292015-12-01 09:57:09 -07001206 errorStr << "descriptor " << i << " for descriptorSet being bound is type '" << string_VkDescriptorType(pSet->pLayout->descriptorTypes[i]) << "' but corresponding descriptor from pipelineLayout is type '" << string_VkDescriptorType(pLayoutNode->descriptorTypes[i]) << "'";
1207 errorMsg = errorStr.str();
Tobin Ehlis982099b2015-11-05 09:52:49 -07001208 return false;
1209 }
1210 if (pLayoutNode->stageFlags[i] != pSet->pLayout->stageFlags[i]) {
Tobin Ehliscb085292015-12-01 09:57:09 -07001211 errorStr << "stageFlags " << i << " for descriptorSet being bound is " << pSet->pLayout->stageFlags[i] << "' but corresponding descriptor from pipelineLayout has stageFlags " << pLayoutNode->stageFlags[i];
1212 errorMsg = errorStr.str();
Tobin Ehlis982099b2015-11-05 09:52:49 -07001213 return false;
1214 }
1215 }
1216 return true;
1217}
1218
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07001219// Validate that the shaders used by the given pipeline
1220// As a side effect this function also records the sets that are actually used by the pipeline
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07001221static VkBool32
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07001222validate_pipeline_shaders(layer_data *my_data, VkDevice dev, PIPELINE_NODE* pPipeline)
Tobin Ehlis32479352015-12-01 09:48:58 -07001223{
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07001224 VkGraphicsPipelineCreateInfo const *pCreateInfo = &pPipeline->graphicsPipelineCI;
Tobin Ehlis32479352015-12-01 09:48:58 -07001225 /* We seem to allow pipeline stages to be specified out of order, so collect and identify them
1226 * before trying to do anything more: */
1227 int vertex_stage = get_shader_stage_id(VK_SHADER_STAGE_VERTEX_BIT);
1228 int geometry_stage = get_shader_stage_id(VK_SHADER_STAGE_GEOMETRY_BIT);
1229 int fragment_stage = get_shader_stage_id(VK_SHADER_STAGE_FRAGMENT_BIT);
1230
1231 shader_module **shaders = new shader_module*[fragment_stage + 1]; /* exclude CS */
1232 memset(shaders, 0, sizeof(shader_module *) * (fragment_stage +1));
Tobin Ehlisad61de42015-12-02 13:53:34 -07001233 RENDER_PASS_NODE const *rp = 0;
Tobin Ehlis32479352015-12-01 09:48:58 -07001234 VkPipelineVertexInputStateCreateInfo const *vi = 0;
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07001235 VkBool32 pass = true;
Tobin Ehlis32479352015-12-01 09:48:58 -07001236
1237 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
1238 VkPipelineShaderStageCreateInfo const *pStage = &pCreateInfo->pStages[i];
1239 if (pStage->sType == VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO) {
1240
1241 if ((pStage->stage & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_GEOMETRY_BIT | VK_SHADER_STAGE_FRAGMENT_BIT
1242 | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT)) == 0) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001243 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, 0, SHADER_CHECKER_UNKNOWN_STAGE, "SC",
Tobin Ehlis32479352015-12-01 09:48:58 -07001244 "Unknown shader stage %d", pStage->stage)) {
1245 pass = false;
1246 }
1247 }
1248 else {
Tobin Ehlisad61de42015-12-02 13:53:34 -07001249 shader_module *module = my_data->shaderModuleMap[pStage->module];
Tobin Ehlis32479352015-12-01 09:48:58 -07001250 shaders[get_shader_stage_id(pStage->stage)] = module;
1251
1252 /* validate descriptor set layout against what the spirv module actually uses */
1253 std::map<std::pair<unsigned, unsigned>, interface_var> descriptor_uses;
1254 collect_interface_by_descriptor_slot(my_data, dev, module, spv::StorageClassUniform,
1255 descriptor_uses);
1256
Tobin Ehlisad61de42015-12-02 13:53:34 -07001257 auto layouts = pCreateInfo->layout != VK_NULL_HANDLE ?
1258 &(my_data->pipelineLayoutMap[pCreateInfo->layout].descriptorSetLayouts) : nullptr;
Tobin Ehlis32479352015-12-01 09:48:58 -07001259
1260 for (auto it = descriptor_uses.begin(); it != descriptor_uses.end(); it++) {
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07001261 // As a side-effect of this function, capture which sets are used by the pipeline
1262 pPipeline->active_sets.insert(it->first.first);
Tobin Ehlis32479352015-12-01 09:48:58 -07001263
1264 /* find the matching binding */
Tobin Ehlisad61de42015-12-02 13:53:34 -07001265 auto found = has_descriptor_binding(my_data, layouts, it->first);
Tobin Ehlis32479352015-12-01 09:48:58 -07001266
1267 if (!found) {
1268 char type_name[1024];
1269 describe_type(type_name, module, it->second.type_id);
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001270 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, 0,
Tobin Ehlis32479352015-12-01 09:48:58 -07001271 SHADER_CHECKER_MISSING_DESCRIPTOR, "SC",
1272 "Shader uses descriptor slot %u.%u (used as type `%s`) but not declared in pipeline layout",
1273 it->first.first, it->first.second, type_name)) {
1274 pass = false;
1275 }
1276 }
1277 }
1278 }
1279 }
1280 }
1281
1282 if (pCreateInfo->renderPass != VK_NULL_HANDLE)
Tobin Ehlisad61de42015-12-02 13:53:34 -07001283 rp = my_data->renderPassMap[pCreateInfo->renderPass];
Tobin Ehlis32479352015-12-01 09:48:58 -07001284
1285 vi = pCreateInfo->pVertexInputState;
1286
1287 if (vi) {
1288 pass = validate_vi_consistency(my_data, dev, vi) && pass;
1289 }
1290
1291 if (shaders[vertex_stage]) {
1292 pass = validate_vi_against_vs_inputs(my_data, dev, vi, shaders[vertex_stage]) && pass;
1293 }
1294
1295 /* TODO: enforce rules about present combinations of shaders */
1296 int producer = get_shader_stage_id(VK_SHADER_STAGE_VERTEX_BIT);
1297 int consumer = get_shader_stage_id(VK_SHADER_STAGE_GEOMETRY_BIT);
1298
1299 while (!shaders[producer] && producer != fragment_stage) {
1300 producer++;
1301 consumer++;
1302 }
1303
1304 for (; producer != fragment_stage && consumer <= fragment_stage; consumer++) {
1305 assert(shaders[producer]);
1306 if (shaders[consumer]) {
1307 pass = validate_interface_between_stages(my_data, dev,
1308 shaders[producer], shader_stage_attribs[producer].name,
1309 shaders[consumer], shader_stage_attribs[consumer].name,
1310 shader_stage_attribs[consumer].arrayed_input) && pass;
1311
1312 producer = consumer;
1313 }
1314 }
1315
1316 if (shaders[fragment_stage] && rp) {
1317 pass = validate_fs_outputs_against_render_pass(my_data, dev, shaders[fragment_stage], rp, pCreateInfo->subpass) && pass;
1318 }
1319
1320 delete shaders;
1321
1322 return pass;
1323}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001324
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06001325// Validate overall state at the time of a draw call
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06001326static VkBool32 validate_draw_state(layer_data* my_data, GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06001327 // First check flag states
Tobin Ehlis42d440c2015-10-20 17:06:16 -06001328 VkBool32 result = validate_draw_state_flags(my_data, pCB, indexedDraw);
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06001329 PIPELINE_NODE* pPipe = getPipeline(my_data, pCB->lastBoundPipeline);
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06001330 // Now complete other state checks
Tobin Ehlis12ab7dc2015-09-09 13:31:01 -06001331 // TODO : Currently only performing next check if *something* was bound (non-zero last bound)
1332 // There is probably a better way to gate when this check happens, and to know if something *should* have been bound
1333 // We should have that check separately and then gate this check based on that check
Mark Lobodzinski611cf592015-12-18 15:35:38 -07001334 if (pPipe) {
1335 if (pCB->lastBoundPipelineLayout) {
1336 string errorString;
1337 for (auto setIndex : pPipe->active_sets) {
1338 // If valid set is not bound throw an error
1339 if ((pCB->boundDescriptorSets.size() <= setIndex) || (!pCB->boundDescriptorSets[setIndex])) {
1340 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_DESCRIPTOR_SET_NOT_BOUND, "DS",
1341 "VkPipeline %#" PRIxLEAST64 " uses set #%u but that set is not bound.", (uint64_t)pPipe->pipeline, setIndex);
1342 } else if (!verify_set_layout_compatibility(my_data, my_data->setMap[pCB->boundDescriptorSets[setIndex]], pPipe->graphicsPipelineCI.layout, setIndex, errorString)) {
1343 // Set is bound but not compatible w/ overlapping pipelineLayout from PSO
1344 VkDescriptorSet setHandle = my_data->setMap[pCB->boundDescriptorSets[setIndex]]->set;
1345 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t)setHandle, 0, DRAWSTATE_PIPELINE_LAYOUTS_INCOMPATIBLE, "DS",
1346 "VkDescriptorSet (%#" PRIxLEAST64 ") bound as set #%u is not compatible with overlapping VkPipelineLayout %#" PRIxLEAST64 " due to: %s",
1347 (uint64_t)setHandle, setIndex, (uint64_t)pPipe->graphicsPipelineCI.layout, errorString.c_str());
1348 }
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07001349 }
1350 }
Mark Lobodzinski74e84692015-12-14 15:14:10 -07001351
Mark Lobodzinski611cf592015-12-18 15:35:38 -07001352 // Verify Vtx binding
1353 if (pPipe->vtxBindingCount > 0) {
1354 VkPipelineVertexInputStateCreateInfo *vtxInCI = &pPipe->vertexInputCI;
1355 for (uint32_t i = 0; i < vtxInCI->vertexBindingDescriptionCount; i++) {
1356 if ((pCB->boundVtxBuffers.size() < (i+1)) || (pCB->boundVtxBuffers[i] == VK_NULL_HANDLE)) {
1357 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS",
1358 "The Pipeline State Object (%#" PRIxLEAST64 ") expects that this Command Buffer's vertex binding Index %d should be set via vkCmdBindVertexBuffers.",
1359 (uint64_t)pCB->lastBoundPipeline, i);
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001360
Mark Lobodzinski611cf592015-12-18 15:35:38 -07001361 }
1362 }
1363 } else {
1364 if (!pCB->boundVtxBuffers.empty()) {
1365 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS,
1366 "DS", "Vertex buffers are bound to command buffer (%#" PRIxLEAST64 ") but no vertex buffers are attached to this Pipeline State Object (%#" PRIxLEAST64 ").",
1367 (uint64_t)pCB->commandBuffer, (uint64_t)pCB->lastBoundPipeline);
Tobin Ehlisd28acef2015-09-09 15:12:35 -06001368 }
1369 }
Mark Lobodzinski74e84692015-12-14 15:14:10 -07001370
Mark Lobodzinski611cf592015-12-18 15:35:38 -07001371 // If Viewport or scissors are dynamic, verify that dynamic count matches PSO count
1372 VkBool32 dynViewport = isDynamic(pPipe, VK_DYNAMIC_STATE_VIEWPORT);
1373 VkBool32 dynScissor = isDynamic(pPipe, VK_DYNAMIC_STATE_SCISSOR);
1374 if (dynViewport) {
1375 if (pCB->viewports.size() != pPipe->graphicsPipelineCI.pViewportState->viewportCount) {
1376 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
1377 "Dynamic viewportCount from vkCmdSetViewport() is " PRINTF_SIZE_T_SPECIFIER ", but PSO viewportCount is %u. These counts must match.", pCB->viewports.size(), pPipe->graphicsPipelineCI.pViewportState->viewportCount);
1378 }
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06001379 }
Mark Lobodzinski611cf592015-12-18 15:35:38 -07001380 if (dynScissor) {
1381 if (pCB->scissors.size() != pPipe->graphicsPipelineCI.pViewportState->scissorCount) {
1382 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
1383 "Dynamic scissorCount from vkCmdSetScissor() is " PRINTF_SIZE_T_SPECIFIER ", but PSO scissorCount is %u. These counts must match.", pCB->scissors.size(), pPipe->graphicsPipelineCI.pViewportState->scissorCount);
1384 }
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06001385 }
1386 }
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06001387 return result;
1388}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001389
Tobin Ehlisde63c532015-06-18 15:59:33 -06001390// Verify that create state for a pipeline is valid
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07001391static VkBool32 verifyPipelineCreateState(layer_data* my_data, const VkDevice device, PIPELINE_NODE* pPipeline)
Tobin Ehlisde63c532015-06-18 15:59:33 -06001392{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001393 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski312274f2015-12-16 14:25:22 -07001394
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07001395 if (!validate_pipeline_shaders(my_data, device, pPipeline)) {
Tobin Ehlisad61de42015-12-02 13:53:34 -07001396 skipCall = VK_TRUE;
1397 }
Mark Lobodzinski312274f2015-12-16 14:25:22 -07001398
Tobin Ehlisde63c532015-06-18 15:59:33 -06001399 // VS is required
1400 if (!(pPipeline->active_shaders & VK_SHADER_STAGE_VERTEX_BIT)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001401 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlisde63c532015-06-18 15:59:33 -06001402 "Invalid Pipeline CreateInfo State: Vtx Shader required");
Tobin Ehlisde63c532015-06-18 15:59:33 -06001403 }
1404 // Either both or neither TC/TE shaders should be defined
Courtney Goeltzenleuchterc6fd2262015-10-15 17:35:38 -06001405 if (((pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) == 0) !=
1406 ((pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) == 0) ) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001407 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlisde63c532015-06-18 15:59:33 -06001408 "Invalid Pipeline CreateInfo State: TE and TC shaders must be included or excluded as a pair");
Tobin Ehlisde63c532015-06-18 15:59:33 -06001409 }
1410 // Compute shaders should be specified independent of Gfx shaders
1411 if ((pPipeline->active_shaders & VK_SHADER_STAGE_COMPUTE_BIT) &&
Courtney Goeltzenleuchterc6fd2262015-10-15 17:35:38 -06001412 (pPipeline->active_shaders & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT |
1413 VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT | VK_SHADER_STAGE_GEOMETRY_BIT |
Tobin Ehlisde63c532015-06-18 15:59:33 -06001414 VK_SHADER_STAGE_FRAGMENT_BIT))) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001415 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlisde63c532015-06-18 15:59:33 -06001416 "Invalid Pipeline CreateInfo State: Do not specify Compute Shader for Gfx Pipeline");
Tobin Ehlisde63c532015-06-18 15:59:33 -06001417 }
Chia-I Wu99ba2bb2015-10-31 00:31:16 +08001418 // VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology is only valid for tessellation pipelines.
Tobin Ehlisde63c532015-06-18 15:59:33 -06001419 // Mismatching primitive topology and tessellation fails graphics pipeline creation.
Courtney Goeltzenleuchterc6fd2262015-10-15 17:35:38 -06001420 if (pPipeline->active_shaders & (VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) &&
Chia-I Wu99ba2bb2015-10-31 00:31:16 +08001421 (pPipeline->iaStateCI.topology != VK_PRIMITIVE_TOPOLOGY_PATCH_LIST)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001422 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Chia-I Wu99ba2bb2015-10-31 00:31:16 +08001423 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH_LIST must be set as IA topology for tessellation pipelines");
Tobin Ehlisde63c532015-06-18 15:59:33 -06001424 }
Chia-I Wu99ba2bb2015-10-31 00:31:16 +08001425 if (pPipeline->iaStateCI.topology == VK_PRIMITIVE_TOPOLOGY_PATCH_LIST) {
Courtney Goeltzenleuchterc6fd2262015-10-15 17:35:38 -06001426 if (~pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001427 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Chia-I Wu99ba2bb2015-10-31 00:31:16 +08001428 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology is only valid for tessellation pipelines");
Tobin Ehlis20693172015-09-17 08:46:18 -06001429 }
1430 if (!pPipeline->tessStateCI.patchControlPoints || (pPipeline->tessStateCI.patchControlPoints > 32)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001431 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Chia-I Wu99ba2bb2015-10-31 00:31:16 +08001432 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology used with patchControlPoints value %u."
Tobin Ehlis20693172015-09-17 08:46:18 -06001433 " patchControlPoints should be >0 and <=32.", pPipeline->tessStateCI.patchControlPoints);
1434 }
Tobin Ehlisde63c532015-06-18 15:59:33 -06001435 }
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06001436 // Viewport state must be included and viewport and scissor counts should always match
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001437 // NOTE : Even if these are flagged as dynamic, counts need to be set correctly for shader compiler
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06001438 if (!pPipeline->graphicsPipelineCI.pViewportState) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001439 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06001440 "Gfx Pipeline pViewportState is null. Even if viewport and scissors are dynamic PSO must include viewportCount and scissorCount in pViewportState.");
1441 } else if (pPipeline->graphicsPipelineCI.pViewportState->scissorCount != pPipeline->graphicsPipelineCI.pViewportState->viewportCount) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001442 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001443 "Gfx Pipeline viewport count (%u) must match scissor count (%u).", pPipeline->vpStateCI.viewportCount, pPipeline->vpStateCI.scissorCount);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06001444 } else {
1445 // If viewport or scissor are not dynamic, then verify that data is appropriate for count
1446 VkBool32 dynViewport = isDynamic(pPipeline, VK_DYNAMIC_STATE_VIEWPORT);
1447 VkBool32 dynScissor = isDynamic(pPipeline, VK_DYNAMIC_STATE_SCISSOR);
1448 if (!dynViewport) {
1449 if (pPipeline->graphicsPipelineCI.pViewportState->viewportCount && !pPipeline->graphicsPipelineCI.pViewportState->pViewports) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001450 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
Courtney Goeltzenleuchter95e6dba2015-11-25 11:38:54 -07001451 "Gfx Pipeline viewportCount is %u, but pViewports is NULL. For non-zero viewportCount, you must either include pViewports data, or include viewport in pDynamicState and set it with vkCmdSetViewport().", pPipeline->graphicsPipelineCI.pViewportState->viewportCount);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001452 }
1453 }
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06001454 if (!dynScissor) {
1455 if (pPipeline->graphicsPipelineCI.pViewportState->scissorCount && !pPipeline->graphicsPipelineCI.pViewportState->pScissors) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001456 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
Courtney Goeltzenleuchter95e6dba2015-11-25 11:38:54 -07001457 "Gfx Pipeline scissorCount is %u, but pScissors is NULL. For non-zero scissorCount, you must either include pScissors data, or include scissor in pDynamicState and set it with vkCmdSetScissor().", pPipeline->graphicsPipelineCI.pViewportState->scissorCount);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06001458 }
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001459 }
1460 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001461 return skipCall;
Tobin Ehlisde63c532015-06-18 15:59:33 -06001462}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001463
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001464// Init the pipeline mapping info based on pipeline create info LL tree
1465// Threading note : Calls to this function should wrapped in mutex
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07001466// TODO : this should really just be in the constructor for PIPELINE_NODE
Mark Lobodzinski2adea752015-11-10 15:25:01 -07001467static PIPELINE_NODE* initGraphicsPipeline(layer_data* dev_data, const VkGraphicsPipelineCreateInfo* pCreateInfo, PIPELINE_NODE* pBasePipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001468{
Tobin Ehlisde63c532015-06-18 15:59:33 -06001469 PIPELINE_NODE* pPipeline = new PIPELINE_NODE;
Mark Lobodzinskie443d2b2015-12-11 11:56:07 -07001470
Tobin Ehlisde63c532015-06-18 15:59:33 -06001471 if (pBasePipeline) {
Mark Lobodzinskie443d2b2015-12-11 11:56:07 -07001472 *pPipeline = *pBasePipeline;
Tobin Ehlisde63c532015-06-18 15:59:33 -06001473 }
Mark Lobodzinskie443d2b2015-12-11 11:56:07 -07001474
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001475 // First init create info
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001476 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001477
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001478 size_t bufferSize = 0;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001479 const VkPipelineVertexInputStateCreateInfo* pVICI = NULL;
Tobin Ehlis59db5712015-07-13 13:14:24 -06001480 const VkPipelineColorBlendStateCreateInfo* pCBCI = NULL;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001481
1482 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
1483 const VkPipelineShaderStageCreateInfo *pPSSCI = &pCreateInfo->pStages[i];
1484
Chia-I Wu062ad152015-10-31 00:31:16 +08001485 switch (pPSSCI->stage) {
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001486 case VK_SHADER_STAGE_VERTEX_BIT:
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001487 memcpy(&pPipeline->vsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1488 pPipeline->active_shaders |= VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001489 break;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001490 case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT:
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001491 memcpy(&pPipeline->tcsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Courtney Goeltzenleuchterc6fd2262015-10-15 17:35:38 -06001492 pPipeline->active_shaders |= VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001493 break;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001494 case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT:
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001495 memcpy(&pPipeline->tesCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Courtney Goeltzenleuchterc6fd2262015-10-15 17:35:38 -06001496 pPipeline->active_shaders |= VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001497 break;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001498 case VK_SHADER_STAGE_GEOMETRY_BIT:
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001499 memcpy(&pPipeline->gsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1500 pPipeline->active_shaders |= VK_SHADER_STAGE_GEOMETRY_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001501 break;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001502 case VK_SHADER_STAGE_FRAGMENT_BIT:
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001503 memcpy(&pPipeline->fsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1504 pPipeline->active_shaders |= VK_SHADER_STAGE_FRAGMENT_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001505 break;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001506 case VK_SHADER_STAGE_COMPUTE_BIT:
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001507 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
1508 pPipeline->active_shaders |= VK_SHADER_STAGE_COMPUTE_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001509 break;
1510 default:
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001511 // TODO : Flag error
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001512 break;
1513 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001514 }
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001515 // Copy over GraphicsPipelineCreateInfo structure embedded pointers
1516 if (pCreateInfo->stageCount != 0) {
1517 pPipeline->graphicsPipelineCI.pStages = new VkPipelineShaderStageCreateInfo[pCreateInfo->stageCount];
1518 bufferSize = pCreateInfo->stageCount * sizeof(VkPipelineShaderStageCreateInfo);
1519 memcpy((void*)pPipeline->graphicsPipelineCI.pStages, pCreateInfo->pStages, bufferSize);
1520 }
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001521 if (pCreateInfo->pVertexInputState != NULL) {
1522 memcpy((void*)&pPipeline->vertexInputCI, pCreateInfo->pVertexInputState , sizeof(VkPipelineVertexInputStateCreateInfo));
1523 // Copy embedded ptrs
1524 pVICI = pCreateInfo->pVertexInputState;
Chia-I Wu763a7492015-10-26 20:48:51 +08001525 pPipeline->vtxBindingCount = pVICI->vertexBindingDescriptionCount;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001526 if (pPipeline->vtxBindingCount) {
1527 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
1528 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
1529 memcpy((void*)pPipeline->pVertexBindingDescriptions, pVICI->pVertexBindingDescriptions, bufferSize);
1530 }
Chia-I Wu763a7492015-10-26 20:48:51 +08001531 pPipeline->vtxAttributeCount = pVICI->vertexAttributeDescriptionCount;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001532 if (pPipeline->vtxAttributeCount) {
1533 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
1534 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
1535 memcpy((void*)pPipeline->pVertexAttributeDescriptions, pVICI->pVertexAttributeDescriptions, bufferSize);
1536 }
1537 pPipeline->graphicsPipelineCI.pVertexInputState = &pPipeline->vertexInputCI;
1538 }
Tony Barboure307f582015-07-10 15:29:03 -06001539 if (pCreateInfo->pInputAssemblyState != NULL) {
1540 memcpy((void*)&pPipeline->iaStateCI, pCreateInfo->pInputAssemblyState, sizeof(VkPipelineInputAssemblyStateCreateInfo));
1541 pPipeline->graphicsPipelineCI.pInputAssemblyState = &pPipeline->iaStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001542 }
Tony Barboure307f582015-07-10 15:29:03 -06001543 if (pCreateInfo->pTessellationState != NULL) {
1544 memcpy((void*)&pPipeline->tessStateCI, pCreateInfo->pTessellationState, sizeof(VkPipelineTessellationStateCreateInfo));
1545 pPipeline->graphicsPipelineCI.pTessellationState = &pPipeline->tessStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001546 }
Tony Barboure307f582015-07-10 15:29:03 -06001547 if (pCreateInfo->pViewportState != NULL) {
1548 memcpy((void*)&pPipeline->vpStateCI, pCreateInfo->pViewportState, sizeof(VkPipelineViewportStateCreateInfo));
1549 pPipeline->graphicsPipelineCI.pViewportState = &pPipeline->vpStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001550 }
Chia-I Wu1f851912015-10-27 18:04:07 +08001551 if (pCreateInfo->pRasterizationState != NULL) {
1552 memcpy((void*)&pPipeline->rsStateCI, pCreateInfo->pRasterizationState, sizeof(VkPipelineRasterizationStateCreateInfo));
1553 pPipeline->graphicsPipelineCI.pRasterizationState = &pPipeline->rsStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001554 }
Tony Barboure307f582015-07-10 15:29:03 -06001555 if (pCreateInfo->pMultisampleState != NULL) {
1556 memcpy((void*)&pPipeline->msStateCI, pCreateInfo->pMultisampleState, sizeof(VkPipelineMultisampleStateCreateInfo));
1557 pPipeline->graphicsPipelineCI.pMultisampleState = &pPipeline->msStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001558 }
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001559 if (pCreateInfo->pDepthStencilState != NULL) {
1560 memcpy((void*)&pPipeline->dsStateCI, pCreateInfo->pDepthStencilState, sizeof(VkPipelineDepthStencilStateCreateInfo));
1561 pPipeline->graphicsPipelineCI.pDepthStencilState = &pPipeline->dsStateCI;
1562 }
Tony Barboure307f582015-07-10 15:29:03 -06001563 if (pCreateInfo->pColorBlendState != NULL) {
1564 memcpy((void*)&pPipeline->cbStateCI, pCreateInfo->pColorBlendState, sizeof(VkPipelineColorBlendStateCreateInfo));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001565 // Copy embedded ptrs
Tony Barboure307f582015-07-10 15:29:03 -06001566 pCBCI = pCreateInfo->pColorBlendState;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001567 pPipeline->attachmentCount = pCBCI->attachmentCount;
1568 if (pPipeline->attachmentCount) {
Tony Barboure307f582015-07-10 15:29:03 -06001569 pPipeline->pAttachments = new VkPipelineColorBlendAttachmentState[pPipeline->attachmentCount];
1570 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineColorBlendAttachmentState);
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001571 memcpy((void*)pPipeline->pAttachments, pCBCI->pAttachments, bufferSize);
1572 }
Tony Barboure307f582015-07-10 15:29:03 -06001573 pPipeline->graphicsPipelineCI.pColorBlendState = &pPipeline->cbStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001574 }
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001575 if (pCreateInfo->pDynamicState != NULL) {
1576 memcpy((void*)&pPipeline->dynStateCI, pCreateInfo->pDynamicState, sizeof(VkPipelineDynamicStateCreateInfo));
1577 if (pPipeline->dynStateCI.dynamicStateCount) {
1578 pPipeline->dynStateCI.pDynamicStates = new VkDynamicState[pPipeline->dynStateCI.dynamicStateCount];
1579 bufferSize = pPipeline->dynStateCI.dynamicStateCount * sizeof(VkDynamicState);
1580 memcpy((void*)pPipeline->dynStateCI.pDynamicStates, pCreateInfo->pDynamicState->pDynamicStates, bufferSize);
1581 }
1582 pPipeline->graphicsPipelineCI.pDynamicState = &pPipeline->dynStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001583 }
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07001584 pPipeline->active_sets.clear();
Tobin Ehlisde63c532015-06-18 15:59:33 -06001585 return pPipeline;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001586}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001587
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001588// Free the Pipeline nodes
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06001589static void deletePipelines(layer_data* my_data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001590{
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06001591 if (my_data->pipelineMap.size() <= 0)
David Pinedof5997ab2015-04-27 16:36:17 -06001592 return;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06001593 for (auto ii=my_data->pipelineMap.begin(); ii!=my_data->pipelineMap.end(); ++ii) {
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001594 if ((*ii).second->graphicsPipelineCI.stageCount != 0) {
1595 delete[] (*ii).second->graphicsPipelineCI.pStages;
1596 }
Tobin Ehliscd3109e2015-04-01 11:59:08 -06001597 if ((*ii).second->pVertexBindingDescriptions) {
1598 delete[] (*ii).second->pVertexBindingDescriptions;
1599 }
1600 if ((*ii).second->pVertexAttributeDescriptions) {
1601 delete[] (*ii).second->pVertexAttributeDescriptions;
1602 }
1603 if ((*ii).second->pAttachments) {
1604 delete[] (*ii).second->pAttachments;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001605 }
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001606 if ((*ii).second->dynStateCI.dynamicStateCount != 0) {
1607 delete[] (*ii).second->dynStateCI.pDynamicStates;
1608 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001609 delete (*ii).second;
1610 }
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06001611 my_data->pipelineMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001612}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001613
Tobin Ehlis2464b882015-04-01 08:40:34 -06001614// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001615static VkSampleCountFlagBits getNumSamples(layer_data* my_data, const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -06001616{
Chia-I Wue420a332015-10-26 20:04:44 +08001617 PIPELINE_NODE* pPipe = my_data->pipelineMap[pipeline];
Tobin Ehlisb3a506f2015-07-13 14:51:15 -06001618 if (VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
Chia-I Wu1f851912015-10-27 18:04:07 +08001619 return pPipe->msStateCI.rasterizationSamples;
Tobin Ehlisb3a506f2015-07-13 14:51:15 -06001620 }
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001621 return VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis2464b882015-04-01 08:40:34 -06001622}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001623
Tobin Ehlis2464b882015-04-01 08:40:34 -06001624// Validate state related to the PSO
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06001625static VkBool32 validatePipelineState(layer_data* my_data, const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -06001626{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001627 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06001628 // Verify that any MSAA request in PSO matches sample# in bound FB
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001629 VkSampleCountFlagBits psoNumSamples = getNumSamples(my_data, pipeline);
Tobin Ehlis2464b882015-04-01 08:40:34 -06001630 if (pCB->activeRenderPass) {
Tobin Ehlisad61de42015-12-02 13:53:34 -07001631 const VkRenderPassCreateInfo* pRPCI = my_data->renderPassMap[pCB->activeRenderPass]->pCreateInfo;
Chia-I Wuc278df82015-07-07 11:50:03 +08001632 const VkSubpassDescription* pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001633 VkSampleCountFlagBits subpassNumSamples = (VkSampleCountFlagBits) 0;
Chia-I Wuc278df82015-07-07 11:50:03 +08001634 uint32_t i;
1635
Chia-I Wu763a7492015-10-26 20:48:51 +08001636 for (i = 0; i < pSD->colorAttachmentCount; i++) {
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001637 VkSampleCountFlagBits samples;
Chia-I Wuc278df82015-07-07 11:50:03 +08001638
Cody Northrop6de6b0b2015-08-04 11:16:41 -06001639 if (pSD->pColorAttachments[i].attachment == VK_ATTACHMENT_UNUSED)
Chia-I Wuc278df82015-07-07 11:50:03 +08001640 continue;
1641
Cody Northrop6de6b0b2015-08-04 11:16:41 -06001642 samples = pRPCI->pAttachments[pSD->pColorAttachments[i].attachment].samples;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001643 if (subpassNumSamples == (VkSampleCountFlagBits) 0) {
Chia-I Wuc278df82015-07-07 11:50:03 +08001644 subpassNumSamples = samples;
1645 } else if (subpassNumSamples != samples) {
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001646 subpassNumSamples = (VkSampleCountFlagBits) -1;
Chia-I Wuc278df82015-07-07 11:50:03 +08001647 break;
1648 }
1649 }
Chia-I Wuce532f72015-10-26 17:32:47 +08001650 if (pSD->pDepthStencilAttachment && pSD->pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001651 const VkSampleCountFlagBits samples = pRPCI->pAttachments[pSD->pDepthStencilAttachment->attachment].samples;
1652 if (subpassNumSamples == (VkSampleCountFlagBits) 0)
Chia-I Wuc278df82015-07-07 11:50:03 +08001653 subpassNumSamples = samples;
1654 else if (subpassNumSamples != samples)
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001655 subpassNumSamples = (VkSampleCountFlagBits) -1;
Chia-I Wuc278df82015-07-07 11:50:03 +08001656 }
1657
1658 if (psoNumSamples != subpassNumSamples) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001659 return log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, (uint64_t) pipeline, 0, DRAWSTATE_NUM_SAMPLES_MISMATCH, "DS",
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06001660 "Num samples mismatch! Binding PSO (%#" PRIxLEAST64 ") with %u samples while current RenderPass (%#" PRIxLEAST64 ") w/ %u samples!",
Chia-I Wue420a332015-10-26 20:04:44 +08001661 (uint64_t) pipeline, psoNumSamples, (uint64_t) pCB->activeRenderPass, subpassNumSamples);
Tobin Ehlis2464b882015-04-01 08:40:34 -06001662 }
1663 } else {
1664 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
1665 // Verify and flag error as appropriate
1666 }
1667 // TODO : Add more checks here
1668 } else {
1669 // TODO : Validate non-gfx pipeline updates
1670 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001671 return VK_FALSE;
Tobin Ehlis2464b882015-04-01 08:40:34 -06001672}
1673
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001674// Block of code at start here specifically for managing/tracking DSs
1675
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001676// Return Pool node ptr for specified pool or else NULL
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07001677static DESCRIPTOR_POOL_NODE* getPoolNode(layer_data* my_data, const VkDescriptorPool pool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001678{
1679 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07001680 if (my_data->descriptorPoolMap.find(pool) == my_data->descriptorPoolMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001681 loader_platform_thread_unlock_mutex(&globalLock);
1682 return NULL;
1683 }
1684 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07001685 return my_data->descriptorPoolMap[pool];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001686}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001687
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001688// Return Set node ptr for specified set or else NULL
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06001689static SET_NODE* getSetNode(layer_data* my_data, const VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001690{
1691 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue420a332015-10-26 20:04:44 +08001692 if (my_data->setMap.find(set) == my_data->setMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001693 loader_platform_thread_unlock_mutex(&globalLock);
1694 return NULL;
1695 }
1696 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wue420a332015-10-26 20:04:44 +08001697 return my_data->setMap[set];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001698}
1699
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06001700static LAYOUT_NODE* getLayoutNode(layer_data* my_data, const VkDescriptorSetLayout layout) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001701 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisad61de42015-12-02 13:53:34 -07001702 if (my_data->descriptorSetLayoutMap.find(layout) == my_data->descriptorSetLayoutMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001703 loader_platform_thread_unlock_mutex(&globalLock);
1704 return NULL;
1705 }
1706 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisad61de42015-12-02 13:53:34 -07001707 return my_data->descriptorSetLayoutMap[layout];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001708}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001709
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001710// Return VK_FALSE if update struct is of valid type, otherwise flag error and return code from callback
Tobin Ehlis42d440c2015-10-20 17:06:16 -06001711static VkBool32 validUpdateStruct(layer_data* my_data, const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001712{
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001713 switch (pUpdateStruct->sType)
1714 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001715 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1716 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001717 return VK_FALSE;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001718 default:
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001719 return log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001720 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001721 }
1722}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001723
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001724// Set count for given update struct in the last parameter
Courtney Goeltzenleuchter5bc11202015-12-16 16:08:44 -07001725// Return value of skipCall, which is only VK_TRUE if error occurs and callback signals execution to cease
Tobin Ehlise66ec962015-10-27 12:54:50 -06001726static uint32_t getUpdateCount(layer_data* my_data, const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001727{
1728 switch (pUpdateStruct->sType)
1729 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001730 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
Chia-I Wu763a7492015-10-26 20:48:51 +08001731 return ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorCount;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001732 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001733 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wu763a7492015-10-26 20:48:51 +08001734 return ((VkCopyDescriptorSet*)pUpdateStruct)->descriptorCount;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001735 }
Courtney Goeltzenleuchter902a0862015-12-16 16:08:08 -07001736
1737 return 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001738}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001739
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001740// For given Layout Node and binding, return index where that binding begins
1741static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
1742{
1743 uint32_t offsetIndex = 0;
Chia-I Wub5689ee2015-10-31 00:31:16 +08001744 for (uint32_t i = 0; i < pLayout->createInfo.bindingCount; i++) {
1745 if (pLayout->createInfo.pBinding[i].binding == binding)
1746 break;
Chia-I Wu045654f2015-11-06 06:42:02 +08001747 offsetIndex += pLayout->createInfo.pBinding[i].descriptorCount;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001748 }
1749 return offsetIndex;
1750}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001751
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001752// For given layout node and binding, return last index that is updated
1753static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
1754{
1755 uint32_t offsetIndex = 0;
Chia-I Wub5689ee2015-10-31 00:31:16 +08001756 for (uint32_t i = 0; i < pLayout->createInfo.bindingCount; i++) {
Chia-I Wu045654f2015-11-06 06:42:02 +08001757 offsetIndex += pLayout->createInfo.pBinding[i].descriptorCount;
Chia-I Wub5689ee2015-10-31 00:31:16 +08001758 if (pLayout->createInfo.pBinding[i].binding == binding)
1759 break;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001760 }
1761 return offsetIndex-1;
1762}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001763
Tobin Ehlise66ec962015-10-27 12:54:50 -06001764// For given layout and update, return the first overall index of the layout that is updated
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06001765static uint32_t getUpdateStartIndex(layer_data* my_data, const VkDevice device, const LAYOUT_NODE* pLayout, const uint32_t binding, const uint32_t arrayIndex, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001766{
Tobin Ehlise66ec962015-10-27 12:54:50 -06001767 return getBindingStartIndex(pLayout, binding)+arrayIndex;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001768}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001769
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06001770// For given layout and update, return the last overall index of the layout that is updated
1771static uint32_t getUpdateEndIndex(layer_data* my_data, const VkDevice device, const LAYOUT_NODE* pLayout, const uint32_t binding, const uint32_t arrayIndex, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001772{
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06001773 uint32_t count = getUpdateCount(my_data, device, pUpdateStruct);
Tobin Ehlise66ec962015-10-27 12:54:50 -06001774 return getBindingStartIndex(pLayout, binding)+arrayIndex+count-1;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001775}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001776
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001777// Verify that the descriptor type in the update struct matches what's expected by the layout
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001778static VkBool32 validateUpdateConsistency(layer_data* my_data, const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct, uint32_t startIndex, uint32_t endIndex)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001779{
1780 // First get actual type of update
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001781 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001782 VkDescriptorType actualType;
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001783 uint32_t i = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001784 switch (pUpdateStruct->sType)
1785 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001786 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1787 actualType = ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001788 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001789 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
1790 /* no need to validate */
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001791 return VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001792 break;
1793 default:
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001794 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001795 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001796 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001797 if (VK_FALSE == skipCall) {
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001798 // Set first stageFlags as reference and verify that all other updates match it
1799 VkShaderStageFlags refStageFlags = pLayout->stageFlags[startIndex];
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001800 for (i = startIndex; i <= endIndex; i++) {
Tobin Ehlis91423d22015-10-20 10:11:55 -06001801 if (pLayout->descriptorTypes[i] != actualType) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001802 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, "DS",
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001803 "Write descriptor update has descriptor type %s that does not match overlapping binding descriptor type of %s!",
1804 string_VkDescriptorType(actualType), string_VkDescriptorType(pLayout->descriptorTypes[i]));
1805 }
1806 if (pLayout->stageFlags[i] != refStageFlags) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001807 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_DESCRIPTOR_STAGEFLAGS_MISMATCH, "DS",
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001808 "Write descriptor update has stageFlags %x that do not match overlapping binding descriptor stageFlags of %x!",
1809 refStageFlags, pLayout->stageFlags[i]);
Tobin Ehlis3b341092015-09-30 08:30:20 -06001810 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001811 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001812 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001813 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001814}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001815
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001816// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001817// struct into the pNewNode param. Return VK_TRUE if error condition encountered and callback signals early exit.
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001818// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlis42d440c2015-10-20 17:06:16 -06001819static VkBool32 shadowUpdateNode(layer_data* my_data, const VkDevice device, GENERIC_HEADER* pUpdate, GENERIC_HEADER** pNewNode)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001820{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001821 VkBool32 skipCall = VK_FALSE;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001822 VkWriteDescriptorSet* pWDS = NULL;
1823 VkCopyDescriptorSet* pCDS = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001824 size_t array_size = 0;
1825 size_t base_array_size = 0;
1826 size_t total_array_size = 0;
1827 size_t baseBuffAddr = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001828 switch (pUpdate->sType)
1829 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001830 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1831 pWDS = new VkWriteDescriptorSet;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001832 *pNewNode = (GENERIC_HEADER*)pWDS;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001833 memcpy(pWDS, pUpdate, sizeof(VkWriteDescriptorSet));
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06001834
1835 switch (pWDS->descriptorType) {
1836 case VK_DESCRIPTOR_TYPE_SAMPLER:
1837 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
1838 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
1839 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
1840 {
Chia-I Wu763a7492015-10-26 20:48:51 +08001841 VkDescriptorImageInfo *info = new VkDescriptorImageInfo[pWDS->descriptorCount];
1842 memcpy(info, pWDS->pImageInfo, pWDS->descriptorCount * sizeof(VkDescriptorImageInfo));
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06001843 pWDS->pImageInfo = info;
Tobin Ehliscb085292015-12-01 09:57:09 -07001844 }
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06001845 break;
1846 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
1847 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
1848 {
Chia-I Wu763a7492015-10-26 20:48:51 +08001849 VkBufferView *info = new VkBufferView[pWDS->descriptorCount];
1850 memcpy(info, pWDS->pTexelBufferView, pWDS->descriptorCount * sizeof(VkBufferView));
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06001851 pWDS->pTexelBufferView = info;
1852 }
1853 break;
1854 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
1855 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
1856 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
1857 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
1858 {
Chia-I Wu763a7492015-10-26 20:48:51 +08001859 VkDescriptorBufferInfo *info = new VkDescriptorBufferInfo[pWDS->descriptorCount];
1860 memcpy(info, pWDS->pBufferInfo, pWDS->descriptorCount * sizeof(VkDescriptorBufferInfo));
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06001861 pWDS->pBufferInfo = info;
1862 }
1863 break;
1864 default:
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07001865 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06001866 break;
1867 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001868 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001869 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
1870 pCDS = new VkCopyDescriptorSet;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001871 *pNewNode = (GENERIC_HEADER*)pCDS;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001872 memcpy(pCDS, pUpdate, sizeof(VkCopyDescriptorSet));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001873 break;
1874 default:
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001875 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001876 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdate->sType), pUpdate->sType))
1877 return VK_TRUE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001878 }
1879 // Make sure that pNext for the end of shadow copy is NULL
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001880 (*pNewNode)->pNext = NULL;
1881 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001882}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001883
Tobin Ehlisb46be812015-10-23 16:00:08 -06001884// Verify that given sampler is valid
1885static VkBool32 validateSampler(const layer_data* my_data, const VkSampler* pSampler, const VkBool32 immutable)
1886{
1887 VkBool32 skipCall = VK_FALSE;
Chia-I Wue420a332015-10-26 20:04:44 +08001888 auto sampIt = my_data->sampleMap.find(*pSampler);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001889 if (sampIt == my_data->sampleMap.end()) {
1890 if (!immutable) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001891 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT, (uint64_t) *pSampler, 0, DRAWSTATE_SAMPLER_DESCRIPTOR_ERROR, "DS",
Chia-I Wue420a332015-10-26 20:04:44 +08001892 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid sampler %#" PRIxLEAST64, (uint64_t) *pSampler);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001893 } else { // immutable
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001894 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT, (uint64_t) *pSampler, 0, DRAWSTATE_SAMPLER_DESCRIPTOR_ERROR, "DS",
Chia-I Wue420a332015-10-26 20:04:44 +08001895 "vkUpdateDescriptorSets: Attempt to update descriptor whose binding has an invalid immutable sampler %#" PRIxLEAST64, (uint64_t) *pSampler);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001896 }
1897 } else {
1898 // TODO : Any further checks we want to do on the sampler?
1899 }
1900 return skipCall;
1901}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001902
Tobin Ehlisb46be812015-10-23 16:00:08 -06001903// Verify that given imageView is valid
1904static VkBool32 validateImageView(const layer_data* my_data, const VkImageView* pImageView, const VkImageLayout imageLayout)
1905{
1906 VkBool32 skipCall = VK_FALSE;
Chia-I Wue420a332015-10-26 20:04:44 +08001907 auto ivIt = my_data->imageViewMap.find(*pImageView);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001908 if (ivIt == my_data->imageViewMap.end()) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001909 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, (uint64_t) *pImageView, 0, DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, "DS",
Chia-I Wue420a332015-10-26 20:04:44 +08001910 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid imageView %#" PRIxLEAST64, (uint64_t) *pImageView);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001911 } else {
1912 // Validate that imageLayout is compatible with aspectMask and image format
1913 VkImageAspectFlags aspectMask = ivIt->second->subresourceRange.aspectMask;
Chia-I Wue420a332015-10-26 20:04:44 +08001914 VkImage image = ivIt->second->image;
Michael Lentineee4ad4d2015-10-23 12:41:44 -07001915 // TODO : Check here in case we have a bad image
Chia-I Wue420a332015-10-26 20:04:44 +08001916 auto imgIt = my_data->imageMap.find(image);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001917 if (imgIt == my_data->imageMap.end()) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001918 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t) image, 0, DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, "DS",
Michael Lentineee4ad4d2015-10-23 12:41:44 -07001919 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid image %#" PRIxLEAST64 " in imageView %#" PRIxLEAST64, (uint64_t) image, (uint64_t) *pImageView);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001920 } else {
1921 VkFormat format = (*imgIt).second->format;
Courtney Goeltzenleuchterf2bca902015-11-03 15:41:43 -07001922 VkBool32 ds = vk_format_is_depth_or_stencil(format);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001923 switch (imageLayout) {
1924 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
1925 // Only Color bit must be set
1926 if ((aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) != VK_IMAGE_ASPECT_COLOR_BIT) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001927 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, (uint64_t) *pImageView, 0,
Tobin Ehlisb46be812015-10-23 16:00:08 -06001928 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL and imageView %#" PRIxLEAST64 ""
Chia-I Wue420a332015-10-26 20:04:44 +08001929 " that does not have VK_IMAGE_ASPECT_COLOR_BIT set.", (uint64_t) *pImageView);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001930 }
1931 // format must NOT be DS
1932 if (ds) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001933 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, (uint64_t) *pImageView, 0,
Tobin Ehlisb46be812015-10-23 16:00:08 -06001934 DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL and imageView %#" PRIxLEAST64 ""
Chia-I Wue420a332015-10-26 20:04:44 +08001935 " but the image format is %s which is not a color format.", (uint64_t) *pImageView, string_VkFormat(format));
Tobin Ehlisb46be812015-10-23 16:00:08 -06001936 }
1937 break;
1938 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
1939 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
1940 // Depth or stencil bit must be set, but both must NOT be set
1941 if (aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) {
1942 if (aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) {
1943 // both must NOT be set
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001944 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, (uint64_t) *pImageView, 0,
Tobin Ehlisb46be812015-10-23 16:00:08 -06001945 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with imageView %#" PRIxLEAST64 ""
Chia-I Wue420a332015-10-26 20:04:44 +08001946 " that has both STENCIL and DEPTH aspects set", (uint64_t) *pImageView);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001947 }
1948 } else if (!(aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)) {
1949 // Neither were set
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001950 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, (uint64_t) *pImageView, 0,
Tobin Ehlisb46be812015-10-23 16:00:08 -06001951 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout %s and imageView %#" PRIxLEAST64 ""
Chia-I Wue420a332015-10-26 20:04:44 +08001952 " that does not have STENCIL or DEPTH aspect set.", string_VkImageLayout(imageLayout), (uint64_t) *pImageView);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001953 }
1954 // format must be DS
1955 if (!ds) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001956 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, (uint64_t) *pImageView, 0,
Tobin Ehlisb46be812015-10-23 16:00:08 -06001957 DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout %s and imageView %#" PRIxLEAST64 ""
Chia-I Wue420a332015-10-26 20:04:44 +08001958 " but the image format is %s which is not a depth/stencil format.", string_VkImageLayout(imageLayout), (uint64_t) *pImageView, string_VkFormat(format));
Tobin Ehlisb46be812015-10-23 16:00:08 -06001959 }
1960 break;
1961 default:
1962 // anything to check for other layouts?
1963 break;
1964 }
1965 }
1966 }
1967 return skipCall;
1968}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001969
Tobin Ehlisb46be812015-10-23 16:00:08 -06001970// Verify that given bufferView is valid
1971static VkBool32 validateBufferView(const layer_data* my_data, const VkBufferView* pBufferView)
1972{
1973 VkBool32 skipCall = VK_FALSE;
Chia-I Wue420a332015-10-26 20:04:44 +08001974 auto sampIt = my_data->bufferViewMap.find(*pBufferView);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001975 if (sampIt == my_data->bufferViewMap.end()) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001976 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_VIEW_EXT, (uint64_t) *pBufferView, 0, DRAWSTATE_BUFFERVIEW_DESCRIPTOR_ERROR, "DS",
Chia-I Wue420a332015-10-26 20:04:44 +08001977 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid bufferView %#" PRIxLEAST64, (uint64_t) *pBufferView);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001978 } else {
1979 // TODO : Any further checks we want to do on the bufferView?
1980 }
1981 return skipCall;
1982}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001983
Tobin Ehlisb46be812015-10-23 16:00:08 -06001984// Verify that given bufferInfo is valid
1985static VkBool32 validateBufferInfo(const layer_data* my_data, const VkDescriptorBufferInfo* pBufferInfo)
1986{
1987 VkBool32 skipCall = VK_FALSE;
Chia-I Wue420a332015-10-26 20:04:44 +08001988 auto sampIt = my_data->bufferMap.find(pBufferInfo->buffer);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001989 if (sampIt == my_data->bufferMap.end()) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001990 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, (uint64_t) pBufferInfo->buffer, 0, DRAWSTATE_BUFFERINFO_DESCRIPTOR_ERROR, "DS",
Chia-I Wue420a332015-10-26 20:04:44 +08001991 "vkUpdateDescriptorSets: Attempt to update descriptor where bufferInfo has invalid buffer %#" PRIxLEAST64, (uint64_t) pBufferInfo->buffer);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001992 } else {
1993 // TODO : Any further checks we want to do on the bufferView?
1994 }
1995 return skipCall;
1996}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001997
Tobin Ehlisb46be812015-10-23 16:00:08 -06001998static VkBool32 validateUpdateContents(const layer_data* my_data, const VkWriteDescriptorSet *pWDS, const VkDescriptorSetLayoutBinding* pLayoutBinding)
1999{
2000 VkBool32 skipCall = VK_FALSE;
2001 // First verify that for the given Descriptor type, the correct DescriptorInfo data is supplied
2002 VkBufferView* pBufferView = NULL;
2003 const VkSampler* pSampler = NULL;
2004 VkImageView* pImageView = NULL;
2005 VkImageLayout* pImageLayout = NULL;
2006 VkDescriptorBufferInfo* pBufferInfo = NULL;
2007 VkBool32 immutable = VK_FALSE;
Tobin Ehlis68fbd442015-10-27 12:25:35 -06002008 uint32_t i = 0;
2009 // For given update type, verify that update contents are correct
2010 switch (pWDS->descriptorType) {
2011 case VK_DESCRIPTOR_TYPE_SAMPLER:
Chia-I Wu763a7492015-10-26 20:48:51 +08002012 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisb46be812015-10-23 16:00:08 -06002013 skipCall |= validateSampler(my_data, &(pWDS->pImageInfo[i].sampler), immutable);
Tobin Ehlis68fbd442015-10-27 12:25:35 -06002014 }
2015 break;
2016 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
Chia-I Wu763a7492015-10-26 20:48:51 +08002017 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisb46be812015-10-23 16:00:08 -06002018 if (NULL == pLayoutBinding->pImmutableSamplers) {
2019 pSampler = &(pWDS->pImageInfo[i].sampler);
Tobin Ehlis68fbd442015-10-27 12:25:35 -06002020 if (immutable) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002021 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT, (uint64_t) *pSampler, 0, DRAWSTATE_INCONSISTENT_IMMUTABLE_SAMPLER_UPDATE, "DS",
Tobin Ehlis68fbd442015-10-27 12:25:35 -06002022 "vkUpdateDescriptorSets: Update #%u is not an immutable sampler %#" PRIxLEAST64 ", but previous update(s) from this "
2023 "VkWriteDescriptorSet struct used an immutable sampler. All updates from a single struct must either "
Chia-I Wue420a332015-10-26 20:04:44 +08002024 "use immutable or non-immutable samplers.", i, (uint64_t) *pSampler);
Tobin Ehlis68fbd442015-10-27 12:25:35 -06002025 }
Tobin Ehlisb46be812015-10-23 16:00:08 -06002026 } else {
Tobin Ehlis68fbd442015-10-27 12:25:35 -06002027 if (i>0 && !immutable) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002028 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT, (uint64_t) *pSampler, 0, DRAWSTATE_INCONSISTENT_IMMUTABLE_SAMPLER_UPDATE, "DS",
Tobin Ehlis68fbd442015-10-27 12:25:35 -06002029 "vkUpdateDescriptorSets: Update #%u is an immutable sampler, but previous update(s) from this "
2030 "VkWriteDescriptorSet struct used a non-immutable sampler. All updates from a single struct must either "
2031 "use immutable or non-immutable samplers.", i);
2032 }
Tobin Ehlisb46be812015-10-23 16:00:08 -06002033 immutable = VK_TRUE;
2034 pSampler = &(pLayoutBinding->pImmutableSamplers[i]);
2035 }
2036 skipCall |= validateSampler(my_data, pSampler, immutable);
Tobin Ehlis68fbd442015-10-27 12:25:35 -06002037 }
2038 // Intentionally fall through here to also validate image stuff
2039 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2040 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
2041 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
Chia-I Wu763a7492015-10-26 20:48:51 +08002042 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisb46be812015-10-23 16:00:08 -06002043 skipCall |= validateImageView(my_data, &(pWDS->pImageInfo[i].imageView), pWDS->pImageInfo[i].imageLayout);
Tobin Ehlis68fbd442015-10-27 12:25:35 -06002044 }
2045 break;
2046 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2047 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
Chia-I Wu763a7492015-10-26 20:48:51 +08002048 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisb46be812015-10-23 16:00:08 -06002049 skipCall |= validateBufferView(my_data, &(pWDS->pTexelBufferView[i]));
Tobin Ehlis68fbd442015-10-27 12:25:35 -06002050 }
2051 break;
2052 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2053 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2054 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2055 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
Chia-I Wu763a7492015-10-26 20:48:51 +08002056 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisb46be812015-10-23 16:00:08 -06002057 skipCall |= validateBufferInfo(my_data, &(pWDS->pBufferInfo[i]));
Tobin Ehlis68fbd442015-10-27 12:25:35 -06002058 }
2059 break;
Tobin Ehlisb46be812015-10-23 16:00:08 -06002060 }
2061 return skipCall;
2062}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002063
Tobin Ehlis68fbd442015-10-27 12:25:35 -06002064// update DS mappings based on write and copy update arrays
Chia-I Wu483e7702015-10-26 17:20:32 +08002065static VkBool32 dsUpdate(layer_data* my_data, VkDevice device, uint32_t descriptorWriteCount, const VkWriteDescriptorSet* pWDS, uint32_t descriptorCopyCount, const VkCopyDescriptorSet* pCDS)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002066{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002067 VkBool32 skipCall = VK_FALSE;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002068
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002069 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002070 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002071 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlis68fbd442015-10-27 12:25:35 -06002072 // Validate Write updates
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06002073 uint32_t i = 0;
Chia-I Wu483e7702015-10-26 17:20:32 +08002074 for (i=0; i < descriptorWriteCount; i++) {
Chia-I Wu1f851912015-10-27 18:04:07 +08002075 VkDescriptorSet ds = pWDS[i].dstSet;
Chia-I Wue420a332015-10-26 20:04:44 +08002076 SET_NODE* pSet = my_data->setMap[ds];
Tobin Ehlisb46be812015-10-23 16:00:08 -06002077 GENERIC_HEADER* pUpdate = (GENERIC_HEADER*) &pWDS[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002078 pLayout = pSet->pLayout;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002079 // First verify valid update struct
Tobin Ehlis42d440c2015-10-20 17:06:16 -06002080 if ((skipCall = validUpdateStruct(my_data, device, pUpdate)) == VK_TRUE) {
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002081 break;
2082 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002083 uint32_t binding = 0, endIndex = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08002084 binding = pWDS[i].dstBinding;
Tobin Ehlis68fbd442015-10-27 12:25:35 -06002085 // Make sure that layout being updated has the binding being updated
Chia-I Wub5689ee2015-10-31 00:31:16 +08002086 if (pLayout->bindings.find(binding) == pLayout->bindings.end()) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002087 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) ds, 0, DRAWSTATE_INVALID_UPDATE_INDEX, "DS",
Michael Lentinecbc4a5e2015-11-03 16:19:46 -08002088 "Descriptor Set %" PRIu64 " does not have binding to match update binding %u for update type %s!", reinterpret_cast<uint64_t>(ds), binding, string_VkStructureType(pUpdate->sType));
Tobin Ehlise42007c2015-06-19 13:00:59 -06002089 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002090 // Next verify that update falls within size of given binding
Chia-I Wu1f851912015-10-27 18:04:07 +08002091 endIndex = getUpdateEndIndex(my_data, device, pLayout, binding, pWDS[i].dstArrayElement, pUpdate);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002092 if (getBindingEndIndex(pLayout, binding) < endIndex) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002093 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002094 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002095 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) ds, 0, DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, "DS",
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002096 "Descriptor update type of %s is out of bounds for matching binding %u in Layout w/ CI:\n%s!", string_VkStructureType(pUpdate->sType), binding, DSstr.c_str());
Tobin Ehlise42007c2015-06-19 13:00:59 -06002097 } else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlis68fbd442015-10-27 12:25:35 -06002098 uint32_t startIndex;
Chia-I Wu1f851912015-10-27 18:04:07 +08002099 startIndex = getUpdateStartIndex(my_data, device, pLayout, binding, pWDS[i].dstArrayElement, pUpdate);
Tobin Ehlis68fbd442015-10-27 12:25:35 -06002100 // Layout bindings match w/ update, now verify that update type & stageFlags are the same for entire update
2101 if ((skipCall = validateUpdateConsistency(my_data, device, pLayout, pUpdate, startIndex, endIndex)) == VK_FALSE) {
2102 // The update is within bounds and consistent, but need to make sure contents make sense as well
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002103 if ((skipCall = validateUpdateContents(my_data, &pWDS[i], &pLayout->createInfo.pBinding[binding])) == VK_FALSE) {
Tobin Ehlisb46be812015-10-23 16:00:08 -06002104 // Update is good. Save the update info
2105 // Create new update struct for this set's shadow copy
2106 GENERIC_HEADER* pNewNode = NULL;
2107 skipCall |= shadowUpdateNode(my_data, device, pUpdate, &pNewNode);
2108 if (NULL == pNewNode) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002109 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) ds, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
Tobin Ehlisb46be812015-10-23 16:00:08 -06002110 "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
2111 } else {
2112 // Insert shadow node into LL of updates for this set
2113 pNewNode->pNext = pSet->pUpdateStructs;
2114 pSet->pUpdateStructs = pNewNode;
2115 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlisb46be812015-10-23 16:00:08 -06002116 for (uint32_t j = startIndex; j <= endIndex; j++) {
2117 assert(j<pSet->descriptorCount);
2118 pSet->ppDescriptors[j] = pNewNode;
2119 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002120 }
2121 }
2122 }
2123 }
2124 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002125 }
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06002126 // Now validate copy updates
Chia-I Wu483e7702015-10-26 17:20:32 +08002127 for (i=0; i < descriptorCopyCount; ++i) {
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06002128 SET_NODE *pSrcSet = NULL, *pDstSet = NULL;
2129 LAYOUT_NODE *pSrcLayout = NULL, *pDstLayout = NULL;
2130 uint32_t srcStartIndex = 0, srcEndIndex = 0, dstStartIndex = 0, dstEndIndex = 0;
2131 // For each copy make sure that update falls within given layout and that types match
Chia-I Wue420a332015-10-26 20:04:44 +08002132 pSrcSet = my_data->setMap[pCDS[i].srcSet];
Chia-I Wu1f851912015-10-27 18:04:07 +08002133 pDstSet = my_data->setMap[pCDS[i].dstSet];
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06002134 pSrcLayout = pSrcSet->pLayout;
2135 pDstLayout = pDstSet->pLayout;
2136 // Validate that src binding is valid for src set layout
Chia-I Wub5689ee2015-10-31 00:31:16 +08002137 if (pSrcLayout->bindings.find(pCDS[i].srcBinding) == pSrcLayout->bindings.end()) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002138 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pSrcSet->set, 0, DRAWSTATE_INVALID_UPDATE_INDEX, "DS",
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06002139 "Copy descriptor update %u has srcBinding %u which is out of bounds for underlying SetLayout %#" PRIxLEAST64 " which only has bindings 0-%u.",
Chia-I Wu763a7492015-10-26 20:48:51 +08002140 i, pCDS[i].srcBinding, (uint64_t) pSrcLayout->layout, pSrcLayout->createInfo.bindingCount-1);
Chia-I Wub5689ee2015-10-31 00:31:16 +08002141 } else if (pDstLayout->bindings.find(pCDS[i].dstBinding) == pDstLayout->bindings.end()) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002142 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pDstSet->set, 0, DRAWSTATE_INVALID_UPDATE_INDEX, "DS",
Chia-I Wu1f851912015-10-27 18:04:07 +08002143 "Copy descriptor update %u has dstBinding %u which is out of bounds for underlying SetLayout %#" PRIxLEAST64 " which only has bindings 0-%u.",
2144 i, pCDS[i].dstBinding, (uint64_t) pDstLayout->layout, pDstLayout->createInfo.bindingCount-1);
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06002145 } else {
2146 // Proceed with validation. Bindings are ok, but make sure update is within bounds of given layout
2147 srcEndIndex = getUpdateEndIndex(my_data, device, pSrcLayout, pCDS[i].srcBinding, pCDS[i].srcArrayElement, (const GENERIC_HEADER*)&(pCDS[i]));
Chia-I Wu1f851912015-10-27 18:04:07 +08002148 dstEndIndex = getUpdateEndIndex(my_data, device, pDstLayout, pCDS[i].dstBinding, pCDS[i].dstArrayElement, (const GENERIC_HEADER*)&(pCDS[i]));
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06002149 if (getBindingEndIndex(pSrcLayout, pCDS[i].srcBinding) < srcEndIndex) {
2150 pLayoutCI = &pSrcLayout->createInfo;
2151 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002152 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pSrcSet->set, 0, DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, "DS",
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06002153 "Copy descriptor src update is out of bounds for matching binding %u in Layout w/ CI:\n%s!", pCDS[i].srcBinding, DSstr.c_str());
Chia-I Wu1f851912015-10-27 18:04:07 +08002154 } else if (getBindingEndIndex(pDstLayout, pCDS[i].dstBinding) < dstEndIndex) {
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06002155 pLayoutCI = &pDstLayout->createInfo;
2156 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002157 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pDstSet->set, 0, DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, "DS",
Chia-I Wu1f851912015-10-27 18:04:07 +08002158 "Copy descriptor dest update is out of bounds for matching binding %u in Layout w/ CI:\n%s!", pCDS[i].dstBinding, DSstr.c_str());
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06002159 } else {
2160 srcStartIndex = getUpdateStartIndex(my_data, device, pSrcLayout, pCDS[i].srcBinding, pCDS[i].srcArrayElement, (const GENERIC_HEADER*)&(pCDS[i]));
Chia-I Wu1f851912015-10-27 18:04:07 +08002161 dstStartIndex = getUpdateStartIndex(my_data, device, pDstLayout, pCDS[i].dstBinding, pCDS[i].dstArrayElement, (const GENERIC_HEADER*)&(pCDS[i]));
Chia-I Wu763a7492015-10-26 20:48:51 +08002162 for (uint32_t j=0; j<pCDS[i].descriptorCount; ++j) {
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06002163 // For copy just make sure that the types match and then perform the update
2164 if (pSrcLayout->descriptorTypes[srcStartIndex+j] != pDstLayout->descriptorTypes[dstStartIndex+j]) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002165 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, "DS",
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06002166 "Copy descriptor update index %u, update count #%u, has src update descriptor type %s that does not match overlapping dest descriptor type of %s!",
2167 i, j+1, string_VkDescriptorType(pSrcLayout->descriptorTypes[srcStartIndex+j]), string_VkDescriptorType(pDstLayout->descriptorTypes[dstStartIndex+j]));
2168 } else {
2169 // point dst descriptor at corresponding src descriptor
2170 pDstSet->ppDescriptors[j+dstStartIndex] = pSrcSet->ppDescriptors[j+srcStartIndex];
2171 }
2172 }
2173 }
2174 }
2175 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002176 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002177 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002178}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002179
Tobin Ehlisc6457d22015-10-20 16:16:04 -06002180// Verify that given pool has descriptors that are being requested for allocation
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002181static VkBool32 validate_descriptor_availability_in_pool(layer_data* dev_data, DESCRIPTOR_POOL_NODE* pPoolNode, uint32_t count, const VkDescriptorSetLayout* pSetLayouts)
Tobin Ehlisc6457d22015-10-20 16:16:04 -06002182{
2183 VkBool32 skipCall = VK_FALSE;
2184 uint32_t i = 0, j = 0;
2185 for (i=0; i<count; ++i) {
2186 LAYOUT_NODE* pLayout = getLayoutNode(dev_data, pSetLayouts[i]);
2187 if (NULL == pLayout) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002188 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, (uint64_t) pSetLayouts[i], 0, DRAWSTATE_INVALID_LAYOUT, "DS",
Chia-I Wu1f851912015-10-27 18:04:07 +08002189 "Unable to find set layout node for layout %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pSetLayouts[i]);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06002190 } else {
Chia-I Wuc51b1212015-10-27 19:25:11 +08002191 uint32_t typeIndex = 0, poolSizeCount = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08002192 for (j=0; j<pLayout->createInfo.bindingCount; ++j) {
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002193 typeIndex = static_cast<uint32_t>(pLayout->createInfo.pBinding[j].descriptorType);
Chia-I Wu045654f2015-11-06 06:42:02 +08002194 poolSizeCount = pLayout->createInfo.pBinding[j].descriptorCount;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002195 if (poolSizeCount > pPoolNode->availableDescriptorTypeCount[typeIndex]) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002196 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, (uint64_t) pLayout->layout, 0, DRAWSTATE_DESCRIPTOR_POOL_EMPTY, "DS",
Tobin Ehlisc6457d22015-10-20 16:16:04 -06002197 "Unable to allocate %u descriptors of type %s from pool %#" PRIxLEAST64 ". This pool only has %u descriptors of this type remaining.",
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002198 poolSizeCount, string_VkDescriptorType(pLayout->createInfo.pBinding[j].descriptorType), (uint64_t) pPoolNode->pool, pPoolNode->availableDescriptorTypeCount[typeIndex]);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06002199 } else { // Decrement available descriptors of this type
Chia-I Wuc51b1212015-10-27 19:25:11 +08002200 pPoolNode->availableDescriptorTypeCount[typeIndex] -= poolSizeCount;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06002201 }
2202 }
2203 }
2204 }
2205 return skipCall;
2206}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002207
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002208// Free the shadowed update node for this Set
2209// NOTE : Calls to this function should be wrapped in mutex
2210static void freeShadowUpdateTree(SET_NODE* pSet)
2211{
2212 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
2213 pSet->pUpdateStructs = NULL;
2214 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
2215 // Clear the descriptor mappings as they will now be invalid
2216 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
2217 while(pShadowUpdate) {
2218 pFreeUpdate = pShadowUpdate;
2219 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
2220 uint32_t index = 0;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002221 VkWriteDescriptorSet * pWDS = NULL;
2222 VkCopyDescriptorSet * pCDS = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002223 void** ppToFree = NULL;
2224 switch (pFreeUpdate->sType)
2225 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002226 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
2227 pWDS = (VkWriteDescriptorSet*)pFreeUpdate;
Tony Barbourf740f902015-11-02 11:46:29 -07002228 switch (pWDS->descriptorType) {
2229 case VK_DESCRIPTOR_TYPE_SAMPLER:
2230 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
2231 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2232 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
2233 {
2234 delete[] pWDS->pImageInfo;
2235 }
2236 break;
2237 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2238 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
2239 {
2240 delete[] pWDS->pTexelBufferView;
2241 }
2242 break;
2243 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2244 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2245 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2246 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
2247 {
2248 delete[] pWDS->pBufferInfo;
2249 }
2250 break;
2251 default:
2252 break;
Courtney Goeltzenleuchtere4099742015-10-22 15:31:56 -06002253 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002254 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002255 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002256 break;
2257 default:
2258 assert(0);
2259 break;
2260 }
Tobin Ehliseaf28662015-04-08 10:58:37 -06002261 delete pFreeUpdate;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002262 }
2263}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002264
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002265// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002266// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002267static void deletePools(layer_data* my_data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002268{
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002269 if (my_data->descriptorPoolMap.size() <= 0)
David Pinedof5997ab2015-04-27 16:36:17 -06002270 return;
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002271 for (auto ii=my_data->descriptorPoolMap.begin(); ii!=my_data->descriptorPoolMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002272 SET_NODE* pSet = (*ii).second->pSets;
2273 SET_NODE* pFreeSet = pSet;
2274 while (pSet) {
2275 pFreeSet = pSet;
2276 pSet = pSet->pNext;
Tobin Ehliseaf28662015-04-08 10:58:37 -06002277 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002278 // Free Update shadow struct tree
2279 freeShadowUpdateTree(pFreeSet);
2280 if (pFreeSet->ppDescriptors) {
Chris Forbes4506d3f2015-06-04 10:49:27 +12002281 delete[] pFreeSet->ppDescriptors;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002282 }
2283 delete pFreeSet;
2284 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002285 delete (*ii).second;
2286 }
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002287 my_data->descriptorPoolMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002288}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002289
Tobin Ehliseaf28662015-04-08 10:58:37 -06002290// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002291// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002292static void deleteLayouts(layer_data* my_data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002293{
Tobin Ehlisad61de42015-12-02 13:53:34 -07002294 if (my_data->descriptorSetLayoutMap.size() <= 0)
David Pinedof5997ab2015-04-27 16:36:17 -06002295 return;
Tobin Ehlisad61de42015-12-02 13:53:34 -07002296 for (auto ii=my_data->descriptorSetLayoutMap.begin(); ii!=my_data->descriptorSetLayoutMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002297 LAYOUT_NODE* pLayout = (*ii).second;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002298 if (pLayout->createInfo.pBinding) {
Chia-I Wu763a7492015-10-26 20:48:51 +08002299 for (uint32_t i=0; i<pLayout->createInfo.bindingCount; i++) {
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002300 if (pLayout->createInfo.pBinding[i].pImmutableSamplers)
2301 delete[] pLayout->createInfo.pBinding[i].pImmutableSamplers;
Tobin Ehliseaf28662015-04-08 10:58:37 -06002302 }
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002303 delete[] pLayout->createInfo.pBinding;
Tobin Ehliseaf28662015-04-08 10:58:37 -06002304 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002305 delete pLayout;
2306 }
Tobin Ehlisad61de42015-12-02 13:53:34 -07002307 my_data->descriptorSetLayoutMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002308}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002309
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002310// Currently clearing a set is removing all previous updates to that set
2311// TODO : Validate if this is correct clearing behavior
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002312static void clearDescriptorSet(layer_data* my_data, VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002313{
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002314 SET_NODE* pSet = getSetNode(my_data, set);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002315 if (!pSet) {
2316 // TODO : Return error
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002317 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002318 loader_platform_thread_lock_mutex(&globalLock);
2319 freeShadowUpdateTree(pSet);
2320 loader_platform_thread_unlock_mutex(&globalLock);
2321 }
2322}
2323
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002324static void clearDescriptorPool(layer_data* my_data, const VkDevice device, const VkDescriptorPool pool, VkDescriptorPoolResetFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002325{
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002326 DESCRIPTOR_POOL_NODE* pPool = getPoolNode(my_data, pool);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002327 if (!pPool) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002328 log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, (uint64_t) pool, 0, DRAWSTATE_INVALID_POOL, "DS",
Chia-I Wue420a332015-10-26 20:04:44 +08002329 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkResetDescriptorPool() call", (uint64_t) pool);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002330 } else {
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002331 // TODO: validate flags
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002332 // For every set off of this pool, clear it
2333 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002334 while (pSet) {
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002335 clearDescriptorSet(my_data, pSet->set);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002336 }
Tobin Ehlisc6457d22015-10-20 16:16:04 -06002337 // Reset available count to max count for this pool
2338 for (uint32_t i=0; i<pPool->availableDescriptorTypeCount.size(); ++i) {
2339 pPool->availableDescriptorTypeCount[i] = pPool->maxDescriptorTypeCount[i];
2340 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002341 }
2342}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002343
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002344// For given CB object, fetch associated CB Node from map
Chia-I Wu1f851912015-10-27 18:04:07 +08002345static GLOBAL_CB_NODE* getCBNode(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002346{
2347 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski13b66742015-11-20 14:33:48 -07002348 if (my_data->commandBufferMap.count(cb) == 0) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002349 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002350 // TODO : How to pass cb as srcObj here?
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002351 log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, 0, DRAWSTATE_INVALID_COMMAND_BUFFER, "DS",
Chia-I Wu1f851912015-10-27 18:04:07 +08002352 "Attempt to use CommandBuffer %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<uint64_t>(cb));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002353 return NULL;
2354 }
2355 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wu1f851912015-10-27 18:04:07 +08002356 return my_data->commandBufferMap[cb];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002357}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002358
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002359// Free all CB Nodes
2360// NOTE : Calls to this function should be wrapped in mutex
Chia-I Wu1f851912015-10-27 18:04:07 +08002361static void deleteCommandBuffers(layer_data* my_data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002362{
Mark Lobodzinski13b66742015-11-20 14:33:48 -07002363 if (my_data->commandBufferMap.size() <= 0) {
David Pinedof5997ab2015-04-27 16:36:17 -06002364 return;
Mark Lobodzinski13b66742015-11-20 14:33:48 -07002365 }
Chia-I Wu1f851912015-10-27 18:04:07 +08002366 for (auto ii=my_data->commandBufferMap.begin(); ii!=my_data->commandBufferMap.end(); ++ii) {
Courtney Goeltzenleuchter09098a72015-04-27 15:04:43 -06002367 vector<CMD_NODE*> cmd_node_list = (*ii).second->pCmds;
2368 while (!cmd_node_list.empty()) {
2369 CMD_NODE* cmd_node = cmd_node_list.back();
2370 delete cmd_node;
2371 cmd_node_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002372 }
2373 delete (*ii).second;
2374 }
Chia-I Wu1f851912015-10-27 18:04:07 +08002375 my_data->commandBufferMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002376}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002377
Chia-I Wu1f851912015-10-27 18:04:07 +08002378static VkBool32 report_error_no_cb_begin(const layer_data* dev_data, const VkCommandBuffer cb, const char* caller_name)
Tobin Ehlise42007c2015-06-19 13:00:59 -06002379{
Tobin Ehlisb51cb782015-12-16 08:19:42 -07002380 return log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2381 (uint64_t)cb, 0, DRAWSTATE_NO_BEGIN_COMMAND_BUFFER, "DS",
2382 "You must call vkBeginCommandBuffer() before this call to %s", caller_name);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002383}
Michael Lentine2b9eda42015-10-28 15:55:18 -07002384
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07002385VkBool32 validateCmdsInCmdBuffer(const layer_data* dev_data, const GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd_type) {
Tony Barbour778b08c2015-12-17 15:54:05 -07002386 // TODO : I think this is trying to validate this part of the spec:
2387 // If contents is VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS, the contents are recorded in secondary command
2388 // buffers that will be called from the primary command buffer, and vkCmdExecuteCommands is the only valid command
2389 // on the command buffer until vkCmdNextSubpass or vkCmdEndRenderPass.
2390 //
2391 // But the code below is forceing vkCmdExecuteCommands to be the only thing in the command buffer which is not necessary
2392 // it just needs to be the only thing in the renderpass
2393 //
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07002394 VkBool32 skip_call = false;
Tony Barbour778b08c2015-12-17 15:54:05 -07002395 //for (auto cmd : pCB->pCmds) {
2396 // if (cmd_type == CMD_EXECUTECOMMANDS && cmd->type != CMD_EXECUTECOMMANDS) {
2397 // skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_COMMAND_BUFFER, "DS",
2398 // "vkCmdExecuteCommands() cannot be called on a cmd buffer with exsiting commands.");
2399 // }
2400 // if (cmd_type != CMD_EXECUTECOMMANDS && cmd->type == CMD_EXECUTECOMMANDS) {
2401 // skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_COMMAND_BUFFER, "DS",
2402 // "Commands cannot be added to a cmd buffer with exsiting secondary commands.");
2403 // }
2404 //}
Michael Lentine2b9eda42015-10-28 15:55:18 -07002405 return skip_call;
2406}
2407
Tobin Ehlisb51cb782015-12-16 08:19:42 -07002408// Add specified CMD to the CmdBuffer in given pCB, flagging errors if CB is not
2409// in the recording state or if there's an issue with the Cmd ordering
2410static VkBool32 addCmd(const layer_data* my_data, GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd, const char* caller_name)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002411{
Tobin Ehlisb51cb782015-12-16 08:19:42 -07002412 VkBool32 skipCall = VK_FALSE;
2413 if (pCB->state != CB_RECORDING) {
2414 skipCall |= report_error_no_cb_begin(my_data, pCB->commandBuffer, caller_name);
2415 skipCall |= validateCmdsInCmdBuffer(my_data, pCB, cmd);
2416 CMD_NODE* pCmd = new CMD_NODE;
2417 if (pCmd) {
2418 // init cmd node and append to end of cmd LL
2419 memset(pCmd, 0, sizeof(CMD_NODE));
2420 pCmd->cmdNumber = ++pCB->numCmds;
2421 pCmd->type = cmd;
2422 pCB->pCmds.push_back(pCmd);
2423 } else {
2424 // TODO : How to pass cb as srcObj here?
2425 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
2426 "Out of memory while attempting to allocate new CMD_NODE for commandBuffer %#" PRIxLEAST64, reinterpret_cast<uint64_t>(pCB->commandBuffer));
2427 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002428 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002429 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002430}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002431
Chia-I Wu1f851912015-10-27 18:04:07 +08002432static void resetCB(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002433{
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002434 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002435 if (pCB) {
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06002436 vector<CMD_NODE*> cmd_list = pCB->pCmds;
2437 while (!cmd_list.empty()) {
2438 delete cmd_list.back();
2439 cmd_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002440 }
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06002441 pCB->pCmds.clear();
Tobin Ehlis0cea4082015-08-18 07:10:58 -06002442 // Reset CB state (need to save createInfo)
Chia-I Wu1f851912015-10-27 18:04:07 +08002443 VkCommandBufferAllocateInfo saveCBCI = pCB->createInfo;
Chia-I Wu1f851912015-10-27 18:04:07 +08002444 pCB->commandBuffer = cb;
Tobin Ehlis0cea4082015-08-18 07:10:58 -06002445 pCB->createInfo = saveCBCI;
Michael Lentine27b0f902015-10-12 11:30:14 -05002446 memset(&pCB->beginInfo, 0, sizeof(VkCommandBufferBeginInfo));
2447 pCB->fence = 0;
2448 pCB->numCmds = 0;
2449 memset(pCB->drawCount, 0, NUM_DRAW_TYPES * sizeof(uint64_t));
2450 pCB->state = CB_NEW;
2451 pCB->submitCount = 0;
2452 pCB->status = 0;
2453 pCB->pCmds.clear();
2454 pCB->lastBoundPipeline = 0;
2455 pCB->viewports.clear();
2456 pCB->scissors.clear();
2457 pCB->lineWidth = 0;
2458 pCB->depthBiasConstantFactor = 0;
2459 pCB->depthBiasClamp = 0;
2460 pCB->depthBiasSlopeFactor = 0;
2461 memset(pCB->blendConstants, 0, 4 * sizeof(float));
2462 pCB->minDepthBounds = 0;
2463 pCB->maxDepthBounds = 0;
2464 memset(&pCB->front, 0, sizeof(stencil_data));
2465 memset(&pCB->back, 0, sizeof(stencil_data));
2466 pCB->lastBoundDescriptorSet = 0;
2467 pCB->lastBoundPipelineLayout = 0;
2468 pCB->activeRenderPass = 0;
2469 pCB->activeSubpass = 0;
2470 pCB->framebuffer = 0;
Michael Lentine27b0f902015-10-12 11:30:14 -05002471 pCB->boundDescriptorSets.clear();
2472 pCB->imageLayoutMap.clear();
Mark Lobodzinski74e84692015-12-14 15:14:10 -07002473 pCB->boundVtxBuffers.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002474 }
2475}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002476
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002477// Set PSO-related status bits for CB, including dynamic state set via PSO
Tobin Ehlis97866202015-06-10 12:57:07 -06002478static void set_cb_pso_status(GLOBAL_CB_NODE* pCB, const PIPELINE_NODE* pPipe)
2479{
2480 for (uint32_t i = 0; i < pPipe->cbStateCI.attachmentCount; i++) {
Chia-I Wuc51b1212015-10-27 19:25:11 +08002481 if (0 != pPipe->pAttachments[i].colorWriteMask) {
Tobin Ehlis97866202015-06-10 12:57:07 -06002482 pCB->status |= CBSTATUS_COLOR_BLEND_WRITE_ENABLE;
2483 }
2484 }
2485 if (pPipe->dsStateCI.depthWriteEnable) {
Cody Northrop2605cb02015-08-18 15:21:16 -06002486 pCB->status |= CBSTATUS_DEPTH_WRITE_ENABLE;
2487 }
Cody Northrop2605cb02015-08-18 15:21:16 -06002488 if (pPipe->dsStateCI.stencilTestEnable) {
2489 pCB->status |= CBSTATUS_STENCIL_TEST_ENABLE;
Tobin Ehlis97866202015-06-10 12:57:07 -06002490 }
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002491 // Account for any dynamic state not set via this PSO
2492 if (!pPipe->dynStateCI.dynamicStateCount) { // All state is static
2493 pCB->status = CBSTATUS_ALL;
2494 } else {
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002495 // First consider all state on
2496 // Then unset any state that's noted as dynamic in PSO
2497 // Finally OR that into CB statemask
2498 CBStatusFlags psoDynStateMask = CBSTATUS_ALL;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002499 for (uint32_t i=0; i < pPipe->dynStateCI.dynamicStateCount; i++) {
2500 switch (pPipe->dynStateCI.pDynamicStates[i]) {
2501 case VK_DYNAMIC_STATE_VIEWPORT:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002502 psoDynStateMask &= ~CBSTATUS_VIEWPORT_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002503 break;
2504 case VK_DYNAMIC_STATE_SCISSOR:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002505 psoDynStateMask &= ~CBSTATUS_SCISSOR_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002506 break;
2507 case VK_DYNAMIC_STATE_LINE_WIDTH:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002508 psoDynStateMask &= ~CBSTATUS_LINE_WIDTH_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002509 break;
2510 case VK_DYNAMIC_STATE_DEPTH_BIAS:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002511 psoDynStateMask &= ~CBSTATUS_DEPTH_BIAS_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002512 break;
2513 case VK_DYNAMIC_STATE_BLEND_CONSTANTS:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002514 psoDynStateMask &= ~CBSTATUS_BLEND_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002515 break;
2516 case VK_DYNAMIC_STATE_DEPTH_BOUNDS:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002517 psoDynStateMask &= ~CBSTATUS_DEPTH_BOUNDS_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002518 break;
2519 case VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002520 psoDynStateMask &= ~CBSTATUS_STENCIL_READ_MASK_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002521 break;
2522 case VK_DYNAMIC_STATE_STENCIL_WRITE_MASK:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002523 psoDynStateMask &= ~CBSTATUS_STENCIL_WRITE_MASK_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002524 break;
2525 case VK_DYNAMIC_STATE_STENCIL_REFERENCE:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002526 psoDynStateMask &= ~CBSTATUS_STENCIL_REFERENCE_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002527 break;
2528 default:
2529 // TODO : Flag error here
2530 break;
2531 }
2532 }
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002533 pCB->status |= psoDynStateMask;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002534 }
Tobin Ehlis97866202015-06-10 12:57:07 -06002535}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002536
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002537// Print the last bound Gfx Pipeline
Chia-I Wu1f851912015-10-27 18:04:07 +08002538static VkBool32 printPipeline(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002539{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002540 VkBool32 skipCall = VK_FALSE;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002541 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002542 if (pCB) {
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002543 PIPELINE_NODE *pPipeTrav = getPipeline(my_data, pCB->lastBoundPipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002544 if (!pPipeTrav) {
2545 // nothing to print
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002546 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002547 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_NONE, "DS",
Michael Lentinecbc4a5e2015-11-03 16:19:46 -08002548 "%s", vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002549 }
2550 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002551 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002552}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002553
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002554// Print details of DS config to stdout
Chia-I Wu1f851912015-10-27 18:04:07 +08002555static VkBool32 printDSConfig(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002556{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002557 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002558 char ds_config_str[1024*256] = {0}; // TODO : Currently making this buffer HUGE w/o overrun protection. Need to be smarter, start smaller, and grow as needed.
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002559 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis7297f192015-06-09 08:39:32 -06002560 if (pCB && pCB->lastBoundDescriptorSet) {
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002561 SET_NODE* pSet = getSetNode(my_data, pCB->lastBoundDescriptorSet);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002562 DESCRIPTOR_POOL_NODE* pPool = getPoolNode(my_data, pSet->pool);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002563 // Print out pool details
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002564 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_NONE, "DS",
Chia-I Wue420a332015-10-26 20:04:44 +08002565 "Details for pool %#" PRIxLEAST64 ".", (uint64_t) pPool->pool);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002566 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002567 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002568 "%s", poolStr.c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002569 // Print out set details
2570 char prefix[10];
2571 uint32_t index = 0;
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002572 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_NONE, "DS",
Chia-I Wue420a332015-10-26 20:04:44 +08002573 "Details for descriptor set %#" PRIxLEAST64 ".", (uint64_t) pSet->set);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002574 LAYOUT_NODE* pLayout = pSet->pLayout;
2575 // Print layout details
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002576 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_NONE, "DS",
Michael Lentinecbc4a5e2015-11-03 16:19:46 -08002577 "Layout #%u, (object %#" PRIxLEAST64 ") for DS %#" PRIxLEAST64 ".", index+1, reinterpret_cast<uint64_t>(pLayout->layout), reinterpret_cast<uint64_t>(pSet->set));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002578 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002579 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002580 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002581 "%s", DSLstr.c_str());
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002582 index++;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002583 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
2584 if (pUpdate) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002585 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_NONE, "DS",
Chia-I Wue420a332015-10-26 20:04:44 +08002586 "Update Chain [UC] for descriptor set %#" PRIxLEAST64 ":", (uint64_t) pSet->set);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002587 sprintf(prefix, " [UC] ");
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002588 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_NONE, "DS",
Michael Lentinecbc4a5e2015-11-03 16:19:46 -08002589 "%s", dynamic_display(pUpdate, prefix).c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002590 // TODO : If there is a "view" associated with this update, print CI for that view
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002591 } else {
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06002592 if (0 != pSet->descriptorCount) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002593 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_NONE, "DS",
Chia-I Wue420a332015-10-26 20:04:44 +08002594 "No Update Chain for descriptor set %#" PRIxLEAST64 " which has %u descriptors (vkUpdateDescriptors has not been called)", (uint64_t) pSet->set, pSet->descriptorCount);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002595 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002596 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_NONE, "DS",
Chia-I Wue420a332015-10-26 20:04:44 +08002597 "FYI: No descriptors in descriptor set %#" PRIxLEAST64 ".", (uint64_t) pSet->set);
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06002598 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002599 }
2600 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002601 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002602}
2603
Chia-I Wu1f851912015-10-27 18:04:07 +08002604static void printCB(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002605{
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002606 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
David Pinedof5997ab2015-04-27 16:36:17 -06002607 if (pCB && pCB->pCmds.size() > 0) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002608 log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002609 "Cmds in CB %p", (void*)cb);
Courtney Goeltzenleuchtercf2a5362015-04-27 11:16:35 -06002610 vector<CMD_NODE*> pCmds = pCB->pCmds;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002611 for (auto ii=pCmds.begin(); ii!=pCmds.end(); ++ii) {
2612 // TODO : Need to pass cb as srcObj here
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002613 log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, 0, DRAWSTATE_NONE, "DS",
Michael Lentinecbc4a5e2015-11-03 16:19:46 -08002614 " CMD#%" PRIu64 ": %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002615 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002616 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002617 // Nothing to print
2618 }
2619}
2620
Chia-I Wu1f851912015-10-27 18:04:07 +08002621static VkBool32 synchAndPrintDSConfig(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002622{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002623 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002624 if (!(my_data->report_data->active_flags & VK_DEBUG_REPORT_INFO_BIT_EXT)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002625 return skipCall;
Mike Stroyanfa2f2222015-08-12 17:11:28 -06002626 }
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002627 skipCall |= printDSConfig(my_data, cb);
2628 skipCall |= printPipeline(my_data, cb);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002629 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002630}
2631
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002632// Flags validation error if the associated call is made inside a render pass. The apiName
2633// routine should ONLY be called outside a render pass.
Tobin Ehlis42d440c2015-10-20 17:06:16 -06002634static VkBool32 insideRenderPass(const layer_data* my_data, GLOBAL_CB_NODE *pCB, const char *apiName)
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002635{
2636 VkBool32 inside = VK_FALSE;
2637 if (pCB->activeRenderPass) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002638 inside = log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Chia-I Wu1f851912015-10-27 18:04:07 +08002639 (uint64_t)pCB->commandBuffer, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002640 "%s: It is invalid to issue this call inside an active render pass (%#" PRIxLEAST64 ")",
Chia-I Wue420a332015-10-26 20:04:44 +08002641 apiName, (uint64_t) pCB->activeRenderPass);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002642 }
2643 return inside;
2644}
2645
2646// Flags validation error if the associated call is made outside a render pass. The apiName
2647// routine should ONLY be called inside a render pass.
Tobin Ehlis42d440c2015-10-20 17:06:16 -06002648static VkBool32 outsideRenderPass(const layer_data* my_data, GLOBAL_CB_NODE *pCB, const char *apiName)
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002649{
2650 VkBool32 outside = VK_FALSE;
Mark Lobodzinski611cf592015-12-18 15:35:38 -07002651 if (((pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) &&
2652 (!pCB->activeRenderPass)) ||
2653 ((pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) &&
2654 (!pCB->activeRenderPass) &&
2655 !(pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT))) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002656 outside = log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Chia-I Wu1f851912015-10-27 18:04:07 +08002657 (uint64_t)pCB->commandBuffer, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002658 "%s: This call must be issued inside an active render pass.", apiName);
2659 }
2660 return outside;
2661}
2662
Courtney Goeltzenleuchterb03a0bf2015-11-25 14:31:49 -07002663static void init_draw_state(layer_data *my_data, const VkAllocationCallbacks *pAllocator)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002664{
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002665 uint32_t report_flags = 0;
2666 uint32_t debug_action = 0;
2667 FILE *log_output = NULL;
2668 const char *option_str;
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002669 VkDebugReportCallbackEXT callback;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002670 // initialize DrawState options
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002671 report_flags = getLayerOptionFlags("DrawStateReportFlags", 0);
2672 getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &debug_action);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002673
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002674 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002675 {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002676 option_str = getLayerOption("DrawStateLogFilename");
Tobin Ehlisb4b6e7c2015-09-15 09:55:54 -06002677 log_output = getLayerLogOutput(option_str, "DrawState");
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002678 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07002679 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002680 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07002681 dbgInfo.pfnCallback = log_callback;
2682 dbgInfo.pUserData = log_output;
2683 dbgInfo.flags = report_flags;
2684 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchter1781b1c2015-10-05 15:58:38 -06002685 my_data->logging_callback.push_back(callback);
2686 }
2687
2688 if (debug_action & VK_DBG_LAYER_ACTION_DEBUG_OUTPUT) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002689 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07002690 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002691 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07002692 dbgInfo.pfnCallback = win32_debug_output_msg;
2693 dbgInfo.pUserData = log_output;
2694 dbgInfo.flags = report_flags;
2695 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchter1781b1c2015-10-05 15:58:38 -06002696 my_data->logging_callback.push_back(callback);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002697 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002698
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002699 if (!globalLockInitialized)
2700 {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002701 loader_platform_thread_create_mutex(&globalLock);
2702 globalLockInitialized = 1;
2703 }
2704}
2705
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002706VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance)
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06002707{
Tobin Ehliscb085292015-12-01 09:57:09 -07002708 // TODOSC : Shouldn't need any customization here
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002709 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
2710 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Chia-I Wu69f40122015-10-26 21:10:41 +08002711 VkResult result = pTable->CreateInstance(pCreateInfo, pAllocator, pInstance);
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06002712
2713 if (result == VK_SUCCESS) {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002714 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
2715 my_data->report_data = debug_report_create_instance(
2716 pTable,
2717 *pInstance,
Chia-I Wu763a7492015-10-26 20:48:51 +08002718 pCreateInfo->enabledExtensionNameCount,
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002719 pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchterf4a2eba2015-06-08 14:58:39 -06002720
Courtney Goeltzenleuchterb03a0bf2015-11-25 14:31:49 -07002721 init_draw_state(my_data, pAllocator);
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06002722 }
2723 return result;
2724}
2725
Jon Ashburne0fa2282015-05-20 09:00:28 -06002726/* hook DestroyInstance to remove tableInstanceMap entry */
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002727VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator)
Jon Ashburne0fa2282015-05-20 09:00:28 -06002728{
Tobin Ehliscb085292015-12-01 09:57:09 -07002729 // TODOSC : Shouldn't need any customization here
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002730 dispatch_key key = get_dispatch_key(instance);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002731 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
2732 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Chia-I Wu69f40122015-10-26 21:10:41 +08002733 pTable->DestroyInstance(instance, pAllocator);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002734
2735 // Clean up logging callback, if any
Courtney Goeltzenleuchter1781b1c2015-10-05 15:58:38 -06002736 while (my_data->logging_callback.size() > 0) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002737 VkDebugReportCallbackEXT callback = my_data->logging_callback.back();
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07002738 layer_destroy_msg_callback(my_data->report_data, callback, pAllocator);
Courtney Goeltzenleuchter1781b1c2015-10-05 15:58:38 -06002739 my_data->logging_callback.pop_back();
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002740 }
2741
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06002742 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002743 delete my_data->instance_dispatch_table;
2744 layer_data_map.erase(key);
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002745 // TODO : Potential race here with separate threads creating/destroying instance
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002746 if (layer_data_map.empty()) {
Mike Stroyand9dd0072015-08-18 15:56:18 -06002747 // Release mutex when destroying last instance.
2748 loader_platform_thread_delete_mutex(&globalLock);
2749 globalLockInitialized = 0;
2750 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002751}
2752
Jon Ashburnf0615e22015-05-25 14:11:37 -06002753static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
2754{
Tony Barbour29b12062015-07-13 13:37:24 -06002755 uint32_t i;
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002756 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
2757 dev_data->device_extensions.debug_marker_enabled = false;
Michael Lentine27b0f902015-10-12 11:30:14 -05002758 dev_data->device_extensions.wsi_enabled = false;
2759
2760
2761 VkLayerDispatchTable *pDisp = dev_data->device_dispatch_table;
2762 PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr;
2763
Michael Lentine27b0f902015-10-12 11:30:14 -05002764 pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR) gpa(device, "vkCreateSwapchainKHR");
2765 pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR) gpa(device, "vkDestroySwapchainKHR");
2766 pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR) gpa(device, "vkGetSwapchainImagesKHR");
2767 pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR) gpa(device, "vkAcquireNextImageKHR");
2768 pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR) gpa(device, "vkQueuePresentKHR");
Jon Ashburnf0615e22015-05-25 14:11:37 -06002769
Chia-I Wu763a7492015-10-26 20:48:51 +08002770 for (i = 0; i < pCreateInfo->enabledExtensionNameCount; i++) {
Ian Elliottc623ba52015-11-20 14:13:17 -07002771 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) {
Michael Lentine27b0f902015-10-12 11:30:14 -05002772 dev_data->device_extensions.wsi_enabled = true;
2773 }
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002774 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002775 /* Found a matching extension name, mark it enabled and init dispatch table*/
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002776 dev_data->device_extensions.debug_marker_enabled = true;
Jon Ashburnc1d059f2015-12-10 19:12:21 -07002777 initDebugMarkerTable(device);
2778
Jon Ashburnf0615e22015-05-25 14:11:37 -06002779 }
Jon Ashburnf0615e22015-05-25 14:11:37 -06002780 }
2781}
2782
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002783VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDevice* pDevice)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002784{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002785 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08002786 VkResult result = dev_data->device_dispatch_table->CreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
Tobin Ehliscb085292015-12-01 09:57:09 -07002787 // TODOSC : shouldn't need any customization here
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002788 if (result == VK_SUCCESS) {
2789 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002790 dev_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
Jon Ashburn7e07faf2015-06-18 15:02:58 -06002791 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002792 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002793 return result;
2794}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002795
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002796// prototype
2797static void deleteRenderPasses(layer_data*);
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002798VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002799{
Tobin Ehliscb085292015-12-01 09:57:09 -07002800 // TODOSC : Shouldn't need any customization here
Jeremy Hayesea1fef52015-06-19 11:37:38 -06002801 dispatch_key key = get_dispatch_key(device);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002802 layer_data* dev_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002803 // Free all the memory
2804 loader_platform_thread_lock_mutex(&globalLock);
2805 deletePipelines(dev_data);
2806 deleteRenderPasses(dev_data);
Chia-I Wu1f851912015-10-27 18:04:07 +08002807 deleteCommandBuffers(dev_data);
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002808 deletePools(dev_data);
2809 deleteLayouts(dev_data);
Tobin Ehlisb46be812015-10-23 16:00:08 -06002810 dev_data->imageViewMap.clear();
2811 dev_data->imageMap.clear();
2812 dev_data->bufferViewMap.clear();
2813 dev_data->bufferMap.clear();
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002814 loader_platform_thread_unlock_mutex(&globalLock);
2815
Chia-I Wu69f40122015-10-26 21:10:41 +08002816 dev_data->device_dispatch_table->DestroyDevice(device, pAllocator);
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002817 tableDebugMarkerMap.erase(key);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002818 delete dev_data->device_dispatch_table;
2819 layer_data_map.erase(key);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002820}
2821
Courtney Goeltzenleuchterd89520d2015-12-01 14:08:28 -07002822static const VkExtensionProperties instance_extensions[] = {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002823 {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002824 VK_EXT_DEBUG_REPORT_EXTENSION_NAME,
2825 VK_EXT_DEBUG_REPORT_REVISION
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002826 }
Jon Ashburneb2728b2015-04-10 14:33:07 -06002827};
2828
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002829VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002830 const char *pLayerName,
2831 uint32_t *pCount,
2832 VkExtensionProperties* pProperties)
Jon Ashburneb2728b2015-04-10 14:33:07 -06002833{
Courtney Goeltzenleuchterd89520d2015-12-01 14:08:28 -07002834 return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002835}
Jon Ashburneb2728b2015-04-10 14:33:07 -06002836
Courtney Goeltzenleuchterd89520d2015-12-01 14:08:28 -07002837static const VkLayerProperties ds_global_layers[] = {
2838 {
2839 "DrawState",
2840 VK_API_VERSION,
2841 VK_MAKE_VERSION(0, 1, 0),
2842 "Validation layer: DrawState",
2843 }
2844};
2845
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002846VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002847 uint32_t *pCount,
2848 VkLayerProperties* pProperties)
2849{
2850 return util_GetLayerProperties(ARRAY_SIZE(ds_global_layers),
2851 ds_global_layers,
2852 pCount, pProperties);
2853}
Jon Ashburneb2728b2015-04-10 14:33:07 -06002854
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002855static const VkExtensionProperties ds_device_extensions[] = {
2856 {
2857 DEBUG_MARKER_EXTENSION_NAME,
2858 VK_MAKE_VERSION(0, 1, 0),
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002859 }
2860};
2861
2862static const VkLayerProperties ds_device_layers[] = {
2863 {
2864 "DrawState",
2865 VK_API_VERSION,
2866 VK_MAKE_VERSION(0, 1, 0),
2867 "Validation layer: DrawState",
2868 }
2869};
2870
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002871VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002872 VkPhysicalDevice physicalDevice,
2873 const char* pLayerName,
2874 uint32_t* pCount,
2875 VkExtensionProperties* pProperties)
2876{
Tobin Ehlis32479352015-12-01 09:48:58 -07002877 // DrawState does not have any physical device extensions
Jon Ashburnaff81ff2015-11-02 17:37:20 -07002878 if (pLayerName == NULL) {
2879 dispatch_key key = get_dispatch_key(physicalDevice);
2880 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlis32479352015-12-01 09:48:58 -07002881 return my_data->instance_dispatch_table->EnumerateDeviceExtensionProperties(
Jon Ashburnaff81ff2015-11-02 17:37:20 -07002882 physicalDevice,
2883 NULL,
2884 pCount,
2885 pProperties);
2886 } else {
2887 return util_GetExtensionProperties(ARRAY_SIZE(ds_device_extensions),
2888 ds_device_extensions,
2889 pCount, pProperties);
2890 }
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002891}
2892
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002893VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002894 VkPhysicalDevice physicalDevice,
2895 uint32_t* pCount,
2896 VkLayerProperties* pProperties)
2897{
Tobin Ehlis32479352015-12-01 09:48:58 -07002898 /* DrawState physical device layers are the same as global */
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002899 return util_GetLayerProperties(ARRAY_SIZE(ds_device_layers), ds_device_layers,
2900 pCount, pProperties);
Jon Ashburneb2728b2015-04-10 14:33:07 -06002901}
2902
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07002903VkBool32 ValidateCmdBufImageLayouts(VkCommandBuffer cmdBuffer) {
2904 VkBool32 skip_call = false;
Michael Lentine27b0f902015-10-12 11:30:14 -05002905 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
2906 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
2907 for (auto cb_image_data : pCB->imageLayoutMap) {
2908 auto image_data = dev_data->imageLayoutMap.find(cb_image_data.first);
2909 if (image_data == dev_data->imageLayoutMap.end()) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002910 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentinecbc4a5e2015-11-03 16:19:46 -08002911 "Cannot submit cmd buffer using deleted image %" PRIu64 ".", reinterpret_cast<uint64_t>(cb_image_data.first));
Michael Lentine27b0f902015-10-12 11:30:14 -05002912 } else {
2913 if (dev_data->imageLayoutMap[cb_image_data.first]->layout != cb_image_data.second.initialLayout) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002914 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentine27b0f902015-10-12 11:30:14 -05002915 "Cannot submit cmd buffer using image with layout %d when first use is %d.", dev_data->imageLayoutMap[cb_image_data.first]->layout, cb_image_data.second.initialLayout);
2916 }
2917 dev_data->imageLayoutMap[cb_image_data.first]->layout = cb_image_data.second.layout;
2918 }
2919 }
2920 return skip_call;
2921}
2922
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002923VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002924{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002925 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis28be0be2015-05-22 12:38:16 -06002926 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002927 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Tobin Ehlis9185b0a2015-12-16 05:01:22 -07002928 // TODO : Any pCommandBuffers must have USAGE_SIMULTANEOUS_USE_BIT set or cannot already be executing on device
2929 // Same goes for any secondary CBs under the primary CB
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06002930 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
Chia-I Wu483e7702015-10-26 17:20:32 +08002931 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Chia-I Wu763a7492015-10-26 20:48:51 +08002932 for (uint32_t i=0; i < submit->commandBufferCount; i++) {
Mark Lobodzinski78940a42015-11-30 16:48:53 -07002933
2934#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
2935 skipCall |= ValidateCmdBufImageLayouts(submit->pCommandBuffers[i]);
2936#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
2937
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06002938 // Validate that cmd buffers have been updated
2939 pCB = getCBNode(dev_data, submit->pCommandBuffers[i]);
2940 loader_platform_thread_lock_mutex(&globalLock);
2941 pCB->submitCount++; // increment submit count
Chia-I Wu1f851912015-10-27 18:04:07 +08002942 if ((pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT) && (pCB->submitCount > 1)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002943 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, 0, DRAWSTATE_COMMAND_BUFFER_SINGLE_SUBMIT_VIOLATION, "DS",
Michael Lentine27b0f902015-10-12 11:30:14 -05002944 "CB %#" PRIxLEAST64 " was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted %#" PRIxLEAST64 " times.",
2945 reinterpret_cast<uint64_t>(pCB->commandBuffer), pCB->submitCount);
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06002946 }
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07002947 if (CB_RECORDED != pCB->state) {
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06002948 // Flag error for using CB w/o vkEndCommandBuffer() called
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002949 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, 0, DRAWSTATE_NO_END_COMMAND_BUFFER, "DS",
Chia-I Wu1f851912015-10-27 18:04:07 +08002950 "You must call vkEndCommandBuffer() on CB %#" PRIxLEAST64 " before this call to vkQueueSubmit()!", reinterpret_cast<uint64_t>(pCB->commandBuffer));
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06002951 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07002952 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06002953 }
Tobin Ehlise90b1712015-05-27 14:30:06 -06002954 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis28be0be2015-05-22 12:38:16 -06002955 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002956 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002957 if (VK_FALSE == skipCall)
Chia-I Wu483e7702015-10-26 17:20:32 +08002958 return dev_data->device_dispatch_table->QueueSubmit(queue, submitCount, pSubmits, fence);
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07002959 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002960}
2961
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002962VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002963{
Chia-I Wu69f40122015-10-26 21:10:41 +08002964 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroyFence(device, fence, pAllocator);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002965 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002966}
2967
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002968VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySemaphore(VkDevice device, VkSemaphore semaphore, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002969{
Chia-I Wu69f40122015-10-26 21:10:41 +08002970 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroySemaphore(device, semaphore, pAllocator);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002971 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002972}
2973
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002974VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002975{
Chia-I Wu69f40122015-10-26 21:10:41 +08002976 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroyEvent(device, event, pAllocator);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002977 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002978}
2979
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002980VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002981{
Chia-I Wu69f40122015-10-26 21:10:41 +08002982 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroyQueryPool(device, queryPool, pAllocator);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002983 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002984}
2985
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002986VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002987{
Tobin Ehlisb46be812015-10-23 16:00:08 -06002988 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08002989 dev_data->device_dispatch_table->DestroyBuffer(device, buffer, pAllocator);
Chia-I Wue420a332015-10-26 20:04:44 +08002990 dev_data->bufferMap.erase(buffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002991}
2992
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002993VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBufferView(VkDevice device, VkBufferView bufferView, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002994{
Tobin Ehlisb46be812015-10-23 16:00:08 -06002995 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08002996 dev_data->device_dispatch_table->DestroyBufferView(device, bufferView, pAllocator);
Chia-I Wue420a332015-10-26 20:04:44 +08002997 dev_data->bufferViewMap.erase(bufferView);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002998}
2999
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003000VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003001{
Tobin Ehlisb46be812015-10-23 16:00:08 -06003002 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003003 dev_data->device_dispatch_table->DestroyImage(device, image, pAllocator);
Chia-I Wue420a332015-10-26 20:04:44 +08003004 dev_data->imageMap.erase(image);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003005}
3006
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003007VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyImageView(VkDevice device, VkImageView imageView, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003008{
Chia-I Wu69f40122015-10-26 21:10:41 +08003009 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroyImageView(device, imageView, pAllocator);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003010 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003011}
3012
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003013VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003014{
Chia-I Wu69f40122015-10-26 21:10:41 +08003015 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroyShaderModule(device, shaderModule, pAllocator);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003016 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003017}
3018
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003019VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyPipeline(VkDevice device, VkPipeline pipeline, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003020{
Chia-I Wu69f40122015-10-26 21:10:41 +08003021 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroyPipeline(device, pipeline, pAllocator);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003022 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003023}
3024
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003025VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003026{
Chia-I Wu69f40122015-10-26 21:10:41 +08003027 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroyPipelineLayout(device, pipelineLayout, pAllocator);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003028 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003029}
3030
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003031VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySampler(VkDevice device, VkSampler sampler, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003032{
Chia-I Wu69f40122015-10-26 21:10:41 +08003033 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroySampler(device, sampler, pAllocator);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003034 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003035}
3036
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003037VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003038{
Chia-I Wu69f40122015-10-26 21:10:41 +08003039 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroyDescriptorSetLayout(device, descriptorSetLayout, pAllocator);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003040 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003041}
3042
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003043VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003044{
Chia-I Wu69f40122015-10-26 21:10:41 +08003045 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroyDescriptorPool(device, descriptorPool, pAllocator);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003046 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003047}
3048
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003049VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t count, const VkCommandBuffer *pCommandBuffers)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003050{
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003051 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3052
Courtney Goeltzenleuchter740451a2015-12-16 16:06:06 -07003053 for (uint32_t i = 0; i < count; i++) {
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003054 // Delete CB information structure, and remove from commandBufferMap
3055 auto cb = dev_data->commandBufferMap.find(pCommandBuffers[i]);
Mark Lobodzinski13b66742015-11-20 14:33:48 -07003056 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003057 if (cb != dev_data->commandBufferMap.end()) {
3058 delete (*cb).second;
3059 dev_data->commandBufferMap.erase(cb);
3060 }
3061
3062 // Remove commandBuffer reference from commandPoolMap
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003063 dev_data->commandPoolMap[commandPool].commandBuffers.remove(pCommandBuffers[i]);
Mark Lobodzinski13b66742015-11-20 14:33:48 -07003064 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003065 }
3066
3067 dev_data->device_dispatch_table->FreeCommandBuffers(device, commandPool, count, pCommandBuffers);
3068}
3069
3070VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkCommandPool* pCommandPool)
3071{
3072 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3073
3074 VkResult result = dev_data->device_dispatch_table->CreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
3075
3076 if (VK_SUCCESS == result) {
Mark Lobodzinski13b66742015-11-20 14:33:48 -07003077 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003078 dev_data->commandPoolMap[*pCommandPool].createFlags = pCreateInfo->flags;
Mark Lobodzinski13b66742015-11-20 14:33:48 -07003079 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003080 }
3081 return result;
3082}
3083
3084VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks* pAllocator)
3085{
3086 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski13b66742015-11-20 14:33:48 -07003087 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003088
3089 // Must remove cmdpool from cmdpoolmap, after removing all cmdbuffers in its list from the commandPoolMap
3090 if (dev_data->commandPoolMap.find(commandPool) != dev_data->commandPoolMap.end()) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003091 for (auto poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.begin(); poolCb != dev_data->commandPoolMap[commandPool].commandBuffers.end();) {
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003092 auto del_cb = dev_data->commandBufferMap.find(*poolCb);
3093 delete (*del_cb).second; // delete CB info structure
3094 dev_data->commandBufferMap.erase(del_cb); // Remove this command buffer from cbMap
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003095 poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.erase(poolCb); // Remove CB reference from commandPoolMap's list
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003096 }
3097 }
3098 dev_data->commandPoolMap.erase(commandPool);
Mark Lobodzinski13b66742015-11-20 14:33:48 -07003099
3100 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003101 dev_data->device_dispatch_table->DestroyCommandPool(device, commandPool, pAllocator);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003102}
3103
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003104VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandPool(
3105 VkDevice device,
3106 VkCommandPool commandPool,
3107 VkCommandPoolResetFlags flags)
3108{
3109 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003110 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003111
3112 result = dev_data->device_dispatch_table->ResetCommandPool(device, commandPool, flags);
3113 // Reset all of the CBs allocated from this pool
3114 if (VK_SUCCESS == result) {
3115 auto it = dev_data->commandPoolMap[commandPool].commandBuffers.begin();
3116 while (it != dev_data->commandPoolMap[commandPool].commandBuffers.end()) {
3117 resetCB(dev_data, (*it));
3118 ++it;
3119 }
3120 }
3121 return result;
3122}
3123
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003124VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003125{
Chia-I Wu69f40122015-10-26 21:10:41 +08003126 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroyFramebuffer(device, framebuffer, pAllocator);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003127 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003128}
3129
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003130VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003131{
Chia-I Wu69f40122015-10-26 21:10:41 +08003132 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroyRenderPass(device, renderPass, pAllocator);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003133 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003134}
3135
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003136VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateBuffer(VkDevice device, const VkBufferCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkBuffer* pBuffer)
Tobin Ehlisb46be812015-10-23 16:00:08 -06003137{
3138 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003139 VkResult result = dev_data->device_dispatch_table->CreateBuffer(device, pCreateInfo, pAllocator, pBuffer);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003140 if (VK_SUCCESS == result) {
3141 loader_platform_thread_lock_mutex(&globalLock);
3142 // TODO : This doesn't create deep copy of pQueueFamilyIndices so need to fix that if/when we want that data to be valid
Chia-I Wue420a332015-10-26 20:04:44 +08003143 dev_data->bufferMap[*pBuffer] = unique_ptr<VkBufferCreateInfo>(new VkBufferCreateInfo(*pCreateInfo));
Tobin Ehlisb46be812015-10-23 16:00:08 -06003144 loader_platform_thread_unlock_mutex(&globalLock);
3145 }
3146 return result;
3147}
3148
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003149VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkBufferView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003150{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003151 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003152 VkResult result = dev_data->device_dispatch_table->CreateBufferView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003153 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003154 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue420a332015-10-26 20:04:44 +08003155 dev_data->bufferViewMap[*pView] = unique_ptr<VkBufferViewCreateInfo>(new VkBufferViewCreateInfo(*pCreateInfo));
Tobin Ehlisb46be812015-10-23 16:00:08 -06003156 loader_platform_thread_unlock_mutex(&globalLock);
3157 }
3158 return result;
3159}
3160
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003161VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateImage(VkDevice device, const VkImageCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkImage* pImage)
Tobin Ehlisb46be812015-10-23 16:00:08 -06003162{
3163 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003164 VkResult result = dev_data->device_dispatch_table->CreateImage(device, pCreateInfo, pAllocator, pImage);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003165 if (VK_SUCCESS == result) {
Michael Lentine27b0f902015-10-12 11:30:14 -05003166 IMAGE_NODE* image_node = new IMAGE_NODE;
3167 image_node->layout = pCreateInfo->initialLayout;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003168 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue420a332015-10-26 20:04:44 +08003169 dev_data->imageMap[*pImage] = unique_ptr<VkImageCreateInfo>(new VkImageCreateInfo(*pCreateInfo));
Michael Lentine27b0f902015-10-12 11:30:14 -05003170 dev_data->imageLayoutMap[*pImage] = image_node;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003171 loader_platform_thread_unlock_mutex(&globalLock);
3172 }
3173 return result;
3174}
3175
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003176VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkImageView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003177{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003178 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003179 VkResult result = dev_data->device_dispatch_table->CreateImageView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003180 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003181 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue420a332015-10-26 20:04:44 +08003182 dev_data->imageViewMap[*pView] = unique_ptr<VkImageViewCreateInfo>(new VkImageViewCreateInfo(*pCreateInfo));
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003183 loader_platform_thread_unlock_mutex(&globalLock);
3184 }
3185 return result;
3186}
3187
Jon Ashburn0d60d272015-07-09 15:02:25 -06003188//TODO handle pipeline caches
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003189VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineCache(
Jon Ashburn0d60d272015-07-09 15:02:25 -06003190 VkDevice device,
3191 const VkPipelineCacheCreateInfo* pCreateInfo,
Chia-I Wu1f851912015-10-27 18:04:07 +08003192 const VkAllocationCallbacks* pAllocator,
Jon Ashburn0d60d272015-07-09 15:02:25 -06003193 VkPipelineCache* pPipelineCache)
3194{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003195 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003196 VkResult result = dev_data->device_dispatch_table->CreatePipelineCache(device, pCreateInfo, pAllocator, pPipelineCache);
Jon Ashburn0d60d272015-07-09 15:02:25 -06003197 return result;
3198}
3199
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003200VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineCache(
Jon Ashburn0d60d272015-07-09 15:02:25 -06003201 VkDevice device,
Chia-I Wu69f40122015-10-26 21:10:41 +08003202 VkPipelineCache pipelineCache,
Chia-I Wu1f851912015-10-27 18:04:07 +08003203 const VkAllocationCallbacks* pAllocator)
Jon Ashburn0d60d272015-07-09 15:02:25 -06003204{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003205 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003206 dev_data->device_dispatch_table->DestroyPipelineCache(device, pipelineCache, pAllocator);
Jon Ashburn0d60d272015-07-09 15:02:25 -06003207}
3208
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003209VKAPI_ATTR VkResult VKAPI_CALL vkGetPipelineCacheData(
Jon Ashburn0d60d272015-07-09 15:02:25 -06003210 VkDevice device,
3211 VkPipelineCache pipelineCache,
Chia-I Wu28c3c432015-10-26 19:17:06 +08003212 size_t* pDataSize,
Jon Ashburn0d60d272015-07-09 15:02:25 -06003213 void* pData)
3214{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003215 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu28c3c432015-10-26 19:17:06 +08003216 VkResult result = dev_data->device_dispatch_table->GetPipelineCacheData(device, pipelineCache, pDataSize, pData);
Jon Ashburn0d60d272015-07-09 15:02:25 -06003217 return result;
3218}
3219
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003220VKAPI_ATTR VkResult VKAPI_CALL vkMergePipelineCaches(
Jon Ashburn0d60d272015-07-09 15:02:25 -06003221 VkDevice device,
Chia-I Wu1f851912015-10-27 18:04:07 +08003222 VkPipelineCache dstCache,
Jon Ashburn0d60d272015-07-09 15:02:25 -06003223 uint32_t srcCacheCount,
3224 const VkPipelineCache* pSrcCaches)
3225{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003226 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu1f851912015-10-27 18:04:07 +08003227 VkResult result = dev_data->device_dispatch_table->MergePipelineCaches(device, dstCache, srcCacheCount, pSrcCaches);
Jon Ashburn0d60d272015-07-09 15:02:25 -06003228 return result;
3229}
3230
Mark Lobodzinski2adea752015-11-10 15:25:01 -07003231VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateGraphicsPipelines(
3232 VkDevice device,
3233 VkPipelineCache pipelineCache,
3234 uint32_t count,
3235 const VkGraphicsPipelineCreateInfo *pCreateInfos,
3236 const VkAllocationCallbacks *pAllocator,
3237 VkPipeline *pPipelines)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003238{
Courtney Goeltzenleuchtera54b76a2015-09-04 13:39:59 -06003239 VkResult result = VK_SUCCESS;
Tobin Ehlise48be202015-09-16 10:33:53 -06003240 //TODO What to do with pipelineCache?
Tobin Ehlisde63c532015-06-18 15:59:33 -06003241 // The order of operations here is a little convoluted but gets the job done
3242 // 1. Pipeline create state is first shadowed into PIPELINE_NODE struct
3243 // 2. Create state is then validated (which uses flags setup during shadowing)
3244 // 3. If everything looks good, we'll then create the pipeline and add NODE to pipelineMap
Tobin Ehlise48be202015-09-16 10:33:53 -06003245 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis76c18852015-09-17 16:33:58 -06003246 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
3247 vector<PIPELINE_NODE*> pPipeNode(count);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003248 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski2adea752015-11-10 15:25:01 -07003249
Tobin Ehlise48be202015-09-16 10:33:53 -06003250 uint32_t i=0;
Tobin Ehlisde63c532015-06-18 15:59:33 -06003251 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski2adea752015-11-10 15:25:01 -07003252
Tobin Ehlise48be202015-09-16 10:33:53 -06003253 for (i=0; i<count; i++) {
Mark Lobodzinski2adea752015-11-10 15:25:01 -07003254 pPipeNode[i] = initGraphicsPipeline(dev_data, &pCreateInfos[i], NULL);
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003255 skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
Tobin Ehlise48be202015-09-16 10:33:53 -06003256 }
Mark Lobodzinski2adea752015-11-10 15:25:01 -07003257
Tobin Ehlisde63c532015-06-18 15:59:33 -06003258 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis32479352015-12-01 09:48:58 -07003259
Tobin Ehlisad61de42015-12-02 13:53:34 -07003260 if (VK_FALSE == skipCall) {
Mark Lobodzinski2adea752015-11-10 15:25:01 -07003261 result = dev_data->device_dispatch_table->CreateGraphicsPipelines(device,
3262 pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
Tobin Ehlisde63c532015-06-18 15:59:33 -06003263 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlise48be202015-09-16 10:33:53 -06003264 for (i=0; i<count; i++) {
3265 pPipeNode[i]->pipeline = pPipelines[i];
Chia-I Wue420a332015-10-26 20:04:44 +08003266 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
Tobin Ehlise48be202015-09-16 10:33:53 -06003267 }
Tobin Ehlisde63c532015-06-18 15:59:33 -06003268 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003269 } else {
Tobin Ehlise48be202015-09-16 10:33:53 -06003270 for (i=0; i<count; i++) {
3271 if (pPipeNode[i]) {
3272 // If we allocated a pipeNode, need to clean it up here
3273 delete[] pPipeNode[i]->pVertexBindingDescriptions;
3274 delete[] pPipeNode[i]->pVertexAttributeDescriptions;
3275 delete[] pPipeNode[i]->pAttachments;
3276 delete pPipeNode[i];
3277 }
Tobin Ehlisde63c532015-06-18 15:59:33 -06003278 }
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003279 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisde63c532015-06-18 15:59:33 -06003280 }
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06003281 return result;
3282}
3283
Mark Lobodzinski2adea752015-11-10 15:25:01 -07003284VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateComputePipelines(
3285 VkDevice device,
3286 VkPipelineCache pipelineCache,
3287 uint32_t count,
3288 const VkComputePipelineCreateInfo *pCreateInfos,
3289 const VkAllocationCallbacks *pAllocator,
3290 VkPipeline *pPipelines)
3291{
3292 VkResult result = VK_SUCCESS;
3293 VkBool32 skipCall = VK_FALSE;
3294
3295 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
3296 vector<PIPELINE_NODE*> pPipeNode(count);
3297 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3298
3299 uint32_t i=0;
3300 loader_platform_thread_lock_mutex(&globalLock);
3301 for (i=0; i<count; i++) {
3302 // TODO: Verify compute stage bits
3303
3304 // Create and initialize internal tracking data structure
3305 pPipeNode[i] = new PIPELINE_NODE;
3306 memset((void*)pPipeNode[i], 0, sizeof(PIPELINE_NODE));
3307 memcpy(&pPipeNode[i]->computePipelineCI, (const void*)&pCreateInfos[i], sizeof(VkComputePipelineCreateInfo));
3308
3309 // TODO: Add Compute Pipeline Verification
3310 // skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
3311 }
3312 loader_platform_thread_unlock_mutex(&globalLock);
3313
3314 if (VK_FALSE == skipCall) {
3315 result = dev_data->device_dispatch_table->CreateComputePipelines(device, pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
3316 loader_platform_thread_lock_mutex(&globalLock);
3317 for (i=0; i<count; i++) {
3318 pPipeNode[i]->pipeline = pPipelines[i];
3319 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
3320 }
3321 loader_platform_thread_unlock_mutex(&globalLock);
3322 } else {
3323 for (i=0; i<count; i++) {
3324 if (pPipeNode[i]) {
3325 // Clean up any locally allocated data structures
3326 delete pPipeNode[i];
3327 }
3328 }
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003329 return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinski2adea752015-11-10 15:25:01 -07003330 }
3331 return result;
3332}
3333
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003334VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSampler* pSampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003335{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003336 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003337 VkResult result = dev_data->device_dispatch_table->CreateSampler(device, pCreateInfo, pAllocator, pSampler);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003338 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003339 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue420a332015-10-26 20:04:44 +08003340 dev_data->sampleMap[*pSampler] = unique_ptr<SAMPLER_NODE>(new SAMPLER_NODE(pSampler, pCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003341 loader_platform_thread_unlock_mutex(&globalLock);
3342 }
3343 return result;
3344}
3345
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003346VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDescriptorSetLayout* pSetLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003347{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003348 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003349 VkResult result = dev_data->device_dispatch_table->CreateDescriptorSetLayout(device, pCreateInfo, pAllocator, pSetLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003350 if (VK_SUCCESS == result) {
Tobin Ehliscb085292015-12-01 09:57:09 -07003351 // TODOSC : Capture layout bindings set
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003352 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
3353 if (NULL == pNewNode) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003354 if (log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, (uint64_t) *pSetLayout, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003355 "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()"))
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003356 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003357 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003358 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003359 pNewNode->createInfo.pBinding = new VkDescriptorSetLayoutBinding[pCreateInfo->bindingCount];
3360 memcpy((void*)pNewNode->createInfo.pBinding, pCreateInfo->pBinding, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->bindingCount);
Chia-I Wub5689ee2015-10-31 00:31:16 +08003361 // g++ does not like reserve with size 0
3362 if (pCreateInfo->bindingCount)
3363 pNewNode->bindings.reserve(pCreateInfo->bindingCount);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003364 uint32_t totalCount = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08003365 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
Chia-I Wub5689ee2015-10-31 00:31:16 +08003366 if (!pNewNode->bindings.insert(pCreateInfo->pBinding[i].binding).second) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003367 if (log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, (uint64_t) *pSetLayout, 0, DRAWSTATE_INVALID_LAYOUT, "DS",
Chia-I Wub5689ee2015-10-31 00:31:16 +08003368 "duplicated binding number in VkDescriptorSetLayoutBinding"))
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003369 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wub5689ee2015-10-31 00:31:16 +08003370 }
3371
Chia-I Wu045654f2015-11-06 06:42:02 +08003372 totalCount += pCreateInfo->pBinding[i].descriptorCount;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003373 if (pCreateInfo->pBinding[i].pImmutableSamplers) {
3374 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBinding[i].pImmutableSamplers;
Chia-I Wu045654f2015-11-06 06:42:02 +08003375 *ppIS = new VkSampler[pCreateInfo->pBinding[i].descriptorCount];
3376 memcpy(*ppIS, pCreateInfo->pBinding[i].pImmutableSamplers, pCreateInfo->pBinding[i].descriptorCount*sizeof(VkSampler));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003377 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003378 }
3379 if (totalCount > 0) {
Cody Northrop8a908322015-10-26 14:07:35 -06003380 pNewNode->descriptorTypes.resize(totalCount);
Tobin Ehlis68fbd442015-10-27 12:25:35 -06003381 pNewNode->stageFlags.resize(totalCount);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003382 uint32_t offset = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003383 uint32_t j = 0;
Tobin Ehlis61ebb312015-11-04 12:28:28 -07003384 VkDescriptorType dType;
Chia-I Wu763a7492015-10-26 20:48:51 +08003385 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
Tobin Ehlis61ebb312015-11-04 12:28:28 -07003386 dType = pCreateInfo->pBinding[i].descriptorType;
Chia-I Wu045654f2015-11-06 06:42:02 +08003387 for (j = 0; j < pCreateInfo->pBinding[i].descriptorCount; j++) {
Tobin Ehlis61ebb312015-11-04 12:28:28 -07003388 pNewNode->descriptorTypes[offset + j] = dType;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003389 pNewNode->stageFlags[offset + j] = pCreateInfo->pBinding[i].stageFlags;
Tobin Ehlis61ebb312015-11-04 12:28:28 -07003390 if ((dType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
3391 (dType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
3392 pNewNode->dynamicDescriptorCount++;
3393 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003394 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003395 offset += j;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003396 }
3397 }
3398 pNewNode->layout = *pSetLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003399 pNewNode->startIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003400 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
3401 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003402 // Put new node at Head of global Layer list
3403 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisad61de42015-12-02 13:53:34 -07003404 dev_data->descriptorSetLayoutMap[*pSetLayout] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003405 loader_platform_thread_unlock_mutex(&globalLock);
3406 }
3407 return result;
3408}
3409
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003410VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003411{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003412 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003413 VkResult result = dev_data->device_dispatch_table->CreatePipelineLayout(device, pCreateInfo, pAllocator, pPipelineLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003414 if (VK_SUCCESS == result) {
Tobin Ehliscb085292015-12-01 09:57:09 -07003415 // TODOSC : Merge capture of the setLayouts per pipeline
Tobin Ehlis982099b2015-11-05 09:52:49 -07003416 PIPELINE_LAYOUT_NODE& plNode = dev_data->pipelineLayoutMap[*pPipelineLayout];
Chia-I Wu763a7492015-10-26 20:48:51 +08003417 plNode.descriptorSetLayouts.resize(pCreateInfo->setLayoutCount);
Tobin Ehlis91423d22015-10-20 10:11:55 -06003418 uint32_t i = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08003419 for (i=0; i<pCreateInfo->setLayoutCount; ++i) {
Tobin Ehlis91423d22015-10-20 10:11:55 -06003420 plNode.descriptorSetLayouts[i] = pCreateInfo->pSetLayouts[i];
3421 }
Cody Northrop8a908322015-10-26 14:07:35 -06003422 plNode.pushConstantRanges.resize(pCreateInfo->pushConstantRangeCount);
Tobin Ehlis91423d22015-10-20 10:11:55 -06003423 for (i=0; i<pCreateInfo->pushConstantRangeCount; ++i) {
3424 plNode.pushConstantRanges[i] = pCreateInfo->pPushConstantRanges[i];
3425 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003426 }
3427 return result;
3428}
3429
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003430VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDescriptorPool* pDescriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003431{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003432 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003433 VkResult result = dev_data->device_dispatch_table->CreateDescriptorPool(device, pCreateInfo, pAllocator, pDescriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003434 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003435 // Insert this pool into Global Pool LL at head
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003436 if (log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, (uint64_t) *pDescriptorPool, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
Chia-I Wue420a332015-10-26 20:04:44 +08003437 "Created Descriptor Pool %#" PRIxLEAST64, (uint64_t) *pDescriptorPool))
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003438 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003439 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003440 DESCRIPTOR_POOL_NODE* pNewNode = new DESCRIPTOR_POOL_NODE(*pDescriptorPool, pCreateInfo);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003441 if (NULL == pNewNode) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003442 if (log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, (uint64_t) *pDescriptorPool, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003443 "Out of memory while attempting to allocate DESCRIPTOR_POOL_NODE in vkCreateDescriptorPool()"))
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003444 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003445 } else {
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003446 dev_data->descriptorPoolMap[*pDescriptorPool] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003447 }
3448 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003449 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003450 // Need to do anything if pool create fails?
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003451 }
3452 return result;
3453}
3454
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003455VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorPoolResetFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003456{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003457 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003458 VkResult result = dev_data->device_dispatch_table->ResetDescriptorPool(device, descriptorPool, flags);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003459 if (VK_SUCCESS == result) {
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003460 clearDescriptorPool(dev_data, device, descriptorPool, flags);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003461 }
3462 return result;
3463}
3464
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003465VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo* pAllocateInfo, VkDescriptorSet* pDescriptorSets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003466{
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003467 VkBool32 skipCall = VK_FALSE;
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003468 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003469 // Verify that requested descriptorSets are available in pool
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003470 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003471 if (!pPoolNode) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003472 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, (uint64_t) pAllocateInfo->descriptorPool, 0, DRAWSTATE_INVALID_POOL, "DS",
Chia-I Wu1f851912015-10-27 18:04:07 +08003473 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pAllocateInfo->descriptorPool);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003474 } else { // Make sure pool has all the available descriptors before calling down chain
Chia-I Wu1f851912015-10-27 18:04:07 +08003475 skipCall |= validate_descriptor_availability_in_pool(dev_data, pPoolNode, pAllocateInfo->setLayoutCount, pAllocateInfo->pSetLayouts);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003476 }
3477 if (skipCall)
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003478 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wu1f851912015-10-27 18:04:07 +08003479 VkResult result = dev_data->device_dispatch_table->AllocateDescriptorSets(device, pAllocateInfo, pDescriptorSets);
Cody Northropc8aa4a52015-08-03 12:47:29 -06003480 if (VK_SUCCESS == result) {
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003481 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003482 if (pPoolNode) {
Chia-I Wu1f851912015-10-27 18:04:07 +08003483 if (pAllocateInfo->setLayoutCount == 0) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003484 log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, pAllocateInfo->setLayoutCount, 0, DRAWSTATE_NONE, "DS",
Chia-I Wu1f851912015-10-27 18:04:07 +08003485 "AllocateDescriptorSets called with 0 count");
Cody Northropc8aa4a52015-08-03 12:47:29 -06003486 }
Chia-I Wu1f851912015-10-27 18:04:07 +08003487 for (uint32_t i = 0; i < pAllocateInfo->setLayoutCount; i++) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003488 log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pDescriptorSets[i], 0, DRAWSTATE_NONE, "DS",
Chia-I Wue420a332015-10-26 20:04:44 +08003489 "Created Descriptor Set %#" PRIxLEAST64, (uint64_t) pDescriptorSets[i]);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003490 // Create new set node and add to head of pool nodes
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003491 SET_NODE* pNewNode = new SET_NODE;
3492 if (NULL == pNewNode) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003493 if (log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pDescriptorSets[i], 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
Chia-I Wu1f851912015-10-27 18:04:07 +08003494 "Out of memory while attempting to allocate SET_NODE in vkAllocateDescriptorSets()"))
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003495 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003496 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003497 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlisf6e93e02015-10-19 12:09:13 -06003498 // TODO : Pool should store a total count of each type of Descriptor available
3499 // When descriptors are allocated, decrement the count and validate here
3500 // that the count doesn't go below 0. One reset/free need to bump count back up.
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003501 // Insert set at head of Set LL for this pool
3502 pNewNode->pNext = pPoolNode->pSets;
3503 pPoolNode->pSets = pNewNode;
Chia-I Wu1f851912015-10-27 18:04:07 +08003504 LAYOUT_NODE* pLayout = getLayoutNode(dev_data, pAllocateInfo->pSetLayouts[i]);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003505 if (NULL == pLayout) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003506 if (log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, (uint64_t) pAllocateInfo->pSetLayouts[i], 0, DRAWSTATE_INVALID_LAYOUT, "DS",
Chia-I Wu1f851912015-10-27 18:04:07 +08003507 "Unable to find set layout node for layout %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pAllocateInfo->pSetLayouts[i]))
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003508 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003509 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003510 pNewNode->pLayout = pLayout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003511 pNewNode->pool = pAllocateInfo->descriptorPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003512 pNewNode->set = pDescriptorSets[i];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003513 pNewNode->descriptorCount = pLayout->endIndex + 1;
3514 if (pNewNode->descriptorCount) {
3515 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
3516 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
3517 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
3518 }
Chia-I Wue420a332015-10-26 20:04:44 +08003519 dev_data->setMap[pDescriptorSets[i]] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003520 }
3521 }
3522 }
3523 }
3524 return result;
3525}
3526
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003527VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, const VkDescriptorSet* pDescriptorSets)
Tony Barbourb857d312015-07-10 10:50:45 -06003528{
Tobin Ehlis3c543112015-10-08 13:13:50 -06003529 VkBool32 skipCall = VK_FALSE;
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003530 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003531 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, descriptorPool);
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003532 if (pPoolNode && !(VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT & pPoolNode->createInfo.flags)) {
3533 // Can't Free from a NON_FREE pool
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003534 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, (uint64_t)device, 0, DRAWSTATE_CANT_FREE_FROM_NON_FREE_POOL, "DS",
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003535 "It is invalid to call vkFreeDescriptorSets() with a pool created without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Tobin Ehlis3c543112015-10-08 13:13:50 -06003536 }
3537 if (skipCall)
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003538 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003539 VkResult result = dev_data->device_dispatch_table->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003540 if (VK_SUCCESS == result) {
3541 // For each freed descriptor add it back into the pool as available
3542 for (uint32_t i=0; i<count; ++i) {
Chia-I Wue420a332015-10-26 20:04:44 +08003543 SET_NODE* pSet = dev_data->setMap[pDescriptorSets[i]]; // getSetNode() without locking
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003544 LAYOUT_NODE* pLayout = pSet->pLayout;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003545 uint32_t typeIndex = 0, poolSizeCount = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08003546 for (uint32_t j=0; j<pLayout->createInfo.bindingCount; ++j) {
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003547 typeIndex = static_cast<uint32_t>(pLayout->createInfo.pBinding[j].descriptorType);
Chia-I Wu045654f2015-11-06 06:42:02 +08003548 poolSizeCount = pLayout->createInfo.pBinding[j].descriptorCount;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003549 pPoolNode->availableDescriptorTypeCount[typeIndex] += poolSizeCount;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003550 }
3551 }
3552 }
3553 // TODO : Any other clean-up or book-keeping to do here?
Tony Barbourb857d312015-07-10 10:50:45 -06003554 return result;
3555}
3556
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003557VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount, const VkWriteDescriptorSet* pDescriptorWrites, uint32_t descriptorCopyCount, const VkCopyDescriptorSet* pDescriptorCopies)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003558{
Tobin Ehlis68fbd442015-10-27 12:25:35 -06003559 // dsUpdate will return VK_TRUE only if a bailout error occurs, so we want to call down tree when update returns VK_FALSE
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06003560 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu483e7702015-10-26 17:20:32 +08003561 if (!dsUpdate(dev_data, device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies)) {
3562 dev_data->device_dispatch_table->UpdateDescriptorSets(device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies);
Jon Ashburne0fa2282015-05-20 09:00:28 -06003563 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003564}
3565
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003566VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo* pCreateInfo, VkCommandBuffer* pCommandBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003567{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003568 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu1f851912015-10-27 18:04:07 +08003569 VkResult result = dev_data->device_dispatch_table->AllocateCommandBuffers(device, pCreateInfo, pCommandBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003570 if (VK_SUCCESS == result) {
Courtney Goeltzenleuchter740451a2015-12-16 16:06:06 -07003571 for (uint32_t i = 0; i < pCreateInfo->bufferCount; i++) {
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003572 // Validate command pool
3573 if (dev_data->commandPoolMap.find(pCreateInfo->commandPool) != dev_data->commandPoolMap.end()) {
Mark Lobodzinski13b66742015-11-20 14:33:48 -07003574 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003575 // Add command buffer to its commandPool map
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003576 dev_data->commandPoolMap[pCreateInfo->commandPool].commandBuffers.push_back(pCommandBuffer[i]);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003577 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
3578 // Add command buffer to map
3579 dev_data->commandBufferMap[pCommandBuffer[i]] = pCB;
Mark Lobodzinski13b66742015-11-20 14:33:48 -07003580 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003581 resetCB(dev_data, pCommandBuffer[i]);
3582 pCB->commandBuffer = pCommandBuffer[i];
3583 pCB->createInfo = *pCreateInfo;
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003584 }
3585 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003586 }
3587 return result;
3588}
3589
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003590VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo* pBeginInfo)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003591{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003592 VkBool32 skipCall = false;
Chia-I Wu1f851912015-10-27 18:04:07 +08003593 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06003594 // Validate command buffer level
Chia-I Wu1f851912015-10-27 18:04:07 +08003595 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06003596 if (pCB) {
Mark Lobodzinskia1420862015-11-19 13:22:11 -07003597 if (pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
Chia-I Wue420a332015-10-26 20:04:44 +08003598 if (pBeginInfo->renderPass || pBeginInfo->framebuffer) {
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06003599 // These should be NULL for a Primary CB
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003600 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, 0, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
Tobin Ehlisc5191da2015-12-16 07:17:23 -07003601 "vkBeginCommandBuffer(): Primary Command Buffer (%p) may not specify framebuffer or renderpass parameters.", (void*)commandBuffer);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06003602 }
Tobin Ehlisc5191da2015-12-16 07:17:23 -07003603 } else { // Secondary Command Buffer
Tobin Ehlisb51cb782015-12-16 08:19:42 -07003604 // TODO : Add check here from spec "If commandBuffer is a secondary command buffer and either the
3605 // occlusionQueryEnable member of pBeginInfo is VK_FALSE, or the precise occlusion queries feature
3606 // is not enabled, the queryFlags member of pBeginInfo must not contain VK_QUERY_CONTROL_PRECISE_BIT"
Tobin Ehlis9185b0a2015-12-16 05:01:22 -07003607 if (pBeginInfo->flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT) {
3608 if (!pBeginInfo->renderPass) { // renderpass should NOT be null for an Secondary CB
3609 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, 0, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
3610 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) must specify a valid renderpass parameter.", (void*)commandBuffer);
3611 }
3612 if (!pBeginInfo->framebuffer) { // framebuffer may be null for an Secondary CB, but this affects perf
3613 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, 0, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
3614 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) may perform better if a valid framebuffer parameter is specified.", (void*)commandBuffer);
3615 } else {
3616 string errorString = "";
3617 VkRenderPass fbRP = dev_data->frameBufferMap[pBeginInfo->framebuffer]->renderPass;
3618 if (!verify_renderpass_compatibility(dev_data, fbRP, pBeginInfo->renderPass, errorString)) {
3619 // renderPass that framebuffer was created with must be compatible with local renderPass
3620 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, 0, DRAWSTATE_RENDERPASS_INCOMPATIBLE, "DS",
3621 "vkBeginCommandBuffer(): Secondary Command Buffer (%p) renderPass (%#" PRIxLEAST64 ") is incompatible w/ framebuffer (%#" PRIxLEAST64 ") w/ render pass (%#" PRIxLEAST64 ") due to: %s",
3622 (void*)commandBuffer, (uint64_t)pBeginInfo->renderPass, (uint64_t)pBeginInfo->framebuffer, (uint64_t)fbRP, errorString.c_str());
3623 }
3624 }
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06003625 }
3626 }
Tobin Ehlis0cea4082015-08-18 07:10:58 -06003627 pCB->beginInfo = *pBeginInfo;
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003628 if (CB_RECORDING == pCB->state) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003629 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, 0, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003630 "vkBeginCommandBuffer(): Cannot call Begin on CB (%#" PRIxLEAST64 ") in the RECORDING state. Must first call vkEndCommandBuffer().", (uint64_t)commandBuffer);
3631 } else if (CB_RECORDED == pCB->state) {
3632 VkCommandPool cmdPool = pCB->createInfo.commandPool;
3633 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003634 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer,
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003635 0, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
3636 "Call to vkBeginCommandBuffer() on command buffer (%#" PRIxLEAST64 ") attempts to implicitly reset cmdBuffer created from command pool (%#" PRIxLEAST64 ") that does NOT have the VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT bit set.",
3637 (uint64_t) commandBuffer, (uint64_t) cmdPool);
3638 }
3639 }
Tobin Ehlis0cea4082015-08-18 07:10:58 -06003640 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003641 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, 0, DRAWSTATE_INVALID_COMMAND_BUFFER, "DS",
Chia-I Wu1f851912015-10-27 18:04:07 +08003642 "In vkBeginCommandBuffer() and unable to find CommandBuffer Node for CB %p!", (void*)commandBuffer);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06003643 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003644 if (skipCall) {
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003645 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter3abd86e2015-09-04 15:03:52 -06003646 }
Chia-I Wu1f851912015-10-27 18:04:07 +08003647 VkResult result = dev_data->device_dispatch_table->BeginCommandBuffer(commandBuffer, pBeginInfo);
Mark Lobodzinski2ad35592015-11-12 16:14:04 -07003648 if ((VK_SUCCESS == result) && (pCB != NULL)) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07003649 if (CB_RECORDED == pCB->state) { resetCB(dev_data, commandBuffer); } pCB->state = CB_RECORDING; }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003650 return result;
3651}
3652
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003653VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEndCommandBuffer(VkCommandBuffer commandBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003654{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003655 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchtera54b76a2015-09-04 13:39:59 -06003656 VkResult result = VK_SUCCESS;
Chia-I Wu1f851912015-10-27 18:04:07 +08003657 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3658 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlise42007c2015-06-19 13:00:59 -06003659 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003660 if (pCB->state != CB_RECORDING) {
Chia-I Wu1f851912015-10-27 18:04:07 +08003661 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkEndCommandBuffer()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003662 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003663 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003664 if (VK_FALSE == skipCall) {
Chia-I Wu1f851912015-10-27 18:04:07 +08003665 result = dev_data->device_dispatch_table->EndCommandBuffer(commandBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003666 if (VK_SUCCESS == result) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003667 pCB->state = CB_RECORDED;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003668 // Reset CB status flags
3669 pCB->status = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08003670 printCB(dev_data, commandBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003671 }
3672 } else {
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003673 result = VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003674 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003675 return result;
3676}
3677
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003678VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003679{
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003680 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003681 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003682 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
3683 VkCommandPool cmdPool = pCB->createInfo.commandPool;
3684 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003685 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t) commandBuffer,
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003686 0, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
3687 "Attempt to reset command buffer (%#" PRIxLEAST64 ") created from command pool (%#" PRIxLEAST64 ") that does NOT have the VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT bit set.",
3688 (uint64_t) commandBuffer, (uint64_t) cmdPool);
3689 }
3690 if (skipCall)
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003691 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wu1f851912015-10-27 18:04:07 +08003692 VkResult result = dev_data->device_dispatch_table->ResetCommandBuffer(commandBuffer, flags);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003693 if (VK_SUCCESS == result) {
Chia-I Wu1f851912015-10-27 18:04:07 +08003694 resetCB(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003695 }
3696 return result;
3697}
3698
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003699VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003700{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003701 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003702 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3703 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003704 if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07003705 skipCall |= addCmd(dev_data, pCB, CMD_BINDPIPELINE, "vkCmdBindPipeline()");
3706 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
3707 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, (uint64_t) pipeline,
3708 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
3709 "Incorrectly binding compute pipeline (%#" PRIxLEAST64 ") during active RenderPass (%#" PRIxLEAST64 ")",
3710 (uint64_t) pipeline, (uint64_t) pCB->activeRenderPass);
3711 } else if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
3712 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdBindPipeline");
3713 }
3714
3715 PIPELINE_NODE* pPN = getPipeline(dev_data, pipeline);
3716 if (pPN) {
3717 pCB->lastBoundPipeline = pipeline;
3718 loader_platform_thread_lock_mutex(&globalLock);
3719 set_cb_pso_status(pCB, pPN);
3720 loader_platform_thread_unlock_mutex(&globalLock);
3721 skipCall |= validatePipelineState(dev_data, pCB, pipelineBindPoint, pipeline);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003722 } else {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07003723 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
3724 (uint64_t) pipeline, 0, DRAWSTATE_INVALID_PIPELINE, "DS",
3725 "Attempt to bind Pipeline %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<uint64_t>(pipeline));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003726 }
3727 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003728 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003729 dev_data->device_dispatch_table->CmdBindPipeline(commandBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003730}
3731
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003732VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetViewport(
Chia-I Wu1f851912015-10-27 18:04:07 +08003733 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06003734 uint32_t viewportCount,
3735 const VkViewport* pViewports)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003736{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003737 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003738 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3739 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlise42007c2015-06-19 13:00:59 -06003740 if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07003741 skipCall |= addCmd(dev_data, pCB, CMD_SETVIEWPORTSTATE, "vkCmdSetViewport()");
3742 loader_platform_thread_lock_mutex(&globalLock);
3743 pCB->status |= CBSTATUS_VIEWPORT_SET;
3744 pCB->viewports.resize(viewportCount);
3745 memcpy(pCB->viewports.data(), pViewports, viewportCount * sizeof(VkViewport));
3746 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlise42007c2015-06-19 13:00:59 -06003747 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003748 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003749 dev_data->device_dispatch_table->CmdSetViewport(commandBuffer, viewportCount, pViewports);
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06003750}
3751
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003752VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetScissor(
Chia-I Wu1f851912015-10-27 18:04:07 +08003753 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06003754 uint32_t scissorCount,
3755 const VkRect2D* pScissors)
3756{
3757 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003758 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3759 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06003760 if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07003761 skipCall |= addCmd(dev_data, pCB, CMD_SETSCISSORSTATE, "vkCmdSetScissor()");
3762 loader_platform_thread_lock_mutex(&globalLock);
3763 pCB->status |= CBSTATUS_SCISSOR_SET;
3764 pCB->scissors.resize(scissorCount);
3765 memcpy(pCB->scissors.data(), pScissors, scissorCount * sizeof(VkRect2D));
3766 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06003767 }
3768 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003769 dev_data->device_dispatch_table->CmdSetScissor(commandBuffer, scissorCount, pScissors);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003770}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003771
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003772VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003773{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003774 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003775 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3776 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003777 if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07003778 skipCall |= addCmd(dev_data, pCB, CMD_SETLINEWIDTHSTATE, "vkCmdSetLineWidth()");
3779 /* TODO: Do we still need this lock? */
3780 loader_platform_thread_lock_mutex(&globalLock);
3781 pCB->status |= CBSTATUS_LINE_WIDTH_SET;
3782 pCB->lineWidth = lineWidth;
3783 loader_platform_thread_unlock_mutex(&globalLock);
Cody Northropf5bd2252015-08-17 11:10:49 -06003784 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003785 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003786 dev_data->device_dispatch_table->CmdSetLineWidth(commandBuffer, lineWidth);
Cody Northropf5bd2252015-08-17 11:10:49 -06003787}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003788
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003789VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBias(
Chia-I Wu1f851912015-10-27 18:04:07 +08003790 VkCommandBuffer commandBuffer,
Chia-I Wufa950c52015-10-26 19:08:09 +08003791 float depthBiasConstantFactor,
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003792 float depthBiasClamp,
Chia-I Wufa950c52015-10-26 19:08:09 +08003793 float depthBiasSlopeFactor)
Cody Northropf5bd2252015-08-17 11:10:49 -06003794{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003795 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003796 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3797 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northropf5bd2252015-08-17 11:10:49 -06003798 if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07003799 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBIASSTATE, "vkCmdSetDepthBias()");
3800 pCB->status |= CBSTATUS_DEPTH_BIAS_SET;
3801 pCB->depthBiasConstantFactor = depthBiasConstantFactor;
3802 pCB->depthBiasClamp = depthBiasClamp;
3803 pCB->depthBiasSlopeFactor = depthBiasSlopeFactor;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003804 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003805 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003806 dev_data->device_dispatch_table->CmdSetDepthBias(commandBuffer, depthBiasConstantFactor, depthBiasClamp, depthBiasSlopeFactor);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003807}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003808
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003809VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4])
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003810{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003811 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003812 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3813 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003814 if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07003815 skipCall |= addCmd(dev_data, pCB, CMD_SETBLENDSTATE, "vkCmdSetBlendConstants()");
3816 pCB->status |= CBSTATUS_BLEND_SET;
3817 memcpy(pCB->blendConstants, blendConstants, 4 * sizeof(float));
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003818 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003819 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003820 dev_data->device_dispatch_table->CmdSetBlendConstants(commandBuffer, blendConstants);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003821}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003822
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003823VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBounds(
Chia-I Wu1f851912015-10-27 18:04:07 +08003824 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003825 float minDepthBounds,
3826 float maxDepthBounds)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003827{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003828 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003829 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3830 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003831 if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07003832 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBOUNDSSTATE, "vkCmdSetDepthBounds()");
3833 pCB->status |= CBSTATUS_DEPTH_BOUNDS_SET;
3834 pCB->minDepthBounds = minDepthBounds;
3835 pCB->maxDepthBounds = maxDepthBounds;
Cody Northrop2605cb02015-08-18 15:21:16 -06003836 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003837 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003838 dev_data->device_dispatch_table->CmdSetDepthBounds(commandBuffer, minDepthBounds, maxDepthBounds);
Cody Northrop2605cb02015-08-18 15:21:16 -06003839}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003840
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003841VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilCompareMask(
Chia-I Wu1f851912015-10-27 18:04:07 +08003842 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003843 VkStencilFaceFlags faceMask,
Chia-I Wuc51b1212015-10-27 19:25:11 +08003844 uint32_t compareMask)
Cody Northrop2605cb02015-08-18 15:21:16 -06003845{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003846 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003847 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3848 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northrop2605cb02015-08-18 15:21:16 -06003849 if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07003850 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREADMASKSTATE, "vkCmdSetStencilCompareMask()");
3851 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
3852 pCB->front.compareMask = compareMask;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003853 }
Tobin Ehlisb51cb782015-12-16 08:19:42 -07003854 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
3855 pCB->back.compareMask = compareMask;
3856 }
3857 /* TODO: Do we need to track front and back separately? */
3858 /* TODO: We aren't capturing the faceMask, do we need to? */
3859 pCB->status |= CBSTATUS_STENCIL_READ_MASK_SET;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003860 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003861 if (VK_FALSE == skipCall)
Chia-I Wuc51b1212015-10-27 19:25:11 +08003862 dev_data->device_dispatch_table->CmdSetStencilCompareMask(commandBuffer, faceMask, compareMask);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003863}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003864
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003865VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilWriteMask(
Chia-I Wu1f851912015-10-27 18:04:07 +08003866 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003867 VkStencilFaceFlags faceMask,
Chia-I Wuc51b1212015-10-27 19:25:11 +08003868 uint32_t writeMask)
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003869{
3870 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003871 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3872 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003873 if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07003874 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILWRITEMASKSTATE, "vkCmdSetStencilWriteMask()");
3875 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
3876 pCB->front.writeMask = writeMask;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003877 }
Tobin Ehlisb51cb782015-12-16 08:19:42 -07003878 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
3879 pCB->back.writeMask = writeMask;
3880 }
3881 pCB->status |= CBSTATUS_STENCIL_WRITE_MASK_SET;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003882 }
3883 if (VK_FALSE == skipCall)
Chia-I Wuc51b1212015-10-27 19:25:11 +08003884 dev_data->device_dispatch_table->CmdSetStencilWriteMask(commandBuffer, faceMask, writeMask);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003885}
3886
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003887VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilReference(
Chia-I Wu1f851912015-10-27 18:04:07 +08003888 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003889 VkStencilFaceFlags faceMask,
Chia-I Wuc51b1212015-10-27 19:25:11 +08003890 uint32_t reference)
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003891{
3892 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003893 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3894 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003895 if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07003896 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREFERENCESTATE, "vkCmdSetStencilReference()");
3897 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
3898 pCB->front.reference = reference;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003899 }
Tobin Ehlisb51cb782015-12-16 08:19:42 -07003900 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
3901 pCB->back.reference = reference;
3902 }
3903 pCB->status |= CBSTATUS_STENCIL_REFERENCE_SET;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003904 }
3905 if (VK_FALSE == skipCall)
Chia-I Wuc51b1212015-10-27 19:25:11 +08003906 dev_data->device_dispatch_table->CmdSetStencilReference(commandBuffer, faceMask, reference);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003907}
3908
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003909VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindDescriptorSets(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, uint32_t firstSet, uint32_t setCount, const VkDescriptorSet* pDescriptorSets, uint32_t dynamicOffsetCount, const uint32_t* pDynamicOffsets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003910{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003911 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003912 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3913 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003914 if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07003915 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
3916 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
3917 "Incorrectly binding compute DescriptorSets during active RenderPass (%#" PRIxLEAST64 ")", (uint64_t) pCB->activeRenderPass);
3918 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) && (!pCB->activeRenderPass)) {
3919 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdBindDescriptorSets");
3920 }
3921 skipCall |= addCmd(dev_data, pCB, CMD_BINDDESCRIPTORSETS, "vkCmdBindDescriptorSets()");
3922 // Track total count of dynamic descriptor types to make sure we have an offset for each one
3923 uint32_t totalDynamicDescriptors = 0;
3924 string errorString = "";
3925 uint32_t lastSetIndex = firstSet+setCount-1;
3926 if (lastSetIndex >= pCB->boundDescriptorSets.size())
3927 pCB->boundDescriptorSets.resize(lastSetIndex+1);
3928 VkDescriptorSet oldFinalBoundSet = pCB->boundDescriptorSets[lastSetIndex];
3929 for (uint32_t i=0; i<setCount; i++) {
3930 SET_NODE* pSet = getSetNode(dev_data, pDescriptorSets[i]);
3931 if (pSet) {
3932 loader_platform_thread_lock_mutex(&globalLock);
3933 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
3934 pCB->lastBoundPipelineLayout = layout;
3935 pCB->boundDescriptorSets[i+firstSet] = pDescriptorSets[i];
3936 loader_platform_thread_unlock_mutex(&globalLock);
3937 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pDescriptorSets[i], 0, DRAWSTATE_NONE, "DS",
3938 "DS %#" PRIxLEAST64 " bound on pipeline %s", (uint64_t) pDescriptorSets[i], string_VkPipelineBindPoint(pipelineBindPoint));
3939 if (!pSet->pUpdateStructs) {
3940 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pDescriptorSets[i], 0, DRAWSTATE_DESCRIPTOR_SET_NOT_UPDATED, "DS",
3941 "DS %#" PRIxLEAST64 " bound but it was never updated. You may want to either update it or not bind it.", (uint64_t) pDescriptorSets[i]);
3942 }
3943 // Verify that set being bound is compatible with overlapping setLayout of pipelineLayout
3944 if (!verify_set_layout_compatibility(dev_data, pSet, layout, i+firstSet, errorString)) {
3945 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pDescriptorSets[i], 0, DRAWSTATE_PIPELINE_LAYOUTS_INCOMPATIBLE, "DS",
3946 "descriptorSet #%u being bound is not compatible with overlapping layout in pipelineLayout due to: %s", i, errorString.c_str());
3947 }
3948 totalDynamicDescriptors += pSet->pLayout->dynamicDescriptorCount;
3949 } else {
3950 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pDescriptorSets[i], 0, DRAWSTATE_INVALID_SET, "DS",
3951 "Attempt to bind DS %#" PRIxLEAST64 " that doesn't exist!", (uint64_t) pDescriptorSets[i]);
Mark Lobodzinski611cf592015-12-18 15:35:38 -07003952 }
Tobin Ehlisb51cb782015-12-16 08:19:42 -07003953 // Check if newly last bound set invalidates any remaining bound sets
3954 if ((pCB->boundDescriptorSets.size()-1) > (lastSetIndex)) {
3955 if (oldFinalBoundSet && !verify_set_layout_compatibility(dev_data, dev_data->setMap[oldFinalBoundSet], layout, lastSetIndex, errorString)) {
3956 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) oldFinalBoundSet, 0, DRAWSTATE_NONE, "DS",
3957 "DescriptorSetDS %#" PRIxLEAST64 " previously bound as set #%u is incompatible with set %#" PRIxLEAST64 " newly bound as set #%u so set #%u and any subsequent sets were disturbed by newly bound pipelineLayout (%#" PRIxLEAST64 ")", (uint64_t) oldFinalBoundSet, lastSetIndex, (uint64_t) pCB->boundDescriptorSets[lastSetIndex], lastSetIndex, lastSetIndex+1, (uint64_t) layout);
Tobin Ehlis982099b2015-11-05 09:52:49 -07003958 pCB->boundDescriptorSets.resize(lastSetIndex+1);
Tobin Ehlis61ebb312015-11-04 12:28:28 -07003959 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003960 }
Tobin Ehlisb51cb782015-12-16 08:19:42 -07003961 // dynamicOffsetCount must equal the total number of dynamic descriptors in the sets being bound
3962 if (totalDynamicDescriptors != dynamicOffsetCount) {
3963 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t) commandBuffer, 0, DRAWSTATE_INVALID_DYNAMIC_OFFSET_COUNT, "DS",
3964 "Attempting to bind %u descriptorSets with %u dynamic descriptors, but dynamicOffsetCount is %u. It should exactly match the number of dynamic descriptors.", setCount, totalDynamicDescriptors, dynamicOffsetCount);
3965 }
3966 }
3967 // For any previously bound sets, need to set them to "invalid" if they were disturbed by this update
3968 if (firstSet > 0) { // Check set #s below the first bound set
3969 for (uint32_t i=0; i<firstSet; ++i) {
3970 if (pCB->boundDescriptorSets[i] && !verify_set_layout_compatibility(dev_data, dev_data->setMap[pCB->boundDescriptorSets[i]], layout, i, errorString)) {
3971 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pCB->boundDescriptorSets[i], 0, DRAWSTATE_NONE, "DS",
3972 "DescriptorSetDS %#" PRIxLEAST64 " previously bound as set #%u was disturbed by newly bound pipelineLayout (%#" PRIxLEAST64 ")", (uint64_t) pCB->boundDescriptorSets[i], i, (uint64_t) layout);
3973 pCB->boundDescriptorSets[i] = VK_NULL_HANDLE;
3974 }
3975 }
3976 }
3977 // Check if newly last bound set invalidates any remaining bound sets
3978 if ((pCB->boundDescriptorSets.size()-1) > (lastSetIndex)) {
3979 if (oldFinalBoundSet && !verify_set_layout_compatibility(dev_data, dev_data->setMap[oldFinalBoundSet], layout, lastSetIndex, errorString)) {
3980 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) oldFinalBoundSet, 0, DRAWSTATE_NONE, "DS",
3981 "DescriptorSetDS %#" PRIxLEAST64 " previously bound as set #%u is incompatible with set %#" PRIxLEAST64 " newly bound as set #%u so set #%u and any subsequent sets were disturbed by newly bound pipelineLayout (%#" PRIxLEAST64 ")", (uint64_t) oldFinalBoundSet, lastSetIndex, (uint64_t) pCB->boundDescriptorSets[lastSetIndex], lastSetIndex, lastSetIndex+1, (uint64_t) layout);
3982 pCB->boundDescriptorSets.resize(lastSetIndex+1);
3983 }
3984 }
3985 // dynamicOffsetCount must equal the total number of dynamic descriptors in the sets being bound
3986 if (totalDynamicDescriptors != dynamicOffsetCount) {
3987 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t) commandBuffer, 0, DRAWSTATE_INVALID_DYNAMIC_OFFSET_COUNT, "DS",
3988 "Attempting to bind %u descriptorSets with %u dynamic descriptors, but dynamicOffsetCount is %u. It should exactly match the number of dynamic descriptors.", setCount, totalDynamicDescriptors, dynamicOffsetCount);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003989 }
3990 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003991 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003992 dev_data->device_dispatch_table->CmdBindDescriptorSets(commandBuffer, pipelineBindPoint, layout, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003993}
3994
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003995VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003996{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003997 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003998 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3999 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004000 if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07004001 skipCall |= addCmd(dev_data, pCB, CMD_BINDINDEXBUFFER, "vkCmdBindIndexBuffer()");
4002 VkDeviceSize offset_align = 0;
4003 switch (indexType) {
4004 case VK_INDEX_TYPE_UINT16:
4005 offset_align = 2;
4006 break;
4007 case VK_INDEX_TYPE_UINT32:
4008 offset_align = 4;
4009 break;
4010 default:
4011 // ParamChecker should catch bad enum, we'll also throw alignment error below if offset_align stays 0
4012 break;
4013 }
4014 if (!offset_align || (offset % offset_align)) {
4015 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_VTX_INDEX_ALIGNMENT_ERROR, "DS",
4016 "vkCmdBindIndexBuffer() offset (%#" PRIxLEAST64 ") does not fall on alignment (%s) boundary.", offset, string_VkIndexType(indexType));
Tobin Ehlise42007c2015-06-19 13:00:59 -06004017 }
Tobin Ehlis8d199e52015-09-17 12:24:13 -06004018 pCB->status |= CBSTATUS_INDEX_BUFFER_BOUND;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004019 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004020 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004021 dev_data->device_dispatch_table->CmdBindIndexBuffer(commandBuffer, buffer, offset, indexType);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004022}
4023
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004024VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindVertexBuffers(
Mark Lobodzinski74e84692015-12-14 15:14:10 -07004025 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06004026 uint32_t startBinding,
4027 uint32_t bindingCount,
Mark Lobodzinski74e84692015-12-14 15:14:10 -07004028 const VkBuffer *pBuffers,
4029 const VkDeviceSize *pOffsets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004030{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004031 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004032 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4033 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004034 if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07004035 addCmd(dev_data, pCB, CMD_BINDVERTEXBUFFER, "vkCmdBindVertexBuffer()");
4036 if ((startBinding + bindingCount) > pCB->boundVtxBuffers.size()) {
4037 pCB->boundVtxBuffers.resize(startBinding+bindingCount, VK_NULL_HANDLE);
4038 }
4039 for (auto i = 0; i < bindingCount; i++) {
4040 pCB->boundVtxBuffers[i+startBinding] = pBuffers[i];
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06004041 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004042 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004043 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004044 dev_data->device_dispatch_table->CmdBindVertexBuffers(commandBuffer, startBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004045}
4046
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004047VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004048{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004049 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004050 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4051 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004052 if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07004053 skipCall |= addCmd(dev_data, pCB, CMD_DRAW, "vkCmdDraw()");
4054 pCB->drawCount[DRAW]++;
4055 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
4056 // TODO : Need to pass commandBuffer as srcObj here
4057 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, 0, DRAWSTATE_NONE, "DS",
4058 "vkCmdDraw() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW]++);
4059 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004060 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDraw");
Jon Ashburne0fa2282015-05-20 09:00:28 -06004061 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004062 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004063 dev_data->device_dispatch_table->CmdDraw(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004064}
4065
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004066VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004067{
Chia-I Wu1f851912015-10-27 18:04:07 +08004068 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4069 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004070 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004071 if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07004072 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXED, "vkCmdDrawIndexed()");
4073 pCB->drawCount[DRAW_INDEXED]++;
4074 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
4075 // TODO : Need to pass commandBuffer as srcObj here
4076 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, 0, DRAWSTATE_NONE, "DS",
4077 "vkCmdDrawIndexed() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED]++);
4078 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004079 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexed");
Jon Ashburne0fa2282015-05-20 09:00:28 -06004080 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004081 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004082 dev_data->device_dispatch_table->CmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004083}
4084
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004085VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004086{
Chia-I Wu1f851912015-10-27 18:04:07 +08004087 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4088 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004089 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004090 if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07004091 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDIRECT, "vkCmdDrawIndirect()");
4092 pCB->drawCount[DRAW_INDIRECT]++;
4093 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
4094 // TODO : Need to pass commandBuffer as srcObj here
4095 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, 0, DRAWSTATE_NONE, "DS",
4096 "vkCmdDrawIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
4097 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004098 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndirect");
Jon Ashburne0fa2282015-05-20 09:00:28 -06004099 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004100 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004101 dev_data->device_dispatch_table->CmdDrawIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004102}
4103
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004104VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004105{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004106 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004107 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4108 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004109 if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07004110 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXEDINDIRECT, "vkCmdDrawIndexedIndirect()");
4111 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
4112 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
4113 // TODO : Need to pass commandBuffer as srcObj here
4114 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, 0, DRAWSTATE_NONE, "DS",
4115 "vkCmdDrawIndexedIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
4116 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004117 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexedIndirect");
Jon Ashburne0fa2282015-05-20 09:00:28 -06004118 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004119 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004120 dev_data->device_dispatch_table->CmdDrawIndexedIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004121}
4122
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004123VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004124{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004125 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004126 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4127 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004128 if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07004129 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCH, "vkCmdDispatch()");
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004130 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatch");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004131 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004132 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004133 dev_data->device_dispatch_table->CmdDispatch(commandBuffer, x, y, z);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004134}
4135
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004136VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004137{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004138 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004139 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4140 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004141 if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07004142 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCHINDIRECT, "vkCmdDispatchIndirect()");
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004143 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatchIndirect");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004144 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004145 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004146 dev_data->device_dispatch_table->CmdDispatchIndirect(commandBuffer, buffer, offset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004147}
4148
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004149VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004150{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004151 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004152 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4153 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004154 if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07004155 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFER, "vkCmdCopyBuffer()");
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004156 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBuffer");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004157 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004158 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004159 dev_data->device_dispatch_table->CmdCopyBuffer(commandBuffer, srcBuffer, dstBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004160}
4161
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004162VkBool32 VerifySourceImageLayout(VkCommandBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout) {
4163 VkBool32 skip_call = false;
Mark Lobodzinski78940a42015-11-30 16:48:53 -07004164
4165#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4166 // TODO: Fix -- initialLayout may have been set in a previous command buffer
4167 return skip_call;
4168#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4169
Michael Lentine27b0f902015-10-12 11:30:14 -05004170 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4171 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4172 auto src_image_element = pCB->imageLayoutMap.find(srcImage);
4173 if (src_image_element == pCB->imageLayoutMap.end()) {
4174 pCB->imageLayoutMap[srcImage].initialLayout = srcImageLayout;
4175 pCB->imageLayoutMap[srcImage].layout = srcImageLayout;
4176 return false;
4177 }
4178 if (src_image_element->second.layout != srcImageLayout) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004179 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentine27b0f902015-10-12 11:30:14 -05004180 "Cannot copy from an image whose source layout is %d and doesn't match the current layout %d.", srcImageLayout, src_image_element->second.layout);
4181 }
4182 if (srcImageLayout != VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL) {
4183 if (srcImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004184 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
4185 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentine472af7d2015-10-16 18:08:09 -05004186 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Michael Lentine27b0f902015-10-12 11:30:14 -05004187 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004188 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentine472af7d2015-10-16 18:08:09 -05004189 "Layout for input image is %d but can only be TRANSFER_SRC_OPTIMAL or GENERAL.", srcImageLayout);
Michael Lentine27b0f902015-10-12 11:30:14 -05004190 }
4191 }
4192 return skip_call;
4193}
4194
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004195VkBool32 VerifyDestImageLayout(VkCommandBuffer cmdBuffer, VkImage destImage, VkImageLayout destImageLayout) {
4196 VkBool32 skip_call = false;
Mark Lobodzinski78940a42015-11-30 16:48:53 -07004197
4198#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4199 // TODO: Fix -- initialLayout may have been set in a previous command buffer
4200 return skip_call;
4201#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4202
Michael Lentine27b0f902015-10-12 11:30:14 -05004203 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4204 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4205 auto dest_image_element = pCB->imageLayoutMap.find(destImage);
4206 if (dest_image_element == pCB->imageLayoutMap.end()) {
4207 pCB->imageLayoutMap[destImage].initialLayout = destImageLayout;
4208 pCB->imageLayoutMap[destImage].layout = destImageLayout;
4209 return false;
4210 }
4211 if (dest_image_element->second.layout != destImageLayout) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004212 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentine27b0f902015-10-12 11:30:14 -05004213 "Cannot copy from an image whose dest layout is %d and doesn't match the current layout %d.", destImageLayout, dest_image_element->second.layout);
4214 }
4215 if (destImageLayout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) {
4216 if (destImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004217 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
4218 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentine27b0f902015-10-12 11:30:14 -05004219 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
4220 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004221 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentine27b0f902015-10-12 11:30:14 -05004222 "Layout for output image is %d but can only be TRANSFER_DST_OPTIMAL or GENERAL.", destImageLayout);
4223 }
4224 }
4225 return skip_call;
4226}
4227
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004228VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004229 VkImage srcImage,
4230 VkImageLayout srcImageLayout,
Chia-I Wu1f851912015-10-27 18:04:07 +08004231 VkImage dstImage,
4232 VkImageLayout dstImageLayout,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004233 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004234{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004235 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004236 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4237 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004238 if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07004239 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGE, "vkCmdCopyImage()");
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004240 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImage");
Michael Lentine27b0f902015-10-12 11:30:14 -05004241 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
4242 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004243 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004244 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004245 dev_data->device_dispatch_table->CmdCopyImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004246}
4247
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004248VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBlitImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004249 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu1f851912015-10-27 18:04:07 +08004250 VkImage dstImage, VkImageLayout dstImageLayout,
Mark Lobodzinski20f68592015-05-22 14:43:25 -05004251 uint32_t regionCount, const VkImageBlit* pRegions,
Chia-I Wu3603b082015-10-26 16:49:32 +08004252 VkFilter filter)
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06004253{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004254 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004255 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4256 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06004257 if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07004258 skipCall |= addCmd(dev_data, pCB, CMD_BLITIMAGE, "vkCmdBlitImage()");
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004259 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBlitImage");
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06004260 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004261 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004262 dev_data->device_dispatch_table->CmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06004263}
4264
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004265VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004266 VkBuffer srcBuffer,
Chia-I Wu1f851912015-10-27 18:04:07 +08004267 VkImage dstImage, VkImageLayout dstImageLayout,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004268 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004269{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004270 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004271 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4272 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004273 if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07004274 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFERTOIMAGE, "vkCmdCopyBufferToImage()");
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004275 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBufferToImage");
Michael Lentine27b0f902015-10-12 11:30:14 -05004276 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004277 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004278 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004279 dev_data->device_dispatch_table->CmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004280}
4281
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004282VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004283 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu1f851912015-10-27 18:04:07 +08004284 VkBuffer dstBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004285 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004286{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004287 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004288 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4289 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004290 if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07004291 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGETOBUFFER, "vkCmdCopyImageToBuffer()");
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004292 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImageToBuffer");
Michael Lentine27b0f902015-10-12 11:30:14 -05004293 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004294 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004295 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004296 dev_data->device_dispatch_table->CmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004297}
4298
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004299VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize dataSize, const uint32_t* pData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004300{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004301 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004302 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4303 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004304 if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07004305 skipCall |= addCmd(dev_data, pCB, CMD_UPDATEBUFFER, "vkCmdUpdateBuffer()");
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004306 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyUpdateBuffer");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004307 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004308 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004309 dev_data->device_dispatch_table->CmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004310}
4311
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004312VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize size, uint32_t data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004313{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004314 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004315 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4316 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004317 if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07004318 skipCall |= addCmd(dev_data, pCB, CMD_FILLBUFFER, "vkCmdFillBuffer()");
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004319 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyFillBuffer");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004320 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004321 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004322 dev_data->device_dispatch_table->CmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004323}
4324
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004325VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearAttachments(
Chia-I Wu1f851912015-10-27 18:04:07 +08004326 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004327 uint32_t attachmentCount,
4328 const VkClearAttachment* pAttachments,
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004329 uint32_t rectCount,
Courtney Goeltzenleuchtera12e2912015-10-15 18:22:08 -06004330 const VkClearRect* pRects)
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004331{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004332 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004333 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4334 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004335 if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07004336 skipCall |= addCmd(dev_data, pCB, CMD_CLEARATTACHMENTS, "vkCmdClearAttachments()");
4337 // Warn if this is issued prior to Draw Cmd and clearing the entire attachment
4338 if (!hasDrawCmd(pCB) &&
4339 (pCB->activeRenderPassBeginInfo.renderArea.extent.width == pRects[0].rect.extent.width) &&
4340 (pCB->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) {
4341 // TODO : commandBuffer should be srcObj
4342 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, 0, DRAWSTATE_CLEAR_CMD_BEFORE_DRAW, "DS",
4343 "vkCmdClearAttachments() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
4344 " It is recommended you use RenderPass LOAD_OP_CLEAR on Attachments prior to any Draw.", reinterpret_cast<uint64_t>(commandBuffer));
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004345 }
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004346 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdClearAttachments");
4347 }
4348
4349 // Validate that attachment is in reference list of active subpass
4350 if (pCB->activeRenderPass) {
Tobin Ehlisad61de42015-12-02 13:53:34 -07004351 const VkRenderPassCreateInfo *pRPCI = dev_data->renderPassMap[pCB->activeRenderPass]->pCreateInfo;
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004352 const VkSubpassDescription *pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
4353
4354 for (uint32_t attachment_idx = 0; attachment_idx < attachmentCount; attachment_idx++) {
4355 const VkClearAttachment *attachment = &pAttachments[attachment_idx];
4356 if (attachment->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) {
4357 VkBool32 found = VK_FALSE;
Chia-I Wu763a7492015-10-26 20:48:51 +08004358 for (uint32_t i = 0; i < pSD->colorAttachmentCount; i++) {
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004359 if (attachment->colorAttachment == pSD->pColorAttachments[i].attachment) {
4360 found = VK_TRUE;
4361 break;
4362 }
4363 }
4364 if (VK_FALSE == found) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004365 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Chia-I Wu1f851912015-10-27 18:04:07 +08004366 (uint64_t)commandBuffer, 0, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004367 "vkCmdClearAttachments() attachment index %d not found in attachment reference array of active subpass %d",
4368 attachment->colorAttachment, pCB->activeSubpass);
4369 }
4370 } else if (attachment->aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) {
Mark Lobodzinski1523e3a2015-11-17 15:11:24 -07004371 if (!pSD->pDepthStencilAttachment || // Says no DS will be used in active subpass
Mark Lobodzinskiea1fff22015-11-18 08:58:31 -07004372 (pSD->pDepthStencilAttachment->attachment == VK_ATTACHMENT_UNUSED)) { // Says no DS will be used in active subpass
Mark Lobodzinski1523e3a2015-11-17 15:11:24 -07004373
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004374 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski1523e3a2015-11-17 15:11:24 -07004375 (uint64_t)commandBuffer, 0, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
4376 "vkCmdClearAttachments() attachment index %d does not match depthStencilAttachment.attachment (%d) found in active subpass %d",
4377 attachment->colorAttachment,
4378 (pSD->pDepthStencilAttachment) ? pSD->pDepthStencilAttachment->attachment : VK_ATTACHMENT_UNUSED,
4379 pCB->activeSubpass);
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004380 }
4381 }
4382 }
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004383 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004384 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004385 dev_data->device_dispatch_table->CmdClearAttachments(commandBuffer, attachmentCount, pAttachments, rectCount, pRects);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004386}
4387
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004388VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearColorImage(
Chia-I Wu1f851912015-10-27 18:04:07 +08004389 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06004390 VkImage image, VkImageLayout imageLayout,
Chris Forbese3105972015-06-24 14:34:53 +12004391 const VkClearColorValue *pColor,
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06004392 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004393{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004394 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004395 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4396 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004397 if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07004398 skipCall |= addCmd(dev_data, pCB, CMD_CLEARCOLORIMAGE, "vkCmdClearColorImage()");
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004399 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearColorImage");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004400 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004401 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004402 dev_data->device_dispatch_table->CmdClearColorImage(commandBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004403}
4404
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004405VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearDepthStencilImage(
Chia-I Wu1f851912015-10-27 18:04:07 +08004406 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter315ad992015-09-15 18:03:22 -06004407 VkImage image, VkImageLayout imageLayout,
4408 const VkClearDepthStencilValue *pDepthStencil,
4409 uint32_t rangeCount,
4410 const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004411{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004412 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004413 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4414 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004415 if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07004416 skipCall |= addCmd(dev_data, pCB, CMD_CLEARDEPTHSTENCILIMAGE, "vkCmdClearDepthStencilImage()");
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004417 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearDepthStencilImage");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004418 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004419 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004420 dev_data->device_dispatch_table->CmdClearDepthStencilImage(commandBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004421}
4422
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004423VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResolveImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004424 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu1f851912015-10-27 18:04:07 +08004425 VkImage dstImage, VkImageLayout dstImageLayout,
Tony Barbour11f74372015-04-13 15:02:52 -06004426 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004427{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004428 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004429 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4430 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004431 if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07004432 skipCall |= addCmd(dev_data, pCB, CMD_RESOLVEIMAGE, "vkCmdResolveImage()");
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004433 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResolveImage");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004434 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004435 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004436 dev_data->device_dispatch_table->CmdResolveImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004437}
4438
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004439VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004440{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004441 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004442 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4443 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004444 if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07004445 skipCall |= addCmd(dev_data, pCB, CMD_SETEVENT, "vkCmdSetEvent()");
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004446 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdSetEvent");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004447 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004448 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004449 dev_data->device_dispatch_table->CmdSetEvent(commandBuffer, event, stageMask);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004450}
4451
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004452VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004453{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004454 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004455 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4456 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004457 if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07004458 skipCall |= addCmd(dev_data, pCB, CMD_RESETEVENT, "vkCmdResetEvent()");
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004459 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResetEvent");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004460 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004461 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004462 dev_data->device_dispatch_table->CmdResetEvent(commandBuffer, event, stageMask);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004463}
4464
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004465VkBool32 TransitionImageLayouts(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const void* const* ppMemBarriers) {
Michael Lentine27b0f902015-10-12 11:30:14 -05004466 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4467 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004468 VkBool32 skip = false;
Mark Lobodzinski78940a42015-11-30 16:48:53 -07004469
4470#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4471 // TODO: Fix -- pay attention to image subresource ranges -- not all subresources transition at the same time
4472 return skip;
4473#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4474
Michael Lentine27b0f902015-10-12 11:30:14 -05004475 for (uint32_t i = 0; i < memBarrierCount; ++i) {
4476 auto mem_barrier = reinterpret_cast<const VkMemoryBarrier*>(ppMemBarriers[i]);
4477 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
4478 auto image_mem_barrier = reinterpret_cast<const VkImageMemoryBarrier*>(mem_barrier);
4479 auto image_data = pCB->imageLayoutMap.find(image_mem_barrier->image);
4480 if (image_data == pCB->imageLayoutMap.end()) {
4481 pCB->imageLayoutMap[image_mem_barrier->image].initialLayout = image_mem_barrier->oldLayout;
4482 pCB->imageLayoutMap[image_mem_barrier->image].layout = image_mem_barrier->newLayout;
4483 } else {
4484 if (image_data->second.layout != image_mem_barrier->oldLayout) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004485 skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Courtney Goeltzenleuchter95e6dba2015-11-25 11:38:54 -07004486 "You cannot transition the layout from %d when current layout is %d.", image_mem_barrier->oldLayout, image_data->second.layout);
Michael Lentine27b0f902015-10-12 11:30:14 -05004487 }
4488 image_data->second.layout = image_mem_barrier->newLayout;
4489 }
4490 }
4491 }
4492 return skip;
4493}
4494
Michael Lentine8469dd62015-11-20 09:48:52 -08004495// AccessFlags MUST have 'required_bit' set, and may have one or more of 'optional_bits' set.
4496// If required_bit is zero, accessMask must have at least one of 'optional_bits' set
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004497VkBool32 ValidateMaskBits(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout, VkAccessFlags required_bit, VkAccessFlags optional_bits) {
4498 VkBool32 skip_call = false;
Michael Lentine8469dd62015-11-20 09:48:52 -08004499 if ((accessMask & required_bit) || (!required_bit && (accessMask & optional_bits))) {
4500 if (accessMask & !(required_bit | optional_bits)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004501 // TODO: Verify against Valid Use
4502 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_BARRIER, "DS",
Michael Lentine8469dd62015-11-20 09:48:52 -08004503 "Additional bits in accessMask %d are specified when layout is %s.", accessMask, string_VkImageLayout(layout));
Michael Lentine472af7d2015-10-16 18:08:09 -05004504 }
4505 } else {
Michael Lentine8469dd62015-11-20 09:48:52 -08004506 if (!required_bit) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004507 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_BARRIER, "DS",
Michael Lentine8469dd62015-11-20 09:48:52 -08004508 "AccessMask %d must contain at least one of access bits %d when layout is %s.",
4509 accessMask, optional_bits, string_VkImageLayout(layout));
4510 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004511 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_BARRIER, "DS",
Michael Lentine8469dd62015-11-20 09:48:52 -08004512 "AccessMask %d must have required access bit %d and may have optional bits %d when layout is %s.",
4513 accessMask, required_bit, optional_bits,string_VkImageLayout(layout));
4514 }
Michael Lentine472af7d2015-10-16 18:08:09 -05004515 }
4516 return skip_call;
4517}
4518
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004519VkBool32 ValidateMaskBitsFromLayouts(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout) {
4520 VkBool32 skip_call = false;
Michael Lentine8469dd62015-11-20 09:48:52 -08004521 switch (layout) {
4522 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: {
4523 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_COLOR_ATTACHMENT_READ_BIT);
4524 break;
Michael Lentine472af7d2015-10-16 18:08:09 -05004525 }
Michael Lentine8469dd62015-11-20 09:48:52 -08004526 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: {
4527 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT);
4528 break;
Michael Lentine472af7d2015-10-16 18:08:09 -05004529 }
Michael Lentine8469dd62015-11-20 09:48:52 -08004530 case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: {
4531 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_WRITE_BIT, 0);
4532 break;
4533 }
4534 case VK_IMAGE_LAYOUT_PREINITIALIZED: {
4535 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_HOST_WRITE_BIT, 0);
4536 break;
4537 }
4538 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: {
4539 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, 0, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT);
4540 break;
4541 }
4542 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: {
4543 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, 0, VK_ACCESS_INPUT_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT);
4544 break;
4545 }
4546 case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: {
4547 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_READ_BIT, 0);
4548 break;
4549 }
4550 case VK_IMAGE_LAYOUT_UNDEFINED: {
4551 if (accessMask != 0) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004552 // TODO: Verify against Valid Use section spec
4553 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_BARRIER, "DS",
Michael Lentine8469dd62015-11-20 09:48:52 -08004554 "Additional bits in accessMask %d are specified when layout is %s.", accessMask, string_VkImageLayout(layout));
4555 }
4556 break;
4557 }
4558 case VK_IMAGE_LAYOUT_GENERAL:
4559 default: {
4560 break;
4561 }
Michael Lentine472af7d2015-10-16 18:08:09 -05004562 }
4563 return skip_call;
4564}
4565
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004566VkBool32 ValidateBarriers(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const void* const* ppMemBarriers) {
4567 VkBool32 skip_call = false;
Michael Lentine07ff1a12015-10-15 17:07:00 -05004568 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4569 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4570 if (pCB->activeRenderPass && memBarrierCount) {
4571 for (uint32_t i = 0; i < memBarrierCount; ++i) {
4572 auto mem_barrier = reinterpret_cast<const VkMemoryBarrier*>(ppMemBarriers[i]);
4573 if (mem_barrier && mem_barrier->sType != VK_STRUCTURE_TYPE_MEMORY_BARRIER) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004574 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_BARRIER, "DS",
Michael Lentine07ff1a12015-10-15 17:07:00 -05004575 "Image or Buffers Barriers cannot be used during a render pass.");
4576 }
4577 }
4578 if (!dev_data->renderPassMap[pCB->activeRenderPass]->hasSelfDependency[pCB->activeSubpass]) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004579 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_BARRIER, "DS",
Michael Lentine07ff1a12015-10-15 17:07:00 -05004580 "Barriers cannot be set during subpass %d with no self dependency specified.", pCB->activeSubpass);
4581 }
4582 }
Mark Lobodzinskib684b512015-11-20 09:27:27 -07004583
Michael Lentine472af7d2015-10-16 18:08:09 -05004584 for (uint32_t i = 0; i < memBarrierCount; ++i) {
4585 auto mem_barrier = reinterpret_cast<const VkMemoryBarrier*>(ppMemBarriers[i]);
4586 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
4587 auto image_mem_barrier = reinterpret_cast<const VkImageMemoryBarrier*>(mem_barrier);
Michael Lentine8469dd62015-11-20 09:48:52 -08004588 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, image_mem_barrier->srcAccessMask, image_mem_barrier->oldLayout);
4589 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, image_mem_barrier->dstAccessMask, image_mem_barrier->newLayout);
Michael Lentine472af7d2015-10-16 18:08:09 -05004590 }
4591 }
Mark Lobodzinskib95fc092015-12-03 15:42:32 -07004592
Michael Lentine07ff1a12015-10-15 17:07:00 -05004593 return skip_call;
4594}
4595
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004596VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent* pEvents, VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask, uint32_t memoryBarrierCount, const void* const* ppMemoryBarriers)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004597{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004598 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004599 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4600 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004601 if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07004602 skipCall |= addCmd(dev_data, pCB, CMD_WAITEVENTS, "vkCmdWaitEvents()");
Michael Lentine27b0f902015-10-12 11:30:14 -05004603 skipCall |= TransitionImageLayouts(commandBuffer, memoryBarrierCount, ppMemoryBarriers);
Michael Lentine07ff1a12015-10-15 17:07:00 -05004604 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, ppMemoryBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004605 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004606 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004607 dev_data->device_dispatch_table->CmdWaitEvents(commandBuffer, eventCount, pEvents, sourceStageMask, dstStageMask, memoryBarrierCount, ppMemoryBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004608}
4609
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004610VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, uint32_t memoryBarrierCount, const void* const* ppMemoryBarriers)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004611{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004612 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004613 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4614 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004615 if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07004616 skipCall |= addCmd(dev_data, pCB, CMD_PIPELINEBARRIER, "vkCmdPipelineBarrier()");
Michael Lentine27b0f902015-10-12 11:30:14 -05004617 skipCall |= TransitionImageLayouts(commandBuffer, memoryBarrierCount, ppMemoryBarriers);
Michael Lentine07ff1a12015-10-15 17:07:00 -05004618 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, ppMemoryBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004619 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004620 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004621 dev_data->device_dispatch_table->CmdPipelineBarrier(commandBuffer, srcStageMask, dstStageMask, dependencyFlags, memoryBarrierCount, ppMemoryBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004622}
4623
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004624VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004625{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004626 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004627 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4628 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004629 if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07004630 skipCall |= addCmd(dev_data, pCB, CMD_BEGINQUERY, "vkCmdBeginQuery()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004631 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004632 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004633 dev_data->device_dispatch_table->CmdBeginQuery(commandBuffer, queryPool, slot, flags);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004634}
4635
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004636VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004637{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004638 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004639 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4640 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004641 if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07004642 skipCall |= addCmd(dev_data, pCB, CMD_ENDQUERY, "vkCmdEndQuery()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004643 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004644 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004645 dev_data->device_dispatch_table->CmdEndQuery(commandBuffer, queryPool, slot);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004646}
4647
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004648VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResetQueryPool(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004649{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004650 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004651 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4652 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004653 if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07004654 skipCall |= addCmd(dev_data, pCB, CMD_RESETQUERYPOOL, "vkCmdResetQueryPool()");
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004655 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdQueryPool");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004656 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004657 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004658 dev_data->device_dispatch_table->CmdResetQueryPool(commandBuffer, queryPool, startQuery, queryCount);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004659}
4660
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004661VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t startQuery,
Chia-I Wu1f851912015-10-27 18:04:07 +08004662 uint32_t queryCount, VkBuffer dstBuffer, VkDeviceSize dstOffset,
Chia-I Wu1f6942d2015-10-26 18:36:20 +08004663 VkDeviceSize stride, VkQueryResultFlags flags)
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06004664{
4665 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004666 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4667 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06004668 if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07004669 skipCall |= addCmd(dev_data, pCB, CMD_COPYQUERYPOOLRESULTS, "vkCmdCopyQueryPoolResults()");
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004670 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyQueryPoolResults");
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06004671 }
4672 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004673 dev_data->device_dispatch_table->CmdCopyQueryPoolResults(commandBuffer, queryPool,
4674 startQuery, queryCount, dstBuffer, dstOffset, stride, flags);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06004675}
4676
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004677VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004678{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004679 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004680 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4681 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004682 if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07004683 skipCall |= addCmd(dev_data, pCB, CMD_WRITETIMESTAMP, "vkCmdWriteTimestamp()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004684 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004685 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004686 dev_data->device_dispatch_table->CmdWriteTimestamp(commandBuffer, pipelineStage, queryPool, slot);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004687}
4688
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004689VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkFramebuffer* pFramebuffer)
Tobin Ehlis2464b882015-04-01 08:40:34 -06004690{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06004691 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08004692 VkResult result = dev_data->device_dispatch_table->CreateFramebuffer(device, pCreateInfo, pAllocator, pFramebuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06004693 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06004694 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004695 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Chia-I Wuc278df82015-07-07 11:50:03 +08004696 if (pCreateInfo->pAttachments) {
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -06004697 localFBCI->pAttachments = new VkImageView[localFBCI->attachmentCount];
4698 memcpy((void*)localFBCI->pAttachments, pCreateInfo->pAttachments, localFBCI->attachmentCount*sizeof(VkImageView));
Tobin Ehlis2464b882015-04-01 08:40:34 -06004699 }
Chia-I Wue420a332015-10-26 20:04:44 +08004700 dev_data->frameBufferMap[*pFramebuffer] = localFBCI;
Tobin Ehlis2464b882015-04-01 08:40:34 -06004701 }
4702 return result;
4703}
4704
Michael Lentine329697b2015-10-06 14:56:18 -07004705// Store the DAG.
4706struct DAGNode {
4707 uint32_t pass;
4708 std::vector<uint32_t> prev;
4709 std::vector<uint32_t> next;
4710};
4711
Courtney Goeltzenleuchterf2bca902015-11-03 15:41:43 -07004712VkBool32 FindDependency(const int index, const int dependent, const std::vector<DAGNode>& subpass_to_node, std::unordered_set<uint32_t>& processed_nodes) {
Michael Lentine329697b2015-10-06 14:56:18 -07004713 // If we have already checked this node we have not found a dependency path so return false.
4714 if (processed_nodes.count(index))
4715 return false;
4716 processed_nodes.insert(index);
4717 const DAGNode& node = subpass_to_node[index];
4718 // Look for a dependency path. If one exists return true else recurse on the previous nodes.
4719 if (std::find(node.prev.begin(), node.prev.end(), dependent) == node.prev.end()) {
4720 for (auto elem : node.prev) {
4721 if (FindDependency(elem, dependent, subpass_to_node, processed_nodes))
4722 return true;
4723 }
4724 } else {
4725 return true;
4726 }
4727 return false;
4728}
4729
Courtney Goeltzenleuchterf2bca902015-11-03 15:41:43 -07004730VkBool32 CheckDependencyExists(const layer_data* my_data, VkDevice device, const int subpass, const std::vector<uint32_t>& dependent_subpasses, const std::vector<DAGNode>& subpass_to_node, VkBool32& skip_call) {
4731 VkBool32 result = true;
Michael Lentine329697b2015-10-06 14:56:18 -07004732 // Loop through all subpasses that share the same attachment and make sure a dependency exists
4733 for (uint32_t k = 0; k < dependent_subpasses.size(); ++k) {
4734 if (subpass == dependent_subpasses[k])
4735 continue;
4736 const DAGNode& node = subpass_to_node[subpass];
4737 // Check for a specified dependency between the two nodes. If one exists we are done.
4738 auto prev_elem = std::find(node.prev.begin(), node.prev.end(), dependent_subpasses[k]);
4739 auto next_elem = std::find(node.next.begin(), node.next.end(), dependent_subpasses[k]);
4740 if (prev_elem == node.prev.end() && next_elem == node.next.end()) {
4741 // If no dependency exits an implicit dependency still might. If so, warn and if not throw an error.
4742 std::unordered_set<uint32_t> processed_nodes;
4743 if (FindDependency(subpass, dependent_subpasses[k], subpass_to_node, processed_nodes) ||
4744 FindDependency(dependent_subpasses[k], subpass, subpass_to_node, processed_nodes)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004745 // TODO: Verify against Valid Use section of spec
4746 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_RENDERPASS, "DS",
Michael Lentine329697b2015-10-06 14:56:18 -07004747 "A dependency between subpasses %d and %d must exist but only an implicit one is specified.",
4748 subpass, dependent_subpasses[k]);
4749 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004750 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_RENDERPASS, "DS",
Michael Lentine329697b2015-10-06 14:56:18 -07004751 "A dependency between subpasses %d and %d must exist but one is not specified.",
4752 subpass, dependent_subpasses[k]);
4753 result = false;
4754 }
4755 }
4756 }
4757 return result;
4758}
4759
Courtney Goeltzenleuchterf2bca902015-11-03 15:41:43 -07004760VkBool32 CheckPreserved(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, const int index, const int attachment, const std::vector<DAGNode>& subpass_to_node, int depth, VkBool32& skip_call) {
Michael Lentine329697b2015-10-06 14:56:18 -07004761 const DAGNode& node = subpass_to_node[index];
4762 // If this node writes to the attachment return true as next nodes need to preserve the attachment.
4763 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Chia-I Wu763a7492015-10-26 20:48:51 +08004764 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentine329697b2015-10-06 14:56:18 -07004765 if (attachment == subpass.pColorAttachments[j].attachment)
Courtney Goeltzenleuchterf2bca902015-11-03 15:41:43 -07004766 return VK_TRUE;
Michael Lentine329697b2015-10-06 14:56:18 -07004767 }
Chia-I Wuce532f72015-10-26 17:32:47 +08004768 if (subpass.pDepthStencilAttachment &&
4769 subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
4770 if (attachment == subpass.pDepthStencilAttachment->attachment)
Courtney Goeltzenleuchterf2bca902015-11-03 15:41:43 -07004771 return VK_TRUE;
Michael Lentine329697b2015-10-06 14:56:18 -07004772 }
Courtney Goeltzenleuchterf2bca902015-11-03 15:41:43 -07004773 VkBool32 result = VK_FALSE;
Michael Lentine329697b2015-10-06 14:56:18 -07004774 // Loop through previous nodes and see if any of them write to the attachment.
4775 for (auto elem : node.prev) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004776 result |= CheckPreserved(my_data, device, pCreateInfo, elem, attachment, subpass_to_node, depth + 1, skip_call);
Michael Lentine329697b2015-10-06 14:56:18 -07004777 }
4778 // If the attachment was written to by a previous node than this node needs to preserve it.
4779 if (result && depth > 0) {
4780 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Courtney Goeltzenleuchterf2bca902015-11-03 15:41:43 -07004781 VkBool32 has_preserved = false;
Chia-I Wu763a7492015-10-26 20:48:51 +08004782 for (uint32_t j = 0; j < subpass.preserveAttachmentCount; ++j) {
Michael Lentine329697b2015-10-06 14:56:18 -07004783 if (subpass.pPreserveAttachments[j].attachment == attachment) {
4784 has_preserved = true;
4785 break;
4786 }
4787 }
4788 if (!has_preserved) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004789 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_RENDERPASS, "DS",
Michael Lentine329697b2015-10-06 14:56:18 -07004790 "Attachment %d is used by a later subpass and must be preserved in subpass %d.", attachment, index);
4791 }
4792 }
4793 return result;
4794}
4795
Michael Lentine27b0f902015-10-12 11:30:14 -05004796VkBool32 ValidateDependencies(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, std::vector<DAGNode>& subpass_to_node) {
4797 VkBool32 skip_call = false;
Michael Lentine329697b2015-10-06 14:56:18 -07004798 std::vector<std::vector<uint32_t>> output_attachment_to_subpass(pCreateInfo->attachmentCount);
4799 std::vector<std::vector<uint32_t>> input_attachment_to_subpass(pCreateInfo->attachmentCount);
Michael Lentine27b0f902015-10-12 11:30:14 -05004800
Michael Lentine329697b2015-10-06 14:56:18 -07004801 // Create DAG
4802 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
4803 DAGNode& subpass_node = subpass_to_node[i];
4804 subpass_node.pass = i;
4805 }
4806 for (uint32_t i = 0; i < pCreateInfo->dependencyCount; ++i) {
4807 const VkSubpassDependency& dependency = pCreateInfo->pDependencies[i];
Chia-I Wu1f851912015-10-27 18:04:07 +08004808 if (dependency.srcSubpass > dependency.dstSubpass) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004809 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_RENDERPASS, "DS",
Michael Lentine329697b2015-10-06 14:56:18 -07004810 "Dependency graph must be specified such that an earlier pass cannot depend on a later pass.");
4811 }
Chia-I Wu1f851912015-10-27 18:04:07 +08004812 subpass_to_node[dependency.dstSubpass].prev.push_back(dependency.srcSubpass);
4813 subpass_to_node[dependency.srcSubpass].next.push_back(dependency.dstSubpass);
Michael Lentine329697b2015-10-06 14:56:18 -07004814 }
Michael Lentine27b0f902015-10-12 11:30:14 -05004815
Michael Lentine329697b2015-10-06 14:56:18 -07004816 // Find for each attachment the subpasses that use them.
4817 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
4818 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wu763a7492015-10-26 20:48:51 +08004819 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Michael Lentine329697b2015-10-06 14:56:18 -07004820 input_attachment_to_subpass[subpass.pInputAttachments[j].attachment].push_back(i);
4821 }
Chia-I Wu763a7492015-10-26 20:48:51 +08004822 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentine329697b2015-10-06 14:56:18 -07004823 output_attachment_to_subpass[subpass.pColorAttachments[j].attachment].push_back(i);
4824 }
Chia-I Wuce532f72015-10-26 17:32:47 +08004825 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
4826 output_attachment_to_subpass[subpass.pDepthStencilAttachment->attachment].push_back(i);
Michael Lentine329697b2015-10-06 14:56:18 -07004827 }
4828 }
4829 // If there is a dependency needed make sure one exists
4830 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
4831 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
4832 // If the attachment is an input then all subpasses that output must have a dependency relationship
Chia-I Wu763a7492015-10-26 20:48:51 +08004833 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Michael Lentine329697b2015-10-06 14:56:18 -07004834 const uint32_t& attachment = subpass.pInputAttachments[j].attachment;
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004835 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentine329697b2015-10-06 14:56:18 -07004836 }
4837 // If the attachment is an output then all subpasses that use the attachment must have a dependency relationship
Chia-I Wu763a7492015-10-26 20:48:51 +08004838 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentine329697b2015-10-06 14:56:18 -07004839 const uint32_t& attachment = subpass.pColorAttachments[j].attachment;
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004840 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
4841 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentine329697b2015-10-06 14:56:18 -07004842 }
Chia-I Wuce532f72015-10-26 17:32:47 +08004843 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
4844 const uint32_t& attachment = subpass.pDepthStencilAttachment->attachment;
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004845 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
4846 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentine329697b2015-10-06 14:56:18 -07004847 }
4848 }
4849 // Loop through implicit dependencies, if this pass reads make sure the attachment is preserved for all passes after it was written.
4850 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
4851 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wu763a7492015-10-26 20:48:51 +08004852 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004853 CheckPreserved(my_data, device, pCreateInfo, i, subpass.pInputAttachments[j].attachment, subpass_to_node, 0, skip_call);
Michael Lentine329697b2015-10-06 14:56:18 -07004854 }
4855 }
4856 return skip_call;
4857}
4858
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004859VkBool32 ValidateLayouts(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo) {
4860 VkBool32 skip = false;
Mark Lobodzinski78940a42015-11-30 16:48:53 -07004861
4862#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4863 return skip;
4864#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4865
Michael Lentine27b0f902015-10-12 11:30:14 -05004866 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
4867 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
4868 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
4869 if (subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL &&
4870 subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) {
4871 if (subpass.pInputAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004872 // TODO: Verify Valid Use in spec. I believe this is allowed (valid) but may not be optimal performance
4873 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentine27b0f902015-10-12 11:30:14 -05004874 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
4875 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004876 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentine27b0f902015-10-12 11:30:14 -05004877 "Layout for input attachment is %d but can only be READ_ONLY_OPTIMAL or GENERAL.", subpass.pInputAttachments[j].attachment);
4878 }
4879 }
4880 }
4881 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
4882 if (subpass.pColorAttachments[j].layout != VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) {
4883 if (subpass.pColorAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004884 // TODO: Verify Valid Use in spec. I believe this is allowed (valid) but may not be optimal performance
4885 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentine27b0f902015-10-12 11:30:14 -05004886 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
4887 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004888 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentine27b0f902015-10-12 11:30:14 -05004889 "Layout for color attachment is %d but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.", subpass.pColorAttachments[j].attachment);
4890 }
4891 }
4892 }
Mark Lobodzinskic344bef2015-10-28 13:03:56 -06004893 if ((subpass.pDepthStencilAttachment != NULL) &&
4894 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
Michael Lentine27b0f902015-10-12 11:30:14 -05004895 if (subpass.pDepthStencilAttachment->layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) {
4896 if (subpass.pDepthStencilAttachment->layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004897 // TODO: Verify Valid Use in spec. I believe this is allowed (valid) but may not be optimal performance
4898 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentine27b0f902015-10-12 11:30:14 -05004899 "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL.");
4900 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004901 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentine27b0f902015-10-12 11:30:14 -05004902 "Layout for depth attachment is %d but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL.", subpass.pDepthStencilAttachment->attachment);
4903 }
4904 }
4905 }
4906 }
4907 return skip;
4908}
4909
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004910VkBool32 CreatePassDAG(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, std::vector<DAGNode>& subpass_to_node, std::vector<bool>& has_self_dependency) {
4911 VkBool32 skip_call = false;
Michael Lentine27b0f902015-10-12 11:30:14 -05004912 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
4913 DAGNode& subpass_node = subpass_to_node[i];
4914 subpass_node.pass = i;
4915 }
4916 for (uint32_t i = 0; i < pCreateInfo->dependencyCount; ++i) {
4917 const VkSubpassDependency& dependency = pCreateInfo->pDependencies[i];
4918 if (dependency.srcSubpass > dependency.dstSubpass) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004919 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_RENDERPASS, "DS",
Michael Lentine27b0f902015-10-12 11:30:14 -05004920 "Depedency graph must be specified such that an earlier pass cannot depend on a later pass.");
Michael Lentine07ff1a12015-10-15 17:07:00 -05004921 } else if (dependency.srcSubpass == dependency.dstSubpass) {
4922 has_self_dependency[dependency.srcSubpass] = true;
Michael Lentine27b0f902015-10-12 11:30:14 -05004923 }
4924 subpass_to_node[dependency.dstSubpass].prev.push_back(dependency.srcSubpass);
4925 subpass_to_node[dependency.srcSubpass].next.push_back(dependency.dstSubpass);
4926 }
4927 return skip_call;
4928}
Tobin Ehliscb085292015-12-01 09:57:09 -07004929// TODOSC : Add intercept of vkCreateShaderModule
Michael Lentine27b0f902015-10-12 11:30:14 -05004930
Tobin Ehlis32479352015-12-01 09:48:58 -07004931VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateShaderModule(
4932 VkDevice device,
4933 const VkShaderModuleCreateInfo *pCreateInfo,
4934 const VkAllocationCallbacks* pAllocator,
4935 VkShaderModule *pShaderModule)
4936{
4937 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004938 VkBool32 skip_call = false;
Tobin Ehlis32479352015-12-01 09:48:58 -07004939 if (!shader_is_spirv(pCreateInfo)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004940 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
Tobin Ehlis32479352015-12-01 09:48:58 -07004941 /* dev */ 0, 0, SHADER_CHECKER_NON_SPIRV_SHADER, "SC",
4942 "Shader is not SPIR-V");
4943 }
4944
4945 if (skip_call)
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07004946 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis32479352015-12-01 09:48:58 -07004947
4948 VkResult res = my_data->device_dispatch_table->CreateShaderModule(device, pCreateInfo, pAllocator, pShaderModule);
4949
4950 if (res == VK_SUCCESS) {
4951 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisad61de42015-12-02 13:53:34 -07004952 my_data->shaderModuleMap[*pShaderModule] = new shader_module(pCreateInfo);
Tobin Ehlis32479352015-12-01 09:48:58 -07004953 loader_platform_thread_unlock_mutex(&globalLock);
4954 }
4955 return res;
4956}
4957
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004958VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkRenderPass* pRenderPass)
Tobin Ehlis2464b882015-04-01 08:40:34 -06004959{
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004960 VkBool32 skip_call = false;
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004961 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentine27b0f902015-10-12 11:30:14 -05004962 // Create DAG
Michael Lentine07ff1a12015-10-15 17:07:00 -05004963 std::vector<bool> has_self_dependency(pCreateInfo->subpassCount);
Michael Lentine27b0f902015-10-12 11:30:14 -05004964 std::vector<DAGNode> subpass_to_node(pCreateInfo->subpassCount);
Michael Lentine07ff1a12015-10-15 17:07:00 -05004965 skip_call |= CreatePassDAG(dev_data, device, pCreateInfo, subpass_to_node, has_self_dependency);
Michael Lentine27b0f902015-10-12 11:30:14 -05004966 // Validate using DAG
4967 skip_call |= ValidateDependencies(dev_data, device, pCreateInfo, subpass_to_node);
4968 skip_call |= ValidateLayouts(dev_data, device, pCreateInfo);
4969 if (skip_call) {
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07004970 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine329697b2015-10-06 14:56:18 -07004971 }
Chia-I Wu69f40122015-10-26 21:10:41 +08004972 VkResult result = dev_data->device_dispatch_table->CreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06004973 if (VK_SUCCESS == result) {
Tobin Ehliscb085292015-12-01 09:57:09 -07004974 // TODOSC : Merge in tracking of renderpass from ShaderChecker
Tobin Ehlis2464b882015-04-01 08:40:34 -06004975 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004976 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Chia-I Wuc278df82015-07-07 11:50:03 +08004977 if (pCreateInfo->pAttachments) {
4978 localRPCI->pAttachments = new VkAttachmentDescription[localRPCI->attachmentCount];
4979 memcpy((void*)localRPCI->pAttachments, pCreateInfo->pAttachments, localRPCI->attachmentCount*sizeof(VkAttachmentDescription));
Tobin Ehlis2464b882015-04-01 08:40:34 -06004980 }
Chia-I Wuc278df82015-07-07 11:50:03 +08004981 if (pCreateInfo->pSubpasses) {
4982 localRPCI->pSubpasses = new VkSubpassDescription[localRPCI->subpassCount];
4983 memcpy((void*)localRPCI->pSubpasses, pCreateInfo->pSubpasses, localRPCI->subpassCount*sizeof(VkSubpassDescription));
4984
4985 for (uint32_t i = 0; i < localRPCI->subpassCount; i++) {
4986 VkSubpassDescription *subpass = (VkSubpassDescription *) &localRPCI->pSubpasses[i];
Chia-I Wu763a7492015-10-26 20:48:51 +08004987 const uint32_t attachmentCount = subpass->inputAttachmentCount +
4988 subpass->colorAttachmentCount * (1 + (subpass->pResolveAttachments?1:0)) +
Chia-I Wuce532f72015-10-26 17:32:47 +08004989 ((subpass->pDepthStencilAttachment) ? 1 : 0) + subpass->preserveAttachmentCount;
Chia-I Wuc278df82015-07-07 11:50:03 +08004990 VkAttachmentReference *attachments = new VkAttachmentReference[attachmentCount];
4991
Cody Northrop6de6b0b2015-08-04 11:16:41 -06004992 memcpy(attachments, subpass->pInputAttachments,
Chia-I Wu763a7492015-10-26 20:48:51 +08004993 sizeof(attachments[0]) * subpass->inputAttachmentCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06004994 subpass->pInputAttachments = attachments;
Chia-I Wu763a7492015-10-26 20:48:51 +08004995 attachments += subpass->inputAttachmentCount;
Chia-I Wuc278df82015-07-07 11:50:03 +08004996
Cody Northrop6de6b0b2015-08-04 11:16:41 -06004997 memcpy(attachments, subpass->pColorAttachments,
Chia-I Wu763a7492015-10-26 20:48:51 +08004998 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06004999 subpass->pColorAttachments = attachments;
Chia-I Wu763a7492015-10-26 20:48:51 +08005000 attachments += subpass->colorAttachmentCount;
Chia-I Wuc278df82015-07-07 11:50:03 +08005001
Cody Northrop6de6b0b2015-08-04 11:16:41 -06005002 if (subpass->pResolveAttachments) {
5003 memcpy(attachments, subpass->pResolveAttachments,
Chia-I Wu763a7492015-10-26 20:48:51 +08005004 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06005005 subpass->pResolveAttachments = attachments;
Chia-I Wu763a7492015-10-26 20:48:51 +08005006 attachments += subpass->colorAttachmentCount;
Chia-I Wuc278df82015-07-07 11:50:03 +08005007 }
5008
Chia-I Wuce532f72015-10-26 17:32:47 +08005009 if (subpass->pDepthStencilAttachment) {
5010 memcpy(attachments, subpass->pDepthStencilAttachment,
5011 sizeof(attachments[0]) * 1);
5012 subpass->pDepthStencilAttachment = attachments;
5013 attachments += 1;
5014 }
5015
Cody Northrop6de6b0b2015-08-04 11:16:41 -06005016 memcpy(attachments, subpass->pPreserveAttachments,
Chia-I Wu763a7492015-10-26 20:48:51 +08005017 sizeof(attachments[0]) * subpass->preserveAttachmentCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06005018 subpass->pPreserveAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08005019 }
Tobin Ehlis2464b882015-04-01 08:40:34 -06005020 }
Chia-I Wuc278df82015-07-07 11:50:03 +08005021 if (pCreateInfo->pDependencies) {
5022 localRPCI->pDependencies = new VkSubpassDependency[localRPCI->dependencyCount];
5023 memcpy((void*)localRPCI->pDependencies, pCreateInfo->pDependencies, localRPCI->dependencyCount*sizeof(VkSubpassDependency));
Tobin Ehlis2464b882015-04-01 08:40:34 -06005024 }
Tobin Ehlis32479352015-12-01 09:48:58 -07005025 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisad61de42015-12-02 13:53:34 -07005026 dev_data->renderPassMap[*pRenderPass] = new RENDER_PASS_NODE(localRPCI);
Michael Lentine07ff1a12015-10-15 17:07:00 -05005027 dev_data->renderPassMap[*pRenderPass]->hasSelfDependency = has_self_dependency;
Tobin Ehlis32479352015-12-01 09:48:58 -07005028 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis2464b882015-04-01 08:40:34 -06005029 }
5030 return result;
5031}
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005032// Free the renderpass shadow
5033static void deleteRenderPasses(layer_data* my_data)
5034{
5035 if (my_data->renderPassMap.size() <= 0)
5036 return;
5037 for (auto ii=my_data->renderPassMap.begin(); ii!=my_data->renderPassMap.end(); ++ii) {
Tobin Ehlisad61de42015-12-02 13:53:34 -07005038 const VkRenderPassCreateInfo* pRenderPassInfo = (*ii).second->pCreateInfo;
Michael Lentine07ff1a12015-10-15 17:07:00 -05005039 if (pRenderPassInfo->pAttachments) {
5040 delete[] pRenderPassInfo->pAttachments;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005041 }
Michael Lentine07ff1a12015-10-15 17:07:00 -05005042 if (pRenderPassInfo->pSubpasses) {
5043 for (uint32_t i=0; i<pRenderPassInfo->subpassCount; ++i) {
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005044 // Attachements are all allocated in a block, so just need to
5045 // find the first non-null one to delete
Michael Lentine07ff1a12015-10-15 17:07:00 -05005046 if (pRenderPassInfo->pSubpasses[i].pInputAttachments) {
5047 delete[] pRenderPassInfo->pSubpasses[i].pInputAttachments;
5048 } else if (pRenderPassInfo->pSubpasses[i].pColorAttachments) {
5049 delete[] pRenderPassInfo->pSubpasses[i].pColorAttachments;
5050 } else if (pRenderPassInfo->pSubpasses[i].pResolveAttachments) {
5051 delete[] pRenderPassInfo->pSubpasses[i].pResolveAttachments;
5052 } else if (pRenderPassInfo->pSubpasses[i].pPreserveAttachments) {
5053 delete[] pRenderPassInfo->pSubpasses[i].pPreserveAttachments;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005054 }
5055 }
Michael Lentine07ff1a12015-10-15 17:07:00 -05005056 delete[] pRenderPassInfo->pSubpasses;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005057 }
Michael Lentine07ff1a12015-10-15 17:07:00 -05005058 if (pRenderPassInfo->pDependencies) {
5059 delete[] pRenderPassInfo->pDependencies;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005060 }
Tobin Ehlisad61de42015-12-02 13:53:34 -07005061 delete pRenderPassInfo;
Michael Lentine07ff1a12015-10-15 17:07:00 -05005062 delete (*ii).second;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005063 }
5064 my_data->renderPassMap.clear();
5065}
Michael Lentine27b0f902015-10-12 11:30:14 -05005066
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07005067VkBool32 VerifyFramebufferAndRenderPassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
5068 VkBool32 skip_call = false;
Michael Lentine27b0f902015-10-12 11:30:14 -05005069 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5070 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Tobin Ehlisad61de42015-12-02 13:53:34 -07005071 const VkRenderPassCreateInfo* pRenderPassInfo = dev_data->renderPassMap[pRenderPassBegin->renderPass]->pCreateInfo;
Michael Lentine27b0f902015-10-12 11:30:14 -05005072 const VkFramebufferCreateInfo* pFramebufferInfo = dev_data->frameBufferMap[pRenderPassBegin->framebuffer];
5073 if (pRenderPassInfo->attachmentCount != pFramebufferInfo->attachmentCount) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005074 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_RENDERPASS, "DS",
Michael Lentine27b0f902015-10-12 11:30:14 -05005075 "You cannot start a render pass using a framebuffer with a different number of attachments.");
5076 }
5077 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
5078 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
5079 const VkImage& image = dev_data->imageViewMap[image_view]->image;
5080 auto image_data = pCB->imageLayoutMap.find(image);
5081 if (image_data == pCB->imageLayoutMap.end()) {
5082 pCB->imageLayoutMap[image].initialLayout = pRenderPassInfo->pAttachments[i].initialLayout;
5083 pCB->imageLayoutMap[image].layout = pRenderPassInfo->pAttachments[i].initialLayout;
5084 } else if (pRenderPassInfo->pAttachments[i].initialLayout != image_data->second.layout) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005085 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_RENDERPASS, "DS",
Michael Lentine27b0f902015-10-12 11:30:14 -05005086 "You cannot start a render pass using attachment %i where the intial layout differs from the starting layout.", i);
5087 }
5088 }
5089 return skip_call;
5090}
5091
5092void TransitionSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, const int subpass_index) {
5093 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5094 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5095 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
5096 if (render_pass_data == dev_data->renderPassMap.end()) {
5097 return;
5098 }
Tobin Ehlisad61de42015-12-02 13:53:34 -07005099 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
Michael Lentine27b0f902015-10-12 11:30:14 -05005100 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
5101 if (framebuffer_data == dev_data->frameBufferMap.end()) {
5102 return;
5103 }
5104 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
5105 const VkSubpassDescription& subpass = pRenderPassInfo->pSubpasses[subpass_index];
5106 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
5107 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pInputAttachments[j].attachment];
5108 auto image_view_data = dev_data->imageViewMap.find(image_view);
5109 if (image_view_data != dev_data->imageViewMap.end()) {
5110 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5111 if (image_layout != pCB->imageLayoutMap.end()) {
5112 image_layout->second.layout = subpass.pInputAttachments[j].layout;
5113 }
5114 }
5115 }
5116 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
5117 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pColorAttachments[j].attachment];
5118 auto image_view_data = dev_data->imageViewMap.find(image_view);
5119 if (image_view_data != dev_data->imageViewMap.end()) {
5120 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5121 if (image_layout != pCB->imageLayoutMap.end()) {
5122 image_layout->second.layout = subpass.pColorAttachments[j].layout;
5123 }
5124 }
5125 }
Michael Lentine2b9eda42015-10-28 15:55:18 -07005126 if ((subpass.pDepthStencilAttachment != NULL) &&
Mark Lobodzinskic344bef2015-10-28 13:03:56 -06005127 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
Michael Lentine27b0f902015-10-12 11:30:14 -05005128 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pDepthStencilAttachment->attachment];
5129 auto image_view_data = dev_data->imageViewMap.find(image_view);
5130 if (image_view_data != dev_data->imageViewMap.end()) {
5131 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5132 if (image_layout != pCB->imageLayoutMap.end()) {
5133 image_layout->second.layout = subpass.pDepthStencilAttachment->layout;
5134 }
5135 }
5136 }
5137}
5138
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07005139VkBool32 validatePrimaryCommandBuffer(const layer_data* my_data, const GLOBAL_CB_NODE* pCB, const std::string& cmd_name) {
5140 VkBool32 skip_call = false;
Michael Lentine2b9eda42015-10-28 15:55:18 -07005141 if (pCB->createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005142 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_COMMAND_BUFFER, "DS",
Michael Lentine2b9eda42015-10-28 15:55:18 -07005143 "Cannot execute command %s on a secondary command buffer.", cmd_name.c_str());
5144 }
5145 return skip_call;
5146}
5147
Michael Lentine27b0f902015-10-12 11:30:14 -05005148void TransitionFinalSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
5149 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5150 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5151 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
5152 if (render_pass_data == dev_data->renderPassMap.end()) {
5153 return;
5154 }
Tobin Ehlisad61de42015-12-02 13:53:34 -07005155 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
Michael Lentine27b0f902015-10-12 11:30:14 -05005156 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
5157 if (framebuffer_data == dev_data->frameBufferMap.end()) {
5158 return;
5159 }
5160 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
5161 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
5162 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
5163 auto image_view_data = dev_data->imageViewMap.find(image_view);
5164 if (image_view_data != dev_data->imageViewMap.end()) {
5165 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5166 if (image_layout != pCB->imageLayoutMap.end()) {
5167 image_layout->second.layout = pRenderPassInfo->pAttachments[i].finalLayout;
5168 }
5169 }
5170 }
5171}
5172
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005173VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, VkSubpassContents contents)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005174{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005175 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08005176 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5177 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005178 if (pCB) {
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06005179 if (pRenderPassBegin && pRenderPassBegin->renderPass) {
Mark Lobodzinskic344bef2015-10-28 13:03:56 -06005180 skipCall |= VerifyFramebufferAndRenderPassLayouts(commandBuffer, pRenderPassBegin);
Tobin Ehlis42d440c2015-10-20 17:06:16 -06005181 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBeginRenderPass");
Michael Lentine2b9eda42015-10-28 15:55:18 -07005182 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdBeginRenderPass");
Tobin Ehlisb51cb782015-12-16 08:19:42 -07005183 skipCall |= addCmd(dev_data, pCB, CMD_BEGINRENDERPASS, "vkCmdBeginRenderPass()");
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06005184 pCB->activeRenderPass = pRenderPassBegin->renderPass;
Michael Lentine27b0f902015-10-12 11:30:14 -05005185 // This is a shallow copy as that is all that is needed for now
5186 pCB->activeRenderPassBeginInfo = *pRenderPassBegin;
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06005187 pCB->activeSubpass = 0;
5188 pCB->framebuffer = pRenderPassBegin->framebuffer;
5189 if (pCB->lastBoundPipeline) {
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005190 skipCall |= validatePipelineState(dev_data, pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06005191 }
Tobin Ehlise4076782015-06-24 15:53:07 -06005192 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005193 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS, "DS",
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06005194 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tony Barbourb9f82ba2015-04-06 11:09:26 -06005195 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005196 }
Mark Lobodzinskic344bef2015-10-28 13:03:56 -06005197 if (VK_FALSE == skipCall) {
Chia-I Wu1f851912015-10-27 18:04:07 +08005198 dev_data->device_dispatch_table->CmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents);
Mark Lobodzinskic344bef2015-10-28 13:03:56 -06005199 // This is a shallow copy as that is all that is needed for now
5200 dev_data->renderPassBeginInfo = *pRenderPassBegin;
5201 dev_data->currentSubpass = 0;
5202 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005203}
5204
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005205VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents)
Chia-I Wuc278df82015-07-07 11:50:03 +08005206{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005207 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08005208 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5209 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Michael Lentine27b0f902015-10-12 11:30:14 -05005210 TransitionSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo, ++dev_data->currentSubpass);
Chia-I Wuc278df82015-07-07 11:50:03 +08005211 if (pCB) {
Michael Lentine2b9eda42015-10-28 15:55:18 -07005212 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdNextSubpass");
Tobin Ehlisb51cb782015-12-16 08:19:42 -07005213 skipCall |= addCmd(dev_data, pCB, CMD_NEXTSUBPASS, "vkCmdNextSubpass()");
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06005214 pCB->activeSubpass++;
Tony Barbourcbc0fa82015-12-15 10:24:45 -07005215 TransitionSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo, pCB->activeSubpass);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06005216 if (pCB->lastBoundPipeline) {
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005217 skipCall |= validatePipelineState(dev_data, pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Chia-I Wuc278df82015-07-07 11:50:03 +08005218 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06005219 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdNextSubpass");
Chia-I Wuc278df82015-07-07 11:50:03 +08005220 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005221 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08005222 dev_data->device_dispatch_table->CmdNextSubpass(commandBuffer, contents);
Chia-I Wuc278df82015-07-07 11:50:03 +08005223}
5224
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005225VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndRenderPass(VkCommandBuffer commandBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005226{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005227 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08005228 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5229 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Michael Lentine27b0f902015-10-12 11:30:14 -05005230 TransitionFinalSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005231 if (pCB) {
Michael Lentine2b9eda42015-10-28 15:55:18 -07005232 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdEndRenderpass");
Michael Lentine2b9eda42015-10-28 15:55:18 -07005233 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdEndRenderPass");
Tobin Ehlisb51cb782015-12-16 08:19:42 -07005234 skipCall |= addCmd(dev_data, pCB, CMD_ENDRENDERPASS, "vkCmdEndRenderPass()");
Michael Lentine27b0f902015-10-12 11:30:14 -05005235 TransitionFinalSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06005236 pCB->activeRenderPass = 0;
5237 pCB->activeSubpass = 0;
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08005238 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005239 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08005240 dev_data->device_dispatch_table->CmdEndRenderPass(commandBuffer);
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08005241}
5242
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005243VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount, const VkCommandBuffer* pCommandBuffers)
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08005244{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005245 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08005246 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5247 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08005248 if (pCB) {
Tobin Ehlis9185b0a2015-12-16 05:01:22 -07005249 // TODO : If secondary CB was not created w/ *_USAGE_SIMULTANEOUS_USE_BIT it cannot be used more than once in given primary CB
5250 // ALSO if secondary w/o this flag is set in primary, then primary must not be pending execution more than once at a time
5251 // If not w/ SIMULTANEOUS bit, then any other references to those 2ndary CBs are invalidated, should warn on that case
Tobin Ehlis5f728d32015-09-17 14:18:16 -06005252 GLOBAL_CB_NODE* pSubCB = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08005253 for (uint32_t i=0; i<commandBuffersCount; i++) {
5254 pSubCB = getCBNode(dev_data, pCommandBuffers[i]);
Tobin Ehlis5f728d32015-09-17 14:18:16 -06005255 if (!pSubCB) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005256 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_INVALID_SECONDARY_COMMAND_BUFFER, "DS",
Chia-I Wu1f851912015-10-27 18:04:07 +08005257 "vkCmdExecuteCommands() called w/ invalid Cmd Buffer %p in element %u of pCommandBuffers array.", (void*)pCommandBuffers[i], i);
5258 } else if (VK_COMMAND_BUFFER_LEVEL_PRIMARY == pSubCB->createInfo.level) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005259 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_INVALID_SECONDARY_COMMAND_BUFFER, "DS",
Chia-I Wu1f851912015-10-27 18:04:07 +08005260 "vkCmdExecuteCommands() called w/ Primary Cmd Buffer %p in element %u of pCommandBuffers array. All cmd buffers in pCommandBuffers array must be secondary.", (void*)pCommandBuffers[i], i);
Tobin Ehlis9185b0a2015-12-16 05:01:22 -07005261 } else if (pCB->activeRenderPass) { // Secondary CB w/i RenderPass must have *CONTINUE_BIT set
5262 if (!(pSubCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT)) {
5263 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)pCommandBuffers[i], 0, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
5264 "vkCmdExecuteCommands(): Secondary Command Buffer (%p) executed within render pass (%#" PRIxLEAST64 ") must have had vkBeginCommandBuffer() called w/ VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT set.", (void*)pCommandBuffers[i], (uint64_t)pCB->activeRenderPass);
5265 }
5266 string errorString = "";
5267 if (!verify_renderpass_compatibility(dev_data, pCB->activeRenderPass, pSubCB->beginInfo.renderPass, errorString)) {
5268 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)pCommandBuffers[i], 0, DRAWSTATE_RENDERPASS_INCOMPATIBLE, "DS",
5269 "vkCmdExecuteCommands(): Secondary Command Buffer (%p) w/ render pass (%#" PRIxLEAST64 ") is incompatible w/ primary command buffer (%p) w/ render pass (%#" PRIxLEAST64 ") due to: %s",
5270 (void*)pCommandBuffers[i], (uint64_t)pSubCB->beginInfo.renderPass, (void*)commandBuffer, (uint64_t)pCB->activeRenderPass, errorString.c_str());
5271 }
5272 // If framebuffer for secondary CB is not NULL, then it must match FB from vkCmdBeginRenderPass()
5273 // that this CB will be executed in AND framebuffer must have been created w/ RP compatible w/ renderpass
5274 if (pSubCB->beginInfo.framebuffer) {
5275 if (pSubCB->beginInfo.framebuffer != pCB->activeRenderPassBeginInfo.framebuffer) {
5276 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)pCommandBuffers[i], 0, DRAWSTATE_FRAMEBUFFER_INCOMPATIBLE, "DS",
5277 "vkCmdExecuteCommands(): Secondary Command Buffer (%p) references framebuffer (%#" PRIxLEAST64 ") that does not match framebuffer (%#" PRIxLEAST64 ") in active renderpass (%#" PRIxLEAST64 ").",
5278 (void*)pCommandBuffers[i], (uint64_t)pSubCB->beginInfo.framebuffer, (uint64_t)pCB->activeRenderPassBeginInfo.framebuffer, (uint64_t)pCB->activeRenderPass);
5279 }
5280 }
Tobin Ehlis5f728d32015-09-17 14:18:16 -06005281 }
5282 }
Michael Lentine2b9eda42015-10-28 15:55:18 -07005283 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdExecuteComands");
Tobin Ehlisb51cb782015-12-16 08:19:42 -07005284 skipCall |= addCmd(dev_data, pCB, CMD_EXECUTECOMMANDS, "vkCmdExecuteComands()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005285 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005286 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08005287 dev_data->device_dispatch_table->CmdExecuteCommands(commandBuffer, commandBuffersCount, pCommandBuffers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005288}
5289
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07005290VkBool32 ValidateMapImageLayouts(VkDevice device, VkDeviceMemory mem) {
5291 VkBool32 skip_call = false;
Michael Lentineee4ad4d2015-10-23 12:41:44 -07005292 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5293 auto mem_data = dev_data->memImageMap.find(mem);
5294 if (mem_data != dev_data->memImageMap.end()) {
5295 auto image_data = dev_data->imageLayoutMap.find(mem_data->second);
5296 if (image_data != dev_data->imageLayoutMap.end()) {
5297 if (image_data->second->layout != VK_IMAGE_LAYOUT_PREINITIALIZED && image_data->second->layout != VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005298 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineee4ad4d2015-10-23 12:41:44 -07005299 "Cannot map an image with layout %d. Only GENERAL or PREINITIALIZED are supported.", image_data->second->layout);
5300 }
5301 }
5302 }
5303 return skip_call;
5304}
5305
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005306VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkMapMemory(
Michael Lentineee4ad4d2015-10-23 12:41:44 -07005307 VkDevice device,
5308 VkDeviceMemory mem,
5309 VkDeviceSize offset,
5310 VkDeviceSize size,
5311 VkFlags flags,
5312 void **ppData)
5313{
5314 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski78940a42015-11-30 16:48:53 -07005315
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07005316 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski78940a42015-11-30 16:48:53 -07005317#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
5318 skip_call = ValidateMapImageLayouts(device, mem);
5319#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5320
Michael Lentineee4ad4d2015-10-23 12:41:44 -07005321 if (VK_FALSE == skip_call) {
5322 return dev_data->device_dispatch_table->MapMemory(device, mem, offset, size, flags, ppData);
5323 }
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07005324 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentineee4ad4d2015-10-23 12:41:44 -07005325}
5326
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005327VKAPI_ATTR VkResult VKAPI_CALL vkBindImageMemory(
Michael Lentineee4ad4d2015-10-23 12:41:44 -07005328 VkDevice device,
5329 VkImage image,
5330 VkDeviceMemory mem,
5331 VkDeviceSize memOffset)
5332{
5333 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5334 VkResult result = dev_data->device_dispatch_table->BindImageMemory(device, image, mem, memOffset);
5335 loader_platform_thread_lock_mutex(&globalLock);
5336 dev_data->memImageMap[mem] = image;
5337 loader_platform_thread_unlock_mutex(&globalLock);
5338 return result;
5339}
5340
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005341VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(
Michael Lentine27b0f902015-10-12 11:30:14 -05005342 VkDevice device,
5343 const VkSwapchainCreateInfoKHR *pCreateInfo,
Ian Elliottc623ba52015-11-20 14:13:17 -07005344 const VkAllocationCallbacks *pAllocator,
Michael Lentine27b0f902015-10-12 11:30:14 -05005345 VkSwapchainKHR *pSwapchain)
5346{
5347 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliottc623ba52015-11-20 14:13:17 -07005348 VkResult result = dev_data->device_dispatch_table->CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
Michael Lentine27b0f902015-10-12 11:30:14 -05005349
5350 if (VK_SUCCESS == result) {
5351 SWAPCHAIN_NODE *swapchain_data = new SWAPCHAIN_NODE;
5352 loader_platform_thread_lock_mutex(&globalLock);
5353 dev_data->device_extensions.swapchainMap[*pSwapchain] = swapchain_data;
5354 loader_platform_thread_unlock_mutex(&globalLock);
5355 }
5356
5357 return result;
5358}
5359
Ian Elliottc623ba52015-11-20 14:13:17 -07005360VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR(
Michael Lentine27b0f902015-10-12 11:30:14 -05005361 VkDevice device,
Ian Elliottc623ba52015-11-20 14:13:17 -07005362 VkSwapchainKHR swapchain,
5363 const VkAllocationCallbacks *pAllocator)
Michael Lentine27b0f902015-10-12 11:30:14 -05005364{
5365 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentine27b0f902015-10-12 11:30:14 -05005366
5367 loader_platform_thread_lock_mutex(&globalLock);
5368 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(swapchain);
5369 if (swapchain_data != dev_data->device_extensions.swapchainMap.end()) {
5370 if (swapchain_data->second->images.size() > 0) {
5371 for (auto swapchain_image : swapchain_data->second->images) {
5372 auto image_item = dev_data->imageLayoutMap.find(swapchain_image);
5373 if (image_item != dev_data->imageLayoutMap.end())
5374 dev_data->imageLayoutMap.erase(image_item);
5375 }
5376 }
5377 delete swapchain_data->second;
5378 dev_data->device_extensions.swapchainMap.erase(swapchain);
5379 }
5380 loader_platform_thread_unlock_mutex(&globalLock);
Ian Elliottc623ba52015-11-20 14:13:17 -07005381 return dev_data->device_dispatch_table->DestroySwapchainKHR(device, swapchain, pAllocator);
Michael Lentine27b0f902015-10-12 11:30:14 -05005382}
5383
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005384VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR(
Michael Lentine27b0f902015-10-12 11:30:14 -05005385 VkDevice device,
5386 VkSwapchainKHR swapchain,
5387 uint32_t* pCount,
5388 VkImage* pSwapchainImages)
5389{
5390 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5391 VkResult result = dev_data->device_dispatch_table->GetSwapchainImagesKHR(device, swapchain, pCount, pSwapchainImages);
5392
5393 if (result == VK_SUCCESS && pSwapchainImages != NULL) {
5394 // This should never happen and is checked by param checker.
5395 if (!pCount) return result;
5396 for (uint32_t i = 0; i < *pCount; ++i) {
5397 IMAGE_NODE* image_node = new IMAGE_NODE;
5398 image_node->layout = VK_IMAGE_LAYOUT_UNDEFINED;
5399 loader_platform_thread_lock_mutex(&globalLock);
5400 dev_data->device_extensions.swapchainMap[swapchain]->images.push_back(pSwapchainImages[i]);
5401 dev_data->imageLayoutMap[pSwapchainImages[i]] = image_node;
5402 loader_platform_thread_unlock_mutex(&globalLock);
5403 }
5404 }
5405 return result;
5406}
5407
Ian Elliottc623ba52015-11-20 14:13:17 -07005408VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo)
Michael Lentine27b0f902015-10-12 11:30:14 -05005409{
5410 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07005411 VkBool32 skip_call = false;
Michael Lentine27b0f902015-10-12 11:30:14 -05005412
Mark Lobodzinski78940a42015-11-30 16:48:53 -07005413#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentine27b0f902015-10-12 11:30:14 -05005414 if (pPresentInfo) {
5415 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
Ian Elliottc623ba52015-11-20 14:13:17 -07005416 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(pPresentInfo->pSwapchains[i]);
5417 if (swapchain_data != dev_data->device_extensions.swapchainMap.end() && pPresentInfo->pImageIndices[i] < swapchain_data->second->images.size()) {
5418 VkImage image = swapchain_data->second->images[pPresentInfo->pImageIndices[i]];
Michael Lentine27b0f902015-10-12 11:30:14 -05005419 auto image_data = dev_data->imageLayoutMap.find(image);
5420 if (image_data != dev_data->imageLayoutMap.end()) {
Ian Elliottc623ba52015-11-20 14:13:17 -07005421 if (image_data->second->layout != VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005422 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT, (uint64_t)queue, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentine27b0f902015-10-12 11:30:14 -05005423 "Images passed to present must be in layout PRESENT_SOURCE_KHR but is in %d", image_data->second->layout);
5424 }
5425 }
5426 }
5427 }
5428 }
Mark Lobodzinski78940a42015-11-30 16:48:53 -07005429#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentine27b0f902015-10-12 11:30:14 -05005430
5431 if (VK_FALSE == skip_call)
5432 return dev_data->device_dispatch_table->QueuePresentKHR(queue, pPresentInfo);
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07005433 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine27b0f902015-10-12 11:30:14 -05005434}
5435
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005436VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(
5437 VkInstance instance,
5438 const VkDebugReportCallbackCreateInfoEXT* pCreateInfo,
5439 const VkAllocationCallbacks* pAllocator,
5440 VkDebugReportCallbackEXT* pMsgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005441{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005442 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07005443 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005444 VkResult res = pTable->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisc91330b2015-06-16 09:04:30 -06005445 if (VK_SUCCESS == res) {
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07005446 res = layer_create_msg_callback(my_data->report_data, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisc91330b2015-06-16 09:04:30 -06005447 }
5448 return res;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005449}
5450
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005451VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07005452 VkInstance instance,
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005453 VkDebugReportCallbackEXT msgCallback,
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07005454 const VkAllocationCallbacks* pAllocator)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005455{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005456 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07005457 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005458 pTable->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07005459 layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005460}
5461
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005462VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDebugReportMessageEXT(
Courtney Goeltzenleuchter5a424ce2015-12-01 14:10:55 -07005463 VkInstance instance,
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005464 VkDebugReportFlagsEXT flags,
5465 VkDebugReportObjectTypeEXT objType,
Courtney Goeltzenleuchter5a424ce2015-12-01 14:10:55 -07005466 uint64_t object,
5467 size_t location,
5468 int32_t msgCode,
5469 const char* pLayerPrefix,
5470 const char* pMsg)
5471{
5472 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005473 my_data->instance_dispatch_table->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg);
Courtney Goeltzenleuchter5a424ce2015-12-01 14:10:55 -07005474}
5475
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005476VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerBegin(VkCommandBuffer commandBuffer, const char* pMarker)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005477{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005478 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08005479 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5480 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005481 if (!dev_data->device_extensions.debug_marker_enabled) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005482 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06005483 "Attempt to use CmdDbgMarkerBegin but extension disabled!");
Jon Ashburn6f8cd632015-06-01 09:37:38 -06005484 return;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06005485 } else if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07005486 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKERBEGIN, "vkCmdDbgMarkerBegin()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005487 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005488 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08005489 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerBegin(commandBuffer, pMarker);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005490}
5491
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005492VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerEnd(VkCommandBuffer commandBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005493{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005494 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08005495 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5496 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005497 if (!dev_data->device_extensions.debug_marker_enabled) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005498 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06005499 "Attempt to use CmdDbgMarkerEnd but extension disabled!");
Jon Ashburn6f8cd632015-06-01 09:37:38 -06005500 return;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06005501 } else if (pCB) {
Tobin Ehlisb51cb782015-12-16 08:19:42 -07005502 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKEREND, "vkCmdDbgMarkerEnd()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005503 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005504 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08005505 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerEnd(commandBuffer);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06005506}
5507
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005508VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005509{
Jon Ashburn1245cec2015-05-18 13:20:15 -06005510 if (dev == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005511 return NULL;
Jon Ashburne0fa2282015-05-20 09:00:28 -06005512
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005513 layer_data *dev_data;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005514 /* loader uses this to force layer initialization; device object is wrapped */
5515 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005516 VkBaseLayerObject* wrapped_dev = (VkBaseLayerObject*) dev;
5517 dev_data = get_my_data_ptr(get_dispatch_key(wrapped_dev->baseObject), layer_data_map);
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005518 dev_data->device_dispatch_table = new VkLayerDispatchTable;
5519 layer_initialize_dispatch_table(dev_data->device_dispatch_table, wrapped_dev);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005520 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005521 }
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005522 dev_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map);
Courtney Goeltzenleuchterbe637992015-06-25 18:01:43 -06005523 if (!strcmp(funcName, "vkCreateDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005524 return (PFN_vkVoidFunction) vkCreateDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005525 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005526 return (PFN_vkVoidFunction) vkDestroyDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005527 if (!strcmp(funcName, "vkQueueSubmit"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005528 return (PFN_vkVoidFunction) vkQueueSubmit;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005529 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005530 return (PFN_vkVoidFunction) vkDestroyInstance;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005531 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005532 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005533 if (!strcmp(funcName, "vkDestroyFence"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005534 return (PFN_vkVoidFunction) vkDestroyFence;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005535 if (!strcmp(funcName, "vkDestroySemaphore"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005536 return (PFN_vkVoidFunction) vkDestroySemaphore;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005537 if (!strcmp(funcName, "vkDestroyEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005538 return (PFN_vkVoidFunction) vkDestroyEvent;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005539 if (!strcmp(funcName, "vkDestroyQueryPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005540 return (PFN_vkVoidFunction) vkDestroyQueryPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005541 if (!strcmp(funcName, "vkDestroyBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005542 return (PFN_vkVoidFunction) vkDestroyBuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005543 if (!strcmp(funcName, "vkDestroyBufferView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005544 return (PFN_vkVoidFunction) vkDestroyBufferView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005545 if (!strcmp(funcName, "vkDestroyImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005546 return (PFN_vkVoidFunction) vkDestroyImage;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005547 if (!strcmp(funcName, "vkDestroyImageView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005548 return (PFN_vkVoidFunction) vkDestroyImageView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005549 if (!strcmp(funcName, "vkDestroyShaderModule"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005550 return (PFN_vkVoidFunction) vkDestroyShaderModule;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005551 if (!strcmp(funcName, "vkDestroyPipeline"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005552 return (PFN_vkVoidFunction) vkDestroyPipeline;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005553 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005554 return (PFN_vkVoidFunction) vkDestroyPipelineLayout;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005555 if (!strcmp(funcName, "vkDestroySampler"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005556 return (PFN_vkVoidFunction) vkDestroySampler;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005557 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005558 return (PFN_vkVoidFunction) vkDestroyDescriptorSetLayout;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005559 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005560 return (PFN_vkVoidFunction) vkDestroyDescriptorPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005561 if (!strcmp(funcName, "vkDestroyFramebuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005562 return (PFN_vkVoidFunction) vkDestroyFramebuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005563 if (!strcmp(funcName, "vkDestroyRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005564 return (PFN_vkVoidFunction) vkDestroyRenderPass;
Tobin Ehlisb46be812015-10-23 16:00:08 -06005565 if (!strcmp(funcName, "vkCreateBuffer"))
5566 return (PFN_vkVoidFunction) vkCreateBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005567 if (!strcmp(funcName, "vkCreateBufferView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005568 return (PFN_vkVoidFunction) vkCreateBufferView;
Tobin Ehlisb46be812015-10-23 16:00:08 -06005569 if (!strcmp(funcName, "vkCreateImage"))
5570 return (PFN_vkVoidFunction) vkCreateImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005571 if (!strcmp(funcName, "vkCreateImageView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005572 return (PFN_vkVoidFunction) vkCreateImageView;
Jon Ashburn0d60d272015-07-09 15:02:25 -06005573 if (!strcmp(funcName, "CreatePipelineCache"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005574 return (PFN_vkVoidFunction) vkCreatePipelineCache;
Jon Ashburn0d60d272015-07-09 15:02:25 -06005575 if (!strcmp(funcName, "DestroyPipelineCache"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005576 return (PFN_vkVoidFunction) vkDestroyPipelineCache;
Jon Ashburn0d60d272015-07-09 15:02:25 -06005577 if (!strcmp(funcName, "GetPipelineCacheData"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005578 return (PFN_vkVoidFunction) vkGetPipelineCacheData;
Jon Ashburn0d60d272015-07-09 15:02:25 -06005579 if (!strcmp(funcName, "MergePipelineCaches"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005580 return (PFN_vkVoidFunction) vkMergePipelineCaches;
Jon Ashburn0d60d272015-07-09 15:02:25 -06005581 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005582 return (PFN_vkVoidFunction) vkCreateGraphicsPipelines;
Mark Lobodzinski2adea752015-11-10 15:25:01 -07005583 if (!strcmp(funcName, "vkCreateComputePipelines"))
5584 return (PFN_vkVoidFunction) vkCreateComputePipelines;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005585 if (!strcmp(funcName, "vkCreateSampler"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005586 return (PFN_vkVoidFunction) vkCreateSampler;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005587 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005588 return (PFN_vkVoidFunction) vkCreateDescriptorSetLayout;
Mark Lobodzinski556f7212015-04-17 14:11:39 -05005589 if (!strcmp(funcName, "vkCreatePipelineLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005590 return (PFN_vkVoidFunction) vkCreatePipelineLayout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005591 if (!strcmp(funcName, "vkCreateDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005592 return (PFN_vkVoidFunction) vkCreateDescriptorPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005593 if (!strcmp(funcName, "vkResetDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005594 return (PFN_vkVoidFunction) vkResetDescriptorPool;
Chia-I Wu1f851912015-10-27 18:04:07 +08005595 if (!strcmp(funcName, "vkAllocateDescriptorSets"))
5596 return (PFN_vkVoidFunction) vkAllocateDescriptorSets;
Tobin Ehlis3c543112015-10-08 13:13:50 -06005597 if (!strcmp(funcName, "vkFreeDescriptorSets"))
5598 return (PFN_vkVoidFunction) vkFreeDescriptorSets;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08005599 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005600 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07005601 if (!strcmp(funcName, "vkCreateCommandPool"))
5602 return (PFN_vkVoidFunction) vkCreateCommandPool;
5603 if (!strcmp(funcName, "vkDestroyCommandPool"))
5604 return (PFN_vkVoidFunction) vkDestroyCommandPool;
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07005605 if (!strcmp(funcName, "vkResetCommandPool"))
5606 return (PFN_vkVoidFunction) vkResetCommandPool;
Chia-I Wu1f851912015-10-27 18:04:07 +08005607 if (!strcmp(funcName, "vkAllocateCommandBuffers"))
5608 return (PFN_vkVoidFunction) vkAllocateCommandBuffers;
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07005609 if (!strcmp(funcName, "vkFreeCommandBuffers"))
5610 return (PFN_vkVoidFunction) vkFreeCommandBuffers;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005611 if (!strcmp(funcName, "vkBeginCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005612 return (PFN_vkVoidFunction) vkBeginCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005613 if (!strcmp(funcName, "vkEndCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005614 return (PFN_vkVoidFunction) vkEndCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005615 if (!strcmp(funcName, "vkResetCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005616 return (PFN_vkVoidFunction) vkResetCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005617 if (!strcmp(funcName, "vkCmdBindPipeline"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005618 return (PFN_vkVoidFunction) vkCmdBindPipeline;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06005619 if (!strcmp(funcName, "vkCmdSetViewport"))
5620 return (PFN_vkVoidFunction) vkCmdSetViewport;
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06005621 if (!strcmp(funcName, "vkCmdSetScissor"))
5622 return (PFN_vkVoidFunction) vkCmdSetScissor;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06005623 if (!strcmp(funcName, "vkCmdSetLineWidth"))
5624 return (PFN_vkVoidFunction) vkCmdSetLineWidth;
5625 if (!strcmp(funcName, "vkCmdSetDepthBias"))
5626 return (PFN_vkVoidFunction) vkCmdSetDepthBias;
5627 if (!strcmp(funcName, "vkCmdSetBlendConstants"))
5628 return (PFN_vkVoidFunction) vkCmdSetBlendConstants;
5629 if (!strcmp(funcName, "vkCmdSetDepthBounds"))
5630 return (PFN_vkVoidFunction) vkCmdSetDepthBounds;
5631 if (!strcmp(funcName, "vkCmdSetStencilCompareMask"))
5632 return (PFN_vkVoidFunction) vkCmdSetStencilCompareMask;
5633 if (!strcmp(funcName, "vkCmdSetStencilWriteMask"))
5634 return (PFN_vkVoidFunction) vkCmdSetStencilWriteMask;
5635 if (!strcmp(funcName, "vkCmdSetStencilReference"))
5636 return (PFN_vkVoidFunction) vkCmdSetStencilReference;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005637 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005638 return (PFN_vkVoidFunction) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06005639 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005640 return (PFN_vkVoidFunction) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005641 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005642 return (PFN_vkVoidFunction) vkCmdBindIndexBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005643 if (!strcmp(funcName, "vkCmdDraw"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005644 return (PFN_vkVoidFunction) vkCmdDraw;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005645 if (!strcmp(funcName, "vkCmdDrawIndexed"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005646 return (PFN_vkVoidFunction) vkCmdDrawIndexed;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005647 if (!strcmp(funcName, "vkCmdDrawIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005648 return (PFN_vkVoidFunction) vkCmdDrawIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005649 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005650 return (PFN_vkVoidFunction) vkCmdDrawIndexedIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005651 if (!strcmp(funcName, "vkCmdDispatch"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005652 return (PFN_vkVoidFunction) vkCmdDispatch;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005653 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005654 return (PFN_vkVoidFunction) vkCmdDispatchIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005655 if (!strcmp(funcName, "vkCmdCopyBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005656 return (PFN_vkVoidFunction) vkCmdCopyBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005657 if (!strcmp(funcName, "vkCmdCopyImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005658 return (PFN_vkVoidFunction) vkCmdCopyImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005659 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005660 return (PFN_vkVoidFunction) vkCmdCopyBufferToImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005661 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005662 return (PFN_vkVoidFunction) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005663 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005664 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005665 if (!strcmp(funcName, "vkCmdFillBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005666 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005667 if (!strcmp(funcName, "vkCmdClearColorImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005668 return (PFN_vkVoidFunction) vkCmdClearColorImage;
Chris Forbes2951d7d2015-06-22 17:21:59 +12005669 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005670 return (PFN_vkVoidFunction) vkCmdClearDepthStencilImage;
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06005671 if (!strcmp(funcName, "vkCmdClearAttachments"))
5672 return (PFN_vkVoidFunction) vkCmdClearAttachments;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005673 if (!strcmp(funcName, "vkCmdResolveImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005674 return (PFN_vkVoidFunction) vkCmdResolveImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005675 if (!strcmp(funcName, "vkCmdSetEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005676 return (PFN_vkVoidFunction) vkCmdSetEvent;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005677 if (!strcmp(funcName, "vkCmdResetEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005678 return (PFN_vkVoidFunction) vkCmdResetEvent;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005679 if (!strcmp(funcName, "vkCmdWaitEvents"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005680 return (PFN_vkVoidFunction) vkCmdWaitEvents;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005681 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005682 return (PFN_vkVoidFunction) vkCmdPipelineBarrier;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005683 if (!strcmp(funcName, "vkCmdBeginQuery"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005684 return (PFN_vkVoidFunction) vkCmdBeginQuery;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005685 if (!strcmp(funcName, "vkCmdEndQuery"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005686 return (PFN_vkVoidFunction) vkCmdEndQuery;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005687 if (!strcmp(funcName, "vkCmdResetQueryPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005688 return (PFN_vkVoidFunction) vkCmdResetQueryPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005689 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005690 return (PFN_vkVoidFunction) vkCmdWriteTimestamp;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005691 if (!strcmp(funcName, "vkCreateFramebuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005692 return (PFN_vkVoidFunction) vkCreateFramebuffer;
Tobin Ehlis32479352015-12-01 09:48:58 -07005693 if (!strcmp(funcName, "vkCreateShaderModule"))
5694 return (PFN_vkVoidFunction) vkCreateShaderModule;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005695 if (!strcmp(funcName, "vkCreateRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005696 return (PFN_vkVoidFunction) vkCreateRenderPass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005697 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005698 return (PFN_vkVoidFunction) vkCmdBeginRenderPass;
Chia-I Wuc278df82015-07-07 11:50:03 +08005699 if (!strcmp(funcName, "vkCmdNextSubpass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005700 return (PFN_vkVoidFunction) vkCmdNextSubpass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005701 if (!strcmp(funcName, "vkCmdEndRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005702 return (PFN_vkVoidFunction) vkCmdEndRenderPass;
Tobin Ehlis5f728d32015-09-17 14:18:16 -06005703 if (!strcmp(funcName, "vkCmdExecuteCommands"))
5704 return (PFN_vkVoidFunction) vkCmdExecuteCommands;
Michael Lentineee4ad4d2015-10-23 12:41:44 -07005705 if (!strcmp(funcName, "vkMapMemory"))
5706 return (PFN_vkVoidFunction) vkMapMemory;
Jon Ashburn6f8cd632015-06-01 09:37:38 -06005707
Michael Lentine27b0f902015-10-12 11:30:14 -05005708 if (dev_data->device_extensions.wsi_enabled)
5709 {
5710 if (!strcmp(funcName, "vkCreateSwapchainKHR"))
5711 return (PFN_vkVoidFunction) vkCreateSwapchainKHR;
5712 if (!strcmp(funcName, "vkDestroySwapchainKHR"))
5713 return (PFN_vkVoidFunction) vkDestroySwapchainKHR;
5714 if (!strcmp(funcName, "vkGetSwapchainImagesKHR"))
5715 return (PFN_vkVoidFunction) vkGetSwapchainImagesKHR;
5716 if (!strcmp(funcName, "vkQueuePresentKHR"))
5717 return (PFN_vkVoidFunction) vkQueuePresentKHR;
5718 }
5719
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005720 VkLayerDispatchTable* pTable = dev_data->device_dispatch_table;
5721 if (dev_data->device_extensions.debug_marker_enabled)
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005722 {
Jon Ashburn7e07faf2015-06-18 15:02:58 -06005723 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005724 return (PFN_vkVoidFunction) vkCmdDbgMarkerBegin;
Jon Ashburn7e07faf2015-06-18 15:02:58 -06005725 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005726 return (PFN_vkVoidFunction) vkCmdDbgMarkerEnd;
Jon Ashburn6f8cd632015-06-01 09:37:38 -06005727 }
5728 {
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005729 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005730 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005731 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburn79b78ac2015-05-05 14:22:52 -06005732 }
5733}
5734
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005735VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06005736{
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005737 PFN_vkVoidFunction fptr;
Jon Ashburn79b78ac2015-05-05 14:22:52 -06005738 if (instance == NULL)
5739 return NULL;
5740
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005741 layer_data* my_data;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005742 /* loader uses this to force layer initialization; instance object is wrapped */
5743 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005744 VkBaseLayerObject* wrapped_inst = (VkBaseLayerObject*) instance;
5745 my_data = get_my_data_ptr(get_dispatch_key(wrapped_inst->baseObject), layer_data_map);
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005746 my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
5747 layer_init_instance_dispatch_table(my_data->instance_dispatch_table, wrapped_inst);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005748 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005749 }
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06005750 if (!strcmp(funcName, "vkCreateInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005751 return (PFN_vkVoidFunction) vkCreateInstance;
Jon Ashburne0fa2282015-05-20 09:00:28 -06005752 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005753 return (PFN_vkVoidFunction) vkDestroyInstance;
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -06005754 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
5755 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
5756 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
5757 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
5758 if (!strcmp(funcName, "vkEnumerateDeviceLayerProperties"))
5759 return (PFN_vkVoidFunction) vkEnumerateDeviceLayerProperties;
5760 if (!strcmp(funcName, "vkEnumerateDeviceExtensionProperties"))
5761 return (PFN_vkVoidFunction) vkEnumerateDeviceExtensionProperties;
Courtney Goeltzenleuchtercc899fe2015-06-01 14:33:14 -06005762
Tobin Ehlis32479352015-12-01 09:48:58 -07005763 my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06005764 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchtercc899fe2015-06-01 14:33:14 -06005765 if (fptr)
5766 return fptr;
5767
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005768 {
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005769 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005770 if (pTable->GetInstanceProcAddr == NULL)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06005771 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005772 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005773 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005774}