blob: ce4d0d3dd09562e862f10cb08ec4216acfd6f63c [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) {
Tony Barbour778b08c2015-12-17 15:54:05 -07002301 // TODO : I think this is trying to validate this part of the spec:
2302 // If contents is VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS, the contents are recorded in secondary command
2303 // buffers that will be called from the primary command buffer, and vkCmdExecuteCommands is the only valid command
2304 // on the command buffer until vkCmdNextSubpass or vkCmdEndRenderPass.
2305 //
2306 // But the code below is forceing vkCmdExecuteCommands to be the only thing in the command buffer which is not necessary
2307 // it just needs to be the only thing in the renderpass
2308 //
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07002309 VkBool32 skip_call = false;
Tony Barbour778b08c2015-12-17 15:54:05 -07002310 //for (auto cmd : pCB->pCmds) {
2311 // if (cmd_type == CMD_EXECUTECOMMANDS && cmd->type != CMD_EXECUTECOMMANDS) {
2312 // skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_COMMAND_BUFFER, "DS",
2313 // "vkCmdExecuteCommands() cannot be called on a cmd buffer with exsiting commands.");
2314 // }
2315 // if (cmd_type != CMD_EXECUTECOMMANDS && cmd->type == CMD_EXECUTECOMMANDS) {
2316 // skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_COMMAND_BUFFER, "DS",
2317 // "Commands cannot be added to a cmd buffer with exsiting secondary commands.");
2318 // }
2319 //}
Michael Lentine2b9eda42015-10-28 15:55:18 -07002320 return skip_call;
2321}
2322
Tobin Ehlis42d440c2015-10-20 17:06:16 -06002323static VkBool32 addCmd(const layer_data* my_data, GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002324{
Michael Lentine2b9eda42015-10-28 15:55:18 -07002325 VkBool32 skipCall = validateCmdsInCmdBuffer(my_data, pCB, cmd);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002326 CMD_NODE* pCmd = new CMD_NODE;
2327 if (pCmd) {
2328 // init cmd node and append to end of cmd LL
2329 memset(pCmd, 0, sizeof(CMD_NODE));
2330 pCmd->cmdNumber = ++pCB->numCmds;
2331 pCmd->type = cmd;
2332 pCB->pCmds.push_back(pCmd);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002333 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002334 // TODO : How to pass cb as srcObj here?
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002335 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 +08002336 "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 -06002337 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002338 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002339}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002340
Chia-I Wu1f851912015-10-27 18:04:07 +08002341static void resetCB(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002342{
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002343 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002344 if (pCB) {
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06002345 vector<CMD_NODE*> cmd_list = pCB->pCmds;
2346 while (!cmd_list.empty()) {
2347 delete cmd_list.back();
2348 cmd_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002349 }
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06002350 pCB->pCmds.clear();
Tobin Ehlis0cea4082015-08-18 07:10:58 -06002351 // Reset CB state (need to save createInfo)
Chia-I Wu1f851912015-10-27 18:04:07 +08002352 VkCommandBufferAllocateInfo saveCBCI = pCB->createInfo;
Chia-I Wu1f851912015-10-27 18:04:07 +08002353 pCB->commandBuffer = cb;
Tobin Ehlis0cea4082015-08-18 07:10:58 -06002354 pCB->createInfo = saveCBCI;
Michael Lentine27b0f902015-10-12 11:30:14 -05002355 memset(&pCB->beginInfo, 0, sizeof(VkCommandBufferBeginInfo));
2356 pCB->fence = 0;
2357 pCB->numCmds = 0;
2358 memset(pCB->drawCount, 0, NUM_DRAW_TYPES * sizeof(uint64_t));
2359 pCB->state = CB_NEW;
2360 pCB->submitCount = 0;
2361 pCB->status = 0;
2362 pCB->pCmds.clear();
2363 pCB->lastBoundPipeline = 0;
2364 pCB->viewports.clear();
2365 pCB->scissors.clear();
2366 pCB->lineWidth = 0;
2367 pCB->depthBiasConstantFactor = 0;
2368 pCB->depthBiasClamp = 0;
2369 pCB->depthBiasSlopeFactor = 0;
2370 memset(pCB->blendConstants, 0, 4 * sizeof(float));
2371 pCB->minDepthBounds = 0;
2372 pCB->maxDepthBounds = 0;
2373 memset(&pCB->front, 0, sizeof(stencil_data));
2374 memset(&pCB->back, 0, sizeof(stencil_data));
2375 pCB->lastBoundDescriptorSet = 0;
2376 pCB->lastBoundPipelineLayout = 0;
2377 pCB->activeRenderPass = 0;
2378 pCB->activeSubpass = 0;
2379 pCB->framebuffer = 0;
Michael Lentine27b0f902015-10-12 11:30:14 -05002380 pCB->boundDescriptorSets.clear();
2381 pCB->imageLayoutMap.clear();
Mark Lobodzinski74e84692015-12-14 15:14:10 -07002382 pCB->boundVtxBuffers.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002383 }
2384}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002385
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002386// Set PSO-related status bits for CB, including dynamic state set via PSO
Tobin Ehlis97866202015-06-10 12:57:07 -06002387static void set_cb_pso_status(GLOBAL_CB_NODE* pCB, const PIPELINE_NODE* pPipe)
2388{
2389 for (uint32_t i = 0; i < pPipe->cbStateCI.attachmentCount; i++) {
Chia-I Wuc51b1212015-10-27 19:25:11 +08002390 if (0 != pPipe->pAttachments[i].colorWriteMask) {
Tobin Ehlis97866202015-06-10 12:57:07 -06002391 pCB->status |= CBSTATUS_COLOR_BLEND_WRITE_ENABLE;
2392 }
2393 }
2394 if (pPipe->dsStateCI.depthWriteEnable) {
Cody Northrop2605cb02015-08-18 15:21:16 -06002395 pCB->status |= CBSTATUS_DEPTH_WRITE_ENABLE;
2396 }
Cody Northrop2605cb02015-08-18 15:21:16 -06002397 if (pPipe->dsStateCI.stencilTestEnable) {
2398 pCB->status |= CBSTATUS_STENCIL_TEST_ENABLE;
Tobin Ehlis97866202015-06-10 12:57:07 -06002399 }
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002400 // Account for any dynamic state not set via this PSO
2401 if (!pPipe->dynStateCI.dynamicStateCount) { // All state is static
2402 pCB->status = CBSTATUS_ALL;
2403 } else {
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002404 // First consider all state on
2405 // Then unset any state that's noted as dynamic in PSO
2406 // Finally OR that into CB statemask
2407 CBStatusFlags psoDynStateMask = CBSTATUS_ALL;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002408 for (uint32_t i=0; i < pPipe->dynStateCI.dynamicStateCount; i++) {
2409 switch (pPipe->dynStateCI.pDynamicStates[i]) {
2410 case VK_DYNAMIC_STATE_VIEWPORT:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002411 psoDynStateMask &= ~CBSTATUS_VIEWPORT_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002412 break;
2413 case VK_DYNAMIC_STATE_SCISSOR:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002414 psoDynStateMask &= ~CBSTATUS_SCISSOR_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002415 break;
2416 case VK_DYNAMIC_STATE_LINE_WIDTH:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002417 psoDynStateMask &= ~CBSTATUS_LINE_WIDTH_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002418 break;
2419 case VK_DYNAMIC_STATE_DEPTH_BIAS:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002420 psoDynStateMask &= ~CBSTATUS_DEPTH_BIAS_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002421 break;
2422 case VK_DYNAMIC_STATE_BLEND_CONSTANTS:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002423 psoDynStateMask &= ~CBSTATUS_BLEND_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002424 break;
2425 case VK_DYNAMIC_STATE_DEPTH_BOUNDS:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002426 psoDynStateMask &= ~CBSTATUS_DEPTH_BOUNDS_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002427 break;
2428 case VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002429 psoDynStateMask &= ~CBSTATUS_STENCIL_READ_MASK_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002430 break;
2431 case VK_DYNAMIC_STATE_STENCIL_WRITE_MASK:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002432 psoDynStateMask &= ~CBSTATUS_STENCIL_WRITE_MASK_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002433 break;
2434 case VK_DYNAMIC_STATE_STENCIL_REFERENCE:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002435 psoDynStateMask &= ~CBSTATUS_STENCIL_REFERENCE_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002436 break;
2437 default:
2438 // TODO : Flag error here
2439 break;
2440 }
2441 }
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002442 pCB->status |= psoDynStateMask;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002443 }
Tobin Ehlis97866202015-06-10 12:57:07 -06002444}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002445
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002446// Print the last bound Gfx Pipeline
Chia-I Wu1f851912015-10-27 18:04:07 +08002447static VkBool32 printPipeline(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002448{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002449 VkBool32 skipCall = VK_FALSE;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002450 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002451 if (pCB) {
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002452 PIPELINE_NODE *pPipeTrav = getPipeline(my_data, pCB->lastBoundPipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002453 if (!pPipeTrav) {
2454 // nothing to print
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002455 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002456 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 -08002457 "%s", vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002458 }
2459 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002460 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002461}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002462
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002463// Print details of DS config to stdout
Chia-I Wu1f851912015-10-27 18:04:07 +08002464static VkBool32 printDSConfig(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002465{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002466 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002467 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 -06002468 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis7297f192015-06-09 08:39:32 -06002469 if (pCB && pCB->lastBoundDescriptorSet) {
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002470 SET_NODE* pSet = getSetNode(my_data, pCB->lastBoundDescriptorSet);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002471 DESCRIPTOR_POOL_NODE* pPool = getPoolNode(my_data, pSet->pool);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002472 // Print out pool details
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 pool %#" PRIxLEAST64 ".", (uint64_t) pPool->pool);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002475 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002476 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 -06002477 "%s", poolStr.c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002478 // Print out set details
2479 char prefix[10];
2480 uint32_t index = 0;
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",
Chia-I Wue420a332015-10-26 20:04:44 +08002482 "Details for descriptor set %#" PRIxLEAST64 ".", (uint64_t) pSet->set);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002483 LAYOUT_NODE* pLayout = pSet->pLayout;
2484 // Print layout details
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002485 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 -08002486 "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 -06002487 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002488 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
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",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002490 "%s", DSLstr.c_str());
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002491 index++;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002492 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
2493 if (pUpdate) {
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 "Update Chain [UC] for descriptor set %#" PRIxLEAST64 ":", (uint64_t) pSet->set);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002496 sprintf(prefix, " [UC] ");
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",
Michael Lentinecbc4a5e2015-11-03 16:19:46 -08002498 "%s", dynamic_display(pUpdate, prefix).c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002499 // TODO : If there is a "view" associated with this update, print CI for that view
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002500 } else {
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06002501 if (0 != pSet->descriptorCount) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002502 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 +08002503 "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 -06002504 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002505 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 +08002506 "FYI: No descriptors in descriptor set %#" PRIxLEAST64 ".", (uint64_t) pSet->set);
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06002507 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002508 }
2509 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002510 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002511}
2512
Chia-I Wu1f851912015-10-27 18:04:07 +08002513static void printCB(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002514{
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002515 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
David Pinedof5997ab2015-04-27 16:36:17 -06002516 if (pCB && pCB->pCmds.size() > 0) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002517 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 -06002518 "Cmds in CB %p", (void*)cb);
Courtney Goeltzenleuchtercf2a5362015-04-27 11:16:35 -06002519 vector<CMD_NODE*> pCmds = pCB->pCmds;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002520 for (auto ii=pCmds.begin(); ii!=pCmds.end(); ++ii) {
2521 // TODO : Need to pass cb as srcObj here
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002522 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 -08002523 " CMD#%" PRIu64 ": %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002524 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002525 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002526 // Nothing to print
2527 }
2528}
2529
Chia-I Wu1f851912015-10-27 18:04:07 +08002530static VkBool32 synchAndPrintDSConfig(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002531{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002532 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002533 if (!(my_data->report_data->active_flags & VK_DEBUG_REPORT_INFO_BIT_EXT)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002534 return skipCall;
Mike Stroyanfa2f2222015-08-12 17:11:28 -06002535 }
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002536 skipCall |= printDSConfig(my_data, cb);
2537 skipCall |= printPipeline(my_data, cb);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002538 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002539}
2540
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002541// Flags validation error if the associated call is made inside a render pass. The apiName
2542// routine should ONLY be called outside a render pass.
Tobin Ehlis42d440c2015-10-20 17:06:16 -06002543static VkBool32 insideRenderPass(const layer_data* my_data, GLOBAL_CB_NODE *pCB, const char *apiName)
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002544{
2545 VkBool32 inside = VK_FALSE;
2546 if (pCB->activeRenderPass) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002547 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 +08002548 (uint64_t)pCB->commandBuffer, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002549 "%s: It is invalid to issue this call inside an active render pass (%#" PRIxLEAST64 ")",
Chia-I Wue420a332015-10-26 20:04:44 +08002550 apiName, (uint64_t) pCB->activeRenderPass);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002551 }
2552 return inside;
2553}
2554
2555// Flags validation error if the associated call is made outside a render pass. The apiName
2556// routine should ONLY be called inside a render pass.
Tobin Ehlis42d440c2015-10-20 17:06:16 -06002557static VkBool32 outsideRenderPass(const layer_data* my_data, GLOBAL_CB_NODE *pCB, const char *apiName)
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002558{
2559 VkBool32 outside = VK_FALSE;
2560 if (!pCB->activeRenderPass) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002561 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 +08002562 (uint64_t)pCB->commandBuffer, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002563 "%s: This call must be issued inside an active render pass.", apiName);
2564 }
2565 return outside;
2566}
2567
Courtney Goeltzenleuchterb03a0bf2015-11-25 14:31:49 -07002568static void init_draw_state(layer_data *my_data, const VkAllocationCallbacks *pAllocator)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002569{
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002570 uint32_t report_flags = 0;
2571 uint32_t debug_action = 0;
2572 FILE *log_output = NULL;
2573 const char *option_str;
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002574 VkDebugReportCallbackEXT callback;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002575 // initialize DrawState options
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002576 report_flags = getLayerOptionFlags("DrawStateReportFlags", 0);
2577 getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &debug_action);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002578
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002579 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002580 {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002581 option_str = getLayerOption("DrawStateLogFilename");
Tobin Ehlisb4b6e7c2015-09-15 09:55:54 -06002582 log_output = getLayerLogOutput(option_str, "DrawState");
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002583 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07002584 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002585 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07002586 dbgInfo.pfnCallback = log_callback;
2587 dbgInfo.pUserData = log_output;
2588 dbgInfo.flags = report_flags;
2589 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchter1781b1c2015-10-05 15:58:38 -06002590 my_data->logging_callback.push_back(callback);
2591 }
2592
2593 if (debug_action & VK_DBG_LAYER_ACTION_DEBUG_OUTPUT) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002594 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07002595 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002596 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07002597 dbgInfo.pfnCallback = win32_debug_output_msg;
2598 dbgInfo.pUserData = log_output;
2599 dbgInfo.flags = report_flags;
2600 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchter1781b1c2015-10-05 15:58:38 -06002601 my_data->logging_callback.push_back(callback);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002602 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002603
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002604 if (!globalLockInitialized)
2605 {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002606 loader_platform_thread_create_mutex(&globalLock);
2607 globalLockInitialized = 1;
2608 }
2609}
2610
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002611VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance)
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06002612{
Tobin Ehliscb085292015-12-01 09:57:09 -07002613 // TODOSC : Shouldn't need any customization here
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002614 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
2615 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Chia-I Wu69f40122015-10-26 21:10:41 +08002616 VkResult result = pTable->CreateInstance(pCreateInfo, pAllocator, pInstance);
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06002617
2618 if (result == VK_SUCCESS) {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002619 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
2620 my_data->report_data = debug_report_create_instance(
2621 pTable,
2622 *pInstance,
Chia-I Wu763a7492015-10-26 20:48:51 +08002623 pCreateInfo->enabledExtensionNameCount,
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002624 pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchterf4a2eba2015-06-08 14:58:39 -06002625
Courtney Goeltzenleuchterb03a0bf2015-11-25 14:31:49 -07002626 init_draw_state(my_data, pAllocator);
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06002627 }
2628 return result;
2629}
2630
Jon Ashburne0fa2282015-05-20 09:00:28 -06002631/* hook DestroyInstance to remove tableInstanceMap entry */
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002632VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator)
Jon Ashburne0fa2282015-05-20 09:00:28 -06002633{
Tobin Ehliscb085292015-12-01 09:57:09 -07002634 // TODOSC : Shouldn't need any customization here
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002635 dispatch_key key = get_dispatch_key(instance);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002636 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
2637 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Chia-I Wu69f40122015-10-26 21:10:41 +08002638 pTable->DestroyInstance(instance, pAllocator);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002639
2640 // Clean up logging callback, if any
Courtney Goeltzenleuchter1781b1c2015-10-05 15:58:38 -06002641 while (my_data->logging_callback.size() > 0) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002642 VkDebugReportCallbackEXT callback = my_data->logging_callback.back();
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07002643 layer_destroy_msg_callback(my_data->report_data, callback, pAllocator);
Courtney Goeltzenleuchter1781b1c2015-10-05 15:58:38 -06002644 my_data->logging_callback.pop_back();
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002645 }
2646
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06002647 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002648 delete my_data->instance_dispatch_table;
2649 layer_data_map.erase(key);
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002650 // TODO : Potential race here with separate threads creating/destroying instance
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002651 if (layer_data_map.empty()) {
Mike Stroyand9dd0072015-08-18 15:56:18 -06002652 // Release mutex when destroying last instance.
2653 loader_platform_thread_delete_mutex(&globalLock);
2654 globalLockInitialized = 0;
2655 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002656}
2657
Jon Ashburnf0615e22015-05-25 14:11:37 -06002658static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
2659{
Tony Barbour29b12062015-07-13 13:37:24 -06002660 uint32_t i;
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002661 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
2662 dev_data->device_extensions.debug_marker_enabled = false;
Michael Lentine27b0f902015-10-12 11:30:14 -05002663 dev_data->device_extensions.wsi_enabled = false;
2664
2665
2666 VkLayerDispatchTable *pDisp = dev_data->device_dispatch_table;
2667 PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr;
2668
Michael Lentine27b0f902015-10-12 11:30:14 -05002669 pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR) gpa(device, "vkCreateSwapchainKHR");
2670 pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR) gpa(device, "vkDestroySwapchainKHR");
2671 pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR) gpa(device, "vkGetSwapchainImagesKHR");
2672 pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR) gpa(device, "vkAcquireNextImageKHR");
2673 pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR) gpa(device, "vkQueuePresentKHR");
Jon Ashburnf0615e22015-05-25 14:11:37 -06002674
Chia-I Wu763a7492015-10-26 20:48:51 +08002675 for (i = 0; i < pCreateInfo->enabledExtensionNameCount; i++) {
Ian Elliottc623ba52015-11-20 14:13:17 -07002676 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) {
Michael Lentine27b0f902015-10-12 11:30:14 -05002677 dev_data->device_extensions.wsi_enabled = true;
2678 }
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002679 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002680 /* Found a matching extension name, mark it enabled and init dispatch table*/
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002681 dev_data->device_extensions.debug_marker_enabled = true;
Jon Ashburnc1d059f2015-12-10 19:12:21 -07002682 initDebugMarkerTable(device);
2683
Jon Ashburnf0615e22015-05-25 14:11:37 -06002684 }
Jon Ashburnf0615e22015-05-25 14:11:37 -06002685 }
2686}
2687
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002688VK_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 -06002689{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002690 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08002691 VkResult result = dev_data->device_dispatch_table->CreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
Tobin Ehliscb085292015-12-01 09:57:09 -07002692 // TODOSC : shouldn't need any customization here
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002693 if (result == VK_SUCCESS) {
2694 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002695 dev_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
Jon Ashburn7e07faf2015-06-18 15:02:58 -06002696 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002697 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002698 return result;
2699}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002700
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002701// prototype
2702static void deleteRenderPasses(layer_data*);
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002703VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002704{
Tobin Ehliscb085292015-12-01 09:57:09 -07002705 // TODOSC : Shouldn't need any customization here
Jeremy Hayesea1fef52015-06-19 11:37:38 -06002706 dispatch_key key = get_dispatch_key(device);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002707 layer_data* dev_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002708 // Free all the memory
2709 loader_platform_thread_lock_mutex(&globalLock);
2710 deletePipelines(dev_data);
2711 deleteRenderPasses(dev_data);
Chia-I Wu1f851912015-10-27 18:04:07 +08002712 deleteCommandBuffers(dev_data);
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002713 deletePools(dev_data);
2714 deleteLayouts(dev_data);
Tobin Ehlisb46be812015-10-23 16:00:08 -06002715 dev_data->imageViewMap.clear();
2716 dev_data->imageMap.clear();
2717 dev_data->bufferViewMap.clear();
2718 dev_data->bufferMap.clear();
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002719 loader_platform_thread_unlock_mutex(&globalLock);
2720
Chia-I Wu69f40122015-10-26 21:10:41 +08002721 dev_data->device_dispatch_table->DestroyDevice(device, pAllocator);
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002722 tableDebugMarkerMap.erase(key);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002723 delete dev_data->device_dispatch_table;
2724 layer_data_map.erase(key);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002725}
2726
Courtney Goeltzenleuchterd89520d2015-12-01 14:08:28 -07002727static const VkExtensionProperties instance_extensions[] = {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002728 {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002729 VK_EXT_DEBUG_REPORT_EXTENSION_NAME,
2730 VK_EXT_DEBUG_REPORT_REVISION
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002731 }
Jon Ashburneb2728b2015-04-10 14:33:07 -06002732};
2733
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002734VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002735 const char *pLayerName,
2736 uint32_t *pCount,
2737 VkExtensionProperties* pProperties)
Jon Ashburneb2728b2015-04-10 14:33:07 -06002738{
Courtney Goeltzenleuchterd89520d2015-12-01 14:08:28 -07002739 return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002740}
Jon Ashburneb2728b2015-04-10 14:33:07 -06002741
Courtney Goeltzenleuchterd89520d2015-12-01 14:08:28 -07002742static const VkLayerProperties ds_global_layers[] = {
2743 {
2744 "DrawState",
2745 VK_API_VERSION,
2746 VK_MAKE_VERSION(0, 1, 0),
2747 "Validation layer: DrawState",
2748 }
2749};
2750
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002751VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002752 uint32_t *pCount,
2753 VkLayerProperties* pProperties)
2754{
2755 return util_GetLayerProperties(ARRAY_SIZE(ds_global_layers),
2756 ds_global_layers,
2757 pCount, pProperties);
2758}
Jon Ashburneb2728b2015-04-10 14:33:07 -06002759
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002760static const VkExtensionProperties ds_device_extensions[] = {
2761 {
2762 DEBUG_MARKER_EXTENSION_NAME,
2763 VK_MAKE_VERSION(0, 1, 0),
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002764 }
2765};
2766
2767static const VkLayerProperties ds_device_layers[] = {
2768 {
2769 "DrawState",
2770 VK_API_VERSION,
2771 VK_MAKE_VERSION(0, 1, 0),
2772 "Validation layer: DrawState",
2773 }
2774};
2775
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002776VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002777 VkPhysicalDevice physicalDevice,
2778 const char* pLayerName,
2779 uint32_t* pCount,
2780 VkExtensionProperties* pProperties)
2781{
Tobin Ehlis32479352015-12-01 09:48:58 -07002782 // DrawState does not have any physical device extensions
Jon Ashburnaff81ff2015-11-02 17:37:20 -07002783 if (pLayerName == NULL) {
2784 dispatch_key key = get_dispatch_key(physicalDevice);
2785 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlis32479352015-12-01 09:48:58 -07002786 return my_data->instance_dispatch_table->EnumerateDeviceExtensionProperties(
Jon Ashburnaff81ff2015-11-02 17:37:20 -07002787 physicalDevice,
2788 NULL,
2789 pCount,
2790 pProperties);
2791 } else {
2792 return util_GetExtensionProperties(ARRAY_SIZE(ds_device_extensions),
2793 ds_device_extensions,
2794 pCount, pProperties);
2795 }
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002796}
2797
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002798VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002799 VkPhysicalDevice physicalDevice,
2800 uint32_t* pCount,
2801 VkLayerProperties* pProperties)
2802{
Tobin Ehlis32479352015-12-01 09:48:58 -07002803 /* DrawState physical device layers are the same as global */
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002804 return util_GetLayerProperties(ARRAY_SIZE(ds_device_layers), ds_device_layers,
2805 pCount, pProperties);
Jon Ashburneb2728b2015-04-10 14:33:07 -06002806}
2807
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07002808VkBool32 ValidateCmdBufImageLayouts(VkCommandBuffer cmdBuffer) {
2809 VkBool32 skip_call = false;
Michael Lentine27b0f902015-10-12 11:30:14 -05002810 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
2811 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
2812 for (auto cb_image_data : pCB->imageLayoutMap) {
2813 auto image_data = dev_data->imageLayoutMap.find(cb_image_data.first);
2814 if (image_data == dev_data->imageLayoutMap.end()) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002815 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 -08002816 "Cannot submit cmd buffer using deleted image %" PRIu64 ".", reinterpret_cast<uint64_t>(cb_image_data.first));
Michael Lentine27b0f902015-10-12 11:30:14 -05002817 } else {
2818 if (dev_data->imageLayoutMap[cb_image_data.first]->layout != cb_image_data.second.initialLayout) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002819 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 -05002820 "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);
2821 }
2822 dev_data->imageLayoutMap[cb_image_data.first]->layout = cb_image_data.second.layout;
2823 }
2824 }
2825 return skip_call;
2826}
2827
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002828VK_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 -06002829{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002830 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis28be0be2015-05-22 12:38:16 -06002831 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002832 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06002833 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
Chia-I Wu483e7702015-10-26 17:20:32 +08002834 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Chia-I Wu763a7492015-10-26 20:48:51 +08002835 for (uint32_t i=0; i < submit->commandBufferCount; i++) {
Mark Lobodzinski78940a42015-11-30 16:48:53 -07002836
2837#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
2838 skipCall |= ValidateCmdBufImageLayouts(submit->pCommandBuffers[i]);
2839#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
2840
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06002841 // Validate that cmd buffers have been updated
2842 pCB = getCBNode(dev_data, submit->pCommandBuffers[i]);
2843 loader_platform_thread_lock_mutex(&globalLock);
2844 pCB->submitCount++; // increment submit count
Chia-I Wu1f851912015-10-27 18:04:07 +08002845 if ((pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT) && (pCB->submitCount > 1)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002846 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 -05002847 "CB %#" PRIxLEAST64 " was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted %#" PRIxLEAST64 " times.",
2848 reinterpret_cast<uint64_t>(pCB->commandBuffer), pCB->submitCount);
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06002849 }
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07002850 if (CB_RECORDED != pCB->state) {
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06002851 // Flag error for using CB w/o vkEndCommandBuffer() called
2852 // TODO : How to pass cb as srcObj?
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002853 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 +08002854 "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 -06002855 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07002856 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06002857 }
Tobin Ehlise90b1712015-05-27 14:30:06 -06002858 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis28be0be2015-05-22 12:38:16 -06002859 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002860 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002861 if (VK_FALSE == skipCall)
Chia-I Wu483e7702015-10-26 17:20:32 +08002862 return dev_data->device_dispatch_table->QueueSubmit(queue, submitCount, pSubmits, fence);
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07002863 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002864}
2865
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002866VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002867{
Chia-I Wu69f40122015-10-26 21:10:41 +08002868 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 -06002869 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002870}
2871
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002872VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySemaphore(VkDevice device, VkSemaphore semaphore, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002873{
Chia-I Wu69f40122015-10-26 21:10:41 +08002874 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 -06002875 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002876}
2877
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002878VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002879{
Chia-I Wu69f40122015-10-26 21:10:41 +08002880 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 -06002881 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002882}
2883
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002884VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002885{
Chia-I Wu69f40122015-10-26 21:10:41 +08002886 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 -06002887 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002888}
2889
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002890VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002891{
Tobin Ehlisb46be812015-10-23 16:00:08 -06002892 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08002893 dev_data->device_dispatch_table->DestroyBuffer(device, buffer, pAllocator);
Chia-I Wue420a332015-10-26 20:04:44 +08002894 dev_data->bufferMap.erase(buffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002895}
2896
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002897VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBufferView(VkDevice device, VkBufferView bufferView, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002898{
Tobin Ehlisb46be812015-10-23 16:00:08 -06002899 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08002900 dev_data->device_dispatch_table->DestroyBufferView(device, bufferView, pAllocator);
Chia-I Wue420a332015-10-26 20:04:44 +08002901 dev_data->bufferViewMap.erase(bufferView);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002902}
2903
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002904VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002905{
Tobin Ehlisb46be812015-10-23 16:00:08 -06002906 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08002907 dev_data->device_dispatch_table->DestroyImage(device, image, pAllocator);
Chia-I Wue420a332015-10-26 20:04:44 +08002908 dev_data->imageMap.erase(image);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002909}
2910
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002911VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyImageView(VkDevice device, VkImageView imageView, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002912{
Chia-I Wu69f40122015-10-26 21:10:41 +08002913 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 -06002914 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002915}
2916
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002917VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002918{
Chia-I Wu69f40122015-10-26 21:10:41 +08002919 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 -06002920 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002921}
2922
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002923VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyPipeline(VkDevice device, VkPipeline pipeline, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002924{
Chia-I Wu69f40122015-10-26 21:10:41 +08002925 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 -06002926 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002927}
2928
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002929VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002930{
Chia-I Wu69f40122015-10-26 21:10:41 +08002931 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 -06002932 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002933}
2934
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002935VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySampler(VkDevice device, VkSampler sampler, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002936{
Chia-I Wu69f40122015-10-26 21:10:41 +08002937 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 -06002938 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002939}
2940
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002941VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002942{
Chia-I Wu69f40122015-10-26 21:10:41 +08002943 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 -06002944 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002945}
2946
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002947VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002948{
Chia-I Wu69f40122015-10-26 21:10:41 +08002949 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 -06002950 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002951}
2952
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002953VK_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 -06002954{
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002955 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
2956
Courtney Goeltzenleuchter740451a2015-12-16 16:06:06 -07002957 for (uint32_t i = 0; i < count; i++) {
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002958 // Delete CB information structure, and remove from commandBufferMap
2959 auto cb = dev_data->commandBufferMap.find(pCommandBuffers[i]);
Mark Lobodzinski13b66742015-11-20 14:33:48 -07002960 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002961 if (cb != dev_data->commandBufferMap.end()) {
2962 delete (*cb).second;
2963 dev_data->commandBufferMap.erase(cb);
2964 }
2965
2966 // Remove commandBuffer reference from commandPoolMap
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07002967 dev_data->commandPoolMap[commandPool].commandBuffers.remove(pCommandBuffers[i]);
Mark Lobodzinski13b66742015-11-20 14:33:48 -07002968 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002969 }
2970
2971 dev_data->device_dispatch_table->FreeCommandBuffers(device, commandPool, count, pCommandBuffers);
2972}
2973
2974VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkCommandPool* pCommandPool)
2975{
2976 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
2977
2978 VkResult result = dev_data->device_dispatch_table->CreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
2979
2980 if (VK_SUCCESS == result) {
Mark Lobodzinski13b66742015-11-20 14:33:48 -07002981 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07002982 dev_data->commandPoolMap[*pCommandPool].createFlags = pCreateInfo->flags;
Mark Lobodzinski13b66742015-11-20 14:33:48 -07002983 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002984 }
2985 return result;
2986}
2987
2988VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks* pAllocator)
2989{
2990 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski13b66742015-11-20 14:33:48 -07002991 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002992
2993 // Must remove cmdpool from cmdpoolmap, after removing all cmdbuffers in its list from the commandPoolMap
2994 if (dev_data->commandPoolMap.find(commandPool) != dev_data->commandPoolMap.end()) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07002995 for (auto poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.begin(); poolCb != dev_data->commandPoolMap[commandPool].commandBuffers.end();) {
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002996 auto del_cb = dev_data->commandBufferMap.find(*poolCb);
2997 delete (*del_cb).second; // delete CB info structure
2998 dev_data->commandBufferMap.erase(del_cb); // Remove this command buffer from cbMap
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07002999 poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.erase(poolCb); // Remove CB reference from commandPoolMap's list
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003000 }
3001 }
3002 dev_data->commandPoolMap.erase(commandPool);
Mark Lobodzinski13b66742015-11-20 14:33:48 -07003003
3004 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003005 dev_data->device_dispatch_table->DestroyCommandPool(device, commandPool, pAllocator);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003006}
3007
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003008VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandPool(
3009 VkDevice device,
3010 VkCommandPool commandPool,
3011 VkCommandPoolResetFlags flags)
3012{
3013 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003014 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003015
3016 result = dev_data->device_dispatch_table->ResetCommandPool(device, commandPool, flags);
3017 // Reset all of the CBs allocated from this pool
3018 if (VK_SUCCESS == result) {
3019 auto it = dev_data->commandPoolMap[commandPool].commandBuffers.begin();
3020 while (it != dev_data->commandPoolMap[commandPool].commandBuffers.end()) {
3021 resetCB(dev_data, (*it));
3022 ++it;
3023 }
3024 }
3025 return result;
3026}
3027
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003028VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003029{
Chia-I Wu69f40122015-10-26 21:10:41 +08003030 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 -06003031 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003032}
3033
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003034VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003035{
Chia-I Wu69f40122015-10-26 21:10:41 +08003036 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 -06003037 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003038}
3039
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003040VK_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 -06003041{
3042 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003043 VkResult result = dev_data->device_dispatch_table->CreateBuffer(device, pCreateInfo, pAllocator, pBuffer);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003044 if (VK_SUCCESS == result) {
3045 loader_platform_thread_lock_mutex(&globalLock);
3046 // 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 +08003047 dev_data->bufferMap[*pBuffer] = unique_ptr<VkBufferCreateInfo>(new VkBufferCreateInfo(*pCreateInfo));
Tobin Ehlisb46be812015-10-23 16:00:08 -06003048 loader_platform_thread_unlock_mutex(&globalLock);
3049 }
3050 return result;
3051}
3052
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003053VK_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 -06003054{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003055 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003056 VkResult result = dev_data->device_dispatch_table->CreateBufferView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003057 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003058 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue420a332015-10-26 20:04:44 +08003059 dev_data->bufferViewMap[*pView] = unique_ptr<VkBufferViewCreateInfo>(new VkBufferViewCreateInfo(*pCreateInfo));
Tobin Ehlisb46be812015-10-23 16:00:08 -06003060 loader_platform_thread_unlock_mutex(&globalLock);
3061 }
3062 return result;
3063}
3064
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003065VK_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 -06003066{
3067 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003068 VkResult result = dev_data->device_dispatch_table->CreateImage(device, pCreateInfo, pAllocator, pImage);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003069 if (VK_SUCCESS == result) {
Michael Lentine27b0f902015-10-12 11:30:14 -05003070 IMAGE_NODE* image_node = new IMAGE_NODE;
3071 image_node->layout = pCreateInfo->initialLayout;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003072 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue420a332015-10-26 20:04:44 +08003073 dev_data->imageMap[*pImage] = unique_ptr<VkImageCreateInfo>(new VkImageCreateInfo(*pCreateInfo));
Michael Lentine27b0f902015-10-12 11:30:14 -05003074 dev_data->imageLayoutMap[*pImage] = image_node;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003075 loader_platform_thread_unlock_mutex(&globalLock);
3076 }
3077 return result;
3078}
3079
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003080VK_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 -06003081{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003082 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003083 VkResult result = dev_data->device_dispatch_table->CreateImageView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003084 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003085 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue420a332015-10-26 20:04:44 +08003086 dev_data->imageViewMap[*pView] = unique_ptr<VkImageViewCreateInfo>(new VkImageViewCreateInfo(*pCreateInfo));
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003087 loader_platform_thread_unlock_mutex(&globalLock);
3088 }
3089 return result;
3090}
3091
Jon Ashburn0d60d272015-07-09 15:02:25 -06003092//TODO handle pipeline caches
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003093VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineCache(
Jon Ashburn0d60d272015-07-09 15:02:25 -06003094 VkDevice device,
3095 const VkPipelineCacheCreateInfo* pCreateInfo,
Chia-I Wu1f851912015-10-27 18:04:07 +08003096 const VkAllocationCallbacks* pAllocator,
Jon Ashburn0d60d272015-07-09 15:02:25 -06003097 VkPipelineCache* pPipelineCache)
3098{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003099 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003100 VkResult result = dev_data->device_dispatch_table->CreatePipelineCache(device, pCreateInfo, pAllocator, pPipelineCache);
Jon Ashburn0d60d272015-07-09 15:02:25 -06003101 return result;
3102}
3103
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003104VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineCache(
Jon Ashburn0d60d272015-07-09 15:02:25 -06003105 VkDevice device,
Chia-I Wu69f40122015-10-26 21:10:41 +08003106 VkPipelineCache pipelineCache,
Chia-I Wu1f851912015-10-27 18:04:07 +08003107 const VkAllocationCallbacks* pAllocator)
Jon Ashburn0d60d272015-07-09 15:02:25 -06003108{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003109 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003110 dev_data->device_dispatch_table->DestroyPipelineCache(device, pipelineCache, pAllocator);
Jon Ashburn0d60d272015-07-09 15:02:25 -06003111}
3112
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003113VKAPI_ATTR VkResult VKAPI_CALL vkGetPipelineCacheData(
Jon Ashburn0d60d272015-07-09 15:02:25 -06003114 VkDevice device,
3115 VkPipelineCache pipelineCache,
Chia-I Wu28c3c432015-10-26 19:17:06 +08003116 size_t* pDataSize,
Jon Ashburn0d60d272015-07-09 15:02:25 -06003117 void* pData)
3118{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003119 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu28c3c432015-10-26 19:17:06 +08003120 VkResult result = dev_data->device_dispatch_table->GetPipelineCacheData(device, pipelineCache, pDataSize, pData);
Jon Ashburn0d60d272015-07-09 15:02:25 -06003121 return result;
3122}
3123
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003124VKAPI_ATTR VkResult VKAPI_CALL vkMergePipelineCaches(
Jon Ashburn0d60d272015-07-09 15:02:25 -06003125 VkDevice device,
Chia-I Wu1f851912015-10-27 18:04:07 +08003126 VkPipelineCache dstCache,
Jon Ashburn0d60d272015-07-09 15:02:25 -06003127 uint32_t srcCacheCount,
3128 const VkPipelineCache* pSrcCaches)
3129{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003130 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu1f851912015-10-27 18:04:07 +08003131 VkResult result = dev_data->device_dispatch_table->MergePipelineCaches(device, dstCache, srcCacheCount, pSrcCaches);
Jon Ashburn0d60d272015-07-09 15:02:25 -06003132 return result;
3133}
3134
Mark Lobodzinski2adea752015-11-10 15:25:01 -07003135VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateGraphicsPipelines(
3136 VkDevice device,
3137 VkPipelineCache pipelineCache,
3138 uint32_t count,
3139 const VkGraphicsPipelineCreateInfo *pCreateInfos,
3140 const VkAllocationCallbacks *pAllocator,
3141 VkPipeline *pPipelines)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003142{
Courtney Goeltzenleuchtera54b76a2015-09-04 13:39:59 -06003143 VkResult result = VK_SUCCESS;
Tobin Ehlise48be202015-09-16 10:33:53 -06003144 //TODO What to do with pipelineCache?
Tobin Ehlisde63c532015-06-18 15:59:33 -06003145 // The order of operations here is a little convoluted but gets the job done
3146 // 1. Pipeline create state is first shadowed into PIPELINE_NODE struct
3147 // 2. Create state is then validated (which uses flags setup during shadowing)
3148 // 3. If everything looks good, we'll then create the pipeline and add NODE to pipelineMap
Tobin Ehlise48be202015-09-16 10:33:53 -06003149 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis76c18852015-09-17 16:33:58 -06003150 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
3151 vector<PIPELINE_NODE*> pPipeNode(count);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003152 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski2adea752015-11-10 15:25:01 -07003153
Tobin Ehlise48be202015-09-16 10:33:53 -06003154 uint32_t i=0;
Tobin Ehlisde63c532015-06-18 15:59:33 -06003155 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski2adea752015-11-10 15:25:01 -07003156
Tobin Ehlise48be202015-09-16 10:33:53 -06003157 for (i=0; i<count; i++) {
Mark Lobodzinski2adea752015-11-10 15:25:01 -07003158 pPipeNode[i] = initGraphicsPipeline(dev_data, &pCreateInfos[i], NULL);
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003159 skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
Tobin Ehlise48be202015-09-16 10:33:53 -06003160 }
Mark Lobodzinski2adea752015-11-10 15:25:01 -07003161
Tobin Ehlisde63c532015-06-18 15:59:33 -06003162 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis32479352015-12-01 09:48:58 -07003163
Tobin Ehlisad61de42015-12-02 13:53:34 -07003164 if (VK_FALSE == skipCall) {
Mark Lobodzinski2adea752015-11-10 15:25:01 -07003165 result = dev_data->device_dispatch_table->CreateGraphicsPipelines(device,
3166 pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
Tobin Ehlisde63c532015-06-18 15:59:33 -06003167 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlise48be202015-09-16 10:33:53 -06003168 for (i=0; i<count; i++) {
3169 pPipeNode[i]->pipeline = pPipelines[i];
Chia-I Wue420a332015-10-26 20:04:44 +08003170 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
Tobin Ehlise48be202015-09-16 10:33:53 -06003171 }
Tobin Ehlisde63c532015-06-18 15:59:33 -06003172 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003173 } else {
Tobin Ehlise48be202015-09-16 10:33:53 -06003174 for (i=0; i<count; i++) {
3175 if (pPipeNode[i]) {
3176 // If we allocated a pipeNode, need to clean it up here
3177 delete[] pPipeNode[i]->pVertexBindingDescriptions;
3178 delete[] pPipeNode[i]->pVertexAttributeDescriptions;
3179 delete[] pPipeNode[i]->pAttachments;
3180 delete pPipeNode[i];
3181 }
Tobin Ehlisde63c532015-06-18 15:59:33 -06003182 }
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003183 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisde63c532015-06-18 15:59:33 -06003184 }
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06003185 return result;
3186}
3187
Mark Lobodzinski2adea752015-11-10 15:25:01 -07003188VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateComputePipelines(
3189 VkDevice device,
3190 VkPipelineCache pipelineCache,
3191 uint32_t count,
3192 const VkComputePipelineCreateInfo *pCreateInfos,
3193 const VkAllocationCallbacks *pAllocator,
3194 VkPipeline *pPipelines)
3195{
3196 VkResult result = VK_SUCCESS;
3197 VkBool32 skipCall = VK_FALSE;
3198
3199 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
3200 vector<PIPELINE_NODE*> pPipeNode(count);
3201 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3202
3203 uint32_t i=0;
3204 loader_platform_thread_lock_mutex(&globalLock);
3205 for (i=0; i<count; i++) {
3206 // TODO: Verify compute stage bits
3207
3208 // Create and initialize internal tracking data structure
3209 pPipeNode[i] = new PIPELINE_NODE;
3210 memset((void*)pPipeNode[i], 0, sizeof(PIPELINE_NODE));
3211 memcpy(&pPipeNode[i]->computePipelineCI, (const void*)&pCreateInfos[i], sizeof(VkComputePipelineCreateInfo));
3212
3213 // TODO: Add Compute Pipeline Verification
3214 // skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
3215 }
3216 loader_platform_thread_unlock_mutex(&globalLock);
3217
3218 if (VK_FALSE == skipCall) {
3219 result = dev_data->device_dispatch_table->CreateComputePipelines(device, pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
3220 loader_platform_thread_lock_mutex(&globalLock);
3221 for (i=0; i<count; i++) {
3222 pPipeNode[i]->pipeline = pPipelines[i];
3223 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
3224 }
3225 loader_platform_thread_unlock_mutex(&globalLock);
3226 } else {
3227 for (i=0; i<count; i++) {
3228 if (pPipeNode[i]) {
3229 // Clean up any locally allocated data structures
3230 delete pPipeNode[i];
3231 }
3232 }
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003233 return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinski2adea752015-11-10 15:25:01 -07003234 }
3235 return result;
3236}
3237
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003238VK_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 -06003239{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003240 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003241 VkResult result = dev_data->device_dispatch_table->CreateSampler(device, pCreateInfo, pAllocator, pSampler);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003242 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003243 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue420a332015-10-26 20:04:44 +08003244 dev_data->sampleMap[*pSampler] = unique_ptr<SAMPLER_NODE>(new SAMPLER_NODE(pSampler, pCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003245 loader_platform_thread_unlock_mutex(&globalLock);
3246 }
3247 return result;
3248}
3249
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003250VK_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 -06003251{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003252 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003253 VkResult result = dev_data->device_dispatch_table->CreateDescriptorSetLayout(device, pCreateInfo, pAllocator, pSetLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003254 if (VK_SUCCESS == result) {
Tobin Ehliscb085292015-12-01 09:57:09 -07003255 // TODOSC : Capture layout bindings set
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003256 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
3257 if (NULL == pNewNode) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003258 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 -06003259 "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()"))
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003260 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003261 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003262 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003263 pNewNode->createInfo.pBinding = new VkDescriptorSetLayoutBinding[pCreateInfo->bindingCount];
3264 memcpy((void*)pNewNode->createInfo.pBinding, pCreateInfo->pBinding, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->bindingCount);
Chia-I Wub5689ee2015-10-31 00:31:16 +08003265 // g++ does not like reserve with size 0
3266 if (pCreateInfo->bindingCount)
3267 pNewNode->bindings.reserve(pCreateInfo->bindingCount);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003268 uint32_t totalCount = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08003269 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
Chia-I Wub5689ee2015-10-31 00:31:16 +08003270 if (!pNewNode->bindings.insert(pCreateInfo->pBinding[i].binding).second) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003271 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 +08003272 "duplicated binding number in VkDescriptorSetLayoutBinding"))
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003273 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wub5689ee2015-10-31 00:31:16 +08003274 }
3275
Chia-I Wu045654f2015-11-06 06:42:02 +08003276 totalCount += pCreateInfo->pBinding[i].descriptorCount;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003277 if (pCreateInfo->pBinding[i].pImmutableSamplers) {
3278 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBinding[i].pImmutableSamplers;
Chia-I Wu045654f2015-11-06 06:42:02 +08003279 *ppIS = new VkSampler[pCreateInfo->pBinding[i].descriptorCount];
3280 memcpy(*ppIS, pCreateInfo->pBinding[i].pImmutableSamplers, pCreateInfo->pBinding[i].descriptorCount*sizeof(VkSampler));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003281 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003282 }
3283 if (totalCount > 0) {
Cody Northrop8a908322015-10-26 14:07:35 -06003284 pNewNode->descriptorTypes.resize(totalCount);
Tobin Ehlis68fbd442015-10-27 12:25:35 -06003285 pNewNode->stageFlags.resize(totalCount);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003286 uint32_t offset = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003287 uint32_t j = 0;
Tobin Ehlis61ebb312015-11-04 12:28:28 -07003288 VkDescriptorType dType;
Chia-I Wu763a7492015-10-26 20:48:51 +08003289 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
Tobin Ehlis61ebb312015-11-04 12:28:28 -07003290 dType = pCreateInfo->pBinding[i].descriptorType;
Chia-I Wu045654f2015-11-06 06:42:02 +08003291 for (j = 0; j < pCreateInfo->pBinding[i].descriptorCount; j++) {
Tobin Ehlis61ebb312015-11-04 12:28:28 -07003292 pNewNode->descriptorTypes[offset + j] = dType;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003293 pNewNode->stageFlags[offset + j] = pCreateInfo->pBinding[i].stageFlags;
Tobin Ehlis61ebb312015-11-04 12:28:28 -07003294 if ((dType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
3295 (dType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
3296 pNewNode->dynamicDescriptorCount++;
3297 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003298 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003299 offset += j;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003300 }
3301 }
3302 pNewNode->layout = *pSetLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003303 pNewNode->startIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003304 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
3305 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003306 // Put new node at Head of global Layer list
3307 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisad61de42015-12-02 13:53:34 -07003308 dev_data->descriptorSetLayoutMap[*pSetLayout] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003309 loader_platform_thread_unlock_mutex(&globalLock);
3310 }
3311 return result;
3312}
3313
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003314VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003315{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003316 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003317 VkResult result = dev_data->device_dispatch_table->CreatePipelineLayout(device, pCreateInfo, pAllocator, pPipelineLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003318 if (VK_SUCCESS == result) {
Tobin Ehliscb085292015-12-01 09:57:09 -07003319 // TODOSC : Merge capture of the setLayouts per pipeline
Tobin Ehlis982099b2015-11-05 09:52:49 -07003320 PIPELINE_LAYOUT_NODE& plNode = dev_data->pipelineLayoutMap[*pPipelineLayout];
Chia-I Wu763a7492015-10-26 20:48:51 +08003321 plNode.descriptorSetLayouts.resize(pCreateInfo->setLayoutCount);
Tobin Ehlis91423d22015-10-20 10:11:55 -06003322 uint32_t i = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08003323 for (i=0; i<pCreateInfo->setLayoutCount; ++i) {
Tobin Ehlis91423d22015-10-20 10:11:55 -06003324 plNode.descriptorSetLayouts[i] = pCreateInfo->pSetLayouts[i];
3325 }
Cody Northrop8a908322015-10-26 14:07:35 -06003326 plNode.pushConstantRanges.resize(pCreateInfo->pushConstantRangeCount);
Tobin Ehlis91423d22015-10-20 10:11:55 -06003327 for (i=0; i<pCreateInfo->pushConstantRangeCount; ++i) {
3328 plNode.pushConstantRanges[i] = pCreateInfo->pPushConstantRanges[i];
3329 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003330 }
3331 return result;
3332}
3333
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003334VK_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 -06003335{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003336 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003337 VkResult result = dev_data->device_dispatch_table->CreateDescriptorPool(device, pCreateInfo, pAllocator, pDescriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003338 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003339 // Insert this pool into Global Pool LL at head
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003340 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 +08003341 "Created Descriptor Pool %#" PRIxLEAST64, (uint64_t) *pDescriptorPool))
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003342 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003343 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003344 DESCRIPTOR_POOL_NODE* pNewNode = new DESCRIPTOR_POOL_NODE(*pDescriptorPool, pCreateInfo);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003345 if (NULL == pNewNode) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003346 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 -07003347 "Out of memory while attempting to allocate DESCRIPTOR_POOL_NODE in vkCreateDescriptorPool()"))
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003348 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003349 } else {
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003350 dev_data->descriptorPoolMap[*pDescriptorPool] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003351 }
3352 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003353 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003354 // Need to do anything if pool create fails?
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003355 }
3356 return result;
3357}
3358
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003359VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorPoolResetFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003360{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003361 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003362 VkResult result = dev_data->device_dispatch_table->ResetDescriptorPool(device, descriptorPool, flags);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003363 if (VK_SUCCESS == result) {
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003364 clearDescriptorPool(dev_data, device, descriptorPool, flags);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003365 }
3366 return result;
3367}
3368
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003369VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo* pAllocateInfo, VkDescriptorSet* pDescriptorSets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003370{
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003371 VkBool32 skipCall = VK_FALSE;
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003372 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003373 // Verify that requested descriptorSets are available in pool
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003374 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003375 if (!pPoolNode) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003376 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 +08003377 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pAllocateInfo->descriptorPool);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003378 } else { // Make sure pool has all the available descriptors before calling down chain
Chia-I Wu1f851912015-10-27 18:04:07 +08003379 skipCall |= validate_descriptor_availability_in_pool(dev_data, pPoolNode, pAllocateInfo->setLayoutCount, pAllocateInfo->pSetLayouts);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003380 }
3381 if (skipCall)
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003382 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wu1f851912015-10-27 18:04:07 +08003383 VkResult result = dev_data->device_dispatch_table->AllocateDescriptorSets(device, pAllocateInfo, pDescriptorSets);
Cody Northropc8aa4a52015-08-03 12:47:29 -06003384 if (VK_SUCCESS == result) {
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003385 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003386 if (pPoolNode) {
Chia-I Wu1f851912015-10-27 18:04:07 +08003387 if (pAllocateInfo->setLayoutCount == 0) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003388 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 +08003389 "AllocateDescriptorSets called with 0 count");
Cody Northropc8aa4a52015-08-03 12:47:29 -06003390 }
Chia-I Wu1f851912015-10-27 18:04:07 +08003391 for (uint32_t i = 0; i < pAllocateInfo->setLayoutCount; i++) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003392 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 +08003393 "Created Descriptor Set %#" PRIxLEAST64, (uint64_t) pDescriptorSets[i]);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003394 // Create new set node and add to head of pool nodes
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003395 SET_NODE* pNewNode = new SET_NODE;
3396 if (NULL == pNewNode) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003397 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 +08003398 "Out of memory while attempting to allocate SET_NODE in vkAllocateDescriptorSets()"))
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003399 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003400 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003401 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlisf6e93e02015-10-19 12:09:13 -06003402 // TODO : Pool should store a total count of each type of Descriptor available
3403 // When descriptors are allocated, decrement the count and validate here
3404 // that the count doesn't go below 0. One reset/free need to bump count back up.
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003405 // Insert set at head of Set LL for this pool
3406 pNewNode->pNext = pPoolNode->pSets;
3407 pPoolNode->pSets = pNewNode;
Chia-I Wu1f851912015-10-27 18:04:07 +08003408 LAYOUT_NODE* pLayout = getLayoutNode(dev_data, pAllocateInfo->pSetLayouts[i]);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003409 if (NULL == pLayout) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003410 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 +08003411 "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 -07003412 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003413 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003414 pNewNode->pLayout = pLayout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003415 pNewNode->pool = pAllocateInfo->descriptorPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003416 pNewNode->set = pDescriptorSets[i];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003417 pNewNode->descriptorCount = pLayout->endIndex + 1;
3418 if (pNewNode->descriptorCount) {
3419 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
3420 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
3421 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
3422 }
Chia-I Wue420a332015-10-26 20:04:44 +08003423 dev_data->setMap[pDescriptorSets[i]] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003424 }
3425 }
3426 }
3427 }
3428 return result;
3429}
3430
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003431VK_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 -06003432{
Tobin Ehlis3c543112015-10-08 13:13:50 -06003433 VkBool32 skipCall = VK_FALSE;
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003434 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003435 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, descriptorPool);
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003436 if (pPoolNode && !(VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT & pPoolNode->createInfo.flags)) {
3437 // Can't Free from a NON_FREE pool
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003438 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 -06003439 "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 -06003440 }
3441 if (skipCall)
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003442 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003443 VkResult result = dev_data->device_dispatch_table->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003444 if (VK_SUCCESS == result) {
3445 // For each freed descriptor add it back into the pool as available
3446 for (uint32_t i=0; i<count; ++i) {
Chia-I Wue420a332015-10-26 20:04:44 +08003447 SET_NODE* pSet = dev_data->setMap[pDescriptorSets[i]]; // getSetNode() without locking
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003448 LAYOUT_NODE* pLayout = pSet->pLayout;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003449 uint32_t typeIndex = 0, poolSizeCount = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08003450 for (uint32_t j=0; j<pLayout->createInfo.bindingCount; ++j) {
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003451 typeIndex = static_cast<uint32_t>(pLayout->createInfo.pBinding[j].descriptorType);
Chia-I Wu045654f2015-11-06 06:42:02 +08003452 poolSizeCount = pLayout->createInfo.pBinding[j].descriptorCount;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003453 pPoolNode->availableDescriptorTypeCount[typeIndex] += poolSizeCount;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003454 }
3455 }
3456 }
3457 // TODO : Any other clean-up or book-keeping to do here?
Tony Barbourb857d312015-07-10 10:50:45 -06003458 return result;
3459}
3460
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003461VK_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 -06003462{
Tobin Ehlis68fbd442015-10-27 12:25:35 -06003463 // 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 -06003464 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu483e7702015-10-26 17:20:32 +08003465 if (!dsUpdate(dev_data, device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies)) {
3466 dev_data->device_dispatch_table->UpdateDescriptorSets(device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies);
Jon Ashburne0fa2282015-05-20 09:00:28 -06003467 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003468}
3469
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003470VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo* pCreateInfo, VkCommandBuffer* pCommandBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003471{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003472 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu1f851912015-10-27 18:04:07 +08003473 VkResult result = dev_data->device_dispatch_table->AllocateCommandBuffers(device, pCreateInfo, pCommandBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003474 if (VK_SUCCESS == result) {
Courtney Goeltzenleuchter740451a2015-12-16 16:06:06 -07003475 for (uint32_t i = 0; i < pCreateInfo->bufferCount; i++) {
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003476 // Validate command pool
3477 if (dev_data->commandPoolMap.find(pCreateInfo->commandPool) != dev_data->commandPoolMap.end()) {
Mark Lobodzinski13b66742015-11-20 14:33:48 -07003478 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003479 // Add command buffer to its commandPool map
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003480 dev_data->commandPoolMap[pCreateInfo->commandPool].commandBuffers.push_back(pCommandBuffer[i]);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003481 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
3482 // Add command buffer to map
3483 dev_data->commandBufferMap[pCommandBuffer[i]] = pCB;
Mark Lobodzinski13b66742015-11-20 14:33:48 -07003484 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003485 resetCB(dev_data, pCommandBuffer[i]);
3486 pCB->commandBuffer = pCommandBuffer[i];
3487 pCB->createInfo = *pCreateInfo;
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003488 }
3489 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003490 }
3491 return result;
3492}
3493
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003494VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo* pBeginInfo)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003495{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003496 VkBool32 skipCall = false;
Chia-I Wu1f851912015-10-27 18:04:07 +08003497 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06003498 // Validate command buffer level
Chia-I Wu1f851912015-10-27 18:04:07 +08003499 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06003500 if (pCB) {
Mark Lobodzinskia1420862015-11-19 13:22:11 -07003501 if (pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
Chia-I Wue420a332015-10-26 20:04:44 +08003502 if (pBeginInfo->renderPass || pBeginInfo->framebuffer) {
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06003503 // These should be NULL for a Primary CB
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003504 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 -07003505 "vkBeginCommandBuffer(): Primary Command Buffer (%p) may not specify framebuffer or renderpass parameters", (void*)commandBuffer);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06003506 }
3507 } else {
Chia-I Wue420a332015-10-26 20:04:44 +08003508 if (!pBeginInfo->renderPass || !pBeginInfo->framebuffer) {
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06003509 // These should NOT be null for an Secondary CB
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003510 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 -07003511 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) must specify framebuffer and renderpass parameters", (void*)commandBuffer);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06003512 }
3513 }
Tobin Ehlis0cea4082015-08-18 07:10:58 -06003514 pCB->beginInfo = *pBeginInfo;
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003515 if (CB_RECORDING == pCB->state) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003516 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 -07003517 "vkBeginCommandBuffer(): Cannot call Begin on CB (%#" PRIxLEAST64 ") in the RECORDING state. Must first call vkEndCommandBuffer().", (uint64_t)commandBuffer);
3518 } else if (CB_RECORDED == pCB->state) {
3519 VkCommandPool cmdPool = pCB->createInfo.commandPool;
3520 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003521 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 -07003522 0, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
3523 "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.",
3524 (uint64_t) commandBuffer, (uint64_t) cmdPool);
3525 }
3526 }
Tobin Ehlis0cea4082015-08-18 07:10:58 -06003527 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003528 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 +08003529 "In vkBeginCommandBuffer() and unable to find CommandBuffer Node for CB %p!", (void*)commandBuffer);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06003530 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003531 if (skipCall) {
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003532 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter3abd86e2015-09-04 15:03:52 -06003533 }
Chia-I Wu1f851912015-10-27 18:04:07 +08003534 VkResult result = dev_data->device_dispatch_table->BeginCommandBuffer(commandBuffer, pBeginInfo);
Mark Lobodzinski2ad35592015-11-12 16:14:04 -07003535 if ((VK_SUCCESS == result) && (pCB != NULL)) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003536 if (CB_RECORDED == pCB->state) {
Chia-I Wu1f851912015-10-27 18:04:07 +08003537 resetCB(dev_data, commandBuffer);
Mark Lobodzinski2ad35592015-11-12 16:14:04 -07003538 }
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003539 pCB->state = CB_RECORDING;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003540 }
3541 return result;
3542}
3543
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003544VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEndCommandBuffer(VkCommandBuffer commandBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003545{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003546 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchtera54b76a2015-09-04 13:39:59 -06003547 VkResult result = VK_SUCCESS;
Chia-I Wu1f851912015-10-27 18:04:07 +08003548 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3549 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlise42007c2015-06-19 13:00:59 -06003550 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003551 if (pCB->state != CB_RECORDING) {
Chia-I Wu1f851912015-10-27 18:04:07 +08003552 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkEndCommandBuffer()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003553 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003554 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003555 if (VK_FALSE == skipCall) {
Chia-I Wu1f851912015-10-27 18:04:07 +08003556 result = dev_data->device_dispatch_table->EndCommandBuffer(commandBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003557 if (VK_SUCCESS == result) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003558 pCB->state = CB_RECORDED;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003559 // Reset CB status flags
3560 pCB->status = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08003561 printCB(dev_data, commandBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003562 }
3563 } else {
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003564 result = VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003565 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003566 return result;
3567}
3568
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003569VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003570{
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003571 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003572 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003573 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
3574 VkCommandPool cmdPool = pCB->createInfo.commandPool;
3575 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003576 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 -07003577 0, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
3578 "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.",
3579 (uint64_t) commandBuffer, (uint64_t) cmdPool);
3580 }
3581 if (skipCall)
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003582 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wu1f851912015-10-27 18:04:07 +08003583 VkResult result = dev_data->device_dispatch_table->ResetCommandBuffer(commandBuffer, flags);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003584 if (VK_SUCCESS == result) {
Chia-I Wu1f851912015-10-27 18:04:07 +08003585 resetCB(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003586 }
3587 return result;
3588}
3589
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003590VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003591{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003592 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003593 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3594 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003595 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003596 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003597 skipCall |= addCmd(dev_data, pCB, CMD_BINDPIPELINE);
Mark Lobodzinski7bc3a9e2015-12-17 09:24:14 -07003598 PIPELINE_NODE* pPN = getPipeline(dev_data, pipeline);
3599 if (pPN) {
3600 pCB->lastBoundPipeline = pipeline;
3601 loader_platform_thread_lock_mutex(&globalLock);
3602 set_cb_pso_status(pCB, pPN);
3603 g_lastBoundPipeline = pPN;
3604 loader_platform_thread_unlock_mutex(&globalLock);
3605 skipCall |= validatePipelineState(dev_data, pCB, pipelineBindPoint, pipeline);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003606 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003607 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 -07003608 0, DRAWSTATE_INVALID_PIPELINE, "DS",
3609 "Attempt to bind Pipeline %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<uint64_t>(pipeline));
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003610
Tobin Ehlise42007c2015-06-19 13:00:59 -06003611 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003612 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003613 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindPipeline()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003614 }
3615 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003616 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003617 dev_data->device_dispatch_table->CmdBindPipeline(commandBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003618}
3619
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003620VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetViewport(
Chia-I Wu1f851912015-10-27 18:04:07 +08003621 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06003622 uint32_t viewportCount,
3623 const VkViewport* pViewports)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003624{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003625 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003626 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3627 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlise42007c2015-06-19 13:00:59 -06003628 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003629 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003630 skipCall |= addCmd(dev_data, pCB, CMD_SETVIEWPORTSTATE);
Tobin Ehlise42007c2015-06-19 13:00:59 -06003631 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003632 pCB->status |= CBSTATUS_VIEWPORT_SET;
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06003633 pCB->viewports.resize(viewportCount);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003634 memcpy(pCB->viewports.data(), pViewports, viewportCount * sizeof(VkViewport));
Tobin Ehlise42007c2015-06-19 13:00:59 -06003635 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlise42007c2015-06-19 13:00:59 -06003636 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003637 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdSetViewport()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06003638 }
3639 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003640 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003641 dev_data->device_dispatch_table->CmdSetViewport(commandBuffer, viewportCount, pViewports);
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06003642}
3643
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003644VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetScissor(
Chia-I Wu1f851912015-10-27 18:04:07 +08003645 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06003646 uint32_t scissorCount,
3647 const VkRect2D* pScissors)
3648{
3649 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003650 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3651 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06003652 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003653 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003654 skipCall |= addCmd(dev_data, pCB, CMD_SETSCISSORSTATE);
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06003655 loader_platform_thread_lock_mutex(&globalLock);
3656 pCB->status |= CBSTATUS_SCISSOR_SET;
3657 pCB->scissors.resize(scissorCount);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003658 memcpy(pCB->scissors.data(), pScissors, scissorCount * sizeof(VkRect2D));
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06003659 loader_platform_thread_unlock_mutex(&globalLock);
3660 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003661 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdSetScissor()");
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06003662 }
3663 }
3664 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003665 dev_data->device_dispatch_table->CmdSetScissor(commandBuffer, scissorCount, pScissors);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003666}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003667
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003668VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003669{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003670 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003671 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3672 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003673 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003674 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003675 skipCall |= addCmd(dev_data, pCB, CMD_SETLINEWIDTHSTATE);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003676 /* TODO: Do we still need this lock? */
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003677 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003678 pCB->status |= CBSTATUS_LINE_WIDTH_SET;
3679 pCB->lineWidth = lineWidth;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003680 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003681 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003682 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindDynamicLineWidthState()");
Cody Northropf5bd2252015-08-17 11:10:49 -06003683 }
3684 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003685 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003686 dev_data->device_dispatch_table->CmdSetLineWidth(commandBuffer, lineWidth);
Cody Northropf5bd2252015-08-17 11:10:49 -06003687}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003688
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003689VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBias(
Chia-I Wu1f851912015-10-27 18:04:07 +08003690 VkCommandBuffer commandBuffer,
Chia-I Wufa950c52015-10-26 19:08:09 +08003691 float depthBiasConstantFactor,
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003692 float depthBiasClamp,
Chia-I Wufa950c52015-10-26 19:08:09 +08003693 float depthBiasSlopeFactor)
Cody Northropf5bd2252015-08-17 11:10:49 -06003694{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003695 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003696 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3697 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northropf5bd2252015-08-17 11:10:49 -06003698 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003699 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003700 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBIASSTATE);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003701 pCB->status |= CBSTATUS_DEPTH_BIAS_SET;
Chia-I Wufa950c52015-10-26 19:08:09 +08003702 pCB->depthBiasConstantFactor = depthBiasConstantFactor;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003703 pCB->depthBiasClamp = depthBiasClamp;
Chia-I Wufa950c52015-10-26 19:08:09 +08003704 pCB->depthBiasSlopeFactor = depthBiasSlopeFactor;
Cody Northropf5bd2252015-08-17 11:10:49 -06003705 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003706 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdSetDepthBias()");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003707 }
3708 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003709 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003710 dev_data->device_dispatch_table->CmdSetDepthBias(commandBuffer, depthBiasConstantFactor, depthBiasClamp, depthBiasSlopeFactor);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003711}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003712
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003713VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4])
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003714{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003715 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003716 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3717 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003718 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003719 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003720 skipCall |= addCmd(dev_data, pCB, CMD_SETBLENDSTATE);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003721 pCB->status |= CBSTATUS_BLEND_SET;
Chia-I Wu7e470702015-10-26 17:24:52 +08003722 memcpy(pCB->blendConstants, blendConstants, 4 * sizeof(float));
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003723 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003724 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdSetBlendConstants()");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003725 }
3726 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003727 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003728 dev_data->device_dispatch_table->CmdSetBlendConstants(commandBuffer, blendConstants);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003729}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003730
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003731VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBounds(
Chia-I Wu1f851912015-10-27 18:04:07 +08003732 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003733 float minDepthBounds,
3734 float maxDepthBounds)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003735{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003736 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003737 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3738 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003739 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003740 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003741 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBOUNDSSTATE);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003742 pCB->status |= CBSTATUS_DEPTH_BOUNDS_SET;
3743 pCB->minDepthBounds = minDepthBounds;
3744 pCB->maxDepthBounds = maxDepthBounds;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003745 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003746 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdSetDepthBounds()");
Cody Northrop2605cb02015-08-18 15:21:16 -06003747 }
3748 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003749 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003750 dev_data->device_dispatch_table->CmdSetDepthBounds(commandBuffer, minDepthBounds, maxDepthBounds);
Cody Northrop2605cb02015-08-18 15:21:16 -06003751}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003752
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003753VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilCompareMask(
Chia-I Wu1f851912015-10-27 18:04:07 +08003754 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003755 VkStencilFaceFlags faceMask,
Chia-I Wuc51b1212015-10-27 19:25:11 +08003756 uint32_t compareMask)
Cody Northrop2605cb02015-08-18 15:21:16 -06003757{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003758 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003759 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3760 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northrop2605cb02015-08-18 15:21:16 -06003761 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003762 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003763 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREADMASKSTATE);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003764 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
Chia-I Wuc51b1212015-10-27 19:25:11 +08003765 pCB->front.compareMask = compareMask;
Cody Northrop2605cb02015-08-18 15:21:16 -06003766 }
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003767 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
Chia-I Wuc51b1212015-10-27 19:25:11 +08003768 pCB->back.compareMask = compareMask;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003769 }
3770 /* TODO: Do we need to track front and back separately? */
3771 /* TODO: We aren't capturing the faceMask, do we need to? */
3772 pCB->status |= CBSTATUS_STENCIL_READ_MASK_SET;
Cody Northrop2605cb02015-08-18 15:21:16 -06003773 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003774 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdSetStencilCompareMask()");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003775 }
3776 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003777 if (VK_FALSE == skipCall)
Chia-I Wuc51b1212015-10-27 19:25:11 +08003778 dev_data->device_dispatch_table->CmdSetStencilCompareMask(commandBuffer, faceMask, compareMask);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003779}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003780
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003781VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilWriteMask(
Chia-I Wu1f851912015-10-27 18:04:07 +08003782 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003783 VkStencilFaceFlags faceMask,
Chia-I Wuc51b1212015-10-27 19:25:11 +08003784 uint32_t writeMask)
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003785{
3786 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003787 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3788 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003789 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003790 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003791 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILWRITEMASKSTATE);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003792 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
Chia-I Wuc51b1212015-10-27 19:25:11 +08003793 pCB->front.writeMask = writeMask;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003794 }
3795 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
Chia-I Wuc51b1212015-10-27 19:25:11 +08003796 pCB->back.writeMask = writeMask;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003797 }
3798 pCB->status |= CBSTATUS_STENCIL_WRITE_MASK_SET;
3799 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003800 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdSetStencilWriteMask()");
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003801 }
3802 }
3803 if (VK_FALSE == skipCall)
Chia-I Wuc51b1212015-10-27 19:25:11 +08003804 dev_data->device_dispatch_table->CmdSetStencilWriteMask(commandBuffer, faceMask, writeMask);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003805}
3806
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003807VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilReference(
Chia-I Wu1f851912015-10-27 18:04:07 +08003808 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003809 VkStencilFaceFlags faceMask,
Chia-I Wuc51b1212015-10-27 19:25:11 +08003810 uint32_t reference)
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003811{
3812 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003813 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3814 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003815 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003816 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003817 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREFERENCESTATE);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003818 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
Chia-I Wuc51b1212015-10-27 19:25:11 +08003819 pCB->front.reference = reference;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003820 }
3821 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
Chia-I Wuc51b1212015-10-27 19:25:11 +08003822 pCB->back.reference = reference;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003823 }
3824 pCB->status |= CBSTATUS_STENCIL_REFERENCE_SET;
3825 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003826 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdSetStencilReference()");
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003827 }
3828 }
3829 if (VK_FALSE == skipCall)
Chia-I Wuc51b1212015-10-27 19:25:11 +08003830 dev_data->device_dispatch_table->CmdSetStencilReference(commandBuffer, faceMask, reference);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003831}
3832
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003833VK_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 -06003834{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003835 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003836 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3837 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003838 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003839 if (pCB->state == CB_RECORDING) {
Tobin Ehlise4076782015-06-24 15:53:07 -06003840 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003841 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 +08003842 "Incorrectly binding compute DescriptorSets during active RenderPass (%#" PRIxLEAST64 ")", (uint64_t) pCB->activeRenderPass);
Tobin Ehlise4076782015-06-24 15:53:07 -06003843 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) && (!pCB->activeRenderPass)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003844 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 -06003845 "Incorrectly binding graphics DescriptorSets without an active RenderPass");
Tobin Ehlisd28acef2015-09-09 15:12:35 -06003846 } else {
Tobin Ehlis61ebb312015-11-04 12:28:28 -07003847 // Track total count of dynamic descriptor types to make sure we have an offset for each one
3848 uint32_t totalDynamicDescriptors = 0;
Tobin Ehlis982099b2015-11-05 09:52:49 -07003849 string errorString = "";
Tobin Ehliscb085292015-12-01 09:57:09 -07003850 uint32_t lastSetIndex = firstSet+setCount-1;
Tobin Ehlis982099b2015-11-05 09:52:49 -07003851 if (lastSetIndex >= pCB->boundDescriptorSets.size())
3852 pCB->boundDescriptorSets.resize(lastSetIndex+1);
3853 VkDescriptorSet oldFinalBoundSet = pCB->boundDescriptorSets[lastSetIndex];
Tobin Ehlise42007c2015-06-19 13:00:59 -06003854 for (uint32_t i=0; i<setCount; i++) {
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06003855 SET_NODE* pSet = getSetNode(dev_data, pDescriptorSets[i]);
Tobin Ehlis55c1c602015-06-24 17:27:33 -06003856 if (pSet) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06003857 loader_platform_thread_lock_mutex(&globalLock);
3858 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06003859 pCB->lastBoundPipelineLayout = layout;
Tobin Ehlis982099b2015-11-05 09:52:49 -07003860 pCB->boundDescriptorSets[i+firstSet] = pDescriptorSets[i];
Tobin Ehlise42007c2015-06-19 13:00:59 -06003861 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003862 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 +08003863 "DS %#" PRIxLEAST64 " bound on pipeline %s", (uint64_t) pDescriptorSets[i], string_VkPipelineBindPoint(pipelineBindPoint));
Tobin Ehlis61ebb312015-11-04 12:28:28 -07003864 if (!pSet->pUpdateStructs) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003865 // TODO: Verify against Valid Usage
3866 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 +08003867 "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 -07003868 }
Tobin Ehlis982099b2015-11-05 09:52:49 -07003869 // Verify that set being bound is compatible with overlapping setLayout of pipelineLayout
3870 if (!verify_set_layout_compatibility(dev_data, pSet, layout, i+firstSet, errorString)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003871 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 -07003872 "descriptorSet #%u being bound is not compatible with overlapping layout in pipelineLayout due to: %s", i, errorString.c_str());
3873 }
Tobin Ehlis61ebb312015-11-04 12:28:28 -07003874 totalDynamicDescriptors += pSet->pLayout->dynamicDescriptorCount;
Tobin Ehlise42007c2015-06-19 13:00:59 -06003875 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003876 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 +08003877 "Attempt to bind DS %#" PRIxLEAST64 " that doesn't exist!", (uint64_t) pDescriptorSets[i]);
Tobin Ehlise42007c2015-06-19 13:00:59 -06003878 }
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06003879 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003880 skipCall |= addCmd(dev_data, pCB, CMD_BINDDESCRIPTORSETS);
Tobin Ehlis982099b2015-11-05 09:52:49 -07003881 // For any previously bound sets, need to set them to "invalid" if they were disturbed by this update
3882 if (firstSet > 0) { // Check set #s below the first bound set
3883 for (uint32_t i=0; i<firstSet; ++i) {
Tobin Ehliscb085292015-12-01 09:57:09 -07003884 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 -07003885 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 -07003886 "DescriptorSetDS %#" PRIxLEAST64 " previously bound as set #%u was disturbed by newly bound pipelineLayout (%#" PRIxLEAST64 ")", (uint64_t) pCB->boundDescriptorSets[i], i, (uint64_t) layout);
3887 pCB->boundDescriptorSets[i] = VK_NULL_HANDLE;
3888 }
3889 }
3890 }
3891 // Check if newly last bound set invalidates any remaining bound sets
3892 if ((pCB->boundDescriptorSets.size()-1) > (lastSetIndex)) {
Tobin Ehliscb085292015-12-01 09:57:09 -07003893 if (oldFinalBoundSet && !verify_set_layout_compatibility(dev_data, dev_data->setMap[oldFinalBoundSet], layout, lastSetIndex, errorString)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003894 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 -07003895 "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 -07003896 pCB->boundDescriptorSets.resize(lastSetIndex+1);
3897 }
3898 }
Tobin Ehlis61ebb312015-11-04 12:28:28 -07003899 // dynamicOffsetCount must equal the total number of dynamic descriptors in the sets being bound
3900 if (totalDynamicDescriptors != dynamicOffsetCount) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003901 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 -07003902 "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);
3903 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003904 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06003905 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003906 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindDescriptorSets()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003907 }
3908 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003909 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003910 dev_data->device_dispatch_table->CmdBindDescriptorSets(commandBuffer, pipelineBindPoint, layout, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003911}
3912
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003913VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003914{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003915 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003916 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3917 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003918 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003919 if (pCB->state == CB_RECORDING) {
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003920 VkDeviceSize offset_align = 0;
3921 switch (indexType) {
3922 case VK_INDEX_TYPE_UINT16:
3923 offset_align = 2;
3924 break;
3925 case VK_INDEX_TYPE_UINT32:
3926 offset_align = 4;
3927 break;
3928 default:
3929 // ParamChecker should catch bad enum, we'll also throw alignment error below if offset_align stays 0
3930 break;
3931 }
3932 if (!offset_align || (offset % offset_align)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003933 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 -06003934 "vkCmdBindIndexBuffer() offset (%#" PRIxLEAST64 ") does not fall on alignment (%s) boundary.", offset, string_VkIndexType(indexType));
Tobin Ehlise4076782015-06-24 15:53:07 -06003935 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003936 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003937 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06003938 }
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003939 pCB->status |= CBSTATUS_INDEX_BUFFER_BOUND;
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003940 skipCall |= addCmd(dev_data, pCB, CMD_BINDINDEXBUFFER);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003941 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003942 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003943 dev_data->device_dispatch_table->CmdBindIndexBuffer(commandBuffer, buffer, offset, indexType);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003944}
3945
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003946VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindVertexBuffers(
Mark Lobodzinski74e84692015-12-14 15:14:10 -07003947 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003948 uint32_t startBinding,
3949 uint32_t bindingCount,
Mark Lobodzinski74e84692015-12-14 15:14:10 -07003950 const VkBuffer *pBuffers,
3951 const VkDeviceSize *pOffsets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003952{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003953 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003954 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3955 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003956 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003957 if (pCB->state == CB_RECORDING) {
Mark Lobodzinski74e84692015-12-14 15:14:10 -07003958 if ((startBinding + bindingCount) > pCB->boundVtxBuffers.size()) {
3959 pCB->boundVtxBuffers.resize(startBinding+bindingCount, VK_NULL_HANDLE);
3960 }
Courtney Goeltzenleuchter740451a2015-12-16 16:06:06 -07003961 for (uint32_t i = 0; i < bindingCount; i++) {
Mark Lobodzinski74e84692015-12-14 15:14:10 -07003962 pCB->boundVtxBuffers[i+startBinding] = pBuffers[i];
3963 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003964 addCmd(dev_data, pCB, CMD_BINDVERTEXBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003965 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003966 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindVertexBuffer()");
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06003967 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003968 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003969 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003970 dev_data->device_dispatch_table->CmdBindVertexBuffers(commandBuffer, startBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003971}
3972
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003973VK_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 -06003974{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003975 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003976 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3977 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003978 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003979 if (pCB->state == CB_RECORDING) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06003980 pCB->drawCount[DRAW]++;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06003981 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
Chia-I Wu1f851912015-10-27 18:04:07 +08003982 // TODO : Need to pass commandBuffer as srcObj here
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003983 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 -08003984 "vkCmdDraw() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW]++);
Chia-I Wu1f851912015-10-27 18:04:07 +08003985 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003986 if (VK_FALSE == skipCall) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003987 skipCall |= addCmd(dev_data, pCB, CMD_DRAW);
Tobin Ehlise42007c2015-06-19 13:00:59 -06003988 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003989 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003990 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdDraw()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06003991 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003992 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDraw");
Jon Ashburne0fa2282015-05-20 09:00:28 -06003993 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003994 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003995 dev_data->device_dispatch_table->CmdDraw(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003996}
3997
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003998VK_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 -06003999{
Chia-I Wu1f851912015-10-27 18:04:07 +08004000 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4001 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004002 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004003 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004004 if (pCB->state == CB_RECORDING) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06004005 pCB->drawCount[DRAW_INDEXED]++;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06004006 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
Chia-I Wu1f851912015-10-27 18:04:07 +08004007 // TODO : Need to pass commandBuffer as srcObj here
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004008 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 -08004009 "vkCmdDrawIndexed() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED]++);
Chia-I Wu1f851912015-10-27 18:04:07 +08004010 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004011 if (VK_FALSE == skipCall) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004012 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXED);
Tobin Ehlise42007c2015-06-19 13:00:59 -06004013 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004014 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004015 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdDrawIndexed()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004016 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004017 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexed");
Jon Ashburne0fa2282015-05-20 09:00:28 -06004018 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004019 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004020 dev_data->device_dispatch_table->CmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004021}
4022
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004023VK_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 -06004024{
Chia-I Wu1f851912015-10-27 18:04:07 +08004025 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4026 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004027 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004028 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004029 if (pCB->state == CB_RECORDING) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06004030 pCB->drawCount[DRAW_INDIRECT]++;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06004031 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
Chia-I Wu1f851912015-10-27 18:04:07 +08004032 // TODO : Need to pass commandBuffer as srcObj here
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004033 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 -08004034 "vkCmdDrawIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
Chia-I Wu1f851912015-10-27 18:04:07 +08004035 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004036 if (VK_FALSE == skipCall) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004037 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDIRECT);
Tobin Ehlise42007c2015-06-19 13:00:59 -06004038 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004039 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004040 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdDrawIndirect()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004041 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004042 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndirect");
Jon Ashburne0fa2282015-05-20 09:00:28 -06004043 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004044 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004045 dev_data->device_dispatch_table->CmdDrawIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004046}
4047
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004048VK_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 -06004049{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004050 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004051 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4052 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004053 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004054 if (pCB->state == CB_RECORDING) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06004055 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06004056 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
Chia-I Wu1f851912015-10-27 18:04:07 +08004057 // TODO : Need to pass commandBuffer as srcObj here
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004058 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 -08004059 "vkCmdDrawIndexedIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
Chia-I Wu1f851912015-10-27 18:04:07 +08004060 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004061 if (VK_FALSE == skipCall) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004062 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXEDINDIRECT);
Tobin Ehlise42007c2015-06-19 13:00:59 -06004063 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004064 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004065 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdDrawIndexedIndirect()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004066 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004067 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexedIndirect");
Jon Ashburne0fa2282015-05-20 09:00:28 -06004068 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004069 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004070 dev_data->device_dispatch_table->CmdDrawIndexedIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004071}
4072
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004073VK_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 -06004074{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004075 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004076 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4077 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004078 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004079 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004080 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCH);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004081 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004082 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdDispatch()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004083 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004084 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatch");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004085 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004086 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004087 dev_data->device_dispatch_table->CmdDispatch(commandBuffer, x, y, z);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004088}
4089
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004090VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004091{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004092 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004093 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4094 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004095 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004096 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004097 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCHINDIRECT);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004098 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004099 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdDispatchIndirect()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004100 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004101 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatchIndirect");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004102 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004103 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004104 dev_data->device_dispatch_table->CmdDispatchIndirect(commandBuffer, buffer, offset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004105}
4106
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004107VK_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 -06004108{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004109 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004110 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4111 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004112 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004113 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004114 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004115 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004116 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdCopyBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004117 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004118 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBuffer");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004119 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004120 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004121 dev_data->device_dispatch_table->CmdCopyBuffer(commandBuffer, srcBuffer, dstBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004122}
4123
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004124VkBool32 VerifySourceImageLayout(VkCommandBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout) {
4125 VkBool32 skip_call = false;
Mark Lobodzinski78940a42015-11-30 16:48:53 -07004126
4127#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4128 // TODO: Fix -- initialLayout may have been set in a previous command buffer
4129 return skip_call;
4130#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4131
Michael Lentine27b0f902015-10-12 11:30:14 -05004132 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4133 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4134 auto src_image_element = pCB->imageLayoutMap.find(srcImage);
4135 if (src_image_element == pCB->imageLayoutMap.end()) {
4136 pCB->imageLayoutMap[srcImage].initialLayout = srcImageLayout;
4137 pCB->imageLayoutMap[srcImage].layout = srcImageLayout;
4138 return false;
4139 }
4140 if (src_image_element->second.layout != srcImageLayout) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004141 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 -05004142 "Cannot copy from an image whose source layout is %d and doesn't match the current layout %d.", srcImageLayout, src_image_element->second.layout);
4143 }
4144 if (srcImageLayout != VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL) {
4145 if (srcImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004146 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
4147 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 -05004148 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Michael Lentine27b0f902015-10-12 11:30:14 -05004149 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004150 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 -05004151 "Layout for input image is %d but can only be TRANSFER_SRC_OPTIMAL or GENERAL.", srcImageLayout);
Michael Lentine27b0f902015-10-12 11:30:14 -05004152 }
4153 }
4154 return skip_call;
4155}
4156
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004157VkBool32 VerifyDestImageLayout(VkCommandBuffer cmdBuffer, VkImage destImage, VkImageLayout destImageLayout) {
4158 VkBool32 skip_call = false;
Mark Lobodzinski78940a42015-11-30 16:48:53 -07004159
4160#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4161 // TODO: Fix -- initialLayout may have been set in a previous command buffer
4162 return skip_call;
4163#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4164
Michael Lentine27b0f902015-10-12 11:30:14 -05004165 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4166 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4167 auto dest_image_element = pCB->imageLayoutMap.find(destImage);
4168 if (dest_image_element == pCB->imageLayoutMap.end()) {
4169 pCB->imageLayoutMap[destImage].initialLayout = destImageLayout;
4170 pCB->imageLayoutMap[destImage].layout = destImageLayout;
4171 return false;
4172 }
4173 if (dest_image_element->second.layout != destImageLayout) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004174 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 -05004175 "Cannot copy from an image whose dest layout is %d and doesn't match the current layout %d.", destImageLayout, dest_image_element->second.layout);
4176 }
4177 if (destImageLayout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) {
4178 if (destImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004179 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
4180 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 -05004181 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
4182 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004183 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 -05004184 "Layout for output image is %d but can only be TRANSFER_DST_OPTIMAL or GENERAL.", destImageLayout);
4185 }
4186 }
4187 return skip_call;
4188}
4189
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004190VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004191 VkImage srcImage,
4192 VkImageLayout srcImageLayout,
Chia-I Wu1f851912015-10-27 18:04:07 +08004193 VkImage dstImage,
4194 VkImageLayout dstImageLayout,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004195 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004196{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004197 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004198 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4199 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004200 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004201 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004202 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGE);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004203 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004204 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdCopyImage()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004205 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004206 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImage");
Michael Lentine27b0f902015-10-12 11:30:14 -05004207 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
4208 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004209 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004210 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004211 dev_data->device_dispatch_table->CmdCopyImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004212}
4213
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004214VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBlitImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004215 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu1f851912015-10-27 18:04:07 +08004216 VkImage dstImage, VkImageLayout dstImageLayout,
Mark Lobodzinski20f68592015-05-22 14:43:25 -05004217 uint32_t regionCount, const VkImageBlit* pRegions,
Chia-I Wu3603b082015-10-26 16:49:32 +08004218 VkFilter filter)
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06004219{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004220 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004221 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4222 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06004223 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004224 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004225 skipCall |= addCmd(dev_data, pCB, CMD_BLITIMAGE);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004226 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004227 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBlitImage()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004228 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004229 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBlitImage");
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06004230 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004231 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004232 dev_data->device_dispatch_table->CmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06004233}
4234
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004235VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004236 VkBuffer srcBuffer,
Chia-I Wu1f851912015-10-27 18:04:07 +08004237 VkImage dstImage, VkImageLayout dstImageLayout,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004238 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004239{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004240 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004241 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4242 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004243 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004244 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004245 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFERTOIMAGE);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004246 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004247 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdCopyBufferToImage()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004248 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004249 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBufferToImage");
Michael Lentine27b0f902015-10-12 11:30:14 -05004250 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004251 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004252 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004253 dev_data->device_dispatch_table->CmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004254}
4255
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004256VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004257 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu1f851912015-10-27 18:04:07 +08004258 VkBuffer dstBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004259 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004260{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004261 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004262 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4263 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004264 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004265 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004266 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGETOBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004267 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004268 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdCopyImageToBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004269 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004270 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImageToBuffer");
Michael Lentine27b0f902015-10-12 11:30:14 -05004271 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004272 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004273 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004274 dev_data->device_dispatch_table->CmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004275}
4276
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004277VK_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 -06004278{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004279 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004280 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4281 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004282 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004283 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004284 skipCall |= addCmd(dev_data, pCB, CMD_UPDATEBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004285 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004286 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdUpdateBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004287 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004288 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyUpdateBuffer");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004289 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004290 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004291 dev_data->device_dispatch_table->CmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004292}
4293
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004294VK_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 -06004295{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004296 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004297 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4298 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004299 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004300 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004301 skipCall |= addCmd(dev_data, pCB, CMD_FILLBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004302 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004303 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdFillBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004304 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004305 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyFillBuffer");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004306 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004307 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004308 dev_data->device_dispatch_table->CmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004309}
4310
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004311VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearAttachments(
Chia-I Wu1f851912015-10-27 18:04:07 +08004312 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004313 uint32_t attachmentCount,
4314 const VkClearAttachment* pAttachments,
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004315 uint32_t rectCount,
Courtney Goeltzenleuchtera12e2912015-10-15 18:22:08 -06004316 const VkClearRect* pRects)
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004317{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004318 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004319 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4320 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004321 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004322 if (pCB->state == CB_RECORDING) {
Mark Lobodzinski92c712c2015-12-08 13:47:14 -07004323 // Warn if this is issued prior to Draw Cmd and clearing the entire attachment
4324 if (!hasDrawCmd(pCB) &&
4325 (pCB->activeRenderPassBeginInfo.renderArea.extent.width == pRects[0].rect.extent.width) &&
4326 (pCB->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) {
Chia-I Wu1f851912015-10-27 18:04:07 +08004327 // TODO : commandBuffer should be srcObj
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004328 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 -06004329 "vkCmdClearAttachments() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
Chia-I Wu1f851912015-10-27 18:04:07 +08004330 " 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 -06004331 }
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004332 skipCall |= addCmd(dev_data, pCB, CMD_CLEARATTACHMENTS);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004333 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004334 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdClearAttachments()");
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004335 }
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004336 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdClearAttachments");
4337 }
4338
4339 // Validate that attachment is in reference list of active subpass
4340 if (pCB->activeRenderPass) {
Tobin Ehlisad61de42015-12-02 13:53:34 -07004341 const VkRenderPassCreateInfo *pRPCI = dev_data->renderPassMap[pCB->activeRenderPass]->pCreateInfo;
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004342 const VkSubpassDescription *pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
4343
4344 for (uint32_t attachment_idx = 0; attachment_idx < attachmentCount; attachment_idx++) {
4345 const VkClearAttachment *attachment = &pAttachments[attachment_idx];
4346 if (attachment->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) {
4347 VkBool32 found = VK_FALSE;
Chia-I Wu763a7492015-10-26 20:48:51 +08004348 for (uint32_t i = 0; i < pSD->colorAttachmentCount; i++) {
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004349 if (attachment->colorAttachment == pSD->pColorAttachments[i].attachment) {
4350 found = VK_TRUE;
4351 break;
4352 }
4353 }
4354 if (VK_FALSE == found) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004355 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 +08004356 (uint64_t)commandBuffer, 0, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004357 "vkCmdClearAttachments() attachment index %d not found in attachment reference array of active subpass %d",
4358 attachment->colorAttachment, pCB->activeSubpass);
4359 }
4360 } else if (attachment->aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) {
Mark Lobodzinski1523e3a2015-11-17 15:11:24 -07004361 if (!pSD->pDepthStencilAttachment || // Says no DS will be used in active subpass
Mark Lobodzinskiea1fff22015-11-18 08:58:31 -07004362 (pSD->pDepthStencilAttachment->attachment == VK_ATTACHMENT_UNUSED)) { // Says no DS will be used in active subpass
Mark Lobodzinski1523e3a2015-11-17 15:11:24 -07004363
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004364 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 -07004365 (uint64_t)commandBuffer, 0, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
4366 "vkCmdClearAttachments() attachment index %d does not match depthStencilAttachment.attachment (%d) found in active subpass %d",
4367 attachment->colorAttachment,
4368 (pSD->pDepthStencilAttachment) ? pSD->pDepthStencilAttachment->attachment : VK_ATTACHMENT_UNUSED,
4369 pCB->activeSubpass);
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004370 }
4371 }
4372 }
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004373 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004374 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004375 dev_data->device_dispatch_table->CmdClearAttachments(commandBuffer, attachmentCount, pAttachments, rectCount, pRects);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004376}
4377
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004378VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearColorImage(
Chia-I Wu1f851912015-10-27 18:04:07 +08004379 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06004380 VkImage image, VkImageLayout imageLayout,
Chris Forbese3105972015-06-24 14:34:53 +12004381 const VkClearColorValue *pColor,
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06004382 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004383{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004384 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004385 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4386 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004387 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004388 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004389 skipCall |= addCmd(dev_data, pCB, CMD_CLEARCOLORIMAGE);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004390 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004391 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdClearColorImage()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004392 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004393 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearColorImage");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004394 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004395 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004396 dev_data->device_dispatch_table->CmdClearColorImage(commandBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004397}
4398
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004399VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearDepthStencilImage(
Chia-I Wu1f851912015-10-27 18:04:07 +08004400 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter315ad992015-09-15 18:03:22 -06004401 VkImage image, VkImageLayout imageLayout,
4402 const VkClearDepthStencilValue *pDepthStencil,
4403 uint32_t rangeCount,
4404 const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004405{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004406 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004407 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4408 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004409 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004410 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004411 skipCall |= addCmd(dev_data, pCB, CMD_CLEARDEPTHSTENCILIMAGE);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004412 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004413 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdClearDepthStencilImage()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004414 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004415 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearDepthStencilImage");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004416 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004417 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004418 dev_data->device_dispatch_table->CmdClearDepthStencilImage(commandBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004419}
4420
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004421VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResolveImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004422 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu1f851912015-10-27 18:04:07 +08004423 VkImage dstImage, VkImageLayout dstImageLayout,
Tony Barbour11f74372015-04-13 15:02:52 -06004424 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004425{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004426 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004427 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4428 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004429 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004430 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004431 skipCall |= addCmd(dev_data, pCB, CMD_RESOLVEIMAGE);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004432 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004433 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdResolveImage()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004434 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004435 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResolveImage");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004436 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004437 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004438 dev_data->device_dispatch_table->CmdResolveImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004439}
4440
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004441VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004442{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004443 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004444 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4445 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004446 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004447 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004448 skipCall |= addCmd(dev_data, pCB, CMD_SETEVENT);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004449 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004450 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdSetEvent()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004451 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004452 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdSetEvent");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004453 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004454 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004455 dev_data->device_dispatch_table->CmdSetEvent(commandBuffer, event, stageMask);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004456}
4457
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004458VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004459{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004460 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004461 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4462 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004463 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004464 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004465 skipCall |= addCmd(dev_data, pCB, CMD_RESETEVENT);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004466 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004467 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdResetEvent()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004468 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004469 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResetEvent");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004470 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004471 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004472 dev_data->device_dispatch_table->CmdResetEvent(commandBuffer, event, stageMask);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004473}
4474
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004475VkBool32 TransitionImageLayouts(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const void* const* ppMemBarriers) {
Michael Lentine27b0f902015-10-12 11:30:14 -05004476 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4477 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004478 VkBool32 skip = false;
Mark Lobodzinski78940a42015-11-30 16:48:53 -07004479
4480#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4481 // TODO: Fix -- pay attention to image subresource ranges -- not all subresources transition at the same time
4482 return skip;
4483#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4484
Michael Lentine27b0f902015-10-12 11:30:14 -05004485 for (uint32_t i = 0; i < memBarrierCount; ++i) {
4486 auto mem_barrier = reinterpret_cast<const VkMemoryBarrier*>(ppMemBarriers[i]);
4487 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
4488 auto image_mem_barrier = reinterpret_cast<const VkImageMemoryBarrier*>(mem_barrier);
4489 auto image_data = pCB->imageLayoutMap.find(image_mem_barrier->image);
4490 if (image_data == pCB->imageLayoutMap.end()) {
4491 pCB->imageLayoutMap[image_mem_barrier->image].initialLayout = image_mem_barrier->oldLayout;
4492 pCB->imageLayoutMap[image_mem_barrier->image].layout = image_mem_barrier->newLayout;
4493 } else {
4494 if (image_data->second.layout != image_mem_barrier->oldLayout) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004495 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 -07004496 "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 -05004497 }
4498 image_data->second.layout = image_mem_barrier->newLayout;
4499 }
4500 }
4501 }
4502 return skip;
4503}
4504
Michael Lentine8469dd62015-11-20 09:48:52 -08004505// AccessFlags MUST have 'required_bit' set, and may have one or more of 'optional_bits' set.
4506// If required_bit is zero, accessMask must have at least one of 'optional_bits' set
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004507VkBool32 ValidateMaskBits(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout, VkAccessFlags required_bit, VkAccessFlags optional_bits) {
4508 VkBool32 skip_call = false;
Michael Lentine8469dd62015-11-20 09:48:52 -08004509 if ((accessMask & required_bit) || (!required_bit && (accessMask & optional_bits))) {
4510 if (accessMask & !(required_bit | optional_bits)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004511 // TODO: Verify against Valid Use
4512 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 -08004513 "Additional bits in accessMask %d are specified when layout is %s.", accessMask, string_VkImageLayout(layout));
Michael Lentine472af7d2015-10-16 18:08:09 -05004514 }
4515 } else {
Michael Lentine8469dd62015-11-20 09:48:52 -08004516 if (!required_bit) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004517 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 -08004518 "AccessMask %d must contain at least one of access bits %d when layout is %s.",
4519 accessMask, optional_bits, string_VkImageLayout(layout));
4520 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004521 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 -08004522 "AccessMask %d must have required access bit %d and may have optional bits %d when layout is %s.",
4523 accessMask, required_bit, optional_bits,string_VkImageLayout(layout));
4524 }
Michael Lentine472af7d2015-10-16 18:08:09 -05004525 }
4526 return skip_call;
4527}
4528
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004529VkBool32 ValidateMaskBitsFromLayouts(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout) {
4530 VkBool32 skip_call = false;
Michael Lentine8469dd62015-11-20 09:48:52 -08004531 switch (layout) {
4532 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: {
4533 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_COLOR_ATTACHMENT_READ_BIT);
4534 break;
Michael Lentine472af7d2015-10-16 18:08:09 -05004535 }
Michael Lentine8469dd62015-11-20 09:48:52 -08004536 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: {
4537 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT);
4538 break;
Michael Lentine472af7d2015-10-16 18:08:09 -05004539 }
Michael Lentine8469dd62015-11-20 09:48:52 -08004540 case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: {
4541 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_WRITE_BIT, 0);
4542 break;
4543 }
4544 case VK_IMAGE_LAYOUT_PREINITIALIZED: {
4545 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_HOST_WRITE_BIT, 0);
4546 break;
4547 }
4548 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: {
4549 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, 0, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT);
4550 break;
4551 }
4552 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: {
4553 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, 0, VK_ACCESS_INPUT_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT);
4554 break;
4555 }
4556 case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: {
4557 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_READ_BIT, 0);
4558 break;
4559 }
4560 case VK_IMAGE_LAYOUT_UNDEFINED: {
4561 if (accessMask != 0) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004562 // TODO: Verify against Valid Use section spec
4563 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 -08004564 "Additional bits in accessMask %d are specified when layout is %s.", accessMask, string_VkImageLayout(layout));
4565 }
4566 break;
4567 }
4568 case VK_IMAGE_LAYOUT_GENERAL:
4569 default: {
4570 break;
4571 }
Michael Lentine472af7d2015-10-16 18:08:09 -05004572 }
4573 return skip_call;
4574}
4575
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004576VkBool32 ValidateBarriers(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const void* const* ppMemBarriers) {
4577 VkBool32 skip_call = false;
Michael Lentine07ff1a12015-10-15 17:07:00 -05004578 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4579 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4580 if (pCB->activeRenderPass && memBarrierCount) {
4581 for (uint32_t i = 0; i < memBarrierCount; ++i) {
4582 auto mem_barrier = reinterpret_cast<const VkMemoryBarrier*>(ppMemBarriers[i]);
4583 if (mem_barrier && mem_barrier->sType != VK_STRUCTURE_TYPE_MEMORY_BARRIER) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004584 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 -05004585 "Image or Buffers Barriers cannot be used during a render pass.");
4586 }
4587 }
4588 if (!dev_data->renderPassMap[pCB->activeRenderPass]->hasSelfDependency[pCB->activeSubpass]) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004589 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 -05004590 "Barriers cannot be set during subpass %d with no self dependency specified.", pCB->activeSubpass);
4591 }
4592 }
Mark Lobodzinskib684b512015-11-20 09:27:27 -07004593
Michael Lentine472af7d2015-10-16 18:08:09 -05004594 for (uint32_t i = 0; i < memBarrierCount; ++i) {
4595 auto mem_barrier = reinterpret_cast<const VkMemoryBarrier*>(ppMemBarriers[i]);
4596 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
4597 auto image_mem_barrier = reinterpret_cast<const VkImageMemoryBarrier*>(mem_barrier);
Michael Lentine8469dd62015-11-20 09:48:52 -08004598 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, image_mem_barrier->srcAccessMask, image_mem_barrier->oldLayout);
4599 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, image_mem_barrier->dstAccessMask, image_mem_barrier->newLayout);
Michael Lentine472af7d2015-10-16 18:08:09 -05004600 }
4601 }
Mark Lobodzinskib95fc092015-12-03 15:42:32 -07004602
Michael Lentine07ff1a12015-10-15 17:07:00 -05004603 return skip_call;
4604}
4605
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004606VK_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 -06004607{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004608 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004609 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4610 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004611 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004612 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004613 skipCall |= addCmd(dev_data, pCB, CMD_WAITEVENTS);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004614 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004615 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdWaitEvents()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004616 }
Michael Lentine27b0f902015-10-12 11:30:14 -05004617 skipCall |= TransitionImageLayouts(commandBuffer, memoryBarrierCount, ppMemoryBarriers);
Michael Lentine07ff1a12015-10-15 17:07:00 -05004618 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, ppMemoryBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004619 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004620 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004621 dev_data->device_dispatch_table->CmdWaitEvents(commandBuffer, eventCount, pEvents, sourceStageMask, dstStageMask, memoryBarrierCount, ppMemoryBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004622}
4623
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004624VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, uint32_t memoryBarrierCount, const void* const* ppMemoryBarriers)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004625{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004626 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004627 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4628 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004629 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004630 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004631 skipCall |= addCmd(dev_data, pCB, CMD_PIPELINEBARRIER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004632 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004633 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdPipelineBarrier()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004634 }
Michael Lentine27b0f902015-10-12 11:30:14 -05004635 skipCall |= TransitionImageLayouts(commandBuffer, memoryBarrierCount, ppMemoryBarriers);
Michael Lentine07ff1a12015-10-15 17:07:00 -05004636 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, ppMemoryBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004637 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004638 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004639 dev_data->device_dispatch_table->CmdPipelineBarrier(commandBuffer, srcStageMask, dstStageMask, dependencyFlags, memoryBarrierCount, ppMemoryBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004640}
4641
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004642VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004643{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004644 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004645 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4646 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004647 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004648 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004649 skipCall |= addCmd(dev_data, pCB, CMD_BEGINQUERY);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004650 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004651 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBeginQuery()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004652 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004653 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004654 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004655 dev_data->device_dispatch_table->CmdBeginQuery(commandBuffer, queryPool, slot, flags);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004656}
4657
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004658VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004659{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004660 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004661 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4662 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004663 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004664 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004665 skipCall |= addCmd(dev_data, pCB, CMD_ENDQUERY);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004666 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004667 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdEndQuery()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004668 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004669 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004670 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004671 dev_data->device_dispatch_table->CmdEndQuery(commandBuffer, queryPool, slot);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004672}
4673
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004674VK_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 -06004675{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004676 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004677 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4678 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004679 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004680 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004681 skipCall |= addCmd(dev_data, pCB, CMD_RESETQUERYPOOL);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004682 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004683 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdResetQueryPool()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004684 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004685 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdQueryPool");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004686 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004687 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004688 dev_data->device_dispatch_table->CmdResetQueryPool(commandBuffer, queryPool, startQuery, queryCount);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004689}
4690
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004691VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t startQuery,
Chia-I Wu1f851912015-10-27 18:04:07 +08004692 uint32_t queryCount, VkBuffer dstBuffer, VkDeviceSize dstOffset,
Chia-I Wu1f6942d2015-10-26 18:36:20 +08004693 VkDeviceSize stride, VkQueryResultFlags flags)
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06004694{
4695 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004696 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4697 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06004698 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004699 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004700 skipCall |= addCmd(dev_data, pCB, CMD_COPYQUERYPOOLRESULTS);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06004701 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004702 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdCopyQueryPoolResults()");
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06004703 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004704 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyQueryPoolResults");
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06004705 }
4706 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004707 dev_data->device_dispatch_table->CmdCopyQueryPoolResults(commandBuffer, queryPool,
4708 startQuery, queryCount, dstBuffer, dstOffset, stride, flags);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06004709}
4710
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004711VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004712{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004713 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004714 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4715 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004716 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004717 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004718 skipCall |= addCmd(dev_data, pCB, CMD_WRITETIMESTAMP);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004719 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004720 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdWriteTimestamp()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004721 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004722 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004723 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004724 dev_data->device_dispatch_table->CmdWriteTimestamp(commandBuffer, pipelineStage, queryPool, slot);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004725}
4726
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004727VK_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 -06004728{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06004729 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08004730 VkResult result = dev_data->device_dispatch_table->CreateFramebuffer(device, pCreateInfo, pAllocator, pFramebuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06004731 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06004732 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004733 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Chia-I Wuc278df82015-07-07 11:50:03 +08004734 if (pCreateInfo->pAttachments) {
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -06004735 localFBCI->pAttachments = new VkImageView[localFBCI->attachmentCount];
4736 memcpy((void*)localFBCI->pAttachments, pCreateInfo->pAttachments, localFBCI->attachmentCount*sizeof(VkImageView));
Tobin Ehlis2464b882015-04-01 08:40:34 -06004737 }
Chia-I Wue420a332015-10-26 20:04:44 +08004738 dev_data->frameBufferMap[*pFramebuffer] = localFBCI;
Tobin Ehlis2464b882015-04-01 08:40:34 -06004739 }
4740 return result;
4741}
4742
Michael Lentine329697b2015-10-06 14:56:18 -07004743// Store the DAG.
4744struct DAGNode {
4745 uint32_t pass;
4746 std::vector<uint32_t> prev;
4747 std::vector<uint32_t> next;
4748};
4749
Courtney Goeltzenleuchterf2bca902015-11-03 15:41:43 -07004750VkBool32 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 -07004751 // If we have already checked this node we have not found a dependency path so return false.
4752 if (processed_nodes.count(index))
4753 return false;
4754 processed_nodes.insert(index);
4755 const DAGNode& node = subpass_to_node[index];
4756 // Look for a dependency path. If one exists return true else recurse on the previous nodes.
4757 if (std::find(node.prev.begin(), node.prev.end(), dependent) == node.prev.end()) {
4758 for (auto elem : node.prev) {
4759 if (FindDependency(elem, dependent, subpass_to_node, processed_nodes))
4760 return true;
4761 }
4762 } else {
4763 return true;
4764 }
4765 return false;
4766}
4767
Courtney Goeltzenleuchterf2bca902015-11-03 15:41:43 -07004768VkBool32 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) {
4769 VkBool32 result = true;
Michael Lentine329697b2015-10-06 14:56:18 -07004770 // Loop through all subpasses that share the same attachment and make sure a dependency exists
4771 for (uint32_t k = 0; k < dependent_subpasses.size(); ++k) {
4772 if (subpass == dependent_subpasses[k])
4773 continue;
4774 const DAGNode& node = subpass_to_node[subpass];
4775 // Check for a specified dependency between the two nodes. If one exists we are done.
4776 auto prev_elem = std::find(node.prev.begin(), node.prev.end(), dependent_subpasses[k]);
4777 auto next_elem = std::find(node.next.begin(), node.next.end(), dependent_subpasses[k]);
4778 if (prev_elem == node.prev.end() && next_elem == node.next.end()) {
4779 // If no dependency exits an implicit dependency still might. If so, warn and if not throw an error.
4780 std::unordered_set<uint32_t> processed_nodes;
4781 if (FindDependency(subpass, dependent_subpasses[k], subpass_to_node, processed_nodes) ||
4782 FindDependency(dependent_subpasses[k], subpass, subpass_to_node, processed_nodes)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004783 // TODO: Verify against Valid Use section of spec
4784 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 -07004785 "A dependency between subpasses %d and %d must exist but only an implicit one is specified.",
4786 subpass, dependent_subpasses[k]);
4787 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004788 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 -07004789 "A dependency between subpasses %d and %d must exist but one is not specified.",
4790 subpass, dependent_subpasses[k]);
4791 result = false;
4792 }
4793 }
4794 }
4795 return result;
4796}
4797
Courtney Goeltzenleuchterf2bca902015-11-03 15:41:43 -07004798VkBool32 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 -07004799 const DAGNode& node = subpass_to_node[index];
4800 // If this node writes to the attachment return true as next nodes need to preserve the attachment.
4801 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Chia-I Wu763a7492015-10-26 20:48:51 +08004802 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentine329697b2015-10-06 14:56:18 -07004803 if (attachment == subpass.pColorAttachments[j].attachment)
Courtney Goeltzenleuchterf2bca902015-11-03 15:41:43 -07004804 return VK_TRUE;
Michael Lentine329697b2015-10-06 14:56:18 -07004805 }
Chia-I Wuce532f72015-10-26 17:32:47 +08004806 if (subpass.pDepthStencilAttachment &&
4807 subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
4808 if (attachment == subpass.pDepthStencilAttachment->attachment)
Courtney Goeltzenleuchterf2bca902015-11-03 15:41:43 -07004809 return VK_TRUE;
Michael Lentine329697b2015-10-06 14:56:18 -07004810 }
Courtney Goeltzenleuchterf2bca902015-11-03 15:41:43 -07004811 VkBool32 result = VK_FALSE;
Michael Lentine329697b2015-10-06 14:56:18 -07004812 // Loop through previous nodes and see if any of them write to the attachment.
4813 for (auto elem : node.prev) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004814 result |= CheckPreserved(my_data, device, pCreateInfo, elem, attachment, subpass_to_node, depth + 1, skip_call);
Michael Lentine329697b2015-10-06 14:56:18 -07004815 }
4816 // If the attachment was written to by a previous node than this node needs to preserve it.
4817 if (result && depth > 0) {
4818 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Courtney Goeltzenleuchterf2bca902015-11-03 15:41:43 -07004819 VkBool32 has_preserved = false;
Chia-I Wu763a7492015-10-26 20:48:51 +08004820 for (uint32_t j = 0; j < subpass.preserveAttachmentCount; ++j) {
Michael Lentine329697b2015-10-06 14:56:18 -07004821 if (subpass.pPreserveAttachments[j].attachment == attachment) {
4822 has_preserved = true;
4823 break;
4824 }
4825 }
4826 if (!has_preserved) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004827 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 -07004828 "Attachment %d is used by a later subpass and must be preserved in subpass %d.", attachment, index);
4829 }
4830 }
4831 return result;
4832}
4833
Michael Lentine27b0f902015-10-12 11:30:14 -05004834VkBool32 ValidateDependencies(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, std::vector<DAGNode>& subpass_to_node) {
4835 VkBool32 skip_call = false;
Michael Lentine329697b2015-10-06 14:56:18 -07004836 std::vector<std::vector<uint32_t>> output_attachment_to_subpass(pCreateInfo->attachmentCount);
4837 std::vector<std::vector<uint32_t>> input_attachment_to_subpass(pCreateInfo->attachmentCount);
Michael Lentine27b0f902015-10-12 11:30:14 -05004838
Michael Lentine329697b2015-10-06 14:56:18 -07004839 // Create DAG
4840 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
4841 DAGNode& subpass_node = subpass_to_node[i];
4842 subpass_node.pass = i;
4843 }
4844 for (uint32_t i = 0; i < pCreateInfo->dependencyCount; ++i) {
4845 const VkSubpassDependency& dependency = pCreateInfo->pDependencies[i];
Chia-I Wu1f851912015-10-27 18:04:07 +08004846 if (dependency.srcSubpass > dependency.dstSubpass) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004847 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 -07004848 "Dependency graph must be specified such that an earlier pass cannot depend on a later pass.");
4849 }
Chia-I Wu1f851912015-10-27 18:04:07 +08004850 subpass_to_node[dependency.dstSubpass].prev.push_back(dependency.srcSubpass);
4851 subpass_to_node[dependency.srcSubpass].next.push_back(dependency.dstSubpass);
Michael Lentine329697b2015-10-06 14:56:18 -07004852 }
Michael Lentine27b0f902015-10-12 11:30:14 -05004853
Michael Lentine329697b2015-10-06 14:56:18 -07004854 // Find for each attachment the subpasses that use them.
4855 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
4856 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wu763a7492015-10-26 20:48:51 +08004857 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Michael Lentine329697b2015-10-06 14:56:18 -07004858 input_attachment_to_subpass[subpass.pInputAttachments[j].attachment].push_back(i);
4859 }
Chia-I Wu763a7492015-10-26 20:48:51 +08004860 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentine329697b2015-10-06 14:56:18 -07004861 output_attachment_to_subpass[subpass.pColorAttachments[j].attachment].push_back(i);
4862 }
Chia-I Wuce532f72015-10-26 17:32:47 +08004863 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
4864 output_attachment_to_subpass[subpass.pDepthStencilAttachment->attachment].push_back(i);
Michael Lentine329697b2015-10-06 14:56:18 -07004865 }
4866 }
4867 // If there is a dependency needed make sure one exists
4868 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
4869 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
4870 // If the attachment is an input then all subpasses that output must have a dependency relationship
Chia-I Wu763a7492015-10-26 20:48:51 +08004871 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Michael Lentine329697b2015-10-06 14:56:18 -07004872 const uint32_t& attachment = subpass.pInputAttachments[j].attachment;
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004873 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentine329697b2015-10-06 14:56:18 -07004874 }
4875 // 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 +08004876 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentine329697b2015-10-06 14:56:18 -07004877 const uint32_t& attachment = subpass.pColorAttachments[j].attachment;
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004878 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
4879 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentine329697b2015-10-06 14:56:18 -07004880 }
Chia-I Wuce532f72015-10-26 17:32:47 +08004881 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
4882 const uint32_t& attachment = subpass.pDepthStencilAttachment->attachment;
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004883 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
4884 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentine329697b2015-10-06 14:56:18 -07004885 }
4886 }
4887 // Loop through implicit dependencies, if this pass reads make sure the attachment is preserved for all passes after it was written.
4888 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
4889 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wu763a7492015-10-26 20:48:51 +08004890 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004891 CheckPreserved(my_data, device, pCreateInfo, i, subpass.pInputAttachments[j].attachment, subpass_to_node, 0, skip_call);
Michael Lentine329697b2015-10-06 14:56:18 -07004892 }
4893 }
4894 return skip_call;
4895}
4896
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004897VkBool32 ValidateLayouts(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo) {
4898 VkBool32 skip = false;
Mark Lobodzinski78940a42015-11-30 16:48:53 -07004899
4900#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4901 return skip;
4902#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4903
Michael Lentine27b0f902015-10-12 11:30:14 -05004904 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
4905 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
4906 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
4907 if (subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL &&
4908 subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) {
4909 if (subpass.pInputAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004910 // TODO: Verify Valid Use in spec. I believe this is allowed (valid) but may not be optimal performance
4911 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 -05004912 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
4913 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004914 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 -05004915 "Layout for input attachment is %d but can only be READ_ONLY_OPTIMAL or GENERAL.", subpass.pInputAttachments[j].attachment);
4916 }
4917 }
4918 }
4919 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
4920 if (subpass.pColorAttachments[j].layout != VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) {
4921 if (subpass.pColorAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004922 // TODO: Verify Valid Use in spec. I believe this is allowed (valid) but may not be optimal performance
4923 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 -05004924 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
4925 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004926 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 -05004927 "Layout for color attachment is %d but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.", subpass.pColorAttachments[j].attachment);
4928 }
4929 }
4930 }
Mark Lobodzinskic344bef2015-10-28 13:03:56 -06004931 if ((subpass.pDepthStencilAttachment != NULL) &&
4932 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
Michael Lentine27b0f902015-10-12 11:30:14 -05004933 if (subpass.pDepthStencilAttachment->layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) {
4934 if (subpass.pDepthStencilAttachment->layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004935 // TODO: Verify Valid Use in spec. I believe this is allowed (valid) but may not be optimal performance
4936 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 -05004937 "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL.");
4938 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004939 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 -05004940 "Layout for depth attachment is %d but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL.", subpass.pDepthStencilAttachment->attachment);
4941 }
4942 }
4943 }
4944 }
4945 return skip;
4946}
4947
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004948VkBool32 CreatePassDAG(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, std::vector<DAGNode>& subpass_to_node, std::vector<bool>& has_self_dependency) {
4949 VkBool32 skip_call = false;
Michael Lentine27b0f902015-10-12 11:30:14 -05004950 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
4951 DAGNode& subpass_node = subpass_to_node[i];
4952 subpass_node.pass = i;
4953 }
4954 for (uint32_t i = 0; i < pCreateInfo->dependencyCount; ++i) {
4955 const VkSubpassDependency& dependency = pCreateInfo->pDependencies[i];
4956 if (dependency.srcSubpass > dependency.dstSubpass) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004957 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 -05004958 "Depedency graph must be specified such that an earlier pass cannot depend on a later pass.");
Michael Lentine07ff1a12015-10-15 17:07:00 -05004959 } else if (dependency.srcSubpass == dependency.dstSubpass) {
4960 has_self_dependency[dependency.srcSubpass] = true;
Michael Lentine27b0f902015-10-12 11:30:14 -05004961 }
4962 subpass_to_node[dependency.dstSubpass].prev.push_back(dependency.srcSubpass);
4963 subpass_to_node[dependency.srcSubpass].next.push_back(dependency.dstSubpass);
4964 }
4965 return skip_call;
4966}
Tobin Ehliscb085292015-12-01 09:57:09 -07004967// TODOSC : Add intercept of vkCreateShaderModule
Michael Lentine27b0f902015-10-12 11:30:14 -05004968
Tobin Ehlis32479352015-12-01 09:48:58 -07004969VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateShaderModule(
4970 VkDevice device,
4971 const VkShaderModuleCreateInfo *pCreateInfo,
4972 const VkAllocationCallbacks* pAllocator,
4973 VkShaderModule *pShaderModule)
4974{
4975 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004976 VkBool32 skip_call = false;
Tobin Ehlis32479352015-12-01 09:48:58 -07004977 if (!shader_is_spirv(pCreateInfo)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004978 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 -07004979 /* dev */ 0, 0, SHADER_CHECKER_NON_SPIRV_SHADER, "SC",
4980 "Shader is not SPIR-V");
4981 }
4982
4983 if (skip_call)
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07004984 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis32479352015-12-01 09:48:58 -07004985
4986 VkResult res = my_data->device_dispatch_table->CreateShaderModule(device, pCreateInfo, pAllocator, pShaderModule);
4987
4988 if (res == VK_SUCCESS) {
4989 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisad61de42015-12-02 13:53:34 -07004990 my_data->shaderModuleMap[*pShaderModule] = new shader_module(pCreateInfo);
Tobin Ehlis32479352015-12-01 09:48:58 -07004991 loader_platform_thread_unlock_mutex(&globalLock);
4992 }
4993 return res;
4994}
4995
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004996VK_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 -06004997{
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004998 VkBool32 skip_call = false;
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004999 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentine27b0f902015-10-12 11:30:14 -05005000 // Create DAG
Michael Lentine07ff1a12015-10-15 17:07:00 -05005001 std::vector<bool> has_self_dependency(pCreateInfo->subpassCount);
Michael Lentine27b0f902015-10-12 11:30:14 -05005002 std::vector<DAGNode> subpass_to_node(pCreateInfo->subpassCount);
Michael Lentine07ff1a12015-10-15 17:07:00 -05005003 skip_call |= CreatePassDAG(dev_data, device, pCreateInfo, subpass_to_node, has_self_dependency);
Michael Lentine27b0f902015-10-12 11:30:14 -05005004 // Validate using DAG
5005 skip_call |= ValidateDependencies(dev_data, device, pCreateInfo, subpass_to_node);
5006 skip_call |= ValidateLayouts(dev_data, device, pCreateInfo);
5007 if (skip_call) {
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07005008 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine329697b2015-10-06 14:56:18 -07005009 }
Chia-I Wu69f40122015-10-26 21:10:41 +08005010 VkResult result = dev_data->device_dispatch_table->CreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005011 if (VK_SUCCESS == result) {
Tobin Ehliscb085292015-12-01 09:57:09 -07005012 // TODOSC : Merge in tracking of renderpass from ShaderChecker
Tobin Ehlis2464b882015-04-01 08:40:34 -06005013 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06005014 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Chia-I Wuc278df82015-07-07 11:50:03 +08005015 if (pCreateInfo->pAttachments) {
5016 localRPCI->pAttachments = new VkAttachmentDescription[localRPCI->attachmentCount];
5017 memcpy((void*)localRPCI->pAttachments, pCreateInfo->pAttachments, localRPCI->attachmentCount*sizeof(VkAttachmentDescription));
Tobin Ehlis2464b882015-04-01 08:40:34 -06005018 }
Chia-I Wuc278df82015-07-07 11:50:03 +08005019 if (pCreateInfo->pSubpasses) {
5020 localRPCI->pSubpasses = new VkSubpassDescription[localRPCI->subpassCount];
5021 memcpy((void*)localRPCI->pSubpasses, pCreateInfo->pSubpasses, localRPCI->subpassCount*sizeof(VkSubpassDescription));
5022
5023 for (uint32_t i = 0; i < localRPCI->subpassCount; i++) {
5024 VkSubpassDescription *subpass = (VkSubpassDescription *) &localRPCI->pSubpasses[i];
Chia-I Wu763a7492015-10-26 20:48:51 +08005025 const uint32_t attachmentCount = subpass->inputAttachmentCount +
5026 subpass->colorAttachmentCount * (1 + (subpass->pResolveAttachments?1:0)) +
Chia-I Wuce532f72015-10-26 17:32:47 +08005027 ((subpass->pDepthStencilAttachment) ? 1 : 0) + subpass->preserveAttachmentCount;
Chia-I Wuc278df82015-07-07 11:50:03 +08005028 VkAttachmentReference *attachments = new VkAttachmentReference[attachmentCount];
5029
Cody Northrop6de6b0b2015-08-04 11:16:41 -06005030 memcpy(attachments, subpass->pInputAttachments,
Chia-I Wu763a7492015-10-26 20:48:51 +08005031 sizeof(attachments[0]) * subpass->inputAttachmentCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06005032 subpass->pInputAttachments = attachments;
Chia-I Wu763a7492015-10-26 20:48:51 +08005033 attachments += subpass->inputAttachmentCount;
Chia-I Wuc278df82015-07-07 11:50:03 +08005034
Cody Northrop6de6b0b2015-08-04 11:16:41 -06005035 memcpy(attachments, subpass->pColorAttachments,
Chia-I Wu763a7492015-10-26 20:48:51 +08005036 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06005037 subpass->pColorAttachments = attachments;
Chia-I Wu763a7492015-10-26 20:48:51 +08005038 attachments += subpass->colorAttachmentCount;
Chia-I Wuc278df82015-07-07 11:50:03 +08005039
Cody Northrop6de6b0b2015-08-04 11:16:41 -06005040 if (subpass->pResolveAttachments) {
5041 memcpy(attachments, subpass->pResolveAttachments,
Chia-I Wu763a7492015-10-26 20:48:51 +08005042 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06005043 subpass->pResolveAttachments = attachments;
Chia-I Wu763a7492015-10-26 20:48:51 +08005044 attachments += subpass->colorAttachmentCount;
Chia-I Wuc278df82015-07-07 11:50:03 +08005045 }
5046
Chia-I Wuce532f72015-10-26 17:32:47 +08005047 if (subpass->pDepthStencilAttachment) {
5048 memcpy(attachments, subpass->pDepthStencilAttachment,
5049 sizeof(attachments[0]) * 1);
5050 subpass->pDepthStencilAttachment = attachments;
5051 attachments += 1;
5052 }
5053
Cody Northrop6de6b0b2015-08-04 11:16:41 -06005054 memcpy(attachments, subpass->pPreserveAttachments,
Chia-I Wu763a7492015-10-26 20:48:51 +08005055 sizeof(attachments[0]) * subpass->preserveAttachmentCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06005056 subpass->pPreserveAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08005057 }
Tobin Ehlis2464b882015-04-01 08:40:34 -06005058 }
Chia-I Wuc278df82015-07-07 11:50:03 +08005059 if (pCreateInfo->pDependencies) {
5060 localRPCI->pDependencies = new VkSubpassDependency[localRPCI->dependencyCount];
5061 memcpy((void*)localRPCI->pDependencies, pCreateInfo->pDependencies, localRPCI->dependencyCount*sizeof(VkSubpassDependency));
Tobin Ehlis2464b882015-04-01 08:40:34 -06005062 }
Tobin Ehlis32479352015-12-01 09:48:58 -07005063 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisad61de42015-12-02 13:53:34 -07005064 dev_data->renderPassMap[*pRenderPass] = new RENDER_PASS_NODE(localRPCI);
Michael Lentine07ff1a12015-10-15 17:07:00 -05005065 dev_data->renderPassMap[*pRenderPass]->hasSelfDependency = has_self_dependency;
Tobin Ehlis32479352015-12-01 09:48:58 -07005066 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis2464b882015-04-01 08:40:34 -06005067 }
5068 return result;
5069}
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005070// Free the renderpass shadow
5071static void deleteRenderPasses(layer_data* my_data)
5072{
5073 if (my_data->renderPassMap.size() <= 0)
5074 return;
5075 for (auto ii=my_data->renderPassMap.begin(); ii!=my_data->renderPassMap.end(); ++ii) {
Tobin Ehlisad61de42015-12-02 13:53:34 -07005076 const VkRenderPassCreateInfo* pRenderPassInfo = (*ii).second->pCreateInfo;
Michael Lentine07ff1a12015-10-15 17:07:00 -05005077 if (pRenderPassInfo->pAttachments) {
5078 delete[] pRenderPassInfo->pAttachments;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005079 }
Michael Lentine07ff1a12015-10-15 17:07:00 -05005080 if (pRenderPassInfo->pSubpasses) {
5081 for (uint32_t i=0; i<pRenderPassInfo->subpassCount; ++i) {
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005082 // Attachements are all allocated in a block, so just need to
5083 // find the first non-null one to delete
Michael Lentine07ff1a12015-10-15 17:07:00 -05005084 if (pRenderPassInfo->pSubpasses[i].pInputAttachments) {
5085 delete[] pRenderPassInfo->pSubpasses[i].pInputAttachments;
5086 } else if (pRenderPassInfo->pSubpasses[i].pColorAttachments) {
5087 delete[] pRenderPassInfo->pSubpasses[i].pColorAttachments;
5088 } else if (pRenderPassInfo->pSubpasses[i].pResolveAttachments) {
5089 delete[] pRenderPassInfo->pSubpasses[i].pResolveAttachments;
5090 } else if (pRenderPassInfo->pSubpasses[i].pPreserveAttachments) {
5091 delete[] pRenderPassInfo->pSubpasses[i].pPreserveAttachments;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005092 }
5093 }
Michael Lentine07ff1a12015-10-15 17:07:00 -05005094 delete[] pRenderPassInfo->pSubpasses;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005095 }
Michael Lentine07ff1a12015-10-15 17:07:00 -05005096 if (pRenderPassInfo->pDependencies) {
5097 delete[] pRenderPassInfo->pDependencies;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005098 }
Tobin Ehlisad61de42015-12-02 13:53:34 -07005099 delete pRenderPassInfo;
Michael Lentine07ff1a12015-10-15 17:07:00 -05005100 delete (*ii).second;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005101 }
5102 my_data->renderPassMap.clear();
5103}
Michael Lentine27b0f902015-10-12 11:30:14 -05005104
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07005105VkBool32 VerifyFramebufferAndRenderPassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
5106 VkBool32 skip_call = false;
Michael Lentine27b0f902015-10-12 11:30:14 -05005107 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5108 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Tobin Ehlisad61de42015-12-02 13:53:34 -07005109 const VkRenderPassCreateInfo* pRenderPassInfo = dev_data->renderPassMap[pRenderPassBegin->renderPass]->pCreateInfo;
Michael Lentine27b0f902015-10-12 11:30:14 -05005110 const VkFramebufferCreateInfo* pFramebufferInfo = dev_data->frameBufferMap[pRenderPassBegin->framebuffer];
5111 if (pRenderPassInfo->attachmentCount != pFramebufferInfo->attachmentCount) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005112 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 -05005113 "You cannot start a render pass using a framebuffer with a different number of attachments.");
5114 }
5115 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
5116 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
5117 const VkImage& image = dev_data->imageViewMap[image_view]->image;
5118 auto image_data = pCB->imageLayoutMap.find(image);
5119 if (image_data == pCB->imageLayoutMap.end()) {
5120 pCB->imageLayoutMap[image].initialLayout = pRenderPassInfo->pAttachments[i].initialLayout;
5121 pCB->imageLayoutMap[image].layout = pRenderPassInfo->pAttachments[i].initialLayout;
5122 } else if (pRenderPassInfo->pAttachments[i].initialLayout != image_data->second.layout) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005123 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 -05005124 "You cannot start a render pass using attachment %i where the intial layout differs from the starting layout.", i);
5125 }
5126 }
5127 return skip_call;
5128}
5129
5130void TransitionSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, const int subpass_index) {
5131 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5132 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5133 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
5134 if (render_pass_data == dev_data->renderPassMap.end()) {
5135 return;
5136 }
Tobin Ehlisad61de42015-12-02 13:53:34 -07005137 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
Michael Lentine27b0f902015-10-12 11:30:14 -05005138 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
5139 if (framebuffer_data == dev_data->frameBufferMap.end()) {
5140 return;
5141 }
5142 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
5143 const VkSubpassDescription& subpass = pRenderPassInfo->pSubpasses[subpass_index];
5144 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
5145 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pInputAttachments[j].attachment];
5146 auto image_view_data = dev_data->imageViewMap.find(image_view);
5147 if (image_view_data != dev_data->imageViewMap.end()) {
5148 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5149 if (image_layout != pCB->imageLayoutMap.end()) {
5150 image_layout->second.layout = subpass.pInputAttachments[j].layout;
5151 }
5152 }
5153 }
5154 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
5155 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pColorAttachments[j].attachment];
5156 auto image_view_data = dev_data->imageViewMap.find(image_view);
5157 if (image_view_data != dev_data->imageViewMap.end()) {
5158 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5159 if (image_layout != pCB->imageLayoutMap.end()) {
5160 image_layout->second.layout = subpass.pColorAttachments[j].layout;
5161 }
5162 }
5163 }
Michael Lentine2b9eda42015-10-28 15:55:18 -07005164 if ((subpass.pDepthStencilAttachment != NULL) &&
Mark Lobodzinskic344bef2015-10-28 13:03:56 -06005165 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
Michael Lentine27b0f902015-10-12 11:30:14 -05005166 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pDepthStencilAttachment->attachment];
5167 auto image_view_data = dev_data->imageViewMap.find(image_view);
5168 if (image_view_data != dev_data->imageViewMap.end()) {
5169 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5170 if (image_layout != pCB->imageLayoutMap.end()) {
5171 image_layout->second.layout = subpass.pDepthStencilAttachment->layout;
5172 }
5173 }
5174 }
5175}
5176
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07005177VkBool32 validatePrimaryCommandBuffer(const layer_data* my_data, const GLOBAL_CB_NODE* pCB, const std::string& cmd_name) {
5178 VkBool32 skip_call = false;
Michael Lentine2b9eda42015-10-28 15:55:18 -07005179 if (pCB->createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005180 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 -07005181 "Cannot execute command %s on a secondary command buffer.", cmd_name.c_str());
5182 }
5183 return skip_call;
5184}
5185
Michael Lentine27b0f902015-10-12 11:30:14 -05005186void TransitionFinalSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
5187 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5188 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5189 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
5190 if (render_pass_data == dev_data->renderPassMap.end()) {
5191 return;
5192 }
Tobin Ehlisad61de42015-12-02 13:53:34 -07005193 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
Michael Lentine27b0f902015-10-12 11:30:14 -05005194 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
5195 if (framebuffer_data == dev_data->frameBufferMap.end()) {
5196 return;
5197 }
5198 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
5199 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
5200 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
5201 auto image_view_data = dev_data->imageViewMap.find(image_view);
5202 if (image_view_data != dev_data->imageViewMap.end()) {
5203 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5204 if (image_layout != pCB->imageLayoutMap.end()) {
5205 image_layout->second.layout = pRenderPassInfo->pAttachments[i].finalLayout;
5206 }
5207 }
5208 }
5209}
5210
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005211VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, VkSubpassContents contents)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005212{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005213 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08005214 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5215 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005216 if (pCB) {
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06005217 if (pRenderPassBegin && pRenderPassBegin->renderPass) {
Mark Lobodzinskic344bef2015-10-28 13:03:56 -06005218 skipCall |= VerifyFramebufferAndRenderPassLayouts(commandBuffer, pRenderPassBegin);
Tobin Ehlis42d440c2015-10-20 17:06:16 -06005219 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBeginRenderPass");
Michael Lentine2b9eda42015-10-28 15:55:18 -07005220 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdBeginRenderPass");
Tobin Ehlis42d440c2015-10-20 17:06:16 -06005221 skipCall |= addCmd(dev_data, pCB, CMD_BEGINRENDERPASS);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06005222 pCB->activeRenderPass = pRenderPassBegin->renderPass;
Michael Lentine27b0f902015-10-12 11:30:14 -05005223 // This is a shallow copy as that is all that is needed for now
5224 pCB->activeRenderPassBeginInfo = *pRenderPassBegin;
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06005225 pCB->activeSubpass = 0;
5226 pCB->framebuffer = pRenderPassBegin->framebuffer;
5227 if (pCB->lastBoundPipeline) {
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005228 skipCall |= validatePipelineState(dev_data, pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06005229 }
Tobin Ehlise4076782015-06-24 15:53:07 -06005230 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005231 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 -06005232 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tony Barbourb9f82ba2015-04-06 11:09:26 -06005233 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005234 }
Mark Lobodzinskic344bef2015-10-28 13:03:56 -06005235 if (VK_FALSE == skipCall) {
Chia-I Wu1f851912015-10-27 18:04:07 +08005236 dev_data->device_dispatch_table->CmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents);
Mark Lobodzinskic344bef2015-10-28 13:03:56 -06005237 // This is a shallow copy as that is all that is needed for now
5238 dev_data->renderPassBeginInfo = *pRenderPassBegin;
5239 dev_data->currentSubpass = 0;
5240 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005241}
5242
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005243VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents)
Chia-I Wuc278df82015-07-07 11:50:03 +08005244{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005245 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08005246 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5247 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Michael Lentine27b0f902015-10-12 11:30:14 -05005248 TransitionSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo, ++dev_data->currentSubpass);
Chia-I Wuc278df82015-07-07 11:50:03 +08005249 if (pCB) {
Michael Lentine2b9eda42015-10-28 15:55:18 -07005250 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdNextSubpass");
Tobin Ehlis42d440c2015-10-20 17:06:16 -06005251 skipCall |= addCmd(dev_data, pCB, CMD_NEXTSUBPASS);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06005252 pCB->activeSubpass++;
Tony Barbourcbc0fa82015-12-15 10:24:45 -07005253 TransitionSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo, pCB->activeSubpass);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06005254 if (pCB->lastBoundPipeline) {
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005255 skipCall |= validatePipelineState(dev_data, pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Chia-I Wuc278df82015-07-07 11:50:03 +08005256 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06005257 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdNextSubpass");
Chia-I Wuc278df82015-07-07 11:50:03 +08005258 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005259 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08005260 dev_data->device_dispatch_table->CmdNextSubpass(commandBuffer, contents);
Chia-I Wuc278df82015-07-07 11:50:03 +08005261}
5262
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005263VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndRenderPass(VkCommandBuffer commandBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005264{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005265 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08005266 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5267 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Michael Lentine27b0f902015-10-12 11:30:14 -05005268 TransitionFinalSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005269 if (pCB) {
Michael Lentine2b9eda42015-10-28 15:55:18 -07005270 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdEndRenderpass");
Michael Lentine2b9eda42015-10-28 15:55:18 -07005271 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdEndRenderPass");
Tobin Ehlis42d440c2015-10-20 17:06:16 -06005272 skipCall |= addCmd(dev_data, pCB, CMD_ENDRENDERPASS);
Michael Lentine27b0f902015-10-12 11:30:14 -05005273 TransitionFinalSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06005274 pCB->activeRenderPass = 0;
5275 pCB->activeSubpass = 0;
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08005276 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005277 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08005278 dev_data->device_dispatch_table->CmdEndRenderPass(commandBuffer);
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08005279}
5280
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005281VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount, const VkCommandBuffer* pCommandBuffers)
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08005282{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005283 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08005284 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5285 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08005286 if (pCB) {
Tobin Ehlis5f728d32015-09-17 14:18:16 -06005287 GLOBAL_CB_NODE* pSubCB = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08005288 for (uint32_t i=0; i<commandBuffersCount; i++) {
5289 pSubCB = getCBNode(dev_data, pCommandBuffers[i]);
Tobin Ehlis5f728d32015-09-17 14:18:16 -06005290 if (!pSubCB) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005291 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 +08005292 "vkCmdExecuteCommands() called w/ invalid Cmd Buffer %p in element %u of pCommandBuffers array.", (void*)pCommandBuffers[i], i);
5293 } else if (VK_COMMAND_BUFFER_LEVEL_PRIMARY == pSubCB->createInfo.level) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005294 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 +08005295 "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 -06005296 }
5297 }
Michael Lentine2b9eda42015-10-28 15:55:18 -07005298 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdExecuteComands");
Tobin Ehlis42d440c2015-10-20 17:06:16 -06005299 skipCall |= addCmd(dev_data, pCB, CMD_EXECUTECOMMANDS);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005300 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005301 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08005302 dev_data->device_dispatch_table->CmdExecuteCommands(commandBuffer, commandBuffersCount, pCommandBuffers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005303}
5304
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07005305VkBool32 ValidateMapImageLayouts(VkDevice device, VkDeviceMemory mem) {
5306 VkBool32 skip_call = false;
Michael Lentineee4ad4d2015-10-23 12:41:44 -07005307 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5308 auto mem_data = dev_data->memImageMap.find(mem);
5309 if (mem_data != dev_data->memImageMap.end()) {
5310 auto image_data = dev_data->imageLayoutMap.find(mem_data->second);
5311 if (image_data != dev_data->imageLayoutMap.end()) {
5312 if (image_data->second->layout != VK_IMAGE_LAYOUT_PREINITIALIZED && image_data->second->layout != VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005313 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 -07005314 "Cannot map an image with layout %d. Only GENERAL or PREINITIALIZED are supported.", image_data->second->layout);
5315 }
5316 }
5317 }
5318 return skip_call;
5319}
5320
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005321VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkMapMemory(
Michael Lentineee4ad4d2015-10-23 12:41:44 -07005322 VkDevice device,
5323 VkDeviceMemory mem,
5324 VkDeviceSize offset,
5325 VkDeviceSize size,
5326 VkFlags flags,
5327 void **ppData)
5328{
5329 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski78940a42015-11-30 16:48:53 -07005330
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07005331 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski78940a42015-11-30 16:48:53 -07005332#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
5333 skip_call = ValidateMapImageLayouts(device, mem);
5334#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5335
Michael Lentineee4ad4d2015-10-23 12:41:44 -07005336 if (VK_FALSE == skip_call) {
5337 return dev_data->device_dispatch_table->MapMemory(device, mem, offset, size, flags, ppData);
5338 }
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07005339 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentineee4ad4d2015-10-23 12:41:44 -07005340}
5341
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005342VKAPI_ATTR VkResult VKAPI_CALL vkBindImageMemory(
Michael Lentineee4ad4d2015-10-23 12:41:44 -07005343 VkDevice device,
5344 VkImage image,
5345 VkDeviceMemory mem,
5346 VkDeviceSize memOffset)
5347{
5348 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5349 VkResult result = dev_data->device_dispatch_table->BindImageMemory(device, image, mem, memOffset);
5350 loader_platform_thread_lock_mutex(&globalLock);
5351 dev_data->memImageMap[mem] = image;
5352 loader_platform_thread_unlock_mutex(&globalLock);
5353 return result;
5354}
5355
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005356VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(
Michael Lentine27b0f902015-10-12 11:30:14 -05005357 VkDevice device,
5358 const VkSwapchainCreateInfoKHR *pCreateInfo,
Ian Elliottc623ba52015-11-20 14:13:17 -07005359 const VkAllocationCallbacks *pAllocator,
Michael Lentine27b0f902015-10-12 11:30:14 -05005360 VkSwapchainKHR *pSwapchain)
5361{
5362 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliottc623ba52015-11-20 14:13:17 -07005363 VkResult result = dev_data->device_dispatch_table->CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
Michael Lentine27b0f902015-10-12 11:30:14 -05005364
5365 if (VK_SUCCESS == result) {
5366 SWAPCHAIN_NODE *swapchain_data = new SWAPCHAIN_NODE;
5367 loader_platform_thread_lock_mutex(&globalLock);
5368 dev_data->device_extensions.swapchainMap[*pSwapchain] = swapchain_data;
5369 loader_platform_thread_unlock_mutex(&globalLock);
5370 }
5371
5372 return result;
5373}
5374
Ian Elliottc623ba52015-11-20 14:13:17 -07005375VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR(
Michael Lentine27b0f902015-10-12 11:30:14 -05005376 VkDevice device,
Ian Elliottc623ba52015-11-20 14:13:17 -07005377 VkSwapchainKHR swapchain,
5378 const VkAllocationCallbacks *pAllocator)
Michael Lentine27b0f902015-10-12 11:30:14 -05005379{
5380 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentine27b0f902015-10-12 11:30:14 -05005381
5382 loader_platform_thread_lock_mutex(&globalLock);
5383 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(swapchain);
5384 if (swapchain_data != dev_data->device_extensions.swapchainMap.end()) {
5385 if (swapchain_data->second->images.size() > 0) {
5386 for (auto swapchain_image : swapchain_data->second->images) {
5387 auto image_item = dev_data->imageLayoutMap.find(swapchain_image);
5388 if (image_item != dev_data->imageLayoutMap.end())
5389 dev_data->imageLayoutMap.erase(image_item);
5390 }
5391 }
5392 delete swapchain_data->second;
5393 dev_data->device_extensions.swapchainMap.erase(swapchain);
5394 }
5395 loader_platform_thread_unlock_mutex(&globalLock);
Ian Elliottc623ba52015-11-20 14:13:17 -07005396 return dev_data->device_dispatch_table->DestroySwapchainKHR(device, swapchain, pAllocator);
Michael Lentine27b0f902015-10-12 11:30:14 -05005397}
5398
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005399VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR(
Michael Lentine27b0f902015-10-12 11:30:14 -05005400 VkDevice device,
5401 VkSwapchainKHR swapchain,
5402 uint32_t* pCount,
5403 VkImage* pSwapchainImages)
5404{
5405 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5406 VkResult result = dev_data->device_dispatch_table->GetSwapchainImagesKHR(device, swapchain, pCount, pSwapchainImages);
5407
5408 if (result == VK_SUCCESS && pSwapchainImages != NULL) {
5409 // This should never happen and is checked by param checker.
5410 if (!pCount) return result;
5411 for (uint32_t i = 0; i < *pCount; ++i) {
5412 IMAGE_NODE* image_node = new IMAGE_NODE;
5413 image_node->layout = VK_IMAGE_LAYOUT_UNDEFINED;
5414 loader_platform_thread_lock_mutex(&globalLock);
5415 dev_data->device_extensions.swapchainMap[swapchain]->images.push_back(pSwapchainImages[i]);
5416 dev_data->imageLayoutMap[pSwapchainImages[i]] = image_node;
5417 loader_platform_thread_unlock_mutex(&globalLock);
5418 }
5419 }
5420 return result;
5421}
5422
Ian Elliottc623ba52015-11-20 14:13:17 -07005423VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo)
Michael Lentine27b0f902015-10-12 11:30:14 -05005424{
5425 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07005426 VkBool32 skip_call = false;
Michael Lentine27b0f902015-10-12 11:30:14 -05005427
Mark Lobodzinski78940a42015-11-30 16:48:53 -07005428#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentine27b0f902015-10-12 11:30:14 -05005429 if (pPresentInfo) {
5430 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
Ian Elliottc623ba52015-11-20 14:13:17 -07005431 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(pPresentInfo->pSwapchains[i]);
5432 if (swapchain_data != dev_data->device_extensions.swapchainMap.end() && pPresentInfo->pImageIndices[i] < swapchain_data->second->images.size()) {
5433 VkImage image = swapchain_data->second->images[pPresentInfo->pImageIndices[i]];
Michael Lentine27b0f902015-10-12 11:30:14 -05005434 auto image_data = dev_data->imageLayoutMap.find(image);
5435 if (image_data != dev_data->imageLayoutMap.end()) {
Ian Elliottc623ba52015-11-20 14:13:17 -07005436 if (image_data->second->layout != VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005437 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 -05005438 "Images passed to present must be in layout PRESENT_SOURCE_KHR but is in %d", image_data->second->layout);
5439 }
5440 }
5441 }
5442 }
5443 }
Mark Lobodzinski78940a42015-11-30 16:48:53 -07005444#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentine27b0f902015-10-12 11:30:14 -05005445
5446 if (VK_FALSE == skip_call)
5447 return dev_data->device_dispatch_table->QueuePresentKHR(queue, pPresentInfo);
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07005448 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine27b0f902015-10-12 11:30:14 -05005449}
5450
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005451VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(
5452 VkInstance instance,
5453 const VkDebugReportCallbackCreateInfoEXT* pCreateInfo,
5454 const VkAllocationCallbacks* pAllocator,
5455 VkDebugReportCallbackEXT* pMsgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005456{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005457 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07005458 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005459 VkResult res = pTable->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisc91330b2015-06-16 09:04:30 -06005460 if (VK_SUCCESS == res) {
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07005461 res = layer_create_msg_callback(my_data->report_data, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisc91330b2015-06-16 09:04:30 -06005462 }
5463 return res;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005464}
5465
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005466VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07005467 VkInstance instance,
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005468 VkDebugReportCallbackEXT msgCallback,
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07005469 const VkAllocationCallbacks* pAllocator)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005470{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005471 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07005472 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005473 pTable->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07005474 layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005475}
5476
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005477VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDebugReportMessageEXT(
Courtney Goeltzenleuchter5a424ce2015-12-01 14:10:55 -07005478 VkInstance instance,
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005479 VkDebugReportFlagsEXT flags,
5480 VkDebugReportObjectTypeEXT objType,
Courtney Goeltzenleuchter5a424ce2015-12-01 14:10:55 -07005481 uint64_t object,
5482 size_t location,
5483 int32_t msgCode,
5484 const char* pLayerPrefix,
5485 const char* pMsg)
5486{
5487 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005488 my_data->instance_dispatch_table->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg);
Courtney Goeltzenleuchter5a424ce2015-12-01 14:10:55 -07005489}
5490
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005491VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerBegin(VkCommandBuffer commandBuffer, const char* pMarker)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005492{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005493 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08005494 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5495 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005496 if (!dev_data->device_extensions.debug_marker_enabled) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005497 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 -06005498 "Attempt to use CmdDbgMarkerBegin but extension disabled!");
Jon Ashburn6f8cd632015-06-01 09:37:38 -06005499 return;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06005500 } else if (pCB) {
Tobin Ehlis32479352015-12-01 09:48:58 -07005501
Tobin Ehlis42d440c2015-10-20 17:06:16 -06005502 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKERBEGIN);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005503 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005504 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08005505 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerBegin(commandBuffer, pMarker);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005506}
5507
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005508VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerEnd(VkCommandBuffer commandBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005509{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005510 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08005511 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5512 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005513 if (!dev_data->device_extensions.debug_marker_enabled) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005514 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 -06005515 "Attempt to use CmdDbgMarkerEnd but extension disabled!");
Jon Ashburn6f8cd632015-06-01 09:37:38 -06005516 return;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06005517 } else if (pCB) {
Tobin Ehlis32479352015-12-01 09:48:58 -07005518
Tobin Ehlis42d440c2015-10-20 17:06:16 -06005519 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKEREND);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005520 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005521 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08005522 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerEnd(commandBuffer);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06005523}
5524
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005525VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005526{
Jon Ashburn1245cec2015-05-18 13:20:15 -06005527 if (dev == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005528 return NULL;
Jon Ashburne0fa2282015-05-20 09:00:28 -06005529
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005530 layer_data *dev_data;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005531 /* loader uses this to force layer initialization; device object is wrapped */
5532 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005533 VkBaseLayerObject* wrapped_dev = (VkBaseLayerObject*) dev;
5534 dev_data = get_my_data_ptr(get_dispatch_key(wrapped_dev->baseObject), layer_data_map);
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005535 dev_data->device_dispatch_table = new VkLayerDispatchTable;
5536 layer_initialize_dispatch_table(dev_data->device_dispatch_table, wrapped_dev);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005537 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005538 }
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005539 dev_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map);
Courtney Goeltzenleuchterbe637992015-06-25 18:01:43 -06005540 if (!strcmp(funcName, "vkCreateDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005541 return (PFN_vkVoidFunction) vkCreateDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005542 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005543 return (PFN_vkVoidFunction) vkDestroyDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005544 if (!strcmp(funcName, "vkQueueSubmit"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005545 return (PFN_vkVoidFunction) vkQueueSubmit;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005546 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005547 return (PFN_vkVoidFunction) vkDestroyInstance;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005548 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005549 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005550 if (!strcmp(funcName, "vkDestroyFence"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005551 return (PFN_vkVoidFunction) vkDestroyFence;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005552 if (!strcmp(funcName, "vkDestroySemaphore"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005553 return (PFN_vkVoidFunction) vkDestroySemaphore;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005554 if (!strcmp(funcName, "vkDestroyEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005555 return (PFN_vkVoidFunction) vkDestroyEvent;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005556 if (!strcmp(funcName, "vkDestroyQueryPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005557 return (PFN_vkVoidFunction) vkDestroyQueryPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005558 if (!strcmp(funcName, "vkDestroyBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005559 return (PFN_vkVoidFunction) vkDestroyBuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005560 if (!strcmp(funcName, "vkDestroyBufferView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005561 return (PFN_vkVoidFunction) vkDestroyBufferView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005562 if (!strcmp(funcName, "vkDestroyImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005563 return (PFN_vkVoidFunction) vkDestroyImage;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005564 if (!strcmp(funcName, "vkDestroyImageView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005565 return (PFN_vkVoidFunction) vkDestroyImageView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005566 if (!strcmp(funcName, "vkDestroyShaderModule"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005567 return (PFN_vkVoidFunction) vkDestroyShaderModule;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005568 if (!strcmp(funcName, "vkDestroyPipeline"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005569 return (PFN_vkVoidFunction) vkDestroyPipeline;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005570 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005571 return (PFN_vkVoidFunction) vkDestroyPipelineLayout;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005572 if (!strcmp(funcName, "vkDestroySampler"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005573 return (PFN_vkVoidFunction) vkDestroySampler;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005574 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005575 return (PFN_vkVoidFunction) vkDestroyDescriptorSetLayout;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005576 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005577 return (PFN_vkVoidFunction) vkDestroyDescriptorPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005578 if (!strcmp(funcName, "vkDestroyFramebuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005579 return (PFN_vkVoidFunction) vkDestroyFramebuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005580 if (!strcmp(funcName, "vkDestroyRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005581 return (PFN_vkVoidFunction) vkDestroyRenderPass;
Tobin Ehlisb46be812015-10-23 16:00:08 -06005582 if (!strcmp(funcName, "vkCreateBuffer"))
5583 return (PFN_vkVoidFunction) vkCreateBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005584 if (!strcmp(funcName, "vkCreateBufferView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005585 return (PFN_vkVoidFunction) vkCreateBufferView;
Tobin Ehlisb46be812015-10-23 16:00:08 -06005586 if (!strcmp(funcName, "vkCreateImage"))
5587 return (PFN_vkVoidFunction) vkCreateImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005588 if (!strcmp(funcName, "vkCreateImageView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005589 return (PFN_vkVoidFunction) vkCreateImageView;
Jon Ashburn0d60d272015-07-09 15:02:25 -06005590 if (!strcmp(funcName, "CreatePipelineCache"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005591 return (PFN_vkVoidFunction) vkCreatePipelineCache;
Jon Ashburn0d60d272015-07-09 15:02:25 -06005592 if (!strcmp(funcName, "DestroyPipelineCache"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005593 return (PFN_vkVoidFunction) vkDestroyPipelineCache;
Jon Ashburn0d60d272015-07-09 15:02:25 -06005594 if (!strcmp(funcName, "GetPipelineCacheData"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005595 return (PFN_vkVoidFunction) vkGetPipelineCacheData;
Jon Ashburn0d60d272015-07-09 15:02:25 -06005596 if (!strcmp(funcName, "MergePipelineCaches"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005597 return (PFN_vkVoidFunction) vkMergePipelineCaches;
Jon Ashburn0d60d272015-07-09 15:02:25 -06005598 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005599 return (PFN_vkVoidFunction) vkCreateGraphicsPipelines;
Mark Lobodzinski2adea752015-11-10 15:25:01 -07005600 if (!strcmp(funcName, "vkCreateComputePipelines"))
5601 return (PFN_vkVoidFunction) vkCreateComputePipelines;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005602 if (!strcmp(funcName, "vkCreateSampler"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005603 return (PFN_vkVoidFunction) vkCreateSampler;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005604 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005605 return (PFN_vkVoidFunction) vkCreateDescriptorSetLayout;
Mark Lobodzinski556f7212015-04-17 14:11:39 -05005606 if (!strcmp(funcName, "vkCreatePipelineLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005607 return (PFN_vkVoidFunction) vkCreatePipelineLayout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005608 if (!strcmp(funcName, "vkCreateDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005609 return (PFN_vkVoidFunction) vkCreateDescriptorPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005610 if (!strcmp(funcName, "vkResetDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005611 return (PFN_vkVoidFunction) vkResetDescriptorPool;
Chia-I Wu1f851912015-10-27 18:04:07 +08005612 if (!strcmp(funcName, "vkAllocateDescriptorSets"))
5613 return (PFN_vkVoidFunction) vkAllocateDescriptorSets;
Tobin Ehlis3c543112015-10-08 13:13:50 -06005614 if (!strcmp(funcName, "vkFreeDescriptorSets"))
5615 return (PFN_vkVoidFunction) vkFreeDescriptorSets;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08005616 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005617 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07005618 if (!strcmp(funcName, "vkCreateCommandPool"))
5619 return (PFN_vkVoidFunction) vkCreateCommandPool;
5620 if (!strcmp(funcName, "vkDestroyCommandPool"))
5621 return (PFN_vkVoidFunction) vkDestroyCommandPool;
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07005622 if (!strcmp(funcName, "vkResetCommandPool"))
5623 return (PFN_vkVoidFunction) vkResetCommandPool;
Chia-I Wu1f851912015-10-27 18:04:07 +08005624 if (!strcmp(funcName, "vkAllocateCommandBuffers"))
5625 return (PFN_vkVoidFunction) vkAllocateCommandBuffers;
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07005626 if (!strcmp(funcName, "vkFreeCommandBuffers"))
5627 return (PFN_vkVoidFunction) vkFreeCommandBuffers;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005628 if (!strcmp(funcName, "vkBeginCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005629 return (PFN_vkVoidFunction) vkBeginCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005630 if (!strcmp(funcName, "vkEndCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005631 return (PFN_vkVoidFunction) vkEndCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005632 if (!strcmp(funcName, "vkResetCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005633 return (PFN_vkVoidFunction) vkResetCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005634 if (!strcmp(funcName, "vkCmdBindPipeline"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005635 return (PFN_vkVoidFunction) vkCmdBindPipeline;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06005636 if (!strcmp(funcName, "vkCmdSetViewport"))
5637 return (PFN_vkVoidFunction) vkCmdSetViewport;
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06005638 if (!strcmp(funcName, "vkCmdSetScissor"))
5639 return (PFN_vkVoidFunction) vkCmdSetScissor;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06005640 if (!strcmp(funcName, "vkCmdSetLineWidth"))
5641 return (PFN_vkVoidFunction) vkCmdSetLineWidth;
5642 if (!strcmp(funcName, "vkCmdSetDepthBias"))
5643 return (PFN_vkVoidFunction) vkCmdSetDepthBias;
5644 if (!strcmp(funcName, "vkCmdSetBlendConstants"))
5645 return (PFN_vkVoidFunction) vkCmdSetBlendConstants;
5646 if (!strcmp(funcName, "vkCmdSetDepthBounds"))
5647 return (PFN_vkVoidFunction) vkCmdSetDepthBounds;
5648 if (!strcmp(funcName, "vkCmdSetStencilCompareMask"))
5649 return (PFN_vkVoidFunction) vkCmdSetStencilCompareMask;
5650 if (!strcmp(funcName, "vkCmdSetStencilWriteMask"))
5651 return (PFN_vkVoidFunction) vkCmdSetStencilWriteMask;
5652 if (!strcmp(funcName, "vkCmdSetStencilReference"))
5653 return (PFN_vkVoidFunction) vkCmdSetStencilReference;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005654 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005655 return (PFN_vkVoidFunction) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06005656 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005657 return (PFN_vkVoidFunction) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005658 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005659 return (PFN_vkVoidFunction) vkCmdBindIndexBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005660 if (!strcmp(funcName, "vkCmdDraw"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005661 return (PFN_vkVoidFunction) vkCmdDraw;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005662 if (!strcmp(funcName, "vkCmdDrawIndexed"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005663 return (PFN_vkVoidFunction) vkCmdDrawIndexed;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005664 if (!strcmp(funcName, "vkCmdDrawIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005665 return (PFN_vkVoidFunction) vkCmdDrawIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005666 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005667 return (PFN_vkVoidFunction) vkCmdDrawIndexedIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005668 if (!strcmp(funcName, "vkCmdDispatch"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005669 return (PFN_vkVoidFunction) vkCmdDispatch;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005670 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005671 return (PFN_vkVoidFunction) vkCmdDispatchIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005672 if (!strcmp(funcName, "vkCmdCopyBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005673 return (PFN_vkVoidFunction) vkCmdCopyBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005674 if (!strcmp(funcName, "vkCmdCopyImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005675 return (PFN_vkVoidFunction) vkCmdCopyImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005676 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005677 return (PFN_vkVoidFunction) vkCmdCopyBufferToImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005678 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005679 return (PFN_vkVoidFunction) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005680 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005681 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005682 if (!strcmp(funcName, "vkCmdFillBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005683 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005684 if (!strcmp(funcName, "vkCmdClearColorImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005685 return (PFN_vkVoidFunction) vkCmdClearColorImage;
Chris Forbes2951d7d2015-06-22 17:21:59 +12005686 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005687 return (PFN_vkVoidFunction) vkCmdClearDepthStencilImage;
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06005688 if (!strcmp(funcName, "vkCmdClearAttachments"))
5689 return (PFN_vkVoidFunction) vkCmdClearAttachments;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005690 if (!strcmp(funcName, "vkCmdResolveImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005691 return (PFN_vkVoidFunction) vkCmdResolveImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005692 if (!strcmp(funcName, "vkCmdSetEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005693 return (PFN_vkVoidFunction) vkCmdSetEvent;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005694 if (!strcmp(funcName, "vkCmdResetEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005695 return (PFN_vkVoidFunction) vkCmdResetEvent;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005696 if (!strcmp(funcName, "vkCmdWaitEvents"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005697 return (PFN_vkVoidFunction) vkCmdWaitEvents;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005698 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005699 return (PFN_vkVoidFunction) vkCmdPipelineBarrier;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005700 if (!strcmp(funcName, "vkCmdBeginQuery"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005701 return (PFN_vkVoidFunction) vkCmdBeginQuery;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005702 if (!strcmp(funcName, "vkCmdEndQuery"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005703 return (PFN_vkVoidFunction) vkCmdEndQuery;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005704 if (!strcmp(funcName, "vkCmdResetQueryPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005705 return (PFN_vkVoidFunction) vkCmdResetQueryPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005706 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005707 return (PFN_vkVoidFunction) vkCmdWriteTimestamp;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005708 if (!strcmp(funcName, "vkCreateFramebuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005709 return (PFN_vkVoidFunction) vkCreateFramebuffer;
Tobin Ehlis32479352015-12-01 09:48:58 -07005710 if (!strcmp(funcName, "vkCreateShaderModule"))
5711 return (PFN_vkVoidFunction) vkCreateShaderModule;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005712 if (!strcmp(funcName, "vkCreateRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005713 return (PFN_vkVoidFunction) vkCreateRenderPass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005714 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005715 return (PFN_vkVoidFunction) vkCmdBeginRenderPass;
Chia-I Wuc278df82015-07-07 11:50:03 +08005716 if (!strcmp(funcName, "vkCmdNextSubpass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005717 return (PFN_vkVoidFunction) vkCmdNextSubpass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005718 if (!strcmp(funcName, "vkCmdEndRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005719 return (PFN_vkVoidFunction) vkCmdEndRenderPass;
Tobin Ehlis5f728d32015-09-17 14:18:16 -06005720 if (!strcmp(funcName, "vkCmdExecuteCommands"))
5721 return (PFN_vkVoidFunction) vkCmdExecuteCommands;
Michael Lentineee4ad4d2015-10-23 12:41:44 -07005722 if (!strcmp(funcName, "vkMapMemory"))
5723 return (PFN_vkVoidFunction) vkMapMemory;
Jon Ashburn6f8cd632015-06-01 09:37:38 -06005724
Michael Lentine27b0f902015-10-12 11:30:14 -05005725 if (dev_data->device_extensions.wsi_enabled)
5726 {
5727 if (!strcmp(funcName, "vkCreateSwapchainKHR"))
5728 return (PFN_vkVoidFunction) vkCreateSwapchainKHR;
5729 if (!strcmp(funcName, "vkDestroySwapchainKHR"))
5730 return (PFN_vkVoidFunction) vkDestroySwapchainKHR;
5731 if (!strcmp(funcName, "vkGetSwapchainImagesKHR"))
5732 return (PFN_vkVoidFunction) vkGetSwapchainImagesKHR;
5733 if (!strcmp(funcName, "vkQueuePresentKHR"))
5734 return (PFN_vkVoidFunction) vkQueuePresentKHR;
5735 }
5736
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005737 VkLayerDispatchTable* pTable = dev_data->device_dispatch_table;
5738 if (dev_data->device_extensions.debug_marker_enabled)
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005739 {
Jon Ashburn7e07faf2015-06-18 15:02:58 -06005740 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005741 return (PFN_vkVoidFunction) vkCmdDbgMarkerBegin;
Jon Ashburn7e07faf2015-06-18 15:02:58 -06005742 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005743 return (PFN_vkVoidFunction) vkCmdDbgMarkerEnd;
Jon Ashburn6f8cd632015-06-01 09:37:38 -06005744 }
5745 {
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005746 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005747 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005748 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburn79b78ac2015-05-05 14:22:52 -06005749 }
5750}
5751
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005752VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06005753{
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005754 PFN_vkVoidFunction fptr;
Jon Ashburn79b78ac2015-05-05 14:22:52 -06005755 if (instance == NULL)
5756 return NULL;
5757
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005758 layer_data* my_data;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005759 /* loader uses this to force layer initialization; instance object is wrapped */
5760 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005761 VkBaseLayerObject* wrapped_inst = (VkBaseLayerObject*) instance;
5762 my_data = get_my_data_ptr(get_dispatch_key(wrapped_inst->baseObject), layer_data_map);
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005763 my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
5764 layer_init_instance_dispatch_table(my_data->instance_dispatch_table, wrapped_inst);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005765 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005766 }
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06005767 if (!strcmp(funcName, "vkCreateInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005768 return (PFN_vkVoidFunction) vkCreateInstance;
Jon Ashburne0fa2282015-05-20 09:00:28 -06005769 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005770 return (PFN_vkVoidFunction) vkDestroyInstance;
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -06005771 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
5772 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
5773 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
5774 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
5775 if (!strcmp(funcName, "vkEnumerateDeviceLayerProperties"))
5776 return (PFN_vkVoidFunction) vkEnumerateDeviceLayerProperties;
5777 if (!strcmp(funcName, "vkEnumerateDeviceExtensionProperties"))
5778 return (PFN_vkVoidFunction) vkEnumerateDeviceExtensionProperties;
Courtney Goeltzenleuchtercc899fe2015-06-01 14:33:14 -06005779
Tobin Ehlis32479352015-12-01 09:48:58 -07005780 my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06005781 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchtercc899fe2015-06-01 14:33:14 -06005782 if (fptr)
5783 return fptr;
5784
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005785 {
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005786 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005787 if (pTable->GetInstanceProcAddr == NULL)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06005788 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005789 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005790 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005791}