blob: eabec5431a041c59b7f668651576fdfd97608abf [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;
Michael Lentineb887b0a2015-12-29 14:12:11 -060098 unordered_set<VkCommandBuffer> inFlightCmdBuffers;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -060099 // Layer specific data
Mark Lobodzinski39298632015-11-18 08:38:27 -0700100 unordered_map<VkSampler, unique_ptr<SAMPLER_NODE>> sampleMap;
101 unordered_map<VkImageView, unique_ptr<VkImageViewCreateInfo>> imageViewMap;
102 unordered_map<VkImage, unique_ptr<VkImageCreateInfo>> imageMap;
103 unordered_map<VkBufferView, unique_ptr<VkBufferViewCreateInfo>> bufferViewMap;
Michael Lentine700b0aa2015-10-30 17:57:32 -0700104 unordered_map<VkBuffer, BUFFER_NODE> bufferMap;
Mark Lobodzinski39298632015-11-18 08:38:27 -0700105 unordered_map<VkPipeline, PIPELINE_NODE*> pipelineMap;
Tobin Ehlisac0ef842015-12-14 13:46:38 -0700106 unordered_map<VkCommandPool, CMD_POOL_INFO> commandPoolMap;
Mark Lobodzinski39298632015-11-18 08:38:27 -0700107 unordered_map<VkDescriptorPool, DESCRIPTOR_POOL_NODE*> descriptorPoolMap;
108 unordered_map<VkDescriptorSet, SET_NODE*> setMap;
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -0700109 unordered_map<VkDescriptorSetLayout, LAYOUT_NODE*> descriptorSetLayoutMap;
Mark Lobodzinski39298632015-11-18 08:38:27 -0700110 unordered_map<VkPipelineLayout, PIPELINE_LAYOUT_NODE> pipelineLayoutMap;
111 unordered_map<VkDeviceMemory, VkImage> memImageMap;
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -0700112 unordered_map<VkFence, FENCE_NODE> fenceMap;
113 unordered_map<VkQueue, QUEUE_NODE> queueMap;
114 unordered_map<VkDevice, DEVICE_NODE> deviceMap;
Michael Lentineb887b0a2015-12-29 14:12:11 -0600115 unordered_map<VkEvent, EVENT_NODE> eventMap;
116 unordered_map<QueryObject, bool> queryToStateMap;
Michael Lentine15a47882016-01-06 10:05:48 -0600117 unordered_map<VkSemaphore, uint32_t> semaphoreSignaledMap;
Mark Lobodzinski39298632015-11-18 08:38:27 -0700118 unordered_map<void*, GLOBAL_CB_NODE*> commandBufferMap;
119 unordered_map<VkFramebuffer, VkFramebufferCreateInfo*> frameBufferMap;
120 unordered_map<VkImage, IMAGE_NODE*> imageLayoutMap;
121 unordered_map<VkRenderPass, RENDER_PASS_NODE*> renderPassMap;
Michael Lentine15a47882016-01-06 10:05:48 -0600122 unordered_map<VkShaderModule, shader_module*> shaderModuleMap;
Michael Lentineabc5e922015-10-12 11:30:14 -0500123 // Current render pass
Michael Lentine15a47882016-01-06 10:05:48 -0600124 VkRenderPassBeginInfo renderPassBeginInfo;
125 uint32_t currentSubpass;
Cody Northrop55443ef2015-09-28 15:09:32 -0600126
127 layer_data() :
128 report_data(nullptr),
Tobin Ehlis0b632332015-10-07 09:38:40 -0600129 device_dispatch_table(nullptr),
130 instance_dispatch_table(nullptr),
131 device_extensions()
Cody Northrop55443ef2015-09-28 15:09:32 -0600132 {};
133};
Michael Lentine15a47882016-01-06 10:05:48 -0600134
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700135// Code imported from ShaderChecker
136static void
137build_type_def_index(std::vector<unsigned> const &words, std::unordered_map<unsigned, unsigned> &type_def_index);
138
139struct shader_module {
140 /* the spirv image itself */
141 vector<uint32_t> words;
142 /* a mapping of <id> to the first word of its def. this is useful because walking type
143 * trees requires jumping all over the instruction stream.
144 */
145 unordered_map<unsigned, unsigned> type_def_index;
146
147 shader_module(VkShaderModuleCreateInfo const *pCreateInfo) :
148 words((uint32_t *)pCreateInfo->pCode, (uint32_t *)pCreateInfo->pCode + pCreateInfo->codeSize / sizeof(uint32_t)),
149 type_def_index() {
150
151 build_type_def_index(words, type_def_index);
152 }
153};
154
Tobin Ehlisb212dfc2015-10-07 15:40:22 -0600155// TODO : Do we need to guard access to layer_data_map w/ lock?
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -0700156static unordered_map<void*, layer_data*> layer_data_map;
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -0600157
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600158static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
159// TODO : This can be much smarter, using separate locks for separate global data
160static int globalLockInitialized = 0;
161static loader_platform_thread_mutex globalLock;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600162#define MAX_TID 513
163static loader_platform_thread_id g_tidMapping[MAX_TID] = {0};
164static uint32_t g_maxTID = 0;
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600165
166template layer_data *get_my_data_ptr<layer_data>(
167 void *data_key,
168 std::unordered_map<void *, layer_data *> &data_map);
169
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600170// Map actual TID to an index value and return that index
171// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs
172static uint32_t getTIDIndex() {
173 loader_platform_thread_id tid = loader_platform_get_thread_id();
174 for (uint32_t i = 0; i < g_maxTID; i++) {
175 if (tid == g_tidMapping[i])
176 return i;
177 }
178 // Don't yet have mapping, set it and return newly set index
179 uint32_t retVal = (uint32_t) g_maxTID;
180 g_tidMapping[g_maxTID++] = tid;
181 assert(g_maxTID < MAX_TID);
182 return retVal;
183}
Tobin Ehlis559c6382015-11-05 09:52:49 -0700184
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600185// Return a string representation of CMD_TYPE enum
186static string cmdTypeToString(CMD_TYPE cmd)
187{
188 switch (cmd)
189 {
190 case CMD_BINDPIPELINE:
191 return "CMD_BINDPIPELINE";
192 case CMD_BINDPIPELINEDELTA:
193 return "CMD_BINDPIPELINEDELTA";
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600194 case CMD_SETVIEWPORTSTATE:
195 return "CMD_SETVIEWPORTSTATE";
196 case CMD_SETLINEWIDTHSTATE:
197 return "CMD_SETLINEWIDTHSTATE";
198 case CMD_SETDEPTHBIASSTATE:
199 return "CMD_SETDEPTHBIASSTATE";
200 case CMD_SETBLENDSTATE:
201 return "CMD_SETBLENDSTATE";
202 case CMD_SETDEPTHBOUNDSSTATE:
203 return "CMD_SETDEPTHBOUNDSSTATE";
204 case CMD_SETSTENCILREADMASKSTATE:
205 return "CMD_SETSTENCILREADMASKSTATE";
206 case CMD_SETSTENCILWRITEMASKSTATE:
207 return "CMD_SETSTENCILWRITEMASKSTATE";
208 case CMD_SETSTENCILREFERENCESTATE:
209 return "CMD_SETSTENCILREFERENCESTATE";
Tobin Ehlis793ad302015-04-03 12:01:11 -0600210 case CMD_BINDDESCRIPTORSETS:
211 return "CMD_BINDDESCRIPTORSETS";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600212 case CMD_BINDINDEXBUFFER:
213 return "CMD_BINDINDEXBUFFER";
214 case CMD_BINDVERTEXBUFFER:
215 return "CMD_BINDVERTEXBUFFER";
216 case CMD_DRAW:
217 return "CMD_DRAW";
218 case CMD_DRAWINDEXED:
219 return "CMD_DRAWINDEXED";
220 case CMD_DRAWINDIRECT:
221 return "CMD_DRAWINDIRECT";
222 case CMD_DRAWINDEXEDINDIRECT:
223 return "CMD_DRAWINDEXEDINDIRECT";
224 case CMD_DISPATCH:
225 return "CMD_DISPATCH";
226 case CMD_DISPATCHINDIRECT:
227 return "CMD_DISPATCHINDIRECT";
228 case CMD_COPYBUFFER:
229 return "CMD_COPYBUFFER";
230 case CMD_COPYIMAGE:
231 return "CMD_COPYIMAGE";
Tobin Ehlis793ad302015-04-03 12:01:11 -0600232 case CMD_BLITIMAGE:
233 return "CMD_BLITIMAGE";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600234 case CMD_COPYBUFFERTOIMAGE:
235 return "CMD_COPYBUFFERTOIMAGE";
236 case CMD_COPYIMAGETOBUFFER:
237 return "CMD_COPYIMAGETOBUFFER";
238 case CMD_CLONEIMAGEDATA:
239 return "CMD_CLONEIMAGEDATA";
240 case CMD_UPDATEBUFFER:
241 return "CMD_UPDATEBUFFER";
242 case CMD_FILLBUFFER:
243 return "CMD_FILLBUFFER";
244 case CMD_CLEARCOLORIMAGE:
245 return "CMD_CLEARCOLORIMAGE";
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -0600246 case CMD_CLEARATTACHMENTS:
Tobin Ehlis53eddda2015-07-01 16:46:13 -0600247 return "CMD_CLEARCOLORATTACHMENT";
248 case CMD_CLEARDEPTHSTENCILIMAGE:
249 return "CMD_CLEARDEPTHSTENCILIMAGE";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600250 case CMD_RESOLVEIMAGE:
251 return "CMD_RESOLVEIMAGE";
252 case CMD_SETEVENT:
253 return "CMD_SETEVENT";
254 case CMD_RESETEVENT:
255 return "CMD_RESETEVENT";
256 case CMD_WAITEVENTS:
257 return "CMD_WAITEVENTS";
258 case CMD_PIPELINEBARRIER:
259 return "CMD_PIPELINEBARRIER";
260 case CMD_BEGINQUERY:
261 return "CMD_BEGINQUERY";
262 case CMD_ENDQUERY:
263 return "CMD_ENDQUERY";
264 case CMD_RESETQUERYPOOL:
265 return "CMD_RESETQUERYPOOL";
Mark Lobodzinski5495d132015-09-30 16:19:16 -0600266 case CMD_COPYQUERYPOOLRESULTS:
267 return "CMD_COPYQUERYPOOLRESULTS";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600268 case CMD_WRITETIMESTAMP:
269 return "CMD_WRITETIMESTAMP";
270 case CMD_INITATOMICCOUNTERS:
271 return "CMD_INITATOMICCOUNTERS";
272 case CMD_LOADATOMICCOUNTERS:
273 return "CMD_LOADATOMICCOUNTERS";
274 case CMD_SAVEATOMICCOUNTERS:
275 return "CMD_SAVEATOMICCOUNTERS";
276 case CMD_BEGINRENDERPASS:
277 return "CMD_BEGINRENDERPASS";
278 case CMD_ENDRENDERPASS:
279 return "CMD_ENDRENDERPASS";
280 case CMD_DBGMARKERBEGIN:
281 return "CMD_DBGMARKERBEGIN";
282 case CMD_DBGMARKEREND:
283 return "CMD_DBGMARKEREND";
284 default:
285 return "UNKNOWN";
286 }
287}
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700288
289// SPIRV utility functions
290static void
291build_type_def_index(std::vector<unsigned> const &words, std::unordered_map<unsigned, unsigned> &type_def_index)
292{
293 unsigned int const *code = (unsigned int const *)&words[0];
294 size_t size = words.size();
295
296 unsigned word = 5;
297 while (word < size) {
298 unsigned opcode = code[word] & 0x0ffffu;
299 unsigned oplen = (code[word] & 0xffff0000u) >> 16;
300
301 switch (opcode) {
302 case spv::OpTypeVoid:
303 case spv::OpTypeBool:
304 case spv::OpTypeInt:
305 case spv::OpTypeFloat:
306 case spv::OpTypeVector:
307 case spv::OpTypeMatrix:
308 case spv::OpTypeImage:
309 case spv::OpTypeSampler:
310 case spv::OpTypeSampledImage:
311 case spv::OpTypeArray:
312 case spv::OpTypeRuntimeArray:
313 case spv::OpTypeStruct:
314 case spv::OpTypeOpaque:
315 case spv::OpTypePointer:
316 case spv::OpTypeFunction:
317 case spv::OpTypeEvent:
318 case spv::OpTypeDeviceEvent:
319 case spv::OpTypeReserveId:
320 case spv::OpTypeQueue:
321 case spv::OpTypePipe:
322 type_def_index[code[word+1]] = word;
323 break;
324
325 default:
326 /* We only care about type definitions */
327 break;
328 }
329
330 word += oplen;
331 }
332}
333
334bool
335shader_is_spirv(VkShaderModuleCreateInfo const *pCreateInfo)
336{
337 uint32_t *words = (uint32_t *)pCreateInfo->pCode;
338 size_t sizeInWords = pCreateInfo->codeSize / sizeof(uint32_t);
339
340 /* Just validate that the header makes sense. */
341 return sizeInWords >= 5 && words[0] == spv::MagicNumber && words[1] == spv::Version;
342}
343
344static char const *
345storage_class_name(unsigned sc)
346{
347 switch (sc) {
348 case spv::StorageClassInput: return "input";
349 case spv::StorageClassOutput: return "output";
350 case spv::StorageClassUniformConstant: return "const uniform";
351 case spv::StorageClassUniform: return "uniform";
352 case spv::StorageClassWorkgroup: return "workgroup local";
353 case spv::StorageClassCrossWorkgroup: return "workgroup global";
354 case spv::StorageClassPrivate: return "private global";
355 case spv::StorageClassFunction: return "function";
356 case spv::StorageClassGeneric: return "generic";
357 case spv::StorageClassAtomicCounter: return "atomic counter";
358 case spv::StorageClassImage: return "image";
359 default: return "unknown";
360 }
361}
362
363/* returns ptr to null terminator */
364static char *
365describe_type(char *dst, shader_module const *src, unsigned type)
366{
367 auto type_def_it = src->type_def_index.find(type);
368
369 if (type_def_it == src->type_def_index.end()) {
370 return dst + sprintf(dst, "undef");
371 }
372
373 unsigned int const *code = (unsigned int const *)&src->words[type_def_it->second];
374 unsigned opcode = code[0] & 0x0ffffu;
375 switch (opcode) {
376 case spv::OpTypeBool:
377 return dst + sprintf(dst, "bool");
378 case spv::OpTypeInt:
379 return dst + sprintf(dst, "%cint%d", code[3] ? 's' : 'u', code[2]);
380 case spv::OpTypeFloat:
381 return dst + sprintf(dst, "float%d", code[2]);
382 case spv::OpTypeVector:
383 dst += sprintf(dst, "vec%d of ", code[3]);
384 return describe_type(dst, src, code[2]);
385 case spv::OpTypeMatrix:
386 dst += sprintf(dst, "mat%d of ", code[3]);
387 return describe_type(dst, src, code[2]);
388 case spv::OpTypeArray:
389 dst += sprintf(dst, "arr[%d] of ", code[3]);
390 return describe_type(dst, src, code[2]);
391 case spv::OpTypePointer:
392 dst += sprintf(dst, "ptr to %s ", storage_class_name(code[2]));
393 return describe_type(dst, src, code[3]);
394 case spv::OpTypeStruct:
395 {
396 unsigned oplen = code[0] >> 16;
397 dst += sprintf(dst, "struct of (");
398 for (unsigned i = 2; i < oplen; i++) {
399 dst = describe_type(dst, src, code[i]);
400 dst += sprintf(dst, i == oplen-1 ? ")" : ", ");
401 }
402 return dst;
403 }
404 case spv::OpTypeSampler:
405 return dst + sprintf(dst, "sampler");
406 default:
407 return dst + sprintf(dst, "oddtype");
408 }
409}
410
411static bool
412types_match(shader_module const *a, shader_module const *b, unsigned a_type, unsigned b_type, bool b_arrayed)
413{
414 auto a_type_def_it = a->type_def_index.find(a_type);
415 auto b_type_def_it = b->type_def_index.find(b_type);
416
417 if (a_type_def_it == a->type_def_index.end()) {
418 return false;
419 }
420
421 if (b_type_def_it == b->type_def_index.end()) {
422 return false;
423 }
424
425 /* walk two type trees together, and complain about differences */
426 unsigned int const *a_code = (unsigned int const *)&a->words[a_type_def_it->second];
427 unsigned int const *b_code = (unsigned int const *)&b->words[b_type_def_it->second];
428
429 unsigned a_opcode = a_code[0] & 0x0ffffu;
430 unsigned b_opcode = b_code[0] & 0x0ffffu;
431
432 if (b_arrayed && b_opcode == spv::OpTypeArray) {
433 /* we probably just found the extra level of arrayness in b_type: compare the type inside it to a_type */
434 return types_match(a, b, a_type, b_code[2], false);
435 }
436
437 if (a_opcode != b_opcode) {
438 return false;
439 }
440
441 switch (a_opcode) {
442 /* if b_arrayed and we hit a leaf type, then we can't match -- there's nowhere for the extra OpTypeArray to be! */
443 case spv::OpTypeBool:
444 return true && !b_arrayed;
445 case spv::OpTypeInt:
446 /* match on width, signedness */
447 return a_code[2] == b_code[2] && a_code[3] == b_code[3] && !b_arrayed;
448 case spv::OpTypeFloat:
449 /* match on width */
450 return a_code[2] == b_code[2] && !b_arrayed;
451 case spv::OpTypeVector:
452 case spv::OpTypeMatrix:
453 case spv::OpTypeArray:
454 /* match on element type, count. these all have the same layout. we don't get here if
455 * b_arrayed -- that is handled above. */
456 return !b_arrayed && types_match(a, b, a_code[2], b_code[2], b_arrayed) && a_code[3] == b_code[3];
457 case spv::OpTypeStruct:
458 /* match on all element types */
459 {
460 if (b_arrayed) {
461 /* for the purposes of matching different levels of arrayness, structs are leaves. */
462 return false;
463 }
464
465 unsigned a_len = a_code[0] >> 16;
466 unsigned b_len = b_code[0] >> 16;
467
468 if (a_len != b_len) {
469 return false; /* structs cannot match if member counts differ */
470 }
471
472 for (unsigned i = 2; i < a_len; i++) {
473 if (!types_match(a, b, a_code[i], b_code[i], b_arrayed)) {
474 return false;
475 }
476 }
477
478 return true;
479 }
480 case spv::OpTypePointer:
481 /* match on pointee type. storage class is expected to differ */
482 return types_match(a, b, a_code[3], b_code[3], b_arrayed);
483
484 default:
485 /* remaining types are CLisms, or may not appear in the interfaces we
486 * are interested in. Just claim no match.
487 */
488 return false;
489
490 }
491}
492
493static int
494value_or_default(std::unordered_map<unsigned, unsigned> const &map, unsigned id, int def)
495{
496 auto it = map.find(id);
497 if (it == map.end())
498 return def;
499 else
500 return it->second;
501}
502
503
504static unsigned
505get_locations_consumed_by_type(shader_module const *src, unsigned type, bool strip_array_level)
506{
507 auto type_def_it = src->type_def_index.find(type);
508
509 if (type_def_it == src->type_def_index.end()) {
510 return 1; /* This is actually broken SPIR-V... */
511 }
512
513 unsigned int const *code = (unsigned int const *)&src->words[type_def_it->second];
514 unsigned opcode = code[0] & 0x0ffffu;
515
516 switch (opcode) {
517 case spv::OpTypePointer:
518 /* see through the ptr -- this is only ever at the toplevel for graphics shaders;
519 * we're never actually passing pointers around. */
520 return get_locations_consumed_by_type(src, code[3], strip_array_level);
521 case spv::OpTypeArray:
522 if (strip_array_level) {
523 return get_locations_consumed_by_type(src, code[2], false);
524 }
525 else {
526 return code[3] * get_locations_consumed_by_type(src, code[2], false);
527 }
528 case spv::OpTypeMatrix:
529 /* num locations is the dimension * element size */
530 return code[3] * get_locations_consumed_by_type(src, code[2], false);
531 default:
532 /* everything else is just 1. */
533 return 1;
534
535 /* TODO: extend to handle 64bit scalar types, whose vectors may need
536 * multiple locations. */
537 }
538}
539
540
541struct interface_var {
542 uint32_t id;
543 uint32_t type_id;
544 uint32_t offset;
545 /* TODO: collect the name, too? Isn't required to be present. */
546};
547
548static void
549collect_interface_by_location(layer_data *my_data, VkDevice dev,
550 shader_module const *src, spv::StorageClass sinterface,
551 std::map<uint32_t, interface_var> &out,
552 std::map<uint32_t, interface_var> &builtins_out,
553 bool is_array_of_verts)
554{
555 unsigned int const *code = (unsigned int const *)&src->words[0];
556 size_t size = src->words.size();
557
558 std::unordered_map<unsigned, unsigned> var_locations;
559 std::unordered_map<unsigned, unsigned> var_builtins;
560
561 unsigned word = 5;
562 while (word < size) {
563
564 unsigned opcode = code[word] & 0x0ffffu;
565 unsigned oplen = (code[word] & 0xffff0000u) >> 16;
566
567 /* We consider two interface models: SSO rendezvous-by-location, and
568 * builtins. Complain about anything that fits neither model.
569 */
570 if (opcode == spv::OpDecorate) {
571 if (code[word+2] == spv::DecorationLocation) {
572 var_locations[code[word+1]] = code[word+3];
573 }
574
575 if (code[word+2] == spv::DecorationBuiltIn) {
576 var_builtins[code[word+1]] = code[word+3];
577 }
578 }
579
580 /* TODO: handle grouped decorations */
581 /* TODO: handle index=1 dual source outputs from FS -- two vars will
582 * have the same location, and we DONT want to clobber. */
583
584 if (opcode == spv::OpVariable && code[word+3] == sinterface) {
585 unsigned id = code[word+2];
586 unsigned type = code[word+1];
587
588 int location = value_or_default(var_locations, code[word+2], -1);
589 int builtin = value_or_default(var_builtins, code[word+2], -1);
590
Chris Forbesf5020cf2016-01-13 09:29:31 +1300591 /* All variables and interface block members in the Input or Output storage classes
592 * must be decorated with either a builtin or an explicit location.
593 *
594 * TODO: integrate the interface block support here. For now, don't complain --
595 * a valid SPIRV module will only hit this path for the interface block case, as the
596 * individual members of the type are decorated, rather than variable declarations.
597 */
598
599 if (location != -1) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700600 /* A user-defined interface variable, with a location. Where a variable
601 * occupied multiple locations, emit one result for each. */
602 unsigned num_locations = get_locations_consumed_by_type(src, type,
603 is_array_of_verts);
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -0700604 for (unsigned int offset = 0; offset < num_locations; offset++) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700605 interface_var v;
606 v.id = id;
607 v.type_id = type;
608 v.offset = offset;
609 out[location + offset] = v;
610 }
611 }
Chris Forbesf5020cf2016-01-13 09:29:31 +1300612 else if (builtin != -1) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700613 /* A builtin interface variable */
614 /* Note that since builtin interface variables do not consume numbered
615 * locations, there is no larger-than-vec4 consideration as above
616 */
617 interface_var v;
618 v.id = id;
619 v.type_id = type;
620 v.offset = 0;
621 builtins_out[builtin] = v;
622 }
623 }
624
625 word += oplen;
626 }
627}
628
629static void
630collect_interface_by_descriptor_slot(layer_data *my_data, VkDevice dev,
631 shader_module const *src, spv::StorageClass sinterface,
632 std::map<std::pair<unsigned, unsigned>, interface_var> &out)
633{
634 unsigned int const *code = (unsigned int const *)&src->words[0];
635 size_t size = src->words.size();
636
637 std::unordered_map<unsigned, unsigned> var_sets;
638 std::unordered_map<unsigned, unsigned> var_bindings;
639
640 unsigned word = 5;
641 while (word < size) {
642
643 unsigned opcode = code[word] & 0x0ffffu;
644 unsigned oplen = (code[word] & 0xffff0000u) >> 16;
645
646 /* All variables in the Uniform or UniformConstant storage classes are required to be decorated with both
647 * DecorationDescriptorSet and DecorationBinding.
648 */
649 if (opcode == spv::OpDecorate) {
650 if (code[word+2] == spv::DecorationDescriptorSet) {
651 var_sets[code[word+1]] = code[word+3];
652 }
653
654 if (code[word+2] == spv::DecorationBinding) {
655 var_bindings[code[word+1]] = code[word+3];
656 }
657 }
658
659 if (opcode == spv::OpVariable && (code[word+3] == spv::StorageClassUniform ||
660 code[word+3] == spv::StorageClassUniformConstant)) {
661 unsigned set = value_or_default(var_sets, code[word+2], 0);
662 unsigned binding = value_or_default(var_bindings, code[word+2], 0);
663
664 auto existing_it = out.find(std::make_pair(set, binding));
665 if (existing_it != out.end()) {
666 /* conflict within spv image */
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700667 log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__,
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700668 SHADER_CHECKER_INCONSISTENT_SPIRV, "SC",
669 "var %d (type %d) in %s interface in descriptor slot (%u,%u) conflicts with existing definition",
670 code[word+2], code[word+1], storage_class_name(sinterface),
671 existing_it->first.first, existing_it->first.second);
672 }
673
674 interface_var v;
675 v.id = code[word+2];
676 v.type_id = code[word+1];
677 out[std::make_pair(set, binding)] = v;
678 }
679
680 word += oplen;
681 }
682}
683
684static bool
685validate_interface_between_stages(layer_data *my_data, VkDevice dev,
686 shader_module const *producer, char const *producer_name,
687 shader_module const *consumer, char const *consumer_name,
688 bool consumer_arrayed_input)
689{
690 std::map<uint32_t, interface_var> outputs;
691 std::map<uint32_t, interface_var> inputs;
692
693 std::map<uint32_t, interface_var> builtin_outputs;
694 std::map<uint32_t, interface_var> builtin_inputs;
695
696 bool pass = true;
697
698 collect_interface_by_location(my_data, dev, producer, spv::StorageClassOutput, outputs, builtin_outputs, false);
699 collect_interface_by_location(my_data, dev, consumer, spv::StorageClassInput, inputs, builtin_inputs,
700 consumer_arrayed_input);
701
702 auto a_it = outputs.begin();
703 auto b_it = inputs.begin();
704
705 /* maps sorted by key (location); walk them together to find mismatches */
706 while ((outputs.size() > 0 && a_it != outputs.end()) || ( inputs.size() && b_it != inputs.end())) {
707 bool a_at_end = outputs.size() == 0 || a_it == outputs.end();
708 bool b_at_end = inputs.size() == 0 || b_it == inputs.end();
709 auto a_first = a_at_end ? 0 : a_it->first;
710 auto b_first = b_at_end ? 0 : b_it->first;
711
712 if (b_at_end || ((!a_at_end) && (a_first < b_first))) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700713 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__, SHADER_CHECKER_OUTPUT_NOT_CONSUMED, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700714 "%s writes to output location %d which is not consumed by %s", producer_name, a_first, consumer_name)) {
715 pass = false;
716 }
717 a_it++;
718 }
719 else if (a_at_end || a_first > b_first) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700720 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__, SHADER_CHECKER_INPUT_NOT_PRODUCED, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700721 "%s consumes input location %d which is not written by %s", consumer_name, b_first, producer_name)) {
722 pass = false;
723 }
724 b_it++;
725 }
726 else {
727 if (types_match(producer, consumer, a_it->second.type_id, b_it->second.type_id, consumer_arrayed_input)) {
728 /* OK! */
729 }
730 else {
731 char producer_type[1024];
732 char consumer_type[1024];
733 describe_type(producer_type, producer, a_it->second.type_id);
734 describe_type(consumer_type, consumer, b_it->second.type_id);
735
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700736 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__, SHADER_CHECKER_INTERFACE_TYPE_MISMATCH, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700737 "Type mismatch on location %d: '%s' vs '%s'", a_it->first, producer_type, consumer_type)) {
738 pass = false;
739 }
740 }
741 a_it++;
742 b_it++;
743 }
744 }
745
746 return pass;
747}
748
749enum FORMAT_TYPE {
750 FORMAT_TYPE_UNDEFINED,
751 FORMAT_TYPE_FLOAT, /* UNORM, SNORM, FLOAT, USCALED, SSCALED, SRGB -- anything we consider float in the shader */
752 FORMAT_TYPE_SINT,
753 FORMAT_TYPE_UINT,
754};
755
756static unsigned
757get_format_type(VkFormat fmt) {
758 switch (fmt) {
759 case VK_FORMAT_UNDEFINED:
760 return FORMAT_TYPE_UNDEFINED;
761 case VK_FORMAT_R8_SINT:
762 case VK_FORMAT_R8G8_SINT:
763 case VK_FORMAT_R8G8B8_SINT:
764 case VK_FORMAT_R8G8B8A8_SINT:
765 case VK_FORMAT_R16_SINT:
766 case VK_FORMAT_R16G16_SINT:
767 case VK_FORMAT_R16G16B16_SINT:
768 case VK_FORMAT_R16G16B16A16_SINT:
769 case VK_FORMAT_R32_SINT:
770 case VK_FORMAT_R32G32_SINT:
771 case VK_FORMAT_R32G32B32_SINT:
772 case VK_FORMAT_R32G32B32A32_SINT:
773 case VK_FORMAT_B8G8R8_SINT:
774 case VK_FORMAT_B8G8R8A8_SINT:
775 case VK_FORMAT_A2B10G10R10_SINT_PACK32:
776 case VK_FORMAT_A2R10G10B10_SINT_PACK32:
777 return FORMAT_TYPE_SINT;
778 case VK_FORMAT_R8_UINT:
779 case VK_FORMAT_R8G8_UINT:
780 case VK_FORMAT_R8G8B8_UINT:
781 case VK_FORMAT_R8G8B8A8_UINT:
782 case VK_FORMAT_R16_UINT:
783 case VK_FORMAT_R16G16_UINT:
784 case VK_FORMAT_R16G16B16_UINT:
785 case VK_FORMAT_R16G16B16A16_UINT:
786 case VK_FORMAT_R32_UINT:
787 case VK_FORMAT_R32G32_UINT:
788 case VK_FORMAT_R32G32B32_UINT:
789 case VK_FORMAT_R32G32B32A32_UINT:
790 case VK_FORMAT_B8G8R8_UINT:
791 case VK_FORMAT_B8G8R8A8_UINT:
792 case VK_FORMAT_A2B10G10R10_UINT_PACK32:
793 case VK_FORMAT_A2R10G10B10_UINT_PACK32:
794 return FORMAT_TYPE_UINT;
795 default:
796 return FORMAT_TYPE_FLOAT;
797 }
798}
799
800/* characterizes a SPIR-V type appearing in an interface to a FF stage,
801 * for comparison to a VkFormat's characterization above. */
802static unsigned
803get_fundamental_type(shader_module const *src, unsigned type)
804{
805 auto type_def_it = src->type_def_index.find(type);
806
807 if (type_def_it == src->type_def_index.end()) {
808 return FORMAT_TYPE_UNDEFINED;
809 }
810
811 unsigned int const *code = (unsigned int const *)&src->words[type_def_it->second];
812 unsigned opcode = code[0] & 0x0ffffu;
813 switch (opcode) {
814 case spv::OpTypeInt:
815 return code[3] ? FORMAT_TYPE_SINT : FORMAT_TYPE_UINT;
816 case spv::OpTypeFloat:
817 return FORMAT_TYPE_FLOAT;
818 case spv::OpTypeVector:
819 return get_fundamental_type(src, code[2]);
820 case spv::OpTypeMatrix:
821 return get_fundamental_type(src, code[2]);
822 case spv::OpTypeArray:
823 return get_fundamental_type(src, code[2]);
824 case spv::OpTypePointer:
825 return get_fundamental_type(src, code[3]);
826 default:
827 return FORMAT_TYPE_UNDEFINED;
828 }
829}
830
831static bool
832validate_vi_consistency(layer_data *my_data, VkDevice dev, VkPipelineVertexInputStateCreateInfo const *vi)
833{
834 /* walk the binding descriptions, which describe the step rate and stride of each vertex buffer.
835 * each binding should be specified only once.
836 */
837 std::unordered_map<uint32_t, VkVertexInputBindingDescription const *> bindings;
838 bool pass = true;
839
840 for (unsigned i = 0; i < vi->vertexBindingDescriptionCount; i++) {
841 auto desc = &vi->pVertexBindingDescriptions[i];
842 auto & binding = bindings[desc->binding];
843 if (binding) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700844 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__, SHADER_CHECKER_INCONSISTENT_VI, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700845 "Duplicate vertex input binding descriptions for binding %d", desc->binding)) {
846 pass = false;
847 }
848 }
849 else {
850 binding = desc;
851 }
852 }
853
854 return pass;
855}
856
857static bool
858validate_vi_against_vs_inputs(layer_data *my_data, VkDevice dev, VkPipelineVertexInputStateCreateInfo const *vi, shader_module const *vs)
859{
860 std::map<uint32_t, interface_var> inputs;
861 /* we collect builtin inputs, but they will never appear in the VI state --
862 * the vs builtin inputs are generated in the pipeline, not sourced from buffers (VertexID, etc)
863 */
864 std::map<uint32_t, interface_var> builtin_inputs;
865 bool pass = true;
866
867 collect_interface_by_location(my_data, dev, vs, spv::StorageClassInput, inputs, builtin_inputs, false);
868
869 /* Build index by location */
870 std::map<uint32_t, VkVertexInputAttributeDescription const *> attribs;
871 if (vi) {
872 for (unsigned i = 0; i < vi->vertexAttributeDescriptionCount; i++)
873 attribs[vi->pVertexAttributeDescriptions[i].location] = &vi->pVertexAttributeDescriptions[i];
874 }
875
876 auto it_a = attribs.begin();
877 auto it_b = inputs.begin();
878
879 while ((attribs.size() > 0 && it_a != attribs.end()) || (inputs.size() > 0 && it_b != inputs.end())) {
880 bool a_at_end = attribs.size() == 0 || it_a == attribs.end();
881 bool b_at_end = inputs.size() == 0 || it_b == inputs.end();
882 auto a_first = a_at_end ? 0 : it_a->first;
883 auto b_first = b_at_end ? 0 : it_b->first;
884 if (b_at_end || a_first < b_first) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700885 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__, SHADER_CHECKER_OUTPUT_NOT_CONSUMED, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700886 "Vertex attribute at location %d not consumed by VS", a_first)) {
887 pass = false;
888 }
889 it_a++;
890 }
891 else if (a_at_end || b_first < a_first) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700892 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__, SHADER_CHECKER_INPUT_NOT_PRODUCED, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700893 "VS consumes input at location %d but not provided", b_first)) {
894 pass = false;
895 }
896 it_b++;
897 }
898 else {
899 unsigned attrib_type = get_format_type(it_a->second->format);
900 unsigned input_type = get_fundamental_type(vs, it_b->second.type_id);
901
902 /* type checking */
903 if (attrib_type != FORMAT_TYPE_UNDEFINED && input_type != FORMAT_TYPE_UNDEFINED && attrib_type != input_type) {
904 char vs_type[1024];
905 describe_type(vs_type, vs, it_b->second.type_id);
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700906 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__, SHADER_CHECKER_INTERFACE_TYPE_MISMATCH, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700907 "Attribute type of `%s` at location %d does not match VS input type of `%s`",
908 string_VkFormat(it_a->second->format), a_first, vs_type)) {
909 pass = false;
910 }
911 }
912
913 /* OK! */
914 it_a++;
915 it_b++;
916 }
917 }
918
919 return pass;
920}
921
922static bool
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -0700923validate_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 -0700924{
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -0700925 const std::vector<VkFormat> &color_formats = rp->subpassColorFormats[subpass];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700926 std::map<uint32_t, interface_var> outputs;
927 std::map<uint32_t, interface_var> builtin_outputs;
928 bool pass = true;
929
930 /* TODO: dual source blend index (spv::DecIndex, zero if not provided) */
931
932 collect_interface_by_location(my_data, dev, fs, spv::StorageClassOutput, outputs, builtin_outputs, false);
933
934 auto it = outputs.begin();
935 uint32_t attachment = 0;
936
937 /* Walk attachment list and outputs together -- this is a little overpowered since attachments
938 * are currently dense, but the parallel with matching between shader stages is nice.
939 */
940
941 /* TODO: Figure out compile error with cb->attachmentCount */
942 while ((outputs.size() > 0 && it != outputs.end()) || attachment < color_formats.size()) {
943 if (attachment == color_formats.size() || ( it != outputs.end() && it->first < attachment)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700944 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__, SHADER_CHECKER_OUTPUT_NOT_CONSUMED, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700945 "FS writes to output location %d with no matching attachment", it->first)) {
946 pass = false;
947 }
948 it++;
949 }
950 else if (it == outputs.end() || it->first > attachment) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700951 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__, SHADER_CHECKER_INPUT_NOT_PRODUCED, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700952 "Attachment %d not written by FS", attachment)) {
953 pass = false;
954 }
955 attachment++;
956 }
957 else {
958 unsigned output_type = get_fundamental_type(fs, it->second.type_id);
959 unsigned att_type = get_format_type(color_formats[attachment]);
960
961 /* type checking */
962 if (att_type != FORMAT_TYPE_UNDEFINED && output_type != FORMAT_TYPE_UNDEFINED && att_type != output_type) {
963 char fs_type[1024];
964 describe_type(fs_type, fs, it->second.type_id);
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700965 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__, SHADER_CHECKER_INTERFACE_TYPE_MISMATCH, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700966 "Attachment %d of type `%s` does not match FS output type of `%s`",
967 attachment, string_VkFormat(color_formats[attachment]), fs_type)) {
968 pass = false;
969 }
970 }
971
972 /* OK! */
973 it++;
974 attachment++;
975 }
976 }
977
978 return pass;
979}
980
981
982struct shader_stage_attributes {
983 char const * const name;
984 bool arrayed_input;
985};
986
987
988static shader_stage_attributes
989shader_stage_attribs[] = {
990 { "vertex shader", false },
991 { "tessellation control shader", true },
992 { "tessellation evaluation shader", false },
993 { "geometry shader", true },
994 { "fragment shader", false },
995};
996
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -0700997// For given pipelineLayout verify that the setLayout at slot.first
998// has the requested binding at slot.second
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700999static bool
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001000has_descriptor_binding(layer_data* my_data,
1001 vector<VkDescriptorSetLayout>* pipelineLayout,
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001002 std::pair<unsigned, unsigned> slot)
1003{
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001004 if (!pipelineLayout)
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001005 return false;
1006
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001007 if (slot.first >= pipelineLayout->size())
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001008 return false;
1009
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001010 auto set = my_data->descriptorSetLayoutMap[(*pipelineLayout)[slot.first]]->bindings;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001011
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001012 return (set.find(slot.second) != set.end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001013}
1014
1015static uint32_t get_shader_stage_id(VkShaderStageFlagBits stage)
1016{
1017 uint32_t bit_pos = u_ffs(stage);
1018 return bit_pos-1;
1019}
1020
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001021// Block of code at start here for managing/tracking Pipeline state that this layer cares about
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001022
1023static uint64_t g_drawCount[NUM_DRAW_TYPES] = {0, 0, 0, 0};
1024
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001025// 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 -06001026// Then need to synchronize the accesses based on cmd buffer so that if I'm reading state on one cmd buffer, updates
1027// to that same cmd buffer by separate thread are not changing state from underneath us
1028// Track the last cmd buffer touched by this thread
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001029
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001030// prototype
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001031static GLOBAL_CB_NODE* getCBNode(layer_data*, const VkCommandBuffer);
Tobin Ehlis559c6382015-11-05 09:52:49 -07001032
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06001033static VkBool32 hasDrawCmd(GLOBAL_CB_NODE* pCB)
Tobin Ehlis53eddda2015-07-01 16:46:13 -06001034{
1035 for (uint32_t i=0; i<NUM_DRAW_TYPES; i++) {
1036 if (pCB->drawCount[i])
1037 return VK_TRUE;
1038 }
1039 return VK_FALSE;
1040}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001041
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001042// Check object status for selected flag state
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001043static 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 -06001044{
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001045 // If non-zero enable mask is present, check it against status but if enable_mask
1046 // is 0 then no enable required so we should always just check status
1047 if ((!enable_mask) || (enable_mask & pNode->status)) {
1048 if ((pNode->status & status_mask) != status_flag) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001049 // TODO : How to pass dispatchable objects as srcObject? Here src obj should be cmd buffer
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001050 return log_msg(my_data->report_data, msg_flags, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, error_code, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001051 "CB object %#" PRIxLEAST64 ": %s", reinterpret_cast<uint64_t>(pNode->commandBuffer), fail_msg);
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001052 }
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001053 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001054 return VK_FALSE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001055}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001056
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001057// Retrieve pipeline node ptr for given pipeline object
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001058static PIPELINE_NODE* getPipeline(layer_data* my_data, const VkPipeline pipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001059{
1060 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08001061 if (my_data->pipelineMap.find(pipeline) == my_data->pipelineMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001062 loader_platform_thread_unlock_mutex(&globalLock);
1063 return NULL;
1064 }
1065 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08001066 return my_data->pipelineMap[pipeline];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001067}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001068
Tobin Ehlisd332f282015-10-02 11:00:56 -06001069// Return VK_TRUE if for a given PSO, the given state enum is dynamic, else return VK_FALSE
1070static VkBool32 isDynamic(const PIPELINE_NODE* pPipeline, const VkDynamicState state)
1071{
1072 if (pPipeline && pPipeline->graphicsPipelineCI.pDynamicState) {
1073 for (uint32_t i=0; i<pPipeline->graphicsPipelineCI.pDynamicState->dynamicStateCount; i++) {
1074 if (state == pPipeline->graphicsPipelineCI.pDynamicState->pDynamicStates[i])
1075 return VK_TRUE;
1076 }
1077 }
1078 return VK_FALSE;
1079}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001080
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001081// Validate state stored as flags at time of draw call
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001082static VkBool32 validate_draw_state_flags(layer_data* my_data, GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06001083 VkBool32 result;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001084 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");
1085 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");
1086 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");
1087 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");
1088 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");
1089 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");
1090 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");
1091 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");
1092 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 -06001093 if (indexedDraw)
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001094 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 -06001095 return result;
1096}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001097
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001098// Verify attachment reference compatibility according to spec
1099// If one array is larger, treat missing elements of shorter array as VK_ATTACHMENT_UNUSED & other array much match this
1100// If both AttachmentReference arrays have requested index, check their corresponding AttachementDescriptions
1101// to make sure that format and samples counts match.
1102// If not, they are not compatible.
1103static bool attachment_references_compatible(const uint32_t index, const VkAttachmentReference* pPrimary, const uint32_t primaryCount, const VkAttachmentDescription* pPrimaryAttachments,
1104 const VkAttachmentReference* pSecondary, const uint32_t secondaryCount, const VkAttachmentDescription* pSecondaryAttachments)
1105{
1106 if (index >= primaryCount) { // Check secondary as if primary is VK_ATTACHMENT_UNUSED
1107 if (VK_ATTACHMENT_UNUSED != pSecondary[index].attachment)
1108 return false;
1109 } else if (index >= secondaryCount) { // Check primary as if secondary is VK_ATTACHMENT_UNUSED
1110 if (VK_ATTACHMENT_UNUSED != pPrimary[index].attachment)
1111 return false;
1112 } else { // format and sample count must match
1113 if ((pPrimaryAttachments[pPrimary[index].attachment].format == pSecondaryAttachments[pSecondary[index].attachment].format) &&
1114 (pPrimaryAttachments[pPrimary[index].attachment].samples == pSecondaryAttachments[pSecondary[index].attachment].samples))
1115 return true;
1116 }
1117 // Format and sample counts didn't match
1118 return false;
1119}
1120
1121// For give primary and secondary RenderPass objects, verify that they're compatible
1122static bool verify_renderpass_compatibility(layer_data* my_data, const VkRenderPass primaryRP, const VkRenderPass secondaryRP, string& errorMsg)
1123{
1124 stringstream errorStr;
1125 if (my_data->renderPassMap.find(primaryRP) == my_data->renderPassMap.end()) {
1126 errorStr << "invalid VkRenderPass (" << primaryRP << ")";
1127 errorMsg = errorStr.str();
1128 return false;
1129 } else if (my_data->renderPassMap.find(secondaryRP) == my_data->renderPassMap.end()) {
1130 errorStr << "invalid VkRenderPass (" << secondaryRP << ")";
1131 errorMsg = errorStr.str();
1132 return false;
1133 }
1134 // Trivial pass case is exact same RP
1135 if (primaryRP == secondaryRP)
1136 return true;
1137 const VkRenderPassCreateInfo* primaryRPCI = my_data->renderPassMap[primaryRP]->pCreateInfo;
1138 const VkRenderPassCreateInfo* secondaryRPCI = my_data->renderPassMap[secondaryRP]->pCreateInfo;
1139 if (primaryRPCI->subpassCount != secondaryRPCI->subpassCount) {
1140 errorStr << "RenderPass for primary cmdBuffer has " << primaryRPCI->subpassCount << " subpasses but renderPass for secondary cmdBuffer has " << secondaryRPCI->subpassCount << " subpasses.";
1141 errorMsg = errorStr.str();
1142 return false;
1143 }
1144 uint32_t spIndex = 0;
1145 for (spIndex = 0; spIndex < primaryRPCI->subpassCount; ++spIndex) {
1146 // For each subpass, verify that corresponding color, input, resolve & depth/stencil attachment references are compatible
1147 uint32_t primaryColorCount = primaryRPCI->pSubpasses[spIndex].colorAttachmentCount;
1148 uint32_t secondaryColorCount = secondaryRPCI->pSubpasses[spIndex].colorAttachmentCount;
1149 uint32_t colorMax = std::max(primaryColorCount, secondaryColorCount);
1150 for (uint32_t cIdx = 0; cIdx < colorMax; ++cIdx) {
1151 if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pColorAttachments, primaryColorCount, primaryRPCI->pAttachments,
1152 secondaryRPCI->pSubpasses[spIndex].pColorAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1153 errorStr << "color 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].pResolveAttachments, primaryColorCount, primaryRPCI->pAttachments,
1157 secondaryRPCI->pSubpasses[spIndex].pResolveAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1158 errorStr << "resolve attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
1159 errorMsg = errorStr.str();
1160 return false;
1161 } else if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pDepthStencilAttachment, primaryColorCount, primaryRPCI->pAttachments,
1162 secondaryRPCI->pSubpasses[spIndex].pDepthStencilAttachment, secondaryColorCount, secondaryRPCI->pAttachments)) {
1163 errorStr << "depth/stencil attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
1164 errorMsg = errorStr.str();
1165 return false;
1166 }
1167 }
1168 uint32_t primaryInputCount = primaryRPCI->pSubpasses[spIndex].inputAttachmentCount;
1169 uint32_t secondaryInputCount = secondaryRPCI->pSubpasses[spIndex].inputAttachmentCount;
1170 uint32_t inputMax = std::max(primaryInputCount, secondaryInputCount);
1171 for (uint32_t i = 0; i < inputMax; ++i) {
1172 if (!attachment_references_compatible(i, primaryRPCI->pSubpasses[spIndex].pInputAttachments, primaryColorCount, primaryRPCI->pAttachments,
1173 secondaryRPCI->pSubpasses[spIndex].pInputAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1174 errorStr << "input attachments at index " << i << " of subpass index " << spIndex << " are not compatible.";
1175 errorMsg = errorStr.str();
1176 return false;
1177 }
1178 }
1179 }
1180 return true;
1181}
1182
Tobin Ehlis559c6382015-11-05 09:52:49 -07001183// For give SET_NODE, verify that its Set is compatible w/ the setLayout corresponding to pipelineLayout[layoutIndex]
1184static bool verify_set_layout_compatibility(layer_data* my_data, const SET_NODE* pSet, const VkPipelineLayout layout, const uint32_t layoutIndex, string& errorMsg)
1185{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001186 stringstream errorStr;
Tobin Ehlis559c6382015-11-05 09:52:49 -07001187 if (my_data->pipelineLayoutMap.find(layout) == my_data->pipelineLayoutMap.end()) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001188 errorStr << "invalid VkPipelineLayout (" << layout << ")";
1189 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001190 return false;
1191 }
1192 PIPELINE_LAYOUT_NODE pl = my_data->pipelineLayoutMap[layout];
1193 if (layoutIndex >= pl.descriptorSetLayouts.size()) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001194 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;
1195 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001196 return false;
1197 }
1198 // Get the specific setLayout from PipelineLayout that overlaps this set
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001199 LAYOUT_NODE* pLayoutNode = my_data->descriptorSetLayoutMap[pl.descriptorSetLayouts[layoutIndex]];
Tobin Ehlis559c6382015-11-05 09:52:49 -07001200 if (pLayoutNode->layout == pSet->pLayout->layout) { // trivial pass case
1201 return true;
1202 }
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07001203 size_t descriptorCount = pLayoutNode->descriptorTypes.size();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001204 if (descriptorCount != pSet->pLayout->descriptorTypes.size()) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001205 errorStr << "setLayout " << layoutIndex << " from pipelineLayout " << layout << " has " << descriptorCount << " descriptors, but corresponding set being bound has " << pSet->pLayout->descriptorTypes.size() << " descriptors.";
1206 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001207 return false; // trivial fail case
1208 }
1209 // Now need to check set against corresponding pipelineLayout to verify compatibility
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07001210 for (size_t i=0; i<descriptorCount; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07001211 // Need to verify that layouts are identically defined
1212 // TODO : Is below sufficient? Making sure that types & stageFlags match per descriptor
1213 // do we also need to check immutable samplers?
1214 if (pLayoutNode->descriptorTypes[i] != pSet->pLayout->descriptorTypes[i]) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001215 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]) << "'";
1216 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001217 return false;
1218 }
1219 if (pLayoutNode->stageFlags[i] != pSet->pLayout->stageFlags[i]) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001220 errorStr << "stageFlags " << i << " for descriptorSet being bound is " << pSet->pLayout->stageFlags[i] << "' but corresponding descriptor from pipelineLayout has stageFlags " << pLayoutNode->stageFlags[i];
1221 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001222 return false;
1223 }
1224 }
1225 return true;
1226}
1227
Tobin Ehlis88452832015-12-03 09:40:56 -07001228// Validate that the shaders used by the given pipeline
1229// As a side effect this function also records the sets that are actually used by the pipeline
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07001230static VkBool32
Tobin Ehlis88452832015-12-03 09:40:56 -07001231validate_pipeline_shaders(layer_data *my_data, VkDevice dev, PIPELINE_NODE* pPipeline)
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001232{
Tobin Ehlis88452832015-12-03 09:40:56 -07001233 VkGraphicsPipelineCreateInfo const *pCreateInfo = &pPipeline->graphicsPipelineCI;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001234 /* We seem to allow pipeline stages to be specified out of order, so collect and identify them
1235 * before trying to do anything more: */
1236 int vertex_stage = get_shader_stage_id(VK_SHADER_STAGE_VERTEX_BIT);
1237 int geometry_stage = get_shader_stage_id(VK_SHADER_STAGE_GEOMETRY_BIT);
1238 int fragment_stage = get_shader_stage_id(VK_SHADER_STAGE_FRAGMENT_BIT);
1239
1240 shader_module **shaders = new shader_module*[fragment_stage + 1]; /* exclude CS */
1241 memset(shaders, 0, sizeof(shader_module *) * (fragment_stage +1));
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001242 RENDER_PASS_NODE const *rp = 0;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001243 VkPipelineVertexInputStateCreateInfo const *vi = 0;
Mark Youngb20a6a82016-01-07 15:41:43 -07001244 VkBool32 pass = VK_TRUE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001245
1246 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
1247 VkPipelineShaderStageCreateInfo const *pStage = &pCreateInfo->pStages[i];
1248 if (pStage->sType == VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO) {
1249
1250 if ((pStage->stage & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_GEOMETRY_BIT | VK_SHADER_STAGE_FRAGMENT_BIT
1251 | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT)) == 0) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001252 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__, SHADER_CHECKER_UNKNOWN_STAGE, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001253 "Unknown shader stage %d", pStage->stage)) {
Mark Youngb20a6a82016-01-07 15:41:43 -07001254 pass = VK_FALSE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001255 }
1256 }
1257 else {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001258 shader_module *module = my_data->shaderModuleMap[pStage->module];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001259 shaders[get_shader_stage_id(pStage->stage)] = module;
1260
1261 /* validate descriptor set layout against what the spirv module actually uses */
1262 std::map<std::pair<unsigned, unsigned>, interface_var> descriptor_uses;
1263 collect_interface_by_descriptor_slot(my_data, dev, module, spv::StorageClassUniform,
1264 descriptor_uses);
1265
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001266 auto layouts = pCreateInfo->layout != VK_NULL_HANDLE ?
1267 &(my_data->pipelineLayoutMap[pCreateInfo->layout].descriptorSetLayouts) : nullptr;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001268
1269 for (auto it = descriptor_uses.begin(); it != descriptor_uses.end(); it++) {
Tobin Ehlis88452832015-12-03 09:40:56 -07001270 // As a side-effect of this function, capture which sets are used by the pipeline
1271 pPipeline->active_sets.insert(it->first.first);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001272
1273 /* find the matching binding */
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001274 auto found = has_descriptor_binding(my_data, layouts, it->first);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001275
1276 if (!found) {
1277 char type_name[1024];
1278 describe_type(type_name, module, it->second.type_id);
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001279 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__,
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001280 SHADER_CHECKER_MISSING_DESCRIPTOR, "SC",
1281 "Shader uses descriptor slot %u.%u (used as type `%s`) but not declared in pipeline layout",
1282 it->first.first, it->first.second, type_name)) {
Mark Youngb20a6a82016-01-07 15:41:43 -07001283 pass = VK_FALSE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001284 }
1285 }
1286 }
1287 }
1288 }
1289 }
1290
1291 if (pCreateInfo->renderPass != VK_NULL_HANDLE)
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001292 rp = my_data->renderPassMap[pCreateInfo->renderPass];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001293
1294 vi = pCreateInfo->pVertexInputState;
1295
1296 if (vi) {
1297 pass = validate_vi_consistency(my_data, dev, vi) && pass;
1298 }
1299
1300 if (shaders[vertex_stage]) {
1301 pass = validate_vi_against_vs_inputs(my_data, dev, vi, shaders[vertex_stage]) && pass;
1302 }
1303
1304 /* TODO: enforce rules about present combinations of shaders */
1305 int producer = get_shader_stage_id(VK_SHADER_STAGE_VERTEX_BIT);
1306 int consumer = get_shader_stage_id(VK_SHADER_STAGE_GEOMETRY_BIT);
1307
1308 while (!shaders[producer] && producer != fragment_stage) {
1309 producer++;
1310 consumer++;
1311 }
1312
1313 for (; producer != fragment_stage && consumer <= fragment_stage; consumer++) {
1314 assert(shaders[producer]);
1315 if (shaders[consumer]) {
1316 pass = validate_interface_between_stages(my_data, dev,
1317 shaders[producer], shader_stage_attribs[producer].name,
1318 shaders[consumer], shader_stage_attribs[consumer].name,
1319 shader_stage_attribs[consumer].arrayed_input) && pass;
1320
1321 producer = consumer;
1322 }
1323 }
1324
1325 if (shaders[fragment_stage] && rp) {
1326 pass = validate_fs_outputs_against_render_pass(my_data, dev, shaders[fragment_stage], rp, pCreateInfo->subpass) && pass;
1327 }
1328
Chris Forbes47f4f6f2015-12-17 17:10:19 +13001329 delete [] shaders;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001330
1331 return pass;
1332}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001333
Tobin Ehlisf6585052015-12-17 11:48:42 -07001334// Return Set node ptr for specified set or else NULL
1335static SET_NODE* getSetNode(layer_data* my_data, const VkDescriptorSet set)
1336{
1337 loader_platform_thread_lock_mutex(&globalLock);
1338 if (my_data->setMap.find(set) == my_data->setMap.end()) {
1339 loader_platform_thread_unlock_mutex(&globalLock);
1340 return NULL;
1341 }
1342 loader_platform_thread_unlock_mutex(&globalLock);
1343 return my_data->setMap[set];
1344}
1345
1346// For the given set, verify that for each dynamic descriptor in that set that its
1347// dynamic offset combined with the offet and range from its descriptor update
1348// do not overflow the size of its buffer being updated
1349static VkBool32 validate_dynamic_offsets(layer_data* my_data, const SET_NODE* pSet)
1350{
1351 VkBool32 result = VK_FALSE;
1352 if (pSet->dynamicOffsets.empty())
1353 return result;
1354
1355 VkWriteDescriptorSet* pWDS = NULL;
1356 uint32_t dynOffsetIndex = 0;
1357 VkDeviceSize bufferSize = 0;
1358 for (uint32_t i=0; i < pSet->descriptorCount; ++i) {
1359 switch (pSet->ppDescriptors[i]->sType) {
1360 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1361 pWDS = (VkWriteDescriptorSet*)pSet->ppDescriptors[i];
1362 if ((pWDS->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
1363 (pWDS->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
1364 for (uint32_t j=0; j<pWDS->descriptorCount; ++j) {
Michael Lentine700b0aa2015-10-30 17:57:32 -07001365 bufferSize = my_data->bufferMap[pWDS->pBufferInfo[j].buffer].create_info->size;
Tobin Ehlisf6585052015-12-17 11:48:42 -07001366 if ((pSet->dynamicOffsets[dynOffsetIndex] + pWDS->pBufferInfo[j].offset + pWDS->pBufferInfo[j].range) > bufferSize) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001367 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, __LINE__, DRAWSTATE_DYNAMIC_OFFSET_OVERFLOW, "DS",
Tobin Ehlisf6585052015-12-17 11:48:42 -07001368 "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 ".",
1369 (uint64_t)pSet->set, i, pSet->dynamicOffsets[dynOffsetIndex], pWDS->pBufferInfo[j].offset, pWDS->pBufferInfo[j].range, (uint64_t)pWDS->pBufferInfo[j].buffer, bufferSize);
1370 }
1371 dynOffsetIndex++;
1372 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)
1373 }
1374 }
1375 break;
1376 default: // Currently only shadowing Write update nodes so shouldn't get here
1377 assert(0);
1378 continue;
1379 }
1380 }
1381 return result;
1382}
1383
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001384// Validate overall state at the time of a draw call
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001385static VkBool32 validate_draw_state(layer_data* my_data, GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001386 // First check flag states
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001387 VkBool32 result = validate_draw_state_flags(my_data, pCB, indexedDraw);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001388 PIPELINE_NODE* pPipe = getPipeline(my_data, pCB->lastBoundPipeline);
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001389 // Now complete other state checks
Tobin Ehlise90e66d2015-09-09 13:31:01 -06001390 // TODO : Currently only performing next check if *something* was bound (non-zero last bound)
1391 // There is probably a better way to gate when this check happens, and to know if something *should* have been bound
1392 // We should have that check separately and then gate this check based on that check
Mark Lobodzinski74635932015-12-18 15:35:38 -07001393 if (pPipe) {
1394 if (pCB->lastBoundPipelineLayout) {
1395 string errorString;
1396 for (auto setIndex : pPipe->active_sets) {
1397 // If valid set is not bound throw an error
1398 if ((pCB->boundDescriptorSets.size() <= setIndex) || (!pCB->boundDescriptorSets[setIndex])) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001399 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_DESCRIPTOR_SET_NOT_BOUND, "DS",
Mark Lobodzinski74635932015-12-18 15:35:38 -07001400 "VkPipeline %#" PRIxLEAST64 " uses set #%u but that set is not bound.", (uint64_t)pPipe->pipeline, setIndex);
1401 } else if (!verify_set_layout_compatibility(my_data, my_data->setMap[pCB->boundDescriptorSets[setIndex]], pPipe->graphicsPipelineCI.layout, setIndex, errorString)) {
1402 // Set is bound but not compatible w/ overlapping pipelineLayout from PSO
1403 VkDescriptorSet setHandle = my_data->setMap[pCB->boundDescriptorSets[setIndex]]->set;
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001404 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t)setHandle, __LINE__, DRAWSTATE_PIPELINE_LAYOUTS_INCOMPATIBLE, "DS",
Mark Lobodzinski74635932015-12-18 15:35:38 -07001405 "VkDescriptorSet (%#" PRIxLEAST64 ") bound as set #%u is not compatible with overlapping VkPipelineLayout %#" PRIxLEAST64 " due to: %s",
1406 (uint64_t)setHandle, setIndex, (uint64_t)pPipe->graphicsPipelineCI.layout, errorString.c_str());
Tobin Ehlis43c39c02016-01-11 13:18:40 -07001407 } else { // Valid set is bound and layout compatible, validate that it's updated and verify any dynamic offsets
1408 // Pull the set node
Tobin Ehlisf6585052015-12-17 11:48:42 -07001409 SET_NODE* pSet = getSetNode(my_data, pCB->boundDescriptorSets[setIndex]);
Tobin Ehlis43c39c02016-01-11 13:18:40 -07001410 // Make sure set has been updated
1411 if (!pSet->pUpdateStructs) {
1412 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, __LINE__, DRAWSTATE_DESCRIPTOR_SET_NOT_UPDATED, "DS",
1413 "DS %#" PRIxLEAST64 " bound but it was never updated. It is now being used to draw so this will result in undefined behavior.", (uint64_t) pSet->set);
1414 }
1415 // For each dynamic descriptor, make sure dynamic offset doesn't overstep buffer
Tobin Ehlisf6585052015-12-17 11:48:42 -07001416 result |= validate_dynamic_offsets(my_data, pSet);
Mark Lobodzinski74635932015-12-18 15:35:38 -07001417 }
Tobin Ehlis88452832015-12-03 09:40:56 -07001418 }
1419 }
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07001420
Mark Lobodzinski74635932015-12-18 15:35:38 -07001421 // Verify Vtx binding
1422 if (pPipe->vtxBindingCount > 0) {
1423 VkPipelineVertexInputStateCreateInfo *vtxInCI = &pPipe->vertexInputCI;
1424 for (uint32_t i = 0; i < vtxInCI->vertexBindingDescriptionCount; i++) {
Michael Lentine700b0aa2015-10-30 17:57:32 -07001425 if ((pCB->currentDrawData.buffers.size() < (i+1)) || (pCB->currentDrawData.buffers[i] == VK_NULL_HANDLE)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001426 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS",
Mark Lobodzinski74635932015-12-18 15:35:38 -07001427 "The Pipeline State Object (%#" PRIxLEAST64 ") expects that this Command Buffer's vertex binding Index %d should be set via vkCmdBindVertexBuffers.",
1428 (uint64_t)pCB->lastBoundPipeline, i);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001429
Mark Lobodzinski74635932015-12-18 15:35:38 -07001430 }
1431 }
1432 } else {
Michael Lentine700b0aa2015-10-30 17:57:32 -07001433 if (!pCB->currentDrawData.buffers.empty()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001434 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS,
Mark Lobodzinski74635932015-12-18 15:35:38 -07001435 "DS", "Vertex buffers are bound to command buffer (%#" PRIxLEAST64 ") but no vertex buffers are attached to this Pipeline State Object (%#" PRIxLEAST64 ").",
1436 (uint64_t)pCB->commandBuffer, (uint64_t)pCB->lastBoundPipeline);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06001437 }
1438 }
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07001439
Mark Lobodzinski74635932015-12-18 15:35:38 -07001440 // If Viewport or scissors are dynamic, verify that dynamic count matches PSO count
1441 VkBool32 dynViewport = isDynamic(pPipe, VK_DYNAMIC_STATE_VIEWPORT);
1442 VkBool32 dynScissor = isDynamic(pPipe, VK_DYNAMIC_STATE_SCISSOR);
1443 if (dynViewport) {
1444 if (pCB->viewports.size() != pPipe->graphicsPipelineCI.pViewportState->viewportCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001445 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
Mark Lobodzinski74635932015-12-18 15:35:38 -07001446 "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);
1447 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001448 }
Mark Lobodzinski74635932015-12-18 15:35:38 -07001449 if (dynScissor) {
1450 if (pCB->scissors.size() != pPipe->graphicsPipelineCI.pViewportState->scissorCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001451 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
Mark Lobodzinski74635932015-12-18 15:35:38 -07001452 "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);
1453 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001454 }
1455 }
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001456 return result;
1457}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001458
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001459// Verify that create state for a pipeline is valid
Tobin Ehlis88452832015-12-03 09:40:56 -07001460static VkBool32 verifyPipelineCreateState(layer_data* my_data, const VkDevice device, PIPELINE_NODE* pPipeline)
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001461{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001462 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski2fd2d032015-12-16 14:25:22 -07001463
Chris Forbesebf42d42015-12-17 17:07:15 +13001464 //if (!validate_pipeline_shaders(my_data, device, &(pPipeline->graphicsPipelineCI))) {
Tobin Ehlis88452832015-12-03 09:40:56 -07001465 if (!validate_pipeline_shaders(my_data, device, pPipeline)) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001466 skipCall = VK_TRUE;
1467 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001468 // VS is required
1469 if (!(pPipeline->active_shaders & VK_SHADER_STAGE_VERTEX_BIT)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001470 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001471 "Invalid Pipeline CreateInfo State: Vtx Shader required");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001472 }
1473 // Either both or neither TC/TE shaders should be defined
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001474 if (((pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) == 0) !=
1475 ((pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) == 0) ) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001476 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001477 "Invalid Pipeline CreateInfo State: TE and TC shaders must be included or excluded as a pair");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001478 }
1479 // Compute shaders should be specified independent of Gfx shaders
1480 if ((pPipeline->active_shaders & VK_SHADER_STAGE_COMPUTE_BIT) &&
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001481 (pPipeline->active_shaders & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT |
1482 VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT | VK_SHADER_STAGE_GEOMETRY_BIT |
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001483 VK_SHADER_STAGE_FRAGMENT_BIT))) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001484 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001485 "Invalid Pipeline CreateInfo State: Do not specify Compute Shader for Gfx Pipeline");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001486 }
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001487 // VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology is only valid for tessellation pipelines.
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001488 // Mismatching primitive topology and tessellation fails graphics pipeline creation.
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001489 if (pPipeline->active_shaders & (VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) &&
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001490 (pPipeline->iaStateCI.topology != VK_PRIMITIVE_TOPOLOGY_PATCH_LIST)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001491 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001492 "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 -06001493 }
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001494 if (pPipeline->iaStateCI.topology == VK_PRIMITIVE_TOPOLOGY_PATCH_LIST) {
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001495 if (~pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001496 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001497 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology is only valid for tessellation pipelines");
Tobin Ehlis912df022015-09-17 08:46:18 -06001498 }
1499 if (!pPipeline->tessStateCI.patchControlPoints || (pPipeline->tessStateCI.patchControlPoints > 32)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001500 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001501 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology used with patchControlPoints value %u."
Tobin Ehlis912df022015-09-17 08:46:18 -06001502 " patchControlPoints should be >0 and <=32.", pPipeline->tessStateCI.patchControlPoints);
1503 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001504 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001505 // Viewport state must be included and viewport and scissor counts should always match
Tobin Ehlise68360f2015-10-01 11:15:13 -06001506 // NOTE : Even if these are flagged as dynamic, counts need to be set correctly for shader compiler
Tobin Ehlisd332f282015-10-02 11:00:56 -06001507 if (!pPipeline->graphicsPipelineCI.pViewportState) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001508 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
Tobin Ehlisd332f282015-10-02 11:00:56 -06001509 "Gfx Pipeline pViewportState is null. Even if viewport and scissors are dynamic PSO must include viewportCount and scissorCount in pViewportState.");
1510 } else if (pPipeline->graphicsPipelineCI.pViewportState->scissorCount != pPipeline->graphicsPipelineCI.pViewportState->viewportCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001511 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
Tobin Ehlise68360f2015-10-01 11:15:13 -06001512 "Gfx Pipeline viewport count (%u) must match scissor count (%u).", pPipeline->vpStateCI.viewportCount, pPipeline->vpStateCI.scissorCount);
Tobin Ehlisd332f282015-10-02 11:00:56 -06001513 } else {
1514 // If viewport or scissor are not dynamic, then verify that data is appropriate for count
1515 VkBool32 dynViewport = isDynamic(pPipeline, VK_DYNAMIC_STATE_VIEWPORT);
1516 VkBool32 dynScissor = isDynamic(pPipeline, VK_DYNAMIC_STATE_SCISSOR);
1517 if (!dynViewport) {
1518 if (pPipeline->graphicsPipelineCI.pViewportState->viewportCount && !pPipeline->graphicsPipelineCI.pViewportState->pViewports) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001519 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
Courtney Goeltzenleuchterb19042e2015-11-25 11:38:54 -07001520 "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 -06001521 }
1522 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001523 if (!dynScissor) {
1524 if (pPipeline->graphicsPipelineCI.pViewportState->scissorCount && !pPipeline->graphicsPipelineCI.pViewportState->pScissors) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001525 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
Courtney Goeltzenleuchterb19042e2015-11-25 11:38:54 -07001526 "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 -06001527 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06001528 }
1529 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001530 return skipCall;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001531}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001532
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001533// Init the pipeline mapping info based on pipeline create info LL tree
1534// Threading note : Calls to this function should wrapped in mutex
Tobin Ehlis88452832015-12-03 09:40:56 -07001535// TODO : this should really just be in the constructor for PIPELINE_NODE
Mark Lobodzinski475a2182015-11-10 15:25:01 -07001536static PIPELINE_NODE* initGraphicsPipeline(layer_data* dev_data, const VkGraphicsPipelineCreateInfo* pCreateInfo, PIPELINE_NODE* pBasePipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001537{
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001538 PIPELINE_NODE* pPipeline = new PIPELINE_NODE;
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001539
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001540 if (pBasePipeline) {
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001541 *pPipeline = *pBasePipeline;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001542 }
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001543
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001544 // First init create info
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001545 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001546
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001547 size_t bufferSize = 0;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001548 const VkPipelineVertexInputStateCreateInfo* pVICI = NULL;
Tobin Ehlis5a65cca2015-07-13 13:14:24 -06001549 const VkPipelineColorBlendStateCreateInfo* pCBCI = NULL;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001550
1551 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
1552 const VkPipelineShaderStageCreateInfo *pPSSCI = &pCreateInfo->pStages[i];
1553
Chia-I Wu28e06912015-10-31 00:31:16 +08001554 switch (pPSSCI->stage) {
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001555 case VK_SHADER_STAGE_VERTEX_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001556 memcpy(&pPipeline->vsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1557 pPipeline->active_shaders |= VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001558 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001559 case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001560 memcpy(&pPipeline->tcsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001561 pPipeline->active_shaders |= VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001562 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001563 case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001564 memcpy(&pPipeline->tesCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001565 pPipeline->active_shaders |= VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001566 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001567 case VK_SHADER_STAGE_GEOMETRY_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001568 memcpy(&pPipeline->gsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1569 pPipeline->active_shaders |= VK_SHADER_STAGE_GEOMETRY_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001570 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001571 case VK_SHADER_STAGE_FRAGMENT_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001572 memcpy(&pPipeline->fsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1573 pPipeline->active_shaders |= VK_SHADER_STAGE_FRAGMENT_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001574 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001575 case VK_SHADER_STAGE_COMPUTE_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001576 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
1577 pPipeline->active_shaders |= VK_SHADER_STAGE_COMPUTE_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001578 break;
1579 default:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001580 // TODO : Flag error
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001581 break;
1582 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001583 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001584 // Copy over GraphicsPipelineCreateInfo structure embedded pointers
1585 if (pCreateInfo->stageCount != 0) {
1586 pPipeline->graphicsPipelineCI.pStages = new VkPipelineShaderStageCreateInfo[pCreateInfo->stageCount];
1587 bufferSize = pCreateInfo->stageCount * sizeof(VkPipelineShaderStageCreateInfo);
1588 memcpy((void*)pPipeline->graphicsPipelineCI.pStages, pCreateInfo->pStages, bufferSize);
1589 }
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001590 if (pCreateInfo->pVertexInputState != NULL) {
1591 memcpy((void*)&pPipeline->vertexInputCI, pCreateInfo->pVertexInputState , sizeof(VkPipelineVertexInputStateCreateInfo));
1592 // Copy embedded ptrs
1593 pVICI = pCreateInfo->pVertexInputState;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001594 pPipeline->vtxBindingCount = pVICI->vertexBindingDescriptionCount;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001595 if (pPipeline->vtxBindingCount) {
1596 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
1597 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
1598 memcpy((void*)pPipeline->pVertexBindingDescriptions, pVICI->pVertexBindingDescriptions, bufferSize);
1599 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08001600 pPipeline->vtxAttributeCount = pVICI->vertexAttributeDescriptionCount;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001601 if (pPipeline->vtxAttributeCount) {
1602 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
1603 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
1604 memcpy((void*)pPipeline->pVertexAttributeDescriptions, pVICI->pVertexAttributeDescriptions, bufferSize);
1605 }
1606 pPipeline->graphicsPipelineCI.pVertexInputState = &pPipeline->vertexInputCI;
1607 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001608 if (pCreateInfo->pInputAssemblyState != NULL) {
1609 memcpy((void*)&pPipeline->iaStateCI, pCreateInfo->pInputAssemblyState, sizeof(VkPipelineInputAssemblyStateCreateInfo));
1610 pPipeline->graphicsPipelineCI.pInputAssemblyState = &pPipeline->iaStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001611 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001612 if (pCreateInfo->pTessellationState != NULL) {
1613 memcpy((void*)&pPipeline->tessStateCI, pCreateInfo->pTessellationState, sizeof(VkPipelineTessellationStateCreateInfo));
1614 pPipeline->graphicsPipelineCI.pTessellationState = &pPipeline->tessStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001615 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001616 if (pCreateInfo->pViewportState != NULL) {
1617 memcpy((void*)&pPipeline->vpStateCI, pCreateInfo->pViewportState, sizeof(VkPipelineViewportStateCreateInfo));
1618 pPipeline->graphicsPipelineCI.pViewportState = &pPipeline->vpStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001619 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001620 if (pCreateInfo->pRasterizationState != NULL) {
1621 memcpy((void*)&pPipeline->rsStateCI, pCreateInfo->pRasterizationState, sizeof(VkPipelineRasterizationStateCreateInfo));
1622 pPipeline->graphicsPipelineCI.pRasterizationState = &pPipeline->rsStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001623 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001624 if (pCreateInfo->pMultisampleState != NULL) {
1625 memcpy((void*)&pPipeline->msStateCI, pCreateInfo->pMultisampleState, sizeof(VkPipelineMultisampleStateCreateInfo));
1626 pPipeline->graphicsPipelineCI.pMultisampleState = &pPipeline->msStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001627 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001628 if (pCreateInfo->pDepthStencilState != NULL) {
1629 memcpy((void*)&pPipeline->dsStateCI, pCreateInfo->pDepthStencilState, sizeof(VkPipelineDepthStencilStateCreateInfo));
1630 pPipeline->graphicsPipelineCI.pDepthStencilState = &pPipeline->dsStateCI;
1631 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001632 if (pCreateInfo->pColorBlendState != NULL) {
1633 memcpy((void*)&pPipeline->cbStateCI, pCreateInfo->pColorBlendState, sizeof(VkPipelineColorBlendStateCreateInfo));
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001634 // Copy embedded ptrs
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001635 pCBCI = pCreateInfo->pColorBlendState;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001636 pPipeline->attachmentCount = pCBCI->attachmentCount;
1637 if (pPipeline->attachmentCount) {
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001638 pPipeline->pAttachments = new VkPipelineColorBlendAttachmentState[pPipeline->attachmentCount];
1639 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineColorBlendAttachmentState);
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001640 memcpy((void*)pPipeline->pAttachments, pCBCI->pAttachments, bufferSize);
1641 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001642 pPipeline->graphicsPipelineCI.pColorBlendState = &pPipeline->cbStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001643 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001644 if (pCreateInfo->pDynamicState != NULL) {
1645 memcpy((void*)&pPipeline->dynStateCI, pCreateInfo->pDynamicState, sizeof(VkPipelineDynamicStateCreateInfo));
1646 if (pPipeline->dynStateCI.dynamicStateCount) {
1647 pPipeline->dynStateCI.pDynamicStates = new VkDynamicState[pPipeline->dynStateCI.dynamicStateCount];
1648 bufferSize = pPipeline->dynStateCI.dynamicStateCount * sizeof(VkDynamicState);
1649 memcpy((void*)pPipeline->dynStateCI.pDynamicStates, pCreateInfo->pDynamicState->pDynamicStates, bufferSize);
1650 }
1651 pPipeline->graphicsPipelineCI.pDynamicState = &pPipeline->dynStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001652 }
Tobin Ehlis88452832015-12-03 09:40:56 -07001653 pPipeline->active_sets.clear();
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001654 return pPipeline;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001655}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001656
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001657// Free the Pipeline nodes
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001658static void deletePipelines(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001659{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001660 if (my_data->pipelineMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06001661 return;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001662 for (auto ii=my_data->pipelineMap.begin(); ii!=my_data->pipelineMap.end(); ++ii) {
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001663 if ((*ii).second->graphicsPipelineCI.stageCount != 0) {
1664 delete[] (*ii).second->graphicsPipelineCI.pStages;
1665 }
Tobin Ehlisf313c8b2015-04-01 11:59:08 -06001666 if ((*ii).second->pVertexBindingDescriptions) {
1667 delete[] (*ii).second->pVertexBindingDescriptions;
1668 }
1669 if ((*ii).second->pVertexAttributeDescriptions) {
1670 delete[] (*ii).second->pVertexAttributeDescriptions;
1671 }
1672 if ((*ii).second->pAttachments) {
1673 delete[] (*ii).second->pAttachments;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001674 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001675 if ((*ii).second->dynStateCI.dynamicStateCount != 0) {
1676 delete[] (*ii).second->dynStateCI.pDynamicStates;
1677 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001678 delete (*ii).second;
1679 }
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001680 my_data->pipelineMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001681}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001682
Tobin Ehliseba312c2015-04-01 08:40:34 -06001683// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Chia-I Wu5c17c962015-10-31 00:31:16 +08001684static VkSampleCountFlagBits getNumSamples(layer_data* my_data, const VkPipeline pipeline)
Tobin Ehliseba312c2015-04-01 08:40:34 -06001685{
Chia-I Wue2fc5522015-10-26 20:04:44 +08001686 PIPELINE_NODE* pPipe = my_data->pipelineMap[pipeline];
Tobin Ehlis577188e2015-07-13 14:51:15 -06001687 if (VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001688 return pPipe->msStateCI.rasterizationSamples;
Tobin Ehlis577188e2015-07-13 14:51:15 -06001689 }
Chia-I Wu5c17c962015-10-31 00:31:16 +08001690 return VK_SAMPLE_COUNT_1_BIT;
Tobin Ehliseba312c2015-04-01 08:40:34 -06001691}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001692
Tobin Ehliseba312c2015-04-01 08:40:34 -06001693// Validate state related to the PSO
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001694static VkBool32 validatePipelineState(layer_data* my_data, const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehliseba312c2015-04-01 08:40:34 -06001695{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001696 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06001697 // Verify that any MSAA request in PSO matches sample# in bound FB
Chia-I Wu5c17c962015-10-31 00:31:16 +08001698 VkSampleCountFlagBits psoNumSamples = getNumSamples(my_data, pipeline);
Tobin Ehliseba312c2015-04-01 08:40:34 -06001699 if (pCB->activeRenderPass) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001700 const VkRenderPassCreateInfo* pRPCI = my_data->renderPassMap[pCB->activeRenderPass]->pCreateInfo;
Chia-I Wu08accc62015-07-07 11:50:03 +08001701 const VkSubpassDescription* pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
Chia-I Wu5c17c962015-10-31 00:31:16 +08001702 VkSampleCountFlagBits subpassNumSamples = (VkSampleCountFlagBits) 0;
Chia-I Wu08accc62015-07-07 11:50:03 +08001703 uint32_t i;
1704
Chia-I Wud50a7d72015-10-26 20:48:51 +08001705 for (i = 0; i < pSD->colorAttachmentCount; i++) {
Chia-I Wu5c17c962015-10-31 00:31:16 +08001706 VkSampleCountFlagBits samples;
Chia-I Wu08accc62015-07-07 11:50:03 +08001707
Cody Northropa505dda2015-08-04 11:16:41 -06001708 if (pSD->pColorAttachments[i].attachment == VK_ATTACHMENT_UNUSED)
Chia-I Wu08accc62015-07-07 11:50:03 +08001709 continue;
1710
Cody Northropa505dda2015-08-04 11:16:41 -06001711 samples = pRPCI->pAttachments[pSD->pColorAttachments[i].attachment].samples;
Chia-I Wu5c17c962015-10-31 00:31:16 +08001712 if (subpassNumSamples == (VkSampleCountFlagBits) 0) {
Chia-I Wu08accc62015-07-07 11:50:03 +08001713 subpassNumSamples = samples;
1714 } else if (subpassNumSamples != samples) {
Chia-I Wu5c17c962015-10-31 00:31:16 +08001715 subpassNumSamples = (VkSampleCountFlagBits) -1;
Chia-I Wu08accc62015-07-07 11:50:03 +08001716 break;
1717 }
1718 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08001719 if (pSD->pDepthStencilAttachment && pSD->pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
Chia-I Wu5c17c962015-10-31 00:31:16 +08001720 const VkSampleCountFlagBits samples = pRPCI->pAttachments[pSD->pDepthStencilAttachment->attachment].samples;
1721 if (subpassNumSamples == (VkSampleCountFlagBits) 0)
Chia-I Wu08accc62015-07-07 11:50:03 +08001722 subpassNumSamples = samples;
1723 else if (subpassNumSamples != samples)
Chia-I Wu5c17c962015-10-31 00:31:16 +08001724 subpassNumSamples = (VkSampleCountFlagBits) -1;
Chia-I Wu08accc62015-07-07 11:50:03 +08001725 }
1726
1727 if (psoNumSamples != subpassNumSamples) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001728 return log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, (uint64_t) pipeline, __LINE__, DRAWSTATE_NUM_SAMPLES_MISMATCH, "DS",
Mark Lobodzinski5495d132015-09-30 16:19:16 -06001729 "Num samples mismatch! Binding PSO (%#" PRIxLEAST64 ") with %u samples while current RenderPass (%#" PRIxLEAST64 ") w/ %u samples!",
Chia-I Wue2fc5522015-10-26 20:04:44 +08001730 (uint64_t) pipeline, psoNumSamples, (uint64_t) pCB->activeRenderPass, subpassNumSamples);
Tobin Ehliseba312c2015-04-01 08:40:34 -06001731 }
1732 } else {
1733 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
1734 // Verify and flag error as appropriate
1735 }
1736 // TODO : Add more checks here
1737 } else {
1738 // TODO : Validate non-gfx pipeline updates
1739 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001740 return VK_FALSE;
Tobin Ehliseba312c2015-04-01 08:40:34 -06001741}
1742
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001743// Block of code at start here specifically for managing/tracking DSs
1744
Tobin Ehlis793ad302015-04-03 12:01:11 -06001745// Return Pool node ptr for specified pool or else NULL
Mark Lobodzinski39298632015-11-18 08:38:27 -07001746static DESCRIPTOR_POOL_NODE* getPoolNode(layer_data* my_data, const VkDescriptorPool pool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001747{
1748 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07001749 if (my_data->descriptorPoolMap.find(pool) == my_data->descriptorPoolMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001750 loader_platform_thread_unlock_mutex(&globalLock);
1751 return NULL;
1752 }
1753 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07001754 return my_data->descriptorPoolMap[pool];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001755}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001756
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001757static LAYOUT_NODE* getLayoutNode(layer_data* my_data, const VkDescriptorSetLayout layout) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001758 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001759 if (my_data->descriptorSetLayoutMap.find(layout) == my_data->descriptorSetLayoutMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001760 loader_platform_thread_unlock_mutex(&globalLock);
1761 return NULL;
1762 }
1763 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001764 return my_data->descriptorSetLayoutMap[layout];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001765}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001766
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001767// 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 -06001768static VkBool32 validUpdateStruct(layer_data* my_data, const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001769{
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001770 switch (pUpdateStruct->sType)
1771 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001772 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1773 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001774 return VK_FALSE;
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001775 default:
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001776 return log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001777 "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 -06001778 }
1779}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001780
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001781// Set count for given update struct in the last parameter
Courtney Goeltzenleuchter085f8dd2015-12-16 16:08:44 -07001782// 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 -06001783static uint32_t getUpdateCount(layer_data* my_data, const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis793ad302015-04-03 12:01:11 -06001784{
1785 switch (pUpdateStruct->sType)
1786 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001787 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
Chia-I Wud50a7d72015-10-26 20:48:51 +08001788 return ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorCount;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001789 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis793ad302015-04-03 12:01:11 -06001790 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wud50a7d72015-10-26 20:48:51 +08001791 return ((VkCopyDescriptorSet*)pUpdateStruct)->descriptorCount;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001792 }
Courtney Goeltzenleuchter7f47bca2015-12-16 16:08:08 -07001793
1794 return 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001795}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001796
Tobin Ehlis793ad302015-04-03 12:01:11 -06001797// For given Layout Node and binding, return index where that binding begins
1798static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
1799{
1800 uint32_t offsetIndex = 0;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001801 for (uint32_t i = 0; i < pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001802 if (pLayout->createInfo.pBindings[i].binding == binding)
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001803 break;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001804 offsetIndex += pLayout->createInfo.pBindings[i].descriptorCount;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001805 }
1806 return offsetIndex;
1807}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001808
Tobin Ehlis793ad302015-04-03 12:01:11 -06001809// For given layout node and binding, return last index that is updated
1810static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
1811{
1812 uint32_t offsetIndex = 0;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001813 for (uint32_t i = 0; i < pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001814 offsetIndex += pLayout->createInfo.pBindings[i].descriptorCount;
1815 if (pLayout->createInfo.pBindings[i].binding == binding)
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001816 break;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001817 }
1818 return offsetIndex-1;
1819}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001820
Tobin Ehlisbaca3ab2015-10-27 12:54:50 -06001821// For given layout and update, return the first overall index of the layout that is updated
Tobin Ehlis8a62e632015-10-27 15:43:38 -06001822static 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 -06001823{
Tobin Ehlisbaca3ab2015-10-27 12:54:50 -06001824 return getBindingStartIndex(pLayout, binding)+arrayIndex;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001825}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001826
Tobin Ehlis8a62e632015-10-27 15:43:38 -06001827// For given layout and update, return the last overall index of the layout that is updated
1828static 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 -06001829{
Tobin Ehlis8a62e632015-10-27 15:43:38 -06001830 uint32_t count = getUpdateCount(my_data, device, pUpdateStruct);
Tobin Ehlisbaca3ab2015-10-27 12:54:50 -06001831 return getBindingStartIndex(pLayout, binding)+arrayIndex+count-1;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001832}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001833
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001834// Verify that the descriptor type in the update struct matches what's expected by the layout
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001835static 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 -06001836{
1837 // First get actual type of update
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001838 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001839 VkDescriptorType actualType;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001840 uint32_t i = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001841 switch (pUpdateStruct->sType)
1842 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001843 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1844 actualType = ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorType;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001845 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001846 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
1847 /* no need to validate */
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001848 return VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001849 break;
1850 default:
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001851 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001852 "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 -06001853 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001854 if (VK_FALSE == skipCall) {
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001855 // Set first stageFlags as reference and verify that all other updates match it
1856 VkShaderStageFlags refStageFlags = pLayout->stageFlags[startIndex];
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001857 for (i = startIndex; i <= endIndex; i++) {
Tobin Ehlis644ff042015-10-20 10:11:55 -06001858 if (pLayout->descriptorTypes[i] != actualType) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001859 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, "DS",
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001860 "Write descriptor update has descriptor type %s that does not match overlapping binding descriptor type of %s!",
1861 string_VkDescriptorType(actualType), string_VkDescriptorType(pLayout->descriptorTypes[i]));
1862 }
1863 if (pLayout->stageFlags[i] != refStageFlags) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001864 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_DESCRIPTOR_STAGEFLAGS_MISMATCH, "DS",
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001865 "Write descriptor update has stageFlags %x that do not match overlapping binding descriptor stageFlags of %x!",
1866 refStageFlags, pLayout->stageFlags[i]);
Tobin Ehlis483cc352015-09-30 08:30:20 -06001867 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001868 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001869 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001870 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001871}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001872
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001873// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001874// struct into the pNewNode param. Return VK_TRUE if error condition encountered and callback signals early exit.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001875// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001876static VkBool32 shadowUpdateNode(layer_data* my_data, const VkDevice device, GENERIC_HEADER* pUpdate, GENERIC_HEADER** pNewNode)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001877{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001878 VkBool32 skipCall = VK_FALSE;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001879 VkWriteDescriptorSet* pWDS = NULL;
1880 VkCopyDescriptorSet* pCDS = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001881 size_t array_size = 0;
1882 size_t base_array_size = 0;
1883 size_t total_array_size = 0;
1884 size_t baseBuffAddr = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001885 switch (pUpdate->sType)
1886 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001887 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1888 pWDS = new VkWriteDescriptorSet;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001889 *pNewNode = (GENERIC_HEADER*)pWDS;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001890 memcpy(pWDS, pUpdate, sizeof(VkWriteDescriptorSet));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001891
1892 switch (pWDS->descriptorType) {
1893 case VK_DESCRIPTOR_TYPE_SAMPLER:
1894 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
1895 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
1896 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
1897 {
Chia-I Wud50a7d72015-10-26 20:48:51 +08001898 VkDescriptorImageInfo *info = new VkDescriptorImageInfo[pWDS->descriptorCount];
1899 memcpy(info, pWDS->pImageInfo, pWDS->descriptorCount * sizeof(VkDescriptorImageInfo));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001900 pWDS->pImageInfo = info;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001901 }
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001902 break;
1903 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
1904 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
1905 {
Chia-I Wud50a7d72015-10-26 20:48:51 +08001906 VkBufferView *info = new VkBufferView[pWDS->descriptorCount];
1907 memcpy(info, pWDS->pTexelBufferView, pWDS->descriptorCount * sizeof(VkBufferView));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001908 pWDS->pTexelBufferView = info;
1909 }
1910 break;
1911 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
1912 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
1913 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
1914 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
1915 {
Chia-I Wud50a7d72015-10-26 20:48:51 +08001916 VkDescriptorBufferInfo *info = new VkDescriptorBufferInfo[pWDS->descriptorCount];
1917 memcpy(info, pWDS->pBufferInfo, pWDS->descriptorCount * sizeof(VkDescriptorBufferInfo));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001918 pWDS->pBufferInfo = info;
1919 }
1920 break;
1921 default:
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07001922 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001923 break;
1924 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001925 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001926 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
1927 pCDS = new VkCopyDescriptorSet;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001928 *pNewNode = (GENERIC_HEADER*)pCDS;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001929 memcpy(pCDS, pUpdate, sizeof(VkCopyDescriptorSet));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001930 break;
1931 default:
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001932 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001933 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdate->sType), pUpdate->sType))
1934 return VK_TRUE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001935 }
1936 // Make sure that pNext for the end of shadow copy is NULL
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001937 (*pNewNode)->pNext = NULL;
1938 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001939}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001940
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001941// Verify that given sampler is valid
1942static VkBool32 validateSampler(const layer_data* my_data, const VkSampler* pSampler, const VkBool32 immutable)
1943{
1944 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08001945 auto sampIt = my_data->sampleMap.find(*pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001946 if (sampIt == my_data->sampleMap.end()) {
1947 if (!immutable) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001948 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT, (uint64_t) *pSampler, __LINE__, DRAWSTATE_SAMPLER_DESCRIPTOR_ERROR, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08001949 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid sampler %#" PRIxLEAST64, (uint64_t) *pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001950 } else { // immutable
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001951 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT, (uint64_t) *pSampler, __LINE__, DRAWSTATE_SAMPLER_DESCRIPTOR_ERROR, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08001952 "vkUpdateDescriptorSets: Attempt to update descriptor whose binding has an invalid immutable sampler %#" PRIxLEAST64, (uint64_t) *pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001953 }
1954 } else {
1955 // TODO : Any further checks we want to do on the sampler?
1956 }
1957 return skipCall;
1958}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001959
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001960// Verify that given imageView is valid
1961static VkBool32 validateImageView(const layer_data* my_data, const VkImageView* pImageView, const VkImageLayout imageLayout)
1962{
1963 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08001964 auto ivIt = my_data->imageViewMap.find(*pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001965 if (ivIt == my_data->imageViewMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001966 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, (uint64_t) *pImageView, __LINE__, DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08001967 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid imageView %#" PRIxLEAST64, (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001968 } else {
1969 // Validate that imageLayout is compatible with aspectMask and image format
1970 VkImageAspectFlags aspectMask = ivIt->second->subresourceRange.aspectMask;
Chia-I Wue2fc5522015-10-26 20:04:44 +08001971 VkImage image = ivIt->second->image;
Michael Lentine7b236262015-10-23 12:41:44 -07001972 // TODO : Check here in case we have a bad image
Chia-I Wue2fc5522015-10-26 20:04:44 +08001973 auto imgIt = my_data->imageMap.find(image);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001974 if (imgIt == my_data->imageMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001975 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t) image, __LINE__, DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, "DS",
Michael Lentine7b236262015-10-23 12:41:44 -07001976 "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 -06001977 } else {
1978 VkFormat format = (*imgIt).second->format;
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07001979 VkBool32 ds = vk_format_is_depth_or_stencil(format);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001980 switch (imageLayout) {
1981 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
1982 // Only Color bit must be set
1983 if ((aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) != VK_IMAGE_ASPECT_COLOR_BIT) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001984 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, (uint64_t) *pImageView, __LINE__,
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001985 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 +08001986 " that does not have VK_IMAGE_ASPECT_COLOR_BIT set.", (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001987 }
1988 // format must NOT be DS
1989 if (ds) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -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, __LINE__,
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001991 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 +08001992 " 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 -06001993 }
1994 break;
1995 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
1996 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
1997 // Depth or stencil bit must be set, but both must NOT be set
1998 if (aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) {
1999 if (aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) {
2000 // both must NOT be set
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002001 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, (uint64_t) *pImageView, __LINE__,
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002002 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with imageView %#" PRIxLEAST64 ""
Chia-I Wue2fc5522015-10-26 20:04:44 +08002003 " that has both STENCIL and DEPTH aspects set", (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002004 }
2005 } else if (!(aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)) {
2006 // Neither were set
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002007 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, (uint64_t) *pImageView, __LINE__,
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002008 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout %s and imageView %#" PRIxLEAST64 ""
Chia-I Wue2fc5522015-10-26 20:04:44 +08002009 " that does not have STENCIL or DEPTH aspect set.", string_VkImageLayout(imageLayout), (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002010 }
2011 // format must be DS
2012 if (!ds) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002013 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, (uint64_t) *pImageView, __LINE__,
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002014 DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout %s and imageView %#" PRIxLEAST64 ""
Chia-I Wue2fc5522015-10-26 20:04:44 +08002015 " 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 -06002016 }
2017 break;
2018 default:
2019 // anything to check for other layouts?
2020 break;
2021 }
2022 }
2023 }
2024 return skipCall;
2025}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002026
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002027// Verify that given bufferView is valid
2028static VkBool32 validateBufferView(const layer_data* my_data, const VkBufferView* pBufferView)
2029{
2030 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002031 auto sampIt = my_data->bufferViewMap.find(*pBufferView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002032 if (sampIt == my_data->bufferViewMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002033 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_VIEW_EXT, (uint64_t) *pBufferView, __LINE__, DRAWSTATE_BUFFERVIEW_DESCRIPTOR_ERROR, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002034 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid bufferView %#" PRIxLEAST64, (uint64_t) *pBufferView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002035 } else {
2036 // TODO : Any further checks we want to do on the bufferView?
2037 }
2038 return skipCall;
2039}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002040
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002041// Verify that given bufferInfo is valid
2042static VkBool32 validateBufferInfo(const layer_data* my_data, const VkDescriptorBufferInfo* pBufferInfo)
2043{
2044 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002045 auto sampIt = my_data->bufferMap.find(pBufferInfo->buffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002046 if (sampIt == my_data->bufferMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002047 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, (uint64_t) pBufferInfo->buffer, __LINE__, DRAWSTATE_BUFFERINFO_DESCRIPTOR_ERROR, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002048 "vkUpdateDescriptorSets: Attempt to update descriptor where bufferInfo has invalid buffer %#" PRIxLEAST64, (uint64_t) pBufferInfo->buffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002049 } else {
2050 // TODO : Any further checks we want to do on the bufferView?
2051 }
2052 return skipCall;
2053}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002054
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002055static VkBool32 validateUpdateContents(const layer_data* my_data, const VkWriteDescriptorSet *pWDS, const VkDescriptorSetLayoutBinding* pLayoutBinding)
2056{
2057 VkBool32 skipCall = VK_FALSE;
2058 // First verify that for the given Descriptor type, the correct DescriptorInfo data is supplied
2059 VkBufferView* pBufferView = NULL;
2060 const VkSampler* pSampler = NULL;
2061 VkImageView* pImageView = NULL;
2062 VkImageLayout* pImageLayout = NULL;
2063 VkDescriptorBufferInfo* pBufferInfo = NULL;
2064 VkBool32 immutable = VK_FALSE;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002065 uint32_t i = 0;
2066 // For given update type, verify that update contents are correct
2067 switch (pWDS->descriptorType) {
2068 case VK_DESCRIPTOR_TYPE_SAMPLER:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002069 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002070 skipCall |= validateSampler(my_data, &(pWDS->pImageInfo[i].sampler), immutable);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002071 }
2072 break;
2073 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002074 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002075 if (NULL == pLayoutBinding->pImmutableSamplers) {
2076 pSampler = &(pWDS->pImageInfo[i].sampler);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002077 if (immutable) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002078 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT, (uint64_t) *pSampler, __LINE__, DRAWSTATE_INCONSISTENT_IMMUTABLE_SAMPLER_UPDATE, "DS",
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002079 "vkUpdateDescriptorSets: Update #%u is not an immutable sampler %#" PRIxLEAST64 ", but previous update(s) from this "
2080 "VkWriteDescriptorSet struct used an immutable sampler. All updates from a single struct must either "
Chia-I Wue2fc5522015-10-26 20:04:44 +08002081 "use immutable or non-immutable samplers.", i, (uint64_t) *pSampler);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002082 }
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002083 } else {
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002084 if (i>0 && !immutable) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002085 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT, (uint64_t) *pSampler, __LINE__, DRAWSTATE_INCONSISTENT_IMMUTABLE_SAMPLER_UPDATE, "DS",
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002086 "vkUpdateDescriptorSets: Update #%u is an immutable sampler, but previous update(s) from this "
2087 "VkWriteDescriptorSet struct used a non-immutable sampler. All updates from a single struct must either "
2088 "use immutable or non-immutable samplers.", i);
2089 }
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002090 immutable = VK_TRUE;
2091 pSampler = &(pLayoutBinding->pImmutableSamplers[i]);
2092 }
2093 skipCall |= validateSampler(my_data, pSampler, immutable);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002094 }
2095 // Intentionally fall through here to also validate image stuff
2096 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2097 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
2098 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002099 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002100 skipCall |= validateImageView(my_data, &(pWDS->pImageInfo[i].imageView), pWDS->pImageInfo[i].imageLayout);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002101 }
2102 break;
2103 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2104 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002105 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002106 skipCall |= validateBufferView(my_data, &(pWDS->pTexelBufferView[i]));
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002107 }
2108 break;
2109 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2110 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2111 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2112 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002113 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002114 skipCall |= validateBufferInfo(my_data, &(pWDS->pBufferInfo[i]));
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002115 }
2116 break;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002117 }
2118 return skipCall;
2119}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002120
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002121// update DS mappings based on write and copy update arrays
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08002122static 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 -06002123{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002124 VkBool32 skipCall = VK_FALSE;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002125
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002126 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002127 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002128 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002129 // Validate Write updates
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002130 uint32_t i = 0;
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08002131 for (i=0; i < descriptorWriteCount; i++) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002132 VkDescriptorSet ds = pWDS[i].dstSet;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002133 SET_NODE* pSet = my_data->setMap[ds];
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002134 GENERIC_HEADER* pUpdate = (GENERIC_HEADER*) &pWDS[i];
Tobin Ehlis793ad302015-04-03 12:01:11 -06002135 pLayout = pSet->pLayout;
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002136 // First verify valid update struct
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06002137 if ((skipCall = validUpdateStruct(my_data, device, pUpdate)) == VK_TRUE) {
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002138 break;
2139 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002140 uint32_t binding = 0, endIndex = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002141 binding = pWDS[i].dstBinding;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002142 // Make sure that layout being updated has the binding being updated
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002143 if (pLayout->bindings.find(binding) == pLayout->bindings.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002144 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) ds, __LINE__, DRAWSTATE_INVALID_UPDATE_INDEX, "DS",
Michael Lentine010f4692015-11-03 16:19:46 -08002145 "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 -06002146 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06002147 // Next verify that update falls within size of given binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002148 endIndex = getUpdateEndIndex(my_data, device, pLayout, binding, pWDS[i].dstArrayElement, pUpdate);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002149 if (getBindingEndIndex(pLayout, binding) < endIndex) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06002150 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002151 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002152 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) ds, __LINE__, DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, "DS",
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002153 "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 -06002154 } else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002155 uint32_t startIndex;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002156 startIndex = getUpdateStartIndex(my_data, device, pLayout, binding, pWDS[i].dstArrayElement, pUpdate);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002157 // Layout bindings match w/ update, now verify that update type & stageFlags are the same for entire update
2158 if ((skipCall = validateUpdateConsistency(my_data, device, pLayout, pUpdate, startIndex, endIndex)) == VK_FALSE) {
2159 // The update is within bounds and consistent, but need to make sure contents make sense as well
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002160 if ((skipCall = validateUpdateContents(my_data, &pWDS[i], &pLayout->createInfo.pBindings[binding])) == VK_FALSE) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002161 // Update is good. Save the update info
2162 // Create new update struct for this set's shadow copy
2163 GENERIC_HEADER* pNewNode = NULL;
2164 skipCall |= shadowUpdateNode(my_data, device, pUpdate, &pNewNode);
2165 if (NULL == pNewNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002166 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) ds, __LINE__, DRAWSTATE_OUT_OF_MEMORY, "DS",
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002167 "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
2168 } else {
2169 // Insert shadow node into LL of updates for this set
2170 pNewNode->pNext = pSet->pUpdateStructs;
2171 pSet->pUpdateStructs = pNewNode;
2172 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002173 for (uint32_t j = startIndex; j <= endIndex; j++) {
2174 assert(j<pSet->descriptorCount);
2175 pSet->ppDescriptors[j] = pNewNode;
2176 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002177 }
2178 }
2179 }
2180 }
2181 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002182 }
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002183 // Now validate copy updates
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08002184 for (i=0; i < descriptorCopyCount; ++i) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002185 SET_NODE *pSrcSet = NULL, *pDstSet = NULL;
2186 LAYOUT_NODE *pSrcLayout = NULL, *pDstLayout = NULL;
2187 uint32_t srcStartIndex = 0, srcEndIndex = 0, dstStartIndex = 0, dstEndIndex = 0;
2188 // For each copy make sure that update falls within given layout and that types match
Chia-I Wue2fc5522015-10-26 20:04:44 +08002189 pSrcSet = my_data->setMap[pCDS[i].srcSet];
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002190 pDstSet = my_data->setMap[pCDS[i].dstSet];
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002191 pSrcLayout = pSrcSet->pLayout;
2192 pDstLayout = pDstSet->pLayout;
2193 // Validate that src binding is valid for src set layout
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002194 if (pSrcLayout->bindings.find(pCDS[i].srcBinding) == pSrcLayout->bindings.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002195 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, __LINE__, DRAWSTATE_INVALID_UPDATE_INDEX, "DS",
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002196 "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 +08002197 i, pCDS[i].srcBinding, (uint64_t) pSrcLayout->layout, pSrcLayout->createInfo.bindingCount-1);
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002198 } else if (pDstLayout->bindings.find(pCDS[i].dstBinding) == pDstLayout->bindings.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002199 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, __LINE__, DRAWSTATE_INVALID_UPDATE_INDEX, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002200 "Copy descriptor update %u has dstBinding %u which is out of bounds for underlying SetLayout %#" PRIxLEAST64 " which only has bindings 0-%u.",
2201 i, pCDS[i].dstBinding, (uint64_t) pDstLayout->layout, pDstLayout->createInfo.bindingCount-1);
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002202 } else {
2203 // Proceed with validation. Bindings are ok, but make sure update is within bounds of given layout
2204 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 +08002205 dstEndIndex = getUpdateEndIndex(my_data, device, pDstLayout, pCDS[i].dstBinding, pCDS[i].dstArrayElement, (const GENERIC_HEADER*)&(pCDS[i]));
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002206 if (getBindingEndIndex(pSrcLayout, pCDS[i].srcBinding) < srcEndIndex) {
2207 pLayoutCI = &pSrcLayout->createInfo;
2208 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002209 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, __LINE__, DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, "DS",
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002210 "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 +08002211 } else if (getBindingEndIndex(pDstLayout, pCDS[i].dstBinding) < dstEndIndex) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002212 pLayoutCI = &pDstLayout->createInfo;
2213 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002214 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, __LINE__, DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002215 "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 -06002216 } else {
2217 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 +08002218 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 +08002219 for (uint32_t j=0; j<pCDS[i].descriptorCount; ++j) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002220 // For copy just make sure that the types match and then perform the update
2221 if (pSrcLayout->descriptorTypes[srcStartIndex+j] != pDstLayout->descriptorTypes[dstStartIndex+j]) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002222 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, "DS",
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002223 "Copy descriptor update index %u, update count #%u, has src update descriptor type %s that does not match overlapping dest descriptor type of %s!",
2224 i, j+1, string_VkDescriptorType(pSrcLayout->descriptorTypes[srcStartIndex+j]), string_VkDescriptorType(pDstLayout->descriptorTypes[dstStartIndex+j]));
2225 } else {
2226 // point dst descriptor at corresponding src descriptor
Tobin Ehlisf6585052015-12-17 11:48:42 -07002227 // TODO : This may be a hole. I believe copy should be its own copy,
2228 // otherwise a subsequent write update to src will incorrectly affect the copy
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002229 pDstSet->ppDescriptors[j+dstStartIndex] = pSrcSet->ppDescriptors[j+srcStartIndex];
2230 }
2231 }
2232 }
2233 }
2234 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002235 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002236 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002237}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002238
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002239// Verify that given pool has descriptors that are being requested for allocation
Mark Lobodzinski39298632015-11-18 08:38:27 -07002240static 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 -06002241{
2242 VkBool32 skipCall = VK_FALSE;
2243 uint32_t i = 0, j = 0;
2244 for (i=0; i<count; ++i) {
2245 LAYOUT_NODE* pLayout = getLayoutNode(dev_data, pSetLayouts[i]);
2246 if (NULL == pLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002247 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], __LINE__, DRAWSTATE_INVALID_LAYOUT, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002248 "Unable to find set layout node for layout %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pSetLayouts[i]);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002249 } else {
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002250 uint32_t typeIndex = 0, poolSizeCount = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002251 for (j=0; j<pLayout->createInfo.bindingCount; ++j) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002252 typeIndex = static_cast<uint32_t>(pLayout->createInfo.pBindings[j].descriptorType);
2253 poolSizeCount = pLayout->createInfo.pBindings[j].descriptorCount;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002254 if (poolSizeCount > pPoolNode->availableDescriptorTypeCount[typeIndex]) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002255 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, __LINE__, DRAWSTATE_DESCRIPTOR_POOL_EMPTY, "DS",
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002256 "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 -07002257 poolSizeCount, string_VkDescriptorType(pLayout->createInfo.pBindings[j].descriptorType), (uint64_t) pPoolNode->pool, pPoolNode->availableDescriptorTypeCount[typeIndex]);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002258 } else { // Decrement available descriptors of this type
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002259 pPoolNode->availableDescriptorTypeCount[typeIndex] -= poolSizeCount;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002260 }
2261 }
2262 }
2263 }
2264 return skipCall;
2265}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002266
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002267// Free the shadowed update node for this Set
2268// NOTE : Calls to this function should be wrapped in mutex
2269static void freeShadowUpdateTree(SET_NODE* pSet)
2270{
2271 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
2272 pSet->pUpdateStructs = NULL;
2273 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
2274 // Clear the descriptor mappings as they will now be invalid
2275 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
2276 while(pShadowUpdate) {
2277 pFreeUpdate = pShadowUpdate;
2278 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
2279 uint32_t index = 0;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002280 VkWriteDescriptorSet * pWDS = NULL;
2281 VkCopyDescriptorSet * pCDS = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002282 void** ppToFree = NULL;
2283 switch (pFreeUpdate->sType)
2284 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002285 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
2286 pWDS = (VkWriteDescriptorSet*)pFreeUpdate;
Tony Barbourb1947942015-11-02 11:46:29 -07002287 switch (pWDS->descriptorType) {
2288 case VK_DESCRIPTOR_TYPE_SAMPLER:
2289 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
2290 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2291 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
2292 {
2293 delete[] pWDS->pImageInfo;
2294 }
2295 break;
2296 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2297 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
2298 {
2299 delete[] pWDS->pTexelBufferView;
2300 }
2301 break;
2302 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2303 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2304 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2305 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
2306 {
2307 delete[] pWDS->pBufferInfo;
2308 }
2309 break;
2310 default:
2311 break;
Courtney Goeltzenleuchteraa132e72015-10-22 15:31:56 -06002312 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002313 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002314 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002315 break;
2316 default:
2317 assert(0);
2318 break;
2319 }
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002320 delete pFreeUpdate;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002321 }
2322}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002323
Tobin Ehlis793ad302015-04-03 12:01:11 -06002324// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002325// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002326static void deletePools(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002327{
Mark Lobodzinski39298632015-11-18 08:38:27 -07002328 if (my_data->descriptorPoolMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06002329 return;
Mark Lobodzinski39298632015-11-18 08:38:27 -07002330 for (auto ii=my_data->descriptorPoolMap.begin(); ii!=my_data->descriptorPoolMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002331 SET_NODE* pSet = (*ii).second->pSets;
2332 SET_NODE* pFreeSet = pSet;
2333 while (pSet) {
2334 pFreeSet = pSet;
2335 pSet = pSet->pNext;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002336 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002337 // Free Update shadow struct tree
2338 freeShadowUpdateTree(pFreeSet);
2339 if (pFreeSet->ppDescriptors) {
Chris Forbes02038792015-06-04 10:49:27 +12002340 delete[] pFreeSet->ppDescriptors;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002341 }
2342 delete pFreeSet;
2343 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002344 delete (*ii).second;
2345 }
Mark Lobodzinski39298632015-11-18 08:38:27 -07002346 my_data->descriptorPoolMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002347}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002348
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002349// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002350// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002351static void deleteLayouts(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002352{
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07002353 if (my_data->descriptorSetLayoutMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06002354 return;
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07002355 for (auto ii=my_data->descriptorSetLayoutMap.begin(); ii!=my_data->descriptorSetLayoutMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002356 LAYOUT_NODE* pLayout = (*ii).second;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002357 if (pLayout->createInfo.pBindings) {
Chia-I Wud50a7d72015-10-26 20:48:51 +08002358 for (uint32_t i=0; i<pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002359 if (pLayout->createInfo.pBindings[i].pImmutableSamplers)
2360 delete[] pLayout->createInfo.pBindings[i].pImmutableSamplers;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002361 }
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002362 delete[] pLayout->createInfo.pBindings;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002363 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002364 delete pLayout;
2365 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07002366 my_data->descriptorSetLayoutMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002367}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002368
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002369// Currently clearing a set is removing all previous updates to that set
2370// TODO : Validate if this is correct clearing behavior
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002371static void clearDescriptorSet(layer_data* my_data, VkDescriptorSet set)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002372{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002373 SET_NODE* pSet = getSetNode(my_data, set);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002374 if (!pSet) {
2375 // TODO : Return error
Tobin Ehlisce132d82015-06-19 15:07:05 -06002376 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002377 loader_platform_thread_lock_mutex(&globalLock);
2378 freeShadowUpdateTree(pSet);
2379 loader_platform_thread_unlock_mutex(&globalLock);
2380 }
2381}
2382
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002383static void clearDescriptorPool(layer_data* my_data, const VkDevice device, const VkDescriptorPool pool, VkDescriptorPoolResetFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002384{
Mark Lobodzinski39298632015-11-18 08:38:27 -07002385 DESCRIPTOR_POOL_NODE* pPool = getPoolNode(my_data, pool);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002386 if (!pPool) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002387 log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, (uint64_t) pool, __LINE__, DRAWSTATE_INVALID_POOL, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002388 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkResetDescriptorPool() call", (uint64_t) pool);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002389 } else {
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002390 // TODO: validate flags
Tobin Ehlis793ad302015-04-03 12:01:11 -06002391 // For every set off of this pool, clear it
2392 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002393 while (pSet) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002394 clearDescriptorSet(my_data, pSet->set);
Mark Lobodzinskidcce0792016-01-04 09:40:19 -07002395 pSet = pSet->pNext;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002396 }
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002397 // Reset available count to max count for this pool
2398 for (uint32_t i=0; i<pPool->availableDescriptorTypeCount.size(); ++i) {
2399 pPool->availableDescriptorTypeCount[i] = pPool->maxDescriptorTypeCount[i];
2400 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002401 }
2402}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002403
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002404// For given CB object, fetch associated CB Node from map
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002405static GLOBAL_CB_NODE* getCBNode(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002406{
2407 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002408 if (my_data->commandBufferMap.count(cb) == 0) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002409 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002410 // TODO : How to pass cb as srcObj here?
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002411 log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002412 "Attempt to use CommandBuffer %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<uint64_t>(cb));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002413 return NULL;
2414 }
2415 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002416 return my_data->commandBufferMap[cb];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002417}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002418
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002419// Free all CB Nodes
2420// NOTE : Calls to this function should be wrapped in mutex
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002421static void deleteCommandBuffers(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002422{
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002423 if (my_data->commandBufferMap.size() <= 0) {
David Pinedod8f83d82015-04-27 16:36:17 -06002424 return;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002425 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002426 for (auto ii=my_data->commandBufferMap.begin(); ii!=my_data->commandBufferMap.end(); ++ii) {
Courtney Goeltzenleuchterea3117c2015-04-27 15:04:43 -06002427 vector<CMD_NODE*> cmd_node_list = (*ii).second->pCmds;
2428 while (!cmd_node_list.empty()) {
2429 CMD_NODE* cmd_node = cmd_node_list.back();
2430 delete cmd_node;
2431 cmd_node_list.pop_back();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002432 }
2433 delete (*ii).second;
2434 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002435 my_data->commandBufferMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002436}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002437
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002438static 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 -06002439{
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002440 return log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002441 (uint64_t)cb, __LINE__, DRAWSTATE_NO_BEGIN_COMMAND_BUFFER, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002442 "You must call vkBeginCommandBuffer() before this call to %s", caller_name);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002443}
Michael Lentine3dea6512015-10-28 15:55:18 -07002444
Mark Youngb20a6a82016-01-07 15:41:43 -07002445VkBool32 validateCmdsInCmdBuffer(const layer_data* dev_data, const GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd_type) {
2446 if (!pCB->activeRenderPass) return VK_FALSE;
2447 VkBool32 skip_call = VK_FALSE;
Michael Lentine2e068b22015-12-29 16:05:27 -06002448 if (pCB->activeSubpassContents == VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS && cmd_type != CMD_EXECUTECOMMANDS) {
2449 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
2450 DRAWSTATE_INVALID_COMMAND_BUFFER, "DS", "Commands cannot be called in a subpass using secondary command buffers.");
2451 } else if (pCB->activeSubpassContents == VK_SUBPASS_CONTENTS_INLINE && cmd_type == CMD_EXECUTECOMMANDS) {
2452 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
2453 DRAWSTATE_INVALID_COMMAND_BUFFER, "DS", "vkCmdExecuteCommands() cannot be called in a subpass using inline commands.");
2454 }
Michael Lentine3dea6512015-10-28 15:55:18 -07002455 return skip_call;
2456}
2457
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002458// Add specified CMD to the CmdBuffer in given pCB, flagging errors if CB is not
2459// in the recording state or if there's an issue with the Cmd ordering
2460static 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 -06002461{
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002462 VkBool32 skipCall = VK_FALSE;
2463 if (pCB->state != CB_RECORDING) {
2464 skipCall |= report_error_no_cb_begin(my_data, pCB->commandBuffer, caller_name);
2465 skipCall |= validateCmdsInCmdBuffer(my_data, pCB, cmd);
2466 CMD_NODE* pCmd = new CMD_NODE;
2467 if (pCmd) {
2468 // init cmd node and append to end of cmd LL
2469 memset(pCmd, 0, sizeof(CMD_NODE));
2470 pCmd->cmdNumber = ++pCB->numCmds;
2471 pCmd->type = cmd;
2472 pCB->pCmds.push_back(pCmd);
2473 } else {
2474 // TODO : How to pass cb as srcObj here?
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002475 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_OUT_OF_MEMORY, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002476 "Out of memory while attempting to allocate new CMD_NODE for commandBuffer %#" PRIxLEAST64, reinterpret_cast<uint64_t>(pCB->commandBuffer));
2477 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002478 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002479 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002480}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002481
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002482static void resetCB(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002483{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002484 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002485 if (pCB) {
Courtney Goeltzenleuchter3597a202015-04-27 17:16:56 -06002486 vector<CMD_NODE*> cmd_list = pCB->pCmds;
2487 while (!cmd_list.empty()) {
2488 delete cmd_list.back();
2489 cmd_list.pop_back();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002490 }
Courtney Goeltzenleuchter3597a202015-04-27 17:16:56 -06002491 pCB->pCmds.clear();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06002492 // Reset CB state (need to save createInfo)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002493 VkCommandBufferAllocateInfo saveCBCI = pCB->createInfo;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002494 pCB->commandBuffer = cb;
Tobin Ehlis59278bf2015-08-18 07:10:58 -06002495 pCB->createInfo = saveCBCI;
Michael Lentineabc5e922015-10-12 11:30:14 -05002496 memset(&pCB->beginInfo, 0, sizeof(VkCommandBufferBeginInfo));
2497 pCB->fence = 0;
2498 pCB->numCmds = 0;
2499 memset(pCB->drawCount, 0, NUM_DRAW_TYPES * sizeof(uint64_t));
2500 pCB->state = CB_NEW;
2501 pCB->submitCount = 0;
2502 pCB->status = 0;
2503 pCB->pCmds.clear();
2504 pCB->lastBoundPipeline = 0;
2505 pCB->viewports.clear();
2506 pCB->scissors.clear();
2507 pCB->lineWidth = 0;
2508 pCB->depthBiasConstantFactor = 0;
2509 pCB->depthBiasClamp = 0;
2510 pCB->depthBiasSlopeFactor = 0;
2511 memset(pCB->blendConstants, 0, 4 * sizeof(float));
2512 pCB->minDepthBounds = 0;
2513 pCB->maxDepthBounds = 0;
2514 memset(&pCB->front, 0, sizeof(stencil_data));
2515 memset(&pCB->back, 0, sizeof(stencil_data));
2516 pCB->lastBoundDescriptorSet = 0;
2517 pCB->lastBoundPipelineLayout = 0;
2518 pCB->activeRenderPass = 0;
2519 pCB->activeSubpass = 0;
2520 pCB->framebuffer = 0;
Michael Lentineabc5e922015-10-12 11:30:14 -05002521 pCB->boundDescriptorSets.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07002522 pCB->drawData.clear();
2523 pCB->currentDrawData.buffers.clear();
Michael Lentineabc5e922015-10-12 11:30:14 -05002524 pCB->imageLayoutMap.clear();
Michael Lentineb887b0a2015-12-29 14:12:11 -06002525 pCB->waitedEvents.clear();
2526 pCB->waitedEventsBeforeQueryReset.clear();
2527 pCB->queryToStateMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002528 }
2529}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002530
Tobin Ehlis963a4042015-09-29 08:18:34 -06002531// Set PSO-related status bits for CB, including dynamic state set via PSO
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002532static void set_cb_pso_status(GLOBAL_CB_NODE* pCB, const PIPELINE_NODE* pPipe)
2533{
2534 for (uint32_t i = 0; i < pPipe->cbStateCI.attachmentCount; i++) {
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002535 if (0 != pPipe->pAttachments[i].colorWriteMask) {
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002536 pCB->status |= CBSTATUS_COLOR_BLEND_WRITE_ENABLE;
2537 }
2538 }
2539 if (pPipe->dsStateCI.depthWriteEnable) {
Cody Northrop82485a82015-08-18 15:21:16 -06002540 pCB->status |= CBSTATUS_DEPTH_WRITE_ENABLE;
2541 }
Cody Northrop82485a82015-08-18 15:21:16 -06002542 if (pPipe->dsStateCI.stencilTestEnable) {
2543 pCB->status |= CBSTATUS_STENCIL_TEST_ENABLE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002544 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06002545 // Account for any dynamic state not set via this PSO
2546 if (!pPipe->dynStateCI.dynamicStateCount) { // All state is static
2547 pCB->status = CBSTATUS_ALL;
2548 } else {
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002549 // First consider all state on
2550 // Then unset any state that's noted as dynamic in PSO
2551 // Finally OR that into CB statemask
2552 CBStatusFlags psoDynStateMask = CBSTATUS_ALL;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002553 for (uint32_t i=0; i < pPipe->dynStateCI.dynamicStateCount; i++) {
2554 switch (pPipe->dynStateCI.pDynamicStates[i]) {
2555 case VK_DYNAMIC_STATE_VIEWPORT:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002556 psoDynStateMask &= ~CBSTATUS_VIEWPORT_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002557 break;
2558 case VK_DYNAMIC_STATE_SCISSOR:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002559 psoDynStateMask &= ~CBSTATUS_SCISSOR_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002560 break;
2561 case VK_DYNAMIC_STATE_LINE_WIDTH:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002562 psoDynStateMask &= ~CBSTATUS_LINE_WIDTH_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002563 break;
2564 case VK_DYNAMIC_STATE_DEPTH_BIAS:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002565 psoDynStateMask &= ~CBSTATUS_DEPTH_BIAS_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002566 break;
2567 case VK_DYNAMIC_STATE_BLEND_CONSTANTS:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002568 psoDynStateMask &= ~CBSTATUS_BLEND_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002569 break;
2570 case VK_DYNAMIC_STATE_DEPTH_BOUNDS:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002571 psoDynStateMask &= ~CBSTATUS_DEPTH_BOUNDS_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002572 break;
2573 case VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002574 psoDynStateMask &= ~CBSTATUS_STENCIL_READ_MASK_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002575 break;
2576 case VK_DYNAMIC_STATE_STENCIL_WRITE_MASK:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002577 psoDynStateMask &= ~CBSTATUS_STENCIL_WRITE_MASK_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002578 break;
2579 case VK_DYNAMIC_STATE_STENCIL_REFERENCE:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002580 psoDynStateMask &= ~CBSTATUS_STENCIL_REFERENCE_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002581 break;
2582 default:
2583 // TODO : Flag error here
2584 break;
2585 }
2586 }
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002587 pCB->status |= psoDynStateMask;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002588 }
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002589}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002590
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002591// Print the last bound Gfx Pipeline
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002592static VkBool32 printPipeline(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002593{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002594 VkBool32 skipCall = VK_FALSE;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002595 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002596 if (pCB) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002597 PIPELINE_NODE *pPipeTrav = getPipeline(my_data, pCB->lastBoundPipeline);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002598 if (!pPipeTrav) {
2599 // nothing to print
Tobin Ehlisce132d82015-06-19 15:07:05 -06002600 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002601 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
Michael Lentine010f4692015-11-03 16:19:46 -08002602 "%s", vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002603 }
2604 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002605 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002606}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002607
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002608// Print details of DS config to stdout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002609static VkBool32 printDSConfig(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002610{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002611 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002612 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 -06002613 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis93f89e82015-06-09 08:39:32 -06002614 if (pCB && pCB->lastBoundDescriptorSet) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002615 SET_NODE* pSet = getSetNode(my_data, pCB->lastBoundDescriptorSet);
Mark Lobodzinski39298632015-11-18 08:38:27 -07002616 DESCRIPTOR_POOL_NODE* pPool = getPoolNode(my_data, pSet->pool);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002617 // Print out pool details
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002618 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002619 "Details for pool %#" PRIxLEAST64 ".", (uint64_t) pPool->pool);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002620 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002621 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002622 "%s", poolStr.c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002623 // Print out set details
2624 char prefix[10];
2625 uint32_t index = 0;
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002626 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002627 "Details for descriptor set %#" PRIxLEAST64 ".", (uint64_t) pSet->set);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002628 LAYOUT_NODE* pLayout = pSet->pLayout;
2629 // Print layout details
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002630 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
Michael Lentine010f4692015-11-03 16:19:46 -08002631 "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 -06002632 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002633 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002634 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002635 "%s", DSLstr.c_str());
Tobin Ehlis793ad302015-04-03 12:01:11 -06002636 index++;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002637 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
2638 if (pUpdate) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002639 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002640 "Update Chain [UC] for descriptor set %#" PRIxLEAST64 ":", (uint64_t) pSet->set);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002641 sprintf(prefix, " [UC] ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002642 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
Michael Lentine010f4692015-11-03 16:19:46 -08002643 "%s", dynamic_display(pUpdate, prefix).c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002644 // TODO : If there is a "view" associated with this update, print CI for that view
Tobin Ehlisce132d82015-06-19 15:07:05 -06002645 } else {
Tobin Ehlisbf081f32015-06-15 08:41:17 -06002646 if (0 != pSet->descriptorCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002647 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002648 "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 -06002649 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002650 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002651 "FYI: No descriptors in descriptor set %#" PRIxLEAST64 ".", (uint64_t) pSet->set);
Tobin Ehlisbf081f32015-06-15 08:41:17 -06002652 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002653 }
2654 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002655 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002656}
2657
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002658static void printCB(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002659{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002660 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
David Pinedod8f83d82015-04-27 16:36:17 -06002661 if (pCB && pCB->pCmds.size() > 0) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002662 log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002663 "Cmds in CB %p", (void*)cb);
Courtney Goeltzenleuchterba348a92015-04-27 11:16:35 -06002664 vector<CMD_NODE*> pCmds = pCB->pCmds;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002665 for (auto ii=pCmds.begin(); ii!=pCmds.end(); ++ii) {
2666 // TODO : Need to pass cb as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002667 log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_NONE, "DS",
Michael Lentine010f4692015-11-03 16:19:46 -08002668 " CMD#%" PRIu64 ": %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002669 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002670 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002671 // Nothing to print
2672 }
2673}
2674
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002675static VkBool32 synchAndPrintDSConfig(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002676{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002677 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002678 if (!(my_data->report_data->active_flags & VK_DEBUG_REPORT_INFO_BIT_EXT)) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002679 return skipCall;
Mike Stroyanba35e352015-08-12 17:11:28 -06002680 }
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002681 skipCall |= printDSConfig(my_data, cb);
2682 skipCall |= printPipeline(my_data, cb);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002683 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002684}
2685
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002686// Flags validation error if the associated call is made inside a render pass. The apiName
2687// routine should ONLY be called outside a render pass.
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06002688static VkBool32 insideRenderPass(const layer_data* my_data, GLOBAL_CB_NODE *pCB, const char *apiName)
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002689{
2690 VkBool32 inside = VK_FALSE;
2691 if (pCB->activeRenderPass) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002692 inside = log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002693 (uint64_t)pCB->commandBuffer, __LINE__, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002694 "%s: It is invalid to issue this call inside an active render pass (%#" PRIxLEAST64 ")",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002695 apiName, (uint64_t) pCB->activeRenderPass);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002696 }
2697 return inside;
2698}
2699
2700// Flags validation error if the associated call is made outside a render pass. The apiName
2701// routine should ONLY be called inside a render pass.
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06002702static VkBool32 outsideRenderPass(const layer_data* my_data, GLOBAL_CB_NODE *pCB, const char *apiName)
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002703{
2704 VkBool32 outside = VK_FALSE;
Mark Lobodzinski74635932015-12-18 15:35:38 -07002705 if (((pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) &&
2706 (!pCB->activeRenderPass)) ||
2707 ((pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) &&
2708 (!pCB->activeRenderPass) &&
2709 !(pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT))) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002710 outside = log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002711 (uint64_t)pCB->commandBuffer, __LINE__, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002712 "%s: This call must be issued inside an active render pass.", apiName);
2713 }
2714 return outside;
2715}
2716
Courtney Goeltzenleuchter6d8e8182015-11-25 14:31:49 -07002717static void init_draw_state(layer_data *my_data, const VkAllocationCallbacks *pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002718{
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002719 uint32_t report_flags = 0;
2720 uint32_t debug_action = 0;
2721 FILE *log_output = NULL;
2722 const char *option_str;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002723 VkDebugReportCallbackEXT callback;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002724 // initialize DrawState options
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002725 report_flags = getLayerOptionFlags("DrawStateReportFlags", 0);
2726 getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &debug_action);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002727
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002728 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002729 {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002730 option_str = getLayerOption("DrawStateLogFilename");
Tobin Ehlisb1df55e2015-09-15 09:55:54 -06002731 log_output = getLayerLogOutput(option_str, "DrawState");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002732 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002733 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002734 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002735 dbgInfo.pfnCallback = log_callback;
2736 dbgInfo.pUserData = log_output;
2737 dbgInfo.flags = report_flags;
2738 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002739 my_data->logging_callback.push_back(callback);
2740 }
2741
2742 if (debug_action & VK_DBG_LAYER_ACTION_DEBUG_OUTPUT) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002743 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002744 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002745 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002746 dbgInfo.pfnCallback = win32_debug_output_msg;
2747 dbgInfo.pUserData = log_output;
2748 dbgInfo.flags = report_flags;
2749 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002750 my_data->logging_callback.push_back(callback);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002751 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002752
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002753 if (!globalLockInitialized)
2754 {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002755 loader_platform_thread_create_mutex(&globalLock);
2756 globalLockInitialized = 1;
2757 }
2758}
2759
Chia-I Wu9ab61502015-11-06 06:42:02 +08002760VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance)
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002761{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002762 // TODOSC : Shouldn't need any customization here
Tobin Ehlis0b632332015-10-07 09:38:40 -06002763 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
2764 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002765 VkResult result = pTable->CreateInstance(pCreateInfo, pAllocator, pInstance);
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002766
2767 if (result == VK_SUCCESS) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002768 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
2769 my_data->report_data = debug_report_create_instance(
2770 pTable,
2771 *pInstance,
Jon Ashburnf19916e2016-01-11 13:12:43 -07002772 pCreateInfo->enabledExtensionCount,
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002773 pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchterd02a9642015-06-08 14:58:39 -06002774
Courtney Goeltzenleuchter6d8e8182015-11-25 14:31:49 -07002775 init_draw_state(my_data, pAllocator);
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002776 }
2777 return result;
2778}
2779
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002780/* hook DestroyInstance to remove tableInstanceMap entry */
Chia-I Wu9ab61502015-11-06 06:42:02 +08002781VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator)
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002782{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002783 // TODOSC : Shouldn't need any customization here
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002784 dispatch_key key = get_dispatch_key(instance);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002785 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
2786 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002787 pTable->DestroyInstance(instance, pAllocator);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002788
2789 // Clean up logging callback, if any
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002790 while (my_data->logging_callback.size() > 0) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002791 VkDebugReportCallbackEXT callback = my_data->logging_callback.back();
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002792 layer_destroy_msg_callback(my_data->report_data, callback, pAllocator);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002793 my_data->logging_callback.pop_back();
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002794 }
2795
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06002796 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002797 delete my_data->instance_dispatch_table;
2798 layer_data_map.erase(key);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002799 // TODO : Potential race here with separate threads creating/destroying instance
Tobin Ehlis0b632332015-10-07 09:38:40 -06002800 if (layer_data_map.empty()) {
Mike Stroyanfcb4ba62015-08-18 15:56:18 -06002801 // Release mutex when destroying last instance.
2802 loader_platform_thread_delete_mutex(&globalLock);
2803 globalLockInitialized = 0;
2804 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002805}
2806
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002807static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
2808{
Tony Barbour3b4732f2015-07-13 13:37:24 -06002809 uint32_t i;
Tobin Ehlis0b632332015-10-07 09:38:40 -06002810 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
2811 dev_data->device_extensions.debug_marker_enabled = false;
Michael Lentineabc5e922015-10-12 11:30:14 -05002812 dev_data->device_extensions.wsi_enabled = false;
2813
2814
2815 VkLayerDispatchTable *pDisp = dev_data->device_dispatch_table;
2816 PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr;
2817
Michael Lentineabc5e922015-10-12 11:30:14 -05002818 pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR) gpa(device, "vkCreateSwapchainKHR");
2819 pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR) gpa(device, "vkDestroySwapchainKHR");
2820 pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR) gpa(device, "vkGetSwapchainImagesKHR");
2821 pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR) gpa(device, "vkAcquireNextImageKHR");
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07002822 pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR) gpa(device, "vkQueuePresentKHR");
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002823
Jon Ashburnf19916e2016-01-11 13:12:43 -07002824 for (i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
Ian Elliott05846062015-11-20 14:13:17 -07002825 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) {
Michael Lentineabc5e922015-10-12 11:30:14 -05002826 dev_data->device_extensions.wsi_enabled = true;
2827 }
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002828 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
Jon Ashburneab34492015-06-01 09:37:38 -06002829 /* Found a matching extension name, mark it enabled and init dispatch table*/
Tobin Ehlis0b632332015-10-07 09:38:40 -06002830 dev_data->device_extensions.debug_marker_enabled = true;
Jon Ashburn1d4b1282015-12-10 19:12:21 -07002831 initDebugMarkerTable(device);
2832
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002833 }
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002834 }
2835}
2836
Chia-I Wu9ab61502015-11-06 06:42:02 +08002837VK_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 -06002838{
Tobin Ehlis0b632332015-10-07 09:38:40 -06002839 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08002840 VkResult result = dev_data->device_dispatch_table->CreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002841 // TODOSC : shouldn't need any customization here
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002842 if (result == VK_SUCCESS) {
2843 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002844 dev_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
Jon Ashburn747f2b62015-06-18 15:02:58 -06002845 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002846 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002847 return result;
2848}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002849
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002850// prototype
2851static void deleteRenderPasses(layer_data*);
Chia-I Wu9ab61502015-11-06 06:42:02 +08002852VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002853{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002854 // TODOSC : Shouldn't need any customization here
Jeremy Hayes5d29ce32015-06-19 11:37:38 -06002855 dispatch_key key = get_dispatch_key(device);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002856 layer_data* dev_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002857 // Free all the memory
2858 loader_platform_thread_lock_mutex(&globalLock);
2859 deletePipelines(dev_data);
2860 deleteRenderPasses(dev_data);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002861 deleteCommandBuffers(dev_data);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002862 deletePools(dev_data);
2863 deleteLayouts(dev_data);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002864 dev_data->imageViewMap.clear();
2865 dev_data->imageMap.clear();
2866 dev_data->bufferViewMap.clear();
2867 dev_data->bufferMap.clear();
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002868 loader_platform_thread_unlock_mutex(&globalLock);
2869
Chia-I Wuf7458c52015-10-26 21:10:41 +08002870 dev_data->device_dispatch_table->DestroyDevice(device, pAllocator);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002871 tableDebugMarkerMap.erase(key);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002872 delete dev_data->device_dispatch_table;
2873 layer_data_map.erase(key);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002874}
2875
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07002876static const VkExtensionProperties instance_extensions[] = {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002877 {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002878 VK_EXT_DEBUG_REPORT_EXTENSION_NAME,
2879 VK_EXT_DEBUG_REPORT_REVISION
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002880 }
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06002881};
2882
Chia-I Wu9ab61502015-11-06 06:42:02 +08002883VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002884 const char *pLayerName,
2885 uint32_t *pCount,
2886 VkExtensionProperties* pProperties)
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06002887{
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07002888 return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002889}
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06002890
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07002891static const VkLayerProperties ds_global_layers[] = {
2892 {
Michael Lentine03107b42015-12-11 10:49:51 -08002893 "VK_LAYER_LUNARG_draw_state",
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07002894 VK_API_VERSION,
2895 VK_MAKE_VERSION(0, 1, 0),
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -07002896 "Validation layer: draw_state",
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07002897 }
2898};
2899
Chia-I Wu9ab61502015-11-06 06:42:02 +08002900VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002901 uint32_t *pCount,
2902 VkLayerProperties* pProperties)
2903{
2904 return util_GetLayerProperties(ARRAY_SIZE(ds_global_layers),
2905 ds_global_layers,
2906 pCount, pProperties);
2907}
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06002908
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002909static const VkExtensionProperties ds_device_extensions[] = {
2910 {
2911 DEBUG_MARKER_EXTENSION_NAME,
2912 VK_MAKE_VERSION(0, 1, 0),
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002913 }
2914};
2915
2916static const VkLayerProperties ds_device_layers[] = {
2917 {
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -07002918 "draw_state",
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002919 VK_API_VERSION,
2920 VK_MAKE_VERSION(0, 1, 0),
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -07002921 "Validation layer: draw_state",
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002922 }
2923};
2924
Chia-I Wu9ab61502015-11-06 06:42:02 +08002925VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002926 VkPhysicalDevice physicalDevice,
2927 const char* pLayerName,
2928 uint32_t* pCount,
2929 VkExtensionProperties* pProperties)
2930{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07002931 // DrawState does not have any physical device extensions
Jon Ashburn751c4842015-11-02 17:37:20 -07002932 if (pLayerName == NULL) {
2933 dispatch_key key = get_dispatch_key(physicalDevice);
2934 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07002935 return my_data->instance_dispatch_table->EnumerateDeviceExtensionProperties(
Jon Ashburn751c4842015-11-02 17:37:20 -07002936 physicalDevice,
2937 NULL,
2938 pCount,
2939 pProperties);
2940 } else {
2941 return util_GetExtensionProperties(ARRAY_SIZE(ds_device_extensions),
2942 ds_device_extensions,
2943 pCount, pProperties);
2944 }
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002945}
2946
Chia-I Wu9ab61502015-11-06 06:42:02 +08002947VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002948 VkPhysicalDevice physicalDevice,
2949 uint32_t* pCount,
2950 VkLayerProperties* pProperties)
2951{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07002952 /* DrawState physical device layers are the same as global */
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002953 return util_GetLayerProperties(ARRAY_SIZE(ds_device_layers), ds_device_layers,
2954 pCount, pProperties);
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06002955}
2956
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07002957VkBool32 ValidateCmdBufImageLayouts(VkCommandBuffer cmdBuffer) {
Mark Youngb20a6a82016-01-07 15:41:43 -07002958 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05002959 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
2960 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
2961 for (auto cb_image_data : pCB->imageLayoutMap) {
2962 auto image_data = dev_data->imageLayoutMap.find(cb_image_data.first);
2963 if (image_data == dev_data->imageLayoutMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002964 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentine010f4692015-11-03 16:19:46 -08002965 "Cannot submit cmd buffer using deleted image %" PRIu64 ".", reinterpret_cast<uint64_t>(cb_image_data.first));
Michael Lentineabc5e922015-10-12 11:30:14 -05002966 } else {
2967 if (dev_data->imageLayoutMap[cb_image_data.first]->layout != cb_image_data.second.initialLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002968 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05002969 "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);
2970 }
2971 dev_data->imageLayoutMap[cb_image_data.first]->layout = cb_image_data.second.layout;
2972 }
2973 }
2974 return skip_call;
2975}
2976
Mark Young7a69c302016-01-07 09:48:47 -07002977VkBool32 validateAndIncrementResources(layer_data* my_data, GLOBAL_CB_NODE* pCB) {
Mark Youngb20a6a82016-01-07 15:41:43 -07002978 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07002979 for (auto drawDataElement : pCB->drawData) {
2980 for (auto buffer : drawDataElement.buffers) {
2981 auto buffer_data = my_data->bufferMap.find(buffer);
2982 if (buffer_data == my_data->bufferMap.end()) {
2983 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, 0, DRAWSTATE_INVALID_BUFFER, "DS",
2984 "Cannot submit cmd buffer using deleted buffer %" PRIu64 ".", reinterpret_cast<uint64_t>(buffer));
2985 } else {
2986 buffer_data->second.in_use.fetch_add(1);
2987 }
2988 }
2989 }
Michael Lentine2e068b22015-12-29 16:05:27 -06002990 return skip_call;
Michael Lentine700b0aa2015-10-30 17:57:32 -07002991}
2992
2993void decrementResources(layer_data* my_data, VkCommandBuffer cmdBuffer) {
2994 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cmdBuffer);
2995 for (auto drawDataElement : pCB->drawData) {
2996 for (auto buffer : drawDataElement.buffers) {
2997 auto buffer_data = my_data->bufferMap.find(buffer);
2998 if (buffer_data != my_data->bufferMap.end()) {
2999 buffer_data->second.in_use.fetch_sub(1);
3000 }
3001 }
3002 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003003 for (auto queryStatePair : pCB->queryToStateMap) {
3004 my_data->queryToStateMap[queryStatePair.first] = queryStatePair.second;
3005 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003006}
3007
3008void decrementResources(layer_data* my_data, uint32_t fenceCount, const VkFence* pFences) {
3009 for (uint32_t i = 0; i < fenceCount; ++i) {
3010 auto fence_data = my_data->fenceMap.find(pFences[i]);
3011 if (fence_data == my_data->fenceMap.end() || !fence_data->second.needsSignaled) return;
3012 fence_data->second.needsSignaled = false;
3013 if (fence_data->second.priorFence != VK_NULL_HANDLE) {
3014 decrementResources(my_data, 1, &fence_data->second.priorFence);
3015 }
3016 for (auto cmdBuffer : fence_data->second.cmdBuffers) {
3017 decrementResources(my_data, cmdBuffer);
3018 }
3019 }
3020}
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07003021
Michael Lentine700b0aa2015-10-30 17:57:32 -07003022void decrementResources(layer_data* my_data, VkQueue queue) {
3023 auto queue_data = my_data->queueMap.find(queue);
3024 if (queue_data != my_data->queueMap.end()) {
3025 for (auto cmdBuffer : queue_data->second.untrackedCmdBuffers) {
3026 decrementResources(my_data, cmdBuffer);
3027 }
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07003028 queue_data->second.untrackedCmdBuffers.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07003029 decrementResources(my_data, 1, &queue_data->second.priorFence);
3030 }
3031}
3032
3033void trackCommandBuffers(layer_data* my_data, VkQueue queue, uint32_t cmdBufferCount, const VkCommandBuffer* pCmdBuffers, VkFence fence) {
3034 auto queue_data = my_data->queueMap.find(queue);
3035 if (fence != VK_NULL_HANDLE) {
3036 VkFence priorFence = VK_NULL_HANDLE;
3037 if (queue_data != my_data->queueMap.end()) {
3038 priorFence = queue_data->second.priorFence;
3039 queue_data->second.priorFence = fence;
3040 for (auto cmdBuffer : queue_data->second.untrackedCmdBuffers) {
3041 my_data->fenceMap[fence].cmdBuffers.push_back(cmdBuffer);
3042 }
3043 queue_data->second.untrackedCmdBuffers.clear();
3044 }
3045 my_data->fenceMap[fence].cmdBuffers.clear();
3046 my_data->fenceMap[fence].priorFence = priorFence;
3047 my_data->fenceMap[fence].needsSignaled = true;
3048 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
3049 my_data->fenceMap[fence].cmdBuffers.push_back(pCmdBuffers[i]);
3050 }
3051 } else {
3052 if (queue_data != my_data->queueMap.end()) {
3053 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
3054 queue_data->second.untrackedCmdBuffers.push_back(pCmdBuffers[i]);
3055 }
3056 }
3057 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003058 if (queue_data != my_data->queueMap.end()) {
3059 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
3060 my_data->inFlightCmdBuffers.insert(pCmdBuffers[i]);
3061 }
3062 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003063}
3064
Chia-I Wu9ab61502015-11-06 06:42:02 +08003065VK_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 -06003066{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003067 VkBool32 skipCall = VK_FALSE;
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06003068 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlis0b632332015-10-07 09:38:40 -06003069 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Tobin Ehlis651d9b02015-12-16 05:01:22 -07003070 // TODO : Any pCommandBuffers must have USAGE_SIMULTANEOUS_USE_BIT set or cannot already be executing on device
3071 // Same goes for any secondary CBs under the primary CB
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003072 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08003073 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Michael Lentine15a47882016-01-06 10:05:48 -06003074 for (uint32_t i=0; i < submit->waitSemaphoreCount; ++i) {
3075 if (dev_data->semaphoreSignaledMap[submit->pWaitSemaphores[i]]) {
3076 dev_data->semaphoreSignaledMap[submit->pWaitSemaphores[i]] = 0;
3077 } else {
3078 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_QUEUE_FORWARD_PROGRESS, "DS",
3079 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
3080 reinterpret_cast<uint64_t>(queue), reinterpret_cast<uint64_t>(submit->pWaitSemaphores[i]));
3081 }
3082 }
3083 for (uint32_t i=0; i < submit->signalSemaphoreCount; ++i) {
3084 dev_data->semaphoreSignaledMap[submit->pSignalSemaphores[i]] = 1;
3085 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08003086 for (uint32_t i=0; i < submit->commandBufferCount; i++) {
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07003087
3088#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
3089 skipCall |= ValidateCmdBufImageLayouts(submit->pCommandBuffers[i]);
3090#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
3091
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003092 // Validate that cmd buffers have been updated
3093 pCB = getCBNode(dev_data, submit->pCommandBuffers[i]);
3094 loader_platform_thread_lock_mutex(&globalLock);
3095 pCB->submitCount++; // increment submit count
Michael Lentine700b0aa2015-10-30 17:57:32 -07003096 skipCall |= validateAndIncrementResources(dev_data, pCB);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003097 if ((pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT) && (pCB->submitCount > 1)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003098 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_COMMAND_BUFFER_SINGLE_SUBMIT_VIOLATION, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05003099 "CB %#" PRIxLEAST64 " was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted %#" PRIxLEAST64 " times.",
3100 reinterpret_cast<uint64_t>(pCB->commandBuffer), pCB->submitCount);
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003101 }
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003102 if (CB_RECORDED != pCB->state) {
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003103 // Flag error for using CB w/o vkEndCommandBuffer() called
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003104 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_NO_END_COMMAND_BUFFER, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003105 "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 -06003106 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003107 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003108 }
Tobin Ehlisc4bdde12015-05-27 14:30:06 -06003109 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06003110 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003111 trackCommandBuffers(dev_data, queue, submit->commandBufferCount, submit->pCommandBuffers, fence);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003112 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003113 if (VK_FALSE == skipCall)
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08003114 return dev_data->device_dispatch_table->QueueSubmit(queue, submitCount, pSubmits, fence);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003115 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003116}
3117
Mark Youngb20a6a82016-01-07 15:41:43 -07003118VkBool32 cleanInFlightCmdBuffer(layer_data* my_data, VkCommandBuffer cmdBuffer) {
3119 VkBool32 skip_call = VK_FALSE;
Michael Lentineb887b0a2015-12-29 14:12:11 -06003120 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cmdBuffer);
3121 for (auto queryEventsPair : pCB->waitedEventsBeforeQueryReset) {
3122 for (auto event : queryEventsPair.second) {
3123 if (my_data->eventMap[event].needsSignaled) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003124 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT, 0, 0, DRAWSTATE_INVALID_QUERY, "DS",
3125 "Cannot get query results on queryPool %" PRIu64 " with index %d which was guarded by unsignaled event %" PRIu64 ".",
Michael Lentineb887b0a2015-12-29 14:12:11 -06003126 reinterpret_cast<uint64_t>(queryEventsPair.first.pool), queryEventsPair.first.index, reinterpret_cast<uint64_t>(event));
3127 }
3128 }
3129 }
3130 return skip_call;
3131}
3132
Michael Lentine700b0aa2015-10-30 17:57:32 -07003133VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence* pFences, VkBool32 waitAll, uint64_t timeout)
3134{
3135 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3136 VkResult result = dev_data->device_dispatch_table->WaitForFences(device, fenceCount, pFences, waitAll, timeout);
Mark Youngb20a6a82016-01-07 15:41:43 -07003137 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003138 if ((waitAll || fenceCount == 1) && result == VK_SUCCESS) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06003139 for (uint32_t i = 0; i < fenceCount; ++i) {
3140 for (auto cmdBuffer : dev_data->fenceMap[pFences[i]].cmdBuffers) {
3141 dev_data->inFlightCmdBuffers.erase(cmdBuffer);
3142 skip_call |= cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3143 }
3144 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003145 decrementResources(dev_data, fenceCount, pFences);
3146 }
Mark Youngb20a6a82016-01-07 15:41:43 -07003147 if (VK_FALSE != skip_call)
Mark Lobodzinskice738852016-01-07 10:04:02 -07003148 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003149 return result;
3150}
3151
3152
3153VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetFenceStatus(VkDevice device, VkFence fence)
3154{
3155 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3156 VkResult result = dev_data->device_dispatch_table->GetFenceStatus(device, fence);
3157 if (result == VK_SUCCESS) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06003158 for (auto cmdBuffer : dev_data->fenceMap[fence].cmdBuffers) {
3159 dev_data->inFlightCmdBuffers.erase(cmdBuffer);
3160 cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3161 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003162 decrementResources(dev_data, 1, &fence);
3163 }
3164 return result;
3165}
3166
3167VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue* pQueue)
3168{
3169 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3170 dev_data->device_dispatch_table->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue);
3171 dev_data->deviceMap[device].queues.push_back(*pQueue);
3172 dev_data->queueMap[*pQueue].device = device;
3173}
3174
3175VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueueWaitIdle(VkQueue queue)
3176{
3177 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
3178 decrementResources(dev_data, queue);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003179 for (auto cmdBuffer : dev_data->inFlightCmdBuffers) {
3180 cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3181 }
3182 dev_data->inFlightCmdBuffers.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07003183 return dev_data->device_dispatch_table->QueueWaitIdle(queue);
3184}
3185
3186VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkDeviceWaitIdle(VkDevice device)
3187{
3188 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3189 auto device_data = dev_data->deviceMap.find(device);
3190 if (device_data != dev_data->deviceMap.end()) {
3191 for (auto queue : device_data->second.queues) {
3192 decrementResources(dev_data, queue);
3193 }
3194 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003195 for (auto cmdBuffer : dev_data->inFlightCmdBuffers) {
3196 cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3197 }
3198 dev_data->inFlightCmdBuffers.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07003199 return dev_data->device_dispatch_table->DeviceWaitIdle(device);
3200}
3201
Chia-I Wu9ab61502015-11-06 06:42:02 +08003202VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003203{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003204 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 -06003205 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003206}
3207
Chia-I Wu9ab61502015-11-06 06:42:02 +08003208VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySemaphore(VkDevice device, VkSemaphore semaphore, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003209{
Michael Lentine15a47882016-01-06 10:05:48 -06003210 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3211 dev_data->device_dispatch_table->DestroySemaphore(device, semaphore, pAllocator);
3212 dev_data->semaphoreSignaledMap.erase(semaphore);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003213 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003214}
3215
Chia-I Wu9ab61502015-11-06 06:42:02 +08003216VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003217{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003218 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 -06003219 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003220}
3221
Chia-I Wu9ab61502015-11-06 06:42:02 +08003222VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003223{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003224 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 -06003225 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003226}
3227
Mark Lobodzinskice738852016-01-07 10:04:02 -07003228VKAPI_ATTR VkResult VKAPI_CALL vkGetQueryPoolResults(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount,
Michael Lentineb887b0a2015-12-29 14:12:11 -06003229 size_t dataSize, void* pData, VkDeviceSize stride, VkQueryResultFlags flags) {
3230 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3231 unordered_map<QueryObject, vector<VkCommandBuffer>> queriesInFlight;
3232 GLOBAL_CB_NODE* pCB = nullptr;
3233 for (auto cmdBuffer : dev_data->inFlightCmdBuffers) {
3234 pCB = getCBNode(dev_data, cmdBuffer);
3235 for (auto queryStatePair : pCB->queryToStateMap) {
3236 queriesInFlight[queryStatePair.first].push_back(cmdBuffer);
3237 }
3238 }
Mark Youngb20a6a82016-01-07 15:41:43 -07003239 VkBool32 skip_call = VK_FALSE;
Michael Lentineb887b0a2015-12-29 14:12:11 -06003240 for (uint32_t i = 0; i < queryCount; ++i) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003241 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06003242 auto queryElement = queriesInFlight.find(query);
3243 auto queryToStateElement = dev_data->queryToStateMap.find(query);
3244 if (queryToStateElement != dev_data->queryToStateMap.end()) {
3245 }
3246 // Available and in flight
3247 if(queryElement != queriesInFlight.end() && queryToStateElement != dev_data->queryToStateMap.end() && queryToStateElement->second) {
3248 for (auto cmdBuffer : queryElement->second) {
3249 pCB = getCBNode(dev_data, cmdBuffer);
3250 auto queryEventElement = pCB->waitedEventsBeforeQueryReset.find(query);
3251 if (queryEventElement == pCB->waitedEventsBeforeQueryReset.end()) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003252 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT, 0, __LINE__,
3253 DRAWSTATE_INVALID_QUERY, "DS", "Cannot get query results on queryPool %" PRIu64 " with index %d which is in flight.",
3254 reinterpret_cast<uint64_t>(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003255 } else {
3256 for (auto event : queryEventElement->second) {
3257 dev_data->eventMap[event].needsSignaled = true;
3258 }
3259 }
3260 }
3261 // Unavailable and in flight
3262 } else if (queryElement != queriesInFlight.end() && queryToStateElement != dev_data->queryToStateMap.end() && !queryToStateElement->second) {
3263 // TODO : Can there be the same query in use by multiple command buffers in flight?
3264 bool make_available = false;
3265 for (auto cmdBuffer : queryElement->second) {
3266 pCB = getCBNode(dev_data, cmdBuffer);
3267 make_available |= pCB->queryToStateMap[query];
3268 }
3269 if (!(((flags & VK_QUERY_RESULT_PARTIAL_BIT) || (flags & VK_QUERY_RESULT_WAIT_BIT)) && make_available)) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003270 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT, 0, __LINE__, DRAWSTATE_INVALID_QUERY, "DS",
Michael Lentineb887b0a2015-12-29 14:12:11 -06003271 "Cannot get query results on queryPool %" PRIu64 " with index %d which is unavailable.",
Mark Lobodzinskice738852016-01-07 10:04:02 -07003272 reinterpret_cast<uint64_t>(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003273 }
3274 // Unavailable
3275 } else if (queryToStateElement != dev_data->queryToStateMap.end() && !queryToStateElement->second) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003276 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT, 0, __LINE__, DRAWSTATE_INVALID_QUERY, "DS",
Michael Lentineb887b0a2015-12-29 14:12:11 -06003277 "Cannot get query results on queryPool %" PRIu64 " with index %d which is unavailable.",
Mark Lobodzinskice738852016-01-07 10:04:02 -07003278 reinterpret_cast<uint64_t>(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003279 // Unitialized
3280 } else if (queryToStateElement == dev_data->queryToStateMap.end()) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003281 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT, 0, __LINE__, DRAWSTATE_INVALID_QUERY, "DS",
Michael Lentineb887b0a2015-12-29 14:12:11 -06003282 "Cannot get query results on queryPool %" PRIu64 " with index %d which is uninitialized.",
Mark Lobodzinskice738852016-01-07 10:04:02 -07003283 reinterpret_cast<uint64_t>(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003284 }
3285 }
3286 if (skip_call)
Mark Lobodzinskice738852016-01-07 10:04:02 -07003287 return VK_ERROR_VALIDATION_FAILED_EXT;
3288 return dev_data->device_dispatch_table->GetQueryPoolResults(device, queryPool, firstQuery, queryCount, dataSize, pData, stride, flags);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003289}
3290
Mark Young7a69c302016-01-07 09:48:47 -07003291VkBool32 validateIdleBuffer(const layer_data* my_data, VkBuffer buffer) {
Mark Youngb20a6a82016-01-07 15:41:43 -07003292 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003293 auto buffer_data = my_data->bufferMap.find(buffer);
3294 if (buffer_data == my_data->bufferMap.end()) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06003295 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_DOUBLE_DESTROY, "DS",
Michael Lentine700b0aa2015-10-30 17:57:32 -07003296 "Cannot free buffer %" PRIxLEAST64 " that has not been allocated.", reinterpret_cast<uint64_t>(buffer));
3297 } else {
3298 if (buffer_data->second.in_use.load()) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06003299 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_OBJECT_INUSE, "DS",
Michael Lentine700b0aa2015-10-30 17:57:32 -07003300 "Cannot free buffer %" PRIxLEAST64 " that is in use by a command buffer.", reinterpret_cast<uint64_t>(buffer));
3301
3302 }
3303 }
3304 return skip_call;
3305}
3306
Chia-I Wu9ab61502015-11-06 06:42:02 +08003307VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003308{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003309 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07003310 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003311 if (!validateIdleBuffer(dev_data, buffer)) {
3312 dev_data->device_dispatch_table->DestroyBuffer(device, buffer, pAllocator);
3313 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08003314 dev_data->bufferMap.erase(buffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003315}
3316
Chia-I Wu9ab61502015-11-06 06:42:02 +08003317VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBufferView(VkDevice device, VkBufferView bufferView, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003318{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003319 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003320 dev_data->device_dispatch_table->DestroyBufferView(device, bufferView, pAllocator);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003321 dev_data->bufferViewMap.erase(bufferView);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003322}
3323
Chia-I Wu9ab61502015-11-06 06:42:02 +08003324VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003325{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003326 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003327 dev_data->device_dispatch_table->DestroyImage(device, image, pAllocator);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003328 dev_data->imageMap.erase(image);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003329}
3330
Chia-I Wu9ab61502015-11-06 06:42:02 +08003331VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyImageView(VkDevice device, VkImageView imageView, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003332{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003333 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 -06003334 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003335}
3336
Chia-I Wu9ab61502015-11-06 06:42:02 +08003337VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003338{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003339 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 -06003340 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003341}
3342
Chia-I Wu9ab61502015-11-06 06:42:02 +08003343VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyPipeline(VkDevice device, VkPipeline pipeline, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003344{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003345 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 -06003346 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003347}
3348
Chia-I Wu9ab61502015-11-06 06:42:02 +08003349VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003350{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003351 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 -06003352 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003353}
3354
Chia-I Wu9ab61502015-11-06 06:42:02 +08003355VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySampler(VkDevice device, VkSampler sampler, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003356{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003357 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 -06003358 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003359}
3360
Chia-I Wu9ab61502015-11-06 06:42:02 +08003361VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003362{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003363 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 -06003364 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003365}
3366
Chia-I Wu9ab61502015-11-06 06:42:02 +08003367VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003368{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003369 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 -06003370 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003371}
3372
Chia-I Wu9ab61502015-11-06 06:42:02 +08003373VK_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 -06003374{
Mark Lobodzinski39298632015-11-18 08:38:27 -07003375 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3376
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07003377 for (uint32_t i = 0; i < count; i++) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003378 // Delete CB information structure, and remove from commandBufferMap
3379 auto cb = dev_data->commandBufferMap.find(pCommandBuffers[i]);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003380 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003381 if (cb != dev_data->commandBufferMap.end()) {
3382 delete (*cb).second;
3383 dev_data->commandBufferMap.erase(cb);
3384 }
3385
3386 // Remove commandBuffer reference from commandPoolMap
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003387 dev_data->commandPoolMap[commandPool].commandBuffers.remove(pCommandBuffers[i]);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003388 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003389 }
3390
3391 dev_data->device_dispatch_table->FreeCommandBuffers(device, commandPool, count, pCommandBuffers);
3392}
3393
3394VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkCommandPool* pCommandPool)
3395{
3396 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3397
3398 VkResult result = dev_data->device_dispatch_table->CreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
3399
3400 if (VK_SUCCESS == result) {
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003401 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003402 dev_data->commandPoolMap[*pCommandPool].createFlags = pCreateInfo->flags;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003403 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003404 }
3405 return result;
3406}
3407
3408VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks* pAllocator)
3409{
3410 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003411 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003412
3413 // Must remove cmdpool from cmdpoolmap, after removing all cmdbuffers in its list from the commandPoolMap
3414 if (dev_data->commandPoolMap.find(commandPool) != dev_data->commandPoolMap.end()) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003415 for (auto poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.begin(); poolCb != dev_data->commandPoolMap[commandPool].commandBuffers.end();) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003416 auto del_cb = dev_data->commandBufferMap.find(*poolCb);
3417 delete (*del_cb).second; // delete CB info structure
3418 dev_data->commandBufferMap.erase(del_cb); // Remove this command buffer from cbMap
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003419 poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.erase(poolCb); // Remove CB reference from commandPoolMap's list
Mark Lobodzinski39298632015-11-18 08:38:27 -07003420 }
3421 }
3422 dev_data->commandPoolMap.erase(commandPool);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003423
3424 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003425 dev_data->device_dispatch_table->DestroyCommandPool(device, commandPool, pAllocator);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003426}
3427
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003428VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandPool(
3429 VkDevice device,
3430 VkCommandPool commandPool,
3431 VkCommandPoolResetFlags flags)
3432{
3433 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003434 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003435
3436 result = dev_data->device_dispatch_table->ResetCommandPool(device, commandPool, flags);
3437 // Reset all of the CBs allocated from this pool
3438 if (VK_SUCCESS == result) {
3439 auto it = dev_data->commandPoolMap[commandPool].commandBuffers.begin();
3440 while (it != dev_data->commandPoolMap[commandPool].commandBuffers.end()) {
3441 resetCB(dev_data, (*it));
3442 ++it;
3443 }
3444 }
3445 return result;
3446}
3447
Chia-I Wu9ab61502015-11-06 06:42:02 +08003448VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003449{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003450 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 -06003451 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003452}
3453
Chia-I Wu9ab61502015-11-06 06:42:02 +08003454VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003455{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003456 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 -06003457 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003458}
3459
Chia-I Wu9ab61502015-11-06 06:42:02 +08003460VK_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 -06003461{
3462 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003463 VkResult result = dev_data->device_dispatch_table->CreateBuffer(device, pCreateInfo, pAllocator, pBuffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003464 if (VK_SUCCESS == result) {
3465 loader_platform_thread_lock_mutex(&globalLock);
3466 // TODO : This doesn't create deep copy of pQueueFamilyIndices so need to fix that if/when we want that data to be valid
Michael Lentine700b0aa2015-10-30 17:57:32 -07003467 dev_data->bufferMap[*pBuffer].create_info = unique_ptr<VkBufferCreateInfo>(new VkBufferCreateInfo(*pCreateInfo));
3468 dev_data->bufferMap[*pBuffer].in_use.store(0);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003469 loader_platform_thread_unlock_mutex(&globalLock);
3470 }
3471 return result;
3472}
3473
Chia-I Wu9ab61502015-11-06 06:42:02 +08003474VK_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 -06003475{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003476 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003477 VkResult result = dev_data->device_dispatch_table->CreateBufferView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003478 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003479 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003480 dev_data->bufferViewMap[*pView] = unique_ptr<VkBufferViewCreateInfo>(new VkBufferViewCreateInfo(*pCreateInfo));
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003481 loader_platform_thread_unlock_mutex(&globalLock);
3482 }
3483 return result;
3484}
3485
Chia-I Wu9ab61502015-11-06 06:42:02 +08003486VK_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 -06003487{
3488 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003489 VkResult result = dev_data->device_dispatch_table->CreateImage(device, pCreateInfo, pAllocator, pImage);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003490 if (VK_SUCCESS == result) {
Michael Lentineabc5e922015-10-12 11:30:14 -05003491 IMAGE_NODE* image_node = new IMAGE_NODE;
3492 image_node->layout = pCreateInfo->initialLayout;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003493 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003494 dev_data->imageMap[*pImage] = unique_ptr<VkImageCreateInfo>(new VkImageCreateInfo(*pCreateInfo));
Michael Lentineabc5e922015-10-12 11:30:14 -05003495 dev_data->imageLayoutMap[*pImage] = image_node;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003496 loader_platform_thread_unlock_mutex(&globalLock);
3497 }
3498 return result;
3499}
3500
Chia-I Wu9ab61502015-11-06 06:42:02 +08003501VK_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 -06003502{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003503 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003504 VkResult result = dev_data->device_dispatch_table->CreateImageView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003505 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003506 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003507 dev_data->imageViewMap[*pView] = unique_ptr<VkImageViewCreateInfo>(new VkImageViewCreateInfo(*pCreateInfo));
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003508 loader_platform_thread_unlock_mutex(&globalLock);
3509 }
3510 return result;
3511}
3512
Jon Ashburnc669cc62015-07-09 15:02:25 -06003513//TODO handle pipeline caches
Chia-I Wu9ab61502015-11-06 06:42:02 +08003514VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineCache(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003515 VkDevice device,
3516 const VkPipelineCacheCreateInfo* pCreateInfo,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003517 const VkAllocationCallbacks* pAllocator,
Jon Ashburnc669cc62015-07-09 15:02:25 -06003518 VkPipelineCache* pPipelineCache)
3519{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003520 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003521 VkResult result = dev_data->device_dispatch_table->CreatePipelineCache(device, pCreateInfo, pAllocator, pPipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003522 return result;
3523}
3524
Chia-I Wu9ab61502015-11-06 06:42:02 +08003525VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineCache(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003526 VkDevice device,
Chia-I Wuf7458c52015-10-26 21:10:41 +08003527 VkPipelineCache pipelineCache,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003528 const VkAllocationCallbacks* pAllocator)
Jon Ashburnc669cc62015-07-09 15:02:25 -06003529{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003530 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003531 dev_data->device_dispatch_table->DestroyPipelineCache(device, pipelineCache, pAllocator);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003532}
3533
Chia-I Wu9ab61502015-11-06 06:42:02 +08003534VKAPI_ATTR VkResult VKAPI_CALL vkGetPipelineCacheData(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003535 VkDevice device,
3536 VkPipelineCache pipelineCache,
Chia-I Wub16facd2015-10-26 19:17:06 +08003537 size_t* pDataSize,
Jon Ashburnc669cc62015-07-09 15:02:25 -06003538 void* pData)
3539{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003540 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wub16facd2015-10-26 19:17:06 +08003541 VkResult result = dev_data->device_dispatch_table->GetPipelineCacheData(device, pipelineCache, pDataSize, pData);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003542 return result;
3543}
3544
Chia-I Wu9ab61502015-11-06 06:42:02 +08003545VKAPI_ATTR VkResult VKAPI_CALL vkMergePipelineCaches(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003546 VkDevice device,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003547 VkPipelineCache dstCache,
Jon Ashburnc669cc62015-07-09 15:02:25 -06003548 uint32_t srcCacheCount,
3549 const VkPipelineCache* pSrcCaches)
3550{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003551 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003552 VkResult result = dev_data->device_dispatch_table->MergePipelineCaches(device, dstCache, srcCacheCount, pSrcCaches);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003553 return result;
3554}
3555
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003556VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateGraphicsPipelines(
3557 VkDevice device,
3558 VkPipelineCache pipelineCache,
3559 uint32_t count,
3560 const VkGraphicsPipelineCreateInfo *pCreateInfos,
3561 const VkAllocationCallbacks *pAllocator,
3562 VkPipeline *pPipelines)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003563{
Courtney Goeltzenleuchtered894072015-09-04 13:39:59 -06003564 VkResult result = VK_SUCCESS;
Tobin Ehlis11efc302015-09-16 10:33:53 -06003565 //TODO What to do with pipelineCache?
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003566 // The order of operations here is a little convoluted but gets the job done
3567 // 1. Pipeline create state is first shadowed into PIPELINE_NODE struct
3568 // 2. Create state is then validated (which uses flags setup during shadowing)
3569 // 3. If everything looks good, we'll then create the pipeline and add NODE to pipelineMap
Tobin Ehlis11efc302015-09-16 10:33:53 -06003570 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis65399772015-09-17 16:33:58 -06003571 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
3572 vector<PIPELINE_NODE*> pPipeNode(count);
Tobin Ehlis0b632332015-10-07 09:38:40 -06003573 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003574
Tobin Ehlis11efc302015-09-16 10:33:53 -06003575 uint32_t i=0;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003576 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003577
Tobin Ehlis11efc302015-09-16 10:33:53 -06003578 for (i=0; i<count; i++) {
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003579 pPipeNode[i] = initGraphicsPipeline(dev_data, &pCreateInfos[i], NULL);
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06003580 skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
Tobin Ehlis11efc302015-09-16 10:33:53 -06003581 }
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003582
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003583 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003584
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07003585 if (VK_FALSE == skipCall) {
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003586 result = dev_data->device_dispatch_table->CreateGraphicsPipelines(device,
3587 pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003588 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis11efc302015-09-16 10:33:53 -06003589 for (i=0; i<count; i++) {
3590 pPipeNode[i]->pipeline = pPipelines[i];
Chia-I Wue2fc5522015-10-26 20:04:44 +08003591 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
Tobin Ehlis11efc302015-09-16 10:33:53 -06003592 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003593 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisce132d82015-06-19 15:07:05 -06003594 } else {
Tobin Ehlis11efc302015-09-16 10:33:53 -06003595 for (i=0; i<count; i++) {
3596 if (pPipeNode[i]) {
3597 // If we allocated a pipeNode, need to clean it up here
3598 delete[] pPipeNode[i]->pVertexBindingDescriptions;
3599 delete[] pPipeNode[i]->pVertexAttributeDescriptions;
3600 delete[] pPipeNode[i]->pAttachments;
3601 delete pPipeNode[i];
3602 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003603 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003604 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003605 }
Courtney Goeltzenleuchtere2aaad02015-04-13 16:16:04 -06003606 return result;
3607}
3608
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003609VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateComputePipelines(
3610 VkDevice device,
3611 VkPipelineCache pipelineCache,
3612 uint32_t count,
3613 const VkComputePipelineCreateInfo *pCreateInfos,
3614 const VkAllocationCallbacks *pAllocator,
3615 VkPipeline *pPipelines)
3616{
3617 VkResult result = VK_SUCCESS;
3618 VkBool32 skipCall = VK_FALSE;
3619
3620 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
3621 vector<PIPELINE_NODE*> pPipeNode(count);
3622 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3623
3624 uint32_t i=0;
3625 loader_platform_thread_lock_mutex(&globalLock);
3626 for (i=0; i<count; i++) {
3627 // TODO: Verify compute stage bits
3628
3629 // Create and initialize internal tracking data structure
3630 pPipeNode[i] = new PIPELINE_NODE;
3631 memset((void*)pPipeNode[i], 0, sizeof(PIPELINE_NODE));
3632 memcpy(&pPipeNode[i]->computePipelineCI, (const void*)&pCreateInfos[i], sizeof(VkComputePipelineCreateInfo));
3633
3634 // TODO: Add Compute Pipeline Verification
3635 // skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
3636 }
3637 loader_platform_thread_unlock_mutex(&globalLock);
3638
3639 if (VK_FALSE == skipCall) {
3640 result = dev_data->device_dispatch_table->CreateComputePipelines(device, pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
3641 loader_platform_thread_lock_mutex(&globalLock);
3642 for (i=0; i<count; i++) {
3643 pPipeNode[i]->pipeline = pPipelines[i];
3644 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
3645 }
3646 loader_platform_thread_unlock_mutex(&globalLock);
3647 } else {
3648 for (i=0; i<count; i++) {
3649 if (pPipeNode[i]) {
3650 // Clean up any locally allocated data structures
3651 delete pPipeNode[i];
3652 }
3653 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003654 return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003655 }
3656 return result;
3657}
3658
Chia-I Wu9ab61502015-11-06 06:42:02 +08003659VK_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 -06003660{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003661 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003662 VkResult result = dev_data->device_dispatch_table->CreateSampler(device, pCreateInfo, pAllocator, pSampler);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003663 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003664 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003665 dev_data->sampleMap[*pSampler] = unique_ptr<SAMPLER_NODE>(new SAMPLER_NODE(pSampler, pCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003666 loader_platform_thread_unlock_mutex(&globalLock);
3667 }
3668 return result;
3669}
3670
Chia-I Wu9ab61502015-11-06 06:42:02 +08003671VK_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 -06003672{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003673 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003674 VkResult result = dev_data->device_dispatch_table->CreateDescriptorSetLayout(device, pCreateInfo, pAllocator, pSetLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003675 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003676 // TODOSC : Capture layout bindings set
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003677 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
3678 if (NULL == pNewNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003679 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, __LINE__, DRAWSTATE_OUT_OF_MEMORY, "DS",
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003680 "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003681 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003682 }
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06003683 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003684 pNewNode->createInfo.pBindings = new VkDescriptorSetLayoutBinding[pCreateInfo->bindingCount];
3685 memcpy((void*)pNewNode->createInfo.pBindings, pCreateInfo->pBindings, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->bindingCount);
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003686 // g++ does not like reserve with size 0
3687 if (pCreateInfo->bindingCount)
3688 pNewNode->bindings.reserve(pCreateInfo->bindingCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003689 uint32_t totalCount = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003690 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003691 if (!pNewNode->bindings.insert(pCreateInfo->pBindings[i].binding).second) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003692 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, __LINE__, DRAWSTATE_INVALID_LAYOUT, "DS",
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003693 "duplicated binding number in VkDescriptorSetLayoutBinding"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003694 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003695 }
3696
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003697 totalCount += pCreateInfo->pBindings[i].descriptorCount;
3698 if (pCreateInfo->pBindings[i].pImmutableSamplers) {
3699 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBindings[i].pImmutableSamplers;
3700 *ppIS = new VkSampler[pCreateInfo->pBindings[i].descriptorCount];
3701 memcpy(*ppIS, pCreateInfo->pBindings[i].pImmutableSamplers, pCreateInfo->pBindings[i].descriptorCount*sizeof(VkSampler));
Tobin Ehlis793ad302015-04-03 12:01:11 -06003702 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003703 }
Tobin Ehlis43c39c02016-01-11 13:18:40 -07003704 pNewNode->layout = *pSetLayout;
3705 pNewNode->startIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003706 if (totalCount > 0) {
Cody Northrop43751cc2015-10-26 14:07:35 -06003707 pNewNode->descriptorTypes.resize(totalCount);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06003708 pNewNode->stageFlags.resize(totalCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003709 uint32_t offset = 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06003710 uint32_t j = 0;
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07003711 VkDescriptorType dType;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003712 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003713 dType = pCreateInfo->pBindings[i].descriptorType;
3714 for (j = 0; j < pCreateInfo->pBindings[i].descriptorCount; j++) {
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07003715 pNewNode->descriptorTypes[offset + j] = dType;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003716 pNewNode->stageFlags[offset + j] = pCreateInfo->pBindings[i].stageFlags;
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07003717 if ((dType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
3718 (dType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
3719 pNewNode->dynamicDescriptorCount++;
3720 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003721 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06003722 offset += j;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003723 }
Tobin Ehlis43c39c02016-01-11 13:18:40 -07003724 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
3725 } else { // no descriptors
3726 pNewNode->endIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003727 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003728 // Put new node at Head of global Layer list
3729 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07003730 dev_data->descriptorSetLayoutMap[*pSetLayout] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003731 loader_platform_thread_unlock_mutex(&globalLock);
3732 }
3733 return result;
3734}
3735
Chia-I Wu9ab61502015-11-06 06:42:02 +08003736VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003737{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003738 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003739 VkResult result = dev_data->device_dispatch_table->CreatePipelineLayout(device, pCreateInfo, pAllocator, pPipelineLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003740 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003741 // TODOSC : Merge capture of the setLayouts per pipeline
Tobin Ehlis559c6382015-11-05 09:52:49 -07003742 PIPELINE_LAYOUT_NODE& plNode = dev_data->pipelineLayoutMap[*pPipelineLayout];
Chia-I Wud50a7d72015-10-26 20:48:51 +08003743 plNode.descriptorSetLayouts.resize(pCreateInfo->setLayoutCount);
Tobin Ehlis644ff042015-10-20 10:11:55 -06003744 uint32_t i = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003745 for (i=0; i<pCreateInfo->setLayoutCount; ++i) {
Tobin Ehlis644ff042015-10-20 10:11:55 -06003746 plNode.descriptorSetLayouts[i] = pCreateInfo->pSetLayouts[i];
3747 }
Cody Northrop43751cc2015-10-26 14:07:35 -06003748 plNode.pushConstantRanges.resize(pCreateInfo->pushConstantRangeCount);
Tobin Ehlis644ff042015-10-20 10:11:55 -06003749 for (i=0; i<pCreateInfo->pushConstantRangeCount; ++i) {
3750 plNode.pushConstantRanges[i] = pCreateInfo->pPushConstantRanges[i];
3751 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06003752 }
3753 return result;
3754}
3755
Chia-I Wu9ab61502015-11-06 06:42:02 +08003756VK_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 -06003757{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003758 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003759 VkResult result = dev_data->device_dispatch_table->CreateDescriptorPool(device, pCreateInfo, pAllocator, pDescriptorPool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003760 if (VK_SUCCESS == result) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06003761 // Insert this pool into Global Pool LL at head
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003762 if (log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, (uint64_t) *pDescriptorPool, __LINE__, DRAWSTATE_OUT_OF_MEMORY, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08003763 "Created Descriptor Pool %#" PRIxLEAST64, (uint64_t) *pDescriptorPool))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003764 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003765 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003766 DESCRIPTOR_POOL_NODE* pNewNode = new DESCRIPTOR_POOL_NODE(*pDescriptorPool, pCreateInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003767 if (NULL == pNewNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003768 if (log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, (uint64_t) *pDescriptorPool, __LINE__, DRAWSTATE_OUT_OF_MEMORY, "DS",
Mark Lobodzinski39298632015-11-18 08:38:27 -07003769 "Out of memory while attempting to allocate DESCRIPTOR_POOL_NODE in vkCreateDescriptorPool()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003770 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisce132d82015-06-19 15:07:05 -06003771 } else {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003772 dev_data->descriptorPoolMap[*pDescriptorPool] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003773 }
3774 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisce132d82015-06-19 15:07:05 -06003775 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06003776 // Need to do anything if pool create fails?
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003777 }
3778 return result;
3779}
3780
Chia-I Wu9ab61502015-11-06 06:42:02 +08003781VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorPoolResetFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003782{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003783 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003784 VkResult result = dev_data->device_dispatch_table->ResetDescriptorPool(device, descriptorPool, flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003785 if (VK_SUCCESS == result) {
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003786 clearDescriptorPool(dev_data, device, descriptorPool, flags);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003787 }
3788 return result;
3789}
3790
Chia-I Wu9ab61502015-11-06 06:42:02 +08003791VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo* pAllocateInfo, VkDescriptorSet* pDescriptorSets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003792{
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003793 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis0b632332015-10-07 09:38:40 -06003794 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003795 // Verify that requested descriptorSets are available in pool
Mark Lobodzinski39298632015-11-18 08:38:27 -07003796 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003797 if (!pPoolNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003798 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, __LINE__, DRAWSTATE_INVALID_POOL, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003799 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003800 } else { // Make sure pool has all the available descriptors before calling down chain
Jon Ashburnf19916e2016-01-11 13:12:43 -07003801 skipCall |= validate_descriptor_availability_in_pool(dev_data, pPoolNode, pAllocateInfo->descriptorSetCount, pAllocateInfo->pSetLayouts);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003802 }
3803 if (skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003804 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003805 VkResult result = dev_data->device_dispatch_table->AllocateDescriptorSets(device, pAllocateInfo, pDescriptorSets);
Cody Northrop1e4f8022015-08-03 12:47:29 -06003806 if (VK_SUCCESS == result) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003807 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003808 if (pPoolNode) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07003809 if (pAllocateInfo->descriptorSetCount == 0) {
3810 log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, pAllocateInfo->descriptorSetCount, __LINE__, DRAWSTATE_NONE, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003811 "AllocateDescriptorSets called with 0 count");
Cody Northrop1e4f8022015-08-03 12:47:29 -06003812 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07003813 for (uint32_t i = 0; i < pAllocateInfo->descriptorSetCount; i++) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003814 log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pDescriptorSets[i], __LINE__, DRAWSTATE_NONE, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08003815 "Created Descriptor Set %#" PRIxLEAST64, (uint64_t) pDescriptorSets[i]);
Tobin Ehlis793ad302015-04-03 12:01:11 -06003816 // Create new set node and add to head of pool nodes
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003817 SET_NODE* pNewNode = new SET_NODE;
3818 if (NULL == pNewNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003819 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], __LINE__, DRAWSTATE_OUT_OF_MEMORY, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003820 "Out of memory while attempting to allocate SET_NODE in vkAllocateDescriptorSets()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003821 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisce132d82015-06-19 15:07:05 -06003822 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003823 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlis8b5b28c2015-10-19 12:09:13 -06003824 // TODO : Pool should store a total count of each type of Descriptor available
3825 // When descriptors are allocated, decrement the count and validate here
3826 // that the count doesn't go below 0. One reset/free need to bump count back up.
Tobin Ehlis793ad302015-04-03 12:01:11 -06003827 // Insert set at head of Set LL for this pool
3828 pNewNode->pNext = pPoolNode->pSets;
3829 pPoolNode->pSets = pNewNode;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003830 LAYOUT_NODE* pLayout = getLayoutNode(dev_data, pAllocateInfo->pSetLayouts[i]);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003831 if (NULL == pLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003832 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], __LINE__, DRAWSTATE_INVALID_LAYOUT, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003833 "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 -07003834 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003835 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06003836 pNewNode->pLayout = pLayout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003837 pNewNode->pool = pAllocateInfo->descriptorPool;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003838 pNewNode->set = pDescriptorSets[i];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003839 pNewNode->descriptorCount = pLayout->endIndex + 1;
3840 if (pNewNode->descriptorCount) {
3841 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
3842 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
3843 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
3844 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08003845 dev_data->setMap[pDescriptorSets[i]] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003846 }
3847 }
3848 }
3849 }
3850 return result;
3851}
3852
Chia-I Wu9ab61502015-11-06 06:42:02 +08003853VK_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 -06003854{
Tobin Ehlise735c692015-10-08 13:13:50 -06003855 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis0b632332015-10-07 09:38:40 -06003856 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003857 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, descriptorPool);
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003858 if (pPoolNode && !(VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT & pPoolNode->createInfo.flags)) {
3859 // Can't Free from a NON_FREE pool
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003860 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, (uint64_t)device, __LINE__, DRAWSTATE_CANT_FREE_FROM_NON_FREE_POOL, "DS",
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003861 "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 -06003862 }
Mark Youngb20a6a82016-01-07 15:41:43 -07003863 if (VK_FALSE != skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003864 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis0b632332015-10-07 09:38:40 -06003865 VkResult result = dev_data->device_dispatch_table->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003866 if (VK_SUCCESS == result) {
3867 // For each freed descriptor add it back into the pool as available
3868 for (uint32_t i=0; i<count; ++i) {
Chia-I Wue2fc5522015-10-26 20:04:44 +08003869 SET_NODE* pSet = dev_data->setMap[pDescriptorSets[i]]; // getSetNode() without locking
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003870 LAYOUT_NODE* pLayout = pSet->pLayout;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003871 uint32_t typeIndex = 0, poolSizeCount = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003872 for (uint32_t j=0; j<pLayout->createInfo.bindingCount; ++j) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003873 typeIndex = static_cast<uint32_t>(pLayout->createInfo.pBindings[j].descriptorType);
3874 poolSizeCount = pLayout->createInfo.pBindings[j].descriptorCount;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003875 pPoolNode->availableDescriptorTypeCount[typeIndex] += poolSizeCount;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003876 }
3877 }
3878 }
3879 // TODO : Any other clean-up or book-keeping to do here?
Tony Barbour34ec6922015-07-10 10:50:45 -06003880 return result;
3881}
3882
Chia-I Wu9ab61502015-11-06 06:42:02 +08003883VK_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 -06003884{
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06003885 // 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 -06003886 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08003887 if (!dsUpdate(dev_data, device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies)) {
3888 dev_data->device_dispatch_table->UpdateDescriptorSets(device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies);
Jon Ashburn3950e1b2015-05-20 09:00:28 -06003889 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003890}
3891
Chia-I Wu9ab61502015-11-06 06:42:02 +08003892VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo* pCreateInfo, VkCommandBuffer* pCommandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003893{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003894 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003895 VkResult result = dev_data->device_dispatch_table->AllocateCommandBuffers(device, pCreateInfo, pCommandBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003896 if (VK_SUCCESS == result) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07003897 for (uint32_t i = 0; i < pCreateInfo->commandBufferCount; i++) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003898 // Validate command pool
3899 if (dev_data->commandPoolMap.find(pCreateInfo->commandPool) != dev_data->commandPoolMap.end()) {
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003900 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003901 // Add command buffer to its commandPool map
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003902 dev_data->commandPoolMap[pCreateInfo->commandPool].commandBuffers.push_back(pCommandBuffer[i]);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003903 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
3904 // Add command buffer to map
3905 dev_data->commandBufferMap[pCommandBuffer[i]] = pCB;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003906 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003907 resetCB(dev_data, pCommandBuffer[i]);
3908 pCB->commandBuffer = pCommandBuffer[i];
3909 pCB->createInfo = *pCreateInfo;
Mark Lobodzinski39298632015-11-18 08:38:27 -07003910 }
3911 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003912 }
3913 return result;
3914}
3915
Chia-I Wu9ab61502015-11-06 06:42:02 +08003916VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo* pBeginInfo)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003917{
Mark Youngb20a6a82016-01-07 15:41:43 -07003918 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003919 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06003920 // Validate command buffer level
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003921 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06003922 if (pCB) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07003923 if (pCB->createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
3924 // Secondary Command Buffer
Tobin Ehlis61b36f32015-12-16 08:19:42 -07003925 // TODO : Add check here from spec "If commandBuffer is a secondary command buffer and either the
3926 // occlusionQueryEnable member of pBeginInfo is VK_FALSE, or the precise occlusion queries feature
3927 // is not enabled, the queryFlags member of pBeginInfo must not contain VK_QUERY_CONTROL_PRECISE_BIT"
Jon Ashburnf19916e2016-01-11 13:12:43 -07003928 const VkCommandBufferInheritanceInfo *pInfo = pBeginInfo->pInheritanceInfo;
Tobin Ehlis651d9b02015-12-16 05:01:22 -07003929 if (pBeginInfo->flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07003930 if (!pInfo->renderPass) { // renderpass should NOT be null for an Secondary CB
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003931 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, __LINE__, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
Tobin Ehlis651d9b02015-12-16 05:01:22 -07003932 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) must specify a valid renderpass parameter.", (void*)commandBuffer);
3933 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07003934 if (!pInfo->framebuffer) { // framebuffer may be null for an Secondary CB, but this affects perf
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003935 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, __LINE__, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
Tobin Ehlis651d9b02015-12-16 05:01:22 -07003936 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) may perform better if a valid framebuffer parameter is specified.", (void*)commandBuffer);
3937 } else {
3938 string errorString = "";
Jon Ashburnf19916e2016-01-11 13:12:43 -07003939 VkRenderPass fbRP = dev_data->frameBufferMap[pInfo->framebuffer]->renderPass;
3940 if (!verify_renderpass_compatibility(dev_data, fbRP, pInfo->renderPass, errorString)) {
Tobin Ehlis651d9b02015-12-16 05:01:22 -07003941 // renderPass that framebuffer was created with must be compatible with local renderPass
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003942 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, __LINE__, DRAWSTATE_RENDERPASS_INCOMPATIBLE, "DS",
Tobin Ehlis651d9b02015-12-16 05:01:22 -07003943 "vkBeginCommandBuffer(): Secondary Command Buffer (%p) renderPass (%#" PRIxLEAST64 ") is incompatible w/ framebuffer (%#" PRIxLEAST64 ") w/ render pass (%#" PRIxLEAST64 ") due to: %s",
Jon Ashburnf19916e2016-01-11 13:12:43 -07003944 (void*)commandBuffer, (uint64_t)pInfo->renderPass, (uint64_t)pInfo->framebuffer, (uint64_t)fbRP, errorString.c_str());
Tobin Ehlis651d9b02015-12-16 05:01:22 -07003945 }
3946 }
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06003947 }
3948 }
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003949 pCB->beginInfo = *pBeginInfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003950 if (CB_RECORDING == pCB->state) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003951 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, __LINE__, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003952 "vkBeginCommandBuffer(): Cannot call Begin on CB (%#" PRIxLEAST64 ") in the RECORDING state. Must first call vkEndCommandBuffer().", (uint64_t)commandBuffer);
3953 } else if (CB_RECORDED == pCB->state) {
3954 VkCommandPool cmdPool = pCB->createInfo.commandPool;
3955 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003956 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer,
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003957 __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003958 "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.",
3959 (uint64_t) commandBuffer, (uint64_t) cmdPool);
3960 }
3961 }
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003962 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003963 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003964 "In vkBeginCommandBuffer() and unable to find CommandBuffer Node for CB %p!", (void*)commandBuffer);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06003965 }
Mark Youngb20a6a82016-01-07 15:41:43 -07003966 if (VK_FALSE != skipCall) {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003967 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter5fe086f2015-09-04 15:03:52 -06003968 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003969 VkResult result = dev_data->device_dispatch_table->BeginCommandBuffer(commandBuffer, pBeginInfo);
Mark Lobodzinski29b8d5a2015-11-12 16:14:04 -07003970 if ((VK_SUCCESS == result) && (pCB != NULL)) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07003971 if (CB_RECORDED == pCB->state) { resetCB(dev_data, commandBuffer); } pCB->state = CB_RECORDING; }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003972 return result;
3973}
3974
Chia-I Wu9ab61502015-11-06 06:42:02 +08003975VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEndCommandBuffer(VkCommandBuffer commandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003976{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003977 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchtered894072015-09-04 13:39:59 -06003978 VkResult result = VK_SUCCESS;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003979 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3980 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis9c536442015-06-19 13:00:59 -06003981 if (pCB) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003982 if (pCB->state != CB_RECORDING) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003983 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkEndCommandBuffer()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003984 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003985 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003986 if (VK_FALSE == skipCall) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003987 result = dev_data->device_dispatch_table->EndCommandBuffer(commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003988 if (VK_SUCCESS == result) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003989 pCB->state = CB_RECORDED;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003990 // Reset CB status flags
3991 pCB->status = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003992 printCB(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003993 }
3994 } else {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003995 result = VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003996 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003997 return result;
3998}
3999
Chia-I Wu9ab61502015-11-06 06:42:02 +08004000VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004001{
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004002 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004003 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004004 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
4005 VkCommandPool cmdPool = pCB->createInfo.commandPool;
4006 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004007 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t) commandBuffer,
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004008 __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004009 "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.",
4010 (uint64_t) commandBuffer, (uint64_t) cmdPool);
4011 }
Mark Youngb20a6a82016-01-07 15:41:43 -07004012 if (skipCall != VK_FALSE)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004013 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004014 VkResult result = dev_data->device_dispatch_table->ResetCommandBuffer(commandBuffer, flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004015 if (VK_SUCCESS == result) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004016 resetCB(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004017 }
4018 return result;
4019}
4020
Chia-I Wu9ab61502015-11-06 06:42:02 +08004021VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004022{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004023 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004024 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4025 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004026 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004027 skipCall |= addCmd(dev_data, pCB, CMD_BINDPIPELINE, "vkCmdBindPipeline()");
4028 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
4029 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, (uint64_t) pipeline,
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004030 __LINE__, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004031 "Incorrectly binding compute pipeline (%#" PRIxLEAST64 ") during active RenderPass (%#" PRIxLEAST64 ")",
4032 (uint64_t) pipeline, (uint64_t) pCB->activeRenderPass);
4033 } else if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
4034 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdBindPipeline");
4035 }
4036
4037 PIPELINE_NODE* pPN = getPipeline(dev_data, pipeline);
4038 if (pPN) {
4039 pCB->lastBoundPipeline = pipeline;
4040 loader_platform_thread_lock_mutex(&globalLock);
4041 set_cb_pso_status(pCB, pPN);
4042 loader_platform_thread_unlock_mutex(&globalLock);
4043 skipCall |= validatePipelineState(dev_data, pCB, pipelineBindPoint, pipeline);
Tobin Ehlisce132d82015-06-19 15:07:05 -06004044 } else {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004045 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004046 (uint64_t) pipeline, __LINE__, DRAWSTATE_INVALID_PIPELINE, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004047 "Attempt to bind Pipeline %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<uint64_t>(pipeline));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004048 }
4049 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004050 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004051 dev_data->device_dispatch_table->CmdBindPipeline(commandBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004052}
4053
Chia-I Wu9ab61502015-11-06 06:42:02 +08004054VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetViewport(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004055 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004056 uint32_t firstViewport,
4057 uint32_t viewportCount,
4058 const VkViewport* pViewports)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004059{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004060 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004061 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4062 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004063 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004064 skipCall |= addCmd(dev_data, pCB, CMD_SETVIEWPORTSTATE, "vkCmdSetViewport()");
4065 loader_platform_thread_lock_mutex(&globalLock);
4066 pCB->status |= CBSTATUS_VIEWPORT_SET;
4067 pCB->viewports.resize(viewportCount);
4068 memcpy(pCB->viewports.data(), pViewports, viewportCount * sizeof(VkViewport));
4069 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004070 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004071 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004072 dev_data->device_dispatch_table->CmdSetViewport(commandBuffer, firstViewport, viewportCount, pViewports);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004073}
4074
Chia-I Wu9ab61502015-11-06 06:42:02 +08004075VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetScissor(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004076 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004077 uint32_t firstScissor,
4078 uint32_t scissorCount,
4079 const VkRect2D* pScissors)
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004080{
4081 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004082 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4083 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004084 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004085 skipCall |= addCmd(dev_data, pCB, CMD_SETSCISSORSTATE, "vkCmdSetScissor()");
4086 loader_platform_thread_lock_mutex(&globalLock);
4087 pCB->status |= CBSTATUS_SCISSOR_SET;
4088 pCB->scissors.resize(scissorCount);
4089 memcpy(pCB->scissors.data(), pScissors, scissorCount * sizeof(VkRect2D));
4090 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004091 }
4092 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004093 dev_data->device_dispatch_table->CmdSetScissor(commandBuffer, firstScissor, scissorCount, pScissors);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004094}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004095
Chia-I Wu9ab61502015-11-06 06:42:02 +08004096VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004097{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004098 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004099 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4100 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004101 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004102 skipCall |= addCmd(dev_data, pCB, CMD_SETLINEWIDTHSTATE, "vkCmdSetLineWidth()");
4103 /* TODO: Do we still need this lock? */
4104 loader_platform_thread_lock_mutex(&globalLock);
4105 pCB->status |= CBSTATUS_LINE_WIDTH_SET;
4106 pCB->lineWidth = lineWidth;
4107 loader_platform_thread_unlock_mutex(&globalLock);
Cody Northrop12365112015-08-17 11:10:49 -06004108 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004109 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004110 dev_data->device_dispatch_table->CmdSetLineWidth(commandBuffer, lineWidth);
Cody Northrop12365112015-08-17 11:10:49 -06004111}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004112
Chia-I Wu9ab61502015-11-06 06:42:02 +08004113VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBias(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004114 VkCommandBuffer commandBuffer,
Chia-I Wud8c946a2015-10-26 19:08:09 +08004115 float depthBiasConstantFactor,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004116 float depthBiasClamp,
Chia-I Wud8c946a2015-10-26 19:08:09 +08004117 float depthBiasSlopeFactor)
Cody Northrop12365112015-08-17 11:10:49 -06004118{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004119 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004120 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4121 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northrop12365112015-08-17 11:10:49 -06004122 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004123 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBIASSTATE, "vkCmdSetDepthBias()");
4124 pCB->status |= CBSTATUS_DEPTH_BIAS_SET;
4125 pCB->depthBiasConstantFactor = depthBiasConstantFactor;
4126 pCB->depthBiasClamp = depthBiasClamp;
4127 pCB->depthBiasSlopeFactor = depthBiasSlopeFactor;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004128 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004129 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004130 dev_data->device_dispatch_table->CmdSetDepthBias(commandBuffer, depthBiasConstantFactor, depthBiasClamp, depthBiasSlopeFactor);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004131}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004132
Chia-I Wu9ab61502015-11-06 06:42:02 +08004133VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4])
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004134{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004135 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004136 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4137 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004138 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004139 skipCall |= addCmd(dev_data, pCB, CMD_SETBLENDSTATE, "vkCmdSetBlendConstants()");
4140 pCB->status |= CBSTATUS_BLEND_SET;
4141 memcpy(pCB->blendConstants, blendConstants, 4 * sizeof(float));
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004142 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004143 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004144 dev_data->device_dispatch_table->CmdSetBlendConstants(commandBuffer, blendConstants);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004145}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004146
Chia-I Wu9ab61502015-11-06 06:42:02 +08004147VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBounds(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004148 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004149 float minDepthBounds,
4150 float maxDepthBounds)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004151{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004152 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004153 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4154 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004155 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004156 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBOUNDSSTATE, "vkCmdSetDepthBounds()");
4157 pCB->status |= CBSTATUS_DEPTH_BOUNDS_SET;
4158 pCB->minDepthBounds = minDepthBounds;
4159 pCB->maxDepthBounds = maxDepthBounds;
Cody Northrop82485a82015-08-18 15:21:16 -06004160 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004161 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004162 dev_data->device_dispatch_table->CmdSetDepthBounds(commandBuffer, minDepthBounds, maxDepthBounds);
Cody Northrop82485a82015-08-18 15:21:16 -06004163}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004164
Chia-I Wu9ab61502015-11-06 06:42:02 +08004165VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilCompareMask(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004166 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004167 VkStencilFaceFlags faceMask,
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004168 uint32_t compareMask)
Cody Northrop82485a82015-08-18 15:21:16 -06004169{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004170 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004171 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4172 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northrop82485a82015-08-18 15:21:16 -06004173 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004174 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREADMASKSTATE, "vkCmdSetStencilCompareMask()");
4175 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4176 pCB->front.compareMask = compareMask;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004177 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004178 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4179 pCB->back.compareMask = compareMask;
4180 }
4181 /* TODO: Do we need to track front and back separately? */
4182 /* TODO: We aren't capturing the faceMask, do we need to? */
4183 pCB->status |= CBSTATUS_STENCIL_READ_MASK_SET;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004184 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004185 if (VK_FALSE == skipCall)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004186 dev_data->device_dispatch_table->CmdSetStencilCompareMask(commandBuffer, faceMask, compareMask);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004187}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004188
Chia-I Wu9ab61502015-11-06 06:42:02 +08004189VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilWriteMask(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004190 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004191 VkStencilFaceFlags faceMask,
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004192 uint32_t writeMask)
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004193{
4194 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);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004197 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004198 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILWRITEMASKSTATE, "vkCmdSetStencilWriteMask()");
4199 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4200 pCB->front.writeMask = writeMask;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004201 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004202 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4203 pCB->back.writeMask = writeMask;
4204 }
4205 pCB->status |= CBSTATUS_STENCIL_WRITE_MASK_SET;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004206 }
4207 if (VK_FALSE == skipCall)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004208 dev_data->device_dispatch_table->CmdSetStencilWriteMask(commandBuffer, faceMask, writeMask);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004209}
4210
Chia-I Wu9ab61502015-11-06 06:42:02 +08004211VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilReference(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004212 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004213 VkStencilFaceFlags faceMask,
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004214 uint32_t reference)
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004215{
4216 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004217 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4218 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004219 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004220 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREFERENCESTATE, "vkCmdSetStencilReference()");
4221 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4222 pCB->front.reference = reference;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004223 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004224 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4225 pCB->back.reference = reference;
4226 }
4227 pCB->status |= CBSTATUS_STENCIL_REFERENCE_SET;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004228 }
4229 if (VK_FALSE == skipCall)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004230 dev_data->device_dispatch_table->CmdSetStencilReference(commandBuffer, faceMask, reference);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004231}
4232
Chia-I Wu9ab61502015-11-06 06:42:02 +08004233VK_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 -06004234{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004235 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004236 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4237 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004238 if (pCB) {
Tobin Ehlisf6585052015-12-17 11:48:42 -07004239 if (pCB->state == CB_RECORDING) {
4240 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004241 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Tobin Ehlisf6585052015-12-17 11:48:42 -07004242 "Incorrectly binding compute DescriptorSets during active RenderPass (%#" PRIxLEAST64 ")", (uint64_t) pCB->activeRenderPass);
4243 } else if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
4244 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdBindDescriptorSets");
Mark Lobodzinski74635932015-12-18 15:35:38 -07004245 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07004246 if (VK_FALSE == skipCall) {
4247 // Track total count of dynamic descriptor types to make sure we have an offset for each one
4248 uint32_t totalDynamicDescriptors = 0;
4249 string errorString = "";
4250 uint32_t lastSetIndex = firstSet+setCount-1;
4251 if (lastSetIndex >= pCB->boundDescriptorSets.size())
Tobin Ehlis559c6382015-11-05 09:52:49 -07004252 pCB->boundDescriptorSets.resize(lastSetIndex+1);
Tobin Ehlisf6585052015-12-17 11:48:42 -07004253 VkDescriptorSet oldFinalBoundSet = pCB->boundDescriptorSets[lastSetIndex];
4254 for (uint32_t i=0; i<setCount; i++) {
4255 SET_NODE* pSet = getSetNode(dev_data, pDescriptorSets[i]);
4256 if (pSet) {
4257 loader_platform_thread_lock_mutex(&globalLock);
4258 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
4259 pCB->lastBoundPipelineLayout = layout;
4260 pCB->boundDescriptorSets[i+firstSet] = pDescriptorSets[i];
4261 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004262 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], __LINE__, DRAWSTATE_NONE, "DS",
Tobin Ehlisf6585052015-12-17 11:48:42 -07004263 "DS %#" PRIxLEAST64 " bound on pipeline %s", (uint64_t) pDescriptorSets[i], string_VkPipelineBindPoint(pipelineBindPoint));
Tobin Ehlis43c39c02016-01-11 13:18:40 -07004264 if (!pSet->pUpdateStructs && (pSet->descriptorCount != 0)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004265 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], __LINE__, DRAWSTATE_DESCRIPTOR_SET_NOT_UPDATED, "DS",
Tobin Ehlisf6585052015-12-17 11:48:42 -07004266 "DS %#" PRIxLEAST64 " bound but it was never updated. You may want to either update it or not bind it.", (uint64_t) pDescriptorSets[i]);
4267 }
4268 // Verify that set being bound is compatible with overlapping setLayout of pipelineLayout
4269 if (!verify_set_layout_compatibility(dev_data, pSet, layout, i+firstSet, errorString)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004270 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], __LINE__, DRAWSTATE_PIPELINE_LAYOUTS_INCOMPATIBLE, "DS",
Tobin Ehlisf6585052015-12-17 11:48:42 -07004271 "descriptorSet #%u being bound is not compatible with overlapping layout in pipelineLayout due to: %s", i, errorString.c_str());
4272 }
4273 if (pSet->pLayout->dynamicDescriptorCount) {
4274 // First make sure we won't overstep bounds of pDynamicOffsets array
4275 if ((totalDynamicDescriptors + pSet->pLayout->dynamicDescriptorCount) > dynamicOffsetCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004276 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], __LINE__, DRAWSTATE_INVALID_DYNAMIC_OFFSET_COUNT, "DS",
Tobin Ehlisf6585052015-12-17 11:48:42 -07004277 "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.",
4278 i, (uint64_t) pDescriptorSets[i], pSet->pLayout->dynamicDescriptorCount, (dynamicOffsetCount - totalDynamicDescriptors));
4279 } else { // Store dynamic offsets with the set
4280 const uint32_t* pStartDynOffset = pDynamicOffsets + totalDynamicDescriptors;
4281 pSet->dynamicOffsets.assign(pStartDynOffset, pStartDynOffset + pSet->pLayout->dynamicDescriptorCount);
4282 totalDynamicDescriptors += pSet->pLayout->dynamicDescriptorCount;
4283 }
4284 }
4285 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004286 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], __LINE__, DRAWSTATE_INVALID_SET, "DS",
Tobin Ehlisf6585052015-12-17 11:48:42 -07004287 "Attempt to bind DS %#" PRIxLEAST64 " that doesn't exist!", (uint64_t) pDescriptorSets[i]);
4288 }
4289 }
4290 skipCall |= addCmd(dev_data, pCB, CMD_BINDDESCRIPTORSETS, "vkCmdBindDescrsiptorSets()");
4291 // For any previously bound sets, need to set them to "invalid" if they were disturbed by this update
4292 if (firstSet > 0) { // Check set #s below the first bound set
4293 for (uint32_t i=0; i<firstSet; ++i) {
4294 if (pCB->boundDescriptorSets[i] && !verify_set_layout_compatibility(dev_data, dev_data->setMap[pCB->boundDescriptorSets[i]], layout, i, errorString)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004295 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], __LINE__, DRAWSTATE_NONE, "DS",
Tobin Ehlisf6585052015-12-17 11:48:42 -07004296 "DescriptorSetDS %#" PRIxLEAST64 " previously bound as set #%u was disturbed by newly bound pipelineLayout (%#" PRIxLEAST64 ")", (uint64_t) pCB->boundDescriptorSets[i], i, (uint64_t) layout);
4297 pCB->boundDescriptorSets[i] = VK_NULL_HANDLE;
4298 }
4299 }
4300 }
4301 // Check if newly last bound set invalidates any remaining bound sets
4302 if ((pCB->boundDescriptorSets.size()-1) > (lastSetIndex)) {
4303 if (oldFinalBoundSet && !verify_set_layout_compatibility(dev_data, dev_data->setMap[oldFinalBoundSet], layout, lastSetIndex, errorString)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004304 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, __LINE__, DRAWSTATE_NONE, "DS",
Tobin Ehlisf6585052015-12-17 11:48:42 -07004305 "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);
4306 pCB->boundDescriptorSets.resize(lastSetIndex+1);
4307 }
4308 }
4309 // dynamicOffsetCount must equal the total number of dynamic descriptors in the sets being bound
4310 if (totalDynamicDescriptors != dynamicOffsetCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004311 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t) commandBuffer, __LINE__, DRAWSTATE_INVALID_DYNAMIC_OFFSET_COUNT, "DS",
Tobin Ehlisf6585052015-12-17 11:48:42 -07004312 "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 -07004313 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004314 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07004315 } else {
4316 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindDescriptorSets()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004317 }
4318 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004319 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004320 dev_data->device_dispatch_table->CmdBindDescriptorSets(commandBuffer, pipelineBindPoint, layout, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004321}
4322
Chia-I Wu9ab61502015-11-06 06:42:02 +08004323VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004324{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004325 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004326 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4327 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004328 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004329 skipCall |= addCmd(dev_data, pCB, CMD_BINDINDEXBUFFER, "vkCmdBindIndexBuffer()");
4330 VkDeviceSize offset_align = 0;
4331 switch (indexType) {
4332 case VK_INDEX_TYPE_UINT16:
4333 offset_align = 2;
4334 break;
4335 case VK_INDEX_TYPE_UINT32:
4336 offset_align = 4;
4337 break;
4338 default:
4339 // ParamChecker should catch bad enum, we'll also throw alignment error below if offset_align stays 0
4340 break;
4341 }
4342 if (!offset_align || (offset % offset_align)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004343 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VTX_INDEX_ALIGNMENT_ERROR, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004344 "vkCmdBindIndexBuffer() offset (%#" PRIxLEAST64 ") does not fall on alignment (%s) boundary.", offset, string_VkIndexType(indexType));
Tobin Ehlis9c536442015-06-19 13:00:59 -06004345 }
Tobin Ehlisc4c23182015-09-17 12:24:13 -06004346 pCB->status |= CBSTATUS_INDEX_BUFFER_BOUND;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004347 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004348 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004349 dev_data->device_dispatch_table->CmdBindIndexBuffer(commandBuffer, buffer, offset, indexType);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004350}
4351
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07004352void updateResourceTracking(GLOBAL_CB_NODE* pCB, uint32_t firstBinding, uint32_t bindingCount, const VkBuffer* pBuffers) {
4353 uint32_t end = firstBinding + bindingCount;
Michael Lentine700b0aa2015-10-30 17:57:32 -07004354 if (pCB->currentDrawData.buffers.size() < end) {
4355 pCB->currentDrawData.buffers.resize(end);
4356 }
4357 for (uint32_t i = 0; i < bindingCount; ++i) {
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07004358 pCB->currentDrawData.buffers[i + firstBinding] = pBuffers[i];
Michael Lentine700b0aa2015-10-30 17:57:32 -07004359 }
4360}
4361
4362void updateResourceTrackingOnDraw(GLOBAL_CB_NODE* pCB) {
4363 pCB->drawData.push_back(pCB->currentDrawData);
4364}
4365
Chia-I Wu9ab61502015-11-06 06:42:02 +08004366VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindVertexBuffers(
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07004367 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004368 uint32_t firstBinding,
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06004369 uint32_t bindingCount,
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07004370 const VkBuffer *pBuffers,
4371 const VkDeviceSize *pOffsets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004372{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004373 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004374 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4375 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004376 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004377 addCmd(dev_data, pCB, CMD_BINDVERTEXBUFFER, "vkCmdBindVertexBuffer()");
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07004378 updateResourceTracking(pCB, firstBinding, bindingCount, pBuffers);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004379 } else {
Mark Youngad779052016-01-06 14:26:04 -07004380 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindVertexBuffer()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004381 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004382 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004383 dev_data->device_dispatch_table->CmdBindVertexBuffers(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004384}
4385
Chia-I Wu9ab61502015-11-06 06:42:02 +08004386VK_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 -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 Ehlis10ae8c12015-03-17 16:24:32 -06004391 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004392 skipCall |= addCmd(dev_data, pCB, CMD_DRAW, "vkCmdDraw()");
4393 pCB->drawCount[DRAW]++;
4394 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
4395 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004396 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_NONE, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004397 "vkCmdDraw() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW]++);
4398 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004399 if (VK_FALSE == skipCall) {
4400 updateResourceTrackingOnDraw(pCB);
4401 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004402 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDraw");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004403 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004404 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004405 dev_data->device_dispatch_table->CmdDraw(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004406}
4407
Chia-I Wu9ab61502015-11-06 06:42:02 +08004408VK_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 -06004409{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004410 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4411 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004412 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004413 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004414 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXED, "vkCmdDrawIndexed()");
4415 pCB->drawCount[DRAW_INDEXED]++;
4416 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
4417 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004418 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_NONE, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004419 "vkCmdDrawIndexed() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED]++);
4420 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004421 if (VK_FALSE == skipCall) {
4422 updateResourceTrackingOnDraw(pCB);
4423 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004424 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexed");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004425 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004426 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004427 dev_data->device_dispatch_table->CmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004428}
4429
Chia-I Wu9ab61502015-11-06 06:42:02 +08004430VK_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 -06004431{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004432 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4433 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004434 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004435 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004436 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDIRECT, "vkCmdDrawIndirect()");
4437 pCB->drawCount[DRAW_INDIRECT]++;
4438 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
4439 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004440 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_NONE, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004441 "vkCmdDrawIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
4442 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004443 if (VK_FALSE == skipCall) {
4444 updateResourceTrackingOnDraw(pCB);
4445 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004446 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndirect");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004447 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004448 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004449 dev_data->device_dispatch_table->CmdDrawIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004450}
4451
Chia-I Wu9ab61502015-11-06 06:42:02 +08004452VK_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 -06004453{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004454 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004455 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4456 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004457 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004458 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXEDINDIRECT, "vkCmdDrawIndexedIndirect()");
4459 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
4460 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
4461 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004462 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_NONE, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004463 "vkCmdDrawIndexedIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
4464 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004465 if (VK_FALSE == skipCall) {
4466 updateResourceTrackingOnDraw(pCB);
4467 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004468 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexedIndirect");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004469 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004470 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004471 dev_data->device_dispatch_table->CmdDrawIndexedIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004472}
4473
Chia-I Wu9ab61502015-11-06 06:42:02 +08004474VK_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 -06004475{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004476 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004477 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4478 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004479 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004480 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCH, "vkCmdDispatch()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004481 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatch");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004482 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004483 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004484 dev_data->device_dispatch_table->CmdDispatch(commandBuffer, x, y, z);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004485}
4486
Chia-I Wu9ab61502015-11-06 06:42:02 +08004487VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004488{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004489 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004490 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4491 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004492 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004493 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCHINDIRECT, "vkCmdDispatchIndirect()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004494 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatchIndirect");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004495 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004496 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004497 dev_data->device_dispatch_table->CmdDispatchIndirect(commandBuffer, buffer, offset);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004498}
4499
Chia-I Wu9ab61502015-11-06 06:42:02 +08004500VK_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 -06004501{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004502 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004503 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4504 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004505 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004506 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFER, "vkCmdCopyBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004507 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004508 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004509 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004510 dev_data->device_dispatch_table->CmdCopyBuffer(commandBuffer, srcBuffer, dstBuffer, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004511}
4512
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07004513VkBool32 VerifySourceImageLayout(VkCommandBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout) {
Mark Youngb20a6a82016-01-07 15:41:43 -07004514 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07004515
4516#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4517 // TODO: Fix -- initialLayout may have been set in a previous command buffer
4518 return skip_call;
4519#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4520
Michael Lentineabc5e922015-10-12 11:30:14 -05004521 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4522 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4523 auto src_image_element = pCB->imageLayoutMap.find(srcImage);
4524 if (src_image_element == pCB->imageLayoutMap.end()) {
4525 pCB->imageLayoutMap[srcImage].initialLayout = srcImageLayout;
4526 pCB->imageLayoutMap[srcImage].layout = srcImageLayout;
Mark Youngb20a6a82016-01-07 15:41:43 -07004527 return VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05004528 }
4529 if (src_image_element->second.layout != srcImageLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004530 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05004531 "Cannot copy from an image whose source layout is %d and doesn't match the current layout %d.", srcImageLayout, src_image_element->second.layout);
4532 }
4533 if (srcImageLayout != VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL) {
4534 if (srcImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004535 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004536 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineecc32b72015-10-16 18:08:09 -05004537 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Michael Lentineabc5e922015-10-12 11:30:14 -05004538 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004539 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineecc32b72015-10-16 18:08:09 -05004540 "Layout for input image is %d but can only be TRANSFER_SRC_OPTIMAL or GENERAL.", srcImageLayout);
Michael Lentineabc5e922015-10-12 11:30:14 -05004541 }
4542 }
4543 return skip_call;
4544}
4545
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07004546VkBool32 VerifyDestImageLayout(VkCommandBuffer cmdBuffer, VkImage destImage, VkImageLayout destImageLayout) {
Mark Youngb20a6a82016-01-07 15:41:43 -07004547 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07004548
4549#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4550 // TODO: Fix -- initialLayout may have been set in a previous command buffer
4551 return skip_call;
4552#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4553
Michael Lentineabc5e922015-10-12 11:30:14 -05004554 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4555 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4556 auto dest_image_element = pCB->imageLayoutMap.find(destImage);
4557 if (dest_image_element == pCB->imageLayoutMap.end()) {
4558 pCB->imageLayoutMap[destImage].initialLayout = destImageLayout;
4559 pCB->imageLayoutMap[destImage].layout = destImageLayout;
Mark Youngb20a6a82016-01-07 15:41:43 -07004560 return VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05004561 }
4562 if (dest_image_element->second.layout != destImageLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004563 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05004564 "Cannot copy from an image whose dest layout is %d and doesn't match the current layout %d.", destImageLayout, dest_image_element->second.layout);
4565 }
4566 if (destImageLayout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) {
4567 if (destImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004568 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004569 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05004570 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
4571 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004572 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05004573 "Layout for output image is %d but can only be TRANSFER_DST_OPTIMAL or GENERAL.", destImageLayout);
4574 }
4575 }
4576 return skip_call;
4577}
4578
Chia-I Wu9ab61502015-11-06 06:42:02 +08004579VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004580 VkImage srcImage,
4581 VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004582 VkImage dstImage,
4583 VkImageLayout dstImageLayout,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004584 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004585{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004586 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004587 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4588 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004589 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004590 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGE, "vkCmdCopyImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004591 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImage");
Michael Lentineabc5e922015-10-12 11:30:14 -05004592 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
4593 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004594 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004595 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004596 dev_data->device_dispatch_table->CmdCopyImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004597}
4598
Chia-I Wu9ab61502015-11-06 06:42:02 +08004599VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBlitImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004600 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004601 VkImage dstImage, VkImageLayout dstImageLayout,
Mark Lobodzinskiee5eef12015-05-22 14:43:25 -05004602 uint32_t regionCount, const VkImageBlit* pRegions,
Chia-I Wub99df442015-10-26 16:49:32 +08004603 VkFilter filter)
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004604{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004605 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004606 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4607 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004608 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004609 skipCall |= addCmd(dev_data, pCB, CMD_BLITIMAGE, "vkCmdBlitImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004610 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBlitImage");
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004611 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004612 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004613 dev_data->device_dispatch_table->CmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter);
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004614}
4615
Chia-I Wu9ab61502015-11-06 06:42:02 +08004616VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004617 VkBuffer srcBuffer,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004618 VkImage dstImage, VkImageLayout dstImageLayout,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004619 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004620{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004621 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004622 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4623 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004624 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004625 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFERTOIMAGE, "vkCmdCopyBufferToImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004626 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBufferToImage");
Michael Lentineabc5e922015-10-12 11:30:14 -05004627 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004628 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004629 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004630 dev_data->device_dispatch_table->CmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004631}
4632
Chia-I Wu9ab61502015-11-06 06:42:02 +08004633VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004634 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004635 VkBuffer dstBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004636 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004637{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004638 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004639 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4640 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004641 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004642 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGETOBUFFER, "vkCmdCopyImageToBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004643 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImageToBuffer");
Michael Lentineabc5e922015-10-12 11:30:14 -05004644 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004645 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004646 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004647 dev_data->device_dispatch_table->CmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004648}
4649
Chia-I Wu9ab61502015-11-06 06:42:02 +08004650VK_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 -06004651{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004652 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004653 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4654 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004655 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004656 skipCall |= addCmd(dev_data, pCB, CMD_UPDATEBUFFER, "vkCmdUpdateBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004657 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyUpdateBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004658 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004659 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004660 dev_data->device_dispatch_table->CmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004661}
4662
Chia-I Wu9ab61502015-11-06 06:42:02 +08004663VK_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 -06004664{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004665 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004666 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4667 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004668 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004669 skipCall |= addCmd(dev_data, pCB, CMD_FILLBUFFER, "vkCmdFillBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004670 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyFillBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004671 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004672 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004673 dev_data->device_dispatch_table->CmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004674}
4675
Chia-I Wu9ab61502015-11-06 06:42:02 +08004676VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearAttachments(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004677 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004678 uint32_t attachmentCount,
4679 const VkClearAttachment* pAttachments,
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004680 uint32_t rectCount,
Courtney Goeltzenleuchter4ca43f62015-10-15 18:22:08 -06004681 const VkClearRect* pRects)
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004682{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004683 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004684 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4685 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004686 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004687 skipCall |= addCmd(dev_data, pCB, CMD_CLEARATTACHMENTS, "vkCmdClearAttachments()");
4688 // Warn if this is issued prior to Draw Cmd and clearing the entire attachment
4689 if (!hasDrawCmd(pCB) &&
4690 (pCB->activeRenderPassBeginInfo.renderArea.extent.width == pRects[0].rect.extent.width) &&
4691 (pCB->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) {
4692 // TODO : commandBuffer should be srcObj
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004693 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_CLEAR_CMD_BEFORE_DRAW, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004694 "vkCmdClearAttachments() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
4695 " 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 -06004696 }
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004697 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdClearAttachments");
4698 }
4699
4700 // Validate that attachment is in reference list of active subpass
4701 if (pCB->activeRenderPass) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07004702 const VkRenderPassCreateInfo *pRPCI = dev_data->renderPassMap[pCB->activeRenderPass]->pCreateInfo;
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004703 const VkSubpassDescription *pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
4704
4705 for (uint32_t attachment_idx = 0; attachment_idx < attachmentCount; attachment_idx++) {
4706 const VkClearAttachment *attachment = &pAttachments[attachment_idx];
4707 if (attachment->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) {
4708 VkBool32 found = VK_FALSE;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004709 for (uint32_t i = 0; i < pSD->colorAttachmentCount; i++) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004710 if (attachment->colorAttachment == pSD->pColorAttachments[i].attachment) {
4711 found = VK_TRUE;
4712 break;
4713 }
4714 }
4715 if (VK_FALSE == found) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004716 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004717 (uint64_t)commandBuffer, __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004718 "vkCmdClearAttachments() attachment index %d not found in attachment reference array of active subpass %d",
4719 attachment->colorAttachment, pCB->activeSubpass);
4720 }
4721 } else if (attachment->aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) {
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07004722 if (!pSD->pDepthStencilAttachment || // Says no DS will be used in active subpass
Mark Lobodzinski2fd355a2015-11-18 08:58:31 -07004723 (pSD->pDepthStencilAttachment->attachment == VK_ATTACHMENT_UNUSED)) { // Says no DS will be used in active subpass
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07004724
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004725 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004726 (uint64_t)commandBuffer, __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07004727 "vkCmdClearAttachments() attachment index %d does not match depthStencilAttachment.attachment (%d) found in active subpass %d",
4728 attachment->colorAttachment,
4729 (pSD->pDepthStencilAttachment) ? pSD->pDepthStencilAttachment->attachment : VK_ATTACHMENT_UNUSED,
4730 pCB->activeSubpass);
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004731 }
4732 }
4733 }
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004734 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004735 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004736 dev_data->device_dispatch_table->CmdClearAttachments(commandBuffer, attachmentCount, pAttachments, rectCount, pRects);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004737}
4738
Chia-I Wu9ab61502015-11-06 06:42:02 +08004739VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearColorImage(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004740 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06004741 VkImage image, VkImageLayout imageLayout,
Chris Forbesf0796e12015-06-24 14:34:53 +12004742 const VkClearColorValue *pColor,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06004743 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004744{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004745 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004746 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4747 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004748 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004749 skipCall |= addCmd(dev_data, pCB, CMD_CLEARCOLORIMAGE, "vkCmdClearColorImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004750 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearColorImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004751 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004752 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004753 dev_data->device_dispatch_table->CmdClearColorImage(commandBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004754}
4755
Chia-I Wu9ab61502015-11-06 06:42:02 +08004756VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearDepthStencilImage(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004757 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter45df9e12015-09-15 18:03:22 -06004758 VkImage image, VkImageLayout imageLayout,
4759 const VkClearDepthStencilValue *pDepthStencil,
4760 uint32_t rangeCount,
4761 const VkImageSubresourceRange* pRanges)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004762{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004763 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004764 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4765 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004766 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004767 skipCall |= addCmd(dev_data, pCB, CMD_CLEARDEPTHSTENCILIMAGE, "vkCmdClearDepthStencilImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004768 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearDepthStencilImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004769 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004770 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004771 dev_data->device_dispatch_table->CmdClearDepthStencilImage(commandBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004772}
4773
Chia-I Wu9ab61502015-11-06 06:42:02 +08004774VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResolveImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004775 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004776 VkImage dstImage, VkImageLayout dstImageLayout,
Tony Barbour6865d4a2015-04-13 15:02:52 -06004777 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004778{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004779 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004780 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4781 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004782 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004783 skipCall |= addCmd(dev_data, pCB, CMD_RESOLVEIMAGE, "vkCmdResolveImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004784 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResolveImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004785 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004786 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004787 dev_data->device_dispatch_table->CmdResolveImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004788}
4789
Chia-I Wu9ab61502015-11-06 06:42:02 +08004790VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004791{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004792 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004793 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4794 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004795 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004796 skipCall |= addCmd(dev_data, pCB, CMD_SETEVENT, "vkCmdSetEvent()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004797 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdSetEvent");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004798 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004799 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004800 dev_data->device_dispatch_table->CmdSetEvent(commandBuffer, event, stageMask);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004801}
4802
Chia-I Wu9ab61502015-11-06 06:42:02 +08004803VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004804{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004805 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004806 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4807 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004808 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004809 skipCall |= addCmd(dev_data, pCB, CMD_RESETEVENT, "vkCmdResetEvent()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004810 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResetEvent");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004811 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004812 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004813 dev_data->device_dispatch_table->CmdResetEvent(commandBuffer, event, stageMask);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004814}
4815
Jon Ashburnf19916e2016-01-11 13:12:43 -07004816VkBool32 TransitionImageLayouts(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const VkImageMemoryBarrier* pImgMemBarriers) {
Michael Lentineabc5e922015-10-12 11:30:14 -05004817 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4818 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Mark Youngb20a6a82016-01-07 15:41:43 -07004819 VkBool32 skip = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07004820
4821#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4822 // TODO: Fix -- pay attention to image subresource ranges -- not all subresources transition at the same time
4823 return skip;
4824#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4825
Michael Lentineabc5e922015-10-12 11:30:14 -05004826 for (uint32_t i = 0; i < memBarrierCount; ++i) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004827 auto mem_barrier = &pImgMemBarriers[i];
Michael Lentineabc5e922015-10-12 11:30:14 -05004828 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004829 auto image_data = pCB->imageLayoutMap.find(mem_barrier->image);
Michael Lentineabc5e922015-10-12 11:30:14 -05004830 if (image_data == pCB->imageLayoutMap.end()) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004831 pCB->imageLayoutMap[mem_barrier->image].initialLayout = mem_barrier->oldLayout;
4832 pCB->imageLayoutMap[mem_barrier->image].layout = mem_barrier->newLayout;
Michael Lentineabc5e922015-10-12 11:30:14 -05004833 } else {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004834 if (image_data->second.layout != mem_barrier->oldLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004835 skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Jon Ashburnf19916e2016-01-11 13:12:43 -07004836 "You cannot transition the layout from %d when current layout is %d.", mem_barrier->oldLayout, image_data->second.layout);
Michael Lentineabc5e922015-10-12 11:30:14 -05004837 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07004838 image_data->second.layout = mem_barrier->newLayout;
Michael Lentineabc5e922015-10-12 11:30:14 -05004839 }
4840 }
4841 }
4842 return skip;
4843}
4844
Mark Lobodzinskia3a86112016-01-05 17:17:55 -07004845// Print readable FlagBits in FlagMask
4846std::string string_VkAccessFlags(VkAccessFlags accessMask)
4847{
4848 std::string result;
4849 std::string separator;
4850
4851 if (accessMask == 0) {
4852 result = "[None]";
4853 } else {
4854 result = "[";
4855 for (auto i = 0; i < 32; i++) {
4856 if (accessMask & (1 << i)) {
4857 result = result + separator + string_VkAccessFlagBits((VkAccessFlagBits)(1 << i));
4858 separator = " | ";
4859 }
4860 }
4861 result = result + "]";
4862 }
4863 return result;
4864}
4865
Michael Lentine97eb7462015-11-20 09:48:52 -08004866// AccessFlags MUST have 'required_bit' set, and may have one or more of 'optional_bits' set.
4867// If required_bit is zero, accessMask must have at least one of 'optional_bits' set
Mark Lobodzinskifd740fc2016-01-06 12:56:29 -07004868// TODO: Add tracking to ensure that at least one barrier has been set for these layout transitions
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004869VkBool32 ValidateMaskBits(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout,
4870 VkAccessFlags required_bit, VkAccessFlags optional_bits, const char* type) {
Mark Youngb20a6a82016-01-07 15:41:43 -07004871 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004872
Michael Lentine97eb7462015-11-20 09:48:52 -08004873 if ((accessMask & required_bit) || (!required_bit && (accessMask & optional_bits))) {
4874 if (accessMask & !(required_bit | optional_bits)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004875 // TODO: Verify against Valid Use
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004876 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004877 "Additional bits in %s accessMask %d %s are specified when layout is %s.",
4878 type, accessMask, string_VkAccessFlags(accessMask).c_str(), string_VkImageLayout(layout));
Michael Lentineecc32b72015-10-16 18:08:09 -05004879 }
4880 } else {
Michael Lentine97eb7462015-11-20 09:48:52 -08004881 if (!required_bit) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004882 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
Mark Lobodzinskifd740fc2016-01-06 12:56:29 -07004883 "%s AccessMask %d %s must contain at least one of access bits %d %s when layout is %s, unless the app has previously added a barrier for this transition.",
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004884 type, accessMask, string_VkAccessFlags(accessMask).c_str(), optional_bits,
4885 string_VkAccessFlags(optional_bits).c_str(), string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08004886 } else {
Mark Lobodzinskif2cc2a52016-01-05 13:35:29 -07004887 std::string opt_bits;
4888 if (optional_bits != 0) {
4889 opt_bits = "and may have optional bits " + std::to_string(optional_bits) + ' ' + string_VkAccessFlags(optional_bits);
4890 }
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004891 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
Mark Lobodzinskifd740fc2016-01-06 12:56:29 -07004892 "%s AccessMask %d %s must have required access bit %d %s %s when layout is %s, unless the app has previously added a barrier for this transition.",
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004893 type, accessMask, string_VkAccessFlags(accessMask).c_str(),
4894 required_bit, string_VkAccessFlags(required_bit).c_str(),
Mark Lobodzinskif2cc2a52016-01-05 13:35:29 -07004895 opt_bits.c_str(), string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08004896 }
Michael Lentineecc32b72015-10-16 18:08:09 -05004897 }
4898 return skip_call;
4899}
4900
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004901VkBool32 ValidateMaskBitsFromLayouts(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout, const char* type) {
Mark Youngb20a6a82016-01-07 15:41:43 -07004902 VkBool32 skip_call = VK_FALSE;
Michael Lentine97eb7462015-11-20 09:48:52 -08004903 switch (layout) {
4904 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004905 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_COLOR_ATTACHMENT_READ_BIT, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08004906 break;
Michael Lentineecc32b72015-10-16 18:08:09 -05004907 }
Michael Lentine97eb7462015-11-20 09:48:52 -08004908 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004909 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08004910 break;
Michael Lentineecc32b72015-10-16 18:08:09 -05004911 }
Michael Lentine97eb7462015-11-20 09:48:52 -08004912 case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004913 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_WRITE_BIT, 0, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08004914 break;
4915 }
4916 case VK_IMAGE_LAYOUT_PREINITIALIZED: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004917 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_HOST_WRITE_BIT, 0, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08004918 break;
4919 }
4920 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004921 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, 0, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08004922 break;
4923 }
4924 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004925 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, 0, VK_ACCESS_INPUT_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08004926 break;
4927 }
4928 case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004929 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_READ_BIT, 0, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08004930 break;
4931 }
4932 case VK_IMAGE_LAYOUT_UNDEFINED: {
4933 if (accessMask != 0) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004934 // TODO: Verify against Valid Use section spec
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004935 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004936 "Additional bits in %s accessMask %d %s are specified when layout is %s.", type, accessMask, string_VkAccessFlags(accessMask).c_str(),
4937 string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08004938 }
4939 break;
4940 }
4941 case VK_IMAGE_LAYOUT_GENERAL:
4942 default: {
4943 break;
4944 }
Michael Lentineecc32b72015-10-16 18:08:09 -05004945 }
4946 return skip_call;
4947}
4948
Jon Ashburnf19916e2016-01-11 13:12:43 -07004949VkBool32 ValidateBarriers(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const VkMemoryBarrier* pMemBarriers, uint32_t imageMemBarrierCount, const VkImageMemoryBarrier *pImageMemBarriers)
4950{
Mark Youngb20a6a82016-01-07 15:41:43 -07004951 VkBool32 skip_call = VK_FALSE;
Michael Lentine48930b82015-10-15 17:07:00 -05004952 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4953 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4954 if (pCB->activeRenderPass && memBarrierCount) {
4955 for (uint32_t i = 0; i < memBarrierCount; ++i) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004956 auto mem_barrier = &pMemBarriers[i];
Michael Lentine48930b82015-10-15 17:07:00 -05004957 if (mem_barrier && mem_barrier->sType != VK_STRUCTURE_TYPE_MEMORY_BARRIER) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004958 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
Michael Lentine48930b82015-10-15 17:07:00 -05004959 "Image or Buffers Barriers cannot be used during a render pass.");
4960 }
4961 }
4962 if (!dev_data->renderPassMap[pCB->activeRenderPass]->hasSelfDependency[pCB->activeSubpass]) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004963 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
Michael Lentine48930b82015-10-15 17:07:00 -05004964 "Barriers cannot be set during subpass %d with no self dependency specified.", pCB->activeSubpass);
4965 }
4966 }
Mark Lobodzinski73a37ec2015-11-20 09:27:27 -07004967
Jon Ashburnf19916e2016-01-11 13:12:43 -07004968 for (uint32_t i = 0; i < imageMemBarrierCount; ++i) {
4969 auto mem_barrier = &pImageMemBarriers[i];
Michael Lentineecc32b72015-10-16 18:08:09 -05004970 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004971 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, mem_barrier->srcAccessMask, mem_barrier->oldLayout, "Source");
4972 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, mem_barrier->dstAccessMask, mem_barrier->newLayout, "Dest");
Michael Lentineecc32b72015-10-16 18:08:09 -05004973 }
4974 }
Mark Lobodzinski3cba24a2015-12-03 15:42:32 -07004975
Michael Lentine48930b82015-10-15 17:07:00 -05004976 return skip_call;
4977}
4978
Jon Ashburnf19916e2016-01-11 13:12:43 -07004979VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdWaitEvents(
4980 VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent* pEvents,
4981 VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask,
4982 uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers,
4983 uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers,
4984 uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004985{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004986 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004987 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4988 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004989 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06004990 for (uint32_t i = 0; i < eventCount; ++i) {
4991 pCB->waitedEvents.push_back(pEvents[i]);
4992 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07004993 if (pCB->state == CB_RECORDING) {
4994 skipCall |= addCmd(dev_data, pCB, CMD_WAITEVENTS, "vkCmdWaitEvents()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06004995 } else {
4996 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdWaitEvents()");
4997 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07004998 skipCall |= TransitionImageLayouts(commandBuffer, imageMemoryBarrierCount, pImageMemoryBarriers);
4999 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, pMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005000 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005001 if (VK_FALSE == skipCall)
Jon Ashburnf19916e2016-01-11 13:12:43 -07005002 dev_data->device_dispatch_table->CmdWaitEvents(commandBuffer, eventCount, pEvents, sourceStageMask, dstStageMask,
5003 memoryBarrierCount, pMemoryBarriers,
5004 bufferMemoryBarrierCount, pBufferMemoryBarriers,
5005 imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005006}
5007
Jon Ashburnf19916e2016-01-11 13:12:43 -07005008VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdPipelineBarrier(
5009 VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask,
5010 VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags,
5011 uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers,
5012 uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers,
5013 uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005014{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005015 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005016 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5017 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005018 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005019 skipCall |= addCmd(dev_data, pCB, CMD_PIPELINEBARRIER, "vkCmdPipelineBarrier()");
Jon Ashburnf19916e2016-01-11 13:12:43 -07005020 skipCall |= TransitionImageLayouts(commandBuffer, imageMemoryBarrierCount, pImageMemoryBarriers);
5021 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, pMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005022 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005023 if (VK_FALSE == skipCall)
Jon Ashburnf19916e2016-01-11 13:12:43 -07005024 dev_data->device_dispatch_table->CmdPipelineBarrier(commandBuffer, srcStageMask, dstStageMask, dependencyFlags,
5025 memoryBarrierCount, pMemoryBarriers,
5026 bufferMemoryBarrierCount, pBufferMemoryBarriers,
5027 imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005028}
5029
Chia-I Wu9ab61502015-11-06 06:42:02 +08005030VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005031{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005032 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005033 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5034 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005035 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005036 skipCall |= addCmd(dev_data, pCB, CMD_BEGINQUERY, "vkCmdBeginQuery()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005037 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005038 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005039 dev_data->device_dispatch_table->CmdBeginQuery(commandBuffer, queryPool, slot, flags);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005040}
5041
Chia-I Wu9ab61502015-11-06 06:42:02 +08005042VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005043{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005044 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005045 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5046 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005047 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005048 QueryObject query = {queryPool, slot};
5049 pCB->queryToStateMap[query] = 1;
Mark Lobodzinskice738852016-01-07 10:04:02 -07005050 if (pCB->state == CB_RECORDING) {
5051 skipCall |= addCmd(dev_data, pCB, CMD_ENDQUERY, "VkCmdEndQuery()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005052 } else {
5053 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdEndQuery()");
5054 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005055 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005056 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005057 dev_data->device_dispatch_table->CmdEndQuery(commandBuffer, queryPool, slot);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005058}
5059
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005060VK_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 -06005061{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005062 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005063 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5064 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005065 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005066 for (uint32_t i = 0; i < queryCount; i++) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005067 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06005068 pCB->waitedEventsBeforeQueryReset[query] = pCB->waitedEvents;
5069 pCB->queryToStateMap[query] = 0;
5070 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005071 if (pCB->state == CB_RECORDING) {
5072 skipCall |= addCmd(dev_data, pCB, CMD_RESETQUERYPOOL, "VkCmdResetQueryPool()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005073 } else {
5074 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdResetQueryPool()");
5075 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005076 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdQueryPool");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005077 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005078 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005079 dev_data->device_dispatch_table->CmdResetQueryPool(commandBuffer, queryPool, firstQuery, queryCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005080}
5081
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005082VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005083 uint32_t queryCount, VkBuffer dstBuffer, VkDeviceSize dstOffset,
Chia-I Wuccc93a72015-10-26 18:36:20 +08005084 VkDeviceSize stride, VkQueryResultFlags flags)
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005085{
5086 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005087 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5088 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005089 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005090 for (uint32_t i = 0; i < queryCount; i++) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005091 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06005092 if(!pCB->queryToStateMap[query]) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005093 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_QUERY, "DS",
5094 "Requesting a copy from query to buffer with invalid query: queryPool %" PRIu64 ", index %d", reinterpret_cast<uint64_t>(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06005095 }
5096 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005097 if (pCB->state == CB_RECORDING) {
5098 skipCall |= addCmd(dev_data, pCB, CMD_COPYQUERYPOOLRESULTS, "vkCmdCopyQueryPoolResults()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005099 } else {
5100 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdCopyQueryPoolResults()");
5101 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005102 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyQueryPoolResults");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005103 }
5104 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005105 dev_data->device_dispatch_table->CmdCopyQueryPoolResults(commandBuffer, queryPool,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005106 firstQuery, queryCount, dstBuffer, dstOffset, stride, flags);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005107}
5108
Chia-I Wu9ab61502015-11-06 06:42:02 +08005109VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005110{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005111 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005112 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5113 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005114 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005115 QueryObject query = {queryPool, slot};
5116 pCB->queryToStateMap[query] = 1;
Mark Lobodzinskice738852016-01-07 10:04:02 -07005117 if (pCB->state == CB_RECORDING) {
5118 skipCall |= addCmd(dev_data, pCB, CMD_WRITETIMESTAMP, "vkCmdWriteTimestamp()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005119 } else {
5120 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdWriteTimestamp()");
5121 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005122 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005123 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005124 dev_data->device_dispatch_table->CmdWriteTimestamp(commandBuffer, pipelineStage, queryPool, slot);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005125}
5126
Chia-I Wu9ab61502015-11-06 06:42:02 +08005127VK_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 -06005128{
Tobin Ehlis0b632332015-10-07 09:38:40 -06005129 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005130 VkResult result = dev_data->device_dispatch_table->CreateFramebuffer(device, pCreateInfo, pAllocator, pFramebuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005131 if (VK_SUCCESS == result) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06005132 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06005133 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +08005134 if (pCreateInfo->pAttachments) {
Courtney Goeltzenleuchter5861a1b2015-09-01 17:30:39 -06005135 localFBCI->pAttachments = new VkImageView[localFBCI->attachmentCount];
5136 memcpy((void*)localFBCI->pAttachments, pCreateInfo->pAttachments, localFBCI->attachmentCount*sizeof(VkImageView));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005137 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08005138 dev_data->frameBufferMap[*pFramebuffer] = localFBCI;
Tobin Ehliseba312c2015-04-01 08:40:34 -06005139 }
5140 return result;
5141}
5142
Michael Lentineb6986752015-10-06 14:56:18 -07005143// Store the DAG.
5144struct DAGNode {
5145 uint32_t pass;
5146 std::vector<uint32_t> prev;
5147 std::vector<uint32_t> next;
5148};
5149
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005150VkBool32 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 -07005151 // If we have already checked this node we have not found a dependency path so return false.
5152 if (processed_nodes.count(index))
Mark Youngb20a6a82016-01-07 15:41:43 -07005153 return VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005154 processed_nodes.insert(index);
5155 const DAGNode& node = subpass_to_node[index];
5156 // Look for a dependency path. If one exists return true else recurse on the previous nodes.
5157 if (std::find(node.prev.begin(), node.prev.end(), dependent) == node.prev.end()) {
5158 for (auto elem : node.prev) {
5159 if (FindDependency(elem, dependent, subpass_to_node, processed_nodes))
Mark Youngb20a6a82016-01-07 15:41:43 -07005160 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005161 }
5162 } else {
Mark Youngb20a6a82016-01-07 15:41:43 -07005163 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005164 }
Mark Youngb20a6a82016-01-07 15:41:43 -07005165 return VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005166}
5167
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005168VkBool32 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) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005169 VkBool32 result = VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005170 // Loop through all subpasses that share the same attachment and make sure a dependency exists
5171 for (uint32_t k = 0; k < dependent_subpasses.size(); ++k) {
5172 if (subpass == dependent_subpasses[k])
5173 continue;
5174 const DAGNode& node = subpass_to_node[subpass];
5175 // Check for a specified dependency between the two nodes. If one exists we are done.
5176 auto prev_elem = std::find(node.prev.begin(), node.prev.end(), dependent_subpasses[k]);
5177 auto next_elem = std::find(node.next.begin(), node.next.end(), dependent_subpasses[k]);
5178 if (prev_elem == node.prev.end() && next_elem == node.next.end()) {
5179 // If no dependency exits an implicit dependency still might. If so, warn and if not throw an error.
5180 std::unordered_set<uint32_t> processed_nodes;
5181 if (FindDependency(subpass, dependent_subpasses[k], subpass_to_node, processed_nodes) ||
5182 FindDependency(dependent_subpasses[k], subpass, subpass_to_node, processed_nodes)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005183 // TODO: Verify against Valid Use section of spec
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005184 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
Michael Lentineb6986752015-10-06 14:56:18 -07005185 "A dependency between subpasses %d and %d must exist but only an implicit one is specified.",
5186 subpass, dependent_subpasses[k]);
5187 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005188 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
Michael Lentineb6986752015-10-06 14:56:18 -07005189 "A dependency between subpasses %d and %d must exist but one is not specified.",
5190 subpass, dependent_subpasses[k]);
Mark Youngb20a6a82016-01-07 15:41:43 -07005191 result = VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005192 }
5193 }
5194 }
5195 return result;
5196}
5197
Jon Ashburnf19916e2016-01-11 13:12:43 -07005198VkBool32 CheckPreserved(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, const int index, const uint32_t attachment, const std::vector<DAGNode>& subpass_to_node, int depth, VkBool32& skip_call) {
Michael Lentineb6986752015-10-06 14:56:18 -07005199 const DAGNode& node = subpass_to_node[index];
5200 // If this node writes to the attachment return true as next nodes need to preserve the attachment.
5201 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005202 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005203 if (attachment == subpass.pColorAttachments[j].attachment)
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005204 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005205 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005206 if (subpass.pDepthStencilAttachment &&
5207 subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
5208 if (attachment == subpass.pDepthStencilAttachment->attachment)
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005209 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005210 }
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005211 VkBool32 result = VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005212 // Loop through previous nodes and see if any of them write to the attachment.
5213 for (auto elem : node.prev) {
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005214 result |= CheckPreserved(my_data, device, pCreateInfo, elem, attachment, subpass_to_node, depth + 1, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005215 }
5216 // If the attachment was written to by a previous node than this node needs to preserve it.
5217 if (result && depth > 0) {
5218 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Mark Youngb20a6a82016-01-07 15:41:43 -07005219 VkBool32 has_preserved = VK_FALSE;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005220 for (uint32_t j = 0; j < subpass.preserveAttachmentCount; ++j) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005221 if (subpass.pPreserveAttachments[j] == attachment) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005222 has_preserved = VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005223 break;
5224 }
5225 }
Mark Youngb20a6a82016-01-07 15:41:43 -07005226 if (has_preserved == VK_FALSE) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005227 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
Michael Lentineb6986752015-10-06 14:56:18 -07005228 "Attachment %d is used by a later subpass and must be preserved in subpass %d.", attachment, index);
5229 }
5230 }
5231 return result;
5232}
5233
Michael Lentineb4979492015-12-22 11:36:14 -06005234VkBool32 ValidateDependencies(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, const std::vector<DAGNode>& subpass_to_node) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005235 VkBool32 skip_call = VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005236 std::vector<std::vector<uint32_t>> output_attachment_to_subpass(pCreateInfo->attachmentCount);
5237 std::vector<std::vector<uint32_t>> input_attachment_to_subpass(pCreateInfo->attachmentCount);
Michael Lentineb6986752015-10-06 14:56:18 -07005238 // Find for each attachment the subpasses that use them.
5239 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5240 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005241 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005242 input_attachment_to_subpass[subpass.pInputAttachments[j].attachment].push_back(i);
5243 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08005244 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005245 output_attachment_to_subpass[subpass.pColorAttachments[j].attachment].push_back(i);
5246 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005247 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
5248 output_attachment_to_subpass[subpass.pDepthStencilAttachment->attachment].push_back(i);
Michael Lentineb6986752015-10-06 14:56:18 -07005249 }
5250 }
5251 // If there is a dependency needed make sure one exists
5252 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5253 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
5254 // If the attachment is an input then all subpasses that output must have a dependency relationship
Chia-I Wud50a7d72015-10-26 20:48:51 +08005255 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005256 const uint32_t& attachment = subpass.pInputAttachments[j].attachment;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005257 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005258 }
5259 // 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 +08005260 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005261 const uint32_t& attachment = subpass.pColorAttachments[j].attachment;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005262 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
5263 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005264 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005265 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
5266 const uint32_t& attachment = subpass.pDepthStencilAttachment->attachment;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005267 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
5268 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005269 }
5270 }
5271 // Loop through implicit dependencies, if this pass reads make sure the attachment is preserved for all passes after it was written.
5272 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5273 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005274 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005275 CheckPreserved(my_data, device, pCreateInfo, i, subpass.pInputAttachments[j].attachment, subpass_to_node, 0, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005276 }
5277 }
5278 return skip_call;
5279}
5280
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005281VkBool32 ValidateLayouts(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005282 VkBool32 skip = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005283
5284#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
5285 return skip;
5286#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5287
Michael Lentineabc5e922015-10-12 11:30:14 -05005288 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5289 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
5290 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
5291 if (subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL &&
5292 subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) {
5293 if (subpass.pInputAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005294 // TODO: Verify Valid Use in spec. I believe this is allowed (valid) but may not be optimal performance
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005295 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05005296 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
5297 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005298 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05005299 "Layout for input attachment is %d but can only be READ_ONLY_OPTIMAL or GENERAL.", subpass.pInputAttachments[j].attachment);
5300 }
5301 }
5302 }
5303 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
5304 if (subpass.pColorAttachments[j].layout != VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) {
5305 if (subpass.pColorAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005306 // TODO: Verify Valid Use in spec. I believe this is allowed (valid) but may not be optimal performance
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005307 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05005308 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
5309 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005310 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05005311 "Layout for color attachment is %d but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.", subpass.pColorAttachments[j].attachment);
5312 }
5313 }
5314 }
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005315 if ((subpass.pDepthStencilAttachment != NULL) &&
5316 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
Michael Lentineabc5e922015-10-12 11:30:14 -05005317 if (subpass.pDepthStencilAttachment->layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) {
5318 if (subpass.pDepthStencilAttachment->layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005319 // TODO: Verify Valid Use in spec. I believe this is allowed (valid) but may not be optimal performance
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005320 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05005321 "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL.");
5322 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005323 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05005324 "Layout for depth attachment is %d but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL.", subpass.pDepthStencilAttachment->attachment);
5325 }
5326 }
5327 }
5328 }
5329 return skip;
5330}
5331
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005332VkBool32 CreatePassDAG(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, std::vector<DAGNode>& subpass_to_node, std::vector<bool>& has_self_dependency) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005333 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05005334 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5335 DAGNode& subpass_node = subpass_to_node[i];
5336 subpass_node.pass = i;
5337 }
5338 for (uint32_t i = 0; i < pCreateInfo->dependencyCount; ++i) {
5339 const VkSubpassDependency& dependency = pCreateInfo->pDependencies[i];
5340 if (dependency.srcSubpass > dependency.dstSubpass) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005341 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05005342 "Depedency graph must be specified such that an earlier pass cannot depend on a later pass.");
Michael Lentine48930b82015-10-15 17:07:00 -05005343 } else if (dependency.srcSubpass == dependency.dstSubpass) {
5344 has_self_dependency[dependency.srcSubpass] = true;
Michael Lentineabc5e922015-10-12 11:30:14 -05005345 }
5346 subpass_to_node[dependency.dstSubpass].prev.push_back(dependency.srcSubpass);
5347 subpass_to_node[dependency.srcSubpass].next.push_back(dependency.dstSubpass);
5348 }
5349 return skip_call;
5350}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005351// TODOSC : Add intercept of vkCreateShaderModule
Michael Lentineabc5e922015-10-12 11:30:14 -05005352
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005353VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateShaderModule(
5354 VkDevice device,
5355 const VkShaderModuleCreateInfo *pCreateInfo,
5356 const VkAllocationCallbacks* pAllocator,
5357 VkShaderModule *pShaderModule)
5358{
5359 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07005360 VkBool32 skip_call = VK_FALSE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005361 if (!shader_is_spirv(pCreateInfo)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005362 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005363 /* dev */ 0, __LINE__, SHADER_CHECKER_NON_SPIRV_SHADER, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005364 "Shader is not SPIR-V");
5365 }
5366
Mark Youngb20a6a82016-01-07 15:41:43 -07005367 if (VK_FALSE != skip_call)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005368 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005369
5370 VkResult res = my_data->device_dispatch_table->CreateShaderModule(device, pCreateInfo, pAllocator, pShaderModule);
5371
5372 if (res == VK_SUCCESS) {
5373 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005374 my_data->shaderModuleMap[*pShaderModule] = new shader_module(pCreateInfo);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005375 loader_platform_thread_unlock_mutex(&globalLock);
5376 }
5377 return res;
5378}
5379
Chia-I Wu9ab61502015-11-06 06:42:02 +08005380VK_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 -06005381{
Mark Youngb20a6a82016-01-07 15:41:43 -07005382 VkBool32 skip_call = VK_FALSE;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005383 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentineabc5e922015-10-12 11:30:14 -05005384 // Create DAG
Michael Lentine48930b82015-10-15 17:07:00 -05005385 std::vector<bool> has_self_dependency(pCreateInfo->subpassCount);
Michael Lentineabc5e922015-10-12 11:30:14 -05005386 std::vector<DAGNode> subpass_to_node(pCreateInfo->subpassCount);
Michael Lentine48930b82015-10-15 17:07:00 -05005387 skip_call |= CreatePassDAG(dev_data, device, pCreateInfo, subpass_to_node, has_self_dependency);
Michael Lentineabc5e922015-10-12 11:30:14 -05005388 // Validate using DAG
5389 skip_call |= ValidateDependencies(dev_data, device, pCreateInfo, subpass_to_node);
5390 skip_call |= ValidateLayouts(dev_data, device, pCreateInfo);
Mark Youngb20a6a82016-01-07 15:41:43 -07005391 if (VK_FALSE != skip_call) {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005392 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentineb6986752015-10-06 14:56:18 -07005393 }
Chia-I Wuf7458c52015-10-26 21:10:41 +08005394 VkResult result = dev_data->device_dispatch_table->CreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005395 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005396 // TODOSC : Merge in tracking of renderpass from ShaderChecker
Tobin Ehliseba312c2015-04-01 08:40:34 -06005397 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06005398 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +08005399 if (pCreateInfo->pAttachments) {
5400 localRPCI->pAttachments = new VkAttachmentDescription[localRPCI->attachmentCount];
5401 memcpy((void*)localRPCI->pAttachments, pCreateInfo->pAttachments, localRPCI->attachmentCount*sizeof(VkAttachmentDescription));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005402 }
Chia-I Wu08accc62015-07-07 11:50:03 +08005403 if (pCreateInfo->pSubpasses) {
5404 localRPCI->pSubpasses = new VkSubpassDescription[localRPCI->subpassCount];
5405 memcpy((void*)localRPCI->pSubpasses, pCreateInfo->pSubpasses, localRPCI->subpassCount*sizeof(VkSubpassDescription));
5406
5407 for (uint32_t i = 0; i < localRPCI->subpassCount; i++) {
5408 VkSubpassDescription *subpass = (VkSubpassDescription *) &localRPCI->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005409 const uint32_t attachmentCount = subpass->inputAttachmentCount +
5410 subpass->colorAttachmentCount * (1 + (subpass->pResolveAttachments?1:0)) +
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005411 ((subpass->pDepthStencilAttachment) ? 1 : 0) + subpass->preserveAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005412 VkAttachmentReference *attachments = new VkAttachmentReference[attachmentCount];
5413
Cody Northropa505dda2015-08-04 11:16:41 -06005414 memcpy(attachments, subpass->pInputAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005415 sizeof(attachments[0]) * subpass->inputAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005416 subpass->pInputAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005417 attachments += subpass->inputAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005418
Cody Northropa505dda2015-08-04 11:16:41 -06005419 memcpy(attachments, subpass->pColorAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005420 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005421 subpass->pColorAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005422 attachments += subpass->colorAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005423
Cody Northropa505dda2015-08-04 11:16:41 -06005424 if (subpass->pResolveAttachments) {
5425 memcpy(attachments, subpass->pResolveAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005426 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005427 subpass->pResolveAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005428 attachments += subpass->colorAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005429 }
5430
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005431 if (subpass->pDepthStencilAttachment) {
5432 memcpy(attachments, subpass->pDepthStencilAttachment,
5433 sizeof(attachments[0]) * 1);
5434 subpass->pDepthStencilAttachment = attachments;
5435 attachments += 1;
5436 }
5437
Cody Northropa505dda2015-08-04 11:16:41 -06005438 memcpy(attachments, subpass->pPreserveAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005439 sizeof(attachments[0]) * subpass->preserveAttachmentCount);
Jon Ashburnf19916e2016-01-11 13:12:43 -07005440 subpass->pPreserveAttachments = &attachments->attachment;
Chia-I Wu08accc62015-07-07 11:50:03 +08005441 }
Tobin Ehliseba312c2015-04-01 08:40:34 -06005442 }
Chia-I Wu08accc62015-07-07 11:50:03 +08005443 if (pCreateInfo->pDependencies) {
5444 localRPCI->pDependencies = new VkSubpassDependency[localRPCI->dependencyCount];
5445 memcpy((void*)localRPCI->pDependencies, pCreateInfo->pDependencies, localRPCI->dependencyCount*sizeof(VkSubpassDependency));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005446 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005447 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005448 dev_data->renderPassMap[*pRenderPass] = new RENDER_PASS_NODE(localRPCI);
Michael Lentine48930b82015-10-15 17:07:00 -05005449 dev_data->renderPassMap[*pRenderPass]->hasSelfDependency = has_self_dependency;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005450 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehliseba312c2015-04-01 08:40:34 -06005451 }
5452 return result;
5453}
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005454// Free the renderpass shadow
5455static void deleteRenderPasses(layer_data* my_data)
5456{
5457 if (my_data->renderPassMap.size() <= 0)
5458 return;
5459 for (auto ii=my_data->renderPassMap.begin(); ii!=my_data->renderPassMap.end(); ++ii) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005460 const VkRenderPassCreateInfo* pRenderPassInfo = (*ii).second->pCreateInfo;
Michael Lentine48930b82015-10-15 17:07:00 -05005461 if (pRenderPassInfo->pAttachments) {
5462 delete[] pRenderPassInfo->pAttachments;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005463 }
Michael Lentine48930b82015-10-15 17:07:00 -05005464 if (pRenderPassInfo->pSubpasses) {
5465 for (uint32_t i=0; i<pRenderPassInfo->subpassCount; ++i) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005466 // Attachements are all allocated in a block, so just need to
5467 // find the first non-null one to delete
Michael Lentine48930b82015-10-15 17:07:00 -05005468 if (pRenderPassInfo->pSubpasses[i].pInputAttachments) {
5469 delete[] pRenderPassInfo->pSubpasses[i].pInputAttachments;
5470 } else if (pRenderPassInfo->pSubpasses[i].pColorAttachments) {
5471 delete[] pRenderPassInfo->pSubpasses[i].pColorAttachments;
5472 } else if (pRenderPassInfo->pSubpasses[i].pResolveAttachments) {
5473 delete[] pRenderPassInfo->pSubpasses[i].pResolveAttachments;
5474 } else if (pRenderPassInfo->pSubpasses[i].pPreserveAttachments) {
5475 delete[] pRenderPassInfo->pSubpasses[i].pPreserveAttachments;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005476 }
5477 }
Michael Lentine48930b82015-10-15 17:07:00 -05005478 delete[] pRenderPassInfo->pSubpasses;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005479 }
Michael Lentine48930b82015-10-15 17:07:00 -05005480 if (pRenderPassInfo->pDependencies) {
5481 delete[] pRenderPassInfo->pDependencies;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005482 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005483 delete pRenderPassInfo;
Michael Lentine48930b82015-10-15 17:07:00 -05005484 delete (*ii).second;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005485 }
5486 my_data->renderPassMap.clear();
5487}
Michael Lentineabc5e922015-10-12 11:30:14 -05005488
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005489VkBool32 VerifyFramebufferAndRenderPassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005490 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05005491 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5492 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005493 const VkRenderPassCreateInfo* pRenderPassInfo = dev_data->renderPassMap[pRenderPassBegin->renderPass]->pCreateInfo;
Michael Lentineabc5e922015-10-12 11:30:14 -05005494 const VkFramebufferCreateInfo* pFramebufferInfo = dev_data->frameBufferMap[pRenderPassBegin->framebuffer];
5495 if (pRenderPassInfo->attachmentCount != pFramebufferInfo->attachmentCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005496 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05005497 "You cannot start a render pass using a framebuffer with a different number of attachments.");
5498 }
5499 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
5500 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
5501 const VkImage& image = dev_data->imageViewMap[image_view]->image;
5502 auto image_data = pCB->imageLayoutMap.find(image);
5503 if (image_data == pCB->imageLayoutMap.end()) {
5504 pCB->imageLayoutMap[image].initialLayout = pRenderPassInfo->pAttachments[i].initialLayout;
5505 pCB->imageLayoutMap[image].layout = pRenderPassInfo->pAttachments[i].initialLayout;
5506 } else if (pRenderPassInfo->pAttachments[i].initialLayout != image_data->second.layout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005507 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05005508 "You cannot start a render pass using attachment %i where the intial layout differs from the starting layout.", i);
5509 }
5510 }
5511 return skip_call;
5512}
5513
5514void TransitionSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, const int subpass_index) {
5515 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5516 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5517 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
5518 if (render_pass_data == dev_data->renderPassMap.end()) {
5519 return;
5520 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005521 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
Michael Lentineabc5e922015-10-12 11:30:14 -05005522 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
5523 if (framebuffer_data == dev_data->frameBufferMap.end()) {
5524 return;
5525 }
5526 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
5527 const VkSubpassDescription& subpass = pRenderPassInfo->pSubpasses[subpass_index];
5528 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
5529 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pInputAttachments[j].attachment];
5530 auto image_view_data = dev_data->imageViewMap.find(image_view);
5531 if (image_view_data != dev_data->imageViewMap.end()) {
5532 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5533 if (image_layout != pCB->imageLayoutMap.end()) {
5534 image_layout->second.layout = subpass.pInputAttachments[j].layout;
5535 }
5536 }
5537 }
5538 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
5539 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pColorAttachments[j].attachment];
5540 auto image_view_data = dev_data->imageViewMap.find(image_view);
5541 if (image_view_data != dev_data->imageViewMap.end()) {
5542 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5543 if (image_layout != pCB->imageLayoutMap.end()) {
5544 image_layout->second.layout = subpass.pColorAttachments[j].layout;
5545 }
5546 }
5547 }
Michael Lentine3dea6512015-10-28 15:55:18 -07005548 if ((subpass.pDepthStencilAttachment != NULL) &&
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005549 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
Michael Lentineabc5e922015-10-12 11:30:14 -05005550 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pDepthStencilAttachment->attachment];
5551 auto image_view_data = dev_data->imageViewMap.find(image_view);
5552 if (image_view_data != dev_data->imageViewMap.end()) {
5553 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5554 if (image_layout != pCB->imageLayoutMap.end()) {
5555 image_layout->second.layout = subpass.pDepthStencilAttachment->layout;
5556 }
5557 }
5558 }
5559}
5560
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005561VkBool32 validatePrimaryCommandBuffer(const layer_data* my_data, const GLOBAL_CB_NODE* pCB, const std::string& cmd_name) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005562 VkBool32 skip_call = VK_FALSE;
Michael Lentine3dea6512015-10-28 15:55:18 -07005563 if (pCB->createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005564 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER, "DS",
Michael Lentine3dea6512015-10-28 15:55:18 -07005565 "Cannot execute command %s on a secondary command buffer.", cmd_name.c_str());
5566 }
5567 return skip_call;
5568}
5569
Michael Lentineabc5e922015-10-12 11:30:14 -05005570void TransitionFinalSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
5571 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5572 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5573 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
5574 if (render_pass_data == dev_data->renderPassMap.end()) {
5575 return;
5576 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005577 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
Michael Lentineabc5e922015-10-12 11:30:14 -05005578 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
5579 if (framebuffer_data == dev_data->frameBufferMap.end()) {
5580 return;
5581 }
5582 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
5583 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
5584 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
5585 auto image_view_data = dev_data->imageViewMap.find(image_view);
5586 if (image_view_data != dev_data->imageViewMap.end()) {
5587 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5588 if (image_layout != pCB->imageLayoutMap.end()) {
5589 image_layout->second.layout = pRenderPassInfo->pAttachments[i].finalLayout;
5590 }
5591 }
5592 }
5593}
5594
Chia-I Wu9ab61502015-11-06 06:42:02 +08005595VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, VkSubpassContents contents)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005596{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005597 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005598 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5599 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005600 if (pCB) {
Tobin Ehlis259730a2015-06-23 16:13:03 -06005601 if (pRenderPassBegin && pRenderPassBegin->renderPass) {
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005602 skipCall |= VerifyFramebufferAndRenderPassLayouts(commandBuffer, pRenderPassBegin);
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005603 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBeginRenderPass");
Michael Lentine3dea6512015-10-28 15:55:18 -07005604 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdBeginRenderPass");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005605 skipCall |= addCmd(dev_data, pCB, CMD_BEGINRENDERPASS, "vkCmdBeginRenderPass()");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005606 pCB->activeRenderPass = pRenderPassBegin->renderPass;
Michael Lentineabc5e922015-10-12 11:30:14 -05005607 // This is a shallow copy as that is all that is needed for now
5608 pCB->activeRenderPassBeginInfo = *pRenderPassBegin;
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005609 pCB->activeSubpass = 0;
Michael Lentine2e068b22015-12-29 16:05:27 -06005610 pCB->activeSubpassContents = contents;
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005611 pCB->framebuffer = pRenderPassBegin->framebuffer;
Tobin Ehlis502480b2015-06-24 15:53:07 -06005612 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005613 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
Tobin Ehlis259730a2015-06-23 16:13:03 -06005614 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tony Barbourbadda992015-04-06 11:09:26 -06005615 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005616 }
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005617 if (VK_FALSE == skipCall) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005618 dev_data->device_dispatch_table->CmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents);
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005619 // This is a shallow copy as that is all that is needed for now
5620 dev_data->renderPassBeginInfo = *pRenderPassBegin;
5621 dev_data->currentSubpass = 0;
5622 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005623}
5624
Chia-I Wu9ab61502015-11-06 06:42:02 +08005625VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents)
Chia-I Wu08accc62015-07-07 11:50:03 +08005626{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005627 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005628 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5629 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Michael Lentineabc5e922015-10-12 11:30:14 -05005630 TransitionSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo, ++dev_data->currentSubpass);
Chia-I Wu08accc62015-07-07 11:50:03 +08005631 if (pCB) {
Michael Lentine3dea6512015-10-28 15:55:18 -07005632 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdNextSubpass");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005633 skipCall |= addCmd(dev_data, pCB, CMD_NEXTSUBPASS, "vkCmdNextSubpass()");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005634 pCB->activeSubpass++;
Michael Lentine2e068b22015-12-29 16:05:27 -06005635 pCB->activeSubpassContents = contents;
Tony Barbourfc5bb6f2016-01-12 11:16:52 -07005636 TransitionSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo, pCB->activeSubpass);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005637 if (pCB->lastBoundPipeline) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005638 skipCall |= validatePipelineState(dev_data, pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Chia-I Wu08accc62015-07-07 11:50:03 +08005639 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005640 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdNextSubpass");
Chia-I Wu08accc62015-07-07 11:50:03 +08005641 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005642 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005643 dev_data->device_dispatch_table->CmdNextSubpass(commandBuffer, contents);
Chia-I Wu08accc62015-07-07 11:50:03 +08005644}
5645
Chia-I Wu9ab61502015-11-06 06:42:02 +08005646VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndRenderPass(VkCommandBuffer commandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005647{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005648 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005649 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5650 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Michael Lentineabc5e922015-10-12 11:30:14 -05005651 TransitionFinalSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005652 if (pCB) {
Michael Lentine3dea6512015-10-28 15:55:18 -07005653 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdEndRenderpass");
Michael Lentine3dea6512015-10-28 15:55:18 -07005654 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdEndRenderPass");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005655 skipCall |= addCmd(dev_data, pCB, CMD_ENDRENDERPASS, "vkCmdEndRenderPass()");
Michael Lentineabc5e922015-10-12 11:30:14 -05005656 TransitionFinalSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005657 pCB->activeRenderPass = 0;
5658 pCB->activeSubpass = 0;
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005659 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005660 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005661 dev_data->device_dispatch_table->CmdEndRenderPass(commandBuffer);
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005662}
5663
Chia-I Wu9ab61502015-11-06 06:42:02 +08005664VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount, const VkCommandBuffer* pCommandBuffers)
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005665{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005666 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005667 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5668 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005669 if (pCB) {
Tobin Ehlis651d9b02015-12-16 05:01:22 -07005670 // TODO : If secondary CB was not created w/ *_USAGE_SIMULTANEOUS_USE_BIT it cannot be used more than once in given primary CB
5671 // ALSO if secondary w/o this flag is set in primary, then primary must not be pending execution more than once at a time
5672 // 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 -06005673 GLOBAL_CB_NODE* pSubCB = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005674 for (uint32_t i=0; i<commandBuffersCount; i++) {
5675 pSubCB = getCBNode(dev_data, pCommandBuffers[i]);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06005676 if (!pSubCB) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005677 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_SECONDARY_COMMAND_BUFFER, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005678 "vkCmdExecuteCommands() called w/ invalid Cmd Buffer %p in element %u of pCommandBuffers array.", (void*)pCommandBuffers[i], i);
5679 } else if (VK_COMMAND_BUFFER_LEVEL_PRIMARY == pSubCB->createInfo.level) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005680 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_SECONDARY_COMMAND_BUFFER, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005681 "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 -07005682 } else if (pCB->activeRenderPass) { // Secondary CB w/i RenderPass must have *CONTINUE_BIT set
5683 if (!(pSubCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005684 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], __LINE__, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
Tobin Ehlis651d9b02015-12-16 05:01:22 -07005685 "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);
5686 }
5687 string errorString = "";
Jon Ashburnf19916e2016-01-11 13:12:43 -07005688 if (!verify_renderpass_compatibility(dev_data, pCB->activeRenderPass, pSubCB->beginInfo.pInheritanceInfo->renderPass, errorString)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005689 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], __LINE__, DRAWSTATE_RENDERPASS_INCOMPATIBLE, "DS",
Tobin Ehlis651d9b02015-12-16 05:01:22 -07005690 "vkCmdExecuteCommands(): Secondary Command Buffer (%p) w/ render pass (%#" PRIxLEAST64 ") is incompatible w/ primary command buffer (%p) w/ render pass (%#" PRIxLEAST64 ") due to: %s",
Jon Ashburnf19916e2016-01-11 13:12:43 -07005691 (void*)pCommandBuffers[i], (uint64_t)pSubCB->beginInfo.pInheritanceInfo->renderPass, (void*)commandBuffer, (uint64_t)pCB->activeRenderPass, errorString.c_str());
Tobin Ehlis651d9b02015-12-16 05:01:22 -07005692 }
5693 // If framebuffer for secondary CB is not NULL, then it must match FB from vkCmdBeginRenderPass()
5694 // that this CB will be executed in AND framebuffer must have been created w/ RP compatible w/ renderpass
Jon Ashburnf19916e2016-01-11 13:12:43 -07005695 if (pSubCB->beginInfo.pInheritanceInfo->framebuffer) {
5696 if (pSubCB->beginInfo.pInheritanceInfo->framebuffer != pCB->activeRenderPassBeginInfo.framebuffer) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005697 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], __LINE__, DRAWSTATE_FRAMEBUFFER_INCOMPATIBLE, "DS",
Tobin Ehlis651d9b02015-12-16 05:01:22 -07005698 "vkCmdExecuteCommands(): Secondary Command Buffer (%p) references framebuffer (%#" PRIxLEAST64 ") that does not match framebuffer (%#" PRIxLEAST64 ") in active renderpass (%#" PRIxLEAST64 ").",
Jon Ashburnf19916e2016-01-11 13:12:43 -07005699 (void*)pCommandBuffers[i], (uint64_t)pSubCB->beginInfo.pInheritanceInfo->framebuffer, (uint64_t)pCB->activeRenderPassBeginInfo.framebuffer, (uint64_t)pCB->activeRenderPass);
Tobin Ehlis651d9b02015-12-16 05:01:22 -07005700 }
5701 }
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06005702 }
5703 }
Michael Lentine3dea6512015-10-28 15:55:18 -07005704 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdExecuteComands");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005705 skipCall |= addCmd(dev_data, pCB, CMD_EXECUTECOMMANDS, "vkCmdExecuteComands()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005706 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005707 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005708 dev_data->device_dispatch_table->CmdExecuteCommands(commandBuffer, commandBuffersCount, pCommandBuffers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005709}
5710
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005711VkBool32 ValidateMapImageLayouts(VkDevice device, VkDeviceMemory mem) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005712 VkBool32 skip_call = VK_FALSE;
Michael Lentine7b236262015-10-23 12:41:44 -07005713 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5714 auto mem_data = dev_data->memImageMap.find(mem);
5715 if (mem_data != dev_data->memImageMap.end()) {
5716 auto image_data = dev_data->imageLayoutMap.find(mem_data->second);
5717 if (image_data != dev_data->imageLayoutMap.end()) {
5718 if (image_data->second->layout != VK_IMAGE_LAYOUT_PREINITIALIZED && image_data->second->layout != VK_IMAGE_LAYOUT_GENERAL) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005719 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentine7b236262015-10-23 12:41:44 -07005720 "Cannot map an image with layout %d. Only GENERAL or PREINITIALIZED are supported.", image_data->second->layout);
5721 }
5722 }
5723 }
5724 return skip_call;
5725}
5726
Chia-I Wu9ab61502015-11-06 06:42:02 +08005727VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkMapMemory(
Michael Lentine7b236262015-10-23 12:41:44 -07005728 VkDevice device,
5729 VkDeviceMemory mem,
5730 VkDeviceSize offset,
5731 VkDeviceSize size,
5732 VkFlags flags,
5733 void **ppData)
5734{
5735 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005736
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005737 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005738#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
5739 skip_call = ValidateMapImageLayouts(device, mem);
5740#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5741
Michael Lentine7b236262015-10-23 12:41:44 -07005742 if (VK_FALSE == skip_call) {
5743 return dev_data->device_dispatch_table->MapMemory(device, mem, offset, size, flags, ppData);
5744 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005745 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine7b236262015-10-23 12:41:44 -07005746}
5747
Chia-I Wu9ab61502015-11-06 06:42:02 +08005748VKAPI_ATTR VkResult VKAPI_CALL vkBindImageMemory(
Michael Lentine7b236262015-10-23 12:41:44 -07005749 VkDevice device,
5750 VkImage image,
5751 VkDeviceMemory mem,
5752 VkDeviceSize memOffset)
5753{
5754 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5755 VkResult result = dev_data->device_dispatch_table->BindImageMemory(device, image, mem, memOffset);
5756 loader_platform_thread_lock_mutex(&globalLock);
5757 dev_data->memImageMap[mem] = image;
5758 loader_platform_thread_unlock_mutex(&globalLock);
5759 return result;
5760}
5761
Michael Lentineb887b0a2015-12-29 14:12:11 -06005762
5763VKAPI_ATTR VkResult VKAPI_CALL vkSetEvent(VkDevice device, VkEvent event) {
5764 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5765 dev_data->eventMap[event].needsSignaled = false;
5766 VkResult result = dev_data->device_dispatch_table->SetEvent(device, event);
5767 return result;
5768}
5769
Michael Lentine15a47882016-01-06 10:05:48 -06005770VKAPI_ATTR VkResult VKAPI_CALL vkQueueBindSparse(
5771 VkQueue queue,
5772 uint32_t bindInfoCount,
5773 const VkBindSparseInfo* pBindInfo,
5774 VkFence fence)
5775{
5776 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07005777 VkBool32 skip_call = VK_FALSE;
Michael Lentine15a47882016-01-06 10:05:48 -06005778
5779 for (uint32_t bindIdx=0; bindIdx < bindInfoCount; ++bindIdx) {
5780 const VkBindSparseInfo& bindInfo = pBindInfo[bindIdx];
5781 for (uint32_t i=0; i < bindInfo.waitSemaphoreCount; ++i) {
5782 if (dev_data->semaphoreSignaledMap[bindInfo.pWaitSemaphores[i]]) {
5783 dev_data->semaphoreSignaledMap[bindInfo.pWaitSemaphores[i]] = 0;
5784 } else {
5785 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_QUEUE_FORWARD_PROGRESS, "DS",
5786 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
5787 reinterpret_cast<uint64_t>(queue), reinterpret_cast<uint64_t>(bindInfo.pWaitSemaphores[i]));
5788 }
5789 }
5790 for (uint32_t i=0; i < bindInfo.signalSemaphoreCount; ++i) {
5791 dev_data->semaphoreSignaledMap[bindInfo.pSignalSemaphores[i]] = 1;
5792 }
5793 }
5794
Mark Youngb20a6a82016-01-07 15:41:43 -07005795 if (VK_FALSE == skip_call)
Michael Lentine15a47882016-01-06 10:05:48 -06005796 return dev_data->device_dispatch_table->QueueBindSparse(queue, bindInfoCount, pBindInfo, fence);
Mark Youngb20a6a82016-01-07 15:41:43 -07005797 else
5798 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine15a47882016-01-06 10:05:48 -06005799}
5800
5801VKAPI_ATTR VkResult VKAPI_CALL vkCreateSemaphore(
5802 VkDevice device,
5803 const VkSemaphoreCreateInfo* pCreateInfo,
5804 const VkAllocationCallbacks* pAllocator,
5805 VkSemaphore* pSemaphore)
5806{
5807 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5808 VkResult result = dev_data->device_dispatch_table->CreateSemaphore(device, pCreateInfo, pAllocator, pSemaphore);
5809 if (result == VK_SUCCESS) {
5810 dev_data->semaphoreSignaledMap[*pSemaphore] = 0;
5811 }
Tobin Ehlis51b78af2016-01-06 10:27:47 -07005812 return result;
Michael Lentine15a47882016-01-06 10:05:48 -06005813}
5814
Chia-I Wu9ab61502015-11-06 06:42:02 +08005815VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(
Michael Lentineabc5e922015-10-12 11:30:14 -05005816 VkDevice device,
5817 const VkSwapchainCreateInfoKHR *pCreateInfo,
Ian Elliott05846062015-11-20 14:13:17 -07005818 const VkAllocationCallbacks *pAllocator,
Michael Lentineabc5e922015-10-12 11:30:14 -05005819 VkSwapchainKHR *pSwapchain)
5820{
5821 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott05846062015-11-20 14:13:17 -07005822 VkResult result = dev_data->device_dispatch_table->CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
Michael Lentineabc5e922015-10-12 11:30:14 -05005823
5824 if (VK_SUCCESS == result) {
5825 SWAPCHAIN_NODE *swapchain_data = new SWAPCHAIN_NODE;
5826 loader_platform_thread_lock_mutex(&globalLock);
5827 dev_data->device_extensions.swapchainMap[*pSwapchain] = swapchain_data;
5828 loader_platform_thread_unlock_mutex(&globalLock);
5829 }
5830
5831 return result;
5832}
5833
Ian Elliott05846062015-11-20 14:13:17 -07005834VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR(
Michael Lentineabc5e922015-10-12 11:30:14 -05005835 VkDevice device,
Ian Elliott05846062015-11-20 14:13:17 -07005836 VkSwapchainKHR swapchain,
5837 const VkAllocationCallbacks *pAllocator)
Michael Lentineabc5e922015-10-12 11:30:14 -05005838{
5839 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentineabc5e922015-10-12 11:30:14 -05005840
5841 loader_platform_thread_lock_mutex(&globalLock);
5842 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(swapchain);
5843 if (swapchain_data != dev_data->device_extensions.swapchainMap.end()) {
5844 if (swapchain_data->second->images.size() > 0) {
5845 for (auto swapchain_image : swapchain_data->second->images) {
5846 auto image_item = dev_data->imageLayoutMap.find(swapchain_image);
5847 if (image_item != dev_data->imageLayoutMap.end())
5848 dev_data->imageLayoutMap.erase(image_item);
5849 }
5850 }
5851 delete swapchain_data->second;
5852 dev_data->device_extensions.swapchainMap.erase(swapchain);
5853 }
5854 loader_platform_thread_unlock_mutex(&globalLock);
Ian Elliott05846062015-11-20 14:13:17 -07005855 return dev_data->device_dispatch_table->DestroySwapchainKHR(device, swapchain, pAllocator);
Michael Lentineabc5e922015-10-12 11:30:14 -05005856}
5857
Chia-I Wu9ab61502015-11-06 06:42:02 +08005858VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR(
Michael Lentineabc5e922015-10-12 11:30:14 -05005859 VkDevice device,
5860 VkSwapchainKHR swapchain,
5861 uint32_t* pCount,
5862 VkImage* pSwapchainImages)
5863{
5864 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5865 VkResult result = dev_data->device_dispatch_table->GetSwapchainImagesKHR(device, swapchain, pCount, pSwapchainImages);
5866
5867 if (result == VK_SUCCESS && pSwapchainImages != NULL) {
5868 // This should never happen and is checked by param checker.
5869 if (!pCount) return result;
5870 for (uint32_t i = 0; i < *pCount; ++i) {
5871 IMAGE_NODE* image_node = new IMAGE_NODE;
5872 image_node->layout = VK_IMAGE_LAYOUT_UNDEFINED;
5873 loader_platform_thread_lock_mutex(&globalLock);
5874 dev_data->device_extensions.swapchainMap[swapchain]->images.push_back(pSwapchainImages[i]);
5875 dev_data->imageLayoutMap[pSwapchainImages[i]] = image_node;
5876 loader_platform_thread_unlock_mutex(&globalLock);
5877 }
5878 }
5879 return result;
5880}
5881
Ian Elliott05846062015-11-20 14:13:17 -07005882VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo)
Michael Lentineabc5e922015-10-12 11:30:14 -05005883{
5884 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07005885 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05005886
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005887#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentineabc5e922015-10-12 11:30:14 -05005888 if (pPresentInfo) {
Michael Lentine15a47882016-01-06 10:05:48 -06005889 for (uint32_t i=0; i < pPresentInfo->waitSemaphoreCount; ++i) {
5890 if (dev_data->semaphoreSignaledMap[pPresentInfo->pWaitSemaphores[i]]) {
5891 dev_data->semaphoreSignaledMap[pPresentInfo->pWaitSemaphores[i]] = 0;
5892 } else {
5893 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_QUEUE_FORWARD_PROGRESS, "DS",
5894 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
5895 reinterpret_cast<uint64_t>(queue), reinterpret_cast<uint64_t>(pPresentInfo->pWaitSemaphores[i]));
5896 }
5897 }
Michael Lentineabc5e922015-10-12 11:30:14 -05005898 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
Ian Elliott05846062015-11-20 14:13:17 -07005899 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(pPresentInfo->pSwapchains[i]);
5900 if (swapchain_data != dev_data->device_extensions.swapchainMap.end() && pPresentInfo->pImageIndices[i] < swapchain_data->second->images.size()) {
5901 VkImage image = swapchain_data->second->images[pPresentInfo->pImageIndices[i]];
Michael Lentineabc5e922015-10-12 11:30:14 -05005902 auto image_data = dev_data->imageLayoutMap.find(image);
5903 if (image_data != dev_data->imageLayoutMap.end()) {
Ian Elliott05846062015-11-20 14:13:17 -07005904 if (image_data->second->layout != VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005905 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT, (uint64_t)queue, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05005906 "Images passed to present must be in layout PRESENT_SOURCE_KHR but is in %d", image_data->second->layout);
5907 }
5908 }
5909 }
5910 }
5911 }
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005912#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentineabc5e922015-10-12 11:30:14 -05005913
5914 if (VK_FALSE == skip_call)
5915 return dev_data->device_dispatch_table->QueuePresentKHR(queue, pPresentInfo);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005916 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentineabc5e922015-10-12 11:30:14 -05005917}
5918
Michael Lentine15a47882016-01-06 10:05:48 -06005919VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImageKHR(
5920 VkDevice device,
5921 VkSwapchainKHR swapchain,
5922 uint64_t timeout,
5923 VkSemaphore semaphore,
5924 VkFence fence,
5925 uint32_t* pImageIndex)
5926{
5927 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5928 VkResult result = dev_data->device_dispatch_table->AcquireNextImageKHR(device, swapchain, timeout, semaphore, fence, pImageIndex);
5929 dev_data->semaphoreSignaledMap[semaphore] = 1;
Tobin Ehlis51b78af2016-01-06 10:27:47 -07005930 return result;
Michael Lentine15a47882016-01-06 10:05:48 -06005931}
5932
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005933VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(
5934 VkInstance instance,
5935 const VkDebugReportCallbackCreateInfoEXT* pCreateInfo,
5936 const VkAllocationCallbacks* pAllocator,
5937 VkDebugReportCallbackEXT* pMsgCallback)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005938{
Tobin Ehlis0b632332015-10-07 09:38:40 -06005939 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07005940 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005941 VkResult res = pTable->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06005942 if (VK_SUCCESS == res) {
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07005943 res = layer_create_msg_callback(my_data->report_data, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06005944 }
5945 return res;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005946}
5947
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005948VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07005949 VkInstance instance,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005950 VkDebugReportCallbackEXT msgCallback,
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07005951 const VkAllocationCallbacks* pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005952{
Tobin Ehlis0b632332015-10-07 09:38:40 -06005953 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07005954 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005955 pTable->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07005956 layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005957}
5958
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005959VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDebugReportMessageEXT(
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07005960 VkInstance instance,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005961 VkDebugReportFlagsEXT flags,
5962 VkDebugReportObjectTypeEXT objType,
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07005963 uint64_t object,
5964 size_t location,
5965 int32_t msgCode,
5966 const char* pLayerPrefix,
5967 const char* pMsg)
5968{
5969 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005970 my_data->instance_dispatch_table->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg);
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07005971}
5972
Chia-I Wu9ab61502015-11-06 06:42:02 +08005973VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerBegin(VkCommandBuffer commandBuffer, const char* pMarker)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005974{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005975 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005976 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5977 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis0b632332015-10-07 09:38:40 -06005978 if (!dev_data->device_extensions.debug_marker_enabled) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005979 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, __LINE__, DRAWSTATE_INVALID_EXTENSION, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06005980 "Attempt to use CmdDbgMarkerBegin but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06005981 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06005982 } else if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005983 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKERBEGIN, "vkCmdDbgMarkerBegin()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005984 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005985 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005986 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerBegin(commandBuffer, pMarker);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005987}
5988
Chia-I Wu9ab61502015-11-06 06:42:02 +08005989VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerEnd(VkCommandBuffer commandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005990{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005991 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005992 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5993 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis0b632332015-10-07 09:38:40 -06005994 if (!dev_data->device_extensions.debug_marker_enabled) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005995 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, __LINE__, DRAWSTATE_INVALID_EXTENSION, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06005996 "Attempt to use CmdDbgMarkerEnd but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06005997 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06005998 } else if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005999 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKEREND, "vkCmdDbgMarkerEnd()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006000 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006001 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006002 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerEnd(commandBuffer);
Jon Ashburneab34492015-06-01 09:37:38 -06006003}
6004
Chia-I Wu9ab61502015-11-06 06:42:02 +08006005VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006006{
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06006007 if (dev == NULL)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006008 return NULL;
Jon Ashburn3950e1b2015-05-20 09:00:28 -06006009
Tobin Ehlis0b632332015-10-07 09:38:40 -06006010 layer_data *dev_data;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006011 /* loader uses this to force layer initialization; device object is wrapped */
6012 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
Tobin Ehlis0b632332015-10-07 09:38:40 -06006013 VkBaseLayerObject* wrapped_dev = (VkBaseLayerObject*) dev;
6014 dev_data = get_my_data_ptr(get_dispatch_key(wrapped_dev->baseObject), layer_data_map);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06006015 dev_data->device_dispatch_table = new VkLayerDispatchTable;
6016 layer_initialize_dispatch_table(dev_data->device_dispatch_table, wrapped_dev);
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006017 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006018 }
Tobin Ehlis0b632332015-10-07 09:38:40 -06006019 dev_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map);
Courtney Goeltzenleuchterca173b82015-06-25 18:01:43 -06006020 if (!strcmp(funcName, "vkCreateDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006021 return (PFN_vkVoidFunction) vkCreateDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006022 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006023 return (PFN_vkVoidFunction) vkDestroyDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006024 if (!strcmp(funcName, "vkQueueSubmit"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006025 return (PFN_vkVoidFunction) vkQueueSubmit;
Michael Lentine700b0aa2015-10-30 17:57:32 -07006026 if (!strcmp(funcName, "vkWaitForFences"))
6027 return (PFN_vkVoidFunction) vkWaitForFences;
6028 if (!strcmp(funcName, "vkGetFenceStatus"))
6029 return (PFN_vkVoidFunction) vkGetFenceStatus;
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07006030 if (!strcmp(funcName, "vkQueueWaitIdle"))
6031 return (PFN_vkVoidFunction) vkQueueWaitIdle;
6032 if (!strcmp(funcName, "vkDeviceWaitIdle"))
6033 return (PFN_vkVoidFunction) vkDeviceWaitIdle;
Michael Lentine700b0aa2015-10-30 17:57:32 -07006034 if (!strcmp(funcName, "vkGetDeviceQueue"))
6035 return (PFN_vkVoidFunction) vkGetDeviceQueue;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006036 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006037 return (PFN_vkVoidFunction) vkDestroyInstance;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006038 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006039 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006040 if (!strcmp(funcName, "vkDestroyFence"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006041 return (PFN_vkVoidFunction) vkDestroyFence;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006042 if (!strcmp(funcName, "vkDestroySemaphore"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006043 return (PFN_vkVoidFunction) vkDestroySemaphore;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006044 if (!strcmp(funcName, "vkDestroyEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006045 return (PFN_vkVoidFunction) vkDestroyEvent;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006046 if (!strcmp(funcName, "vkDestroyQueryPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006047 return (PFN_vkVoidFunction) vkDestroyQueryPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006048 if (!strcmp(funcName, "vkDestroyBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006049 return (PFN_vkVoidFunction) vkDestroyBuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006050 if (!strcmp(funcName, "vkDestroyBufferView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006051 return (PFN_vkVoidFunction) vkDestroyBufferView;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006052 if (!strcmp(funcName, "vkDestroyImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006053 return (PFN_vkVoidFunction) vkDestroyImage;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006054 if (!strcmp(funcName, "vkDestroyImageView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006055 return (PFN_vkVoidFunction) vkDestroyImageView;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006056 if (!strcmp(funcName, "vkDestroyShaderModule"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006057 return (PFN_vkVoidFunction) vkDestroyShaderModule;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006058 if (!strcmp(funcName, "vkDestroyPipeline"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006059 return (PFN_vkVoidFunction) vkDestroyPipeline;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006060 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006061 return (PFN_vkVoidFunction) vkDestroyPipelineLayout;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006062 if (!strcmp(funcName, "vkDestroySampler"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006063 return (PFN_vkVoidFunction) vkDestroySampler;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006064 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006065 return (PFN_vkVoidFunction) vkDestroyDescriptorSetLayout;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006066 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006067 return (PFN_vkVoidFunction) vkDestroyDescriptorPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006068 if (!strcmp(funcName, "vkDestroyFramebuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006069 return (PFN_vkVoidFunction) vkDestroyFramebuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006070 if (!strcmp(funcName, "vkDestroyRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006071 return (PFN_vkVoidFunction) vkDestroyRenderPass;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006072 if (!strcmp(funcName, "vkCreateBuffer"))
6073 return (PFN_vkVoidFunction) vkCreateBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006074 if (!strcmp(funcName, "vkCreateBufferView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006075 return (PFN_vkVoidFunction) vkCreateBufferView;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006076 if (!strcmp(funcName, "vkCreateImage"))
6077 return (PFN_vkVoidFunction) vkCreateImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006078 if (!strcmp(funcName, "vkCreateImageView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006079 return (PFN_vkVoidFunction) vkCreateImageView;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006080 if (!strcmp(funcName, "CreatePipelineCache"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006081 return (PFN_vkVoidFunction) vkCreatePipelineCache;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006082 if (!strcmp(funcName, "DestroyPipelineCache"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006083 return (PFN_vkVoidFunction) vkDestroyPipelineCache;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006084 if (!strcmp(funcName, "GetPipelineCacheData"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006085 return (PFN_vkVoidFunction) vkGetPipelineCacheData;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006086 if (!strcmp(funcName, "MergePipelineCaches"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006087 return (PFN_vkVoidFunction) vkMergePipelineCaches;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006088 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006089 return (PFN_vkVoidFunction) vkCreateGraphicsPipelines;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07006090 if (!strcmp(funcName, "vkCreateComputePipelines"))
6091 return (PFN_vkVoidFunction) vkCreateComputePipelines;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006092 if (!strcmp(funcName, "vkCreateSampler"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006093 return (PFN_vkVoidFunction) vkCreateSampler;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006094 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006095 return (PFN_vkVoidFunction) vkCreateDescriptorSetLayout;
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05006096 if (!strcmp(funcName, "vkCreatePipelineLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006097 return (PFN_vkVoidFunction) vkCreatePipelineLayout;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006098 if (!strcmp(funcName, "vkCreateDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006099 return (PFN_vkVoidFunction) vkCreateDescriptorPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006100 if (!strcmp(funcName, "vkResetDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006101 return (PFN_vkVoidFunction) vkResetDescriptorPool;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006102 if (!strcmp(funcName, "vkAllocateDescriptorSets"))
6103 return (PFN_vkVoidFunction) vkAllocateDescriptorSets;
Tobin Ehlise735c692015-10-08 13:13:50 -06006104 if (!strcmp(funcName, "vkFreeDescriptorSets"))
6105 return (PFN_vkVoidFunction) vkFreeDescriptorSets;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08006106 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006107 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
Mark Lobodzinski39298632015-11-18 08:38:27 -07006108 if (!strcmp(funcName, "vkCreateCommandPool"))
6109 return (PFN_vkVoidFunction) vkCreateCommandPool;
6110 if (!strcmp(funcName, "vkDestroyCommandPool"))
6111 return (PFN_vkVoidFunction) vkDestroyCommandPool;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006112 if (!strcmp(funcName, "vkResetCommandPool"))
6113 return (PFN_vkVoidFunction) vkResetCommandPool;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006114 if (!strcmp(funcName, "vkAllocateCommandBuffers"))
6115 return (PFN_vkVoidFunction) vkAllocateCommandBuffers;
Mark Lobodzinski39298632015-11-18 08:38:27 -07006116 if (!strcmp(funcName, "vkFreeCommandBuffers"))
6117 return (PFN_vkVoidFunction) vkFreeCommandBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006118 if (!strcmp(funcName, "vkBeginCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006119 return (PFN_vkVoidFunction) vkBeginCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006120 if (!strcmp(funcName, "vkEndCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006121 return (PFN_vkVoidFunction) vkEndCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006122 if (!strcmp(funcName, "vkResetCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006123 return (PFN_vkVoidFunction) vkResetCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006124 if (!strcmp(funcName, "vkCmdBindPipeline"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006125 return (PFN_vkVoidFunction) vkCmdBindPipeline;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06006126 if (!strcmp(funcName, "vkCmdSetViewport"))
6127 return (PFN_vkVoidFunction) vkCmdSetViewport;
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06006128 if (!strcmp(funcName, "vkCmdSetScissor"))
6129 return (PFN_vkVoidFunction) vkCmdSetScissor;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06006130 if (!strcmp(funcName, "vkCmdSetLineWidth"))
6131 return (PFN_vkVoidFunction) vkCmdSetLineWidth;
6132 if (!strcmp(funcName, "vkCmdSetDepthBias"))
6133 return (PFN_vkVoidFunction) vkCmdSetDepthBias;
6134 if (!strcmp(funcName, "vkCmdSetBlendConstants"))
6135 return (PFN_vkVoidFunction) vkCmdSetBlendConstants;
6136 if (!strcmp(funcName, "vkCmdSetDepthBounds"))
6137 return (PFN_vkVoidFunction) vkCmdSetDepthBounds;
6138 if (!strcmp(funcName, "vkCmdSetStencilCompareMask"))
6139 return (PFN_vkVoidFunction) vkCmdSetStencilCompareMask;
6140 if (!strcmp(funcName, "vkCmdSetStencilWriteMask"))
6141 return (PFN_vkVoidFunction) vkCmdSetStencilWriteMask;
6142 if (!strcmp(funcName, "vkCmdSetStencilReference"))
6143 return (PFN_vkVoidFunction) vkCmdSetStencilReference;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006144 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006145 return (PFN_vkVoidFunction) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06006146 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006147 return (PFN_vkVoidFunction) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006148 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006149 return (PFN_vkVoidFunction) vkCmdBindIndexBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006150 if (!strcmp(funcName, "vkCmdDraw"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006151 return (PFN_vkVoidFunction) vkCmdDraw;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006152 if (!strcmp(funcName, "vkCmdDrawIndexed"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006153 return (PFN_vkVoidFunction) vkCmdDrawIndexed;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006154 if (!strcmp(funcName, "vkCmdDrawIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006155 return (PFN_vkVoidFunction) vkCmdDrawIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006156 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006157 return (PFN_vkVoidFunction) vkCmdDrawIndexedIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006158 if (!strcmp(funcName, "vkCmdDispatch"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006159 return (PFN_vkVoidFunction) vkCmdDispatch;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006160 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006161 return (PFN_vkVoidFunction) vkCmdDispatchIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006162 if (!strcmp(funcName, "vkCmdCopyBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006163 return (PFN_vkVoidFunction) vkCmdCopyBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006164 if (!strcmp(funcName, "vkCmdCopyImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006165 return (PFN_vkVoidFunction) vkCmdCopyImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006166 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006167 return (PFN_vkVoidFunction) vkCmdCopyBufferToImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006168 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006169 return (PFN_vkVoidFunction) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006170 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006171 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006172 if (!strcmp(funcName, "vkCmdFillBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006173 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006174 if (!strcmp(funcName, "vkCmdClearColorImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006175 return (PFN_vkVoidFunction) vkCmdClearColorImage;
Chris Forbesd9be82b2015-06-22 17:21:59 +12006176 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006177 return (PFN_vkVoidFunction) vkCmdClearDepthStencilImage;
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06006178 if (!strcmp(funcName, "vkCmdClearAttachments"))
6179 return (PFN_vkVoidFunction) vkCmdClearAttachments;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006180 if (!strcmp(funcName, "vkCmdResolveImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006181 return (PFN_vkVoidFunction) vkCmdResolveImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006182 if (!strcmp(funcName, "vkCmdSetEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006183 return (PFN_vkVoidFunction) vkCmdSetEvent;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006184 if (!strcmp(funcName, "vkCmdResetEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006185 return (PFN_vkVoidFunction) vkCmdResetEvent;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006186 if (!strcmp(funcName, "vkCmdWaitEvents"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006187 return (PFN_vkVoidFunction) vkCmdWaitEvents;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006188 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006189 return (PFN_vkVoidFunction) vkCmdPipelineBarrier;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006190 if (!strcmp(funcName, "vkCmdBeginQuery"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006191 return (PFN_vkVoidFunction) vkCmdBeginQuery;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006192 if (!strcmp(funcName, "vkCmdEndQuery"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006193 return (PFN_vkVoidFunction) vkCmdEndQuery;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006194 if (!strcmp(funcName, "vkCmdResetQueryPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006195 return (PFN_vkVoidFunction) vkCmdResetQueryPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006196 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006197 return (PFN_vkVoidFunction) vkCmdWriteTimestamp;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006198 if (!strcmp(funcName, "vkCreateFramebuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006199 return (PFN_vkVoidFunction) vkCreateFramebuffer;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006200 if (!strcmp(funcName, "vkCreateShaderModule"))
6201 return (PFN_vkVoidFunction) vkCreateShaderModule;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006202 if (!strcmp(funcName, "vkCreateRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006203 return (PFN_vkVoidFunction) vkCreateRenderPass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006204 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006205 return (PFN_vkVoidFunction) vkCmdBeginRenderPass;
Chia-I Wu08accc62015-07-07 11:50:03 +08006206 if (!strcmp(funcName, "vkCmdNextSubpass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006207 return (PFN_vkVoidFunction) vkCmdNextSubpass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006208 if (!strcmp(funcName, "vkCmdEndRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006209 return (PFN_vkVoidFunction) vkCmdEndRenderPass;
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06006210 if (!strcmp(funcName, "vkCmdExecuteCommands"))
6211 return (PFN_vkVoidFunction) vkCmdExecuteCommands;
Michael Lentineb887b0a2015-12-29 14:12:11 -06006212 if (!strcmp(funcName, "vkSetEvent"))
6213 return (PFN_vkVoidFunction) vkSetEvent;
Michael Lentine7b236262015-10-23 12:41:44 -07006214 if (!strcmp(funcName, "vkMapMemory"))
6215 return (PFN_vkVoidFunction) vkMapMemory;
Michael Lentineb887b0a2015-12-29 14:12:11 -06006216 if (!strcmp(funcName, "vkGetQueryPoolResults"))
6217 return (PFN_vkVoidFunction) vkGetQueryPoolResults;
Michael Lentine15a47882016-01-06 10:05:48 -06006218 if (!strcmp(funcName, "vkBindImageMemory"))
6219 return (PFN_vkVoidFunction) vkBindImageMemory;
6220 if (!strcmp(funcName, "vkQueueBindSparse"))
6221 return (PFN_vkVoidFunction) vkQueueBindSparse;
6222 if (!strcmp(funcName, "vkCreateSemaphore"))
6223 return (PFN_vkVoidFunction) vkCreateSemaphore;
Jon Ashburneab34492015-06-01 09:37:38 -06006224
Michael Lentineabc5e922015-10-12 11:30:14 -05006225 if (dev_data->device_extensions.wsi_enabled)
6226 {
6227 if (!strcmp(funcName, "vkCreateSwapchainKHR"))
6228 return (PFN_vkVoidFunction) vkCreateSwapchainKHR;
6229 if (!strcmp(funcName, "vkDestroySwapchainKHR"))
6230 return (PFN_vkVoidFunction) vkDestroySwapchainKHR;
6231 if (!strcmp(funcName, "vkGetSwapchainImagesKHR"))
6232 return (PFN_vkVoidFunction) vkGetSwapchainImagesKHR;
Michael Lentine15a47882016-01-06 10:05:48 -06006233 if (!strcmp(funcName, "vkAcquireNextImageKHR"))
6234 return (PFN_vkVoidFunction) vkAcquireNextImageKHR;
Michael Lentineabc5e922015-10-12 11:30:14 -05006235 if (!strcmp(funcName, "vkQueuePresentKHR"))
6236 return (PFN_vkVoidFunction) vkQueuePresentKHR;
6237 }
6238
Tobin Ehlis0b632332015-10-07 09:38:40 -06006239 VkLayerDispatchTable* pTable = dev_data->device_dispatch_table;
6240 if (dev_data->device_extensions.debug_marker_enabled)
Jon Ashburn8fd08252015-05-28 16:25:02 -06006241 {
Jon Ashburn747f2b62015-06-18 15:02:58 -06006242 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006243 return (PFN_vkVoidFunction) vkCmdDbgMarkerBegin;
Jon Ashburn747f2b62015-06-18 15:02:58 -06006244 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006245 return (PFN_vkVoidFunction) vkCmdDbgMarkerEnd;
Jon Ashburneab34492015-06-01 09:37:38 -06006246 }
6247 {
Jon Ashburn8fd08252015-05-28 16:25:02 -06006248 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006249 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006250 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburnf6b33db2015-05-05 14:22:52 -06006251 }
6252}
6253
Chia-I Wu9ab61502015-11-06 06:42:02 +08006254VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Jon Ashburnf6b33db2015-05-05 14:22:52 -06006255{
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006256 PFN_vkVoidFunction fptr;
Jon Ashburnf6b33db2015-05-05 14:22:52 -06006257 if (instance == NULL)
6258 return NULL;
6259
Tobin Ehlis0b632332015-10-07 09:38:40 -06006260 layer_data* my_data;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006261 /* loader uses this to force layer initialization; instance object is wrapped */
6262 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
Tobin Ehlis0b632332015-10-07 09:38:40 -06006263 VkBaseLayerObject* wrapped_inst = (VkBaseLayerObject*) instance;
6264 my_data = get_my_data_ptr(get_dispatch_key(wrapped_inst->baseObject), layer_data_map);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06006265 my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
6266 layer_init_instance_dispatch_table(my_data->instance_dispatch_table, wrapped_inst);
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006267 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006268 }
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06006269 if (!strcmp(funcName, "vkCreateInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006270 return (PFN_vkVoidFunction) vkCreateInstance;
Jon Ashburn3950e1b2015-05-20 09:00:28 -06006271 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006272 return (PFN_vkVoidFunction) vkDestroyInstance;
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -06006273 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
6274 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
6275 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
6276 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
6277 if (!strcmp(funcName, "vkEnumerateDeviceLayerProperties"))
6278 return (PFN_vkVoidFunction) vkEnumerateDeviceLayerProperties;
6279 if (!strcmp(funcName, "vkEnumerateDeviceExtensionProperties"))
6280 return (PFN_vkVoidFunction) vkEnumerateDeviceExtensionProperties;
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06006281
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006282 my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06006283 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06006284 if (fptr)
6285 return fptr;
6286
Jon Ashburn8fd08252015-05-28 16:25:02 -06006287 {
Tobin Ehlis0b632332015-10-07 09:38:40 -06006288 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006289 if (pTable->GetInstanceProcAddr == NULL)
Jon Ashburnf6b33db2015-05-05 14:22:52 -06006290 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006291 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006292 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006293}