blob: 3e47c3745942bd2f473cd14b1c7ccd0121a2c45a [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
Mark Lobodzinski611cf592015-12-18 15:35:38 -07001251 if (pPipe) {
1252 if (pCB->lastBoundPipelineLayout) {
1253 string errorString;
1254 for (auto setIndex : pPipe->active_sets) {
1255 // If valid set is not bound throw an error
1256 if ((pCB->boundDescriptorSets.size() <= setIndex) || (!pCB->boundDescriptorSets[setIndex])) {
1257 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_DESCRIPTOR_SET_NOT_BOUND, "DS",
1258 "VkPipeline %#" PRIxLEAST64 " uses set #%u but that set is not bound.", (uint64_t)pPipe->pipeline, setIndex);
1259 } else if (!verify_set_layout_compatibility(my_data, my_data->setMap[pCB->boundDescriptorSets[setIndex]], pPipe->graphicsPipelineCI.layout, setIndex, errorString)) {
1260 // Set is bound but not compatible w/ overlapping pipelineLayout from PSO
1261 VkDescriptorSet setHandle = my_data->setMap[pCB->boundDescriptorSets[setIndex]]->set;
1262 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",
1263 "VkDescriptorSet (%#" PRIxLEAST64 ") bound as set #%u is not compatible with overlapping VkPipelineLayout %#" PRIxLEAST64 " due to: %s",
1264 (uint64_t)setHandle, setIndex, (uint64_t)pPipe->graphicsPipelineCI.layout, errorString.c_str());
1265 }
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07001266 }
1267 }
Mark Lobodzinski74e84692015-12-14 15:14:10 -07001268
Mark Lobodzinski611cf592015-12-18 15:35:38 -07001269 // Verify Vtx binding
1270 if (pPipe->vtxBindingCount > 0) {
1271 VkPipelineVertexInputStateCreateInfo *vtxInCI = &pPipe->vertexInputCI;
1272 for (uint32_t i = 0; i < vtxInCI->vertexBindingDescriptionCount; i++) {
1273 if ((pCB->boundVtxBuffers.size() < (i+1)) || (pCB->boundVtxBuffers[i] == VK_NULL_HANDLE)) {
1274 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS",
1275 "The Pipeline State Object (%#" PRIxLEAST64 ") expects that this Command Buffer's vertex binding Index %d should be set via vkCmdBindVertexBuffers.",
1276 (uint64_t)pCB->lastBoundPipeline, i);
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001277
Mark Lobodzinski611cf592015-12-18 15:35:38 -07001278 }
1279 }
1280 } else {
1281 if (!pCB->boundVtxBuffers.empty()) {
1282 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS,
1283 "DS", "Vertex buffers are bound to command buffer (%#" PRIxLEAST64 ") but no vertex buffers are attached to this Pipeline State Object (%#" PRIxLEAST64 ").",
1284 (uint64_t)pCB->commandBuffer, (uint64_t)pCB->lastBoundPipeline);
Tobin Ehlisd28acef2015-09-09 15:12:35 -06001285 }
1286 }
Mark Lobodzinski74e84692015-12-14 15:14:10 -07001287
Mark Lobodzinski611cf592015-12-18 15:35:38 -07001288 // If Viewport or scissors are dynamic, verify that dynamic count matches PSO count
1289 VkBool32 dynViewport = isDynamic(pPipe, VK_DYNAMIC_STATE_VIEWPORT);
1290 VkBool32 dynScissor = isDynamic(pPipe, VK_DYNAMIC_STATE_SCISSOR);
1291 if (dynViewport) {
1292 if (pCB->viewports.size() != pPipe->graphicsPipelineCI.pViewportState->viewportCount) {
1293 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
1294 "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);
1295 }
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06001296 }
Mark Lobodzinski611cf592015-12-18 15:35:38 -07001297 if (dynScissor) {
1298 if (pCB->scissors.size() != pPipe->graphicsPipelineCI.pViewportState->scissorCount) {
1299 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
1300 "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);
1301 }
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06001302 }
1303 }
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06001304 return result;
1305}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001306
Tobin Ehlisde63c532015-06-18 15:59:33 -06001307// Verify that create state for a pipeline is valid
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07001308static VkBool32 verifyPipelineCreateState(layer_data* my_data, const VkDevice device, PIPELINE_NODE* pPipeline)
Tobin Ehlisde63c532015-06-18 15:59:33 -06001309{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001310 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski312274f2015-12-16 14:25:22 -07001311
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07001312 if (!validate_pipeline_shaders(my_data, device, pPipeline)) {
Tobin Ehlisad61de42015-12-02 13:53:34 -07001313 skipCall = VK_TRUE;
1314 }
Mark Lobodzinski312274f2015-12-16 14:25:22 -07001315
Tobin Ehlisde63c532015-06-18 15:59:33 -06001316 // VS is required
1317 if (!(pPipeline->active_shaders & VK_SHADER_STAGE_VERTEX_BIT)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001318 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 -06001319 "Invalid Pipeline CreateInfo State: Vtx Shader required");
Tobin Ehlisde63c532015-06-18 15:59:33 -06001320 }
1321 // Either both or neither TC/TE shaders should be defined
Courtney Goeltzenleuchterc6fd2262015-10-15 17:35:38 -06001322 if (((pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) == 0) !=
1323 ((pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) == 0) ) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001324 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 -06001325 "Invalid Pipeline CreateInfo State: TE and TC shaders must be included or excluded as a pair");
Tobin Ehlisde63c532015-06-18 15:59:33 -06001326 }
1327 // Compute shaders should be specified independent of Gfx shaders
1328 if ((pPipeline->active_shaders & VK_SHADER_STAGE_COMPUTE_BIT) &&
Courtney Goeltzenleuchterc6fd2262015-10-15 17:35:38 -06001329 (pPipeline->active_shaders & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT |
1330 VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT | VK_SHADER_STAGE_GEOMETRY_BIT |
Tobin Ehlisde63c532015-06-18 15:59:33 -06001331 VK_SHADER_STAGE_FRAGMENT_BIT))) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001332 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 -06001333 "Invalid Pipeline CreateInfo State: Do not specify Compute Shader for Gfx Pipeline");
Tobin Ehlisde63c532015-06-18 15:59:33 -06001334 }
Chia-I Wu99ba2bb2015-10-31 00:31:16 +08001335 // VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology is only valid for tessellation pipelines.
Tobin Ehlisde63c532015-06-18 15:59:33 -06001336 // Mismatching primitive topology and tessellation fails graphics pipeline creation.
Courtney Goeltzenleuchterc6fd2262015-10-15 17:35:38 -06001337 if (pPipeline->active_shaders & (VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) &&
Chia-I Wu99ba2bb2015-10-31 00:31:16 +08001338 (pPipeline->iaStateCI.topology != VK_PRIMITIVE_TOPOLOGY_PATCH_LIST)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001339 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 +08001340 "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 -06001341 }
Chia-I Wu99ba2bb2015-10-31 00:31:16 +08001342 if (pPipeline->iaStateCI.topology == VK_PRIMITIVE_TOPOLOGY_PATCH_LIST) {
Courtney Goeltzenleuchterc6fd2262015-10-15 17:35:38 -06001343 if (~pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001344 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 +08001345 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology is only valid for tessellation pipelines");
Tobin Ehlis20693172015-09-17 08:46:18 -06001346 }
1347 if (!pPipeline->tessStateCI.patchControlPoints || (pPipeline->tessStateCI.patchControlPoints > 32)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001348 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 +08001349 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology used with patchControlPoints value %u."
Tobin Ehlis20693172015-09-17 08:46:18 -06001350 " patchControlPoints should be >0 and <=32.", pPipeline->tessStateCI.patchControlPoints);
1351 }
Tobin Ehlisde63c532015-06-18 15:59:33 -06001352 }
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06001353 // Viewport state must be included and viewport and scissor counts should always match
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001354 // NOTE : Even if these are flagged as dynamic, counts need to be set correctly for shader compiler
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06001355 if (!pPipeline->graphicsPipelineCI.pViewportState) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001356 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 -06001357 "Gfx Pipeline pViewportState is null. Even if viewport and scissors are dynamic PSO must include viewportCount and scissorCount in pViewportState.");
1358 } else if (pPipeline->graphicsPipelineCI.pViewportState->scissorCount != pPipeline->graphicsPipelineCI.pViewportState->viewportCount) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001359 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 -06001360 "Gfx Pipeline viewport count (%u) must match scissor count (%u).", pPipeline->vpStateCI.viewportCount, pPipeline->vpStateCI.scissorCount);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06001361 } else {
1362 // If viewport or scissor are not dynamic, then verify that data is appropriate for count
1363 VkBool32 dynViewport = isDynamic(pPipeline, VK_DYNAMIC_STATE_VIEWPORT);
1364 VkBool32 dynScissor = isDynamic(pPipeline, VK_DYNAMIC_STATE_SCISSOR);
1365 if (!dynViewport) {
1366 if (pPipeline->graphicsPipelineCI.pViewportState->viewportCount && !pPipeline->graphicsPipelineCI.pViewportState->pViewports) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001367 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 -07001368 "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 -06001369 }
1370 }
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06001371 if (!dynScissor) {
1372 if (pPipeline->graphicsPipelineCI.pViewportState->scissorCount && !pPipeline->graphicsPipelineCI.pViewportState->pScissors) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001373 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 -07001374 "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 -06001375 }
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001376 }
1377 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001378 return skipCall;
Tobin Ehlisde63c532015-06-18 15:59:33 -06001379}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001380
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001381// Init the pipeline mapping info based on pipeline create info LL tree
1382// Threading note : Calls to this function should wrapped in mutex
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07001383// TODO : this should really just be in the constructor for PIPELINE_NODE
Mark Lobodzinski2adea752015-11-10 15:25:01 -07001384static PIPELINE_NODE* initGraphicsPipeline(layer_data* dev_data, const VkGraphicsPipelineCreateInfo* pCreateInfo, PIPELINE_NODE* pBasePipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001385{
Tobin Ehlisde63c532015-06-18 15:59:33 -06001386 PIPELINE_NODE* pPipeline = new PIPELINE_NODE;
Mark Lobodzinskie443d2b2015-12-11 11:56:07 -07001387
Tobin Ehlisde63c532015-06-18 15:59:33 -06001388 if (pBasePipeline) {
Mark Lobodzinskie443d2b2015-12-11 11:56:07 -07001389 *pPipeline = *pBasePipeline;
Tobin Ehlisde63c532015-06-18 15:59:33 -06001390 }
Mark Lobodzinskie443d2b2015-12-11 11:56:07 -07001391
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001392 // First init create info
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001393 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001394
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001395 size_t bufferSize = 0;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001396 const VkPipelineVertexInputStateCreateInfo* pVICI = NULL;
Tobin Ehlis59db5712015-07-13 13:14:24 -06001397 const VkPipelineColorBlendStateCreateInfo* pCBCI = NULL;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001398
1399 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
1400 const VkPipelineShaderStageCreateInfo *pPSSCI = &pCreateInfo->pStages[i];
1401
Chia-I Wu062ad152015-10-31 00:31:16 +08001402 switch (pPSSCI->stage) {
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001403 case VK_SHADER_STAGE_VERTEX_BIT:
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001404 memcpy(&pPipeline->vsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1405 pPipeline->active_shaders |= VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001406 break;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001407 case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT:
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001408 memcpy(&pPipeline->tcsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Courtney Goeltzenleuchterc6fd2262015-10-15 17:35:38 -06001409 pPipeline->active_shaders |= VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001410 break;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001411 case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT:
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001412 memcpy(&pPipeline->tesCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Courtney Goeltzenleuchterc6fd2262015-10-15 17:35:38 -06001413 pPipeline->active_shaders |= VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001414 break;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001415 case VK_SHADER_STAGE_GEOMETRY_BIT:
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001416 memcpy(&pPipeline->gsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1417 pPipeline->active_shaders |= VK_SHADER_STAGE_GEOMETRY_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001418 break;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001419 case VK_SHADER_STAGE_FRAGMENT_BIT:
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001420 memcpy(&pPipeline->fsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1421 pPipeline->active_shaders |= VK_SHADER_STAGE_FRAGMENT_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001422 break;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001423 case VK_SHADER_STAGE_COMPUTE_BIT:
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001424 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
1425 pPipeline->active_shaders |= VK_SHADER_STAGE_COMPUTE_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001426 break;
1427 default:
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001428 // TODO : Flag error
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001429 break;
1430 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001431 }
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001432 // Copy over GraphicsPipelineCreateInfo structure embedded pointers
1433 if (pCreateInfo->stageCount != 0) {
1434 pPipeline->graphicsPipelineCI.pStages = new VkPipelineShaderStageCreateInfo[pCreateInfo->stageCount];
1435 bufferSize = pCreateInfo->stageCount * sizeof(VkPipelineShaderStageCreateInfo);
1436 memcpy((void*)pPipeline->graphicsPipelineCI.pStages, pCreateInfo->pStages, bufferSize);
1437 }
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001438 if (pCreateInfo->pVertexInputState != NULL) {
1439 memcpy((void*)&pPipeline->vertexInputCI, pCreateInfo->pVertexInputState , sizeof(VkPipelineVertexInputStateCreateInfo));
1440 // Copy embedded ptrs
1441 pVICI = pCreateInfo->pVertexInputState;
Chia-I Wu763a7492015-10-26 20:48:51 +08001442 pPipeline->vtxBindingCount = pVICI->vertexBindingDescriptionCount;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001443 if (pPipeline->vtxBindingCount) {
1444 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
1445 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
1446 memcpy((void*)pPipeline->pVertexBindingDescriptions, pVICI->pVertexBindingDescriptions, bufferSize);
1447 }
Chia-I Wu763a7492015-10-26 20:48:51 +08001448 pPipeline->vtxAttributeCount = pVICI->vertexAttributeDescriptionCount;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001449 if (pPipeline->vtxAttributeCount) {
1450 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
1451 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
1452 memcpy((void*)pPipeline->pVertexAttributeDescriptions, pVICI->pVertexAttributeDescriptions, bufferSize);
1453 }
1454 pPipeline->graphicsPipelineCI.pVertexInputState = &pPipeline->vertexInputCI;
1455 }
Tony Barboure307f582015-07-10 15:29:03 -06001456 if (pCreateInfo->pInputAssemblyState != NULL) {
1457 memcpy((void*)&pPipeline->iaStateCI, pCreateInfo->pInputAssemblyState, sizeof(VkPipelineInputAssemblyStateCreateInfo));
1458 pPipeline->graphicsPipelineCI.pInputAssemblyState = &pPipeline->iaStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001459 }
Tony Barboure307f582015-07-10 15:29:03 -06001460 if (pCreateInfo->pTessellationState != NULL) {
1461 memcpy((void*)&pPipeline->tessStateCI, pCreateInfo->pTessellationState, sizeof(VkPipelineTessellationStateCreateInfo));
1462 pPipeline->graphicsPipelineCI.pTessellationState = &pPipeline->tessStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001463 }
Tony Barboure307f582015-07-10 15:29:03 -06001464 if (pCreateInfo->pViewportState != NULL) {
1465 memcpy((void*)&pPipeline->vpStateCI, pCreateInfo->pViewportState, sizeof(VkPipelineViewportStateCreateInfo));
1466 pPipeline->graphicsPipelineCI.pViewportState = &pPipeline->vpStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001467 }
Chia-I Wu1f851912015-10-27 18:04:07 +08001468 if (pCreateInfo->pRasterizationState != NULL) {
1469 memcpy((void*)&pPipeline->rsStateCI, pCreateInfo->pRasterizationState, sizeof(VkPipelineRasterizationStateCreateInfo));
1470 pPipeline->graphicsPipelineCI.pRasterizationState = &pPipeline->rsStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001471 }
Tony Barboure307f582015-07-10 15:29:03 -06001472 if (pCreateInfo->pMultisampleState != NULL) {
1473 memcpy((void*)&pPipeline->msStateCI, pCreateInfo->pMultisampleState, sizeof(VkPipelineMultisampleStateCreateInfo));
1474 pPipeline->graphicsPipelineCI.pMultisampleState = &pPipeline->msStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001475 }
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001476 if (pCreateInfo->pDepthStencilState != NULL) {
1477 memcpy((void*)&pPipeline->dsStateCI, pCreateInfo->pDepthStencilState, sizeof(VkPipelineDepthStencilStateCreateInfo));
1478 pPipeline->graphicsPipelineCI.pDepthStencilState = &pPipeline->dsStateCI;
1479 }
Tony Barboure307f582015-07-10 15:29:03 -06001480 if (pCreateInfo->pColorBlendState != NULL) {
1481 memcpy((void*)&pPipeline->cbStateCI, pCreateInfo->pColorBlendState, sizeof(VkPipelineColorBlendStateCreateInfo));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001482 // Copy embedded ptrs
Tony Barboure307f582015-07-10 15:29:03 -06001483 pCBCI = pCreateInfo->pColorBlendState;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001484 pPipeline->attachmentCount = pCBCI->attachmentCount;
1485 if (pPipeline->attachmentCount) {
Tony Barboure307f582015-07-10 15:29:03 -06001486 pPipeline->pAttachments = new VkPipelineColorBlendAttachmentState[pPipeline->attachmentCount];
1487 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineColorBlendAttachmentState);
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001488 memcpy((void*)pPipeline->pAttachments, pCBCI->pAttachments, bufferSize);
1489 }
Tony Barboure307f582015-07-10 15:29:03 -06001490 pPipeline->graphicsPipelineCI.pColorBlendState = &pPipeline->cbStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001491 }
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001492 if (pCreateInfo->pDynamicState != NULL) {
1493 memcpy((void*)&pPipeline->dynStateCI, pCreateInfo->pDynamicState, sizeof(VkPipelineDynamicStateCreateInfo));
1494 if (pPipeline->dynStateCI.dynamicStateCount) {
1495 pPipeline->dynStateCI.pDynamicStates = new VkDynamicState[pPipeline->dynStateCI.dynamicStateCount];
1496 bufferSize = pPipeline->dynStateCI.dynamicStateCount * sizeof(VkDynamicState);
1497 memcpy((void*)pPipeline->dynStateCI.pDynamicStates, pCreateInfo->pDynamicState->pDynamicStates, bufferSize);
1498 }
1499 pPipeline->graphicsPipelineCI.pDynamicState = &pPipeline->dynStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001500 }
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07001501 pPipeline->active_sets.clear();
Tobin Ehlisde63c532015-06-18 15:59:33 -06001502 return pPipeline;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001503}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001504
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001505// Free the Pipeline nodes
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06001506static void deletePipelines(layer_data* my_data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001507{
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06001508 if (my_data->pipelineMap.size() <= 0)
David Pinedof5997ab2015-04-27 16:36:17 -06001509 return;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06001510 for (auto ii=my_data->pipelineMap.begin(); ii!=my_data->pipelineMap.end(); ++ii) {
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001511 if ((*ii).second->graphicsPipelineCI.stageCount != 0) {
1512 delete[] (*ii).second->graphicsPipelineCI.pStages;
1513 }
Tobin Ehliscd3109e2015-04-01 11:59:08 -06001514 if ((*ii).second->pVertexBindingDescriptions) {
1515 delete[] (*ii).second->pVertexBindingDescriptions;
1516 }
1517 if ((*ii).second->pVertexAttributeDescriptions) {
1518 delete[] (*ii).second->pVertexAttributeDescriptions;
1519 }
1520 if ((*ii).second->pAttachments) {
1521 delete[] (*ii).second->pAttachments;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001522 }
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001523 if ((*ii).second->dynStateCI.dynamicStateCount != 0) {
1524 delete[] (*ii).second->dynStateCI.pDynamicStates;
1525 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001526 delete (*ii).second;
1527 }
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06001528 my_data->pipelineMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001529}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001530
Tobin Ehlis2464b882015-04-01 08:40:34 -06001531// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001532static VkSampleCountFlagBits getNumSamples(layer_data* my_data, const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -06001533{
Chia-I Wue420a332015-10-26 20:04:44 +08001534 PIPELINE_NODE* pPipe = my_data->pipelineMap[pipeline];
Tobin Ehlisb3a506f2015-07-13 14:51:15 -06001535 if (VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
Chia-I Wu1f851912015-10-27 18:04:07 +08001536 return pPipe->msStateCI.rasterizationSamples;
Tobin Ehlisb3a506f2015-07-13 14:51:15 -06001537 }
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001538 return VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis2464b882015-04-01 08:40:34 -06001539}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001540
Tobin Ehlis2464b882015-04-01 08:40:34 -06001541// Validate state related to the PSO
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06001542static VkBool32 validatePipelineState(layer_data* my_data, const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -06001543{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001544 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06001545 // Verify that any MSAA request in PSO matches sample# in bound FB
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001546 VkSampleCountFlagBits psoNumSamples = getNumSamples(my_data, pipeline);
Tobin Ehlis2464b882015-04-01 08:40:34 -06001547 if (pCB->activeRenderPass) {
Tobin Ehlisad61de42015-12-02 13:53:34 -07001548 const VkRenderPassCreateInfo* pRPCI = my_data->renderPassMap[pCB->activeRenderPass]->pCreateInfo;
Chia-I Wuc278df82015-07-07 11:50:03 +08001549 const VkSubpassDescription* pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001550 VkSampleCountFlagBits subpassNumSamples = (VkSampleCountFlagBits) 0;
Chia-I Wuc278df82015-07-07 11:50:03 +08001551 uint32_t i;
1552
Chia-I Wu763a7492015-10-26 20:48:51 +08001553 for (i = 0; i < pSD->colorAttachmentCount; i++) {
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001554 VkSampleCountFlagBits samples;
Chia-I Wuc278df82015-07-07 11:50:03 +08001555
Cody Northrop6de6b0b2015-08-04 11:16:41 -06001556 if (pSD->pColorAttachments[i].attachment == VK_ATTACHMENT_UNUSED)
Chia-I Wuc278df82015-07-07 11:50:03 +08001557 continue;
1558
Cody Northrop6de6b0b2015-08-04 11:16:41 -06001559 samples = pRPCI->pAttachments[pSD->pColorAttachments[i].attachment].samples;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001560 if (subpassNumSamples == (VkSampleCountFlagBits) 0) {
Chia-I Wuc278df82015-07-07 11:50:03 +08001561 subpassNumSamples = samples;
1562 } else if (subpassNumSamples != samples) {
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001563 subpassNumSamples = (VkSampleCountFlagBits) -1;
Chia-I Wuc278df82015-07-07 11:50:03 +08001564 break;
1565 }
1566 }
Chia-I Wuce532f72015-10-26 17:32:47 +08001567 if (pSD->pDepthStencilAttachment && pSD->pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001568 const VkSampleCountFlagBits samples = pRPCI->pAttachments[pSD->pDepthStencilAttachment->attachment].samples;
1569 if (subpassNumSamples == (VkSampleCountFlagBits) 0)
Chia-I Wuc278df82015-07-07 11:50:03 +08001570 subpassNumSamples = samples;
1571 else if (subpassNumSamples != samples)
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001572 subpassNumSamples = (VkSampleCountFlagBits) -1;
Chia-I Wuc278df82015-07-07 11:50:03 +08001573 }
1574
1575 if (psoNumSamples != subpassNumSamples) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001576 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 -06001577 "Num samples mismatch! Binding PSO (%#" PRIxLEAST64 ") with %u samples while current RenderPass (%#" PRIxLEAST64 ") w/ %u samples!",
Chia-I Wue420a332015-10-26 20:04:44 +08001578 (uint64_t) pipeline, psoNumSamples, (uint64_t) pCB->activeRenderPass, subpassNumSamples);
Tobin Ehlis2464b882015-04-01 08:40:34 -06001579 }
1580 } else {
1581 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
1582 // Verify and flag error as appropriate
1583 }
1584 // TODO : Add more checks here
1585 } else {
1586 // TODO : Validate non-gfx pipeline updates
1587 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001588 return VK_FALSE;
Tobin Ehlis2464b882015-04-01 08:40:34 -06001589}
1590
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001591// Block of code at start here specifically for managing/tracking DSs
1592
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001593// Return Pool node ptr for specified pool or else NULL
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07001594static DESCRIPTOR_POOL_NODE* getPoolNode(layer_data* my_data, const VkDescriptorPool pool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001595{
1596 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07001597 if (my_data->descriptorPoolMap.find(pool) == my_data->descriptorPoolMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001598 loader_platform_thread_unlock_mutex(&globalLock);
1599 return NULL;
1600 }
1601 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07001602 return my_data->descriptorPoolMap[pool];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001603}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001604
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001605// Return Set node ptr for specified set or else NULL
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06001606static SET_NODE* getSetNode(layer_data* my_data, const VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001607{
1608 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue420a332015-10-26 20:04:44 +08001609 if (my_data->setMap.find(set) == my_data->setMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001610 loader_platform_thread_unlock_mutex(&globalLock);
1611 return NULL;
1612 }
1613 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wue420a332015-10-26 20:04:44 +08001614 return my_data->setMap[set];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001615}
1616
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06001617static LAYOUT_NODE* getLayoutNode(layer_data* my_data, const VkDescriptorSetLayout layout) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001618 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisad61de42015-12-02 13:53:34 -07001619 if (my_data->descriptorSetLayoutMap.find(layout) == my_data->descriptorSetLayoutMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001620 loader_platform_thread_unlock_mutex(&globalLock);
1621 return NULL;
1622 }
1623 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisad61de42015-12-02 13:53:34 -07001624 return my_data->descriptorSetLayoutMap[layout];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001625}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001626
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001627// 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 -06001628static VkBool32 validUpdateStruct(layer_data* my_data, const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001629{
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001630 switch (pUpdateStruct->sType)
1631 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001632 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1633 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001634 return VK_FALSE;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001635 default:
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001636 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 -06001637 "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 -06001638 }
1639}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001640
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001641// Set count for given update struct in the last parameter
Courtney Goeltzenleuchter5bc11202015-12-16 16:08:44 -07001642// 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 -06001643static uint32_t getUpdateCount(layer_data* my_data, const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001644{
1645 switch (pUpdateStruct->sType)
1646 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001647 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
Chia-I Wu763a7492015-10-26 20:48:51 +08001648 return ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorCount;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001649 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001650 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wu763a7492015-10-26 20:48:51 +08001651 return ((VkCopyDescriptorSet*)pUpdateStruct)->descriptorCount;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001652 }
Courtney Goeltzenleuchter902a0862015-12-16 16:08:08 -07001653
1654 return 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001655}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001656
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001657// For given Layout Node and binding, return index where that binding begins
1658static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
1659{
1660 uint32_t offsetIndex = 0;
Chia-I Wub5689ee2015-10-31 00:31:16 +08001661 for (uint32_t i = 0; i < pLayout->createInfo.bindingCount; i++) {
1662 if (pLayout->createInfo.pBinding[i].binding == binding)
1663 break;
Chia-I Wu045654f2015-11-06 06:42:02 +08001664 offsetIndex += pLayout->createInfo.pBinding[i].descriptorCount;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001665 }
1666 return offsetIndex;
1667}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001668
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001669// For given layout node and binding, return last index that is updated
1670static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
1671{
1672 uint32_t offsetIndex = 0;
Chia-I Wub5689ee2015-10-31 00:31:16 +08001673 for (uint32_t i = 0; i < pLayout->createInfo.bindingCount; i++) {
Chia-I Wu045654f2015-11-06 06:42:02 +08001674 offsetIndex += pLayout->createInfo.pBinding[i].descriptorCount;
Chia-I Wub5689ee2015-10-31 00:31:16 +08001675 if (pLayout->createInfo.pBinding[i].binding == binding)
1676 break;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001677 }
1678 return offsetIndex-1;
1679}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001680
Tobin Ehlise66ec962015-10-27 12:54:50 -06001681// For given layout and update, return the first overall index of the layout that is updated
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06001682static 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 -06001683{
Tobin Ehlise66ec962015-10-27 12:54:50 -06001684 return getBindingStartIndex(pLayout, binding)+arrayIndex;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001685}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001686
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06001687// For given layout and update, return the last overall index of the layout that is updated
1688static 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 -06001689{
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06001690 uint32_t count = getUpdateCount(my_data, device, pUpdateStruct);
Tobin Ehlise66ec962015-10-27 12:54:50 -06001691 return getBindingStartIndex(pLayout, binding)+arrayIndex+count-1;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001692}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001693
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001694// Verify that the descriptor type in the update struct matches what's expected by the layout
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001695static 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 -06001696{
1697 // First get actual type of update
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001698 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001699 VkDescriptorType actualType;
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001700 uint32_t i = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001701 switch (pUpdateStruct->sType)
1702 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001703 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1704 actualType = ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001705 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001706 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
1707 /* no need to validate */
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001708 return VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001709 break;
1710 default:
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001711 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 -06001712 "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 -06001713 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001714 if (VK_FALSE == skipCall) {
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001715 // Set first stageFlags as reference and verify that all other updates match it
1716 VkShaderStageFlags refStageFlags = pLayout->stageFlags[startIndex];
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001717 for (i = startIndex; i <= endIndex; i++) {
Tobin Ehlis91423d22015-10-20 10:11:55 -06001718 if (pLayout->descriptorTypes[i] != actualType) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001719 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 -06001720 "Write descriptor update has descriptor type %s that does not match overlapping binding descriptor type of %s!",
1721 string_VkDescriptorType(actualType), string_VkDescriptorType(pLayout->descriptorTypes[i]));
1722 }
1723 if (pLayout->stageFlags[i] != refStageFlags) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001724 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 -06001725 "Write descriptor update has stageFlags %x that do not match overlapping binding descriptor stageFlags of %x!",
1726 refStageFlags, pLayout->stageFlags[i]);
Tobin Ehlis3b341092015-09-30 08:30:20 -06001727 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001728 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001729 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001730 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001731}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001732
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001733// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001734// struct into the pNewNode param. Return VK_TRUE if error condition encountered and callback signals early exit.
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001735// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlis42d440c2015-10-20 17:06:16 -06001736static VkBool32 shadowUpdateNode(layer_data* my_data, const VkDevice device, GENERIC_HEADER* pUpdate, GENERIC_HEADER** pNewNode)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001737{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001738 VkBool32 skipCall = VK_FALSE;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001739 VkWriteDescriptorSet* pWDS = NULL;
1740 VkCopyDescriptorSet* pCDS = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001741 size_t array_size = 0;
1742 size_t base_array_size = 0;
1743 size_t total_array_size = 0;
1744 size_t baseBuffAddr = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001745 switch (pUpdate->sType)
1746 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001747 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1748 pWDS = new VkWriteDescriptorSet;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001749 *pNewNode = (GENERIC_HEADER*)pWDS;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001750 memcpy(pWDS, pUpdate, sizeof(VkWriteDescriptorSet));
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06001751
1752 switch (pWDS->descriptorType) {
1753 case VK_DESCRIPTOR_TYPE_SAMPLER:
1754 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
1755 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
1756 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
1757 {
Chia-I Wu763a7492015-10-26 20:48:51 +08001758 VkDescriptorImageInfo *info = new VkDescriptorImageInfo[pWDS->descriptorCount];
1759 memcpy(info, pWDS->pImageInfo, pWDS->descriptorCount * sizeof(VkDescriptorImageInfo));
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06001760 pWDS->pImageInfo = info;
Tobin Ehliscb085292015-12-01 09:57:09 -07001761 }
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06001762 break;
1763 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
1764 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
1765 {
Chia-I Wu763a7492015-10-26 20:48:51 +08001766 VkBufferView *info = new VkBufferView[pWDS->descriptorCount];
1767 memcpy(info, pWDS->pTexelBufferView, pWDS->descriptorCount * sizeof(VkBufferView));
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06001768 pWDS->pTexelBufferView = info;
1769 }
1770 break;
1771 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
1772 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
1773 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
1774 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
1775 {
Chia-I Wu763a7492015-10-26 20:48:51 +08001776 VkDescriptorBufferInfo *info = new VkDescriptorBufferInfo[pWDS->descriptorCount];
1777 memcpy(info, pWDS->pBufferInfo, pWDS->descriptorCount * sizeof(VkDescriptorBufferInfo));
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06001778 pWDS->pBufferInfo = info;
1779 }
1780 break;
1781 default:
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07001782 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06001783 break;
1784 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001785 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001786 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
1787 pCDS = new VkCopyDescriptorSet;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001788 *pNewNode = (GENERIC_HEADER*)pCDS;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001789 memcpy(pCDS, pUpdate, sizeof(VkCopyDescriptorSet));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001790 break;
1791 default:
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001792 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 -06001793 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdate->sType), pUpdate->sType))
1794 return VK_TRUE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001795 }
1796 // Make sure that pNext for the end of shadow copy is NULL
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001797 (*pNewNode)->pNext = NULL;
1798 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001799}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001800
Tobin Ehlisb46be812015-10-23 16:00:08 -06001801// Verify that given sampler is valid
1802static VkBool32 validateSampler(const layer_data* my_data, const VkSampler* pSampler, const VkBool32 immutable)
1803{
1804 VkBool32 skipCall = VK_FALSE;
Chia-I Wue420a332015-10-26 20:04:44 +08001805 auto sampIt = my_data->sampleMap.find(*pSampler);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001806 if (sampIt == my_data->sampleMap.end()) {
1807 if (!immutable) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001808 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 +08001809 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid sampler %#" PRIxLEAST64, (uint64_t) *pSampler);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001810 } else { // immutable
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001811 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 +08001812 "vkUpdateDescriptorSets: Attempt to update descriptor whose binding has an invalid immutable sampler %#" PRIxLEAST64, (uint64_t) *pSampler);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001813 }
1814 } else {
1815 // TODO : Any further checks we want to do on the sampler?
1816 }
1817 return skipCall;
1818}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001819
Tobin Ehlisb46be812015-10-23 16:00:08 -06001820// Verify that given imageView is valid
1821static VkBool32 validateImageView(const layer_data* my_data, const VkImageView* pImageView, const VkImageLayout imageLayout)
1822{
1823 VkBool32 skipCall = VK_FALSE;
Chia-I Wue420a332015-10-26 20:04:44 +08001824 auto ivIt = my_data->imageViewMap.find(*pImageView);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001825 if (ivIt == my_data->imageViewMap.end()) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001826 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 +08001827 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid imageView %#" PRIxLEAST64, (uint64_t) *pImageView);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001828 } else {
1829 // Validate that imageLayout is compatible with aspectMask and image format
1830 VkImageAspectFlags aspectMask = ivIt->second->subresourceRange.aspectMask;
Chia-I Wue420a332015-10-26 20:04:44 +08001831 VkImage image = ivIt->second->image;
Michael Lentineee4ad4d2015-10-23 12:41:44 -07001832 // TODO : Check here in case we have a bad image
Chia-I Wue420a332015-10-26 20:04:44 +08001833 auto imgIt = my_data->imageMap.find(image);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001834 if (imgIt == my_data->imageMap.end()) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001835 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 -07001836 "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 -06001837 } else {
1838 VkFormat format = (*imgIt).second->format;
Courtney Goeltzenleuchterf2bca902015-11-03 15:41:43 -07001839 VkBool32 ds = vk_format_is_depth_or_stencil(format);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001840 switch (imageLayout) {
1841 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
1842 // Only Color bit must be set
1843 if ((aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) != VK_IMAGE_ASPECT_COLOR_BIT) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001844 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 -06001845 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 +08001846 " that does not have VK_IMAGE_ASPECT_COLOR_BIT set.", (uint64_t) *pImageView);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001847 }
1848 // format must NOT be DS
1849 if (ds) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001850 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 -06001851 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 +08001852 " 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 -06001853 }
1854 break;
1855 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
1856 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
1857 // Depth or stencil bit must be set, but both must NOT be set
1858 if (aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) {
1859 if (aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) {
1860 // both must NOT be set
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001861 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 -06001862 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with imageView %#" PRIxLEAST64 ""
Chia-I Wue420a332015-10-26 20:04:44 +08001863 " that has both STENCIL and DEPTH aspects set", (uint64_t) *pImageView);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001864 }
1865 } else if (!(aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)) {
1866 // Neither were set
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001867 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 -06001868 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout %s and imageView %#" PRIxLEAST64 ""
Chia-I Wue420a332015-10-26 20:04:44 +08001869 " that does not have STENCIL or DEPTH aspect set.", string_VkImageLayout(imageLayout), (uint64_t) *pImageView);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001870 }
1871 // format must be DS
1872 if (!ds) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001873 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 -06001874 DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout %s and imageView %#" PRIxLEAST64 ""
Chia-I Wue420a332015-10-26 20:04:44 +08001875 " 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 -06001876 }
1877 break;
1878 default:
1879 // anything to check for other layouts?
1880 break;
1881 }
1882 }
1883 }
1884 return skipCall;
1885}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001886
Tobin Ehlisb46be812015-10-23 16:00:08 -06001887// Verify that given bufferView is valid
1888static VkBool32 validateBufferView(const layer_data* my_data, const VkBufferView* pBufferView)
1889{
1890 VkBool32 skipCall = VK_FALSE;
Chia-I Wue420a332015-10-26 20:04:44 +08001891 auto sampIt = my_data->bufferViewMap.find(*pBufferView);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001892 if (sampIt == my_data->bufferViewMap.end()) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001893 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 +08001894 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid bufferView %#" PRIxLEAST64, (uint64_t) *pBufferView);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001895 } else {
1896 // TODO : Any further checks we want to do on the bufferView?
1897 }
1898 return skipCall;
1899}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001900
Tobin Ehlisb46be812015-10-23 16:00:08 -06001901// Verify that given bufferInfo is valid
1902static VkBool32 validateBufferInfo(const layer_data* my_data, const VkDescriptorBufferInfo* pBufferInfo)
1903{
1904 VkBool32 skipCall = VK_FALSE;
Chia-I Wue420a332015-10-26 20:04:44 +08001905 auto sampIt = my_data->bufferMap.find(pBufferInfo->buffer);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001906 if (sampIt == my_data->bufferMap.end()) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001907 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 +08001908 "vkUpdateDescriptorSets: Attempt to update descriptor where bufferInfo has invalid buffer %#" PRIxLEAST64, (uint64_t) pBufferInfo->buffer);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001909 } else {
1910 // TODO : Any further checks we want to do on the bufferView?
1911 }
1912 return skipCall;
1913}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001914
Tobin Ehlisb46be812015-10-23 16:00:08 -06001915static VkBool32 validateUpdateContents(const layer_data* my_data, const VkWriteDescriptorSet *pWDS, const VkDescriptorSetLayoutBinding* pLayoutBinding)
1916{
1917 VkBool32 skipCall = VK_FALSE;
1918 // First verify that for the given Descriptor type, the correct DescriptorInfo data is supplied
1919 VkBufferView* pBufferView = NULL;
1920 const VkSampler* pSampler = NULL;
1921 VkImageView* pImageView = NULL;
1922 VkImageLayout* pImageLayout = NULL;
1923 VkDescriptorBufferInfo* pBufferInfo = NULL;
1924 VkBool32 immutable = VK_FALSE;
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001925 uint32_t i = 0;
1926 // For given update type, verify that update contents are correct
1927 switch (pWDS->descriptorType) {
1928 case VK_DESCRIPTOR_TYPE_SAMPLER:
Chia-I Wu763a7492015-10-26 20:48:51 +08001929 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisb46be812015-10-23 16:00:08 -06001930 skipCall |= validateSampler(my_data, &(pWDS->pImageInfo[i].sampler), immutable);
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001931 }
1932 break;
1933 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
Chia-I Wu763a7492015-10-26 20:48:51 +08001934 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisb46be812015-10-23 16:00:08 -06001935 if (NULL == pLayoutBinding->pImmutableSamplers) {
1936 pSampler = &(pWDS->pImageInfo[i].sampler);
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001937 if (immutable) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001938 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 -06001939 "vkUpdateDescriptorSets: Update #%u is not an immutable sampler %#" PRIxLEAST64 ", but previous update(s) from this "
1940 "VkWriteDescriptorSet struct used an immutable sampler. All updates from a single struct must either "
Chia-I Wue420a332015-10-26 20:04:44 +08001941 "use immutable or non-immutable samplers.", i, (uint64_t) *pSampler);
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001942 }
Tobin Ehlisb46be812015-10-23 16:00:08 -06001943 } else {
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001944 if (i>0 && !immutable) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001945 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 -06001946 "vkUpdateDescriptorSets: Update #%u is an immutable sampler, but previous update(s) from this "
1947 "VkWriteDescriptorSet struct used a non-immutable sampler. All updates from a single struct must either "
1948 "use immutable or non-immutable samplers.", i);
1949 }
Tobin Ehlisb46be812015-10-23 16:00:08 -06001950 immutable = VK_TRUE;
1951 pSampler = &(pLayoutBinding->pImmutableSamplers[i]);
1952 }
1953 skipCall |= validateSampler(my_data, pSampler, immutable);
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001954 }
1955 // Intentionally fall through here to also validate image stuff
1956 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
1957 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
1958 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
Chia-I Wu763a7492015-10-26 20:48:51 +08001959 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisb46be812015-10-23 16:00:08 -06001960 skipCall |= validateImageView(my_data, &(pWDS->pImageInfo[i].imageView), pWDS->pImageInfo[i].imageLayout);
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001961 }
1962 break;
1963 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
1964 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
Chia-I Wu763a7492015-10-26 20:48:51 +08001965 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisb46be812015-10-23 16:00:08 -06001966 skipCall |= validateBufferView(my_data, &(pWDS->pTexelBufferView[i]));
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001967 }
1968 break;
1969 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
1970 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
1971 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
1972 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
Chia-I Wu763a7492015-10-26 20:48:51 +08001973 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisb46be812015-10-23 16:00:08 -06001974 skipCall |= validateBufferInfo(my_data, &(pWDS->pBufferInfo[i]));
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001975 }
1976 break;
Tobin Ehlisb46be812015-10-23 16:00:08 -06001977 }
1978 return skipCall;
1979}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001980
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001981// update DS mappings based on write and copy update arrays
Chia-I Wu483e7702015-10-26 17:20:32 +08001982static 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 -06001983{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001984 VkBool32 skipCall = VK_FALSE;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001985
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001986 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001987 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001988 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001989 // Validate Write updates
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06001990 uint32_t i = 0;
Chia-I Wu483e7702015-10-26 17:20:32 +08001991 for (i=0; i < descriptorWriteCount; i++) {
Chia-I Wu1f851912015-10-27 18:04:07 +08001992 VkDescriptorSet ds = pWDS[i].dstSet;
Chia-I Wue420a332015-10-26 20:04:44 +08001993 SET_NODE* pSet = my_data->setMap[ds];
Tobin Ehlisb46be812015-10-23 16:00:08 -06001994 GENERIC_HEADER* pUpdate = (GENERIC_HEADER*) &pWDS[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001995 pLayout = pSet->pLayout;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001996 // First verify valid update struct
Tobin Ehlis42d440c2015-10-20 17:06:16 -06001997 if ((skipCall = validUpdateStruct(my_data, device, pUpdate)) == VK_TRUE) {
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001998 break;
1999 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002000 uint32_t binding = 0, endIndex = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08002001 binding = pWDS[i].dstBinding;
Tobin Ehlis68fbd442015-10-27 12:25:35 -06002002 // Make sure that layout being updated has the binding being updated
Chia-I Wub5689ee2015-10-31 00:31:16 +08002003 if (pLayout->bindings.find(binding) == pLayout->bindings.end()) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002004 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 -08002005 "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 -06002006 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002007 // Next verify that update falls within size of given binding
Chia-I Wu1f851912015-10-27 18:04:07 +08002008 endIndex = getUpdateEndIndex(my_data, device, pLayout, binding, pWDS[i].dstArrayElement, pUpdate);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002009 if (getBindingEndIndex(pLayout, binding) < endIndex) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002010 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002011 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002012 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 -06002013 "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 -06002014 } else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlis68fbd442015-10-27 12:25:35 -06002015 uint32_t startIndex;
Chia-I Wu1f851912015-10-27 18:04:07 +08002016 startIndex = getUpdateStartIndex(my_data, device, pLayout, binding, pWDS[i].dstArrayElement, pUpdate);
Tobin Ehlis68fbd442015-10-27 12:25:35 -06002017 // Layout bindings match w/ update, now verify that update type & stageFlags are the same for entire update
2018 if ((skipCall = validateUpdateConsistency(my_data, device, pLayout, pUpdate, startIndex, endIndex)) == VK_FALSE) {
2019 // 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 +08002020 if ((skipCall = validateUpdateContents(my_data, &pWDS[i], &pLayout->createInfo.pBinding[binding])) == VK_FALSE) {
Tobin Ehlisb46be812015-10-23 16:00:08 -06002021 // Update is good. Save the update info
2022 // Create new update struct for this set's shadow copy
2023 GENERIC_HEADER* pNewNode = NULL;
2024 skipCall |= shadowUpdateNode(my_data, device, pUpdate, &pNewNode);
2025 if (NULL == pNewNode) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002026 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 -06002027 "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
2028 } else {
2029 // Insert shadow node into LL of updates for this set
2030 pNewNode->pNext = pSet->pUpdateStructs;
2031 pSet->pUpdateStructs = pNewNode;
2032 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlisb46be812015-10-23 16:00:08 -06002033 for (uint32_t j = startIndex; j <= endIndex; j++) {
2034 assert(j<pSet->descriptorCount);
2035 pSet->ppDescriptors[j] = pNewNode;
2036 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002037 }
2038 }
2039 }
2040 }
2041 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002042 }
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06002043 // Now validate copy updates
Chia-I Wu483e7702015-10-26 17:20:32 +08002044 for (i=0; i < descriptorCopyCount; ++i) {
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06002045 SET_NODE *pSrcSet = NULL, *pDstSet = NULL;
2046 LAYOUT_NODE *pSrcLayout = NULL, *pDstLayout = NULL;
2047 uint32_t srcStartIndex = 0, srcEndIndex = 0, dstStartIndex = 0, dstEndIndex = 0;
2048 // For each copy make sure that update falls within given layout and that types match
Chia-I Wue420a332015-10-26 20:04:44 +08002049 pSrcSet = my_data->setMap[pCDS[i].srcSet];
Chia-I Wu1f851912015-10-27 18:04:07 +08002050 pDstSet = my_data->setMap[pCDS[i].dstSet];
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06002051 pSrcLayout = pSrcSet->pLayout;
2052 pDstLayout = pDstSet->pLayout;
2053 // Validate that src binding is valid for src set layout
Chia-I Wub5689ee2015-10-31 00:31:16 +08002054 if (pSrcLayout->bindings.find(pCDS[i].srcBinding) == pSrcLayout->bindings.end()) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002055 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 -06002056 "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 +08002057 i, pCDS[i].srcBinding, (uint64_t) pSrcLayout->layout, pSrcLayout->createInfo.bindingCount-1);
Chia-I Wub5689ee2015-10-31 00:31:16 +08002058 } else if (pDstLayout->bindings.find(pCDS[i].dstBinding) == pDstLayout->bindings.end()) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002059 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 +08002060 "Copy descriptor update %u has dstBinding %u which is out of bounds for underlying SetLayout %#" PRIxLEAST64 " which only has bindings 0-%u.",
2061 i, pCDS[i].dstBinding, (uint64_t) pDstLayout->layout, pDstLayout->createInfo.bindingCount-1);
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06002062 } else {
2063 // Proceed with validation. Bindings are ok, but make sure update is within bounds of given layout
2064 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 +08002065 dstEndIndex = getUpdateEndIndex(my_data, device, pDstLayout, pCDS[i].dstBinding, pCDS[i].dstArrayElement, (const GENERIC_HEADER*)&(pCDS[i]));
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06002066 if (getBindingEndIndex(pSrcLayout, pCDS[i].srcBinding) < srcEndIndex) {
2067 pLayoutCI = &pSrcLayout->createInfo;
2068 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002069 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 -06002070 "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 +08002071 } else if (getBindingEndIndex(pDstLayout, pCDS[i].dstBinding) < dstEndIndex) {
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06002072 pLayoutCI = &pDstLayout->createInfo;
2073 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002074 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 +08002075 "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 -06002076 } else {
2077 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 +08002078 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 +08002079 for (uint32_t j=0; j<pCDS[i].descriptorCount; ++j) {
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06002080 // For copy just make sure that the types match and then perform the update
2081 if (pSrcLayout->descriptorTypes[srcStartIndex+j] != pDstLayout->descriptorTypes[dstStartIndex+j]) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002082 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 -06002083 "Copy descriptor update index %u, update count #%u, has src update descriptor type %s that does not match overlapping dest descriptor type of %s!",
2084 i, j+1, string_VkDescriptorType(pSrcLayout->descriptorTypes[srcStartIndex+j]), string_VkDescriptorType(pDstLayout->descriptorTypes[dstStartIndex+j]));
2085 } else {
2086 // point dst descriptor at corresponding src descriptor
2087 pDstSet->ppDescriptors[j+dstStartIndex] = pSrcSet->ppDescriptors[j+srcStartIndex];
2088 }
2089 }
2090 }
2091 }
2092 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002093 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002094 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002095}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002096
Tobin Ehlisc6457d22015-10-20 16:16:04 -06002097// Verify that given pool has descriptors that are being requested for allocation
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002098static 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 -06002099{
2100 VkBool32 skipCall = VK_FALSE;
2101 uint32_t i = 0, j = 0;
2102 for (i=0; i<count; ++i) {
2103 LAYOUT_NODE* pLayout = getLayoutNode(dev_data, pSetLayouts[i]);
2104 if (NULL == pLayout) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002105 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 +08002106 "Unable to find set layout node for layout %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pSetLayouts[i]);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06002107 } else {
Chia-I Wuc51b1212015-10-27 19:25:11 +08002108 uint32_t typeIndex = 0, poolSizeCount = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08002109 for (j=0; j<pLayout->createInfo.bindingCount; ++j) {
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002110 typeIndex = static_cast<uint32_t>(pLayout->createInfo.pBinding[j].descriptorType);
Chia-I Wu045654f2015-11-06 06:42:02 +08002111 poolSizeCount = pLayout->createInfo.pBinding[j].descriptorCount;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002112 if (poolSizeCount > pPoolNode->availableDescriptorTypeCount[typeIndex]) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002113 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 -06002114 "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 +08002115 poolSizeCount, string_VkDescriptorType(pLayout->createInfo.pBinding[j].descriptorType), (uint64_t) pPoolNode->pool, pPoolNode->availableDescriptorTypeCount[typeIndex]);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06002116 } else { // Decrement available descriptors of this type
Chia-I Wuc51b1212015-10-27 19:25:11 +08002117 pPoolNode->availableDescriptorTypeCount[typeIndex] -= poolSizeCount;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06002118 }
2119 }
2120 }
2121 }
2122 return skipCall;
2123}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002124
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002125// Free the shadowed update node for this Set
2126// NOTE : Calls to this function should be wrapped in mutex
2127static void freeShadowUpdateTree(SET_NODE* pSet)
2128{
2129 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
2130 pSet->pUpdateStructs = NULL;
2131 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
2132 // Clear the descriptor mappings as they will now be invalid
2133 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
2134 while(pShadowUpdate) {
2135 pFreeUpdate = pShadowUpdate;
2136 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
2137 uint32_t index = 0;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002138 VkWriteDescriptorSet * pWDS = NULL;
2139 VkCopyDescriptorSet * pCDS = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002140 void** ppToFree = NULL;
2141 switch (pFreeUpdate->sType)
2142 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002143 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
2144 pWDS = (VkWriteDescriptorSet*)pFreeUpdate;
Tony Barbourf740f902015-11-02 11:46:29 -07002145 switch (pWDS->descriptorType) {
2146 case VK_DESCRIPTOR_TYPE_SAMPLER:
2147 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
2148 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2149 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
2150 {
2151 delete[] pWDS->pImageInfo;
2152 }
2153 break;
2154 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2155 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
2156 {
2157 delete[] pWDS->pTexelBufferView;
2158 }
2159 break;
2160 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2161 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2162 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2163 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
2164 {
2165 delete[] pWDS->pBufferInfo;
2166 }
2167 break;
2168 default:
2169 break;
Courtney Goeltzenleuchtere4099742015-10-22 15:31:56 -06002170 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002171 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002172 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002173 break;
2174 default:
2175 assert(0);
2176 break;
2177 }
Tobin Ehliseaf28662015-04-08 10:58:37 -06002178 delete pFreeUpdate;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002179 }
2180}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002181
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002182// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002183// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002184static void deletePools(layer_data* my_data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002185{
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002186 if (my_data->descriptorPoolMap.size() <= 0)
David Pinedof5997ab2015-04-27 16:36:17 -06002187 return;
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002188 for (auto ii=my_data->descriptorPoolMap.begin(); ii!=my_data->descriptorPoolMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002189 SET_NODE* pSet = (*ii).second->pSets;
2190 SET_NODE* pFreeSet = pSet;
2191 while (pSet) {
2192 pFreeSet = pSet;
2193 pSet = pSet->pNext;
Tobin Ehliseaf28662015-04-08 10:58:37 -06002194 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002195 // Free Update shadow struct tree
2196 freeShadowUpdateTree(pFreeSet);
2197 if (pFreeSet->ppDescriptors) {
Chris Forbes4506d3f2015-06-04 10:49:27 +12002198 delete[] pFreeSet->ppDescriptors;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002199 }
2200 delete pFreeSet;
2201 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002202 delete (*ii).second;
2203 }
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002204 my_data->descriptorPoolMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002205}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002206
Tobin Ehliseaf28662015-04-08 10:58:37 -06002207// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002208// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002209static void deleteLayouts(layer_data* my_data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002210{
Tobin Ehlisad61de42015-12-02 13:53:34 -07002211 if (my_data->descriptorSetLayoutMap.size() <= 0)
David Pinedof5997ab2015-04-27 16:36:17 -06002212 return;
Tobin Ehlisad61de42015-12-02 13:53:34 -07002213 for (auto ii=my_data->descriptorSetLayoutMap.begin(); ii!=my_data->descriptorSetLayoutMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002214 LAYOUT_NODE* pLayout = (*ii).second;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002215 if (pLayout->createInfo.pBinding) {
Chia-I Wu763a7492015-10-26 20:48:51 +08002216 for (uint32_t i=0; i<pLayout->createInfo.bindingCount; i++) {
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002217 if (pLayout->createInfo.pBinding[i].pImmutableSamplers)
2218 delete[] pLayout->createInfo.pBinding[i].pImmutableSamplers;
Tobin Ehliseaf28662015-04-08 10:58:37 -06002219 }
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002220 delete[] pLayout->createInfo.pBinding;
Tobin Ehliseaf28662015-04-08 10:58:37 -06002221 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002222 delete pLayout;
2223 }
Tobin Ehlisad61de42015-12-02 13:53:34 -07002224 my_data->descriptorSetLayoutMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002225}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002226
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002227// Currently clearing a set is removing all previous updates to that set
2228// TODO : Validate if this is correct clearing behavior
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002229static void clearDescriptorSet(layer_data* my_data, VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002230{
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002231 SET_NODE* pSet = getSetNode(my_data, set);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002232 if (!pSet) {
2233 // TODO : Return error
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002234 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002235 loader_platform_thread_lock_mutex(&globalLock);
2236 freeShadowUpdateTree(pSet);
2237 loader_platform_thread_unlock_mutex(&globalLock);
2238 }
2239}
2240
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002241static void clearDescriptorPool(layer_data* my_data, const VkDevice device, const VkDescriptorPool pool, VkDescriptorPoolResetFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002242{
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002243 DESCRIPTOR_POOL_NODE* pPool = getPoolNode(my_data, pool);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002244 if (!pPool) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002245 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 +08002246 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkResetDescriptorPool() call", (uint64_t) pool);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002247 } else {
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002248 // TODO: validate flags
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002249 // For every set off of this pool, clear it
2250 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002251 while (pSet) {
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002252 clearDescriptorSet(my_data, pSet->set);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002253 }
Tobin Ehlisc6457d22015-10-20 16:16:04 -06002254 // Reset available count to max count for this pool
2255 for (uint32_t i=0; i<pPool->availableDescriptorTypeCount.size(); ++i) {
2256 pPool->availableDescriptorTypeCount[i] = pPool->maxDescriptorTypeCount[i];
2257 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002258 }
2259}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002260
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002261// For given CB object, fetch associated CB Node from map
Chia-I Wu1f851912015-10-27 18:04:07 +08002262static GLOBAL_CB_NODE* getCBNode(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002263{
2264 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski13b66742015-11-20 14:33:48 -07002265 if (my_data->commandBufferMap.count(cb) == 0) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002266 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002267 // TODO : How to pass cb as srcObj here?
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002268 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 +08002269 "Attempt to use CommandBuffer %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<uint64_t>(cb));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002270 return NULL;
2271 }
2272 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wu1f851912015-10-27 18:04:07 +08002273 return my_data->commandBufferMap[cb];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002274}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002275
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002276// Free all CB Nodes
2277// NOTE : Calls to this function should be wrapped in mutex
Chia-I Wu1f851912015-10-27 18:04:07 +08002278static void deleteCommandBuffers(layer_data* my_data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002279{
Mark Lobodzinski13b66742015-11-20 14:33:48 -07002280 if (my_data->commandBufferMap.size() <= 0) {
David Pinedof5997ab2015-04-27 16:36:17 -06002281 return;
Mark Lobodzinski13b66742015-11-20 14:33:48 -07002282 }
Chia-I Wu1f851912015-10-27 18:04:07 +08002283 for (auto ii=my_data->commandBufferMap.begin(); ii!=my_data->commandBufferMap.end(); ++ii) {
Courtney Goeltzenleuchter09098a72015-04-27 15:04:43 -06002284 vector<CMD_NODE*> cmd_node_list = (*ii).second->pCmds;
2285 while (!cmd_node_list.empty()) {
2286 CMD_NODE* cmd_node = cmd_node_list.back();
2287 delete cmd_node;
2288 cmd_node_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002289 }
2290 delete (*ii).second;
2291 }
Chia-I Wu1f851912015-10-27 18:04:07 +08002292 my_data->commandBufferMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002293}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002294
Chia-I Wu1f851912015-10-27 18:04:07 +08002295static 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 -06002296{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002297 // TODO : How to pass cb as srcObj here?
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002298 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 -08002299 "You must call vkBeginCommandBuffer() before this call to %s", caller_name);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002300}
Michael Lentine2b9eda42015-10-28 15:55:18 -07002301
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07002302VkBool32 validateCmdsInCmdBuffer(const layer_data* dev_data, const GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd_type) {
Tony Barbour778b08c2015-12-17 15:54:05 -07002303 // TODO : I think this is trying to validate this part of the spec:
2304 // If contents is VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS, the contents are recorded in secondary command
2305 // buffers that will be called from the primary command buffer, and vkCmdExecuteCommands is the only valid command
2306 // on the command buffer until vkCmdNextSubpass or vkCmdEndRenderPass.
2307 //
2308 // But the code below is forceing vkCmdExecuteCommands to be the only thing in the command buffer which is not necessary
2309 // it just needs to be the only thing in the renderpass
2310 //
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07002311 VkBool32 skip_call = false;
Tony Barbour778b08c2015-12-17 15:54:05 -07002312 //for (auto cmd : pCB->pCmds) {
2313 // if (cmd_type == CMD_EXECUTECOMMANDS && cmd->type != CMD_EXECUTECOMMANDS) {
2314 // skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_COMMAND_BUFFER, "DS",
2315 // "vkCmdExecuteCommands() cannot be called on a cmd buffer with exsiting commands.");
2316 // }
2317 // if (cmd_type != CMD_EXECUTECOMMANDS && cmd->type == CMD_EXECUTECOMMANDS) {
2318 // skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_COMMAND_BUFFER, "DS",
2319 // "Commands cannot be added to a cmd buffer with exsiting secondary commands.");
2320 // }
2321 //}
Michael Lentine2b9eda42015-10-28 15:55:18 -07002322 return skip_call;
2323}
2324
Tobin Ehlis42d440c2015-10-20 17:06:16 -06002325static VkBool32 addCmd(const layer_data* my_data, GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002326{
Michael Lentine2b9eda42015-10-28 15:55:18 -07002327 VkBool32 skipCall = validateCmdsInCmdBuffer(my_data, pCB, cmd);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002328 CMD_NODE* pCmd = new CMD_NODE;
2329 if (pCmd) {
2330 // init cmd node and append to end of cmd LL
2331 memset(pCmd, 0, sizeof(CMD_NODE));
2332 pCmd->cmdNumber = ++pCB->numCmds;
2333 pCmd->type = cmd;
2334 pCB->pCmds.push_back(pCmd);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002335 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002336 // TODO : How to pass cb as srcObj here?
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002337 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 +08002338 "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 -06002339 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002340 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002341}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002342
Chia-I Wu1f851912015-10-27 18:04:07 +08002343static void resetCB(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002344{
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002345 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002346 if (pCB) {
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06002347 vector<CMD_NODE*> cmd_list = pCB->pCmds;
2348 while (!cmd_list.empty()) {
2349 delete cmd_list.back();
2350 cmd_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002351 }
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06002352 pCB->pCmds.clear();
Tobin Ehlis0cea4082015-08-18 07:10:58 -06002353 // Reset CB state (need to save createInfo)
Chia-I Wu1f851912015-10-27 18:04:07 +08002354 VkCommandBufferAllocateInfo saveCBCI = pCB->createInfo;
Chia-I Wu1f851912015-10-27 18:04:07 +08002355 pCB->commandBuffer = cb;
Tobin Ehlis0cea4082015-08-18 07:10:58 -06002356 pCB->createInfo = saveCBCI;
Michael Lentine27b0f902015-10-12 11:30:14 -05002357 memset(&pCB->beginInfo, 0, sizeof(VkCommandBufferBeginInfo));
2358 pCB->fence = 0;
2359 pCB->numCmds = 0;
2360 memset(pCB->drawCount, 0, NUM_DRAW_TYPES * sizeof(uint64_t));
2361 pCB->state = CB_NEW;
2362 pCB->submitCount = 0;
2363 pCB->status = 0;
2364 pCB->pCmds.clear();
2365 pCB->lastBoundPipeline = 0;
2366 pCB->viewports.clear();
2367 pCB->scissors.clear();
2368 pCB->lineWidth = 0;
2369 pCB->depthBiasConstantFactor = 0;
2370 pCB->depthBiasClamp = 0;
2371 pCB->depthBiasSlopeFactor = 0;
2372 memset(pCB->blendConstants, 0, 4 * sizeof(float));
2373 pCB->minDepthBounds = 0;
2374 pCB->maxDepthBounds = 0;
2375 memset(&pCB->front, 0, sizeof(stencil_data));
2376 memset(&pCB->back, 0, sizeof(stencil_data));
2377 pCB->lastBoundDescriptorSet = 0;
2378 pCB->lastBoundPipelineLayout = 0;
2379 pCB->activeRenderPass = 0;
2380 pCB->activeSubpass = 0;
2381 pCB->framebuffer = 0;
Michael Lentine27b0f902015-10-12 11:30:14 -05002382 pCB->boundDescriptorSets.clear();
2383 pCB->imageLayoutMap.clear();
Mark Lobodzinski74e84692015-12-14 15:14:10 -07002384 pCB->boundVtxBuffers.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002385 }
2386}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002387
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002388// Set PSO-related status bits for CB, including dynamic state set via PSO
Tobin Ehlis97866202015-06-10 12:57:07 -06002389static void set_cb_pso_status(GLOBAL_CB_NODE* pCB, const PIPELINE_NODE* pPipe)
2390{
2391 for (uint32_t i = 0; i < pPipe->cbStateCI.attachmentCount; i++) {
Chia-I Wuc51b1212015-10-27 19:25:11 +08002392 if (0 != pPipe->pAttachments[i].colorWriteMask) {
Tobin Ehlis97866202015-06-10 12:57:07 -06002393 pCB->status |= CBSTATUS_COLOR_BLEND_WRITE_ENABLE;
2394 }
2395 }
2396 if (pPipe->dsStateCI.depthWriteEnable) {
Cody Northrop2605cb02015-08-18 15:21:16 -06002397 pCB->status |= CBSTATUS_DEPTH_WRITE_ENABLE;
2398 }
Cody Northrop2605cb02015-08-18 15:21:16 -06002399 if (pPipe->dsStateCI.stencilTestEnable) {
2400 pCB->status |= CBSTATUS_STENCIL_TEST_ENABLE;
Tobin Ehlis97866202015-06-10 12:57:07 -06002401 }
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002402 // Account for any dynamic state not set via this PSO
2403 if (!pPipe->dynStateCI.dynamicStateCount) { // All state is static
2404 pCB->status = CBSTATUS_ALL;
2405 } else {
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002406 // First consider all state on
2407 // Then unset any state that's noted as dynamic in PSO
2408 // Finally OR that into CB statemask
2409 CBStatusFlags psoDynStateMask = CBSTATUS_ALL;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002410 for (uint32_t i=0; i < pPipe->dynStateCI.dynamicStateCount; i++) {
2411 switch (pPipe->dynStateCI.pDynamicStates[i]) {
2412 case VK_DYNAMIC_STATE_VIEWPORT:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002413 psoDynStateMask &= ~CBSTATUS_VIEWPORT_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002414 break;
2415 case VK_DYNAMIC_STATE_SCISSOR:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002416 psoDynStateMask &= ~CBSTATUS_SCISSOR_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002417 break;
2418 case VK_DYNAMIC_STATE_LINE_WIDTH:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002419 psoDynStateMask &= ~CBSTATUS_LINE_WIDTH_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002420 break;
2421 case VK_DYNAMIC_STATE_DEPTH_BIAS:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002422 psoDynStateMask &= ~CBSTATUS_DEPTH_BIAS_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002423 break;
2424 case VK_DYNAMIC_STATE_BLEND_CONSTANTS:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002425 psoDynStateMask &= ~CBSTATUS_BLEND_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002426 break;
2427 case VK_DYNAMIC_STATE_DEPTH_BOUNDS:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002428 psoDynStateMask &= ~CBSTATUS_DEPTH_BOUNDS_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002429 break;
2430 case VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002431 psoDynStateMask &= ~CBSTATUS_STENCIL_READ_MASK_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002432 break;
2433 case VK_DYNAMIC_STATE_STENCIL_WRITE_MASK:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002434 psoDynStateMask &= ~CBSTATUS_STENCIL_WRITE_MASK_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002435 break;
2436 case VK_DYNAMIC_STATE_STENCIL_REFERENCE:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002437 psoDynStateMask &= ~CBSTATUS_STENCIL_REFERENCE_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002438 break;
2439 default:
2440 // TODO : Flag error here
2441 break;
2442 }
2443 }
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002444 pCB->status |= psoDynStateMask;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002445 }
Tobin Ehlis97866202015-06-10 12:57:07 -06002446}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002447
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002448// Print the last bound Gfx Pipeline
Chia-I Wu1f851912015-10-27 18:04:07 +08002449static VkBool32 printPipeline(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002450{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002451 VkBool32 skipCall = VK_FALSE;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002452 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002453 if (pCB) {
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002454 PIPELINE_NODE *pPipeTrav = getPipeline(my_data, pCB->lastBoundPipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002455 if (!pPipeTrav) {
2456 // nothing to print
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002457 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002458 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 -08002459 "%s", vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002460 }
2461 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002462 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002463}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002464
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002465// Print details of DS config to stdout
Chia-I Wu1f851912015-10-27 18:04:07 +08002466static VkBool32 printDSConfig(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002467{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002468 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002469 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 -06002470 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis7297f192015-06-09 08:39:32 -06002471 if (pCB && pCB->lastBoundDescriptorSet) {
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002472 SET_NODE* pSet = getSetNode(my_data, pCB->lastBoundDescriptorSet);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002473 DESCRIPTOR_POOL_NODE* pPool = getPoolNode(my_data, pSet->pool);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002474 // Print out pool details
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002475 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 +08002476 "Details for pool %#" PRIxLEAST64 ".", (uint64_t) pPool->pool);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002477 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002478 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 -06002479 "%s", poolStr.c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002480 // Print out set details
2481 char prefix[10];
2482 uint32_t index = 0;
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002483 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 +08002484 "Details for descriptor set %#" PRIxLEAST64 ".", (uint64_t) pSet->set);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002485 LAYOUT_NODE* pLayout = pSet->pLayout;
2486 // Print layout details
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002487 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 -08002488 "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 -06002489 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002490 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002491 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 -06002492 "%s", DSLstr.c_str());
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002493 index++;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002494 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
2495 if (pUpdate) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002496 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 +08002497 "Update Chain [UC] for descriptor set %#" PRIxLEAST64 ":", (uint64_t) pSet->set);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002498 sprintf(prefix, " [UC] ");
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002499 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 -08002500 "%s", dynamic_display(pUpdate, prefix).c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002501 // TODO : If there is a "view" associated with this update, print CI for that view
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002502 } else {
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06002503 if (0 != pSet->descriptorCount) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002504 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 +08002505 "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 -06002506 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002507 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 +08002508 "FYI: No descriptors in descriptor set %#" PRIxLEAST64 ".", (uint64_t) pSet->set);
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06002509 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002510 }
2511 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002512 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002513}
2514
Chia-I Wu1f851912015-10-27 18:04:07 +08002515static void printCB(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002516{
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002517 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
David Pinedof5997ab2015-04-27 16:36:17 -06002518 if (pCB && pCB->pCmds.size() > 0) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002519 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 -06002520 "Cmds in CB %p", (void*)cb);
Courtney Goeltzenleuchtercf2a5362015-04-27 11:16:35 -06002521 vector<CMD_NODE*> pCmds = pCB->pCmds;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002522 for (auto ii=pCmds.begin(); ii!=pCmds.end(); ++ii) {
2523 // TODO : Need to pass cb as srcObj here
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002524 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 -08002525 " CMD#%" PRIu64 ": %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002526 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002527 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002528 // Nothing to print
2529 }
2530}
2531
Chia-I Wu1f851912015-10-27 18:04:07 +08002532static VkBool32 synchAndPrintDSConfig(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002533{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002534 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002535 if (!(my_data->report_data->active_flags & VK_DEBUG_REPORT_INFO_BIT_EXT)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002536 return skipCall;
Mike Stroyanfa2f2222015-08-12 17:11:28 -06002537 }
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002538 skipCall |= printDSConfig(my_data, cb);
2539 skipCall |= printPipeline(my_data, cb);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002540 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002541}
2542
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002543// Flags validation error if the associated call is made inside a render pass. The apiName
2544// routine should ONLY be called outside a render pass.
Tobin Ehlis42d440c2015-10-20 17:06:16 -06002545static VkBool32 insideRenderPass(const layer_data* my_data, GLOBAL_CB_NODE *pCB, const char *apiName)
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002546{
2547 VkBool32 inside = VK_FALSE;
2548 if (pCB->activeRenderPass) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002549 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 +08002550 (uint64_t)pCB->commandBuffer, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002551 "%s: It is invalid to issue this call inside an active render pass (%#" PRIxLEAST64 ")",
Chia-I Wue420a332015-10-26 20:04:44 +08002552 apiName, (uint64_t) pCB->activeRenderPass);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002553 }
2554 return inside;
2555}
2556
2557// Flags validation error if the associated call is made outside a render pass. The apiName
2558// routine should ONLY be called inside a render pass.
Tobin Ehlis42d440c2015-10-20 17:06:16 -06002559static VkBool32 outsideRenderPass(const layer_data* my_data, GLOBAL_CB_NODE *pCB, const char *apiName)
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002560{
2561 VkBool32 outside = VK_FALSE;
Mark Lobodzinski611cf592015-12-18 15:35:38 -07002562 if (((pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) &&
2563 (!pCB->activeRenderPass)) ||
2564 ((pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) &&
2565 (!pCB->activeRenderPass) &&
2566 !(pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT))) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002567 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 +08002568 (uint64_t)pCB->commandBuffer, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002569 "%s: This call must be issued inside an active render pass.", apiName);
2570 }
2571 return outside;
2572}
2573
Courtney Goeltzenleuchterb03a0bf2015-11-25 14:31:49 -07002574static void init_draw_state(layer_data *my_data, const VkAllocationCallbacks *pAllocator)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002575{
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002576 uint32_t report_flags = 0;
2577 uint32_t debug_action = 0;
2578 FILE *log_output = NULL;
2579 const char *option_str;
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002580 VkDebugReportCallbackEXT callback;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002581 // initialize DrawState options
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002582 report_flags = getLayerOptionFlags("DrawStateReportFlags", 0);
2583 getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &debug_action);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002584
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002585 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002586 {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002587 option_str = getLayerOption("DrawStateLogFilename");
Tobin Ehlisb4b6e7c2015-09-15 09:55:54 -06002588 log_output = getLayerLogOutput(option_str, "DrawState");
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002589 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07002590 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002591 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07002592 dbgInfo.pfnCallback = log_callback;
2593 dbgInfo.pUserData = log_output;
2594 dbgInfo.flags = report_flags;
2595 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchter1781b1c2015-10-05 15:58:38 -06002596 my_data->logging_callback.push_back(callback);
2597 }
2598
2599 if (debug_action & VK_DBG_LAYER_ACTION_DEBUG_OUTPUT) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002600 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07002601 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002602 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07002603 dbgInfo.pfnCallback = win32_debug_output_msg;
2604 dbgInfo.pUserData = log_output;
2605 dbgInfo.flags = report_flags;
2606 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchter1781b1c2015-10-05 15:58:38 -06002607 my_data->logging_callback.push_back(callback);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002608 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002609
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002610 if (!globalLockInitialized)
2611 {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002612 loader_platform_thread_create_mutex(&globalLock);
2613 globalLockInitialized = 1;
2614 }
2615}
2616
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002617VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance)
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06002618{
Tobin Ehliscb085292015-12-01 09:57:09 -07002619 // TODOSC : Shouldn't need any customization here
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002620 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
2621 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Chia-I Wu69f40122015-10-26 21:10:41 +08002622 VkResult result = pTable->CreateInstance(pCreateInfo, pAllocator, pInstance);
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06002623
2624 if (result == VK_SUCCESS) {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002625 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
2626 my_data->report_data = debug_report_create_instance(
2627 pTable,
2628 *pInstance,
Chia-I Wu763a7492015-10-26 20:48:51 +08002629 pCreateInfo->enabledExtensionNameCount,
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002630 pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchterf4a2eba2015-06-08 14:58:39 -06002631
Courtney Goeltzenleuchterb03a0bf2015-11-25 14:31:49 -07002632 init_draw_state(my_data, pAllocator);
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06002633 }
2634 return result;
2635}
2636
Jon Ashburne0fa2282015-05-20 09:00:28 -06002637/* hook DestroyInstance to remove tableInstanceMap entry */
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002638VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator)
Jon Ashburne0fa2282015-05-20 09:00:28 -06002639{
Tobin Ehliscb085292015-12-01 09:57:09 -07002640 // TODOSC : Shouldn't need any customization here
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002641 dispatch_key key = get_dispatch_key(instance);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002642 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
2643 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Chia-I Wu69f40122015-10-26 21:10:41 +08002644 pTable->DestroyInstance(instance, pAllocator);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002645
2646 // Clean up logging callback, if any
Courtney Goeltzenleuchter1781b1c2015-10-05 15:58:38 -06002647 while (my_data->logging_callback.size() > 0) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002648 VkDebugReportCallbackEXT callback = my_data->logging_callback.back();
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07002649 layer_destroy_msg_callback(my_data->report_data, callback, pAllocator);
Courtney Goeltzenleuchter1781b1c2015-10-05 15:58:38 -06002650 my_data->logging_callback.pop_back();
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002651 }
2652
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06002653 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002654 delete my_data->instance_dispatch_table;
2655 layer_data_map.erase(key);
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002656 // TODO : Potential race here with separate threads creating/destroying instance
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002657 if (layer_data_map.empty()) {
Mike Stroyand9dd0072015-08-18 15:56:18 -06002658 // Release mutex when destroying last instance.
2659 loader_platform_thread_delete_mutex(&globalLock);
2660 globalLockInitialized = 0;
2661 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002662}
2663
Jon Ashburnf0615e22015-05-25 14:11:37 -06002664static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
2665{
Tony Barbour29b12062015-07-13 13:37:24 -06002666 uint32_t i;
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002667 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
2668 dev_data->device_extensions.debug_marker_enabled = false;
Michael Lentine27b0f902015-10-12 11:30:14 -05002669 dev_data->device_extensions.wsi_enabled = false;
2670
2671
2672 VkLayerDispatchTable *pDisp = dev_data->device_dispatch_table;
2673 PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr;
2674
Michael Lentine27b0f902015-10-12 11:30:14 -05002675 pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR) gpa(device, "vkCreateSwapchainKHR");
2676 pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR) gpa(device, "vkDestroySwapchainKHR");
2677 pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR) gpa(device, "vkGetSwapchainImagesKHR");
2678 pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR) gpa(device, "vkAcquireNextImageKHR");
2679 pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR) gpa(device, "vkQueuePresentKHR");
Jon Ashburnf0615e22015-05-25 14:11:37 -06002680
Chia-I Wu763a7492015-10-26 20:48:51 +08002681 for (i = 0; i < pCreateInfo->enabledExtensionNameCount; i++) {
Ian Elliottc623ba52015-11-20 14:13:17 -07002682 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) {
Michael Lentine27b0f902015-10-12 11:30:14 -05002683 dev_data->device_extensions.wsi_enabled = true;
2684 }
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002685 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002686 /* Found a matching extension name, mark it enabled and init dispatch table*/
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002687 dev_data->device_extensions.debug_marker_enabled = true;
Jon Ashburnc1d059f2015-12-10 19:12:21 -07002688 initDebugMarkerTable(device);
2689
Jon Ashburnf0615e22015-05-25 14:11:37 -06002690 }
Jon Ashburnf0615e22015-05-25 14:11:37 -06002691 }
2692}
2693
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002694VK_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 -06002695{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002696 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08002697 VkResult result = dev_data->device_dispatch_table->CreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
Tobin Ehliscb085292015-12-01 09:57:09 -07002698 // TODOSC : shouldn't need any customization here
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002699 if (result == VK_SUCCESS) {
2700 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002701 dev_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
Jon Ashburn7e07faf2015-06-18 15:02:58 -06002702 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002703 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002704 return result;
2705}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002706
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002707// prototype
2708static void deleteRenderPasses(layer_data*);
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002709VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002710{
Tobin Ehliscb085292015-12-01 09:57:09 -07002711 // TODOSC : Shouldn't need any customization here
Jeremy Hayesea1fef52015-06-19 11:37:38 -06002712 dispatch_key key = get_dispatch_key(device);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002713 layer_data* dev_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002714 // Free all the memory
2715 loader_platform_thread_lock_mutex(&globalLock);
2716 deletePipelines(dev_data);
2717 deleteRenderPasses(dev_data);
Chia-I Wu1f851912015-10-27 18:04:07 +08002718 deleteCommandBuffers(dev_data);
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002719 deletePools(dev_data);
2720 deleteLayouts(dev_data);
Tobin Ehlisb46be812015-10-23 16:00:08 -06002721 dev_data->imageViewMap.clear();
2722 dev_data->imageMap.clear();
2723 dev_data->bufferViewMap.clear();
2724 dev_data->bufferMap.clear();
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002725 loader_platform_thread_unlock_mutex(&globalLock);
2726
Chia-I Wu69f40122015-10-26 21:10:41 +08002727 dev_data->device_dispatch_table->DestroyDevice(device, pAllocator);
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002728 tableDebugMarkerMap.erase(key);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002729 delete dev_data->device_dispatch_table;
2730 layer_data_map.erase(key);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002731}
2732
Courtney Goeltzenleuchterd89520d2015-12-01 14:08:28 -07002733static const VkExtensionProperties instance_extensions[] = {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002734 {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002735 VK_EXT_DEBUG_REPORT_EXTENSION_NAME,
2736 VK_EXT_DEBUG_REPORT_REVISION
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002737 }
Jon Ashburneb2728b2015-04-10 14:33:07 -06002738};
2739
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002740VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002741 const char *pLayerName,
2742 uint32_t *pCount,
2743 VkExtensionProperties* pProperties)
Jon Ashburneb2728b2015-04-10 14:33:07 -06002744{
Courtney Goeltzenleuchterd89520d2015-12-01 14:08:28 -07002745 return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002746}
Jon Ashburneb2728b2015-04-10 14:33:07 -06002747
Courtney Goeltzenleuchterd89520d2015-12-01 14:08:28 -07002748static const VkLayerProperties ds_global_layers[] = {
2749 {
2750 "DrawState",
2751 VK_API_VERSION,
2752 VK_MAKE_VERSION(0, 1, 0),
2753 "Validation layer: DrawState",
2754 }
2755};
2756
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002757VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002758 uint32_t *pCount,
2759 VkLayerProperties* pProperties)
2760{
2761 return util_GetLayerProperties(ARRAY_SIZE(ds_global_layers),
2762 ds_global_layers,
2763 pCount, pProperties);
2764}
Jon Ashburneb2728b2015-04-10 14:33:07 -06002765
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002766static const VkExtensionProperties ds_device_extensions[] = {
2767 {
2768 DEBUG_MARKER_EXTENSION_NAME,
2769 VK_MAKE_VERSION(0, 1, 0),
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002770 }
2771};
2772
2773static const VkLayerProperties ds_device_layers[] = {
2774 {
2775 "DrawState",
2776 VK_API_VERSION,
2777 VK_MAKE_VERSION(0, 1, 0),
2778 "Validation layer: DrawState",
2779 }
2780};
2781
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002782VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002783 VkPhysicalDevice physicalDevice,
2784 const char* pLayerName,
2785 uint32_t* pCount,
2786 VkExtensionProperties* pProperties)
2787{
Tobin Ehlis32479352015-12-01 09:48:58 -07002788 // DrawState does not have any physical device extensions
Jon Ashburnaff81ff2015-11-02 17:37:20 -07002789 if (pLayerName == NULL) {
2790 dispatch_key key = get_dispatch_key(physicalDevice);
2791 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlis32479352015-12-01 09:48:58 -07002792 return my_data->instance_dispatch_table->EnumerateDeviceExtensionProperties(
Jon Ashburnaff81ff2015-11-02 17:37:20 -07002793 physicalDevice,
2794 NULL,
2795 pCount,
2796 pProperties);
2797 } else {
2798 return util_GetExtensionProperties(ARRAY_SIZE(ds_device_extensions),
2799 ds_device_extensions,
2800 pCount, pProperties);
2801 }
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002802}
2803
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002804VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002805 VkPhysicalDevice physicalDevice,
2806 uint32_t* pCount,
2807 VkLayerProperties* pProperties)
2808{
Tobin Ehlis32479352015-12-01 09:48:58 -07002809 /* DrawState physical device layers are the same as global */
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002810 return util_GetLayerProperties(ARRAY_SIZE(ds_device_layers), ds_device_layers,
2811 pCount, pProperties);
Jon Ashburneb2728b2015-04-10 14:33:07 -06002812}
2813
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07002814VkBool32 ValidateCmdBufImageLayouts(VkCommandBuffer cmdBuffer) {
2815 VkBool32 skip_call = false;
Michael Lentine27b0f902015-10-12 11:30:14 -05002816 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
2817 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
2818 for (auto cb_image_data : pCB->imageLayoutMap) {
2819 auto image_data = dev_data->imageLayoutMap.find(cb_image_data.first);
2820 if (image_data == dev_data->imageLayoutMap.end()) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002821 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 -08002822 "Cannot submit cmd buffer using deleted image %" PRIu64 ".", reinterpret_cast<uint64_t>(cb_image_data.first));
Michael Lentine27b0f902015-10-12 11:30:14 -05002823 } else {
2824 if (dev_data->imageLayoutMap[cb_image_data.first]->layout != cb_image_data.second.initialLayout) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002825 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 -05002826 "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);
2827 }
2828 dev_data->imageLayoutMap[cb_image_data.first]->layout = cb_image_data.second.layout;
2829 }
2830 }
2831 return skip_call;
2832}
2833
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002834VK_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 -06002835{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002836 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis28be0be2015-05-22 12:38:16 -06002837 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002838 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06002839 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
Chia-I Wu483e7702015-10-26 17:20:32 +08002840 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Chia-I Wu763a7492015-10-26 20:48:51 +08002841 for (uint32_t i=0; i < submit->commandBufferCount; i++) {
Mark Lobodzinski78940a42015-11-30 16:48:53 -07002842
2843#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
2844 skipCall |= ValidateCmdBufImageLayouts(submit->pCommandBuffers[i]);
2845#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
2846
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06002847 // Validate that cmd buffers have been updated
2848 pCB = getCBNode(dev_data, submit->pCommandBuffers[i]);
2849 loader_platform_thread_lock_mutex(&globalLock);
2850 pCB->submitCount++; // increment submit count
Chia-I Wu1f851912015-10-27 18:04:07 +08002851 if ((pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT) && (pCB->submitCount > 1)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002852 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 -05002853 "CB %#" PRIxLEAST64 " was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted %#" PRIxLEAST64 " times.",
2854 reinterpret_cast<uint64_t>(pCB->commandBuffer), pCB->submitCount);
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06002855 }
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07002856 if (CB_RECORDED != pCB->state) {
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06002857 // Flag error for using CB w/o vkEndCommandBuffer() called
2858 // TODO : How to pass cb as srcObj?
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002859 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 +08002860 "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 -06002861 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07002862 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06002863 }
Tobin Ehlise90b1712015-05-27 14:30:06 -06002864 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis28be0be2015-05-22 12:38:16 -06002865 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002866 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002867 if (VK_FALSE == skipCall)
Chia-I Wu483e7702015-10-26 17:20:32 +08002868 return dev_data->device_dispatch_table->QueueSubmit(queue, submitCount, pSubmits, fence);
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07002869 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002870}
2871
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002872VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002873{
Chia-I Wu69f40122015-10-26 21:10:41 +08002874 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 -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 vkDestroySemaphore(VkDevice device, VkSemaphore semaphore, 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->DestroySemaphore(device, semaphore, 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 vkDestroyEvent(VkDevice device, VkEvent event, 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->DestroyEvent(device, event, 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 vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002891{
Chia-I Wu69f40122015-10-26 21:10:41 +08002892 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 -06002893 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002894}
2895
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002896VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002897{
Tobin Ehlisb46be812015-10-23 16:00:08 -06002898 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08002899 dev_data->device_dispatch_table->DestroyBuffer(device, buffer, pAllocator);
Chia-I Wue420a332015-10-26 20:04:44 +08002900 dev_data->bufferMap.erase(buffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002901}
2902
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002903VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBufferView(VkDevice device, VkBufferView bufferView, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002904{
Tobin Ehlisb46be812015-10-23 16:00:08 -06002905 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08002906 dev_data->device_dispatch_table->DestroyBufferView(device, bufferView, pAllocator);
Chia-I Wue420a332015-10-26 20:04:44 +08002907 dev_data->bufferViewMap.erase(bufferView);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002908}
2909
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002910VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002911{
Tobin Ehlisb46be812015-10-23 16:00:08 -06002912 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08002913 dev_data->device_dispatch_table->DestroyImage(device, image, pAllocator);
Chia-I Wue420a332015-10-26 20:04:44 +08002914 dev_data->imageMap.erase(image);
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 vkDestroyImageView(VkDevice device, VkImageView imageView, 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->DestroyImageView(device, imageView, 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 vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule, 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->DestroyShaderModule(device, shaderModule, 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 vkDestroyPipeline(VkDevice device, VkPipeline pipeline, 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->DestroyPipeline(device, pipeline, 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 vkDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout, 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->DestroyPipelineLayout(device, pipelineLayout, 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 vkDestroySampler(VkDevice device, VkSampler sampler, 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->DestroySampler(device, sampler, 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 vkDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout, 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->DestroyDescriptorSetLayout(device, descriptorSetLayout, 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 vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002954{
Chia-I Wu69f40122015-10-26 21:10:41 +08002955 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 -06002956 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002957}
2958
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002959VK_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 -06002960{
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002961 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
2962
Courtney Goeltzenleuchter740451a2015-12-16 16:06:06 -07002963 for (uint32_t i = 0; i < count; i++) {
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002964 // Delete CB information structure, and remove from commandBufferMap
2965 auto cb = dev_data->commandBufferMap.find(pCommandBuffers[i]);
Mark Lobodzinski13b66742015-11-20 14:33:48 -07002966 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002967 if (cb != dev_data->commandBufferMap.end()) {
2968 delete (*cb).second;
2969 dev_data->commandBufferMap.erase(cb);
2970 }
2971
2972 // Remove commandBuffer reference from commandPoolMap
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07002973 dev_data->commandPoolMap[commandPool].commandBuffers.remove(pCommandBuffers[i]);
Mark Lobodzinski13b66742015-11-20 14:33:48 -07002974 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002975 }
2976
2977 dev_data->device_dispatch_table->FreeCommandBuffers(device, commandPool, count, pCommandBuffers);
2978}
2979
2980VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkCommandPool* pCommandPool)
2981{
2982 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
2983
2984 VkResult result = dev_data->device_dispatch_table->CreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
2985
2986 if (VK_SUCCESS == result) {
Mark Lobodzinski13b66742015-11-20 14:33:48 -07002987 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07002988 dev_data->commandPoolMap[*pCommandPool].createFlags = pCreateInfo->flags;
Mark Lobodzinski13b66742015-11-20 14:33:48 -07002989 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002990 }
2991 return result;
2992}
2993
2994VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks* pAllocator)
2995{
2996 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski13b66742015-11-20 14:33:48 -07002997 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002998
2999 // Must remove cmdpool from cmdpoolmap, after removing all cmdbuffers in its list from the commandPoolMap
3000 if (dev_data->commandPoolMap.find(commandPool) != dev_data->commandPoolMap.end()) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003001 for (auto poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.begin(); poolCb != dev_data->commandPoolMap[commandPool].commandBuffers.end();) {
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003002 auto del_cb = dev_data->commandBufferMap.find(*poolCb);
3003 delete (*del_cb).second; // delete CB info structure
3004 dev_data->commandBufferMap.erase(del_cb); // Remove this command buffer from cbMap
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003005 poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.erase(poolCb); // Remove CB reference from commandPoolMap's list
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003006 }
3007 }
3008 dev_data->commandPoolMap.erase(commandPool);
Mark Lobodzinski13b66742015-11-20 14:33:48 -07003009
3010 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003011 dev_data->device_dispatch_table->DestroyCommandPool(device, commandPool, pAllocator);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003012}
3013
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003014VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandPool(
3015 VkDevice device,
3016 VkCommandPool commandPool,
3017 VkCommandPoolResetFlags flags)
3018{
3019 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003020 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003021
3022 result = dev_data->device_dispatch_table->ResetCommandPool(device, commandPool, flags);
3023 // Reset all of the CBs allocated from this pool
3024 if (VK_SUCCESS == result) {
3025 auto it = dev_data->commandPoolMap[commandPool].commandBuffers.begin();
3026 while (it != dev_data->commandPoolMap[commandPool].commandBuffers.end()) {
3027 resetCB(dev_data, (*it));
3028 ++it;
3029 }
3030 }
3031 return result;
3032}
3033
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003034VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer, 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->DestroyFramebuffer(device, framebuffer, pAllocator);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003037 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003038}
3039
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003040VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003041{
Chia-I Wu69f40122015-10-26 21:10:41 +08003042 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 -06003043 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003044}
3045
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003046VK_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 -06003047{
3048 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003049 VkResult result = dev_data->device_dispatch_table->CreateBuffer(device, pCreateInfo, pAllocator, pBuffer);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003050 if (VK_SUCCESS == result) {
3051 loader_platform_thread_lock_mutex(&globalLock);
3052 // 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 +08003053 dev_data->bufferMap[*pBuffer] = unique_ptr<VkBufferCreateInfo>(new VkBufferCreateInfo(*pCreateInfo));
Tobin Ehlisb46be812015-10-23 16:00:08 -06003054 loader_platform_thread_unlock_mutex(&globalLock);
3055 }
3056 return result;
3057}
3058
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003059VK_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 -06003060{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003061 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003062 VkResult result = dev_data->device_dispatch_table->CreateBufferView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003063 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003064 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue420a332015-10-26 20:04:44 +08003065 dev_data->bufferViewMap[*pView] = unique_ptr<VkBufferViewCreateInfo>(new VkBufferViewCreateInfo(*pCreateInfo));
Tobin Ehlisb46be812015-10-23 16:00:08 -06003066 loader_platform_thread_unlock_mutex(&globalLock);
3067 }
3068 return result;
3069}
3070
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003071VK_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 -06003072{
3073 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003074 VkResult result = dev_data->device_dispatch_table->CreateImage(device, pCreateInfo, pAllocator, pImage);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003075 if (VK_SUCCESS == result) {
Michael Lentine27b0f902015-10-12 11:30:14 -05003076 IMAGE_NODE* image_node = new IMAGE_NODE;
3077 image_node->layout = pCreateInfo->initialLayout;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003078 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue420a332015-10-26 20:04:44 +08003079 dev_data->imageMap[*pImage] = unique_ptr<VkImageCreateInfo>(new VkImageCreateInfo(*pCreateInfo));
Michael Lentine27b0f902015-10-12 11:30:14 -05003080 dev_data->imageLayoutMap[*pImage] = image_node;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003081 loader_platform_thread_unlock_mutex(&globalLock);
3082 }
3083 return result;
3084}
3085
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003086VK_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 -06003087{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003088 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003089 VkResult result = dev_data->device_dispatch_table->CreateImageView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003090 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003091 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue420a332015-10-26 20:04:44 +08003092 dev_data->imageViewMap[*pView] = unique_ptr<VkImageViewCreateInfo>(new VkImageViewCreateInfo(*pCreateInfo));
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003093 loader_platform_thread_unlock_mutex(&globalLock);
3094 }
3095 return result;
3096}
3097
Jon Ashburn0d60d272015-07-09 15:02:25 -06003098//TODO handle pipeline caches
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003099VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineCache(
Jon Ashburn0d60d272015-07-09 15:02:25 -06003100 VkDevice device,
3101 const VkPipelineCacheCreateInfo* pCreateInfo,
Chia-I Wu1f851912015-10-27 18:04:07 +08003102 const VkAllocationCallbacks* pAllocator,
Jon Ashburn0d60d272015-07-09 15:02:25 -06003103 VkPipelineCache* pPipelineCache)
3104{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003105 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003106 VkResult result = dev_data->device_dispatch_table->CreatePipelineCache(device, pCreateInfo, pAllocator, pPipelineCache);
Jon Ashburn0d60d272015-07-09 15:02:25 -06003107 return result;
3108}
3109
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003110VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineCache(
Jon Ashburn0d60d272015-07-09 15:02:25 -06003111 VkDevice device,
Chia-I Wu69f40122015-10-26 21:10:41 +08003112 VkPipelineCache pipelineCache,
Chia-I Wu1f851912015-10-27 18:04:07 +08003113 const VkAllocationCallbacks* pAllocator)
Jon Ashburn0d60d272015-07-09 15:02:25 -06003114{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003115 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003116 dev_data->device_dispatch_table->DestroyPipelineCache(device, pipelineCache, pAllocator);
Jon Ashburn0d60d272015-07-09 15:02:25 -06003117}
3118
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003119VKAPI_ATTR VkResult VKAPI_CALL vkGetPipelineCacheData(
Jon Ashburn0d60d272015-07-09 15:02:25 -06003120 VkDevice device,
3121 VkPipelineCache pipelineCache,
Chia-I Wu28c3c432015-10-26 19:17:06 +08003122 size_t* pDataSize,
Jon Ashburn0d60d272015-07-09 15:02:25 -06003123 void* pData)
3124{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003125 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu28c3c432015-10-26 19:17:06 +08003126 VkResult result = dev_data->device_dispatch_table->GetPipelineCacheData(device, pipelineCache, pDataSize, pData);
Jon Ashburn0d60d272015-07-09 15:02:25 -06003127 return result;
3128}
3129
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003130VKAPI_ATTR VkResult VKAPI_CALL vkMergePipelineCaches(
Jon Ashburn0d60d272015-07-09 15:02:25 -06003131 VkDevice device,
Chia-I Wu1f851912015-10-27 18:04:07 +08003132 VkPipelineCache dstCache,
Jon Ashburn0d60d272015-07-09 15:02:25 -06003133 uint32_t srcCacheCount,
3134 const VkPipelineCache* pSrcCaches)
3135{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003136 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu1f851912015-10-27 18:04:07 +08003137 VkResult result = dev_data->device_dispatch_table->MergePipelineCaches(device, dstCache, srcCacheCount, pSrcCaches);
Jon Ashburn0d60d272015-07-09 15:02:25 -06003138 return result;
3139}
3140
Mark Lobodzinski2adea752015-11-10 15:25:01 -07003141VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateGraphicsPipelines(
3142 VkDevice device,
3143 VkPipelineCache pipelineCache,
3144 uint32_t count,
3145 const VkGraphicsPipelineCreateInfo *pCreateInfos,
3146 const VkAllocationCallbacks *pAllocator,
3147 VkPipeline *pPipelines)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003148{
Courtney Goeltzenleuchtera54b76a2015-09-04 13:39:59 -06003149 VkResult result = VK_SUCCESS;
Tobin Ehlise48be202015-09-16 10:33:53 -06003150 //TODO What to do with pipelineCache?
Tobin Ehlisde63c532015-06-18 15:59:33 -06003151 // The order of operations here is a little convoluted but gets the job done
3152 // 1. Pipeline create state is first shadowed into PIPELINE_NODE struct
3153 // 2. Create state is then validated (which uses flags setup during shadowing)
3154 // 3. If everything looks good, we'll then create the pipeline and add NODE to pipelineMap
Tobin Ehlise48be202015-09-16 10:33:53 -06003155 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis76c18852015-09-17 16:33:58 -06003156 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
3157 vector<PIPELINE_NODE*> pPipeNode(count);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003158 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski2adea752015-11-10 15:25:01 -07003159
Tobin Ehlise48be202015-09-16 10:33:53 -06003160 uint32_t i=0;
Tobin Ehlisde63c532015-06-18 15:59:33 -06003161 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski2adea752015-11-10 15:25:01 -07003162
Tobin Ehlise48be202015-09-16 10:33:53 -06003163 for (i=0; i<count; i++) {
Mark Lobodzinski2adea752015-11-10 15:25:01 -07003164 pPipeNode[i] = initGraphicsPipeline(dev_data, &pCreateInfos[i], NULL);
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003165 skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
Tobin Ehlise48be202015-09-16 10:33:53 -06003166 }
Mark Lobodzinski2adea752015-11-10 15:25:01 -07003167
Tobin Ehlisde63c532015-06-18 15:59:33 -06003168 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis32479352015-12-01 09:48:58 -07003169
Tobin Ehlisad61de42015-12-02 13:53:34 -07003170 if (VK_FALSE == skipCall) {
Mark Lobodzinski2adea752015-11-10 15:25:01 -07003171 result = dev_data->device_dispatch_table->CreateGraphicsPipelines(device,
3172 pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
Tobin Ehlisde63c532015-06-18 15:59:33 -06003173 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlise48be202015-09-16 10:33:53 -06003174 for (i=0; i<count; i++) {
3175 pPipeNode[i]->pipeline = pPipelines[i];
Chia-I Wue420a332015-10-26 20:04:44 +08003176 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
Tobin Ehlise48be202015-09-16 10:33:53 -06003177 }
Tobin Ehlisde63c532015-06-18 15:59:33 -06003178 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003179 } else {
Tobin Ehlise48be202015-09-16 10:33:53 -06003180 for (i=0; i<count; i++) {
3181 if (pPipeNode[i]) {
3182 // If we allocated a pipeNode, need to clean it up here
3183 delete[] pPipeNode[i]->pVertexBindingDescriptions;
3184 delete[] pPipeNode[i]->pVertexAttributeDescriptions;
3185 delete[] pPipeNode[i]->pAttachments;
3186 delete pPipeNode[i];
3187 }
Tobin Ehlisde63c532015-06-18 15:59:33 -06003188 }
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003189 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisde63c532015-06-18 15:59:33 -06003190 }
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06003191 return result;
3192}
3193
Mark Lobodzinski2adea752015-11-10 15:25:01 -07003194VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateComputePipelines(
3195 VkDevice device,
3196 VkPipelineCache pipelineCache,
3197 uint32_t count,
3198 const VkComputePipelineCreateInfo *pCreateInfos,
3199 const VkAllocationCallbacks *pAllocator,
3200 VkPipeline *pPipelines)
3201{
3202 VkResult result = VK_SUCCESS;
3203 VkBool32 skipCall = VK_FALSE;
3204
3205 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
3206 vector<PIPELINE_NODE*> pPipeNode(count);
3207 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3208
3209 uint32_t i=0;
3210 loader_platform_thread_lock_mutex(&globalLock);
3211 for (i=0; i<count; i++) {
3212 // TODO: Verify compute stage bits
3213
3214 // Create and initialize internal tracking data structure
3215 pPipeNode[i] = new PIPELINE_NODE;
3216 memset((void*)pPipeNode[i], 0, sizeof(PIPELINE_NODE));
3217 memcpy(&pPipeNode[i]->computePipelineCI, (const void*)&pCreateInfos[i], sizeof(VkComputePipelineCreateInfo));
3218
3219 // TODO: Add Compute Pipeline Verification
3220 // skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
3221 }
3222 loader_platform_thread_unlock_mutex(&globalLock);
3223
3224 if (VK_FALSE == skipCall) {
3225 result = dev_data->device_dispatch_table->CreateComputePipelines(device, pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
3226 loader_platform_thread_lock_mutex(&globalLock);
3227 for (i=0; i<count; i++) {
3228 pPipeNode[i]->pipeline = pPipelines[i];
3229 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
3230 }
3231 loader_platform_thread_unlock_mutex(&globalLock);
3232 } else {
3233 for (i=0; i<count; i++) {
3234 if (pPipeNode[i]) {
3235 // Clean up any locally allocated data structures
3236 delete pPipeNode[i];
3237 }
3238 }
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003239 return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinski2adea752015-11-10 15:25:01 -07003240 }
3241 return result;
3242}
3243
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003244VK_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 -06003245{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003246 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003247 VkResult result = dev_data->device_dispatch_table->CreateSampler(device, pCreateInfo, pAllocator, pSampler);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003248 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003249 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue420a332015-10-26 20:04:44 +08003250 dev_data->sampleMap[*pSampler] = unique_ptr<SAMPLER_NODE>(new SAMPLER_NODE(pSampler, pCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003251 loader_platform_thread_unlock_mutex(&globalLock);
3252 }
3253 return result;
3254}
3255
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003256VK_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 -06003257{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003258 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003259 VkResult result = dev_data->device_dispatch_table->CreateDescriptorSetLayout(device, pCreateInfo, pAllocator, pSetLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003260 if (VK_SUCCESS == result) {
Tobin Ehliscb085292015-12-01 09:57:09 -07003261 // TODOSC : Capture layout bindings set
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003262 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
3263 if (NULL == pNewNode) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003264 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 -06003265 "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()"))
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003266 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003267 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003268 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003269 pNewNode->createInfo.pBinding = new VkDescriptorSetLayoutBinding[pCreateInfo->bindingCount];
3270 memcpy((void*)pNewNode->createInfo.pBinding, pCreateInfo->pBinding, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->bindingCount);
Chia-I Wub5689ee2015-10-31 00:31:16 +08003271 // g++ does not like reserve with size 0
3272 if (pCreateInfo->bindingCount)
3273 pNewNode->bindings.reserve(pCreateInfo->bindingCount);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003274 uint32_t totalCount = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08003275 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
Chia-I Wub5689ee2015-10-31 00:31:16 +08003276 if (!pNewNode->bindings.insert(pCreateInfo->pBinding[i].binding).second) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003277 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 +08003278 "duplicated binding number in VkDescriptorSetLayoutBinding"))
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003279 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wub5689ee2015-10-31 00:31:16 +08003280 }
3281
Chia-I Wu045654f2015-11-06 06:42:02 +08003282 totalCount += pCreateInfo->pBinding[i].descriptorCount;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003283 if (pCreateInfo->pBinding[i].pImmutableSamplers) {
3284 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBinding[i].pImmutableSamplers;
Chia-I Wu045654f2015-11-06 06:42:02 +08003285 *ppIS = new VkSampler[pCreateInfo->pBinding[i].descriptorCount];
3286 memcpy(*ppIS, pCreateInfo->pBinding[i].pImmutableSamplers, pCreateInfo->pBinding[i].descriptorCount*sizeof(VkSampler));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003287 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003288 }
3289 if (totalCount > 0) {
Cody Northrop8a908322015-10-26 14:07:35 -06003290 pNewNode->descriptorTypes.resize(totalCount);
Tobin Ehlis68fbd442015-10-27 12:25:35 -06003291 pNewNode->stageFlags.resize(totalCount);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003292 uint32_t offset = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003293 uint32_t j = 0;
Tobin Ehlis61ebb312015-11-04 12:28:28 -07003294 VkDescriptorType dType;
Chia-I Wu763a7492015-10-26 20:48:51 +08003295 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
Tobin Ehlis61ebb312015-11-04 12:28:28 -07003296 dType = pCreateInfo->pBinding[i].descriptorType;
Chia-I Wu045654f2015-11-06 06:42:02 +08003297 for (j = 0; j < pCreateInfo->pBinding[i].descriptorCount; j++) {
Tobin Ehlis61ebb312015-11-04 12:28:28 -07003298 pNewNode->descriptorTypes[offset + j] = dType;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003299 pNewNode->stageFlags[offset + j] = pCreateInfo->pBinding[i].stageFlags;
Tobin Ehlis61ebb312015-11-04 12:28:28 -07003300 if ((dType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
3301 (dType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
3302 pNewNode->dynamicDescriptorCount++;
3303 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003304 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003305 offset += j;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003306 }
3307 }
3308 pNewNode->layout = *pSetLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003309 pNewNode->startIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003310 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
3311 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003312 // Put new node at Head of global Layer list
3313 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisad61de42015-12-02 13:53:34 -07003314 dev_data->descriptorSetLayoutMap[*pSetLayout] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003315 loader_platform_thread_unlock_mutex(&globalLock);
3316 }
3317 return result;
3318}
3319
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003320VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003321{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003322 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003323 VkResult result = dev_data->device_dispatch_table->CreatePipelineLayout(device, pCreateInfo, pAllocator, pPipelineLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003324 if (VK_SUCCESS == result) {
Tobin Ehliscb085292015-12-01 09:57:09 -07003325 // TODOSC : Merge capture of the setLayouts per pipeline
Tobin Ehlis982099b2015-11-05 09:52:49 -07003326 PIPELINE_LAYOUT_NODE& plNode = dev_data->pipelineLayoutMap[*pPipelineLayout];
Chia-I Wu763a7492015-10-26 20:48:51 +08003327 plNode.descriptorSetLayouts.resize(pCreateInfo->setLayoutCount);
Tobin Ehlis91423d22015-10-20 10:11:55 -06003328 uint32_t i = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08003329 for (i=0; i<pCreateInfo->setLayoutCount; ++i) {
Tobin Ehlis91423d22015-10-20 10:11:55 -06003330 plNode.descriptorSetLayouts[i] = pCreateInfo->pSetLayouts[i];
3331 }
Cody Northrop8a908322015-10-26 14:07:35 -06003332 plNode.pushConstantRanges.resize(pCreateInfo->pushConstantRangeCount);
Tobin Ehlis91423d22015-10-20 10:11:55 -06003333 for (i=0; i<pCreateInfo->pushConstantRangeCount; ++i) {
3334 plNode.pushConstantRanges[i] = pCreateInfo->pPushConstantRanges[i];
3335 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003336 }
3337 return result;
3338}
3339
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003340VK_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 -06003341{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003342 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003343 VkResult result = dev_data->device_dispatch_table->CreateDescriptorPool(device, pCreateInfo, pAllocator, pDescriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003344 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003345 // Insert this pool into Global Pool LL at head
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003346 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 +08003347 "Created Descriptor Pool %#" PRIxLEAST64, (uint64_t) *pDescriptorPool))
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003348 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003349 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003350 DESCRIPTOR_POOL_NODE* pNewNode = new DESCRIPTOR_POOL_NODE(*pDescriptorPool, pCreateInfo);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003351 if (NULL == pNewNode) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003352 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 -07003353 "Out of memory while attempting to allocate DESCRIPTOR_POOL_NODE in vkCreateDescriptorPool()"))
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003354 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003355 } else {
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003356 dev_data->descriptorPoolMap[*pDescriptorPool] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003357 }
3358 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003359 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003360 // Need to do anything if pool create fails?
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003361 }
3362 return result;
3363}
3364
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003365VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorPoolResetFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003366{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003367 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003368 VkResult result = dev_data->device_dispatch_table->ResetDescriptorPool(device, descriptorPool, flags);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003369 if (VK_SUCCESS == result) {
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003370 clearDescriptorPool(dev_data, device, descriptorPool, flags);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003371 }
3372 return result;
3373}
3374
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003375VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo* pAllocateInfo, VkDescriptorSet* pDescriptorSets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003376{
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003377 VkBool32 skipCall = VK_FALSE;
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003378 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003379 // Verify that requested descriptorSets are available in pool
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003380 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003381 if (!pPoolNode) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003382 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 +08003383 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pAllocateInfo->descriptorPool);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003384 } else { // Make sure pool has all the available descriptors before calling down chain
Chia-I Wu1f851912015-10-27 18:04:07 +08003385 skipCall |= validate_descriptor_availability_in_pool(dev_data, pPoolNode, pAllocateInfo->setLayoutCount, pAllocateInfo->pSetLayouts);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003386 }
3387 if (skipCall)
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003388 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wu1f851912015-10-27 18:04:07 +08003389 VkResult result = dev_data->device_dispatch_table->AllocateDescriptorSets(device, pAllocateInfo, pDescriptorSets);
Cody Northropc8aa4a52015-08-03 12:47:29 -06003390 if (VK_SUCCESS == result) {
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003391 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003392 if (pPoolNode) {
Chia-I Wu1f851912015-10-27 18:04:07 +08003393 if (pAllocateInfo->setLayoutCount == 0) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003394 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 +08003395 "AllocateDescriptorSets called with 0 count");
Cody Northropc8aa4a52015-08-03 12:47:29 -06003396 }
Chia-I Wu1f851912015-10-27 18:04:07 +08003397 for (uint32_t i = 0; i < pAllocateInfo->setLayoutCount; i++) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003398 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 +08003399 "Created Descriptor Set %#" PRIxLEAST64, (uint64_t) pDescriptorSets[i]);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003400 // Create new set node and add to head of pool nodes
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003401 SET_NODE* pNewNode = new SET_NODE;
3402 if (NULL == pNewNode) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003403 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 +08003404 "Out of memory while attempting to allocate SET_NODE in vkAllocateDescriptorSets()"))
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003405 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003406 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003407 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlisf6e93e02015-10-19 12:09:13 -06003408 // TODO : Pool should store a total count of each type of Descriptor available
3409 // When descriptors are allocated, decrement the count and validate here
3410 // that the count doesn't go below 0. One reset/free need to bump count back up.
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003411 // Insert set at head of Set LL for this pool
3412 pNewNode->pNext = pPoolNode->pSets;
3413 pPoolNode->pSets = pNewNode;
Chia-I Wu1f851912015-10-27 18:04:07 +08003414 LAYOUT_NODE* pLayout = getLayoutNode(dev_data, pAllocateInfo->pSetLayouts[i]);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003415 if (NULL == pLayout) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003416 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 +08003417 "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 -07003418 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003419 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003420 pNewNode->pLayout = pLayout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003421 pNewNode->pool = pAllocateInfo->descriptorPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003422 pNewNode->set = pDescriptorSets[i];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003423 pNewNode->descriptorCount = pLayout->endIndex + 1;
3424 if (pNewNode->descriptorCount) {
3425 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
3426 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
3427 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
3428 }
Chia-I Wue420a332015-10-26 20:04:44 +08003429 dev_data->setMap[pDescriptorSets[i]] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003430 }
3431 }
3432 }
3433 }
3434 return result;
3435}
3436
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003437VK_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 -06003438{
Tobin Ehlis3c543112015-10-08 13:13:50 -06003439 VkBool32 skipCall = VK_FALSE;
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003440 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003441 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, descriptorPool);
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003442 if (pPoolNode && !(VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT & pPoolNode->createInfo.flags)) {
3443 // Can't Free from a NON_FREE pool
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003444 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 -06003445 "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 -06003446 }
3447 if (skipCall)
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003448 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003449 VkResult result = dev_data->device_dispatch_table->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003450 if (VK_SUCCESS == result) {
3451 // For each freed descriptor add it back into the pool as available
3452 for (uint32_t i=0; i<count; ++i) {
Chia-I Wue420a332015-10-26 20:04:44 +08003453 SET_NODE* pSet = dev_data->setMap[pDescriptorSets[i]]; // getSetNode() without locking
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003454 LAYOUT_NODE* pLayout = pSet->pLayout;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003455 uint32_t typeIndex = 0, poolSizeCount = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08003456 for (uint32_t j=0; j<pLayout->createInfo.bindingCount; ++j) {
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003457 typeIndex = static_cast<uint32_t>(pLayout->createInfo.pBinding[j].descriptorType);
Chia-I Wu045654f2015-11-06 06:42:02 +08003458 poolSizeCount = pLayout->createInfo.pBinding[j].descriptorCount;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003459 pPoolNode->availableDescriptorTypeCount[typeIndex] += poolSizeCount;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003460 }
3461 }
3462 }
3463 // TODO : Any other clean-up or book-keeping to do here?
Tony Barbourb857d312015-07-10 10:50:45 -06003464 return result;
3465}
3466
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003467VK_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 -06003468{
Tobin Ehlis68fbd442015-10-27 12:25:35 -06003469 // 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 -06003470 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu483e7702015-10-26 17:20:32 +08003471 if (!dsUpdate(dev_data, device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies)) {
3472 dev_data->device_dispatch_table->UpdateDescriptorSets(device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies);
Jon Ashburne0fa2282015-05-20 09:00:28 -06003473 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003474}
3475
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003476VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo* pCreateInfo, VkCommandBuffer* pCommandBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003477{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003478 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu1f851912015-10-27 18:04:07 +08003479 VkResult result = dev_data->device_dispatch_table->AllocateCommandBuffers(device, pCreateInfo, pCommandBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003480 if (VK_SUCCESS == result) {
Courtney Goeltzenleuchter740451a2015-12-16 16:06:06 -07003481 for (uint32_t i = 0; i < pCreateInfo->bufferCount; i++) {
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003482 // Validate command pool
3483 if (dev_data->commandPoolMap.find(pCreateInfo->commandPool) != dev_data->commandPoolMap.end()) {
Mark Lobodzinski13b66742015-11-20 14:33:48 -07003484 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003485 // Add command buffer to its commandPool map
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003486 dev_data->commandPoolMap[pCreateInfo->commandPool].commandBuffers.push_back(pCommandBuffer[i]);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003487 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
3488 // Add command buffer to map
3489 dev_data->commandBufferMap[pCommandBuffer[i]] = pCB;
Mark Lobodzinski13b66742015-11-20 14:33:48 -07003490 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003491 resetCB(dev_data, pCommandBuffer[i]);
3492 pCB->commandBuffer = pCommandBuffer[i];
3493 pCB->createInfo = *pCreateInfo;
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003494 }
3495 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003496 }
3497 return result;
3498}
3499
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003500VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo* pBeginInfo)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003501{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003502 VkBool32 skipCall = false;
Chia-I Wu1f851912015-10-27 18:04:07 +08003503 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06003504 // Validate command buffer level
Chia-I Wu1f851912015-10-27 18:04:07 +08003505 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06003506 if (pCB) {
Mark Lobodzinskia1420862015-11-19 13:22:11 -07003507 if (pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
Chia-I Wue420a332015-10-26 20:04:44 +08003508 if (pBeginInfo->renderPass || pBeginInfo->framebuffer) {
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06003509 // These should be NULL for a Primary 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 Ehlisc5191da2015-12-16 07:17:23 -07003511 "vkBeginCommandBuffer(): Primary Command Buffer (%p) may not specify framebuffer or renderpass parameters.", (void*)commandBuffer);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06003512 }
Tobin Ehlisc5191da2015-12-16 07:17:23 -07003513 } else { // Secondary Command Buffer
3514 if (!pBeginInfo->renderPass) { // renderpass should NOT be null for an Secondary CB
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003515 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, 0, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
Tobin Ehlisc5191da2015-12-16 07:17:23 -07003516 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) must specify a valid renderpass parameter.", (void*)commandBuffer);
3517 }
3518 if (!pBeginInfo->framebuffer) { // framebuffer may be null for an Secondary CB, but this affects perf
3519 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, 0, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
3520 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) may perform better if a valid framebuffer parameter is specified.", (void*)commandBuffer);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06003521 }
3522 }
Tobin Ehlis0cea4082015-08-18 07:10:58 -06003523 pCB->beginInfo = *pBeginInfo;
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003524 if (CB_RECORDING == pCB->state) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003525 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 -07003526 "vkBeginCommandBuffer(): Cannot call Begin on CB (%#" PRIxLEAST64 ") in the RECORDING state. Must first call vkEndCommandBuffer().", (uint64_t)commandBuffer);
3527 } else if (CB_RECORDED == pCB->state) {
3528 VkCommandPool cmdPool = pCB->createInfo.commandPool;
3529 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003530 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 -07003531 0, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
3532 "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.",
3533 (uint64_t) commandBuffer, (uint64_t) cmdPool);
3534 }
3535 }
Tobin Ehlis0cea4082015-08-18 07:10:58 -06003536 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003537 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 +08003538 "In vkBeginCommandBuffer() and unable to find CommandBuffer Node for CB %p!", (void*)commandBuffer);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06003539 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003540 if (skipCall) {
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003541 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter3abd86e2015-09-04 15:03:52 -06003542 }
Chia-I Wu1f851912015-10-27 18:04:07 +08003543 VkResult result = dev_data->device_dispatch_table->BeginCommandBuffer(commandBuffer, pBeginInfo);
Mark Lobodzinski2ad35592015-11-12 16:14:04 -07003544 if ((VK_SUCCESS == result) && (pCB != NULL)) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003545 if (CB_RECORDED == pCB->state) {
Chia-I Wu1f851912015-10-27 18:04:07 +08003546 resetCB(dev_data, commandBuffer);
Mark Lobodzinski2ad35592015-11-12 16:14:04 -07003547 }
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003548 pCB->state = CB_RECORDING;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003549 }
3550 return result;
3551}
3552
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003553VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEndCommandBuffer(VkCommandBuffer commandBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003554{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003555 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchtera54b76a2015-09-04 13:39:59 -06003556 VkResult result = VK_SUCCESS;
Chia-I Wu1f851912015-10-27 18:04:07 +08003557 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3558 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlise42007c2015-06-19 13:00:59 -06003559 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003560 if (pCB->state != CB_RECORDING) {
Chia-I Wu1f851912015-10-27 18:04:07 +08003561 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkEndCommandBuffer()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003562 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003563 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003564 if (VK_FALSE == skipCall) {
Chia-I Wu1f851912015-10-27 18:04:07 +08003565 result = dev_data->device_dispatch_table->EndCommandBuffer(commandBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003566 if (VK_SUCCESS == result) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003567 pCB->state = CB_RECORDED;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003568 // Reset CB status flags
3569 pCB->status = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08003570 printCB(dev_data, commandBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003571 }
3572 } else {
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003573 result = VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003574 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003575 return result;
3576}
3577
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003578VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003579{
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003580 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003581 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003582 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
3583 VkCommandPool cmdPool = pCB->createInfo.commandPool;
3584 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003585 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 -07003586 0, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
3587 "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.",
3588 (uint64_t) commandBuffer, (uint64_t) cmdPool);
3589 }
3590 if (skipCall)
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07003591 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wu1f851912015-10-27 18:04:07 +08003592 VkResult result = dev_data->device_dispatch_table->ResetCommandBuffer(commandBuffer, flags);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003593 if (VK_SUCCESS == result) {
Chia-I Wu1f851912015-10-27 18:04:07 +08003594 resetCB(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003595 }
3596 return result;
3597}
3598
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003599VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003600{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003601 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003602 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3603 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003604 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003605 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003606 skipCall |= addCmd(dev_data, pCB, CMD_BINDPIPELINE);
Mark Lobodzinski611cf592015-12-18 15:35:38 -07003607 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
3608 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdBindPipeline");
3609 // TODO: Verify whether compute pipelines must be outside a render pass
3610 } else if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
3611 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
3612 (uint64_t)pipeline, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS", "Incorrectly binding compute pipeline "
3613 " (%#" PRIxLEAST64 ") inside an active RenderPass", (uint64_t) pipeline);
3614 }
Mark Lobodzinski7bc3a9e2015-12-17 09:24:14 -07003615 PIPELINE_NODE* pPN = getPipeline(dev_data, pipeline);
3616 if (pPN) {
3617 pCB->lastBoundPipeline = pipeline;
3618 loader_platform_thread_lock_mutex(&globalLock);
3619 set_cb_pso_status(pCB, pPN);
3620 g_lastBoundPipeline = pPN;
3621 loader_platform_thread_unlock_mutex(&globalLock);
3622 skipCall |= validatePipelineState(dev_data, pCB, pipelineBindPoint, pipeline);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003623 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003624 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 -07003625 0, DRAWSTATE_INVALID_PIPELINE, "DS",
3626 "Attempt to bind Pipeline %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<uint64_t>(pipeline));
Tobin Ehlise42007c2015-06-19 13:00:59 -06003627 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003628 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003629 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindPipeline()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003630 }
3631 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003632 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003633 dev_data->device_dispatch_table->CmdBindPipeline(commandBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003634}
3635
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003636VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetViewport(
Chia-I Wu1f851912015-10-27 18:04:07 +08003637 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06003638 uint32_t viewportCount,
3639 const VkViewport* pViewports)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003640{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003641 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003642 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3643 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlise42007c2015-06-19 13:00:59 -06003644 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003645 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003646 skipCall |= addCmd(dev_data, pCB, CMD_SETVIEWPORTSTATE);
Tobin Ehlise42007c2015-06-19 13:00:59 -06003647 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003648 pCB->status |= CBSTATUS_VIEWPORT_SET;
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06003649 pCB->viewports.resize(viewportCount);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003650 memcpy(pCB->viewports.data(), pViewports, viewportCount * sizeof(VkViewport));
Tobin Ehlise42007c2015-06-19 13:00:59 -06003651 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlise42007c2015-06-19 13:00:59 -06003652 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003653 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdSetViewport()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06003654 }
3655 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003656 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003657 dev_data->device_dispatch_table->CmdSetViewport(commandBuffer, viewportCount, pViewports);
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06003658}
3659
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003660VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetScissor(
Chia-I Wu1f851912015-10-27 18:04:07 +08003661 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06003662 uint32_t scissorCount,
3663 const VkRect2D* pScissors)
3664{
3665 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003666 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3667 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06003668 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003669 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003670 skipCall |= addCmd(dev_data, pCB, CMD_SETSCISSORSTATE);
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06003671 loader_platform_thread_lock_mutex(&globalLock);
3672 pCB->status |= CBSTATUS_SCISSOR_SET;
3673 pCB->scissors.resize(scissorCount);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003674 memcpy(pCB->scissors.data(), pScissors, scissorCount * sizeof(VkRect2D));
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06003675 loader_platform_thread_unlock_mutex(&globalLock);
3676 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003677 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdSetScissor()");
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06003678 }
3679 }
3680 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003681 dev_data->device_dispatch_table->CmdSetScissor(commandBuffer, scissorCount, pScissors);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003682}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003683
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003684VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003685{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003686 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003687 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3688 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003689 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003690 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003691 skipCall |= addCmd(dev_data, pCB, CMD_SETLINEWIDTHSTATE);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003692 /* TODO: Do we still need this lock? */
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003693 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003694 pCB->status |= CBSTATUS_LINE_WIDTH_SET;
3695 pCB->lineWidth = lineWidth;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003696 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003697 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003698 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindDynamicLineWidthState()");
Cody Northropf5bd2252015-08-17 11:10:49 -06003699 }
3700 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003701 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003702 dev_data->device_dispatch_table->CmdSetLineWidth(commandBuffer, lineWidth);
Cody Northropf5bd2252015-08-17 11:10:49 -06003703}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003704
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003705VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBias(
Chia-I Wu1f851912015-10-27 18:04:07 +08003706 VkCommandBuffer commandBuffer,
Chia-I Wufa950c52015-10-26 19:08:09 +08003707 float depthBiasConstantFactor,
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003708 float depthBiasClamp,
Chia-I Wufa950c52015-10-26 19:08:09 +08003709 float depthBiasSlopeFactor)
Cody Northropf5bd2252015-08-17 11:10:49 -06003710{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003711 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003712 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3713 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northropf5bd2252015-08-17 11:10:49 -06003714 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003715 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003716 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBIASSTATE);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003717 pCB->status |= CBSTATUS_DEPTH_BIAS_SET;
Chia-I Wufa950c52015-10-26 19:08:09 +08003718 pCB->depthBiasConstantFactor = depthBiasConstantFactor;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003719 pCB->depthBiasClamp = depthBiasClamp;
Chia-I Wufa950c52015-10-26 19:08:09 +08003720 pCB->depthBiasSlopeFactor = depthBiasSlopeFactor;
Cody Northropf5bd2252015-08-17 11:10:49 -06003721 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003722 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdSetDepthBias()");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003723 }
3724 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003725 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003726 dev_data->device_dispatch_table->CmdSetDepthBias(commandBuffer, depthBiasConstantFactor, depthBiasClamp, depthBiasSlopeFactor);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003727}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003728
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003729VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4])
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003730{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003731 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003732 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3733 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003734 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003735 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003736 skipCall |= addCmd(dev_data, pCB, CMD_SETBLENDSTATE);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003737 pCB->status |= CBSTATUS_BLEND_SET;
Chia-I Wu7e470702015-10-26 17:24:52 +08003738 memcpy(pCB->blendConstants, blendConstants, 4 * sizeof(float));
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003739 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003740 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdSetBlendConstants()");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003741 }
3742 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003743 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003744 dev_data->device_dispatch_table->CmdSetBlendConstants(commandBuffer, blendConstants);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003745}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003746
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003747VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBounds(
Chia-I Wu1f851912015-10-27 18:04:07 +08003748 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003749 float minDepthBounds,
3750 float maxDepthBounds)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003751{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003752 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003753 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3754 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003755 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003756 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003757 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBOUNDSSTATE);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003758 pCB->status |= CBSTATUS_DEPTH_BOUNDS_SET;
3759 pCB->minDepthBounds = minDepthBounds;
3760 pCB->maxDepthBounds = maxDepthBounds;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003761 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003762 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdSetDepthBounds()");
Cody Northrop2605cb02015-08-18 15:21:16 -06003763 }
3764 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003765 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003766 dev_data->device_dispatch_table->CmdSetDepthBounds(commandBuffer, minDepthBounds, maxDepthBounds);
Cody Northrop2605cb02015-08-18 15:21:16 -06003767}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003768
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003769VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilCompareMask(
Chia-I Wu1f851912015-10-27 18:04:07 +08003770 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003771 VkStencilFaceFlags faceMask,
Chia-I Wuc51b1212015-10-27 19:25:11 +08003772 uint32_t compareMask)
Cody Northrop2605cb02015-08-18 15:21:16 -06003773{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003774 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003775 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3776 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northrop2605cb02015-08-18 15:21:16 -06003777 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003778 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003779 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREADMASKSTATE);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003780 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
Chia-I Wuc51b1212015-10-27 19:25:11 +08003781 pCB->front.compareMask = compareMask;
Cody Northrop2605cb02015-08-18 15:21:16 -06003782 }
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003783 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
Chia-I Wuc51b1212015-10-27 19:25:11 +08003784 pCB->back.compareMask = compareMask;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003785 }
3786 /* TODO: Do we need to track front and back separately? */
3787 /* TODO: We aren't capturing the faceMask, do we need to? */
3788 pCB->status |= CBSTATUS_STENCIL_READ_MASK_SET;
Cody Northrop2605cb02015-08-18 15:21:16 -06003789 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003790 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdSetStencilCompareMask()");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003791 }
3792 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003793 if (VK_FALSE == skipCall)
Chia-I Wuc51b1212015-10-27 19:25:11 +08003794 dev_data->device_dispatch_table->CmdSetStencilCompareMask(commandBuffer, faceMask, compareMask);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003795}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003796
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003797VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilWriteMask(
Chia-I Wu1f851912015-10-27 18:04:07 +08003798 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003799 VkStencilFaceFlags faceMask,
Chia-I Wuc51b1212015-10-27 19:25:11 +08003800 uint32_t writeMask)
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003801{
3802 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003803 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3804 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003805 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003806 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003807 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILWRITEMASKSTATE);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003808 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
Chia-I Wuc51b1212015-10-27 19:25:11 +08003809 pCB->front.writeMask = writeMask;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003810 }
3811 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
Chia-I Wuc51b1212015-10-27 19:25:11 +08003812 pCB->back.writeMask = writeMask;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003813 }
3814 pCB->status |= CBSTATUS_STENCIL_WRITE_MASK_SET;
3815 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003816 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdSetStencilWriteMask()");
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003817 }
3818 }
3819 if (VK_FALSE == skipCall)
Chia-I Wuc51b1212015-10-27 19:25:11 +08003820 dev_data->device_dispatch_table->CmdSetStencilWriteMask(commandBuffer, faceMask, writeMask);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003821}
3822
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003823VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilReference(
Chia-I Wu1f851912015-10-27 18:04:07 +08003824 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003825 VkStencilFaceFlags faceMask,
Chia-I Wuc51b1212015-10-27 19:25:11 +08003826 uint32_t reference)
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003827{
3828 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003829 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3830 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003831 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003832 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003833 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREFERENCESTATE);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003834 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
Chia-I Wuc51b1212015-10-27 19:25:11 +08003835 pCB->front.reference = reference;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003836 }
3837 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
Chia-I Wuc51b1212015-10-27 19:25:11 +08003838 pCB->back.reference = reference;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003839 }
3840 pCB->status |= CBSTATUS_STENCIL_REFERENCE_SET;
3841 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003842 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdSetStencilReference()");
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003843 }
3844 }
3845 if (VK_FALSE == skipCall)
Chia-I Wuc51b1212015-10-27 19:25:11 +08003846 dev_data->device_dispatch_table->CmdSetStencilReference(commandBuffer, faceMask, reference);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003847}
3848
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003849VK_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 -06003850{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003851 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003852 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3853 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003854 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003855 if (pCB->state == CB_RECORDING) {
Tobin Ehlise4076782015-06-24 15:53:07 -06003856 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003857 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 +08003858 "Incorrectly binding compute DescriptorSets during active RenderPass (%#" PRIxLEAST64 ")", (uint64_t) pCB->activeRenderPass);
Mark Lobodzinski611cf592015-12-18 15:35:38 -07003859 } else if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
3860 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdBindDescriptorSets");
3861 }
3862 if (!skipCall) {
Tobin Ehlis61ebb312015-11-04 12:28:28 -07003863 // Track total count of dynamic descriptor types to make sure we have an offset for each one
3864 uint32_t totalDynamicDescriptors = 0;
Tobin Ehlis982099b2015-11-05 09:52:49 -07003865 string errorString = "";
Tobin Ehliscb085292015-12-01 09:57:09 -07003866 uint32_t lastSetIndex = firstSet+setCount-1;
Tobin Ehlis982099b2015-11-05 09:52:49 -07003867 if (lastSetIndex >= pCB->boundDescriptorSets.size())
3868 pCB->boundDescriptorSets.resize(lastSetIndex+1);
3869 VkDescriptorSet oldFinalBoundSet = pCB->boundDescriptorSets[lastSetIndex];
Tobin Ehlise42007c2015-06-19 13:00:59 -06003870 for (uint32_t i=0; i<setCount; i++) {
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06003871 SET_NODE* pSet = getSetNode(dev_data, pDescriptorSets[i]);
Tobin Ehlis55c1c602015-06-24 17:27:33 -06003872 if (pSet) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06003873 loader_platform_thread_lock_mutex(&globalLock);
3874 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06003875 pCB->lastBoundPipelineLayout = layout;
Tobin Ehlis982099b2015-11-05 09:52:49 -07003876 pCB->boundDescriptorSets[i+firstSet] = pDescriptorSets[i];
Tobin Ehlise42007c2015-06-19 13:00:59 -06003877 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003878 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 +08003879 "DS %#" PRIxLEAST64 " bound on pipeline %s", (uint64_t) pDescriptorSets[i], string_VkPipelineBindPoint(pipelineBindPoint));
Tobin Ehlis61ebb312015-11-04 12:28:28 -07003880 if (!pSet->pUpdateStructs) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003881 // TODO: Verify against Valid Usage
3882 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 +08003883 "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 -07003884 }
Tobin Ehlis982099b2015-11-05 09:52:49 -07003885 // Verify that set being bound is compatible with overlapping setLayout of pipelineLayout
3886 if (!verify_set_layout_compatibility(dev_data, pSet, layout, i+firstSet, errorString)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003887 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 -07003888 "descriptorSet #%u being bound is not compatible with overlapping layout in pipelineLayout due to: %s", i, errorString.c_str());
3889 }
Tobin Ehlis61ebb312015-11-04 12:28:28 -07003890 totalDynamicDescriptors += pSet->pLayout->dynamicDescriptorCount;
Tobin Ehlise42007c2015-06-19 13:00:59 -06003891 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003892 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 +08003893 "Attempt to bind DS %#" PRIxLEAST64 " that doesn't exist!", (uint64_t) pDescriptorSets[i]);
Tobin Ehlise42007c2015-06-19 13:00:59 -06003894 }
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06003895 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003896 skipCall |= addCmd(dev_data, pCB, CMD_BINDDESCRIPTORSETS);
Tobin Ehlis982099b2015-11-05 09:52:49 -07003897 // For any previously bound sets, need to set them to "invalid" if they were disturbed by this update
3898 if (firstSet > 0) { // Check set #s below the first bound set
3899 for (uint32_t i=0; i<firstSet; ++i) {
Tobin Ehliscb085292015-12-01 09:57:09 -07003900 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 -07003901 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 -07003902 "DescriptorSetDS %#" PRIxLEAST64 " previously bound as set #%u was disturbed by newly bound pipelineLayout (%#" PRIxLEAST64 ")", (uint64_t) pCB->boundDescriptorSets[i], i, (uint64_t) layout);
3903 pCB->boundDescriptorSets[i] = VK_NULL_HANDLE;
3904 }
3905 }
3906 }
3907 // Check if newly last bound set invalidates any remaining bound sets
3908 if ((pCB->boundDescriptorSets.size()-1) > (lastSetIndex)) {
Tobin Ehliscb085292015-12-01 09:57:09 -07003909 if (oldFinalBoundSet && !verify_set_layout_compatibility(dev_data, dev_data->setMap[oldFinalBoundSet], layout, lastSetIndex, errorString)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003910 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 -07003911 "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 -07003912 pCB->boundDescriptorSets.resize(lastSetIndex+1);
3913 }
3914 }
Tobin Ehlis61ebb312015-11-04 12:28:28 -07003915 // dynamicOffsetCount must equal the total number of dynamic descriptors in the sets being bound
3916 if (totalDynamicDescriptors != dynamicOffsetCount) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003917 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 -07003918 "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);
3919 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003920 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06003921 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003922 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindDescriptorSets()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003923 }
3924 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003925 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003926 dev_data->device_dispatch_table->CmdBindDescriptorSets(commandBuffer, pipelineBindPoint, layout, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003927}
3928
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003929VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003930{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003931 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003932 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3933 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003934 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003935 if (pCB->state == CB_RECORDING) {
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003936 VkDeviceSize offset_align = 0;
3937 switch (indexType) {
3938 case VK_INDEX_TYPE_UINT16:
3939 offset_align = 2;
3940 break;
3941 case VK_INDEX_TYPE_UINT32:
3942 offset_align = 4;
3943 break;
3944 default:
3945 // ParamChecker should catch bad enum, we'll also throw alignment error below if offset_align stays 0
3946 break;
3947 }
3948 if (!offset_align || (offset % offset_align)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003949 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 -06003950 "vkCmdBindIndexBuffer() offset (%#" PRIxLEAST64 ") does not fall on alignment (%s) boundary.", offset, string_VkIndexType(indexType));
Tobin Ehlise4076782015-06-24 15:53:07 -06003951 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003952 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003953 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06003954 }
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003955 pCB->status |= CBSTATUS_INDEX_BUFFER_BOUND;
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003956 skipCall |= addCmd(dev_data, pCB, CMD_BINDINDEXBUFFER);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003957 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003958 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003959 dev_data->device_dispatch_table->CmdBindIndexBuffer(commandBuffer, buffer, offset, indexType);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003960}
3961
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003962VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindVertexBuffers(
Mark Lobodzinski74e84692015-12-14 15:14:10 -07003963 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003964 uint32_t startBinding,
3965 uint32_t bindingCount,
Mark Lobodzinski74e84692015-12-14 15:14:10 -07003966 const VkBuffer *pBuffers,
3967 const VkDeviceSize *pOffsets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003968{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003969 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003970 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3971 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003972 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003973 if (pCB->state == CB_RECORDING) {
Mark Lobodzinski74e84692015-12-14 15:14:10 -07003974 if ((startBinding + bindingCount) > pCB->boundVtxBuffers.size()) {
3975 pCB->boundVtxBuffers.resize(startBinding+bindingCount, VK_NULL_HANDLE);
3976 }
Courtney Goeltzenleuchter740451a2015-12-16 16:06:06 -07003977 for (uint32_t i = 0; i < bindingCount; i++) {
Mark Lobodzinski74e84692015-12-14 15:14:10 -07003978 pCB->boundVtxBuffers[i+startBinding] = pBuffers[i];
3979 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003980 addCmd(dev_data, pCB, CMD_BINDVERTEXBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003981 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003982 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindVertexBuffer()");
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06003983 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003984 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003985 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003986 dev_data->device_dispatch_table->CmdBindVertexBuffers(commandBuffer, startBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003987}
3988
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003989VK_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 -06003990{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003991 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003992 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3993 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003994 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003995 if (pCB->state == CB_RECORDING) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06003996 pCB->drawCount[DRAW]++;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06003997 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
Chia-I Wu1f851912015-10-27 18:04:07 +08003998 // TODO : Need to pass commandBuffer as srcObj here
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003999 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 -08004000 "vkCmdDraw() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW]++);
Chia-I Wu1f851912015-10-27 18:04:07 +08004001 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004002 if (VK_FALSE == skipCall) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004003 skipCall |= addCmd(dev_data, pCB, CMD_DRAW);
Tobin Ehlise42007c2015-06-19 13:00:59 -06004004 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004005 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004006 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdDraw()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004007 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004008 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDraw");
Jon Ashburne0fa2282015-05-20 09:00:28 -06004009 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004010 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004011 dev_data->device_dispatch_table->CmdDraw(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004012}
4013
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004014VK_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 -06004015{
Chia-I Wu1f851912015-10-27 18:04:07 +08004016 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4017 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004018 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004019 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004020 if (pCB->state == CB_RECORDING) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06004021 pCB->drawCount[DRAW_INDEXED]++;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06004022 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
Chia-I Wu1f851912015-10-27 18:04:07 +08004023 // TODO : Need to pass commandBuffer as srcObj here
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004024 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 -08004025 "vkCmdDrawIndexed() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED]++);
Chia-I Wu1f851912015-10-27 18:04:07 +08004026 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004027 if (VK_FALSE == skipCall) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004028 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXED);
Tobin Ehlise42007c2015-06-19 13:00:59 -06004029 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004030 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004031 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdDrawIndexed()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004032 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004033 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexed");
Jon Ashburne0fa2282015-05-20 09:00:28 -06004034 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004035 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004036 dev_data->device_dispatch_table->CmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004037}
4038
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004039VK_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 -06004040{
Chia-I Wu1f851912015-10-27 18:04:07 +08004041 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4042 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004043 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004044 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004045 if (pCB->state == CB_RECORDING) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06004046 pCB->drawCount[DRAW_INDIRECT]++;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06004047 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
Chia-I Wu1f851912015-10-27 18:04:07 +08004048 // TODO : Need to pass commandBuffer as srcObj here
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004049 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 -08004050 "vkCmdDrawIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
Chia-I Wu1f851912015-10-27 18:04:07 +08004051 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004052 if (VK_FALSE == skipCall) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004053 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDIRECT);
Tobin Ehlise42007c2015-06-19 13:00:59 -06004054 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004055 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004056 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdDrawIndirect()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004057 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004058 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndirect");
Jon Ashburne0fa2282015-05-20 09:00:28 -06004059 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004060 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004061 dev_data->device_dispatch_table->CmdDrawIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004062}
4063
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004064VK_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 -06004065{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004066 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004067 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4068 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004069 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004070 if (pCB->state == CB_RECORDING) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06004071 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06004072 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
Chia-I Wu1f851912015-10-27 18:04:07 +08004073 // TODO : Need to pass commandBuffer as srcObj here
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004074 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 -08004075 "vkCmdDrawIndexedIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
Chia-I Wu1f851912015-10-27 18:04:07 +08004076 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004077 if (VK_FALSE == skipCall) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004078 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXEDINDIRECT);
Tobin Ehlise42007c2015-06-19 13:00:59 -06004079 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004080 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004081 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdDrawIndexedIndirect()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004082 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004083 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexedIndirect");
Jon Ashburne0fa2282015-05-20 09:00:28 -06004084 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004085 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004086 dev_data->device_dispatch_table->CmdDrawIndexedIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004087}
4088
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004089VK_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 -06004090{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004091 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004092 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4093 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004094 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004095 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004096 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCH);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004097 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004098 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdDispatch()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004099 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004100 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatch");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004101 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004102 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004103 dev_data->device_dispatch_table->CmdDispatch(commandBuffer, x, y, z);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004104}
4105
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004106VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004107{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004108 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004109 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4110 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004111 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004112 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004113 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCHINDIRECT);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004114 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004115 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdDispatchIndirect()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004116 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004117 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatchIndirect");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004118 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004119 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004120 dev_data->device_dispatch_table->CmdDispatchIndirect(commandBuffer, buffer, offset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004121}
4122
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004123VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004124{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004125 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004126 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4127 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004128 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004129 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004130 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004131 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004132 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdCopyBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004133 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004134 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBuffer");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004135 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004136 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004137 dev_data->device_dispatch_table->CmdCopyBuffer(commandBuffer, srcBuffer, dstBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004138}
4139
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004140VkBool32 VerifySourceImageLayout(VkCommandBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout) {
4141 VkBool32 skip_call = false;
Mark Lobodzinski78940a42015-11-30 16:48:53 -07004142
4143#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4144 // TODO: Fix -- initialLayout may have been set in a previous command buffer
4145 return skip_call;
4146#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4147
Michael Lentine27b0f902015-10-12 11:30:14 -05004148 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4149 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4150 auto src_image_element = pCB->imageLayoutMap.find(srcImage);
4151 if (src_image_element == pCB->imageLayoutMap.end()) {
4152 pCB->imageLayoutMap[srcImage].initialLayout = srcImageLayout;
4153 pCB->imageLayoutMap[srcImage].layout = srcImageLayout;
4154 return false;
4155 }
4156 if (src_image_element->second.layout != srcImageLayout) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004157 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 -05004158 "Cannot copy from an image whose source layout is %d and doesn't match the current layout %d.", srcImageLayout, src_image_element->second.layout);
4159 }
4160 if (srcImageLayout != VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL) {
4161 if (srcImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004162 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
4163 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 -05004164 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Michael Lentine27b0f902015-10-12 11:30:14 -05004165 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004166 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 -05004167 "Layout for input image is %d but can only be TRANSFER_SRC_OPTIMAL or GENERAL.", srcImageLayout);
Michael Lentine27b0f902015-10-12 11:30:14 -05004168 }
4169 }
4170 return skip_call;
4171}
4172
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004173VkBool32 VerifyDestImageLayout(VkCommandBuffer cmdBuffer, VkImage destImage, VkImageLayout destImageLayout) {
4174 VkBool32 skip_call = false;
Mark Lobodzinski78940a42015-11-30 16:48:53 -07004175
4176#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4177 // TODO: Fix -- initialLayout may have been set in a previous command buffer
4178 return skip_call;
4179#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4180
Michael Lentine27b0f902015-10-12 11:30:14 -05004181 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4182 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4183 auto dest_image_element = pCB->imageLayoutMap.find(destImage);
4184 if (dest_image_element == pCB->imageLayoutMap.end()) {
4185 pCB->imageLayoutMap[destImage].initialLayout = destImageLayout;
4186 pCB->imageLayoutMap[destImage].layout = destImageLayout;
4187 return false;
4188 }
4189 if (dest_image_element->second.layout != destImageLayout) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004190 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 -05004191 "Cannot copy from an image whose dest layout is %d and doesn't match the current layout %d.", destImageLayout, dest_image_element->second.layout);
4192 }
4193 if (destImageLayout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) {
4194 if (destImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004195 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
4196 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 -05004197 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
4198 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004199 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 -05004200 "Layout for output image is %d but can only be TRANSFER_DST_OPTIMAL or GENERAL.", destImageLayout);
4201 }
4202 }
4203 return skip_call;
4204}
4205
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004206VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004207 VkImage srcImage,
4208 VkImageLayout srcImageLayout,
Chia-I Wu1f851912015-10-27 18:04:07 +08004209 VkImage dstImage,
4210 VkImageLayout dstImageLayout,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004211 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004212{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004213 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004214 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4215 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004216 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004217 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004218 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGE);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004219 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004220 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdCopyImage()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004221 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004222 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImage");
Michael Lentine27b0f902015-10-12 11:30:14 -05004223 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
4224 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004225 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004226 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004227 dev_data->device_dispatch_table->CmdCopyImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004228}
4229
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004230VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBlitImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004231 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu1f851912015-10-27 18:04:07 +08004232 VkImage dstImage, VkImageLayout dstImageLayout,
Mark Lobodzinski20f68592015-05-22 14:43:25 -05004233 uint32_t regionCount, const VkImageBlit* pRegions,
Chia-I Wu3603b082015-10-26 16:49:32 +08004234 VkFilter filter)
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06004235{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004236 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004237 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4238 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06004239 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004240 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004241 skipCall |= addCmd(dev_data, pCB, CMD_BLITIMAGE);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004242 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004243 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBlitImage()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004244 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004245 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBlitImage");
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06004246 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004247 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004248 dev_data->device_dispatch_table->CmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06004249}
4250
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004251VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004252 VkBuffer srcBuffer,
Chia-I Wu1f851912015-10-27 18:04:07 +08004253 VkImage dstImage, VkImageLayout dstImageLayout,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004254 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004255{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004256 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004257 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4258 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004259 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004260 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004261 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFERTOIMAGE);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004262 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004263 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdCopyBufferToImage()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004264 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004265 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBufferToImage");
Michael Lentine27b0f902015-10-12 11:30:14 -05004266 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004267 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004268 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004269 dev_data->device_dispatch_table->CmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004270}
4271
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004272VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004273 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu1f851912015-10-27 18:04:07 +08004274 VkBuffer dstBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004275 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004276{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004277 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004278 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4279 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004280 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004281 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004282 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGETOBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004283 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004284 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdCopyImageToBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004285 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004286 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImageToBuffer");
Michael Lentine27b0f902015-10-12 11:30:14 -05004287 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004288 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004289 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004290 dev_data->device_dispatch_table->CmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004291}
4292
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004293VK_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 -06004294{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004295 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004296 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4297 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004298 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004299 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004300 skipCall |= addCmd(dev_data, pCB, CMD_UPDATEBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004301 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004302 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdUpdateBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004303 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004304 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyUpdateBuffer");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004305 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004306 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004307 dev_data->device_dispatch_table->CmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004308}
4309
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004310VK_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 -06004311{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004312 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004313 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4314 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004315 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004316 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004317 skipCall |= addCmd(dev_data, pCB, CMD_FILLBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004318 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004319 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdFillBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004320 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004321 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyFillBuffer");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004322 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004323 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004324 dev_data->device_dispatch_table->CmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004325}
4326
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004327VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearAttachments(
Chia-I Wu1f851912015-10-27 18:04:07 +08004328 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004329 uint32_t attachmentCount,
4330 const VkClearAttachment* pAttachments,
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004331 uint32_t rectCount,
Courtney Goeltzenleuchtera12e2912015-10-15 18:22:08 -06004332 const VkClearRect* pRects)
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004333{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004334 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004335 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4336 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004337 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004338 if (pCB->state == CB_RECORDING) {
Mark Lobodzinski92c712c2015-12-08 13:47:14 -07004339 // Warn if this is issued prior to Draw Cmd and clearing the entire attachment
4340 if (!hasDrawCmd(pCB) &&
4341 (pCB->activeRenderPassBeginInfo.renderArea.extent.width == pRects[0].rect.extent.width) &&
4342 (pCB->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) {
Chia-I Wu1f851912015-10-27 18:04:07 +08004343 // TODO : commandBuffer should be srcObj
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004344 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 -06004345 "vkCmdClearAttachments() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
Chia-I Wu1f851912015-10-27 18:04:07 +08004346 " 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 -06004347 }
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004348 skipCall |= addCmd(dev_data, pCB, CMD_CLEARATTACHMENTS);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004349 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004350 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdClearAttachments()");
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004351 }
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004352 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdClearAttachments");
4353 }
4354
4355 // Validate that attachment is in reference list of active subpass
4356 if (pCB->activeRenderPass) {
Tobin Ehlisad61de42015-12-02 13:53:34 -07004357 const VkRenderPassCreateInfo *pRPCI = dev_data->renderPassMap[pCB->activeRenderPass]->pCreateInfo;
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004358 const VkSubpassDescription *pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
4359
4360 for (uint32_t attachment_idx = 0; attachment_idx < attachmentCount; attachment_idx++) {
4361 const VkClearAttachment *attachment = &pAttachments[attachment_idx];
4362 if (attachment->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) {
4363 VkBool32 found = VK_FALSE;
Chia-I Wu763a7492015-10-26 20:48:51 +08004364 for (uint32_t i = 0; i < pSD->colorAttachmentCount; i++) {
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004365 if (attachment->colorAttachment == pSD->pColorAttachments[i].attachment) {
4366 found = VK_TRUE;
4367 break;
4368 }
4369 }
4370 if (VK_FALSE == found) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004371 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 +08004372 (uint64_t)commandBuffer, 0, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004373 "vkCmdClearAttachments() attachment index %d not found in attachment reference array of active subpass %d",
4374 attachment->colorAttachment, pCB->activeSubpass);
4375 }
4376 } else if (attachment->aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) {
Mark Lobodzinski1523e3a2015-11-17 15:11:24 -07004377 if (!pSD->pDepthStencilAttachment || // Says no DS will be used in active subpass
Mark Lobodzinskiea1fff22015-11-18 08:58:31 -07004378 (pSD->pDepthStencilAttachment->attachment == VK_ATTACHMENT_UNUSED)) { // Says no DS will be used in active subpass
Mark Lobodzinski1523e3a2015-11-17 15:11:24 -07004379
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004380 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 -07004381 (uint64_t)commandBuffer, 0, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
4382 "vkCmdClearAttachments() attachment index %d does not match depthStencilAttachment.attachment (%d) found in active subpass %d",
4383 attachment->colorAttachment,
4384 (pSD->pDepthStencilAttachment) ? pSD->pDepthStencilAttachment->attachment : VK_ATTACHMENT_UNUSED,
4385 pCB->activeSubpass);
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004386 }
4387 }
4388 }
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004389 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004390 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004391 dev_data->device_dispatch_table->CmdClearAttachments(commandBuffer, attachmentCount, pAttachments, rectCount, pRects);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004392}
4393
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004394VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearColorImage(
Chia-I Wu1f851912015-10-27 18:04:07 +08004395 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06004396 VkImage image, VkImageLayout imageLayout,
Chris Forbese3105972015-06-24 14:34:53 +12004397 const VkClearColorValue *pColor,
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06004398 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004399{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004400 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004401 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4402 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004403 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004404 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004405 skipCall |= addCmd(dev_data, pCB, CMD_CLEARCOLORIMAGE);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004406 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004407 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdClearColorImage()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004408 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004409 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearColorImage");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004410 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004411 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004412 dev_data->device_dispatch_table->CmdClearColorImage(commandBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004413}
4414
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004415VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearDepthStencilImage(
Chia-I Wu1f851912015-10-27 18:04:07 +08004416 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter315ad992015-09-15 18:03:22 -06004417 VkImage image, VkImageLayout imageLayout,
4418 const VkClearDepthStencilValue *pDepthStencil,
4419 uint32_t rangeCount,
4420 const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004421{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004422 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004423 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4424 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004425 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004426 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004427 skipCall |= addCmd(dev_data, pCB, CMD_CLEARDEPTHSTENCILIMAGE);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004428 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004429 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdClearDepthStencilImage()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004430 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004431 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearDepthStencilImage");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004432 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004433 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004434 dev_data->device_dispatch_table->CmdClearDepthStencilImage(commandBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004435}
4436
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004437VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResolveImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004438 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu1f851912015-10-27 18:04:07 +08004439 VkImage dstImage, VkImageLayout dstImageLayout,
Tony Barbour11f74372015-04-13 15:02:52 -06004440 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004441{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004442 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004443 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4444 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004445 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004446 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004447 skipCall |= addCmd(dev_data, pCB, CMD_RESOLVEIMAGE);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004448 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004449 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdResolveImage()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004450 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004451 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResolveImage");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004452 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004453 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004454 dev_data->device_dispatch_table->CmdResolveImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004455}
4456
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004457VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004458{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004459 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004460 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4461 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004462 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004463 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004464 skipCall |= addCmd(dev_data, pCB, CMD_SETEVENT);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004465 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004466 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdSetEvent()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004467 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004468 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdSetEvent");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004469 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004470 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004471 dev_data->device_dispatch_table->CmdSetEvent(commandBuffer, event, stageMask);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004472}
4473
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004474VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004475{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004476 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004477 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4478 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004479 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004480 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004481 skipCall |= addCmd(dev_data, pCB, CMD_RESETEVENT);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004482 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004483 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdResetEvent()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004484 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004485 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResetEvent");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004486 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004487 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004488 dev_data->device_dispatch_table->CmdResetEvent(commandBuffer, event, stageMask);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004489}
4490
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004491VkBool32 TransitionImageLayouts(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const void* const* ppMemBarriers) {
Michael Lentine27b0f902015-10-12 11:30:14 -05004492 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4493 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004494 VkBool32 skip = false;
Mark Lobodzinski78940a42015-11-30 16:48:53 -07004495
4496#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4497 // TODO: Fix -- pay attention to image subresource ranges -- not all subresources transition at the same time
4498 return skip;
4499#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4500
Michael Lentine27b0f902015-10-12 11:30:14 -05004501 for (uint32_t i = 0; i < memBarrierCount; ++i) {
4502 auto mem_barrier = reinterpret_cast<const VkMemoryBarrier*>(ppMemBarriers[i]);
4503 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
4504 auto image_mem_barrier = reinterpret_cast<const VkImageMemoryBarrier*>(mem_barrier);
4505 auto image_data = pCB->imageLayoutMap.find(image_mem_barrier->image);
4506 if (image_data == pCB->imageLayoutMap.end()) {
4507 pCB->imageLayoutMap[image_mem_barrier->image].initialLayout = image_mem_barrier->oldLayout;
4508 pCB->imageLayoutMap[image_mem_barrier->image].layout = image_mem_barrier->newLayout;
4509 } else {
4510 if (image_data->second.layout != image_mem_barrier->oldLayout) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004511 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 -07004512 "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 -05004513 }
4514 image_data->second.layout = image_mem_barrier->newLayout;
4515 }
4516 }
4517 }
4518 return skip;
4519}
4520
Michael Lentine8469dd62015-11-20 09:48:52 -08004521// AccessFlags MUST have 'required_bit' set, and may have one or more of 'optional_bits' set.
4522// If required_bit is zero, accessMask must have at least one of 'optional_bits' set
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004523VkBool32 ValidateMaskBits(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout, VkAccessFlags required_bit, VkAccessFlags optional_bits) {
4524 VkBool32 skip_call = false;
Michael Lentine8469dd62015-11-20 09:48:52 -08004525 if ((accessMask & required_bit) || (!required_bit && (accessMask & optional_bits))) {
4526 if (accessMask & !(required_bit | optional_bits)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004527 // TODO: Verify against Valid Use
4528 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 -08004529 "Additional bits in accessMask %d are specified when layout is %s.", accessMask, string_VkImageLayout(layout));
Michael Lentine472af7d2015-10-16 18:08:09 -05004530 }
4531 } else {
Michael Lentine8469dd62015-11-20 09:48:52 -08004532 if (!required_bit) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004533 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 -08004534 "AccessMask %d must contain at least one of access bits %d when layout is %s.",
4535 accessMask, optional_bits, string_VkImageLayout(layout));
4536 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004537 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 -08004538 "AccessMask %d must have required access bit %d and may have optional bits %d when layout is %s.",
4539 accessMask, required_bit, optional_bits,string_VkImageLayout(layout));
4540 }
Michael Lentine472af7d2015-10-16 18:08:09 -05004541 }
4542 return skip_call;
4543}
4544
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004545VkBool32 ValidateMaskBitsFromLayouts(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout) {
4546 VkBool32 skip_call = false;
Michael Lentine8469dd62015-11-20 09:48:52 -08004547 switch (layout) {
4548 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: {
4549 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_COLOR_ATTACHMENT_READ_BIT);
4550 break;
Michael Lentine472af7d2015-10-16 18:08:09 -05004551 }
Michael Lentine8469dd62015-11-20 09:48:52 -08004552 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: {
4553 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT);
4554 break;
Michael Lentine472af7d2015-10-16 18:08:09 -05004555 }
Michael Lentine8469dd62015-11-20 09:48:52 -08004556 case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: {
4557 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_WRITE_BIT, 0);
4558 break;
4559 }
4560 case VK_IMAGE_LAYOUT_PREINITIALIZED: {
4561 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_HOST_WRITE_BIT, 0);
4562 break;
4563 }
4564 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: {
4565 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, 0, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT);
4566 break;
4567 }
4568 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: {
4569 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, 0, VK_ACCESS_INPUT_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT);
4570 break;
4571 }
4572 case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: {
4573 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_READ_BIT, 0);
4574 break;
4575 }
4576 case VK_IMAGE_LAYOUT_UNDEFINED: {
4577 if (accessMask != 0) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004578 // TODO: Verify against Valid Use section spec
4579 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 -08004580 "Additional bits in accessMask %d are specified when layout is %s.", accessMask, string_VkImageLayout(layout));
4581 }
4582 break;
4583 }
4584 case VK_IMAGE_LAYOUT_GENERAL:
4585 default: {
4586 break;
4587 }
Michael Lentine472af7d2015-10-16 18:08:09 -05004588 }
4589 return skip_call;
4590}
4591
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004592VkBool32 ValidateBarriers(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const void* const* ppMemBarriers) {
4593 VkBool32 skip_call = false;
Michael Lentine07ff1a12015-10-15 17:07:00 -05004594 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4595 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4596 if (pCB->activeRenderPass && memBarrierCount) {
4597 for (uint32_t i = 0; i < memBarrierCount; ++i) {
4598 auto mem_barrier = reinterpret_cast<const VkMemoryBarrier*>(ppMemBarriers[i]);
4599 if (mem_barrier && mem_barrier->sType != VK_STRUCTURE_TYPE_MEMORY_BARRIER) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004600 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 -05004601 "Image or Buffers Barriers cannot be used during a render pass.");
4602 }
4603 }
4604 if (!dev_data->renderPassMap[pCB->activeRenderPass]->hasSelfDependency[pCB->activeSubpass]) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004605 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 -05004606 "Barriers cannot be set during subpass %d with no self dependency specified.", pCB->activeSubpass);
4607 }
4608 }
Mark Lobodzinskib684b512015-11-20 09:27:27 -07004609
Michael Lentine472af7d2015-10-16 18:08:09 -05004610 for (uint32_t i = 0; i < memBarrierCount; ++i) {
4611 auto mem_barrier = reinterpret_cast<const VkMemoryBarrier*>(ppMemBarriers[i]);
4612 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
4613 auto image_mem_barrier = reinterpret_cast<const VkImageMemoryBarrier*>(mem_barrier);
Michael Lentine8469dd62015-11-20 09:48:52 -08004614 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, image_mem_barrier->srcAccessMask, image_mem_barrier->oldLayout);
4615 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, image_mem_barrier->dstAccessMask, image_mem_barrier->newLayout);
Michael Lentine472af7d2015-10-16 18:08:09 -05004616 }
4617 }
Mark Lobodzinskib95fc092015-12-03 15:42:32 -07004618
Michael Lentine07ff1a12015-10-15 17:07:00 -05004619 return skip_call;
4620}
4621
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004622VK_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 -06004623{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004624 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004625 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4626 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004627 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004628 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004629 skipCall |= addCmd(dev_data, pCB, CMD_WAITEVENTS);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004630 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004631 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdWaitEvents()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004632 }
Michael Lentine27b0f902015-10-12 11:30:14 -05004633 skipCall |= TransitionImageLayouts(commandBuffer, memoryBarrierCount, ppMemoryBarriers);
Michael Lentine07ff1a12015-10-15 17:07:00 -05004634 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, ppMemoryBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004635 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004636 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004637 dev_data->device_dispatch_table->CmdWaitEvents(commandBuffer, eventCount, pEvents, sourceStageMask, dstStageMask, memoryBarrierCount, ppMemoryBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004638}
4639
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004640VK_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 -06004641{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004642 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004643 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4644 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004645 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004646 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004647 skipCall |= addCmd(dev_data, pCB, CMD_PIPELINEBARRIER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004648 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004649 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdPipelineBarrier()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004650 }
Michael Lentine27b0f902015-10-12 11:30:14 -05004651 skipCall |= TransitionImageLayouts(commandBuffer, memoryBarrierCount, ppMemoryBarriers);
Michael Lentine07ff1a12015-10-15 17:07:00 -05004652 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, ppMemoryBarriers);
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->CmdPipelineBarrier(commandBuffer, srcStageMask, dstStageMask, dependencyFlags, memoryBarrierCount, ppMemoryBarriers);
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 vkCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
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_BEGINQUERY);
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, "vkCmdBeginQuery()");
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->CmdBeginQuery(commandBuffer, queryPool, slot, flags);
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 vkCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot)
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_ENDQUERY);
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, "vkCmdEndQuery()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004684 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004685 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004686 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004687 dev_data->device_dispatch_table->CmdEndQuery(commandBuffer, queryPool, slot);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004688}
4689
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004690VK_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 -06004691{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004692 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004693 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4694 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004695 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004696 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004697 skipCall |= addCmd(dev_data, pCB, CMD_RESETQUERYPOOL);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004698 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004699 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdResetQueryPool()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004700 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004701 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdQueryPool");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004702 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004703 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004704 dev_data->device_dispatch_table->CmdResetQueryPool(commandBuffer, queryPool, startQuery, queryCount);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004705}
4706
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004707VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t startQuery,
Chia-I Wu1f851912015-10-27 18:04:07 +08004708 uint32_t queryCount, VkBuffer dstBuffer, VkDeviceSize dstOffset,
Chia-I Wu1f6942d2015-10-26 18:36:20 +08004709 VkDeviceSize stride, VkQueryResultFlags flags)
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06004710{
4711 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004712 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4713 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06004714 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004715 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004716 skipCall |= addCmd(dev_data, pCB, CMD_COPYQUERYPOOLRESULTS);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06004717 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004718 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdCopyQueryPoolResults()");
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06004719 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004720 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyQueryPoolResults");
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06004721 }
4722 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004723 dev_data->device_dispatch_table->CmdCopyQueryPoolResults(commandBuffer, queryPool,
4724 startQuery, queryCount, dstBuffer, dstOffset, stride, flags);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06004725}
4726
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004727VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004728{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004729 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004730 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4731 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004732 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004733 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004734 skipCall |= addCmd(dev_data, pCB, CMD_WRITETIMESTAMP);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004735 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004736 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdWriteTimestamp()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004737 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004738 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004739 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004740 dev_data->device_dispatch_table->CmdWriteTimestamp(commandBuffer, pipelineStage, queryPool, slot);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004741}
4742
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004743VK_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 -06004744{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06004745 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08004746 VkResult result = dev_data->device_dispatch_table->CreateFramebuffer(device, pCreateInfo, pAllocator, pFramebuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06004747 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06004748 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004749 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Chia-I Wuc278df82015-07-07 11:50:03 +08004750 if (pCreateInfo->pAttachments) {
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -06004751 localFBCI->pAttachments = new VkImageView[localFBCI->attachmentCount];
4752 memcpy((void*)localFBCI->pAttachments, pCreateInfo->pAttachments, localFBCI->attachmentCount*sizeof(VkImageView));
Tobin Ehlis2464b882015-04-01 08:40:34 -06004753 }
Chia-I Wue420a332015-10-26 20:04:44 +08004754 dev_data->frameBufferMap[*pFramebuffer] = localFBCI;
Tobin Ehlis2464b882015-04-01 08:40:34 -06004755 }
4756 return result;
4757}
4758
Michael Lentine329697b2015-10-06 14:56:18 -07004759// Store the DAG.
4760struct DAGNode {
4761 uint32_t pass;
4762 std::vector<uint32_t> prev;
4763 std::vector<uint32_t> next;
4764};
4765
Courtney Goeltzenleuchterf2bca902015-11-03 15:41:43 -07004766VkBool32 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 -07004767 // If we have already checked this node we have not found a dependency path so return false.
4768 if (processed_nodes.count(index))
4769 return false;
4770 processed_nodes.insert(index);
4771 const DAGNode& node = subpass_to_node[index];
4772 // Look for a dependency path. If one exists return true else recurse on the previous nodes.
4773 if (std::find(node.prev.begin(), node.prev.end(), dependent) == node.prev.end()) {
4774 for (auto elem : node.prev) {
4775 if (FindDependency(elem, dependent, subpass_to_node, processed_nodes))
4776 return true;
4777 }
4778 } else {
4779 return true;
4780 }
4781 return false;
4782}
4783
Courtney Goeltzenleuchterf2bca902015-11-03 15:41:43 -07004784VkBool32 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) {
4785 VkBool32 result = true;
Michael Lentine329697b2015-10-06 14:56:18 -07004786 // Loop through all subpasses that share the same attachment and make sure a dependency exists
4787 for (uint32_t k = 0; k < dependent_subpasses.size(); ++k) {
4788 if (subpass == dependent_subpasses[k])
4789 continue;
4790 const DAGNode& node = subpass_to_node[subpass];
4791 // Check for a specified dependency between the two nodes. If one exists we are done.
4792 auto prev_elem = std::find(node.prev.begin(), node.prev.end(), dependent_subpasses[k]);
4793 auto next_elem = std::find(node.next.begin(), node.next.end(), dependent_subpasses[k]);
4794 if (prev_elem == node.prev.end() && next_elem == node.next.end()) {
4795 // If no dependency exits an implicit dependency still might. If so, warn and if not throw an error.
4796 std::unordered_set<uint32_t> processed_nodes;
4797 if (FindDependency(subpass, dependent_subpasses[k], subpass_to_node, processed_nodes) ||
4798 FindDependency(dependent_subpasses[k], subpass, subpass_to_node, processed_nodes)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004799 // TODO: Verify against Valid Use section of spec
4800 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 -07004801 "A dependency between subpasses %d and %d must exist but only an implicit one is specified.",
4802 subpass, dependent_subpasses[k]);
4803 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004804 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 -07004805 "A dependency between subpasses %d and %d must exist but one is not specified.",
4806 subpass, dependent_subpasses[k]);
4807 result = false;
4808 }
4809 }
4810 }
4811 return result;
4812}
4813
Courtney Goeltzenleuchterf2bca902015-11-03 15:41:43 -07004814VkBool32 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 -07004815 const DAGNode& node = subpass_to_node[index];
4816 // If this node writes to the attachment return true as next nodes need to preserve the attachment.
4817 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Chia-I Wu763a7492015-10-26 20:48:51 +08004818 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentine329697b2015-10-06 14:56:18 -07004819 if (attachment == subpass.pColorAttachments[j].attachment)
Courtney Goeltzenleuchterf2bca902015-11-03 15:41:43 -07004820 return VK_TRUE;
Michael Lentine329697b2015-10-06 14:56:18 -07004821 }
Chia-I Wuce532f72015-10-26 17:32:47 +08004822 if (subpass.pDepthStencilAttachment &&
4823 subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
4824 if (attachment == subpass.pDepthStencilAttachment->attachment)
Courtney Goeltzenleuchterf2bca902015-11-03 15:41:43 -07004825 return VK_TRUE;
Michael Lentine329697b2015-10-06 14:56:18 -07004826 }
Courtney Goeltzenleuchterf2bca902015-11-03 15:41:43 -07004827 VkBool32 result = VK_FALSE;
Michael Lentine329697b2015-10-06 14:56:18 -07004828 // Loop through previous nodes and see if any of them write to the attachment.
4829 for (auto elem : node.prev) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004830 result |= CheckPreserved(my_data, device, pCreateInfo, elem, attachment, subpass_to_node, depth + 1, skip_call);
Michael Lentine329697b2015-10-06 14:56:18 -07004831 }
4832 // If the attachment was written to by a previous node than this node needs to preserve it.
4833 if (result && depth > 0) {
4834 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Courtney Goeltzenleuchterf2bca902015-11-03 15:41:43 -07004835 VkBool32 has_preserved = false;
Chia-I Wu763a7492015-10-26 20:48:51 +08004836 for (uint32_t j = 0; j < subpass.preserveAttachmentCount; ++j) {
Michael Lentine329697b2015-10-06 14:56:18 -07004837 if (subpass.pPreserveAttachments[j].attachment == attachment) {
4838 has_preserved = true;
4839 break;
4840 }
4841 }
4842 if (!has_preserved) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004843 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 -07004844 "Attachment %d is used by a later subpass and must be preserved in subpass %d.", attachment, index);
4845 }
4846 }
4847 return result;
4848}
4849
Michael Lentine27b0f902015-10-12 11:30:14 -05004850VkBool32 ValidateDependencies(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, std::vector<DAGNode>& subpass_to_node) {
4851 VkBool32 skip_call = false;
Michael Lentine329697b2015-10-06 14:56:18 -07004852 std::vector<std::vector<uint32_t>> output_attachment_to_subpass(pCreateInfo->attachmentCount);
4853 std::vector<std::vector<uint32_t>> input_attachment_to_subpass(pCreateInfo->attachmentCount);
Michael Lentine27b0f902015-10-12 11:30:14 -05004854
Michael Lentine329697b2015-10-06 14:56:18 -07004855 // Create DAG
4856 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
4857 DAGNode& subpass_node = subpass_to_node[i];
4858 subpass_node.pass = i;
4859 }
4860 for (uint32_t i = 0; i < pCreateInfo->dependencyCount; ++i) {
4861 const VkSubpassDependency& dependency = pCreateInfo->pDependencies[i];
Chia-I Wu1f851912015-10-27 18:04:07 +08004862 if (dependency.srcSubpass > dependency.dstSubpass) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004863 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 -07004864 "Dependency graph must be specified such that an earlier pass cannot depend on a later pass.");
4865 }
Chia-I Wu1f851912015-10-27 18:04:07 +08004866 subpass_to_node[dependency.dstSubpass].prev.push_back(dependency.srcSubpass);
4867 subpass_to_node[dependency.srcSubpass].next.push_back(dependency.dstSubpass);
Michael Lentine329697b2015-10-06 14:56:18 -07004868 }
Michael Lentine27b0f902015-10-12 11:30:14 -05004869
Michael Lentine329697b2015-10-06 14:56:18 -07004870 // Find for each attachment the subpasses that use them.
4871 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
4872 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wu763a7492015-10-26 20:48:51 +08004873 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Michael Lentine329697b2015-10-06 14:56:18 -07004874 input_attachment_to_subpass[subpass.pInputAttachments[j].attachment].push_back(i);
4875 }
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 output_attachment_to_subpass[subpass.pColorAttachments[j].attachment].push_back(i);
4878 }
Chia-I Wuce532f72015-10-26 17:32:47 +08004879 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
4880 output_attachment_to_subpass[subpass.pDepthStencilAttachment->attachment].push_back(i);
Michael Lentine329697b2015-10-06 14:56:18 -07004881 }
4882 }
4883 // If there is a dependency needed make sure one exists
4884 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
4885 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
4886 // If the attachment is an input then all subpasses that output must have a dependency relationship
Chia-I Wu763a7492015-10-26 20:48:51 +08004887 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Michael Lentine329697b2015-10-06 14:56:18 -07004888 const uint32_t& attachment = subpass.pInputAttachments[j].attachment;
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004889 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentine329697b2015-10-06 14:56:18 -07004890 }
4891 // 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 +08004892 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentine329697b2015-10-06 14:56:18 -07004893 const uint32_t& attachment = subpass.pColorAttachments[j].attachment;
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004894 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
4895 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentine329697b2015-10-06 14:56:18 -07004896 }
Chia-I Wuce532f72015-10-26 17:32:47 +08004897 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
4898 const uint32_t& attachment = subpass.pDepthStencilAttachment->attachment;
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004899 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
4900 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentine329697b2015-10-06 14:56:18 -07004901 }
4902 }
4903 // Loop through implicit dependencies, if this pass reads make sure the attachment is preserved for all passes after it was written.
4904 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
4905 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wu763a7492015-10-26 20:48:51 +08004906 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004907 CheckPreserved(my_data, device, pCreateInfo, i, subpass.pInputAttachments[j].attachment, subpass_to_node, 0, skip_call);
Michael Lentine329697b2015-10-06 14:56:18 -07004908 }
4909 }
4910 return skip_call;
4911}
4912
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004913VkBool32 ValidateLayouts(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo) {
4914 VkBool32 skip = false;
Mark Lobodzinski78940a42015-11-30 16:48:53 -07004915
4916#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4917 return skip;
4918#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4919
Michael Lentine27b0f902015-10-12 11:30:14 -05004920 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
4921 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
4922 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
4923 if (subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL &&
4924 subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) {
4925 if (subpass.pInputAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004926 // TODO: Verify Valid Use in spec. I believe this is allowed (valid) but may not be optimal performance
4927 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 -05004928 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
4929 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004930 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 -05004931 "Layout for input attachment is %d but can only be READ_ONLY_OPTIMAL or GENERAL.", subpass.pInputAttachments[j].attachment);
4932 }
4933 }
4934 }
4935 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
4936 if (subpass.pColorAttachments[j].layout != VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) {
4937 if (subpass.pColorAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004938 // TODO: Verify Valid Use in spec. I believe this is allowed (valid) but may not be optimal performance
4939 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 -05004940 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
4941 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004942 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 -05004943 "Layout for color attachment is %d but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.", subpass.pColorAttachments[j].attachment);
4944 }
4945 }
4946 }
Mark Lobodzinskic344bef2015-10-28 13:03:56 -06004947 if ((subpass.pDepthStencilAttachment != NULL) &&
4948 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
Michael Lentine27b0f902015-10-12 11:30:14 -05004949 if (subpass.pDepthStencilAttachment->layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) {
4950 if (subpass.pDepthStencilAttachment->layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004951 // TODO: Verify Valid Use in spec. I believe this is allowed (valid) but may not be optimal performance
4952 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 -05004953 "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL.");
4954 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004955 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 -05004956 "Layout for depth attachment is %d but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL.", subpass.pDepthStencilAttachment->attachment);
4957 }
4958 }
4959 }
4960 }
4961 return skip;
4962}
4963
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004964VkBool32 CreatePassDAG(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, std::vector<DAGNode>& subpass_to_node, std::vector<bool>& has_self_dependency) {
4965 VkBool32 skip_call = false;
Michael Lentine27b0f902015-10-12 11:30:14 -05004966 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
4967 DAGNode& subpass_node = subpass_to_node[i];
4968 subpass_node.pass = i;
4969 }
4970 for (uint32_t i = 0; i < pCreateInfo->dependencyCount; ++i) {
4971 const VkSubpassDependency& dependency = pCreateInfo->pDependencies[i];
4972 if (dependency.srcSubpass > dependency.dstSubpass) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004973 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 -05004974 "Depedency graph must be specified such that an earlier pass cannot depend on a later pass.");
Michael Lentine07ff1a12015-10-15 17:07:00 -05004975 } else if (dependency.srcSubpass == dependency.dstSubpass) {
4976 has_self_dependency[dependency.srcSubpass] = true;
Michael Lentine27b0f902015-10-12 11:30:14 -05004977 }
4978 subpass_to_node[dependency.dstSubpass].prev.push_back(dependency.srcSubpass);
4979 subpass_to_node[dependency.srcSubpass].next.push_back(dependency.dstSubpass);
4980 }
4981 return skip_call;
4982}
Tobin Ehliscb085292015-12-01 09:57:09 -07004983// TODOSC : Add intercept of vkCreateShaderModule
Michael Lentine27b0f902015-10-12 11:30:14 -05004984
Tobin Ehlis32479352015-12-01 09:48:58 -07004985VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateShaderModule(
4986 VkDevice device,
4987 const VkShaderModuleCreateInfo *pCreateInfo,
4988 const VkAllocationCallbacks* pAllocator,
4989 VkShaderModule *pShaderModule)
4990{
4991 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07004992 VkBool32 skip_call = false;
Tobin Ehlis32479352015-12-01 09:48:58 -07004993 if (!shader_is_spirv(pCreateInfo)) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004994 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 -07004995 /* dev */ 0, 0, SHADER_CHECKER_NON_SPIRV_SHADER, "SC",
4996 "Shader is not SPIR-V");
4997 }
4998
4999 if (skip_call)
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07005000 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis32479352015-12-01 09:48:58 -07005001
5002 VkResult res = my_data->device_dispatch_table->CreateShaderModule(device, pCreateInfo, pAllocator, pShaderModule);
5003
5004 if (res == VK_SUCCESS) {
5005 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisad61de42015-12-02 13:53:34 -07005006 my_data->shaderModuleMap[*pShaderModule] = new shader_module(pCreateInfo);
Tobin Ehlis32479352015-12-01 09:48:58 -07005007 loader_platform_thread_unlock_mutex(&globalLock);
5008 }
5009 return res;
5010}
5011
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005012VK_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 -06005013{
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07005014 VkBool32 skip_call = false;
Tobin Ehlis42d440c2015-10-20 17:06:16 -06005015 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentine27b0f902015-10-12 11:30:14 -05005016 // Create DAG
Michael Lentine07ff1a12015-10-15 17:07:00 -05005017 std::vector<bool> has_self_dependency(pCreateInfo->subpassCount);
Michael Lentine27b0f902015-10-12 11:30:14 -05005018 std::vector<DAGNode> subpass_to_node(pCreateInfo->subpassCount);
Michael Lentine07ff1a12015-10-15 17:07:00 -05005019 skip_call |= CreatePassDAG(dev_data, device, pCreateInfo, subpass_to_node, has_self_dependency);
Michael Lentine27b0f902015-10-12 11:30:14 -05005020 // Validate using DAG
5021 skip_call |= ValidateDependencies(dev_data, device, pCreateInfo, subpass_to_node);
5022 skip_call |= ValidateLayouts(dev_data, device, pCreateInfo);
5023 if (skip_call) {
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07005024 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine329697b2015-10-06 14:56:18 -07005025 }
Chia-I Wu69f40122015-10-26 21:10:41 +08005026 VkResult result = dev_data->device_dispatch_table->CreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005027 if (VK_SUCCESS == result) {
Tobin Ehliscb085292015-12-01 09:57:09 -07005028 // TODOSC : Merge in tracking of renderpass from ShaderChecker
Tobin Ehlis2464b882015-04-01 08:40:34 -06005029 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06005030 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Chia-I Wuc278df82015-07-07 11:50:03 +08005031 if (pCreateInfo->pAttachments) {
5032 localRPCI->pAttachments = new VkAttachmentDescription[localRPCI->attachmentCount];
5033 memcpy((void*)localRPCI->pAttachments, pCreateInfo->pAttachments, localRPCI->attachmentCount*sizeof(VkAttachmentDescription));
Tobin Ehlis2464b882015-04-01 08:40:34 -06005034 }
Chia-I Wuc278df82015-07-07 11:50:03 +08005035 if (pCreateInfo->pSubpasses) {
5036 localRPCI->pSubpasses = new VkSubpassDescription[localRPCI->subpassCount];
5037 memcpy((void*)localRPCI->pSubpasses, pCreateInfo->pSubpasses, localRPCI->subpassCount*sizeof(VkSubpassDescription));
5038
5039 for (uint32_t i = 0; i < localRPCI->subpassCount; i++) {
5040 VkSubpassDescription *subpass = (VkSubpassDescription *) &localRPCI->pSubpasses[i];
Chia-I Wu763a7492015-10-26 20:48:51 +08005041 const uint32_t attachmentCount = subpass->inputAttachmentCount +
5042 subpass->colorAttachmentCount * (1 + (subpass->pResolveAttachments?1:0)) +
Chia-I Wuce532f72015-10-26 17:32:47 +08005043 ((subpass->pDepthStencilAttachment) ? 1 : 0) + subpass->preserveAttachmentCount;
Chia-I Wuc278df82015-07-07 11:50:03 +08005044 VkAttachmentReference *attachments = new VkAttachmentReference[attachmentCount];
5045
Cody Northrop6de6b0b2015-08-04 11:16:41 -06005046 memcpy(attachments, subpass->pInputAttachments,
Chia-I Wu763a7492015-10-26 20:48:51 +08005047 sizeof(attachments[0]) * subpass->inputAttachmentCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06005048 subpass->pInputAttachments = attachments;
Chia-I Wu763a7492015-10-26 20:48:51 +08005049 attachments += subpass->inputAttachmentCount;
Chia-I Wuc278df82015-07-07 11:50:03 +08005050
Cody Northrop6de6b0b2015-08-04 11:16:41 -06005051 memcpy(attachments, subpass->pColorAttachments,
Chia-I Wu763a7492015-10-26 20:48:51 +08005052 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06005053 subpass->pColorAttachments = attachments;
Chia-I Wu763a7492015-10-26 20:48:51 +08005054 attachments += subpass->colorAttachmentCount;
Chia-I Wuc278df82015-07-07 11:50:03 +08005055
Cody Northrop6de6b0b2015-08-04 11:16:41 -06005056 if (subpass->pResolveAttachments) {
5057 memcpy(attachments, subpass->pResolveAttachments,
Chia-I Wu763a7492015-10-26 20:48:51 +08005058 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06005059 subpass->pResolveAttachments = attachments;
Chia-I Wu763a7492015-10-26 20:48:51 +08005060 attachments += subpass->colorAttachmentCount;
Chia-I Wuc278df82015-07-07 11:50:03 +08005061 }
5062
Chia-I Wuce532f72015-10-26 17:32:47 +08005063 if (subpass->pDepthStencilAttachment) {
5064 memcpy(attachments, subpass->pDepthStencilAttachment,
5065 sizeof(attachments[0]) * 1);
5066 subpass->pDepthStencilAttachment = attachments;
5067 attachments += 1;
5068 }
5069
Cody Northrop6de6b0b2015-08-04 11:16:41 -06005070 memcpy(attachments, subpass->pPreserveAttachments,
Chia-I Wu763a7492015-10-26 20:48:51 +08005071 sizeof(attachments[0]) * subpass->preserveAttachmentCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06005072 subpass->pPreserveAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08005073 }
Tobin Ehlis2464b882015-04-01 08:40:34 -06005074 }
Chia-I Wuc278df82015-07-07 11:50:03 +08005075 if (pCreateInfo->pDependencies) {
5076 localRPCI->pDependencies = new VkSubpassDependency[localRPCI->dependencyCount];
5077 memcpy((void*)localRPCI->pDependencies, pCreateInfo->pDependencies, localRPCI->dependencyCount*sizeof(VkSubpassDependency));
Tobin Ehlis2464b882015-04-01 08:40:34 -06005078 }
Tobin Ehlis32479352015-12-01 09:48:58 -07005079 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisad61de42015-12-02 13:53:34 -07005080 dev_data->renderPassMap[*pRenderPass] = new RENDER_PASS_NODE(localRPCI);
Michael Lentine07ff1a12015-10-15 17:07:00 -05005081 dev_data->renderPassMap[*pRenderPass]->hasSelfDependency = has_self_dependency;
Tobin Ehlis32479352015-12-01 09:48:58 -07005082 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis2464b882015-04-01 08:40:34 -06005083 }
5084 return result;
5085}
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005086// Free the renderpass shadow
5087static void deleteRenderPasses(layer_data* my_data)
5088{
5089 if (my_data->renderPassMap.size() <= 0)
5090 return;
5091 for (auto ii=my_data->renderPassMap.begin(); ii!=my_data->renderPassMap.end(); ++ii) {
Tobin Ehlisad61de42015-12-02 13:53:34 -07005092 const VkRenderPassCreateInfo* pRenderPassInfo = (*ii).second->pCreateInfo;
Michael Lentine07ff1a12015-10-15 17:07:00 -05005093 if (pRenderPassInfo->pAttachments) {
5094 delete[] pRenderPassInfo->pAttachments;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005095 }
Michael Lentine07ff1a12015-10-15 17:07:00 -05005096 if (pRenderPassInfo->pSubpasses) {
5097 for (uint32_t i=0; i<pRenderPassInfo->subpassCount; ++i) {
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005098 // Attachements are all allocated in a block, so just need to
5099 // find the first non-null one to delete
Michael Lentine07ff1a12015-10-15 17:07:00 -05005100 if (pRenderPassInfo->pSubpasses[i].pInputAttachments) {
5101 delete[] pRenderPassInfo->pSubpasses[i].pInputAttachments;
5102 } else if (pRenderPassInfo->pSubpasses[i].pColorAttachments) {
5103 delete[] pRenderPassInfo->pSubpasses[i].pColorAttachments;
5104 } else if (pRenderPassInfo->pSubpasses[i].pResolveAttachments) {
5105 delete[] pRenderPassInfo->pSubpasses[i].pResolveAttachments;
5106 } else if (pRenderPassInfo->pSubpasses[i].pPreserveAttachments) {
5107 delete[] pRenderPassInfo->pSubpasses[i].pPreserveAttachments;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005108 }
5109 }
Michael Lentine07ff1a12015-10-15 17:07:00 -05005110 delete[] pRenderPassInfo->pSubpasses;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005111 }
Michael Lentine07ff1a12015-10-15 17:07:00 -05005112 if (pRenderPassInfo->pDependencies) {
5113 delete[] pRenderPassInfo->pDependencies;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005114 }
Tobin Ehlisad61de42015-12-02 13:53:34 -07005115 delete pRenderPassInfo;
Michael Lentine07ff1a12015-10-15 17:07:00 -05005116 delete (*ii).second;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005117 }
5118 my_data->renderPassMap.clear();
5119}
Michael Lentine27b0f902015-10-12 11:30:14 -05005120
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07005121VkBool32 VerifyFramebufferAndRenderPassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
5122 VkBool32 skip_call = false;
Michael Lentine27b0f902015-10-12 11:30:14 -05005123 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5124 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Tobin Ehlisad61de42015-12-02 13:53:34 -07005125 const VkRenderPassCreateInfo* pRenderPassInfo = dev_data->renderPassMap[pRenderPassBegin->renderPass]->pCreateInfo;
Michael Lentine27b0f902015-10-12 11:30:14 -05005126 const VkFramebufferCreateInfo* pFramebufferInfo = dev_data->frameBufferMap[pRenderPassBegin->framebuffer];
5127 if (pRenderPassInfo->attachmentCount != pFramebufferInfo->attachmentCount) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005128 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 -05005129 "You cannot start a render pass using a framebuffer with a different number of attachments.");
5130 }
5131 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
5132 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
5133 const VkImage& image = dev_data->imageViewMap[image_view]->image;
5134 auto image_data = pCB->imageLayoutMap.find(image);
5135 if (image_data == pCB->imageLayoutMap.end()) {
5136 pCB->imageLayoutMap[image].initialLayout = pRenderPassInfo->pAttachments[i].initialLayout;
5137 pCB->imageLayoutMap[image].layout = pRenderPassInfo->pAttachments[i].initialLayout;
5138 } else if (pRenderPassInfo->pAttachments[i].initialLayout != image_data->second.layout) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005139 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 -05005140 "You cannot start a render pass using attachment %i where the intial layout differs from the starting layout.", i);
5141 }
5142 }
5143 return skip_call;
5144}
5145
5146void TransitionSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, const int subpass_index) {
5147 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5148 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5149 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
5150 if (render_pass_data == dev_data->renderPassMap.end()) {
5151 return;
5152 }
Tobin Ehlisad61de42015-12-02 13:53:34 -07005153 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
Michael Lentine27b0f902015-10-12 11:30:14 -05005154 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
5155 if (framebuffer_data == dev_data->frameBufferMap.end()) {
5156 return;
5157 }
5158 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
5159 const VkSubpassDescription& subpass = pRenderPassInfo->pSubpasses[subpass_index];
5160 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
5161 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pInputAttachments[j].attachment];
5162 auto image_view_data = dev_data->imageViewMap.find(image_view);
5163 if (image_view_data != dev_data->imageViewMap.end()) {
5164 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5165 if (image_layout != pCB->imageLayoutMap.end()) {
5166 image_layout->second.layout = subpass.pInputAttachments[j].layout;
5167 }
5168 }
5169 }
5170 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
5171 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pColorAttachments[j].attachment];
5172 auto image_view_data = dev_data->imageViewMap.find(image_view);
5173 if (image_view_data != dev_data->imageViewMap.end()) {
5174 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5175 if (image_layout != pCB->imageLayoutMap.end()) {
5176 image_layout->second.layout = subpass.pColorAttachments[j].layout;
5177 }
5178 }
5179 }
Michael Lentine2b9eda42015-10-28 15:55:18 -07005180 if ((subpass.pDepthStencilAttachment != NULL) &&
Mark Lobodzinskic344bef2015-10-28 13:03:56 -06005181 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
Michael Lentine27b0f902015-10-12 11:30:14 -05005182 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pDepthStencilAttachment->attachment];
5183 auto image_view_data = dev_data->imageViewMap.find(image_view);
5184 if (image_view_data != dev_data->imageViewMap.end()) {
5185 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5186 if (image_layout != pCB->imageLayoutMap.end()) {
5187 image_layout->second.layout = subpass.pDepthStencilAttachment->layout;
5188 }
5189 }
5190 }
5191}
5192
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07005193VkBool32 validatePrimaryCommandBuffer(const layer_data* my_data, const GLOBAL_CB_NODE* pCB, const std::string& cmd_name) {
5194 VkBool32 skip_call = false;
Michael Lentine2b9eda42015-10-28 15:55:18 -07005195 if (pCB->createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005196 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 -07005197 "Cannot execute command %s on a secondary command buffer.", cmd_name.c_str());
5198 }
5199 return skip_call;
5200}
5201
Michael Lentine27b0f902015-10-12 11:30:14 -05005202void TransitionFinalSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
5203 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5204 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5205 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
5206 if (render_pass_data == dev_data->renderPassMap.end()) {
5207 return;
5208 }
Tobin Ehlisad61de42015-12-02 13:53:34 -07005209 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
Michael Lentine27b0f902015-10-12 11:30:14 -05005210 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
5211 if (framebuffer_data == dev_data->frameBufferMap.end()) {
5212 return;
5213 }
5214 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
5215 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
5216 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
5217 auto image_view_data = dev_data->imageViewMap.find(image_view);
5218 if (image_view_data != dev_data->imageViewMap.end()) {
5219 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5220 if (image_layout != pCB->imageLayoutMap.end()) {
5221 image_layout->second.layout = pRenderPassInfo->pAttachments[i].finalLayout;
5222 }
5223 }
5224 }
5225}
5226
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005227VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, VkSubpassContents contents)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005228{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005229 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08005230 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5231 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005232 if (pCB) {
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06005233 if (pRenderPassBegin && pRenderPassBegin->renderPass) {
Mark Lobodzinskic344bef2015-10-28 13:03:56 -06005234 skipCall |= VerifyFramebufferAndRenderPassLayouts(commandBuffer, pRenderPassBegin);
Tobin Ehlis42d440c2015-10-20 17:06:16 -06005235 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBeginRenderPass");
Michael Lentine2b9eda42015-10-28 15:55:18 -07005236 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdBeginRenderPass");
Tobin Ehlis42d440c2015-10-20 17:06:16 -06005237 skipCall |= addCmd(dev_data, pCB, CMD_BEGINRENDERPASS);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06005238 pCB->activeRenderPass = pRenderPassBegin->renderPass;
Michael Lentine27b0f902015-10-12 11:30:14 -05005239 // This is a shallow copy as that is all that is needed for now
5240 pCB->activeRenderPassBeginInfo = *pRenderPassBegin;
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06005241 pCB->activeSubpass = 0;
5242 pCB->framebuffer = pRenderPassBegin->framebuffer;
5243 if (pCB->lastBoundPipeline) {
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005244 skipCall |= validatePipelineState(dev_data, pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06005245 }
Tobin Ehlise4076782015-06-24 15:53:07 -06005246 } else {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005247 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 -06005248 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tony Barbourb9f82ba2015-04-06 11:09:26 -06005249 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005250 }
Mark Lobodzinskic344bef2015-10-28 13:03:56 -06005251 if (VK_FALSE == skipCall) {
Chia-I Wu1f851912015-10-27 18:04:07 +08005252 dev_data->device_dispatch_table->CmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents);
Mark Lobodzinskic344bef2015-10-28 13:03:56 -06005253 // This is a shallow copy as that is all that is needed for now
5254 dev_data->renderPassBeginInfo = *pRenderPassBegin;
5255 dev_data->currentSubpass = 0;
5256 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005257}
5258
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005259VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents)
Chia-I Wuc278df82015-07-07 11:50:03 +08005260{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005261 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08005262 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5263 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Michael Lentine27b0f902015-10-12 11:30:14 -05005264 TransitionSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo, ++dev_data->currentSubpass);
Chia-I Wuc278df82015-07-07 11:50:03 +08005265 if (pCB) {
Michael Lentine2b9eda42015-10-28 15:55:18 -07005266 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdNextSubpass");
Tobin Ehlis42d440c2015-10-20 17:06:16 -06005267 skipCall |= addCmd(dev_data, pCB, CMD_NEXTSUBPASS);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06005268 pCB->activeSubpass++;
Tony Barbourcbc0fa82015-12-15 10:24:45 -07005269 TransitionSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo, pCB->activeSubpass);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06005270 if (pCB->lastBoundPipeline) {
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005271 skipCall |= validatePipelineState(dev_data, pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Chia-I Wuc278df82015-07-07 11:50:03 +08005272 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06005273 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdNextSubpass");
Chia-I Wuc278df82015-07-07 11:50:03 +08005274 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005275 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08005276 dev_data->device_dispatch_table->CmdNextSubpass(commandBuffer, contents);
Chia-I Wuc278df82015-07-07 11:50:03 +08005277}
5278
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005279VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndRenderPass(VkCommandBuffer commandBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005280{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005281 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08005282 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5283 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Michael Lentine27b0f902015-10-12 11:30:14 -05005284 TransitionFinalSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005285 if (pCB) {
Michael Lentine2b9eda42015-10-28 15:55:18 -07005286 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdEndRenderpass");
Michael Lentine2b9eda42015-10-28 15:55:18 -07005287 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdEndRenderPass");
Tobin Ehlis42d440c2015-10-20 17:06:16 -06005288 skipCall |= addCmd(dev_data, pCB, CMD_ENDRENDERPASS);
Michael Lentine27b0f902015-10-12 11:30:14 -05005289 TransitionFinalSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06005290 pCB->activeRenderPass = 0;
5291 pCB->activeSubpass = 0;
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08005292 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005293 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08005294 dev_data->device_dispatch_table->CmdEndRenderPass(commandBuffer);
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08005295}
5296
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005297VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount, const VkCommandBuffer* pCommandBuffers)
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08005298{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005299 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08005300 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5301 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08005302 if (pCB) {
Tobin Ehlis5f728d32015-09-17 14:18:16 -06005303 GLOBAL_CB_NODE* pSubCB = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08005304 for (uint32_t i=0; i<commandBuffersCount; i++) {
5305 pSubCB = getCBNode(dev_data, pCommandBuffers[i]);
Tobin Ehlis5f728d32015-09-17 14:18:16 -06005306 if (!pSubCB) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005307 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 +08005308 "vkCmdExecuteCommands() called w/ invalid Cmd Buffer %p in element %u of pCommandBuffers array.", (void*)pCommandBuffers[i], i);
5309 } else if (VK_COMMAND_BUFFER_LEVEL_PRIMARY == pSubCB->createInfo.level) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005310 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 +08005311 "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 -06005312 }
5313 }
Michael Lentine2b9eda42015-10-28 15:55:18 -07005314 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdExecuteComands");
Tobin Ehlis42d440c2015-10-20 17:06:16 -06005315 skipCall |= addCmd(dev_data, pCB, CMD_EXECUTECOMMANDS);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005316 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005317 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08005318 dev_data->device_dispatch_table->CmdExecuteCommands(commandBuffer, commandBuffersCount, pCommandBuffers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005319}
5320
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07005321VkBool32 ValidateMapImageLayouts(VkDevice device, VkDeviceMemory mem) {
5322 VkBool32 skip_call = false;
Michael Lentineee4ad4d2015-10-23 12:41:44 -07005323 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5324 auto mem_data = dev_data->memImageMap.find(mem);
5325 if (mem_data != dev_data->memImageMap.end()) {
5326 auto image_data = dev_data->imageLayoutMap.find(mem_data->second);
5327 if (image_data != dev_data->imageLayoutMap.end()) {
5328 if (image_data->second->layout != VK_IMAGE_LAYOUT_PREINITIALIZED && image_data->second->layout != VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005329 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 -07005330 "Cannot map an image with layout %d. Only GENERAL or PREINITIALIZED are supported.", image_data->second->layout);
5331 }
5332 }
5333 }
5334 return skip_call;
5335}
5336
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005337VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkMapMemory(
Michael Lentineee4ad4d2015-10-23 12:41:44 -07005338 VkDevice device,
5339 VkDeviceMemory mem,
5340 VkDeviceSize offset,
5341 VkDeviceSize size,
5342 VkFlags flags,
5343 void **ppData)
5344{
5345 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski78940a42015-11-30 16:48:53 -07005346
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07005347 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski78940a42015-11-30 16:48:53 -07005348#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
5349 skip_call = ValidateMapImageLayouts(device, mem);
5350#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5351
Michael Lentineee4ad4d2015-10-23 12:41:44 -07005352 if (VK_FALSE == skip_call) {
5353 return dev_data->device_dispatch_table->MapMemory(device, mem, offset, size, flags, ppData);
5354 }
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07005355 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentineee4ad4d2015-10-23 12:41:44 -07005356}
5357
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005358VKAPI_ATTR VkResult VKAPI_CALL vkBindImageMemory(
Michael Lentineee4ad4d2015-10-23 12:41:44 -07005359 VkDevice device,
5360 VkImage image,
5361 VkDeviceMemory mem,
5362 VkDeviceSize memOffset)
5363{
5364 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5365 VkResult result = dev_data->device_dispatch_table->BindImageMemory(device, image, mem, memOffset);
5366 loader_platform_thread_lock_mutex(&globalLock);
5367 dev_data->memImageMap[mem] = image;
5368 loader_platform_thread_unlock_mutex(&globalLock);
5369 return result;
5370}
5371
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005372VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(
Michael Lentine27b0f902015-10-12 11:30:14 -05005373 VkDevice device,
5374 const VkSwapchainCreateInfoKHR *pCreateInfo,
Ian Elliottc623ba52015-11-20 14:13:17 -07005375 const VkAllocationCallbacks *pAllocator,
Michael Lentine27b0f902015-10-12 11:30:14 -05005376 VkSwapchainKHR *pSwapchain)
5377{
5378 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliottc623ba52015-11-20 14:13:17 -07005379 VkResult result = dev_data->device_dispatch_table->CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
Michael Lentine27b0f902015-10-12 11:30:14 -05005380
5381 if (VK_SUCCESS == result) {
5382 SWAPCHAIN_NODE *swapchain_data = new SWAPCHAIN_NODE;
5383 loader_platform_thread_lock_mutex(&globalLock);
5384 dev_data->device_extensions.swapchainMap[*pSwapchain] = swapchain_data;
5385 loader_platform_thread_unlock_mutex(&globalLock);
5386 }
5387
5388 return result;
5389}
5390
Ian Elliottc623ba52015-11-20 14:13:17 -07005391VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR(
Michael Lentine27b0f902015-10-12 11:30:14 -05005392 VkDevice device,
Ian Elliottc623ba52015-11-20 14:13:17 -07005393 VkSwapchainKHR swapchain,
5394 const VkAllocationCallbacks *pAllocator)
Michael Lentine27b0f902015-10-12 11:30:14 -05005395{
5396 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentine27b0f902015-10-12 11:30:14 -05005397
5398 loader_platform_thread_lock_mutex(&globalLock);
5399 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(swapchain);
5400 if (swapchain_data != dev_data->device_extensions.swapchainMap.end()) {
5401 if (swapchain_data->second->images.size() > 0) {
5402 for (auto swapchain_image : swapchain_data->second->images) {
5403 auto image_item = dev_data->imageLayoutMap.find(swapchain_image);
5404 if (image_item != dev_data->imageLayoutMap.end())
5405 dev_data->imageLayoutMap.erase(image_item);
5406 }
5407 }
5408 delete swapchain_data->second;
5409 dev_data->device_extensions.swapchainMap.erase(swapchain);
5410 }
5411 loader_platform_thread_unlock_mutex(&globalLock);
Ian Elliottc623ba52015-11-20 14:13:17 -07005412 return dev_data->device_dispatch_table->DestroySwapchainKHR(device, swapchain, pAllocator);
Michael Lentine27b0f902015-10-12 11:30:14 -05005413}
5414
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005415VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR(
Michael Lentine27b0f902015-10-12 11:30:14 -05005416 VkDevice device,
5417 VkSwapchainKHR swapchain,
5418 uint32_t* pCount,
5419 VkImage* pSwapchainImages)
5420{
5421 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5422 VkResult result = dev_data->device_dispatch_table->GetSwapchainImagesKHR(device, swapchain, pCount, pSwapchainImages);
5423
5424 if (result == VK_SUCCESS && pSwapchainImages != NULL) {
5425 // This should never happen and is checked by param checker.
5426 if (!pCount) return result;
5427 for (uint32_t i = 0; i < *pCount; ++i) {
5428 IMAGE_NODE* image_node = new IMAGE_NODE;
5429 image_node->layout = VK_IMAGE_LAYOUT_UNDEFINED;
5430 loader_platform_thread_lock_mutex(&globalLock);
5431 dev_data->device_extensions.swapchainMap[swapchain]->images.push_back(pSwapchainImages[i]);
5432 dev_data->imageLayoutMap[pSwapchainImages[i]] = image_node;
5433 loader_platform_thread_unlock_mutex(&globalLock);
5434 }
5435 }
5436 return result;
5437}
5438
Ian Elliottc623ba52015-11-20 14:13:17 -07005439VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo)
Michael Lentine27b0f902015-10-12 11:30:14 -05005440{
5441 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Courtney Goeltzenleuchterda665bf2015-12-16 16:07:01 -07005442 VkBool32 skip_call = false;
Michael Lentine27b0f902015-10-12 11:30:14 -05005443
Mark Lobodzinski78940a42015-11-30 16:48:53 -07005444#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentine27b0f902015-10-12 11:30:14 -05005445 if (pPresentInfo) {
5446 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
Ian Elliottc623ba52015-11-20 14:13:17 -07005447 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(pPresentInfo->pSwapchains[i]);
5448 if (swapchain_data != dev_data->device_extensions.swapchainMap.end() && pPresentInfo->pImageIndices[i] < swapchain_data->second->images.size()) {
5449 VkImage image = swapchain_data->second->images[pPresentInfo->pImageIndices[i]];
Michael Lentine27b0f902015-10-12 11:30:14 -05005450 auto image_data = dev_data->imageLayoutMap.find(image);
5451 if (image_data != dev_data->imageLayoutMap.end()) {
Ian Elliottc623ba52015-11-20 14:13:17 -07005452 if (image_data->second->layout != VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005453 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 -05005454 "Images passed to present must be in layout PRESENT_SOURCE_KHR but is in %d", image_data->second->layout);
5455 }
5456 }
5457 }
5458 }
5459 }
Mark Lobodzinski78940a42015-11-30 16:48:53 -07005460#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentine27b0f902015-10-12 11:30:14 -05005461
5462 if (VK_FALSE == skip_call)
5463 return dev_data->device_dispatch_table->QueuePresentKHR(queue, pPresentInfo);
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -07005464 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine27b0f902015-10-12 11:30:14 -05005465}
5466
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005467VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(
5468 VkInstance instance,
5469 const VkDebugReportCallbackCreateInfoEXT* pCreateInfo,
5470 const VkAllocationCallbacks* pAllocator,
5471 VkDebugReportCallbackEXT* pMsgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005472{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005473 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07005474 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005475 VkResult res = pTable->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisc91330b2015-06-16 09:04:30 -06005476 if (VK_SUCCESS == res) {
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07005477 res = layer_create_msg_callback(my_data->report_data, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisc91330b2015-06-16 09:04:30 -06005478 }
5479 return res;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005480}
5481
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005482VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07005483 VkInstance instance,
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005484 VkDebugReportCallbackEXT msgCallback,
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07005485 const VkAllocationCallbacks* pAllocator)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005486{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005487 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07005488 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005489 pTable->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -07005490 layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005491}
5492
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005493VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDebugReportMessageEXT(
Courtney Goeltzenleuchter5a424ce2015-12-01 14:10:55 -07005494 VkInstance instance,
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005495 VkDebugReportFlagsEXT flags,
5496 VkDebugReportObjectTypeEXT objType,
Courtney Goeltzenleuchter5a424ce2015-12-01 14:10:55 -07005497 uint64_t object,
5498 size_t location,
5499 int32_t msgCode,
5500 const char* pLayerPrefix,
5501 const char* pMsg)
5502{
5503 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005504 my_data->instance_dispatch_table->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg);
Courtney Goeltzenleuchter5a424ce2015-12-01 14:10:55 -07005505}
5506
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005507VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerBegin(VkCommandBuffer commandBuffer, const char* pMarker)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005508{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005509 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08005510 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5511 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005512 if (!dev_data->device_extensions.debug_marker_enabled) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005513 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 -06005514 "Attempt to use CmdDbgMarkerBegin but extension disabled!");
Jon Ashburn6f8cd632015-06-01 09:37:38 -06005515 return;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06005516 } else if (pCB) {
Tobin Ehlis32479352015-12-01 09:48:58 -07005517
Tobin Ehlis42d440c2015-10-20 17:06:16 -06005518 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKERBEGIN);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005519 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005520 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08005521 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerBegin(commandBuffer, pMarker);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005522}
5523
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005524VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerEnd(VkCommandBuffer commandBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005525{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005526 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08005527 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5528 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005529 if (!dev_data->device_extensions.debug_marker_enabled) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005530 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 -06005531 "Attempt to use CmdDbgMarkerEnd but extension disabled!");
Jon Ashburn6f8cd632015-06-01 09:37:38 -06005532 return;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06005533 } else if (pCB) {
Tobin Ehlis32479352015-12-01 09:48:58 -07005534
Tobin Ehlis42d440c2015-10-20 17:06:16 -06005535 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKEREND);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005536 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005537 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08005538 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerEnd(commandBuffer);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06005539}
5540
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005541VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005542{
Jon Ashburn1245cec2015-05-18 13:20:15 -06005543 if (dev == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005544 return NULL;
Jon Ashburne0fa2282015-05-20 09:00:28 -06005545
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005546 layer_data *dev_data;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005547 /* loader uses this to force layer initialization; device object is wrapped */
5548 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005549 VkBaseLayerObject* wrapped_dev = (VkBaseLayerObject*) dev;
5550 dev_data = get_my_data_ptr(get_dispatch_key(wrapped_dev->baseObject), layer_data_map);
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005551 dev_data->device_dispatch_table = new VkLayerDispatchTable;
5552 layer_initialize_dispatch_table(dev_data->device_dispatch_table, wrapped_dev);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005553 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005554 }
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005555 dev_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map);
Courtney Goeltzenleuchterbe637992015-06-25 18:01:43 -06005556 if (!strcmp(funcName, "vkCreateDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005557 return (PFN_vkVoidFunction) vkCreateDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005558 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005559 return (PFN_vkVoidFunction) vkDestroyDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005560 if (!strcmp(funcName, "vkQueueSubmit"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005561 return (PFN_vkVoidFunction) vkQueueSubmit;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005562 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005563 return (PFN_vkVoidFunction) vkDestroyInstance;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005564 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005565 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005566 if (!strcmp(funcName, "vkDestroyFence"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005567 return (PFN_vkVoidFunction) vkDestroyFence;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005568 if (!strcmp(funcName, "vkDestroySemaphore"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005569 return (PFN_vkVoidFunction) vkDestroySemaphore;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005570 if (!strcmp(funcName, "vkDestroyEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005571 return (PFN_vkVoidFunction) vkDestroyEvent;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005572 if (!strcmp(funcName, "vkDestroyQueryPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005573 return (PFN_vkVoidFunction) vkDestroyQueryPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005574 if (!strcmp(funcName, "vkDestroyBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005575 return (PFN_vkVoidFunction) vkDestroyBuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005576 if (!strcmp(funcName, "vkDestroyBufferView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005577 return (PFN_vkVoidFunction) vkDestroyBufferView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005578 if (!strcmp(funcName, "vkDestroyImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005579 return (PFN_vkVoidFunction) vkDestroyImage;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005580 if (!strcmp(funcName, "vkDestroyImageView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005581 return (PFN_vkVoidFunction) vkDestroyImageView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005582 if (!strcmp(funcName, "vkDestroyShaderModule"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005583 return (PFN_vkVoidFunction) vkDestroyShaderModule;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005584 if (!strcmp(funcName, "vkDestroyPipeline"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005585 return (PFN_vkVoidFunction) vkDestroyPipeline;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005586 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005587 return (PFN_vkVoidFunction) vkDestroyPipelineLayout;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005588 if (!strcmp(funcName, "vkDestroySampler"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005589 return (PFN_vkVoidFunction) vkDestroySampler;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005590 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005591 return (PFN_vkVoidFunction) vkDestroyDescriptorSetLayout;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005592 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005593 return (PFN_vkVoidFunction) vkDestroyDescriptorPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005594 if (!strcmp(funcName, "vkDestroyFramebuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005595 return (PFN_vkVoidFunction) vkDestroyFramebuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005596 if (!strcmp(funcName, "vkDestroyRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005597 return (PFN_vkVoidFunction) vkDestroyRenderPass;
Tobin Ehlisb46be812015-10-23 16:00:08 -06005598 if (!strcmp(funcName, "vkCreateBuffer"))
5599 return (PFN_vkVoidFunction) vkCreateBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005600 if (!strcmp(funcName, "vkCreateBufferView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005601 return (PFN_vkVoidFunction) vkCreateBufferView;
Tobin Ehlisb46be812015-10-23 16:00:08 -06005602 if (!strcmp(funcName, "vkCreateImage"))
5603 return (PFN_vkVoidFunction) vkCreateImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005604 if (!strcmp(funcName, "vkCreateImageView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005605 return (PFN_vkVoidFunction) vkCreateImageView;
Jon Ashburn0d60d272015-07-09 15:02:25 -06005606 if (!strcmp(funcName, "CreatePipelineCache"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005607 return (PFN_vkVoidFunction) vkCreatePipelineCache;
Jon Ashburn0d60d272015-07-09 15:02:25 -06005608 if (!strcmp(funcName, "DestroyPipelineCache"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005609 return (PFN_vkVoidFunction) vkDestroyPipelineCache;
Jon Ashburn0d60d272015-07-09 15:02:25 -06005610 if (!strcmp(funcName, "GetPipelineCacheData"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005611 return (PFN_vkVoidFunction) vkGetPipelineCacheData;
Jon Ashburn0d60d272015-07-09 15:02:25 -06005612 if (!strcmp(funcName, "MergePipelineCaches"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005613 return (PFN_vkVoidFunction) vkMergePipelineCaches;
Jon Ashburn0d60d272015-07-09 15:02:25 -06005614 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005615 return (PFN_vkVoidFunction) vkCreateGraphicsPipelines;
Mark Lobodzinski2adea752015-11-10 15:25:01 -07005616 if (!strcmp(funcName, "vkCreateComputePipelines"))
5617 return (PFN_vkVoidFunction) vkCreateComputePipelines;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005618 if (!strcmp(funcName, "vkCreateSampler"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005619 return (PFN_vkVoidFunction) vkCreateSampler;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005620 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005621 return (PFN_vkVoidFunction) vkCreateDescriptorSetLayout;
Mark Lobodzinski556f7212015-04-17 14:11:39 -05005622 if (!strcmp(funcName, "vkCreatePipelineLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005623 return (PFN_vkVoidFunction) vkCreatePipelineLayout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005624 if (!strcmp(funcName, "vkCreateDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005625 return (PFN_vkVoidFunction) vkCreateDescriptorPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005626 if (!strcmp(funcName, "vkResetDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005627 return (PFN_vkVoidFunction) vkResetDescriptorPool;
Chia-I Wu1f851912015-10-27 18:04:07 +08005628 if (!strcmp(funcName, "vkAllocateDescriptorSets"))
5629 return (PFN_vkVoidFunction) vkAllocateDescriptorSets;
Tobin Ehlis3c543112015-10-08 13:13:50 -06005630 if (!strcmp(funcName, "vkFreeDescriptorSets"))
5631 return (PFN_vkVoidFunction) vkFreeDescriptorSets;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08005632 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005633 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07005634 if (!strcmp(funcName, "vkCreateCommandPool"))
5635 return (PFN_vkVoidFunction) vkCreateCommandPool;
5636 if (!strcmp(funcName, "vkDestroyCommandPool"))
5637 return (PFN_vkVoidFunction) vkDestroyCommandPool;
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07005638 if (!strcmp(funcName, "vkResetCommandPool"))
5639 return (PFN_vkVoidFunction) vkResetCommandPool;
Chia-I Wu1f851912015-10-27 18:04:07 +08005640 if (!strcmp(funcName, "vkAllocateCommandBuffers"))
5641 return (PFN_vkVoidFunction) vkAllocateCommandBuffers;
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07005642 if (!strcmp(funcName, "vkFreeCommandBuffers"))
5643 return (PFN_vkVoidFunction) vkFreeCommandBuffers;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005644 if (!strcmp(funcName, "vkBeginCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005645 return (PFN_vkVoidFunction) vkBeginCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005646 if (!strcmp(funcName, "vkEndCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005647 return (PFN_vkVoidFunction) vkEndCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005648 if (!strcmp(funcName, "vkResetCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005649 return (PFN_vkVoidFunction) vkResetCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005650 if (!strcmp(funcName, "vkCmdBindPipeline"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005651 return (PFN_vkVoidFunction) vkCmdBindPipeline;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06005652 if (!strcmp(funcName, "vkCmdSetViewport"))
5653 return (PFN_vkVoidFunction) vkCmdSetViewport;
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06005654 if (!strcmp(funcName, "vkCmdSetScissor"))
5655 return (PFN_vkVoidFunction) vkCmdSetScissor;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06005656 if (!strcmp(funcName, "vkCmdSetLineWidth"))
5657 return (PFN_vkVoidFunction) vkCmdSetLineWidth;
5658 if (!strcmp(funcName, "vkCmdSetDepthBias"))
5659 return (PFN_vkVoidFunction) vkCmdSetDepthBias;
5660 if (!strcmp(funcName, "vkCmdSetBlendConstants"))
5661 return (PFN_vkVoidFunction) vkCmdSetBlendConstants;
5662 if (!strcmp(funcName, "vkCmdSetDepthBounds"))
5663 return (PFN_vkVoidFunction) vkCmdSetDepthBounds;
5664 if (!strcmp(funcName, "vkCmdSetStencilCompareMask"))
5665 return (PFN_vkVoidFunction) vkCmdSetStencilCompareMask;
5666 if (!strcmp(funcName, "vkCmdSetStencilWriteMask"))
5667 return (PFN_vkVoidFunction) vkCmdSetStencilWriteMask;
5668 if (!strcmp(funcName, "vkCmdSetStencilReference"))
5669 return (PFN_vkVoidFunction) vkCmdSetStencilReference;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005670 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005671 return (PFN_vkVoidFunction) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06005672 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005673 return (PFN_vkVoidFunction) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005674 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005675 return (PFN_vkVoidFunction) vkCmdBindIndexBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005676 if (!strcmp(funcName, "vkCmdDraw"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005677 return (PFN_vkVoidFunction) vkCmdDraw;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005678 if (!strcmp(funcName, "vkCmdDrawIndexed"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005679 return (PFN_vkVoidFunction) vkCmdDrawIndexed;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005680 if (!strcmp(funcName, "vkCmdDrawIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005681 return (PFN_vkVoidFunction) vkCmdDrawIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005682 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005683 return (PFN_vkVoidFunction) vkCmdDrawIndexedIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005684 if (!strcmp(funcName, "vkCmdDispatch"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005685 return (PFN_vkVoidFunction) vkCmdDispatch;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005686 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005687 return (PFN_vkVoidFunction) vkCmdDispatchIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005688 if (!strcmp(funcName, "vkCmdCopyBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005689 return (PFN_vkVoidFunction) vkCmdCopyBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005690 if (!strcmp(funcName, "vkCmdCopyImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005691 return (PFN_vkVoidFunction) vkCmdCopyImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005692 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005693 return (PFN_vkVoidFunction) vkCmdCopyBufferToImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005694 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005695 return (PFN_vkVoidFunction) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005696 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005697 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005698 if (!strcmp(funcName, "vkCmdFillBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005699 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005700 if (!strcmp(funcName, "vkCmdClearColorImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005701 return (PFN_vkVoidFunction) vkCmdClearColorImage;
Chris Forbes2951d7d2015-06-22 17:21:59 +12005702 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005703 return (PFN_vkVoidFunction) vkCmdClearDepthStencilImage;
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06005704 if (!strcmp(funcName, "vkCmdClearAttachments"))
5705 return (PFN_vkVoidFunction) vkCmdClearAttachments;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005706 if (!strcmp(funcName, "vkCmdResolveImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005707 return (PFN_vkVoidFunction) vkCmdResolveImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005708 if (!strcmp(funcName, "vkCmdSetEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005709 return (PFN_vkVoidFunction) vkCmdSetEvent;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005710 if (!strcmp(funcName, "vkCmdResetEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005711 return (PFN_vkVoidFunction) vkCmdResetEvent;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005712 if (!strcmp(funcName, "vkCmdWaitEvents"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005713 return (PFN_vkVoidFunction) vkCmdWaitEvents;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005714 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005715 return (PFN_vkVoidFunction) vkCmdPipelineBarrier;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005716 if (!strcmp(funcName, "vkCmdBeginQuery"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005717 return (PFN_vkVoidFunction) vkCmdBeginQuery;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005718 if (!strcmp(funcName, "vkCmdEndQuery"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005719 return (PFN_vkVoidFunction) vkCmdEndQuery;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005720 if (!strcmp(funcName, "vkCmdResetQueryPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005721 return (PFN_vkVoidFunction) vkCmdResetQueryPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005722 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005723 return (PFN_vkVoidFunction) vkCmdWriteTimestamp;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005724 if (!strcmp(funcName, "vkCreateFramebuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005725 return (PFN_vkVoidFunction) vkCreateFramebuffer;
Tobin Ehlis32479352015-12-01 09:48:58 -07005726 if (!strcmp(funcName, "vkCreateShaderModule"))
5727 return (PFN_vkVoidFunction) vkCreateShaderModule;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005728 if (!strcmp(funcName, "vkCreateRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005729 return (PFN_vkVoidFunction) vkCreateRenderPass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005730 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005731 return (PFN_vkVoidFunction) vkCmdBeginRenderPass;
Chia-I Wuc278df82015-07-07 11:50:03 +08005732 if (!strcmp(funcName, "vkCmdNextSubpass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005733 return (PFN_vkVoidFunction) vkCmdNextSubpass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005734 if (!strcmp(funcName, "vkCmdEndRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005735 return (PFN_vkVoidFunction) vkCmdEndRenderPass;
Tobin Ehlis5f728d32015-09-17 14:18:16 -06005736 if (!strcmp(funcName, "vkCmdExecuteCommands"))
5737 return (PFN_vkVoidFunction) vkCmdExecuteCommands;
Michael Lentineee4ad4d2015-10-23 12:41:44 -07005738 if (!strcmp(funcName, "vkMapMemory"))
5739 return (PFN_vkVoidFunction) vkMapMemory;
Jon Ashburn6f8cd632015-06-01 09:37:38 -06005740
Michael Lentine27b0f902015-10-12 11:30:14 -05005741 if (dev_data->device_extensions.wsi_enabled)
5742 {
5743 if (!strcmp(funcName, "vkCreateSwapchainKHR"))
5744 return (PFN_vkVoidFunction) vkCreateSwapchainKHR;
5745 if (!strcmp(funcName, "vkDestroySwapchainKHR"))
5746 return (PFN_vkVoidFunction) vkDestroySwapchainKHR;
5747 if (!strcmp(funcName, "vkGetSwapchainImagesKHR"))
5748 return (PFN_vkVoidFunction) vkGetSwapchainImagesKHR;
5749 if (!strcmp(funcName, "vkQueuePresentKHR"))
5750 return (PFN_vkVoidFunction) vkQueuePresentKHR;
5751 }
5752
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005753 VkLayerDispatchTable* pTable = dev_data->device_dispatch_table;
5754 if (dev_data->device_extensions.debug_marker_enabled)
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005755 {
Jon Ashburn7e07faf2015-06-18 15:02:58 -06005756 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005757 return (PFN_vkVoidFunction) vkCmdDbgMarkerBegin;
Jon Ashburn7e07faf2015-06-18 15:02:58 -06005758 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005759 return (PFN_vkVoidFunction) vkCmdDbgMarkerEnd;
Jon Ashburn6f8cd632015-06-01 09:37:38 -06005760 }
5761 {
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005762 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005763 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005764 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburn79b78ac2015-05-05 14:22:52 -06005765 }
5766}
5767
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005768VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06005769{
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005770 PFN_vkVoidFunction fptr;
Jon Ashburn79b78ac2015-05-05 14:22:52 -06005771 if (instance == NULL)
5772 return NULL;
5773
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005774 layer_data* my_data;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005775 /* loader uses this to force layer initialization; instance object is wrapped */
5776 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005777 VkBaseLayerObject* wrapped_inst = (VkBaseLayerObject*) instance;
5778 my_data = get_my_data_ptr(get_dispatch_key(wrapped_inst->baseObject), layer_data_map);
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005779 my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
5780 layer_init_instance_dispatch_table(my_data->instance_dispatch_table, wrapped_inst);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005781 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005782 }
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06005783 if (!strcmp(funcName, "vkCreateInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005784 return (PFN_vkVoidFunction) vkCreateInstance;
Jon Ashburne0fa2282015-05-20 09:00:28 -06005785 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005786 return (PFN_vkVoidFunction) vkDestroyInstance;
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -06005787 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
5788 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
5789 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
5790 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
5791 if (!strcmp(funcName, "vkEnumerateDeviceLayerProperties"))
5792 return (PFN_vkVoidFunction) vkEnumerateDeviceLayerProperties;
5793 if (!strcmp(funcName, "vkEnumerateDeviceExtensionProperties"))
5794 return (PFN_vkVoidFunction) vkEnumerateDeviceExtensionProperties;
Courtney Goeltzenleuchtercc899fe2015-06-01 14:33:14 -06005795
Tobin Ehlis32479352015-12-01 09:48:58 -07005796 my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06005797 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchtercc899fe2015-06-01 14:33:14 -06005798 if (fptr)
5799 return fptr;
5800
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005801 {
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005802 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005803 if (pTable->GetInstanceProcAddr == NULL)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06005804 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005805 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005806 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005807}