blob: 58f9cf67d09c9ee1df2ee0f03849d1aae3236b63 [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// Track the last global DrawState of interest touched by any thread
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001021static PIPELINE_NODE* g_lastBoundPipeline = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001022#define MAX_BINDING 0xFFFFFFFF // Default vtxBinding value in CB Node to identify if no vtxBinding set
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06001023// prototype
Chia-I Wu1f851912015-10-27 18:04:07 +08001024static GLOBAL_CB_NODE* getCBNode(layer_data*, const VkCommandBuffer);
Tobin Ehlis982099b2015-11-05 09:52:49 -07001025
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -06001026static VkBool32 hasDrawCmd(GLOBAL_CB_NODE* pCB)
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001027{
1028 for (uint32_t i=0; i<NUM_DRAW_TYPES; i++) {
1029 if (pCB->drawCount[i])
1030 return VK_TRUE;
1031 }
1032 return VK_FALSE;
1033}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001034
Tobin Ehlis97866202015-06-10 12:57:07 -06001035// Check object status for selected flag state
Tobin Ehlis42d440c2015-10-20 17:06:16 -06001036static 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 -06001037{
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06001038 // If non-zero enable mask is present, check it against status but if enable_mask
1039 // is 0 then no enable required so we should always just check status
1040 if ((!enable_mask) || (enable_mask & pNode->status)) {
1041 if ((pNode->status & status_mask) != status_flag) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001042 // TODO : How to pass dispatchable objects as srcObject? Here src obj should be cmd buffer
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001043 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 +08001044 "CB object %#" PRIxLEAST64 ": %s", reinterpret_cast<uint64_t>(pNode->commandBuffer), fail_msg);
Tobin Ehlis97866202015-06-10 12:57:07 -06001045 }
Tobin Ehlis97866202015-06-10 12:57:07 -06001046 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001047 return VK_FALSE;
Tobin Ehlis97866202015-06-10 12:57:07 -06001048}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001049
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001050// Retrieve pipeline node ptr for given pipeline object
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06001051static PIPELINE_NODE* getPipeline(layer_data* my_data, const VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001052{
1053 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue420a332015-10-26 20:04:44 +08001054 if (my_data->pipelineMap.find(pipeline) == my_data->pipelineMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001055 loader_platform_thread_unlock_mutex(&globalLock);
1056 return NULL;
1057 }
1058 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wue420a332015-10-26 20:04:44 +08001059 return my_data->pipelineMap[pipeline];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001060}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001061
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06001062// Return VK_TRUE if for a given PSO, the given state enum is dynamic, else return VK_FALSE
1063static VkBool32 isDynamic(const PIPELINE_NODE* pPipeline, const VkDynamicState state)
1064{
1065 if (pPipeline && pPipeline->graphicsPipelineCI.pDynamicState) {
1066 for (uint32_t i=0; i<pPipeline->graphicsPipelineCI.pDynamicState->dynamicStateCount; i++) {
1067 if (state == pPipeline->graphicsPipelineCI.pDynamicState->pDynamicStates[i])
1068 return VK_TRUE;
1069 }
1070 }
1071 return VK_FALSE;
1072}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001073
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06001074// Validate state stored as flags at time of draw call
Tobin Ehlis42d440c2015-10-20 17:06:16 -06001075static VkBool32 validate_draw_state_flags(layer_data* my_data, GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -06001076 VkBool32 result;
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001077 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");
1078 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");
1079 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");
1080 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");
1081 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");
1082 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");
1083 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");
1084 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");
1085 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 -06001086 if (indexedDraw)
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001087 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 -06001088 return result;
1089}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001090
1091// For give SET_NODE, verify that its Set is compatible w/ the setLayout corresponding to pipelineLayout[layoutIndex]
1092static bool verify_set_layout_compatibility(layer_data* my_data, const SET_NODE* pSet, const VkPipelineLayout layout, const uint32_t layoutIndex, string& errorMsg)
1093{
Tobin Ehliscb085292015-12-01 09:57:09 -07001094 stringstream errorStr;
Tobin Ehlis982099b2015-11-05 09:52:49 -07001095 if (my_data->pipelineLayoutMap.find(layout) == my_data->pipelineLayoutMap.end()) {
Tobin Ehliscb085292015-12-01 09:57:09 -07001096 errorStr << "invalid VkPipelineLayout (" << layout << ")";
1097 errorMsg = errorStr.str();
Tobin Ehlis982099b2015-11-05 09:52:49 -07001098 return false;
1099 }
1100 PIPELINE_LAYOUT_NODE pl = my_data->pipelineLayoutMap[layout];
1101 if (layoutIndex >= pl.descriptorSetLayouts.size()) {
Tobin Ehliscb085292015-12-01 09:57:09 -07001102 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;
1103 errorMsg = errorStr.str();
Tobin Ehlis982099b2015-11-05 09:52:49 -07001104 return false;
1105 }
1106 // Get the specific setLayout from PipelineLayout that overlaps this set
Tobin Ehlisad61de42015-12-02 13:53:34 -07001107 LAYOUT_NODE* pLayoutNode = my_data->descriptorSetLayoutMap[pl.descriptorSetLayouts[layoutIndex]];
Tobin Ehlis982099b2015-11-05 09:52:49 -07001108 if (pLayoutNode->layout == pSet->pLayout->layout) { // trivial pass case
1109 return true;
1110 }
Courtney Goeltzenleuchter740451a2015-12-16 16:06:06 -07001111 size_t descriptorCount = pLayoutNode->descriptorTypes.size();
Tobin Ehlis982099b2015-11-05 09:52:49 -07001112 if (descriptorCount != pSet->pLayout->descriptorTypes.size()) {
Tobin Ehliscb085292015-12-01 09:57:09 -07001113 errorStr << "setLayout " << layoutIndex << " from pipelineLayout " << layout << " has " << descriptorCount << " descriptors, but corresponding set being bound has " << pSet->pLayout->descriptorTypes.size() << " descriptors.";
1114 errorMsg = errorStr.str();
Tobin Ehlis982099b2015-11-05 09:52:49 -07001115 return false; // trivial fail case
1116 }
1117 // Now need to check set against corresponding pipelineLayout to verify compatibility
Courtney Goeltzenleuchter740451a2015-12-16 16:06:06 -07001118 for (size_t i=0; i<descriptorCount; ++i) {
Tobin Ehlis982099b2015-11-05 09:52:49 -07001119 // Need to verify that layouts are identically defined
1120 // TODO : Is below sufficient? Making sure that types & stageFlags match per descriptor
1121 // do we also need to check immutable samplers?
1122 if (pLayoutNode->descriptorTypes[i] != pSet->pLayout->descriptorTypes[i]) {
Tobin Ehliscb085292015-12-01 09:57:09 -07001123 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]) << "'";
1124 errorMsg = errorStr.str();
Tobin Ehlis982099b2015-11-05 09:52:49 -07001125 return false;
1126 }
1127 if (pLayoutNode->stageFlags[i] != pSet->pLayout->stageFlags[i]) {
Tobin Ehliscb085292015-12-01 09:57:09 -07001128 errorStr << "stageFlags " << i << " for descriptorSet being bound is " << pSet->pLayout->stageFlags[i] << "' but corresponding descriptor from pipelineLayout has stageFlags " << pLayoutNode->stageFlags[i];
1129 errorMsg = errorStr.str();
Tobin Ehlis982099b2015-11-05 09:52:49 -07001130 return false;
1131 }
1132 }
1133 return true;
1134}
1135
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07001136// Validate that the shaders used by the given pipeline
1137// As a side effect this function also records the sets that are actually used by the pipeline
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07001138static VkBool32
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07001139validate_pipeline_shaders(layer_data *my_data, VkDevice dev, PIPELINE_NODE* pPipeline)
Tobin Ehlis32479352015-12-01 09:48:58 -07001140{
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07001141 VkGraphicsPipelineCreateInfo const *pCreateInfo = &pPipeline->graphicsPipelineCI;
Tobin Ehlis32479352015-12-01 09:48:58 -07001142 /* We seem to allow pipeline stages to be specified out of order, so collect and identify them
1143 * before trying to do anything more: */
1144 int vertex_stage = get_shader_stage_id(VK_SHADER_STAGE_VERTEX_BIT);
1145 int geometry_stage = get_shader_stage_id(VK_SHADER_STAGE_GEOMETRY_BIT);
1146 int fragment_stage = get_shader_stage_id(VK_SHADER_STAGE_FRAGMENT_BIT);
1147
1148 shader_module **shaders = new shader_module*[fragment_stage + 1]; /* exclude CS */
1149 memset(shaders, 0, sizeof(shader_module *) * (fragment_stage +1));
Tobin Ehlisad61de42015-12-02 13:53:34 -07001150 RENDER_PASS_NODE const *rp = 0;
Tobin Ehlis32479352015-12-01 09:48:58 -07001151 VkPipelineVertexInputStateCreateInfo const *vi = 0;
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07001152 VkBool32 pass = true;
Tobin Ehlis32479352015-12-01 09:48:58 -07001153
1154 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
1155 VkPipelineShaderStageCreateInfo const *pStage = &pCreateInfo->pStages[i];
1156 if (pStage->sType == VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO) {
1157
1158 if ((pStage->stage & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_GEOMETRY_BIT | VK_SHADER_STAGE_FRAGMENT_BIT
1159 | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT)) == 0) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001160 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 -07001161 "Unknown shader stage %d", pStage->stage)) {
1162 pass = false;
1163 }
1164 }
1165 else {
Tobin Ehlisad61de42015-12-02 13:53:34 -07001166 shader_module *module = my_data->shaderModuleMap[pStage->module];
Tobin Ehlis32479352015-12-01 09:48:58 -07001167 shaders[get_shader_stage_id(pStage->stage)] = module;
1168
1169 /* validate descriptor set layout against what the spirv module actually uses */
1170 std::map<std::pair<unsigned, unsigned>, interface_var> descriptor_uses;
1171 collect_interface_by_descriptor_slot(my_data, dev, module, spv::StorageClassUniform,
1172 descriptor_uses);
1173
Tobin Ehlisad61de42015-12-02 13:53:34 -07001174 auto layouts = pCreateInfo->layout != VK_NULL_HANDLE ?
1175 &(my_data->pipelineLayoutMap[pCreateInfo->layout].descriptorSetLayouts) : nullptr;
Tobin Ehlis32479352015-12-01 09:48:58 -07001176
1177 for (auto it = descriptor_uses.begin(); it != descriptor_uses.end(); it++) {
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07001178 // As a side-effect of this function, capture which sets are used by the pipeline
1179 pPipeline->active_sets.insert(it->first.first);
Tobin Ehlis32479352015-12-01 09:48:58 -07001180
1181 /* find the matching binding */
Tobin Ehlisad61de42015-12-02 13:53:34 -07001182 auto found = has_descriptor_binding(my_data, layouts, it->first);
Tobin Ehlis32479352015-12-01 09:48:58 -07001183
1184 if (!found) {
1185 char type_name[1024];
1186 describe_type(type_name, module, it->second.type_id);
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001187 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 -07001188 SHADER_CHECKER_MISSING_DESCRIPTOR, "SC",
1189 "Shader uses descriptor slot %u.%u (used as type `%s`) but not declared in pipeline layout",
1190 it->first.first, it->first.second, type_name)) {
1191 pass = false;
1192 }
1193 }
1194 }
1195 }
1196 }
1197 }
1198
1199 if (pCreateInfo->renderPass != VK_NULL_HANDLE)
Tobin Ehlisad61de42015-12-02 13:53:34 -07001200 rp = my_data->renderPassMap[pCreateInfo->renderPass];
Tobin Ehlis32479352015-12-01 09:48:58 -07001201
1202 vi = pCreateInfo->pVertexInputState;
1203
1204 if (vi) {
1205 pass = validate_vi_consistency(my_data, dev, vi) && pass;
1206 }
1207
1208 if (shaders[vertex_stage]) {
1209 pass = validate_vi_against_vs_inputs(my_data, dev, vi, shaders[vertex_stage]) && pass;
1210 }
1211
1212 /* TODO: enforce rules about present combinations of shaders */
1213 int producer = get_shader_stage_id(VK_SHADER_STAGE_VERTEX_BIT);
1214 int consumer = get_shader_stage_id(VK_SHADER_STAGE_GEOMETRY_BIT);
1215
1216 while (!shaders[producer] && producer != fragment_stage) {
1217 producer++;
1218 consumer++;
1219 }
1220
1221 for (; producer != fragment_stage && consumer <= fragment_stage; consumer++) {
1222 assert(shaders[producer]);
1223 if (shaders[consumer]) {
1224 pass = validate_interface_between_stages(my_data, dev,
1225 shaders[producer], shader_stage_attribs[producer].name,
1226 shaders[consumer], shader_stage_attribs[consumer].name,
1227 shader_stage_attribs[consumer].arrayed_input) && pass;
1228
1229 producer = consumer;
1230 }
1231 }
1232
1233 if (shaders[fragment_stage] && rp) {
1234 pass = validate_fs_outputs_against_render_pass(my_data, dev, shaders[fragment_stage], rp, pCreateInfo->subpass) && pass;
1235 }
1236
1237 delete shaders;
1238
1239 return pass;
1240}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001241
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06001242// Validate overall state at the time of a draw call
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06001243static VkBool32 validate_draw_state(layer_data* my_data, GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06001244 // First check flag states
Tobin Ehlis42d440c2015-10-20 17:06:16 -06001245 VkBool32 result = validate_draw_state_flags(my_data, pCB, indexedDraw);
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06001246 PIPELINE_NODE* pPipe = getPipeline(my_data, pCB->lastBoundPipeline);
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06001247 // Now complete other state checks
Tobin Ehlis12ab7dc2015-09-09 13:31:01 -06001248 // TODO : Currently only performing next check if *something* was bound (non-zero last bound)
1249 // There is probably a better way to gate when this check happens, and to know if something *should* have been bound
1250 // We should have that check separately and then gate this check based on that check
Tobin Ehlis982099b2015-11-05 09:52:49 -07001251 if (pPipe && (pCB->lastBoundPipelineLayout)) {
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07001252 string errorString;
1253 for (auto setIndex : pPipe->active_sets) {
1254 // If valid set is not bound throw an error
1255 if ((pCB->boundDescriptorSets.size() <= setIndex) || (!pCB->boundDescriptorSets[setIndex])) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001256 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_DESCRIPTOR_SET_NOT_BOUND, "DS",
1257 "VkPipeline %#" PRIxLEAST64 " uses set #%u but that set is not bound.", (uint64_t)pPipe->pipeline, setIndex);
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07001258 } else if (!verify_set_layout_compatibility(my_data, my_data->setMap[pCB->boundDescriptorSets[setIndex]], pPipe->graphicsPipelineCI.layout, setIndex, errorString)) {
1259 // Set is bound but not compatible w/ overlapping pipelineLayout from PSO
1260 VkDescriptorSet setHandle = my_data->setMap[pCB->boundDescriptorSets[setIndex]]->set;
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001261 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",
Mark Lobodzinski74e84692015-12-14 15:14:10 -07001262 "VkDescriptorSet (%#" PRIxLEAST64 ") bound as set #%u is not compatible with overlapping VkPipelineLayout %#" PRIxLEAST64 " due to: %s",
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001263 (uint64_t)setHandle, setIndex, (uint64_t)pPipe->graphicsPipelineCI.layout, errorString.c_str());
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07001264 }
1265 }
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06001266 }
Mark Lobodzinski74e84692015-12-14 15:14:10 -07001267
Tobin Ehlisd28acef2015-09-09 15:12:35 -06001268 // Verify Vtx binding
Mark Lobodzinski74e84692015-12-14 15:14:10 -07001269 if (pPipe->vtxBindingCount > 0) {
1270 VkPipelineVertexInputStateCreateInfo *vtxInCI = &pPipe->vertexInputCI;
Courtney Goeltzenleuchter740451a2015-12-16 16:06:06 -07001271 for (uint32_t i = 0; i < vtxInCI->vertexBindingDescriptionCount; i++) {
Mark Lobodzinski74e84692015-12-14 15:14:10 -07001272 if ((pCB->boundVtxBuffers.size() < (i+1)) || (pCB->boundVtxBuffers[i] == VK_NULL_HANDLE)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001273 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS",
Mark Lobodzinski74e84692015-12-14 15:14:10 -07001274 "The Pipeline State Object (%#" PRIxLEAST64 ") expects that this Command Buffer's vertex binding Index %d should be set via vkCmdBindVertexBuffers.",
1275 (uint64_t)pCB->lastBoundPipeline, i);
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001276
Tobin Ehlisd28acef2015-09-09 15:12:35 -06001277 }
1278 }
Mark Lobodzinski74e84692015-12-14 15:14:10 -07001279 } else {
1280 if (!pCB->boundVtxBuffers.empty()) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001281 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS,
Mark Lobodzinski74e84692015-12-14 15:14:10 -07001282 "DS", "Vertex buffers are bound to command buffer (%#" PRIxLEAST64 ") but no vertex buffers are attached to this Pipeline State Object (%#" PRIxLEAST64 ").",
1283 (uint64_t)pCB->commandBuffer, (uint64_t)pCB->lastBoundPipeline);
1284 }
Tobin Ehlisd28acef2015-09-09 15:12:35 -06001285 }
Mark Lobodzinski74e84692015-12-14 15:14:10 -07001286
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06001287 // If Viewport or scissors are dynamic, verify that dynamic count matches PSO count
1288 VkBool32 dynViewport = isDynamic(pPipe, VK_DYNAMIC_STATE_VIEWPORT);
1289 VkBool32 dynScissor = isDynamic(pPipe, VK_DYNAMIC_STATE_SCISSOR);
1290 if (dynViewport) {
1291 if (pCB->viewports.size() != pPipe->graphicsPipelineCI.pViewportState->viewportCount) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001292 result |= 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 -07001293 "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);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06001294 }
1295 }
1296 if (dynScissor) {
1297 if (pCB->scissors.size() != pPipe->graphicsPipelineCI.pViewportState->scissorCount) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001298 result |= 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 -07001299 "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);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06001300 }
1301 }
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06001302 return result;
1303}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001304
Tobin Ehlisde63c532015-06-18 15:59:33 -06001305// Verify that create state for a pipeline is valid
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07001306static VkBool32 verifyPipelineCreateState(layer_data* my_data, const VkDevice device, PIPELINE_NODE* pPipeline)
Tobin Ehlisde63c532015-06-18 15:59:33 -06001307{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001308 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski312274f2015-12-16 14:25:22 -07001309
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07001310 if (!validate_pipeline_shaders(my_data, device, pPipeline)) {
Tobin Ehlisad61de42015-12-02 13:53:34 -07001311 skipCall = VK_TRUE;
1312 }
Mark Lobodzinski312274f2015-12-16 14:25:22 -07001313
Tobin Ehlisde63c532015-06-18 15:59:33 -06001314 // VS is required
1315 if (!(pPipeline->active_shaders & VK_SHADER_STAGE_VERTEX_BIT)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001316 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 -06001317 "Invalid Pipeline CreateInfo State: Vtx Shader required");
Tobin Ehlisde63c532015-06-18 15:59:33 -06001318 }
1319 // Either both or neither TC/TE shaders should be defined
Courtney Goeltzenleuchterc6fd2262015-10-15 17:35:38 -06001320 if (((pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) == 0) !=
1321 ((pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) == 0) ) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001322 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 -06001323 "Invalid Pipeline CreateInfo State: TE and TC shaders must be included or excluded as a pair");
Tobin Ehlisde63c532015-06-18 15:59:33 -06001324 }
1325 // Compute shaders should be specified independent of Gfx shaders
1326 if ((pPipeline->active_shaders & VK_SHADER_STAGE_COMPUTE_BIT) &&
Courtney Goeltzenleuchterc6fd2262015-10-15 17:35:38 -06001327 (pPipeline->active_shaders & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT |
1328 VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT | VK_SHADER_STAGE_GEOMETRY_BIT |
Tobin Ehlisde63c532015-06-18 15:59:33 -06001329 VK_SHADER_STAGE_FRAGMENT_BIT))) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001330 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 -06001331 "Invalid Pipeline CreateInfo State: Do not specify Compute Shader for Gfx Pipeline");
Tobin Ehlisde63c532015-06-18 15:59:33 -06001332 }
Chia-I Wu99ba2bb2015-10-31 00:31:16 +08001333 // VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology is only valid for tessellation pipelines.
Tobin Ehlisde63c532015-06-18 15:59:33 -06001334 // Mismatching primitive topology and tessellation fails graphics pipeline creation.
Courtney Goeltzenleuchterc6fd2262015-10-15 17:35:38 -06001335 if (pPipeline->active_shaders & (VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) &&
Chia-I Wu99ba2bb2015-10-31 00:31:16 +08001336 (pPipeline->iaStateCI.topology != VK_PRIMITIVE_TOPOLOGY_PATCH_LIST)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001337 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 +08001338 "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 -06001339 }
Chia-I Wu99ba2bb2015-10-31 00:31:16 +08001340 if (pPipeline->iaStateCI.topology == VK_PRIMITIVE_TOPOLOGY_PATCH_LIST) {
Courtney Goeltzenleuchterc6fd2262015-10-15 17:35:38 -06001341 if (~pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001342 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 +08001343 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology is only valid for tessellation pipelines");
Tobin Ehlis20693172015-09-17 08:46:18 -06001344 }
1345 if (!pPipeline->tessStateCI.patchControlPoints || (pPipeline->tessStateCI.patchControlPoints > 32)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001346 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 +08001347 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology used with patchControlPoints value %u."
Tobin Ehlis20693172015-09-17 08:46:18 -06001348 " patchControlPoints should be >0 and <=32.", pPipeline->tessStateCI.patchControlPoints);
1349 }
Tobin Ehlisde63c532015-06-18 15:59:33 -06001350 }
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06001351 // Viewport state must be included and viewport and scissor counts should always match
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001352 // NOTE : Even if these are flagged as dynamic, counts need to be set correctly for shader compiler
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06001353 if (!pPipeline->graphicsPipelineCI.pViewportState) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001354 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 -06001355 "Gfx Pipeline pViewportState is null. Even if viewport and scissors are dynamic PSO must include viewportCount and scissorCount in pViewportState.");
1356 } else if (pPipeline->graphicsPipelineCI.pViewportState->scissorCount != pPipeline->graphicsPipelineCI.pViewportState->viewportCount) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001357 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 -06001358 "Gfx Pipeline viewport count (%u) must match scissor count (%u).", pPipeline->vpStateCI.viewportCount, pPipeline->vpStateCI.scissorCount);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06001359 } else {
1360 // If viewport or scissor are not dynamic, then verify that data is appropriate for count
1361 VkBool32 dynViewport = isDynamic(pPipeline, VK_DYNAMIC_STATE_VIEWPORT);
1362 VkBool32 dynScissor = isDynamic(pPipeline, VK_DYNAMIC_STATE_SCISSOR);
1363 if (!dynViewport) {
1364 if (pPipeline->graphicsPipelineCI.pViewportState->viewportCount && !pPipeline->graphicsPipelineCI.pViewportState->pViewports) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001365 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 -07001366 "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 -06001367 }
1368 }
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06001369 if (!dynScissor) {
1370 if (pPipeline->graphicsPipelineCI.pViewportState->scissorCount && !pPipeline->graphicsPipelineCI.pViewportState->pScissors) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001371 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 -07001372 "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 -06001373 }
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001374 }
1375 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001376 return skipCall;
Tobin Ehlisde63c532015-06-18 15:59:33 -06001377}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001378
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001379// Init the pipeline mapping info based on pipeline create info LL tree
1380// Threading note : Calls to this function should wrapped in mutex
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07001381// TODO : this should really just be in the constructor for PIPELINE_NODE
Mark Lobodzinski2adea752015-11-10 15:25:01 -07001382static PIPELINE_NODE* initGraphicsPipeline(layer_data* dev_data, const VkGraphicsPipelineCreateInfo* pCreateInfo, PIPELINE_NODE* pBasePipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001383{
Tobin Ehlisde63c532015-06-18 15:59:33 -06001384 PIPELINE_NODE* pPipeline = new PIPELINE_NODE;
Mark Lobodzinskie443d2b2015-12-11 11:56:07 -07001385
Tobin Ehlisde63c532015-06-18 15:59:33 -06001386 if (pBasePipeline) {
Mark Lobodzinskie443d2b2015-12-11 11:56:07 -07001387 *pPipeline = *pBasePipeline;
Tobin Ehlisde63c532015-06-18 15:59:33 -06001388 }
Mark Lobodzinskie443d2b2015-12-11 11:56:07 -07001389
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001390 // First init create info
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001391 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001392
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001393 size_t bufferSize = 0;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001394 const VkPipelineVertexInputStateCreateInfo* pVICI = NULL;
Tobin Ehlis59db5712015-07-13 13:14:24 -06001395 const VkPipelineColorBlendStateCreateInfo* pCBCI = NULL;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001396
1397 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
1398 const VkPipelineShaderStageCreateInfo *pPSSCI = &pCreateInfo->pStages[i];
1399
Chia-I Wu062ad152015-10-31 00:31:16 +08001400 switch (pPSSCI->stage) {
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001401 case VK_SHADER_STAGE_VERTEX_BIT:
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001402 memcpy(&pPipeline->vsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1403 pPipeline->active_shaders |= VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001404 break;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001405 case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT:
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001406 memcpy(&pPipeline->tcsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Courtney Goeltzenleuchterc6fd2262015-10-15 17:35:38 -06001407 pPipeline->active_shaders |= VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001408 break;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001409 case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT:
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001410 memcpy(&pPipeline->tesCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Courtney Goeltzenleuchterc6fd2262015-10-15 17:35:38 -06001411 pPipeline->active_shaders |= VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001412 break;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001413 case VK_SHADER_STAGE_GEOMETRY_BIT:
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001414 memcpy(&pPipeline->gsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1415 pPipeline->active_shaders |= VK_SHADER_STAGE_GEOMETRY_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001416 break;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001417 case VK_SHADER_STAGE_FRAGMENT_BIT:
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001418 memcpy(&pPipeline->fsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1419 pPipeline->active_shaders |= VK_SHADER_STAGE_FRAGMENT_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001420 break;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001421 case VK_SHADER_STAGE_COMPUTE_BIT:
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001422 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
1423 pPipeline->active_shaders |= VK_SHADER_STAGE_COMPUTE_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001424 break;
1425 default:
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001426 // TODO : Flag error
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001427 break;
1428 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001429 }
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001430 // Copy over GraphicsPipelineCreateInfo structure embedded pointers
1431 if (pCreateInfo->stageCount != 0) {
1432 pPipeline->graphicsPipelineCI.pStages = new VkPipelineShaderStageCreateInfo[pCreateInfo->stageCount];
1433 bufferSize = pCreateInfo->stageCount * sizeof(VkPipelineShaderStageCreateInfo);
1434 memcpy((void*)pPipeline->graphicsPipelineCI.pStages, pCreateInfo->pStages, bufferSize);
1435 }
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001436 if (pCreateInfo->pVertexInputState != NULL) {
1437 memcpy((void*)&pPipeline->vertexInputCI, pCreateInfo->pVertexInputState , sizeof(VkPipelineVertexInputStateCreateInfo));
1438 // Copy embedded ptrs
1439 pVICI = pCreateInfo->pVertexInputState;
Chia-I Wu763a7492015-10-26 20:48:51 +08001440 pPipeline->vtxBindingCount = pVICI->vertexBindingDescriptionCount;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001441 if (pPipeline->vtxBindingCount) {
1442 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
1443 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
1444 memcpy((void*)pPipeline->pVertexBindingDescriptions, pVICI->pVertexBindingDescriptions, bufferSize);
1445 }
Chia-I Wu763a7492015-10-26 20:48:51 +08001446 pPipeline->vtxAttributeCount = pVICI->vertexAttributeDescriptionCount;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001447 if (pPipeline->vtxAttributeCount) {
1448 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
1449 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
1450 memcpy((void*)pPipeline->pVertexAttributeDescriptions, pVICI->pVertexAttributeDescriptions, bufferSize);
1451 }
1452 pPipeline->graphicsPipelineCI.pVertexInputState = &pPipeline->vertexInputCI;
1453 }
Tony Barboure307f582015-07-10 15:29:03 -06001454 if (pCreateInfo->pInputAssemblyState != NULL) {
1455 memcpy((void*)&pPipeline->iaStateCI, pCreateInfo->pInputAssemblyState, sizeof(VkPipelineInputAssemblyStateCreateInfo));
1456 pPipeline->graphicsPipelineCI.pInputAssemblyState = &pPipeline->iaStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001457 }
Tony Barboure307f582015-07-10 15:29:03 -06001458 if (pCreateInfo->pTessellationState != NULL) {
1459 memcpy((void*)&pPipeline->tessStateCI, pCreateInfo->pTessellationState, sizeof(VkPipelineTessellationStateCreateInfo));
1460 pPipeline->graphicsPipelineCI.pTessellationState = &pPipeline->tessStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001461 }
Tony Barboure307f582015-07-10 15:29:03 -06001462 if (pCreateInfo->pViewportState != NULL) {
1463 memcpy((void*)&pPipeline->vpStateCI, pCreateInfo->pViewportState, sizeof(VkPipelineViewportStateCreateInfo));
1464 pPipeline->graphicsPipelineCI.pViewportState = &pPipeline->vpStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001465 }
Chia-I Wu1f851912015-10-27 18:04:07 +08001466 if (pCreateInfo->pRasterizationState != NULL) {
1467 memcpy((void*)&pPipeline->rsStateCI, pCreateInfo->pRasterizationState, sizeof(VkPipelineRasterizationStateCreateInfo));
1468 pPipeline->graphicsPipelineCI.pRasterizationState = &pPipeline->rsStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001469 }
Tony Barboure307f582015-07-10 15:29:03 -06001470 if (pCreateInfo->pMultisampleState != NULL) {
1471 memcpy((void*)&pPipeline->msStateCI, pCreateInfo->pMultisampleState, sizeof(VkPipelineMultisampleStateCreateInfo));
1472 pPipeline->graphicsPipelineCI.pMultisampleState = &pPipeline->msStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001473 }
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001474 if (pCreateInfo->pDepthStencilState != NULL) {
1475 memcpy((void*)&pPipeline->dsStateCI, pCreateInfo->pDepthStencilState, sizeof(VkPipelineDepthStencilStateCreateInfo));
1476 pPipeline->graphicsPipelineCI.pDepthStencilState = &pPipeline->dsStateCI;
1477 }
Tony Barboure307f582015-07-10 15:29:03 -06001478 if (pCreateInfo->pColorBlendState != NULL) {
1479 memcpy((void*)&pPipeline->cbStateCI, pCreateInfo->pColorBlendState, sizeof(VkPipelineColorBlendStateCreateInfo));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001480 // Copy embedded ptrs
Tony Barboure307f582015-07-10 15:29:03 -06001481 pCBCI = pCreateInfo->pColorBlendState;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001482 pPipeline->attachmentCount = pCBCI->attachmentCount;
1483 if (pPipeline->attachmentCount) {
Tony Barboure307f582015-07-10 15:29:03 -06001484 pPipeline->pAttachments = new VkPipelineColorBlendAttachmentState[pPipeline->attachmentCount];
1485 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineColorBlendAttachmentState);
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001486 memcpy((void*)pPipeline->pAttachments, pCBCI->pAttachments, bufferSize);
1487 }
Tony Barboure307f582015-07-10 15:29:03 -06001488 pPipeline->graphicsPipelineCI.pColorBlendState = &pPipeline->cbStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001489 }
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001490 if (pCreateInfo->pDynamicState != NULL) {
1491 memcpy((void*)&pPipeline->dynStateCI, pCreateInfo->pDynamicState, sizeof(VkPipelineDynamicStateCreateInfo));
1492 if (pPipeline->dynStateCI.dynamicStateCount) {
1493 pPipeline->dynStateCI.pDynamicStates = new VkDynamicState[pPipeline->dynStateCI.dynamicStateCount];
1494 bufferSize = pPipeline->dynStateCI.dynamicStateCount * sizeof(VkDynamicState);
1495 memcpy((void*)pPipeline->dynStateCI.pDynamicStates, pCreateInfo->pDynamicState->pDynamicStates, bufferSize);
1496 }
1497 pPipeline->graphicsPipelineCI.pDynamicState = &pPipeline->dynStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001498 }
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07001499 pPipeline->active_sets.clear();
Tobin Ehlisde63c532015-06-18 15:59:33 -06001500 return pPipeline;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001501}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001502
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001503// Free the Pipeline nodes
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06001504static void deletePipelines(layer_data* my_data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001505{
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06001506 if (my_data->pipelineMap.size() <= 0)
David Pinedof5997ab2015-04-27 16:36:17 -06001507 return;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06001508 for (auto ii=my_data->pipelineMap.begin(); ii!=my_data->pipelineMap.end(); ++ii) {
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001509 if ((*ii).second->graphicsPipelineCI.stageCount != 0) {
1510 delete[] (*ii).second->graphicsPipelineCI.pStages;
1511 }
Tobin Ehliscd3109e2015-04-01 11:59:08 -06001512 if ((*ii).second->pVertexBindingDescriptions) {
1513 delete[] (*ii).second->pVertexBindingDescriptions;
1514 }
1515 if ((*ii).second->pVertexAttributeDescriptions) {
1516 delete[] (*ii).second->pVertexAttributeDescriptions;
1517 }
1518 if ((*ii).second->pAttachments) {
1519 delete[] (*ii).second->pAttachments;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001520 }
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001521 if ((*ii).second->dynStateCI.dynamicStateCount != 0) {
1522 delete[] (*ii).second->dynStateCI.pDynamicStates;
1523 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001524 delete (*ii).second;
1525 }
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06001526 my_data->pipelineMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001527}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001528
Tobin Ehlis2464b882015-04-01 08:40:34 -06001529// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001530static VkSampleCountFlagBits getNumSamples(layer_data* my_data, const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -06001531{
Chia-I Wue420a332015-10-26 20:04:44 +08001532 PIPELINE_NODE* pPipe = my_data->pipelineMap[pipeline];
Tobin Ehlisb3a506f2015-07-13 14:51:15 -06001533 if (VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
Chia-I Wu1f851912015-10-27 18:04:07 +08001534 return pPipe->msStateCI.rasterizationSamples;
Tobin Ehlisb3a506f2015-07-13 14:51:15 -06001535 }
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001536 return VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis2464b882015-04-01 08:40:34 -06001537}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001538
Tobin Ehlis2464b882015-04-01 08:40:34 -06001539// Validate state related to the PSO
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06001540static VkBool32 validatePipelineState(layer_data* my_data, const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -06001541{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001542 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06001543 // Verify that any MSAA request in PSO matches sample# in bound FB
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001544 VkSampleCountFlagBits psoNumSamples = getNumSamples(my_data, pipeline);
Tobin Ehlis2464b882015-04-01 08:40:34 -06001545 if (pCB->activeRenderPass) {
Tobin Ehlisad61de42015-12-02 13:53:34 -07001546 const VkRenderPassCreateInfo* pRPCI = my_data->renderPassMap[pCB->activeRenderPass]->pCreateInfo;
Chia-I Wuc278df82015-07-07 11:50:03 +08001547 const VkSubpassDescription* pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001548 VkSampleCountFlagBits subpassNumSamples = (VkSampleCountFlagBits) 0;
Chia-I Wuc278df82015-07-07 11:50:03 +08001549 uint32_t i;
1550
Chia-I Wu763a7492015-10-26 20:48:51 +08001551 for (i = 0; i < pSD->colorAttachmentCount; i++) {
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001552 VkSampleCountFlagBits samples;
Chia-I Wuc278df82015-07-07 11:50:03 +08001553
Cody Northrop6de6b0b2015-08-04 11:16:41 -06001554 if (pSD->pColorAttachments[i].attachment == VK_ATTACHMENT_UNUSED)
Chia-I Wuc278df82015-07-07 11:50:03 +08001555 continue;
1556
Cody Northrop6de6b0b2015-08-04 11:16:41 -06001557 samples = pRPCI->pAttachments[pSD->pColorAttachments[i].attachment].samples;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001558 if (subpassNumSamples == (VkSampleCountFlagBits) 0) {
Chia-I Wuc278df82015-07-07 11:50:03 +08001559 subpassNumSamples = samples;
1560 } else if (subpassNumSamples != samples) {
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001561 subpassNumSamples = (VkSampleCountFlagBits) -1;
Chia-I Wuc278df82015-07-07 11:50:03 +08001562 break;
1563 }
1564 }
Chia-I Wuce532f72015-10-26 17:32:47 +08001565 if (pSD->pDepthStencilAttachment && pSD->pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001566 const VkSampleCountFlagBits samples = pRPCI->pAttachments[pSD->pDepthStencilAttachment->attachment].samples;
1567 if (subpassNumSamples == (VkSampleCountFlagBits) 0)
Chia-I Wuc278df82015-07-07 11:50:03 +08001568 subpassNumSamples = samples;
1569 else if (subpassNumSamples != samples)
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001570 subpassNumSamples = (VkSampleCountFlagBits) -1;
Chia-I Wuc278df82015-07-07 11:50:03 +08001571 }
1572
1573 if (psoNumSamples != subpassNumSamples) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001574 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 -06001575 "Num samples mismatch! Binding PSO (%#" PRIxLEAST64 ") with %u samples while current RenderPass (%#" PRIxLEAST64 ") w/ %u samples!",
Chia-I Wue420a332015-10-26 20:04:44 +08001576 (uint64_t) pipeline, psoNumSamples, (uint64_t) pCB->activeRenderPass, subpassNumSamples);
Tobin Ehlis2464b882015-04-01 08:40:34 -06001577 }
1578 } else {
1579 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
1580 // Verify and flag error as appropriate
1581 }
1582 // TODO : Add more checks here
1583 } else {
1584 // TODO : Validate non-gfx pipeline updates
1585 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001586 return VK_FALSE;
Tobin Ehlis2464b882015-04-01 08:40:34 -06001587}
1588
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001589// Block of code at start here specifically for managing/tracking DSs
1590
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001591// Return Pool node ptr for specified pool or else NULL
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07001592static DESCRIPTOR_POOL_NODE* getPoolNode(layer_data* my_data, const VkDescriptorPool pool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001593{
1594 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07001595 if (my_data->descriptorPoolMap.find(pool) == my_data->descriptorPoolMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001596 loader_platform_thread_unlock_mutex(&globalLock);
1597 return NULL;
1598 }
1599 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07001600 return my_data->descriptorPoolMap[pool];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001601}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001602
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001603// Return Set node ptr for specified set or else NULL
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06001604static SET_NODE* getSetNode(layer_data* my_data, const VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001605{
1606 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue420a332015-10-26 20:04:44 +08001607 if (my_data->setMap.find(set) == my_data->setMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001608 loader_platform_thread_unlock_mutex(&globalLock);
1609 return NULL;
1610 }
1611 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wue420a332015-10-26 20:04:44 +08001612 return my_data->setMap[set];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001613}
1614
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06001615static LAYOUT_NODE* getLayoutNode(layer_data* my_data, const VkDescriptorSetLayout layout) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001616 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisad61de42015-12-02 13:53:34 -07001617 if (my_data->descriptorSetLayoutMap.find(layout) == my_data->descriptorSetLayoutMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001618 loader_platform_thread_unlock_mutex(&globalLock);
1619 return NULL;
1620 }
1621 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisad61de42015-12-02 13:53:34 -07001622 return my_data->descriptorSetLayoutMap[layout];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001623}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001624
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001625// 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 -06001626static VkBool32 validUpdateStruct(layer_data* my_data, const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001627{
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001628 switch (pUpdateStruct->sType)
1629 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001630 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1631 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001632 return VK_FALSE;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001633 default:
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001634 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 -06001635 "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 -06001636 }
1637}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001638
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001639// Set count for given update struct in the last parameter
Courtney Goeltzenleuchter5bc11202015-12-16 16:08:44 -07001640// 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 -06001641static uint32_t getUpdateCount(layer_data* my_data, const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001642{
1643 switch (pUpdateStruct->sType)
1644 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001645 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
Chia-I Wu763a7492015-10-26 20:48:51 +08001646 return ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorCount;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001647 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001648 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wu763a7492015-10-26 20:48:51 +08001649 return ((VkCopyDescriptorSet*)pUpdateStruct)->descriptorCount;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001650 }
Courtney Goeltzenleuchter902a0862015-12-16 16:08:08 -07001651
1652 return 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001653}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001654
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001655// For given Layout Node and binding, return index where that binding begins
1656static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
1657{
1658 uint32_t offsetIndex = 0;
Chia-I Wub5689ee2015-10-31 00:31:16 +08001659 for (uint32_t i = 0; i < pLayout->createInfo.bindingCount; i++) {
1660 if (pLayout->createInfo.pBinding[i].binding == binding)
1661 break;
Chia-I Wu045654f2015-11-06 06:42:02 +08001662 offsetIndex += pLayout->createInfo.pBinding[i].descriptorCount;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001663 }
1664 return offsetIndex;
1665}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001666
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001667// For given layout node and binding, return last index that is updated
1668static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
1669{
1670 uint32_t offsetIndex = 0;
Chia-I Wub5689ee2015-10-31 00:31:16 +08001671 for (uint32_t i = 0; i < pLayout->createInfo.bindingCount; i++) {
Chia-I Wu045654f2015-11-06 06:42:02 +08001672 offsetIndex += pLayout->createInfo.pBinding[i].descriptorCount;
Chia-I Wub5689ee2015-10-31 00:31:16 +08001673 if (pLayout->createInfo.pBinding[i].binding == binding)
1674 break;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001675 }
1676 return offsetIndex-1;
1677}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001678
Tobin Ehlise66ec962015-10-27 12:54:50 -06001679// For given layout and update, return the first overall index of the layout that is updated
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06001680static 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 -06001681{
Tobin Ehlise66ec962015-10-27 12:54:50 -06001682 return getBindingStartIndex(pLayout, binding)+arrayIndex;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001683}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001684
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06001685// For given layout and update, return the last overall index of the layout that is updated
1686static 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 -06001687{
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06001688 uint32_t count = getUpdateCount(my_data, device, pUpdateStruct);
Tobin Ehlise66ec962015-10-27 12:54:50 -06001689 return getBindingStartIndex(pLayout, binding)+arrayIndex+count-1;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001690}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001691
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001692// Verify that the descriptor type in the update struct matches what's expected by the layout
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001693static 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 -06001694{
1695 // First get actual type of update
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001696 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001697 VkDescriptorType actualType;
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001698 uint32_t i = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001699 switch (pUpdateStruct->sType)
1700 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001701 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1702 actualType = ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001703 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001704 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
1705 /* no need to validate */
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001706 return VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001707 break;
1708 default:
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001709 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 -06001710 "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 -06001711 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001712 if (VK_FALSE == skipCall) {
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001713 // Set first stageFlags as reference and verify that all other updates match it
1714 VkShaderStageFlags refStageFlags = pLayout->stageFlags[startIndex];
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001715 for (i = startIndex; i <= endIndex; i++) {
Tobin Ehlis91423d22015-10-20 10:11:55 -06001716 if (pLayout->descriptorTypes[i] != actualType) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001717 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 -06001718 "Write descriptor update has descriptor type %s that does not match overlapping binding descriptor type of %s!",
1719 string_VkDescriptorType(actualType), string_VkDescriptorType(pLayout->descriptorTypes[i]));
1720 }
1721 if (pLayout->stageFlags[i] != refStageFlags) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001722 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 -06001723 "Write descriptor update has stageFlags %x that do not match overlapping binding descriptor stageFlags of %x!",
1724 refStageFlags, pLayout->stageFlags[i]);
Tobin Ehlis3b341092015-09-30 08:30:20 -06001725 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001726 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001727 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001728 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001729}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001730
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001731// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001732// struct into the pNewNode param. Return VK_TRUE if error condition encountered and callback signals early exit.
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001733// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlis42d440c2015-10-20 17:06:16 -06001734static VkBool32 shadowUpdateNode(layer_data* my_data, const VkDevice device, GENERIC_HEADER* pUpdate, GENERIC_HEADER** pNewNode)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001735{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001736 VkBool32 skipCall = VK_FALSE;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001737 VkWriteDescriptorSet* pWDS = NULL;
1738 VkCopyDescriptorSet* pCDS = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001739 size_t array_size = 0;
1740 size_t base_array_size = 0;
1741 size_t total_array_size = 0;
1742 size_t baseBuffAddr = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001743 switch (pUpdate->sType)
1744 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001745 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1746 pWDS = new VkWriteDescriptorSet;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001747 *pNewNode = (GENERIC_HEADER*)pWDS;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001748 memcpy(pWDS, pUpdate, sizeof(VkWriteDescriptorSet));
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06001749
1750 switch (pWDS->descriptorType) {
1751 case VK_DESCRIPTOR_TYPE_SAMPLER:
1752 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
1753 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
1754 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
1755 {
Chia-I Wu763a7492015-10-26 20:48:51 +08001756 VkDescriptorImageInfo *info = new VkDescriptorImageInfo[pWDS->descriptorCount];
1757 memcpy(info, pWDS->pImageInfo, pWDS->descriptorCount * sizeof(VkDescriptorImageInfo));
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06001758 pWDS->pImageInfo = info;
Tobin Ehliscb085292015-12-01 09:57:09 -07001759 }
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06001760 break;
1761 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
1762 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
1763 {
Chia-I Wu763a7492015-10-26 20:48:51 +08001764 VkBufferView *info = new VkBufferView[pWDS->descriptorCount];
1765 memcpy(info, pWDS->pTexelBufferView, pWDS->descriptorCount * sizeof(VkBufferView));
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06001766 pWDS->pTexelBufferView = info;
1767 }
1768 break;
1769 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
1770 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
1771 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
1772 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
1773 {
Chia-I Wu763a7492015-10-26 20:48:51 +08001774 VkDescriptorBufferInfo *info = new VkDescriptorBufferInfo[pWDS->descriptorCount];
1775 memcpy(info, pWDS->pBufferInfo, pWDS->descriptorCount * sizeof(VkDescriptorBufferInfo));
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06001776 pWDS->pBufferInfo = info;
1777 }
1778 break;
1779 default:
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07001780 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06001781 break;
1782 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001783 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001784 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
1785 pCDS = new VkCopyDescriptorSet;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001786 *pNewNode = (GENERIC_HEADER*)pCDS;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001787 memcpy(pCDS, pUpdate, sizeof(VkCopyDescriptorSet));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001788 break;
1789 default:
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001790 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 -06001791 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdate->sType), pUpdate->sType))
1792 return VK_TRUE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001793 }
1794 // Make sure that pNext for the end of shadow copy is NULL
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001795 (*pNewNode)->pNext = NULL;
1796 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001797}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001798
Tobin Ehlisb46be812015-10-23 16:00:08 -06001799// Verify that given sampler is valid
1800static VkBool32 validateSampler(const layer_data* my_data, const VkSampler* pSampler, const VkBool32 immutable)
1801{
1802 VkBool32 skipCall = VK_FALSE;
Chia-I Wue420a332015-10-26 20:04:44 +08001803 auto sampIt = my_data->sampleMap.find(*pSampler);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001804 if (sampIt == my_data->sampleMap.end()) {
1805 if (!immutable) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001806 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 +08001807 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid sampler %#" PRIxLEAST64, (uint64_t) *pSampler);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001808 } else { // immutable
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001809 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 +08001810 "vkUpdateDescriptorSets: Attempt to update descriptor whose binding has an invalid immutable sampler %#" PRIxLEAST64, (uint64_t) *pSampler);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001811 }
1812 } else {
1813 // TODO : Any further checks we want to do on the sampler?
1814 }
1815 return skipCall;
1816}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001817
Tobin Ehlisb46be812015-10-23 16:00:08 -06001818// Verify that given imageView is valid
1819static VkBool32 validateImageView(const layer_data* my_data, const VkImageView* pImageView, const VkImageLayout imageLayout)
1820{
1821 VkBool32 skipCall = VK_FALSE;
Chia-I Wue420a332015-10-26 20:04:44 +08001822 auto ivIt = my_data->imageViewMap.find(*pImageView);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001823 if (ivIt == my_data->imageViewMap.end()) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001824 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 +08001825 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid imageView %#" PRIxLEAST64, (uint64_t) *pImageView);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001826 } else {
1827 // Validate that imageLayout is compatible with aspectMask and image format
1828 VkImageAspectFlags aspectMask = ivIt->second->subresourceRange.aspectMask;
Chia-I Wue420a332015-10-26 20:04:44 +08001829 VkImage image = ivIt->second->image;
Michael Lentineee4ad4d2015-10-23 12:41:44 -07001830 // TODO : Check here in case we have a bad image
Chia-I Wue420a332015-10-26 20:04:44 +08001831 auto imgIt = my_data->imageMap.find(image);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001832 if (imgIt == my_data->imageMap.end()) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001833 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 -07001834 "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 -06001835 } else {
1836 VkFormat format = (*imgIt).second->format;
Courtney Goeltzenleuchterf2bca902015-11-03 15:41:43 -07001837 VkBool32 ds = vk_format_is_depth_or_stencil(format);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001838 switch (imageLayout) {
1839 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
1840 // Only Color bit must be set
1841 if ((aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) != VK_IMAGE_ASPECT_COLOR_BIT) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001842 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 -06001843 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 +08001844 " that does not have VK_IMAGE_ASPECT_COLOR_BIT set.", (uint64_t) *pImageView);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001845 }
1846 // format must NOT be DS
1847 if (ds) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001848 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 -06001849 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 +08001850 " 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 -06001851 }
1852 break;
1853 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
1854 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
1855 // Depth or stencil bit must be set, but both must NOT be set
1856 if (aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) {
1857 if (aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) {
1858 // both must NOT be set
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001859 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 -06001860 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with imageView %#" PRIxLEAST64 ""
Chia-I Wue420a332015-10-26 20:04:44 +08001861 " that has both STENCIL and DEPTH aspects set", (uint64_t) *pImageView);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001862 }
1863 } else if (!(aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)) {
1864 // Neither were set
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001865 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 -06001866 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout %s and imageView %#" PRIxLEAST64 ""
Chia-I Wue420a332015-10-26 20:04:44 +08001867 " that does not have STENCIL or DEPTH aspect set.", string_VkImageLayout(imageLayout), (uint64_t) *pImageView);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001868 }
1869 // format must be DS
1870 if (!ds) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001871 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 -06001872 DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout %s and imageView %#" PRIxLEAST64 ""
Chia-I Wue420a332015-10-26 20:04:44 +08001873 " 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 -06001874 }
1875 break;
1876 default:
1877 // anything to check for other layouts?
1878 break;
1879 }
1880 }
1881 }
1882 return skipCall;
1883}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001884
Tobin Ehlisb46be812015-10-23 16:00:08 -06001885// Verify that given bufferView is valid
1886static VkBool32 validateBufferView(const layer_data* my_data, const VkBufferView* pBufferView)
1887{
1888 VkBool32 skipCall = VK_FALSE;
Chia-I Wue420a332015-10-26 20:04:44 +08001889 auto sampIt = my_data->bufferViewMap.find(*pBufferView);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001890 if (sampIt == my_data->bufferViewMap.end()) {
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_BUFFER_VIEW_EXT, (uint64_t) *pBufferView, 0, DRAWSTATE_BUFFERVIEW_DESCRIPTOR_ERROR, "DS",
Chia-I Wue420a332015-10-26 20:04:44 +08001892 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid bufferView %#" PRIxLEAST64, (uint64_t) *pBufferView);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001893 } else {
1894 // TODO : Any further checks we want to do on the bufferView?
1895 }
1896 return skipCall;
1897}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001898
Tobin Ehlisb46be812015-10-23 16:00:08 -06001899// Verify that given bufferInfo is valid
1900static VkBool32 validateBufferInfo(const layer_data* my_data, const VkDescriptorBufferInfo* pBufferInfo)
1901{
1902 VkBool32 skipCall = VK_FALSE;
Chia-I Wue420a332015-10-26 20:04:44 +08001903 auto sampIt = my_data->bufferMap.find(pBufferInfo->buffer);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001904 if (sampIt == my_data->bufferMap.end()) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001905 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 +08001906 "vkUpdateDescriptorSets: Attempt to update descriptor where bufferInfo has invalid buffer %#" PRIxLEAST64, (uint64_t) pBufferInfo->buffer);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001907 } else {
1908 // TODO : Any further checks we want to do on the bufferView?
1909 }
1910 return skipCall;
1911}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001912
Tobin Ehlisb46be812015-10-23 16:00:08 -06001913static VkBool32 validateUpdateContents(const layer_data* my_data, const VkWriteDescriptorSet *pWDS, const VkDescriptorSetLayoutBinding* pLayoutBinding)
1914{
1915 VkBool32 skipCall = VK_FALSE;
1916 // First verify that for the given Descriptor type, the correct DescriptorInfo data is supplied
1917 VkBufferView* pBufferView = NULL;
1918 const VkSampler* pSampler = NULL;
1919 VkImageView* pImageView = NULL;
1920 VkImageLayout* pImageLayout = NULL;
1921 VkDescriptorBufferInfo* pBufferInfo = NULL;
1922 VkBool32 immutable = VK_FALSE;
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001923 uint32_t i = 0;
1924 // For given update type, verify that update contents are correct
1925 switch (pWDS->descriptorType) {
1926 case VK_DESCRIPTOR_TYPE_SAMPLER:
Chia-I Wu763a7492015-10-26 20:48:51 +08001927 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisb46be812015-10-23 16:00:08 -06001928 skipCall |= validateSampler(my_data, &(pWDS->pImageInfo[i].sampler), immutable);
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001929 }
1930 break;
1931 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
Chia-I Wu763a7492015-10-26 20:48:51 +08001932 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisb46be812015-10-23 16:00:08 -06001933 if (NULL == pLayoutBinding->pImmutableSamplers) {
1934 pSampler = &(pWDS->pImageInfo[i].sampler);
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001935 if (immutable) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001936 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 -06001937 "vkUpdateDescriptorSets: Update #%u is not an immutable sampler %#" PRIxLEAST64 ", but previous update(s) from this "
1938 "VkWriteDescriptorSet struct used an immutable sampler. All updates from a single struct must either "
Chia-I Wue420a332015-10-26 20:04:44 +08001939 "use immutable or non-immutable samplers.", i, (uint64_t) *pSampler);
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001940 }
Tobin Ehlisb46be812015-10-23 16:00:08 -06001941 } else {
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001942 if (i>0 && !immutable) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001943 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 -06001944 "vkUpdateDescriptorSets: Update #%u is an immutable sampler, but previous update(s) from this "
1945 "VkWriteDescriptorSet struct used a non-immutable sampler. All updates from a single struct must either "
1946 "use immutable or non-immutable samplers.", i);
1947 }
Tobin Ehlisb46be812015-10-23 16:00:08 -06001948 immutable = VK_TRUE;
1949 pSampler = &(pLayoutBinding->pImmutableSamplers[i]);
1950 }
1951 skipCall |= validateSampler(my_data, pSampler, immutable);
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001952 }
1953 // Intentionally fall through here to also validate image stuff
1954 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
1955 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
1956 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
Chia-I Wu763a7492015-10-26 20:48:51 +08001957 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisb46be812015-10-23 16:00:08 -06001958 skipCall |= validateImageView(my_data, &(pWDS->pImageInfo[i].imageView), pWDS->pImageInfo[i].imageLayout);
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001959 }
1960 break;
1961 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
1962 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
Chia-I Wu763a7492015-10-26 20:48:51 +08001963 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisb46be812015-10-23 16:00:08 -06001964 skipCall |= validateBufferView(my_data, &(pWDS->pTexelBufferView[i]));
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001965 }
1966 break;
1967 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
1968 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
1969 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
1970 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
Chia-I Wu763a7492015-10-26 20:48:51 +08001971 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisb46be812015-10-23 16:00:08 -06001972 skipCall |= validateBufferInfo(my_data, &(pWDS->pBufferInfo[i]));
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001973 }
1974 break;
Tobin Ehlisb46be812015-10-23 16:00:08 -06001975 }
1976 return skipCall;
1977}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001978
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001979// update DS mappings based on write and copy update arrays
Chia-I Wu483e7702015-10-26 17:20:32 +08001980static 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 -06001981{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001982 VkBool32 skipCall = VK_FALSE;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001983
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001984 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001985 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001986 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001987 // Validate Write updates
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06001988 uint32_t i = 0;
Chia-I Wu483e7702015-10-26 17:20:32 +08001989 for (i=0; i < descriptorWriteCount; i++) {
Chia-I Wu1f851912015-10-27 18:04:07 +08001990 VkDescriptorSet ds = pWDS[i].dstSet;
Chia-I Wue420a332015-10-26 20:04:44 +08001991 SET_NODE* pSet = my_data->setMap[ds];
Tobin Ehlisb46be812015-10-23 16:00:08 -06001992 GENERIC_HEADER* pUpdate = (GENERIC_HEADER*) &pWDS[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001993 pLayout = pSet->pLayout;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001994 // First verify valid update struct
Tobin Ehlis42d440c2015-10-20 17:06:16 -06001995 if ((skipCall = validUpdateStruct(my_data, device, pUpdate)) == VK_TRUE) {
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001996 break;
1997 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001998 uint32_t binding = 0, endIndex = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08001999 binding = pWDS[i].dstBinding;
Tobin Ehlis68fbd442015-10-27 12:25:35 -06002000 // Make sure that layout being updated has the binding being updated
Chia-I Wub5689ee2015-10-31 00:31:16 +08002001 if (pLayout->bindings.find(binding) == pLayout->bindings.end()) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002002 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 -08002003 "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 -06002004 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002005 // Next verify that update falls within size of given binding
Chia-I Wu1f851912015-10-27 18:04:07 +08002006 endIndex = getUpdateEndIndex(my_data, device, pLayout, binding, pWDS[i].dstArrayElement, pUpdate);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002007 if (getBindingEndIndex(pLayout, binding) < endIndex) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002008 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002009 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002010 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 -06002011 "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 -06002012 } else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlis68fbd442015-10-27 12:25:35 -06002013 uint32_t startIndex;
Chia-I Wu1f851912015-10-27 18:04:07 +08002014 startIndex = getUpdateStartIndex(my_data, device, pLayout, binding, pWDS[i].dstArrayElement, pUpdate);
Tobin Ehlis68fbd442015-10-27 12:25:35 -06002015 // Layout bindings match w/ update, now verify that update type & stageFlags are the same for entire update
2016 if ((skipCall = validateUpdateConsistency(my_data, device, pLayout, pUpdate, startIndex, endIndex)) == VK_FALSE) {
2017 // 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 +08002018 if ((skipCall = validateUpdateContents(my_data, &pWDS[i], &pLayout->createInfo.pBinding[binding])) == VK_FALSE) {
Tobin Ehlisb46be812015-10-23 16:00:08 -06002019 // Update is good. Save the update info
2020 // Create new update struct for this set's shadow copy
2021 GENERIC_HEADER* pNewNode = NULL;
2022 skipCall |= shadowUpdateNode(my_data, device, pUpdate, &pNewNode);
2023 if (NULL == pNewNode) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002024 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 -06002025 "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
2026 } else {
2027 // Insert shadow node into LL of updates for this set
2028 pNewNode->pNext = pSet->pUpdateStructs;
2029 pSet->pUpdateStructs = pNewNode;
2030 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlisb46be812015-10-23 16:00:08 -06002031 for (uint32_t j = startIndex; j <= endIndex; j++) {
2032 assert(j<pSet->descriptorCount);
2033 pSet->ppDescriptors[j] = pNewNode;
2034 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002035 }
2036 }
2037 }
2038 }
2039 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002040 }
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06002041 // Now validate copy updates
Chia-I Wu483e7702015-10-26 17:20:32 +08002042 for (i=0; i < descriptorCopyCount; ++i) {
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06002043 SET_NODE *pSrcSet = NULL, *pDstSet = NULL;
2044 LAYOUT_NODE *pSrcLayout = NULL, *pDstLayout = NULL;
2045 uint32_t srcStartIndex = 0, srcEndIndex = 0, dstStartIndex = 0, dstEndIndex = 0;
2046 // For each copy make sure that update falls within given layout and that types match
Chia-I Wue420a332015-10-26 20:04:44 +08002047 pSrcSet = my_data->setMap[pCDS[i].srcSet];
Chia-I Wu1f851912015-10-27 18:04:07 +08002048 pDstSet = my_data->setMap[pCDS[i].dstSet];
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06002049 pSrcLayout = pSrcSet->pLayout;
2050 pDstLayout = pDstSet->pLayout;
2051 // Validate that src binding is valid for src set layout
Chia-I Wub5689ee2015-10-31 00:31:16 +08002052 if (pSrcLayout->bindings.find(pCDS[i].srcBinding) == pSrcLayout->bindings.end()) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002053 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 -06002054 "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 +08002055 i, pCDS[i].srcBinding, (uint64_t) pSrcLayout->layout, pSrcLayout->createInfo.bindingCount-1);
Chia-I Wub5689ee2015-10-31 00:31:16 +08002056 } else if (pDstLayout->bindings.find(pCDS[i].dstBinding) == pDstLayout->bindings.end()) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002057 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 +08002058 "Copy descriptor update %u has dstBinding %u which is out of bounds for underlying SetLayout %#" PRIxLEAST64 " which only has bindings 0-%u.",
2059 i, pCDS[i].dstBinding, (uint64_t) pDstLayout->layout, pDstLayout->createInfo.bindingCount-1);
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06002060 } else {
2061 // Proceed with validation. Bindings are ok, but make sure update is within bounds of given layout
2062 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 +08002063 dstEndIndex = getUpdateEndIndex(my_data, device, pDstLayout, pCDS[i].dstBinding, pCDS[i].dstArrayElement, (const GENERIC_HEADER*)&(pCDS[i]));
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06002064 if (getBindingEndIndex(pSrcLayout, pCDS[i].srcBinding) < srcEndIndex) {
2065 pLayoutCI = &pSrcLayout->createInfo;
2066 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002067 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 -06002068 "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 +08002069 } else if (getBindingEndIndex(pDstLayout, pCDS[i].dstBinding) < dstEndIndex) {
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06002070 pLayoutCI = &pDstLayout->createInfo;
2071 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002072 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 +08002073 "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 -06002074 } else {
2075 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 +08002076 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 +08002077 for (uint32_t j=0; j<pCDS[i].descriptorCount; ++j) {
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06002078 // For copy just make sure that the types match and then perform the update
2079 if (pSrcLayout->descriptorTypes[srcStartIndex+j] != pDstLayout->descriptorTypes[dstStartIndex+j]) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002080 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 -06002081 "Copy descriptor update index %u, update count #%u, has src update descriptor type %s that does not match overlapping dest descriptor type of %s!",
2082 i, j+1, string_VkDescriptorType(pSrcLayout->descriptorTypes[srcStartIndex+j]), string_VkDescriptorType(pDstLayout->descriptorTypes[dstStartIndex+j]));
2083 } else {
2084 // point dst descriptor at corresponding src descriptor
2085 pDstSet->ppDescriptors[j+dstStartIndex] = pSrcSet->ppDescriptors[j+srcStartIndex];
2086 }
2087 }
2088 }
2089 }
2090 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002091 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002092 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002093}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002094
Tobin Ehlisc6457d22015-10-20 16:16:04 -06002095// Verify that given pool has descriptors that are being requested for allocation
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002096static 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 -06002097{
2098 VkBool32 skipCall = VK_FALSE;
2099 uint32_t i = 0, j = 0;
2100 for (i=0; i<count; ++i) {
2101 LAYOUT_NODE* pLayout = getLayoutNode(dev_data, pSetLayouts[i]);
2102 if (NULL == pLayout) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002103 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 +08002104 "Unable to find set layout node for layout %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pSetLayouts[i]);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06002105 } else {
Chia-I Wuc51b1212015-10-27 19:25:11 +08002106 uint32_t typeIndex = 0, poolSizeCount = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08002107 for (j=0; j<pLayout->createInfo.bindingCount; ++j) {
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002108 typeIndex = static_cast<uint32_t>(pLayout->createInfo.pBinding[j].descriptorType);
Chia-I Wu045654f2015-11-06 06:42:02 +08002109 poolSizeCount = pLayout->createInfo.pBinding[j].descriptorCount;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002110 if (poolSizeCount > pPoolNode->availableDescriptorTypeCount[typeIndex]) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002111 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 -06002112 "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 +08002113 poolSizeCount, string_VkDescriptorType(pLayout->createInfo.pBinding[j].descriptorType), (uint64_t) pPoolNode->pool, pPoolNode->availableDescriptorTypeCount[typeIndex]);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06002114 } else { // Decrement available descriptors of this type
Chia-I Wuc51b1212015-10-27 19:25:11 +08002115 pPoolNode->availableDescriptorTypeCount[typeIndex] -= poolSizeCount;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06002116 }
2117 }
2118 }
2119 }
2120 return skipCall;
2121}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002122
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002123// Free the shadowed update node for this Set
2124// NOTE : Calls to this function should be wrapped in mutex
2125static void freeShadowUpdateTree(SET_NODE* pSet)
2126{
2127 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
2128 pSet->pUpdateStructs = NULL;
2129 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
2130 // Clear the descriptor mappings as they will now be invalid
2131 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
2132 while(pShadowUpdate) {
2133 pFreeUpdate = pShadowUpdate;
2134 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
2135 uint32_t index = 0;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002136 VkWriteDescriptorSet * pWDS = NULL;
2137 VkCopyDescriptorSet * pCDS = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002138 void** ppToFree = NULL;
2139 switch (pFreeUpdate->sType)
2140 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002141 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
2142 pWDS = (VkWriteDescriptorSet*)pFreeUpdate;
Tony Barbourf740f902015-11-02 11:46:29 -07002143 switch (pWDS->descriptorType) {
2144 case VK_DESCRIPTOR_TYPE_SAMPLER:
2145 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
2146 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2147 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
2148 {
2149 delete[] pWDS->pImageInfo;
2150 }
2151 break;
2152 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2153 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
2154 {
2155 delete[] pWDS->pTexelBufferView;
2156 }
2157 break;
2158 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2159 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2160 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2161 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
2162 {
2163 delete[] pWDS->pBufferInfo;
2164 }
2165 break;
2166 default:
2167 break;
Courtney Goeltzenleuchtere4099742015-10-22 15:31:56 -06002168 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002169 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002170 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002171 break;
2172 default:
2173 assert(0);
2174 break;
2175 }
Tobin Ehliseaf28662015-04-08 10:58:37 -06002176 delete pFreeUpdate;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002177 }
2178}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002179
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002180// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002181// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002182static void deletePools(layer_data* my_data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002183{
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002184 if (my_data->descriptorPoolMap.size() <= 0)
David Pinedof5997ab2015-04-27 16:36:17 -06002185 return;
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002186 for (auto ii=my_data->descriptorPoolMap.begin(); ii!=my_data->descriptorPoolMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002187 SET_NODE* pSet = (*ii).second->pSets;
2188 SET_NODE* pFreeSet = pSet;
2189 while (pSet) {
2190 pFreeSet = pSet;
2191 pSet = pSet->pNext;
Tobin Ehliseaf28662015-04-08 10:58:37 -06002192 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002193 // Free Update shadow struct tree
2194 freeShadowUpdateTree(pFreeSet);
2195 if (pFreeSet->ppDescriptors) {
Chris Forbes4506d3f2015-06-04 10:49:27 +12002196 delete[] pFreeSet->ppDescriptors;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002197 }
2198 delete pFreeSet;
2199 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002200 delete (*ii).second;
2201 }
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002202 my_data->descriptorPoolMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002203}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002204
Tobin Ehliseaf28662015-04-08 10:58:37 -06002205// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002206// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002207static void deleteLayouts(layer_data* my_data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002208{
Tobin Ehlisad61de42015-12-02 13:53:34 -07002209 if (my_data->descriptorSetLayoutMap.size() <= 0)
David Pinedof5997ab2015-04-27 16:36:17 -06002210 return;
Tobin Ehlisad61de42015-12-02 13:53:34 -07002211 for (auto ii=my_data->descriptorSetLayoutMap.begin(); ii!=my_data->descriptorSetLayoutMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002212 LAYOUT_NODE* pLayout = (*ii).second;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002213 if (pLayout->createInfo.pBinding) {
Chia-I Wu763a7492015-10-26 20:48:51 +08002214 for (uint32_t i=0; i<pLayout->createInfo.bindingCount; i++) {
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002215 if (pLayout->createInfo.pBinding[i].pImmutableSamplers)
2216 delete[] pLayout->createInfo.pBinding[i].pImmutableSamplers;
Tobin Ehliseaf28662015-04-08 10:58:37 -06002217 }
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002218 delete[] pLayout->createInfo.pBinding;
Tobin Ehliseaf28662015-04-08 10:58:37 -06002219 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002220 delete pLayout;
2221 }
Tobin Ehlisad61de42015-12-02 13:53:34 -07002222 my_data->descriptorSetLayoutMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002223}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002224
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002225// Currently clearing a set is removing all previous updates to that set
2226// TODO : Validate if this is correct clearing behavior
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002227static void clearDescriptorSet(layer_data* my_data, VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002228{
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002229 SET_NODE* pSet = getSetNode(my_data, set);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002230 if (!pSet) {
2231 // TODO : Return error
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002232 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002233 loader_platform_thread_lock_mutex(&globalLock);
2234 freeShadowUpdateTree(pSet);
2235 loader_platform_thread_unlock_mutex(&globalLock);
2236 }
2237}
2238
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002239static void clearDescriptorPool(layer_data* my_data, const VkDevice device, const VkDescriptorPool pool, VkDescriptorPoolResetFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002240{
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002241 DESCRIPTOR_POOL_NODE* pPool = getPoolNode(my_data, pool);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002242 if (!pPool) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002243 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 +08002244 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkResetDescriptorPool() call", (uint64_t) pool);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002245 } else {
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002246 // TODO: validate flags
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002247 // For every set off of this pool, clear it
2248 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002249 while (pSet) {
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002250 clearDescriptorSet(my_data, pSet->set);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002251 }
Tobin Ehlisc6457d22015-10-20 16:16:04 -06002252 // Reset available count to max count for this pool
2253 for (uint32_t i=0; i<pPool->availableDescriptorTypeCount.size(); ++i) {
2254 pPool->availableDescriptorTypeCount[i] = pPool->maxDescriptorTypeCount[i];
2255 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002256 }
2257}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002258
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002259// For given CB object, fetch associated CB Node from map
Chia-I Wu1f851912015-10-27 18:04:07 +08002260static GLOBAL_CB_NODE* getCBNode(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002261{
2262 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski13b66742015-11-20 14:33:48 -07002263 if (my_data->commandBufferMap.count(cb) == 0) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002264 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002265 // TODO : How to pass cb as srcObj here?
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002266 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 +08002267 "Attempt to use CommandBuffer %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<uint64_t>(cb));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002268 return NULL;
2269 }
2270 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wu1f851912015-10-27 18:04:07 +08002271 return my_data->commandBufferMap[cb];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002272}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002273
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002274// Free all CB Nodes
2275// NOTE : Calls to this function should be wrapped in mutex
Chia-I Wu1f851912015-10-27 18:04:07 +08002276static void deleteCommandBuffers(layer_data* my_data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002277{
Mark Lobodzinski13b66742015-11-20 14:33:48 -07002278 if (my_data->commandBufferMap.size() <= 0) {
David Pinedof5997ab2015-04-27 16:36:17 -06002279 return;
Mark Lobodzinski13b66742015-11-20 14:33:48 -07002280 }
Chia-I Wu1f851912015-10-27 18:04:07 +08002281 for (auto ii=my_data->commandBufferMap.begin(); ii!=my_data->commandBufferMap.end(); ++ii) {
Courtney Goeltzenleuchter09098a72015-04-27 15:04:43 -06002282 vector<CMD_NODE*> cmd_node_list = (*ii).second->pCmds;
2283 while (!cmd_node_list.empty()) {
2284 CMD_NODE* cmd_node = cmd_node_list.back();
2285 delete cmd_node;
2286 cmd_node_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002287 }
2288 delete (*ii).second;
2289 }
Chia-I Wu1f851912015-10-27 18:04:07 +08002290 my_data->commandBufferMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002291}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002292
Chia-I Wu1f851912015-10-27 18:04:07 +08002293static 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 -06002294{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002295 // TODO : How to pass cb as srcObj here?
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002296 return log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, 0, DRAWSTATE_NO_BEGIN_COMMAND_BUFFER, "DS",
Michael Lentinecbc4a5e2015-11-03 16:19:46 -08002297 "You must call vkBeginCommandBuffer() before this call to %s", caller_name);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002298}
Michael Lentine2b9eda42015-10-28 15:55:18 -07002299
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07002300VkBool32 validateCmdsInCmdBuffer(const layer_data* dev_data, const GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd_type) {
2301 VkBool32 skip_call = false;
Michael Lentine2b9eda42015-10-28 15:55:18 -07002302 for (auto cmd : pCB->pCmds) {
2303 if (cmd_type == CMD_EXECUTECOMMANDS && cmd->type != CMD_EXECUTECOMMANDS) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002304 skip_call |= log_msg(dev_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 -07002305 "vkCmdExecuteCommands() cannot be called on a cmd buffer with exsiting commands.");
2306 }
2307 if (cmd_type != CMD_EXECUTECOMMANDS && cmd->type == CMD_EXECUTECOMMANDS) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002308 skip_call |= log_msg(dev_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 -07002309 "Commands cannot be added to a cmd buffer with exsiting secondary commands.");
2310 }
2311 }
2312 return skip_call;
2313}
2314
Tobin Ehlis42d440c2015-10-20 17:06:16 -06002315static VkBool32 addCmd(const layer_data* my_data, GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002316{
Michael Lentine2b9eda42015-10-28 15:55:18 -07002317 VkBool32 skipCall = validateCmdsInCmdBuffer(my_data, pCB, cmd);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002318 CMD_NODE* pCmd = new CMD_NODE;
2319 if (pCmd) {
2320 // init cmd node and append to end of cmd LL
2321 memset(pCmd, 0, sizeof(CMD_NODE));
2322 pCmd->cmdNumber = ++pCB->numCmds;
2323 pCmd->type = cmd;
2324 pCB->pCmds.push_back(pCmd);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002325 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002326 // TODO : How to pass cb as srcObj here?
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002327 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",
Chia-I Wu1f851912015-10-27 18:04:07 +08002328 "Out of memory while attempting to allocate new CMD_NODE for commandBuffer %#" PRIxLEAST64, reinterpret_cast<uint64_t>(pCB->commandBuffer));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002329 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002330 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002331}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002332
Chia-I Wu1f851912015-10-27 18:04:07 +08002333static void resetCB(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002334{
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002335 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002336 if (pCB) {
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06002337 vector<CMD_NODE*> cmd_list = pCB->pCmds;
2338 while (!cmd_list.empty()) {
2339 delete cmd_list.back();
2340 cmd_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002341 }
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06002342 pCB->pCmds.clear();
Tobin Ehlis0cea4082015-08-18 07:10:58 -06002343 // Reset CB state (need to save createInfo)
Chia-I Wu1f851912015-10-27 18:04:07 +08002344 VkCommandBufferAllocateInfo saveCBCI = pCB->createInfo;
Chia-I Wu1f851912015-10-27 18:04:07 +08002345 pCB->commandBuffer = cb;
Tobin Ehlis0cea4082015-08-18 07:10:58 -06002346 pCB->createInfo = saveCBCI;
Michael Lentine27b0f902015-10-12 11:30:14 -05002347 memset(&pCB->beginInfo, 0, sizeof(VkCommandBufferBeginInfo));
2348 pCB->fence = 0;
2349 pCB->numCmds = 0;
2350 memset(pCB->drawCount, 0, NUM_DRAW_TYPES * sizeof(uint64_t));
2351 pCB->state = CB_NEW;
2352 pCB->submitCount = 0;
2353 pCB->status = 0;
2354 pCB->pCmds.clear();
2355 pCB->lastBoundPipeline = 0;
2356 pCB->viewports.clear();
2357 pCB->scissors.clear();
2358 pCB->lineWidth = 0;
2359 pCB->depthBiasConstantFactor = 0;
2360 pCB->depthBiasClamp = 0;
2361 pCB->depthBiasSlopeFactor = 0;
2362 memset(pCB->blendConstants, 0, 4 * sizeof(float));
2363 pCB->minDepthBounds = 0;
2364 pCB->maxDepthBounds = 0;
2365 memset(&pCB->front, 0, sizeof(stencil_data));
2366 memset(&pCB->back, 0, sizeof(stencil_data));
2367 pCB->lastBoundDescriptorSet = 0;
2368 pCB->lastBoundPipelineLayout = 0;
2369 pCB->activeRenderPass = 0;
2370 pCB->activeSubpass = 0;
2371 pCB->framebuffer = 0;
Michael Lentine27b0f902015-10-12 11:30:14 -05002372 pCB->boundDescriptorSets.clear();
2373 pCB->imageLayoutMap.clear();
Mark Lobodzinski74e84692015-12-14 15:14:10 -07002374 pCB->boundVtxBuffers.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002375 }
2376}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002377
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002378// Set PSO-related status bits for CB, including dynamic state set via PSO
Tobin Ehlis97866202015-06-10 12:57:07 -06002379static void set_cb_pso_status(GLOBAL_CB_NODE* pCB, const PIPELINE_NODE* pPipe)
2380{
2381 for (uint32_t i = 0; i < pPipe->cbStateCI.attachmentCount; i++) {
Chia-I Wuc51b1212015-10-27 19:25:11 +08002382 if (0 != pPipe->pAttachments[i].colorWriteMask) {
Tobin Ehlis97866202015-06-10 12:57:07 -06002383 pCB->status |= CBSTATUS_COLOR_BLEND_WRITE_ENABLE;
2384 }
2385 }
2386 if (pPipe->dsStateCI.depthWriteEnable) {
Cody Northrop2605cb02015-08-18 15:21:16 -06002387 pCB->status |= CBSTATUS_DEPTH_WRITE_ENABLE;
2388 }
Cody Northrop2605cb02015-08-18 15:21:16 -06002389 if (pPipe->dsStateCI.stencilTestEnable) {
2390 pCB->status |= CBSTATUS_STENCIL_TEST_ENABLE;
Tobin Ehlis97866202015-06-10 12:57:07 -06002391 }
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002392 // Account for any dynamic state not set via this PSO
2393 if (!pPipe->dynStateCI.dynamicStateCount) { // All state is static
2394 pCB->status = CBSTATUS_ALL;
2395 } else {
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002396 // First consider all state on
2397 // Then unset any state that's noted as dynamic in PSO
2398 // Finally OR that into CB statemask
2399 CBStatusFlags psoDynStateMask = CBSTATUS_ALL;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002400 for (uint32_t i=0; i < pPipe->dynStateCI.dynamicStateCount; i++) {
2401 switch (pPipe->dynStateCI.pDynamicStates[i]) {
2402 case VK_DYNAMIC_STATE_VIEWPORT:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002403 psoDynStateMask &= ~CBSTATUS_VIEWPORT_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002404 break;
2405 case VK_DYNAMIC_STATE_SCISSOR:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002406 psoDynStateMask &= ~CBSTATUS_SCISSOR_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002407 break;
2408 case VK_DYNAMIC_STATE_LINE_WIDTH:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002409 psoDynStateMask &= ~CBSTATUS_LINE_WIDTH_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002410 break;
2411 case VK_DYNAMIC_STATE_DEPTH_BIAS:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002412 psoDynStateMask &= ~CBSTATUS_DEPTH_BIAS_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002413 break;
2414 case VK_DYNAMIC_STATE_BLEND_CONSTANTS:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002415 psoDynStateMask &= ~CBSTATUS_BLEND_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002416 break;
2417 case VK_DYNAMIC_STATE_DEPTH_BOUNDS:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002418 psoDynStateMask &= ~CBSTATUS_DEPTH_BOUNDS_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002419 break;
2420 case VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002421 psoDynStateMask &= ~CBSTATUS_STENCIL_READ_MASK_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002422 break;
2423 case VK_DYNAMIC_STATE_STENCIL_WRITE_MASK:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002424 psoDynStateMask &= ~CBSTATUS_STENCIL_WRITE_MASK_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002425 break;
2426 case VK_DYNAMIC_STATE_STENCIL_REFERENCE:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002427 psoDynStateMask &= ~CBSTATUS_STENCIL_REFERENCE_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002428 break;
2429 default:
2430 // TODO : Flag error here
2431 break;
2432 }
2433 }
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002434 pCB->status |= psoDynStateMask;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002435 }
Tobin Ehlis97866202015-06-10 12:57:07 -06002436}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002437
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002438// Print the last bound Gfx Pipeline
Chia-I Wu1f851912015-10-27 18:04:07 +08002439static VkBool32 printPipeline(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002440{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002441 VkBool32 skipCall = VK_FALSE;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002442 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002443 if (pCB) {
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002444 PIPELINE_NODE *pPipeTrav = getPipeline(my_data, pCB->lastBoundPipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002445 if (!pPipeTrav) {
2446 // nothing to print
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002447 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002448 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 -08002449 "%s", vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002450 }
2451 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002452 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002453}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002454
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002455// Print details of DS config to stdout
Chia-I Wu1f851912015-10-27 18:04:07 +08002456static VkBool32 printDSConfig(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002457{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002458 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002459 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 -06002460 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis7297f192015-06-09 08:39:32 -06002461 if (pCB && pCB->lastBoundDescriptorSet) {
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002462 SET_NODE* pSet = getSetNode(my_data, pCB->lastBoundDescriptorSet);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002463 DESCRIPTOR_POOL_NODE* pPool = getPoolNode(my_data, pSet->pool);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002464 // Print out pool details
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002465 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 +08002466 "Details for pool %#" PRIxLEAST64 ".", (uint64_t) pPool->pool);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002467 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002468 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 -06002469 "%s", poolStr.c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002470 // Print out set details
2471 char prefix[10];
2472 uint32_t index = 0;
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002473 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 +08002474 "Details for descriptor set %#" PRIxLEAST64 ".", (uint64_t) pSet->set);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002475 LAYOUT_NODE* pLayout = pSet->pLayout;
2476 // Print layout details
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002477 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 -08002478 "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 -06002479 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002480 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002481 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 -06002482 "%s", DSLstr.c_str());
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002483 index++;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002484 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
2485 if (pUpdate) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002486 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 +08002487 "Update Chain [UC] for descriptor set %#" PRIxLEAST64 ":", (uint64_t) pSet->set);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002488 sprintf(prefix, " [UC] ");
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002489 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 -08002490 "%s", dynamic_display(pUpdate, prefix).c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002491 // TODO : If there is a "view" associated with this update, print CI for that view
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002492 } else {
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06002493 if (0 != pSet->descriptorCount) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002494 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 +08002495 "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 -06002496 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002497 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 +08002498 "FYI: No descriptors in descriptor set %#" PRIxLEAST64 ".", (uint64_t) pSet->set);
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06002499 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002500 }
2501 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002502 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002503}
2504
Chia-I Wu1f851912015-10-27 18:04:07 +08002505static void printCB(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002506{
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002507 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
David Pinedof5997ab2015-04-27 16:36:17 -06002508 if (pCB && pCB->pCmds.size() > 0) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002509 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 -06002510 "Cmds in CB %p", (void*)cb);
Courtney Goeltzenleuchtercf2a5362015-04-27 11:16:35 -06002511 vector<CMD_NODE*> pCmds = pCB->pCmds;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002512 for (auto ii=pCmds.begin(); ii!=pCmds.end(); ++ii) {
2513 // TODO : Need to pass cb as srcObj here
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002514 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 -08002515 " CMD#%" PRIu64 ": %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002516 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002517 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002518 // Nothing to print
2519 }
2520}
2521
Chia-I Wu1f851912015-10-27 18:04:07 +08002522static VkBool32 synchAndPrintDSConfig(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002523{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002524 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002525 if (!(my_data->report_data->active_flags & VK_DEBUG_REPORT_INFO_BIT_EXT)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002526 return skipCall;
Mike Stroyanfa2f2222015-08-12 17:11:28 -06002527 }
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002528 skipCall |= printDSConfig(my_data, cb);
2529 skipCall |= printPipeline(my_data, cb);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002530 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002531}
2532
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002533// Flags validation error if the associated call is made inside a render pass. The apiName
2534// routine should ONLY be called outside a render pass.
Tobin Ehlis42d440c2015-10-20 17:06:16 -06002535static VkBool32 insideRenderPass(const layer_data* my_data, GLOBAL_CB_NODE *pCB, const char *apiName)
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002536{
2537 VkBool32 inside = VK_FALSE;
2538 if (pCB->activeRenderPass) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002539 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 +08002540 (uint64_t)pCB->commandBuffer, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002541 "%s: It is invalid to issue this call inside an active render pass (%#" PRIxLEAST64 ")",
Chia-I Wue420a332015-10-26 20:04:44 +08002542 apiName, (uint64_t) pCB->activeRenderPass);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002543 }
2544 return inside;
2545}
2546
2547// Flags validation error if the associated call is made outside a render pass. The apiName
2548// routine should ONLY be called inside a render pass.
Tobin Ehlis42d440c2015-10-20 17:06:16 -06002549static VkBool32 outsideRenderPass(const layer_data* my_data, GLOBAL_CB_NODE *pCB, const char *apiName)
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002550{
2551 VkBool32 outside = VK_FALSE;
2552 if (!pCB->activeRenderPass) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002553 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 +08002554 (uint64_t)pCB->commandBuffer, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002555 "%s: This call must be issued inside an active render pass.", apiName);
2556 }
2557 return outside;
2558}
2559
Courtney Goeltzenleuchterb03a0bf2015-11-25 14:31:49 -07002560static void init_draw_state(layer_data *my_data, const VkAllocationCallbacks *pAllocator)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002561{
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002562 uint32_t report_flags = 0;
2563 uint32_t debug_action = 0;
2564 FILE *log_output = NULL;
2565 const char *option_str;
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002566 VkDebugReportCallbackEXT callback;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002567 // initialize DrawState options
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002568 report_flags = getLayerOptionFlags("DrawStateReportFlags", 0);
2569 getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &debug_action);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002570
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002571 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002572 {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002573 option_str = getLayerOption("DrawStateLogFilename");
Tobin Ehlisb4b6e7c2015-09-15 09:55:54 -06002574 log_output = getLayerLogOutput(option_str, "DrawState");
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002575 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07002576 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002577 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07002578 dbgInfo.pfnCallback = log_callback;
2579 dbgInfo.pUserData = log_output;
2580 dbgInfo.flags = report_flags;
2581 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchter1781b1c2015-10-05 15:58:38 -06002582 my_data->logging_callback.push_back(callback);
2583 }
2584
2585 if (debug_action & VK_DBG_LAYER_ACTION_DEBUG_OUTPUT) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002586 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07002587 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002588 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07002589 dbgInfo.pfnCallback = win32_debug_output_msg;
2590 dbgInfo.pUserData = log_output;
2591 dbgInfo.flags = report_flags;
2592 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchter1781b1c2015-10-05 15:58:38 -06002593 my_data->logging_callback.push_back(callback);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002594 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002595
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002596 if (!globalLockInitialized)
2597 {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002598 loader_platform_thread_create_mutex(&globalLock);
2599 globalLockInitialized = 1;
2600 }
2601}
2602
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002603VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance)
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06002604{
Tobin Ehliscb085292015-12-01 09:57:09 -07002605 // TODOSC : Shouldn't need any customization here
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002606 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
2607 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Chia-I Wu69f40122015-10-26 21:10:41 +08002608 VkResult result = pTable->CreateInstance(pCreateInfo, pAllocator, pInstance);
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06002609
2610 if (result == VK_SUCCESS) {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002611 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
2612 my_data->report_data = debug_report_create_instance(
2613 pTable,
2614 *pInstance,
Chia-I Wu763a7492015-10-26 20:48:51 +08002615 pCreateInfo->enabledExtensionNameCount,
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002616 pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchterf4a2eba2015-06-08 14:58:39 -06002617
Courtney Goeltzenleuchterb03a0bf2015-11-25 14:31:49 -07002618 init_draw_state(my_data, pAllocator);
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06002619 }
2620 return result;
2621}
2622
Jon Ashburne0fa2282015-05-20 09:00:28 -06002623/* hook DestroyInstance to remove tableInstanceMap entry */
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002624VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator)
Jon Ashburne0fa2282015-05-20 09:00:28 -06002625{
Tobin Ehliscb085292015-12-01 09:57:09 -07002626 // TODOSC : Shouldn't need any customization here
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002627 dispatch_key key = get_dispatch_key(instance);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002628 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
2629 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Chia-I Wu69f40122015-10-26 21:10:41 +08002630 pTable->DestroyInstance(instance, pAllocator);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002631
2632 // Clean up logging callback, if any
Courtney Goeltzenleuchter1781b1c2015-10-05 15:58:38 -06002633 while (my_data->logging_callback.size() > 0) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002634 VkDebugReportCallbackEXT callback = my_data->logging_callback.back();
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07002635 layer_destroy_msg_callback(my_data->report_data, callback, pAllocator);
Courtney Goeltzenleuchter1781b1c2015-10-05 15:58:38 -06002636 my_data->logging_callback.pop_back();
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002637 }
2638
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06002639 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002640 delete my_data->instance_dispatch_table;
2641 layer_data_map.erase(key);
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002642 // TODO : Potential race here with separate threads creating/destroying instance
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002643 if (layer_data_map.empty()) {
Mike Stroyand9dd0072015-08-18 15:56:18 -06002644 // Release mutex when destroying last instance.
2645 loader_platform_thread_delete_mutex(&globalLock);
2646 globalLockInitialized = 0;
2647 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002648}
2649
Jon Ashburnf0615e22015-05-25 14:11:37 -06002650static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
2651{
Tony Barbour29b12062015-07-13 13:37:24 -06002652 uint32_t i;
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002653 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
2654 dev_data->device_extensions.debug_marker_enabled = false;
Michael Lentine27b0f902015-10-12 11:30:14 -05002655 dev_data->device_extensions.wsi_enabled = false;
2656
2657
2658 VkLayerDispatchTable *pDisp = dev_data->device_dispatch_table;
2659 PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr;
2660
Michael Lentine27b0f902015-10-12 11:30:14 -05002661 pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR) gpa(device, "vkCreateSwapchainKHR");
2662 pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR) gpa(device, "vkDestroySwapchainKHR");
2663 pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR) gpa(device, "vkGetSwapchainImagesKHR");
2664 pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR) gpa(device, "vkAcquireNextImageKHR");
2665 pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR) gpa(device, "vkQueuePresentKHR");
Jon Ashburnf0615e22015-05-25 14:11:37 -06002666
Chia-I Wu763a7492015-10-26 20:48:51 +08002667 for (i = 0; i < pCreateInfo->enabledExtensionNameCount; i++) {
Ian Elliottc623ba52015-11-20 14:13:17 -07002668 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) {
Michael Lentine27b0f902015-10-12 11:30:14 -05002669 dev_data->device_extensions.wsi_enabled = true;
2670 }
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002671 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002672 /* Found a matching extension name, mark it enabled and init dispatch table*/
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002673 dev_data->device_extensions.debug_marker_enabled = true;
Jon Ashburnc1d059f2015-12-10 19:12:21 -07002674 initDebugMarkerTable(device);
2675
Jon Ashburnf0615e22015-05-25 14:11:37 -06002676 }
Jon Ashburnf0615e22015-05-25 14:11:37 -06002677 }
2678}
2679
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002680VK_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 -06002681{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002682 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08002683 VkResult result = dev_data->device_dispatch_table->CreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
Tobin Ehliscb085292015-12-01 09:57:09 -07002684 // TODOSC : shouldn't need any customization here
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002685 if (result == VK_SUCCESS) {
2686 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002687 dev_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
Jon Ashburn7e07faf2015-06-18 15:02:58 -06002688 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002689 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002690 return result;
2691}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002692
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002693// prototype
2694static void deleteRenderPasses(layer_data*);
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002695VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002696{
Tobin Ehliscb085292015-12-01 09:57:09 -07002697 // TODOSC : Shouldn't need any customization here
Jeremy Hayesea1fef52015-06-19 11:37:38 -06002698 dispatch_key key = get_dispatch_key(device);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002699 layer_data* dev_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002700 // Free all the memory
2701 loader_platform_thread_lock_mutex(&globalLock);
2702 deletePipelines(dev_data);
2703 deleteRenderPasses(dev_data);
Chia-I Wu1f851912015-10-27 18:04:07 +08002704 deleteCommandBuffers(dev_data);
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002705 deletePools(dev_data);
2706 deleteLayouts(dev_data);
Tobin Ehlisb46be812015-10-23 16:00:08 -06002707 dev_data->imageViewMap.clear();
2708 dev_data->imageMap.clear();
2709 dev_data->bufferViewMap.clear();
2710 dev_data->bufferMap.clear();
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002711 loader_platform_thread_unlock_mutex(&globalLock);
2712
Chia-I Wu69f40122015-10-26 21:10:41 +08002713 dev_data->device_dispatch_table->DestroyDevice(device, pAllocator);
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002714 tableDebugMarkerMap.erase(key);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002715 delete dev_data->device_dispatch_table;
2716 layer_data_map.erase(key);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002717}
2718
Courtney Goeltzenleuchterd89520d2015-12-01 14:08:28 -07002719static const VkExtensionProperties instance_extensions[] = {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002720 {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002721 VK_EXT_DEBUG_REPORT_EXTENSION_NAME,
2722 VK_EXT_DEBUG_REPORT_REVISION
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002723 }
Jon Ashburneb2728b2015-04-10 14:33:07 -06002724};
2725
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002726VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002727 const char *pLayerName,
2728 uint32_t *pCount,
2729 VkExtensionProperties* pProperties)
Jon Ashburneb2728b2015-04-10 14:33:07 -06002730{
Courtney Goeltzenleuchterd89520d2015-12-01 14:08:28 -07002731 return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002732}
Jon Ashburneb2728b2015-04-10 14:33:07 -06002733
Courtney Goeltzenleuchterd89520d2015-12-01 14:08:28 -07002734static const VkLayerProperties ds_global_layers[] = {
2735 {
2736 "DrawState",
2737 VK_API_VERSION,
2738 VK_MAKE_VERSION(0, 1, 0),
2739 "Validation layer: DrawState",
2740 }
2741};
2742
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002743VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002744 uint32_t *pCount,
2745 VkLayerProperties* pProperties)
2746{
2747 return util_GetLayerProperties(ARRAY_SIZE(ds_global_layers),
2748 ds_global_layers,
2749 pCount, pProperties);
2750}
Jon Ashburneb2728b2015-04-10 14:33:07 -06002751
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002752static const VkExtensionProperties ds_device_extensions[] = {
2753 {
2754 DEBUG_MARKER_EXTENSION_NAME,
2755 VK_MAKE_VERSION(0, 1, 0),
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002756 }
2757};
2758
2759static const VkLayerProperties ds_device_layers[] = {
2760 {
2761 "DrawState",
2762 VK_API_VERSION,
2763 VK_MAKE_VERSION(0, 1, 0),
2764 "Validation layer: DrawState",
2765 }
2766};
2767
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002768VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002769 VkPhysicalDevice physicalDevice,
2770 const char* pLayerName,
2771 uint32_t* pCount,
2772 VkExtensionProperties* pProperties)
2773{
Tobin Ehlis32479352015-12-01 09:48:58 -07002774 // DrawState does not have any physical device extensions
Jon Ashburnaff81ff2015-11-02 17:37:20 -07002775 if (pLayerName == NULL) {
2776 dispatch_key key = get_dispatch_key(physicalDevice);
2777 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlis32479352015-12-01 09:48:58 -07002778 return my_data->instance_dispatch_table->EnumerateDeviceExtensionProperties(
Jon Ashburnaff81ff2015-11-02 17:37:20 -07002779 physicalDevice,
2780 NULL,
2781 pCount,
2782 pProperties);
2783 } else {
2784 return util_GetExtensionProperties(ARRAY_SIZE(ds_device_extensions),
2785 ds_device_extensions,
2786 pCount, pProperties);
2787 }
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002788}
2789
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002790VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002791 VkPhysicalDevice physicalDevice,
2792 uint32_t* pCount,
2793 VkLayerProperties* pProperties)
2794{
Tobin Ehlis32479352015-12-01 09:48:58 -07002795 /* DrawState physical device layers are the same as global */
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002796 return util_GetLayerProperties(ARRAY_SIZE(ds_device_layers), ds_device_layers,
2797 pCount, pProperties);
Jon Ashburneb2728b2015-04-10 14:33:07 -06002798}
2799
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07002800VkBool32 ValidateCmdBufImageLayouts(VkCommandBuffer cmdBuffer) {
2801 VkBool32 skip_call = false;
Michael Lentine27b0f902015-10-12 11:30:14 -05002802 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
2803 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
2804 for (auto cb_image_data : pCB->imageLayoutMap) {
2805 auto image_data = dev_data->imageLayoutMap.find(cb_image_data.first);
2806 if (image_data == dev_data->imageLayoutMap.end()) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002807 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 -08002808 "Cannot submit cmd buffer using deleted image %" PRIu64 ".", reinterpret_cast<uint64_t>(cb_image_data.first));
Michael Lentine27b0f902015-10-12 11:30:14 -05002809 } else {
2810 if (dev_data->imageLayoutMap[cb_image_data.first]->layout != cb_image_data.second.initialLayout) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002811 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 -05002812 "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);
2813 }
2814 dev_data->imageLayoutMap[cb_image_data.first]->layout = cb_image_data.second.layout;
2815 }
2816 }
2817 return skip_call;
2818}
2819
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002820VK_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 -06002821{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002822 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis28be0be2015-05-22 12:38:16 -06002823 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002824 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06002825 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
Chia-I Wu483e7702015-10-26 17:20:32 +08002826 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Chia-I Wu763a7492015-10-26 20:48:51 +08002827 for (uint32_t i=0; i < submit->commandBufferCount; i++) {
Mark Lobodzinski78940a42015-11-30 16:48:53 -07002828
2829#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
2830 skipCall |= ValidateCmdBufImageLayouts(submit->pCommandBuffers[i]);
2831#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
2832
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06002833 // Validate that cmd buffers have been updated
2834 pCB = getCBNode(dev_data, submit->pCommandBuffers[i]);
2835 loader_platform_thread_lock_mutex(&globalLock);
2836 pCB->submitCount++; // increment submit count
Chia-I Wu1f851912015-10-27 18:04:07 +08002837 if ((pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT) && (pCB->submitCount > 1)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002838 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 -05002839 "CB %#" PRIxLEAST64 " was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted %#" PRIxLEAST64 " times.",
2840 reinterpret_cast<uint64_t>(pCB->commandBuffer), pCB->submitCount);
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06002841 }
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07002842 if (CB_RECORDED != pCB->state) {
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06002843 // Flag error for using CB w/o vkEndCommandBuffer() called
2844 // TODO : How to pass cb as srcObj?
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002845 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 +08002846 "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 -06002847 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07002848 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06002849 }
Tobin Ehlise90b1712015-05-27 14:30:06 -06002850 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis28be0be2015-05-22 12:38:16 -06002851 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002852 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002853 if (VK_FALSE == skipCall)
Chia-I Wu483e7702015-10-26 17:20:32 +08002854 return dev_data->device_dispatch_table->QueueSubmit(queue, submitCount, pSubmits, fence);
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07002855 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002856}
2857
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002858VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002859{
Chia-I Wu69f40122015-10-26 21:10:41 +08002860 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 -06002861 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002862}
2863
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002864VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySemaphore(VkDevice device, VkSemaphore semaphore, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002865{
Chia-I Wu69f40122015-10-26 21:10:41 +08002866 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 -06002867 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002868}
2869
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002870VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002871{
Chia-I Wu69f40122015-10-26 21:10:41 +08002872 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 -06002873 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002874}
2875
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002876VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002877{
Chia-I Wu69f40122015-10-26 21:10:41 +08002878 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 -06002879 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002880}
2881
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002882VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002883{
Tobin Ehlisb46be812015-10-23 16:00:08 -06002884 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08002885 dev_data->device_dispatch_table->DestroyBuffer(device, buffer, pAllocator);
Chia-I Wue420a332015-10-26 20:04:44 +08002886 dev_data->bufferMap.erase(buffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002887}
2888
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002889VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBufferView(VkDevice device, VkBufferView bufferView, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002890{
Tobin Ehlisb46be812015-10-23 16:00:08 -06002891 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08002892 dev_data->device_dispatch_table->DestroyBufferView(device, bufferView, pAllocator);
Chia-I Wue420a332015-10-26 20:04:44 +08002893 dev_data->bufferViewMap.erase(bufferView);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002894}
2895
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002896VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002897{
Tobin Ehlisb46be812015-10-23 16:00:08 -06002898 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08002899 dev_data->device_dispatch_table->DestroyImage(device, image, pAllocator);
Chia-I Wue420a332015-10-26 20:04:44 +08002900 dev_data->imageMap.erase(image);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002901}
2902
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002903VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyImageView(VkDevice device, VkImageView imageView, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002904{
Chia-I Wu69f40122015-10-26 21:10:41 +08002905 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 -06002906 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002907}
2908
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002909VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002910{
Chia-I Wu69f40122015-10-26 21:10:41 +08002911 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 -06002912 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002913}
2914
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002915VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyPipeline(VkDevice device, VkPipeline pipeline, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002916{
Chia-I Wu69f40122015-10-26 21:10:41 +08002917 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 -06002918 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002919}
2920
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002921VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002922{
Chia-I Wu69f40122015-10-26 21:10:41 +08002923 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 -06002924 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002925}
2926
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002927VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySampler(VkDevice device, VkSampler sampler, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002928{
Chia-I Wu69f40122015-10-26 21:10:41 +08002929 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 -06002930 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002931}
2932
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002933VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002934{
Chia-I Wu69f40122015-10-26 21:10:41 +08002935 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 -06002936 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002937}
2938
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002939VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002940{
Chia-I Wu69f40122015-10-26 21:10:41 +08002941 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 -06002942 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002943}
2944
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002945VK_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 -06002946{
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002947 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
2948
Courtney Goeltzenleuchter740451a2015-12-16 16:06:06 -07002949 for (uint32_t i = 0; i < count; i++) {
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002950 // Delete CB information structure, and remove from commandBufferMap
2951 auto cb = dev_data->commandBufferMap.find(pCommandBuffers[i]);
Mark Lobodzinski13b66742015-11-20 14:33:48 -07002952 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002953 if (cb != dev_data->commandBufferMap.end()) {
2954 delete (*cb).second;
2955 dev_data->commandBufferMap.erase(cb);
2956 }
2957
2958 // Remove commandBuffer reference from commandPoolMap
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07002959 dev_data->commandPoolMap[commandPool].commandBuffers.remove(pCommandBuffers[i]);
Mark Lobodzinski13b66742015-11-20 14:33:48 -07002960 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002961 }
2962
2963 dev_data->device_dispatch_table->FreeCommandBuffers(device, commandPool, count, pCommandBuffers);
2964}
2965
2966VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkCommandPool* pCommandPool)
2967{
2968 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
2969
2970 VkResult result = dev_data->device_dispatch_table->CreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
2971
2972 if (VK_SUCCESS == result) {
Mark Lobodzinski13b66742015-11-20 14:33:48 -07002973 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07002974 dev_data->commandPoolMap[*pCommandPool].createFlags = pCreateInfo->flags;
Mark Lobodzinski13b66742015-11-20 14:33:48 -07002975 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002976 }
2977 return result;
2978}
2979
2980VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks* pAllocator)
2981{
2982 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski13b66742015-11-20 14:33:48 -07002983 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002984
2985 // Must remove cmdpool from cmdpoolmap, after removing all cmdbuffers in its list from the commandPoolMap
2986 if (dev_data->commandPoolMap.find(commandPool) != dev_data->commandPoolMap.end()) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07002987 for (auto poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.begin(); poolCb != dev_data->commandPoolMap[commandPool].commandBuffers.end();) {
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002988 auto del_cb = dev_data->commandBufferMap.find(*poolCb);
2989 delete (*del_cb).second; // delete CB info structure
2990 dev_data->commandBufferMap.erase(del_cb); // Remove this command buffer from cbMap
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07002991 poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.erase(poolCb); // Remove CB reference from commandPoolMap's list
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002992 }
2993 }
2994 dev_data->commandPoolMap.erase(commandPool);
Mark Lobodzinski13b66742015-11-20 14:33:48 -07002995
2996 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002997 dev_data->device_dispatch_table->DestroyCommandPool(device, commandPool, pAllocator);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002998}
2999
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003000VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandPool(
3001 VkDevice device,
3002 VkCommandPool commandPool,
3003 VkCommandPoolResetFlags flags)
3004{
3005 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003006 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003007
3008 result = dev_data->device_dispatch_table->ResetCommandPool(device, commandPool, flags);
3009 // Reset all of the CBs allocated from this pool
3010 if (VK_SUCCESS == result) {
3011 auto it = dev_data->commandPoolMap[commandPool].commandBuffers.begin();
3012 while (it != dev_data->commandPoolMap[commandPool].commandBuffers.end()) {
3013 resetCB(dev_data, (*it));
3014 ++it;
3015 }
3016 }
3017 return result;
3018}
3019
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003020VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003021{
Chia-I Wu69f40122015-10-26 21:10:41 +08003022 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 -06003023 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003024}
3025
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003026VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003027{
Chia-I Wu69f40122015-10-26 21:10:41 +08003028 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 -06003029 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003030}
3031
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003032VK_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 -06003033{
3034 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003035 VkResult result = dev_data->device_dispatch_table->CreateBuffer(device, pCreateInfo, pAllocator, pBuffer);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003036 if (VK_SUCCESS == result) {
3037 loader_platform_thread_lock_mutex(&globalLock);
3038 // 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 +08003039 dev_data->bufferMap[*pBuffer] = unique_ptr<VkBufferCreateInfo>(new VkBufferCreateInfo(*pCreateInfo));
Tobin Ehlisb46be812015-10-23 16:00:08 -06003040 loader_platform_thread_unlock_mutex(&globalLock);
3041 }
3042 return result;
3043}
3044
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003045VK_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 -06003046{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003047 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003048 VkResult result = dev_data->device_dispatch_table->CreateBufferView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003049 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003050 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue420a332015-10-26 20:04:44 +08003051 dev_data->bufferViewMap[*pView] = unique_ptr<VkBufferViewCreateInfo>(new VkBufferViewCreateInfo(*pCreateInfo));
Tobin Ehlisb46be812015-10-23 16:00:08 -06003052 loader_platform_thread_unlock_mutex(&globalLock);
3053 }
3054 return result;
3055}
3056
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003057VK_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 -06003058{
3059 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003060 VkResult result = dev_data->device_dispatch_table->CreateImage(device, pCreateInfo, pAllocator, pImage);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003061 if (VK_SUCCESS == result) {
Michael Lentine27b0f902015-10-12 11:30:14 -05003062 IMAGE_NODE* image_node = new IMAGE_NODE;
3063 image_node->layout = pCreateInfo->initialLayout;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003064 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue420a332015-10-26 20:04:44 +08003065 dev_data->imageMap[*pImage] = unique_ptr<VkImageCreateInfo>(new VkImageCreateInfo(*pCreateInfo));
Michael Lentine27b0f902015-10-12 11:30:14 -05003066 dev_data->imageLayoutMap[*pImage] = image_node;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003067 loader_platform_thread_unlock_mutex(&globalLock);
3068 }
3069 return result;
3070}
3071
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003072VK_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 -06003073{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003074 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003075 VkResult result = dev_data->device_dispatch_table->CreateImageView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003076 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003077 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue420a332015-10-26 20:04:44 +08003078 dev_data->imageViewMap[*pView] = unique_ptr<VkImageViewCreateInfo>(new VkImageViewCreateInfo(*pCreateInfo));
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003079 loader_platform_thread_unlock_mutex(&globalLock);
3080 }
3081 return result;
3082}
3083
Jon Ashburn0d60d272015-07-09 15:02:25 -06003084//TODO handle pipeline caches
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003085VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineCache(
Jon Ashburn0d60d272015-07-09 15:02:25 -06003086 VkDevice device,
3087 const VkPipelineCacheCreateInfo* pCreateInfo,
Chia-I Wu1f851912015-10-27 18:04:07 +08003088 const VkAllocationCallbacks* pAllocator,
Jon Ashburn0d60d272015-07-09 15:02:25 -06003089 VkPipelineCache* pPipelineCache)
3090{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003091 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003092 VkResult result = dev_data->device_dispatch_table->CreatePipelineCache(device, pCreateInfo, pAllocator, pPipelineCache);
Jon Ashburn0d60d272015-07-09 15:02:25 -06003093 return result;
3094}
3095
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003096VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineCache(
Jon Ashburn0d60d272015-07-09 15:02:25 -06003097 VkDevice device,
Chia-I Wu69f40122015-10-26 21:10:41 +08003098 VkPipelineCache pipelineCache,
Chia-I Wu1f851912015-10-27 18:04:07 +08003099 const VkAllocationCallbacks* pAllocator)
Jon Ashburn0d60d272015-07-09 15:02:25 -06003100{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003101 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003102 dev_data->device_dispatch_table->DestroyPipelineCache(device, pipelineCache, pAllocator);
Jon Ashburn0d60d272015-07-09 15:02:25 -06003103}
3104
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003105VKAPI_ATTR VkResult VKAPI_CALL vkGetPipelineCacheData(
Jon Ashburn0d60d272015-07-09 15:02:25 -06003106 VkDevice device,
3107 VkPipelineCache pipelineCache,
Chia-I Wu28c3c432015-10-26 19:17:06 +08003108 size_t* pDataSize,
Jon Ashburn0d60d272015-07-09 15:02:25 -06003109 void* pData)
3110{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003111 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu28c3c432015-10-26 19:17:06 +08003112 VkResult result = dev_data->device_dispatch_table->GetPipelineCacheData(device, pipelineCache, pDataSize, pData);
Jon Ashburn0d60d272015-07-09 15:02:25 -06003113 return result;
3114}
3115
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003116VKAPI_ATTR VkResult VKAPI_CALL vkMergePipelineCaches(
Jon Ashburn0d60d272015-07-09 15:02:25 -06003117 VkDevice device,
Chia-I Wu1f851912015-10-27 18:04:07 +08003118 VkPipelineCache dstCache,
Jon Ashburn0d60d272015-07-09 15:02:25 -06003119 uint32_t srcCacheCount,
3120 const VkPipelineCache* pSrcCaches)
3121{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003122 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu1f851912015-10-27 18:04:07 +08003123 VkResult result = dev_data->device_dispatch_table->MergePipelineCaches(device, dstCache, srcCacheCount, pSrcCaches);
Jon Ashburn0d60d272015-07-09 15:02:25 -06003124 return result;
3125}
3126
Mark Lobodzinski2adea752015-11-10 15:25:01 -07003127VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateGraphicsPipelines(
3128 VkDevice device,
3129 VkPipelineCache pipelineCache,
3130 uint32_t count,
3131 const VkGraphicsPipelineCreateInfo *pCreateInfos,
3132 const VkAllocationCallbacks *pAllocator,
3133 VkPipeline *pPipelines)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003134{
Courtney Goeltzenleuchtera54b76a2015-09-04 13:39:59 -06003135 VkResult result = VK_SUCCESS;
Tobin Ehlise48be202015-09-16 10:33:53 -06003136 //TODO What to do with pipelineCache?
Tobin Ehlisde63c532015-06-18 15:59:33 -06003137 // The order of operations here is a little convoluted but gets the job done
3138 // 1. Pipeline create state is first shadowed into PIPELINE_NODE struct
3139 // 2. Create state is then validated (which uses flags setup during shadowing)
3140 // 3. If everything looks good, we'll then create the pipeline and add NODE to pipelineMap
Tobin Ehlise48be202015-09-16 10:33:53 -06003141 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis76c18852015-09-17 16:33:58 -06003142 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
3143 vector<PIPELINE_NODE*> pPipeNode(count);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003144 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski2adea752015-11-10 15:25:01 -07003145
Tobin Ehlise48be202015-09-16 10:33:53 -06003146 uint32_t i=0;
Tobin Ehlisde63c532015-06-18 15:59:33 -06003147 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski2adea752015-11-10 15:25:01 -07003148
Tobin Ehlise48be202015-09-16 10:33:53 -06003149 for (i=0; i<count; i++) {
Mark Lobodzinski2adea752015-11-10 15:25:01 -07003150 pPipeNode[i] = initGraphicsPipeline(dev_data, &pCreateInfos[i], NULL);
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003151 skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
Tobin Ehlise48be202015-09-16 10:33:53 -06003152 }
Mark Lobodzinski2adea752015-11-10 15:25:01 -07003153
Tobin Ehlisde63c532015-06-18 15:59:33 -06003154 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis32479352015-12-01 09:48:58 -07003155
Tobin Ehlisad61de42015-12-02 13:53:34 -07003156 if (VK_FALSE == skipCall) {
Mark Lobodzinski2adea752015-11-10 15:25:01 -07003157 result = dev_data->device_dispatch_table->CreateGraphicsPipelines(device,
3158 pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
Tobin Ehlisde63c532015-06-18 15:59:33 -06003159 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlise48be202015-09-16 10:33:53 -06003160 for (i=0; i<count; i++) {
3161 pPipeNode[i]->pipeline = pPipelines[i];
Chia-I Wue420a332015-10-26 20:04:44 +08003162 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
Tobin Ehlise48be202015-09-16 10:33:53 -06003163 }
Tobin Ehlisde63c532015-06-18 15:59:33 -06003164 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003165 } else {
Tobin Ehlise48be202015-09-16 10:33:53 -06003166 for (i=0; i<count; i++) {
3167 if (pPipeNode[i]) {
3168 // If we allocated a pipeNode, need to clean it up here
3169 delete[] pPipeNode[i]->pVertexBindingDescriptions;
3170 delete[] pPipeNode[i]->pVertexAttributeDescriptions;
3171 delete[] pPipeNode[i]->pAttachments;
3172 delete pPipeNode[i];
3173 }
Tobin Ehlisde63c532015-06-18 15:59:33 -06003174 }
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003175 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisde63c532015-06-18 15:59:33 -06003176 }
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06003177 return result;
3178}
3179
Mark Lobodzinski2adea752015-11-10 15:25:01 -07003180VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateComputePipelines(
3181 VkDevice device,
3182 VkPipelineCache pipelineCache,
3183 uint32_t count,
3184 const VkComputePipelineCreateInfo *pCreateInfos,
3185 const VkAllocationCallbacks *pAllocator,
3186 VkPipeline *pPipelines)
3187{
3188 VkResult result = VK_SUCCESS;
3189 VkBool32 skipCall = VK_FALSE;
3190
3191 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
3192 vector<PIPELINE_NODE*> pPipeNode(count);
3193 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3194
3195 uint32_t i=0;
3196 loader_platform_thread_lock_mutex(&globalLock);
3197 for (i=0; i<count; i++) {
3198 // TODO: Verify compute stage bits
3199
3200 // Create and initialize internal tracking data structure
3201 pPipeNode[i] = new PIPELINE_NODE;
3202 memset((void*)pPipeNode[i], 0, sizeof(PIPELINE_NODE));
3203 memcpy(&pPipeNode[i]->computePipelineCI, (const void*)&pCreateInfos[i], sizeof(VkComputePipelineCreateInfo));
3204
3205 // TODO: Add Compute Pipeline Verification
3206 // skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
3207 }
3208 loader_platform_thread_unlock_mutex(&globalLock);
3209
3210 if (VK_FALSE == skipCall) {
3211 result = dev_data->device_dispatch_table->CreateComputePipelines(device, pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
3212 loader_platform_thread_lock_mutex(&globalLock);
3213 for (i=0; i<count; i++) {
3214 pPipeNode[i]->pipeline = pPipelines[i];
3215 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
3216 }
3217 loader_platform_thread_unlock_mutex(&globalLock);
3218 } else {
3219 for (i=0; i<count; i++) {
3220 if (pPipeNode[i]) {
3221 // Clean up any locally allocated data structures
3222 delete pPipeNode[i];
3223 }
3224 }
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003225 return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinski2adea752015-11-10 15:25:01 -07003226 }
3227 return result;
3228}
3229
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003230VK_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 -06003231{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003232 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003233 VkResult result = dev_data->device_dispatch_table->CreateSampler(device, pCreateInfo, pAllocator, pSampler);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003234 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003235 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue420a332015-10-26 20:04:44 +08003236 dev_data->sampleMap[*pSampler] = unique_ptr<SAMPLER_NODE>(new SAMPLER_NODE(pSampler, pCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003237 loader_platform_thread_unlock_mutex(&globalLock);
3238 }
3239 return result;
3240}
3241
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003242VK_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 -06003243{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003244 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003245 VkResult result = dev_data->device_dispatch_table->CreateDescriptorSetLayout(device, pCreateInfo, pAllocator, pSetLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003246 if (VK_SUCCESS == result) {
Tobin Ehliscb085292015-12-01 09:57:09 -07003247 // TODOSC : Capture layout bindings set
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003248 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
3249 if (NULL == pNewNode) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003250 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 -06003251 "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()"))
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003252 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003253 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003254 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003255 pNewNode->createInfo.pBinding = new VkDescriptorSetLayoutBinding[pCreateInfo->bindingCount];
3256 memcpy((void*)pNewNode->createInfo.pBinding, pCreateInfo->pBinding, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->bindingCount);
Chia-I Wub5689ee2015-10-31 00:31:16 +08003257 // g++ does not like reserve with size 0
3258 if (pCreateInfo->bindingCount)
3259 pNewNode->bindings.reserve(pCreateInfo->bindingCount);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003260 uint32_t totalCount = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08003261 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
Chia-I Wub5689ee2015-10-31 00:31:16 +08003262 if (!pNewNode->bindings.insert(pCreateInfo->pBinding[i].binding).second) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003263 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 +08003264 "duplicated binding number in VkDescriptorSetLayoutBinding"))
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003265 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wub5689ee2015-10-31 00:31:16 +08003266 }
3267
Chia-I Wu045654f2015-11-06 06:42:02 +08003268 totalCount += pCreateInfo->pBinding[i].descriptorCount;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003269 if (pCreateInfo->pBinding[i].pImmutableSamplers) {
3270 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBinding[i].pImmutableSamplers;
Chia-I Wu045654f2015-11-06 06:42:02 +08003271 *ppIS = new VkSampler[pCreateInfo->pBinding[i].descriptorCount];
3272 memcpy(*ppIS, pCreateInfo->pBinding[i].pImmutableSamplers, pCreateInfo->pBinding[i].descriptorCount*sizeof(VkSampler));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003273 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003274 }
3275 if (totalCount > 0) {
Cody Northrop8a908322015-10-26 14:07:35 -06003276 pNewNode->descriptorTypes.resize(totalCount);
Tobin Ehlis68fbd442015-10-27 12:25:35 -06003277 pNewNode->stageFlags.resize(totalCount);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003278 uint32_t offset = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003279 uint32_t j = 0;
Tobin Ehlis61ebb312015-11-04 12:28:28 -07003280 VkDescriptorType dType;
Chia-I Wu763a7492015-10-26 20:48:51 +08003281 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
Tobin Ehlis61ebb312015-11-04 12:28:28 -07003282 dType = pCreateInfo->pBinding[i].descriptorType;
Chia-I Wu045654f2015-11-06 06:42:02 +08003283 for (j = 0; j < pCreateInfo->pBinding[i].descriptorCount; j++) {
Tobin Ehlis61ebb312015-11-04 12:28:28 -07003284 pNewNode->descriptorTypes[offset + j] = dType;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003285 pNewNode->stageFlags[offset + j] = pCreateInfo->pBinding[i].stageFlags;
Tobin Ehlis61ebb312015-11-04 12:28:28 -07003286 if ((dType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
3287 (dType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
3288 pNewNode->dynamicDescriptorCount++;
3289 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003290 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003291 offset += j;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003292 }
3293 }
3294 pNewNode->layout = *pSetLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003295 pNewNode->startIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003296 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
3297 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003298 // Put new node at Head of global Layer list
3299 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisad61de42015-12-02 13:53:34 -07003300 dev_data->descriptorSetLayoutMap[*pSetLayout] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003301 loader_platform_thread_unlock_mutex(&globalLock);
3302 }
3303 return result;
3304}
3305
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003306VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003307{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003308 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003309 VkResult result = dev_data->device_dispatch_table->CreatePipelineLayout(device, pCreateInfo, pAllocator, pPipelineLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003310 if (VK_SUCCESS == result) {
Tobin Ehliscb085292015-12-01 09:57:09 -07003311 // TODOSC : Merge capture of the setLayouts per pipeline
Tobin Ehlis982099b2015-11-05 09:52:49 -07003312 PIPELINE_LAYOUT_NODE& plNode = dev_data->pipelineLayoutMap[*pPipelineLayout];
Chia-I Wu763a7492015-10-26 20:48:51 +08003313 plNode.descriptorSetLayouts.resize(pCreateInfo->setLayoutCount);
Tobin Ehlis91423d22015-10-20 10:11:55 -06003314 uint32_t i = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08003315 for (i=0; i<pCreateInfo->setLayoutCount; ++i) {
Tobin Ehlis91423d22015-10-20 10:11:55 -06003316 plNode.descriptorSetLayouts[i] = pCreateInfo->pSetLayouts[i];
3317 }
Cody Northrop8a908322015-10-26 14:07:35 -06003318 plNode.pushConstantRanges.resize(pCreateInfo->pushConstantRangeCount);
Tobin Ehlis91423d22015-10-20 10:11:55 -06003319 for (i=0; i<pCreateInfo->pushConstantRangeCount; ++i) {
3320 plNode.pushConstantRanges[i] = pCreateInfo->pPushConstantRanges[i];
3321 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003322 }
3323 return result;
3324}
3325
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003326VK_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 -06003327{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003328 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003329 VkResult result = dev_data->device_dispatch_table->CreateDescriptorPool(device, pCreateInfo, pAllocator, pDescriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003330 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003331 // Insert this pool into Global Pool LL at head
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003332 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 +08003333 "Created Descriptor Pool %#" PRIxLEAST64, (uint64_t) *pDescriptorPool))
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003334 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003335 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003336 DESCRIPTOR_POOL_NODE* pNewNode = new DESCRIPTOR_POOL_NODE(*pDescriptorPool, pCreateInfo);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003337 if (NULL == pNewNode) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003338 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 -07003339 "Out of memory while attempting to allocate DESCRIPTOR_POOL_NODE in vkCreateDescriptorPool()"))
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003340 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003341 } else {
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003342 dev_data->descriptorPoolMap[*pDescriptorPool] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003343 }
3344 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003345 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003346 // Need to do anything if pool create fails?
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003347 }
3348 return result;
3349}
3350
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003351VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorPoolResetFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003352{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003353 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003354 VkResult result = dev_data->device_dispatch_table->ResetDescriptorPool(device, descriptorPool, flags);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003355 if (VK_SUCCESS == result) {
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003356 clearDescriptorPool(dev_data, device, descriptorPool, flags);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003357 }
3358 return result;
3359}
3360
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003361VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo* pAllocateInfo, VkDescriptorSet* pDescriptorSets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003362{
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003363 VkBool32 skipCall = VK_FALSE;
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003364 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003365 // Verify that requested descriptorSets are available in pool
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003366 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003367 if (!pPoolNode) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003368 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 +08003369 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pAllocateInfo->descriptorPool);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003370 } else { // Make sure pool has all the available descriptors before calling down chain
Chia-I Wu1f851912015-10-27 18:04:07 +08003371 skipCall |= validate_descriptor_availability_in_pool(dev_data, pPoolNode, pAllocateInfo->setLayoutCount, pAllocateInfo->pSetLayouts);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003372 }
3373 if (skipCall)
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003374 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wu1f851912015-10-27 18:04:07 +08003375 VkResult result = dev_data->device_dispatch_table->AllocateDescriptorSets(device, pAllocateInfo, pDescriptorSets);
Cody Northropc8aa4a52015-08-03 12:47:29 -06003376 if (VK_SUCCESS == result) {
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003377 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003378 if (pPoolNode) {
Chia-I Wu1f851912015-10-27 18:04:07 +08003379 if (pAllocateInfo->setLayoutCount == 0) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003380 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 +08003381 "AllocateDescriptorSets called with 0 count");
Cody Northropc8aa4a52015-08-03 12:47:29 -06003382 }
Chia-I Wu1f851912015-10-27 18:04:07 +08003383 for (uint32_t i = 0; i < pAllocateInfo->setLayoutCount; i++) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003384 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 +08003385 "Created Descriptor Set %#" PRIxLEAST64, (uint64_t) pDescriptorSets[i]);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003386 // Create new set node and add to head of pool nodes
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003387 SET_NODE* pNewNode = new SET_NODE;
3388 if (NULL == pNewNode) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003389 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 +08003390 "Out of memory while attempting to allocate SET_NODE in vkAllocateDescriptorSets()"))
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003391 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003392 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003393 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlisf6e93e02015-10-19 12:09:13 -06003394 // TODO : Pool should store a total count of each type of Descriptor available
3395 // When descriptors are allocated, decrement the count and validate here
3396 // that the count doesn't go below 0. One reset/free need to bump count back up.
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003397 // Insert set at head of Set LL for this pool
3398 pNewNode->pNext = pPoolNode->pSets;
3399 pPoolNode->pSets = pNewNode;
Chia-I Wu1f851912015-10-27 18:04:07 +08003400 LAYOUT_NODE* pLayout = getLayoutNode(dev_data, pAllocateInfo->pSetLayouts[i]);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003401 if (NULL == pLayout) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003402 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 +08003403 "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 -07003404 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003405 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003406 pNewNode->pLayout = pLayout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003407 pNewNode->pool = pAllocateInfo->descriptorPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003408 pNewNode->set = pDescriptorSets[i];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003409 pNewNode->descriptorCount = pLayout->endIndex + 1;
3410 if (pNewNode->descriptorCount) {
3411 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
3412 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
3413 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
3414 }
Chia-I Wue420a332015-10-26 20:04:44 +08003415 dev_data->setMap[pDescriptorSets[i]] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003416 }
3417 }
3418 }
3419 }
3420 return result;
3421}
3422
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003423VK_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 -06003424{
Tobin Ehlis3c543112015-10-08 13:13:50 -06003425 VkBool32 skipCall = VK_FALSE;
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003426 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003427 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, descriptorPool);
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003428 if (pPoolNode && !(VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT & pPoolNode->createInfo.flags)) {
3429 // Can't Free from a NON_FREE pool
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003430 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 -06003431 "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 -06003432 }
3433 if (skipCall)
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003434 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003435 VkResult result = dev_data->device_dispatch_table->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003436 if (VK_SUCCESS == result) {
3437 // For each freed descriptor add it back into the pool as available
3438 for (uint32_t i=0; i<count; ++i) {
Chia-I Wue420a332015-10-26 20:04:44 +08003439 SET_NODE* pSet = dev_data->setMap[pDescriptorSets[i]]; // getSetNode() without locking
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003440 LAYOUT_NODE* pLayout = pSet->pLayout;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003441 uint32_t typeIndex = 0, poolSizeCount = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08003442 for (uint32_t j=0; j<pLayout->createInfo.bindingCount; ++j) {
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003443 typeIndex = static_cast<uint32_t>(pLayout->createInfo.pBinding[j].descriptorType);
Chia-I Wu045654f2015-11-06 06:42:02 +08003444 poolSizeCount = pLayout->createInfo.pBinding[j].descriptorCount;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003445 pPoolNode->availableDescriptorTypeCount[typeIndex] += poolSizeCount;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003446 }
3447 }
3448 }
3449 // TODO : Any other clean-up or book-keeping to do here?
Tony Barbourb857d312015-07-10 10:50:45 -06003450 return result;
3451}
3452
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003453VK_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 -06003454{
Tobin Ehlis68fbd442015-10-27 12:25:35 -06003455 // 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 -06003456 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu483e7702015-10-26 17:20:32 +08003457 if (!dsUpdate(dev_data, device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies)) {
3458 dev_data->device_dispatch_table->UpdateDescriptorSets(device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies);
Jon Ashburne0fa2282015-05-20 09:00:28 -06003459 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003460}
3461
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003462VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo* pCreateInfo, VkCommandBuffer* pCommandBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003463{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003464 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu1f851912015-10-27 18:04:07 +08003465 VkResult result = dev_data->device_dispatch_table->AllocateCommandBuffers(device, pCreateInfo, pCommandBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003466 if (VK_SUCCESS == result) {
Courtney Goeltzenleuchter740451a2015-12-16 16:06:06 -07003467 for (uint32_t i = 0; i < pCreateInfo->bufferCount; i++) {
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003468 // Validate command pool
3469 if (dev_data->commandPoolMap.find(pCreateInfo->commandPool) != dev_data->commandPoolMap.end()) {
Mark Lobodzinski13b66742015-11-20 14:33:48 -07003470 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003471 // Add command buffer to its commandPool map
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003472 dev_data->commandPoolMap[pCreateInfo->commandPool].commandBuffers.push_back(pCommandBuffer[i]);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003473 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
3474 // Add command buffer to map
3475 dev_data->commandBufferMap[pCommandBuffer[i]] = pCB;
Mark Lobodzinski13b66742015-11-20 14:33:48 -07003476 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003477 resetCB(dev_data, pCommandBuffer[i]);
3478 pCB->commandBuffer = pCommandBuffer[i];
3479 pCB->createInfo = *pCreateInfo;
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003480 }
3481 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003482 }
3483 return result;
3484}
3485
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003486VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo* pBeginInfo)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003487{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003488 VkBool32 skipCall = false;
Chia-I Wu1f851912015-10-27 18:04:07 +08003489 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06003490 // Validate command buffer level
Chia-I Wu1f851912015-10-27 18:04:07 +08003491 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06003492 if (pCB) {
Mark Lobodzinskia1420862015-11-19 13:22:11 -07003493 if (pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
Chia-I Wue420a332015-10-26 20:04:44 +08003494 if (pBeginInfo->renderPass || pBeginInfo->framebuffer) {
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06003495 // These should be NULL for a Primary CB
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003496 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 -07003497 "vkBeginCommandBuffer(): Primary Command Buffer (%p) may not specify framebuffer or renderpass parameters", (void*)commandBuffer);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06003498 }
3499 } else {
Chia-I Wue420a332015-10-26 20:04:44 +08003500 if (!pBeginInfo->renderPass || !pBeginInfo->framebuffer) {
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06003501 // These should NOT be null for an Secondary CB
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003502 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 -07003503 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) must specify framebuffer and renderpass parameters", (void*)commandBuffer);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06003504 }
3505 }
Tobin Ehlis0cea4082015-08-18 07:10:58 -06003506 pCB->beginInfo = *pBeginInfo;
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003507 if (CB_RECORDING == pCB->state) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003508 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 -07003509 "vkBeginCommandBuffer(): Cannot call Begin on CB (%#" PRIxLEAST64 ") in the RECORDING state. Must first call vkEndCommandBuffer().", (uint64_t)commandBuffer);
3510 } else if (CB_RECORDED == pCB->state) {
3511 VkCommandPool cmdPool = pCB->createInfo.commandPool;
3512 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003513 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 -07003514 0, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
3515 "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.",
3516 (uint64_t) commandBuffer, (uint64_t) cmdPool);
3517 }
3518 }
Tobin Ehlis0cea4082015-08-18 07:10:58 -06003519 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003520 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 +08003521 "In vkBeginCommandBuffer() and unable to find CommandBuffer Node for CB %p!", (void*)commandBuffer);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06003522 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003523 if (skipCall) {
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003524 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter3abd86e2015-09-04 15:03:52 -06003525 }
Chia-I Wu1f851912015-10-27 18:04:07 +08003526 VkResult result = dev_data->device_dispatch_table->BeginCommandBuffer(commandBuffer, pBeginInfo);
Mark Lobodzinski2ad35592015-11-12 16:14:04 -07003527 if ((VK_SUCCESS == result) && (pCB != NULL)) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003528 if (CB_RECORDED == pCB->state) {
Chia-I Wu1f851912015-10-27 18:04:07 +08003529 resetCB(dev_data, commandBuffer);
Mark Lobodzinski2ad35592015-11-12 16:14:04 -07003530 }
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003531 pCB->state = CB_RECORDING;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003532 }
3533 return result;
3534}
3535
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003536VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEndCommandBuffer(VkCommandBuffer commandBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003537{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003538 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchtera54b76a2015-09-04 13:39:59 -06003539 VkResult result = VK_SUCCESS;
Chia-I Wu1f851912015-10-27 18:04:07 +08003540 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3541 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlise42007c2015-06-19 13:00:59 -06003542 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003543 if (pCB->state != CB_RECORDING) {
Chia-I Wu1f851912015-10-27 18:04:07 +08003544 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkEndCommandBuffer()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003545 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003546 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003547 if (VK_FALSE == skipCall) {
Chia-I Wu1f851912015-10-27 18:04:07 +08003548 result = dev_data->device_dispatch_table->EndCommandBuffer(commandBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003549 if (VK_SUCCESS == result) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003550 pCB->state = CB_RECORDED;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003551 // Reset CB status flags
3552 pCB->status = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08003553 printCB(dev_data, commandBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003554 }
3555 } else {
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003556 result = VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003557 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003558 return result;
3559}
3560
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003561VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003562{
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003563 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003564 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003565 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
3566 VkCommandPool cmdPool = pCB->createInfo.commandPool;
3567 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003568 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 -07003569 0, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
3570 "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.",
3571 (uint64_t) commandBuffer, (uint64_t) cmdPool);
3572 }
3573 if (skipCall)
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003574 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wu1f851912015-10-27 18:04:07 +08003575 VkResult result = dev_data->device_dispatch_table->ResetCommandBuffer(commandBuffer, flags);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003576 if (VK_SUCCESS == result) {
Chia-I Wu1f851912015-10-27 18:04:07 +08003577 resetCB(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003578 }
3579 return result;
3580}
3581
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003582VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003583{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003584 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003585 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3586 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003587 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003588 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003589 skipCall |= addCmd(dev_data, pCB, CMD_BINDPIPELINE);
Mark Lobodzinski7bc3a9e2015-12-17 09:24:14 -07003590 PIPELINE_NODE* pPN = getPipeline(dev_data, pipeline);
3591 if (pPN) {
3592 pCB->lastBoundPipeline = pipeline;
3593 loader_platform_thread_lock_mutex(&globalLock);
3594 set_cb_pso_status(pCB, pPN);
3595 g_lastBoundPipeline = pPN;
3596 loader_platform_thread_unlock_mutex(&globalLock);
3597 skipCall |= validatePipelineState(dev_data, pCB, pipelineBindPoint, pipeline);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003598 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003599 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, (uint64_t) pipeline,
Mark Lobodzinski7bc3a9e2015-12-17 09:24:14 -07003600 0, DRAWSTATE_INVALID_PIPELINE, "DS",
3601 "Attempt to bind Pipeline %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<uint64_t>(pipeline));
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003602
Tobin Ehlise42007c2015-06-19 13:00:59 -06003603 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003604 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003605 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindPipeline()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003606 }
3607 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003608 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003609 dev_data->device_dispatch_table->CmdBindPipeline(commandBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003610}
3611
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003612VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetViewport(
Chia-I Wu1f851912015-10-27 18:04:07 +08003613 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06003614 uint32_t viewportCount,
3615 const VkViewport* pViewports)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003616{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003617 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003618 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3619 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlise42007c2015-06-19 13:00:59 -06003620 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003621 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003622 skipCall |= addCmd(dev_data, pCB, CMD_SETVIEWPORTSTATE);
Tobin Ehlise42007c2015-06-19 13:00:59 -06003623 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003624 pCB->status |= CBSTATUS_VIEWPORT_SET;
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06003625 pCB->viewports.resize(viewportCount);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003626 memcpy(pCB->viewports.data(), pViewports, viewportCount * sizeof(VkViewport));
Tobin Ehlise42007c2015-06-19 13:00:59 -06003627 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlise42007c2015-06-19 13:00:59 -06003628 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003629 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdSetViewport()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06003630 }
3631 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003632 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003633 dev_data->device_dispatch_table->CmdSetViewport(commandBuffer, viewportCount, pViewports);
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06003634}
3635
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003636VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetScissor(
Chia-I Wu1f851912015-10-27 18:04:07 +08003637 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06003638 uint32_t scissorCount,
3639 const VkRect2D* pScissors)
3640{
3641 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003642 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3643 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06003644 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003645 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003646 skipCall |= addCmd(dev_data, pCB, CMD_SETSCISSORSTATE);
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06003647 loader_platform_thread_lock_mutex(&globalLock);
3648 pCB->status |= CBSTATUS_SCISSOR_SET;
3649 pCB->scissors.resize(scissorCount);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003650 memcpy(pCB->scissors.data(), pScissors, scissorCount * sizeof(VkRect2D));
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06003651 loader_platform_thread_unlock_mutex(&globalLock);
3652 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003653 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdSetScissor()");
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06003654 }
3655 }
3656 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003657 dev_data->device_dispatch_table->CmdSetScissor(commandBuffer, scissorCount, pScissors);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003658}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003659
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003660VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003661{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003662 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003663 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3664 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003665 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003666 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003667 skipCall |= addCmd(dev_data, pCB, CMD_SETLINEWIDTHSTATE);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003668 /* TODO: Do we still need this lock? */
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003669 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003670 pCB->status |= CBSTATUS_LINE_WIDTH_SET;
3671 pCB->lineWidth = lineWidth;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003672 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003673 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003674 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindDynamicLineWidthState()");
Cody Northropf5bd2252015-08-17 11:10:49 -06003675 }
3676 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003677 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003678 dev_data->device_dispatch_table->CmdSetLineWidth(commandBuffer, lineWidth);
Cody Northropf5bd2252015-08-17 11:10:49 -06003679}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003680
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003681VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBias(
Chia-I Wu1f851912015-10-27 18:04:07 +08003682 VkCommandBuffer commandBuffer,
Chia-I Wufa950c52015-10-26 19:08:09 +08003683 float depthBiasConstantFactor,
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003684 float depthBiasClamp,
Chia-I Wufa950c52015-10-26 19:08:09 +08003685 float depthBiasSlopeFactor)
Cody Northropf5bd2252015-08-17 11:10:49 -06003686{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003687 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003688 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3689 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northropf5bd2252015-08-17 11:10:49 -06003690 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003691 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003692 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBIASSTATE);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003693 pCB->status |= CBSTATUS_DEPTH_BIAS_SET;
Chia-I Wufa950c52015-10-26 19:08:09 +08003694 pCB->depthBiasConstantFactor = depthBiasConstantFactor;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003695 pCB->depthBiasClamp = depthBiasClamp;
Chia-I Wufa950c52015-10-26 19:08:09 +08003696 pCB->depthBiasSlopeFactor = depthBiasSlopeFactor;
Cody Northropf5bd2252015-08-17 11:10:49 -06003697 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003698 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdSetDepthBias()");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003699 }
3700 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003701 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003702 dev_data->device_dispatch_table->CmdSetDepthBias(commandBuffer, depthBiasConstantFactor, depthBiasClamp, depthBiasSlopeFactor);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003703}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003704
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003705VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4])
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003706{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003707 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003708 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3709 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003710 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003711 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003712 skipCall |= addCmd(dev_data, pCB, CMD_SETBLENDSTATE);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003713 pCB->status |= CBSTATUS_BLEND_SET;
Chia-I Wu7e470702015-10-26 17:24:52 +08003714 memcpy(pCB->blendConstants, blendConstants, 4 * sizeof(float));
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003715 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003716 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdSetBlendConstants()");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003717 }
3718 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003719 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003720 dev_data->device_dispatch_table->CmdSetBlendConstants(commandBuffer, blendConstants);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003721}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003722
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003723VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBounds(
Chia-I Wu1f851912015-10-27 18:04:07 +08003724 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003725 float minDepthBounds,
3726 float maxDepthBounds)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003727{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003728 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003729 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3730 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003731 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003732 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003733 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBOUNDSSTATE);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003734 pCB->status |= CBSTATUS_DEPTH_BOUNDS_SET;
3735 pCB->minDepthBounds = minDepthBounds;
3736 pCB->maxDepthBounds = maxDepthBounds;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003737 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003738 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdSetDepthBounds()");
Cody Northrop2605cb02015-08-18 15:21:16 -06003739 }
3740 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003741 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003742 dev_data->device_dispatch_table->CmdSetDepthBounds(commandBuffer, minDepthBounds, maxDepthBounds);
Cody Northrop2605cb02015-08-18 15:21:16 -06003743}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003744
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003745VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilCompareMask(
Chia-I Wu1f851912015-10-27 18:04:07 +08003746 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003747 VkStencilFaceFlags faceMask,
Chia-I Wuc51b1212015-10-27 19:25:11 +08003748 uint32_t compareMask)
Cody Northrop2605cb02015-08-18 15:21:16 -06003749{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003750 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003751 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3752 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northrop2605cb02015-08-18 15:21:16 -06003753 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003754 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003755 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREADMASKSTATE);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003756 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
Chia-I Wuc51b1212015-10-27 19:25:11 +08003757 pCB->front.compareMask = compareMask;
Cody Northrop2605cb02015-08-18 15:21:16 -06003758 }
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003759 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
Chia-I Wuc51b1212015-10-27 19:25:11 +08003760 pCB->back.compareMask = compareMask;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003761 }
3762 /* TODO: Do we need to track front and back separately? */
3763 /* TODO: We aren't capturing the faceMask, do we need to? */
3764 pCB->status |= CBSTATUS_STENCIL_READ_MASK_SET;
Cody Northrop2605cb02015-08-18 15:21:16 -06003765 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003766 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdSetStencilCompareMask()");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003767 }
3768 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003769 if (VK_FALSE == skipCall)
Chia-I Wuc51b1212015-10-27 19:25:11 +08003770 dev_data->device_dispatch_table->CmdSetStencilCompareMask(commandBuffer, faceMask, compareMask);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003771}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003772
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003773VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilWriteMask(
Chia-I Wu1f851912015-10-27 18:04:07 +08003774 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003775 VkStencilFaceFlags faceMask,
Chia-I Wuc51b1212015-10-27 19:25:11 +08003776 uint32_t writeMask)
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003777{
3778 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003779 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3780 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003781 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003782 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003783 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILWRITEMASKSTATE);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003784 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
Chia-I Wuc51b1212015-10-27 19:25:11 +08003785 pCB->front.writeMask = writeMask;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003786 }
3787 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
Chia-I Wuc51b1212015-10-27 19:25:11 +08003788 pCB->back.writeMask = writeMask;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003789 }
3790 pCB->status |= CBSTATUS_STENCIL_WRITE_MASK_SET;
3791 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003792 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdSetStencilWriteMask()");
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003793 }
3794 }
3795 if (VK_FALSE == skipCall)
Chia-I Wuc51b1212015-10-27 19:25:11 +08003796 dev_data->device_dispatch_table->CmdSetStencilWriteMask(commandBuffer, faceMask, writeMask);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003797}
3798
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003799VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilReference(
Chia-I Wu1f851912015-10-27 18:04:07 +08003800 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003801 VkStencilFaceFlags faceMask,
Chia-I Wuc51b1212015-10-27 19:25:11 +08003802 uint32_t reference)
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003803{
3804 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003805 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3806 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003807 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003808 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003809 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREFERENCESTATE);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003810 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
Chia-I Wuc51b1212015-10-27 19:25:11 +08003811 pCB->front.reference = reference;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003812 }
3813 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
Chia-I Wuc51b1212015-10-27 19:25:11 +08003814 pCB->back.reference = reference;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003815 }
3816 pCB->status |= CBSTATUS_STENCIL_REFERENCE_SET;
3817 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003818 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdSetStencilReference()");
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003819 }
3820 }
3821 if (VK_FALSE == skipCall)
Chia-I Wuc51b1212015-10-27 19:25:11 +08003822 dev_data->device_dispatch_table->CmdSetStencilReference(commandBuffer, faceMask, reference);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003823}
3824
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003825VK_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 -06003826{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003827 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003828 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3829 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003830 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003831 if (pCB->state == CB_RECORDING) {
Tobin Ehlise4076782015-06-24 15:53:07 -06003832 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003833 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Chia-I Wue420a332015-10-26 20:04:44 +08003834 "Incorrectly binding compute DescriptorSets during active RenderPass (%#" PRIxLEAST64 ")", (uint64_t) pCB->activeRenderPass);
Tobin Ehlise4076782015-06-24 15:53:07 -06003835 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) && (!pCB->activeRenderPass)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003836 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Tobin Ehlise4076782015-06-24 15:53:07 -06003837 "Incorrectly binding graphics DescriptorSets without an active RenderPass");
Tobin Ehlisd28acef2015-09-09 15:12:35 -06003838 } else {
Tobin Ehlis61ebb312015-11-04 12:28:28 -07003839 // Track total count of dynamic descriptor types to make sure we have an offset for each one
3840 uint32_t totalDynamicDescriptors = 0;
Tobin Ehlis982099b2015-11-05 09:52:49 -07003841 string errorString = "";
Tobin Ehliscb085292015-12-01 09:57:09 -07003842 uint32_t lastSetIndex = firstSet+setCount-1;
Tobin Ehlis982099b2015-11-05 09:52:49 -07003843 if (lastSetIndex >= pCB->boundDescriptorSets.size())
3844 pCB->boundDescriptorSets.resize(lastSetIndex+1);
3845 VkDescriptorSet oldFinalBoundSet = pCB->boundDescriptorSets[lastSetIndex];
Tobin Ehlise42007c2015-06-19 13:00:59 -06003846 for (uint32_t i=0; i<setCount; i++) {
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06003847 SET_NODE* pSet = getSetNode(dev_data, pDescriptorSets[i]);
Tobin Ehlis55c1c602015-06-24 17:27:33 -06003848 if (pSet) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06003849 loader_platform_thread_lock_mutex(&globalLock);
3850 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06003851 pCB->lastBoundPipelineLayout = layout;
Tobin Ehlis982099b2015-11-05 09:52:49 -07003852 pCB->boundDescriptorSets[i+firstSet] = pDescriptorSets[i];
Tobin Ehlise42007c2015-06-19 13:00:59 -06003853 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003854 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",
Chia-I Wue420a332015-10-26 20:04:44 +08003855 "DS %#" PRIxLEAST64 " bound on pipeline %s", (uint64_t) pDescriptorSets[i], string_VkPipelineBindPoint(pipelineBindPoint));
Tobin Ehlis61ebb312015-11-04 12:28:28 -07003856 if (!pSet->pUpdateStructs) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003857 // TODO: Verify against Valid Usage
3858 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",
Chia-I Wue420a332015-10-26 20:04:44 +08003859 "DS %#" PRIxLEAST64 " bound but it was never updated. You may want to either update it or not bind it.", (uint64_t) pDescriptorSets[i]);
Tobin Ehlis61ebb312015-11-04 12:28:28 -07003860 }
Tobin Ehlis982099b2015-11-05 09:52:49 -07003861 // Verify that set being bound is compatible with overlapping setLayout of pipelineLayout
3862 if (!verify_set_layout_compatibility(dev_data, pSet, layout, i+firstSet, errorString)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003863 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",
Tobin Ehlis982099b2015-11-05 09:52:49 -07003864 "descriptorSet #%u being bound is not compatible with overlapping layout in pipelineLayout due to: %s", i, errorString.c_str());
3865 }
Tobin Ehlis61ebb312015-11-04 12:28:28 -07003866 totalDynamicDescriptors += pSet->pLayout->dynamicDescriptorCount;
Tobin Ehlise42007c2015-06-19 13:00:59 -06003867 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003868 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",
Chia-I Wue420a332015-10-26 20:04:44 +08003869 "Attempt to bind DS %#" PRIxLEAST64 " that doesn't exist!", (uint64_t) pDescriptorSets[i]);
Tobin Ehlise42007c2015-06-19 13:00:59 -06003870 }
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06003871 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003872 skipCall |= addCmd(dev_data, pCB, CMD_BINDDESCRIPTORSETS);
Tobin Ehlis982099b2015-11-05 09:52:49 -07003873 // For any previously bound sets, need to set them to "invalid" if they were disturbed by this update
3874 if (firstSet > 0) { // Check set #s below the first bound set
3875 for (uint32_t i=0; i<firstSet; ++i) {
Tobin Ehliscb085292015-12-01 09:57:09 -07003876 if (pCB->boundDescriptorSets[i] && !verify_set_layout_compatibility(dev_data, dev_data->setMap[pCB->boundDescriptorSets[i]], layout, i, errorString)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003877 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",
Tobin Ehlis982099b2015-11-05 09:52:49 -07003878 "DescriptorSetDS %#" PRIxLEAST64 " previously bound as set #%u was disturbed by newly bound pipelineLayout (%#" PRIxLEAST64 ")", (uint64_t) pCB->boundDescriptorSets[i], i, (uint64_t) layout);
3879 pCB->boundDescriptorSets[i] = VK_NULL_HANDLE;
3880 }
3881 }
3882 }
3883 // Check if newly last bound set invalidates any remaining bound sets
3884 if ((pCB->boundDescriptorSets.size()-1) > (lastSetIndex)) {
Tobin Ehliscb085292015-12-01 09:57:09 -07003885 if (oldFinalBoundSet && !verify_set_layout_compatibility(dev_data, dev_data->setMap[oldFinalBoundSet], layout, lastSetIndex, errorString)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003886 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",
Tobin Ehliscb085292015-12-01 09:57:09 -07003887 "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 -07003888 pCB->boundDescriptorSets.resize(lastSetIndex+1);
3889 }
3890 }
Tobin Ehlis61ebb312015-11-04 12:28:28 -07003891 // dynamicOffsetCount must equal the total number of dynamic descriptors in the sets being bound
3892 if (totalDynamicDescriptors != dynamicOffsetCount) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003893 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",
Tobin Ehlis61ebb312015-11-04 12:28:28 -07003894 "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);
3895 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003896 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06003897 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003898 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindDescriptorSets()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003899 }
3900 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003901 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003902 dev_data->device_dispatch_table->CmdBindDescriptorSets(commandBuffer, pipelineBindPoint, layout, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003903}
3904
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003905VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003906{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003907 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003908 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3909 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003910 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003911 if (pCB->state == CB_RECORDING) {
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003912 VkDeviceSize offset_align = 0;
3913 switch (indexType) {
3914 case VK_INDEX_TYPE_UINT16:
3915 offset_align = 2;
3916 break;
3917 case VK_INDEX_TYPE_UINT32:
3918 offset_align = 4;
3919 break;
3920 default:
3921 // ParamChecker should catch bad enum, we'll also throw alignment error below if offset_align stays 0
3922 break;
3923 }
3924 if (!offset_align || (offset % offset_align)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003925 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_VTX_INDEX_ALIGNMENT_ERROR, "DS",
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003926 "vkCmdBindIndexBuffer() offset (%#" PRIxLEAST64 ") does not fall on alignment (%s) boundary.", offset, string_VkIndexType(indexType));
Tobin Ehlise4076782015-06-24 15:53:07 -06003927 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003928 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003929 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06003930 }
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003931 pCB->status |= CBSTATUS_INDEX_BUFFER_BOUND;
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003932 skipCall |= addCmd(dev_data, pCB, CMD_BINDINDEXBUFFER);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003933 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003934 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003935 dev_data->device_dispatch_table->CmdBindIndexBuffer(commandBuffer, buffer, offset, indexType);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003936}
3937
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003938VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindVertexBuffers(
Mark Lobodzinski74e84692015-12-14 15:14:10 -07003939 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003940 uint32_t startBinding,
3941 uint32_t bindingCount,
Mark Lobodzinski74e84692015-12-14 15:14:10 -07003942 const VkBuffer *pBuffers,
3943 const VkDeviceSize *pOffsets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003944{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003945 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003946 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3947 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003948 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003949 if (pCB->state == CB_RECORDING) {
Mark Lobodzinski74e84692015-12-14 15:14:10 -07003950 if ((startBinding + bindingCount) > pCB->boundVtxBuffers.size()) {
3951 pCB->boundVtxBuffers.resize(startBinding+bindingCount, VK_NULL_HANDLE);
3952 }
Courtney Goeltzenleuchter740451a2015-12-16 16:06:06 -07003953 for (uint32_t i = 0; i < bindingCount; i++) {
Mark Lobodzinski74e84692015-12-14 15:14:10 -07003954 pCB->boundVtxBuffers[i+startBinding] = pBuffers[i];
3955 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003956 addCmd(dev_data, pCB, CMD_BINDVERTEXBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003957 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003958 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindVertexBuffer()");
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06003959 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003960 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003961 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003962 dev_data->device_dispatch_table->CmdBindVertexBuffers(commandBuffer, startBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003963}
3964
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003965VK_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 -06003966{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003967 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003968 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3969 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003970 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003971 if (pCB->state == CB_RECORDING) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06003972 pCB->drawCount[DRAW]++;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06003973 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
Chia-I Wu1f851912015-10-27 18:04:07 +08003974 // TODO : Need to pass commandBuffer as srcObj here
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003975 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",
Michael Lentinecbc4a5e2015-11-03 16:19:46 -08003976 "vkCmdDraw() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW]++);
Chia-I Wu1f851912015-10-27 18:04:07 +08003977 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003978 if (VK_FALSE == skipCall) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003979 skipCall |= addCmd(dev_data, pCB, CMD_DRAW);
Tobin Ehlise42007c2015-06-19 13:00:59 -06003980 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003981 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003982 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdDraw()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06003983 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003984 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDraw");
Jon Ashburne0fa2282015-05-20 09:00:28 -06003985 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003986 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003987 dev_data->device_dispatch_table->CmdDraw(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003988}
3989
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003990VK_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 -06003991{
Chia-I Wu1f851912015-10-27 18:04:07 +08003992 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3993 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003994 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003995 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003996 if (pCB->state == CB_RECORDING) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06003997 pCB->drawCount[DRAW_INDEXED]++;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06003998 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
Chia-I Wu1f851912015-10-27 18:04:07 +08003999 // TODO : Need to pass commandBuffer as srcObj here
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004000 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",
Michael Lentinecbc4a5e2015-11-03 16:19:46 -08004001 "vkCmdDrawIndexed() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED]++);
Chia-I Wu1f851912015-10-27 18:04:07 +08004002 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004003 if (VK_FALSE == skipCall) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004004 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXED);
Tobin Ehlise42007c2015-06-19 13:00:59 -06004005 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004006 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004007 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdDrawIndexed()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004008 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004009 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexed");
Jon Ashburne0fa2282015-05-20 09:00:28 -06004010 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004011 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004012 dev_data->device_dispatch_table->CmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004013}
4014
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004015VK_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 -06004016{
Chia-I Wu1f851912015-10-27 18:04:07 +08004017 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4018 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004019 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004020 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004021 if (pCB->state == CB_RECORDING) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06004022 pCB->drawCount[DRAW_INDIRECT]++;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06004023 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
Chia-I Wu1f851912015-10-27 18:04:07 +08004024 // TODO : Need to pass commandBuffer as srcObj here
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004025 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",
Michael Lentinecbc4a5e2015-11-03 16:19:46 -08004026 "vkCmdDrawIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
Chia-I Wu1f851912015-10-27 18:04:07 +08004027 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004028 if (VK_FALSE == skipCall) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004029 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDIRECT);
Tobin Ehlise42007c2015-06-19 13:00:59 -06004030 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004031 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004032 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdDrawIndirect()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004033 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004034 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndirect");
Jon Ashburne0fa2282015-05-20 09:00:28 -06004035 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004036 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004037 dev_data->device_dispatch_table->CmdDrawIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004038}
4039
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004040VK_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 -06004041{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004042 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004043 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4044 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004045 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004046 if (pCB->state == CB_RECORDING) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06004047 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06004048 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
Chia-I Wu1f851912015-10-27 18:04:07 +08004049 // TODO : Need to pass commandBuffer as srcObj here
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004050 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",
Michael Lentinecbc4a5e2015-11-03 16:19:46 -08004051 "vkCmdDrawIndexedIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
Chia-I Wu1f851912015-10-27 18:04:07 +08004052 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004053 if (VK_FALSE == skipCall) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004054 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXEDINDIRECT);
Tobin Ehlise42007c2015-06-19 13:00:59 -06004055 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004056 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004057 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdDrawIndexedIndirect()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004058 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004059 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexedIndirect");
Jon Ashburne0fa2282015-05-20 09:00:28 -06004060 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004061 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004062 dev_data->device_dispatch_table->CmdDrawIndexedIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004063}
4064
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004065VK_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 -06004066{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004067 VkBool32 skipCall = VK_FALSE;
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 Ehlis63bb9482015-03-17 16:24:32 -06004070 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004071 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004072 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCH);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004073 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004074 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdDispatch()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004075 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004076 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatch");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004077 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004078 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004079 dev_data->device_dispatch_table->CmdDispatch(commandBuffer, x, y, z);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004080}
4081
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004082VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004083{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004084 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004085 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4086 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004087 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004088 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004089 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCHINDIRECT);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004090 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004091 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdDispatchIndirect()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004092 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004093 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatchIndirect");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004094 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004095 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004096 dev_data->device_dispatch_table->CmdDispatchIndirect(commandBuffer, buffer, offset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004097}
4098
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004099VK_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 -06004100{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004101 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004102 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4103 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004104 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004105 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004106 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004107 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004108 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdCopyBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004109 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004110 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBuffer");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004111 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004112 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004113 dev_data->device_dispatch_table->CmdCopyBuffer(commandBuffer, srcBuffer, dstBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004114}
4115
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004116VkBool32 VerifySourceImageLayout(VkCommandBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout) {
4117 VkBool32 skip_call = false;
Mark Lobodzinski78940a42015-11-30 16:48:53 -07004118
4119#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4120 // TODO: Fix -- initialLayout may have been set in a previous command buffer
4121 return skip_call;
4122#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4123
Michael Lentine27b0f902015-10-12 11:30:14 -05004124 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4125 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4126 auto src_image_element = pCB->imageLayoutMap.find(srcImage);
4127 if (src_image_element == pCB->imageLayoutMap.end()) {
4128 pCB->imageLayoutMap[srcImage].initialLayout = srcImageLayout;
4129 pCB->imageLayoutMap[srcImage].layout = srcImageLayout;
4130 return false;
4131 }
4132 if (src_image_element->second.layout != srcImageLayout) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004133 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 -05004134 "Cannot copy from an image whose source layout is %d and doesn't match the current layout %d.", srcImageLayout, src_image_element->second.layout);
4135 }
4136 if (srcImageLayout != VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL) {
4137 if (srcImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004138 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
4139 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 -05004140 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Michael Lentine27b0f902015-10-12 11:30:14 -05004141 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004142 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 -05004143 "Layout for input image is %d but can only be TRANSFER_SRC_OPTIMAL or GENERAL.", srcImageLayout);
Michael Lentine27b0f902015-10-12 11:30:14 -05004144 }
4145 }
4146 return skip_call;
4147}
4148
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004149VkBool32 VerifyDestImageLayout(VkCommandBuffer cmdBuffer, VkImage destImage, VkImageLayout destImageLayout) {
4150 VkBool32 skip_call = false;
Mark Lobodzinski78940a42015-11-30 16:48:53 -07004151
4152#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4153 // TODO: Fix -- initialLayout may have been set in a previous command buffer
4154 return skip_call;
4155#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4156
Michael Lentine27b0f902015-10-12 11:30:14 -05004157 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4158 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4159 auto dest_image_element = pCB->imageLayoutMap.find(destImage);
4160 if (dest_image_element == pCB->imageLayoutMap.end()) {
4161 pCB->imageLayoutMap[destImage].initialLayout = destImageLayout;
4162 pCB->imageLayoutMap[destImage].layout = destImageLayout;
4163 return false;
4164 }
4165 if (dest_image_element->second.layout != destImageLayout) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004166 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 -05004167 "Cannot copy from an image whose dest layout is %d and doesn't match the current layout %d.", destImageLayout, dest_image_element->second.layout);
4168 }
4169 if (destImageLayout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) {
4170 if (destImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004171 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
4172 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 -05004173 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
4174 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004175 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 -05004176 "Layout for output image is %d but can only be TRANSFER_DST_OPTIMAL or GENERAL.", destImageLayout);
4177 }
4178 }
4179 return skip_call;
4180}
4181
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004182VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004183 VkImage srcImage,
4184 VkImageLayout srcImageLayout,
Chia-I Wu1f851912015-10-27 18:04:07 +08004185 VkImage dstImage,
4186 VkImageLayout dstImageLayout,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004187 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004188{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004189 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004190 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4191 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004192 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004193 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004194 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGE);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004195 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004196 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdCopyImage()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004197 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004198 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImage");
Michael Lentine27b0f902015-10-12 11:30:14 -05004199 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
4200 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004201 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004202 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004203 dev_data->device_dispatch_table->CmdCopyImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004204}
4205
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004206VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBlitImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004207 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu1f851912015-10-27 18:04:07 +08004208 VkImage dstImage, VkImageLayout dstImageLayout,
Mark Lobodzinski20f68592015-05-22 14:43:25 -05004209 uint32_t regionCount, const VkImageBlit* pRegions,
Chia-I Wu3603b082015-10-26 16:49:32 +08004210 VkFilter filter)
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06004211{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004212 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004213 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4214 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06004215 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004216 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004217 skipCall |= addCmd(dev_data, pCB, CMD_BLITIMAGE);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004218 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004219 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBlitImage()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004220 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004221 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBlitImage");
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06004222 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004223 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004224 dev_data->device_dispatch_table->CmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06004225}
4226
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004227VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004228 VkBuffer srcBuffer,
Chia-I Wu1f851912015-10-27 18:04:07 +08004229 VkImage dstImage, VkImageLayout dstImageLayout,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004230 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004231{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004232 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004233 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4234 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004235 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004236 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004237 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFERTOIMAGE);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004238 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004239 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdCopyBufferToImage()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004240 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004241 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBufferToImage");
Michael Lentine27b0f902015-10-12 11:30:14 -05004242 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->CmdCopyBufferToImage(commandBuffer, srcBuffer, 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 vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004249 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu1f851912015-10-27 18:04:07 +08004250 VkBuffer dstBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004251 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004252{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004253 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004254 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4255 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004256 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004257 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004258 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGETOBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004259 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004260 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdCopyImageToBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004261 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004262 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImageToBuffer");
Michael Lentine27b0f902015-10-12 11:30:14 -05004263 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004264 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004265 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004266 dev_data->device_dispatch_table->CmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004267}
4268
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004269VK_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 -06004270{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004271 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004272 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4273 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004274 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004275 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004276 skipCall |= addCmd(dev_data, pCB, CMD_UPDATEBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004277 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004278 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdUpdateBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004279 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004280 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyUpdateBuffer");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004281 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004282 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004283 dev_data->device_dispatch_table->CmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004284}
4285
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004286VK_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 -06004287{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004288 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004289 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4290 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004291 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004292 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004293 skipCall |= addCmd(dev_data, pCB, CMD_FILLBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004294 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004295 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdFillBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004296 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004297 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyFillBuffer");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004298 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004299 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004300 dev_data->device_dispatch_table->CmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004301}
4302
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004303VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearAttachments(
Chia-I Wu1f851912015-10-27 18:04:07 +08004304 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004305 uint32_t attachmentCount,
4306 const VkClearAttachment* pAttachments,
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004307 uint32_t rectCount,
Courtney Goeltzenleuchtera12e2912015-10-15 18:22:08 -06004308 const VkClearRect* pRects)
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004309{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004310 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004311 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4312 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004313 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004314 if (pCB->state == CB_RECORDING) {
Mark Lobodzinski92c712c2015-12-08 13:47:14 -07004315 // Warn if this is issued prior to Draw Cmd and clearing the entire attachment
4316 if (!hasDrawCmd(pCB) &&
4317 (pCB->activeRenderPassBeginInfo.renderArea.extent.width == pRects[0].rect.extent.width) &&
4318 (pCB->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) {
Chia-I Wu1f851912015-10-27 18:04:07 +08004319 // TODO : commandBuffer should be srcObj
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004320 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",
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004321 "vkCmdClearAttachments() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
Chia-I Wu1f851912015-10-27 18:04:07 +08004322 " 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 -06004323 }
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004324 skipCall |= addCmd(dev_data, pCB, CMD_CLEARATTACHMENTS);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004325 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004326 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdClearAttachments()");
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004327 }
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004328 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdClearAttachments");
4329 }
4330
4331 // Validate that attachment is in reference list of active subpass
4332 if (pCB->activeRenderPass) {
Tobin Ehlisad61de42015-12-02 13:53:34 -07004333 const VkRenderPassCreateInfo *pRPCI = dev_data->renderPassMap[pCB->activeRenderPass]->pCreateInfo;
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004334 const VkSubpassDescription *pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
4335
4336 for (uint32_t attachment_idx = 0; attachment_idx < attachmentCount; attachment_idx++) {
4337 const VkClearAttachment *attachment = &pAttachments[attachment_idx];
4338 if (attachment->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) {
4339 VkBool32 found = VK_FALSE;
Chia-I Wu763a7492015-10-26 20:48:51 +08004340 for (uint32_t i = 0; i < pSD->colorAttachmentCount; i++) {
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004341 if (attachment->colorAttachment == pSD->pColorAttachments[i].attachment) {
4342 found = VK_TRUE;
4343 break;
4344 }
4345 }
4346 if (VK_FALSE == found) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004347 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 +08004348 (uint64_t)commandBuffer, 0, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004349 "vkCmdClearAttachments() attachment index %d not found in attachment reference array of active subpass %d",
4350 attachment->colorAttachment, pCB->activeSubpass);
4351 }
4352 } else if (attachment->aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) {
Mark Lobodzinski1523e3a2015-11-17 15:11:24 -07004353 if (!pSD->pDepthStencilAttachment || // Says no DS will be used in active subpass
Mark Lobodzinskiea1fff22015-11-18 08:58:31 -07004354 (pSD->pDepthStencilAttachment->attachment == VK_ATTACHMENT_UNUSED)) { // Says no DS will be used in active subpass
Mark Lobodzinski1523e3a2015-11-17 15:11:24 -07004355
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004356 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 -07004357 (uint64_t)commandBuffer, 0, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
4358 "vkCmdClearAttachments() attachment index %d does not match depthStencilAttachment.attachment (%d) found in active subpass %d",
4359 attachment->colorAttachment,
4360 (pSD->pDepthStencilAttachment) ? pSD->pDepthStencilAttachment->attachment : VK_ATTACHMENT_UNUSED,
4361 pCB->activeSubpass);
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004362 }
4363 }
4364 }
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004365 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004366 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004367 dev_data->device_dispatch_table->CmdClearAttachments(commandBuffer, attachmentCount, pAttachments, rectCount, pRects);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004368}
4369
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004370VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearColorImage(
Chia-I Wu1f851912015-10-27 18:04:07 +08004371 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06004372 VkImage image, VkImageLayout imageLayout,
Chris Forbese3105972015-06-24 14:34:53 +12004373 const VkClearColorValue *pColor,
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06004374 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004375{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004376 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004377 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4378 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004379 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004380 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004381 skipCall |= addCmd(dev_data, pCB, CMD_CLEARCOLORIMAGE);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004382 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004383 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdClearColorImage()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004384 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004385 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearColorImage");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004386 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004387 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004388 dev_data->device_dispatch_table->CmdClearColorImage(commandBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004389}
4390
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004391VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearDepthStencilImage(
Chia-I Wu1f851912015-10-27 18:04:07 +08004392 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter315ad992015-09-15 18:03:22 -06004393 VkImage image, VkImageLayout imageLayout,
4394 const VkClearDepthStencilValue *pDepthStencil,
4395 uint32_t rangeCount,
4396 const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004397{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004398 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004399 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4400 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004401 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004402 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004403 skipCall |= addCmd(dev_data, pCB, CMD_CLEARDEPTHSTENCILIMAGE);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004404 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004405 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdClearDepthStencilImage()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004406 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004407 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearDepthStencilImage");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004408 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004409 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004410 dev_data->device_dispatch_table->CmdClearDepthStencilImage(commandBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004411}
4412
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004413VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResolveImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004414 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu1f851912015-10-27 18:04:07 +08004415 VkImage dstImage, VkImageLayout dstImageLayout,
Tony Barbour11f74372015-04-13 15:02:52 -06004416 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004417{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004418 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004419 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4420 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004421 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004422 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004423 skipCall |= addCmd(dev_data, pCB, CMD_RESOLVEIMAGE);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004424 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004425 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdResolveImage()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004426 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004427 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResolveImage");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004428 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004429 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004430 dev_data->device_dispatch_table->CmdResolveImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004431}
4432
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004433VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004434{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004435 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004436 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4437 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004438 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004439 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004440 skipCall |= addCmd(dev_data, pCB, CMD_SETEVENT);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004441 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004442 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdSetEvent()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004443 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004444 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdSetEvent");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004445 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004446 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004447 dev_data->device_dispatch_table->CmdSetEvent(commandBuffer, event, stageMask);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004448}
4449
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004450VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004451{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004452 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004453 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4454 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004455 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004456 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004457 skipCall |= addCmd(dev_data, pCB, CMD_RESETEVENT);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004458 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004459 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdResetEvent()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004460 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004461 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResetEvent");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004462 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004463 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004464 dev_data->device_dispatch_table->CmdResetEvent(commandBuffer, event, stageMask);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004465}
4466
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004467VkBool32 TransitionImageLayouts(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const void* const* ppMemBarriers) {
Michael Lentine27b0f902015-10-12 11:30:14 -05004468 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4469 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004470 VkBool32 skip = false;
Mark Lobodzinski78940a42015-11-30 16:48:53 -07004471
4472#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4473 // TODO: Fix -- pay attention to image subresource ranges -- not all subresources transition at the same time
4474 return skip;
4475#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4476
Michael Lentine27b0f902015-10-12 11:30:14 -05004477 for (uint32_t i = 0; i < memBarrierCount; ++i) {
4478 auto mem_barrier = reinterpret_cast<const VkMemoryBarrier*>(ppMemBarriers[i]);
4479 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
4480 auto image_mem_barrier = reinterpret_cast<const VkImageMemoryBarrier*>(mem_barrier);
4481 auto image_data = pCB->imageLayoutMap.find(image_mem_barrier->image);
4482 if (image_data == pCB->imageLayoutMap.end()) {
4483 pCB->imageLayoutMap[image_mem_barrier->image].initialLayout = image_mem_barrier->oldLayout;
4484 pCB->imageLayoutMap[image_mem_barrier->image].layout = image_mem_barrier->newLayout;
4485 } else {
4486 if (image_data->second.layout != image_mem_barrier->oldLayout) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004487 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 -07004488 "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 -05004489 }
4490 image_data->second.layout = image_mem_barrier->newLayout;
4491 }
4492 }
4493 }
4494 return skip;
4495}
4496
Michael Lentine8469dd62015-11-20 09:48:52 -08004497// AccessFlags MUST have 'required_bit' set, and may have one or more of 'optional_bits' set.
4498// If required_bit is zero, accessMask must have at least one of 'optional_bits' set
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004499VkBool32 ValidateMaskBits(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout, VkAccessFlags required_bit, VkAccessFlags optional_bits) {
4500 VkBool32 skip_call = false;
Michael Lentine8469dd62015-11-20 09:48:52 -08004501 if ((accessMask & required_bit) || (!required_bit && (accessMask & optional_bits))) {
4502 if (accessMask & !(required_bit | optional_bits)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004503 // TODO: Verify against Valid Use
4504 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 -08004505 "Additional bits in accessMask %d are specified when layout is %s.", accessMask, string_VkImageLayout(layout));
Michael Lentine472af7d2015-10-16 18:08:09 -05004506 }
4507 } else {
Michael Lentine8469dd62015-11-20 09:48:52 -08004508 if (!required_bit) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004509 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 -08004510 "AccessMask %d must contain at least one of access bits %d when layout is %s.",
4511 accessMask, optional_bits, string_VkImageLayout(layout));
4512 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004513 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 -08004514 "AccessMask %d must have required access bit %d and may have optional bits %d when layout is %s.",
4515 accessMask, required_bit, optional_bits,string_VkImageLayout(layout));
4516 }
Michael Lentine472af7d2015-10-16 18:08:09 -05004517 }
4518 return skip_call;
4519}
4520
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004521VkBool32 ValidateMaskBitsFromLayouts(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout) {
4522 VkBool32 skip_call = false;
Michael Lentine8469dd62015-11-20 09:48:52 -08004523 switch (layout) {
4524 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: {
4525 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_COLOR_ATTACHMENT_READ_BIT);
4526 break;
Michael Lentine472af7d2015-10-16 18:08:09 -05004527 }
Michael Lentine8469dd62015-11-20 09:48:52 -08004528 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: {
4529 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT);
4530 break;
Michael Lentine472af7d2015-10-16 18:08:09 -05004531 }
Michael Lentine8469dd62015-11-20 09:48:52 -08004532 case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: {
4533 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_WRITE_BIT, 0);
4534 break;
4535 }
4536 case VK_IMAGE_LAYOUT_PREINITIALIZED: {
4537 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_HOST_WRITE_BIT, 0);
4538 break;
4539 }
4540 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: {
4541 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, 0, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT);
4542 break;
4543 }
4544 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: {
4545 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, 0, VK_ACCESS_INPUT_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT);
4546 break;
4547 }
4548 case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: {
4549 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_READ_BIT, 0);
4550 break;
4551 }
4552 case VK_IMAGE_LAYOUT_UNDEFINED: {
4553 if (accessMask != 0) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004554 // TODO: Verify against Valid Use section spec
4555 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 -08004556 "Additional bits in accessMask %d are specified when layout is %s.", accessMask, string_VkImageLayout(layout));
4557 }
4558 break;
4559 }
4560 case VK_IMAGE_LAYOUT_GENERAL:
4561 default: {
4562 break;
4563 }
Michael Lentine472af7d2015-10-16 18:08:09 -05004564 }
4565 return skip_call;
4566}
4567
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004568VkBool32 ValidateBarriers(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const void* const* ppMemBarriers) {
4569 VkBool32 skip_call = false;
Michael Lentine07ff1a12015-10-15 17:07:00 -05004570 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4571 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4572 if (pCB->activeRenderPass && memBarrierCount) {
4573 for (uint32_t i = 0; i < memBarrierCount; ++i) {
4574 auto mem_barrier = reinterpret_cast<const VkMemoryBarrier*>(ppMemBarriers[i]);
4575 if (mem_barrier && mem_barrier->sType != VK_STRUCTURE_TYPE_MEMORY_BARRIER) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004576 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 -05004577 "Image or Buffers Barriers cannot be used during a render pass.");
4578 }
4579 }
4580 if (!dev_data->renderPassMap[pCB->activeRenderPass]->hasSelfDependency[pCB->activeSubpass]) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004581 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 -05004582 "Barriers cannot be set during subpass %d with no self dependency specified.", pCB->activeSubpass);
4583 }
4584 }
Mark Lobodzinskib684b512015-11-20 09:27:27 -07004585
Michael Lentine472af7d2015-10-16 18:08:09 -05004586 for (uint32_t i = 0; i < memBarrierCount; ++i) {
4587 auto mem_barrier = reinterpret_cast<const VkMemoryBarrier*>(ppMemBarriers[i]);
4588 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
4589 auto image_mem_barrier = reinterpret_cast<const VkImageMemoryBarrier*>(mem_barrier);
Michael Lentine8469dd62015-11-20 09:48:52 -08004590 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, image_mem_barrier->srcAccessMask, image_mem_barrier->oldLayout);
4591 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, image_mem_barrier->dstAccessMask, image_mem_barrier->newLayout);
Michael Lentine472af7d2015-10-16 18:08:09 -05004592 }
4593 }
Mark Lobodzinskib95fc092015-12-03 15:42:32 -07004594
Michael Lentine07ff1a12015-10-15 17:07:00 -05004595 return skip_call;
4596}
4597
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004598VK_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 -06004599{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004600 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004601 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4602 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004603 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004604 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004605 skipCall |= addCmd(dev_data, pCB, CMD_WAITEVENTS);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004606 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004607 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdWaitEvents()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004608 }
Michael Lentine27b0f902015-10-12 11:30:14 -05004609 skipCall |= TransitionImageLayouts(commandBuffer, memoryBarrierCount, ppMemoryBarriers);
Michael Lentine07ff1a12015-10-15 17:07:00 -05004610 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, ppMemoryBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004611 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004612 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004613 dev_data->device_dispatch_table->CmdWaitEvents(commandBuffer, eventCount, pEvents, sourceStageMask, dstStageMask, memoryBarrierCount, ppMemoryBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004614}
4615
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004616VK_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 -06004617{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004618 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004619 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4620 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004621 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004622 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004623 skipCall |= addCmd(dev_data, pCB, CMD_PIPELINEBARRIER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004624 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004625 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdPipelineBarrier()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004626 }
Michael Lentine27b0f902015-10-12 11:30:14 -05004627 skipCall |= TransitionImageLayouts(commandBuffer, memoryBarrierCount, ppMemoryBarriers);
Michael Lentine07ff1a12015-10-15 17:07:00 -05004628 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, ppMemoryBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004629 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004630 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004631 dev_data->device_dispatch_table->CmdPipelineBarrier(commandBuffer, srcStageMask, dstStageMask, dependencyFlags, memoryBarrierCount, ppMemoryBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004632}
4633
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004634VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004635{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004636 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004637 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4638 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004639 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004640 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004641 skipCall |= addCmd(dev_data, pCB, CMD_BEGINQUERY);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004642 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004643 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBeginQuery()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004644 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004645 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004646 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004647 dev_data->device_dispatch_table->CmdBeginQuery(commandBuffer, queryPool, slot, flags);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004648}
4649
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004650VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004651{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004652 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004653 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4654 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004655 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004656 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004657 skipCall |= addCmd(dev_data, pCB, CMD_ENDQUERY);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004658 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004659 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdEndQuery()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004660 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004661 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004662 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004663 dev_data->device_dispatch_table->CmdEndQuery(commandBuffer, queryPool, slot);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004664}
4665
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004666VK_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 -06004667{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004668 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004669 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4670 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004671 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004672 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004673 skipCall |= addCmd(dev_data, pCB, CMD_RESETQUERYPOOL);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004674 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004675 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdResetQueryPool()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004676 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004677 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdQueryPool");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004678 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004679 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004680 dev_data->device_dispatch_table->CmdResetQueryPool(commandBuffer, queryPool, startQuery, queryCount);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004681}
4682
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004683VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t startQuery,
Chia-I Wu1f851912015-10-27 18:04:07 +08004684 uint32_t queryCount, VkBuffer dstBuffer, VkDeviceSize dstOffset,
Chia-I Wu1f6942d2015-10-26 18:36:20 +08004685 VkDeviceSize stride, VkQueryResultFlags flags)
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06004686{
4687 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004688 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4689 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06004690 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004691 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004692 skipCall |= addCmd(dev_data, pCB, CMD_COPYQUERYPOOLRESULTS);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06004693 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004694 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdCopyQueryPoolResults()");
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06004695 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004696 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyQueryPoolResults");
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06004697 }
4698 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004699 dev_data->device_dispatch_table->CmdCopyQueryPoolResults(commandBuffer, queryPool,
4700 startQuery, queryCount, dstBuffer, dstOffset, stride, flags);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06004701}
4702
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004703VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004704{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004705 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004706 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4707 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004708 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004709 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004710 skipCall |= addCmd(dev_data, pCB, CMD_WRITETIMESTAMP);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004711 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004712 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdWriteTimestamp()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004713 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004714 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004715 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004716 dev_data->device_dispatch_table->CmdWriteTimestamp(commandBuffer, pipelineStage, queryPool, slot);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004717}
4718
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004719VK_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 -06004720{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06004721 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08004722 VkResult result = dev_data->device_dispatch_table->CreateFramebuffer(device, pCreateInfo, pAllocator, pFramebuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06004723 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06004724 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004725 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Chia-I Wuc278df82015-07-07 11:50:03 +08004726 if (pCreateInfo->pAttachments) {
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -06004727 localFBCI->pAttachments = new VkImageView[localFBCI->attachmentCount];
4728 memcpy((void*)localFBCI->pAttachments, pCreateInfo->pAttachments, localFBCI->attachmentCount*sizeof(VkImageView));
Tobin Ehlis2464b882015-04-01 08:40:34 -06004729 }
Chia-I Wue420a332015-10-26 20:04:44 +08004730 dev_data->frameBufferMap[*pFramebuffer] = localFBCI;
Tobin Ehlis2464b882015-04-01 08:40:34 -06004731 }
4732 return result;
4733}
4734
Michael Lentine329697b2015-10-06 14:56:18 -07004735// Store the DAG.
4736struct DAGNode {
4737 uint32_t pass;
4738 std::vector<uint32_t> prev;
4739 std::vector<uint32_t> next;
4740};
4741
Courtney Goeltzenleuchterf2bca902015-11-03 15:41:43 -07004742VkBool32 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 -07004743 // If we have already checked this node we have not found a dependency path so return false.
4744 if (processed_nodes.count(index))
4745 return false;
4746 processed_nodes.insert(index);
4747 const DAGNode& node = subpass_to_node[index];
4748 // Look for a dependency path. If one exists return true else recurse on the previous nodes.
4749 if (std::find(node.prev.begin(), node.prev.end(), dependent) == node.prev.end()) {
4750 for (auto elem : node.prev) {
4751 if (FindDependency(elem, dependent, subpass_to_node, processed_nodes))
4752 return true;
4753 }
4754 } else {
4755 return true;
4756 }
4757 return false;
4758}
4759
Courtney Goeltzenleuchterf2bca902015-11-03 15:41:43 -07004760VkBool32 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) {
4761 VkBool32 result = true;
Michael Lentine329697b2015-10-06 14:56:18 -07004762 // Loop through all subpasses that share the same attachment and make sure a dependency exists
4763 for (uint32_t k = 0; k < dependent_subpasses.size(); ++k) {
4764 if (subpass == dependent_subpasses[k])
4765 continue;
4766 const DAGNode& node = subpass_to_node[subpass];
4767 // Check for a specified dependency between the two nodes. If one exists we are done.
4768 auto prev_elem = std::find(node.prev.begin(), node.prev.end(), dependent_subpasses[k]);
4769 auto next_elem = std::find(node.next.begin(), node.next.end(), dependent_subpasses[k]);
4770 if (prev_elem == node.prev.end() && next_elem == node.next.end()) {
4771 // If no dependency exits an implicit dependency still might. If so, warn and if not throw an error.
4772 std::unordered_set<uint32_t> processed_nodes;
4773 if (FindDependency(subpass, dependent_subpasses[k], subpass_to_node, processed_nodes) ||
4774 FindDependency(dependent_subpasses[k], subpass, subpass_to_node, processed_nodes)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004775 // TODO: Verify against Valid Use section of spec
4776 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 -07004777 "A dependency between subpasses %d and %d must exist but only an implicit one is specified.",
4778 subpass, dependent_subpasses[k]);
4779 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004780 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 -07004781 "A dependency between subpasses %d and %d must exist but one is not specified.",
4782 subpass, dependent_subpasses[k]);
4783 result = false;
4784 }
4785 }
4786 }
4787 return result;
4788}
4789
Courtney Goeltzenleuchterf2bca902015-11-03 15:41:43 -07004790VkBool32 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 -07004791 const DAGNode& node = subpass_to_node[index];
4792 // If this node writes to the attachment return true as next nodes need to preserve the attachment.
4793 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Chia-I Wu763a7492015-10-26 20:48:51 +08004794 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentine329697b2015-10-06 14:56:18 -07004795 if (attachment == subpass.pColorAttachments[j].attachment)
Courtney Goeltzenleuchterf2bca902015-11-03 15:41:43 -07004796 return VK_TRUE;
Michael Lentine329697b2015-10-06 14:56:18 -07004797 }
Chia-I Wuce532f72015-10-26 17:32:47 +08004798 if (subpass.pDepthStencilAttachment &&
4799 subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
4800 if (attachment == subpass.pDepthStencilAttachment->attachment)
Courtney Goeltzenleuchterf2bca902015-11-03 15:41:43 -07004801 return VK_TRUE;
Michael Lentine329697b2015-10-06 14:56:18 -07004802 }
Courtney Goeltzenleuchterf2bca902015-11-03 15:41:43 -07004803 VkBool32 result = VK_FALSE;
Michael Lentine329697b2015-10-06 14:56:18 -07004804 // Loop through previous nodes and see if any of them write to the attachment.
4805 for (auto elem : node.prev) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004806 result |= CheckPreserved(my_data, device, pCreateInfo, elem, attachment, subpass_to_node, depth + 1, skip_call);
Michael Lentine329697b2015-10-06 14:56:18 -07004807 }
4808 // If the attachment was written to by a previous node than this node needs to preserve it.
4809 if (result && depth > 0) {
4810 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Courtney Goeltzenleuchterf2bca902015-11-03 15:41:43 -07004811 VkBool32 has_preserved = false;
Chia-I Wu763a7492015-10-26 20:48:51 +08004812 for (uint32_t j = 0; j < subpass.preserveAttachmentCount; ++j) {
Michael Lentine329697b2015-10-06 14:56:18 -07004813 if (subpass.pPreserveAttachments[j].attachment == attachment) {
4814 has_preserved = true;
4815 break;
4816 }
4817 }
4818 if (!has_preserved) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004819 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 -07004820 "Attachment %d is used by a later subpass and must be preserved in subpass %d.", attachment, index);
4821 }
4822 }
4823 return result;
4824}
4825
Michael Lentine27b0f902015-10-12 11:30:14 -05004826VkBool32 ValidateDependencies(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, std::vector<DAGNode>& subpass_to_node) {
4827 VkBool32 skip_call = false;
Michael Lentine329697b2015-10-06 14:56:18 -07004828 std::vector<std::vector<uint32_t>> output_attachment_to_subpass(pCreateInfo->attachmentCount);
4829 std::vector<std::vector<uint32_t>> input_attachment_to_subpass(pCreateInfo->attachmentCount);
Michael Lentine27b0f902015-10-12 11:30:14 -05004830
Michael Lentine329697b2015-10-06 14:56:18 -07004831 // Create DAG
4832 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
4833 DAGNode& subpass_node = subpass_to_node[i];
4834 subpass_node.pass = i;
4835 }
4836 for (uint32_t i = 0; i < pCreateInfo->dependencyCount; ++i) {
4837 const VkSubpassDependency& dependency = pCreateInfo->pDependencies[i];
Chia-I Wu1f851912015-10-27 18:04:07 +08004838 if (dependency.srcSubpass > dependency.dstSubpass) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004839 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 -07004840 "Dependency graph must be specified such that an earlier pass cannot depend on a later pass.");
4841 }
Chia-I Wu1f851912015-10-27 18:04:07 +08004842 subpass_to_node[dependency.dstSubpass].prev.push_back(dependency.srcSubpass);
4843 subpass_to_node[dependency.srcSubpass].next.push_back(dependency.dstSubpass);
Michael Lentine329697b2015-10-06 14:56:18 -07004844 }
Michael Lentine27b0f902015-10-12 11:30:14 -05004845
Michael Lentine329697b2015-10-06 14:56:18 -07004846 // Find for each attachment the subpasses that use them.
4847 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
4848 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wu763a7492015-10-26 20:48:51 +08004849 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Michael Lentine329697b2015-10-06 14:56:18 -07004850 input_attachment_to_subpass[subpass.pInputAttachments[j].attachment].push_back(i);
4851 }
Chia-I Wu763a7492015-10-26 20:48:51 +08004852 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentine329697b2015-10-06 14:56:18 -07004853 output_attachment_to_subpass[subpass.pColorAttachments[j].attachment].push_back(i);
4854 }
Chia-I Wuce532f72015-10-26 17:32:47 +08004855 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
4856 output_attachment_to_subpass[subpass.pDepthStencilAttachment->attachment].push_back(i);
Michael Lentine329697b2015-10-06 14:56:18 -07004857 }
4858 }
4859 // If there is a dependency needed make sure one exists
4860 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
4861 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
4862 // If the attachment is an input then all subpasses that output must have a dependency relationship
Chia-I Wu763a7492015-10-26 20:48:51 +08004863 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Michael Lentine329697b2015-10-06 14:56:18 -07004864 const uint32_t& attachment = subpass.pInputAttachments[j].attachment;
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004865 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentine329697b2015-10-06 14:56:18 -07004866 }
4867 // 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 +08004868 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentine329697b2015-10-06 14:56:18 -07004869 const uint32_t& attachment = subpass.pColorAttachments[j].attachment;
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004870 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
4871 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentine329697b2015-10-06 14:56:18 -07004872 }
Chia-I Wuce532f72015-10-26 17:32:47 +08004873 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
4874 const uint32_t& attachment = subpass.pDepthStencilAttachment->attachment;
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004875 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
4876 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentine329697b2015-10-06 14:56:18 -07004877 }
4878 }
4879 // Loop through implicit dependencies, if this pass reads make sure the attachment is preserved for all passes after it was written.
4880 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
4881 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wu763a7492015-10-26 20:48:51 +08004882 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004883 CheckPreserved(my_data, device, pCreateInfo, i, subpass.pInputAttachments[j].attachment, subpass_to_node, 0, skip_call);
Michael Lentine329697b2015-10-06 14:56:18 -07004884 }
4885 }
4886 return skip_call;
4887}
4888
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004889VkBool32 ValidateLayouts(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo) {
4890 VkBool32 skip = false;
Mark Lobodzinski78940a42015-11-30 16:48:53 -07004891
4892#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4893 return skip;
4894#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4895
Michael Lentine27b0f902015-10-12 11:30:14 -05004896 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
4897 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
4898 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
4899 if (subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL &&
4900 subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) {
4901 if (subpass.pInputAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004902 // TODO: Verify Valid Use in spec. I believe this is allowed (valid) but may not be optimal performance
4903 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 -05004904 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
4905 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004906 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 -05004907 "Layout for input attachment is %d but can only be READ_ONLY_OPTIMAL or GENERAL.", subpass.pInputAttachments[j].attachment);
4908 }
4909 }
4910 }
4911 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
4912 if (subpass.pColorAttachments[j].layout != VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) {
4913 if (subpass.pColorAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004914 // TODO: Verify Valid Use in spec. I believe this is allowed (valid) but may not be optimal performance
4915 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 -05004916 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
4917 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004918 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 -05004919 "Layout for color attachment is %d but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.", subpass.pColorAttachments[j].attachment);
4920 }
4921 }
4922 }
Mark Lobodzinskic344bef2015-10-28 13:03:56 -06004923 if ((subpass.pDepthStencilAttachment != NULL) &&
4924 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
Michael Lentine27b0f902015-10-12 11:30:14 -05004925 if (subpass.pDepthStencilAttachment->layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) {
4926 if (subpass.pDepthStencilAttachment->layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004927 // TODO: Verify Valid Use in spec. I believe this is allowed (valid) but may not be optimal performance
4928 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 -05004929 "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL.");
4930 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004931 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 -05004932 "Layout for depth attachment is %d but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL.", subpass.pDepthStencilAttachment->attachment);
4933 }
4934 }
4935 }
4936 }
4937 return skip;
4938}
4939
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004940VkBool32 CreatePassDAG(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, std::vector<DAGNode>& subpass_to_node, std::vector<bool>& has_self_dependency) {
4941 VkBool32 skip_call = false;
Michael Lentine27b0f902015-10-12 11:30:14 -05004942 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
4943 DAGNode& subpass_node = subpass_to_node[i];
4944 subpass_node.pass = i;
4945 }
4946 for (uint32_t i = 0; i < pCreateInfo->dependencyCount; ++i) {
4947 const VkSubpassDependency& dependency = pCreateInfo->pDependencies[i];
4948 if (dependency.srcSubpass > dependency.dstSubpass) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004949 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 -05004950 "Depedency graph must be specified such that an earlier pass cannot depend on a later pass.");
Michael Lentine07ff1a12015-10-15 17:07:00 -05004951 } else if (dependency.srcSubpass == dependency.dstSubpass) {
4952 has_self_dependency[dependency.srcSubpass] = true;
Michael Lentine27b0f902015-10-12 11:30:14 -05004953 }
4954 subpass_to_node[dependency.dstSubpass].prev.push_back(dependency.srcSubpass);
4955 subpass_to_node[dependency.srcSubpass].next.push_back(dependency.dstSubpass);
4956 }
4957 return skip_call;
4958}
Tobin Ehliscb085292015-12-01 09:57:09 -07004959// TODOSC : Add intercept of vkCreateShaderModule
Michael Lentine27b0f902015-10-12 11:30:14 -05004960
Tobin Ehlis32479352015-12-01 09:48:58 -07004961VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateShaderModule(
4962 VkDevice device,
4963 const VkShaderModuleCreateInfo *pCreateInfo,
4964 const VkAllocationCallbacks* pAllocator,
4965 VkShaderModule *pShaderModule)
4966{
4967 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004968 VkBool32 skip_call = false;
Tobin Ehlis32479352015-12-01 09:48:58 -07004969 if (!shader_is_spirv(pCreateInfo)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004970 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 -07004971 /* dev */ 0, 0, SHADER_CHECKER_NON_SPIRV_SHADER, "SC",
4972 "Shader is not SPIR-V");
4973 }
4974
4975 if (skip_call)
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07004976 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis32479352015-12-01 09:48:58 -07004977
4978 VkResult res = my_data->device_dispatch_table->CreateShaderModule(device, pCreateInfo, pAllocator, pShaderModule);
4979
4980 if (res == VK_SUCCESS) {
4981 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisad61de42015-12-02 13:53:34 -07004982 my_data->shaderModuleMap[*pShaderModule] = new shader_module(pCreateInfo);
Tobin Ehlis32479352015-12-01 09:48:58 -07004983 loader_platform_thread_unlock_mutex(&globalLock);
4984 }
4985 return res;
4986}
4987
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004988VK_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 -06004989{
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004990 VkBool32 skip_call = false;
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004991 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentine27b0f902015-10-12 11:30:14 -05004992 // Create DAG
Michael Lentine07ff1a12015-10-15 17:07:00 -05004993 std::vector<bool> has_self_dependency(pCreateInfo->subpassCount);
Michael Lentine27b0f902015-10-12 11:30:14 -05004994 std::vector<DAGNode> subpass_to_node(pCreateInfo->subpassCount);
Michael Lentine07ff1a12015-10-15 17:07:00 -05004995 skip_call |= CreatePassDAG(dev_data, device, pCreateInfo, subpass_to_node, has_self_dependency);
Michael Lentine27b0f902015-10-12 11:30:14 -05004996 // Validate using DAG
4997 skip_call |= ValidateDependencies(dev_data, device, pCreateInfo, subpass_to_node);
4998 skip_call |= ValidateLayouts(dev_data, device, pCreateInfo);
4999 if (skip_call) {
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07005000 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine329697b2015-10-06 14:56:18 -07005001 }
Chia-I Wu69f40122015-10-26 21:10:41 +08005002 VkResult result = dev_data->device_dispatch_table->CreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005003 if (VK_SUCCESS == result) {
Tobin Ehliscb085292015-12-01 09:57:09 -07005004 // TODOSC : Merge in tracking of renderpass from ShaderChecker
Tobin Ehlis2464b882015-04-01 08:40:34 -06005005 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06005006 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Chia-I Wuc278df82015-07-07 11:50:03 +08005007 if (pCreateInfo->pAttachments) {
5008 localRPCI->pAttachments = new VkAttachmentDescription[localRPCI->attachmentCount];
5009 memcpy((void*)localRPCI->pAttachments, pCreateInfo->pAttachments, localRPCI->attachmentCount*sizeof(VkAttachmentDescription));
Tobin Ehlis2464b882015-04-01 08:40:34 -06005010 }
Chia-I Wuc278df82015-07-07 11:50:03 +08005011 if (pCreateInfo->pSubpasses) {
5012 localRPCI->pSubpasses = new VkSubpassDescription[localRPCI->subpassCount];
5013 memcpy((void*)localRPCI->pSubpasses, pCreateInfo->pSubpasses, localRPCI->subpassCount*sizeof(VkSubpassDescription));
5014
5015 for (uint32_t i = 0; i < localRPCI->subpassCount; i++) {
5016 VkSubpassDescription *subpass = (VkSubpassDescription *) &localRPCI->pSubpasses[i];
Chia-I Wu763a7492015-10-26 20:48:51 +08005017 const uint32_t attachmentCount = subpass->inputAttachmentCount +
5018 subpass->colorAttachmentCount * (1 + (subpass->pResolveAttachments?1:0)) +
Chia-I Wuce532f72015-10-26 17:32:47 +08005019 ((subpass->pDepthStencilAttachment) ? 1 : 0) + subpass->preserveAttachmentCount;
Chia-I Wuc278df82015-07-07 11:50:03 +08005020 VkAttachmentReference *attachments = new VkAttachmentReference[attachmentCount];
5021
Cody Northrop6de6b0b2015-08-04 11:16:41 -06005022 memcpy(attachments, subpass->pInputAttachments,
Chia-I Wu763a7492015-10-26 20:48:51 +08005023 sizeof(attachments[0]) * subpass->inputAttachmentCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06005024 subpass->pInputAttachments = attachments;
Chia-I Wu763a7492015-10-26 20:48:51 +08005025 attachments += subpass->inputAttachmentCount;
Chia-I Wuc278df82015-07-07 11:50:03 +08005026
Cody Northrop6de6b0b2015-08-04 11:16:41 -06005027 memcpy(attachments, subpass->pColorAttachments,
Chia-I Wu763a7492015-10-26 20:48:51 +08005028 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06005029 subpass->pColorAttachments = attachments;
Chia-I Wu763a7492015-10-26 20:48:51 +08005030 attachments += subpass->colorAttachmentCount;
Chia-I Wuc278df82015-07-07 11:50:03 +08005031
Cody Northrop6de6b0b2015-08-04 11:16:41 -06005032 if (subpass->pResolveAttachments) {
5033 memcpy(attachments, subpass->pResolveAttachments,
Chia-I Wu763a7492015-10-26 20:48:51 +08005034 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06005035 subpass->pResolveAttachments = attachments;
Chia-I Wu763a7492015-10-26 20:48:51 +08005036 attachments += subpass->colorAttachmentCount;
Chia-I Wuc278df82015-07-07 11:50:03 +08005037 }
5038
Chia-I Wuce532f72015-10-26 17:32:47 +08005039 if (subpass->pDepthStencilAttachment) {
5040 memcpy(attachments, subpass->pDepthStencilAttachment,
5041 sizeof(attachments[0]) * 1);
5042 subpass->pDepthStencilAttachment = attachments;
5043 attachments += 1;
5044 }
5045
Cody Northrop6de6b0b2015-08-04 11:16:41 -06005046 memcpy(attachments, subpass->pPreserveAttachments,
Chia-I Wu763a7492015-10-26 20:48:51 +08005047 sizeof(attachments[0]) * subpass->preserveAttachmentCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06005048 subpass->pPreserveAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08005049 }
Tobin Ehlis2464b882015-04-01 08:40:34 -06005050 }
Chia-I Wuc278df82015-07-07 11:50:03 +08005051 if (pCreateInfo->pDependencies) {
5052 localRPCI->pDependencies = new VkSubpassDependency[localRPCI->dependencyCount];
5053 memcpy((void*)localRPCI->pDependencies, pCreateInfo->pDependencies, localRPCI->dependencyCount*sizeof(VkSubpassDependency));
Tobin Ehlis2464b882015-04-01 08:40:34 -06005054 }
Tobin Ehlis32479352015-12-01 09:48:58 -07005055 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisad61de42015-12-02 13:53:34 -07005056 dev_data->renderPassMap[*pRenderPass] = new RENDER_PASS_NODE(localRPCI);
Michael Lentine07ff1a12015-10-15 17:07:00 -05005057 dev_data->renderPassMap[*pRenderPass]->hasSelfDependency = has_self_dependency;
Tobin Ehlis32479352015-12-01 09:48:58 -07005058 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis2464b882015-04-01 08:40:34 -06005059 }
5060 return result;
5061}
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005062// Free the renderpass shadow
5063static void deleteRenderPasses(layer_data* my_data)
5064{
5065 if (my_data->renderPassMap.size() <= 0)
5066 return;
5067 for (auto ii=my_data->renderPassMap.begin(); ii!=my_data->renderPassMap.end(); ++ii) {
Tobin Ehlisad61de42015-12-02 13:53:34 -07005068 const VkRenderPassCreateInfo* pRenderPassInfo = (*ii).second->pCreateInfo;
Michael Lentine07ff1a12015-10-15 17:07:00 -05005069 if (pRenderPassInfo->pAttachments) {
5070 delete[] pRenderPassInfo->pAttachments;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005071 }
Michael Lentine07ff1a12015-10-15 17:07:00 -05005072 if (pRenderPassInfo->pSubpasses) {
5073 for (uint32_t i=0; i<pRenderPassInfo->subpassCount; ++i) {
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005074 // Attachements are all allocated in a block, so just need to
5075 // find the first non-null one to delete
Michael Lentine07ff1a12015-10-15 17:07:00 -05005076 if (pRenderPassInfo->pSubpasses[i].pInputAttachments) {
5077 delete[] pRenderPassInfo->pSubpasses[i].pInputAttachments;
5078 } else if (pRenderPassInfo->pSubpasses[i].pColorAttachments) {
5079 delete[] pRenderPassInfo->pSubpasses[i].pColorAttachments;
5080 } else if (pRenderPassInfo->pSubpasses[i].pResolveAttachments) {
5081 delete[] pRenderPassInfo->pSubpasses[i].pResolveAttachments;
5082 } else if (pRenderPassInfo->pSubpasses[i].pPreserveAttachments) {
5083 delete[] pRenderPassInfo->pSubpasses[i].pPreserveAttachments;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005084 }
5085 }
Michael Lentine07ff1a12015-10-15 17:07:00 -05005086 delete[] pRenderPassInfo->pSubpasses;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005087 }
Michael Lentine07ff1a12015-10-15 17:07:00 -05005088 if (pRenderPassInfo->pDependencies) {
5089 delete[] pRenderPassInfo->pDependencies;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005090 }
Tobin Ehlisad61de42015-12-02 13:53:34 -07005091 delete pRenderPassInfo;
Michael Lentine07ff1a12015-10-15 17:07:00 -05005092 delete (*ii).second;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005093 }
5094 my_data->renderPassMap.clear();
5095}
Michael Lentine27b0f902015-10-12 11:30:14 -05005096
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07005097VkBool32 VerifyFramebufferAndRenderPassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
5098 VkBool32 skip_call = false;
Michael Lentine27b0f902015-10-12 11:30:14 -05005099 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5100 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Tobin Ehlisad61de42015-12-02 13:53:34 -07005101 const VkRenderPassCreateInfo* pRenderPassInfo = dev_data->renderPassMap[pRenderPassBegin->renderPass]->pCreateInfo;
Michael Lentine27b0f902015-10-12 11:30:14 -05005102 const VkFramebufferCreateInfo* pFramebufferInfo = dev_data->frameBufferMap[pRenderPassBegin->framebuffer];
5103 if (pRenderPassInfo->attachmentCount != pFramebufferInfo->attachmentCount) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005104 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 -05005105 "You cannot start a render pass using a framebuffer with a different number of attachments.");
5106 }
5107 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
5108 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
5109 const VkImage& image = dev_data->imageViewMap[image_view]->image;
5110 auto image_data = pCB->imageLayoutMap.find(image);
5111 if (image_data == pCB->imageLayoutMap.end()) {
5112 pCB->imageLayoutMap[image].initialLayout = pRenderPassInfo->pAttachments[i].initialLayout;
5113 pCB->imageLayoutMap[image].layout = pRenderPassInfo->pAttachments[i].initialLayout;
5114 } else if (pRenderPassInfo->pAttachments[i].initialLayout != image_data->second.layout) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005115 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 -05005116 "You cannot start a render pass using attachment %i where the intial layout differs from the starting layout.", i);
5117 }
5118 }
5119 return skip_call;
5120}
5121
5122void TransitionSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, const int subpass_index) {
5123 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5124 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5125 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
5126 if (render_pass_data == dev_data->renderPassMap.end()) {
5127 return;
5128 }
Tobin Ehlisad61de42015-12-02 13:53:34 -07005129 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
Michael Lentine27b0f902015-10-12 11:30:14 -05005130 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
5131 if (framebuffer_data == dev_data->frameBufferMap.end()) {
5132 return;
5133 }
5134 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
5135 const VkSubpassDescription& subpass = pRenderPassInfo->pSubpasses[subpass_index];
5136 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
5137 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pInputAttachments[j].attachment];
5138 auto image_view_data = dev_data->imageViewMap.find(image_view);
5139 if (image_view_data != dev_data->imageViewMap.end()) {
5140 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5141 if (image_layout != pCB->imageLayoutMap.end()) {
5142 image_layout->second.layout = subpass.pInputAttachments[j].layout;
5143 }
5144 }
5145 }
5146 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
5147 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pColorAttachments[j].attachment];
5148 auto image_view_data = dev_data->imageViewMap.find(image_view);
5149 if (image_view_data != dev_data->imageViewMap.end()) {
5150 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5151 if (image_layout != pCB->imageLayoutMap.end()) {
5152 image_layout->second.layout = subpass.pColorAttachments[j].layout;
5153 }
5154 }
5155 }
Michael Lentine2b9eda42015-10-28 15:55:18 -07005156 if ((subpass.pDepthStencilAttachment != NULL) &&
Mark Lobodzinskic344bef2015-10-28 13:03:56 -06005157 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
Michael Lentine27b0f902015-10-12 11:30:14 -05005158 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pDepthStencilAttachment->attachment];
5159 auto image_view_data = dev_data->imageViewMap.find(image_view);
5160 if (image_view_data != dev_data->imageViewMap.end()) {
5161 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5162 if (image_layout != pCB->imageLayoutMap.end()) {
5163 image_layout->second.layout = subpass.pDepthStencilAttachment->layout;
5164 }
5165 }
5166 }
5167}
5168
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07005169VkBool32 validatePrimaryCommandBuffer(const layer_data* my_data, const GLOBAL_CB_NODE* pCB, const std::string& cmd_name) {
5170 VkBool32 skip_call = false;
Michael Lentine2b9eda42015-10-28 15:55:18 -07005171 if (pCB->createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005172 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 -07005173 "Cannot execute command %s on a secondary command buffer.", cmd_name.c_str());
5174 }
5175 return skip_call;
5176}
5177
Michael Lentine27b0f902015-10-12 11:30:14 -05005178void TransitionFinalSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
5179 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5180 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5181 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
5182 if (render_pass_data == dev_data->renderPassMap.end()) {
5183 return;
5184 }
Tobin Ehlisad61de42015-12-02 13:53:34 -07005185 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
Michael Lentine27b0f902015-10-12 11:30:14 -05005186 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
5187 if (framebuffer_data == dev_data->frameBufferMap.end()) {
5188 return;
5189 }
5190 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
5191 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
5192 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
5193 auto image_view_data = dev_data->imageViewMap.find(image_view);
5194 if (image_view_data != dev_data->imageViewMap.end()) {
5195 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5196 if (image_layout != pCB->imageLayoutMap.end()) {
5197 image_layout->second.layout = pRenderPassInfo->pAttachments[i].finalLayout;
5198 }
5199 }
5200 }
5201}
5202
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005203VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, VkSubpassContents contents)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005204{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005205 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08005206 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5207 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005208 if (pCB) {
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06005209 if (pRenderPassBegin && pRenderPassBegin->renderPass) {
Mark Lobodzinskic344bef2015-10-28 13:03:56 -06005210 skipCall |= VerifyFramebufferAndRenderPassLayouts(commandBuffer, pRenderPassBegin);
Tobin Ehlis42d440c2015-10-20 17:06:16 -06005211 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBeginRenderPass");
Michael Lentine2b9eda42015-10-28 15:55:18 -07005212 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdBeginRenderPass");
Tobin Ehlis42d440c2015-10-20 17:06:16 -06005213 skipCall |= addCmd(dev_data, pCB, CMD_BEGINRENDERPASS);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06005214 pCB->activeRenderPass = pRenderPassBegin->renderPass;
Michael Lentine27b0f902015-10-12 11:30:14 -05005215 // This is a shallow copy as that is all that is needed for now
5216 pCB->activeRenderPassBeginInfo = *pRenderPassBegin;
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06005217 pCB->activeSubpass = 0;
5218 pCB->framebuffer = pRenderPassBegin->framebuffer;
5219 if (pCB->lastBoundPipeline) {
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005220 skipCall |= validatePipelineState(dev_data, pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06005221 }
Tobin Ehlise4076782015-06-24 15:53:07 -06005222 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005223 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 -06005224 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tony Barbourb9f82ba2015-04-06 11:09:26 -06005225 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005226 }
Mark Lobodzinskic344bef2015-10-28 13:03:56 -06005227 if (VK_FALSE == skipCall) {
Chia-I Wu1f851912015-10-27 18:04:07 +08005228 dev_data->device_dispatch_table->CmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents);
Mark Lobodzinskic344bef2015-10-28 13:03:56 -06005229 // This is a shallow copy as that is all that is needed for now
5230 dev_data->renderPassBeginInfo = *pRenderPassBegin;
5231 dev_data->currentSubpass = 0;
5232 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005233}
5234
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005235VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents)
Chia-I Wuc278df82015-07-07 11:50:03 +08005236{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005237 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08005238 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5239 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Michael Lentine27b0f902015-10-12 11:30:14 -05005240 TransitionSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo, ++dev_data->currentSubpass);
Chia-I Wuc278df82015-07-07 11:50:03 +08005241 if (pCB) {
Michael Lentine2b9eda42015-10-28 15:55:18 -07005242 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdNextSubpass");
Tobin Ehlis42d440c2015-10-20 17:06:16 -06005243 skipCall |= addCmd(dev_data, pCB, CMD_NEXTSUBPASS);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06005244 pCB->activeSubpass++;
Tony Barbourcbc0fa82015-12-15 10:24:45 -07005245 TransitionSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo, pCB->activeSubpass);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06005246 if (pCB->lastBoundPipeline) {
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005247 skipCall |= validatePipelineState(dev_data, pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Chia-I Wuc278df82015-07-07 11:50:03 +08005248 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06005249 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdNextSubpass");
Chia-I Wuc278df82015-07-07 11:50:03 +08005250 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005251 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08005252 dev_data->device_dispatch_table->CmdNextSubpass(commandBuffer, contents);
Chia-I Wuc278df82015-07-07 11:50:03 +08005253}
5254
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005255VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndRenderPass(VkCommandBuffer commandBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005256{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005257 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08005258 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5259 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Michael Lentine27b0f902015-10-12 11:30:14 -05005260 TransitionFinalSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005261 if (pCB) {
Michael Lentine2b9eda42015-10-28 15:55:18 -07005262 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdEndRenderpass");
Michael Lentine2b9eda42015-10-28 15:55:18 -07005263 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdEndRenderPass");
Tobin Ehlis42d440c2015-10-20 17:06:16 -06005264 skipCall |= addCmd(dev_data, pCB, CMD_ENDRENDERPASS);
Michael Lentine27b0f902015-10-12 11:30:14 -05005265 TransitionFinalSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06005266 pCB->activeRenderPass = 0;
5267 pCB->activeSubpass = 0;
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08005268 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005269 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08005270 dev_data->device_dispatch_table->CmdEndRenderPass(commandBuffer);
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08005271}
5272
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005273VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount, const VkCommandBuffer* pCommandBuffers)
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08005274{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005275 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08005276 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5277 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08005278 if (pCB) {
Tobin Ehlis5f728d32015-09-17 14:18:16 -06005279 GLOBAL_CB_NODE* pSubCB = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08005280 for (uint32_t i=0; i<commandBuffersCount; i++) {
5281 pSubCB = getCBNode(dev_data, pCommandBuffers[i]);
Tobin Ehlis5f728d32015-09-17 14:18:16 -06005282 if (!pSubCB) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005283 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 +08005284 "vkCmdExecuteCommands() called w/ invalid Cmd Buffer %p in element %u of pCommandBuffers array.", (void*)pCommandBuffers[i], i);
5285 } else if (VK_COMMAND_BUFFER_LEVEL_PRIMARY == pSubCB->createInfo.level) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005286 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 +08005287 "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 Ehlis5f728d32015-09-17 14:18:16 -06005288 }
5289 }
Michael Lentine2b9eda42015-10-28 15:55:18 -07005290 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdExecuteComands");
Tobin Ehlis42d440c2015-10-20 17:06:16 -06005291 skipCall |= addCmd(dev_data, pCB, CMD_EXECUTECOMMANDS);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005292 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005293 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08005294 dev_data->device_dispatch_table->CmdExecuteCommands(commandBuffer, commandBuffersCount, pCommandBuffers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005295}
5296
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07005297VkBool32 ValidateMapImageLayouts(VkDevice device, VkDeviceMemory mem) {
5298 VkBool32 skip_call = false;
Michael Lentineee4ad4d2015-10-23 12:41:44 -07005299 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5300 auto mem_data = dev_data->memImageMap.find(mem);
5301 if (mem_data != dev_data->memImageMap.end()) {
5302 auto image_data = dev_data->imageLayoutMap.find(mem_data->second);
5303 if (image_data != dev_data->imageLayoutMap.end()) {
5304 if (image_data->second->layout != VK_IMAGE_LAYOUT_PREINITIALIZED && image_data->second->layout != VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005305 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 -07005306 "Cannot map an image with layout %d. Only GENERAL or PREINITIALIZED are supported.", image_data->second->layout);
5307 }
5308 }
5309 }
5310 return skip_call;
5311}
5312
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005313VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkMapMemory(
Michael Lentineee4ad4d2015-10-23 12:41:44 -07005314 VkDevice device,
5315 VkDeviceMemory mem,
5316 VkDeviceSize offset,
5317 VkDeviceSize size,
5318 VkFlags flags,
5319 void **ppData)
5320{
5321 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski78940a42015-11-30 16:48:53 -07005322
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07005323 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski78940a42015-11-30 16:48:53 -07005324#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
5325 skip_call = ValidateMapImageLayouts(device, mem);
5326#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5327
Michael Lentineee4ad4d2015-10-23 12:41:44 -07005328 if (VK_FALSE == skip_call) {
5329 return dev_data->device_dispatch_table->MapMemory(device, mem, offset, size, flags, ppData);
5330 }
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07005331 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentineee4ad4d2015-10-23 12:41:44 -07005332}
5333
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005334VKAPI_ATTR VkResult VKAPI_CALL vkBindImageMemory(
Michael Lentineee4ad4d2015-10-23 12:41:44 -07005335 VkDevice device,
5336 VkImage image,
5337 VkDeviceMemory mem,
5338 VkDeviceSize memOffset)
5339{
5340 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5341 VkResult result = dev_data->device_dispatch_table->BindImageMemory(device, image, mem, memOffset);
5342 loader_platform_thread_lock_mutex(&globalLock);
5343 dev_data->memImageMap[mem] = image;
5344 loader_platform_thread_unlock_mutex(&globalLock);
5345 return result;
5346}
5347
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005348VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(
Michael Lentine27b0f902015-10-12 11:30:14 -05005349 VkDevice device,
5350 const VkSwapchainCreateInfoKHR *pCreateInfo,
Ian Elliottc623ba52015-11-20 14:13:17 -07005351 const VkAllocationCallbacks *pAllocator,
Michael Lentine27b0f902015-10-12 11:30:14 -05005352 VkSwapchainKHR *pSwapchain)
5353{
5354 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliottc623ba52015-11-20 14:13:17 -07005355 VkResult result = dev_data->device_dispatch_table->CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
Michael Lentine27b0f902015-10-12 11:30:14 -05005356
5357 if (VK_SUCCESS == result) {
5358 SWAPCHAIN_NODE *swapchain_data = new SWAPCHAIN_NODE;
5359 loader_platform_thread_lock_mutex(&globalLock);
5360 dev_data->device_extensions.swapchainMap[*pSwapchain] = swapchain_data;
5361 loader_platform_thread_unlock_mutex(&globalLock);
5362 }
5363
5364 return result;
5365}
5366
Ian Elliottc623ba52015-11-20 14:13:17 -07005367VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR(
Michael Lentine27b0f902015-10-12 11:30:14 -05005368 VkDevice device,
Ian Elliottc623ba52015-11-20 14:13:17 -07005369 VkSwapchainKHR swapchain,
5370 const VkAllocationCallbacks *pAllocator)
Michael Lentine27b0f902015-10-12 11:30:14 -05005371{
5372 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentine27b0f902015-10-12 11:30:14 -05005373
5374 loader_platform_thread_lock_mutex(&globalLock);
5375 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(swapchain);
5376 if (swapchain_data != dev_data->device_extensions.swapchainMap.end()) {
5377 if (swapchain_data->second->images.size() > 0) {
5378 for (auto swapchain_image : swapchain_data->second->images) {
5379 auto image_item = dev_data->imageLayoutMap.find(swapchain_image);
5380 if (image_item != dev_data->imageLayoutMap.end())
5381 dev_data->imageLayoutMap.erase(image_item);
5382 }
5383 }
5384 delete swapchain_data->second;
5385 dev_data->device_extensions.swapchainMap.erase(swapchain);
5386 }
5387 loader_platform_thread_unlock_mutex(&globalLock);
Ian Elliottc623ba52015-11-20 14:13:17 -07005388 return dev_data->device_dispatch_table->DestroySwapchainKHR(device, swapchain, pAllocator);
Michael Lentine27b0f902015-10-12 11:30:14 -05005389}
5390
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005391VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR(
Michael Lentine27b0f902015-10-12 11:30:14 -05005392 VkDevice device,
5393 VkSwapchainKHR swapchain,
5394 uint32_t* pCount,
5395 VkImage* pSwapchainImages)
5396{
5397 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5398 VkResult result = dev_data->device_dispatch_table->GetSwapchainImagesKHR(device, swapchain, pCount, pSwapchainImages);
5399
5400 if (result == VK_SUCCESS && pSwapchainImages != NULL) {
5401 // This should never happen and is checked by param checker.
5402 if (!pCount) return result;
5403 for (uint32_t i = 0; i < *pCount; ++i) {
5404 IMAGE_NODE* image_node = new IMAGE_NODE;
5405 image_node->layout = VK_IMAGE_LAYOUT_UNDEFINED;
5406 loader_platform_thread_lock_mutex(&globalLock);
5407 dev_data->device_extensions.swapchainMap[swapchain]->images.push_back(pSwapchainImages[i]);
5408 dev_data->imageLayoutMap[pSwapchainImages[i]] = image_node;
5409 loader_platform_thread_unlock_mutex(&globalLock);
5410 }
5411 }
5412 return result;
5413}
5414
Ian Elliottc623ba52015-11-20 14:13:17 -07005415VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo)
Michael Lentine27b0f902015-10-12 11:30:14 -05005416{
5417 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07005418 VkBool32 skip_call = false;
Michael Lentine27b0f902015-10-12 11:30:14 -05005419
Mark Lobodzinski78940a42015-11-30 16:48:53 -07005420#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentine27b0f902015-10-12 11:30:14 -05005421 if (pPresentInfo) {
5422 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
Ian Elliottc623ba52015-11-20 14:13:17 -07005423 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(pPresentInfo->pSwapchains[i]);
5424 if (swapchain_data != dev_data->device_extensions.swapchainMap.end() && pPresentInfo->pImageIndices[i] < swapchain_data->second->images.size()) {
5425 VkImage image = swapchain_data->second->images[pPresentInfo->pImageIndices[i]];
Michael Lentine27b0f902015-10-12 11:30:14 -05005426 auto image_data = dev_data->imageLayoutMap.find(image);
5427 if (image_data != dev_data->imageLayoutMap.end()) {
Ian Elliottc623ba52015-11-20 14:13:17 -07005428 if (image_data->second->layout != VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005429 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 -05005430 "Images passed to present must be in layout PRESENT_SOURCE_KHR but is in %d", image_data->second->layout);
5431 }
5432 }
5433 }
5434 }
5435 }
Mark Lobodzinski78940a42015-11-30 16:48:53 -07005436#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentine27b0f902015-10-12 11:30:14 -05005437
5438 if (VK_FALSE == skip_call)
5439 return dev_data->device_dispatch_table->QueuePresentKHR(queue, pPresentInfo);
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07005440 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine27b0f902015-10-12 11:30:14 -05005441}
5442
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005443VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(
5444 VkInstance instance,
5445 const VkDebugReportCallbackCreateInfoEXT* pCreateInfo,
5446 const VkAllocationCallbacks* pAllocator,
5447 VkDebugReportCallbackEXT* pMsgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005448{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005449 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07005450 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005451 VkResult res = pTable->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisc91330b2015-06-16 09:04:30 -06005452 if (VK_SUCCESS == res) {
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07005453 res = layer_create_msg_callback(my_data->report_data, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisc91330b2015-06-16 09:04:30 -06005454 }
5455 return res;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005456}
5457
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005458VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07005459 VkInstance instance,
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005460 VkDebugReportCallbackEXT msgCallback,
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07005461 const VkAllocationCallbacks* pAllocator)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005462{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005463 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07005464 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005465 pTable->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07005466 layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005467}
5468
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005469VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDebugReportMessageEXT(
Courtney Goeltzenleuchter5a424ce2015-12-01 14:10:55 -07005470 VkInstance instance,
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005471 VkDebugReportFlagsEXT flags,
5472 VkDebugReportObjectTypeEXT objType,
Courtney Goeltzenleuchter5a424ce2015-12-01 14:10:55 -07005473 uint64_t object,
5474 size_t location,
5475 int32_t msgCode,
5476 const char* pLayerPrefix,
5477 const char* pMsg)
5478{
5479 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005480 my_data->instance_dispatch_table->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg);
Courtney Goeltzenleuchter5a424ce2015-12-01 14:10:55 -07005481}
5482
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005483VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerBegin(VkCommandBuffer commandBuffer, const char* pMarker)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005484{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005485 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08005486 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5487 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005488 if (!dev_data->device_extensions.debug_marker_enabled) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005489 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 -06005490 "Attempt to use CmdDbgMarkerBegin but extension disabled!");
Jon Ashburn6f8cd632015-06-01 09:37:38 -06005491 return;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06005492 } else if (pCB) {
Tobin Ehlis32479352015-12-01 09:48:58 -07005493
Tobin Ehlis42d440c2015-10-20 17:06:16 -06005494 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKERBEGIN);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005495 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005496 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08005497 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerBegin(commandBuffer, pMarker);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005498}
5499
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005500VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerEnd(VkCommandBuffer commandBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005501{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005502 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08005503 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5504 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005505 if (!dev_data->device_extensions.debug_marker_enabled) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005506 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 -06005507 "Attempt to use CmdDbgMarkerEnd but extension disabled!");
Jon Ashburn6f8cd632015-06-01 09:37:38 -06005508 return;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06005509 } else if (pCB) {
Tobin Ehlis32479352015-12-01 09:48:58 -07005510
Tobin Ehlis42d440c2015-10-20 17:06:16 -06005511 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKEREND);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005512 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005513 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08005514 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerEnd(commandBuffer);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06005515}
5516
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005517VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005518{
Jon Ashburn1245cec2015-05-18 13:20:15 -06005519 if (dev == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005520 return NULL;
Jon Ashburne0fa2282015-05-20 09:00:28 -06005521
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005522 layer_data *dev_data;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005523 /* loader uses this to force layer initialization; device object is wrapped */
5524 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005525 VkBaseLayerObject* wrapped_dev = (VkBaseLayerObject*) dev;
5526 dev_data = get_my_data_ptr(get_dispatch_key(wrapped_dev->baseObject), layer_data_map);
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005527 dev_data->device_dispatch_table = new VkLayerDispatchTable;
5528 layer_initialize_dispatch_table(dev_data->device_dispatch_table, wrapped_dev);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005529 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005530 }
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005531 dev_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map);
Courtney Goeltzenleuchterbe637992015-06-25 18:01:43 -06005532 if (!strcmp(funcName, "vkCreateDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005533 return (PFN_vkVoidFunction) vkCreateDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005534 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005535 return (PFN_vkVoidFunction) vkDestroyDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005536 if (!strcmp(funcName, "vkQueueSubmit"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005537 return (PFN_vkVoidFunction) vkQueueSubmit;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005538 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005539 return (PFN_vkVoidFunction) vkDestroyInstance;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005540 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005541 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005542 if (!strcmp(funcName, "vkDestroyFence"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005543 return (PFN_vkVoidFunction) vkDestroyFence;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005544 if (!strcmp(funcName, "vkDestroySemaphore"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005545 return (PFN_vkVoidFunction) vkDestroySemaphore;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005546 if (!strcmp(funcName, "vkDestroyEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005547 return (PFN_vkVoidFunction) vkDestroyEvent;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005548 if (!strcmp(funcName, "vkDestroyQueryPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005549 return (PFN_vkVoidFunction) vkDestroyQueryPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005550 if (!strcmp(funcName, "vkDestroyBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005551 return (PFN_vkVoidFunction) vkDestroyBuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005552 if (!strcmp(funcName, "vkDestroyBufferView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005553 return (PFN_vkVoidFunction) vkDestroyBufferView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005554 if (!strcmp(funcName, "vkDestroyImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005555 return (PFN_vkVoidFunction) vkDestroyImage;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005556 if (!strcmp(funcName, "vkDestroyImageView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005557 return (PFN_vkVoidFunction) vkDestroyImageView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005558 if (!strcmp(funcName, "vkDestroyShaderModule"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005559 return (PFN_vkVoidFunction) vkDestroyShaderModule;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005560 if (!strcmp(funcName, "vkDestroyPipeline"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005561 return (PFN_vkVoidFunction) vkDestroyPipeline;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005562 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005563 return (PFN_vkVoidFunction) vkDestroyPipelineLayout;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005564 if (!strcmp(funcName, "vkDestroySampler"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005565 return (PFN_vkVoidFunction) vkDestroySampler;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005566 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005567 return (PFN_vkVoidFunction) vkDestroyDescriptorSetLayout;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005568 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005569 return (PFN_vkVoidFunction) vkDestroyDescriptorPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005570 if (!strcmp(funcName, "vkDestroyFramebuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005571 return (PFN_vkVoidFunction) vkDestroyFramebuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005572 if (!strcmp(funcName, "vkDestroyRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005573 return (PFN_vkVoidFunction) vkDestroyRenderPass;
Tobin Ehlisb46be812015-10-23 16:00:08 -06005574 if (!strcmp(funcName, "vkCreateBuffer"))
5575 return (PFN_vkVoidFunction) vkCreateBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005576 if (!strcmp(funcName, "vkCreateBufferView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005577 return (PFN_vkVoidFunction) vkCreateBufferView;
Tobin Ehlisb46be812015-10-23 16:00:08 -06005578 if (!strcmp(funcName, "vkCreateImage"))
5579 return (PFN_vkVoidFunction) vkCreateImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005580 if (!strcmp(funcName, "vkCreateImageView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005581 return (PFN_vkVoidFunction) vkCreateImageView;
Jon Ashburn0d60d272015-07-09 15:02:25 -06005582 if (!strcmp(funcName, "CreatePipelineCache"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005583 return (PFN_vkVoidFunction) vkCreatePipelineCache;
Jon Ashburn0d60d272015-07-09 15:02:25 -06005584 if (!strcmp(funcName, "DestroyPipelineCache"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005585 return (PFN_vkVoidFunction) vkDestroyPipelineCache;
Jon Ashburn0d60d272015-07-09 15:02:25 -06005586 if (!strcmp(funcName, "GetPipelineCacheData"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005587 return (PFN_vkVoidFunction) vkGetPipelineCacheData;
Jon Ashburn0d60d272015-07-09 15:02:25 -06005588 if (!strcmp(funcName, "MergePipelineCaches"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005589 return (PFN_vkVoidFunction) vkMergePipelineCaches;
Jon Ashburn0d60d272015-07-09 15:02:25 -06005590 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005591 return (PFN_vkVoidFunction) vkCreateGraphicsPipelines;
Mark Lobodzinski2adea752015-11-10 15:25:01 -07005592 if (!strcmp(funcName, "vkCreateComputePipelines"))
5593 return (PFN_vkVoidFunction) vkCreateComputePipelines;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005594 if (!strcmp(funcName, "vkCreateSampler"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005595 return (PFN_vkVoidFunction) vkCreateSampler;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005596 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005597 return (PFN_vkVoidFunction) vkCreateDescriptorSetLayout;
Mark Lobodzinski556f7212015-04-17 14:11:39 -05005598 if (!strcmp(funcName, "vkCreatePipelineLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005599 return (PFN_vkVoidFunction) vkCreatePipelineLayout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005600 if (!strcmp(funcName, "vkCreateDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005601 return (PFN_vkVoidFunction) vkCreateDescriptorPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005602 if (!strcmp(funcName, "vkResetDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005603 return (PFN_vkVoidFunction) vkResetDescriptorPool;
Chia-I Wu1f851912015-10-27 18:04:07 +08005604 if (!strcmp(funcName, "vkAllocateDescriptorSets"))
5605 return (PFN_vkVoidFunction) vkAllocateDescriptorSets;
Tobin Ehlis3c543112015-10-08 13:13:50 -06005606 if (!strcmp(funcName, "vkFreeDescriptorSets"))
5607 return (PFN_vkVoidFunction) vkFreeDescriptorSets;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08005608 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005609 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07005610 if (!strcmp(funcName, "vkCreateCommandPool"))
5611 return (PFN_vkVoidFunction) vkCreateCommandPool;
5612 if (!strcmp(funcName, "vkDestroyCommandPool"))
5613 return (PFN_vkVoidFunction) vkDestroyCommandPool;
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07005614 if (!strcmp(funcName, "vkResetCommandPool"))
5615 return (PFN_vkVoidFunction) vkResetCommandPool;
Chia-I Wu1f851912015-10-27 18:04:07 +08005616 if (!strcmp(funcName, "vkAllocateCommandBuffers"))
5617 return (PFN_vkVoidFunction) vkAllocateCommandBuffers;
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07005618 if (!strcmp(funcName, "vkFreeCommandBuffers"))
5619 return (PFN_vkVoidFunction) vkFreeCommandBuffers;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005620 if (!strcmp(funcName, "vkBeginCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005621 return (PFN_vkVoidFunction) vkBeginCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005622 if (!strcmp(funcName, "vkEndCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005623 return (PFN_vkVoidFunction) vkEndCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005624 if (!strcmp(funcName, "vkResetCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005625 return (PFN_vkVoidFunction) vkResetCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005626 if (!strcmp(funcName, "vkCmdBindPipeline"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005627 return (PFN_vkVoidFunction) vkCmdBindPipeline;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06005628 if (!strcmp(funcName, "vkCmdSetViewport"))
5629 return (PFN_vkVoidFunction) vkCmdSetViewport;
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06005630 if (!strcmp(funcName, "vkCmdSetScissor"))
5631 return (PFN_vkVoidFunction) vkCmdSetScissor;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06005632 if (!strcmp(funcName, "vkCmdSetLineWidth"))
5633 return (PFN_vkVoidFunction) vkCmdSetLineWidth;
5634 if (!strcmp(funcName, "vkCmdSetDepthBias"))
5635 return (PFN_vkVoidFunction) vkCmdSetDepthBias;
5636 if (!strcmp(funcName, "vkCmdSetBlendConstants"))
5637 return (PFN_vkVoidFunction) vkCmdSetBlendConstants;
5638 if (!strcmp(funcName, "vkCmdSetDepthBounds"))
5639 return (PFN_vkVoidFunction) vkCmdSetDepthBounds;
5640 if (!strcmp(funcName, "vkCmdSetStencilCompareMask"))
5641 return (PFN_vkVoidFunction) vkCmdSetStencilCompareMask;
5642 if (!strcmp(funcName, "vkCmdSetStencilWriteMask"))
5643 return (PFN_vkVoidFunction) vkCmdSetStencilWriteMask;
5644 if (!strcmp(funcName, "vkCmdSetStencilReference"))
5645 return (PFN_vkVoidFunction) vkCmdSetStencilReference;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005646 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005647 return (PFN_vkVoidFunction) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06005648 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005649 return (PFN_vkVoidFunction) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005650 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005651 return (PFN_vkVoidFunction) vkCmdBindIndexBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005652 if (!strcmp(funcName, "vkCmdDraw"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005653 return (PFN_vkVoidFunction) vkCmdDraw;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005654 if (!strcmp(funcName, "vkCmdDrawIndexed"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005655 return (PFN_vkVoidFunction) vkCmdDrawIndexed;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005656 if (!strcmp(funcName, "vkCmdDrawIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005657 return (PFN_vkVoidFunction) vkCmdDrawIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005658 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005659 return (PFN_vkVoidFunction) vkCmdDrawIndexedIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005660 if (!strcmp(funcName, "vkCmdDispatch"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005661 return (PFN_vkVoidFunction) vkCmdDispatch;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005662 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005663 return (PFN_vkVoidFunction) vkCmdDispatchIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005664 if (!strcmp(funcName, "vkCmdCopyBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005665 return (PFN_vkVoidFunction) vkCmdCopyBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005666 if (!strcmp(funcName, "vkCmdCopyImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005667 return (PFN_vkVoidFunction) vkCmdCopyImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005668 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005669 return (PFN_vkVoidFunction) vkCmdCopyBufferToImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005670 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005671 return (PFN_vkVoidFunction) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005672 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005673 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005674 if (!strcmp(funcName, "vkCmdFillBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005675 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005676 if (!strcmp(funcName, "vkCmdClearColorImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005677 return (PFN_vkVoidFunction) vkCmdClearColorImage;
Chris Forbes2951d7d2015-06-22 17:21:59 +12005678 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005679 return (PFN_vkVoidFunction) vkCmdClearDepthStencilImage;
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06005680 if (!strcmp(funcName, "vkCmdClearAttachments"))
5681 return (PFN_vkVoidFunction) vkCmdClearAttachments;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005682 if (!strcmp(funcName, "vkCmdResolveImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005683 return (PFN_vkVoidFunction) vkCmdResolveImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005684 if (!strcmp(funcName, "vkCmdSetEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005685 return (PFN_vkVoidFunction) vkCmdSetEvent;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005686 if (!strcmp(funcName, "vkCmdResetEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005687 return (PFN_vkVoidFunction) vkCmdResetEvent;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005688 if (!strcmp(funcName, "vkCmdWaitEvents"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005689 return (PFN_vkVoidFunction) vkCmdWaitEvents;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005690 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005691 return (PFN_vkVoidFunction) vkCmdPipelineBarrier;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005692 if (!strcmp(funcName, "vkCmdBeginQuery"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005693 return (PFN_vkVoidFunction) vkCmdBeginQuery;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005694 if (!strcmp(funcName, "vkCmdEndQuery"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005695 return (PFN_vkVoidFunction) vkCmdEndQuery;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005696 if (!strcmp(funcName, "vkCmdResetQueryPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005697 return (PFN_vkVoidFunction) vkCmdResetQueryPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005698 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005699 return (PFN_vkVoidFunction) vkCmdWriteTimestamp;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005700 if (!strcmp(funcName, "vkCreateFramebuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005701 return (PFN_vkVoidFunction) vkCreateFramebuffer;
Tobin Ehlis32479352015-12-01 09:48:58 -07005702 if (!strcmp(funcName, "vkCreateShaderModule"))
5703 return (PFN_vkVoidFunction) vkCreateShaderModule;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005704 if (!strcmp(funcName, "vkCreateRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005705 return (PFN_vkVoidFunction) vkCreateRenderPass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005706 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005707 return (PFN_vkVoidFunction) vkCmdBeginRenderPass;
Chia-I Wuc278df82015-07-07 11:50:03 +08005708 if (!strcmp(funcName, "vkCmdNextSubpass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005709 return (PFN_vkVoidFunction) vkCmdNextSubpass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005710 if (!strcmp(funcName, "vkCmdEndRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005711 return (PFN_vkVoidFunction) vkCmdEndRenderPass;
Tobin Ehlis5f728d32015-09-17 14:18:16 -06005712 if (!strcmp(funcName, "vkCmdExecuteCommands"))
5713 return (PFN_vkVoidFunction) vkCmdExecuteCommands;
Michael Lentineee4ad4d2015-10-23 12:41:44 -07005714 if (!strcmp(funcName, "vkMapMemory"))
5715 return (PFN_vkVoidFunction) vkMapMemory;
Jon Ashburn6f8cd632015-06-01 09:37:38 -06005716
Michael Lentine27b0f902015-10-12 11:30:14 -05005717 if (dev_data->device_extensions.wsi_enabled)
5718 {
5719 if (!strcmp(funcName, "vkCreateSwapchainKHR"))
5720 return (PFN_vkVoidFunction) vkCreateSwapchainKHR;
5721 if (!strcmp(funcName, "vkDestroySwapchainKHR"))
5722 return (PFN_vkVoidFunction) vkDestroySwapchainKHR;
5723 if (!strcmp(funcName, "vkGetSwapchainImagesKHR"))
5724 return (PFN_vkVoidFunction) vkGetSwapchainImagesKHR;
5725 if (!strcmp(funcName, "vkQueuePresentKHR"))
5726 return (PFN_vkVoidFunction) vkQueuePresentKHR;
5727 }
5728
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005729 VkLayerDispatchTable* pTable = dev_data->device_dispatch_table;
5730 if (dev_data->device_extensions.debug_marker_enabled)
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005731 {
Jon Ashburn7e07faf2015-06-18 15:02:58 -06005732 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005733 return (PFN_vkVoidFunction) vkCmdDbgMarkerBegin;
Jon Ashburn7e07faf2015-06-18 15:02:58 -06005734 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005735 return (PFN_vkVoidFunction) vkCmdDbgMarkerEnd;
Jon Ashburn6f8cd632015-06-01 09:37:38 -06005736 }
5737 {
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005738 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005739 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005740 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburn79b78ac2015-05-05 14:22:52 -06005741 }
5742}
5743
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005744VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06005745{
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005746 PFN_vkVoidFunction fptr;
Jon Ashburn79b78ac2015-05-05 14:22:52 -06005747 if (instance == NULL)
5748 return NULL;
5749
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005750 layer_data* my_data;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005751 /* loader uses this to force layer initialization; instance object is wrapped */
5752 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005753 VkBaseLayerObject* wrapped_inst = (VkBaseLayerObject*) instance;
5754 my_data = get_my_data_ptr(get_dispatch_key(wrapped_inst->baseObject), layer_data_map);
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005755 my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
5756 layer_init_instance_dispatch_table(my_data->instance_dispatch_table, wrapped_inst);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005757 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005758 }
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06005759 if (!strcmp(funcName, "vkCreateInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005760 return (PFN_vkVoidFunction) vkCreateInstance;
Jon Ashburne0fa2282015-05-20 09:00:28 -06005761 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005762 return (PFN_vkVoidFunction) vkDestroyInstance;
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -06005763 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
5764 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
5765 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
5766 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
5767 if (!strcmp(funcName, "vkEnumerateDeviceLayerProperties"))
5768 return (PFN_vkVoidFunction) vkEnumerateDeviceLayerProperties;
5769 if (!strcmp(funcName, "vkEnumerateDeviceExtensionProperties"))
5770 return (PFN_vkVoidFunction) vkEnumerateDeviceExtensionProperties;
Courtney Goeltzenleuchtercc899fe2015-06-01 14:33:14 -06005771
Tobin Ehlis32479352015-12-01 09:48:58 -07005772 my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06005773 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchtercc899fe2015-06-01 14:33:14 -06005774 if (fptr)
5775 return fptr;
5776
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005777 {
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005778 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005779 if (pTable->GetInstanceProcAddr == NULL)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06005780 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005781 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005782 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005783}