blob: 4b5daa842907d77e5f232ef532646cf691362b71 [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 Goeltzenleuchter1781b1c2015-10-05 15:58:38 -060090 std::vector<VkDbgMsgCallback> 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 Goeltzenleuchterf8fe1282015-11-25 10:30:56 -0700585 log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT, VK_OBJECT_TYPE_DEVICE, /*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);
594 for (int offset = 0; offset < num_locations; offset++) {
595 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 Goeltzenleuchterf8fe1282015-11-25 10:30:56 -0700657 log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE, /*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 Goeltzenleuchterf8fe1282015-11-25 10:30:56 -0700703 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT, VK_OBJECT_TYPE_DEVICE, /*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 Goeltzenleuchterf8fe1282015-11-25 10:30:56 -0700710 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE, /*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 Goeltzenleuchterf8fe1282015-11-25 10:30:56 -0700726 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE, /*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 Goeltzenleuchterf8fe1282015-11-25 10:30:56 -0700834 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE, /*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 Goeltzenleuchterf8fe1282015-11-25 10:30:56 -0700875 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT, VK_OBJECT_TYPE_DEVICE, /*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 Goeltzenleuchterf8fe1282015-11-25 10:30:56 -0700882 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE, /*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 Goeltzenleuchterf8fe1282015-11-25 10:30:56 -0700896 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE, /*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 Goeltzenleuchterf8fe1282015-11-25 10:30:56 -0700934 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT, VK_OBJECT_TYPE_DEVICE, /*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 Goeltzenleuchterf8fe1282015-11-25 10:30:56 -0700941 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE, /*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 Goeltzenleuchterf8fe1282015-11-25 10:30:56 -0700955 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE, /*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
Tobin Ehlis42d440c2015-10-20 17:06:16 -06001043 return log_msg(my_data->report_data, msg_flags, VK_OBJECT_TYPE_COMMAND_BUFFER, 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 Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07001077 result = validate_status(my_data, pCB, CBSTATUS_NONE, CBSTATUS_VIEWPORT_SET, CBSTATUS_VIEWPORT_SET, VK_DEBUG_REPORT_ERROR_BIT, 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, 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, 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, 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, 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, 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, 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, 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, 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 Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07001087 result |= validate_status(my_data, pCB, CBSTATUS_NONE, CBSTATUS_INDEX_BUFFER_BOUND, CBSTATUS_INDEX_BUFFER_BOUND, VK_DEBUG_REPORT_ERROR_BIT, 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 }
1111 uint32_t descriptorCount = pLayoutNode->descriptorTypes.size();
1112 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
1118 for (uint32_t i=0; i<descriptorCount; ++i) {
1119 // 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
Tobin Ehlis32479352015-12-01 09:48:58 -07001138static bool
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;
1152 bool pass = true;
1153
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 Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07001160 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT, VK_OBJECT_TYPE_DEVICE, /*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 Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07001187 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE, /*dev*/0, 0,
Tobin Ehlis32479352015-12-01 09:48:58 -07001188 SHADER_CHECKER_MISSING_DESCRIPTOR, "SC",
1189 "Shader uses descriptor slot %u.%u (used as type `%s`) but not declared in pipeline layout",
1190 it->first.first, it->first.second, type_name)) {
1191 pass = false;
1192 }
1193 }
1194 }
1195 }
1196 }
1197 }
1198
1199 if (pCreateInfo->renderPass != VK_NULL_HANDLE)
Tobin Ehlisad61de42015-12-02 13:53:34 -07001200 rp = my_data->renderPassMap[pCreateInfo->renderPass];
Tobin Ehlis32479352015-12-01 09:48:58 -07001201
1202 vi = pCreateInfo->pVertexInputState;
1203
1204 if (vi) {
1205 pass = validate_vi_consistency(my_data, dev, vi) && pass;
1206 }
1207
1208 if (shaders[vertex_stage]) {
1209 pass = validate_vi_against_vs_inputs(my_data, dev, vi, shaders[vertex_stage]) && pass;
1210 }
1211
1212 /* TODO: enforce rules about present combinations of shaders */
1213 int producer = get_shader_stage_id(VK_SHADER_STAGE_VERTEX_BIT);
1214 int consumer = get_shader_stage_id(VK_SHADER_STAGE_GEOMETRY_BIT);
1215
1216 while (!shaders[producer] && producer != fragment_stage) {
1217 producer++;
1218 consumer++;
1219 }
1220
1221 for (; producer != fragment_stage && consumer <= fragment_stage; consumer++) {
1222 assert(shaders[producer]);
1223 if (shaders[consumer]) {
1224 pass = validate_interface_between_stages(my_data, dev,
1225 shaders[producer], shader_stage_attribs[producer].name,
1226 shaders[consumer], shader_stage_attribs[consumer].name,
1227 shader_stage_attribs[consumer].arrayed_input) && pass;
1228
1229 producer = consumer;
1230 }
1231 }
1232
1233 if (shaders[fragment_stage] && rp) {
1234 pass = validate_fs_outputs_against_render_pass(my_data, dev, shaders[fragment_stage], rp, pCreateInfo->subpass) && pass;
1235 }
1236
1237 delete shaders;
1238
1239 return pass;
1240}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001241
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06001242// Validate overall state at the time of a draw call
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06001243static VkBool32 validate_draw_state(layer_data* my_data, GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06001244 // First check flag states
Tobin Ehlis42d440c2015-10-20 17:06:16 -06001245 VkBool32 result = validate_draw_state_flags(my_data, pCB, indexedDraw);
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06001246 PIPELINE_NODE* pPipe = getPipeline(my_data, pCB->lastBoundPipeline);
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06001247 // Now complete other state checks
Tobin Ehlis12ab7dc2015-09-09 13:31:01 -06001248 // TODO : Currently only performing next check if *something* was bound (non-zero last bound)
1249 // There is probably a better way to gate when this check happens, and to know if something *should* have been bound
1250 // We should have that check separately and then gate this check based on that check
Tobin Ehlis982099b2015-11-05 09:52:49 -07001251 if (pPipe && (pCB->lastBoundPipelineLayout)) {
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07001252 string errorString;
1253 for (auto setIndex : pPipe->active_sets) {
1254 // If valid set is not bound throw an error
1255 if ((pCB->boundDescriptorSets.size() <= setIndex) || (!pCB->boundDescriptorSets[setIndex])) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07001256 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_DESCRIPTOR_SET_NOT_BOUND, "DS",
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07001257 "VkPipeline %#" PRIxLEAST64 " uses set #%u but that set is not bound.", (uint64_t)pPipe->pipeline, setIndex);
1258 } else if (!verify_set_layout_compatibility(my_data, my_data->setMap[pCB->boundDescriptorSets[setIndex]], pPipe->graphicsPipelineCI.layout, setIndex, errorString)) {
1259 // Set is bound but not compatible w/ overlapping pipelineLayout from PSO
1260 VkDescriptorSet setHandle = my_data->setMap[pCB->boundDescriptorSets[setIndex]]->set;
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07001261 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, (uint64_t)setHandle, 0, DRAWSTATE_PIPELINE_LAYOUTS_INCOMPATIBLE, "DS",
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07001262 "VkDescriptorSet (%#" PRIxLEAST64 ") bound as set #%u is not compatible with overlapping VkPipelineLayout %#" PRIxLEAST64 " due to: %s", (uint64_t)setHandle, setIndex, (uint64_t)pPipe->graphicsPipelineCI.layout, errorString.c_str());
1263 }
1264 }
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06001265 }
Tobin Ehlisd28acef2015-09-09 15:12:35 -06001266 // Verify Vtx binding
1267 if (MAX_BINDING != pCB->lastVtxBinding) {
1268 if (pCB->lastVtxBinding >= pPipe->vtxBindingCount) {
1269 if (0 == pPipe->vtxBindingCount) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07001270 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS",
Tobin Ehlisd28acef2015-09-09 15:12:35 -06001271 "Vtx Buffer Index %u was bound, but no vtx buffers are attached to PSO.", pCB->lastVtxBinding);
Tobin Ehlisd28acef2015-09-09 15:12:35 -06001272 }
1273 else {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07001274 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS",
Tobin Ehlisd28acef2015-09-09 15:12:35 -06001275 "Vtx binding Index of %u exceeds PSO pVertexBindingDescriptions max array index of %u.", pCB->lastVtxBinding, (pPipe->vtxBindingCount - 1));
Tobin Ehlisd28acef2015-09-09 15:12:35 -06001276 }
1277 }
1278 }
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06001279 // If Viewport or scissors are dynamic, verify that dynamic count matches PSO count
1280 VkBool32 dynViewport = isDynamic(pPipe, VK_DYNAMIC_STATE_VIEWPORT);
1281 VkBool32 dynScissor = isDynamic(pPipe, VK_DYNAMIC_STATE_SCISSOR);
1282 if (dynViewport) {
1283 if (pCB->viewports.size() != pPipe->graphicsPipelineCI.pViewportState->viewportCount) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07001284 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
Mark Lobodzinski2adea752015-11-10 15:25:01 -07001285 "Dynamic viewportCount from vkCmdSetViewport() is " PRINTF_SIZE_T_SPECIFIER ", but PSO viewportCount is %u. These counts must match.",
1286 pCB->viewports.size(), pPipe->graphicsPipelineCI.pViewportState->viewportCount);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06001287 }
1288 }
1289 if (dynScissor) {
1290 if (pCB->scissors.size() != pPipe->graphicsPipelineCI.pViewportState->scissorCount) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07001291 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
Mark Lobodzinski2adea752015-11-10 15:25:01 -07001292 "Dynamic scissorCount from vkCmdSetScissor() is " PRINTF_SIZE_T_SPECIFIER ", but PSO scissorCount is %u. These counts must match.",
1293 pCB->scissors.size(), pPipe->graphicsPipelineCI.pViewportState->scissorCount);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06001294 }
1295 }
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06001296 return result;
1297}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001298
Tobin Ehlisde63c532015-06-18 15:59:33 -06001299// Verify that create state for a pipeline is valid
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07001300static VkBool32 verifyPipelineCreateState(layer_data* my_data, const VkDevice device, PIPELINE_NODE* pPipeline)
Tobin Ehlisde63c532015-06-18 15:59:33 -06001301{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001302 VkBool32 skipCall = VK_FALSE;
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07001303 //if (!validate_pipeline_shaders(my_data, device, &(pPipeline->graphicsPipelineCI))) {
1304 if (!validate_pipeline_shaders(my_data, device, pPipeline)) {
Tobin Ehlisad61de42015-12-02 13:53:34 -07001305 skipCall = VK_TRUE;
1306 }
Tobin Ehlisde63c532015-06-18 15:59:33 -06001307 // VS is required
1308 if (!(pPipeline->active_shaders & VK_SHADER_STAGE_VERTEX_BIT)) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07001309 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlisde63c532015-06-18 15:59:33 -06001310 "Invalid Pipeline CreateInfo State: Vtx Shader required");
Tobin Ehlisde63c532015-06-18 15:59:33 -06001311 }
1312 // Either both or neither TC/TE shaders should be defined
Courtney Goeltzenleuchterc6fd2262015-10-15 17:35:38 -06001313 if (((pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) == 0) !=
1314 ((pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) == 0) ) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07001315 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlisde63c532015-06-18 15:59:33 -06001316 "Invalid Pipeline CreateInfo State: TE and TC shaders must be included or excluded as a pair");
Tobin Ehlisde63c532015-06-18 15:59:33 -06001317 }
1318 // Compute shaders should be specified independent of Gfx shaders
1319 if ((pPipeline->active_shaders & VK_SHADER_STAGE_COMPUTE_BIT) &&
Courtney Goeltzenleuchterc6fd2262015-10-15 17:35:38 -06001320 (pPipeline->active_shaders & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT |
1321 VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT | VK_SHADER_STAGE_GEOMETRY_BIT |
Tobin Ehlisde63c532015-06-18 15:59:33 -06001322 VK_SHADER_STAGE_FRAGMENT_BIT))) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07001323 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlisde63c532015-06-18 15:59:33 -06001324 "Invalid Pipeline CreateInfo State: Do not specify Compute Shader for Gfx Pipeline");
Tobin Ehlisde63c532015-06-18 15:59:33 -06001325 }
Chia-I Wu99ba2bb2015-10-31 00:31:16 +08001326 // VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology is only valid for tessellation pipelines.
Tobin Ehlisde63c532015-06-18 15:59:33 -06001327 // Mismatching primitive topology and tessellation fails graphics pipeline creation.
Courtney Goeltzenleuchterc6fd2262015-10-15 17:35:38 -06001328 if (pPipeline->active_shaders & (VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) &&
Chia-I Wu99ba2bb2015-10-31 00:31:16 +08001329 (pPipeline->iaStateCI.topology != VK_PRIMITIVE_TOPOLOGY_PATCH_LIST)) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07001330 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Chia-I Wu99ba2bb2015-10-31 00:31:16 +08001331 "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 -06001332 }
Chia-I Wu99ba2bb2015-10-31 00:31:16 +08001333 if (pPipeline->iaStateCI.topology == VK_PRIMITIVE_TOPOLOGY_PATCH_LIST) {
Courtney Goeltzenleuchterc6fd2262015-10-15 17:35:38 -06001334 if (~pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07001335 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Chia-I Wu99ba2bb2015-10-31 00:31:16 +08001336 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology is only valid for tessellation pipelines");
Tobin Ehlis20693172015-09-17 08:46:18 -06001337 }
1338 if (!pPipeline->tessStateCI.patchControlPoints || (pPipeline->tessStateCI.patchControlPoints > 32)) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07001339 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType) 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 primitive topology used with patchControlPoints value %u."
Tobin Ehlis20693172015-09-17 08:46:18 -06001341 " patchControlPoints should be >0 and <=32.", pPipeline->tessStateCI.patchControlPoints);
1342 }
Tobin Ehlisde63c532015-06-18 15:59:33 -06001343 }
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06001344 // Viewport state must be included and viewport and scissor counts should always match
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001345 // NOTE : Even if these are flagged as dynamic, counts need to be set correctly for shader compiler
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06001346 if (!pPipeline->graphicsPipelineCI.pViewportState) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07001347 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06001348 "Gfx Pipeline pViewportState is null. Even if viewport and scissors are dynamic PSO must include viewportCount and scissorCount in pViewportState.");
1349 } else if (pPipeline->graphicsPipelineCI.pViewportState->scissorCount != pPipeline->graphicsPipelineCI.pViewportState->viewportCount) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07001350 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001351 "Gfx Pipeline viewport count (%u) must match scissor count (%u).", pPipeline->vpStateCI.viewportCount, pPipeline->vpStateCI.scissorCount);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06001352 } else {
1353 // If viewport or scissor are not dynamic, then verify that data is appropriate for count
1354 VkBool32 dynViewport = isDynamic(pPipeline, VK_DYNAMIC_STATE_VIEWPORT);
1355 VkBool32 dynScissor = isDynamic(pPipeline, VK_DYNAMIC_STATE_SCISSOR);
1356 if (!dynViewport) {
1357 if (pPipeline->graphicsPipelineCI.pViewportState->viewportCount && !pPipeline->graphicsPipelineCI.pViewportState->pViewports) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07001358 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
Mark Lobodzinski2adea752015-11-10 15:25:01 -07001359 "Gfx Pipeline viewportCount is %u, but pViewports is NULL. For non-zero viewportCount, you must either include pViewports data, or "
1360 "include viewport in pDynamicState and set it with vkCmdSetViewport().", pPipeline->graphicsPipelineCI.pViewportState->viewportCount);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001361 }
1362 }
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06001363 if (!dynScissor) {
1364 if (pPipeline->graphicsPipelineCI.pViewportState->scissorCount && !pPipeline->graphicsPipelineCI.pViewportState->pScissors) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07001365 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
Mark Lobodzinski2adea752015-11-10 15:25:01 -07001366 "Gfx Pipeline scissorCount is %u, but pScissors is NULL. For non-zero scissorCount, you must either include pScissors data, or include "
1367 "scissor in pDynamicState and set it with vkCmdSetScissor().", pPipeline->graphicsPipelineCI.pViewportState->scissorCount);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06001368 }
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001369 }
1370 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001371 return skipCall;
Tobin Ehlisde63c532015-06-18 15:59:33 -06001372}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001373
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001374// Init the pipeline mapping info based on pipeline create info LL tree
1375// Threading note : Calls to this function should wrapped in mutex
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07001376// TODO : this should really just be in the constructor for PIPELINE_NODE
Mark Lobodzinski2adea752015-11-10 15:25:01 -07001377static PIPELINE_NODE* initGraphicsPipeline(layer_data* dev_data, const VkGraphicsPipelineCreateInfo* pCreateInfo, PIPELINE_NODE* pBasePipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001378{
Tobin Ehlisde63c532015-06-18 15:59:33 -06001379 PIPELINE_NODE* pPipeline = new PIPELINE_NODE;
Mark Lobodzinskie443d2b2015-12-11 11:56:07 -07001380
Tobin Ehlisde63c532015-06-18 15:59:33 -06001381 if (pBasePipeline) {
Mark Lobodzinskie443d2b2015-12-11 11:56:07 -07001382 *pPipeline = *pBasePipeline;
Tobin Ehlisde63c532015-06-18 15:59:33 -06001383 }
Mark Lobodzinskie443d2b2015-12-11 11:56:07 -07001384
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001385 // First init create info
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001386 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001387
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001388 size_t bufferSize = 0;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001389 const VkPipelineVertexInputStateCreateInfo* pVICI = NULL;
Tobin Ehlis59db5712015-07-13 13:14:24 -06001390 const VkPipelineColorBlendStateCreateInfo* pCBCI = NULL;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001391
1392 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
1393 const VkPipelineShaderStageCreateInfo *pPSSCI = &pCreateInfo->pStages[i];
1394
Chia-I Wu062ad152015-10-31 00:31:16 +08001395 switch (pPSSCI->stage) {
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001396 case VK_SHADER_STAGE_VERTEX_BIT:
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001397 memcpy(&pPipeline->vsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1398 pPipeline->active_shaders |= VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001399 break;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001400 case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT:
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001401 memcpy(&pPipeline->tcsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Courtney Goeltzenleuchterc6fd2262015-10-15 17:35:38 -06001402 pPipeline->active_shaders |= VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001403 break;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001404 case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT:
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001405 memcpy(&pPipeline->tesCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Courtney Goeltzenleuchterc6fd2262015-10-15 17:35:38 -06001406 pPipeline->active_shaders |= VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001407 break;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001408 case VK_SHADER_STAGE_GEOMETRY_BIT:
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001409 memcpy(&pPipeline->gsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1410 pPipeline->active_shaders |= VK_SHADER_STAGE_GEOMETRY_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001411 break;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001412 case VK_SHADER_STAGE_FRAGMENT_BIT:
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001413 memcpy(&pPipeline->fsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1414 pPipeline->active_shaders |= VK_SHADER_STAGE_FRAGMENT_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001415 break;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001416 case VK_SHADER_STAGE_COMPUTE_BIT:
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001417 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
1418 pPipeline->active_shaders |= VK_SHADER_STAGE_COMPUTE_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001419 break;
1420 default:
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001421 // TODO : Flag error
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001422 break;
1423 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001424 }
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001425 // Copy over GraphicsPipelineCreateInfo structure embedded pointers
1426 if (pCreateInfo->stageCount != 0) {
1427 pPipeline->graphicsPipelineCI.pStages = new VkPipelineShaderStageCreateInfo[pCreateInfo->stageCount];
1428 bufferSize = pCreateInfo->stageCount * sizeof(VkPipelineShaderStageCreateInfo);
1429 memcpy((void*)pPipeline->graphicsPipelineCI.pStages, pCreateInfo->pStages, bufferSize);
1430 }
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001431 if (pCreateInfo->pVertexInputState != NULL) {
1432 memcpy((void*)&pPipeline->vertexInputCI, pCreateInfo->pVertexInputState , sizeof(VkPipelineVertexInputStateCreateInfo));
1433 // Copy embedded ptrs
1434 pVICI = pCreateInfo->pVertexInputState;
Chia-I Wu763a7492015-10-26 20:48:51 +08001435 pPipeline->vtxBindingCount = pVICI->vertexBindingDescriptionCount;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001436 if (pPipeline->vtxBindingCount) {
1437 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
1438 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
1439 memcpy((void*)pPipeline->pVertexBindingDescriptions, pVICI->pVertexBindingDescriptions, bufferSize);
1440 }
Chia-I Wu763a7492015-10-26 20:48:51 +08001441 pPipeline->vtxAttributeCount = pVICI->vertexAttributeDescriptionCount;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001442 if (pPipeline->vtxAttributeCount) {
1443 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
1444 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
1445 memcpy((void*)pPipeline->pVertexAttributeDescriptions, pVICI->pVertexAttributeDescriptions, bufferSize);
1446 }
1447 pPipeline->graphicsPipelineCI.pVertexInputState = &pPipeline->vertexInputCI;
1448 }
Tony Barboure307f582015-07-10 15:29:03 -06001449 if (pCreateInfo->pInputAssemblyState != NULL) {
1450 memcpy((void*)&pPipeline->iaStateCI, pCreateInfo->pInputAssemblyState, sizeof(VkPipelineInputAssemblyStateCreateInfo));
1451 pPipeline->graphicsPipelineCI.pInputAssemblyState = &pPipeline->iaStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001452 }
Tony Barboure307f582015-07-10 15:29:03 -06001453 if (pCreateInfo->pTessellationState != NULL) {
1454 memcpy((void*)&pPipeline->tessStateCI, pCreateInfo->pTessellationState, sizeof(VkPipelineTessellationStateCreateInfo));
1455 pPipeline->graphicsPipelineCI.pTessellationState = &pPipeline->tessStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001456 }
Tony Barboure307f582015-07-10 15:29:03 -06001457 if (pCreateInfo->pViewportState != NULL) {
1458 memcpy((void*)&pPipeline->vpStateCI, pCreateInfo->pViewportState, sizeof(VkPipelineViewportStateCreateInfo));
1459 pPipeline->graphicsPipelineCI.pViewportState = &pPipeline->vpStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001460 }
Chia-I Wu1f851912015-10-27 18:04:07 +08001461 if (pCreateInfo->pRasterizationState != NULL) {
1462 memcpy((void*)&pPipeline->rsStateCI, pCreateInfo->pRasterizationState, sizeof(VkPipelineRasterizationStateCreateInfo));
1463 pPipeline->graphicsPipelineCI.pRasterizationState = &pPipeline->rsStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001464 }
Tony Barboure307f582015-07-10 15:29:03 -06001465 if (pCreateInfo->pMultisampleState != NULL) {
1466 memcpy((void*)&pPipeline->msStateCI, pCreateInfo->pMultisampleState, sizeof(VkPipelineMultisampleStateCreateInfo));
1467 pPipeline->graphicsPipelineCI.pMultisampleState = &pPipeline->msStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001468 }
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001469 if (pCreateInfo->pDepthStencilState != NULL) {
1470 memcpy((void*)&pPipeline->dsStateCI, pCreateInfo->pDepthStencilState, sizeof(VkPipelineDepthStencilStateCreateInfo));
1471 pPipeline->graphicsPipelineCI.pDepthStencilState = &pPipeline->dsStateCI;
1472 }
Tony Barboure307f582015-07-10 15:29:03 -06001473 if (pCreateInfo->pColorBlendState != NULL) {
1474 memcpy((void*)&pPipeline->cbStateCI, pCreateInfo->pColorBlendState, sizeof(VkPipelineColorBlendStateCreateInfo));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001475 // Copy embedded ptrs
Tony Barboure307f582015-07-10 15:29:03 -06001476 pCBCI = pCreateInfo->pColorBlendState;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001477 pPipeline->attachmentCount = pCBCI->attachmentCount;
1478 if (pPipeline->attachmentCount) {
Tony Barboure307f582015-07-10 15:29:03 -06001479 pPipeline->pAttachments = new VkPipelineColorBlendAttachmentState[pPipeline->attachmentCount];
1480 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineColorBlendAttachmentState);
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001481 memcpy((void*)pPipeline->pAttachments, pCBCI->pAttachments, bufferSize);
1482 }
Tony Barboure307f582015-07-10 15:29:03 -06001483 pPipeline->graphicsPipelineCI.pColorBlendState = &pPipeline->cbStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001484 }
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001485 if (pCreateInfo->pDynamicState != NULL) {
1486 memcpy((void*)&pPipeline->dynStateCI, pCreateInfo->pDynamicState, sizeof(VkPipelineDynamicStateCreateInfo));
1487 if (pPipeline->dynStateCI.dynamicStateCount) {
1488 pPipeline->dynStateCI.pDynamicStates = new VkDynamicState[pPipeline->dynStateCI.dynamicStateCount];
1489 bufferSize = pPipeline->dynStateCI.dynamicStateCount * sizeof(VkDynamicState);
1490 memcpy((void*)pPipeline->dynStateCI.pDynamicStates, pCreateInfo->pDynamicState->pDynamicStates, bufferSize);
1491 }
1492 pPipeline->graphicsPipelineCI.pDynamicState = &pPipeline->dynStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001493 }
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07001494 pPipeline->active_sets.clear();
Tobin Ehlisde63c532015-06-18 15:59:33 -06001495 return pPipeline;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001496}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001497
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001498// Free the Pipeline nodes
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06001499static void deletePipelines(layer_data* my_data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001500{
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06001501 if (my_data->pipelineMap.size() <= 0)
David Pinedof5997ab2015-04-27 16:36:17 -06001502 return;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06001503 for (auto ii=my_data->pipelineMap.begin(); ii!=my_data->pipelineMap.end(); ++ii) {
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001504 if ((*ii).second->graphicsPipelineCI.stageCount != 0) {
1505 delete[] (*ii).second->graphicsPipelineCI.pStages;
1506 }
Tobin Ehliscd3109e2015-04-01 11:59:08 -06001507 if ((*ii).second->pVertexBindingDescriptions) {
1508 delete[] (*ii).second->pVertexBindingDescriptions;
1509 }
1510 if ((*ii).second->pVertexAttributeDescriptions) {
1511 delete[] (*ii).second->pVertexAttributeDescriptions;
1512 }
1513 if ((*ii).second->pAttachments) {
1514 delete[] (*ii).second->pAttachments;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001515 }
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001516 if ((*ii).second->dynStateCI.dynamicStateCount != 0) {
1517 delete[] (*ii).second->dynStateCI.pDynamicStates;
1518 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001519 delete (*ii).second;
1520 }
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06001521 my_data->pipelineMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001522}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001523
Tobin Ehlis2464b882015-04-01 08:40:34 -06001524// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001525static VkSampleCountFlagBits getNumSamples(layer_data* my_data, const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -06001526{
Chia-I Wue420a332015-10-26 20:04:44 +08001527 PIPELINE_NODE* pPipe = my_data->pipelineMap[pipeline];
Tobin Ehlisb3a506f2015-07-13 14:51:15 -06001528 if (VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
Chia-I Wu1f851912015-10-27 18:04:07 +08001529 return pPipe->msStateCI.rasterizationSamples;
Tobin Ehlisb3a506f2015-07-13 14:51:15 -06001530 }
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001531 return VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis2464b882015-04-01 08:40:34 -06001532}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001533
Tobin Ehlis2464b882015-04-01 08:40:34 -06001534// Validate state related to the PSO
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06001535static VkBool32 validatePipelineState(layer_data* my_data, const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -06001536{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001537 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06001538 // Verify that any MSAA request in PSO matches sample# in bound FB
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001539 VkSampleCountFlagBits psoNumSamples = getNumSamples(my_data, pipeline);
Tobin Ehlis2464b882015-04-01 08:40:34 -06001540 if (pCB->activeRenderPass) {
Tobin Ehlisad61de42015-12-02 13:53:34 -07001541 const VkRenderPassCreateInfo* pRPCI = my_data->renderPassMap[pCB->activeRenderPass]->pCreateInfo;
Chia-I Wuc278df82015-07-07 11:50:03 +08001542 const VkSubpassDescription* pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001543 VkSampleCountFlagBits subpassNumSamples = (VkSampleCountFlagBits) 0;
Chia-I Wuc278df82015-07-07 11:50:03 +08001544 uint32_t i;
1545
Chia-I Wu763a7492015-10-26 20:48:51 +08001546 for (i = 0; i < pSD->colorAttachmentCount; i++) {
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001547 VkSampleCountFlagBits samples;
Chia-I Wuc278df82015-07-07 11:50:03 +08001548
Cody Northrop6de6b0b2015-08-04 11:16:41 -06001549 if (pSD->pColorAttachments[i].attachment == VK_ATTACHMENT_UNUSED)
Chia-I Wuc278df82015-07-07 11:50:03 +08001550 continue;
1551
Cody Northrop6de6b0b2015-08-04 11:16:41 -06001552 samples = pRPCI->pAttachments[pSD->pColorAttachments[i].attachment].samples;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001553 if (subpassNumSamples == (VkSampleCountFlagBits) 0) {
Chia-I Wuc278df82015-07-07 11:50:03 +08001554 subpassNumSamples = samples;
1555 } else if (subpassNumSamples != samples) {
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001556 subpassNumSamples = (VkSampleCountFlagBits) -1;
Chia-I Wuc278df82015-07-07 11:50:03 +08001557 break;
1558 }
1559 }
Chia-I Wuce532f72015-10-26 17:32:47 +08001560 if (pSD->pDepthStencilAttachment && pSD->pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001561 const VkSampleCountFlagBits samples = pRPCI->pAttachments[pSD->pDepthStencilAttachment->attachment].samples;
1562 if (subpassNumSamples == (VkSampleCountFlagBits) 0)
Chia-I Wuc278df82015-07-07 11:50:03 +08001563 subpassNumSamples = samples;
1564 else if (subpassNumSamples != samples)
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001565 subpassNumSamples = (VkSampleCountFlagBits) -1;
Chia-I Wuc278df82015-07-07 11:50:03 +08001566 }
1567
1568 if (psoNumSamples != subpassNumSamples) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07001569 return log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, (uint64_t) pipeline, 0, DRAWSTATE_NUM_SAMPLES_MISMATCH, "DS",
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06001570 "Num samples mismatch! Binding PSO (%#" PRIxLEAST64 ") with %u samples while current RenderPass (%#" PRIxLEAST64 ") w/ %u samples!",
Chia-I Wue420a332015-10-26 20:04:44 +08001571 (uint64_t) pipeline, psoNumSamples, (uint64_t) pCB->activeRenderPass, subpassNumSamples);
Tobin Ehlis2464b882015-04-01 08:40:34 -06001572 }
1573 } else {
1574 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
1575 // Verify and flag error as appropriate
1576 }
1577 // TODO : Add more checks here
1578 } else {
1579 // TODO : Validate non-gfx pipeline updates
1580 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001581 return VK_FALSE;
Tobin Ehlis2464b882015-04-01 08:40:34 -06001582}
1583
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001584// Block of code at start here specifically for managing/tracking DSs
1585
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001586// Return Pool node ptr for specified pool or else NULL
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07001587static DESCRIPTOR_POOL_NODE* getPoolNode(layer_data* my_data, const VkDescriptorPool pool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001588{
1589 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07001590 if (my_data->descriptorPoolMap.find(pool) == my_data->descriptorPoolMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001591 loader_platform_thread_unlock_mutex(&globalLock);
1592 return NULL;
1593 }
1594 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07001595 return my_data->descriptorPoolMap[pool];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001596}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001597
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001598// Return Set node ptr for specified set or else NULL
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06001599static SET_NODE* getSetNode(layer_data* my_data, const VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001600{
1601 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue420a332015-10-26 20:04:44 +08001602 if (my_data->setMap.find(set) == my_data->setMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001603 loader_platform_thread_unlock_mutex(&globalLock);
1604 return NULL;
1605 }
1606 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wue420a332015-10-26 20:04:44 +08001607 return my_data->setMap[set];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001608}
1609
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06001610static LAYOUT_NODE* getLayoutNode(layer_data* my_data, const VkDescriptorSetLayout layout) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001611 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisad61de42015-12-02 13:53:34 -07001612 if (my_data->descriptorSetLayoutMap.find(layout) == my_data->descriptorSetLayoutMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001613 loader_platform_thread_unlock_mutex(&globalLock);
1614 return NULL;
1615 }
1616 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisad61de42015-12-02 13:53:34 -07001617 return my_data->descriptorSetLayoutMap[layout];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001618}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001619
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001620// 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 -06001621static VkBool32 validUpdateStruct(layer_data* my_data, const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001622{
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001623 switch (pUpdateStruct->sType)
1624 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001625 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1626 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001627 return VK_FALSE;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001628 default:
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07001629 return log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001630 "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 -06001631 }
1632}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001633
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001634// Set count for given update struct in the last parameter
1635// Return value of skipCall, which is only VK_TRUE is error occurs and callback signals execution to cease
Tobin Ehlise66ec962015-10-27 12:54:50 -06001636static uint32_t getUpdateCount(layer_data* my_data, const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001637{
1638 switch (pUpdateStruct->sType)
1639 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001640 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
Chia-I Wu763a7492015-10-26 20:48:51 +08001641 return ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorCount;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001642 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001643 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wu763a7492015-10-26 20:48:51 +08001644 return ((VkCopyDescriptorSet*)pUpdateStruct)->descriptorCount;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001645 }
1646}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001647
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001648// For given Layout Node and binding, return index where that binding begins
1649static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
1650{
1651 uint32_t offsetIndex = 0;
Chia-I Wub5689ee2015-10-31 00:31:16 +08001652 for (uint32_t i = 0; i < pLayout->createInfo.bindingCount; i++) {
1653 if (pLayout->createInfo.pBinding[i].binding == binding)
1654 break;
Chia-I Wu045654f2015-11-06 06:42:02 +08001655 offsetIndex += pLayout->createInfo.pBinding[i].descriptorCount;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001656 }
1657 return offsetIndex;
1658}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001659
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001660// For given layout node and binding, return last index that is updated
1661static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
1662{
1663 uint32_t offsetIndex = 0;
Chia-I Wub5689ee2015-10-31 00:31:16 +08001664 for (uint32_t i = 0; i < pLayout->createInfo.bindingCount; i++) {
Chia-I Wu045654f2015-11-06 06:42:02 +08001665 offsetIndex += pLayout->createInfo.pBinding[i].descriptorCount;
Chia-I Wub5689ee2015-10-31 00:31:16 +08001666 if (pLayout->createInfo.pBinding[i].binding == binding)
1667 break;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001668 }
1669 return offsetIndex-1;
1670}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001671
Tobin Ehlise66ec962015-10-27 12:54:50 -06001672// For given layout and update, return the first overall index of the layout that is updated
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06001673static 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 -06001674{
Tobin Ehlise66ec962015-10-27 12:54:50 -06001675 return getBindingStartIndex(pLayout, binding)+arrayIndex;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001676}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001677
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06001678// For given layout and update, return the last overall index of the layout that is updated
1679static 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 -06001680{
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06001681 uint32_t count = getUpdateCount(my_data, device, pUpdateStruct);
Tobin Ehlise66ec962015-10-27 12:54:50 -06001682 return getBindingStartIndex(pLayout, binding)+arrayIndex+count-1;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001683}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001684
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001685// Verify that the descriptor type in the update struct matches what's expected by the layout
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001686static 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 -06001687{
1688 // First get actual type of update
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001689 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001690 VkDescriptorType actualType;
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001691 uint32_t i = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001692 switch (pUpdateStruct->sType)
1693 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001694 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1695 actualType = ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001696 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001697 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
1698 /* no need to validate */
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001699 return VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001700 break;
1701 default:
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07001702 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001703 "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 -06001704 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001705 if (VK_FALSE == skipCall) {
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001706 // Set first stageFlags as reference and verify that all other updates match it
1707 VkShaderStageFlags refStageFlags = pLayout->stageFlags[startIndex];
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001708 for (i = startIndex; i <= endIndex; i++) {
Tobin Ehlis91423d22015-10-20 10:11:55 -06001709 if (pLayout->descriptorTypes[i] != actualType) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07001710 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, "DS",
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001711 "Write descriptor update has descriptor type %s that does not match overlapping binding descriptor type of %s!",
1712 string_VkDescriptorType(actualType), string_VkDescriptorType(pLayout->descriptorTypes[i]));
1713 }
1714 if (pLayout->stageFlags[i] != refStageFlags) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07001715 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_DESCRIPTOR_STAGEFLAGS_MISMATCH, "DS",
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001716 "Write descriptor update has stageFlags %x that do not match overlapping binding descriptor stageFlags of %x!",
1717 refStageFlags, pLayout->stageFlags[i]);
Tobin Ehlis3b341092015-09-30 08:30:20 -06001718 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001719 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001720 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001721 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001722}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001723
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001724// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001725// struct into the pNewNode param. Return VK_TRUE if error condition encountered and callback signals early exit.
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001726// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlis42d440c2015-10-20 17:06:16 -06001727static VkBool32 shadowUpdateNode(layer_data* my_data, const VkDevice device, GENERIC_HEADER* pUpdate, GENERIC_HEADER** pNewNode)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001728{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001729 VkBool32 skipCall = VK_FALSE;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001730 VkWriteDescriptorSet* pWDS = NULL;
1731 VkCopyDescriptorSet* pCDS = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001732 size_t array_size = 0;
1733 size_t base_array_size = 0;
1734 size_t total_array_size = 0;
1735 size_t baseBuffAddr = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001736 switch (pUpdate->sType)
1737 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001738 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1739 pWDS = new VkWriteDescriptorSet;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001740 *pNewNode = (GENERIC_HEADER*)pWDS;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001741 memcpy(pWDS, pUpdate, sizeof(VkWriteDescriptorSet));
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06001742
1743 switch (pWDS->descriptorType) {
1744 case VK_DESCRIPTOR_TYPE_SAMPLER:
1745 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
1746 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
1747 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
1748 {
Chia-I Wu763a7492015-10-26 20:48:51 +08001749 VkDescriptorImageInfo *info = new VkDescriptorImageInfo[pWDS->descriptorCount];
1750 memcpy(info, pWDS->pImageInfo, pWDS->descriptorCount * sizeof(VkDescriptorImageInfo));
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06001751 pWDS->pImageInfo = info;
Tobin Ehliscb085292015-12-01 09:57:09 -07001752 }
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06001753 break;
1754 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
1755 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
1756 {
Chia-I Wu763a7492015-10-26 20:48:51 +08001757 VkBufferView *info = new VkBufferView[pWDS->descriptorCount];
1758 memcpy(info, pWDS->pTexelBufferView, pWDS->descriptorCount * sizeof(VkBufferView));
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06001759 pWDS->pTexelBufferView = info;
1760 }
1761 break;
1762 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
1763 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
1764 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
1765 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
1766 {
Chia-I Wu763a7492015-10-26 20:48:51 +08001767 VkDescriptorBufferInfo *info = new VkDescriptorBufferInfo[pWDS->descriptorCount];
1768 memcpy(info, pWDS->pBufferInfo, pWDS->descriptorCount * sizeof(VkDescriptorBufferInfo));
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06001769 pWDS->pBufferInfo = info;
1770 }
1771 break;
1772 default:
1773 return VK_ERROR_VALIDATION_FAILED;
1774 break;
1775 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001776 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001777 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
1778 pCDS = new VkCopyDescriptorSet;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001779 *pNewNode = (GENERIC_HEADER*)pCDS;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001780 memcpy(pCDS, pUpdate, sizeof(VkCopyDescriptorSet));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001781 break;
1782 default:
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07001783 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001784 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdate->sType), pUpdate->sType))
1785 return VK_TRUE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001786 }
1787 // Make sure that pNext for the end of shadow copy is NULL
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001788 (*pNewNode)->pNext = NULL;
1789 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001790}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001791
Tobin Ehlisb46be812015-10-23 16:00:08 -06001792// Verify that given sampler is valid
1793static VkBool32 validateSampler(const layer_data* my_data, const VkSampler* pSampler, const VkBool32 immutable)
1794{
1795 VkBool32 skipCall = VK_FALSE;
Chia-I Wue420a332015-10-26 20:04:44 +08001796 auto sampIt = my_data->sampleMap.find(*pSampler);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001797 if (sampIt == my_data->sampleMap.end()) {
1798 if (!immutable) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07001799 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_SAMPLER, (uint64_t) *pSampler, 0, DRAWSTATE_SAMPLER_DESCRIPTOR_ERROR, "DS",
Chia-I Wue420a332015-10-26 20:04:44 +08001800 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid sampler %#" PRIxLEAST64, (uint64_t) *pSampler);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001801 } else { // immutable
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07001802 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_SAMPLER, (uint64_t) *pSampler, 0, DRAWSTATE_SAMPLER_DESCRIPTOR_ERROR, "DS",
Chia-I Wue420a332015-10-26 20:04:44 +08001803 "vkUpdateDescriptorSets: Attempt to update descriptor whose binding has an invalid immutable sampler %#" PRIxLEAST64, (uint64_t) *pSampler);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001804 }
1805 } else {
1806 // TODO : Any further checks we want to do on the sampler?
1807 }
1808 return skipCall;
1809}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001810
Tobin Ehlisb46be812015-10-23 16:00:08 -06001811// Verify that given imageView is valid
1812static VkBool32 validateImageView(const layer_data* my_data, const VkImageView* pImageView, const VkImageLayout imageLayout)
1813{
1814 VkBool32 skipCall = VK_FALSE;
Chia-I Wue420a332015-10-26 20:04:44 +08001815 auto ivIt = my_data->imageViewMap.find(*pImageView);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001816 if (ivIt == my_data->imageViewMap.end()) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07001817 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_IMAGE_VIEW, (uint64_t) *pImageView, 0, DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, "DS",
Chia-I Wue420a332015-10-26 20:04:44 +08001818 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid imageView %#" PRIxLEAST64, (uint64_t) *pImageView);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001819 } else {
1820 // Validate that imageLayout is compatible with aspectMask and image format
1821 VkImageAspectFlags aspectMask = ivIt->second->subresourceRange.aspectMask;
Chia-I Wue420a332015-10-26 20:04:44 +08001822 VkImage image = ivIt->second->image;
Michael Lentineee4ad4d2015-10-23 12:41:44 -07001823 // TODO : Check here in case we have a bad image
Chia-I Wue420a332015-10-26 20:04:44 +08001824 auto imgIt = my_data->imageMap.find(image);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001825 if (imgIt == my_data->imageMap.end()) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07001826 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_IMAGE, (uint64_t) image, 0, DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, "DS",
Michael Lentineee4ad4d2015-10-23 12:41:44 -07001827 "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 -06001828 } else {
1829 VkFormat format = (*imgIt).second->format;
Courtney Goeltzenleuchterf2bca902015-11-03 15:41:43 -07001830 VkBool32 ds = vk_format_is_depth_or_stencil(format);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001831 switch (imageLayout) {
1832 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
1833 // Only Color bit must be set
1834 if ((aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) != VK_IMAGE_ASPECT_COLOR_BIT) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07001835 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_IMAGE_VIEW, (uint64_t) *pImageView, 0,
Tobin Ehlisb46be812015-10-23 16:00:08 -06001836 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 +08001837 " that does not have VK_IMAGE_ASPECT_COLOR_BIT set.", (uint64_t) *pImageView);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001838 }
1839 // format must NOT be DS
1840 if (ds) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07001841 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_IMAGE_VIEW, (uint64_t) *pImageView, 0,
Tobin Ehlisb46be812015-10-23 16:00:08 -06001842 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 +08001843 " 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 -06001844 }
1845 break;
1846 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
1847 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
1848 // Depth or stencil bit must be set, but both must NOT be set
1849 if (aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) {
1850 if (aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) {
1851 // both must NOT be set
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07001852 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_IMAGE_VIEW, (uint64_t) *pImageView, 0,
Tobin Ehlisb46be812015-10-23 16:00:08 -06001853 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with imageView %#" PRIxLEAST64 ""
Chia-I Wue420a332015-10-26 20:04:44 +08001854 " that has both STENCIL and DEPTH aspects set", (uint64_t) *pImageView);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001855 }
1856 } else if (!(aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)) {
1857 // Neither were set
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07001858 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_IMAGE_VIEW, (uint64_t) *pImageView, 0,
Tobin Ehlisb46be812015-10-23 16:00:08 -06001859 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout %s and imageView %#" PRIxLEAST64 ""
Chia-I Wue420a332015-10-26 20:04:44 +08001860 " that does not have STENCIL or DEPTH aspect set.", string_VkImageLayout(imageLayout), (uint64_t) *pImageView);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001861 }
1862 // format must be DS
1863 if (!ds) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07001864 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_IMAGE_VIEW, (uint64_t) *pImageView, 0,
Tobin Ehlisb46be812015-10-23 16:00:08 -06001865 DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout %s and imageView %#" PRIxLEAST64 ""
Chia-I Wue420a332015-10-26 20:04:44 +08001866 " 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 -06001867 }
1868 break;
1869 default:
1870 // anything to check for other layouts?
1871 break;
1872 }
1873 }
1874 }
1875 return skipCall;
1876}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001877
Tobin Ehlisb46be812015-10-23 16:00:08 -06001878// Verify that given bufferView is valid
1879static VkBool32 validateBufferView(const layer_data* my_data, const VkBufferView* pBufferView)
1880{
1881 VkBool32 skipCall = VK_FALSE;
Chia-I Wue420a332015-10-26 20:04:44 +08001882 auto sampIt = my_data->bufferViewMap.find(*pBufferView);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001883 if (sampIt == my_data->bufferViewMap.end()) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07001884 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_BUFFER_VIEW, (uint64_t) *pBufferView, 0, DRAWSTATE_BUFFERVIEW_DESCRIPTOR_ERROR, "DS",
Chia-I Wue420a332015-10-26 20:04:44 +08001885 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid bufferView %#" PRIxLEAST64, (uint64_t) *pBufferView);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001886 } else {
1887 // TODO : Any further checks we want to do on the bufferView?
1888 }
1889 return skipCall;
1890}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001891
Tobin Ehlisb46be812015-10-23 16:00:08 -06001892// Verify that given bufferInfo is valid
1893static VkBool32 validateBufferInfo(const layer_data* my_data, const VkDescriptorBufferInfo* pBufferInfo)
1894{
1895 VkBool32 skipCall = VK_FALSE;
Chia-I Wue420a332015-10-26 20:04:44 +08001896 auto sampIt = my_data->bufferMap.find(pBufferInfo->buffer);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001897 if (sampIt == my_data->bufferMap.end()) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07001898 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_BUFFER, (uint64_t) pBufferInfo->buffer, 0, DRAWSTATE_BUFFERINFO_DESCRIPTOR_ERROR, "DS",
Chia-I Wue420a332015-10-26 20:04:44 +08001899 "vkUpdateDescriptorSets: Attempt to update descriptor where bufferInfo has invalid buffer %#" PRIxLEAST64, (uint64_t) pBufferInfo->buffer);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001900 } else {
1901 // TODO : Any further checks we want to do on the bufferView?
1902 }
1903 return skipCall;
1904}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001905
Tobin Ehlisb46be812015-10-23 16:00:08 -06001906static VkBool32 validateUpdateContents(const layer_data* my_data, const VkWriteDescriptorSet *pWDS, const VkDescriptorSetLayoutBinding* pLayoutBinding)
1907{
1908 VkBool32 skipCall = VK_FALSE;
1909 // First verify that for the given Descriptor type, the correct DescriptorInfo data is supplied
1910 VkBufferView* pBufferView = NULL;
1911 const VkSampler* pSampler = NULL;
1912 VkImageView* pImageView = NULL;
1913 VkImageLayout* pImageLayout = NULL;
1914 VkDescriptorBufferInfo* pBufferInfo = NULL;
1915 VkBool32 immutable = VK_FALSE;
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001916 uint32_t i = 0;
1917 // For given update type, verify that update contents are correct
1918 switch (pWDS->descriptorType) {
1919 case VK_DESCRIPTOR_TYPE_SAMPLER:
Chia-I Wu763a7492015-10-26 20:48:51 +08001920 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisb46be812015-10-23 16:00:08 -06001921 skipCall |= validateSampler(my_data, &(pWDS->pImageInfo[i].sampler), immutable);
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001922 }
1923 break;
1924 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
Chia-I Wu763a7492015-10-26 20:48:51 +08001925 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisb46be812015-10-23 16:00:08 -06001926 if (NULL == pLayoutBinding->pImmutableSamplers) {
1927 pSampler = &(pWDS->pImageInfo[i].sampler);
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001928 if (immutable) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07001929 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_SAMPLER, (uint64_t) *pSampler, 0, DRAWSTATE_INCONSISTENT_IMMUTABLE_SAMPLER_UPDATE, "DS",
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001930 "vkUpdateDescriptorSets: Update #%u is not an immutable sampler %#" PRIxLEAST64 ", but previous update(s) from this "
1931 "VkWriteDescriptorSet struct used an immutable sampler. All updates from a single struct must either "
Chia-I Wue420a332015-10-26 20:04:44 +08001932 "use immutable or non-immutable samplers.", i, (uint64_t) *pSampler);
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001933 }
Tobin Ehlisb46be812015-10-23 16:00:08 -06001934 } else {
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001935 if (i>0 && !immutable) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07001936 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_SAMPLER, (uint64_t) *pSampler, 0, DRAWSTATE_INCONSISTENT_IMMUTABLE_SAMPLER_UPDATE, "DS",
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001937 "vkUpdateDescriptorSets: Update #%u is an immutable sampler, but previous update(s) from this "
1938 "VkWriteDescriptorSet struct used a non-immutable sampler. All updates from a single struct must either "
1939 "use immutable or non-immutable samplers.", i);
1940 }
Tobin Ehlisb46be812015-10-23 16:00:08 -06001941 immutable = VK_TRUE;
1942 pSampler = &(pLayoutBinding->pImmutableSamplers[i]);
1943 }
1944 skipCall |= validateSampler(my_data, pSampler, immutable);
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001945 }
1946 // Intentionally fall through here to also validate image stuff
1947 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
1948 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
1949 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
Chia-I Wu763a7492015-10-26 20:48:51 +08001950 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisb46be812015-10-23 16:00:08 -06001951 skipCall |= validateImageView(my_data, &(pWDS->pImageInfo[i].imageView), pWDS->pImageInfo[i].imageLayout);
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001952 }
1953 break;
1954 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
1955 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
Chia-I Wu763a7492015-10-26 20:48:51 +08001956 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisb46be812015-10-23 16:00:08 -06001957 skipCall |= validateBufferView(my_data, &(pWDS->pTexelBufferView[i]));
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001958 }
1959 break;
1960 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
1961 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
1962 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
1963 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
Chia-I Wu763a7492015-10-26 20:48:51 +08001964 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisb46be812015-10-23 16:00:08 -06001965 skipCall |= validateBufferInfo(my_data, &(pWDS->pBufferInfo[i]));
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001966 }
1967 break;
Tobin Ehlisb46be812015-10-23 16:00:08 -06001968 }
1969 return skipCall;
1970}
Tobin Ehlis982099b2015-11-05 09:52:49 -07001971
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001972// update DS mappings based on write and copy update arrays
Chia-I Wu483e7702015-10-26 17:20:32 +08001973static 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 -06001974{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001975 VkBool32 skipCall = VK_FALSE;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001976
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001977 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001978 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001979 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001980 // Validate Write updates
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06001981 uint32_t i = 0;
Chia-I Wu483e7702015-10-26 17:20:32 +08001982 for (i=0; i < descriptorWriteCount; i++) {
Chia-I Wu1f851912015-10-27 18:04:07 +08001983 VkDescriptorSet ds = pWDS[i].dstSet;
Chia-I Wue420a332015-10-26 20:04:44 +08001984 SET_NODE* pSet = my_data->setMap[ds];
Tobin Ehlisb46be812015-10-23 16:00:08 -06001985 GENERIC_HEADER* pUpdate = (GENERIC_HEADER*) &pWDS[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001986 pLayout = pSet->pLayout;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001987 // First verify valid update struct
Tobin Ehlis42d440c2015-10-20 17:06:16 -06001988 if ((skipCall = validUpdateStruct(my_data, device, pUpdate)) == VK_TRUE) {
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001989 break;
1990 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001991 uint32_t binding = 0, endIndex = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08001992 binding = pWDS[i].dstBinding;
Tobin Ehlis68fbd442015-10-27 12:25:35 -06001993 // Make sure that layout being updated has the binding being updated
Chia-I Wub5689ee2015-10-31 00:31:16 +08001994 if (pLayout->bindings.find(binding) == pLayout->bindings.end()) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07001995 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, (uint64_t) ds, 0, DRAWSTATE_INVALID_UPDATE_INDEX, "DS",
Michael Lentinecbc4a5e2015-11-03 16:19:46 -08001996 "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 -06001997 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001998 // Next verify that update falls within size of given binding
Chia-I Wu1f851912015-10-27 18:04:07 +08001999 endIndex = getUpdateEndIndex(my_data, device, pLayout, binding, pWDS[i].dstArrayElement, pUpdate);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002000 if (getBindingEndIndex(pLayout, binding) < endIndex) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002001 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002002 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07002003 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, (uint64_t) ds, 0, DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, "DS",
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002004 "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 -06002005 } else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlis68fbd442015-10-27 12:25:35 -06002006 uint32_t startIndex;
Chia-I Wu1f851912015-10-27 18:04:07 +08002007 startIndex = getUpdateStartIndex(my_data, device, pLayout, binding, pWDS[i].dstArrayElement, pUpdate);
Tobin Ehlis68fbd442015-10-27 12:25:35 -06002008 // Layout bindings match w/ update, now verify that update type & stageFlags are the same for entire update
2009 if ((skipCall = validateUpdateConsistency(my_data, device, pLayout, pUpdate, startIndex, endIndex)) == VK_FALSE) {
2010 // 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 +08002011 if ((skipCall = validateUpdateContents(my_data, &pWDS[i], &pLayout->createInfo.pBinding[binding])) == VK_FALSE) {
Tobin Ehlisb46be812015-10-23 16:00:08 -06002012 // Update is good. Save the update info
2013 // Create new update struct for this set's shadow copy
2014 GENERIC_HEADER* pNewNode = NULL;
2015 skipCall |= shadowUpdateNode(my_data, device, pUpdate, &pNewNode);
2016 if (NULL == pNewNode) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07002017 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, (uint64_t) ds, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
Tobin Ehlisb46be812015-10-23 16:00:08 -06002018 "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
2019 } else {
2020 // Insert shadow node into LL of updates for this set
2021 pNewNode->pNext = pSet->pUpdateStructs;
2022 pSet->pUpdateStructs = pNewNode;
2023 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlisb46be812015-10-23 16:00:08 -06002024 for (uint32_t j = startIndex; j <= endIndex; j++) {
2025 assert(j<pSet->descriptorCount);
2026 pSet->ppDescriptors[j] = pNewNode;
2027 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002028 }
2029 }
2030 }
2031 }
2032 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002033 }
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06002034 // Now validate copy updates
Chia-I Wu483e7702015-10-26 17:20:32 +08002035 for (i=0; i < descriptorCopyCount; ++i) {
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06002036 SET_NODE *pSrcSet = NULL, *pDstSet = NULL;
2037 LAYOUT_NODE *pSrcLayout = NULL, *pDstLayout = NULL;
2038 uint32_t srcStartIndex = 0, srcEndIndex = 0, dstStartIndex = 0, dstEndIndex = 0;
2039 // For each copy make sure that update falls within given layout and that types match
Chia-I Wue420a332015-10-26 20:04:44 +08002040 pSrcSet = my_data->setMap[pCDS[i].srcSet];
Chia-I Wu1f851912015-10-27 18:04:07 +08002041 pDstSet = my_data->setMap[pCDS[i].dstSet];
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06002042 pSrcLayout = pSrcSet->pLayout;
2043 pDstLayout = pDstSet->pLayout;
2044 // Validate that src binding is valid for src set layout
Chia-I Wub5689ee2015-10-31 00:31:16 +08002045 if (pSrcLayout->bindings.find(pCDS[i].srcBinding) == pSrcLayout->bindings.end()) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07002046 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, (uint64_t) pSrcSet->set, 0, DRAWSTATE_INVALID_UPDATE_INDEX, "DS",
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06002047 "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 +08002048 i, pCDS[i].srcBinding, (uint64_t) pSrcLayout->layout, pSrcLayout->createInfo.bindingCount-1);
Chia-I Wub5689ee2015-10-31 00:31:16 +08002049 } else if (pDstLayout->bindings.find(pCDS[i].dstBinding) == pDstLayout->bindings.end()) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07002050 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, (uint64_t) pDstSet->set, 0, DRAWSTATE_INVALID_UPDATE_INDEX, "DS",
Chia-I Wu1f851912015-10-27 18:04:07 +08002051 "Copy descriptor update %u has dstBinding %u which is out of bounds for underlying SetLayout %#" PRIxLEAST64 " which only has bindings 0-%u.",
2052 i, pCDS[i].dstBinding, (uint64_t) pDstLayout->layout, pDstLayout->createInfo.bindingCount-1);
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06002053 } else {
2054 // Proceed with validation. Bindings are ok, but make sure update is within bounds of given layout
2055 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 +08002056 dstEndIndex = getUpdateEndIndex(my_data, device, pDstLayout, pCDS[i].dstBinding, pCDS[i].dstArrayElement, (const GENERIC_HEADER*)&(pCDS[i]));
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06002057 if (getBindingEndIndex(pSrcLayout, pCDS[i].srcBinding) < srcEndIndex) {
2058 pLayoutCI = &pSrcLayout->createInfo;
2059 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07002060 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, (uint64_t) pSrcSet->set, 0, DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, "DS",
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06002061 "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 +08002062 } else if (getBindingEndIndex(pDstLayout, pCDS[i].dstBinding) < dstEndIndex) {
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06002063 pLayoutCI = &pDstLayout->createInfo;
2064 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07002065 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, (uint64_t) pDstSet->set, 0, DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, "DS",
Chia-I Wu1f851912015-10-27 18:04:07 +08002066 "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 -06002067 } else {
2068 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 +08002069 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 +08002070 for (uint32_t j=0; j<pCDS[i].descriptorCount; ++j) {
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06002071 // For copy just make sure that the types match and then perform the update
2072 if (pSrcLayout->descriptorTypes[srcStartIndex+j] != pDstLayout->descriptorTypes[dstStartIndex+j]) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07002073 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, "DS",
Tobin Ehlisd2e246e2015-10-27 15:43:38 -06002074 "Copy descriptor update index %u, update count #%u, has src update descriptor type %s that does not match overlapping dest descriptor type of %s!",
2075 i, j+1, string_VkDescriptorType(pSrcLayout->descriptorTypes[srcStartIndex+j]), string_VkDescriptorType(pDstLayout->descriptorTypes[dstStartIndex+j]));
2076 } else {
2077 // point dst descriptor at corresponding src descriptor
2078 pDstSet->ppDescriptors[j+dstStartIndex] = pSrcSet->ppDescriptors[j+srcStartIndex];
2079 }
2080 }
2081 }
2082 }
2083 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002084 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002085 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002086}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002087
Tobin Ehlisc6457d22015-10-20 16:16:04 -06002088// Verify that given pool has descriptors that are being requested for allocation
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002089static 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 -06002090{
2091 VkBool32 skipCall = VK_FALSE;
2092 uint32_t i = 0, j = 0;
2093 for (i=0; i<count; ++i) {
2094 LAYOUT_NODE* pLayout = getLayoutNode(dev_data, pSetLayouts[i]);
2095 if (NULL == pLayout) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07002096 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, (uint64_t) pSetLayouts[i], 0, DRAWSTATE_INVALID_LAYOUT, "DS",
Chia-I Wu1f851912015-10-27 18:04:07 +08002097 "Unable to find set layout node for layout %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pSetLayouts[i]);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06002098 } else {
Chia-I Wuc51b1212015-10-27 19:25:11 +08002099 uint32_t typeIndex = 0, poolSizeCount = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08002100 for (j=0; j<pLayout->createInfo.bindingCount; ++j) {
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002101 typeIndex = static_cast<uint32_t>(pLayout->createInfo.pBinding[j].descriptorType);
Chia-I Wu045654f2015-11-06 06:42:02 +08002102 poolSizeCount = pLayout->createInfo.pBinding[j].descriptorCount;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002103 if (poolSizeCount > pPoolNode->availableDescriptorTypeCount[typeIndex]) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07002104 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, (uint64_t) pLayout->layout, 0, DRAWSTATE_DESCRIPTOR_POOL_EMPTY, "DS",
Tobin Ehlisc6457d22015-10-20 16:16:04 -06002105 "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 +08002106 poolSizeCount, string_VkDescriptorType(pLayout->createInfo.pBinding[j].descriptorType), (uint64_t) pPoolNode->pool, pPoolNode->availableDescriptorTypeCount[typeIndex]);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06002107 } else { // Decrement available descriptors of this type
Chia-I Wuc51b1212015-10-27 19:25:11 +08002108 pPoolNode->availableDescriptorTypeCount[typeIndex] -= poolSizeCount;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06002109 }
2110 }
2111 }
2112 }
2113 return skipCall;
2114}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002115
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002116// Free the shadowed update node for this Set
2117// NOTE : Calls to this function should be wrapped in mutex
2118static void freeShadowUpdateTree(SET_NODE* pSet)
2119{
2120 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
2121 pSet->pUpdateStructs = NULL;
2122 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
2123 // Clear the descriptor mappings as they will now be invalid
2124 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
2125 while(pShadowUpdate) {
2126 pFreeUpdate = pShadowUpdate;
2127 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
2128 uint32_t index = 0;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002129 VkWriteDescriptorSet * pWDS = NULL;
2130 VkCopyDescriptorSet * pCDS = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002131 void** ppToFree = NULL;
2132 switch (pFreeUpdate->sType)
2133 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002134 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
2135 pWDS = (VkWriteDescriptorSet*)pFreeUpdate;
Tony Barbourf740f902015-11-02 11:46:29 -07002136 switch (pWDS->descriptorType) {
2137 case VK_DESCRIPTOR_TYPE_SAMPLER:
2138 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
2139 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2140 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
2141 {
2142 delete[] pWDS->pImageInfo;
2143 }
2144 break;
2145 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2146 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
2147 {
2148 delete[] pWDS->pTexelBufferView;
2149 }
2150 break;
2151 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2152 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2153 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2154 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
2155 {
2156 delete[] pWDS->pBufferInfo;
2157 }
2158 break;
2159 default:
2160 break;
Courtney Goeltzenleuchtere4099742015-10-22 15:31:56 -06002161 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002162 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002163 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002164 break;
2165 default:
2166 assert(0);
2167 break;
2168 }
Tobin Ehliseaf28662015-04-08 10:58:37 -06002169 delete pFreeUpdate;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002170 }
2171}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002172
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002173// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002174// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002175static void deletePools(layer_data* my_data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002176{
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002177 if (my_data->descriptorPoolMap.size() <= 0)
David Pinedof5997ab2015-04-27 16:36:17 -06002178 return;
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002179 for (auto ii=my_data->descriptorPoolMap.begin(); ii!=my_data->descriptorPoolMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002180 SET_NODE* pSet = (*ii).second->pSets;
2181 SET_NODE* pFreeSet = pSet;
2182 while (pSet) {
2183 pFreeSet = pSet;
2184 pSet = pSet->pNext;
Tobin Ehliseaf28662015-04-08 10:58:37 -06002185 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002186 // Free Update shadow struct tree
2187 freeShadowUpdateTree(pFreeSet);
2188 if (pFreeSet->ppDescriptors) {
Chris Forbes4506d3f2015-06-04 10:49:27 +12002189 delete[] pFreeSet->ppDescriptors;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002190 }
2191 delete pFreeSet;
2192 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002193 delete (*ii).second;
2194 }
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002195 my_data->descriptorPoolMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002196}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002197
Tobin Ehliseaf28662015-04-08 10:58:37 -06002198// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002199// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002200static void deleteLayouts(layer_data* my_data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002201{
Tobin Ehlisad61de42015-12-02 13:53:34 -07002202 if (my_data->descriptorSetLayoutMap.size() <= 0)
David Pinedof5997ab2015-04-27 16:36:17 -06002203 return;
Tobin Ehlisad61de42015-12-02 13:53:34 -07002204 for (auto ii=my_data->descriptorSetLayoutMap.begin(); ii!=my_data->descriptorSetLayoutMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002205 LAYOUT_NODE* pLayout = (*ii).second;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002206 if (pLayout->createInfo.pBinding) {
Chia-I Wu763a7492015-10-26 20:48:51 +08002207 for (uint32_t i=0; i<pLayout->createInfo.bindingCount; i++) {
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002208 if (pLayout->createInfo.pBinding[i].pImmutableSamplers)
2209 delete[] pLayout->createInfo.pBinding[i].pImmutableSamplers;
Tobin Ehliseaf28662015-04-08 10:58:37 -06002210 }
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002211 delete[] pLayout->createInfo.pBinding;
Tobin Ehliseaf28662015-04-08 10:58:37 -06002212 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002213 delete pLayout;
2214 }
Tobin Ehlisad61de42015-12-02 13:53:34 -07002215 my_data->descriptorSetLayoutMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002216}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002217
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002218// Currently clearing a set is removing all previous updates to that set
2219// TODO : Validate if this is correct clearing behavior
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002220static void clearDescriptorSet(layer_data* my_data, VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002221{
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002222 SET_NODE* pSet = getSetNode(my_data, set);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002223 if (!pSet) {
2224 // TODO : Return error
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002225 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002226 loader_platform_thread_lock_mutex(&globalLock);
2227 freeShadowUpdateTree(pSet);
2228 loader_platform_thread_unlock_mutex(&globalLock);
2229 }
2230}
2231
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002232static void clearDescriptorPool(layer_data* my_data, const VkDevice device, const VkDescriptorPool pool, VkDescriptorPoolResetFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002233{
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002234 DESCRIPTOR_POOL_NODE* pPool = getPoolNode(my_data, pool);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002235 if (!pPool) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07002236 log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (uint64_t) pool, 0, DRAWSTATE_INVALID_POOL, "DS",
Chia-I Wue420a332015-10-26 20:04:44 +08002237 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkResetDescriptorPool() call", (uint64_t) pool);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002238 } else {
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002239 // TODO: validate flags
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002240 // For every set off of this pool, clear it
2241 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002242 while (pSet) {
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002243 clearDescriptorSet(my_data, pSet->set);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002244 }
Tobin Ehlisc6457d22015-10-20 16:16:04 -06002245 // Reset available count to max count for this pool
2246 for (uint32_t i=0; i<pPool->availableDescriptorTypeCount.size(); ++i) {
2247 pPool->availableDescriptorTypeCount[i] = pPool->maxDescriptorTypeCount[i];
2248 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002249 }
2250}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002251
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002252// For given CB object, fetch associated CB Node from map
Chia-I Wu1f851912015-10-27 18:04:07 +08002253static GLOBAL_CB_NODE* getCBNode(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002254{
2255 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski13b66742015-11-20 14:33:48 -07002256 if (my_data->commandBufferMap.count(cb) == 0) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002257 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002258 // TODO : How to pass cb as srcObj here?
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07002259 log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_INVALID_COMMAND_BUFFER, "DS",
Chia-I Wu1f851912015-10-27 18:04:07 +08002260 "Attempt to use CommandBuffer %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<uint64_t>(cb));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002261 return NULL;
2262 }
2263 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wu1f851912015-10-27 18:04:07 +08002264 return my_data->commandBufferMap[cb];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002265}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002266
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002267// Free all CB Nodes
2268// NOTE : Calls to this function should be wrapped in mutex
Chia-I Wu1f851912015-10-27 18:04:07 +08002269static void deleteCommandBuffers(layer_data* my_data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002270{
Mark Lobodzinski13b66742015-11-20 14:33:48 -07002271 if (my_data->commandBufferMap.size() <= 0) {
David Pinedof5997ab2015-04-27 16:36:17 -06002272 return;
Mark Lobodzinski13b66742015-11-20 14:33:48 -07002273 }
Chia-I Wu1f851912015-10-27 18:04:07 +08002274 for (auto ii=my_data->commandBufferMap.begin(); ii!=my_data->commandBufferMap.end(); ++ii) {
Courtney Goeltzenleuchter09098a72015-04-27 15:04:43 -06002275 vector<CMD_NODE*> cmd_node_list = (*ii).second->pCmds;
2276 while (!cmd_node_list.empty()) {
2277 CMD_NODE* cmd_node = cmd_node_list.back();
2278 delete cmd_node;
2279 cmd_node_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002280 }
2281 delete (*ii).second;
2282 }
Chia-I Wu1f851912015-10-27 18:04:07 +08002283 my_data->commandBufferMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002284}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002285
Chia-I Wu1f851912015-10-27 18:04:07 +08002286static 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 -06002287{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002288 // TODO : How to pass cb as srcObj here?
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07002289 return log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NO_BEGIN_COMMAND_BUFFER, "DS",
Michael Lentinecbc4a5e2015-11-03 16:19:46 -08002290 "You must call vkBeginCommandBuffer() before this call to %s", caller_name);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002291}
Michael Lentine2b9eda42015-10-28 15:55:18 -07002292
2293bool validateCmdsInCmdBuffer(const layer_data* dev_data, const GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd_type) {
2294 bool skip_call = false;
2295 for (auto cmd : pCB->pCmds) {
2296 if (cmd_type == CMD_EXECUTECOMMANDS && cmd->type != CMD_EXECUTECOMMANDS) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07002297 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, DRAWSTATE_INVALID_COMMAND_BUFFER, "DS",
Michael Lentine2b9eda42015-10-28 15:55:18 -07002298 "vkCmdExecuteCommands() cannot be called on a cmd buffer with exsiting commands.");
2299 }
2300 if (cmd_type != CMD_EXECUTECOMMANDS && cmd->type == CMD_EXECUTECOMMANDS) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07002301 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, DRAWSTATE_INVALID_COMMAND_BUFFER, "DS",
Michael Lentine2b9eda42015-10-28 15:55:18 -07002302 "Commands cannot be added to a cmd buffer with exsiting secondary commands.");
2303 }
2304 }
2305 return skip_call;
2306}
2307
Tobin Ehlis42d440c2015-10-20 17:06:16 -06002308static VkBool32 addCmd(const layer_data* my_data, GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002309{
Michael Lentine2b9eda42015-10-28 15:55:18 -07002310 VkBool32 skipCall = validateCmdsInCmdBuffer(my_data, pCB, cmd);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002311 CMD_NODE* pCmd = new CMD_NODE;
2312 if (pCmd) {
2313 // init cmd node and append to end of cmd LL
2314 memset(pCmd, 0, sizeof(CMD_NODE));
2315 pCmd->cmdNumber = ++pCB->numCmds;
2316 pCmd->type = cmd;
2317 pCB->pCmds.push_back(pCmd);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002318 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002319 // TODO : How to pass cb as srcObj here?
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07002320 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
Chia-I Wu1f851912015-10-27 18:04:07 +08002321 "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 -06002322 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002323 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002324}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002325
Chia-I Wu1f851912015-10-27 18:04:07 +08002326static void resetCB(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002327{
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002328 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002329 if (pCB) {
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06002330 vector<CMD_NODE*> cmd_list = pCB->pCmds;
2331 while (!cmd_list.empty()) {
2332 delete cmd_list.back();
2333 cmd_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002334 }
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06002335 pCB->pCmds.clear();
Tobin Ehlis0cea4082015-08-18 07:10:58 -06002336 // Reset CB state (need to save createInfo)
Chia-I Wu1f851912015-10-27 18:04:07 +08002337 VkCommandBufferAllocateInfo saveCBCI = pCB->createInfo;
Chia-I Wu1f851912015-10-27 18:04:07 +08002338 pCB->commandBuffer = cb;
Tobin Ehlis0cea4082015-08-18 07:10:58 -06002339 pCB->createInfo = saveCBCI;
Michael Lentine27b0f902015-10-12 11:30:14 -05002340 memset(&pCB->beginInfo, 0, sizeof(VkCommandBufferBeginInfo));
2341 pCB->fence = 0;
2342 pCB->numCmds = 0;
2343 memset(pCB->drawCount, 0, NUM_DRAW_TYPES * sizeof(uint64_t));
2344 pCB->state = CB_NEW;
2345 pCB->submitCount = 0;
2346 pCB->status = 0;
2347 pCB->pCmds.clear();
2348 pCB->lastBoundPipeline = 0;
2349 pCB->viewports.clear();
2350 pCB->scissors.clear();
2351 pCB->lineWidth = 0;
2352 pCB->depthBiasConstantFactor = 0;
2353 pCB->depthBiasClamp = 0;
2354 pCB->depthBiasSlopeFactor = 0;
2355 memset(pCB->blendConstants, 0, 4 * sizeof(float));
2356 pCB->minDepthBounds = 0;
2357 pCB->maxDepthBounds = 0;
2358 memset(&pCB->front, 0, sizeof(stencil_data));
2359 memset(&pCB->back, 0, sizeof(stencil_data));
2360 pCB->lastBoundDescriptorSet = 0;
2361 pCB->lastBoundPipelineLayout = 0;
2362 pCB->activeRenderPass = 0;
2363 pCB->activeSubpass = 0;
2364 pCB->framebuffer = 0;
Michael Lentine27b0f902015-10-12 11:30:14 -05002365 pCB->boundDescriptorSets.clear();
2366 pCB->imageLayoutMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002367 pCB->lastVtxBinding = MAX_BINDING;
2368 }
2369}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002370
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002371// Set PSO-related status bits for CB, including dynamic state set via PSO
Tobin Ehlis97866202015-06-10 12:57:07 -06002372static void set_cb_pso_status(GLOBAL_CB_NODE* pCB, const PIPELINE_NODE* pPipe)
2373{
2374 for (uint32_t i = 0; i < pPipe->cbStateCI.attachmentCount; i++) {
Chia-I Wuc51b1212015-10-27 19:25:11 +08002375 if (0 != pPipe->pAttachments[i].colorWriteMask) {
Tobin Ehlis97866202015-06-10 12:57:07 -06002376 pCB->status |= CBSTATUS_COLOR_BLEND_WRITE_ENABLE;
2377 }
2378 }
2379 if (pPipe->dsStateCI.depthWriteEnable) {
Cody Northrop2605cb02015-08-18 15:21:16 -06002380 pCB->status |= CBSTATUS_DEPTH_WRITE_ENABLE;
2381 }
Cody Northrop2605cb02015-08-18 15:21:16 -06002382 if (pPipe->dsStateCI.stencilTestEnable) {
2383 pCB->status |= CBSTATUS_STENCIL_TEST_ENABLE;
Tobin Ehlis97866202015-06-10 12:57:07 -06002384 }
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002385 // Account for any dynamic state not set via this PSO
2386 if (!pPipe->dynStateCI.dynamicStateCount) { // All state is static
2387 pCB->status = CBSTATUS_ALL;
2388 } else {
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002389 // First consider all state on
2390 // Then unset any state that's noted as dynamic in PSO
2391 // Finally OR that into CB statemask
2392 CBStatusFlags psoDynStateMask = CBSTATUS_ALL;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002393 for (uint32_t i=0; i < pPipe->dynStateCI.dynamicStateCount; i++) {
2394 switch (pPipe->dynStateCI.pDynamicStates[i]) {
2395 case VK_DYNAMIC_STATE_VIEWPORT:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002396 psoDynStateMask &= ~CBSTATUS_VIEWPORT_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002397 break;
2398 case VK_DYNAMIC_STATE_SCISSOR:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002399 psoDynStateMask &= ~CBSTATUS_SCISSOR_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002400 break;
2401 case VK_DYNAMIC_STATE_LINE_WIDTH:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002402 psoDynStateMask &= ~CBSTATUS_LINE_WIDTH_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002403 break;
2404 case VK_DYNAMIC_STATE_DEPTH_BIAS:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002405 psoDynStateMask &= ~CBSTATUS_DEPTH_BIAS_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002406 break;
2407 case VK_DYNAMIC_STATE_BLEND_CONSTANTS:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002408 psoDynStateMask &= ~CBSTATUS_BLEND_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002409 break;
2410 case VK_DYNAMIC_STATE_DEPTH_BOUNDS:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002411 psoDynStateMask &= ~CBSTATUS_DEPTH_BOUNDS_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002412 break;
2413 case VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002414 psoDynStateMask &= ~CBSTATUS_STENCIL_READ_MASK_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002415 break;
2416 case VK_DYNAMIC_STATE_STENCIL_WRITE_MASK:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002417 psoDynStateMask &= ~CBSTATUS_STENCIL_WRITE_MASK_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002418 break;
2419 case VK_DYNAMIC_STATE_STENCIL_REFERENCE:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002420 psoDynStateMask &= ~CBSTATUS_STENCIL_REFERENCE_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002421 break;
2422 default:
2423 // TODO : Flag error here
2424 break;
2425 }
2426 }
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06002427 pCB->status |= psoDynStateMask;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06002428 }
Tobin Ehlis97866202015-06-10 12:57:07 -06002429}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002430
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002431// Print the last bound Gfx Pipeline
Chia-I Wu1f851912015-10-27 18:04:07 +08002432static VkBool32 printPipeline(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002433{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002434 VkBool32 skipCall = VK_FALSE;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002435 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002436 if (pCB) {
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002437 PIPELINE_NODE *pPipeTrav = getPipeline(my_data, pCB->lastBoundPipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002438 if (!pPipeTrav) {
2439 // nothing to print
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002440 } else {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07002441 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Michael Lentinecbc4a5e2015-11-03 16:19:46 -08002442 "%s", vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002443 }
2444 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002445 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002446}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002447
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002448// Print details of DS config to stdout
Chia-I Wu1f851912015-10-27 18:04:07 +08002449static VkBool32 printDSConfig(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 Ehlis63bb9482015-03-17 16:24:32 -06002452 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 -06002453 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis7297f192015-06-09 08:39:32 -06002454 if (pCB && pCB->lastBoundDescriptorSet) {
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002455 SET_NODE* pSet = getSetNode(my_data, pCB->lastBoundDescriptorSet);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002456 DESCRIPTOR_POOL_NODE* pPool = getPoolNode(my_data, pSet->pool);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002457 // Print out pool details
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07002458 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Chia-I Wue420a332015-10-26 20:04:44 +08002459 "Details for pool %#" PRIxLEAST64 ".", (uint64_t) pPool->pool);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002460 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07002461 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002462 "%s", poolStr.c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002463 // Print out set details
2464 char prefix[10];
2465 uint32_t index = 0;
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07002466 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Chia-I Wue420a332015-10-26 20:04:44 +08002467 "Details for descriptor set %#" PRIxLEAST64 ".", (uint64_t) pSet->set);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002468 LAYOUT_NODE* pLayout = pSet->pLayout;
2469 // Print layout details
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07002470 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Michael Lentinecbc4a5e2015-11-03 16:19:46 -08002471 "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 -06002472 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002473 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07002474 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002475 "%s", DSLstr.c_str());
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002476 index++;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002477 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
2478 if (pUpdate) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07002479 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Chia-I Wue420a332015-10-26 20:04:44 +08002480 "Update Chain [UC] for descriptor set %#" PRIxLEAST64 ":", (uint64_t) pSet->set);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002481 sprintf(prefix, " [UC] ");
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07002482 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Michael Lentinecbc4a5e2015-11-03 16:19:46 -08002483 "%s", dynamic_display(pUpdate, prefix).c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002484 // TODO : If there is a "view" associated with this update, print CI for that view
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002485 } else {
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06002486 if (0 != pSet->descriptorCount) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07002487 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Chia-I Wue420a332015-10-26 20:04:44 +08002488 "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 -06002489 } else {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07002490 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Chia-I Wue420a332015-10-26 20:04:44 +08002491 "FYI: No descriptors in descriptor set %#" PRIxLEAST64 ".", (uint64_t) pSet->set);
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06002492 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002493 }
2494 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002495 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002496}
2497
Chia-I Wu1f851912015-10-27 18:04:07 +08002498static void printCB(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002499{
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002500 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
David Pinedof5997ab2015-04-27 16:36:17 -06002501 if (pCB && pCB->pCmds.size() > 0) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07002502 log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002503 "Cmds in CB %p", (void*)cb);
Courtney Goeltzenleuchtercf2a5362015-04-27 11:16:35 -06002504 vector<CMD_NODE*> pCmds = pCB->pCmds;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002505 for (auto ii=pCmds.begin(); ii!=pCmds.end(); ++ii) {
2506 // TODO : Need to pass cb as srcObj here
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07002507 log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NONE, "DS",
Michael Lentinecbc4a5e2015-11-03 16:19:46 -08002508 " CMD#%" PRIu64 ": %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002509 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002510 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002511 // Nothing to print
2512 }
2513}
2514
Chia-I Wu1f851912015-10-27 18:04:07 +08002515static VkBool32 synchAndPrintDSConfig(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002516{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002517 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07002518 if (!(my_data->report_data->active_flags & VK_DEBUG_REPORT_INFO_BIT)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002519 return skipCall;
Mike Stroyanfa2f2222015-08-12 17:11:28 -06002520 }
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002521 skipCall |= printDSConfig(my_data, cb);
2522 skipCall |= printPipeline(my_data, cb);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002523 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002524}
2525
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002526// Flags validation error if the associated call is made inside a render pass. The apiName
2527// routine should ONLY be called outside a render pass.
Tobin Ehlis42d440c2015-10-20 17:06:16 -06002528static VkBool32 insideRenderPass(const layer_data* my_data, GLOBAL_CB_NODE *pCB, const char *apiName)
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002529{
2530 VkBool32 inside = VK_FALSE;
2531 if (pCB->activeRenderPass) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07002532 inside = log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER,
Chia-I Wu1f851912015-10-27 18:04:07 +08002533 (uint64_t)pCB->commandBuffer, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002534 "%s: It is invalid to issue this call inside an active render pass (%#" PRIxLEAST64 ")",
Chia-I Wue420a332015-10-26 20:04:44 +08002535 apiName, (uint64_t) pCB->activeRenderPass);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002536 }
2537 return inside;
2538}
2539
2540// Flags validation error if the associated call is made outside a render pass. The apiName
2541// routine should ONLY be called inside a render pass.
Tobin Ehlis42d440c2015-10-20 17:06:16 -06002542static VkBool32 outsideRenderPass(const layer_data* my_data, GLOBAL_CB_NODE *pCB, const char *apiName)
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002543{
2544 VkBool32 outside = VK_FALSE;
2545 if (!pCB->activeRenderPass) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07002546 outside = log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER,
Chia-I Wu1f851912015-10-27 18:04:07 +08002547 (uint64_t)pCB->commandBuffer, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002548 "%s: This call must be issued inside an active render pass.", apiName);
2549 }
2550 return outside;
2551}
2552
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002553static void init_draw_state(layer_data *my_data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002554{
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002555 uint32_t report_flags = 0;
2556 uint32_t debug_action = 0;
2557 FILE *log_output = NULL;
2558 const char *option_str;
Courtney Goeltzenleuchter1781b1c2015-10-05 15:58:38 -06002559 VkDbgMsgCallback callback;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002560 // initialize DrawState options
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002561 report_flags = getLayerOptionFlags("DrawStateReportFlags", 0);
2562 getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &debug_action);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002563
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002564 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002565 {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002566 option_str = getLayerOption("DrawStateLogFilename");
Tobin Ehlisb4b6e7c2015-09-15 09:55:54 -06002567 log_output = getLayerLogOutput(option_str, "DrawState");
Courtney Goeltzenleuchter1781b1c2015-10-05 15:58:38 -06002568 layer_create_msg_callback(my_data->report_data, report_flags, log_callback, (void *) log_output, &callback);
2569 my_data->logging_callback.push_back(callback);
2570 }
2571
2572 if (debug_action & VK_DBG_LAYER_ACTION_DEBUG_OUTPUT) {
2573 layer_create_msg_callback(my_data->report_data, report_flags, win32_debug_output_msg, NULL, &callback);
2574 my_data->logging_callback.push_back(callback);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002575 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002576
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002577 if (!globalLockInitialized)
2578 {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002579 loader_platform_thread_create_mutex(&globalLock);
2580 globalLockInitialized = 1;
2581 }
2582}
2583
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002584VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance)
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06002585{
Tobin Ehliscb085292015-12-01 09:57:09 -07002586 // TODOSC : Shouldn't need any customization here
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002587 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
2588 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Chia-I Wu69f40122015-10-26 21:10:41 +08002589 VkResult result = pTable->CreateInstance(pCreateInfo, pAllocator, pInstance);
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06002590
2591 if (result == VK_SUCCESS) {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002592 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
2593 my_data->report_data = debug_report_create_instance(
2594 pTable,
2595 *pInstance,
Chia-I Wu763a7492015-10-26 20:48:51 +08002596 pCreateInfo->enabledExtensionNameCount,
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002597 pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchterf4a2eba2015-06-08 14:58:39 -06002598
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002599 init_draw_state(my_data);
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06002600 }
2601 return result;
2602}
2603
Jon Ashburne0fa2282015-05-20 09:00:28 -06002604/* hook DestroyInstance to remove tableInstanceMap entry */
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002605VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator)
Jon Ashburne0fa2282015-05-20 09:00:28 -06002606{
Tobin Ehliscb085292015-12-01 09:57:09 -07002607 // TODOSC : Shouldn't need any customization here
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002608 dispatch_key key = get_dispatch_key(instance);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002609 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
2610 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Chia-I Wu69f40122015-10-26 21:10:41 +08002611 pTable->DestroyInstance(instance, pAllocator);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002612
2613 // Clean up logging callback, if any
Courtney Goeltzenleuchter1781b1c2015-10-05 15:58:38 -06002614 while (my_data->logging_callback.size() > 0) {
2615 VkDbgMsgCallback callback = my_data->logging_callback.back();
2616 layer_destroy_msg_callback(my_data->report_data, callback);
2617 my_data->logging_callback.pop_back();
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002618 }
2619
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06002620 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002621 delete my_data->instance_dispatch_table;
2622 layer_data_map.erase(key);
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002623 // TODO : Potential race here with separate threads creating/destroying instance
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002624 if (layer_data_map.empty()) {
Mike Stroyand9dd0072015-08-18 15:56:18 -06002625 // Release mutex when destroying last instance.
2626 loader_platform_thread_delete_mutex(&globalLock);
2627 globalLockInitialized = 0;
2628 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002629}
2630
Jon Ashburnf0615e22015-05-25 14:11:37 -06002631static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
2632{
Tony Barbour29b12062015-07-13 13:37:24 -06002633 uint32_t i;
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002634 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
2635 dev_data->device_extensions.debug_marker_enabled = false;
Michael Lentine27b0f902015-10-12 11:30:14 -05002636 dev_data->device_extensions.wsi_enabled = false;
2637
2638
2639 VkLayerDispatchTable *pDisp = dev_data->device_dispatch_table;
2640 PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr;
2641
Michael Lentine27b0f902015-10-12 11:30:14 -05002642 pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR) gpa(device, "vkCreateSwapchainKHR");
2643 pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR) gpa(device, "vkDestroySwapchainKHR");
2644 pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR) gpa(device, "vkGetSwapchainImagesKHR");
2645 pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR) gpa(device, "vkAcquireNextImageKHR");
2646 pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR) gpa(device, "vkQueuePresentKHR");
Jon Ashburnf0615e22015-05-25 14:11:37 -06002647
Chia-I Wu763a7492015-10-26 20:48:51 +08002648 for (i = 0; i < pCreateInfo->enabledExtensionNameCount; i++) {
Ian Elliottc623ba52015-11-20 14:13:17 -07002649 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) {
Michael Lentine27b0f902015-10-12 11:30:14 -05002650 dev_data->device_extensions.wsi_enabled = true;
2651 }
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002652 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002653 /* Found a matching extension name, mark it enabled and init dispatch table*/
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002654 dev_data->device_extensions.debug_marker_enabled = true;
Jon Ashburnc1d059f2015-12-10 19:12:21 -07002655 initDebugMarkerTable(device);
2656
Jon Ashburnf0615e22015-05-25 14:11:37 -06002657 }
Jon Ashburnf0615e22015-05-25 14:11:37 -06002658 }
2659}
2660
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002661VK_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 -06002662{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002663 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08002664 VkResult result = dev_data->device_dispatch_table->CreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
Tobin Ehliscb085292015-12-01 09:57:09 -07002665 // TODOSC : shouldn't need any customization here
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002666 if (result == VK_SUCCESS) {
2667 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002668 dev_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
Jon Ashburn7e07faf2015-06-18 15:02:58 -06002669 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002670 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002671 return result;
2672}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002673
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002674// prototype
2675static void deleteRenderPasses(layer_data*);
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002676VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002677{
Tobin Ehliscb085292015-12-01 09:57:09 -07002678 // TODOSC : Shouldn't need any customization here
Jeremy Hayesea1fef52015-06-19 11:37:38 -06002679 dispatch_key key = get_dispatch_key(device);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002680 layer_data* dev_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002681 // Free all the memory
2682 loader_platform_thread_lock_mutex(&globalLock);
2683 deletePipelines(dev_data);
2684 deleteRenderPasses(dev_data);
Chia-I Wu1f851912015-10-27 18:04:07 +08002685 deleteCommandBuffers(dev_data);
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002686 deletePools(dev_data);
2687 deleteLayouts(dev_data);
Tobin Ehlisb46be812015-10-23 16:00:08 -06002688 dev_data->imageViewMap.clear();
2689 dev_data->imageMap.clear();
2690 dev_data->bufferViewMap.clear();
2691 dev_data->bufferMap.clear();
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002692 loader_platform_thread_unlock_mutex(&globalLock);
2693
Chia-I Wu69f40122015-10-26 21:10:41 +08002694 dev_data->device_dispatch_table->DestroyDevice(device, pAllocator);
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06002695 tableDebugMarkerMap.erase(key);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002696 delete dev_data->device_dispatch_table;
2697 layer_data_map.erase(key);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002698}
2699
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002700static const VkLayerProperties ds_global_layers[] = {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002701 {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002702 "DrawState",
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002703 VK_API_VERSION,
2704 VK_MAKE_VERSION(0, 1, 0),
2705 "Validation layer: DrawState",
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002706 }
Jon Ashburneb2728b2015-04-10 14:33:07 -06002707};
2708
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002709VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002710 const char *pLayerName,
2711 uint32_t *pCount,
2712 VkExtensionProperties* pProperties)
Jon Ashburneb2728b2015-04-10 14:33:07 -06002713{
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002714 /* DrawState does not have any global extensions */
2715 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
2716}
Jon Ashburneb2728b2015-04-10 14:33:07 -06002717
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002718VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002719 uint32_t *pCount,
2720 VkLayerProperties* pProperties)
2721{
2722 return util_GetLayerProperties(ARRAY_SIZE(ds_global_layers),
2723 ds_global_layers,
2724 pCount, pProperties);
2725}
Jon Ashburneb2728b2015-04-10 14:33:07 -06002726
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002727static const VkExtensionProperties ds_device_extensions[] = {
2728 {
2729 DEBUG_MARKER_EXTENSION_NAME,
2730 VK_MAKE_VERSION(0, 1, 0),
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002731 }
2732};
2733
2734static const VkLayerProperties ds_device_layers[] = {
2735 {
2736 "DrawState",
2737 VK_API_VERSION,
2738 VK_MAKE_VERSION(0, 1, 0),
2739 "Validation layer: DrawState",
2740 }
2741};
2742
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002743VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002744 VkPhysicalDevice physicalDevice,
2745 const char* pLayerName,
2746 uint32_t* pCount,
2747 VkExtensionProperties* pProperties)
2748{
Tobin Ehlis32479352015-12-01 09:48:58 -07002749 // DrawState does not have any physical device extensions
Jon Ashburnaff81ff2015-11-02 17:37:20 -07002750 if (pLayerName == NULL) {
2751 dispatch_key key = get_dispatch_key(physicalDevice);
2752 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlis32479352015-12-01 09:48:58 -07002753 return my_data->instance_dispatch_table->EnumerateDeviceExtensionProperties(
Jon Ashburnaff81ff2015-11-02 17:37:20 -07002754 physicalDevice,
2755 NULL,
2756 pCount,
2757 pProperties);
2758 } else {
2759 return util_GetExtensionProperties(ARRAY_SIZE(ds_device_extensions),
2760 ds_device_extensions,
2761 pCount, pProperties);
2762 }
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002763}
2764
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002765VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002766 VkPhysicalDevice physicalDevice,
2767 uint32_t* pCount,
2768 VkLayerProperties* pProperties)
2769{
Tobin Ehlis32479352015-12-01 09:48:58 -07002770 /* DrawState physical device layers are the same as global */
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06002771 return util_GetLayerProperties(ARRAY_SIZE(ds_device_layers), ds_device_layers,
2772 pCount, pProperties);
Jon Ashburneb2728b2015-04-10 14:33:07 -06002773}
2774
Michael Lentine27b0f902015-10-12 11:30:14 -05002775bool ValidateCmdBufImageLayouts(VkCommandBuffer cmdBuffer) {
2776 bool skip_call = false;
2777 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
2778 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
2779 for (auto cb_image_data : pCB->imageLayoutMap) {
2780 auto image_data = dev_data->imageLayoutMap.find(cb_image_data.first);
2781 if (image_data == dev_data->imageLayoutMap.end()) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07002782 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentinecbc4a5e2015-11-03 16:19:46 -08002783 "Cannot submit cmd buffer using deleted image %" PRIu64 ".", reinterpret_cast<uint64_t>(cb_image_data.first));
Michael Lentine27b0f902015-10-12 11:30:14 -05002784 } else {
2785 if (dev_data->imageLayoutMap[cb_image_data.first]->layout != cb_image_data.second.initialLayout) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07002786 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentine27b0f902015-10-12 11:30:14 -05002787 "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);
2788 }
2789 dev_data->imageLayoutMap[cb_image_data.first]->layout = cb_image_data.second.layout;
2790 }
2791 }
2792 return skip_call;
2793}
2794
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002795VK_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 -06002796{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002797 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis28be0be2015-05-22 12:38:16 -06002798 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06002799 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06002800 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
Chia-I Wu483e7702015-10-26 17:20:32 +08002801 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Chia-I Wu763a7492015-10-26 20:48:51 +08002802 for (uint32_t i=0; i < submit->commandBufferCount; i++) {
Mark Lobodzinski78940a42015-11-30 16:48:53 -07002803
2804#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
2805 skipCall |= ValidateCmdBufImageLayouts(submit->pCommandBuffers[i]);
2806#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
2807
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06002808 // Validate that cmd buffers have been updated
2809 pCB = getCBNode(dev_data, submit->pCommandBuffers[i]);
2810 loader_platform_thread_lock_mutex(&globalLock);
2811 pCB->submitCount++; // increment submit count
Chia-I Wu1f851912015-10-27 18:04:07 +08002812 if ((pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT) && (pCB->submitCount > 1)) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07002813 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_COMMAND_BUFFER_SINGLE_SUBMIT_VIOLATION, "DS",
Michael Lentine27b0f902015-10-12 11:30:14 -05002814 "CB %#" PRIxLEAST64 " was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted %#" PRIxLEAST64 " times.",
2815 reinterpret_cast<uint64_t>(pCB->commandBuffer), pCB->submitCount);
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06002816 }
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07002817 if (CB_RECORDED != pCB->state) {
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06002818 // Flag error for using CB w/o vkEndCommandBuffer() called
2819 // TODO : How to pass cb as srcObj?
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07002820 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NO_END_COMMAND_BUFFER, "DS",
Chia-I Wu1f851912015-10-27 18:04:07 +08002821 "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 -06002822 loader_platform_thread_unlock_mutex(&globalLock);
2823 return VK_ERROR_VALIDATION_FAILED;
2824 }
Tobin Ehlise90b1712015-05-27 14:30:06 -06002825 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis28be0be2015-05-22 12:38:16 -06002826 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002827 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002828 if (VK_FALSE == skipCall)
Chia-I Wu483e7702015-10-26 17:20:32 +08002829 return dev_data->device_dispatch_table->QueueSubmit(queue, submitCount, pSubmits, fence);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002830 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002831}
2832
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002833VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002834{
Chia-I Wu69f40122015-10-26 21:10:41 +08002835 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 -06002836 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002837}
2838
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002839VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySemaphore(VkDevice device, VkSemaphore semaphore, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002840{
Chia-I Wu69f40122015-10-26 21:10:41 +08002841 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 -06002842 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002843}
2844
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002845VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002846{
Chia-I Wu69f40122015-10-26 21:10:41 +08002847 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 -06002848 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002849}
2850
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002851VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002852{
Chia-I Wu69f40122015-10-26 21:10:41 +08002853 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 -06002854 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002855}
2856
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002857VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002858{
Tobin Ehlisb46be812015-10-23 16:00:08 -06002859 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08002860 dev_data->device_dispatch_table->DestroyBuffer(device, buffer, pAllocator);
Chia-I Wue420a332015-10-26 20:04:44 +08002861 dev_data->bufferMap.erase(buffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002862}
2863
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002864VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBufferView(VkDevice device, VkBufferView bufferView, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002865{
Tobin Ehlisb46be812015-10-23 16:00:08 -06002866 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08002867 dev_data->device_dispatch_table->DestroyBufferView(device, bufferView, pAllocator);
Chia-I Wue420a332015-10-26 20:04:44 +08002868 dev_data->bufferViewMap.erase(bufferView);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002869}
2870
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002871VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002872{
Tobin Ehlisb46be812015-10-23 16:00:08 -06002873 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08002874 dev_data->device_dispatch_table->DestroyImage(device, image, pAllocator);
Chia-I Wue420a332015-10-26 20:04:44 +08002875 dev_data->imageMap.erase(image);
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 vkDestroyImageView(VkDevice device, VkImageView imageView, 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->DestroyImageView(device, imageView, 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 vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule, 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->DestroyShaderModule(device, shaderModule, 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 vkDestroyPipeline(VkDevice device, VkPipeline pipeline, 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->DestroyPipeline(device, pipeline, 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 vkDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002897{
Chia-I Wu69f40122015-10-26 21:10:41 +08002898 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 -06002899 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002900}
2901
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002902VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySampler(VkDevice device, VkSampler sampler, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002903{
Chia-I Wu69f40122015-10-26 21:10:41 +08002904 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 -06002905 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002906}
2907
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002908VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002909{
Chia-I Wu69f40122015-10-26 21:10:41 +08002910 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 -06002911 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002912}
2913
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002914VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002915{
Chia-I Wu69f40122015-10-26 21:10:41 +08002916 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 -06002917 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002918}
2919
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002920VK_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 -06002921{
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002922 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
2923
2924 for (auto i = 0; i < count; i++) {
2925 // Delete CB information structure, and remove from commandBufferMap
2926 auto cb = dev_data->commandBufferMap.find(pCommandBuffers[i]);
Mark Lobodzinski13b66742015-11-20 14:33:48 -07002927 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002928 if (cb != dev_data->commandBufferMap.end()) {
2929 delete (*cb).second;
2930 dev_data->commandBufferMap.erase(cb);
2931 }
2932
2933 // Remove commandBuffer reference from commandPoolMap
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07002934 dev_data->commandPoolMap[commandPool].commandBuffers.remove(pCommandBuffers[i]);
Mark Lobodzinski13b66742015-11-20 14:33:48 -07002935 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002936 }
2937
2938 dev_data->device_dispatch_table->FreeCommandBuffers(device, commandPool, count, pCommandBuffers);
2939}
2940
2941VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkCommandPool* pCommandPool)
2942{
2943 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
2944
2945 VkResult result = dev_data->device_dispatch_table->CreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
2946
2947 if (VK_SUCCESS == result) {
Mark Lobodzinski13b66742015-11-20 14:33:48 -07002948 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07002949 dev_data->commandPoolMap[*pCommandPool].createFlags = pCreateInfo->flags;
Mark Lobodzinski13b66742015-11-20 14:33:48 -07002950 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002951 }
2952 return result;
2953}
2954
2955VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks* pAllocator)
2956{
2957 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski13b66742015-11-20 14:33:48 -07002958 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002959
2960 // Must remove cmdpool from cmdpoolmap, after removing all cmdbuffers in its list from the commandPoolMap
2961 if (dev_data->commandPoolMap.find(commandPool) != dev_data->commandPoolMap.end()) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07002962 for (auto poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.begin(); poolCb != dev_data->commandPoolMap[commandPool].commandBuffers.end();) {
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002963 auto del_cb = dev_data->commandBufferMap.find(*poolCb);
2964 delete (*del_cb).second; // delete CB info structure
2965 dev_data->commandBufferMap.erase(del_cb); // Remove this command buffer from cbMap
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07002966 poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.erase(poolCb); // Remove CB reference from commandPoolMap's list
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002967 }
2968 }
2969 dev_data->commandPoolMap.erase(commandPool);
Mark Lobodzinski13b66742015-11-20 14:33:48 -07002970
2971 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07002972 dev_data->device_dispatch_table->DestroyCommandPool(device, commandPool, pAllocator);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002973}
2974
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07002975VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandPool(
2976 VkDevice device,
2977 VkCommandPool commandPool,
2978 VkCommandPoolResetFlags flags)
2979{
2980 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
2981 VkResult result = VK_ERROR_VALIDATION_FAILED;
2982
2983 result = dev_data->device_dispatch_table->ResetCommandPool(device, commandPool, flags);
2984 // Reset all of the CBs allocated from this pool
2985 if (VK_SUCCESS == result) {
2986 auto it = dev_data->commandPoolMap[commandPool].commandBuffers.begin();
2987 while (it != dev_data->commandPoolMap[commandPool].commandBuffers.end()) {
2988 resetCB(dev_data, (*it));
2989 ++it;
2990 }
2991 }
2992 return result;
2993}
2994
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08002995VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002996{
Chia-I Wu69f40122015-10-26 21:10:41 +08002997 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 -06002998 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002999}
3000
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003001VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003002{
Chia-I Wu69f40122015-10-26 21:10:41 +08003003 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 -06003004 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003005}
3006
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003007VK_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 -06003008{
3009 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003010 VkResult result = dev_data->device_dispatch_table->CreateBuffer(device, pCreateInfo, pAllocator, pBuffer);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003011 if (VK_SUCCESS == result) {
3012 loader_platform_thread_lock_mutex(&globalLock);
3013 // 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 +08003014 dev_data->bufferMap[*pBuffer] = unique_ptr<VkBufferCreateInfo>(new VkBufferCreateInfo(*pCreateInfo));
Tobin Ehlisb46be812015-10-23 16:00:08 -06003015 loader_platform_thread_unlock_mutex(&globalLock);
3016 }
3017 return result;
3018}
3019
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003020VK_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 -06003021{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003022 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003023 VkResult result = dev_data->device_dispatch_table->CreateBufferView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003024 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003025 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue420a332015-10-26 20:04:44 +08003026 dev_data->bufferViewMap[*pView] = unique_ptr<VkBufferViewCreateInfo>(new VkBufferViewCreateInfo(*pCreateInfo));
Tobin Ehlisb46be812015-10-23 16:00:08 -06003027 loader_platform_thread_unlock_mutex(&globalLock);
3028 }
3029 return result;
3030}
3031
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003032VK_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 -06003033{
3034 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003035 VkResult result = dev_data->device_dispatch_table->CreateImage(device, pCreateInfo, pAllocator, pImage);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003036 if (VK_SUCCESS == result) {
Michael Lentine27b0f902015-10-12 11:30:14 -05003037 IMAGE_NODE* image_node = new IMAGE_NODE;
3038 image_node->layout = pCreateInfo->initialLayout;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003039 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue420a332015-10-26 20:04:44 +08003040 dev_data->imageMap[*pImage] = unique_ptr<VkImageCreateInfo>(new VkImageCreateInfo(*pCreateInfo));
Michael Lentine27b0f902015-10-12 11:30:14 -05003041 dev_data->imageLayoutMap[*pImage] = image_node;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003042 loader_platform_thread_unlock_mutex(&globalLock);
3043 }
3044 return result;
3045}
3046
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003047VK_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 -06003048{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003049 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003050 VkResult result = dev_data->device_dispatch_table->CreateImageView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003051 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003052 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue420a332015-10-26 20:04:44 +08003053 dev_data->imageViewMap[*pView] = unique_ptr<VkImageViewCreateInfo>(new VkImageViewCreateInfo(*pCreateInfo));
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003054 loader_platform_thread_unlock_mutex(&globalLock);
3055 }
3056 return result;
3057}
3058
Jon Ashburn0d60d272015-07-09 15:02:25 -06003059//TODO handle pipeline caches
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003060VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineCache(
Jon Ashburn0d60d272015-07-09 15:02:25 -06003061 VkDevice device,
3062 const VkPipelineCacheCreateInfo* pCreateInfo,
Chia-I Wu1f851912015-10-27 18:04:07 +08003063 const VkAllocationCallbacks* pAllocator,
Jon Ashburn0d60d272015-07-09 15:02:25 -06003064 VkPipelineCache* pPipelineCache)
3065{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003066 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003067 VkResult result = dev_data->device_dispatch_table->CreatePipelineCache(device, pCreateInfo, pAllocator, pPipelineCache);
Jon Ashburn0d60d272015-07-09 15:02:25 -06003068 return result;
3069}
3070
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003071VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineCache(
Jon Ashburn0d60d272015-07-09 15:02:25 -06003072 VkDevice device,
Chia-I Wu69f40122015-10-26 21:10:41 +08003073 VkPipelineCache pipelineCache,
Chia-I Wu1f851912015-10-27 18:04:07 +08003074 const VkAllocationCallbacks* pAllocator)
Jon Ashburn0d60d272015-07-09 15:02:25 -06003075{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003076 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003077 dev_data->device_dispatch_table->DestroyPipelineCache(device, pipelineCache, pAllocator);
Jon Ashburn0d60d272015-07-09 15:02:25 -06003078}
3079
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003080VKAPI_ATTR VkResult VKAPI_CALL vkGetPipelineCacheData(
Jon Ashburn0d60d272015-07-09 15:02:25 -06003081 VkDevice device,
3082 VkPipelineCache pipelineCache,
Chia-I Wu28c3c432015-10-26 19:17:06 +08003083 size_t* pDataSize,
Jon Ashburn0d60d272015-07-09 15:02:25 -06003084 void* pData)
3085{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003086 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu28c3c432015-10-26 19:17:06 +08003087 VkResult result = dev_data->device_dispatch_table->GetPipelineCacheData(device, pipelineCache, pDataSize, pData);
Jon Ashburn0d60d272015-07-09 15:02:25 -06003088 return result;
3089}
3090
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003091VKAPI_ATTR VkResult VKAPI_CALL vkMergePipelineCaches(
Jon Ashburn0d60d272015-07-09 15:02:25 -06003092 VkDevice device,
Chia-I Wu1f851912015-10-27 18:04:07 +08003093 VkPipelineCache dstCache,
Jon Ashburn0d60d272015-07-09 15:02:25 -06003094 uint32_t srcCacheCount,
3095 const VkPipelineCache* pSrcCaches)
3096{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003097 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu1f851912015-10-27 18:04:07 +08003098 VkResult result = dev_data->device_dispatch_table->MergePipelineCaches(device, dstCache, srcCacheCount, pSrcCaches);
Jon Ashburn0d60d272015-07-09 15:02:25 -06003099 return result;
3100}
3101
Mark Lobodzinski2adea752015-11-10 15:25:01 -07003102VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateGraphicsPipelines(
3103 VkDevice device,
3104 VkPipelineCache pipelineCache,
3105 uint32_t count,
3106 const VkGraphicsPipelineCreateInfo *pCreateInfos,
3107 const VkAllocationCallbacks *pAllocator,
3108 VkPipeline *pPipelines)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003109{
Courtney Goeltzenleuchtera54b76a2015-09-04 13:39:59 -06003110 VkResult result = VK_SUCCESS;
Tobin Ehlise48be202015-09-16 10:33:53 -06003111 //TODO What to do with pipelineCache?
Tobin Ehlisde63c532015-06-18 15:59:33 -06003112 // The order of operations here is a little convoluted but gets the job done
3113 // 1. Pipeline create state is first shadowed into PIPELINE_NODE struct
3114 // 2. Create state is then validated (which uses flags setup during shadowing)
3115 // 3. If everything looks good, we'll then create the pipeline and add NODE to pipelineMap
Tobin Ehlise48be202015-09-16 10:33:53 -06003116 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis76c18852015-09-17 16:33:58 -06003117 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
3118 vector<PIPELINE_NODE*> pPipeNode(count);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003119 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski2adea752015-11-10 15:25:01 -07003120
Tobin Ehlise48be202015-09-16 10:33:53 -06003121 uint32_t i=0;
Tobin Ehlisde63c532015-06-18 15:59:33 -06003122 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski2adea752015-11-10 15:25:01 -07003123
Tobin Ehlise48be202015-09-16 10:33:53 -06003124 for (i=0; i<count; i++) {
Mark Lobodzinski2adea752015-11-10 15:25:01 -07003125 pPipeNode[i] = initGraphicsPipeline(dev_data, &pCreateInfos[i], NULL);
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003126 skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
Tobin Ehlise48be202015-09-16 10:33:53 -06003127 }
Mark Lobodzinski2adea752015-11-10 15:25:01 -07003128
Tobin Ehlisde63c532015-06-18 15:59:33 -06003129 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis32479352015-12-01 09:48:58 -07003130
Tobin Ehlisad61de42015-12-02 13:53:34 -07003131 if (VK_FALSE == skipCall) {
Mark Lobodzinski2adea752015-11-10 15:25:01 -07003132 result = dev_data->device_dispatch_table->CreateGraphicsPipelines(device,
3133 pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
Tobin Ehlisde63c532015-06-18 15:59:33 -06003134 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlise48be202015-09-16 10:33:53 -06003135 for (i=0; i<count; i++) {
3136 pPipeNode[i]->pipeline = pPipelines[i];
Chia-I Wue420a332015-10-26 20:04:44 +08003137 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
Tobin Ehlise48be202015-09-16 10:33:53 -06003138 }
Tobin Ehlisde63c532015-06-18 15:59:33 -06003139 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003140 } else {
Tobin Ehlise48be202015-09-16 10:33:53 -06003141 for (i=0; i<count; i++) {
3142 if (pPipeNode[i]) {
3143 // If we allocated a pipeNode, need to clean it up here
3144 delete[] pPipeNode[i]->pVertexBindingDescriptions;
3145 delete[] pPipeNode[i]->pVertexAttributeDescriptions;
3146 delete[] pPipeNode[i]->pAttachments;
3147 delete pPipeNode[i];
3148 }
Tobin Ehlisde63c532015-06-18 15:59:33 -06003149 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003150 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlisde63c532015-06-18 15:59:33 -06003151 }
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06003152 return result;
3153}
3154
Mark Lobodzinski2adea752015-11-10 15:25:01 -07003155VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateComputePipelines(
3156 VkDevice device,
3157 VkPipelineCache pipelineCache,
3158 uint32_t count,
3159 const VkComputePipelineCreateInfo *pCreateInfos,
3160 const VkAllocationCallbacks *pAllocator,
3161 VkPipeline *pPipelines)
3162{
3163 VkResult result = VK_SUCCESS;
3164 VkBool32 skipCall = VK_FALSE;
3165
3166 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
3167 vector<PIPELINE_NODE*> pPipeNode(count);
3168 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3169
3170 uint32_t i=0;
3171 loader_platform_thread_lock_mutex(&globalLock);
3172 for (i=0; i<count; i++) {
3173 // TODO: Verify compute stage bits
3174
3175 // Create and initialize internal tracking data structure
3176 pPipeNode[i] = new PIPELINE_NODE;
3177 memset((void*)pPipeNode[i], 0, sizeof(PIPELINE_NODE));
3178 memcpy(&pPipeNode[i]->computePipelineCI, (const void*)&pCreateInfos[i], sizeof(VkComputePipelineCreateInfo));
3179
3180 // TODO: Add Compute Pipeline Verification
3181 // skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
3182 }
3183 loader_platform_thread_unlock_mutex(&globalLock);
3184
3185 if (VK_FALSE == skipCall) {
3186 result = dev_data->device_dispatch_table->CreateComputePipelines(device, pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
3187 loader_platform_thread_lock_mutex(&globalLock);
3188 for (i=0; i<count; i++) {
3189 pPipeNode[i]->pipeline = pPipelines[i];
3190 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
3191 }
3192 loader_platform_thread_unlock_mutex(&globalLock);
3193 } else {
3194 for (i=0; i<count; i++) {
3195 if (pPipeNode[i]) {
3196 // Clean up any locally allocated data structures
3197 delete pPipeNode[i];
3198 }
3199 }
3200 return VK_ERROR_VALIDATION_FAILED;
3201 }
3202 return result;
3203}
3204
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003205VK_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 -06003206{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003207 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003208 VkResult result = dev_data->device_dispatch_table->CreateSampler(device, pCreateInfo, pAllocator, pSampler);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003209 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003210 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue420a332015-10-26 20:04:44 +08003211 dev_data->sampleMap[*pSampler] = unique_ptr<SAMPLER_NODE>(new SAMPLER_NODE(pSampler, pCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003212 loader_platform_thread_unlock_mutex(&globalLock);
3213 }
3214 return result;
3215}
3216
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003217VK_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 -06003218{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003219 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003220 VkResult result = dev_data->device_dispatch_table->CreateDescriptorSetLayout(device, pCreateInfo, pAllocator, pSetLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003221 if (VK_SUCCESS == result) {
Tobin Ehliscb085292015-12-01 09:57:09 -07003222 // TODOSC : Capture layout bindings set
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003223 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
3224 if (NULL == pNewNode) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07003225 if (log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, (uint64_t) *pSetLayout, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003226 "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()"))
3227 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003228 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003229 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003230 pNewNode->createInfo.pBinding = new VkDescriptorSetLayoutBinding[pCreateInfo->bindingCount];
3231 memcpy((void*)pNewNode->createInfo.pBinding, pCreateInfo->pBinding, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->bindingCount);
Chia-I Wub5689ee2015-10-31 00:31:16 +08003232 // g++ does not like reserve with size 0
3233 if (pCreateInfo->bindingCount)
3234 pNewNode->bindings.reserve(pCreateInfo->bindingCount);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003235 uint32_t totalCount = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08003236 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
Chia-I Wub5689ee2015-10-31 00:31:16 +08003237 if (!pNewNode->bindings.insert(pCreateInfo->pBinding[i].binding).second) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07003238 if (log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, (uint64_t) *pSetLayout, 0, DRAWSTATE_INVALID_LAYOUT, "DS",
Chia-I Wub5689ee2015-10-31 00:31:16 +08003239 "duplicated binding number in VkDescriptorSetLayoutBinding"))
3240 return VK_ERROR_VALIDATION_FAILED;
3241 }
3242
Chia-I Wu045654f2015-11-06 06:42:02 +08003243 totalCount += pCreateInfo->pBinding[i].descriptorCount;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003244 if (pCreateInfo->pBinding[i].pImmutableSamplers) {
3245 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBinding[i].pImmutableSamplers;
Chia-I Wu045654f2015-11-06 06:42:02 +08003246 *ppIS = new VkSampler[pCreateInfo->pBinding[i].descriptorCount];
3247 memcpy(*ppIS, pCreateInfo->pBinding[i].pImmutableSamplers, pCreateInfo->pBinding[i].descriptorCount*sizeof(VkSampler));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003248 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003249 }
3250 if (totalCount > 0) {
Cody Northrop8a908322015-10-26 14:07:35 -06003251 pNewNode->descriptorTypes.resize(totalCount);
Tobin Ehlis68fbd442015-10-27 12:25:35 -06003252 pNewNode->stageFlags.resize(totalCount);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003253 uint32_t offset = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003254 uint32_t j = 0;
Tobin Ehlis61ebb312015-11-04 12:28:28 -07003255 VkDescriptorType dType;
Chia-I Wu763a7492015-10-26 20:48:51 +08003256 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
Tobin Ehlis61ebb312015-11-04 12:28:28 -07003257 dType = pCreateInfo->pBinding[i].descriptorType;
Chia-I Wu045654f2015-11-06 06:42:02 +08003258 for (j = 0; j < pCreateInfo->pBinding[i].descriptorCount; j++) {
Tobin Ehlis61ebb312015-11-04 12:28:28 -07003259 pNewNode->descriptorTypes[offset + j] = dType;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003260 pNewNode->stageFlags[offset + j] = pCreateInfo->pBinding[i].stageFlags;
Tobin Ehlis61ebb312015-11-04 12:28:28 -07003261 if ((dType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
3262 (dType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
3263 pNewNode->dynamicDescriptorCount++;
3264 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003265 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003266 offset += j;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003267 }
3268 }
3269 pNewNode->layout = *pSetLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003270 pNewNode->startIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003271 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
3272 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003273 // Put new node at Head of global Layer list
3274 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisad61de42015-12-02 13:53:34 -07003275 dev_data->descriptorSetLayoutMap[*pSetLayout] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003276 loader_platform_thread_unlock_mutex(&globalLock);
3277 }
3278 return result;
3279}
3280
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003281VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003282{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003283 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003284 VkResult result = dev_data->device_dispatch_table->CreatePipelineLayout(device, pCreateInfo, pAllocator, pPipelineLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003285 if (VK_SUCCESS == result) {
Tobin Ehliscb085292015-12-01 09:57:09 -07003286 // TODOSC : Merge capture of the setLayouts per pipeline
Tobin Ehlis982099b2015-11-05 09:52:49 -07003287 PIPELINE_LAYOUT_NODE& plNode = dev_data->pipelineLayoutMap[*pPipelineLayout];
Chia-I Wu763a7492015-10-26 20:48:51 +08003288 plNode.descriptorSetLayouts.resize(pCreateInfo->setLayoutCount);
Tobin Ehlis91423d22015-10-20 10:11:55 -06003289 uint32_t i = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08003290 for (i=0; i<pCreateInfo->setLayoutCount; ++i) {
Tobin Ehlis91423d22015-10-20 10:11:55 -06003291 plNode.descriptorSetLayouts[i] = pCreateInfo->pSetLayouts[i];
3292 }
Cody Northrop8a908322015-10-26 14:07:35 -06003293 plNode.pushConstantRanges.resize(pCreateInfo->pushConstantRangeCount);
Tobin Ehlis91423d22015-10-20 10:11:55 -06003294 for (i=0; i<pCreateInfo->pushConstantRangeCount; ++i) {
3295 plNode.pushConstantRanges[i] = pCreateInfo->pPushConstantRanges[i];
3296 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003297 }
3298 return result;
3299}
3300
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003301VK_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 -06003302{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003303 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08003304 VkResult result = dev_data->device_dispatch_table->CreateDescriptorPool(device, pCreateInfo, pAllocator, pDescriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003305 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003306 // Insert this pool into Global Pool LL at head
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07003307 if (log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (uint64_t) *pDescriptorPool, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
Chia-I Wue420a332015-10-26 20:04:44 +08003308 "Created Descriptor Pool %#" PRIxLEAST64, (uint64_t) *pDescriptorPool))
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003309 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003310 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003311 DESCRIPTOR_POOL_NODE* pNewNode = new DESCRIPTOR_POOL_NODE(*pDescriptorPool, pCreateInfo);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003312 if (NULL == pNewNode) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07003313 if (log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (uint64_t) *pDescriptorPool, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003314 "Out of memory while attempting to allocate DESCRIPTOR_POOL_NODE in vkCreateDescriptorPool()"))
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003315 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003316 } else {
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003317 dev_data->descriptorPoolMap[*pDescriptorPool] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003318 }
3319 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003320 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003321 // Need to do anything if pool create fails?
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003322 }
3323 return result;
3324}
3325
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003326VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorPoolResetFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003327{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003328 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003329 VkResult result = dev_data->device_dispatch_table->ResetDescriptorPool(device, descriptorPool, flags);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003330 if (VK_SUCCESS == result) {
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003331 clearDescriptorPool(dev_data, device, descriptorPool, flags);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003332 }
3333 return result;
3334}
3335
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003336VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo* pAllocateInfo, VkDescriptorSet* pDescriptorSets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003337{
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003338 VkBool32 skipCall = VK_FALSE;
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003339 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003340 // Verify that requested descriptorSets are available in pool
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003341 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003342 if (!pPoolNode) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07003343 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (uint64_t) pAllocateInfo->descriptorPool, 0, DRAWSTATE_INVALID_POOL, "DS",
Chia-I Wu1f851912015-10-27 18:04:07 +08003344 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pAllocateInfo->descriptorPool);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003345 } else { // Make sure pool has all the available descriptors before calling down chain
Chia-I Wu1f851912015-10-27 18:04:07 +08003346 skipCall |= validate_descriptor_availability_in_pool(dev_data, pPoolNode, pAllocateInfo->setLayoutCount, pAllocateInfo->pSetLayouts);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003347 }
3348 if (skipCall)
3349 return VK_ERROR_VALIDATION_FAILED;
Chia-I Wu1f851912015-10-27 18:04:07 +08003350 VkResult result = dev_data->device_dispatch_table->AllocateDescriptorSets(device, pAllocateInfo, pDescriptorSets);
Cody Northropc8aa4a52015-08-03 12:47:29 -06003351 if (VK_SUCCESS == result) {
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003352 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003353 if (pPoolNode) {
Chia-I Wu1f851912015-10-27 18:04:07 +08003354 if (pAllocateInfo->setLayoutCount == 0) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07003355 log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pAllocateInfo->setLayoutCount, 0, DRAWSTATE_NONE, "DS",
Chia-I Wu1f851912015-10-27 18:04:07 +08003356 "AllocateDescriptorSets called with 0 count");
Cody Northropc8aa4a52015-08-03 12:47:29 -06003357 }
Chia-I Wu1f851912015-10-27 18:04:07 +08003358 for (uint32_t i = 0; i < pAllocateInfo->setLayoutCount; i++) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07003359 log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, (uint64_t) pDescriptorSets[i], 0, DRAWSTATE_NONE, "DS",
Chia-I Wue420a332015-10-26 20:04:44 +08003360 "Created Descriptor Set %#" PRIxLEAST64, (uint64_t) pDescriptorSets[i]);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003361 // Create new set node and add to head of pool nodes
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003362 SET_NODE* pNewNode = new SET_NODE;
3363 if (NULL == pNewNode) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07003364 if (log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, (uint64_t) pDescriptorSets[i], 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
Chia-I Wu1f851912015-10-27 18:04:07 +08003365 "Out of memory while attempting to allocate SET_NODE in vkAllocateDescriptorSets()"))
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003366 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003367 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003368 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlisf6e93e02015-10-19 12:09:13 -06003369 // TODO : Pool should store a total count of each type of Descriptor available
3370 // When descriptors are allocated, decrement the count and validate here
3371 // that the count doesn't go below 0. One reset/free need to bump count back up.
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003372 // Insert set at head of Set LL for this pool
3373 pNewNode->pNext = pPoolNode->pSets;
3374 pPoolNode->pSets = pNewNode;
Chia-I Wu1f851912015-10-27 18:04:07 +08003375 LAYOUT_NODE* pLayout = getLayoutNode(dev_data, pAllocateInfo->pSetLayouts[i]);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003376 if (NULL == pLayout) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07003377 if (log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, (uint64_t) pAllocateInfo->pSetLayouts[i], 0, DRAWSTATE_INVALID_LAYOUT, "DS",
Chia-I Wu1f851912015-10-27 18:04:07 +08003378 "Unable to find set layout node for layout %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pAllocateInfo->pSetLayouts[i]))
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003379 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003380 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06003381 pNewNode->pLayout = pLayout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003382 pNewNode->pool = pAllocateInfo->descriptorPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003383 pNewNode->set = pDescriptorSets[i];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003384 pNewNode->descriptorCount = pLayout->endIndex + 1;
3385 if (pNewNode->descriptorCount) {
3386 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
3387 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
3388 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
3389 }
Chia-I Wue420a332015-10-26 20:04:44 +08003390 dev_data->setMap[pDescriptorSets[i]] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003391 }
3392 }
3393 }
3394 }
3395 return result;
3396}
3397
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003398VK_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 -06003399{
Tobin Ehlis3c543112015-10-08 13:13:50 -06003400 VkBool32 skipCall = VK_FALSE;
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003401 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003402 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, descriptorPool);
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003403 if (pPoolNode && !(VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT & pPoolNode->createInfo.flags)) {
3404 // Can't Free from a NON_FREE pool
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07003405 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE, (uint64_t)device, 0, DRAWSTATE_CANT_FREE_FROM_NON_FREE_POOL, "DS",
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003406 "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 -06003407 }
3408 if (skipCall)
3409 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003410 VkResult result = dev_data->device_dispatch_table->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003411 if (VK_SUCCESS == result) {
3412 // For each freed descriptor add it back into the pool as available
3413 for (uint32_t i=0; i<count; ++i) {
Chia-I Wue420a332015-10-26 20:04:44 +08003414 SET_NODE* pSet = dev_data->setMap[pDescriptorSets[i]]; // getSetNode() without locking
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003415 LAYOUT_NODE* pLayout = pSet->pLayout;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003416 uint32_t typeIndex = 0, poolSizeCount = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08003417 for (uint32_t j=0; j<pLayout->createInfo.bindingCount; ++j) {
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003418 typeIndex = static_cast<uint32_t>(pLayout->createInfo.pBinding[j].descriptorType);
Chia-I Wu045654f2015-11-06 06:42:02 +08003419 poolSizeCount = pLayout->createInfo.pBinding[j].descriptorCount;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003420 pPoolNode->availableDescriptorTypeCount[typeIndex] += poolSizeCount;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06003421 }
3422 }
3423 }
3424 // TODO : Any other clean-up or book-keeping to do here?
Tony Barbourb857d312015-07-10 10:50:45 -06003425 return result;
3426}
3427
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003428VK_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 -06003429{
Tobin Ehlis68fbd442015-10-27 12:25:35 -06003430 // 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 -06003431 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu483e7702015-10-26 17:20:32 +08003432 if (!dsUpdate(dev_data, device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies)) {
3433 dev_data->device_dispatch_table->UpdateDescriptorSets(device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies);
Jon Ashburne0fa2282015-05-20 09:00:28 -06003434 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003435}
3436
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003437VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo* pCreateInfo, VkCommandBuffer* pCommandBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003438{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06003439 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu1f851912015-10-27 18:04:07 +08003440 VkResult result = dev_data->device_dispatch_table->AllocateCommandBuffers(device, pCreateInfo, pCommandBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003441 if (VK_SUCCESS == result) {
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003442 for (auto i = 0; i < pCreateInfo->bufferCount; i++) {
3443 // Validate command pool
3444 if (dev_data->commandPoolMap.find(pCreateInfo->commandPool) != dev_data->commandPoolMap.end()) {
Mark Lobodzinski13b66742015-11-20 14:33:48 -07003445 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003446 // Add command buffer to its commandPool map
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003447 dev_data->commandPoolMap[pCreateInfo->commandPool].commandBuffers.push_back(pCommandBuffer[i]);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003448 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
3449 // Add command buffer to map
3450 dev_data->commandBufferMap[pCommandBuffer[i]] = pCB;
Mark Lobodzinski13b66742015-11-20 14:33:48 -07003451 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003452 resetCB(dev_data, pCommandBuffer[i]);
3453 pCB->commandBuffer = pCommandBuffer[i];
3454 pCB->createInfo = *pCreateInfo;
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07003455 }
3456 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003457 }
3458 return result;
3459}
3460
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003461VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo* pBeginInfo)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003462{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003463 VkBool32 skipCall = false;
Chia-I Wu1f851912015-10-27 18:04:07 +08003464 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06003465 // Validate command buffer level
Chia-I Wu1f851912015-10-27 18:04:07 +08003466 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06003467 if (pCB) {
Mark Lobodzinskia1420862015-11-19 13:22:11 -07003468 if (pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
Chia-I Wue420a332015-10-26 20:04:44 +08003469 if (pBeginInfo->renderPass || pBeginInfo->framebuffer) {
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06003470 // These should be NULL for a Primary CB
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07003471 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, (uint64_t)commandBuffer, 0, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003472 "vkBeginCommandBuffer(): Primary Command Buffer (%p) may not specify framebuffer or renderpass parameters", (void*)commandBuffer);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06003473 }
3474 } else {
Chia-I Wue420a332015-10-26 20:04:44 +08003475 if (!pBeginInfo->renderPass || !pBeginInfo->framebuffer) {
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06003476 // These should NOT be null for an Secondary CB
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07003477 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, (uint64_t)commandBuffer, 0, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003478 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) must specify framebuffer and renderpass parameters", (void*)commandBuffer);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06003479 }
3480 }
Tobin Ehlis0cea4082015-08-18 07:10:58 -06003481 pCB->beginInfo = *pBeginInfo;
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003482 if (CB_RECORDING == pCB->state) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07003483 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, (uint64_t)commandBuffer, 0, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003484 "vkBeginCommandBuffer(): Cannot call Begin on CB (%#" PRIxLEAST64 ") in the RECORDING state. Must first call vkEndCommandBuffer().", (uint64_t)commandBuffer);
3485 } else if (CB_RECORDED == pCB->state) {
3486 VkCommandPool cmdPool = pCB->createInfo.commandPool;
3487 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07003488 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, (uint64_t)commandBuffer,
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003489 0, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
3490 "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.",
3491 (uint64_t) commandBuffer, (uint64_t) cmdPool);
3492 }
3493 }
Tobin Ehlis0cea4082015-08-18 07:10:58 -06003494 } else {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07003495 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, (uint64_t)commandBuffer, 0, DRAWSTATE_INVALID_COMMAND_BUFFER, "DS",
Chia-I Wu1f851912015-10-27 18:04:07 +08003496 "In vkBeginCommandBuffer() and unable to find CommandBuffer Node for CB %p!", (void*)commandBuffer);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06003497 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003498 if (skipCall) {
3499 return VK_ERROR_VALIDATION_FAILED;
Courtney Goeltzenleuchter3abd86e2015-09-04 15:03:52 -06003500 }
Chia-I Wu1f851912015-10-27 18:04:07 +08003501 VkResult result = dev_data->device_dispatch_table->BeginCommandBuffer(commandBuffer, pBeginInfo);
Mark Lobodzinski2ad35592015-11-12 16:14:04 -07003502 if ((VK_SUCCESS == result) && (pCB != NULL)) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003503 if (CB_RECORDED == pCB->state) {
Chia-I Wu1f851912015-10-27 18:04:07 +08003504 resetCB(dev_data, commandBuffer);
Mark Lobodzinski2ad35592015-11-12 16:14:04 -07003505 }
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003506 pCB->state = CB_RECORDING;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003507 }
3508 return result;
3509}
3510
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003511VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEndCommandBuffer(VkCommandBuffer commandBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003512{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003513 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchtera54b76a2015-09-04 13:39:59 -06003514 VkResult result = VK_SUCCESS;
Chia-I Wu1f851912015-10-27 18:04:07 +08003515 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3516 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlise42007c2015-06-19 13:00:59 -06003517 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003518 if (pCB->state != CB_RECORDING) {
Chia-I Wu1f851912015-10-27 18:04:07 +08003519 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkEndCommandBuffer()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003520 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003521 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003522 if (VK_FALSE == skipCall) {
Chia-I Wu1f851912015-10-27 18:04:07 +08003523 result = dev_data->device_dispatch_table->EndCommandBuffer(commandBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003524 if (VK_SUCCESS == result) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003525 pCB->state = CB_RECORDED;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003526 // Reset CB status flags
3527 pCB->status = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08003528 printCB(dev_data, commandBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003529 }
3530 } else {
3531 result = VK_ERROR_VALIDATION_FAILED;
3532 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003533 return result;
3534}
3535
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003536VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003537{
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003538 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003539 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003540 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
3541 VkCommandPool cmdPool = pCB->createInfo.commandPool;
3542 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07003543 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, (uint64_t) commandBuffer,
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003544 0, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
3545 "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.",
3546 (uint64_t) commandBuffer, (uint64_t) cmdPool);
3547 }
3548 if (skipCall)
3549 return VK_ERROR_VALIDATION_FAILED;
Chia-I Wu1f851912015-10-27 18:04:07 +08003550 VkResult result = dev_data->device_dispatch_table->ResetCommandBuffer(commandBuffer, flags);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003551 if (VK_SUCCESS == result) {
Chia-I Wu1f851912015-10-27 18:04:07 +08003552 resetCB(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003553 }
3554 return result;
3555}
3556
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003557VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003558{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003559 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003560 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3561 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003562 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003563 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003564 skipCall |= addCmd(dev_data, pCB, CMD_BINDPIPELINE);
Tobin Ehlis642d5a52015-06-23 08:46:18 -06003565 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07003566 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, (uint64_t) pipeline,
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06003567 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
3568 "Incorrectly binding compute pipeline (%#" PRIxLEAST64 ") during active RenderPass (%#" PRIxLEAST64 ")",
Chia-I Wue420a332015-10-26 20:04:44 +08003569 (uint64_t) pipeline, (uint64_t) pCB->activeRenderPass);
Tobin Ehlise4076782015-06-24 15:53:07 -06003570 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) && (!pCB->activeRenderPass)) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07003571 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, (uint64_t) pipeline,
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06003572 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS", "Incorrectly binding graphics pipeline "
Chia-I Wue420a332015-10-26 20:04:44 +08003573 " (%#" PRIxLEAST64 ") without an active RenderPass", (uint64_t) pipeline);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003574 } else {
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06003575 PIPELINE_NODE* pPN = getPipeline(dev_data, pipeline);
Tobin Ehlise4076782015-06-24 15:53:07 -06003576 if (pPN) {
3577 pCB->lastBoundPipeline = pipeline;
3578 loader_platform_thread_lock_mutex(&globalLock);
3579 set_cb_pso_status(pCB, pPN);
3580 g_lastBoundPipeline = pPN;
3581 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06003582 skipCall |= validatePipelineState(dev_data, pCB, pipelineBindPoint, pipeline);
Tobin Ehlise4076782015-06-24 15:53:07 -06003583 } else {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07003584 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, (uint64_t) pipeline,
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06003585 0, DRAWSTATE_INVALID_PIPELINE, "DS",
Michael Lentinecbc4a5e2015-11-03 16:19:46 -08003586 "Attempt to bind Pipeline %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<uint64_t>(pipeline));
Tobin Ehlise4076782015-06-24 15:53:07 -06003587 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06003588 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003589 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003590 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindPipeline()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003591 }
3592 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003593 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003594 dev_data->device_dispatch_table->CmdBindPipeline(commandBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003595}
3596
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003597VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetViewport(
Chia-I Wu1f851912015-10-27 18:04:07 +08003598 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06003599 uint32_t viewportCount,
3600 const VkViewport* pViewports)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003601{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003602 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003603 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3604 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlise42007c2015-06-19 13:00:59 -06003605 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003606 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003607 skipCall |= addCmd(dev_data, pCB, CMD_SETVIEWPORTSTATE);
Tobin Ehlise42007c2015-06-19 13:00:59 -06003608 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003609 pCB->status |= CBSTATUS_VIEWPORT_SET;
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06003610 pCB->viewports.resize(viewportCount);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003611 memcpy(pCB->viewports.data(), pViewports, viewportCount * sizeof(VkViewport));
Tobin Ehlise42007c2015-06-19 13:00:59 -06003612 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlise42007c2015-06-19 13:00:59 -06003613 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003614 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdSetViewport()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06003615 }
3616 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003617 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003618 dev_data->device_dispatch_table->CmdSetViewport(commandBuffer, viewportCount, pViewports);
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06003619}
3620
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003621VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetScissor(
Chia-I Wu1f851912015-10-27 18:04:07 +08003622 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06003623 uint32_t scissorCount,
3624 const VkRect2D* pScissors)
3625{
3626 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003627 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3628 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06003629 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003630 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003631 skipCall |= addCmd(dev_data, pCB, CMD_SETSCISSORSTATE);
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06003632 loader_platform_thread_lock_mutex(&globalLock);
3633 pCB->status |= CBSTATUS_SCISSOR_SET;
3634 pCB->scissors.resize(scissorCount);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003635 memcpy(pCB->scissors.data(), pScissors, scissorCount * sizeof(VkRect2D));
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06003636 loader_platform_thread_unlock_mutex(&globalLock);
3637 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003638 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdSetScissor()");
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06003639 }
3640 }
3641 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003642 dev_data->device_dispatch_table->CmdSetScissor(commandBuffer, scissorCount, pScissors);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003643}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003644
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003645VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003646{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003647 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003648 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3649 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003650 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003651 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003652 skipCall |= addCmd(dev_data, pCB, CMD_SETLINEWIDTHSTATE);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003653 /* TODO: Do we still need this lock? */
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003654 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003655 pCB->status |= CBSTATUS_LINE_WIDTH_SET;
3656 pCB->lineWidth = lineWidth;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003657 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003658 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003659 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindDynamicLineWidthState()");
Cody Northropf5bd2252015-08-17 11:10:49 -06003660 }
3661 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003662 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003663 dev_data->device_dispatch_table->CmdSetLineWidth(commandBuffer, lineWidth);
Cody Northropf5bd2252015-08-17 11:10:49 -06003664}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003665
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003666VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBias(
Chia-I Wu1f851912015-10-27 18:04:07 +08003667 VkCommandBuffer commandBuffer,
Chia-I Wufa950c52015-10-26 19:08:09 +08003668 float depthBiasConstantFactor,
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003669 float depthBiasClamp,
Chia-I Wufa950c52015-10-26 19:08:09 +08003670 float depthBiasSlopeFactor)
Cody Northropf5bd2252015-08-17 11:10:49 -06003671{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003672 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003673 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3674 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northropf5bd2252015-08-17 11:10:49 -06003675 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003676 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003677 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBIASSTATE);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003678 pCB->status |= CBSTATUS_DEPTH_BIAS_SET;
Chia-I Wufa950c52015-10-26 19:08:09 +08003679 pCB->depthBiasConstantFactor = depthBiasConstantFactor;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003680 pCB->depthBiasClamp = depthBiasClamp;
Chia-I Wufa950c52015-10-26 19:08:09 +08003681 pCB->depthBiasSlopeFactor = depthBiasSlopeFactor;
Cody Northropf5bd2252015-08-17 11:10:49 -06003682 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003683 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdSetDepthBias()");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003684 }
3685 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003686 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003687 dev_data->device_dispatch_table->CmdSetDepthBias(commandBuffer, depthBiasConstantFactor, depthBiasClamp, depthBiasSlopeFactor);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003688}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003689
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003690VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4])
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003691{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003692 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003693 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3694 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003695 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003696 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003697 skipCall |= addCmd(dev_data, pCB, CMD_SETBLENDSTATE);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003698 pCB->status |= CBSTATUS_BLEND_SET;
Chia-I Wu7e470702015-10-26 17:24:52 +08003699 memcpy(pCB->blendConstants, blendConstants, 4 * sizeof(float));
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003700 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003701 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdSetBlendConstants()");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003702 }
3703 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003704 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003705 dev_data->device_dispatch_table->CmdSetBlendConstants(commandBuffer, blendConstants);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003706}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003707
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003708VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBounds(
Chia-I Wu1f851912015-10-27 18:04:07 +08003709 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003710 float minDepthBounds,
3711 float maxDepthBounds)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003712{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003713 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003714 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3715 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003716 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003717 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003718 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBOUNDSSTATE);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003719 pCB->status |= CBSTATUS_DEPTH_BOUNDS_SET;
3720 pCB->minDepthBounds = minDepthBounds;
3721 pCB->maxDepthBounds = maxDepthBounds;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003722 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003723 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdSetDepthBounds()");
Cody Northrop2605cb02015-08-18 15:21:16 -06003724 }
3725 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003726 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003727 dev_data->device_dispatch_table->CmdSetDepthBounds(commandBuffer, minDepthBounds, maxDepthBounds);
Cody Northrop2605cb02015-08-18 15:21:16 -06003728}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003729
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003730VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilCompareMask(
Chia-I Wu1f851912015-10-27 18:04:07 +08003731 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003732 VkStencilFaceFlags faceMask,
Chia-I Wuc51b1212015-10-27 19:25:11 +08003733 uint32_t compareMask)
Cody Northrop2605cb02015-08-18 15:21:16 -06003734{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003735 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003736 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3737 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northrop2605cb02015-08-18 15:21:16 -06003738 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003739 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003740 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREADMASKSTATE);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003741 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
Chia-I Wuc51b1212015-10-27 19:25:11 +08003742 pCB->front.compareMask = compareMask;
Cody Northrop2605cb02015-08-18 15:21:16 -06003743 }
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003744 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
Chia-I Wuc51b1212015-10-27 19:25:11 +08003745 pCB->back.compareMask = compareMask;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003746 }
3747 /* TODO: Do we need to track front and back separately? */
3748 /* TODO: We aren't capturing the faceMask, do we need to? */
3749 pCB->status |= CBSTATUS_STENCIL_READ_MASK_SET;
Cody Northrop2605cb02015-08-18 15:21:16 -06003750 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003751 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdSetStencilCompareMask()");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003752 }
3753 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003754 if (VK_FALSE == skipCall)
Chia-I Wuc51b1212015-10-27 19:25:11 +08003755 dev_data->device_dispatch_table->CmdSetStencilCompareMask(commandBuffer, faceMask, compareMask);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003756}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003757
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003758VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilWriteMask(
Chia-I Wu1f851912015-10-27 18:04:07 +08003759 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003760 VkStencilFaceFlags faceMask,
Chia-I Wuc51b1212015-10-27 19:25:11 +08003761 uint32_t writeMask)
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003762{
3763 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003764 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3765 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003766 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003767 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003768 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILWRITEMASKSTATE);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003769 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
Chia-I Wuc51b1212015-10-27 19:25:11 +08003770 pCB->front.writeMask = writeMask;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003771 }
3772 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
Chia-I Wuc51b1212015-10-27 19:25:11 +08003773 pCB->back.writeMask = writeMask;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003774 }
3775 pCB->status |= CBSTATUS_STENCIL_WRITE_MASK_SET;
3776 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003777 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdSetStencilWriteMask()");
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003778 }
3779 }
3780 if (VK_FALSE == skipCall)
Chia-I Wuc51b1212015-10-27 19:25:11 +08003781 dev_data->device_dispatch_table->CmdSetStencilWriteMask(commandBuffer, faceMask, writeMask);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003782}
3783
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003784VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilReference(
Chia-I Wu1f851912015-10-27 18:04:07 +08003785 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003786 VkStencilFaceFlags faceMask,
Chia-I Wuc51b1212015-10-27 19:25:11 +08003787 uint32_t reference)
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003788{
3789 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003790 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3791 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003792 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003793 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003794 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREFERENCESTATE);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003795 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
Chia-I Wuc51b1212015-10-27 19:25:11 +08003796 pCB->front.reference = reference;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003797 }
3798 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
Chia-I Wuc51b1212015-10-27 19:25:11 +08003799 pCB->back.reference = reference;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003800 }
3801 pCB->status |= CBSTATUS_STENCIL_REFERENCE_SET;
3802 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003803 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdSetStencilReference()");
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003804 }
3805 }
3806 if (VK_FALSE == skipCall)
Chia-I Wuc51b1212015-10-27 19:25:11 +08003807 dev_data->device_dispatch_table->CmdSetStencilReference(commandBuffer, faceMask, reference);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003808}
3809
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003810VK_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 -06003811{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003812 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003813 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3814 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003815 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003816 if (pCB->state == CB_RECORDING) {
Tobin Ehlise4076782015-06-24 15:53:07 -06003817 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07003818 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Chia-I Wue420a332015-10-26 20:04:44 +08003819 "Incorrectly binding compute DescriptorSets during active RenderPass (%#" PRIxLEAST64 ")", (uint64_t) pCB->activeRenderPass);
Tobin Ehlise4076782015-06-24 15:53:07 -06003820 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) && (!pCB->activeRenderPass)) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07003821 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Tobin Ehlise4076782015-06-24 15:53:07 -06003822 "Incorrectly binding graphics DescriptorSets without an active RenderPass");
Tobin Ehlisd28acef2015-09-09 15:12:35 -06003823 } else {
Tobin Ehlis61ebb312015-11-04 12:28:28 -07003824 // Track total count of dynamic descriptor types to make sure we have an offset for each one
3825 uint32_t totalDynamicDescriptors = 0;
Tobin Ehlis982099b2015-11-05 09:52:49 -07003826 string errorString = "";
Tobin Ehliscb085292015-12-01 09:57:09 -07003827 uint32_t lastSetIndex = firstSet+setCount-1;
Tobin Ehlis982099b2015-11-05 09:52:49 -07003828 if (lastSetIndex >= pCB->boundDescriptorSets.size())
3829 pCB->boundDescriptorSets.resize(lastSetIndex+1);
3830 VkDescriptorSet oldFinalBoundSet = pCB->boundDescriptorSets[lastSetIndex];
Tobin Ehlise42007c2015-06-19 13:00:59 -06003831 for (uint32_t i=0; i<setCount; i++) {
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06003832 SET_NODE* pSet = getSetNode(dev_data, pDescriptorSets[i]);
Tobin Ehlis55c1c602015-06-24 17:27:33 -06003833 if (pSet) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06003834 loader_platform_thread_lock_mutex(&globalLock);
3835 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06003836 pCB->lastBoundPipelineLayout = layout;
Tobin Ehlis982099b2015-11-05 09:52:49 -07003837 pCB->boundDescriptorSets[i+firstSet] = pDescriptorSets[i];
Tobin Ehlise42007c2015-06-19 13:00:59 -06003838 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07003839 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, (uint64_t) pDescriptorSets[i], 0, DRAWSTATE_NONE, "DS",
Chia-I Wue420a332015-10-26 20:04:44 +08003840 "DS %#" PRIxLEAST64 " bound on pipeline %s", (uint64_t) pDescriptorSets[i], string_VkPipelineBindPoint(pipelineBindPoint));
Tobin Ehlis61ebb312015-11-04 12:28:28 -07003841 if (!pSet->pUpdateStructs) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07003842 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_WARN_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, (uint64_t) pDescriptorSets[i], 0, DRAWSTATE_DESCRIPTOR_SET_NOT_UPDATED, "DS",
Chia-I Wue420a332015-10-26 20:04:44 +08003843 "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 -07003844 }
Tobin Ehlis982099b2015-11-05 09:52:49 -07003845 // Verify that set being bound is compatible with overlapping setLayout of pipelineLayout
3846 if (!verify_set_layout_compatibility(dev_data, pSet, layout, i+firstSet, errorString)) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07003847 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, (uint64_t) pDescriptorSets[i], 0, DRAWSTATE_PIPELINE_LAYOUTS_INCOMPATIBLE, "DS",
Tobin Ehlis982099b2015-11-05 09:52:49 -07003848 "descriptorSet #%u being bound is not compatible with overlapping layout in pipelineLayout due to: %s", i, errorString.c_str());
3849 }
Tobin Ehlis61ebb312015-11-04 12:28:28 -07003850 totalDynamicDescriptors += pSet->pLayout->dynamicDescriptorCount;
Tobin Ehlise42007c2015-06-19 13:00:59 -06003851 } else {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07003852 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, (uint64_t) pDescriptorSets[i], 0, DRAWSTATE_INVALID_SET, "DS",
Chia-I Wue420a332015-10-26 20:04:44 +08003853 "Attempt to bind DS %#" PRIxLEAST64 " that doesn't exist!", (uint64_t) pDescriptorSets[i]);
Tobin Ehlise42007c2015-06-19 13:00:59 -06003854 }
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06003855 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003856 skipCall |= addCmd(dev_data, pCB, CMD_BINDDESCRIPTORSETS);
Tobin Ehlis982099b2015-11-05 09:52:49 -07003857 // For any previously bound sets, need to set them to "invalid" if they were disturbed by this update
3858 if (firstSet > 0) { // Check set #s below the first bound set
3859 for (uint32_t i=0; i<firstSet; ++i) {
Tobin Ehliscb085292015-12-01 09:57:09 -07003860 if (pCB->boundDescriptorSets[i] && !verify_set_layout_compatibility(dev_data, dev_data->setMap[pCB->boundDescriptorSets[i]], layout, i, errorString)) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07003861 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, (uint64_t) pCB->boundDescriptorSets[i], 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis982099b2015-11-05 09:52:49 -07003862 "DescriptorSetDS %#" PRIxLEAST64 " previously bound as set #%u was disturbed by newly bound pipelineLayout (%#" PRIxLEAST64 ")", (uint64_t) pCB->boundDescriptorSets[i], i, (uint64_t) layout);
3863 pCB->boundDescriptorSets[i] = VK_NULL_HANDLE;
3864 }
3865 }
3866 }
3867 // Check if newly last bound set invalidates any remaining bound sets
3868 if ((pCB->boundDescriptorSets.size()-1) > (lastSetIndex)) {
Tobin Ehliscb085292015-12-01 09:57:09 -07003869 if (oldFinalBoundSet && !verify_set_layout_compatibility(dev_data, dev_data->setMap[oldFinalBoundSet], layout, lastSetIndex, errorString)) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07003870 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, (uint64_t) oldFinalBoundSet, 0, DRAWSTATE_NONE, "DS",
Tobin Ehliscb085292015-12-01 09:57:09 -07003871 "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 -07003872 pCB->boundDescriptorSets.resize(lastSetIndex+1);
3873 }
3874 }
Tobin Ehlis61ebb312015-11-04 12:28:28 -07003875 // dynamicOffsetCount must equal the total number of dynamic descriptors in the sets being bound
3876 if (totalDynamicDescriptors != dynamicOffsetCount) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07003877 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, (uint64_t) commandBuffer, 0, DRAWSTATE_INVALID_DYNAMIC_OFFSET_COUNT, "DS",
Tobin Ehlis61ebb312015-11-04 12:28:28 -07003878 "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);
3879 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003880 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06003881 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003882 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindDescriptorSets()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003883 }
3884 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003885 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003886 dev_data->device_dispatch_table->CmdBindDescriptorSets(commandBuffer, pipelineBindPoint, layout, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003887}
3888
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003889VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003890{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003891 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003892 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3893 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003894 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003895 if (pCB->state == CB_RECORDING) {
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003896 VkDeviceSize offset_align = 0;
3897 switch (indexType) {
3898 case VK_INDEX_TYPE_UINT16:
3899 offset_align = 2;
3900 break;
3901 case VK_INDEX_TYPE_UINT32:
3902 offset_align = 4;
3903 break;
3904 default:
3905 // ParamChecker should catch bad enum, we'll also throw alignment error below if offset_align stays 0
3906 break;
3907 }
3908 if (!offset_align || (offset % offset_align)) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07003909 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_VTX_INDEX_ALIGNMENT_ERROR, "DS",
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003910 "vkCmdBindIndexBuffer() offset (%#" PRIxLEAST64 ") does not fall on alignment (%s) boundary.", offset, string_VkIndexType(indexType));
Tobin Ehlise4076782015-06-24 15:53:07 -06003911 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003912 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003913 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06003914 }
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003915 pCB->status |= CBSTATUS_INDEX_BUFFER_BOUND;
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003916 skipCall |= addCmd(dev_data, pCB, CMD_BINDINDEXBUFFER);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003917 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003918 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003919 dev_data->device_dispatch_table->CmdBindIndexBuffer(commandBuffer, buffer, offset, indexType);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003920}
3921
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003922VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindVertexBuffers(
Chia-I Wu1f851912015-10-27 18:04:07 +08003923 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003924 uint32_t startBinding,
3925 uint32_t bindingCount,
3926 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06003927 const VkDeviceSize* pOffsets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003928{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003929 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003930 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3931 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003932 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003933 if (pCB->state == CB_RECORDING) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06003934 /* TODO: Need to track all the vertex buffers, not just last one */
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06003935 pCB->lastVtxBinding = startBinding + bindingCount -1;
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003936 addCmd(dev_data, pCB, CMD_BINDVERTEXBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003937 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003938 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindVertexBuffer()");
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06003939 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003940 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003941 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003942 dev_data->device_dispatch_table->CmdBindVertexBuffers(commandBuffer, startBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003943}
3944
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003945VK_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 -06003946{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003947 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08003948 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3949 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003950 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003951 if (pCB->state == CB_RECORDING) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06003952 pCB->drawCount[DRAW]++;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06003953 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
Chia-I Wu1f851912015-10-27 18:04:07 +08003954 // TODO : Need to pass commandBuffer as srcObj here
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07003955 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NONE, "DS",
Michael Lentinecbc4a5e2015-11-03 16:19:46 -08003956 "vkCmdDraw() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW]++);
Chia-I Wu1f851912015-10-27 18:04:07 +08003957 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003958 if (VK_FALSE == skipCall) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003959 skipCall |= addCmd(dev_data, pCB, CMD_DRAW);
Tobin Ehlise42007c2015-06-19 13:00:59 -06003960 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003961 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003962 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdDraw()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06003963 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003964 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDraw");
Jon Ashburne0fa2282015-05-20 09:00:28 -06003965 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003966 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003967 dev_data->device_dispatch_table->CmdDraw(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003968}
3969
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003970VK_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 -06003971{
Chia-I Wu1f851912015-10-27 18:04:07 +08003972 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3973 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003974 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003975 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07003976 if (pCB->state == CB_RECORDING) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06003977 pCB->drawCount[DRAW_INDEXED]++;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06003978 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
Chia-I Wu1f851912015-10-27 18:04:07 +08003979 // TODO : Need to pass commandBuffer as srcObj here
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07003980 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NONE, "DS",
Michael Lentinecbc4a5e2015-11-03 16:19:46 -08003981 "vkCmdDrawIndexed() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED]++);
Chia-I Wu1f851912015-10-27 18:04:07 +08003982 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003983 if (VK_FALSE == skipCall) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003984 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXED);
Tobin Ehlise42007c2015-06-19 13:00:59 -06003985 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003986 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08003987 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdDrawIndexed()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06003988 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06003989 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexed");
Jon Ashburne0fa2282015-05-20 09:00:28 -06003990 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003991 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08003992 dev_data->device_dispatch_table->CmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003993}
3994
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08003995VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003996{
Chia-I Wu1f851912015-10-27 18:04:07 +08003997 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3998 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003999 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004000 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004001 if (pCB->state == CB_RECORDING) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06004002 pCB->drawCount[DRAW_INDIRECT]++;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06004003 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
Chia-I Wu1f851912015-10-27 18:04:07 +08004004 // TODO : Need to pass commandBuffer as srcObj here
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07004005 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NONE, "DS",
Michael Lentinecbc4a5e2015-11-03 16:19:46 -08004006 "vkCmdDrawIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
Chia-I Wu1f851912015-10-27 18:04:07 +08004007 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004008 if (VK_FALSE == skipCall) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004009 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDIRECT);
Tobin Ehlise42007c2015-06-19 13:00:59 -06004010 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004011 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004012 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdDrawIndirect()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004013 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004014 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndirect");
Jon Ashburne0fa2282015-05-20 09:00:28 -06004015 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004016 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004017 dev_data->device_dispatch_table->CmdDrawIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004018}
4019
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004020VK_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 -06004021{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004022 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004023 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4024 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004025 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004026 if (pCB->state == CB_RECORDING) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06004027 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06004028 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
Chia-I Wu1f851912015-10-27 18:04:07 +08004029 // TODO : Need to pass commandBuffer as srcObj here
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07004030 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NONE, "DS",
Michael Lentinecbc4a5e2015-11-03 16:19:46 -08004031 "vkCmdDrawIndexedIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
Chia-I Wu1f851912015-10-27 18:04:07 +08004032 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004033 if (VK_FALSE == skipCall) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004034 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXEDINDIRECT);
Tobin Ehlise42007c2015-06-19 13:00:59 -06004035 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004036 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004037 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdDrawIndexedIndirect()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004038 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004039 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexedIndirect");
Jon Ashburne0fa2282015-05-20 09:00:28 -06004040 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004041 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004042 dev_data->device_dispatch_table->CmdDrawIndexedIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004043}
4044
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004045VK_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 -06004046{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004047 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004048 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4049 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004050 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004051 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004052 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCH);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004053 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004054 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdDispatch()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004055 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004056 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatch");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004057 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004058 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004059 dev_data->device_dispatch_table->CmdDispatch(commandBuffer, x, y, z);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004060}
4061
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004062VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004063{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004064 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004065 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4066 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004067 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004068 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004069 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCHINDIRECT);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004070 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004071 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdDispatchIndirect()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004072 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004073 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatchIndirect");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004074 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004075 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004076 dev_data->device_dispatch_table->CmdDispatchIndirect(commandBuffer, buffer, offset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004077}
4078
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004079VK_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 -06004080{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004081 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004082 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4083 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004084 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004085 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004086 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004087 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004088 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdCopyBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004089 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004090 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBuffer");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004091 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004092 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004093 dev_data->device_dispatch_table->CmdCopyBuffer(commandBuffer, srcBuffer, dstBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004094}
4095
Michael Lentine27b0f902015-10-12 11:30:14 -05004096bool VerifySourceImageLayout(VkCommandBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout) {
4097 bool skip_call = false;
Mark Lobodzinski78940a42015-11-30 16:48:53 -07004098
4099#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4100 // TODO: Fix -- initialLayout may have been set in a previous command buffer
4101 return skip_call;
4102#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4103
Michael Lentine27b0f902015-10-12 11:30:14 -05004104 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4105 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4106 auto src_image_element = pCB->imageLayoutMap.find(srcImage);
4107 if (src_image_element == pCB->imageLayoutMap.end()) {
4108 pCB->imageLayoutMap[srcImage].initialLayout = srcImageLayout;
4109 pCB->imageLayoutMap[srcImage].layout = srcImageLayout;
4110 return false;
4111 }
4112 if (src_image_element->second.layout != srcImageLayout) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07004113 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentine27b0f902015-10-12 11:30:14 -05004114 "Cannot copy from an image whose source layout is %d and doesn't match the current layout %d.", srcImageLayout, src_image_element->second.layout);
4115 }
4116 if (srcImageLayout != VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL) {
4117 if (srcImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07004118 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_WARN_BIT, (VkDbgObjectType)0, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentine472af7d2015-10-16 18:08:09 -05004119 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Michael Lentine27b0f902015-10-12 11:30:14 -05004120 } else {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07004121 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentine472af7d2015-10-16 18:08:09 -05004122 "Layout for input image is %d but can only be TRANSFER_SRC_OPTIMAL or GENERAL.", srcImageLayout);
Michael Lentine27b0f902015-10-12 11:30:14 -05004123 }
4124 }
4125 return skip_call;
4126}
4127
4128bool VerifyDestImageLayout(VkCommandBuffer cmdBuffer, VkImage destImage, VkImageLayout destImageLayout) {
4129 bool skip_call = false;
Mark Lobodzinski78940a42015-11-30 16:48:53 -07004130
4131#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4132 // TODO: Fix -- initialLayout may have been set in a previous command buffer
4133 return skip_call;
4134#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4135
Michael Lentine27b0f902015-10-12 11:30:14 -05004136 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4137 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4138 auto dest_image_element = pCB->imageLayoutMap.find(destImage);
4139 if (dest_image_element == pCB->imageLayoutMap.end()) {
4140 pCB->imageLayoutMap[destImage].initialLayout = destImageLayout;
4141 pCB->imageLayoutMap[destImage].layout = destImageLayout;
4142 return false;
4143 }
4144 if (dest_image_element->second.layout != destImageLayout) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07004145 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentine27b0f902015-10-12 11:30:14 -05004146 "Cannot copy from an image whose dest layout is %d and doesn't match the current layout %d.", destImageLayout, dest_image_element->second.layout);
4147 }
4148 if (destImageLayout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) {
4149 if (destImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07004150 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_WARN_BIT, (VkDbgObjectType)0, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentine27b0f902015-10-12 11:30:14 -05004151 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
4152 } else {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07004153 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentine27b0f902015-10-12 11:30:14 -05004154 "Layout for output image is %d but can only be TRANSFER_DST_OPTIMAL or GENERAL.", destImageLayout);
4155 }
4156 }
4157 return skip_call;
4158}
4159
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004160VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004161 VkImage srcImage,
4162 VkImageLayout srcImageLayout,
Chia-I Wu1f851912015-10-27 18:04:07 +08004163 VkImage dstImage,
4164 VkImageLayout dstImageLayout,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004165 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004166{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004167 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004168 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4169 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004170 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004171 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004172 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGE);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004173 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004174 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdCopyImage()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004175 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004176 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImage");
Michael Lentine27b0f902015-10-12 11:30:14 -05004177 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
4178 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004179 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004180 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004181 dev_data->device_dispatch_table->CmdCopyImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004182}
4183
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004184VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBlitImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004185 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu1f851912015-10-27 18:04:07 +08004186 VkImage dstImage, VkImageLayout dstImageLayout,
Mark Lobodzinski20f68592015-05-22 14:43:25 -05004187 uint32_t regionCount, const VkImageBlit* pRegions,
Chia-I Wu3603b082015-10-26 16:49:32 +08004188 VkFilter filter)
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06004189{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004190 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004191 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4192 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06004193 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004194 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004195 skipCall |= addCmd(dev_data, pCB, CMD_BLITIMAGE);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004196 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004197 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBlitImage()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004198 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004199 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBlitImage");
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06004200 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004201 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004202 dev_data->device_dispatch_table->CmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06004203}
4204
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004205VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004206 VkBuffer srcBuffer,
Chia-I Wu1f851912015-10-27 18:04:07 +08004207 VkImage dstImage, VkImageLayout dstImageLayout,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004208 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004209{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004210 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004211 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4212 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004213 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004214 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004215 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFERTOIMAGE);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004216 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004217 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdCopyBufferToImage()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004218 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004219 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBufferToImage");
Michael Lentine27b0f902015-10-12 11:30:14 -05004220 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004221 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004222 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004223 dev_data->device_dispatch_table->CmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004224}
4225
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004226VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004227 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu1f851912015-10-27 18:04:07 +08004228 VkBuffer dstBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004229 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004230{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004231 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004232 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4233 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004234 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004235 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004236 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGETOBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004237 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004238 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdCopyImageToBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004239 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004240 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImageToBuffer");
Michael Lentine27b0f902015-10-12 11:30:14 -05004241 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004242 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004243 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004244 dev_data->device_dispatch_table->CmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004245}
4246
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004247VK_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 -06004248{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004249 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004250 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4251 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004252 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004253 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004254 skipCall |= addCmd(dev_data, pCB, CMD_UPDATEBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004255 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004256 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdUpdateBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004257 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004258 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyUpdateBuffer");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004259 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004260 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004261 dev_data->device_dispatch_table->CmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004262}
4263
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004264VK_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 -06004265{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004266 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004267 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4268 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004269 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004270 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004271 skipCall |= addCmd(dev_data, pCB, CMD_FILLBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004272 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004273 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdFillBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004274 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004275 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyFillBuffer");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004276 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004277 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004278 dev_data->device_dispatch_table->CmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004279}
4280
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004281VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearAttachments(
Chia-I Wu1f851912015-10-27 18:04:07 +08004282 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004283 uint32_t attachmentCount,
4284 const VkClearAttachment* pAttachments,
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004285 uint32_t rectCount,
Courtney Goeltzenleuchtera12e2912015-10-15 18:22:08 -06004286 const VkClearRect* pRects)
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004287{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004288 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004289 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4290 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004291 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004292 if (pCB->state == CB_RECORDING) {
Mark Lobodzinski92c712c2015-12-08 13:47:14 -07004293 // Warn if this is issued prior to Draw Cmd and clearing the entire attachment
4294 if (!hasDrawCmd(pCB) &&
4295 (pCB->activeRenderPassBeginInfo.renderArea.extent.width == pRects[0].rect.extent.width) &&
4296 (pCB->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) {
Chia-I Wu1f851912015-10-27 18:04:07 +08004297 // TODO : commandBuffer should be srcObj
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07004298 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_WARN_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_CLEAR_CMD_BEFORE_DRAW, "DS",
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004299 "vkCmdClearAttachments() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
Chia-I Wu1f851912015-10-27 18:04:07 +08004300 " 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 -06004301 }
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004302 skipCall |= addCmd(dev_data, pCB, CMD_CLEARATTACHMENTS);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004303 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004304 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdClearAttachments()");
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004305 }
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004306 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdClearAttachments");
4307 }
4308
4309 // Validate that attachment is in reference list of active subpass
4310 if (pCB->activeRenderPass) {
Tobin Ehlisad61de42015-12-02 13:53:34 -07004311 const VkRenderPassCreateInfo *pRPCI = dev_data->renderPassMap[pCB->activeRenderPass]->pCreateInfo;
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004312 const VkSubpassDescription *pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
4313
4314 for (uint32_t attachment_idx = 0; attachment_idx < attachmentCount; attachment_idx++) {
4315 const VkClearAttachment *attachment = &pAttachments[attachment_idx];
4316 if (attachment->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) {
4317 VkBool32 found = VK_FALSE;
Chia-I Wu763a7492015-10-26 20:48:51 +08004318 for (uint32_t i = 0; i < pSD->colorAttachmentCount; i++) {
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004319 if (attachment->colorAttachment == pSD->pColorAttachments[i].attachment) {
4320 found = VK_TRUE;
4321 break;
4322 }
4323 }
4324 if (VK_FALSE == found) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07004325 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER,
Chia-I Wu1f851912015-10-27 18:04:07 +08004326 (uint64_t)commandBuffer, 0, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004327 "vkCmdClearAttachments() attachment index %d not found in attachment reference array of active subpass %d",
4328 attachment->colorAttachment, pCB->activeSubpass);
4329 }
4330 } else if (attachment->aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) {
Mark Lobodzinski1523e3a2015-11-17 15:11:24 -07004331 if (!pSD->pDepthStencilAttachment || // Says no DS will be used in active subpass
Mark Lobodzinskiea1fff22015-11-18 08:58:31 -07004332 (pSD->pDepthStencilAttachment->attachment == VK_ATTACHMENT_UNUSED)) { // Says no DS will be used in active subpass
Mark Lobodzinski1523e3a2015-11-17 15:11:24 -07004333
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07004334 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER,
Mark Lobodzinski1523e3a2015-11-17 15:11:24 -07004335 (uint64_t)commandBuffer, 0, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
4336 "vkCmdClearAttachments() attachment index %d does not match depthStencilAttachment.attachment (%d) found in active subpass %d",
4337 attachment->colorAttachment,
4338 (pSD->pDepthStencilAttachment) ? pSD->pDepthStencilAttachment->attachment : VK_ATTACHMENT_UNUSED,
4339 pCB->activeSubpass);
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004340 }
4341 }
4342 }
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004343 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004344 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004345 dev_data->device_dispatch_table->CmdClearAttachments(commandBuffer, attachmentCount, pAttachments, rectCount, pRects);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004346}
4347
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004348VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearColorImage(
Chia-I Wu1f851912015-10-27 18:04:07 +08004349 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06004350 VkImage image, VkImageLayout imageLayout,
Chris Forbese3105972015-06-24 14:34:53 +12004351 const VkClearColorValue *pColor,
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06004352 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004353{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004354 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004355 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4356 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004357 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004358 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004359 skipCall |= addCmd(dev_data, pCB, CMD_CLEARCOLORIMAGE);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004360 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004361 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdClearColorImage()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004362 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004363 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearColorImage");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004364 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004365 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004366 dev_data->device_dispatch_table->CmdClearColorImage(commandBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004367}
4368
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004369VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearDepthStencilImage(
Chia-I Wu1f851912015-10-27 18:04:07 +08004370 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter315ad992015-09-15 18:03:22 -06004371 VkImage image, VkImageLayout imageLayout,
4372 const VkClearDepthStencilValue *pDepthStencil,
4373 uint32_t rangeCount,
4374 const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004375{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004376 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004377 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4378 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004379 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004380 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004381 skipCall |= addCmd(dev_data, pCB, CMD_CLEARDEPTHSTENCILIMAGE);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004382 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004383 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdClearDepthStencilImage()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004384 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004385 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearDepthStencilImage");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004386 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004387 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004388 dev_data->device_dispatch_table->CmdClearDepthStencilImage(commandBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004389}
4390
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004391VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResolveImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004392 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu1f851912015-10-27 18:04:07 +08004393 VkImage dstImage, VkImageLayout dstImageLayout,
Tony Barbour11f74372015-04-13 15:02:52 -06004394 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004395{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004396 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004397 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4398 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004399 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004400 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004401 skipCall |= addCmd(dev_data, pCB, CMD_RESOLVEIMAGE);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004402 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004403 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdResolveImage()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004404 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004405 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResolveImage");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004406 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004407 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004408 dev_data->device_dispatch_table->CmdResolveImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004409}
4410
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004411VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004412{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004413 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004414 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4415 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004416 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004417 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004418 skipCall |= addCmd(dev_data, pCB, CMD_SETEVENT);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004419 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004420 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdSetEvent()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004421 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004422 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdSetEvent");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004423 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004424 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004425 dev_data->device_dispatch_table->CmdSetEvent(commandBuffer, event, stageMask);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004426}
4427
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004428VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004429{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004430 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004431 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4432 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004433 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004434 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004435 skipCall |= addCmd(dev_data, pCB, CMD_RESETEVENT);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004436 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004437 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdResetEvent()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004438 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004439 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResetEvent");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004440 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004441 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004442 dev_data->device_dispatch_table->CmdResetEvent(commandBuffer, event, stageMask);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004443}
4444
Michael Lentine27b0f902015-10-12 11:30:14 -05004445bool TransitionImageLayouts(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const void* const* ppMemBarriers) {
4446 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4447 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4448 bool skip = false;
Mark Lobodzinski78940a42015-11-30 16:48:53 -07004449
4450#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4451 // TODO: Fix -- pay attention to image subresource ranges -- not all subresources transition at the same time
4452 return skip;
4453#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4454
Michael Lentine27b0f902015-10-12 11:30:14 -05004455 for (uint32_t i = 0; i < memBarrierCount; ++i) {
4456 auto mem_barrier = reinterpret_cast<const VkMemoryBarrier*>(ppMemBarriers[i]);
4457 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
4458 auto image_mem_barrier = reinterpret_cast<const VkImageMemoryBarrier*>(mem_barrier);
4459 auto image_data = pCB->imageLayoutMap.find(image_mem_barrier->image);
4460 if (image_data == pCB->imageLayoutMap.end()) {
4461 pCB->imageLayoutMap[image_mem_barrier->image].initialLayout = image_mem_barrier->oldLayout;
4462 pCB->imageLayoutMap[image_mem_barrier->image].layout = image_mem_barrier->newLayout;
4463 } else {
4464 if (image_data->second.layout != image_mem_barrier->oldLayout) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07004465 skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentine8469dd62015-11-20 09:48:52 -08004466 "You cannot transition the layout from %s when current layout is %s.",
4467 string_VkImageLayout(image_mem_barrier->oldLayout), string_VkImageLayout(image_data->second.layout));
Michael Lentine27b0f902015-10-12 11:30:14 -05004468 }
4469 image_data->second.layout = image_mem_barrier->newLayout;
4470 }
4471 }
4472 }
4473 return skip;
4474}
4475
Michael Lentine8469dd62015-11-20 09:48:52 -08004476// AccessFlags MUST have 'required_bit' set, and may have one or more of 'optional_bits' set.
4477// If required_bit is zero, accessMask must have at least one of 'optional_bits' set
4478bool ValidateMaskBits(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout, VkAccessFlags required_bit, VkAccessFlags optional_bits) {
Michael Lentine472af7d2015-10-16 18:08:09 -05004479 bool skip_call = false;
Michael Lentine8469dd62015-11-20 09:48:52 -08004480 if ((accessMask & required_bit) || (!required_bit && (accessMask & optional_bits))) {
4481 if (accessMask & !(required_bit | optional_bits)) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07004482 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT, (VkDbgObjectType)0, 0, 0, DRAWSTATE_INVALID_BARRIER, "DS",
Michael Lentine8469dd62015-11-20 09:48:52 -08004483 "Additional bits in accessMask %d are specified when layout is %s.", accessMask, string_VkImageLayout(layout));
Michael Lentine472af7d2015-10-16 18:08:09 -05004484 }
4485 } else {
Michael Lentine8469dd62015-11-20 09:48:52 -08004486 if (!required_bit) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07004487 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT, (VkDbgObjectType)0, 0, 0, DRAWSTATE_INVALID_BARRIER, "DS",
Michael Lentine8469dd62015-11-20 09:48:52 -08004488 "AccessMask %d must contain at least one of access bits %d when layout is %s.",
4489 accessMask, optional_bits, string_VkImageLayout(layout));
4490 } else {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07004491 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT, (VkDbgObjectType)0, 0, 0, DRAWSTATE_INVALID_BARRIER, "DS",
Michael Lentine8469dd62015-11-20 09:48:52 -08004492 "AccessMask %d must have required access bit %d and may have optional bits %d when layout is %s.",
4493 accessMask, required_bit, optional_bits,string_VkImageLayout(layout));
4494 }
Michael Lentine472af7d2015-10-16 18:08:09 -05004495 }
4496 return skip_call;
4497}
4498
Michael Lentine8469dd62015-11-20 09:48:52 -08004499bool ValidateMaskBitsFromLayouts(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout) {
Michael Lentine472af7d2015-10-16 18:08:09 -05004500 bool skip_call = false;
Michael Lentine8469dd62015-11-20 09:48:52 -08004501 switch (layout) {
4502 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: {
4503 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_COLOR_ATTACHMENT_READ_BIT);
4504 break;
Michael Lentine472af7d2015-10-16 18:08:09 -05004505 }
Michael Lentine8469dd62015-11-20 09:48:52 -08004506 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: {
4507 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT);
4508 break;
Michael Lentine472af7d2015-10-16 18:08:09 -05004509 }
Michael Lentine8469dd62015-11-20 09:48:52 -08004510 case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: {
4511 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_WRITE_BIT, 0);
4512 break;
4513 }
4514 case VK_IMAGE_LAYOUT_PREINITIALIZED: {
4515 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_HOST_WRITE_BIT, 0);
4516 break;
4517 }
4518 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: {
4519 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, 0, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT);
4520 break;
4521 }
4522 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: {
4523 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, 0, VK_ACCESS_INPUT_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT);
4524 break;
4525 }
4526 case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: {
4527 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_READ_BIT, 0);
4528 break;
4529 }
4530 case VK_IMAGE_LAYOUT_UNDEFINED: {
4531 if (accessMask != 0) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07004532 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT, (VkDbgObjectType)0, 0, 0, DRAWSTATE_INVALID_BARRIER, "DS",
Michael Lentine8469dd62015-11-20 09:48:52 -08004533 "Additional bits in accessMask %d are specified when layout is %s.", accessMask, string_VkImageLayout(layout));
4534 }
4535 break;
4536 }
4537 case VK_IMAGE_LAYOUT_GENERAL:
4538 default: {
4539 break;
4540 }
Michael Lentine472af7d2015-10-16 18:08:09 -05004541 }
4542 return skip_call;
4543}
4544
Michael Lentine07ff1a12015-10-15 17:07:00 -05004545bool ValidateBarriers(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const void* const* ppMemBarriers) {
4546 bool skip_call = false;
4547 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4548 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4549 if (pCB->activeRenderPass && memBarrierCount) {
4550 for (uint32_t i = 0; i < memBarrierCount; ++i) {
4551 auto mem_barrier = reinterpret_cast<const VkMemoryBarrier*>(ppMemBarriers[i]);
4552 if (mem_barrier && mem_barrier->sType != VK_STRUCTURE_TYPE_MEMORY_BARRIER) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07004553 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, DRAWSTATE_INVALID_BARRIER, "DS",
Michael Lentine07ff1a12015-10-15 17:07:00 -05004554 "Image or Buffers Barriers cannot be used during a render pass.");
4555 }
4556 }
4557 if (!dev_data->renderPassMap[pCB->activeRenderPass]->hasSelfDependency[pCB->activeSubpass]) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07004558 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, DRAWSTATE_INVALID_BARRIER, "DS",
Michael Lentine07ff1a12015-10-15 17:07:00 -05004559 "Barriers cannot be set during subpass %d with no self dependency specified.", pCB->activeSubpass);
4560 }
4561 }
Mark Lobodzinskib684b512015-11-20 09:27:27 -07004562
Michael Lentine472af7d2015-10-16 18:08:09 -05004563 for (uint32_t i = 0; i < memBarrierCount; ++i) {
4564 auto mem_barrier = reinterpret_cast<const VkMemoryBarrier*>(ppMemBarriers[i]);
4565 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
4566 auto image_mem_barrier = reinterpret_cast<const VkImageMemoryBarrier*>(mem_barrier);
Michael Lentine8469dd62015-11-20 09:48:52 -08004567 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, image_mem_barrier->srcAccessMask, image_mem_barrier->oldLayout);
4568 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, image_mem_barrier->dstAccessMask, image_mem_barrier->newLayout);
Michael Lentine472af7d2015-10-16 18:08:09 -05004569 }
4570 }
Mark Lobodzinskib95fc092015-12-03 15:42:32 -07004571
Michael Lentine07ff1a12015-10-15 17:07:00 -05004572 return skip_call;
4573}
4574
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004575VK_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 -06004576{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004577 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004578 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4579 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004580 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004581 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004582 skipCall |= addCmd(dev_data, pCB, CMD_WAITEVENTS);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004583 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004584 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdWaitEvents()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004585 }
Michael Lentine27b0f902015-10-12 11:30:14 -05004586 skipCall |= TransitionImageLayouts(commandBuffer, memoryBarrierCount, ppMemoryBarriers);
Michael Lentine07ff1a12015-10-15 17:07:00 -05004587 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, ppMemoryBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004588 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004589 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004590 dev_data->device_dispatch_table->CmdWaitEvents(commandBuffer, eventCount, pEvents, sourceStageMask, dstStageMask, memoryBarrierCount, ppMemoryBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004591}
4592
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004593VK_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 -06004594{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004595 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004596 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4597 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004598 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004599 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004600 skipCall |= addCmd(dev_data, pCB, CMD_PIPELINEBARRIER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004601 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004602 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdPipelineBarrier()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004603 }
Michael Lentine27b0f902015-10-12 11:30:14 -05004604 skipCall |= TransitionImageLayouts(commandBuffer, memoryBarrierCount, ppMemoryBarriers);
Michael Lentine07ff1a12015-10-15 17:07:00 -05004605 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, ppMemoryBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004606 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004607 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004608 dev_data->device_dispatch_table->CmdPipelineBarrier(commandBuffer, srcStageMask, dstStageMask, dependencyFlags, memoryBarrierCount, ppMemoryBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004609}
4610
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004611VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004612{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004613 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004614 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4615 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004616 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004617 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004618 skipCall |= addCmd(dev_data, pCB, CMD_BEGINQUERY);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004619 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004620 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBeginQuery()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004621 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004622 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004623 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004624 dev_data->device_dispatch_table->CmdBeginQuery(commandBuffer, queryPool, slot, flags);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004625}
4626
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004627VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004628{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004629 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004630 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4631 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004632 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004633 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004634 skipCall |= addCmd(dev_data, pCB, CMD_ENDQUERY);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004635 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004636 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdEndQuery()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004637 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004638 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004639 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004640 dev_data->device_dispatch_table->CmdEndQuery(commandBuffer, queryPool, slot);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004641}
4642
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004643VK_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 -06004644{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004645 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004646 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4647 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004648 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004649 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004650 skipCall |= addCmd(dev_data, pCB, CMD_RESETQUERYPOOL);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004651 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004652 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdResetQueryPool()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004653 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004654 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdQueryPool");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004655 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004656 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004657 dev_data->device_dispatch_table->CmdResetQueryPool(commandBuffer, queryPool, startQuery, queryCount);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004658}
4659
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004660VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t startQuery,
Chia-I Wu1f851912015-10-27 18:04:07 +08004661 uint32_t queryCount, VkBuffer dstBuffer, VkDeviceSize dstOffset,
Chia-I Wu1f6942d2015-10-26 18:36:20 +08004662 VkDeviceSize stride, VkQueryResultFlags flags)
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06004663{
4664 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004665 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4666 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06004667 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004668 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004669 skipCall |= addCmd(dev_data, pCB, CMD_COPYQUERYPOOLRESULTS);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06004670 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004671 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdCopyQueryPoolResults()");
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06004672 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004673 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyQueryPoolResults");
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06004674 }
4675 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004676 dev_data->device_dispatch_table->CmdCopyQueryPoolResults(commandBuffer, queryPool,
4677 startQuery, queryCount, dstBuffer, dstOffset, stride, flags);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06004678}
4679
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004680VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004681{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004682 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08004683 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4684 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004685 if (pCB) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07004686 if (pCB->state == CB_RECORDING) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004687 skipCall |= addCmd(dev_data, pCB, CMD_WRITETIMESTAMP);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06004688 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +08004689 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdWriteTimestamp()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06004690 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004691 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06004692 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08004693 dev_data->device_dispatch_table->CmdWriteTimestamp(commandBuffer, pipelineStage, queryPool, slot);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06004694}
4695
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004696VK_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 -06004697{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06004698 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +08004699 VkResult result = dev_data->device_dispatch_table->CreateFramebuffer(device, pCreateInfo, pAllocator, pFramebuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06004700 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06004701 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004702 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Chia-I Wuc278df82015-07-07 11:50:03 +08004703 if (pCreateInfo->pAttachments) {
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -06004704 localFBCI->pAttachments = new VkImageView[localFBCI->attachmentCount];
4705 memcpy((void*)localFBCI->pAttachments, pCreateInfo->pAttachments, localFBCI->attachmentCount*sizeof(VkImageView));
Tobin Ehlis2464b882015-04-01 08:40:34 -06004706 }
Chia-I Wue420a332015-10-26 20:04:44 +08004707 dev_data->frameBufferMap[*pFramebuffer] = localFBCI;
Tobin Ehlis2464b882015-04-01 08:40:34 -06004708 }
4709 return result;
4710}
4711
Michael Lentine329697b2015-10-06 14:56:18 -07004712// Store the DAG.
4713struct DAGNode {
4714 uint32_t pass;
4715 std::vector<uint32_t> prev;
4716 std::vector<uint32_t> next;
4717};
4718
Courtney Goeltzenleuchterf2bca902015-11-03 15:41:43 -07004719VkBool32 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 -07004720 // If we have already checked this node we have not found a dependency path so return false.
4721 if (processed_nodes.count(index))
4722 return false;
4723 processed_nodes.insert(index);
4724 const DAGNode& node = subpass_to_node[index];
4725 // Look for a dependency path. If one exists return true else recurse on the previous nodes.
4726 if (std::find(node.prev.begin(), node.prev.end(), dependent) == node.prev.end()) {
4727 for (auto elem : node.prev) {
4728 if (FindDependency(elem, dependent, subpass_to_node, processed_nodes))
4729 return true;
4730 }
4731 } else {
4732 return true;
4733 }
4734 return false;
4735}
4736
Courtney Goeltzenleuchterf2bca902015-11-03 15:41:43 -07004737VkBool32 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) {
4738 VkBool32 result = true;
Michael Lentine329697b2015-10-06 14:56:18 -07004739 // Loop through all subpasses that share the same attachment and make sure a dependency exists
4740 for (uint32_t k = 0; k < dependent_subpasses.size(); ++k) {
4741 if (subpass == dependent_subpasses[k])
4742 continue;
4743 const DAGNode& node = subpass_to_node[subpass];
4744 // Check for a specified dependency between the two nodes. If one exists we are done.
4745 auto prev_elem = std::find(node.prev.begin(), node.prev.end(), dependent_subpasses[k]);
4746 auto next_elem = std::find(node.next.begin(), node.next.end(), dependent_subpasses[k]);
4747 if (prev_elem == node.prev.end() && next_elem == node.next.end()) {
4748 // If no dependency exits an implicit dependency still might. If so, warn and if not throw an error.
4749 std::unordered_set<uint32_t> processed_nodes;
4750 if (FindDependency(subpass, dependent_subpasses[k], subpass_to_node, processed_nodes) ||
4751 FindDependency(dependent_subpasses[k], subpass, subpass_to_node, processed_nodes)) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07004752 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT, (VkDbgObjectType)0, 0, 0, DRAWSTATE_INVALID_RENDERPASS, "DS",
Michael Lentine329697b2015-10-06 14:56:18 -07004753 "A dependency between subpasses %d and %d must exist but only an implicit one is specified.",
4754 subpass, dependent_subpasses[k]);
4755 } else {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07004756 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, DRAWSTATE_INVALID_RENDERPASS, "DS",
Michael Lentine329697b2015-10-06 14:56:18 -07004757 "A dependency between subpasses %d and %d must exist but one is not specified.",
4758 subpass, dependent_subpasses[k]);
4759 result = false;
4760 }
4761 }
4762 }
4763 return result;
4764}
4765
Courtney Goeltzenleuchterf2bca902015-11-03 15:41:43 -07004766VkBool32 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 -07004767 const DAGNode& node = subpass_to_node[index];
4768 // If this node writes to the attachment return true as next nodes need to preserve the attachment.
4769 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Chia-I Wu763a7492015-10-26 20:48:51 +08004770 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentine329697b2015-10-06 14:56:18 -07004771 if (attachment == subpass.pColorAttachments[j].attachment)
Courtney Goeltzenleuchterf2bca902015-11-03 15:41:43 -07004772 return VK_TRUE;
Michael Lentine329697b2015-10-06 14:56:18 -07004773 }
Chia-I Wuce532f72015-10-26 17:32:47 +08004774 if (subpass.pDepthStencilAttachment &&
4775 subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
4776 if (attachment == subpass.pDepthStencilAttachment->attachment)
Courtney Goeltzenleuchterf2bca902015-11-03 15:41:43 -07004777 return VK_TRUE;
Michael Lentine329697b2015-10-06 14:56:18 -07004778 }
Courtney Goeltzenleuchterf2bca902015-11-03 15:41:43 -07004779 VkBool32 result = VK_FALSE;
Michael Lentine329697b2015-10-06 14:56:18 -07004780 // Loop through previous nodes and see if any of them write to the attachment.
4781 for (auto elem : node.prev) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004782 result |= CheckPreserved(my_data, device, pCreateInfo, elem, attachment, subpass_to_node, depth + 1, skip_call);
Michael Lentine329697b2015-10-06 14:56:18 -07004783 }
4784 // If the attachment was written to by a previous node than this node needs to preserve it.
4785 if (result && depth > 0) {
4786 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Courtney Goeltzenleuchterf2bca902015-11-03 15:41:43 -07004787 VkBool32 has_preserved = false;
Chia-I Wu763a7492015-10-26 20:48:51 +08004788 for (uint32_t j = 0; j < subpass.preserveAttachmentCount; ++j) {
Michael Lentine329697b2015-10-06 14:56:18 -07004789 if (subpass.pPreserveAttachments[j].attachment == attachment) {
4790 has_preserved = true;
4791 break;
4792 }
4793 }
4794 if (!has_preserved) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07004795 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, DRAWSTATE_INVALID_RENDERPASS, "DS",
Michael Lentine329697b2015-10-06 14:56:18 -07004796 "Attachment %d is used by a later subpass and must be preserved in subpass %d.", attachment, index);
4797 }
4798 }
4799 return result;
4800}
4801
Michael Lentine27b0f902015-10-12 11:30:14 -05004802VkBool32 ValidateDependencies(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, std::vector<DAGNode>& subpass_to_node) {
4803 VkBool32 skip_call = false;
Michael Lentine329697b2015-10-06 14:56:18 -07004804 std::vector<std::vector<uint32_t>> output_attachment_to_subpass(pCreateInfo->attachmentCount);
4805 std::vector<std::vector<uint32_t>> input_attachment_to_subpass(pCreateInfo->attachmentCount);
Michael Lentine27b0f902015-10-12 11:30:14 -05004806
Michael Lentine329697b2015-10-06 14:56:18 -07004807 // Create DAG
4808 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
4809 DAGNode& subpass_node = subpass_to_node[i];
4810 subpass_node.pass = i;
4811 }
4812 for (uint32_t i = 0; i < pCreateInfo->dependencyCount; ++i) {
4813 const VkSubpassDependency& dependency = pCreateInfo->pDependencies[i];
Chia-I Wu1f851912015-10-27 18:04:07 +08004814 if (dependency.srcSubpass > dependency.dstSubpass) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07004815 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, DRAWSTATE_INVALID_RENDERPASS, "DS",
Michael Lentine329697b2015-10-06 14:56:18 -07004816 "Dependency graph must be specified such that an earlier pass cannot depend on a later pass.");
4817 }
Chia-I Wu1f851912015-10-27 18:04:07 +08004818 subpass_to_node[dependency.dstSubpass].prev.push_back(dependency.srcSubpass);
4819 subpass_to_node[dependency.srcSubpass].next.push_back(dependency.dstSubpass);
Michael Lentine329697b2015-10-06 14:56:18 -07004820 }
Michael Lentine27b0f902015-10-12 11:30:14 -05004821
Michael Lentine329697b2015-10-06 14:56:18 -07004822 // Find for each attachment the subpasses that use them.
4823 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
4824 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wu763a7492015-10-26 20:48:51 +08004825 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Michael Lentine329697b2015-10-06 14:56:18 -07004826 input_attachment_to_subpass[subpass.pInputAttachments[j].attachment].push_back(i);
4827 }
Chia-I Wu763a7492015-10-26 20:48:51 +08004828 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentine329697b2015-10-06 14:56:18 -07004829 output_attachment_to_subpass[subpass.pColorAttachments[j].attachment].push_back(i);
4830 }
Chia-I Wuce532f72015-10-26 17:32:47 +08004831 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
4832 output_attachment_to_subpass[subpass.pDepthStencilAttachment->attachment].push_back(i);
Michael Lentine329697b2015-10-06 14:56:18 -07004833 }
4834 }
4835 // If there is a dependency needed make sure one exists
4836 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
4837 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
4838 // If the attachment is an input then all subpasses that output must have a dependency relationship
Chia-I Wu763a7492015-10-26 20:48:51 +08004839 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Michael Lentine329697b2015-10-06 14:56:18 -07004840 const uint32_t& attachment = subpass.pInputAttachments[j].attachment;
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004841 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentine329697b2015-10-06 14:56:18 -07004842 }
4843 // 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 +08004844 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentine329697b2015-10-06 14:56:18 -07004845 const uint32_t& attachment = subpass.pColorAttachments[j].attachment;
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004846 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
4847 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentine329697b2015-10-06 14:56:18 -07004848 }
Chia-I Wuce532f72015-10-26 17:32:47 +08004849 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
4850 const uint32_t& attachment = subpass.pDepthStencilAttachment->attachment;
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004851 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
4852 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentine329697b2015-10-06 14:56:18 -07004853 }
4854 }
4855 // Loop through implicit dependencies, if this pass reads make sure the attachment is preserved for all passes after it was written.
4856 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
4857 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wu763a7492015-10-26 20:48:51 +08004858 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004859 CheckPreserved(my_data, device, pCreateInfo, i, subpass.pInputAttachments[j].attachment, subpass_to_node, 0, skip_call);
Michael Lentine329697b2015-10-06 14:56:18 -07004860 }
4861 }
4862 return skip_call;
4863}
4864
Michael Lentine27b0f902015-10-12 11:30:14 -05004865bool ValidateLayouts(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo) {
4866 bool skip = false;
Mark Lobodzinski78940a42015-11-30 16:48:53 -07004867
4868#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4869 return skip;
4870#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4871
Michael Lentine27b0f902015-10-12 11:30:14 -05004872 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
4873 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
4874 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
4875 if (subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL &&
4876 subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) {
4877 if (subpass.pInputAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07004878 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT, (VkDbgObjectType)0, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentine27b0f902015-10-12 11:30:14 -05004879 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
4880 } else {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07004881 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentine27b0f902015-10-12 11:30:14 -05004882 "Layout for input attachment is %d but can only be READ_ONLY_OPTIMAL or GENERAL.", subpass.pInputAttachments[j].attachment);
4883 }
4884 }
4885 }
4886 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
4887 if (subpass.pColorAttachments[j].layout != VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) {
4888 if (subpass.pColorAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07004889 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT, (VkDbgObjectType)0, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentine27b0f902015-10-12 11:30:14 -05004890 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
4891 } else {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07004892 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentine27b0f902015-10-12 11:30:14 -05004893 "Layout for color attachment is %d but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.", subpass.pColorAttachments[j].attachment);
4894 }
4895 }
4896 }
Mark Lobodzinskic344bef2015-10-28 13:03:56 -06004897 if ((subpass.pDepthStencilAttachment != NULL) &&
4898 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
Michael Lentine27b0f902015-10-12 11:30:14 -05004899 if (subpass.pDepthStencilAttachment->layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) {
4900 if (subpass.pDepthStencilAttachment->layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07004901 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT, (VkDbgObjectType)0, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentine27b0f902015-10-12 11:30:14 -05004902 "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL.");
4903 } else {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07004904 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentine27b0f902015-10-12 11:30:14 -05004905 "Layout for depth attachment is %d but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL.", subpass.pDepthStencilAttachment->attachment);
4906 }
4907 }
4908 }
4909 }
4910 return skip;
4911}
4912
Michael Lentine07ff1a12015-10-15 17:07:00 -05004913bool CreatePassDAG(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, std::vector<DAGNode>& subpass_to_node, std::vector<bool>& has_self_dependency) {
Michael Lentine27b0f902015-10-12 11:30:14 -05004914 bool skip_call = false;
4915 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
4916 DAGNode& subpass_node = subpass_to_node[i];
4917 subpass_node.pass = i;
4918 }
4919 for (uint32_t i = 0; i < pCreateInfo->dependencyCount; ++i) {
4920 const VkSubpassDependency& dependency = pCreateInfo->pDependencies[i];
4921 if (dependency.srcSubpass > dependency.dstSubpass) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07004922 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, DRAWSTATE_INVALID_RENDERPASS, "DS",
Michael Lentine27b0f902015-10-12 11:30:14 -05004923 "Depedency graph must be specified such that an earlier pass cannot depend on a later pass.");
Michael Lentine07ff1a12015-10-15 17:07:00 -05004924 } else if (dependency.srcSubpass == dependency.dstSubpass) {
4925 has_self_dependency[dependency.srcSubpass] = true;
Michael Lentine27b0f902015-10-12 11:30:14 -05004926 }
4927 subpass_to_node[dependency.dstSubpass].prev.push_back(dependency.srcSubpass);
4928 subpass_to_node[dependency.srcSubpass].next.push_back(dependency.dstSubpass);
4929 }
4930 return skip_call;
4931}
Tobin Ehliscb085292015-12-01 09:57:09 -07004932// TODOSC : Add intercept of vkCreateShaderModule
Michael Lentine27b0f902015-10-12 11:30:14 -05004933
Tobin Ehlis32479352015-12-01 09:48:58 -07004934VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateShaderModule(
4935 VkDevice device,
4936 const VkShaderModuleCreateInfo *pCreateInfo,
4937 const VkAllocationCallbacks* pAllocator,
4938 VkShaderModule *pShaderModule)
4939{
4940 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4941 bool skip_call = false;
4942 if (!shader_is_spirv(pCreateInfo)) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07004943 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE,
Tobin Ehlis32479352015-12-01 09:48:58 -07004944 /* dev */ 0, 0, SHADER_CHECKER_NON_SPIRV_SHADER, "SC",
4945 "Shader is not SPIR-V");
4946 }
4947
4948 if (skip_call)
4949 return VK_ERROR_VALIDATION_FAILED;
4950
4951 VkResult res = my_data->device_dispatch_table->CreateShaderModule(device, pCreateInfo, pAllocator, pShaderModule);
4952
4953 if (res == VK_SUCCESS) {
4954 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisad61de42015-12-02 13:53:34 -07004955 my_data->shaderModuleMap[*pShaderModule] = new shader_module(pCreateInfo);
Tobin Ehlis32479352015-12-01 09:48:58 -07004956 loader_platform_thread_unlock_mutex(&globalLock);
4957 }
4958 return res;
4959}
4960
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08004961VK_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 -06004962{
Michael Lentine27b0f902015-10-12 11:30:14 -05004963 bool skip_call = false;
Tobin Ehlis42d440c2015-10-20 17:06:16 -06004964 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentine27b0f902015-10-12 11:30:14 -05004965 // Create DAG
Michael Lentine07ff1a12015-10-15 17:07:00 -05004966 std::vector<bool> has_self_dependency(pCreateInfo->subpassCount);
Michael Lentine27b0f902015-10-12 11:30:14 -05004967 std::vector<DAGNode> subpass_to_node(pCreateInfo->subpassCount);
Michael Lentine07ff1a12015-10-15 17:07:00 -05004968 skip_call |= CreatePassDAG(dev_data, device, pCreateInfo, subpass_to_node, has_self_dependency);
Michael Lentine27b0f902015-10-12 11:30:14 -05004969 // Validate using DAG
4970 skip_call |= ValidateDependencies(dev_data, device, pCreateInfo, subpass_to_node);
4971 skip_call |= ValidateLayouts(dev_data, device, pCreateInfo);
4972 if (skip_call) {
Michael Lentine329697b2015-10-06 14:56:18 -07004973 return VK_ERROR_VALIDATION_FAILED;
4974 }
Chia-I Wu69f40122015-10-26 21:10:41 +08004975 VkResult result = dev_data->device_dispatch_table->CreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06004976 if (VK_SUCCESS == result) {
Tobin Ehliscb085292015-12-01 09:57:09 -07004977 // TODOSC : Merge in tracking of renderpass from ShaderChecker
Tobin Ehlis2464b882015-04-01 08:40:34 -06004978 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06004979 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Chia-I Wuc278df82015-07-07 11:50:03 +08004980 if (pCreateInfo->pAttachments) {
4981 localRPCI->pAttachments = new VkAttachmentDescription[localRPCI->attachmentCount];
4982 memcpy((void*)localRPCI->pAttachments, pCreateInfo->pAttachments, localRPCI->attachmentCount*sizeof(VkAttachmentDescription));
Tobin Ehlis2464b882015-04-01 08:40:34 -06004983 }
Chia-I Wuc278df82015-07-07 11:50:03 +08004984 if (pCreateInfo->pSubpasses) {
4985 localRPCI->pSubpasses = new VkSubpassDescription[localRPCI->subpassCount];
4986 memcpy((void*)localRPCI->pSubpasses, pCreateInfo->pSubpasses, localRPCI->subpassCount*sizeof(VkSubpassDescription));
4987
4988 for (uint32_t i = 0; i < localRPCI->subpassCount; i++) {
4989 VkSubpassDescription *subpass = (VkSubpassDescription *) &localRPCI->pSubpasses[i];
Chia-I Wu763a7492015-10-26 20:48:51 +08004990 const uint32_t attachmentCount = subpass->inputAttachmentCount +
4991 subpass->colorAttachmentCount * (1 + (subpass->pResolveAttachments?1:0)) +
Chia-I Wuce532f72015-10-26 17:32:47 +08004992 ((subpass->pDepthStencilAttachment) ? 1 : 0) + subpass->preserveAttachmentCount;
Chia-I Wuc278df82015-07-07 11:50:03 +08004993 VkAttachmentReference *attachments = new VkAttachmentReference[attachmentCount];
4994
Cody Northrop6de6b0b2015-08-04 11:16:41 -06004995 memcpy(attachments, subpass->pInputAttachments,
Chia-I Wu763a7492015-10-26 20:48:51 +08004996 sizeof(attachments[0]) * subpass->inputAttachmentCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06004997 subpass->pInputAttachments = attachments;
Chia-I Wu763a7492015-10-26 20:48:51 +08004998 attachments += subpass->inputAttachmentCount;
Chia-I Wuc278df82015-07-07 11:50:03 +08004999
Cody Northrop6de6b0b2015-08-04 11:16:41 -06005000 memcpy(attachments, subpass->pColorAttachments,
Chia-I Wu763a7492015-10-26 20:48:51 +08005001 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06005002 subpass->pColorAttachments = attachments;
Chia-I Wu763a7492015-10-26 20:48:51 +08005003 attachments += subpass->colorAttachmentCount;
Chia-I Wuc278df82015-07-07 11:50:03 +08005004
Cody Northrop6de6b0b2015-08-04 11:16:41 -06005005 if (subpass->pResolveAttachments) {
5006 memcpy(attachments, subpass->pResolveAttachments,
Chia-I Wu763a7492015-10-26 20:48:51 +08005007 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06005008 subpass->pResolveAttachments = attachments;
Chia-I Wu763a7492015-10-26 20:48:51 +08005009 attachments += subpass->colorAttachmentCount;
Chia-I Wuc278df82015-07-07 11:50:03 +08005010 }
5011
Chia-I Wuce532f72015-10-26 17:32:47 +08005012 if (subpass->pDepthStencilAttachment) {
5013 memcpy(attachments, subpass->pDepthStencilAttachment,
5014 sizeof(attachments[0]) * 1);
5015 subpass->pDepthStencilAttachment = attachments;
5016 attachments += 1;
5017 }
5018
Cody Northrop6de6b0b2015-08-04 11:16:41 -06005019 memcpy(attachments, subpass->pPreserveAttachments,
Chia-I Wu763a7492015-10-26 20:48:51 +08005020 sizeof(attachments[0]) * subpass->preserveAttachmentCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06005021 subpass->pPreserveAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08005022 }
Tobin Ehlis2464b882015-04-01 08:40:34 -06005023 }
Chia-I Wuc278df82015-07-07 11:50:03 +08005024 if (pCreateInfo->pDependencies) {
5025 localRPCI->pDependencies = new VkSubpassDependency[localRPCI->dependencyCount];
5026 memcpy((void*)localRPCI->pDependencies, pCreateInfo->pDependencies, localRPCI->dependencyCount*sizeof(VkSubpassDependency));
Tobin Ehlis2464b882015-04-01 08:40:34 -06005027 }
Tobin Ehlis32479352015-12-01 09:48:58 -07005028 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisad61de42015-12-02 13:53:34 -07005029 dev_data->renderPassMap[*pRenderPass] = new RENDER_PASS_NODE(localRPCI);
Michael Lentine07ff1a12015-10-15 17:07:00 -05005030 dev_data->renderPassMap[*pRenderPass]->hasSelfDependency = has_self_dependency;
Tobin Ehlis32479352015-12-01 09:48:58 -07005031 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis2464b882015-04-01 08:40:34 -06005032 }
5033 return result;
5034}
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005035// Free the renderpass shadow
5036static void deleteRenderPasses(layer_data* my_data)
5037{
5038 if (my_data->renderPassMap.size() <= 0)
5039 return;
5040 for (auto ii=my_data->renderPassMap.begin(); ii!=my_data->renderPassMap.end(); ++ii) {
Tobin Ehlisad61de42015-12-02 13:53:34 -07005041 const VkRenderPassCreateInfo* pRenderPassInfo = (*ii).second->pCreateInfo;
Michael Lentine07ff1a12015-10-15 17:07:00 -05005042 if (pRenderPassInfo->pAttachments) {
5043 delete[] pRenderPassInfo->pAttachments;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005044 }
Michael Lentine07ff1a12015-10-15 17:07:00 -05005045 if (pRenderPassInfo->pSubpasses) {
5046 for (uint32_t i=0; i<pRenderPassInfo->subpassCount; ++i) {
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005047 // Attachements are all allocated in a block, so just need to
5048 // find the first non-null one to delete
Michael Lentine07ff1a12015-10-15 17:07:00 -05005049 if (pRenderPassInfo->pSubpasses[i].pInputAttachments) {
5050 delete[] pRenderPassInfo->pSubpasses[i].pInputAttachments;
5051 } else if (pRenderPassInfo->pSubpasses[i].pColorAttachments) {
5052 delete[] pRenderPassInfo->pSubpasses[i].pColorAttachments;
5053 } else if (pRenderPassInfo->pSubpasses[i].pResolveAttachments) {
5054 delete[] pRenderPassInfo->pSubpasses[i].pResolveAttachments;
5055 } else if (pRenderPassInfo->pSubpasses[i].pPreserveAttachments) {
5056 delete[] pRenderPassInfo->pSubpasses[i].pPreserveAttachments;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005057 }
5058 }
Michael Lentine07ff1a12015-10-15 17:07:00 -05005059 delete[] pRenderPassInfo->pSubpasses;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005060 }
Michael Lentine07ff1a12015-10-15 17:07:00 -05005061 if (pRenderPassInfo->pDependencies) {
5062 delete[] pRenderPassInfo->pDependencies;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005063 }
Tobin Ehlisad61de42015-12-02 13:53:34 -07005064 delete pRenderPassInfo;
Michael Lentine07ff1a12015-10-15 17:07:00 -05005065 delete (*ii).second;
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005066 }
5067 my_data->renderPassMap.clear();
5068}
Michael Lentine27b0f902015-10-12 11:30:14 -05005069
5070bool VerifyFramebufferAndRenderPassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
5071 bool skip_call = false;
5072 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5073 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Tobin Ehlisad61de42015-12-02 13:53:34 -07005074 const VkRenderPassCreateInfo* pRenderPassInfo = dev_data->renderPassMap[pRenderPassBegin->renderPass]->pCreateInfo;
Michael Lentine27b0f902015-10-12 11:30:14 -05005075 const VkFramebufferCreateInfo* pFramebufferInfo = dev_data->frameBufferMap[pRenderPassBegin->framebuffer];
5076 if (pRenderPassInfo->attachmentCount != pFramebufferInfo->attachmentCount) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07005077 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, DRAWSTATE_INVALID_RENDERPASS, "DS",
Michael Lentine27b0f902015-10-12 11:30:14 -05005078 "You cannot start a render pass using a framebuffer with a different number of attachments.");
5079 }
5080 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
5081 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
5082 const VkImage& image = dev_data->imageViewMap[image_view]->image;
5083 auto image_data = pCB->imageLayoutMap.find(image);
5084 if (image_data == pCB->imageLayoutMap.end()) {
5085 pCB->imageLayoutMap[image].initialLayout = pRenderPassInfo->pAttachments[i].initialLayout;
5086 pCB->imageLayoutMap[image].layout = pRenderPassInfo->pAttachments[i].initialLayout;
5087 } else if (pRenderPassInfo->pAttachments[i].initialLayout != image_data->second.layout) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07005088 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, DRAWSTATE_INVALID_RENDERPASS, "DS",
Michael Lentine27b0f902015-10-12 11:30:14 -05005089 "You cannot start a render pass using attachment %i where the intial layout differs from the starting layout.", i);
5090 }
5091 }
5092 return skip_call;
5093}
5094
5095void TransitionSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, const int subpass_index) {
5096 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5097 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5098 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
5099 if (render_pass_data == dev_data->renderPassMap.end()) {
5100 return;
5101 }
Tobin Ehlisad61de42015-12-02 13:53:34 -07005102 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
Michael Lentine27b0f902015-10-12 11:30:14 -05005103 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
5104 if (framebuffer_data == dev_data->frameBufferMap.end()) {
5105 return;
5106 }
5107 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
5108 const VkSubpassDescription& subpass = pRenderPassInfo->pSubpasses[subpass_index];
5109 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
5110 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pInputAttachments[j].attachment];
5111 auto image_view_data = dev_data->imageViewMap.find(image_view);
5112 if (image_view_data != dev_data->imageViewMap.end()) {
5113 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5114 if (image_layout != pCB->imageLayoutMap.end()) {
5115 image_layout->second.layout = subpass.pInputAttachments[j].layout;
5116 }
5117 }
5118 }
5119 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
5120 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pColorAttachments[j].attachment];
5121 auto image_view_data = dev_data->imageViewMap.find(image_view);
5122 if (image_view_data != dev_data->imageViewMap.end()) {
5123 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5124 if (image_layout != pCB->imageLayoutMap.end()) {
5125 image_layout->second.layout = subpass.pColorAttachments[j].layout;
5126 }
5127 }
5128 }
Michael Lentine2b9eda42015-10-28 15:55:18 -07005129 if ((subpass.pDepthStencilAttachment != NULL) &&
Mark Lobodzinskic344bef2015-10-28 13:03:56 -06005130 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
Michael Lentine27b0f902015-10-12 11:30:14 -05005131 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pDepthStencilAttachment->attachment];
5132 auto image_view_data = dev_data->imageViewMap.find(image_view);
5133 if (image_view_data != dev_data->imageViewMap.end()) {
5134 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5135 if (image_layout != pCB->imageLayoutMap.end()) {
5136 image_layout->second.layout = subpass.pDepthStencilAttachment->layout;
5137 }
5138 }
5139 }
5140}
5141
Michael Lentine2b9eda42015-10-28 15:55:18 -07005142bool validatePrimaryCommandBuffer(const layer_data* my_data, const GLOBAL_CB_NODE* pCB, const std::string& cmd_name) {
5143 bool skip_call = false;
5144 if (pCB->createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07005145 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, DRAWSTATE_INVALID_COMMAND_BUFFER, "DS",
Michael Lentine2b9eda42015-10-28 15:55:18 -07005146 "Cannot execute command %s on a secondary command buffer.", cmd_name.c_str());
5147 }
5148 return skip_call;
5149}
5150
Michael Lentine27b0f902015-10-12 11:30:14 -05005151void TransitionFinalSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
5152 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5153 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5154 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
5155 if (render_pass_data == dev_data->renderPassMap.end()) {
5156 return;
5157 }
Tobin Ehlisad61de42015-12-02 13:53:34 -07005158 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
Michael Lentine27b0f902015-10-12 11:30:14 -05005159 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
5160 if (framebuffer_data == dev_data->frameBufferMap.end()) {
5161 return;
5162 }
5163 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
5164 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
5165 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
5166 auto image_view_data = dev_data->imageViewMap.find(image_view);
5167 if (image_view_data != dev_data->imageViewMap.end()) {
5168 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5169 if (image_layout != pCB->imageLayoutMap.end()) {
5170 image_layout->second.layout = pRenderPassInfo->pAttachments[i].finalLayout;
5171 }
5172 }
5173 }
5174}
5175
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005176VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, VkSubpassContents contents)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005177{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005178 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08005179 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5180 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005181 if (pCB) {
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06005182 if (pRenderPassBegin && pRenderPassBegin->renderPass) {
Mark Lobodzinskic344bef2015-10-28 13:03:56 -06005183 skipCall |= VerifyFramebufferAndRenderPassLayouts(commandBuffer, pRenderPassBegin);
Tobin Ehlis42d440c2015-10-20 17:06:16 -06005184 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBeginRenderPass");
Michael Lentine2b9eda42015-10-28 15:55:18 -07005185 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdBeginRenderPass");
Tobin Ehlis42d440c2015-10-20 17:06:16 -06005186 skipCall |= addCmd(dev_data, pCB, CMD_BEGINRENDERPASS);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06005187 pCB->activeRenderPass = pRenderPassBegin->renderPass;
Michael Lentine27b0f902015-10-12 11:30:14 -05005188 // This is a shallow copy as that is all that is needed for now
5189 pCB->activeRenderPassBeginInfo = *pRenderPassBegin;
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06005190 pCB->activeSubpass = 0;
5191 pCB->framebuffer = pRenderPassBegin->framebuffer;
5192 if (pCB->lastBoundPipeline) {
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005193 skipCall |= validatePipelineState(dev_data, pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06005194 }
Tobin Ehlise4076782015-06-24 15:53:07 -06005195 } else {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07005196 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS, "DS",
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06005197 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tony Barbourb9f82ba2015-04-06 11:09:26 -06005198 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005199 }
Mark Lobodzinskic344bef2015-10-28 13:03:56 -06005200 if (VK_FALSE == skipCall) {
Chia-I Wu1f851912015-10-27 18:04:07 +08005201 dev_data->device_dispatch_table->CmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents);
Mark Lobodzinskic344bef2015-10-28 13:03:56 -06005202 // This is a shallow copy as that is all that is needed for now
5203 dev_data->renderPassBeginInfo = *pRenderPassBegin;
5204 dev_data->currentSubpass = 0;
5205 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005206}
5207
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005208VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents)
Chia-I Wuc278df82015-07-07 11:50:03 +08005209{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005210 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08005211 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5212 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Michael Lentine27b0f902015-10-12 11:30:14 -05005213 TransitionSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo, ++dev_data->currentSubpass);
Chia-I Wuc278df82015-07-07 11:50:03 +08005214 if (pCB) {
Michael Lentine2b9eda42015-10-28 15:55:18 -07005215 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdNextSubpass");
Tobin Ehlis42d440c2015-10-20 17:06:16 -06005216 skipCall |= addCmd(dev_data, pCB, CMD_NEXTSUBPASS);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06005217 pCB->activeSubpass++;
Michael Lentine27b0f902015-10-12 11:30:14 -05005218 TransitionSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo, ++pCB->activeSubpass);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06005219 if (pCB->lastBoundPipeline) {
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005220 skipCall |= validatePipelineState(dev_data, pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Chia-I Wuc278df82015-07-07 11:50:03 +08005221 }
Tobin Ehlis42d440c2015-10-20 17:06:16 -06005222 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdNextSubpass");
Chia-I Wuc278df82015-07-07 11:50:03 +08005223 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005224 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08005225 dev_data->device_dispatch_table->CmdNextSubpass(commandBuffer, contents);
Chia-I Wuc278df82015-07-07 11:50:03 +08005226}
5227
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005228VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndRenderPass(VkCommandBuffer commandBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005229{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005230 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08005231 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5232 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Michael Lentine27b0f902015-10-12 11:30:14 -05005233 TransitionFinalSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005234 if (pCB) {
Michael Lentine2b9eda42015-10-28 15:55:18 -07005235 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdEndRenderpass");
Michael Lentine2b9eda42015-10-28 15:55:18 -07005236 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdEndRenderPass");
Tobin Ehlis42d440c2015-10-20 17:06:16 -06005237 skipCall |= addCmd(dev_data, pCB, CMD_ENDRENDERPASS);
Michael Lentine27b0f902015-10-12 11:30:14 -05005238 TransitionFinalSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06005239 pCB->activeRenderPass = 0;
5240 pCB->activeSubpass = 0;
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08005241 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005242 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08005243 dev_data->device_dispatch_table->CmdEndRenderPass(commandBuffer);
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08005244}
5245
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005246VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount, const VkCommandBuffer* pCommandBuffers)
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08005247{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005248 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08005249 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5250 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08005251 if (pCB) {
Tobin Ehlis5f728d32015-09-17 14:18:16 -06005252 GLOBAL_CB_NODE* pSubCB = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08005253 for (uint32_t i=0; i<commandBuffersCount; i++) {
5254 pSubCB = getCBNode(dev_data, pCommandBuffers[i]);
Tobin Ehlis5f728d32015-09-17 14:18:16 -06005255 if (!pSubCB) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07005256 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_SECONDARY_COMMAND_BUFFER, "DS",
Chia-I Wu1f851912015-10-27 18:04:07 +08005257 "vkCmdExecuteCommands() called w/ invalid Cmd Buffer %p in element %u of pCommandBuffers array.", (void*)pCommandBuffers[i], i);
5258 } else if (VK_COMMAND_BUFFER_LEVEL_PRIMARY == pSubCB->createInfo.level) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07005259 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_SECONDARY_COMMAND_BUFFER, "DS",
Chia-I Wu1f851912015-10-27 18:04:07 +08005260 "vkCmdExecuteCommands() called w/ Primary Cmd Buffer %p in element %u of pCommandBuffers array. All cmd buffers in pCommandBuffers array must be secondary.", (void*)pCommandBuffers[i], i);
Tobin Ehlis5f728d32015-09-17 14:18:16 -06005261 }
5262 }
Michael Lentine2b9eda42015-10-28 15:55:18 -07005263 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdExecuteComands");
Tobin Ehlis42d440c2015-10-20 17:06:16 -06005264 skipCall |= addCmd(dev_data, pCB, CMD_EXECUTECOMMANDS);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005265 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005266 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08005267 dev_data->device_dispatch_table->CmdExecuteCommands(commandBuffer, commandBuffersCount, pCommandBuffers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005268}
5269
Michael Lentineee4ad4d2015-10-23 12:41:44 -07005270bool ValidateMapImageLayouts(VkDevice device, VkDeviceMemory mem) {
5271 bool skip_call = false;
5272 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5273 auto mem_data = dev_data->memImageMap.find(mem);
5274 if (mem_data != dev_data->memImageMap.end()) {
5275 auto image_data = dev_data->imageLayoutMap.find(mem_data->second);
5276 if (image_data != dev_data->imageLayoutMap.end()) {
5277 if (image_data->second->layout != VK_IMAGE_LAYOUT_PREINITIALIZED && image_data->second->layout != VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07005278 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineee4ad4d2015-10-23 12:41:44 -07005279 "Cannot map an image with layout %d. Only GENERAL or PREINITIALIZED are supported.", image_data->second->layout);
5280 }
5281 }
5282 }
5283 return skip_call;
5284}
5285
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005286VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkMapMemory(
Michael Lentineee4ad4d2015-10-23 12:41:44 -07005287 VkDevice device,
5288 VkDeviceMemory mem,
5289 VkDeviceSize offset,
5290 VkDeviceSize size,
5291 VkFlags flags,
5292 void **ppData)
5293{
5294 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski78940a42015-11-30 16:48:53 -07005295
5296 bool skip_call = VK_FALSE;
5297#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
5298 skip_call = ValidateMapImageLayouts(device, mem);
5299#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5300
Michael Lentineee4ad4d2015-10-23 12:41:44 -07005301 if (VK_FALSE == skip_call) {
5302 return dev_data->device_dispatch_table->MapMemory(device, mem, offset, size, flags, ppData);
5303 }
5304 return VK_ERROR_VALIDATION_FAILED;
5305}
5306
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005307VKAPI_ATTR VkResult VKAPI_CALL vkBindImageMemory(
Michael Lentineee4ad4d2015-10-23 12:41:44 -07005308 VkDevice device,
5309 VkImage image,
5310 VkDeviceMemory mem,
5311 VkDeviceSize memOffset)
5312{
5313 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5314 VkResult result = dev_data->device_dispatch_table->BindImageMemory(device, image, mem, memOffset);
5315 loader_platform_thread_lock_mutex(&globalLock);
5316 dev_data->memImageMap[mem] = image;
5317 loader_platform_thread_unlock_mutex(&globalLock);
5318 return result;
5319}
5320
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005321VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(
Michael Lentine27b0f902015-10-12 11:30:14 -05005322 VkDevice device,
5323 const VkSwapchainCreateInfoKHR *pCreateInfo,
Ian Elliottc623ba52015-11-20 14:13:17 -07005324 const VkAllocationCallbacks *pAllocator,
Michael Lentine27b0f902015-10-12 11:30:14 -05005325 VkSwapchainKHR *pSwapchain)
5326{
5327 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliottc623ba52015-11-20 14:13:17 -07005328 VkResult result = dev_data->device_dispatch_table->CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
Michael Lentine27b0f902015-10-12 11:30:14 -05005329
5330 if (VK_SUCCESS == result) {
5331 SWAPCHAIN_NODE *swapchain_data = new SWAPCHAIN_NODE;
5332 loader_platform_thread_lock_mutex(&globalLock);
5333 dev_data->device_extensions.swapchainMap[*pSwapchain] = swapchain_data;
5334 loader_platform_thread_unlock_mutex(&globalLock);
5335 }
5336
5337 return result;
5338}
5339
Ian Elliottc623ba52015-11-20 14:13:17 -07005340VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR(
Michael Lentine27b0f902015-10-12 11:30:14 -05005341 VkDevice device,
Ian Elliottc623ba52015-11-20 14:13:17 -07005342 VkSwapchainKHR swapchain,
5343 const VkAllocationCallbacks *pAllocator)
Michael Lentine27b0f902015-10-12 11:30:14 -05005344{
5345 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentine27b0f902015-10-12 11:30:14 -05005346
5347 loader_platform_thread_lock_mutex(&globalLock);
5348 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(swapchain);
5349 if (swapchain_data != dev_data->device_extensions.swapchainMap.end()) {
5350 if (swapchain_data->second->images.size() > 0) {
5351 for (auto swapchain_image : swapchain_data->second->images) {
5352 auto image_item = dev_data->imageLayoutMap.find(swapchain_image);
5353 if (image_item != dev_data->imageLayoutMap.end())
5354 dev_data->imageLayoutMap.erase(image_item);
5355 }
5356 }
5357 delete swapchain_data->second;
5358 dev_data->device_extensions.swapchainMap.erase(swapchain);
5359 }
5360 loader_platform_thread_unlock_mutex(&globalLock);
Ian Elliottc623ba52015-11-20 14:13:17 -07005361 return dev_data->device_dispatch_table->DestroySwapchainKHR(device, swapchain, pAllocator);
Michael Lentine27b0f902015-10-12 11:30:14 -05005362}
5363
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005364VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR(
Michael Lentine27b0f902015-10-12 11:30:14 -05005365 VkDevice device,
5366 VkSwapchainKHR swapchain,
5367 uint32_t* pCount,
5368 VkImage* pSwapchainImages)
5369{
5370 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5371 VkResult result = dev_data->device_dispatch_table->GetSwapchainImagesKHR(device, swapchain, pCount, pSwapchainImages);
5372
5373 if (result == VK_SUCCESS && pSwapchainImages != NULL) {
5374 // This should never happen and is checked by param checker.
5375 if (!pCount) return result;
5376 for (uint32_t i = 0; i < *pCount; ++i) {
5377 IMAGE_NODE* image_node = new IMAGE_NODE;
5378 image_node->layout = VK_IMAGE_LAYOUT_UNDEFINED;
5379 loader_platform_thread_lock_mutex(&globalLock);
5380 dev_data->device_extensions.swapchainMap[swapchain]->images.push_back(pSwapchainImages[i]);
5381 dev_data->imageLayoutMap[pSwapchainImages[i]] = image_node;
5382 loader_platform_thread_unlock_mutex(&globalLock);
5383 }
5384 }
5385 return result;
5386}
5387
Ian Elliottc623ba52015-11-20 14:13:17 -07005388VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo)
Michael Lentine27b0f902015-10-12 11:30:14 -05005389{
5390 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
5391 bool skip_call = false;
5392
Mark Lobodzinski78940a42015-11-30 16:48:53 -07005393#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentine27b0f902015-10-12 11:30:14 -05005394 if (pPresentInfo) {
5395 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
Ian Elliottc623ba52015-11-20 14:13:17 -07005396 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(pPresentInfo->pSwapchains[i]);
5397 if (swapchain_data != dev_data->device_extensions.swapchainMap.end() && pPresentInfo->pImageIndices[i] < swapchain_data->second->images.size()) {
5398 VkImage image = swapchain_data->second->images[pPresentInfo->pImageIndices[i]];
Michael Lentine27b0f902015-10-12 11:30:14 -05005399 auto image_data = dev_data->imageLayoutMap.find(image);
5400 if (image_data != dev_data->imageLayoutMap.end()) {
Ian Elliottc623ba52015-11-20 14:13:17 -07005401 if (image_data->second->layout != VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07005402 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_QUEUE, (uint64_t)queue, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentine27b0f902015-10-12 11:30:14 -05005403 "Images passed to present must be in layout PRESENT_SOURCE_KHR but is in %d", image_data->second->layout);
5404 }
5405 }
5406 }
5407 }
5408 }
Mark Lobodzinski78940a42015-11-30 16:48:53 -07005409#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentine27b0f902015-10-12 11:30:14 -05005410
5411 if (VK_FALSE == skip_call)
5412 return dev_data->device_dispatch_table->QueuePresentKHR(queue, pPresentInfo);
5413 return VK_ERROR_VALIDATION_FAILED;
5414}
5415
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005416VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkDbgCreateMsgCallback(
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06005417 VkInstance instance,
5418 VkFlags msgFlags,
5419 const PFN_vkDbgMsgCallback pfnMsgCallback,
5420 void* pUserData,
5421 VkDbgMsgCallback* pMsgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005422{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005423 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehliscb085292015-12-01 09:57:09 -07005424 VkResult res = my_data->instance_dispatch_table->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
Tobin Ehlisc91330b2015-06-16 09:04:30 -06005425 if (VK_SUCCESS == res) {
Tobin Ehlisc91330b2015-06-16 09:04:30 -06005426 res = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
5427 }
5428 return res;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005429}
5430
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005431VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkDbgDestroyMsgCallback(
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06005432 VkInstance instance,
5433 VkDbgMsgCallback msgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005434{
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005435 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehliscb085292015-12-01 09:57:09 -07005436 VkResult res = my_data->instance_dispatch_table->DbgDestroyMsgCallback(instance, msgCallback);
Tobin Ehlisc91330b2015-06-16 09:04:30 -06005437 layer_destroy_msg_callback(my_data->report_data, msgCallback);
5438 return res;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005439}
5440
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005441VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerBegin(VkCommandBuffer commandBuffer, const char* pMarker)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005442{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005443 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08005444 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5445 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005446 if (!dev_data->device_extensions.debug_marker_enabled) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07005447 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, (uint64_t)commandBuffer, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06005448 "Attempt to use CmdDbgMarkerBegin but extension disabled!");
Jon Ashburn6f8cd632015-06-01 09:37:38 -06005449 return;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06005450 } else if (pCB) {
Tobin Ehlis32479352015-12-01 09:48:58 -07005451
Tobin Ehlis42d440c2015-10-20 17:06:16 -06005452 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKERBEGIN);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005453 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005454 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08005455 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerBegin(commandBuffer, pMarker);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005456}
5457
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005458VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerEnd(VkCommandBuffer commandBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005459{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005460 VkBool32 skipCall = VK_FALSE;
Chia-I Wu1f851912015-10-27 18:04:07 +08005461 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5462 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005463 if (!dev_data->device_extensions.debug_marker_enabled) {
Courtney Goeltzenleuchterf8fe1282015-11-25 10:30:56 -07005464 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, (uint64_t)commandBuffer, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06005465 "Attempt to use CmdDbgMarkerEnd but extension disabled!");
Jon Ashburn6f8cd632015-06-01 09:37:38 -06005466 return;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06005467 } else if (pCB) {
Tobin Ehlis32479352015-12-01 09:48:58 -07005468
Tobin Ehlis42d440c2015-10-20 17:06:16 -06005469 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKEREND);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005470 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06005471 if (VK_FALSE == skipCall)
Chia-I Wu1f851912015-10-27 18:04:07 +08005472 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerEnd(commandBuffer);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06005473}
5474
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005475VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005476{
Jon Ashburn1245cec2015-05-18 13:20:15 -06005477 if (dev == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005478 return NULL;
Jon Ashburne0fa2282015-05-20 09:00:28 -06005479
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005480 layer_data *dev_data;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005481 /* loader uses this to force layer initialization; device object is wrapped */
5482 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005483 VkBaseLayerObject* wrapped_dev = (VkBaseLayerObject*) dev;
5484 dev_data = get_my_data_ptr(get_dispatch_key(wrapped_dev->baseObject), layer_data_map);
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005485 dev_data->device_dispatch_table = new VkLayerDispatchTable;
5486 layer_initialize_dispatch_table(dev_data->device_dispatch_table, wrapped_dev);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005487 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005488 }
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005489 dev_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map);
Courtney Goeltzenleuchterbe637992015-06-25 18:01:43 -06005490 if (!strcmp(funcName, "vkCreateDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005491 return (PFN_vkVoidFunction) vkCreateDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005492 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005493 return (PFN_vkVoidFunction) vkDestroyDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005494 if (!strcmp(funcName, "vkQueueSubmit"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005495 return (PFN_vkVoidFunction) vkQueueSubmit;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005496 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005497 return (PFN_vkVoidFunction) vkDestroyInstance;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005498 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005499 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005500 if (!strcmp(funcName, "vkDestroyFence"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005501 return (PFN_vkVoidFunction) vkDestroyFence;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005502 if (!strcmp(funcName, "vkDestroySemaphore"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005503 return (PFN_vkVoidFunction) vkDestroySemaphore;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005504 if (!strcmp(funcName, "vkDestroyEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005505 return (PFN_vkVoidFunction) vkDestroyEvent;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005506 if (!strcmp(funcName, "vkDestroyQueryPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005507 return (PFN_vkVoidFunction) vkDestroyQueryPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005508 if (!strcmp(funcName, "vkDestroyBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005509 return (PFN_vkVoidFunction) vkDestroyBuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005510 if (!strcmp(funcName, "vkDestroyBufferView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005511 return (PFN_vkVoidFunction) vkDestroyBufferView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005512 if (!strcmp(funcName, "vkDestroyImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005513 return (PFN_vkVoidFunction) vkDestroyImage;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005514 if (!strcmp(funcName, "vkDestroyImageView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005515 return (PFN_vkVoidFunction) vkDestroyImageView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005516 if (!strcmp(funcName, "vkDestroyShaderModule"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005517 return (PFN_vkVoidFunction) vkDestroyShaderModule;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005518 if (!strcmp(funcName, "vkDestroyPipeline"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005519 return (PFN_vkVoidFunction) vkDestroyPipeline;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005520 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005521 return (PFN_vkVoidFunction) vkDestroyPipelineLayout;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005522 if (!strcmp(funcName, "vkDestroySampler"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005523 return (PFN_vkVoidFunction) vkDestroySampler;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005524 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005525 return (PFN_vkVoidFunction) vkDestroyDescriptorSetLayout;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005526 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005527 return (PFN_vkVoidFunction) vkDestroyDescriptorPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005528 if (!strcmp(funcName, "vkDestroyFramebuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005529 return (PFN_vkVoidFunction) vkDestroyFramebuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06005530 if (!strcmp(funcName, "vkDestroyRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005531 return (PFN_vkVoidFunction) vkDestroyRenderPass;
Tobin Ehlisb46be812015-10-23 16:00:08 -06005532 if (!strcmp(funcName, "vkCreateBuffer"))
5533 return (PFN_vkVoidFunction) vkCreateBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005534 if (!strcmp(funcName, "vkCreateBufferView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005535 return (PFN_vkVoidFunction) vkCreateBufferView;
Tobin Ehlisb46be812015-10-23 16:00:08 -06005536 if (!strcmp(funcName, "vkCreateImage"))
5537 return (PFN_vkVoidFunction) vkCreateImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005538 if (!strcmp(funcName, "vkCreateImageView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005539 return (PFN_vkVoidFunction) vkCreateImageView;
Jon Ashburn0d60d272015-07-09 15:02:25 -06005540 if (!strcmp(funcName, "CreatePipelineCache"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005541 return (PFN_vkVoidFunction) vkCreatePipelineCache;
Jon Ashburn0d60d272015-07-09 15:02:25 -06005542 if (!strcmp(funcName, "DestroyPipelineCache"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005543 return (PFN_vkVoidFunction) vkDestroyPipelineCache;
Jon Ashburn0d60d272015-07-09 15:02:25 -06005544 if (!strcmp(funcName, "GetPipelineCacheData"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005545 return (PFN_vkVoidFunction) vkGetPipelineCacheData;
Jon Ashburn0d60d272015-07-09 15:02:25 -06005546 if (!strcmp(funcName, "MergePipelineCaches"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005547 return (PFN_vkVoidFunction) vkMergePipelineCaches;
Jon Ashburn0d60d272015-07-09 15:02:25 -06005548 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005549 return (PFN_vkVoidFunction) vkCreateGraphicsPipelines;
Mark Lobodzinski2adea752015-11-10 15:25:01 -07005550 if (!strcmp(funcName, "vkCreateComputePipelines"))
5551 return (PFN_vkVoidFunction) vkCreateComputePipelines;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005552 if (!strcmp(funcName, "vkCreateSampler"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005553 return (PFN_vkVoidFunction) vkCreateSampler;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005554 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005555 return (PFN_vkVoidFunction) vkCreateDescriptorSetLayout;
Mark Lobodzinski556f7212015-04-17 14:11:39 -05005556 if (!strcmp(funcName, "vkCreatePipelineLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005557 return (PFN_vkVoidFunction) vkCreatePipelineLayout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005558 if (!strcmp(funcName, "vkCreateDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005559 return (PFN_vkVoidFunction) vkCreateDescriptorPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005560 if (!strcmp(funcName, "vkResetDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005561 return (PFN_vkVoidFunction) vkResetDescriptorPool;
Chia-I Wu1f851912015-10-27 18:04:07 +08005562 if (!strcmp(funcName, "vkAllocateDescriptorSets"))
5563 return (PFN_vkVoidFunction) vkAllocateDescriptorSets;
Tobin Ehlis3c543112015-10-08 13:13:50 -06005564 if (!strcmp(funcName, "vkFreeDescriptorSets"))
5565 return (PFN_vkVoidFunction) vkFreeDescriptorSets;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08005566 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005567 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07005568 if (!strcmp(funcName, "vkCreateCommandPool"))
5569 return (PFN_vkVoidFunction) vkCreateCommandPool;
5570 if (!strcmp(funcName, "vkDestroyCommandPool"))
5571 return (PFN_vkVoidFunction) vkDestroyCommandPool;
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07005572 if (!strcmp(funcName, "vkResetCommandPool"))
5573 return (PFN_vkVoidFunction) vkResetCommandPool;
Chia-I Wu1f851912015-10-27 18:04:07 +08005574 if (!strcmp(funcName, "vkAllocateCommandBuffers"))
5575 return (PFN_vkVoidFunction) vkAllocateCommandBuffers;
Mark Lobodzinskia3b99d82015-11-18 08:38:27 -07005576 if (!strcmp(funcName, "vkFreeCommandBuffers"))
5577 return (PFN_vkVoidFunction) vkFreeCommandBuffers;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005578 if (!strcmp(funcName, "vkBeginCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005579 return (PFN_vkVoidFunction) vkBeginCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005580 if (!strcmp(funcName, "vkEndCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005581 return (PFN_vkVoidFunction) vkEndCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005582 if (!strcmp(funcName, "vkResetCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005583 return (PFN_vkVoidFunction) vkResetCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005584 if (!strcmp(funcName, "vkCmdBindPipeline"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005585 return (PFN_vkVoidFunction) vkCmdBindPipeline;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06005586 if (!strcmp(funcName, "vkCmdSetViewport"))
5587 return (PFN_vkVoidFunction) vkCmdSetViewport;
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06005588 if (!strcmp(funcName, "vkCmdSetScissor"))
5589 return (PFN_vkVoidFunction) vkCmdSetScissor;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06005590 if (!strcmp(funcName, "vkCmdSetLineWidth"))
5591 return (PFN_vkVoidFunction) vkCmdSetLineWidth;
5592 if (!strcmp(funcName, "vkCmdSetDepthBias"))
5593 return (PFN_vkVoidFunction) vkCmdSetDepthBias;
5594 if (!strcmp(funcName, "vkCmdSetBlendConstants"))
5595 return (PFN_vkVoidFunction) vkCmdSetBlendConstants;
5596 if (!strcmp(funcName, "vkCmdSetDepthBounds"))
5597 return (PFN_vkVoidFunction) vkCmdSetDepthBounds;
5598 if (!strcmp(funcName, "vkCmdSetStencilCompareMask"))
5599 return (PFN_vkVoidFunction) vkCmdSetStencilCompareMask;
5600 if (!strcmp(funcName, "vkCmdSetStencilWriteMask"))
5601 return (PFN_vkVoidFunction) vkCmdSetStencilWriteMask;
5602 if (!strcmp(funcName, "vkCmdSetStencilReference"))
5603 return (PFN_vkVoidFunction) vkCmdSetStencilReference;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005604 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005605 return (PFN_vkVoidFunction) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06005606 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005607 return (PFN_vkVoidFunction) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005608 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005609 return (PFN_vkVoidFunction) vkCmdBindIndexBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005610 if (!strcmp(funcName, "vkCmdDraw"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005611 return (PFN_vkVoidFunction) vkCmdDraw;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005612 if (!strcmp(funcName, "vkCmdDrawIndexed"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005613 return (PFN_vkVoidFunction) vkCmdDrawIndexed;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005614 if (!strcmp(funcName, "vkCmdDrawIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005615 return (PFN_vkVoidFunction) vkCmdDrawIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005616 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005617 return (PFN_vkVoidFunction) vkCmdDrawIndexedIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005618 if (!strcmp(funcName, "vkCmdDispatch"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005619 return (PFN_vkVoidFunction) vkCmdDispatch;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005620 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005621 return (PFN_vkVoidFunction) vkCmdDispatchIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005622 if (!strcmp(funcName, "vkCmdCopyBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005623 return (PFN_vkVoidFunction) vkCmdCopyBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005624 if (!strcmp(funcName, "vkCmdCopyImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005625 return (PFN_vkVoidFunction) vkCmdCopyImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005626 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005627 return (PFN_vkVoidFunction) vkCmdCopyBufferToImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005628 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005629 return (PFN_vkVoidFunction) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005630 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005631 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005632 if (!strcmp(funcName, "vkCmdFillBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005633 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005634 if (!strcmp(funcName, "vkCmdClearColorImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005635 return (PFN_vkVoidFunction) vkCmdClearColorImage;
Chris Forbes2951d7d2015-06-22 17:21:59 +12005636 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005637 return (PFN_vkVoidFunction) vkCmdClearDepthStencilImage;
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06005638 if (!strcmp(funcName, "vkCmdClearAttachments"))
5639 return (PFN_vkVoidFunction) vkCmdClearAttachments;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005640 if (!strcmp(funcName, "vkCmdResolveImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005641 return (PFN_vkVoidFunction) vkCmdResolveImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005642 if (!strcmp(funcName, "vkCmdSetEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005643 return (PFN_vkVoidFunction) vkCmdSetEvent;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005644 if (!strcmp(funcName, "vkCmdResetEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005645 return (PFN_vkVoidFunction) vkCmdResetEvent;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005646 if (!strcmp(funcName, "vkCmdWaitEvents"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005647 return (PFN_vkVoidFunction) vkCmdWaitEvents;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005648 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005649 return (PFN_vkVoidFunction) vkCmdPipelineBarrier;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005650 if (!strcmp(funcName, "vkCmdBeginQuery"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005651 return (PFN_vkVoidFunction) vkCmdBeginQuery;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005652 if (!strcmp(funcName, "vkCmdEndQuery"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005653 return (PFN_vkVoidFunction) vkCmdEndQuery;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005654 if (!strcmp(funcName, "vkCmdResetQueryPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005655 return (PFN_vkVoidFunction) vkCmdResetQueryPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005656 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005657 return (PFN_vkVoidFunction) vkCmdWriteTimestamp;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005658 if (!strcmp(funcName, "vkCreateFramebuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005659 return (PFN_vkVoidFunction) vkCreateFramebuffer;
Tobin Ehlis32479352015-12-01 09:48:58 -07005660 if (!strcmp(funcName, "vkCreateShaderModule"))
5661 return (PFN_vkVoidFunction) vkCreateShaderModule;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005662 if (!strcmp(funcName, "vkCreateRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005663 return (PFN_vkVoidFunction) vkCreateRenderPass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005664 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005665 return (PFN_vkVoidFunction) vkCmdBeginRenderPass;
Chia-I Wuc278df82015-07-07 11:50:03 +08005666 if (!strcmp(funcName, "vkCmdNextSubpass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005667 return (PFN_vkVoidFunction) vkCmdNextSubpass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005668 if (!strcmp(funcName, "vkCmdEndRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005669 return (PFN_vkVoidFunction) vkCmdEndRenderPass;
Tobin Ehlis5f728d32015-09-17 14:18:16 -06005670 if (!strcmp(funcName, "vkCmdExecuteCommands"))
5671 return (PFN_vkVoidFunction) vkCmdExecuteCommands;
Michael Lentineee4ad4d2015-10-23 12:41:44 -07005672 if (!strcmp(funcName, "vkMapMemory"))
5673 return (PFN_vkVoidFunction) vkMapMemory;
Jon Ashburn6f8cd632015-06-01 09:37:38 -06005674
Michael Lentine27b0f902015-10-12 11:30:14 -05005675 if (dev_data->device_extensions.wsi_enabled)
5676 {
5677 if (!strcmp(funcName, "vkCreateSwapchainKHR"))
5678 return (PFN_vkVoidFunction) vkCreateSwapchainKHR;
5679 if (!strcmp(funcName, "vkDestroySwapchainKHR"))
5680 return (PFN_vkVoidFunction) vkDestroySwapchainKHR;
5681 if (!strcmp(funcName, "vkGetSwapchainImagesKHR"))
5682 return (PFN_vkVoidFunction) vkGetSwapchainImagesKHR;
5683 if (!strcmp(funcName, "vkQueuePresentKHR"))
5684 return (PFN_vkVoidFunction) vkQueuePresentKHR;
5685 }
5686
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005687 VkLayerDispatchTable* pTable = dev_data->device_dispatch_table;
5688 if (dev_data->device_extensions.debug_marker_enabled)
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005689 {
Jon Ashburn7e07faf2015-06-18 15:02:58 -06005690 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005691 return (PFN_vkVoidFunction) vkCmdDbgMarkerBegin;
Jon Ashburn7e07faf2015-06-18 15:02:58 -06005692 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005693 return (PFN_vkVoidFunction) vkCmdDbgMarkerEnd;
Jon Ashburn6f8cd632015-06-01 09:37:38 -06005694 }
5695 {
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005696 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005697 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005698 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburn79b78ac2015-05-05 14:22:52 -06005699 }
5700}
5701
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +08005702VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06005703{
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005704 PFN_vkVoidFunction fptr;
Jon Ashburn79b78ac2015-05-05 14:22:52 -06005705 if (instance == NULL)
5706 return NULL;
5707
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005708 layer_data* my_data;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005709 /* loader uses this to force layer initialization; instance object is wrapped */
5710 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005711 VkBaseLayerObject* wrapped_inst = (VkBaseLayerObject*) instance;
5712 my_data = get_my_data_ptr(get_dispatch_key(wrapped_inst->baseObject), layer_data_map);
Tobin Ehlisd04ccab2015-10-07 15:40:22 -06005713 my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
5714 layer_init_instance_dispatch_table(my_data->instance_dispatch_table, wrapped_inst);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005715 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005716 }
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06005717 if (!strcmp(funcName, "vkCreateInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005718 return (PFN_vkVoidFunction) vkCreateInstance;
Jon Ashburne0fa2282015-05-20 09:00:28 -06005719 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06005720 return (PFN_vkVoidFunction) vkDestroyInstance;
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -06005721 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
5722 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
5723 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
5724 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
5725 if (!strcmp(funcName, "vkEnumerateDeviceLayerProperties"))
5726 return (PFN_vkVoidFunction) vkEnumerateDeviceLayerProperties;
5727 if (!strcmp(funcName, "vkEnumerateDeviceExtensionProperties"))
5728 return (PFN_vkVoidFunction) vkEnumerateDeviceExtensionProperties;
Courtney Goeltzenleuchtercc899fe2015-06-01 14:33:14 -06005729
Tobin Ehlis32479352015-12-01 09:48:58 -07005730 my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06005731 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchtercc899fe2015-06-01 14:33:14 -06005732 if (fptr)
5733 return fptr;
5734
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005735 {
Tobin Ehlise6ab55a2015-10-07 09:38:40 -06005736 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005737 if (pTable->GetInstanceProcAddr == NULL)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06005738 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06005739 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005740 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06005741}