blob: f4386e9689524aee0efcf017fd264f1c57ca9072 [file] [log] [blame]
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001/*
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002 *
Courtney Goeltzenleuchterfcbe16f2015-10-29 13:50:34 -06003 * Copyright (C) 2015 Valve Corporation
Michael Lentineb6986752015-10-06 14:56:18 -07004 * Copyright (C) 2015 Google, Inc.
Tobin Ehlis10ae8c12015-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 Goeltzenleuchter05559522015-10-30 11:14:30 -060023 *
Tobin Ehlis88452832015-12-03 09:40:56 -070024 * Author: Cody Northrop <cnorthrop@google.com>
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060025 * Author: Michael Lentine <mlentine@google.com>
Tobin Ehlis88452832015-12-03 09:40:56 -070026 * Author: Tobin Ehlis <tobine@google.com>
27 * Author: Chia-I Wu <olv@google.com>
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070028 * Author: Chris Forbes <chrisf@ijw.co.nz>
Mark Lobodzinski78da8cb2015-12-28 15:51:07 -070029 * Author: Mark Lobodzinski <mark@lunarg.com>
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060030 */
31
Mark Lobodzinski78da8cb2015-12-28 15:51:07 -070032// Allow use of STL min and max functions in Windows
33#define NOMINMAX
34
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060035#include <stdio.h>
36#include <stdlib.h>
37#include <string.h>
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070038#include <assert.h>
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060039#include <unordered_map>
Michael Lentineb6986752015-10-06 14:56:18 -070040#include <unordered_set>
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070041#include <map>
42#include <string>
43#include <iostream>
44#include <algorithm>
Mark Lobodzinski39298632015-11-18 08:38:27 -070045#include <list>
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070046#include <spirv.hpp>
Tobin Ehlis88452832015-12-03 09:40:56 -070047#include <set>
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060048
Tobin Ehlisb835d1b2015-07-03 10:34:49 -060049#include "vk_loader_platform.h"
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060050#include "vk_dispatch_table_helper.h"
51#include "vk_struct_string_helper_cpp.h"
Tony Barbour18f71552015-04-22 11:36:22 -060052#if defined(__GNUC__)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060053#pragma GCC diagnostic ignored "-Wwrite-strings"
Tony Barbour18f71552015-04-22 11:36:22 -060054#endif
Tony Barbour18f71552015-04-22 11:36:22 -060055#if defined(__GNUC__)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060056#pragma GCC diagnostic warning "-Wwrite-strings"
Tony Barbour18f71552015-04-22 11:36:22 -060057#endif
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060058#include "vk_struct_size_helper.h"
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060059#include "draw_state.h"
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -060060#include "vk_layer_config.h"
Michael Lentine97eb7462015-11-20 09:48:52 -080061#include "vulkan/vk_debug_marker_layer.h"
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -060062#include "vk_layer_table.h"
63#include "vk_layer_debug_marker_table.h"
64#include "vk_layer_data.h"
65#include "vk_layer_logging.h"
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -060066#include "vk_layer_extension_utils.h"
Tobin Ehlisa1c28562015-10-23 16:00:08 -060067#include "vk_layer_utils.h"
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060068
Mark Lobodzinski31e5f282015-11-30 16:48:53 -070069// This definition controls whether image layout transitions are enabled/disabled.
70// disable until corner cases are fixed
71#define DISABLE_IMAGE_LAYOUT_VALIDATION
72
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070073using std::unordered_map;
74using std::unordered_set;
75
Tobin Ehlisac0ef842015-12-14 13:46:38 -070076// Track command pools and their command buffers
77struct CMD_POOL_INFO {
78 VkCommandPoolCreateFlags createFlags;
79 list<VkCommandBuffer> commandBuffers; // list container of cmd buffers allocated from this pool
80};
81
Tobin Ehlis0b632332015-10-07 09:38:40 -060082struct devExts {
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -070083 VkBool32 debug_marker_enabled;
Michael Lentineabc5e922015-10-12 11:30:14 -050084 VkBool32 wsi_enabled;
85 unordered_map<VkSwapchainKHR, SWAPCHAIN_NODE*> swapchainMap;
Tobin Ehlis0b632332015-10-07 09:38:40 -060086};
87
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070088// fwd decls
89struct shader_module;
90struct render_pass;
91
Cody Northrop55443ef2015-09-28 15:09:32 -060092struct layer_data {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -070093 debug_report_data* report_data;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070094 std::vector<VkDebugReportCallbackEXT> logging_callback;
Tobin Ehlis0b632332015-10-07 09:38:40 -060095 VkLayerDispatchTable* device_dispatch_table;
96 VkLayerInstanceDispatchTable* instance_dispatch_table;
97 devExts device_extensions;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -060098 // Layer specific data
Mark Lobodzinski39298632015-11-18 08:38:27 -070099 unordered_map<VkSampler, unique_ptr<SAMPLER_NODE>> sampleMap;
100 unordered_map<VkImageView, unique_ptr<VkImageViewCreateInfo>> imageViewMap;
101 unordered_map<VkImage, unique_ptr<VkImageCreateInfo>> imageMap;
102 unordered_map<VkBufferView, unique_ptr<VkBufferViewCreateInfo>> bufferViewMap;
103 unordered_map<VkBuffer, unique_ptr<VkBufferCreateInfo>> bufferMap;
104 unordered_map<VkPipeline, PIPELINE_NODE*> pipelineMap;
Tobin Ehlisac0ef842015-12-14 13:46:38 -0700105 unordered_map<VkCommandPool, CMD_POOL_INFO> commandPoolMap;
Mark Lobodzinski39298632015-11-18 08:38:27 -0700106 unordered_map<VkDescriptorPool, DESCRIPTOR_POOL_NODE*> descriptorPoolMap;
107 unordered_map<VkDescriptorSet, SET_NODE*> setMap;
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -0700108 unordered_map<VkDescriptorSetLayout, LAYOUT_NODE*> descriptorSetLayoutMap;
Mark Lobodzinski39298632015-11-18 08:38:27 -0700109 unordered_map<VkPipelineLayout, PIPELINE_LAYOUT_NODE> pipelineLayoutMap;
110 unordered_map<VkDeviceMemory, VkImage> memImageMap;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -0600111 // Map for layout chains
Mark Lobodzinski39298632015-11-18 08:38:27 -0700112 unordered_map<void*, GLOBAL_CB_NODE*> commandBufferMap;
113 unordered_map<VkFramebuffer, VkFramebufferCreateInfo*> frameBufferMap;
114 unordered_map<VkImage, IMAGE_NODE*> imageLayoutMap;
115 unordered_map<VkRenderPass, RENDER_PASS_NODE*> renderPassMap;
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -0700116 unordered_map<VkShaderModule, shader_module*> shaderModuleMap;
Michael Lentineabc5e922015-10-12 11:30:14 -0500117 // Current render pass
118 VkRenderPassBeginInfo renderPassBeginInfo;
119 uint32_t currentSubpass;
Cody Northrop55443ef2015-09-28 15:09:32 -0600120
121 layer_data() :
122 report_data(nullptr),
Tobin Ehlis0b632332015-10-07 09:38:40 -0600123 device_dispatch_table(nullptr),
124 instance_dispatch_table(nullptr),
125 device_extensions()
Cody Northrop55443ef2015-09-28 15:09:32 -0600126 {};
127};
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700128// Code imported from ShaderChecker
129static void
130build_type_def_index(std::vector<unsigned> const &words, std::unordered_map<unsigned, unsigned> &type_def_index);
131
132struct shader_module {
133 /* the spirv image itself */
134 vector<uint32_t> words;
135 /* a mapping of <id> to the first word of its def. this is useful because walking type
136 * trees requires jumping all over the instruction stream.
137 */
138 unordered_map<unsigned, unsigned> type_def_index;
139
140 shader_module(VkShaderModuleCreateInfo const *pCreateInfo) :
141 words((uint32_t *)pCreateInfo->pCode, (uint32_t *)pCreateInfo->pCode + pCreateInfo->codeSize / sizeof(uint32_t)),
142 type_def_index() {
143
144 build_type_def_index(words, type_def_index);
145 }
146};
147
Tobin Ehlisb212dfc2015-10-07 15:40:22 -0600148// TODO : Do we need to guard access to layer_data_map w/ lock?
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -0700149static unordered_map<void*, layer_data*> layer_data_map;
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -0600150
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600151static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
152// TODO : This can be much smarter, using separate locks for separate global data
153static int globalLockInitialized = 0;
154static loader_platform_thread_mutex globalLock;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600155#define MAX_TID 513
156static loader_platform_thread_id g_tidMapping[MAX_TID] = {0};
157static uint32_t g_maxTID = 0;
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600158
159template layer_data *get_my_data_ptr<layer_data>(
160 void *data_key,
161 std::unordered_map<void *, layer_data *> &data_map);
162
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600163// Map actual TID to an index value and return that index
164// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs
165static uint32_t getTIDIndex() {
166 loader_platform_thread_id tid = loader_platform_get_thread_id();
167 for (uint32_t i = 0; i < g_maxTID; i++) {
168 if (tid == g_tidMapping[i])
169 return i;
170 }
171 // Don't yet have mapping, set it and return newly set index
172 uint32_t retVal = (uint32_t) g_maxTID;
173 g_tidMapping[g_maxTID++] = tid;
174 assert(g_maxTID < MAX_TID);
175 return retVal;
176}
Tobin Ehlis559c6382015-11-05 09:52:49 -0700177
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600178// Return a string representation of CMD_TYPE enum
179static string cmdTypeToString(CMD_TYPE cmd)
180{
181 switch (cmd)
182 {
183 case CMD_BINDPIPELINE:
184 return "CMD_BINDPIPELINE";
185 case CMD_BINDPIPELINEDELTA:
186 return "CMD_BINDPIPELINEDELTA";
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600187 case CMD_SETVIEWPORTSTATE:
188 return "CMD_SETVIEWPORTSTATE";
189 case CMD_SETLINEWIDTHSTATE:
190 return "CMD_SETLINEWIDTHSTATE";
191 case CMD_SETDEPTHBIASSTATE:
192 return "CMD_SETDEPTHBIASSTATE";
193 case CMD_SETBLENDSTATE:
194 return "CMD_SETBLENDSTATE";
195 case CMD_SETDEPTHBOUNDSSTATE:
196 return "CMD_SETDEPTHBOUNDSSTATE";
197 case CMD_SETSTENCILREADMASKSTATE:
198 return "CMD_SETSTENCILREADMASKSTATE";
199 case CMD_SETSTENCILWRITEMASKSTATE:
200 return "CMD_SETSTENCILWRITEMASKSTATE";
201 case CMD_SETSTENCILREFERENCESTATE:
202 return "CMD_SETSTENCILREFERENCESTATE";
Tobin Ehlis793ad302015-04-03 12:01:11 -0600203 case CMD_BINDDESCRIPTORSETS:
204 return "CMD_BINDDESCRIPTORSETS";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600205 case CMD_BINDINDEXBUFFER:
206 return "CMD_BINDINDEXBUFFER";
207 case CMD_BINDVERTEXBUFFER:
208 return "CMD_BINDVERTEXBUFFER";
209 case CMD_DRAW:
210 return "CMD_DRAW";
211 case CMD_DRAWINDEXED:
212 return "CMD_DRAWINDEXED";
213 case CMD_DRAWINDIRECT:
214 return "CMD_DRAWINDIRECT";
215 case CMD_DRAWINDEXEDINDIRECT:
216 return "CMD_DRAWINDEXEDINDIRECT";
217 case CMD_DISPATCH:
218 return "CMD_DISPATCH";
219 case CMD_DISPATCHINDIRECT:
220 return "CMD_DISPATCHINDIRECT";
221 case CMD_COPYBUFFER:
222 return "CMD_COPYBUFFER";
223 case CMD_COPYIMAGE:
224 return "CMD_COPYIMAGE";
Tobin Ehlis793ad302015-04-03 12:01:11 -0600225 case CMD_BLITIMAGE:
226 return "CMD_BLITIMAGE";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600227 case CMD_COPYBUFFERTOIMAGE:
228 return "CMD_COPYBUFFERTOIMAGE";
229 case CMD_COPYIMAGETOBUFFER:
230 return "CMD_COPYIMAGETOBUFFER";
231 case CMD_CLONEIMAGEDATA:
232 return "CMD_CLONEIMAGEDATA";
233 case CMD_UPDATEBUFFER:
234 return "CMD_UPDATEBUFFER";
235 case CMD_FILLBUFFER:
236 return "CMD_FILLBUFFER";
237 case CMD_CLEARCOLORIMAGE:
238 return "CMD_CLEARCOLORIMAGE";
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -0600239 case CMD_CLEARATTACHMENTS:
Tobin Ehlis53eddda2015-07-01 16:46:13 -0600240 return "CMD_CLEARCOLORATTACHMENT";
241 case CMD_CLEARDEPTHSTENCILIMAGE:
242 return "CMD_CLEARDEPTHSTENCILIMAGE";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600243 case CMD_RESOLVEIMAGE:
244 return "CMD_RESOLVEIMAGE";
245 case CMD_SETEVENT:
246 return "CMD_SETEVENT";
247 case CMD_RESETEVENT:
248 return "CMD_RESETEVENT";
249 case CMD_WAITEVENTS:
250 return "CMD_WAITEVENTS";
251 case CMD_PIPELINEBARRIER:
252 return "CMD_PIPELINEBARRIER";
253 case CMD_BEGINQUERY:
254 return "CMD_BEGINQUERY";
255 case CMD_ENDQUERY:
256 return "CMD_ENDQUERY";
257 case CMD_RESETQUERYPOOL:
258 return "CMD_RESETQUERYPOOL";
Mark Lobodzinski5495d132015-09-30 16:19:16 -0600259 case CMD_COPYQUERYPOOLRESULTS:
260 return "CMD_COPYQUERYPOOLRESULTS";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600261 case CMD_WRITETIMESTAMP:
262 return "CMD_WRITETIMESTAMP";
263 case CMD_INITATOMICCOUNTERS:
264 return "CMD_INITATOMICCOUNTERS";
265 case CMD_LOADATOMICCOUNTERS:
266 return "CMD_LOADATOMICCOUNTERS";
267 case CMD_SAVEATOMICCOUNTERS:
268 return "CMD_SAVEATOMICCOUNTERS";
269 case CMD_BEGINRENDERPASS:
270 return "CMD_BEGINRENDERPASS";
271 case CMD_ENDRENDERPASS:
272 return "CMD_ENDRENDERPASS";
273 case CMD_DBGMARKERBEGIN:
274 return "CMD_DBGMARKERBEGIN";
275 case CMD_DBGMARKEREND:
276 return "CMD_DBGMARKEREND";
277 default:
278 return "UNKNOWN";
279 }
280}
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700281
282// SPIRV utility functions
283static void
284build_type_def_index(std::vector<unsigned> const &words, std::unordered_map<unsigned, unsigned> &type_def_index)
285{
286 unsigned int const *code = (unsigned int const *)&words[0];
287 size_t size = words.size();
288
289 unsigned word = 5;
290 while (word < size) {
291 unsigned opcode = code[word] & 0x0ffffu;
292 unsigned oplen = (code[word] & 0xffff0000u) >> 16;
293
294 switch (opcode) {
295 case spv::OpTypeVoid:
296 case spv::OpTypeBool:
297 case spv::OpTypeInt:
298 case spv::OpTypeFloat:
299 case spv::OpTypeVector:
300 case spv::OpTypeMatrix:
301 case spv::OpTypeImage:
302 case spv::OpTypeSampler:
303 case spv::OpTypeSampledImage:
304 case spv::OpTypeArray:
305 case spv::OpTypeRuntimeArray:
306 case spv::OpTypeStruct:
307 case spv::OpTypeOpaque:
308 case spv::OpTypePointer:
309 case spv::OpTypeFunction:
310 case spv::OpTypeEvent:
311 case spv::OpTypeDeviceEvent:
312 case spv::OpTypeReserveId:
313 case spv::OpTypeQueue:
314 case spv::OpTypePipe:
315 type_def_index[code[word+1]] = word;
316 break;
317
318 default:
319 /* We only care about type definitions */
320 break;
321 }
322
323 word += oplen;
324 }
325}
326
327bool
328shader_is_spirv(VkShaderModuleCreateInfo const *pCreateInfo)
329{
330 uint32_t *words = (uint32_t *)pCreateInfo->pCode;
331 size_t sizeInWords = pCreateInfo->codeSize / sizeof(uint32_t);
332
333 /* Just validate that the header makes sense. */
334 return sizeInWords >= 5 && words[0] == spv::MagicNumber && words[1] == spv::Version;
335}
336
337static char const *
338storage_class_name(unsigned sc)
339{
340 switch (sc) {
341 case spv::StorageClassInput: return "input";
342 case spv::StorageClassOutput: return "output";
343 case spv::StorageClassUniformConstant: return "const uniform";
344 case spv::StorageClassUniform: return "uniform";
345 case spv::StorageClassWorkgroup: return "workgroup local";
346 case spv::StorageClassCrossWorkgroup: return "workgroup global";
347 case spv::StorageClassPrivate: return "private global";
348 case spv::StorageClassFunction: return "function";
349 case spv::StorageClassGeneric: return "generic";
350 case spv::StorageClassAtomicCounter: return "atomic counter";
351 case spv::StorageClassImage: return "image";
352 default: return "unknown";
353 }
354}
355
356/* returns ptr to null terminator */
357static char *
358describe_type(char *dst, shader_module const *src, unsigned type)
359{
360 auto type_def_it = src->type_def_index.find(type);
361
362 if (type_def_it == src->type_def_index.end()) {
363 return dst + sprintf(dst, "undef");
364 }
365
366 unsigned int const *code = (unsigned int const *)&src->words[type_def_it->second];
367 unsigned opcode = code[0] & 0x0ffffu;
368 switch (opcode) {
369 case spv::OpTypeBool:
370 return dst + sprintf(dst, "bool");
371 case spv::OpTypeInt:
372 return dst + sprintf(dst, "%cint%d", code[3] ? 's' : 'u', code[2]);
373 case spv::OpTypeFloat:
374 return dst + sprintf(dst, "float%d", code[2]);
375 case spv::OpTypeVector:
376 dst += sprintf(dst, "vec%d of ", code[3]);
377 return describe_type(dst, src, code[2]);
378 case spv::OpTypeMatrix:
379 dst += sprintf(dst, "mat%d of ", code[3]);
380 return describe_type(dst, src, code[2]);
381 case spv::OpTypeArray:
382 dst += sprintf(dst, "arr[%d] of ", code[3]);
383 return describe_type(dst, src, code[2]);
384 case spv::OpTypePointer:
385 dst += sprintf(dst, "ptr to %s ", storage_class_name(code[2]));
386 return describe_type(dst, src, code[3]);
387 case spv::OpTypeStruct:
388 {
389 unsigned oplen = code[0] >> 16;
390 dst += sprintf(dst, "struct of (");
391 for (unsigned i = 2; i < oplen; i++) {
392 dst = describe_type(dst, src, code[i]);
393 dst += sprintf(dst, i == oplen-1 ? ")" : ", ");
394 }
395 return dst;
396 }
397 case spv::OpTypeSampler:
398 return dst + sprintf(dst, "sampler");
399 default:
400 return dst + sprintf(dst, "oddtype");
401 }
402}
403
404static bool
405types_match(shader_module const *a, shader_module const *b, unsigned a_type, unsigned b_type, bool b_arrayed)
406{
407 auto a_type_def_it = a->type_def_index.find(a_type);
408 auto b_type_def_it = b->type_def_index.find(b_type);
409
410 if (a_type_def_it == a->type_def_index.end()) {
411 return false;
412 }
413
414 if (b_type_def_it == b->type_def_index.end()) {
415 return false;
416 }
417
418 /* walk two type trees together, and complain about differences */
419 unsigned int const *a_code = (unsigned int const *)&a->words[a_type_def_it->second];
420 unsigned int const *b_code = (unsigned int const *)&b->words[b_type_def_it->second];
421
422 unsigned a_opcode = a_code[0] & 0x0ffffu;
423 unsigned b_opcode = b_code[0] & 0x0ffffu;
424
425 if (b_arrayed && b_opcode == spv::OpTypeArray) {
426 /* we probably just found the extra level of arrayness in b_type: compare the type inside it to a_type */
427 return types_match(a, b, a_type, b_code[2], false);
428 }
429
430 if (a_opcode != b_opcode) {
431 return false;
432 }
433
434 switch (a_opcode) {
435 /* if b_arrayed and we hit a leaf type, then we can't match -- there's nowhere for the extra OpTypeArray to be! */
436 case spv::OpTypeBool:
437 return true && !b_arrayed;
438 case spv::OpTypeInt:
439 /* match on width, signedness */
440 return a_code[2] == b_code[2] && a_code[3] == b_code[3] && !b_arrayed;
441 case spv::OpTypeFloat:
442 /* match on width */
443 return a_code[2] == b_code[2] && !b_arrayed;
444 case spv::OpTypeVector:
445 case spv::OpTypeMatrix:
446 case spv::OpTypeArray:
447 /* match on element type, count. these all have the same layout. we don't get here if
448 * b_arrayed -- that is handled above. */
449 return !b_arrayed && types_match(a, b, a_code[2], b_code[2], b_arrayed) && a_code[3] == b_code[3];
450 case spv::OpTypeStruct:
451 /* match on all element types */
452 {
453 if (b_arrayed) {
454 /* for the purposes of matching different levels of arrayness, structs are leaves. */
455 return false;
456 }
457
458 unsigned a_len = a_code[0] >> 16;
459 unsigned b_len = b_code[0] >> 16;
460
461 if (a_len != b_len) {
462 return false; /* structs cannot match if member counts differ */
463 }
464
465 for (unsigned i = 2; i < a_len; i++) {
466 if (!types_match(a, b, a_code[i], b_code[i], b_arrayed)) {
467 return false;
468 }
469 }
470
471 return true;
472 }
473 case spv::OpTypePointer:
474 /* match on pointee type. storage class is expected to differ */
475 return types_match(a, b, a_code[3], b_code[3], b_arrayed);
476
477 default:
478 /* remaining types are CLisms, or may not appear in the interfaces we
479 * are interested in. Just claim no match.
480 */
481 return false;
482
483 }
484}
485
486static int
487value_or_default(std::unordered_map<unsigned, unsigned> const &map, unsigned id, int def)
488{
489 auto it = map.find(id);
490 if (it == map.end())
491 return def;
492 else
493 return it->second;
494}
495
496
497static unsigned
498get_locations_consumed_by_type(shader_module const *src, unsigned type, bool strip_array_level)
499{
500 auto type_def_it = src->type_def_index.find(type);
501
502 if (type_def_it == src->type_def_index.end()) {
503 return 1; /* This is actually broken SPIR-V... */
504 }
505
506 unsigned int const *code = (unsigned int const *)&src->words[type_def_it->second];
507 unsigned opcode = code[0] & 0x0ffffu;
508
509 switch (opcode) {
510 case spv::OpTypePointer:
511 /* see through the ptr -- this is only ever at the toplevel for graphics shaders;
512 * we're never actually passing pointers around. */
513 return get_locations_consumed_by_type(src, code[3], strip_array_level);
514 case spv::OpTypeArray:
515 if (strip_array_level) {
516 return get_locations_consumed_by_type(src, code[2], false);
517 }
518 else {
519 return code[3] * get_locations_consumed_by_type(src, code[2], false);
520 }
521 case spv::OpTypeMatrix:
522 /* num locations is the dimension * element size */
523 return code[3] * get_locations_consumed_by_type(src, code[2], false);
524 default:
525 /* everything else is just 1. */
526 return 1;
527
528 /* TODO: extend to handle 64bit scalar types, whose vectors may need
529 * multiple locations. */
530 }
531}
532
533
534struct interface_var {
535 uint32_t id;
536 uint32_t type_id;
537 uint32_t offset;
538 /* TODO: collect the name, too? Isn't required to be present. */
539};
540
541static void
542collect_interface_by_location(layer_data *my_data, VkDevice dev,
543 shader_module const *src, spv::StorageClass sinterface,
544 std::map<uint32_t, interface_var> &out,
545 std::map<uint32_t, interface_var> &builtins_out,
546 bool is_array_of_verts)
547{
548 unsigned int const *code = (unsigned int const *)&src->words[0];
549 size_t size = src->words.size();
550
551 std::unordered_map<unsigned, unsigned> var_locations;
552 std::unordered_map<unsigned, unsigned> var_builtins;
553
554 unsigned word = 5;
555 while (word < size) {
556
557 unsigned opcode = code[word] & 0x0ffffu;
558 unsigned oplen = (code[word] & 0xffff0000u) >> 16;
559
560 /* We consider two interface models: SSO rendezvous-by-location, and
561 * builtins. Complain about anything that fits neither model.
562 */
563 if (opcode == spv::OpDecorate) {
564 if (code[word+2] == spv::DecorationLocation) {
565 var_locations[code[word+1]] = code[word+3];
566 }
567
568 if (code[word+2] == spv::DecorationBuiltIn) {
569 var_builtins[code[word+1]] = code[word+3];
570 }
571 }
572
573 /* TODO: handle grouped decorations */
574 /* TODO: handle index=1 dual source outputs from FS -- two vars will
575 * have the same location, and we DONT want to clobber. */
576
577 if (opcode == spv::OpVariable && code[word+3] == sinterface) {
578 unsigned id = code[word+2];
579 unsigned type = code[word+1];
580
581 int location = value_or_default(var_locations, code[word+2], -1);
582 int builtin = value_or_default(var_builtins, code[word+2], -1);
583
584 if (location == -1 && builtin == -1) {
585 /* No location defined, and not bound to an API builtin.
586 * The spec says nothing about how this case works (or doesn't)
587 * for interface matching.
588 */
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700589 log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, 0, SHADER_CHECKER_INCONSISTENT_SPIRV, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700590 "var %d (type %d) in %s interface has no Location or Builtin decoration",
591 code[word+2], code[word+1], storage_class_name(sinterface));
592 }
593 else if (location != -1) {
594 /* A user-defined interface variable, with a location. Where a variable
595 * occupied multiple locations, emit one result for each. */
596 unsigned num_locations = get_locations_consumed_by_type(src, type,
597 is_array_of_verts);
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -0700598 for (unsigned int offset = 0; offset < num_locations; offset++) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700599 interface_var v;
600 v.id = id;
601 v.type_id = type;
602 v.offset = offset;
603 out[location + offset] = v;
604 }
605 }
606 else {
607 /* A builtin interface variable */
608 /* Note that since builtin interface variables do not consume numbered
609 * locations, there is no larger-than-vec4 consideration as above
610 */
611 interface_var v;
612 v.id = id;
613 v.type_id = type;
614 v.offset = 0;
615 builtins_out[builtin] = v;
616 }
617 }
618
619 word += oplen;
620 }
621}
622
623static void
624collect_interface_by_descriptor_slot(layer_data *my_data, VkDevice dev,
625 shader_module const *src, spv::StorageClass sinterface,
626 std::map<std::pair<unsigned, unsigned>, interface_var> &out)
627{
628 unsigned int const *code = (unsigned int const *)&src->words[0];
629 size_t size = src->words.size();
630
631 std::unordered_map<unsigned, unsigned> var_sets;
632 std::unordered_map<unsigned, unsigned> var_bindings;
633
634 unsigned word = 5;
635 while (word < size) {
636
637 unsigned opcode = code[word] & 0x0ffffu;
638 unsigned oplen = (code[word] & 0xffff0000u) >> 16;
639
640 /* All variables in the Uniform or UniformConstant storage classes are required to be decorated with both
641 * DecorationDescriptorSet and DecorationBinding.
642 */
643 if (opcode == spv::OpDecorate) {
644 if (code[word+2] == spv::DecorationDescriptorSet) {
645 var_sets[code[word+1]] = code[word+3];
646 }
647
648 if (code[word+2] == spv::DecorationBinding) {
649 var_bindings[code[word+1]] = code[word+3];
650 }
651 }
652
653 if (opcode == spv::OpVariable && (code[word+3] == spv::StorageClassUniform ||
654 code[word+3] == spv::StorageClassUniformConstant)) {
655 unsigned set = value_or_default(var_sets, code[word+2], 0);
656 unsigned binding = value_or_default(var_bindings, code[word+2], 0);
657
658 auto existing_it = out.find(std::make_pair(set, binding));
659 if (existing_it != out.end()) {
660 /* conflict within spv image */
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700661 log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, 0,
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700662 SHADER_CHECKER_INCONSISTENT_SPIRV, "SC",
663 "var %d (type %d) in %s interface in descriptor slot (%u,%u) conflicts with existing definition",
664 code[word+2], code[word+1], storage_class_name(sinterface),
665 existing_it->first.first, existing_it->first.second);
666 }
667
668 interface_var v;
669 v.id = code[word+2];
670 v.type_id = code[word+1];
671 out[std::make_pair(set, binding)] = v;
672 }
673
674 word += oplen;
675 }
676}
677
678static bool
679validate_interface_between_stages(layer_data *my_data, VkDevice dev,
680 shader_module const *producer, char const *producer_name,
681 shader_module const *consumer, char const *consumer_name,
682 bool consumer_arrayed_input)
683{
684 std::map<uint32_t, interface_var> outputs;
685 std::map<uint32_t, interface_var> inputs;
686
687 std::map<uint32_t, interface_var> builtin_outputs;
688 std::map<uint32_t, interface_var> builtin_inputs;
689
690 bool pass = true;
691
692 collect_interface_by_location(my_data, dev, producer, spv::StorageClassOutput, outputs, builtin_outputs, false);
693 collect_interface_by_location(my_data, dev, consumer, spv::StorageClassInput, inputs, builtin_inputs,
694 consumer_arrayed_input);
695
696 auto a_it = outputs.begin();
697 auto b_it = inputs.begin();
698
699 /* maps sorted by key (location); walk them together to find mismatches */
700 while ((outputs.size() > 0 && a_it != outputs.end()) || ( inputs.size() && b_it != inputs.end())) {
701 bool a_at_end = outputs.size() == 0 || a_it == outputs.end();
702 bool b_at_end = inputs.size() == 0 || b_it == inputs.end();
703 auto a_first = a_at_end ? 0 : a_it->first;
704 auto b_first = b_at_end ? 0 : b_it->first;
705
706 if (b_at_end || ((!a_at_end) && (a_first < b_first))) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700707 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, 0, SHADER_CHECKER_OUTPUT_NOT_CONSUMED, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700708 "%s writes to output location %d which is not consumed by %s", producer_name, a_first, consumer_name)) {
709 pass = false;
710 }
711 a_it++;
712 }
713 else if (a_at_end || a_first > b_first) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700714 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, 0, SHADER_CHECKER_INPUT_NOT_PRODUCED, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700715 "%s consumes input location %d which is not written by %s", consumer_name, b_first, producer_name)) {
716 pass = false;
717 }
718 b_it++;
719 }
720 else {
721 if (types_match(producer, consumer, a_it->second.type_id, b_it->second.type_id, consumer_arrayed_input)) {
722 /* OK! */
723 }
724 else {
725 char producer_type[1024];
726 char consumer_type[1024];
727 describe_type(producer_type, producer, a_it->second.type_id);
728 describe_type(consumer_type, consumer, b_it->second.type_id);
729
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700730 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, 0, SHADER_CHECKER_INTERFACE_TYPE_MISMATCH, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700731 "Type mismatch on location %d: '%s' vs '%s'", a_it->first, producer_type, consumer_type)) {
732 pass = false;
733 }
734 }
735 a_it++;
736 b_it++;
737 }
738 }
739
740 return pass;
741}
742
743enum FORMAT_TYPE {
744 FORMAT_TYPE_UNDEFINED,
745 FORMAT_TYPE_FLOAT, /* UNORM, SNORM, FLOAT, USCALED, SSCALED, SRGB -- anything we consider float in the shader */
746 FORMAT_TYPE_SINT,
747 FORMAT_TYPE_UINT,
748};
749
750static unsigned
751get_format_type(VkFormat fmt) {
752 switch (fmt) {
753 case VK_FORMAT_UNDEFINED:
754 return FORMAT_TYPE_UNDEFINED;
755 case VK_FORMAT_R8_SINT:
756 case VK_FORMAT_R8G8_SINT:
757 case VK_FORMAT_R8G8B8_SINT:
758 case VK_FORMAT_R8G8B8A8_SINT:
759 case VK_FORMAT_R16_SINT:
760 case VK_FORMAT_R16G16_SINT:
761 case VK_FORMAT_R16G16B16_SINT:
762 case VK_FORMAT_R16G16B16A16_SINT:
763 case VK_FORMAT_R32_SINT:
764 case VK_FORMAT_R32G32_SINT:
765 case VK_FORMAT_R32G32B32_SINT:
766 case VK_FORMAT_R32G32B32A32_SINT:
767 case VK_FORMAT_B8G8R8_SINT:
768 case VK_FORMAT_B8G8R8A8_SINT:
769 case VK_FORMAT_A2B10G10R10_SINT_PACK32:
770 case VK_FORMAT_A2R10G10B10_SINT_PACK32:
771 return FORMAT_TYPE_SINT;
772 case VK_FORMAT_R8_UINT:
773 case VK_FORMAT_R8G8_UINT:
774 case VK_FORMAT_R8G8B8_UINT:
775 case VK_FORMAT_R8G8B8A8_UINT:
776 case VK_FORMAT_R16_UINT:
777 case VK_FORMAT_R16G16_UINT:
778 case VK_FORMAT_R16G16B16_UINT:
779 case VK_FORMAT_R16G16B16A16_UINT:
780 case VK_FORMAT_R32_UINT:
781 case VK_FORMAT_R32G32_UINT:
782 case VK_FORMAT_R32G32B32_UINT:
783 case VK_FORMAT_R32G32B32A32_UINT:
784 case VK_FORMAT_B8G8R8_UINT:
785 case VK_FORMAT_B8G8R8A8_UINT:
786 case VK_FORMAT_A2B10G10R10_UINT_PACK32:
787 case VK_FORMAT_A2R10G10B10_UINT_PACK32:
788 return FORMAT_TYPE_UINT;
789 default:
790 return FORMAT_TYPE_FLOAT;
791 }
792}
793
794/* characterizes a SPIR-V type appearing in an interface to a FF stage,
795 * for comparison to a VkFormat's characterization above. */
796static unsigned
797get_fundamental_type(shader_module const *src, unsigned type)
798{
799 auto type_def_it = src->type_def_index.find(type);
800
801 if (type_def_it == src->type_def_index.end()) {
802 return FORMAT_TYPE_UNDEFINED;
803 }
804
805 unsigned int const *code = (unsigned int const *)&src->words[type_def_it->second];
806 unsigned opcode = code[0] & 0x0ffffu;
807 switch (opcode) {
808 case spv::OpTypeInt:
809 return code[3] ? FORMAT_TYPE_SINT : FORMAT_TYPE_UINT;
810 case spv::OpTypeFloat:
811 return FORMAT_TYPE_FLOAT;
812 case spv::OpTypeVector:
813 return get_fundamental_type(src, code[2]);
814 case spv::OpTypeMatrix:
815 return get_fundamental_type(src, code[2]);
816 case spv::OpTypeArray:
817 return get_fundamental_type(src, code[2]);
818 case spv::OpTypePointer:
819 return get_fundamental_type(src, code[3]);
820 default:
821 return FORMAT_TYPE_UNDEFINED;
822 }
823}
824
825static bool
826validate_vi_consistency(layer_data *my_data, VkDevice dev, VkPipelineVertexInputStateCreateInfo const *vi)
827{
828 /* walk the binding descriptions, which describe the step rate and stride of each vertex buffer.
829 * each binding should be specified only once.
830 */
831 std::unordered_map<uint32_t, VkVertexInputBindingDescription const *> bindings;
832 bool pass = true;
833
834 for (unsigned i = 0; i < vi->vertexBindingDescriptionCount; i++) {
835 auto desc = &vi->pVertexBindingDescriptions[i];
836 auto & binding = bindings[desc->binding];
837 if (binding) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700838 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, 0, SHADER_CHECKER_INCONSISTENT_VI, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700839 "Duplicate vertex input binding descriptions for binding %d", desc->binding)) {
840 pass = false;
841 }
842 }
843 else {
844 binding = desc;
845 }
846 }
847
848 return pass;
849}
850
851static bool
852validate_vi_against_vs_inputs(layer_data *my_data, VkDevice dev, VkPipelineVertexInputStateCreateInfo const *vi, shader_module const *vs)
853{
854 std::map<uint32_t, interface_var> inputs;
855 /* we collect builtin inputs, but they will never appear in the VI state --
856 * the vs builtin inputs are generated in the pipeline, not sourced from buffers (VertexID, etc)
857 */
858 std::map<uint32_t, interface_var> builtin_inputs;
859 bool pass = true;
860
861 collect_interface_by_location(my_data, dev, vs, spv::StorageClassInput, inputs, builtin_inputs, false);
862
863 /* Build index by location */
864 std::map<uint32_t, VkVertexInputAttributeDescription const *> attribs;
865 if (vi) {
866 for (unsigned i = 0; i < vi->vertexAttributeDescriptionCount; i++)
867 attribs[vi->pVertexAttributeDescriptions[i].location] = &vi->pVertexAttributeDescriptions[i];
868 }
869
870 auto it_a = attribs.begin();
871 auto it_b = inputs.begin();
872
873 while ((attribs.size() > 0 && it_a != attribs.end()) || (inputs.size() > 0 && it_b != inputs.end())) {
874 bool a_at_end = attribs.size() == 0 || it_a == attribs.end();
875 bool b_at_end = inputs.size() == 0 || it_b == inputs.end();
876 auto a_first = a_at_end ? 0 : it_a->first;
877 auto b_first = b_at_end ? 0 : it_b->first;
878 if (b_at_end || a_first < b_first) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700879 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, 0, SHADER_CHECKER_OUTPUT_NOT_CONSUMED, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700880 "Vertex attribute at location %d not consumed by VS", a_first)) {
881 pass = false;
882 }
883 it_a++;
884 }
885 else if (a_at_end || b_first < a_first) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700886 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, 0, SHADER_CHECKER_INPUT_NOT_PRODUCED, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700887 "VS consumes input at location %d but not provided", b_first)) {
888 pass = false;
889 }
890 it_b++;
891 }
892 else {
893 unsigned attrib_type = get_format_type(it_a->second->format);
894 unsigned input_type = get_fundamental_type(vs, it_b->second.type_id);
895
896 /* type checking */
897 if (attrib_type != FORMAT_TYPE_UNDEFINED && input_type != FORMAT_TYPE_UNDEFINED && attrib_type != input_type) {
898 char vs_type[1024];
899 describe_type(vs_type, vs, it_b->second.type_id);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700900 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, 0, SHADER_CHECKER_INTERFACE_TYPE_MISMATCH, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700901 "Attribute type of `%s` at location %d does not match VS input type of `%s`",
902 string_VkFormat(it_a->second->format), a_first, vs_type)) {
903 pass = false;
904 }
905 }
906
907 /* OK! */
908 it_a++;
909 it_b++;
910 }
911 }
912
913 return pass;
914}
915
916static bool
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -0700917validate_fs_outputs_against_render_pass(layer_data *my_data, VkDevice dev, shader_module const *fs, RENDER_PASS_NODE const *rp, uint32_t subpass)
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700918{
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -0700919 const std::vector<VkFormat> &color_formats = rp->subpassColorFormats[subpass];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700920 std::map<uint32_t, interface_var> outputs;
921 std::map<uint32_t, interface_var> builtin_outputs;
922 bool pass = true;
923
924 /* TODO: dual source blend index (spv::DecIndex, zero if not provided) */
925
926 collect_interface_by_location(my_data, dev, fs, spv::StorageClassOutput, outputs, builtin_outputs, false);
927
928 auto it = outputs.begin();
929 uint32_t attachment = 0;
930
931 /* Walk attachment list and outputs together -- this is a little overpowered since attachments
932 * are currently dense, but the parallel with matching between shader stages is nice.
933 */
934
935 /* TODO: Figure out compile error with cb->attachmentCount */
936 while ((outputs.size() > 0 && it != outputs.end()) || attachment < color_formats.size()) {
937 if (attachment == color_formats.size() || ( it != outputs.end() && it->first < attachment)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700938 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, 0, SHADER_CHECKER_OUTPUT_NOT_CONSUMED, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700939 "FS writes to output location %d with no matching attachment", it->first)) {
940 pass = false;
941 }
942 it++;
943 }
944 else if (it == outputs.end() || it->first > attachment) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700945 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, 0, SHADER_CHECKER_INPUT_NOT_PRODUCED, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700946 "Attachment %d not written by FS", attachment)) {
947 pass = false;
948 }
949 attachment++;
950 }
951 else {
952 unsigned output_type = get_fundamental_type(fs, it->second.type_id);
953 unsigned att_type = get_format_type(color_formats[attachment]);
954
955 /* type checking */
956 if (att_type != FORMAT_TYPE_UNDEFINED && output_type != FORMAT_TYPE_UNDEFINED && att_type != output_type) {
957 char fs_type[1024];
958 describe_type(fs_type, fs, it->second.type_id);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700959 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, 0, SHADER_CHECKER_INTERFACE_TYPE_MISMATCH, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700960 "Attachment %d of type `%s` does not match FS output type of `%s`",
961 attachment, string_VkFormat(color_formats[attachment]), fs_type)) {
962 pass = false;
963 }
964 }
965
966 /* OK! */
967 it++;
968 attachment++;
969 }
970 }
971
972 return pass;
973}
974
975
976struct shader_stage_attributes {
977 char const * const name;
978 bool arrayed_input;
979};
980
981
982static shader_stage_attributes
983shader_stage_attribs[] = {
984 { "vertex shader", false },
985 { "tessellation control shader", true },
986 { "tessellation evaluation shader", false },
987 { "geometry shader", true },
988 { "fragment shader", false },
989};
990
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -0700991// For given pipelineLayout verify that the setLayout at slot.first
992// has the requested binding at slot.second
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700993static bool
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -0700994has_descriptor_binding(layer_data* my_data,
995 vector<VkDescriptorSetLayout>* pipelineLayout,
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700996 std::pair<unsigned, unsigned> slot)
997{
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -0700998 if (!pipelineLayout)
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700999 return false;
1000
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001001 if (slot.first >= pipelineLayout->size())
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001002 return false;
1003
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001004 auto set = my_data->descriptorSetLayoutMap[(*pipelineLayout)[slot.first]]->bindings;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001005
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001006 return (set.find(slot.second) != set.end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001007}
1008
1009static uint32_t get_shader_stage_id(VkShaderStageFlagBits stage)
1010{
1011 uint32_t bit_pos = u_ffs(stage);
1012 return bit_pos-1;
1013}
1014
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001015// Block of code at start here for managing/tracking Pipeline state that this layer cares about
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001016
1017static uint64_t g_drawCount[NUM_DRAW_TYPES] = {0, 0, 0, 0};
1018
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001019// TODO : Should be tracking lastBound per commandBuffer and when draws occur, report based on that cmd buffer lastBound
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001020// Then need to synchronize the accesses based on cmd buffer so that if I'm reading state on one cmd buffer, updates
1021// to that same cmd buffer by separate thread are not changing state from underneath us
1022// Track the last cmd buffer touched by this thread
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001023
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001024#define MAX_BINDING 0xFFFFFFFF // Default vtxBinding value in CB Node to identify if no vtxBinding set
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001025// prototype
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001026static GLOBAL_CB_NODE* getCBNode(layer_data*, const VkCommandBuffer);
Tobin Ehlis559c6382015-11-05 09:52:49 -07001027
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06001028static VkBool32 hasDrawCmd(GLOBAL_CB_NODE* pCB)
Tobin Ehlis53eddda2015-07-01 16:46:13 -06001029{
1030 for (uint32_t i=0; i<NUM_DRAW_TYPES; i++) {
1031 if (pCB->drawCount[i])
1032 return VK_TRUE;
1033 }
1034 return VK_FALSE;
1035}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001036
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001037// Check object status for selected flag state
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001038static 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 Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001039{
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001040 // If non-zero enable mask is present, check it against status but if enable_mask
1041 // is 0 then no enable required so we should always just check status
1042 if ((!enable_mask) || (enable_mask & pNode->status)) {
1043 if ((pNode->status & status_mask) != status_flag) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001044 // TODO : How to pass dispatchable objects as srcObject? Here src obj should be cmd buffer
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001045 return log_msg(my_data->report_data, msg_flags, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, 0, error_code, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001046 "CB object %#" PRIxLEAST64 ": %s", reinterpret_cast<uint64_t>(pNode->commandBuffer), fail_msg);
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001047 }
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001048 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001049 return VK_FALSE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001050}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001051
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001052// Retrieve pipeline node ptr for given pipeline object
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001053static PIPELINE_NODE* getPipeline(layer_data* my_data, const VkPipeline pipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001054{
1055 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08001056 if (my_data->pipelineMap.find(pipeline) == my_data->pipelineMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001057 loader_platform_thread_unlock_mutex(&globalLock);
1058 return NULL;
1059 }
1060 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08001061 return my_data->pipelineMap[pipeline];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001062}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001063
Tobin Ehlisd332f282015-10-02 11:00:56 -06001064// Return VK_TRUE if for a given PSO, the given state enum is dynamic, else return VK_FALSE
1065static VkBool32 isDynamic(const PIPELINE_NODE* pPipeline, const VkDynamicState state)
1066{
1067 if (pPipeline && pPipeline->graphicsPipelineCI.pDynamicState) {
1068 for (uint32_t i=0; i<pPipeline->graphicsPipelineCI.pDynamicState->dynamicStateCount; i++) {
1069 if (state == pPipeline->graphicsPipelineCI.pDynamicState->pDynamicStates[i])
1070 return VK_TRUE;
1071 }
1072 }
1073 return VK_FALSE;
1074}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001075
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001076// Validate state stored as flags at time of draw call
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001077static VkBool32 validate_draw_state_flags(layer_data* my_data, GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06001078 VkBool32 result;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001079 result = validate_status(my_data, pCB, CBSTATUS_NONE, CBSTATUS_VIEWPORT_SET, CBSTATUS_VIEWPORT_SET, VK_DEBUG_REPORT_ERROR_BIT_EXT, DRAWSTATE_VIEWPORT_NOT_BOUND, "Dynamic viewport state not set for this command buffer");
1080 result |= validate_status(my_data, pCB, CBSTATUS_NONE, CBSTATUS_SCISSOR_SET, CBSTATUS_SCISSOR_SET, VK_DEBUG_REPORT_ERROR_BIT_EXT, DRAWSTATE_SCISSOR_NOT_BOUND, "Dynamic scissor state not set for this command buffer");
1081 result |= validate_status(my_data, pCB, CBSTATUS_NONE, CBSTATUS_LINE_WIDTH_SET, CBSTATUS_LINE_WIDTH_SET, VK_DEBUG_REPORT_ERROR_BIT_EXT, DRAWSTATE_LINE_WIDTH_NOT_BOUND, "Dynamic line width state not set for this command buffer");
1082 result |= validate_status(my_data, pCB, CBSTATUS_NONE, CBSTATUS_DEPTH_BIAS_SET, CBSTATUS_DEPTH_BIAS_SET, VK_DEBUG_REPORT_ERROR_BIT_EXT, DRAWSTATE_DEPTH_BIAS_NOT_BOUND, "Dynamic depth bias state not set for this command buffer");
1083 result |= validate_status(my_data, pCB, CBSTATUS_COLOR_BLEND_WRITE_ENABLE, CBSTATUS_BLEND_SET, CBSTATUS_BLEND_SET, VK_DEBUG_REPORT_ERROR_BIT_EXT, DRAWSTATE_BLEND_NOT_BOUND, "Dynamic blend object state not set for this command buffer");
1084 result |= validate_status(my_data, pCB, CBSTATUS_DEPTH_WRITE_ENABLE, CBSTATUS_DEPTH_BOUNDS_SET, CBSTATUS_DEPTH_BOUNDS_SET, VK_DEBUG_REPORT_ERROR_BIT_EXT, DRAWSTATE_DEPTH_BOUNDS_NOT_BOUND, "Dynamic depth bounds state not set for this command buffer");
1085 result |= validate_status(my_data, pCB, CBSTATUS_STENCIL_TEST_ENABLE, CBSTATUS_STENCIL_READ_MASK_SET, CBSTATUS_STENCIL_READ_MASK_SET, VK_DEBUG_REPORT_ERROR_BIT_EXT, DRAWSTATE_STENCIL_NOT_BOUND, "Dynamic stencil read mask state not set for this command buffer");
1086 result |= validate_status(my_data, pCB, CBSTATUS_STENCIL_TEST_ENABLE, CBSTATUS_STENCIL_WRITE_MASK_SET, CBSTATUS_STENCIL_WRITE_MASK_SET, VK_DEBUG_REPORT_ERROR_BIT_EXT, DRAWSTATE_STENCIL_NOT_BOUND, "Dynamic stencil write mask state not set for this command buffer");
1087 result |= validate_status(my_data, pCB, CBSTATUS_STENCIL_TEST_ENABLE, CBSTATUS_STENCIL_REFERENCE_SET, CBSTATUS_STENCIL_REFERENCE_SET, VK_DEBUG_REPORT_ERROR_BIT_EXT, DRAWSTATE_STENCIL_NOT_BOUND, "Dynamic stencil reference state not set for this command buffer");
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001088 if (indexedDraw)
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001089 result |= validate_status(my_data, pCB, CBSTATUS_NONE, CBSTATUS_INDEX_BUFFER_BOUND, CBSTATUS_INDEX_BUFFER_BOUND, VK_DEBUG_REPORT_ERROR_BIT_EXT, DRAWSTATE_INDEX_BUFFER_NOT_BOUND, "Index buffer object not bound to this command buffer when Indexed Draw attempted");
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001090 return result;
1091}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001092
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001093// Verify attachment reference compatibility according to spec
1094// If one array is larger, treat missing elements of shorter array as VK_ATTACHMENT_UNUSED & other array much match this
1095// If both AttachmentReference arrays have requested index, check their corresponding AttachementDescriptions
1096// to make sure that format and samples counts match.
1097// If not, they are not compatible.
1098static bool attachment_references_compatible(const uint32_t index, const VkAttachmentReference* pPrimary, const uint32_t primaryCount, const VkAttachmentDescription* pPrimaryAttachments,
1099 const VkAttachmentReference* pSecondary, const uint32_t secondaryCount, const VkAttachmentDescription* pSecondaryAttachments)
1100{
1101 if (index >= primaryCount) { // Check secondary as if primary is VK_ATTACHMENT_UNUSED
1102 if (VK_ATTACHMENT_UNUSED != pSecondary[index].attachment)
1103 return false;
1104 } else if (index >= secondaryCount) { // Check primary as if secondary is VK_ATTACHMENT_UNUSED
1105 if (VK_ATTACHMENT_UNUSED != pPrimary[index].attachment)
1106 return false;
1107 } else { // format and sample count must match
1108 if ((pPrimaryAttachments[pPrimary[index].attachment].format == pSecondaryAttachments[pSecondary[index].attachment].format) &&
1109 (pPrimaryAttachments[pPrimary[index].attachment].samples == pSecondaryAttachments[pSecondary[index].attachment].samples))
1110 return true;
1111 }
1112 // Format and sample counts didn't match
1113 return false;
1114}
1115
1116// For give primary and secondary RenderPass objects, verify that they're compatible
1117static bool verify_renderpass_compatibility(layer_data* my_data, const VkRenderPass primaryRP, const VkRenderPass secondaryRP, string& errorMsg)
1118{
1119 stringstream errorStr;
1120 if (my_data->renderPassMap.find(primaryRP) == my_data->renderPassMap.end()) {
1121 errorStr << "invalid VkRenderPass (" << primaryRP << ")";
1122 errorMsg = errorStr.str();
1123 return false;
1124 } else if (my_data->renderPassMap.find(secondaryRP) == my_data->renderPassMap.end()) {
1125 errorStr << "invalid VkRenderPass (" << secondaryRP << ")";
1126 errorMsg = errorStr.str();
1127 return false;
1128 }
1129 // Trivial pass case is exact same RP
1130 if (primaryRP == secondaryRP)
1131 return true;
1132 const VkRenderPassCreateInfo* primaryRPCI = my_data->renderPassMap[primaryRP]->pCreateInfo;
1133 const VkRenderPassCreateInfo* secondaryRPCI = my_data->renderPassMap[secondaryRP]->pCreateInfo;
1134 if (primaryRPCI->subpassCount != secondaryRPCI->subpassCount) {
1135 errorStr << "RenderPass for primary cmdBuffer has " << primaryRPCI->subpassCount << " subpasses but renderPass for secondary cmdBuffer has " << secondaryRPCI->subpassCount << " subpasses.";
1136 errorMsg = errorStr.str();
1137 return false;
1138 }
1139 uint32_t spIndex = 0;
1140 for (spIndex = 0; spIndex < primaryRPCI->subpassCount; ++spIndex) {
1141 // For each subpass, verify that corresponding color, input, resolve & depth/stencil attachment references are compatible
1142 uint32_t primaryColorCount = primaryRPCI->pSubpasses[spIndex].colorAttachmentCount;
1143 uint32_t secondaryColorCount = secondaryRPCI->pSubpasses[spIndex].colorAttachmentCount;
1144 uint32_t colorMax = std::max(primaryColorCount, secondaryColorCount);
1145 for (uint32_t cIdx = 0; cIdx < colorMax; ++cIdx) {
1146 if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pColorAttachments, primaryColorCount, primaryRPCI->pAttachments,
1147 secondaryRPCI->pSubpasses[spIndex].pColorAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1148 errorStr << "color attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
1149 errorMsg = errorStr.str();
1150 return false;
1151 } else if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pResolveAttachments, primaryColorCount, primaryRPCI->pAttachments,
1152 secondaryRPCI->pSubpasses[spIndex].pResolveAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1153 errorStr << "resolve attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
1154 errorMsg = errorStr.str();
1155 return false;
1156 } else if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pDepthStencilAttachment, primaryColorCount, primaryRPCI->pAttachments,
1157 secondaryRPCI->pSubpasses[spIndex].pDepthStencilAttachment, secondaryColorCount, secondaryRPCI->pAttachments)) {
1158 errorStr << "depth/stencil attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
1159 errorMsg = errorStr.str();
1160 return false;
1161 }
1162 }
1163 uint32_t primaryInputCount = primaryRPCI->pSubpasses[spIndex].inputAttachmentCount;
1164 uint32_t secondaryInputCount = secondaryRPCI->pSubpasses[spIndex].inputAttachmentCount;
1165 uint32_t inputMax = std::max(primaryInputCount, secondaryInputCount);
1166 for (uint32_t i = 0; i < inputMax; ++i) {
1167 if (!attachment_references_compatible(i, primaryRPCI->pSubpasses[spIndex].pInputAttachments, primaryColorCount, primaryRPCI->pAttachments,
1168 secondaryRPCI->pSubpasses[spIndex].pInputAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1169 errorStr << "input attachments at index " << i << " of subpass index " << spIndex << " are not compatible.";
1170 errorMsg = errorStr.str();
1171 return false;
1172 }
1173 }
1174 }
1175 return true;
1176}
1177
Tobin Ehlis559c6382015-11-05 09:52:49 -07001178// For give SET_NODE, verify that its Set is compatible w/ the setLayout corresponding to pipelineLayout[layoutIndex]
1179static bool verify_set_layout_compatibility(layer_data* my_data, const SET_NODE* pSet, const VkPipelineLayout layout, const uint32_t layoutIndex, string& errorMsg)
1180{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001181 stringstream errorStr;
Tobin Ehlis559c6382015-11-05 09:52:49 -07001182 if (my_data->pipelineLayoutMap.find(layout) == my_data->pipelineLayoutMap.end()) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001183 errorStr << "invalid VkPipelineLayout (" << layout << ")";
1184 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001185 return false;
1186 }
1187 PIPELINE_LAYOUT_NODE pl = my_data->pipelineLayoutMap[layout];
1188 if (layoutIndex >= pl.descriptorSetLayouts.size()) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001189 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;
1190 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001191 return false;
1192 }
1193 // Get the specific setLayout from PipelineLayout that overlaps this set
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001194 LAYOUT_NODE* pLayoutNode = my_data->descriptorSetLayoutMap[pl.descriptorSetLayouts[layoutIndex]];
Tobin Ehlis559c6382015-11-05 09:52:49 -07001195 if (pLayoutNode->layout == pSet->pLayout->layout) { // trivial pass case
1196 return true;
1197 }
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07001198 size_t descriptorCount = pLayoutNode->descriptorTypes.size();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001199 if (descriptorCount != pSet->pLayout->descriptorTypes.size()) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001200 errorStr << "setLayout " << layoutIndex << " from pipelineLayout " << layout << " has " << descriptorCount << " descriptors, but corresponding set being bound has " << pSet->pLayout->descriptorTypes.size() << " descriptors.";
1201 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001202 return false; // trivial fail case
1203 }
1204 // Now need to check set against corresponding pipelineLayout to verify compatibility
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07001205 for (size_t i=0; i<descriptorCount; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07001206 // Need to verify that layouts are identically defined
1207 // TODO : Is below sufficient? Making sure that types & stageFlags match per descriptor
1208 // do we also need to check immutable samplers?
1209 if (pLayoutNode->descriptorTypes[i] != pSet->pLayout->descriptorTypes[i]) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001210 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]) << "'";
1211 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001212 return false;
1213 }
1214 if (pLayoutNode->stageFlags[i] != pSet->pLayout->stageFlags[i]) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001215 errorStr << "stageFlags " << i << " for descriptorSet being bound is " << pSet->pLayout->stageFlags[i] << "' but corresponding descriptor from pipelineLayout has stageFlags " << pLayoutNode->stageFlags[i];
1216 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001217 return false;
1218 }
1219 }
1220 return true;
1221}
1222
Tobin Ehlis88452832015-12-03 09:40:56 -07001223// Validate that the shaders used by the given pipeline
1224// As a side effect this function also records the sets that are actually used by the pipeline
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07001225static VkBool32
Tobin Ehlis88452832015-12-03 09:40:56 -07001226validate_pipeline_shaders(layer_data *my_data, VkDevice dev, PIPELINE_NODE* pPipeline)
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001227{
Tobin Ehlis88452832015-12-03 09:40:56 -07001228 VkGraphicsPipelineCreateInfo const *pCreateInfo = &pPipeline->graphicsPipelineCI;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001229 /* We seem to allow pipeline stages to be specified out of order, so collect and identify them
1230 * before trying to do anything more: */
1231 int vertex_stage = get_shader_stage_id(VK_SHADER_STAGE_VERTEX_BIT);
1232 int geometry_stage = get_shader_stage_id(VK_SHADER_STAGE_GEOMETRY_BIT);
1233 int fragment_stage = get_shader_stage_id(VK_SHADER_STAGE_FRAGMENT_BIT);
1234
1235 shader_module **shaders = new shader_module*[fragment_stage + 1]; /* exclude CS */
1236 memset(shaders, 0, sizeof(shader_module *) * (fragment_stage +1));
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001237 RENDER_PASS_NODE const *rp = 0;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001238 VkPipelineVertexInputStateCreateInfo const *vi = 0;
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07001239 VkBool32 pass = true;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001240
1241 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
1242 VkPipelineShaderStageCreateInfo const *pStage = &pCreateInfo->pStages[i];
1243 if (pStage->sType == VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO) {
1244
1245 if ((pStage->stage & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_GEOMETRY_BIT | VK_SHADER_STAGE_FRAGMENT_BIT
1246 | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT)) == 0) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001247 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, 0, SHADER_CHECKER_UNKNOWN_STAGE, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001248 "Unknown shader stage %d", pStage->stage)) {
1249 pass = false;
1250 }
1251 }
1252 else {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001253 shader_module *module = my_data->shaderModuleMap[pStage->module];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001254 shaders[get_shader_stage_id(pStage->stage)] = module;
1255
1256 /* validate descriptor set layout against what the spirv module actually uses */
1257 std::map<std::pair<unsigned, unsigned>, interface_var> descriptor_uses;
1258 collect_interface_by_descriptor_slot(my_data, dev, module, spv::StorageClassUniform,
1259 descriptor_uses);
1260
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001261 auto layouts = pCreateInfo->layout != VK_NULL_HANDLE ?
1262 &(my_data->pipelineLayoutMap[pCreateInfo->layout].descriptorSetLayouts) : nullptr;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001263
1264 for (auto it = descriptor_uses.begin(); it != descriptor_uses.end(); it++) {
Tobin Ehlis88452832015-12-03 09:40:56 -07001265 // As a side-effect of this function, capture which sets are used by the pipeline
1266 pPipeline->active_sets.insert(it->first.first);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001267
1268 /* find the matching binding */
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001269 auto found = has_descriptor_binding(my_data, layouts, it->first);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001270
1271 if (!found) {
1272 char type_name[1024];
1273 describe_type(type_name, module, it->second.type_id);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001274 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, 0,
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001275 SHADER_CHECKER_MISSING_DESCRIPTOR, "SC",
1276 "Shader uses descriptor slot %u.%u (used as type `%s`) but not declared in pipeline layout",
1277 it->first.first, it->first.second, type_name)) {
1278 pass = false;
1279 }
1280 }
1281 }
1282 }
1283 }
1284 }
1285
1286 if (pCreateInfo->renderPass != VK_NULL_HANDLE)
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001287 rp = my_data->renderPassMap[pCreateInfo->renderPass];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001288
1289 vi = pCreateInfo->pVertexInputState;
1290
1291 if (vi) {
1292 pass = validate_vi_consistency(my_data, dev, vi) && pass;
1293 }
1294
1295 if (shaders[vertex_stage]) {
1296 pass = validate_vi_against_vs_inputs(my_data, dev, vi, shaders[vertex_stage]) && pass;
1297 }
1298
1299 /* TODO: enforce rules about present combinations of shaders */
1300 int producer = get_shader_stage_id(VK_SHADER_STAGE_VERTEX_BIT);
1301 int consumer = get_shader_stage_id(VK_SHADER_STAGE_GEOMETRY_BIT);
1302
1303 while (!shaders[producer] && producer != fragment_stage) {
1304 producer++;
1305 consumer++;
1306 }
1307
1308 for (; producer != fragment_stage && consumer <= fragment_stage; consumer++) {
1309 assert(shaders[producer]);
1310 if (shaders[consumer]) {
1311 pass = validate_interface_between_stages(my_data, dev,
1312 shaders[producer], shader_stage_attribs[producer].name,
1313 shaders[consumer], shader_stage_attribs[consumer].name,
1314 shader_stage_attribs[consumer].arrayed_input) && pass;
1315
1316 producer = consumer;
1317 }
1318 }
1319
1320 if (shaders[fragment_stage] && rp) {
1321 pass = validate_fs_outputs_against_render_pass(my_data, dev, shaders[fragment_stage], rp, pCreateInfo->subpass) && pass;
1322 }
1323
1324 delete shaders;
1325
1326 return pass;
1327}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001328
Tobin Ehlisf6585052015-12-17 11:48:42 -07001329// Return Set node ptr for specified set or else NULL
1330static SET_NODE* getSetNode(layer_data* my_data, const VkDescriptorSet set)
1331{
1332 loader_platform_thread_lock_mutex(&globalLock);
1333 if (my_data->setMap.find(set) == my_data->setMap.end()) {
1334 loader_platform_thread_unlock_mutex(&globalLock);
1335 return NULL;
1336 }
1337 loader_platform_thread_unlock_mutex(&globalLock);
1338 return my_data->setMap[set];
1339}
1340
1341// For the given set, verify that for each dynamic descriptor in that set that its
1342// dynamic offset combined with the offet and range from its descriptor update
1343// do not overflow the size of its buffer being updated
1344static VkBool32 validate_dynamic_offsets(layer_data* my_data, const SET_NODE* pSet)
1345{
1346 VkBool32 result = VK_FALSE;
1347 if (pSet->dynamicOffsets.empty())
1348 return result;
1349
1350 VkWriteDescriptorSet* pWDS = NULL;
1351 uint32_t dynOffsetIndex = 0;
1352 VkDeviceSize bufferSize = 0;
1353 for (uint32_t i=0; i < pSet->descriptorCount; ++i) {
1354 switch (pSet->ppDescriptors[i]->sType) {
1355 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1356 pWDS = (VkWriteDescriptorSet*)pSet->ppDescriptors[i];
1357 if ((pWDS->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
1358 (pWDS->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
1359 for (uint32_t j=0; j<pWDS->descriptorCount; ++j) {
1360 bufferSize = my_data->bufferMap[pWDS->pBufferInfo[j].buffer]->size;
1361 if ((pSet->dynamicOffsets[dynOffsetIndex] + pWDS->pBufferInfo[j].offset + pWDS->pBufferInfo[j].range) > bufferSize) {
1362 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t)pSet->set, 0, DRAWSTATE_DYNAMIC_OFFSET_OVERFLOW, "DS",
1363 "VkDescriptorSet (%#" PRIxLEAST64 ") bound as set #%u has dynamic offset %u. Combined with offet %#" PRIxLEAST64 " and range %#" PRIxLEAST64 " from its update, this oversteps its buffer (%#" PRIxLEAST64 ") which has a size of %#" PRIxLEAST64 ".",
1364 (uint64_t)pSet->set, i, pSet->dynamicOffsets[dynOffsetIndex], pWDS->pBufferInfo[j].offset, pWDS->pBufferInfo[j].range, (uint64_t)pWDS->pBufferInfo[j].buffer, bufferSize);
1365 }
1366 dynOffsetIndex++;
1367 i += j; // Advance i to end of this set of descriptors (++i at end of for loop will move 1 index past last of these descriptors)
1368 }
1369 }
1370 break;
1371 default: // Currently only shadowing Write update nodes so shouldn't get here
1372 assert(0);
1373 continue;
1374 }
1375 }
1376 return result;
1377}
1378
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001379// Validate overall state at the time of a draw call
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001380static VkBool32 validate_draw_state(layer_data* my_data, GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001381 // First check flag states
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001382 VkBool32 result = validate_draw_state_flags(my_data, pCB, indexedDraw);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001383 PIPELINE_NODE* pPipe = getPipeline(my_data, pCB->lastBoundPipeline);
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001384 // Now complete other state checks
Tobin Ehlise90e66d2015-09-09 13:31:01 -06001385 // TODO : Currently only performing next check if *something* was bound (non-zero last bound)
1386 // There is probably a better way to gate when this check happens, and to know if something *should* have been bound
1387 // We should have that check separately and then gate this check based on that check
Mark Lobodzinski74635932015-12-18 15:35:38 -07001388 if (pPipe) {
1389 if (pCB->lastBoundPipelineLayout) {
1390 string errorString;
1391 for (auto setIndex : pPipe->active_sets) {
1392 // If valid set is not bound throw an error
1393 if ((pCB->boundDescriptorSets.size() <= setIndex) || (!pCB->boundDescriptorSets[setIndex])) {
1394 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_DESCRIPTOR_SET_NOT_BOUND, "DS",
1395 "VkPipeline %#" PRIxLEAST64 " uses set #%u but that set is not bound.", (uint64_t)pPipe->pipeline, setIndex);
1396 } else if (!verify_set_layout_compatibility(my_data, my_data->setMap[pCB->boundDescriptorSets[setIndex]], pPipe->graphicsPipelineCI.layout, setIndex, errorString)) {
1397 // Set is bound but not compatible w/ overlapping pipelineLayout from PSO
1398 VkDescriptorSet setHandle = my_data->setMap[pCB->boundDescriptorSets[setIndex]]->set;
1399 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t)setHandle, 0, DRAWSTATE_PIPELINE_LAYOUTS_INCOMPATIBLE, "DS",
1400 "VkDescriptorSet (%#" PRIxLEAST64 ") bound as set #%u is not compatible with overlapping VkPipelineLayout %#" PRIxLEAST64 " due to: %s",
1401 (uint64_t)setHandle, setIndex, (uint64_t)pPipe->graphicsPipelineCI.layout, errorString.c_str());
Tobin Ehlisf6585052015-12-17 11:48:42 -07001402 } else { // Valid set is bound and layout compatible, validate any dynamic offsets
1403 // Pull the set node, and for each dynamic descriptor, make sure dynamic offset doesn't overstep buffer
1404 SET_NODE* pSet = getSetNode(my_data, pCB->boundDescriptorSets[setIndex]);
1405 result |= validate_dynamic_offsets(my_data, pSet);
Mark Lobodzinski74635932015-12-18 15:35:38 -07001406 }
Tobin Ehlis88452832015-12-03 09:40:56 -07001407 }
1408 }
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07001409
Mark Lobodzinski74635932015-12-18 15:35:38 -07001410 // Verify Vtx binding
1411 if (pPipe->vtxBindingCount > 0) {
1412 VkPipelineVertexInputStateCreateInfo *vtxInCI = &pPipe->vertexInputCI;
1413 for (uint32_t i = 0; i < vtxInCI->vertexBindingDescriptionCount; i++) {
1414 if ((pCB->boundVtxBuffers.size() < (i+1)) || (pCB->boundVtxBuffers[i] == VK_NULL_HANDLE)) {
1415 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS",
1416 "The Pipeline State Object (%#" PRIxLEAST64 ") expects that this Command Buffer's vertex binding Index %d should be set via vkCmdBindVertexBuffers.",
1417 (uint64_t)pCB->lastBoundPipeline, i);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001418
Mark Lobodzinski74635932015-12-18 15:35:38 -07001419 }
1420 }
1421 } else {
1422 if (!pCB->boundVtxBuffers.empty()) {
1423 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS,
1424 "DS", "Vertex buffers are bound to command buffer (%#" PRIxLEAST64 ") but no vertex buffers are attached to this Pipeline State Object (%#" PRIxLEAST64 ").",
1425 (uint64_t)pCB->commandBuffer, (uint64_t)pCB->lastBoundPipeline);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06001426 }
1427 }
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07001428
Mark Lobodzinski74635932015-12-18 15:35:38 -07001429 // If Viewport or scissors are dynamic, verify that dynamic count matches PSO count
1430 VkBool32 dynViewport = isDynamic(pPipe, VK_DYNAMIC_STATE_VIEWPORT);
1431 VkBool32 dynScissor = isDynamic(pPipe, VK_DYNAMIC_STATE_SCISSOR);
1432 if (dynViewport) {
1433 if (pCB->viewports.size() != pPipe->graphicsPipelineCI.pViewportState->viewportCount) {
1434 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
1435 "Dynamic viewportCount from vkCmdSetViewport() is " PRINTF_SIZE_T_SPECIFIER ", but PSO viewportCount is %u. These counts must match.", pCB->viewports.size(), pPipe->graphicsPipelineCI.pViewportState->viewportCount);
1436 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001437 }
Mark Lobodzinski74635932015-12-18 15:35:38 -07001438 if (dynScissor) {
1439 if (pCB->scissors.size() != pPipe->graphicsPipelineCI.pViewportState->scissorCount) {
1440 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
1441 "Dynamic scissorCount from vkCmdSetScissor() is " PRINTF_SIZE_T_SPECIFIER ", but PSO scissorCount is %u. These counts must match.", pCB->scissors.size(), pPipe->graphicsPipelineCI.pViewportState->scissorCount);
1442 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001443 }
1444 }
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001445 return result;
1446}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001447
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001448// Verify that create state for a pipeline is valid
Tobin Ehlis88452832015-12-03 09:40:56 -07001449static VkBool32 verifyPipelineCreateState(layer_data* my_data, const VkDevice device, PIPELINE_NODE* pPipeline)
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001450{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001451 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski2fd2d032015-12-16 14:25:22 -07001452
Tobin Ehlis88452832015-12-03 09:40:56 -07001453 if (!validate_pipeline_shaders(my_data, device, pPipeline)) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001454 skipCall = VK_TRUE;
1455 }
Mark Lobodzinski2fd2d032015-12-16 14:25:22 -07001456
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001457 // VS is required
1458 if (!(pPipeline->active_shaders & VK_SHADER_STAGE_VERTEX_BIT)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001459 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001460 "Invalid Pipeline CreateInfo State: Vtx Shader required");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001461 }
1462 // Either both or neither TC/TE shaders should be defined
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001463 if (((pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) == 0) !=
1464 ((pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) == 0) ) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001465 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001466 "Invalid Pipeline CreateInfo State: TE and TC shaders must be included or excluded as a pair");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001467 }
1468 // Compute shaders should be specified independent of Gfx shaders
1469 if ((pPipeline->active_shaders & VK_SHADER_STAGE_COMPUTE_BIT) &&
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001470 (pPipeline->active_shaders & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT |
1471 VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT | VK_SHADER_STAGE_GEOMETRY_BIT |
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001472 VK_SHADER_STAGE_FRAGMENT_BIT))) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001473 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001474 "Invalid Pipeline CreateInfo State: Do not specify Compute Shader for Gfx Pipeline");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001475 }
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001476 // VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology is only valid for tessellation pipelines.
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001477 // Mismatching primitive topology and tessellation fails graphics pipeline creation.
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001478 if (pPipeline->active_shaders & (VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) &&
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001479 (pPipeline->iaStateCI.topology != VK_PRIMITIVE_TOPOLOGY_PATCH_LIST)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001480 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001481 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH_LIST must be set as IA topology for tessellation pipelines");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001482 }
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001483 if (pPipeline->iaStateCI.topology == VK_PRIMITIVE_TOPOLOGY_PATCH_LIST) {
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001484 if (~pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001485 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001486 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology is only valid for tessellation pipelines");
Tobin Ehlis912df022015-09-17 08:46:18 -06001487 }
1488 if (!pPipeline->tessStateCI.patchControlPoints || (pPipeline->tessStateCI.patchControlPoints > 32)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001489 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001490 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology used with patchControlPoints value %u."
Tobin Ehlis912df022015-09-17 08:46:18 -06001491 " patchControlPoints should be >0 and <=32.", pPipeline->tessStateCI.patchControlPoints);
1492 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001493 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001494 // Viewport state must be included and viewport and scissor counts should always match
Tobin Ehlise68360f2015-10-01 11:15:13 -06001495 // NOTE : Even if these are flagged as dynamic, counts need to be set correctly for shader compiler
Tobin Ehlisd332f282015-10-02 11:00:56 -06001496 if (!pPipeline->graphicsPipelineCI.pViewportState) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001497 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
Tobin Ehlisd332f282015-10-02 11:00:56 -06001498 "Gfx Pipeline pViewportState is null. Even if viewport and scissors are dynamic PSO must include viewportCount and scissorCount in pViewportState.");
1499 } else if (pPipeline->graphicsPipelineCI.pViewportState->scissorCount != pPipeline->graphicsPipelineCI.pViewportState->viewportCount) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001500 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
Tobin Ehlise68360f2015-10-01 11:15:13 -06001501 "Gfx Pipeline viewport count (%u) must match scissor count (%u).", pPipeline->vpStateCI.viewportCount, pPipeline->vpStateCI.scissorCount);
Tobin Ehlisd332f282015-10-02 11:00:56 -06001502 } else {
1503 // If viewport or scissor are not dynamic, then verify that data is appropriate for count
1504 VkBool32 dynViewport = isDynamic(pPipeline, VK_DYNAMIC_STATE_VIEWPORT);
1505 VkBool32 dynScissor = isDynamic(pPipeline, VK_DYNAMIC_STATE_SCISSOR);
1506 if (!dynViewport) {
1507 if (pPipeline->graphicsPipelineCI.pViewportState->viewportCount && !pPipeline->graphicsPipelineCI.pViewportState->pViewports) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001508 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
Courtney Goeltzenleuchterb19042e2015-11-25 11:38:54 -07001509 "Gfx Pipeline viewportCount is %u, but pViewports is NULL. For non-zero viewportCount, you must either include pViewports data, or include viewport in pDynamicState and set it with vkCmdSetViewport().", pPipeline->graphicsPipelineCI.pViewportState->viewportCount);
Tobin Ehlise68360f2015-10-01 11:15:13 -06001510 }
1511 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001512 if (!dynScissor) {
1513 if (pPipeline->graphicsPipelineCI.pViewportState->scissorCount && !pPipeline->graphicsPipelineCI.pViewportState->pScissors) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001514 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
Courtney Goeltzenleuchterb19042e2015-11-25 11:38:54 -07001515 "Gfx Pipeline scissorCount is %u, but pScissors is NULL. For non-zero scissorCount, you must either include pScissors data, or include scissor in pDynamicState and set it with vkCmdSetScissor().", pPipeline->graphicsPipelineCI.pViewportState->scissorCount);
Tobin Ehlisd332f282015-10-02 11:00:56 -06001516 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06001517 }
1518 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001519 return skipCall;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001520}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001521
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001522// Init the pipeline mapping info based on pipeline create info LL tree
1523// Threading note : Calls to this function should wrapped in mutex
Tobin Ehlis88452832015-12-03 09:40:56 -07001524// TODO : this should really just be in the constructor for PIPELINE_NODE
Mark Lobodzinski475a2182015-11-10 15:25:01 -07001525static PIPELINE_NODE* initGraphicsPipeline(layer_data* dev_data, const VkGraphicsPipelineCreateInfo* pCreateInfo, PIPELINE_NODE* pBasePipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001526{
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001527 PIPELINE_NODE* pPipeline = new PIPELINE_NODE;
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001528
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001529 if (pBasePipeline) {
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001530 *pPipeline = *pBasePipeline;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001531 }
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001532
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001533 // First init create info
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001534 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001535
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001536 size_t bufferSize = 0;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001537 const VkPipelineVertexInputStateCreateInfo* pVICI = NULL;
Tobin Ehlis5a65cca2015-07-13 13:14:24 -06001538 const VkPipelineColorBlendStateCreateInfo* pCBCI = NULL;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001539
1540 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
1541 const VkPipelineShaderStageCreateInfo *pPSSCI = &pCreateInfo->pStages[i];
1542
Chia-I Wu28e06912015-10-31 00:31:16 +08001543 switch (pPSSCI->stage) {
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001544 case VK_SHADER_STAGE_VERTEX_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001545 memcpy(&pPipeline->vsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1546 pPipeline->active_shaders |= VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001547 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001548 case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001549 memcpy(&pPipeline->tcsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001550 pPipeline->active_shaders |= VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001551 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001552 case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001553 memcpy(&pPipeline->tesCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001554 pPipeline->active_shaders |= VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001555 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001556 case VK_SHADER_STAGE_GEOMETRY_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001557 memcpy(&pPipeline->gsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1558 pPipeline->active_shaders |= VK_SHADER_STAGE_GEOMETRY_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001559 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001560 case VK_SHADER_STAGE_FRAGMENT_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001561 memcpy(&pPipeline->fsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1562 pPipeline->active_shaders |= VK_SHADER_STAGE_FRAGMENT_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001563 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001564 case VK_SHADER_STAGE_COMPUTE_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001565 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
1566 pPipeline->active_shaders |= VK_SHADER_STAGE_COMPUTE_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001567 break;
1568 default:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001569 // TODO : Flag error
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001570 break;
1571 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001572 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001573 // Copy over GraphicsPipelineCreateInfo structure embedded pointers
1574 if (pCreateInfo->stageCount != 0) {
1575 pPipeline->graphicsPipelineCI.pStages = new VkPipelineShaderStageCreateInfo[pCreateInfo->stageCount];
1576 bufferSize = pCreateInfo->stageCount * sizeof(VkPipelineShaderStageCreateInfo);
1577 memcpy((void*)pPipeline->graphicsPipelineCI.pStages, pCreateInfo->pStages, bufferSize);
1578 }
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001579 if (pCreateInfo->pVertexInputState != NULL) {
1580 memcpy((void*)&pPipeline->vertexInputCI, pCreateInfo->pVertexInputState , sizeof(VkPipelineVertexInputStateCreateInfo));
1581 // Copy embedded ptrs
1582 pVICI = pCreateInfo->pVertexInputState;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001583 pPipeline->vtxBindingCount = pVICI->vertexBindingDescriptionCount;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001584 if (pPipeline->vtxBindingCount) {
1585 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
1586 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
1587 memcpy((void*)pPipeline->pVertexBindingDescriptions, pVICI->pVertexBindingDescriptions, bufferSize);
1588 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08001589 pPipeline->vtxAttributeCount = pVICI->vertexAttributeDescriptionCount;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001590 if (pPipeline->vtxAttributeCount) {
1591 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
1592 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
1593 memcpy((void*)pPipeline->pVertexAttributeDescriptions, pVICI->pVertexAttributeDescriptions, bufferSize);
1594 }
1595 pPipeline->graphicsPipelineCI.pVertexInputState = &pPipeline->vertexInputCI;
1596 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001597 if (pCreateInfo->pInputAssemblyState != NULL) {
1598 memcpy((void*)&pPipeline->iaStateCI, pCreateInfo->pInputAssemblyState, sizeof(VkPipelineInputAssemblyStateCreateInfo));
1599 pPipeline->graphicsPipelineCI.pInputAssemblyState = &pPipeline->iaStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001600 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001601 if (pCreateInfo->pTessellationState != NULL) {
1602 memcpy((void*)&pPipeline->tessStateCI, pCreateInfo->pTessellationState, sizeof(VkPipelineTessellationStateCreateInfo));
1603 pPipeline->graphicsPipelineCI.pTessellationState = &pPipeline->tessStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001604 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001605 if (pCreateInfo->pViewportState != NULL) {
1606 memcpy((void*)&pPipeline->vpStateCI, pCreateInfo->pViewportState, sizeof(VkPipelineViewportStateCreateInfo));
1607 pPipeline->graphicsPipelineCI.pViewportState = &pPipeline->vpStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001608 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001609 if (pCreateInfo->pRasterizationState != NULL) {
1610 memcpy((void*)&pPipeline->rsStateCI, pCreateInfo->pRasterizationState, sizeof(VkPipelineRasterizationStateCreateInfo));
1611 pPipeline->graphicsPipelineCI.pRasterizationState = &pPipeline->rsStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001612 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001613 if (pCreateInfo->pMultisampleState != NULL) {
1614 memcpy((void*)&pPipeline->msStateCI, pCreateInfo->pMultisampleState, sizeof(VkPipelineMultisampleStateCreateInfo));
1615 pPipeline->graphicsPipelineCI.pMultisampleState = &pPipeline->msStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001616 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001617 if (pCreateInfo->pDepthStencilState != NULL) {
1618 memcpy((void*)&pPipeline->dsStateCI, pCreateInfo->pDepthStencilState, sizeof(VkPipelineDepthStencilStateCreateInfo));
1619 pPipeline->graphicsPipelineCI.pDepthStencilState = &pPipeline->dsStateCI;
1620 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001621 if (pCreateInfo->pColorBlendState != NULL) {
1622 memcpy((void*)&pPipeline->cbStateCI, pCreateInfo->pColorBlendState, sizeof(VkPipelineColorBlendStateCreateInfo));
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001623 // Copy embedded ptrs
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001624 pCBCI = pCreateInfo->pColorBlendState;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001625 pPipeline->attachmentCount = pCBCI->attachmentCount;
1626 if (pPipeline->attachmentCount) {
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001627 pPipeline->pAttachments = new VkPipelineColorBlendAttachmentState[pPipeline->attachmentCount];
1628 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineColorBlendAttachmentState);
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001629 memcpy((void*)pPipeline->pAttachments, pCBCI->pAttachments, bufferSize);
1630 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001631 pPipeline->graphicsPipelineCI.pColorBlendState = &pPipeline->cbStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001632 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001633 if (pCreateInfo->pDynamicState != NULL) {
1634 memcpy((void*)&pPipeline->dynStateCI, pCreateInfo->pDynamicState, sizeof(VkPipelineDynamicStateCreateInfo));
1635 if (pPipeline->dynStateCI.dynamicStateCount) {
1636 pPipeline->dynStateCI.pDynamicStates = new VkDynamicState[pPipeline->dynStateCI.dynamicStateCount];
1637 bufferSize = pPipeline->dynStateCI.dynamicStateCount * sizeof(VkDynamicState);
1638 memcpy((void*)pPipeline->dynStateCI.pDynamicStates, pCreateInfo->pDynamicState->pDynamicStates, bufferSize);
1639 }
1640 pPipeline->graphicsPipelineCI.pDynamicState = &pPipeline->dynStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001641 }
Tobin Ehlis88452832015-12-03 09:40:56 -07001642 pPipeline->active_sets.clear();
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001643 return pPipeline;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001644}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001645
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001646// Free the Pipeline nodes
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001647static void deletePipelines(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001648{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001649 if (my_data->pipelineMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06001650 return;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001651 for (auto ii=my_data->pipelineMap.begin(); ii!=my_data->pipelineMap.end(); ++ii) {
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001652 if ((*ii).second->graphicsPipelineCI.stageCount != 0) {
1653 delete[] (*ii).second->graphicsPipelineCI.pStages;
1654 }
Tobin Ehlisf313c8b2015-04-01 11:59:08 -06001655 if ((*ii).second->pVertexBindingDescriptions) {
1656 delete[] (*ii).second->pVertexBindingDescriptions;
1657 }
1658 if ((*ii).second->pVertexAttributeDescriptions) {
1659 delete[] (*ii).second->pVertexAttributeDescriptions;
1660 }
1661 if ((*ii).second->pAttachments) {
1662 delete[] (*ii).second->pAttachments;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001663 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001664 if ((*ii).second->dynStateCI.dynamicStateCount != 0) {
1665 delete[] (*ii).second->dynStateCI.pDynamicStates;
1666 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001667 delete (*ii).second;
1668 }
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001669 my_data->pipelineMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001670}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001671
Tobin Ehliseba312c2015-04-01 08:40:34 -06001672// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Chia-I Wu5c17c962015-10-31 00:31:16 +08001673static VkSampleCountFlagBits getNumSamples(layer_data* my_data, const VkPipeline pipeline)
Tobin Ehliseba312c2015-04-01 08:40:34 -06001674{
Chia-I Wue2fc5522015-10-26 20:04:44 +08001675 PIPELINE_NODE* pPipe = my_data->pipelineMap[pipeline];
Tobin Ehlis577188e2015-07-13 14:51:15 -06001676 if (VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001677 return pPipe->msStateCI.rasterizationSamples;
Tobin Ehlis577188e2015-07-13 14:51:15 -06001678 }
Chia-I Wu5c17c962015-10-31 00:31:16 +08001679 return VK_SAMPLE_COUNT_1_BIT;
Tobin Ehliseba312c2015-04-01 08:40:34 -06001680}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001681
Tobin Ehliseba312c2015-04-01 08:40:34 -06001682// Validate state related to the PSO
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001683static VkBool32 validatePipelineState(layer_data* my_data, const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehliseba312c2015-04-01 08:40:34 -06001684{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001685 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06001686 // Verify that any MSAA request in PSO matches sample# in bound FB
Chia-I Wu5c17c962015-10-31 00:31:16 +08001687 VkSampleCountFlagBits psoNumSamples = getNumSamples(my_data, pipeline);
Tobin Ehliseba312c2015-04-01 08:40:34 -06001688 if (pCB->activeRenderPass) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001689 const VkRenderPassCreateInfo* pRPCI = my_data->renderPassMap[pCB->activeRenderPass]->pCreateInfo;
Chia-I Wu08accc62015-07-07 11:50:03 +08001690 const VkSubpassDescription* pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
Chia-I Wu5c17c962015-10-31 00:31:16 +08001691 VkSampleCountFlagBits subpassNumSamples = (VkSampleCountFlagBits) 0;
Chia-I Wu08accc62015-07-07 11:50:03 +08001692 uint32_t i;
1693
Chia-I Wud50a7d72015-10-26 20:48:51 +08001694 for (i = 0; i < pSD->colorAttachmentCount; i++) {
Chia-I Wu5c17c962015-10-31 00:31:16 +08001695 VkSampleCountFlagBits samples;
Chia-I Wu08accc62015-07-07 11:50:03 +08001696
Cody Northropa505dda2015-08-04 11:16:41 -06001697 if (pSD->pColorAttachments[i].attachment == VK_ATTACHMENT_UNUSED)
Chia-I Wu08accc62015-07-07 11:50:03 +08001698 continue;
1699
Cody Northropa505dda2015-08-04 11:16:41 -06001700 samples = pRPCI->pAttachments[pSD->pColorAttachments[i].attachment].samples;
Chia-I Wu5c17c962015-10-31 00:31:16 +08001701 if (subpassNumSamples == (VkSampleCountFlagBits) 0) {
Chia-I Wu08accc62015-07-07 11:50:03 +08001702 subpassNumSamples = samples;
1703 } else if (subpassNumSamples != samples) {
Chia-I Wu5c17c962015-10-31 00:31:16 +08001704 subpassNumSamples = (VkSampleCountFlagBits) -1;
Chia-I Wu08accc62015-07-07 11:50:03 +08001705 break;
1706 }
1707 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08001708 if (pSD->pDepthStencilAttachment && pSD->pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
Chia-I Wu5c17c962015-10-31 00:31:16 +08001709 const VkSampleCountFlagBits samples = pRPCI->pAttachments[pSD->pDepthStencilAttachment->attachment].samples;
1710 if (subpassNumSamples == (VkSampleCountFlagBits) 0)
Chia-I Wu08accc62015-07-07 11:50:03 +08001711 subpassNumSamples = samples;
1712 else if (subpassNumSamples != samples)
Chia-I Wu5c17c962015-10-31 00:31:16 +08001713 subpassNumSamples = (VkSampleCountFlagBits) -1;
Chia-I Wu08accc62015-07-07 11:50:03 +08001714 }
1715
1716 if (psoNumSamples != subpassNumSamples) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001717 return log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, (uint64_t) pipeline, 0, DRAWSTATE_NUM_SAMPLES_MISMATCH, "DS",
Mark Lobodzinski5495d132015-09-30 16:19:16 -06001718 "Num samples mismatch! Binding PSO (%#" PRIxLEAST64 ") with %u samples while current RenderPass (%#" PRIxLEAST64 ") w/ %u samples!",
Chia-I Wue2fc5522015-10-26 20:04:44 +08001719 (uint64_t) pipeline, psoNumSamples, (uint64_t) pCB->activeRenderPass, subpassNumSamples);
Tobin Ehliseba312c2015-04-01 08:40:34 -06001720 }
1721 } else {
1722 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
1723 // Verify and flag error as appropriate
1724 }
1725 // TODO : Add more checks here
1726 } else {
1727 // TODO : Validate non-gfx pipeline updates
1728 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001729 return VK_FALSE;
Tobin Ehliseba312c2015-04-01 08:40:34 -06001730}
1731
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001732// Block of code at start here specifically for managing/tracking DSs
1733
Tobin Ehlis793ad302015-04-03 12:01:11 -06001734// Return Pool node ptr for specified pool or else NULL
Mark Lobodzinski39298632015-11-18 08:38:27 -07001735static DESCRIPTOR_POOL_NODE* getPoolNode(layer_data* my_data, const VkDescriptorPool pool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001736{
1737 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07001738 if (my_data->descriptorPoolMap.find(pool) == my_data->descriptorPoolMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001739 loader_platform_thread_unlock_mutex(&globalLock);
1740 return NULL;
1741 }
1742 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07001743 return my_data->descriptorPoolMap[pool];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001744}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001745
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001746static LAYOUT_NODE* getLayoutNode(layer_data* my_data, const VkDescriptorSetLayout layout) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001747 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001748 if (my_data->descriptorSetLayoutMap.find(layout) == my_data->descriptorSetLayoutMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001749 loader_platform_thread_unlock_mutex(&globalLock);
1750 return NULL;
1751 }
1752 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001753 return my_data->descriptorSetLayoutMap[layout];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001754}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001755
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001756// Return VK_FALSE if update struct is of valid type, otherwise flag error and return code from callback
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001757static VkBool32 validUpdateStruct(layer_data* my_data, const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001758{
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001759 switch (pUpdateStruct->sType)
1760 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001761 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1762 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001763 return VK_FALSE;
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001764 default:
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001765 return log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001766 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001767 }
1768}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001769
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001770// Set count for given update struct in the last parameter
Courtney Goeltzenleuchter085f8dd2015-12-16 16:08:44 -07001771// Return value of skipCall, which is only VK_TRUE if error occurs and callback signals execution to cease
Tobin Ehlisbaca3ab2015-10-27 12:54:50 -06001772static uint32_t getUpdateCount(layer_data* my_data, const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis793ad302015-04-03 12:01:11 -06001773{
1774 switch (pUpdateStruct->sType)
1775 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001776 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
Chia-I Wud50a7d72015-10-26 20:48:51 +08001777 return ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorCount;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001778 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis793ad302015-04-03 12:01:11 -06001779 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wud50a7d72015-10-26 20:48:51 +08001780 return ((VkCopyDescriptorSet*)pUpdateStruct)->descriptorCount;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001781 }
Courtney Goeltzenleuchter7f47bca2015-12-16 16:08:08 -07001782
1783 return 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001784}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001785
Tobin Ehlis793ad302015-04-03 12:01:11 -06001786// For given Layout Node and binding, return index where that binding begins
1787static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
1788{
1789 uint32_t offsetIndex = 0;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001790 for (uint32_t i = 0; i < pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001791 if (pLayout->createInfo.pBindings[i].binding == binding)
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001792 break;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001793 offsetIndex += pLayout->createInfo.pBindings[i].descriptorCount;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001794 }
1795 return offsetIndex;
1796}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001797
Tobin Ehlis793ad302015-04-03 12:01:11 -06001798// For given layout node and binding, return last index that is updated
1799static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
1800{
1801 uint32_t offsetIndex = 0;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001802 for (uint32_t i = 0; i < pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001803 offsetIndex += pLayout->createInfo.pBindings[i].descriptorCount;
1804 if (pLayout->createInfo.pBindings[i].binding == binding)
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001805 break;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001806 }
1807 return offsetIndex-1;
1808}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001809
Tobin Ehlisbaca3ab2015-10-27 12:54:50 -06001810// For given layout and update, return the first overall index of the layout that is updated
Tobin Ehlis8a62e632015-10-27 15:43:38 -06001811static 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 Ehlis793ad302015-04-03 12:01:11 -06001812{
Tobin Ehlisbaca3ab2015-10-27 12:54:50 -06001813 return getBindingStartIndex(pLayout, binding)+arrayIndex;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001814}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001815
Tobin Ehlis8a62e632015-10-27 15:43:38 -06001816// For given layout and update, return the last overall index of the layout that is updated
1817static 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 Ehlis793ad302015-04-03 12:01:11 -06001818{
Tobin Ehlis8a62e632015-10-27 15:43:38 -06001819 uint32_t count = getUpdateCount(my_data, device, pUpdateStruct);
Tobin Ehlisbaca3ab2015-10-27 12:54:50 -06001820 return getBindingStartIndex(pLayout, binding)+arrayIndex+count-1;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001821}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001822
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001823// Verify that the descriptor type in the update struct matches what's expected by the layout
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001824static VkBool32 validateUpdateConsistency(layer_data* my_data, const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct, uint32_t startIndex, uint32_t endIndex)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001825{
1826 // First get actual type of update
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001827 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001828 VkDescriptorType actualType;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001829 uint32_t i = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001830 switch (pUpdateStruct->sType)
1831 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001832 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1833 actualType = ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorType;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001834 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001835 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
1836 /* no need to validate */
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001837 return VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001838 break;
1839 default:
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001840 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001841 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001842 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001843 if (VK_FALSE == skipCall) {
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001844 // Set first stageFlags as reference and verify that all other updates match it
1845 VkShaderStageFlags refStageFlags = pLayout->stageFlags[startIndex];
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001846 for (i = startIndex; i <= endIndex; i++) {
Tobin Ehlis644ff042015-10-20 10:11:55 -06001847 if (pLayout->descriptorTypes[i] != actualType) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001848 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, "DS",
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001849 "Write descriptor update has descriptor type %s that does not match overlapping binding descriptor type of %s!",
1850 string_VkDescriptorType(actualType), string_VkDescriptorType(pLayout->descriptorTypes[i]));
1851 }
1852 if (pLayout->stageFlags[i] != refStageFlags) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001853 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_DESCRIPTOR_STAGEFLAGS_MISMATCH, "DS",
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001854 "Write descriptor update has stageFlags %x that do not match overlapping binding descriptor stageFlags of %x!",
1855 refStageFlags, pLayout->stageFlags[i]);
Tobin Ehlis483cc352015-09-30 08:30:20 -06001856 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001857 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001858 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001859 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001860}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001861
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001862// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001863// struct into the pNewNode param. Return VK_TRUE if error condition encountered and callback signals early exit.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001864// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001865static VkBool32 shadowUpdateNode(layer_data* my_data, const VkDevice device, GENERIC_HEADER* pUpdate, GENERIC_HEADER** pNewNode)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001866{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001867 VkBool32 skipCall = VK_FALSE;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001868 VkWriteDescriptorSet* pWDS = NULL;
1869 VkCopyDescriptorSet* pCDS = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001870 size_t array_size = 0;
1871 size_t base_array_size = 0;
1872 size_t total_array_size = 0;
1873 size_t baseBuffAddr = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001874 switch (pUpdate->sType)
1875 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001876 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1877 pWDS = new VkWriteDescriptorSet;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001878 *pNewNode = (GENERIC_HEADER*)pWDS;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001879 memcpy(pWDS, pUpdate, sizeof(VkWriteDescriptorSet));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001880
1881 switch (pWDS->descriptorType) {
1882 case VK_DESCRIPTOR_TYPE_SAMPLER:
1883 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
1884 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
1885 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
1886 {
Chia-I Wud50a7d72015-10-26 20:48:51 +08001887 VkDescriptorImageInfo *info = new VkDescriptorImageInfo[pWDS->descriptorCount];
1888 memcpy(info, pWDS->pImageInfo, pWDS->descriptorCount * sizeof(VkDescriptorImageInfo));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001889 pWDS->pImageInfo = info;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001890 }
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001891 break;
1892 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
1893 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
1894 {
Chia-I Wud50a7d72015-10-26 20:48:51 +08001895 VkBufferView *info = new VkBufferView[pWDS->descriptorCount];
1896 memcpy(info, pWDS->pTexelBufferView, pWDS->descriptorCount * sizeof(VkBufferView));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001897 pWDS->pTexelBufferView = info;
1898 }
1899 break;
1900 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
1901 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
1902 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
1903 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
1904 {
Chia-I Wud50a7d72015-10-26 20:48:51 +08001905 VkDescriptorBufferInfo *info = new VkDescriptorBufferInfo[pWDS->descriptorCount];
1906 memcpy(info, pWDS->pBufferInfo, pWDS->descriptorCount * sizeof(VkDescriptorBufferInfo));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001907 pWDS->pBufferInfo = info;
1908 }
1909 break;
1910 default:
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07001911 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001912 break;
1913 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001914 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001915 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
1916 pCDS = new VkCopyDescriptorSet;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001917 *pNewNode = (GENERIC_HEADER*)pCDS;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001918 memcpy(pCDS, pUpdate, sizeof(VkCopyDescriptorSet));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001919 break;
1920 default:
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001921 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001922 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdate->sType), pUpdate->sType))
1923 return VK_TRUE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001924 }
1925 // Make sure that pNext for the end of shadow copy is NULL
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001926 (*pNewNode)->pNext = NULL;
1927 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001928}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001929
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001930// Verify that given sampler is valid
1931static VkBool32 validateSampler(const layer_data* my_data, const VkSampler* pSampler, const VkBool32 immutable)
1932{
1933 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08001934 auto sampIt = my_data->sampleMap.find(*pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001935 if (sampIt == my_data->sampleMap.end()) {
1936 if (!immutable) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001937 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT, (uint64_t) *pSampler, 0, DRAWSTATE_SAMPLER_DESCRIPTOR_ERROR, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08001938 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid sampler %#" PRIxLEAST64, (uint64_t) *pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001939 } else { // immutable
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001940 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT, (uint64_t) *pSampler, 0, DRAWSTATE_SAMPLER_DESCRIPTOR_ERROR, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08001941 "vkUpdateDescriptorSets: Attempt to update descriptor whose binding has an invalid immutable sampler %#" PRIxLEAST64, (uint64_t) *pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001942 }
1943 } else {
1944 // TODO : Any further checks we want to do on the sampler?
1945 }
1946 return skipCall;
1947}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001948
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001949// Verify that given imageView is valid
1950static VkBool32 validateImageView(const layer_data* my_data, const VkImageView* pImageView, const VkImageLayout imageLayout)
1951{
1952 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08001953 auto ivIt = my_data->imageViewMap.find(*pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001954 if (ivIt == my_data->imageViewMap.end()) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001955 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, (uint64_t) *pImageView, 0, DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08001956 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid imageView %#" PRIxLEAST64, (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001957 } else {
1958 // Validate that imageLayout is compatible with aspectMask and image format
1959 VkImageAspectFlags aspectMask = ivIt->second->subresourceRange.aspectMask;
Chia-I Wue2fc5522015-10-26 20:04:44 +08001960 VkImage image = ivIt->second->image;
Michael Lentine7b236262015-10-23 12:41:44 -07001961 // TODO : Check here in case we have a bad image
Chia-I Wue2fc5522015-10-26 20:04:44 +08001962 auto imgIt = my_data->imageMap.find(image);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001963 if (imgIt == my_data->imageMap.end()) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001964 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t) image, 0, DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, "DS",
Michael Lentine7b236262015-10-23 12:41:44 -07001965 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid image %#" PRIxLEAST64 " in imageView %#" PRIxLEAST64, (uint64_t) image, (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001966 } else {
1967 VkFormat format = (*imgIt).second->format;
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07001968 VkBool32 ds = vk_format_is_depth_or_stencil(format);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001969 switch (imageLayout) {
1970 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
1971 // Only Color bit must be set
1972 if ((aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) != VK_IMAGE_ASPECT_COLOR_BIT) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001973 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, (uint64_t) *pImageView, 0,
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001974 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL and imageView %#" PRIxLEAST64 ""
Chia-I Wue2fc5522015-10-26 20:04:44 +08001975 " that does not have VK_IMAGE_ASPECT_COLOR_BIT set.", (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001976 }
1977 // format must NOT be DS
1978 if (ds) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001979 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, (uint64_t) *pImageView, 0,
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001980 DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL and imageView %#" PRIxLEAST64 ""
Chia-I Wue2fc5522015-10-26 20:04:44 +08001981 " but the image format is %s which is not a color format.", (uint64_t) *pImageView, string_VkFormat(format));
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001982 }
1983 break;
1984 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
1985 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
1986 // Depth or stencil bit must be set, but both must NOT be set
1987 if (aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) {
1988 if (aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) {
1989 // both must NOT be set
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001990 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, (uint64_t) *pImageView, 0,
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001991 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with imageView %#" PRIxLEAST64 ""
Chia-I Wue2fc5522015-10-26 20:04:44 +08001992 " that has both STENCIL and DEPTH aspects set", (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001993 }
1994 } else if (!(aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)) {
1995 // Neither were set
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001996 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, (uint64_t) *pImageView, 0,
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001997 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout %s and imageView %#" PRIxLEAST64 ""
Chia-I Wue2fc5522015-10-26 20:04:44 +08001998 " that does not have STENCIL or DEPTH aspect set.", string_VkImageLayout(imageLayout), (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001999 }
2000 // format must be DS
2001 if (!ds) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002002 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, (uint64_t) *pImageView, 0,
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002003 DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout %s and imageView %#" PRIxLEAST64 ""
Chia-I Wue2fc5522015-10-26 20:04:44 +08002004 " but the image format is %s which is not a depth/stencil format.", string_VkImageLayout(imageLayout), (uint64_t) *pImageView, string_VkFormat(format));
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002005 }
2006 break;
2007 default:
2008 // anything to check for other layouts?
2009 break;
2010 }
2011 }
2012 }
2013 return skipCall;
2014}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002015
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002016// Verify that given bufferView is valid
2017static VkBool32 validateBufferView(const layer_data* my_data, const VkBufferView* pBufferView)
2018{
2019 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002020 auto sampIt = my_data->bufferViewMap.find(*pBufferView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002021 if (sampIt == my_data->bufferViewMap.end()) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002022 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_VIEW_EXT, (uint64_t) *pBufferView, 0, DRAWSTATE_BUFFERVIEW_DESCRIPTOR_ERROR, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002023 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid bufferView %#" PRIxLEAST64, (uint64_t) *pBufferView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002024 } else {
2025 // TODO : Any further checks we want to do on the bufferView?
2026 }
2027 return skipCall;
2028}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002029
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002030// Verify that given bufferInfo is valid
2031static VkBool32 validateBufferInfo(const layer_data* my_data, const VkDescriptorBufferInfo* pBufferInfo)
2032{
2033 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002034 auto sampIt = my_data->bufferMap.find(pBufferInfo->buffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002035 if (sampIt == my_data->bufferMap.end()) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002036 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, (uint64_t) pBufferInfo->buffer, 0, DRAWSTATE_BUFFERINFO_DESCRIPTOR_ERROR, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002037 "vkUpdateDescriptorSets: Attempt to update descriptor where bufferInfo has invalid buffer %#" PRIxLEAST64, (uint64_t) pBufferInfo->buffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002038 } else {
2039 // TODO : Any further checks we want to do on the bufferView?
2040 }
2041 return skipCall;
2042}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002043
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002044static VkBool32 validateUpdateContents(const layer_data* my_data, const VkWriteDescriptorSet *pWDS, const VkDescriptorSetLayoutBinding* pLayoutBinding)
2045{
2046 VkBool32 skipCall = VK_FALSE;
2047 // First verify that for the given Descriptor type, the correct DescriptorInfo data is supplied
2048 VkBufferView* pBufferView = NULL;
2049 const VkSampler* pSampler = NULL;
2050 VkImageView* pImageView = NULL;
2051 VkImageLayout* pImageLayout = NULL;
2052 VkDescriptorBufferInfo* pBufferInfo = NULL;
2053 VkBool32 immutable = VK_FALSE;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002054 uint32_t i = 0;
2055 // For given update type, verify that update contents are correct
2056 switch (pWDS->descriptorType) {
2057 case VK_DESCRIPTOR_TYPE_SAMPLER:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002058 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002059 skipCall |= validateSampler(my_data, &(pWDS->pImageInfo[i].sampler), immutable);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002060 }
2061 break;
2062 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002063 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002064 if (NULL == pLayoutBinding->pImmutableSamplers) {
2065 pSampler = &(pWDS->pImageInfo[i].sampler);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002066 if (immutable) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002067 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT, (uint64_t) *pSampler, 0, DRAWSTATE_INCONSISTENT_IMMUTABLE_SAMPLER_UPDATE, "DS",
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002068 "vkUpdateDescriptorSets: Update #%u is not an immutable sampler %#" PRIxLEAST64 ", but previous update(s) from this "
2069 "VkWriteDescriptorSet struct used an immutable sampler. All updates from a single struct must either "
Chia-I Wue2fc5522015-10-26 20:04:44 +08002070 "use immutable or non-immutable samplers.", i, (uint64_t) *pSampler);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002071 }
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002072 } else {
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002073 if (i>0 && !immutable) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002074 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT, (uint64_t) *pSampler, 0, DRAWSTATE_INCONSISTENT_IMMUTABLE_SAMPLER_UPDATE, "DS",
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002075 "vkUpdateDescriptorSets: Update #%u is an immutable sampler, but previous update(s) from this "
2076 "VkWriteDescriptorSet struct used a non-immutable sampler. All updates from a single struct must either "
2077 "use immutable or non-immutable samplers.", i);
2078 }
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002079 immutable = VK_TRUE;
2080 pSampler = &(pLayoutBinding->pImmutableSamplers[i]);
2081 }
2082 skipCall |= validateSampler(my_data, pSampler, immutable);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002083 }
2084 // Intentionally fall through here to also validate image stuff
2085 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2086 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
2087 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002088 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002089 skipCall |= validateImageView(my_data, &(pWDS->pImageInfo[i].imageView), pWDS->pImageInfo[i].imageLayout);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002090 }
2091 break;
2092 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2093 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002094 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002095 skipCall |= validateBufferView(my_data, &(pWDS->pTexelBufferView[i]));
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002096 }
2097 break;
2098 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2099 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2100 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2101 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002102 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002103 skipCall |= validateBufferInfo(my_data, &(pWDS->pBufferInfo[i]));
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002104 }
2105 break;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002106 }
2107 return skipCall;
2108}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002109
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002110// update DS mappings based on write and copy update arrays
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08002111static VkBool32 dsUpdate(layer_data* my_data, VkDevice device, uint32_t descriptorWriteCount, const VkWriteDescriptorSet* pWDS, uint32_t descriptorCopyCount, const VkCopyDescriptorSet* pCDS)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002112{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002113 VkBool32 skipCall = VK_FALSE;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002114
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002115 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002116 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002117 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002118 // Validate Write updates
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002119 uint32_t i = 0;
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08002120 for (i=0; i < descriptorWriteCount; i++) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002121 VkDescriptorSet ds = pWDS[i].dstSet;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002122 SET_NODE* pSet = my_data->setMap[ds];
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002123 GENERIC_HEADER* pUpdate = (GENERIC_HEADER*) &pWDS[i];
Tobin Ehlis793ad302015-04-03 12:01:11 -06002124 pLayout = pSet->pLayout;
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002125 // First verify valid update struct
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06002126 if ((skipCall = validUpdateStruct(my_data, device, pUpdate)) == VK_TRUE) {
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002127 break;
2128 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002129 uint32_t binding = 0, endIndex = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002130 binding = pWDS[i].dstBinding;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002131 // Make sure that layout being updated has the binding being updated
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002132 if (pLayout->bindings.find(binding) == pLayout->bindings.end()) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002133 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) ds, 0, DRAWSTATE_INVALID_UPDATE_INDEX, "DS",
Michael Lentine010f4692015-11-03 16:19:46 -08002134 "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 Ehlis9c536442015-06-19 13:00:59 -06002135 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06002136 // Next verify that update falls within size of given binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002137 endIndex = getUpdateEndIndex(my_data, device, pLayout, binding, pWDS[i].dstArrayElement, pUpdate);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002138 if (getBindingEndIndex(pLayout, binding) < endIndex) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06002139 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002140 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002141 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) ds, 0, DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, "DS",
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002142 "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 Ehlis9c536442015-06-19 13:00:59 -06002143 } else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002144 uint32_t startIndex;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002145 startIndex = getUpdateStartIndex(my_data, device, pLayout, binding, pWDS[i].dstArrayElement, pUpdate);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002146 // Layout bindings match w/ update, now verify that update type & stageFlags are the same for entire update
2147 if ((skipCall = validateUpdateConsistency(my_data, device, pLayout, pUpdate, startIndex, endIndex)) == VK_FALSE) {
2148 // The update is within bounds and consistent, but need to make sure contents make sense as well
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002149 if ((skipCall = validateUpdateContents(my_data, &pWDS[i], &pLayout->createInfo.pBindings[binding])) == VK_FALSE) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002150 // Update is good. Save the update info
2151 // Create new update struct for this set's shadow copy
2152 GENERIC_HEADER* pNewNode = NULL;
2153 skipCall |= shadowUpdateNode(my_data, device, pUpdate, &pNewNode);
2154 if (NULL == pNewNode) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002155 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) ds, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002156 "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
2157 } else {
2158 // Insert shadow node into LL of updates for this set
2159 pNewNode->pNext = pSet->pUpdateStructs;
2160 pSet->pUpdateStructs = pNewNode;
2161 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002162 for (uint32_t j = startIndex; j <= endIndex; j++) {
2163 assert(j<pSet->descriptorCount);
2164 pSet->ppDescriptors[j] = pNewNode;
2165 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002166 }
2167 }
2168 }
2169 }
2170 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002171 }
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002172 // Now validate copy updates
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08002173 for (i=0; i < descriptorCopyCount; ++i) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002174 SET_NODE *pSrcSet = NULL, *pDstSet = NULL;
2175 LAYOUT_NODE *pSrcLayout = NULL, *pDstLayout = NULL;
2176 uint32_t srcStartIndex = 0, srcEndIndex = 0, dstStartIndex = 0, dstEndIndex = 0;
2177 // For each copy make sure that update falls within given layout and that types match
Chia-I Wue2fc5522015-10-26 20:04:44 +08002178 pSrcSet = my_data->setMap[pCDS[i].srcSet];
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002179 pDstSet = my_data->setMap[pCDS[i].dstSet];
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002180 pSrcLayout = pSrcSet->pLayout;
2181 pDstLayout = pDstSet->pLayout;
2182 // Validate that src binding is valid for src set layout
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002183 if (pSrcLayout->bindings.find(pCDS[i].srcBinding) == pSrcLayout->bindings.end()) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002184 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pSrcSet->set, 0, DRAWSTATE_INVALID_UPDATE_INDEX, "DS",
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002185 "Copy descriptor update %u has srcBinding %u which is out of bounds for underlying SetLayout %#" PRIxLEAST64 " which only has bindings 0-%u.",
Chia-I Wud50a7d72015-10-26 20:48:51 +08002186 i, pCDS[i].srcBinding, (uint64_t) pSrcLayout->layout, pSrcLayout->createInfo.bindingCount-1);
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002187 } else if (pDstLayout->bindings.find(pCDS[i].dstBinding) == pDstLayout->bindings.end()) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002188 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pDstSet->set, 0, DRAWSTATE_INVALID_UPDATE_INDEX, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002189 "Copy descriptor update %u has dstBinding %u which is out of bounds for underlying SetLayout %#" PRIxLEAST64 " which only has bindings 0-%u.",
2190 i, pCDS[i].dstBinding, (uint64_t) pDstLayout->layout, pDstLayout->createInfo.bindingCount-1);
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002191 } else {
2192 // Proceed with validation. Bindings are ok, but make sure update is within bounds of given layout
2193 srcEndIndex = getUpdateEndIndex(my_data, device, pSrcLayout, pCDS[i].srcBinding, pCDS[i].srcArrayElement, (const GENERIC_HEADER*)&(pCDS[i]));
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002194 dstEndIndex = getUpdateEndIndex(my_data, device, pDstLayout, pCDS[i].dstBinding, pCDS[i].dstArrayElement, (const GENERIC_HEADER*)&(pCDS[i]));
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002195 if (getBindingEndIndex(pSrcLayout, pCDS[i].srcBinding) < srcEndIndex) {
2196 pLayoutCI = &pSrcLayout->createInfo;
2197 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002198 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pSrcSet->set, 0, DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, "DS",
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002199 "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 Wu3432a0c2015-10-27 18:04:07 +08002200 } else if (getBindingEndIndex(pDstLayout, pCDS[i].dstBinding) < dstEndIndex) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002201 pLayoutCI = &pDstLayout->createInfo;
2202 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002203 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pDstSet->set, 0, DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002204 "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 Ehlis8a62e632015-10-27 15:43:38 -06002205 } else {
2206 srcStartIndex = getUpdateStartIndex(my_data, device, pSrcLayout, pCDS[i].srcBinding, pCDS[i].srcArrayElement, (const GENERIC_HEADER*)&(pCDS[i]));
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002207 dstStartIndex = getUpdateStartIndex(my_data, device, pDstLayout, pCDS[i].dstBinding, pCDS[i].dstArrayElement, (const GENERIC_HEADER*)&(pCDS[i]));
Chia-I Wud50a7d72015-10-26 20:48:51 +08002208 for (uint32_t j=0; j<pCDS[i].descriptorCount; ++j) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002209 // For copy just make sure that the types match and then perform the update
2210 if (pSrcLayout->descriptorTypes[srcStartIndex+j] != pDstLayout->descriptorTypes[dstStartIndex+j]) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002211 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, "DS",
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002212 "Copy descriptor update index %u, update count #%u, has src update descriptor type %s that does not match overlapping dest descriptor type of %s!",
2213 i, j+1, string_VkDescriptorType(pSrcLayout->descriptorTypes[srcStartIndex+j]), string_VkDescriptorType(pDstLayout->descriptorTypes[dstStartIndex+j]));
2214 } else {
2215 // point dst descriptor at corresponding src descriptor
Tobin Ehlisf6585052015-12-17 11:48:42 -07002216 // TODO : This may be a hole. I believe copy should be its own copy,
2217 // otherwise a subsequent write update to src will incorrectly affect the copy
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002218 pDstSet->ppDescriptors[j+dstStartIndex] = pSrcSet->ppDescriptors[j+srcStartIndex];
2219 }
2220 }
2221 }
2222 }
2223 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002224 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002225 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002226}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002227
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002228// Verify that given pool has descriptors that are being requested for allocation
Mark Lobodzinski39298632015-11-18 08:38:27 -07002229static VkBool32 validate_descriptor_availability_in_pool(layer_data* dev_data, DESCRIPTOR_POOL_NODE* pPoolNode, uint32_t count, const VkDescriptorSetLayout* pSetLayouts)
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002230{
2231 VkBool32 skipCall = VK_FALSE;
2232 uint32_t i = 0, j = 0;
2233 for (i=0; i<count; ++i) {
2234 LAYOUT_NODE* pLayout = getLayoutNode(dev_data, pSetLayouts[i]);
2235 if (NULL == pLayout) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002236 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, (uint64_t) pSetLayouts[i], 0, DRAWSTATE_INVALID_LAYOUT, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002237 "Unable to find set layout node for layout %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pSetLayouts[i]);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002238 } else {
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002239 uint32_t typeIndex = 0, poolSizeCount = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002240 for (j=0; j<pLayout->createInfo.bindingCount; ++j) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002241 typeIndex = static_cast<uint32_t>(pLayout->createInfo.pBindings[j].descriptorType);
2242 poolSizeCount = pLayout->createInfo.pBindings[j].descriptorCount;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002243 if (poolSizeCount > pPoolNode->availableDescriptorTypeCount[typeIndex]) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002244 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, (uint64_t) pLayout->layout, 0, DRAWSTATE_DESCRIPTOR_POOL_EMPTY, "DS",
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002245 "Unable to allocate %u descriptors of type %s from pool %#" PRIxLEAST64 ". This pool only has %u descriptors of this type remaining.",
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002246 poolSizeCount, string_VkDescriptorType(pLayout->createInfo.pBindings[j].descriptorType), (uint64_t) pPoolNode->pool, pPoolNode->availableDescriptorTypeCount[typeIndex]);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002247 } else { // Decrement available descriptors of this type
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002248 pPoolNode->availableDescriptorTypeCount[typeIndex] -= poolSizeCount;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002249 }
2250 }
2251 }
2252 }
2253 return skipCall;
2254}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002255
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002256// Free the shadowed update node for this Set
2257// NOTE : Calls to this function should be wrapped in mutex
2258static void freeShadowUpdateTree(SET_NODE* pSet)
2259{
2260 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
2261 pSet->pUpdateStructs = NULL;
2262 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
2263 // Clear the descriptor mappings as they will now be invalid
2264 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
2265 while(pShadowUpdate) {
2266 pFreeUpdate = pShadowUpdate;
2267 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
2268 uint32_t index = 0;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002269 VkWriteDescriptorSet * pWDS = NULL;
2270 VkCopyDescriptorSet * pCDS = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002271 void** ppToFree = NULL;
2272 switch (pFreeUpdate->sType)
2273 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002274 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
2275 pWDS = (VkWriteDescriptorSet*)pFreeUpdate;
Tony Barbourb1947942015-11-02 11:46:29 -07002276 switch (pWDS->descriptorType) {
2277 case VK_DESCRIPTOR_TYPE_SAMPLER:
2278 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
2279 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2280 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
2281 {
2282 delete[] pWDS->pImageInfo;
2283 }
2284 break;
2285 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2286 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
2287 {
2288 delete[] pWDS->pTexelBufferView;
2289 }
2290 break;
2291 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2292 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2293 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2294 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
2295 {
2296 delete[] pWDS->pBufferInfo;
2297 }
2298 break;
2299 default:
2300 break;
Courtney Goeltzenleuchteraa132e72015-10-22 15:31:56 -06002301 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002302 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002303 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002304 break;
2305 default:
2306 assert(0);
2307 break;
2308 }
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002309 delete pFreeUpdate;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002310 }
2311}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002312
Tobin Ehlis793ad302015-04-03 12:01:11 -06002313// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002314// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002315static void deletePools(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002316{
Mark Lobodzinski39298632015-11-18 08:38:27 -07002317 if (my_data->descriptorPoolMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06002318 return;
Mark Lobodzinski39298632015-11-18 08:38:27 -07002319 for (auto ii=my_data->descriptorPoolMap.begin(); ii!=my_data->descriptorPoolMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002320 SET_NODE* pSet = (*ii).second->pSets;
2321 SET_NODE* pFreeSet = pSet;
2322 while (pSet) {
2323 pFreeSet = pSet;
2324 pSet = pSet->pNext;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002325 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002326 // Free Update shadow struct tree
2327 freeShadowUpdateTree(pFreeSet);
2328 if (pFreeSet->ppDescriptors) {
Chris Forbes02038792015-06-04 10:49:27 +12002329 delete[] pFreeSet->ppDescriptors;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002330 }
2331 delete pFreeSet;
2332 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002333 delete (*ii).second;
2334 }
Mark Lobodzinski39298632015-11-18 08:38:27 -07002335 my_data->descriptorPoolMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002336}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002337
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002338// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002339// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002340static void deleteLayouts(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002341{
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07002342 if (my_data->descriptorSetLayoutMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06002343 return;
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07002344 for (auto ii=my_data->descriptorSetLayoutMap.begin(); ii!=my_data->descriptorSetLayoutMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002345 LAYOUT_NODE* pLayout = (*ii).second;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002346 if (pLayout->createInfo.pBindings) {
Chia-I Wud50a7d72015-10-26 20:48:51 +08002347 for (uint32_t i=0; i<pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002348 if (pLayout->createInfo.pBindings[i].pImmutableSamplers)
2349 delete[] pLayout->createInfo.pBindings[i].pImmutableSamplers;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002350 }
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002351 delete[] pLayout->createInfo.pBindings;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002352 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002353 delete pLayout;
2354 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07002355 my_data->descriptorSetLayoutMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002356}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002357
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002358// Currently clearing a set is removing all previous updates to that set
2359// TODO : Validate if this is correct clearing behavior
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002360static void clearDescriptorSet(layer_data* my_data, VkDescriptorSet set)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002361{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002362 SET_NODE* pSet = getSetNode(my_data, set);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002363 if (!pSet) {
2364 // TODO : Return error
Tobin Ehlisce132d82015-06-19 15:07:05 -06002365 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002366 loader_platform_thread_lock_mutex(&globalLock);
2367 freeShadowUpdateTree(pSet);
2368 loader_platform_thread_unlock_mutex(&globalLock);
2369 }
2370}
2371
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002372static void clearDescriptorPool(layer_data* my_data, const VkDevice device, const VkDescriptorPool pool, VkDescriptorPoolResetFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002373{
Mark Lobodzinski39298632015-11-18 08:38:27 -07002374 DESCRIPTOR_POOL_NODE* pPool = getPoolNode(my_data, pool);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002375 if (!pPool) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002376 log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, (uint64_t) pool, 0, DRAWSTATE_INVALID_POOL, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002377 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkResetDescriptorPool() call", (uint64_t) pool);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002378 } else {
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002379 // TODO: validate flags
Tobin Ehlis793ad302015-04-03 12:01:11 -06002380 // For every set off of this pool, clear it
2381 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002382 while (pSet) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002383 clearDescriptorSet(my_data, pSet->set);
Mark Lobodzinskidcce0792016-01-04 09:40:19 -07002384 pSet = pSet->pNext;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002385 }
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002386 // Reset available count to max count for this pool
2387 for (uint32_t i=0; i<pPool->availableDescriptorTypeCount.size(); ++i) {
2388 pPool->availableDescriptorTypeCount[i] = pPool->maxDescriptorTypeCount[i];
2389 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002390 }
2391}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002392
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002393// For given CB object, fetch associated CB Node from map
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002394static GLOBAL_CB_NODE* getCBNode(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002395{
2396 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002397 if (my_data->commandBufferMap.count(cb) == 0) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002398 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002399 // TODO : How to pass cb as srcObj here?
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002400 log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, 0, DRAWSTATE_INVALID_COMMAND_BUFFER, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002401 "Attempt to use CommandBuffer %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<uint64_t>(cb));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002402 return NULL;
2403 }
2404 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002405 return my_data->commandBufferMap[cb];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002406}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002407
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002408// Free all CB Nodes
2409// NOTE : Calls to this function should be wrapped in mutex
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002410static void deleteCommandBuffers(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002411{
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002412 if (my_data->commandBufferMap.size() <= 0) {
David Pinedod8f83d82015-04-27 16:36:17 -06002413 return;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002414 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002415 for (auto ii=my_data->commandBufferMap.begin(); ii!=my_data->commandBufferMap.end(); ++ii) {
Courtney Goeltzenleuchterea3117c2015-04-27 15:04:43 -06002416 vector<CMD_NODE*> cmd_node_list = (*ii).second->pCmds;
2417 while (!cmd_node_list.empty()) {
2418 CMD_NODE* cmd_node = cmd_node_list.back();
2419 delete cmd_node;
2420 cmd_node_list.pop_back();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002421 }
2422 delete (*ii).second;
2423 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002424 my_data->commandBufferMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002425}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002426
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002427static VkBool32 report_error_no_cb_begin(const layer_data* dev_data, const VkCommandBuffer cb, const char* caller_name)
Tobin Ehlis9c536442015-06-19 13:00:59 -06002428{
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002429 return log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2430 (uint64_t)cb, 0, DRAWSTATE_NO_BEGIN_COMMAND_BUFFER, "DS",
2431 "You must call vkBeginCommandBuffer() before this call to %s", caller_name);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002432}
Michael Lentine3dea6512015-10-28 15:55:18 -07002433
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07002434VkBool32 validateCmdsInCmdBuffer(const layer_data* dev_data, const GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd_type) {
Tony Barbour352108f2015-12-17 15:54:05 -07002435 // TODO : I think this is trying to validate this part of the spec:
2436 // If contents is VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS, the contents are recorded in secondary command
2437 // buffers that will be called from the primary command buffer, and vkCmdExecuteCommands is the only valid command
2438 // on the command buffer until vkCmdNextSubpass or vkCmdEndRenderPass.
2439 //
2440 // But the code below is forceing vkCmdExecuteCommands to be the only thing in the command buffer which is not necessary
2441 // it just needs to be the only thing in the renderpass
2442 //
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07002443 VkBool32 skip_call = false;
Tony Barbour352108f2015-12-17 15:54:05 -07002444 //for (auto cmd : pCB->pCmds) {
2445 // if (cmd_type == CMD_EXECUTECOMMANDS && cmd->type != CMD_EXECUTECOMMANDS) {
2446 // skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_COMMAND_BUFFER, "DS",
2447 // "vkCmdExecuteCommands() cannot be called on a cmd buffer with exsiting commands.");
2448 // }
2449 // if (cmd_type != CMD_EXECUTECOMMANDS && cmd->type == CMD_EXECUTECOMMANDS) {
2450 // skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_COMMAND_BUFFER, "DS",
2451 // "Commands cannot be added to a cmd buffer with exsiting secondary commands.");
2452 // }
2453 //}
Michael Lentine3dea6512015-10-28 15:55:18 -07002454 return skip_call;
2455}
2456
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002457// Add specified CMD to the CmdBuffer in given pCB, flagging errors if CB is not
2458// in the recording state or if there's an issue with the Cmd ordering
2459static VkBool32 addCmd(const layer_data* my_data, GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd, const char* caller_name)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002460{
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002461 VkBool32 skipCall = VK_FALSE;
2462 if (pCB->state != CB_RECORDING) {
2463 skipCall |= report_error_no_cb_begin(my_data, pCB->commandBuffer, caller_name);
2464 skipCall |= validateCmdsInCmdBuffer(my_data, pCB, cmd);
2465 CMD_NODE* pCmd = new CMD_NODE;
2466 if (pCmd) {
2467 // init cmd node and append to end of cmd LL
2468 memset(pCmd, 0, sizeof(CMD_NODE));
2469 pCmd->cmdNumber = ++pCB->numCmds;
2470 pCmd->type = cmd;
2471 pCB->pCmds.push_back(pCmd);
2472 } else {
2473 // TODO : How to pass cb as srcObj here?
2474 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
2475 "Out of memory while attempting to allocate new CMD_NODE for commandBuffer %#" PRIxLEAST64, reinterpret_cast<uint64_t>(pCB->commandBuffer));
2476 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002477 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002478 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002479}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002480
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002481static void resetCB(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002482{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002483 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002484 if (pCB) {
Courtney Goeltzenleuchter3597a202015-04-27 17:16:56 -06002485 vector<CMD_NODE*> cmd_list = pCB->pCmds;
2486 while (!cmd_list.empty()) {
2487 delete cmd_list.back();
2488 cmd_list.pop_back();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002489 }
Courtney Goeltzenleuchter3597a202015-04-27 17:16:56 -06002490 pCB->pCmds.clear();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06002491 // Reset CB state (need to save createInfo)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002492 VkCommandBufferAllocateInfo saveCBCI = pCB->createInfo;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002493 pCB->commandBuffer = cb;
Tobin Ehlis59278bf2015-08-18 07:10:58 -06002494 pCB->createInfo = saveCBCI;
Michael Lentineabc5e922015-10-12 11:30:14 -05002495 memset(&pCB->beginInfo, 0, sizeof(VkCommandBufferBeginInfo));
2496 pCB->fence = 0;
2497 pCB->numCmds = 0;
2498 memset(pCB->drawCount, 0, NUM_DRAW_TYPES * sizeof(uint64_t));
2499 pCB->state = CB_NEW;
2500 pCB->submitCount = 0;
2501 pCB->status = 0;
2502 pCB->pCmds.clear();
2503 pCB->lastBoundPipeline = 0;
2504 pCB->viewports.clear();
2505 pCB->scissors.clear();
2506 pCB->lineWidth = 0;
2507 pCB->depthBiasConstantFactor = 0;
2508 pCB->depthBiasClamp = 0;
2509 pCB->depthBiasSlopeFactor = 0;
2510 memset(pCB->blendConstants, 0, 4 * sizeof(float));
2511 pCB->minDepthBounds = 0;
2512 pCB->maxDepthBounds = 0;
2513 memset(&pCB->front, 0, sizeof(stencil_data));
2514 memset(&pCB->back, 0, sizeof(stencil_data));
2515 pCB->lastBoundDescriptorSet = 0;
2516 pCB->lastBoundPipelineLayout = 0;
2517 pCB->activeRenderPass = 0;
2518 pCB->activeSubpass = 0;
2519 pCB->framebuffer = 0;
Michael Lentineabc5e922015-10-12 11:30:14 -05002520 pCB->boundDescriptorSets.clear();
2521 pCB->imageLayoutMap.clear();
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07002522 pCB->boundVtxBuffers.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002523 }
2524}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002525
Tobin Ehlis963a4042015-09-29 08:18:34 -06002526// Set PSO-related status bits for CB, including dynamic state set via PSO
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002527static void set_cb_pso_status(GLOBAL_CB_NODE* pCB, const PIPELINE_NODE* pPipe)
2528{
2529 for (uint32_t i = 0; i < pPipe->cbStateCI.attachmentCount; i++) {
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002530 if (0 != pPipe->pAttachments[i].colorWriteMask) {
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002531 pCB->status |= CBSTATUS_COLOR_BLEND_WRITE_ENABLE;
2532 }
2533 }
2534 if (pPipe->dsStateCI.depthWriteEnable) {
Cody Northrop82485a82015-08-18 15:21:16 -06002535 pCB->status |= CBSTATUS_DEPTH_WRITE_ENABLE;
2536 }
Cody Northrop82485a82015-08-18 15:21:16 -06002537 if (pPipe->dsStateCI.stencilTestEnable) {
2538 pCB->status |= CBSTATUS_STENCIL_TEST_ENABLE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002539 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06002540 // Account for any dynamic state not set via this PSO
2541 if (!pPipe->dynStateCI.dynamicStateCount) { // All state is static
2542 pCB->status = CBSTATUS_ALL;
2543 } else {
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002544 // First consider all state on
2545 // Then unset any state that's noted as dynamic in PSO
2546 // Finally OR that into CB statemask
2547 CBStatusFlags psoDynStateMask = CBSTATUS_ALL;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002548 for (uint32_t i=0; i < pPipe->dynStateCI.dynamicStateCount; i++) {
2549 switch (pPipe->dynStateCI.pDynamicStates[i]) {
2550 case VK_DYNAMIC_STATE_VIEWPORT:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002551 psoDynStateMask &= ~CBSTATUS_VIEWPORT_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002552 break;
2553 case VK_DYNAMIC_STATE_SCISSOR:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002554 psoDynStateMask &= ~CBSTATUS_SCISSOR_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002555 break;
2556 case VK_DYNAMIC_STATE_LINE_WIDTH:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002557 psoDynStateMask &= ~CBSTATUS_LINE_WIDTH_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002558 break;
2559 case VK_DYNAMIC_STATE_DEPTH_BIAS:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002560 psoDynStateMask &= ~CBSTATUS_DEPTH_BIAS_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002561 break;
2562 case VK_DYNAMIC_STATE_BLEND_CONSTANTS:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002563 psoDynStateMask &= ~CBSTATUS_BLEND_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002564 break;
2565 case VK_DYNAMIC_STATE_DEPTH_BOUNDS:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002566 psoDynStateMask &= ~CBSTATUS_DEPTH_BOUNDS_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002567 break;
2568 case VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002569 psoDynStateMask &= ~CBSTATUS_STENCIL_READ_MASK_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002570 break;
2571 case VK_DYNAMIC_STATE_STENCIL_WRITE_MASK:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002572 psoDynStateMask &= ~CBSTATUS_STENCIL_WRITE_MASK_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002573 break;
2574 case VK_DYNAMIC_STATE_STENCIL_REFERENCE:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002575 psoDynStateMask &= ~CBSTATUS_STENCIL_REFERENCE_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002576 break;
2577 default:
2578 // TODO : Flag error here
2579 break;
2580 }
2581 }
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002582 pCB->status |= psoDynStateMask;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002583 }
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002584}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002585
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002586// Print the last bound Gfx Pipeline
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002587static VkBool32 printPipeline(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002588{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002589 VkBool32 skipCall = VK_FALSE;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002590 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002591 if (pCB) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002592 PIPELINE_NODE *pPipeTrav = getPipeline(my_data, pCB->lastBoundPipeline);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002593 if (!pPipeTrav) {
2594 // nothing to print
Tobin Ehlisce132d82015-06-19 15:07:05 -06002595 } else {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002596 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_NONE, "DS",
Michael Lentine010f4692015-11-03 16:19:46 -08002597 "%s", vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002598 }
2599 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002600 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002601}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002602
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002603// Print details of DS config to stdout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002604static VkBool32 printDSConfig(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002605{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002606 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002607 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 Ehlisb212dfc2015-10-07 15:40:22 -06002608 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis93f89e82015-06-09 08:39:32 -06002609 if (pCB && pCB->lastBoundDescriptorSet) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002610 SET_NODE* pSet = getSetNode(my_data, pCB->lastBoundDescriptorSet);
Mark Lobodzinski39298632015-11-18 08:38:27 -07002611 DESCRIPTOR_POOL_NODE* pPool = getPoolNode(my_data, pSet->pool);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002612 // Print out pool details
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002613 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_NONE, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002614 "Details for pool %#" PRIxLEAST64 ".", (uint64_t) pPool->pool);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002615 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002616 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002617 "%s", poolStr.c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002618 // Print out set details
2619 char prefix[10];
2620 uint32_t index = 0;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002621 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_NONE, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002622 "Details for descriptor set %#" PRIxLEAST64 ".", (uint64_t) pSet->set);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002623 LAYOUT_NODE* pLayout = pSet->pLayout;
2624 // Print layout details
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002625 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_NONE, "DS",
Michael Lentine010f4692015-11-03 16:19:46 -08002626 "Layout #%u, (object %#" PRIxLEAST64 ") for DS %#" PRIxLEAST64 ".", index+1, reinterpret_cast<uint64_t>(pLayout->layout), reinterpret_cast<uint64_t>(pSet->set));
Tobin Ehlis793ad302015-04-03 12:01:11 -06002627 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002628 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002629 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002630 "%s", DSLstr.c_str());
Tobin Ehlis793ad302015-04-03 12:01:11 -06002631 index++;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002632 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
2633 if (pUpdate) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002634 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_NONE, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002635 "Update Chain [UC] for descriptor set %#" PRIxLEAST64 ":", (uint64_t) pSet->set);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002636 sprintf(prefix, " [UC] ");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002637 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_NONE, "DS",
Michael Lentine010f4692015-11-03 16:19:46 -08002638 "%s", dynamic_display(pUpdate, prefix).c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002639 // TODO : If there is a "view" associated with this update, print CI for that view
Tobin Ehlisce132d82015-06-19 15:07:05 -06002640 } else {
Tobin Ehlisbf081f32015-06-15 08:41:17 -06002641 if (0 != pSet->descriptorCount) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002642 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_NONE, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002643 "No Update Chain for descriptor set %#" PRIxLEAST64 " which has %u descriptors (vkUpdateDescriptors has not been called)", (uint64_t) pSet->set, pSet->descriptorCount);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002644 } else {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002645 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_NONE, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002646 "FYI: No descriptors in descriptor set %#" PRIxLEAST64 ".", (uint64_t) pSet->set);
Tobin Ehlisbf081f32015-06-15 08:41:17 -06002647 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002648 }
2649 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002650 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002651}
2652
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002653static void printCB(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002654{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002655 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
David Pinedod8f83d82015-04-27 16:36:17 -06002656 if (pCB && pCB->pCmds.size() > 0) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002657 log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002658 "Cmds in CB %p", (void*)cb);
Courtney Goeltzenleuchterba348a92015-04-27 11:16:35 -06002659 vector<CMD_NODE*> pCmds = pCB->pCmds;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002660 for (auto ii=pCmds.begin(); ii!=pCmds.end(); ++ii) {
2661 // TODO : Need to pass cb as srcObj here
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002662 log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, 0, DRAWSTATE_NONE, "DS",
Michael Lentine010f4692015-11-03 16:19:46 -08002663 " CMD#%" PRIu64 ": %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002664 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002665 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002666 // Nothing to print
2667 }
2668}
2669
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002670static VkBool32 synchAndPrintDSConfig(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002671{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002672 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002673 if (!(my_data->report_data->active_flags & VK_DEBUG_REPORT_INFO_BIT_EXT)) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002674 return skipCall;
Mike Stroyanba35e352015-08-12 17:11:28 -06002675 }
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002676 skipCall |= printDSConfig(my_data, cb);
2677 skipCall |= printPipeline(my_data, cb);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002678 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002679}
2680
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002681// Flags validation error if the associated call is made inside a render pass. The apiName
2682// routine should ONLY be called outside a render pass.
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06002683static VkBool32 insideRenderPass(const layer_data* my_data, GLOBAL_CB_NODE *pCB, const char *apiName)
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002684{
2685 VkBool32 inside = VK_FALSE;
2686 if (pCB->activeRenderPass) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002687 inside = log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002688 (uint64_t)pCB->commandBuffer, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002689 "%s: It is invalid to issue this call inside an active render pass (%#" PRIxLEAST64 ")",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002690 apiName, (uint64_t) pCB->activeRenderPass);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002691 }
2692 return inside;
2693}
2694
2695// Flags validation error if the associated call is made outside a render pass. The apiName
2696// routine should ONLY be called inside a render pass.
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06002697static VkBool32 outsideRenderPass(const layer_data* my_data, GLOBAL_CB_NODE *pCB, const char *apiName)
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002698{
2699 VkBool32 outside = VK_FALSE;
Mark Lobodzinski74635932015-12-18 15:35:38 -07002700 if (((pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) &&
2701 (!pCB->activeRenderPass)) ||
2702 ((pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) &&
2703 (!pCB->activeRenderPass) &&
2704 !(pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT))) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002705 outside = log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002706 (uint64_t)pCB->commandBuffer, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002707 "%s: This call must be issued inside an active render pass.", apiName);
2708 }
2709 return outside;
2710}
2711
Courtney Goeltzenleuchter6d8e8182015-11-25 14:31:49 -07002712static void init_draw_state(layer_data *my_data, const VkAllocationCallbacks *pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002713{
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002714 uint32_t report_flags = 0;
2715 uint32_t debug_action = 0;
2716 FILE *log_output = NULL;
2717 const char *option_str;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002718 VkDebugReportCallbackEXT callback;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002719 // initialize DrawState options
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002720 report_flags = getLayerOptionFlags("DrawStateReportFlags", 0);
2721 getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &debug_action);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002722
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002723 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002724 {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002725 option_str = getLayerOption("DrawStateLogFilename");
Tobin Ehlisb1df55e2015-09-15 09:55:54 -06002726 log_output = getLayerLogOutput(option_str, "DrawState");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002727 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002728 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002729 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002730 dbgInfo.pfnCallback = log_callback;
2731 dbgInfo.pUserData = log_output;
2732 dbgInfo.flags = report_flags;
2733 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002734 my_data->logging_callback.push_back(callback);
2735 }
2736
2737 if (debug_action & VK_DBG_LAYER_ACTION_DEBUG_OUTPUT) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002738 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002739 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002740 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002741 dbgInfo.pfnCallback = win32_debug_output_msg;
2742 dbgInfo.pUserData = log_output;
2743 dbgInfo.flags = report_flags;
2744 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002745 my_data->logging_callback.push_back(callback);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002746 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002747
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002748 if (!globalLockInitialized)
2749 {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002750 loader_platform_thread_create_mutex(&globalLock);
2751 globalLockInitialized = 1;
2752 }
2753}
2754
Chia-I Wu9ab61502015-11-06 06:42:02 +08002755VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance)
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002756{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002757 // TODOSC : Shouldn't need any customization here
Tobin Ehlis0b632332015-10-07 09:38:40 -06002758 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
2759 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002760 VkResult result = pTable->CreateInstance(pCreateInfo, pAllocator, pInstance);
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002761
2762 if (result == VK_SUCCESS) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002763 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
2764 my_data->report_data = debug_report_create_instance(
2765 pTable,
2766 *pInstance,
Chia-I Wud50a7d72015-10-26 20:48:51 +08002767 pCreateInfo->enabledExtensionNameCount,
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002768 pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchterd02a9642015-06-08 14:58:39 -06002769
Courtney Goeltzenleuchter6d8e8182015-11-25 14:31:49 -07002770 init_draw_state(my_data, pAllocator);
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002771 }
2772 return result;
2773}
2774
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002775/* hook DestroyInstance to remove tableInstanceMap entry */
Chia-I Wu9ab61502015-11-06 06:42:02 +08002776VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator)
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002777{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002778 // TODOSC : Shouldn't need any customization here
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002779 dispatch_key key = get_dispatch_key(instance);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002780 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
2781 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002782 pTable->DestroyInstance(instance, pAllocator);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002783
2784 // Clean up logging callback, if any
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002785 while (my_data->logging_callback.size() > 0) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002786 VkDebugReportCallbackEXT callback = my_data->logging_callback.back();
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002787 layer_destroy_msg_callback(my_data->report_data, callback, pAllocator);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002788 my_data->logging_callback.pop_back();
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002789 }
2790
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06002791 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002792 delete my_data->instance_dispatch_table;
2793 layer_data_map.erase(key);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002794 // TODO : Potential race here with separate threads creating/destroying instance
Tobin Ehlis0b632332015-10-07 09:38:40 -06002795 if (layer_data_map.empty()) {
Mike Stroyanfcb4ba62015-08-18 15:56:18 -06002796 // Release mutex when destroying last instance.
2797 loader_platform_thread_delete_mutex(&globalLock);
2798 globalLockInitialized = 0;
2799 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002800}
2801
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002802static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
2803{
Tony Barbour3b4732f2015-07-13 13:37:24 -06002804 uint32_t i;
Tobin Ehlis0b632332015-10-07 09:38:40 -06002805 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
2806 dev_data->device_extensions.debug_marker_enabled = false;
Michael Lentineabc5e922015-10-12 11:30:14 -05002807 dev_data->device_extensions.wsi_enabled = false;
2808
2809
2810 VkLayerDispatchTable *pDisp = dev_data->device_dispatch_table;
2811 PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr;
2812
Michael Lentineabc5e922015-10-12 11:30:14 -05002813 pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR) gpa(device, "vkCreateSwapchainKHR");
2814 pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR) gpa(device, "vkDestroySwapchainKHR");
2815 pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR) gpa(device, "vkGetSwapchainImagesKHR");
2816 pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR) gpa(device, "vkAcquireNextImageKHR");
2817 pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR) gpa(device, "vkQueuePresentKHR");
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002818
Chia-I Wud50a7d72015-10-26 20:48:51 +08002819 for (i = 0; i < pCreateInfo->enabledExtensionNameCount; i++) {
Ian Elliott05846062015-11-20 14:13:17 -07002820 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) {
Michael Lentineabc5e922015-10-12 11:30:14 -05002821 dev_data->device_extensions.wsi_enabled = true;
2822 }
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002823 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
Jon Ashburneab34492015-06-01 09:37:38 -06002824 /* Found a matching extension name, mark it enabled and init dispatch table*/
Tobin Ehlis0b632332015-10-07 09:38:40 -06002825 dev_data->device_extensions.debug_marker_enabled = true;
Jon Ashburn1d4b1282015-12-10 19:12:21 -07002826 initDebugMarkerTable(device);
2827
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002828 }
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002829 }
2830}
2831
Chia-I Wu9ab61502015-11-06 06:42:02 +08002832VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDevice* pDevice)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002833{
Tobin Ehlis0b632332015-10-07 09:38:40 -06002834 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08002835 VkResult result = dev_data->device_dispatch_table->CreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002836 // TODOSC : shouldn't need any customization here
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002837 if (result == VK_SUCCESS) {
2838 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002839 dev_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
Jon Ashburn747f2b62015-06-18 15:02:58 -06002840 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002841 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002842 return result;
2843}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002844
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002845// prototype
2846static void deleteRenderPasses(layer_data*);
Chia-I Wu9ab61502015-11-06 06:42:02 +08002847VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002848{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002849 // TODOSC : Shouldn't need any customization here
Jeremy Hayes5d29ce32015-06-19 11:37:38 -06002850 dispatch_key key = get_dispatch_key(device);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002851 layer_data* dev_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002852 // Free all the memory
2853 loader_platform_thread_lock_mutex(&globalLock);
2854 deletePipelines(dev_data);
2855 deleteRenderPasses(dev_data);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002856 deleteCommandBuffers(dev_data);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002857 deletePools(dev_data);
2858 deleteLayouts(dev_data);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002859 dev_data->imageViewMap.clear();
2860 dev_data->imageMap.clear();
2861 dev_data->bufferViewMap.clear();
2862 dev_data->bufferMap.clear();
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002863 loader_platform_thread_unlock_mutex(&globalLock);
2864
Chia-I Wuf7458c52015-10-26 21:10:41 +08002865 dev_data->device_dispatch_table->DestroyDevice(device, pAllocator);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002866 tableDebugMarkerMap.erase(key);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002867 delete dev_data->device_dispatch_table;
2868 layer_data_map.erase(key);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002869}
2870
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07002871static const VkExtensionProperties instance_extensions[] = {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002872 {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002873 VK_EXT_DEBUG_REPORT_EXTENSION_NAME,
2874 VK_EXT_DEBUG_REPORT_REVISION
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002875 }
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06002876};
2877
Chia-I Wu9ab61502015-11-06 06:42:02 +08002878VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002879 const char *pLayerName,
2880 uint32_t *pCount,
2881 VkExtensionProperties* pProperties)
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06002882{
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07002883 return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002884}
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06002885
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07002886static const VkLayerProperties ds_global_layers[] = {
2887 {
Michael Lentine03107b42015-12-11 10:49:51 -08002888 "VK_LAYER_LUNARG_draw_state",
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07002889 VK_API_VERSION,
2890 VK_MAKE_VERSION(0, 1, 0),
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -07002891 "Validation layer: draw_state",
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07002892 }
2893};
2894
Chia-I Wu9ab61502015-11-06 06:42:02 +08002895VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002896 uint32_t *pCount,
2897 VkLayerProperties* pProperties)
2898{
2899 return util_GetLayerProperties(ARRAY_SIZE(ds_global_layers),
2900 ds_global_layers,
2901 pCount, pProperties);
2902}
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06002903
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002904static const VkExtensionProperties ds_device_extensions[] = {
2905 {
2906 DEBUG_MARKER_EXTENSION_NAME,
2907 VK_MAKE_VERSION(0, 1, 0),
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002908 }
2909};
2910
2911static const VkLayerProperties ds_device_layers[] = {
2912 {
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -07002913 "draw_state",
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002914 VK_API_VERSION,
2915 VK_MAKE_VERSION(0, 1, 0),
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -07002916 "Validation layer: draw_state",
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002917 }
2918};
2919
Chia-I Wu9ab61502015-11-06 06:42:02 +08002920VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002921 VkPhysicalDevice physicalDevice,
2922 const char* pLayerName,
2923 uint32_t* pCount,
2924 VkExtensionProperties* pProperties)
2925{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07002926 // DrawState does not have any physical device extensions
Jon Ashburn751c4842015-11-02 17:37:20 -07002927 if (pLayerName == NULL) {
2928 dispatch_key key = get_dispatch_key(physicalDevice);
2929 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07002930 return my_data->instance_dispatch_table->EnumerateDeviceExtensionProperties(
Jon Ashburn751c4842015-11-02 17:37:20 -07002931 physicalDevice,
2932 NULL,
2933 pCount,
2934 pProperties);
2935 } else {
2936 return util_GetExtensionProperties(ARRAY_SIZE(ds_device_extensions),
2937 ds_device_extensions,
2938 pCount, pProperties);
2939 }
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002940}
2941
Chia-I Wu9ab61502015-11-06 06:42:02 +08002942VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002943 VkPhysicalDevice physicalDevice,
2944 uint32_t* pCount,
2945 VkLayerProperties* pProperties)
2946{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07002947 /* DrawState physical device layers are the same as global */
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002948 return util_GetLayerProperties(ARRAY_SIZE(ds_device_layers), ds_device_layers,
2949 pCount, pProperties);
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06002950}
2951
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07002952VkBool32 ValidateCmdBufImageLayouts(VkCommandBuffer cmdBuffer) {
2953 VkBool32 skip_call = false;
Michael Lentineabc5e922015-10-12 11:30:14 -05002954 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
2955 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
2956 for (auto cb_image_data : pCB->imageLayoutMap) {
2957 auto image_data = dev_data->imageLayoutMap.find(cb_image_data.first);
2958 if (image_data == dev_data->imageLayoutMap.end()) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002959 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentine010f4692015-11-03 16:19:46 -08002960 "Cannot submit cmd buffer using deleted image %" PRIu64 ".", reinterpret_cast<uint64_t>(cb_image_data.first));
Michael Lentineabc5e922015-10-12 11:30:14 -05002961 } else {
2962 if (dev_data->imageLayoutMap[cb_image_data.first]->layout != cb_image_data.second.initialLayout) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002963 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05002964 "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);
2965 }
2966 dev_data->imageLayoutMap[cb_image_data.first]->layout = cb_image_data.second.layout;
2967 }
2968 }
2969 return skip_call;
2970}
2971
Chia-I Wu9ab61502015-11-06 06:42:02 +08002972VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence fence)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002973{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002974 VkBool32 skipCall = VK_FALSE;
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06002975 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlis0b632332015-10-07 09:38:40 -06002976 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Tobin Ehlis651d9b02015-12-16 05:01:22 -07002977 // TODO : Any pCommandBuffers must have USAGE_SIMULTANEOUS_USE_BIT set or cannot already be executing on device
2978 // Same goes for any secondary CBs under the primary CB
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002979 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08002980 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Chia-I Wud50a7d72015-10-26 20:48:51 +08002981 for (uint32_t i=0; i < submit->commandBufferCount; i++) {
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07002982
2983#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
2984 skipCall |= ValidateCmdBufImageLayouts(submit->pCommandBuffers[i]);
2985#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
2986
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002987 // Validate that cmd buffers have been updated
2988 pCB = getCBNode(dev_data, submit->pCommandBuffers[i]);
2989 loader_platform_thread_lock_mutex(&globalLock);
2990 pCB->submitCount++; // increment submit count
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002991 if ((pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT) && (pCB->submitCount > 1)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002992 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, 0, DRAWSTATE_COMMAND_BUFFER_SINGLE_SUBMIT_VIOLATION, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05002993 "CB %#" PRIxLEAST64 " was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted %#" PRIxLEAST64 " times.",
2994 reinterpret_cast<uint64_t>(pCB->commandBuffer), pCB->submitCount);
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002995 }
Tobin Ehlisac0ef842015-12-14 13:46:38 -07002996 if (CB_RECORDED != pCB->state) {
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002997 // Flag error for using CB w/o vkEndCommandBuffer() called
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002998 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, 0, DRAWSTATE_NO_END_COMMAND_BUFFER, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002999 "You must call vkEndCommandBuffer() on CB %#" PRIxLEAST64 " before this call to vkQueueSubmit()!", reinterpret_cast<uint64_t>(pCB->commandBuffer));
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003000 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003001 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003002 }
Tobin Ehlisc4bdde12015-05-27 14:30:06 -06003003 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06003004 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003005 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003006 if (VK_FALSE == skipCall)
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08003007 return dev_data->device_dispatch_table->QueueSubmit(queue, submitCount, pSubmits, fence);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003008 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003009}
3010
Chia-I Wu9ab61502015-11-06 06:42:02 +08003011VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003012{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003013 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroyFence(device, fence, pAllocator);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003014 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003015}
3016
Chia-I Wu9ab61502015-11-06 06:42:02 +08003017VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySemaphore(VkDevice device, VkSemaphore semaphore, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003018{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003019 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroySemaphore(device, semaphore, pAllocator);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003020 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003021}
3022
Chia-I Wu9ab61502015-11-06 06:42:02 +08003023VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003024{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003025 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroyEvent(device, event, pAllocator);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003026 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003027}
3028
Chia-I Wu9ab61502015-11-06 06:42:02 +08003029VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003030{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003031 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroyQueryPool(device, queryPool, pAllocator);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003032 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003033}
3034
Chia-I Wu9ab61502015-11-06 06:42:02 +08003035VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003036{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003037 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003038 dev_data->device_dispatch_table->DestroyBuffer(device, buffer, pAllocator);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003039 dev_data->bufferMap.erase(buffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003040}
3041
Chia-I Wu9ab61502015-11-06 06:42:02 +08003042VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBufferView(VkDevice device, VkBufferView bufferView, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003043{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003044 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003045 dev_data->device_dispatch_table->DestroyBufferView(device, bufferView, pAllocator);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003046 dev_data->bufferViewMap.erase(bufferView);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003047}
3048
Chia-I Wu9ab61502015-11-06 06:42:02 +08003049VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003050{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003051 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003052 dev_data->device_dispatch_table->DestroyImage(device, image, pAllocator);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003053 dev_data->imageMap.erase(image);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003054}
3055
Chia-I Wu9ab61502015-11-06 06:42:02 +08003056VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyImageView(VkDevice device, VkImageView imageView, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003057{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003058 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroyImageView(device, imageView, pAllocator);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003059 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003060}
3061
Chia-I Wu9ab61502015-11-06 06:42:02 +08003062VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003063{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003064 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroyShaderModule(device, shaderModule, pAllocator);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003065 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003066}
3067
Chia-I Wu9ab61502015-11-06 06:42:02 +08003068VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyPipeline(VkDevice device, VkPipeline pipeline, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003069{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003070 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroyPipeline(device, pipeline, pAllocator);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003071 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003072}
3073
Chia-I Wu9ab61502015-11-06 06:42:02 +08003074VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003075{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003076 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroyPipelineLayout(device, pipelineLayout, pAllocator);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003077 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003078}
3079
Chia-I Wu9ab61502015-11-06 06:42:02 +08003080VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySampler(VkDevice device, VkSampler sampler, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003081{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003082 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroySampler(device, sampler, pAllocator);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003083 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003084}
3085
Chia-I Wu9ab61502015-11-06 06:42:02 +08003086VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003087{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003088 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroyDescriptorSetLayout(device, descriptorSetLayout, pAllocator);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003089 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003090}
3091
Chia-I Wu9ab61502015-11-06 06:42:02 +08003092VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003093{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003094 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroyDescriptorPool(device, descriptorPool, pAllocator);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003095 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003096}
3097
Chia-I Wu9ab61502015-11-06 06:42:02 +08003098VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t count, const VkCommandBuffer *pCommandBuffers)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003099{
Mark Lobodzinski39298632015-11-18 08:38:27 -07003100 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3101
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07003102 for (uint32_t i = 0; i < count; i++) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003103 // Delete CB information structure, and remove from commandBufferMap
3104 auto cb = dev_data->commandBufferMap.find(pCommandBuffers[i]);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003105 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003106 if (cb != dev_data->commandBufferMap.end()) {
3107 delete (*cb).second;
3108 dev_data->commandBufferMap.erase(cb);
3109 }
3110
3111 // Remove commandBuffer reference from commandPoolMap
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003112 dev_data->commandPoolMap[commandPool].commandBuffers.remove(pCommandBuffers[i]);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003113 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003114 }
3115
3116 dev_data->device_dispatch_table->FreeCommandBuffers(device, commandPool, count, pCommandBuffers);
3117}
3118
3119VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkCommandPool* pCommandPool)
3120{
3121 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3122
3123 VkResult result = dev_data->device_dispatch_table->CreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
3124
3125 if (VK_SUCCESS == result) {
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003126 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003127 dev_data->commandPoolMap[*pCommandPool].createFlags = pCreateInfo->flags;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003128 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003129 }
3130 return result;
3131}
3132
3133VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks* pAllocator)
3134{
3135 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003136 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003137
3138 // Must remove cmdpool from cmdpoolmap, after removing all cmdbuffers in its list from the commandPoolMap
3139 if (dev_data->commandPoolMap.find(commandPool) != dev_data->commandPoolMap.end()) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003140 for (auto poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.begin(); poolCb != dev_data->commandPoolMap[commandPool].commandBuffers.end();) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003141 auto del_cb = dev_data->commandBufferMap.find(*poolCb);
3142 delete (*del_cb).second; // delete CB info structure
3143 dev_data->commandBufferMap.erase(del_cb); // Remove this command buffer from cbMap
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003144 poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.erase(poolCb); // Remove CB reference from commandPoolMap's list
Mark Lobodzinski39298632015-11-18 08:38:27 -07003145 }
3146 }
3147 dev_data->commandPoolMap.erase(commandPool);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003148
3149 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003150 dev_data->device_dispatch_table->DestroyCommandPool(device, commandPool, pAllocator);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003151}
3152
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003153VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandPool(
3154 VkDevice device,
3155 VkCommandPool commandPool,
3156 VkCommandPoolResetFlags flags)
3157{
3158 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003159 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003160
3161 result = dev_data->device_dispatch_table->ResetCommandPool(device, commandPool, flags);
3162 // Reset all of the CBs allocated from this pool
3163 if (VK_SUCCESS == result) {
3164 auto it = dev_data->commandPoolMap[commandPool].commandBuffers.begin();
3165 while (it != dev_data->commandPoolMap[commandPool].commandBuffers.end()) {
3166 resetCB(dev_data, (*it));
3167 ++it;
3168 }
3169 }
3170 return result;
3171}
3172
Chia-I Wu9ab61502015-11-06 06:42:02 +08003173VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003174{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003175 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroyFramebuffer(device, framebuffer, pAllocator);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003176 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003177}
3178
Chia-I Wu9ab61502015-11-06 06:42:02 +08003179VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003180{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003181 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroyRenderPass(device, renderPass, pAllocator);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003182 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003183}
3184
Chia-I Wu9ab61502015-11-06 06:42:02 +08003185VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateBuffer(VkDevice device, const VkBufferCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkBuffer* pBuffer)
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003186{
3187 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003188 VkResult result = dev_data->device_dispatch_table->CreateBuffer(device, pCreateInfo, pAllocator, pBuffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003189 if (VK_SUCCESS == result) {
3190 loader_platform_thread_lock_mutex(&globalLock);
3191 // 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 Wue2fc5522015-10-26 20:04:44 +08003192 dev_data->bufferMap[*pBuffer] = unique_ptr<VkBufferCreateInfo>(new VkBufferCreateInfo(*pCreateInfo));
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003193 loader_platform_thread_unlock_mutex(&globalLock);
3194 }
3195 return result;
3196}
3197
Chia-I Wu9ab61502015-11-06 06:42:02 +08003198VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkBufferView* pView)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003199{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003200 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003201 VkResult result = dev_data->device_dispatch_table->CreateBufferView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003202 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003203 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003204 dev_data->bufferViewMap[*pView] = unique_ptr<VkBufferViewCreateInfo>(new VkBufferViewCreateInfo(*pCreateInfo));
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003205 loader_platform_thread_unlock_mutex(&globalLock);
3206 }
3207 return result;
3208}
3209
Chia-I Wu9ab61502015-11-06 06:42:02 +08003210VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateImage(VkDevice device, const VkImageCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkImage* pImage)
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003211{
3212 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003213 VkResult result = dev_data->device_dispatch_table->CreateImage(device, pCreateInfo, pAllocator, pImage);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003214 if (VK_SUCCESS == result) {
Michael Lentineabc5e922015-10-12 11:30:14 -05003215 IMAGE_NODE* image_node = new IMAGE_NODE;
3216 image_node->layout = pCreateInfo->initialLayout;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003217 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003218 dev_data->imageMap[*pImage] = unique_ptr<VkImageCreateInfo>(new VkImageCreateInfo(*pCreateInfo));
Michael Lentineabc5e922015-10-12 11:30:14 -05003219 dev_data->imageLayoutMap[*pImage] = image_node;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003220 loader_platform_thread_unlock_mutex(&globalLock);
3221 }
3222 return result;
3223}
3224
Chia-I Wu9ab61502015-11-06 06:42:02 +08003225VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkImageView* pView)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003226{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003227 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003228 VkResult result = dev_data->device_dispatch_table->CreateImageView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003229 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003230 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003231 dev_data->imageViewMap[*pView] = unique_ptr<VkImageViewCreateInfo>(new VkImageViewCreateInfo(*pCreateInfo));
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003232 loader_platform_thread_unlock_mutex(&globalLock);
3233 }
3234 return result;
3235}
3236
Jon Ashburnc669cc62015-07-09 15:02:25 -06003237//TODO handle pipeline caches
Chia-I Wu9ab61502015-11-06 06:42:02 +08003238VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineCache(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003239 VkDevice device,
3240 const VkPipelineCacheCreateInfo* pCreateInfo,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003241 const VkAllocationCallbacks* pAllocator,
Jon Ashburnc669cc62015-07-09 15:02:25 -06003242 VkPipelineCache* pPipelineCache)
3243{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003244 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003245 VkResult result = dev_data->device_dispatch_table->CreatePipelineCache(device, pCreateInfo, pAllocator, pPipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003246 return result;
3247}
3248
Chia-I Wu9ab61502015-11-06 06:42:02 +08003249VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineCache(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003250 VkDevice device,
Chia-I Wuf7458c52015-10-26 21:10:41 +08003251 VkPipelineCache pipelineCache,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003252 const VkAllocationCallbacks* pAllocator)
Jon Ashburnc669cc62015-07-09 15:02:25 -06003253{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003254 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003255 dev_data->device_dispatch_table->DestroyPipelineCache(device, pipelineCache, pAllocator);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003256}
3257
Chia-I Wu9ab61502015-11-06 06:42:02 +08003258VKAPI_ATTR VkResult VKAPI_CALL vkGetPipelineCacheData(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003259 VkDevice device,
3260 VkPipelineCache pipelineCache,
Chia-I Wub16facd2015-10-26 19:17:06 +08003261 size_t* pDataSize,
Jon Ashburnc669cc62015-07-09 15:02:25 -06003262 void* pData)
3263{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003264 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wub16facd2015-10-26 19:17:06 +08003265 VkResult result = dev_data->device_dispatch_table->GetPipelineCacheData(device, pipelineCache, pDataSize, pData);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003266 return result;
3267}
3268
Chia-I Wu9ab61502015-11-06 06:42:02 +08003269VKAPI_ATTR VkResult VKAPI_CALL vkMergePipelineCaches(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003270 VkDevice device,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003271 VkPipelineCache dstCache,
Jon Ashburnc669cc62015-07-09 15:02:25 -06003272 uint32_t srcCacheCount,
3273 const VkPipelineCache* pSrcCaches)
3274{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003275 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003276 VkResult result = dev_data->device_dispatch_table->MergePipelineCaches(device, dstCache, srcCacheCount, pSrcCaches);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003277 return result;
3278}
3279
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003280VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateGraphicsPipelines(
3281 VkDevice device,
3282 VkPipelineCache pipelineCache,
3283 uint32_t count,
3284 const VkGraphicsPipelineCreateInfo *pCreateInfos,
3285 const VkAllocationCallbacks *pAllocator,
3286 VkPipeline *pPipelines)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003287{
Courtney Goeltzenleuchtered894072015-09-04 13:39:59 -06003288 VkResult result = VK_SUCCESS;
Tobin Ehlis11efc302015-09-16 10:33:53 -06003289 //TODO What to do with pipelineCache?
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003290 // The order of operations here is a little convoluted but gets the job done
3291 // 1. Pipeline create state is first shadowed into PIPELINE_NODE struct
3292 // 2. Create state is then validated (which uses flags setup during shadowing)
3293 // 3. If everything looks good, we'll then create the pipeline and add NODE to pipelineMap
Tobin Ehlis11efc302015-09-16 10:33:53 -06003294 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis65399772015-09-17 16:33:58 -06003295 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
3296 vector<PIPELINE_NODE*> pPipeNode(count);
Tobin Ehlis0b632332015-10-07 09:38:40 -06003297 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003298
Tobin Ehlis11efc302015-09-16 10:33:53 -06003299 uint32_t i=0;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003300 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003301
Tobin Ehlis11efc302015-09-16 10:33:53 -06003302 for (i=0; i<count; i++) {
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003303 pPipeNode[i] = initGraphicsPipeline(dev_data, &pCreateInfos[i], NULL);
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06003304 skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
Tobin Ehlis11efc302015-09-16 10:33:53 -06003305 }
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003306
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003307 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003308
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07003309 if (VK_FALSE == skipCall) {
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003310 result = dev_data->device_dispatch_table->CreateGraphicsPipelines(device,
3311 pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003312 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis11efc302015-09-16 10:33:53 -06003313 for (i=0; i<count; i++) {
3314 pPipeNode[i]->pipeline = pPipelines[i];
Chia-I Wue2fc5522015-10-26 20:04:44 +08003315 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
Tobin Ehlis11efc302015-09-16 10:33:53 -06003316 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003317 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisce132d82015-06-19 15:07:05 -06003318 } else {
Tobin Ehlis11efc302015-09-16 10:33:53 -06003319 for (i=0; i<count; i++) {
3320 if (pPipeNode[i]) {
3321 // If we allocated a pipeNode, need to clean it up here
3322 delete[] pPipeNode[i]->pVertexBindingDescriptions;
3323 delete[] pPipeNode[i]->pVertexAttributeDescriptions;
3324 delete[] pPipeNode[i]->pAttachments;
3325 delete pPipeNode[i];
3326 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003327 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003328 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003329 }
Courtney Goeltzenleuchtere2aaad02015-04-13 16:16:04 -06003330 return result;
3331}
3332
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003333VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateComputePipelines(
3334 VkDevice device,
3335 VkPipelineCache pipelineCache,
3336 uint32_t count,
3337 const VkComputePipelineCreateInfo *pCreateInfos,
3338 const VkAllocationCallbacks *pAllocator,
3339 VkPipeline *pPipelines)
3340{
3341 VkResult result = VK_SUCCESS;
3342 VkBool32 skipCall = VK_FALSE;
3343
3344 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
3345 vector<PIPELINE_NODE*> pPipeNode(count);
3346 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3347
3348 uint32_t i=0;
3349 loader_platform_thread_lock_mutex(&globalLock);
3350 for (i=0; i<count; i++) {
3351 // TODO: Verify compute stage bits
3352
3353 // Create and initialize internal tracking data structure
3354 pPipeNode[i] = new PIPELINE_NODE;
3355 memset((void*)pPipeNode[i], 0, sizeof(PIPELINE_NODE));
3356 memcpy(&pPipeNode[i]->computePipelineCI, (const void*)&pCreateInfos[i], sizeof(VkComputePipelineCreateInfo));
3357
3358 // TODO: Add Compute Pipeline Verification
3359 // skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
3360 }
3361 loader_platform_thread_unlock_mutex(&globalLock);
3362
3363 if (VK_FALSE == skipCall) {
3364 result = dev_data->device_dispatch_table->CreateComputePipelines(device, pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
3365 loader_platform_thread_lock_mutex(&globalLock);
3366 for (i=0; i<count; i++) {
3367 pPipeNode[i]->pipeline = pPipelines[i];
3368 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
3369 }
3370 loader_platform_thread_unlock_mutex(&globalLock);
3371 } else {
3372 for (i=0; i<count; i++) {
3373 if (pPipeNode[i]) {
3374 // Clean up any locally allocated data structures
3375 delete pPipeNode[i];
3376 }
3377 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003378 return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003379 }
3380 return result;
3381}
3382
Chia-I Wu9ab61502015-11-06 06:42:02 +08003383VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSampler* pSampler)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003384{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003385 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003386 VkResult result = dev_data->device_dispatch_table->CreateSampler(device, pCreateInfo, pAllocator, pSampler);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003387 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003388 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003389 dev_data->sampleMap[*pSampler] = unique_ptr<SAMPLER_NODE>(new SAMPLER_NODE(pSampler, pCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003390 loader_platform_thread_unlock_mutex(&globalLock);
3391 }
3392 return result;
3393}
3394
Chia-I Wu9ab61502015-11-06 06:42:02 +08003395VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDescriptorSetLayout* pSetLayout)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003396{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003397 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003398 VkResult result = dev_data->device_dispatch_table->CreateDescriptorSetLayout(device, pCreateInfo, pAllocator, pSetLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003399 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003400 // TODOSC : Capture layout bindings set
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003401 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
3402 if (NULL == pNewNode) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003403 if (log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, (uint64_t) *pSetLayout, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003404 "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003405 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003406 }
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06003407 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003408 pNewNode->createInfo.pBindings = new VkDescriptorSetLayoutBinding[pCreateInfo->bindingCount];
3409 memcpy((void*)pNewNode->createInfo.pBindings, pCreateInfo->pBindings, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->bindingCount);
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003410 // g++ does not like reserve with size 0
3411 if (pCreateInfo->bindingCount)
3412 pNewNode->bindings.reserve(pCreateInfo->bindingCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003413 uint32_t totalCount = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003414 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003415 if (!pNewNode->bindings.insert(pCreateInfo->pBindings[i].binding).second) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003416 if (log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, (uint64_t) *pSetLayout, 0, DRAWSTATE_INVALID_LAYOUT, "DS",
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003417 "duplicated binding number in VkDescriptorSetLayoutBinding"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003418 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003419 }
3420
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003421 totalCount += pCreateInfo->pBindings[i].descriptorCount;
3422 if (pCreateInfo->pBindings[i].pImmutableSamplers) {
3423 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBindings[i].pImmutableSamplers;
3424 *ppIS = new VkSampler[pCreateInfo->pBindings[i].descriptorCount];
3425 memcpy(*ppIS, pCreateInfo->pBindings[i].pImmutableSamplers, pCreateInfo->pBindings[i].descriptorCount*sizeof(VkSampler));
Tobin Ehlis793ad302015-04-03 12:01:11 -06003426 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003427 }
3428 if (totalCount > 0) {
Cody Northrop43751cc2015-10-26 14:07:35 -06003429 pNewNode->descriptorTypes.resize(totalCount);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06003430 pNewNode->stageFlags.resize(totalCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003431 uint32_t offset = 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06003432 uint32_t j = 0;
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07003433 VkDescriptorType dType;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003434 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003435 dType = pCreateInfo->pBindings[i].descriptorType;
3436 for (j = 0; j < pCreateInfo->pBindings[i].descriptorCount; j++) {
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07003437 pNewNode->descriptorTypes[offset + j] = dType;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003438 pNewNode->stageFlags[offset + j] = pCreateInfo->pBindings[i].stageFlags;
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07003439 if ((dType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
3440 (dType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
3441 pNewNode->dynamicDescriptorCount++;
3442 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003443 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06003444 offset += j;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003445 }
3446 }
3447 pNewNode->layout = *pSetLayout;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003448 pNewNode->startIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003449 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
3450 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003451 // Put new node at Head of global Layer list
3452 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07003453 dev_data->descriptorSetLayoutMap[*pSetLayout] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003454 loader_platform_thread_unlock_mutex(&globalLock);
3455 }
3456 return result;
3457}
3458
Chia-I Wu9ab61502015-11-06 06:42:02 +08003459VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003460{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003461 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003462 VkResult result = dev_data->device_dispatch_table->CreatePipelineLayout(device, pCreateInfo, pAllocator, pPipelineLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003463 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003464 // TODOSC : Merge capture of the setLayouts per pipeline
Tobin Ehlis559c6382015-11-05 09:52:49 -07003465 PIPELINE_LAYOUT_NODE& plNode = dev_data->pipelineLayoutMap[*pPipelineLayout];
Chia-I Wud50a7d72015-10-26 20:48:51 +08003466 plNode.descriptorSetLayouts.resize(pCreateInfo->setLayoutCount);
Tobin Ehlis644ff042015-10-20 10:11:55 -06003467 uint32_t i = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003468 for (i=0; i<pCreateInfo->setLayoutCount; ++i) {
Tobin Ehlis644ff042015-10-20 10:11:55 -06003469 plNode.descriptorSetLayouts[i] = pCreateInfo->pSetLayouts[i];
3470 }
Cody Northrop43751cc2015-10-26 14:07:35 -06003471 plNode.pushConstantRanges.resize(pCreateInfo->pushConstantRangeCount);
Tobin Ehlis644ff042015-10-20 10:11:55 -06003472 for (i=0; i<pCreateInfo->pushConstantRangeCount; ++i) {
3473 plNode.pushConstantRanges[i] = pCreateInfo->pPushConstantRanges[i];
3474 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06003475 }
3476 return result;
3477}
3478
Chia-I Wu9ab61502015-11-06 06:42:02 +08003479VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDescriptorPool* pDescriptorPool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003480{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003481 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003482 VkResult result = dev_data->device_dispatch_table->CreateDescriptorPool(device, pCreateInfo, pAllocator, pDescriptorPool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003483 if (VK_SUCCESS == result) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06003484 // Insert this pool into Global Pool LL at head
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003485 if (log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, (uint64_t) *pDescriptorPool, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08003486 "Created Descriptor Pool %#" PRIxLEAST64, (uint64_t) *pDescriptorPool))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003487 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003488 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003489 DESCRIPTOR_POOL_NODE* pNewNode = new DESCRIPTOR_POOL_NODE(*pDescriptorPool, pCreateInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003490 if (NULL == pNewNode) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003491 if (log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, (uint64_t) *pDescriptorPool, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
Mark Lobodzinski39298632015-11-18 08:38:27 -07003492 "Out of memory while attempting to allocate DESCRIPTOR_POOL_NODE in vkCreateDescriptorPool()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003493 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisce132d82015-06-19 15:07:05 -06003494 } else {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003495 dev_data->descriptorPoolMap[*pDescriptorPool] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003496 }
3497 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisce132d82015-06-19 15:07:05 -06003498 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06003499 // Need to do anything if pool create fails?
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003500 }
3501 return result;
3502}
3503
Chia-I Wu9ab61502015-11-06 06:42:02 +08003504VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorPoolResetFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003505{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003506 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003507 VkResult result = dev_data->device_dispatch_table->ResetDescriptorPool(device, descriptorPool, flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003508 if (VK_SUCCESS == result) {
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003509 clearDescriptorPool(dev_data, device, descriptorPool, flags);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003510 }
3511 return result;
3512}
3513
Chia-I Wu9ab61502015-11-06 06:42:02 +08003514VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo* pAllocateInfo, VkDescriptorSet* pDescriptorSets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003515{
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003516 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis0b632332015-10-07 09:38:40 -06003517 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003518 // Verify that requested descriptorSets are available in pool
Mark Lobodzinski39298632015-11-18 08:38:27 -07003519 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003520 if (!pPoolNode) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003521 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, (uint64_t) pAllocateInfo->descriptorPool, 0, DRAWSTATE_INVALID_POOL, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003522 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003523 } else { // Make sure pool has all the available descriptors before calling down chain
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003524 skipCall |= validate_descriptor_availability_in_pool(dev_data, pPoolNode, pAllocateInfo->setLayoutCount, pAllocateInfo->pSetLayouts);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003525 }
3526 if (skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003527 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003528 VkResult result = dev_data->device_dispatch_table->AllocateDescriptorSets(device, pAllocateInfo, pDescriptorSets);
Cody Northrop1e4f8022015-08-03 12:47:29 -06003529 if (VK_SUCCESS == result) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003530 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003531 if (pPoolNode) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003532 if (pAllocateInfo->setLayoutCount == 0) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003533 log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, pAllocateInfo->setLayoutCount, 0, DRAWSTATE_NONE, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003534 "AllocateDescriptorSets called with 0 count");
Cody Northrop1e4f8022015-08-03 12:47:29 -06003535 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003536 for (uint32_t i = 0; i < pAllocateInfo->setLayoutCount; i++) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003537 log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pDescriptorSets[i], 0, DRAWSTATE_NONE, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08003538 "Created Descriptor Set %#" PRIxLEAST64, (uint64_t) pDescriptorSets[i]);
Tobin Ehlis793ad302015-04-03 12:01:11 -06003539 // Create new set node and add to head of pool nodes
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003540 SET_NODE* pNewNode = new SET_NODE;
3541 if (NULL == pNewNode) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003542 if (log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pDescriptorSets[i], 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003543 "Out of memory while attempting to allocate SET_NODE in vkAllocateDescriptorSets()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003544 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisce132d82015-06-19 15:07:05 -06003545 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003546 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlis8b5b28c2015-10-19 12:09:13 -06003547 // TODO : Pool should store a total count of each type of Descriptor available
3548 // When descriptors are allocated, decrement the count and validate here
3549 // that the count doesn't go below 0. One reset/free need to bump count back up.
Tobin Ehlis793ad302015-04-03 12:01:11 -06003550 // Insert set at head of Set LL for this pool
3551 pNewNode->pNext = pPoolNode->pSets;
3552 pPoolNode->pSets = pNewNode;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003553 LAYOUT_NODE* pLayout = getLayoutNode(dev_data, pAllocateInfo->pSetLayouts[i]);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003554 if (NULL == pLayout) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003555 if (log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, (uint64_t) pAllocateInfo->pSetLayouts[i], 0, DRAWSTATE_INVALID_LAYOUT, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003556 "Unable to find set layout node for layout %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pAllocateInfo->pSetLayouts[i]))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003557 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003558 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06003559 pNewNode->pLayout = pLayout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003560 pNewNode->pool = pAllocateInfo->descriptorPool;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003561 pNewNode->set = pDescriptorSets[i];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003562 pNewNode->descriptorCount = pLayout->endIndex + 1;
3563 if (pNewNode->descriptorCount) {
3564 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
3565 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
3566 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
3567 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08003568 dev_data->setMap[pDescriptorSets[i]] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003569 }
3570 }
3571 }
3572 }
3573 return result;
3574}
3575
Chia-I Wu9ab61502015-11-06 06:42:02 +08003576VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, const VkDescriptorSet* pDescriptorSets)
Tony Barbour34ec6922015-07-10 10:50:45 -06003577{
Tobin Ehlise735c692015-10-08 13:13:50 -06003578 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis0b632332015-10-07 09:38:40 -06003579 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003580 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, descriptorPool);
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003581 if (pPoolNode && !(VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT & pPoolNode->createInfo.flags)) {
3582 // Can't Free from a NON_FREE pool
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003583 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, (uint64_t)device, 0, DRAWSTATE_CANT_FREE_FROM_NON_FREE_POOL, "DS",
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003584 "It is invalid to call vkFreeDescriptorSets() with a pool created without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Tobin Ehlise735c692015-10-08 13:13:50 -06003585 }
3586 if (skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003587 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis0b632332015-10-07 09:38:40 -06003588 VkResult result = dev_data->device_dispatch_table->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003589 if (VK_SUCCESS == result) {
3590 // For each freed descriptor add it back into the pool as available
3591 for (uint32_t i=0; i<count; ++i) {
Chia-I Wue2fc5522015-10-26 20:04:44 +08003592 SET_NODE* pSet = dev_data->setMap[pDescriptorSets[i]]; // getSetNode() without locking
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003593 LAYOUT_NODE* pLayout = pSet->pLayout;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003594 uint32_t typeIndex = 0, poolSizeCount = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003595 for (uint32_t j=0; j<pLayout->createInfo.bindingCount; ++j) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003596 typeIndex = static_cast<uint32_t>(pLayout->createInfo.pBindings[j].descriptorType);
3597 poolSizeCount = pLayout->createInfo.pBindings[j].descriptorCount;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003598 pPoolNode->availableDescriptorTypeCount[typeIndex] += poolSizeCount;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003599 }
3600 }
3601 }
3602 // TODO : Any other clean-up or book-keeping to do here?
Tony Barbour34ec6922015-07-10 10:50:45 -06003603 return result;
3604}
3605
Chia-I Wu9ab61502015-11-06 06:42:02 +08003606VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount, const VkWriteDescriptorSet* pDescriptorWrites, uint32_t descriptorCopyCount, const VkCopyDescriptorSet* pDescriptorCopies)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003607{
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06003608 // dsUpdate will return VK_TRUE only if a bailout error occurs, so we want to call down tree when update returns VK_FALSE
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06003609 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08003610 if (!dsUpdate(dev_data, device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies)) {
3611 dev_data->device_dispatch_table->UpdateDescriptorSets(device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies);
Jon Ashburn3950e1b2015-05-20 09:00:28 -06003612 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003613}
3614
Chia-I Wu9ab61502015-11-06 06:42:02 +08003615VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo* pCreateInfo, VkCommandBuffer* pCommandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003616{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003617 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003618 VkResult result = dev_data->device_dispatch_table->AllocateCommandBuffers(device, pCreateInfo, pCommandBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003619 if (VK_SUCCESS == result) {
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07003620 for (uint32_t i = 0; i < pCreateInfo->bufferCount; i++) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003621 // Validate command pool
3622 if (dev_data->commandPoolMap.find(pCreateInfo->commandPool) != dev_data->commandPoolMap.end()) {
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003623 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003624 // Add command buffer to its commandPool map
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003625 dev_data->commandPoolMap[pCreateInfo->commandPool].commandBuffers.push_back(pCommandBuffer[i]);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003626 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
3627 // Add command buffer to map
3628 dev_data->commandBufferMap[pCommandBuffer[i]] = pCB;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003629 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003630 resetCB(dev_data, pCommandBuffer[i]);
3631 pCB->commandBuffer = pCommandBuffer[i];
3632 pCB->createInfo = *pCreateInfo;
Mark Lobodzinski39298632015-11-18 08:38:27 -07003633 }
3634 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003635 }
3636 return result;
3637}
3638
Chia-I Wu9ab61502015-11-06 06:42:02 +08003639VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo* pBeginInfo)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003640{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003641 VkBool32 skipCall = false;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003642 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06003643 // Validate command buffer level
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003644 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06003645 if (pCB) {
Mark Lobodzinski85881c72015-11-19 13:22:11 -07003646 if (pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
Chia-I Wue2fc5522015-10-26 20:04:44 +08003647 if (pBeginInfo->renderPass || pBeginInfo->framebuffer) {
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06003648 // These should be NULL for a Primary CB
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003649 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, 0, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
Tobin Ehlis75f6fa92015-12-16 07:17:23 -07003650 "vkBeginCommandBuffer(): Primary Command Buffer (%p) may not specify framebuffer or renderpass parameters.", (void*)commandBuffer);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06003651 }
Tobin Ehlis75f6fa92015-12-16 07:17:23 -07003652 } else { // Secondary Command Buffer
Tobin Ehlis61b36f32015-12-16 08:19:42 -07003653 // TODO : Add check here from spec "If commandBuffer is a secondary command buffer and either the
3654 // occlusionQueryEnable member of pBeginInfo is VK_FALSE, or the precise occlusion queries feature
3655 // is not enabled, the queryFlags member of pBeginInfo must not contain VK_QUERY_CONTROL_PRECISE_BIT"
Tobin Ehlis651d9b02015-12-16 05:01:22 -07003656 if (pBeginInfo->flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT) {
3657 if (!pBeginInfo->renderPass) { // renderpass should NOT be null for an Secondary CB
3658 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, 0, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
3659 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) must specify a valid renderpass parameter.", (void*)commandBuffer);
3660 }
3661 if (!pBeginInfo->framebuffer) { // framebuffer may be null for an Secondary CB, but this affects perf
3662 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, 0, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
3663 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) may perform better if a valid framebuffer parameter is specified.", (void*)commandBuffer);
3664 } else {
3665 string errorString = "";
3666 VkRenderPass fbRP = dev_data->frameBufferMap[pBeginInfo->framebuffer]->renderPass;
3667 if (!verify_renderpass_compatibility(dev_data, fbRP, pBeginInfo->renderPass, errorString)) {
3668 // renderPass that framebuffer was created with must be compatible with local renderPass
3669 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, 0, DRAWSTATE_RENDERPASS_INCOMPATIBLE, "DS",
3670 "vkBeginCommandBuffer(): Secondary Command Buffer (%p) renderPass (%#" PRIxLEAST64 ") is incompatible w/ framebuffer (%#" PRIxLEAST64 ") w/ render pass (%#" PRIxLEAST64 ") due to: %s",
3671 (void*)commandBuffer, (uint64_t)pBeginInfo->renderPass, (uint64_t)pBeginInfo->framebuffer, (uint64_t)fbRP, errorString.c_str());
3672 }
3673 }
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06003674 }
3675 }
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003676 pCB->beginInfo = *pBeginInfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003677 if (CB_RECORDING == pCB->state) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003678 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, 0, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003679 "vkBeginCommandBuffer(): Cannot call Begin on CB (%#" PRIxLEAST64 ") in the RECORDING state. Must first call vkEndCommandBuffer().", (uint64_t)commandBuffer);
3680 } else if (CB_RECORDED == pCB->state) {
3681 VkCommandPool cmdPool = pCB->createInfo.commandPool;
3682 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003683 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer,
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003684 0, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
3685 "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.",
3686 (uint64_t) commandBuffer, (uint64_t) cmdPool);
3687 }
3688 }
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003689 } else {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003690 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, 0, DRAWSTATE_INVALID_COMMAND_BUFFER, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003691 "In vkBeginCommandBuffer() and unable to find CommandBuffer Node for CB %p!", (void*)commandBuffer);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06003692 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003693 if (skipCall) {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003694 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter5fe086f2015-09-04 15:03:52 -06003695 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003696 VkResult result = dev_data->device_dispatch_table->BeginCommandBuffer(commandBuffer, pBeginInfo);
Mark Lobodzinski29b8d5a2015-11-12 16:14:04 -07003697 if ((VK_SUCCESS == result) && (pCB != NULL)) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07003698 if (CB_RECORDED == pCB->state) { resetCB(dev_data, commandBuffer); } pCB->state = CB_RECORDING; }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003699 return result;
3700}
3701
Chia-I Wu9ab61502015-11-06 06:42:02 +08003702VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEndCommandBuffer(VkCommandBuffer commandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003703{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003704 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchtered894072015-09-04 13:39:59 -06003705 VkResult result = VK_SUCCESS;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003706 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3707 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis9c536442015-06-19 13:00:59 -06003708 if (pCB) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003709 if (pCB->state != CB_RECORDING) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003710 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkEndCommandBuffer()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003711 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003712 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003713 if (VK_FALSE == skipCall) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003714 result = dev_data->device_dispatch_table->EndCommandBuffer(commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003715 if (VK_SUCCESS == result) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003716 pCB->state = CB_RECORDED;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003717 // Reset CB status flags
3718 pCB->status = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003719 printCB(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003720 }
3721 } else {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003722 result = VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003723 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003724 return result;
3725}
3726
Chia-I Wu9ab61502015-11-06 06:42:02 +08003727VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003728{
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003729 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003730 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003731 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
3732 VkCommandPool cmdPool = pCB->createInfo.commandPool;
3733 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003734 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t) commandBuffer,
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003735 0, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
3736 "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.",
3737 (uint64_t) commandBuffer, (uint64_t) cmdPool);
3738 }
3739 if (skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003740 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003741 VkResult result = dev_data->device_dispatch_table->ResetCommandBuffer(commandBuffer, flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003742 if (VK_SUCCESS == result) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003743 resetCB(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003744 }
3745 return result;
3746}
3747
Chia-I Wu9ab61502015-11-06 06:42:02 +08003748VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003749{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003750 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003751 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3752 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003753 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07003754 skipCall |= addCmd(dev_data, pCB, CMD_BINDPIPELINE, "vkCmdBindPipeline()");
3755 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
3756 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, (uint64_t) pipeline,
3757 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
3758 "Incorrectly binding compute pipeline (%#" PRIxLEAST64 ") during active RenderPass (%#" PRIxLEAST64 ")",
3759 (uint64_t) pipeline, (uint64_t) pCB->activeRenderPass);
3760 } else if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
3761 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdBindPipeline");
3762 }
3763
3764 PIPELINE_NODE* pPN = getPipeline(dev_data, pipeline);
3765 if (pPN) {
3766 pCB->lastBoundPipeline = pipeline;
3767 loader_platform_thread_lock_mutex(&globalLock);
3768 set_cb_pso_status(pCB, pPN);
3769 loader_platform_thread_unlock_mutex(&globalLock);
3770 skipCall |= validatePipelineState(dev_data, pCB, pipelineBindPoint, pipeline);
Tobin Ehlisce132d82015-06-19 15:07:05 -06003771 } else {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07003772 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
3773 (uint64_t) pipeline, 0, DRAWSTATE_INVALID_PIPELINE, "DS",
3774 "Attempt to bind Pipeline %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<uint64_t>(pipeline));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003775 }
3776 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003777 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003778 dev_data->device_dispatch_table->CmdBindPipeline(commandBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003779}
3780
Chia-I Wu9ab61502015-11-06 06:42:02 +08003781VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetViewport(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003782 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07003783 uint32_t firstViewport,
3784 uint32_t viewportCount,
3785 const VkViewport* pViewports)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003786{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003787 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003788 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3789 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis9c536442015-06-19 13:00:59 -06003790 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07003791 skipCall |= addCmd(dev_data, pCB, CMD_SETVIEWPORTSTATE, "vkCmdSetViewport()");
3792 loader_platform_thread_lock_mutex(&globalLock);
3793 pCB->status |= CBSTATUS_VIEWPORT_SET;
3794 pCB->viewports.resize(viewportCount);
3795 memcpy(pCB->viewports.data(), pViewports, viewportCount * sizeof(VkViewport));
3796 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis9c536442015-06-19 13:00:59 -06003797 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003798 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07003799 dev_data->device_dispatch_table->CmdSetViewport(commandBuffer, firstViewport, viewportCount, pViewports);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06003800}
3801
Chia-I Wu9ab61502015-11-06 06:42:02 +08003802VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetScissor(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003803 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07003804 uint32_t firstScissor,
3805 uint32_t scissorCount,
3806 const VkRect2D* pScissors)
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06003807{
3808 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003809 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3810 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06003811 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07003812 skipCall |= addCmd(dev_data, pCB, CMD_SETSCISSORSTATE, "vkCmdSetScissor()");
3813 loader_platform_thread_lock_mutex(&globalLock);
3814 pCB->status |= CBSTATUS_SCISSOR_SET;
3815 pCB->scissors.resize(scissorCount);
3816 memcpy(pCB->scissors.data(), pScissors, scissorCount * sizeof(VkRect2D));
3817 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06003818 }
3819 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07003820 dev_data->device_dispatch_table->CmdSetScissor(commandBuffer, firstScissor, scissorCount, pScissors);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003821}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06003822
Chia-I Wu9ab61502015-11-06 06:42:02 +08003823VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003824{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003825 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003826 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3827 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003828 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07003829 skipCall |= addCmd(dev_data, pCB, CMD_SETLINEWIDTHSTATE, "vkCmdSetLineWidth()");
3830 /* TODO: Do we still need this lock? */
3831 loader_platform_thread_lock_mutex(&globalLock);
3832 pCB->status |= CBSTATUS_LINE_WIDTH_SET;
3833 pCB->lineWidth = lineWidth;
3834 loader_platform_thread_unlock_mutex(&globalLock);
Cody Northrop12365112015-08-17 11:10:49 -06003835 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003836 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003837 dev_data->device_dispatch_table->CmdSetLineWidth(commandBuffer, lineWidth);
Cody Northrop12365112015-08-17 11:10:49 -06003838}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06003839
Chia-I Wu9ab61502015-11-06 06:42:02 +08003840VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBias(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003841 VkCommandBuffer commandBuffer,
Chia-I Wud8c946a2015-10-26 19:08:09 +08003842 float depthBiasConstantFactor,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06003843 float depthBiasClamp,
Chia-I Wud8c946a2015-10-26 19:08:09 +08003844 float depthBiasSlopeFactor)
Cody Northrop12365112015-08-17 11:10:49 -06003845{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003846 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003847 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3848 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northrop12365112015-08-17 11:10:49 -06003849 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07003850 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBIASSTATE, "vkCmdSetDepthBias()");
3851 pCB->status |= CBSTATUS_DEPTH_BIAS_SET;
3852 pCB->depthBiasConstantFactor = depthBiasConstantFactor;
3853 pCB->depthBiasClamp = depthBiasClamp;
3854 pCB->depthBiasSlopeFactor = depthBiasSlopeFactor;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003855 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003856 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003857 dev_data->device_dispatch_table->CmdSetDepthBias(commandBuffer, depthBiasConstantFactor, depthBiasClamp, depthBiasSlopeFactor);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003858}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06003859
Chia-I Wu9ab61502015-11-06 06:42:02 +08003860VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4])
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003861{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003862 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003863 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3864 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003865 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07003866 skipCall |= addCmd(dev_data, pCB, CMD_SETBLENDSTATE, "vkCmdSetBlendConstants()");
3867 pCB->status |= CBSTATUS_BLEND_SET;
3868 memcpy(pCB->blendConstants, blendConstants, 4 * sizeof(float));
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003869 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003870 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003871 dev_data->device_dispatch_table->CmdSetBlendConstants(commandBuffer, blendConstants);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003872}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06003873
Chia-I Wu9ab61502015-11-06 06:42:02 +08003874VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBounds(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003875 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06003876 float minDepthBounds,
3877 float maxDepthBounds)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003878{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003879 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003880 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3881 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003882 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07003883 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBOUNDSSTATE, "vkCmdSetDepthBounds()");
3884 pCB->status |= CBSTATUS_DEPTH_BOUNDS_SET;
3885 pCB->minDepthBounds = minDepthBounds;
3886 pCB->maxDepthBounds = maxDepthBounds;
Cody Northrop82485a82015-08-18 15:21:16 -06003887 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003888 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003889 dev_data->device_dispatch_table->CmdSetDepthBounds(commandBuffer, minDepthBounds, maxDepthBounds);
Cody Northrop82485a82015-08-18 15:21:16 -06003890}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06003891
Chia-I Wu9ab61502015-11-06 06:42:02 +08003892VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilCompareMask(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003893 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06003894 VkStencilFaceFlags faceMask,
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003895 uint32_t compareMask)
Cody Northrop82485a82015-08-18 15:21:16 -06003896{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003897 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003898 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3899 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northrop82485a82015-08-18 15:21:16 -06003900 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07003901 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREADMASKSTATE, "vkCmdSetStencilCompareMask()");
3902 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
3903 pCB->front.compareMask = compareMask;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003904 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07003905 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
3906 pCB->back.compareMask = compareMask;
3907 }
3908 /* TODO: Do we need to track front and back separately? */
3909 /* TODO: We aren't capturing the faceMask, do we need to? */
3910 pCB->status |= CBSTATUS_STENCIL_READ_MASK_SET;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003911 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003912 if (VK_FALSE == skipCall)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003913 dev_data->device_dispatch_table->CmdSetStencilCompareMask(commandBuffer, faceMask, compareMask);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003914}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06003915
Chia-I Wu9ab61502015-11-06 06:42:02 +08003916VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilWriteMask(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003917 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06003918 VkStencilFaceFlags faceMask,
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003919 uint32_t writeMask)
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06003920{
3921 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003922 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3923 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06003924 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07003925 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILWRITEMASKSTATE, "vkCmdSetStencilWriteMask()");
3926 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
3927 pCB->front.writeMask = writeMask;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06003928 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07003929 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
3930 pCB->back.writeMask = writeMask;
3931 }
3932 pCB->status |= CBSTATUS_STENCIL_WRITE_MASK_SET;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06003933 }
3934 if (VK_FALSE == skipCall)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003935 dev_data->device_dispatch_table->CmdSetStencilWriteMask(commandBuffer, faceMask, writeMask);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06003936}
3937
Chia-I Wu9ab61502015-11-06 06:42:02 +08003938VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilReference(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003939 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06003940 VkStencilFaceFlags faceMask,
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003941 uint32_t reference)
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06003942{
3943 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003944 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3945 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06003946 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07003947 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREFERENCESTATE, "vkCmdSetStencilReference()");
3948 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
3949 pCB->front.reference = reference;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06003950 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07003951 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
3952 pCB->back.reference = reference;
3953 }
3954 pCB->status |= CBSTATUS_STENCIL_REFERENCE_SET;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06003955 }
3956 if (VK_FALSE == skipCall)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003957 dev_data->device_dispatch_table->CmdSetStencilReference(commandBuffer, faceMask, reference);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06003958}
3959
Chia-I Wu9ab61502015-11-06 06:42:02 +08003960VK_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 Ehlis10ae8c12015-03-17 16:24:32 -06003961{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003962 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003963 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3964 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003965 if (pCB) {
Tobin Ehlisf6585052015-12-17 11:48:42 -07003966 if (pCB->state == CB_RECORDING) {
3967 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
3968 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
3969 "Incorrectly binding compute DescriptorSets during active RenderPass (%#" PRIxLEAST64 ")", (uint64_t) pCB->activeRenderPass);
3970 } else if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
3971 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdBindDescriptorSets");
Mark Lobodzinski74635932015-12-18 15:35:38 -07003972 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07003973 if (VK_FALSE == skipCall) {
3974 // Track total count of dynamic descriptor types to make sure we have an offset for each one
3975 uint32_t totalDynamicDescriptors = 0;
3976 string errorString = "";
3977 uint32_t lastSetIndex = firstSet+setCount-1;
3978 if (lastSetIndex >= pCB->boundDescriptorSets.size())
Tobin Ehlis559c6382015-11-05 09:52:49 -07003979 pCB->boundDescriptorSets.resize(lastSetIndex+1);
Tobin Ehlisf6585052015-12-17 11:48:42 -07003980 VkDescriptorSet oldFinalBoundSet = pCB->boundDescriptorSets[lastSetIndex];
3981 for (uint32_t i=0; i<setCount; i++) {
3982 SET_NODE* pSet = getSetNode(dev_data, pDescriptorSets[i]);
3983 if (pSet) {
3984 loader_platform_thread_lock_mutex(&globalLock);
3985 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
3986 pCB->lastBoundPipelineLayout = layout;
3987 pCB->boundDescriptorSets[i+firstSet] = pDescriptorSets[i];
3988 loader_platform_thread_unlock_mutex(&globalLock);
3989 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pDescriptorSets[i], 0, DRAWSTATE_NONE, "DS",
3990 "DS %#" PRIxLEAST64 " bound on pipeline %s", (uint64_t) pDescriptorSets[i], string_VkPipelineBindPoint(pipelineBindPoint));
3991 if (!pSet->pUpdateStructs) {
3992 // TODO: Verify against Valid Usage
3993 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pDescriptorSets[i], 0, DRAWSTATE_DESCRIPTOR_SET_NOT_UPDATED, "DS",
3994 "DS %#" PRIxLEAST64 " bound but it was never updated. You may want to either update it or not bind it.", (uint64_t) pDescriptorSets[i]);
3995 }
3996 // Verify that set being bound is compatible with overlapping setLayout of pipelineLayout
3997 if (!verify_set_layout_compatibility(dev_data, pSet, layout, i+firstSet, errorString)) {
3998 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pDescriptorSets[i], 0, DRAWSTATE_PIPELINE_LAYOUTS_INCOMPATIBLE, "DS",
3999 "descriptorSet #%u being bound is not compatible with overlapping layout in pipelineLayout due to: %s", i, errorString.c_str());
4000 }
4001 if (pSet->pLayout->dynamicDescriptorCount) {
4002 // First make sure we won't overstep bounds of pDynamicOffsets array
4003 if ((totalDynamicDescriptors + pSet->pLayout->dynamicDescriptorCount) > dynamicOffsetCount) {
4004 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pDescriptorSets[i], 0, DRAWSTATE_INVALID_DYNAMIC_OFFSET_COUNT, "DS",
4005 "descriptorSet #%u (%#" PRIxLEAST64 ") requires %u dynamicOffsets, but only %u dynamicOffsets are left in pDynamicOffsets array. There must be one dynamic offset for each dynamic descriptor being bound.",
4006 i, (uint64_t) pDescriptorSets[i], pSet->pLayout->dynamicDescriptorCount, (dynamicOffsetCount - totalDynamicDescriptors));
4007 } else { // Store dynamic offsets with the set
4008 const uint32_t* pStartDynOffset = pDynamicOffsets + totalDynamicDescriptors;
4009 pSet->dynamicOffsets.assign(pStartDynOffset, pStartDynOffset + pSet->pLayout->dynamicDescriptorCount);
4010 totalDynamicDescriptors += pSet->pLayout->dynamicDescriptorCount;
4011 }
4012 }
4013 } else {
4014 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pDescriptorSets[i], 0, DRAWSTATE_INVALID_SET, "DS",
4015 "Attempt to bind DS %#" PRIxLEAST64 " that doesn't exist!", (uint64_t) pDescriptorSets[i]);
4016 }
4017 }
4018 skipCall |= addCmd(dev_data, pCB, CMD_BINDDESCRIPTORSETS, "vkCmdBindDescrsiptorSets()");
4019 // For any previously bound sets, need to set them to "invalid" if they were disturbed by this update
4020 if (firstSet > 0) { // Check set #s below the first bound set
4021 for (uint32_t i=0; i<firstSet; ++i) {
4022 if (pCB->boundDescriptorSets[i] && !verify_set_layout_compatibility(dev_data, dev_data->setMap[pCB->boundDescriptorSets[i]], layout, i, errorString)) {
4023 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pCB->boundDescriptorSets[i], 0, DRAWSTATE_NONE, "DS",
4024 "DescriptorSetDS %#" PRIxLEAST64 " previously bound as set #%u was disturbed by newly bound pipelineLayout (%#" PRIxLEAST64 ")", (uint64_t) pCB->boundDescriptorSets[i], i, (uint64_t) layout);
4025 pCB->boundDescriptorSets[i] = VK_NULL_HANDLE;
4026 }
4027 }
4028 }
4029 // Check if newly last bound set invalidates any remaining bound sets
4030 if ((pCB->boundDescriptorSets.size()-1) > (lastSetIndex)) {
4031 if (oldFinalBoundSet && !verify_set_layout_compatibility(dev_data, dev_data->setMap[oldFinalBoundSet], layout, lastSetIndex, errorString)) {
4032 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) oldFinalBoundSet, 0, DRAWSTATE_NONE, "DS",
4033 "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);
4034 pCB->boundDescriptorSets.resize(lastSetIndex+1);
4035 }
4036 }
4037 // dynamicOffsetCount must equal the total number of dynamic descriptors in the sets being bound
4038 if (totalDynamicDescriptors != dynamicOffsetCount) {
4039 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t) commandBuffer, 0, DRAWSTATE_INVALID_DYNAMIC_OFFSET_COUNT, "DS",
4040 "Attempting to bind %u descriptorSets with %u dynamic descriptors, but dynamicOffsetCount is %u. It should exactly match the number of dynamic descriptors.", setCount, totalDynamicDescriptors, dynamicOffsetCount);
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07004041 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004042 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07004043 } else {
4044 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindDescriptorSets()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004045 }
4046 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004047 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004048 dev_data->device_dispatch_table->CmdBindDescriptorSets(commandBuffer, pipelineBindPoint, layout, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004049}
4050
Chia-I Wu9ab61502015-11-06 06:42:02 +08004051VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004052{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004053 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004054 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4055 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004056 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004057 skipCall |= addCmd(dev_data, pCB, CMD_BINDINDEXBUFFER, "vkCmdBindIndexBuffer()");
4058 VkDeviceSize offset_align = 0;
4059 switch (indexType) {
4060 case VK_INDEX_TYPE_UINT16:
4061 offset_align = 2;
4062 break;
4063 case VK_INDEX_TYPE_UINT32:
4064 offset_align = 4;
4065 break;
4066 default:
4067 // ParamChecker should catch bad enum, we'll also throw alignment error below if offset_align stays 0
4068 break;
4069 }
4070 if (!offset_align || (offset % offset_align)) {
4071 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_VTX_INDEX_ALIGNMENT_ERROR, "DS",
4072 "vkCmdBindIndexBuffer() offset (%#" PRIxLEAST64 ") does not fall on alignment (%s) boundary.", offset, string_VkIndexType(indexType));
Tobin Ehlis9c536442015-06-19 13:00:59 -06004073 }
Tobin Ehlisc4c23182015-09-17 12:24:13 -06004074 pCB->status |= CBSTATUS_INDEX_BUFFER_BOUND;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004075 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004076 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004077 dev_data->device_dispatch_table->CmdBindIndexBuffer(commandBuffer, buffer, offset, indexType);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004078}
4079
Chia-I Wu9ab61502015-11-06 06:42:02 +08004080VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindVertexBuffers(
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07004081 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004082 uint32_t firstBinding,
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06004083 uint32_t bindingCount,
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07004084 const VkBuffer *pBuffers,
4085 const VkDeviceSize *pOffsets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004086{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004087 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004088 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4089 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004090 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004091 addCmd(dev_data, pCB, CMD_BINDVERTEXBUFFER, "vkCmdBindVertexBuffer()");
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004092 if ((firstBinding + bindingCount) > pCB->boundVtxBuffers.size()) {
4093 pCB->boundVtxBuffers.resize(firstBinding+bindingCount, VK_NULL_HANDLE);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004094 }
4095 for (auto i = 0; i < bindingCount; i++) {
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004096 pCB->boundVtxBuffers[i+firstBinding] = pBuffers[i];
Tobin Ehlis0174fed2015-05-28 12:10:17 -06004097 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004098 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004099 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004100 dev_data->device_dispatch_table->CmdBindVertexBuffers(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004101}
4102
Chia-I Wu9ab61502015-11-06 06:42:02 +08004103VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004104{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004105 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004106 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4107 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004108 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004109 skipCall |= addCmd(dev_data, pCB, CMD_DRAW, "vkCmdDraw()");
4110 pCB->drawCount[DRAW]++;
4111 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
4112 // TODO : Need to pass commandBuffer as srcObj here
4113 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, 0, DRAWSTATE_NONE, "DS",
4114 "vkCmdDraw() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW]++);
4115 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004116 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDraw");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004117 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004118 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004119 dev_data->device_dispatch_table->CmdDraw(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004120}
4121
Chia-I Wu9ab61502015-11-06 06:42:02 +08004122VK_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 Ehlis10ae8c12015-03-17 16:24:32 -06004123{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004124 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4125 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004126 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004127 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004128 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXED, "vkCmdDrawIndexed()");
4129 pCB->drawCount[DRAW_INDEXED]++;
4130 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
4131 // TODO : Need to pass commandBuffer as srcObj here
4132 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, 0, DRAWSTATE_NONE, "DS",
4133 "vkCmdDrawIndexed() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED]++);
4134 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004135 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexed");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004136 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004137 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004138 dev_data->device_dispatch_table->CmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004139}
4140
Chia-I Wu9ab61502015-11-06 06:42:02 +08004141VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004142{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004143 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4144 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004145 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004146 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004147 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDIRECT, "vkCmdDrawIndirect()");
4148 pCB->drawCount[DRAW_INDIRECT]++;
4149 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
4150 // TODO : Need to pass commandBuffer as srcObj here
4151 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, 0, DRAWSTATE_NONE, "DS",
4152 "vkCmdDrawIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
4153 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004154 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndirect");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004155 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004156 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004157 dev_data->device_dispatch_table->CmdDrawIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004158}
4159
Chia-I Wu9ab61502015-11-06 06:42:02 +08004160VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004161{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004162 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004163 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4164 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004165 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004166 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXEDINDIRECT, "vkCmdDrawIndexedIndirect()");
4167 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
4168 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
4169 // TODO : Need to pass commandBuffer as srcObj here
4170 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, 0, DRAWSTATE_NONE, "DS",
4171 "vkCmdDrawIndexedIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
4172 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004173 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexedIndirect");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004174 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004175 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004176 dev_data->device_dispatch_table->CmdDrawIndexedIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004177}
4178
Chia-I Wu9ab61502015-11-06 06:42:02 +08004179VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004180{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004181 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004182 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4183 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004184 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004185 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCH, "vkCmdDispatch()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004186 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatch");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004187 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004188 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004189 dev_data->device_dispatch_table->CmdDispatch(commandBuffer, x, y, z);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004190}
4191
Chia-I Wu9ab61502015-11-06 06:42:02 +08004192VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004193{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004194 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004195 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4196 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004197 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004198 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCHINDIRECT, "vkCmdDispatchIndirect()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004199 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatchIndirect");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004200 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004201 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004202 dev_data->device_dispatch_table->CmdDispatchIndirect(commandBuffer, buffer, offset);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004203}
4204
Chia-I Wu9ab61502015-11-06 06:42:02 +08004205VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004206{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004207 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004208 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4209 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004210 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004211 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFER, "vkCmdCopyBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004212 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004213 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004214 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004215 dev_data->device_dispatch_table->CmdCopyBuffer(commandBuffer, srcBuffer, dstBuffer, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004216}
4217
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07004218VkBool32 VerifySourceImageLayout(VkCommandBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout) {
4219 VkBool32 skip_call = false;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07004220
4221#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4222 // TODO: Fix -- initialLayout may have been set in a previous command buffer
4223 return skip_call;
4224#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4225
Michael Lentineabc5e922015-10-12 11:30:14 -05004226 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4227 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4228 auto src_image_element = pCB->imageLayoutMap.find(srcImage);
4229 if (src_image_element == pCB->imageLayoutMap.end()) {
4230 pCB->imageLayoutMap[srcImage].initialLayout = srcImageLayout;
4231 pCB->imageLayoutMap[srcImage].layout = srcImageLayout;
4232 return false;
4233 }
4234 if (src_image_element->second.layout != srcImageLayout) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004235 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05004236 "Cannot copy from an image whose source layout is %d and doesn't match the current layout %d.", srcImageLayout, src_image_element->second.layout);
4237 }
4238 if (srcImageLayout != VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL) {
4239 if (srcImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004240 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
4241 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineecc32b72015-10-16 18:08:09 -05004242 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Michael Lentineabc5e922015-10-12 11:30:14 -05004243 } else {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004244 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineecc32b72015-10-16 18:08:09 -05004245 "Layout for input image is %d but can only be TRANSFER_SRC_OPTIMAL or GENERAL.", srcImageLayout);
Michael Lentineabc5e922015-10-12 11:30:14 -05004246 }
4247 }
4248 return skip_call;
4249}
4250
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07004251VkBool32 VerifyDestImageLayout(VkCommandBuffer cmdBuffer, VkImage destImage, VkImageLayout destImageLayout) {
4252 VkBool32 skip_call = false;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07004253
4254#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4255 // TODO: Fix -- initialLayout may have been set in a previous command buffer
4256 return skip_call;
4257#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4258
Michael Lentineabc5e922015-10-12 11:30:14 -05004259 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4260 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4261 auto dest_image_element = pCB->imageLayoutMap.find(destImage);
4262 if (dest_image_element == pCB->imageLayoutMap.end()) {
4263 pCB->imageLayoutMap[destImage].initialLayout = destImageLayout;
4264 pCB->imageLayoutMap[destImage].layout = destImageLayout;
4265 return false;
4266 }
4267 if (dest_image_element->second.layout != destImageLayout) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004268 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05004269 "Cannot copy from an image whose dest layout is %d and doesn't match the current layout %d.", destImageLayout, dest_image_element->second.layout);
4270 }
4271 if (destImageLayout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) {
4272 if (destImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004273 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
4274 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05004275 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
4276 } else {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004277 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05004278 "Layout for output image is %d but can only be TRANSFER_DST_OPTIMAL or GENERAL.", destImageLayout);
4279 }
4280 }
4281 return skip_call;
4282}
4283
Chia-I Wu9ab61502015-11-06 06:42:02 +08004284VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004285 VkImage srcImage,
4286 VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004287 VkImage dstImage,
4288 VkImageLayout dstImageLayout,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004289 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004290{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004291 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004292 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4293 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004294 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004295 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGE, "vkCmdCopyImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004296 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImage");
Michael Lentineabc5e922015-10-12 11:30:14 -05004297 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
4298 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004299 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004300 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004301 dev_data->device_dispatch_table->CmdCopyImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004302}
4303
Chia-I Wu9ab61502015-11-06 06:42:02 +08004304VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBlitImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004305 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004306 VkImage dstImage, VkImageLayout dstImageLayout,
Mark Lobodzinskiee5eef12015-05-22 14:43:25 -05004307 uint32_t regionCount, const VkImageBlit* pRegions,
Chia-I Wub99df442015-10-26 16:49:32 +08004308 VkFilter filter)
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004309{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004310 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004311 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4312 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004313 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004314 skipCall |= addCmd(dev_data, pCB, CMD_BLITIMAGE, "vkCmdBlitImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004315 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBlitImage");
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004316 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004317 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004318 dev_data->device_dispatch_table->CmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter);
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004319}
4320
Chia-I Wu9ab61502015-11-06 06:42:02 +08004321VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004322 VkBuffer srcBuffer,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004323 VkImage dstImage, VkImageLayout dstImageLayout,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004324 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004325{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004326 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004327 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4328 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004329 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004330 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFERTOIMAGE, "vkCmdCopyBufferToImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004331 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBufferToImage");
Michael Lentineabc5e922015-10-12 11:30:14 -05004332 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004333 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004334 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004335 dev_data->device_dispatch_table->CmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004336}
4337
Chia-I Wu9ab61502015-11-06 06:42:02 +08004338VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004339 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004340 VkBuffer dstBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004341 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004342{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004343 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004344 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4345 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004346 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004347 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGETOBUFFER, "vkCmdCopyImageToBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004348 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImageToBuffer");
Michael Lentineabc5e922015-10-12 11:30:14 -05004349 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004350 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004351 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004352 dev_data->device_dispatch_table->CmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004353}
4354
Chia-I Wu9ab61502015-11-06 06:42:02 +08004355VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize dataSize, const uint32_t* pData)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004356{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004357 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004358 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4359 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004360 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004361 skipCall |= addCmd(dev_data, pCB, CMD_UPDATEBUFFER, "vkCmdUpdateBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004362 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyUpdateBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004363 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004364 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004365 dev_data->device_dispatch_table->CmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004366}
4367
Chia-I Wu9ab61502015-11-06 06:42:02 +08004368VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize size, uint32_t data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004369{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004370 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004371 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4372 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004373 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004374 skipCall |= addCmd(dev_data, pCB, CMD_FILLBUFFER, "vkCmdFillBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004375 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyFillBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004376 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004377 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004378 dev_data->device_dispatch_table->CmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004379}
4380
Chia-I Wu9ab61502015-11-06 06:42:02 +08004381VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearAttachments(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004382 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004383 uint32_t attachmentCount,
4384 const VkClearAttachment* pAttachments,
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004385 uint32_t rectCount,
Courtney Goeltzenleuchter4ca43f62015-10-15 18:22:08 -06004386 const VkClearRect* pRects)
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004387{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004388 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004389 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4390 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004391 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004392 skipCall |= addCmd(dev_data, pCB, CMD_CLEARATTACHMENTS, "vkCmdClearAttachments()");
4393 // Warn if this is issued prior to Draw Cmd and clearing the entire attachment
4394 if (!hasDrawCmd(pCB) &&
4395 (pCB->activeRenderPassBeginInfo.renderArea.extent.width == pRects[0].rect.extent.width) &&
4396 (pCB->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) {
4397 // TODO : commandBuffer should be srcObj
4398 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, 0, DRAWSTATE_CLEAR_CMD_BEFORE_DRAW, "DS",
4399 "vkCmdClearAttachments() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
4400 " It is recommended you use RenderPass LOAD_OP_CLEAR on Attachments prior to any Draw.", reinterpret_cast<uint64_t>(commandBuffer));
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004401 }
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004402 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdClearAttachments");
4403 }
4404
4405 // Validate that attachment is in reference list of active subpass
4406 if (pCB->activeRenderPass) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07004407 const VkRenderPassCreateInfo *pRPCI = dev_data->renderPassMap[pCB->activeRenderPass]->pCreateInfo;
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004408 const VkSubpassDescription *pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
4409
4410 for (uint32_t attachment_idx = 0; attachment_idx < attachmentCount; attachment_idx++) {
4411 const VkClearAttachment *attachment = &pAttachments[attachment_idx];
4412 if (attachment->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) {
4413 VkBool32 found = VK_FALSE;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004414 for (uint32_t i = 0; i < pSD->colorAttachmentCount; i++) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004415 if (attachment->colorAttachment == pSD->pColorAttachments[i].attachment) {
4416 found = VK_TRUE;
4417 break;
4418 }
4419 }
4420 if (VK_FALSE == found) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004421 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004422 (uint64_t)commandBuffer, 0, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004423 "vkCmdClearAttachments() attachment index %d not found in attachment reference array of active subpass %d",
4424 attachment->colorAttachment, pCB->activeSubpass);
4425 }
4426 } else if (attachment->aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) {
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07004427 if (!pSD->pDepthStencilAttachment || // Says no DS will be used in active subpass
Mark Lobodzinski2fd355a2015-11-18 08:58:31 -07004428 (pSD->pDepthStencilAttachment->attachment == VK_ATTACHMENT_UNUSED)) { // Says no DS will be used in active subpass
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07004429
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004430 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07004431 (uint64_t)commandBuffer, 0, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
4432 "vkCmdClearAttachments() attachment index %d does not match depthStencilAttachment.attachment (%d) found in active subpass %d",
4433 attachment->colorAttachment,
4434 (pSD->pDepthStencilAttachment) ? pSD->pDepthStencilAttachment->attachment : VK_ATTACHMENT_UNUSED,
4435 pCB->activeSubpass);
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004436 }
4437 }
4438 }
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004439 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004440 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004441 dev_data->device_dispatch_table->CmdClearAttachments(commandBuffer, attachmentCount, pAttachments, rectCount, pRects);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004442}
4443
Chia-I Wu9ab61502015-11-06 06:42:02 +08004444VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearColorImage(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004445 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06004446 VkImage image, VkImageLayout imageLayout,
Chris Forbesf0796e12015-06-24 14:34:53 +12004447 const VkClearColorValue *pColor,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06004448 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004449{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004450 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004451 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4452 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004453 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004454 skipCall |= addCmd(dev_data, pCB, CMD_CLEARCOLORIMAGE, "vkCmdClearColorImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004455 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearColorImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004456 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004457 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004458 dev_data->device_dispatch_table->CmdClearColorImage(commandBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004459}
4460
Chia-I Wu9ab61502015-11-06 06:42:02 +08004461VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearDepthStencilImage(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004462 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter45df9e12015-09-15 18:03:22 -06004463 VkImage image, VkImageLayout imageLayout,
4464 const VkClearDepthStencilValue *pDepthStencil,
4465 uint32_t rangeCount,
4466 const VkImageSubresourceRange* pRanges)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004467{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004468 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004469 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4470 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004471 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004472 skipCall |= addCmd(dev_data, pCB, CMD_CLEARDEPTHSTENCILIMAGE, "vkCmdClearDepthStencilImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004473 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearDepthStencilImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004474 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004475 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004476 dev_data->device_dispatch_table->CmdClearDepthStencilImage(commandBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004477}
4478
Chia-I Wu9ab61502015-11-06 06:42:02 +08004479VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResolveImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004480 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004481 VkImage dstImage, VkImageLayout dstImageLayout,
Tony Barbour6865d4a2015-04-13 15:02:52 -06004482 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004483{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004484 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004485 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4486 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004487 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004488 skipCall |= addCmd(dev_data, pCB, CMD_RESOLVEIMAGE, "vkCmdResolveImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004489 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResolveImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004490 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004491 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004492 dev_data->device_dispatch_table->CmdResolveImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004493}
4494
Chia-I Wu9ab61502015-11-06 06:42:02 +08004495VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004496{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004497 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004498 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4499 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004500 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004501 skipCall |= addCmd(dev_data, pCB, CMD_SETEVENT, "vkCmdSetEvent()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004502 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdSetEvent");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004503 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004504 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004505 dev_data->device_dispatch_table->CmdSetEvent(commandBuffer, event, stageMask);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004506}
4507
Chia-I Wu9ab61502015-11-06 06:42:02 +08004508VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004509{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004510 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004511 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4512 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004513 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004514 skipCall |= addCmd(dev_data, pCB, CMD_RESETEVENT, "vkCmdResetEvent()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004515 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResetEvent");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004516 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004517 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004518 dev_data->device_dispatch_table->CmdResetEvent(commandBuffer, event, stageMask);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004519}
4520
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07004521VkBool32 TransitionImageLayouts(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const void* const* ppMemBarriers) {
Michael Lentineabc5e922015-10-12 11:30:14 -05004522 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4523 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07004524 VkBool32 skip = false;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07004525
4526#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4527 // TODO: Fix -- pay attention to image subresource ranges -- not all subresources transition at the same time
4528 return skip;
4529#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4530
Michael Lentineabc5e922015-10-12 11:30:14 -05004531 for (uint32_t i = 0; i < memBarrierCount; ++i) {
4532 auto mem_barrier = reinterpret_cast<const VkMemoryBarrier*>(ppMemBarriers[i]);
4533 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
4534 auto image_mem_barrier = reinterpret_cast<const VkImageMemoryBarrier*>(mem_barrier);
4535 auto image_data = pCB->imageLayoutMap.find(image_mem_barrier->image);
4536 if (image_data == pCB->imageLayoutMap.end()) {
4537 pCB->imageLayoutMap[image_mem_barrier->image].initialLayout = image_mem_barrier->oldLayout;
4538 pCB->imageLayoutMap[image_mem_barrier->image].layout = image_mem_barrier->newLayout;
4539 } else {
4540 if (image_data->second.layout != image_mem_barrier->oldLayout) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004541 skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Courtney Goeltzenleuchterb19042e2015-11-25 11:38:54 -07004542 "You cannot transition the layout from %d when current layout is %d.", image_mem_barrier->oldLayout, image_data->second.layout);
Michael Lentineabc5e922015-10-12 11:30:14 -05004543 }
4544 image_data->second.layout = image_mem_barrier->newLayout;
4545 }
4546 }
4547 }
4548 return skip;
4549}
4550
Michael Lentine97eb7462015-11-20 09:48:52 -08004551// AccessFlags MUST have 'required_bit' set, and may have one or more of 'optional_bits' set.
4552// If required_bit is zero, accessMask must have at least one of 'optional_bits' set
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07004553VkBool32 ValidateMaskBits(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout, VkAccessFlags required_bit, VkAccessFlags optional_bits) {
4554 VkBool32 skip_call = false;
Michael Lentine97eb7462015-11-20 09:48:52 -08004555 if ((accessMask & required_bit) || (!required_bit && (accessMask & optional_bits))) {
4556 if (accessMask & !(required_bit | optional_bits)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004557 // TODO: Verify against Valid Use
4558 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_BARRIER, "DS",
Michael Lentine97eb7462015-11-20 09:48:52 -08004559 "Additional bits in accessMask %d are specified when layout is %s.", accessMask, string_VkImageLayout(layout));
Michael Lentineecc32b72015-10-16 18:08:09 -05004560 }
4561 } else {
Michael Lentine97eb7462015-11-20 09:48:52 -08004562 if (!required_bit) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004563 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_BARRIER, "DS",
Michael Lentine97eb7462015-11-20 09:48:52 -08004564 "AccessMask %d must contain at least one of access bits %d when layout is %s.",
4565 accessMask, optional_bits, string_VkImageLayout(layout));
4566 } else {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004567 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_BARRIER, "DS",
Michael Lentine97eb7462015-11-20 09:48:52 -08004568 "AccessMask %d must have required access bit %d and may have optional bits %d when layout is %s.",
4569 accessMask, required_bit, optional_bits,string_VkImageLayout(layout));
4570 }
Michael Lentineecc32b72015-10-16 18:08:09 -05004571 }
4572 return skip_call;
4573}
4574
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07004575VkBool32 ValidateMaskBitsFromLayouts(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout) {
4576 VkBool32 skip_call = false;
Michael Lentine97eb7462015-11-20 09:48:52 -08004577 switch (layout) {
4578 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: {
4579 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_COLOR_ATTACHMENT_READ_BIT);
4580 break;
Michael Lentineecc32b72015-10-16 18:08:09 -05004581 }
Michael Lentine97eb7462015-11-20 09:48:52 -08004582 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: {
4583 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT);
4584 break;
Michael Lentineecc32b72015-10-16 18:08:09 -05004585 }
Michael Lentine97eb7462015-11-20 09:48:52 -08004586 case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: {
4587 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_WRITE_BIT, 0);
4588 break;
4589 }
4590 case VK_IMAGE_LAYOUT_PREINITIALIZED: {
4591 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_HOST_WRITE_BIT, 0);
4592 break;
4593 }
4594 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: {
4595 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, 0, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT);
4596 break;
4597 }
4598 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: {
4599 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, 0, VK_ACCESS_INPUT_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT);
4600 break;
4601 }
4602 case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: {
4603 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_READ_BIT, 0);
4604 break;
4605 }
4606 case VK_IMAGE_LAYOUT_UNDEFINED: {
4607 if (accessMask != 0) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004608 // TODO: Verify against Valid Use section spec
4609 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_BARRIER, "DS",
Michael Lentine97eb7462015-11-20 09:48:52 -08004610 "Additional bits in accessMask %d are specified when layout is %s.", accessMask, string_VkImageLayout(layout));
4611 }
4612 break;
4613 }
4614 case VK_IMAGE_LAYOUT_GENERAL:
4615 default: {
4616 break;
4617 }
Michael Lentineecc32b72015-10-16 18:08:09 -05004618 }
4619 return skip_call;
4620}
4621
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07004622VkBool32 ValidateBarriers(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const void* const* ppMemBarriers) {
4623 VkBool32 skip_call = false;
Michael Lentine48930b82015-10-15 17:07:00 -05004624 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4625 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4626 if (pCB->activeRenderPass && memBarrierCount) {
4627 for (uint32_t i = 0; i < memBarrierCount; ++i) {
4628 auto mem_barrier = reinterpret_cast<const VkMemoryBarrier*>(ppMemBarriers[i]);
4629 if (mem_barrier && mem_barrier->sType != VK_STRUCTURE_TYPE_MEMORY_BARRIER) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004630 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_BARRIER, "DS",
Michael Lentine48930b82015-10-15 17:07:00 -05004631 "Image or Buffers Barriers cannot be used during a render pass.");
4632 }
4633 }
4634 if (!dev_data->renderPassMap[pCB->activeRenderPass]->hasSelfDependency[pCB->activeSubpass]) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004635 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_BARRIER, "DS",
Michael Lentine48930b82015-10-15 17:07:00 -05004636 "Barriers cannot be set during subpass %d with no self dependency specified.", pCB->activeSubpass);
4637 }
4638 }
Mark Lobodzinski73a37ec2015-11-20 09:27:27 -07004639
Michael Lentineecc32b72015-10-16 18:08:09 -05004640 for (uint32_t i = 0; i < memBarrierCount; ++i) {
4641 auto mem_barrier = reinterpret_cast<const VkMemoryBarrier*>(ppMemBarriers[i]);
4642 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
4643 auto image_mem_barrier = reinterpret_cast<const VkImageMemoryBarrier*>(mem_barrier);
Michael Lentine97eb7462015-11-20 09:48:52 -08004644 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, image_mem_barrier->srcAccessMask, image_mem_barrier->oldLayout);
4645 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, image_mem_barrier->dstAccessMask, image_mem_barrier->newLayout);
Michael Lentineecc32b72015-10-16 18:08:09 -05004646 }
4647 }
Mark Lobodzinski3cba24a2015-12-03 15:42:32 -07004648
Michael Lentine48930b82015-10-15 17:07:00 -05004649 return skip_call;
4650}
4651
Chia-I Wu9ab61502015-11-06 06:42:02 +08004652VK_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 Ehlis10ae8c12015-03-17 16:24:32 -06004653{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004654 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004655 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4656 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004657 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004658 skipCall |= addCmd(dev_data, pCB, CMD_WAITEVENTS, "vkCmdWaitEvents()");
Michael Lentineabc5e922015-10-12 11:30:14 -05004659 skipCall |= TransitionImageLayouts(commandBuffer, memoryBarrierCount, ppMemoryBarriers);
Michael Lentine48930b82015-10-15 17:07:00 -05004660 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, ppMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004661 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004662 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004663 dev_data->device_dispatch_table->CmdWaitEvents(commandBuffer, eventCount, pEvents, sourceStageMask, dstStageMask, memoryBarrierCount, ppMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004664}
4665
Chia-I Wu9ab61502015-11-06 06:42:02 +08004666VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, uint32_t memoryBarrierCount, const void* const* ppMemoryBarriers)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004667{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004668 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004669 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4670 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004671 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004672 skipCall |= addCmd(dev_data, pCB, CMD_PIPELINEBARRIER, "vkCmdPipelineBarrier()");
Michael Lentineabc5e922015-10-12 11:30:14 -05004673 skipCall |= TransitionImageLayouts(commandBuffer, memoryBarrierCount, ppMemoryBarriers);
Michael Lentine48930b82015-10-15 17:07:00 -05004674 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, ppMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004675 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004676 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004677 dev_data->device_dispatch_table->CmdPipelineBarrier(commandBuffer, srcStageMask, dstStageMask, dependencyFlags, memoryBarrierCount, ppMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004678}
4679
Chia-I Wu9ab61502015-11-06 06:42:02 +08004680VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004681{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004682 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-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 Ehlis10ae8c12015-03-17 16:24:32 -06004685 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004686 skipCall |= addCmd(dev_data, pCB, CMD_BEGINQUERY, "vkCmdBeginQuery()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004687 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004688 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004689 dev_data->device_dispatch_table->CmdBeginQuery(commandBuffer, queryPool, slot, flags);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004690}
4691
Chia-I Wu9ab61502015-11-06 06:42:02 +08004692VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004693{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004694 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004695 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4696 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004697 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004698 skipCall |= addCmd(dev_data, pCB, CMD_ENDQUERY, "vkCmdEndQuery()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004699 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004700 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004701 dev_data->device_dispatch_table->CmdEndQuery(commandBuffer, queryPool, slot);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004702}
4703
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004704VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResetQueryPool(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004705{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004706 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004707 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4708 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004709 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004710 skipCall |= addCmd(dev_data, pCB, CMD_RESETQUERYPOOL, "vkCmdResetQueryPool()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004711 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdQueryPool");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004712 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004713 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004714 dev_data->device_dispatch_table->CmdResetQueryPool(commandBuffer, queryPool, firstQuery, queryCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004715}
4716
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004717VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004718 uint32_t queryCount, VkBuffer dstBuffer, VkDeviceSize dstOffset,
Chia-I Wuccc93a72015-10-26 18:36:20 +08004719 VkDeviceSize stride, VkQueryResultFlags flags)
Mark Lobodzinski5495d132015-09-30 16:19:16 -06004720{
4721 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004722 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4723 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06004724 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004725 skipCall |= addCmd(dev_data, pCB, CMD_COPYQUERYPOOLRESULTS, "vkCmdCopyQueryPoolResults()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004726 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyQueryPoolResults");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06004727 }
4728 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004729 dev_data->device_dispatch_table->CmdCopyQueryPoolResults(commandBuffer, queryPool,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004730 firstQuery, queryCount, dstBuffer, dstOffset, stride, flags);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06004731}
4732
Chia-I Wu9ab61502015-11-06 06:42:02 +08004733VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004734{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004735 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004736 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4737 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004738 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004739 skipCall |= addCmd(dev_data, pCB, CMD_WRITETIMESTAMP, "vkCmdWriteTimestamp()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004740 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004741 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004742 dev_data->device_dispatch_table->CmdWriteTimestamp(commandBuffer, pipelineStage, queryPool, slot);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004743}
4744
Chia-I Wu9ab61502015-11-06 06:42:02 +08004745VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkFramebuffer* pFramebuffer)
Tobin Ehliseba312c2015-04-01 08:40:34 -06004746{
Tobin Ehlis0b632332015-10-07 09:38:40 -06004747 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08004748 VkResult result = dev_data->device_dispatch_table->CreateFramebuffer(device, pCreateInfo, pAllocator, pFramebuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004749 if (VK_SUCCESS == result) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06004750 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004751 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +08004752 if (pCreateInfo->pAttachments) {
Courtney Goeltzenleuchter5861a1b2015-09-01 17:30:39 -06004753 localFBCI->pAttachments = new VkImageView[localFBCI->attachmentCount];
4754 memcpy((void*)localFBCI->pAttachments, pCreateInfo->pAttachments, localFBCI->attachmentCount*sizeof(VkImageView));
Tobin Ehliseba312c2015-04-01 08:40:34 -06004755 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08004756 dev_data->frameBufferMap[*pFramebuffer] = localFBCI;
Tobin Ehliseba312c2015-04-01 08:40:34 -06004757 }
4758 return result;
4759}
4760
Michael Lentineb6986752015-10-06 14:56:18 -07004761// Store the DAG.
4762struct DAGNode {
4763 uint32_t pass;
4764 std::vector<uint32_t> prev;
4765 std::vector<uint32_t> next;
4766};
4767
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07004768VkBool32 FindDependency(const int index, const int dependent, const std::vector<DAGNode>& subpass_to_node, std::unordered_set<uint32_t>& processed_nodes) {
Michael Lentineb6986752015-10-06 14:56:18 -07004769 // If we have already checked this node we have not found a dependency path so return false.
4770 if (processed_nodes.count(index))
4771 return false;
4772 processed_nodes.insert(index);
4773 const DAGNode& node = subpass_to_node[index];
4774 // Look for a dependency path. If one exists return true else recurse on the previous nodes.
4775 if (std::find(node.prev.begin(), node.prev.end(), dependent) == node.prev.end()) {
4776 for (auto elem : node.prev) {
4777 if (FindDependency(elem, dependent, subpass_to_node, processed_nodes))
4778 return true;
4779 }
4780 } else {
4781 return true;
4782 }
4783 return false;
4784}
4785
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07004786VkBool32 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) {
4787 VkBool32 result = true;
Michael Lentineb6986752015-10-06 14:56:18 -07004788 // Loop through all subpasses that share the same attachment and make sure a dependency exists
4789 for (uint32_t k = 0; k < dependent_subpasses.size(); ++k) {
4790 if (subpass == dependent_subpasses[k])
4791 continue;
4792 const DAGNode& node = subpass_to_node[subpass];
4793 // Check for a specified dependency between the two nodes. If one exists we are done.
4794 auto prev_elem = std::find(node.prev.begin(), node.prev.end(), dependent_subpasses[k]);
4795 auto next_elem = std::find(node.next.begin(), node.next.end(), dependent_subpasses[k]);
4796 if (prev_elem == node.prev.end() && next_elem == node.next.end()) {
4797 // If no dependency exits an implicit dependency still might. If so, warn and if not throw an error.
4798 std::unordered_set<uint32_t> processed_nodes;
4799 if (FindDependency(subpass, dependent_subpasses[k], subpass_to_node, processed_nodes) ||
4800 FindDependency(dependent_subpasses[k], subpass, subpass_to_node, processed_nodes)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004801 // TODO: Verify against Valid Use section of spec
4802 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_RENDERPASS, "DS",
Michael Lentineb6986752015-10-06 14:56:18 -07004803 "A dependency between subpasses %d and %d must exist but only an implicit one is specified.",
4804 subpass, dependent_subpasses[k]);
4805 } else {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004806 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_RENDERPASS, "DS",
Michael Lentineb6986752015-10-06 14:56:18 -07004807 "A dependency between subpasses %d and %d must exist but one is not specified.",
4808 subpass, dependent_subpasses[k]);
4809 result = false;
4810 }
4811 }
4812 }
4813 return result;
4814}
4815
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07004816VkBool32 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 Lentineb6986752015-10-06 14:56:18 -07004817 const DAGNode& node = subpass_to_node[index];
4818 // If this node writes to the attachment return true as next nodes need to preserve the attachment.
4819 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Chia-I Wud50a7d72015-10-26 20:48:51 +08004820 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07004821 if (attachment == subpass.pColorAttachments[j].attachment)
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07004822 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07004823 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08004824 if (subpass.pDepthStencilAttachment &&
4825 subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
4826 if (attachment == subpass.pDepthStencilAttachment->attachment)
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07004827 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07004828 }
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07004829 VkBool32 result = VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07004830 // Loop through previous nodes and see if any of them write to the attachment.
4831 for (auto elem : node.prev) {
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004832 result |= CheckPreserved(my_data, device, pCreateInfo, elem, attachment, subpass_to_node, depth + 1, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07004833 }
4834 // If the attachment was written to by a previous node than this node needs to preserve it.
4835 if (result && depth > 0) {
4836 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07004837 VkBool32 has_preserved = false;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004838 for (uint32_t j = 0; j < subpass.preserveAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07004839 if (subpass.pPreserveAttachments[j].attachment == attachment) {
4840 has_preserved = true;
4841 break;
4842 }
4843 }
4844 if (!has_preserved) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004845 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_RENDERPASS, "DS",
Michael Lentineb6986752015-10-06 14:56:18 -07004846 "Attachment %d is used by a later subpass and must be preserved in subpass %d.", attachment, index);
4847 }
4848 }
4849 return result;
4850}
4851
Michael Lentineb4979492015-12-22 11:36:14 -06004852VkBool32 ValidateDependencies(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, const std::vector<DAGNode>& subpass_to_node) {
4853 VkBool32 skip_call = false;
Michael Lentineb6986752015-10-06 14:56:18 -07004854 std::vector<std::vector<uint32_t>> output_attachment_to_subpass(pCreateInfo->attachmentCount);
4855 std::vector<std::vector<uint32_t>> input_attachment_to_subpass(pCreateInfo->attachmentCount);
Michael Lentineb6986752015-10-06 14:56:18 -07004856 // Find for each attachment the subpasses that use them.
4857 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
4858 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08004859 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07004860 input_attachment_to_subpass[subpass.pInputAttachments[j].attachment].push_back(i);
4861 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08004862 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07004863 output_attachment_to_subpass[subpass.pColorAttachments[j].attachment].push_back(i);
4864 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08004865 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
4866 output_attachment_to_subpass[subpass.pDepthStencilAttachment->attachment].push_back(i);
Michael Lentineb6986752015-10-06 14:56:18 -07004867 }
4868 }
4869 // If there is a dependency needed make sure one exists
4870 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
4871 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
4872 // If the attachment is an input then all subpasses that output must have a dependency relationship
Chia-I Wud50a7d72015-10-26 20:48:51 +08004873 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07004874 const uint32_t& attachment = subpass.pInputAttachments[j].attachment;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004875 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07004876 }
4877 // If the attachment is an output then all subpasses that use the attachment must have a dependency relationship
Chia-I Wud50a7d72015-10-26 20:48:51 +08004878 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07004879 const uint32_t& attachment = subpass.pColorAttachments[j].attachment;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004880 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
4881 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07004882 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08004883 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
4884 const uint32_t& attachment = subpass.pDepthStencilAttachment->attachment;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004885 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
4886 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07004887 }
4888 }
4889 // Loop through implicit dependencies, if this pass reads make sure the attachment is preserved for all passes after it was written.
4890 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
4891 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08004892 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004893 CheckPreserved(my_data, device, pCreateInfo, i, subpass.pInputAttachments[j].attachment, subpass_to_node, 0, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07004894 }
4895 }
4896 return skip_call;
4897}
4898
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07004899VkBool32 ValidateLayouts(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo) {
4900 VkBool32 skip = false;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07004901
4902#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4903 return skip;
4904#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4905
Michael Lentineabc5e922015-10-12 11:30:14 -05004906 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
4907 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
4908 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
4909 if (subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL &&
4910 subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) {
4911 if (subpass.pInputAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004912 // TODO: Verify Valid Use in spec. I believe this is allowed (valid) but may not be optimal performance
4913 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05004914 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
4915 } else {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004916 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05004917 "Layout for input attachment is %d but can only be READ_ONLY_OPTIMAL or GENERAL.", subpass.pInputAttachments[j].attachment);
4918 }
4919 }
4920 }
4921 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
4922 if (subpass.pColorAttachments[j].layout != VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) {
4923 if (subpass.pColorAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004924 // TODO: Verify Valid Use in spec. I believe this is allowed (valid) but may not be optimal performance
4925 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05004926 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
4927 } else {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004928 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05004929 "Layout for color attachment is %d but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.", subpass.pColorAttachments[j].attachment);
4930 }
4931 }
4932 }
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06004933 if ((subpass.pDepthStencilAttachment != NULL) &&
4934 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
Michael Lentineabc5e922015-10-12 11:30:14 -05004935 if (subpass.pDepthStencilAttachment->layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) {
4936 if (subpass.pDepthStencilAttachment->layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004937 // TODO: Verify Valid Use in spec. I believe this is allowed (valid) but may not be optimal performance
4938 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05004939 "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL.");
4940 } else {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004941 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05004942 "Layout for depth attachment is %d but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL.", subpass.pDepthStencilAttachment->attachment);
4943 }
4944 }
4945 }
4946 }
4947 return skip;
4948}
4949
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07004950VkBool32 CreatePassDAG(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, std::vector<DAGNode>& subpass_to_node, std::vector<bool>& has_self_dependency) {
4951 VkBool32 skip_call = false;
Michael Lentineabc5e922015-10-12 11:30:14 -05004952 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
4953 DAGNode& subpass_node = subpass_to_node[i];
4954 subpass_node.pass = i;
4955 }
4956 for (uint32_t i = 0; i < pCreateInfo->dependencyCount; ++i) {
4957 const VkSubpassDependency& dependency = pCreateInfo->pDependencies[i];
4958 if (dependency.srcSubpass > dependency.dstSubpass) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004959 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_RENDERPASS, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05004960 "Depedency graph must be specified such that an earlier pass cannot depend on a later pass.");
Michael Lentine48930b82015-10-15 17:07:00 -05004961 } else if (dependency.srcSubpass == dependency.dstSubpass) {
4962 has_self_dependency[dependency.srcSubpass] = true;
Michael Lentineabc5e922015-10-12 11:30:14 -05004963 }
4964 subpass_to_node[dependency.dstSubpass].prev.push_back(dependency.srcSubpass);
4965 subpass_to_node[dependency.srcSubpass].next.push_back(dependency.dstSubpass);
4966 }
4967 return skip_call;
4968}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07004969// TODOSC : Add intercept of vkCreateShaderModule
Michael Lentineabc5e922015-10-12 11:30:14 -05004970
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07004971VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateShaderModule(
4972 VkDevice device,
4973 const VkShaderModuleCreateInfo *pCreateInfo,
4974 const VkAllocationCallbacks* pAllocator,
4975 VkShaderModule *pShaderModule)
4976{
4977 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07004978 VkBool32 skip_call = false;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07004979 if (!shader_is_spirv(pCreateInfo)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004980 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07004981 /* dev */ 0, 0, SHADER_CHECKER_NON_SPIRV_SHADER, "SC",
4982 "Shader is not SPIR-V");
4983 }
4984
4985 if (skip_call)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004986 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07004987
4988 VkResult res = my_data->device_dispatch_table->CreateShaderModule(device, pCreateInfo, pAllocator, pShaderModule);
4989
4990 if (res == VK_SUCCESS) {
4991 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07004992 my_data->shaderModuleMap[*pShaderModule] = new shader_module(pCreateInfo);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07004993 loader_platform_thread_unlock_mutex(&globalLock);
4994 }
4995 return res;
4996}
4997
Chia-I Wu9ab61502015-11-06 06:42:02 +08004998VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkRenderPass* pRenderPass)
Tobin Ehliseba312c2015-04-01 08:40:34 -06004999{
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005000 VkBool32 skip_call = false;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005001 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentineabc5e922015-10-12 11:30:14 -05005002 // Create DAG
Michael Lentine48930b82015-10-15 17:07:00 -05005003 std::vector<bool> has_self_dependency(pCreateInfo->subpassCount);
Michael Lentineabc5e922015-10-12 11:30:14 -05005004 std::vector<DAGNode> subpass_to_node(pCreateInfo->subpassCount);
Michael Lentine48930b82015-10-15 17:07:00 -05005005 skip_call |= CreatePassDAG(dev_data, device, pCreateInfo, subpass_to_node, has_self_dependency);
Michael Lentineabc5e922015-10-12 11:30:14 -05005006 // Validate using DAG
5007 skip_call |= ValidateDependencies(dev_data, device, pCreateInfo, subpass_to_node);
5008 skip_call |= ValidateLayouts(dev_data, device, pCreateInfo);
5009 if (skip_call) {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005010 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentineb6986752015-10-06 14:56:18 -07005011 }
Chia-I Wuf7458c52015-10-26 21:10:41 +08005012 VkResult result = dev_data->device_dispatch_table->CreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005013 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005014 // TODOSC : Merge in tracking of renderpass from ShaderChecker
Tobin Ehliseba312c2015-04-01 08:40:34 -06005015 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06005016 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +08005017 if (pCreateInfo->pAttachments) {
5018 localRPCI->pAttachments = new VkAttachmentDescription[localRPCI->attachmentCount];
5019 memcpy((void*)localRPCI->pAttachments, pCreateInfo->pAttachments, localRPCI->attachmentCount*sizeof(VkAttachmentDescription));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005020 }
Chia-I Wu08accc62015-07-07 11:50:03 +08005021 if (pCreateInfo->pSubpasses) {
5022 localRPCI->pSubpasses = new VkSubpassDescription[localRPCI->subpassCount];
5023 memcpy((void*)localRPCI->pSubpasses, pCreateInfo->pSubpasses, localRPCI->subpassCount*sizeof(VkSubpassDescription));
5024
5025 for (uint32_t i = 0; i < localRPCI->subpassCount; i++) {
5026 VkSubpassDescription *subpass = (VkSubpassDescription *) &localRPCI->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005027 const uint32_t attachmentCount = subpass->inputAttachmentCount +
5028 subpass->colorAttachmentCount * (1 + (subpass->pResolveAttachments?1:0)) +
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005029 ((subpass->pDepthStencilAttachment) ? 1 : 0) + subpass->preserveAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005030 VkAttachmentReference *attachments = new VkAttachmentReference[attachmentCount];
5031
Cody Northropa505dda2015-08-04 11:16:41 -06005032 memcpy(attachments, subpass->pInputAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005033 sizeof(attachments[0]) * subpass->inputAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005034 subpass->pInputAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005035 attachments += subpass->inputAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005036
Cody Northropa505dda2015-08-04 11:16:41 -06005037 memcpy(attachments, subpass->pColorAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005038 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005039 subpass->pColorAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005040 attachments += subpass->colorAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005041
Cody Northropa505dda2015-08-04 11:16:41 -06005042 if (subpass->pResolveAttachments) {
5043 memcpy(attachments, subpass->pResolveAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005044 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005045 subpass->pResolveAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005046 attachments += subpass->colorAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005047 }
5048
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005049 if (subpass->pDepthStencilAttachment) {
5050 memcpy(attachments, subpass->pDepthStencilAttachment,
5051 sizeof(attachments[0]) * 1);
5052 subpass->pDepthStencilAttachment = attachments;
5053 attachments += 1;
5054 }
5055
Cody Northropa505dda2015-08-04 11:16:41 -06005056 memcpy(attachments, subpass->pPreserveAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005057 sizeof(attachments[0]) * subpass->preserveAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005058 subpass->pPreserveAttachments = attachments;
Chia-I Wu08accc62015-07-07 11:50:03 +08005059 }
Tobin Ehliseba312c2015-04-01 08:40:34 -06005060 }
Chia-I Wu08accc62015-07-07 11:50:03 +08005061 if (pCreateInfo->pDependencies) {
5062 localRPCI->pDependencies = new VkSubpassDependency[localRPCI->dependencyCount];
5063 memcpy((void*)localRPCI->pDependencies, pCreateInfo->pDependencies, localRPCI->dependencyCount*sizeof(VkSubpassDependency));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005064 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005065 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005066 dev_data->renderPassMap[*pRenderPass] = new RENDER_PASS_NODE(localRPCI);
Michael Lentine48930b82015-10-15 17:07:00 -05005067 dev_data->renderPassMap[*pRenderPass]->hasSelfDependency = has_self_dependency;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005068 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehliseba312c2015-04-01 08:40:34 -06005069 }
5070 return result;
5071}
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005072// Free the renderpass shadow
5073static void deleteRenderPasses(layer_data* my_data)
5074{
5075 if (my_data->renderPassMap.size() <= 0)
5076 return;
5077 for (auto ii=my_data->renderPassMap.begin(); ii!=my_data->renderPassMap.end(); ++ii) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005078 const VkRenderPassCreateInfo* pRenderPassInfo = (*ii).second->pCreateInfo;
Michael Lentine48930b82015-10-15 17:07:00 -05005079 if (pRenderPassInfo->pAttachments) {
5080 delete[] pRenderPassInfo->pAttachments;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005081 }
Michael Lentine48930b82015-10-15 17:07:00 -05005082 if (pRenderPassInfo->pSubpasses) {
5083 for (uint32_t i=0; i<pRenderPassInfo->subpassCount; ++i) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005084 // Attachements are all allocated in a block, so just need to
5085 // find the first non-null one to delete
Michael Lentine48930b82015-10-15 17:07:00 -05005086 if (pRenderPassInfo->pSubpasses[i].pInputAttachments) {
5087 delete[] pRenderPassInfo->pSubpasses[i].pInputAttachments;
5088 } else if (pRenderPassInfo->pSubpasses[i].pColorAttachments) {
5089 delete[] pRenderPassInfo->pSubpasses[i].pColorAttachments;
5090 } else if (pRenderPassInfo->pSubpasses[i].pResolveAttachments) {
5091 delete[] pRenderPassInfo->pSubpasses[i].pResolveAttachments;
5092 } else if (pRenderPassInfo->pSubpasses[i].pPreserveAttachments) {
5093 delete[] pRenderPassInfo->pSubpasses[i].pPreserveAttachments;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005094 }
5095 }
Michael Lentine48930b82015-10-15 17:07:00 -05005096 delete[] pRenderPassInfo->pSubpasses;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005097 }
Michael Lentine48930b82015-10-15 17:07:00 -05005098 if (pRenderPassInfo->pDependencies) {
5099 delete[] pRenderPassInfo->pDependencies;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005100 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005101 delete pRenderPassInfo;
Michael Lentine48930b82015-10-15 17:07:00 -05005102 delete (*ii).second;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005103 }
5104 my_data->renderPassMap.clear();
5105}
Michael Lentineabc5e922015-10-12 11:30:14 -05005106
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005107VkBool32 VerifyFramebufferAndRenderPassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
5108 VkBool32 skip_call = false;
Michael Lentineabc5e922015-10-12 11:30:14 -05005109 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5110 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005111 const VkRenderPassCreateInfo* pRenderPassInfo = dev_data->renderPassMap[pRenderPassBegin->renderPass]->pCreateInfo;
Michael Lentineabc5e922015-10-12 11:30:14 -05005112 const VkFramebufferCreateInfo* pFramebufferInfo = dev_data->frameBufferMap[pRenderPassBegin->framebuffer];
5113 if (pRenderPassInfo->attachmentCount != pFramebufferInfo->attachmentCount) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005114 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_RENDERPASS, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05005115 "You cannot start a render pass using a framebuffer with a different number of attachments.");
5116 }
5117 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
5118 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
5119 const VkImage& image = dev_data->imageViewMap[image_view]->image;
5120 auto image_data = pCB->imageLayoutMap.find(image);
5121 if (image_data == pCB->imageLayoutMap.end()) {
5122 pCB->imageLayoutMap[image].initialLayout = pRenderPassInfo->pAttachments[i].initialLayout;
5123 pCB->imageLayoutMap[image].layout = pRenderPassInfo->pAttachments[i].initialLayout;
5124 } else if (pRenderPassInfo->pAttachments[i].initialLayout != image_data->second.layout) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005125 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_RENDERPASS, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05005126 "You cannot start a render pass using attachment %i where the intial layout differs from the starting layout.", i);
5127 }
5128 }
5129 return skip_call;
5130}
5131
5132void TransitionSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, const int subpass_index) {
5133 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5134 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5135 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
5136 if (render_pass_data == dev_data->renderPassMap.end()) {
5137 return;
5138 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005139 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
Michael Lentineabc5e922015-10-12 11:30:14 -05005140 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
5141 if (framebuffer_data == dev_data->frameBufferMap.end()) {
5142 return;
5143 }
5144 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
5145 const VkSubpassDescription& subpass = pRenderPassInfo->pSubpasses[subpass_index];
5146 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
5147 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pInputAttachments[j].attachment];
5148 auto image_view_data = dev_data->imageViewMap.find(image_view);
5149 if (image_view_data != dev_data->imageViewMap.end()) {
5150 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5151 if (image_layout != pCB->imageLayoutMap.end()) {
5152 image_layout->second.layout = subpass.pInputAttachments[j].layout;
5153 }
5154 }
5155 }
5156 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
5157 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pColorAttachments[j].attachment];
5158 auto image_view_data = dev_data->imageViewMap.find(image_view);
5159 if (image_view_data != dev_data->imageViewMap.end()) {
5160 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5161 if (image_layout != pCB->imageLayoutMap.end()) {
5162 image_layout->second.layout = subpass.pColorAttachments[j].layout;
5163 }
5164 }
5165 }
Michael Lentine3dea6512015-10-28 15:55:18 -07005166 if ((subpass.pDepthStencilAttachment != NULL) &&
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005167 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
Michael Lentineabc5e922015-10-12 11:30:14 -05005168 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pDepthStencilAttachment->attachment];
5169 auto image_view_data = dev_data->imageViewMap.find(image_view);
5170 if (image_view_data != dev_data->imageViewMap.end()) {
5171 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5172 if (image_layout != pCB->imageLayoutMap.end()) {
5173 image_layout->second.layout = subpass.pDepthStencilAttachment->layout;
5174 }
5175 }
5176 }
5177}
5178
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005179VkBool32 validatePrimaryCommandBuffer(const layer_data* my_data, const GLOBAL_CB_NODE* pCB, const std::string& cmd_name) {
5180 VkBool32 skip_call = false;
Michael Lentine3dea6512015-10-28 15:55:18 -07005181 if (pCB->createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005182 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, 0, DRAWSTATE_INVALID_COMMAND_BUFFER, "DS",
Michael Lentine3dea6512015-10-28 15:55:18 -07005183 "Cannot execute command %s on a secondary command buffer.", cmd_name.c_str());
5184 }
5185 return skip_call;
5186}
5187
Michael Lentineabc5e922015-10-12 11:30:14 -05005188void TransitionFinalSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
5189 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5190 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5191 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
5192 if (render_pass_data == dev_data->renderPassMap.end()) {
5193 return;
5194 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005195 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
Michael Lentineabc5e922015-10-12 11:30:14 -05005196 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
5197 if (framebuffer_data == dev_data->frameBufferMap.end()) {
5198 return;
5199 }
5200 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
5201 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
5202 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
5203 auto image_view_data = dev_data->imageViewMap.find(image_view);
5204 if (image_view_data != dev_data->imageViewMap.end()) {
5205 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5206 if (image_layout != pCB->imageLayoutMap.end()) {
5207 image_layout->second.layout = pRenderPassInfo->pAttachments[i].finalLayout;
5208 }
5209 }
5210 }
5211}
5212
Chia-I Wu9ab61502015-11-06 06:42:02 +08005213VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, VkSubpassContents contents)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005214{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005215 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005216 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5217 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005218 if (pCB) {
Tobin Ehlis259730a2015-06-23 16:13:03 -06005219 if (pRenderPassBegin && pRenderPassBegin->renderPass) {
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005220 skipCall |= VerifyFramebufferAndRenderPassLayouts(commandBuffer, pRenderPassBegin);
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005221 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBeginRenderPass");
Michael Lentine3dea6512015-10-28 15:55:18 -07005222 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdBeginRenderPass");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005223 skipCall |= addCmd(dev_data, pCB, CMD_BEGINRENDERPASS, "vkCmdBeginRenderPass()");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005224 pCB->activeRenderPass = pRenderPassBegin->renderPass;
Michael Lentineabc5e922015-10-12 11:30:14 -05005225 // This is a shallow copy as that is all that is needed for now
5226 pCB->activeRenderPassBeginInfo = *pRenderPassBegin;
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005227 pCB->activeSubpass = 0;
5228 pCB->framebuffer = pRenderPassBegin->framebuffer;
5229 if (pCB->lastBoundPipeline) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005230 skipCall |= validatePipelineState(dev_data, pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Tobin Ehlis259730a2015-06-23 16:13:03 -06005231 }
Tobin Ehlis502480b2015-06-24 15:53:07 -06005232 } else {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005233 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS, "DS",
Tobin Ehlis259730a2015-06-23 16:13:03 -06005234 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tony Barbourbadda992015-04-06 11:09:26 -06005235 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005236 }
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005237 if (VK_FALSE == skipCall) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005238 dev_data->device_dispatch_table->CmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents);
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005239 // This is a shallow copy as that is all that is needed for now
5240 dev_data->renderPassBeginInfo = *pRenderPassBegin;
5241 dev_data->currentSubpass = 0;
5242 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005243}
5244
Chia-I Wu9ab61502015-11-06 06:42:02 +08005245VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents)
Chia-I Wu08accc62015-07-07 11:50:03 +08005246{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005247 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005248 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5249 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Michael Lentineabc5e922015-10-12 11:30:14 -05005250 TransitionSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo, ++dev_data->currentSubpass);
Chia-I Wu08accc62015-07-07 11:50:03 +08005251 if (pCB) {
Michael Lentine3dea6512015-10-28 15:55:18 -07005252 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdNextSubpass");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005253 skipCall |= addCmd(dev_data, pCB, CMD_NEXTSUBPASS, "vkCmdNextSubpass()");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005254 pCB->activeSubpass++;
Tony Barbour6e1b5ba2015-12-15 10:24:45 -07005255 TransitionSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo, pCB->activeSubpass);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005256 if (pCB->lastBoundPipeline) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005257 skipCall |= validatePipelineState(dev_data, pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Chia-I Wu08accc62015-07-07 11:50:03 +08005258 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005259 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdNextSubpass");
Chia-I Wu08accc62015-07-07 11:50:03 +08005260 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005261 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005262 dev_data->device_dispatch_table->CmdNextSubpass(commandBuffer, contents);
Chia-I Wu08accc62015-07-07 11:50:03 +08005263}
5264
Chia-I Wu9ab61502015-11-06 06:42:02 +08005265VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndRenderPass(VkCommandBuffer commandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005266{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005267 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005268 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5269 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Michael Lentineabc5e922015-10-12 11:30:14 -05005270 TransitionFinalSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005271 if (pCB) {
Michael Lentine3dea6512015-10-28 15:55:18 -07005272 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdEndRenderpass");
Michael Lentine3dea6512015-10-28 15:55:18 -07005273 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdEndRenderPass");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005274 skipCall |= addCmd(dev_data, pCB, CMD_ENDRENDERPASS, "vkCmdEndRenderPass()");
Michael Lentineabc5e922015-10-12 11:30:14 -05005275 TransitionFinalSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005276 pCB->activeRenderPass = 0;
5277 pCB->activeSubpass = 0;
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005278 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005279 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005280 dev_data->device_dispatch_table->CmdEndRenderPass(commandBuffer);
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005281}
5282
Chia-I Wu9ab61502015-11-06 06:42:02 +08005283VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount, const VkCommandBuffer* pCommandBuffers)
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005284{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005285 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005286 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5287 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005288 if (pCB) {
Tobin Ehlis651d9b02015-12-16 05:01:22 -07005289 // TODO : If secondary CB was not created w/ *_USAGE_SIMULTANEOUS_USE_BIT it cannot be used more than once in given primary CB
5290 // ALSO if secondary w/o this flag is set in primary, then primary must not be pending execution more than once at a time
5291 // If not w/ SIMULTANEOUS bit, then any other references to those 2ndary CBs are invalidated, should warn on that case
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06005292 GLOBAL_CB_NODE* pSubCB = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005293 for (uint32_t i=0; i<commandBuffersCount; i++) {
5294 pSubCB = getCBNode(dev_data, pCommandBuffers[i]);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06005295 if (!pSubCB) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005296 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_INVALID_SECONDARY_COMMAND_BUFFER, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005297 "vkCmdExecuteCommands() called w/ invalid Cmd Buffer %p in element %u of pCommandBuffers array.", (void*)pCommandBuffers[i], i);
5298 } else if (VK_COMMAND_BUFFER_LEVEL_PRIMARY == pSubCB->createInfo.level) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005299 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_INVALID_SECONDARY_COMMAND_BUFFER, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005300 "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 Ehlis651d9b02015-12-16 05:01:22 -07005301 } else if (pCB->activeRenderPass) { // Secondary CB w/i RenderPass must have *CONTINUE_BIT set
5302 if (!(pSubCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT)) {
5303 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)pCommandBuffers[i], 0, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
5304 "vkCmdExecuteCommands(): Secondary Command Buffer (%p) executed within render pass (%#" PRIxLEAST64 ") must have had vkBeginCommandBuffer() called w/ VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT set.", (void*)pCommandBuffers[i], (uint64_t)pCB->activeRenderPass);
5305 }
5306 string errorString = "";
5307 if (!verify_renderpass_compatibility(dev_data, pCB->activeRenderPass, pSubCB->beginInfo.renderPass, errorString)) {
5308 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)pCommandBuffers[i], 0, DRAWSTATE_RENDERPASS_INCOMPATIBLE, "DS",
5309 "vkCmdExecuteCommands(): Secondary Command Buffer (%p) w/ render pass (%#" PRIxLEAST64 ") is incompatible w/ primary command buffer (%p) w/ render pass (%#" PRIxLEAST64 ") due to: %s",
5310 (void*)pCommandBuffers[i], (uint64_t)pSubCB->beginInfo.renderPass, (void*)commandBuffer, (uint64_t)pCB->activeRenderPass, errorString.c_str());
5311 }
5312 // If framebuffer for secondary CB is not NULL, then it must match FB from vkCmdBeginRenderPass()
5313 // that this CB will be executed in AND framebuffer must have been created w/ RP compatible w/ renderpass
5314 if (pSubCB->beginInfo.framebuffer) {
5315 if (pSubCB->beginInfo.framebuffer != pCB->activeRenderPassBeginInfo.framebuffer) {
5316 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)pCommandBuffers[i], 0, DRAWSTATE_FRAMEBUFFER_INCOMPATIBLE, "DS",
5317 "vkCmdExecuteCommands(): Secondary Command Buffer (%p) references framebuffer (%#" PRIxLEAST64 ") that does not match framebuffer (%#" PRIxLEAST64 ") in active renderpass (%#" PRIxLEAST64 ").",
5318 (void*)pCommandBuffers[i], (uint64_t)pSubCB->beginInfo.framebuffer, (uint64_t)pCB->activeRenderPassBeginInfo.framebuffer, (uint64_t)pCB->activeRenderPass);
5319 }
5320 }
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06005321 }
5322 }
Michael Lentine3dea6512015-10-28 15:55:18 -07005323 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdExecuteComands");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005324 skipCall |= addCmd(dev_data, pCB, CMD_EXECUTECOMMANDS, "vkCmdExecuteComands()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005325 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005326 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005327 dev_data->device_dispatch_table->CmdExecuteCommands(commandBuffer, commandBuffersCount, pCommandBuffers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005328}
5329
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005330VkBool32 ValidateMapImageLayouts(VkDevice device, VkDeviceMemory mem) {
5331 VkBool32 skip_call = false;
Michael Lentine7b236262015-10-23 12:41:44 -07005332 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5333 auto mem_data = dev_data->memImageMap.find(mem);
5334 if (mem_data != dev_data->memImageMap.end()) {
5335 auto image_data = dev_data->imageLayoutMap.find(mem_data->second);
5336 if (image_data != dev_data->imageLayoutMap.end()) {
5337 if (image_data->second->layout != VK_IMAGE_LAYOUT_PREINITIALIZED && image_data->second->layout != VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005338 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentine7b236262015-10-23 12:41:44 -07005339 "Cannot map an image with layout %d. Only GENERAL or PREINITIALIZED are supported.", image_data->second->layout);
5340 }
5341 }
5342 }
5343 return skip_call;
5344}
5345
Chia-I Wu9ab61502015-11-06 06:42:02 +08005346VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkMapMemory(
Michael Lentine7b236262015-10-23 12:41:44 -07005347 VkDevice device,
5348 VkDeviceMemory mem,
5349 VkDeviceSize offset,
5350 VkDeviceSize size,
5351 VkFlags flags,
5352 void **ppData)
5353{
5354 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005355
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005356 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005357#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
5358 skip_call = ValidateMapImageLayouts(device, mem);
5359#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5360
Michael Lentine7b236262015-10-23 12:41:44 -07005361 if (VK_FALSE == skip_call) {
5362 return dev_data->device_dispatch_table->MapMemory(device, mem, offset, size, flags, ppData);
5363 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005364 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine7b236262015-10-23 12:41:44 -07005365}
5366
Chia-I Wu9ab61502015-11-06 06:42:02 +08005367VKAPI_ATTR VkResult VKAPI_CALL vkBindImageMemory(
Michael Lentine7b236262015-10-23 12:41:44 -07005368 VkDevice device,
5369 VkImage image,
5370 VkDeviceMemory mem,
5371 VkDeviceSize memOffset)
5372{
5373 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5374 VkResult result = dev_data->device_dispatch_table->BindImageMemory(device, image, mem, memOffset);
5375 loader_platform_thread_lock_mutex(&globalLock);
5376 dev_data->memImageMap[mem] = image;
5377 loader_platform_thread_unlock_mutex(&globalLock);
5378 return result;
5379}
5380
Chia-I Wu9ab61502015-11-06 06:42:02 +08005381VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(
Michael Lentineabc5e922015-10-12 11:30:14 -05005382 VkDevice device,
5383 const VkSwapchainCreateInfoKHR *pCreateInfo,
Ian Elliott05846062015-11-20 14:13:17 -07005384 const VkAllocationCallbacks *pAllocator,
Michael Lentineabc5e922015-10-12 11:30:14 -05005385 VkSwapchainKHR *pSwapchain)
5386{
5387 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott05846062015-11-20 14:13:17 -07005388 VkResult result = dev_data->device_dispatch_table->CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
Michael Lentineabc5e922015-10-12 11:30:14 -05005389
5390 if (VK_SUCCESS == result) {
5391 SWAPCHAIN_NODE *swapchain_data = new SWAPCHAIN_NODE;
5392 loader_platform_thread_lock_mutex(&globalLock);
5393 dev_data->device_extensions.swapchainMap[*pSwapchain] = swapchain_data;
5394 loader_platform_thread_unlock_mutex(&globalLock);
5395 }
5396
5397 return result;
5398}
5399
Ian Elliott05846062015-11-20 14:13:17 -07005400VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR(
Michael Lentineabc5e922015-10-12 11:30:14 -05005401 VkDevice device,
Ian Elliott05846062015-11-20 14:13:17 -07005402 VkSwapchainKHR swapchain,
5403 const VkAllocationCallbacks *pAllocator)
Michael Lentineabc5e922015-10-12 11:30:14 -05005404{
5405 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentineabc5e922015-10-12 11:30:14 -05005406
5407 loader_platform_thread_lock_mutex(&globalLock);
5408 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(swapchain);
5409 if (swapchain_data != dev_data->device_extensions.swapchainMap.end()) {
5410 if (swapchain_data->second->images.size() > 0) {
5411 for (auto swapchain_image : swapchain_data->second->images) {
5412 auto image_item = dev_data->imageLayoutMap.find(swapchain_image);
5413 if (image_item != dev_data->imageLayoutMap.end())
5414 dev_data->imageLayoutMap.erase(image_item);
5415 }
5416 }
5417 delete swapchain_data->second;
5418 dev_data->device_extensions.swapchainMap.erase(swapchain);
5419 }
5420 loader_platform_thread_unlock_mutex(&globalLock);
Ian Elliott05846062015-11-20 14:13:17 -07005421 return dev_data->device_dispatch_table->DestroySwapchainKHR(device, swapchain, pAllocator);
Michael Lentineabc5e922015-10-12 11:30:14 -05005422}
5423
Chia-I Wu9ab61502015-11-06 06:42:02 +08005424VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR(
Michael Lentineabc5e922015-10-12 11:30:14 -05005425 VkDevice device,
5426 VkSwapchainKHR swapchain,
5427 uint32_t* pCount,
5428 VkImage* pSwapchainImages)
5429{
5430 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5431 VkResult result = dev_data->device_dispatch_table->GetSwapchainImagesKHR(device, swapchain, pCount, pSwapchainImages);
5432
5433 if (result == VK_SUCCESS && pSwapchainImages != NULL) {
5434 // This should never happen and is checked by param checker.
5435 if (!pCount) return result;
5436 for (uint32_t i = 0; i < *pCount; ++i) {
5437 IMAGE_NODE* image_node = new IMAGE_NODE;
5438 image_node->layout = VK_IMAGE_LAYOUT_UNDEFINED;
5439 loader_platform_thread_lock_mutex(&globalLock);
5440 dev_data->device_extensions.swapchainMap[swapchain]->images.push_back(pSwapchainImages[i]);
5441 dev_data->imageLayoutMap[pSwapchainImages[i]] = image_node;
5442 loader_platform_thread_unlock_mutex(&globalLock);
5443 }
5444 }
5445 return result;
5446}
5447
Ian Elliott05846062015-11-20 14:13:17 -07005448VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo)
Michael Lentineabc5e922015-10-12 11:30:14 -05005449{
5450 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005451 VkBool32 skip_call = false;
Michael Lentineabc5e922015-10-12 11:30:14 -05005452
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005453#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentineabc5e922015-10-12 11:30:14 -05005454 if (pPresentInfo) {
5455 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
Ian Elliott05846062015-11-20 14:13:17 -07005456 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(pPresentInfo->pSwapchains[i]);
5457 if (swapchain_data != dev_data->device_extensions.swapchainMap.end() && pPresentInfo->pImageIndices[i] < swapchain_data->second->images.size()) {
5458 VkImage image = swapchain_data->second->images[pPresentInfo->pImageIndices[i]];
Michael Lentineabc5e922015-10-12 11:30:14 -05005459 auto image_data = dev_data->imageLayoutMap.find(image);
5460 if (image_data != dev_data->imageLayoutMap.end()) {
Ian Elliott05846062015-11-20 14:13:17 -07005461 if (image_data->second->layout != VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005462 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT, (uint64_t)queue, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05005463 "Images passed to present must be in layout PRESENT_SOURCE_KHR but is in %d", image_data->second->layout);
5464 }
5465 }
5466 }
5467 }
5468 }
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005469#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentineabc5e922015-10-12 11:30:14 -05005470
5471 if (VK_FALSE == skip_call)
5472 return dev_data->device_dispatch_table->QueuePresentKHR(queue, pPresentInfo);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005473 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentineabc5e922015-10-12 11:30:14 -05005474}
5475
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005476VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(
5477 VkInstance instance,
5478 const VkDebugReportCallbackCreateInfoEXT* pCreateInfo,
5479 const VkAllocationCallbacks* pAllocator,
5480 VkDebugReportCallbackEXT* pMsgCallback)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005481{
Tobin Ehlis0b632332015-10-07 09:38:40 -06005482 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07005483 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005484 VkResult res = pTable->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06005485 if (VK_SUCCESS == res) {
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07005486 res = layer_create_msg_callback(my_data->report_data, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06005487 }
5488 return res;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005489}
5490
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005491VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07005492 VkInstance instance,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005493 VkDebugReportCallbackEXT msgCallback,
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07005494 const VkAllocationCallbacks* pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005495{
Tobin Ehlis0b632332015-10-07 09:38:40 -06005496 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07005497 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005498 pTable->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07005499 layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005500}
5501
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005502VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDebugReportMessageEXT(
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07005503 VkInstance instance,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005504 VkDebugReportFlagsEXT flags,
5505 VkDebugReportObjectTypeEXT objType,
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07005506 uint64_t object,
5507 size_t location,
5508 int32_t msgCode,
5509 const char* pLayerPrefix,
5510 const char* pMsg)
5511{
5512 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005513 my_data->instance_dispatch_table->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg);
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07005514}
5515
Chia-I Wu9ab61502015-11-06 06:42:02 +08005516VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerBegin(VkCommandBuffer commandBuffer, const char* pMarker)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005517{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005518 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005519 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5520 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis0b632332015-10-07 09:38:40 -06005521 if (!dev_data->device_extensions.debug_marker_enabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005522 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06005523 "Attempt to use CmdDbgMarkerBegin but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06005524 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06005525 } else if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005526 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKERBEGIN, "vkCmdDbgMarkerBegin()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005527 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005528 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005529 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerBegin(commandBuffer, pMarker);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005530}
5531
Chia-I Wu9ab61502015-11-06 06:42:02 +08005532VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerEnd(VkCommandBuffer commandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005533{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005534 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005535 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5536 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis0b632332015-10-07 09:38:40 -06005537 if (!dev_data->device_extensions.debug_marker_enabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005538 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06005539 "Attempt to use CmdDbgMarkerEnd but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06005540 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06005541 } else if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005542 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKEREND, "vkCmdDbgMarkerEnd()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005543 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005544 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005545 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerEnd(commandBuffer);
Jon Ashburneab34492015-06-01 09:37:38 -06005546}
5547
Chia-I Wu9ab61502015-11-06 06:42:02 +08005548VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005549{
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06005550 if (dev == NULL)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005551 return NULL;
Jon Ashburn3950e1b2015-05-20 09:00:28 -06005552
Tobin Ehlis0b632332015-10-07 09:38:40 -06005553 layer_data *dev_data;
Jon Ashburn8fd08252015-05-28 16:25:02 -06005554 /* loader uses this to force layer initialization; device object is wrapped */
5555 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
Tobin Ehlis0b632332015-10-07 09:38:40 -06005556 VkBaseLayerObject* wrapped_dev = (VkBaseLayerObject*) dev;
5557 dev_data = get_my_data_ptr(get_dispatch_key(wrapped_dev->baseObject), layer_data_map);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005558 dev_data->device_dispatch_table = new VkLayerDispatchTable;
5559 layer_initialize_dispatch_table(dev_data->device_dispatch_table, wrapped_dev);
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005560 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -06005561 }
Tobin Ehlis0b632332015-10-07 09:38:40 -06005562 dev_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map);
Courtney Goeltzenleuchterca173b82015-06-25 18:01:43 -06005563 if (!strcmp(funcName, "vkCreateDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005564 return (PFN_vkVoidFunction) vkCreateDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005565 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005566 return (PFN_vkVoidFunction) vkDestroyDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005567 if (!strcmp(funcName, "vkQueueSubmit"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005568 return (PFN_vkVoidFunction) vkQueueSubmit;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06005569 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005570 return (PFN_vkVoidFunction) vkDestroyInstance;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06005571 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005572 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06005573 if (!strcmp(funcName, "vkDestroyFence"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005574 return (PFN_vkVoidFunction) vkDestroyFence;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06005575 if (!strcmp(funcName, "vkDestroySemaphore"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005576 return (PFN_vkVoidFunction) vkDestroySemaphore;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06005577 if (!strcmp(funcName, "vkDestroyEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005578 return (PFN_vkVoidFunction) vkDestroyEvent;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06005579 if (!strcmp(funcName, "vkDestroyQueryPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005580 return (PFN_vkVoidFunction) vkDestroyQueryPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06005581 if (!strcmp(funcName, "vkDestroyBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005582 return (PFN_vkVoidFunction) vkDestroyBuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06005583 if (!strcmp(funcName, "vkDestroyBufferView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005584 return (PFN_vkVoidFunction) vkDestroyBufferView;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06005585 if (!strcmp(funcName, "vkDestroyImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005586 return (PFN_vkVoidFunction) vkDestroyImage;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06005587 if (!strcmp(funcName, "vkDestroyImageView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005588 return (PFN_vkVoidFunction) vkDestroyImageView;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06005589 if (!strcmp(funcName, "vkDestroyShaderModule"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005590 return (PFN_vkVoidFunction) vkDestroyShaderModule;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06005591 if (!strcmp(funcName, "vkDestroyPipeline"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005592 return (PFN_vkVoidFunction) vkDestroyPipeline;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06005593 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005594 return (PFN_vkVoidFunction) vkDestroyPipelineLayout;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06005595 if (!strcmp(funcName, "vkDestroySampler"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005596 return (PFN_vkVoidFunction) vkDestroySampler;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06005597 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005598 return (PFN_vkVoidFunction) vkDestroyDescriptorSetLayout;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06005599 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005600 return (PFN_vkVoidFunction) vkDestroyDescriptorPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06005601 if (!strcmp(funcName, "vkDestroyFramebuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005602 return (PFN_vkVoidFunction) vkDestroyFramebuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06005603 if (!strcmp(funcName, "vkDestroyRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005604 return (PFN_vkVoidFunction) vkDestroyRenderPass;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005605 if (!strcmp(funcName, "vkCreateBuffer"))
5606 return (PFN_vkVoidFunction) vkCreateBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005607 if (!strcmp(funcName, "vkCreateBufferView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005608 return (PFN_vkVoidFunction) vkCreateBufferView;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005609 if (!strcmp(funcName, "vkCreateImage"))
5610 return (PFN_vkVoidFunction) vkCreateImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005611 if (!strcmp(funcName, "vkCreateImageView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005612 return (PFN_vkVoidFunction) vkCreateImageView;
Jon Ashburnc669cc62015-07-09 15:02:25 -06005613 if (!strcmp(funcName, "CreatePipelineCache"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005614 return (PFN_vkVoidFunction) vkCreatePipelineCache;
Jon Ashburnc669cc62015-07-09 15:02:25 -06005615 if (!strcmp(funcName, "DestroyPipelineCache"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005616 return (PFN_vkVoidFunction) vkDestroyPipelineCache;
Jon Ashburnc669cc62015-07-09 15:02:25 -06005617 if (!strcmp(funcName, "GetPipelineCacheData"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005618 return (PFN_vkVoidFunction) vkGetPipelineCacheData;
Jon Ashburnc669cc62015-07-09 15:02:25 -06005619 if (!strcmp(funcName, "MergePipelineCaches"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005620 return (PFN_vkVoidFunction) vkMergePipelineCaches;
Jon Ashburnc669cc62015-07-09 15:02:25 -06005621 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005622 return (PFN_vkVoidFunction) vkCreateGraphicsPipelines;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07005623 if (!strcmp(funcName, "vkCreateComputePipelines"))
5624 return (PFN_vkVoidFunction) vkCreateComputePipelines;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005625 if (!strcmp(funcName, "vkCreateSampler"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005626 return (PFN_vkVoidFunction) vkCreateSampler;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005627 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005628 return (PFN_vkVoidFunction) vkCreateDescriptorSetLayout;
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05005629 if (!strcmp(funcName, "vkCreatePipelineLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005630 return (PFN_vkVoidFunction) vkCreatePipelineLayout;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005631 if (!strcmp(funcName, "vkCreateDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005632 return (PFN_vkVoidFunction) vkCreateDescriptorPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005633 if (!strcmp(funcName, "vkResetDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005634 return (PFN_vkVoidFunction) vkResetDescriptorPool;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005635 if (!strcmp(funcName, "vkAllocateDescriptorSets"))
5636 return (PFN_vkVoidFunction) vkAllocateDescriptorSets;
Tobin Ehlise735c692015-10-08 13:13:50 -06005637 if (!strcmp(funcName, "vkFreeDescriptorSets"))
5638 return (PFN_vkVoidFunction) vkFreeDescriptorSets;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08005639 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005640 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
Mark Lobodzinski39298632015-11-18 08:38:27 -07005641 if (!strcmp(funcName, "vkCreateCommandPool"))
5642 return (PFN_vkVoidFunction) vkCreateCommandPool;
5643 if (!strcmp(funcName, "vkDestroyCommandPool"))
5644 return (PFN_vkVoidFunction) vkDestroyCommandPool;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005645 if (!strcmp(funcName, "vkResetCommandPool"))
5646 return (PFN_vkVoidFunction) vkResetCommandPool;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005647 if (!strcmp(funcName, "vkAllocateCommandBuffers"))
5648 return (PFN_vkVoidFunction) vkAllocateCommandBuffers;
Mark Lobodzinski39298632015-11-18 08:38:27 -07005649 if (!strcmp(funcName, "vkFreeCommandBuffers"))
5650 return (PFN_vkVoidFunction) vkFreeCommandBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005651 if (!strcmp(funcName, "vkBeginCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005652 return (PFN_vkVoidFunction) vkBeginCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005653 if (!strcmp(funcName, "vkEndCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005654 return (PFN_vkVoidFunction) vkEndCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005655 if (!strcmp(funcName, "vkResetCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005656 return (PFN_vkVoidFunction) vkResetCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005657 if (!strcmp(funcName, "vkCmdBindPipeline"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005658 return (PFN_vkVoidFunction) vkCmdBindPipeline;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06005659 if (!strcmp(funcName, "vkCmdSetViewport"))
5660 return (PFN_vkVoidFunction) vkCmdSetViewport;
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06005661 if (!strcmp(funcName, "vkCmdSetScissor"))
5662 return (PFN_vkVoidFunction) vkCmdSetScissor;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06005663 if (!strcmp(funcName, "vkCmdSetLineWidth"))
5664 return (PFN_vkVoidFunction) vkCmdSetLineWidth;
5665 if (!strcmp(funcName, "vkCmdSetDepthBias"))
5666 return (PFN_vkVoidFunction) vkCmdSetDepthBias;
5667 if (!strcmp(funcName, "vkCmdSetBlendConstants"))
5668 return (PFN_vkVoidFunction) vkCmdSetBlendConstants;
5669 if (!strcmp(funcName, "vkCmdSetDepthBounds"))
5670 return (PFN_vkVoidFunction) vkCmdSetDepthBounds;
5671 if (!strcmp(funcName, "vkCmdSetStencilCompareMask"))
5672 return (PFN_vkVoidFunction) vkCmdSetStencilCompareMask;
5673 if (!strcmp(funcName, "vkCmdSetStencilWriteMask"))
5674 return (PFN_vkVoidFunction) vkCmdSetStencilWriteMask;
5675 if (!strcmp(funcName, "vkCmdSetStencilReference"))
5676 return (PFN_vkVoidFunction) vkCmdSetStencilReference;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005677 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005678 return (PFN_vkVoidFunction) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06005679 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005680 return (PFN_vkVoidFunction) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005681 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005682 return (PFN_vkVoidFunction) vkCmdBindIndexBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005683 if (!strcmp(funcName, "vkCmdDraw"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005684 return (PFN_vkVoidFunction) vkCmdDraw;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005685 if (!strcmp(funcName, "vkCmdDrawIndexed"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005686 return (PFN_vkVoidFunction) vkCmdDrawIndexed;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005687 if (!strcmp(funcName, "vkCmdDrawIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005688 return (PFN_vkVoidFunction) vkCmdDrawIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005689 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005690 return (PFN_vkVoidFunction) vkCmdDrawIndexedIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005691 if (!strcmp(funcName, "vkCmdDispatch"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005692 return (PFN_vkVoidFunction) vkCmdDispatch;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005693 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005694 return (PFN_vkVoidFunction) vkCmdDispatchIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005695 if (!strcmp(funcName, "vkCmdCopyBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005696 return (PFN_vkVoidFunction) vkCmdCopyBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005697 if (!strcmp(funcName, "vkCmdCopyImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005698 return (PFN_vkVoidFunction) vkCmdCopyImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005699 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005700 return (PFN_vkVoidFunction) vkCmdCopyBufferToImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005701 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005702 return (PFN_vkVoidFunction) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005703 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005704 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005705 if (!strcmp(funcName, "vkCmdFillBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005706 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005707 if (!strcmp(funcName, "vkCmdClearColorImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005708 return (PFN_vkVoidFunction) vkCmdClearColorImage;
Chris Forbesd9be82b2015-06-22 17:21:59 +12005709 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005710 return (PFN_vkVoidFunction) vkCmdClearDepthStencilImage;
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06005711 if (!strcmp(funcName, "vkCmdClearAttachments"))
5712 return (PFN_vkVoidFunction) vkCmdClearAttachments;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005713 if (!strcmp(funcName, "vkCmdResolveImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005714 return (PFN_vkVoidFunction) vkCmdResolveImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005715 if (!strcmp(funcName, "vkCmdSetEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005716 return (PFN_vkVoidFunction) vkCmdSetEvent;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005717 if (!strcmp(funcName, "vkCmdResetEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005718 return (PFN_vkVoidFunction) vkCmdResetEvent;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005719 if (!strcmp(funcName, "vkCmdWaitEvents"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005720 return (PFN_vkVoidFunction) vkCmdWaitEvents;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005721 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005722 return (PFN_vkVoidFunction) vkCmdPipelineBarrier;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005723 if (!strcmp(funcName, "vkCmdBeginQuery"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005724 return (PFN_vkVoidFunction) vkCmdBeginQuery;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005725 if (!strcmp(funcName, "vkCmdEndQuery"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005726 return (PFN_vkVoidFunction) vkCmdEndQuery;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005727 if (!strcmp(funcName, "vkCmdResetQueryPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005728 return (PFN_vkVoidFunction) vkCmdResetQueryPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005729 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005730 return (PFN_vkVoidFunction) vkCmdWriteTimestamp;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005731 if (!strcmp(funcName, "vkCreateFramebuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005732 return (PFN_vkVoidFunction) vkCreateFramebuffer;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005733 if (!strcmp(funcName, "vkCreateShaderModule"))
5734 return (PFN_vkVoidFunction) vkCreateShaderModule;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005735 if (!strcmp(funcName, "vkCreateRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005736 return (PFN_vkVoidFunction) vkCreateRenderPass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005737 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005738 return (PFN_vkVoidFunction) vkCmdBeginRenderPass;
Chia-I Wu08accc62015-07-07 11:50:03 +08005739 if (!strcmp(funcName, "vkCmdNextSubpass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005740 return (PFN_vkVoidFunction) vkCmdNextSubpass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005741 if (!strcmp(funcName, "vkCmdEndRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005742 return (PFN_vkVoidFunction) vkCmdEndRenderPass;
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06005743 if (!strcmp(funcName, "vkCmdExecuteCommands"))
5744 return (PFN_vkVoidFunction) vkCmdExecuteCommands;
Michael Lentine7b236262015-10-23 12:41:44 -07005745 if (!strcmp(funcName, "vkMapMemory"))
5746 return (PFN_vkVoidFunction) vkMapMemory;
Jon Ashburneab34492015-06-01 09:37:38 -06005747
Michael Lentineabc5e922015-10-12 11:30:14 -05005748 if (dev_data->device_extensions.wsi_enabled)
5749 {
5750 if (!strcmp(funcName, "vkCreateSwapchainKHR"))
5751 return (PFN_vkVoidFunction) vkCreateSwapchainKHR;
5752 if (!strcmp(funcName, "vkDestroySwapchainKHR"))
5753 return (PFN_vkVoidFunction) vkDestroySwapchainKHR;
5754 if (!strcmp(funcName, "vkGetSwapchainImagesKHR"))
5755 return (PFN_vkVoidFunction) vkGetSwapchainImagesKHR;
5756 if (!strcmp(funcName, "vkQueuePresentKHR"))
5757 return (PFN_vkVoidFunction) vkQueuePresentKHR;
5758 }
5759
Tobin Ehlis0b632332015-10-07 09:38:40 -06005760 VkLayerDispatchTable* pTable = dev_data->device_dispatch_table;
5761 if (dev_data->device_extensions.debug_marker_enabled)
Jon Ashburn8fd08252015-05-28 16:25:02 -06005762 {
Jon Ashburn747f2b62015-06-18 15:02:58 -06005763 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005764 return (PFN_vkVoidFunction) vkCmdDbgMarkerBegin;
Jon Ashburn747f2b62015-06-18 15:02:58 -06005765 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005766 return (PFN_vkVoidFunction) vkCmdDbgMarkerEnd;
Jon Ashburneab34492015-06-01 09:37:38 -06005767 }
5768 {
Jon Ashburn8fd08252015-05-28 16:25:02 -06005769 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005770 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -06005771 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburnf6b33db2015-05-05 14:22:52 -06005772 }
5773}
5774
Chia-I Wu9ab61502015-11-06 06:42:02 +08005775VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Jon Ashburnf6b33db2015-05-05 14:22:52 -06005776{
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005777 PFN_vkVoidFunction fptr;
Jon Ashburnf6b33db2015-05-05 14:22:52 -06005778 if (instance == NULL)
5779 return NULL;
5780
Tobin Ehlis0b632332015-10-07 09:38:40 -06005781 layer_data* my_data;
Jon Ashburn8fd08252015-05-28 16:25:02 -06005782 /* loader uses this to force layer initialization; instance object is wrapped */
5783 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
Tobin Ehlis0b632332015-10-07 09:38:40 -06005784 VkBaseLayerObject* wrapped_inst = (VkBaseLayerObject*) instance;
5785 my_data = get_my_data_ptr(get_dispatch_key(wrapped_inst->baseObject), layer_data_map);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005786 my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
5787 layer_init_instance_dispatch_table(my_data->instance_dispatch_table, wrapped_inst);
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005788 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -06005789 }
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06005790 if (!strcmp(funcName, "vkCreateInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005791 return (PFN_vkVoidFunction) vkCreateInstance;
Jon Ashburn3950e1b2015-05-20 09:00:28 -06005792 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005793 return (PFN_vkVoidFunction) vkDestroyInstance;
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -06005794 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
5795 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
5796 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
5797 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
5798 if (!strcmp(funcName, "vkEnumerateDeviceLayerProperties"))
5799 return (PFN_vkVoidFunction) vkEnumerateDeviceLayerProperties;
5800 if (!strcmp(funcName, "vkEnumerateDeviceExtensionProperties"))
5801 return (PFN_vkVoidFunction) vkEnumerateDeviceExtensionProperties;
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06005802
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005803 my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06005804 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06005805 if (fptr)
5806 return fptr;
5807
Jon Ashburn8fd08252015-05-28 16:25:02 -06005808 {
Tobin Ehlis0b632332015-10-07 09:38:40 -06005809 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
Jon Ashburn8fd08252015-05-28 16:25:02 -06005810 if (pTable->GetInstanceProcAddr == NULL)
Jon Ashburnf6b33db2015-05-05 14:22:52 -06005811 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -06005812 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005813 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005814}