blob: 0ddce43cd908c4070492f5ad5653574b8601f99b [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
591 if (location == -1 && builtin == -1) {
592 /* No location defined, and not bound to an API builtin.
593 * The spec says nothing about how this case works (or doesn't)
594 * for interface matching.
595 */
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700596 log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__, SHADER_CHECKER_INCONSISTENT_SPIRV, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700597 "var %d (type %d) in %s interface has no Location or Builtin decoration",
598 code[word+2], code[word+1], storage_class_name(sinterface));
599 }
600 else if (location != -1) {
601 /* A user-defined interface variable, with a location. Where a variable
602 * occupied multiple locations, emit one result for each. */
603 unsigned num_locations = get_locations_consumed_by_type(src, type,
604 is_array_of_verts);
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -0700605 for (unsigned int offset = 0; offset < num_locations; offset++) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700606 interface_var v;
607 v.id = id;
608 v.type_id = type;
609 v.offset = offset;
610 out[location + offset] = v;
611 }
612 }
613 else {
614 /* A builtin interface variable */
615 /* Note that since builtin interface variables do not consume numbered
616 * locations, there is no larger-than-vec4 consideration as above
617 */
618 interface_var v;
619 v.id = id;
620 v.type_id = type;
621 v.offset = 0;
622 builtins_out[builtin] = v;
623 }
624 }
625
626 word += oplen;
627 }
628}
629
630static void
631collect_interface_by_descriptor_slot(layer_data *my_data, VkDevice dev,
632 shader_module const *src, spv::StorageClass sinterface,
633 std::map<std::pair<unsigned, unsigned>, interface_var> &out)
634{
635 unsigned int const *code = (unsigned int const *)&src->words[0];
636 size_t size = src->words.size();
637
638 std::unordered_map<unsigned, unsigned> var_sets;
639 std::unordered_map<unsigned, unsigned> var_bindings;
640
641 unsigned word = 5;
642 while (word < size) {
643
644 unsigned opcode = code[word] & 0x0ffffu;
645 unsigned oplen = (code[word] & 0xffff0000u) >> 16;
646
647 /* All variables in the Uniform or UniformConstant storage classes are required to be decorated with both
648 * DecorationDescriptorSet and DecorationBinding.
649 */
650 if (opcode == spv::OpDecorate) {
651 if (code[word+2] == spv::DecorationDescriptorSet) {
652 var_sets[code[word+1]] = code[word+3];
653 }
654
655 if (code[word+2] == spv::DecorationBinding) {
656 var_bindings[code[word+1]] = code[word+3];
657 }
658 }
659
660 if (opcode == spv::OpVariable && (code[word+3] == spv::StorageClassUniform ||
661 code[word+3] == spv::StorageClassUniformConstant)) {
662 unsigned set = value_or_default(var_sets, code[word+2], 0);
663 unsigned binding = value_or_default(var_bindings, code[word+2], 0);
664
665 auto existing_it = out.find(std::make_pair(set, binding));
666 if (existing_it != out.end()) {
667 /* conflict within spv image */
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700668 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 -0700669 SHADER_CHECKER_INCONSISTENT_SPIRV, "SC",
670 "var %d (type %d) in %s interface in descriptor slot (%u,%u) conflicts with existing definition",
671 code[word+2], code[word+1], storage_class_name(sinterface),
672 existing_it->first.first, existing_it->first.second);
673 }
674
675 interface_var v;
676 v.id = code[word+2];
677 v.type_id = code[word+1];
678 out[std::make_pair(set, binding)] = v;
679 }
680
681 word += oplen;
682 }
683}
684
685static bool
686validate_interface_between_stages(layer_data *my_data, VkDevice dev,
687 shader_module const *producer, char const *producer_name,
688 shader_module const *consumer, char const *consumer_name,
689 bool consumer_arrayed_input)
690{
691 std::map<uint32_t, interface_var> outputs;
692 std::map<uint32_t, interface_var> inputs;
693
694 std::map<uint32_t, interface_var> builtin_outputs;
695 std::map<uint32_t, interface_var> builtin_inputs;
696
697 bool pass = true;
698
699 collect_interface_by_location(my_data, dev, producer, spv::StorageClassOutput, outputs, builtin_outputs, false);
700 collect_interface_by_location(my_data, dev, consumer, spv::StorageClassInput, inputs, builtin_inputs,
701 consumer_arrayed_input);
702
703 auto a_it = outputs.begin();
704 auto b_it = inputs.begin();
705
706 /* maps sorted by key (location); walk them together to find mismatches */
707 while ((outputs.size() > 0 && a_it != outputs.end()) || ( inputs.size() && b_it != inputs.end())) {
708 bool a_at_end = outputs.size() == 0 || a_it == outputs.end();
709 bool b_at_end = inputs.size() == 0 || b_it == inputs.end();
710 auto a_first = a_at_end ? 0 : a_it->first;
711 auto b_first = b_at_end ? 0 : b_it->first;
712
713 if (b_at_end || ((!a_at_end) && (a_first < b_first))) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700714 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 -0700715 "%s writes to output location %d which is not consumed by %s", producer_name, a_first, consumer_name)) {
716 pass = false;
717 }
718 a_it++;
719 }
720 else if (a_at_end || a_first > b_first) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700721 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 -0700722 "%s consumes input location %d which is not written by %s", consumer_name, b_first, producer_name)) {
723 pass = false;
724 }
725 b_it++;
726 }
727 else {
728 if (types_match(producer, consumer, a_it->second.type_id, b_it->second.type_id, consumer_arrayed_input)) {
729 /* OK! */
730 }
731 else {
732 char producer_type[1024];
733 char consumer_type[1024];
734 describe_type(producer_type, producer, a_it->second.type_id);
735 describe_type(consumer_type, consumer, b_it->second.type_id);
736
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700737 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 -0700738 "Type mismatch on location %d: '%s' vs '%s'", a_it->first, producer_type, consumer_type)) {
739 pass = false;
740 }
741 }
742 a_it++;
743 b_it++;
744 }
745 }
746
747 return pass;
748}
749
750enum FORMAT_TYPE {
751 FORMAT_TYPE_UNDEFINED,
752 FORMAT_TYPE_FLOAT, /* UNORM, SNORM, FLOAT, USCALED, SSCALED, SRGB -- anything we consider float in the shader */
753 FORMAT_TYPE_SINT,
754 FORMAT_TYPE_UINT,
755};
756
757static unsigned
758get_format_type(VkFormat fmt) {
759 switch (fmt) {
760 case VK_FORMAT_UNDEFINED:
761 return FORMAT_TYPE_UNDEFINED;
762 case VK_FORMAT_R8_SINT:
763 case VK_FORMAT_R8G8_SINT:
764 case VK_FORMAT_R8G8B8_SINT:
765 case VK_FORMAT_R8G8B8A8_SINT:
766 case VK_FORMAT_R16_SINT:
767 case VK_FORMAT_R16G16_SINT:
768 case VK_FORMAT_R16G16B16_SINT:
769 case VK_FORMAT_R16G16B16A16_SINT:
770 case VK_FORMAT_R32_SINT:
771 case VK_FORMAT_R32G32_SINT:
772 case VK_FORMAT_R32G32B32_SINT:
773 case VK_FORMAT_R32G32B32A32_SINT:
774 case VK_FORMAT_B8G8R8_SINT:
775 case VK_FORMAT_B8G8R8A8_SINT:
776 case VK_FORMAT_A2B10G10R10_SINT_PACK32:
777 case VK_FORMAT_A2R10G10B10_SINT_PACK32:
778 return FORMAT_TYPE_SINT;
779 case VK_FORMAT_R8_UINT:
780 case VK_FORMAT_R8G8_UINT:
781 case VK_FORMAT_R8G8B8_UINT:
782 case VK_FORMAT_R8G8B8A8_UINT:
783 case VK_FORMAT_R16_UINT:
784 case VK_FORMAT_R16G16_UINT:
785 case VK_FORMAT_R16G16B16_UINT:
786 case VK_FORMAT_R16G16B16A16_UINT:
787 case VK_FORMAT_R32_UINT:
788 case VK_FORMAT_R32G32_UINT:
789 case VK_FORMAT_R32G32B32_UINT:
790 case VK_FORMAT_R32G32B32A32_UINT:
791 case VK_FORMAT_B8G8R8_UINT:
792 case VK_FORMAT_B8G8R8A8_UINT:
793 case VK_FORMAT_A2B10G10R10_UINT_PACK32:
794 case VK_FORMAT_A2R10G10B10_UINT_PACK32:
795 return FORMAT_TYPE_UINT;
796 default:
797 return FORMAT_TYPE_FLOAT;
798 }
799}
800
801/* characterizes a SPIR-V type appearing in an interface to a FF stage,
802 * for comparison to a VkFormat's characterization above. */
803static unsigned
804get_fundamental_type(shader_module const *src, unsigned type)
805{
806 auto type_def_it = src->type_def_index.find(type);
807
808 if (type_def_it == src->type_def_index.end()) {
809 return FORMAT_TYPE_UNDEFINED;
810 }
811
812 unsigned int const *code = (unsigned int const *)&src->words[type_def_it->second];
813 unsigned opcode = code[0] & 0x0ffffu;
814 switch (opcode) {
815 case spv::OpTypeInt:
816 return code[3] ? FORMAT_TYPE_SINT : FORMAT_TYPE_UINT;
817 case spv::OpTypeFloat:
818 return FORMAT_TYPE_FLOAT;
819 case spv::OpTypeVector:
820 return get_fundamental_type(src, code[2]);
821 case spv::OpTypeMatrix:
822 return get_fundamental_type(src, code[2]);
823 case spv::OpTypeArray:
824 return get_fundamental_type(src, code[2]);
825 case spv::OpTypePointer:
826 return get_fundamental_type(src, code[3]);
827 default:
828 return FORMAT_TYPE_UNDEFINED;
829 }
830}
831
832static bool
833validate_vi_consistency(layer_data *my_data, VkDevice dev, VkPipelineVertexInputStateCreateInfo const *vi)
834{
835 /* walk the binding descriptions, which describe the step rate and stride of each vertex buffer.
836 * each binding should be specified only once.
837 */
838 std::unordered_map<uint32_t, VkVertexInputBindingDescription const *> bindings;
839 bool pass = true;
840
841 for (unsigned i = 0; i < vi->vertexBindingDescriptionCount; i++) {
842 auto desc = &vi->pVertexBindingDescriptions[i];
843 auto & binding = bindings[desc->binding];
844 if (binding) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700845 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 -0700846 "Duplicate vertex input binding descriptions for binding %d", desc->binding)) {
847 pass = false;
848 }
849 }
850 else {
851 binding = desc;
852 }
853 }
854
855 return pass;
856}
857
858static bool
859validate_vi_against_vs_inputs(layer_data *my_data, VkDevice dev, VkPipelineVertexInputStateCreateInfo const *vi, shader_module const *vs)
860{
861 std::map<uint32_t, interface_var> inputs;
862 /* we collect builtin inputs, but they will never appear in the VI state --
863 * the vs builtin inputs are generated in the pipeline, not sourced from buffers (VertexID, etc)
864 */
865 std::map<uint32_t, interface_var> builtin_inputs;
866 bool pass = true;
867
868 collect_interface_by_location(my_data, dev, vs, spv::StorageClassInput, inputs, builtin_inputs, false);
869
870 /* Build index by location */
871 std::map<uint32_t, VkVertexInputAttributeDescription const *> attribs;
872 if (vi) {
873 for (unsigned i = 0; i < vi->vertexAttributeDescriptionCount; i++)
874 attribs[vi->pVertexAttributeDescriptions[i].location] = &vi->pVertexAttributeDescriptions[i];
875 }
876
877 auto it_a = attribs.begin();
878 auto it_b = inputs.begin();
879
880 while ((attribs.size() > 0 && it_a != attribs.end()) || (inputs.size() > 0 && it_b != inputs.end())) {
881 bool a_at_end = attribs.size() == 0 || it_a == attribs.end();
882 bool b_at_end = inputs.size() == 0 || it_b == inputs.end();
883 auto a_first = a_at_end ? 0 : it_a->first;
884 auto b_first = b_at_end ? 0 : it_b->first;
885 if (b_at_end || a_first < b_first) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700886 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 -0700887 "Vertex attribute at location %d not consumed by VS", a_first)) {
888 pass = false;
889 }
890 it_a++;
891 }
892 else if (a_at_end || b_first < a_first) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700893 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 -0700894 "VS consumes input at location %d but not provided", b_first)) {
895 pass = false;
896 }
897 it_b++;
898 }
899 else {
900 unsigned attrib_type = get_format_type(it_a->second->format);
901 unsigned input_type = get_fundamental_type(vs, it_b->second.type_id);
902
903 /* type checking */
904 if (attrib_type != FORMAT_TYPE_UNDEFINED && input_type != FORMAT_TYPE_UNDEFINED && attrib_type != input_type) {
905 char vs_type[1024];
906 describe_type(vs_type, vs, it_b->second.type_id);
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700907 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 -0700908 "Attribute type of `%s` at location %d does not match VS input type of `%s`",
909 string_VkFormat(it_a->second->format), a_first, vs_type)) {
910 pass = false;
911 }
912 }
913
914 /* OK! */
915 it_a++;
916 it_b++;
917 }
918 }
919
920 return pass;
921}
922
923static bool
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -0700924validate_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 -0700925{
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -0700926 const std::vector<VkFormat> &color_formats = rp->subpassColorFormats[subpass];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700927 std::map<uint32_t, interface_var> outputs;
928 std::map<uint32_t, interface_var> builtin_outputs;
929 bool pass = true;
930
931 /* TODO: dual source blend index (spv::DecIndex, zero if not provided) */
932
933 collect_interface_by_location(my_data, dev, fs, spv::StorageClassOutput, outputs, builtin_outputs, false);
934
935 auto it = outputs.begin();
936 uint32_t attachment = 0;
937
938 /* Walk attachment list and outputs together -- this is a little overpowered since attachments
939 * are currently dense, but the parallel with matching between shader stages is nice.
940 */
941
942 /* TODO: Figure out compile error with cb->attachmentCount */
943 while ((outputs.size() > 0 && it != outputs.end()) || attachment < color_formats.size()) {
944 if (attachment == color_formats.size() || ( it != outputs.end() && it->first < attachment)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700945 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 -0700946 "FS writes to output location %d with no matching attachment", it->first)) {
947 pass = false;
948 }
949 it++;
950 }
951 else if (it == outputs.end() || it->first > attachment) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700952 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 -0700953 "Attachment %d not written by FS", attachment)) {
954 pass = false;
955 }
956 attachment++;
957 }
958 else {
959 unsigned output_type = get_fundamental_type(fs, it->second.type_id);
960 unsigned att_type = get_format_type(color_formats[attachment]);
961
962 /* type checking */
963 if (att_type != FORMAT_TYPE_UNDEFINED && output_type != FORMAT_TYPE_UNDEFINED && att_type != output_type) {
964 char fs_type[1024];
965 describe_type(fs_type, fs, it->second.type_id);
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700966 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 -0700967 "Attachment %d of type `%s` does not match FS output type of `%s`",
968 attachment, string_VkFormat(color_formats[attachment]), fs_type)) {
969 pass = false;
970 }
971 }
972
973 /* OK! */
974 it++;
975 attachment++;
976 }
977 }
978
979 return pass;
980}
981
982
983struct shader_stage_attributes {
984 char const * const name;
985 bool arrayed_input;
986};
987
988
989static shader_stage_attributes
990shader_stage_attribs[] = {
991 { "vertex shader", false },
992 { "tessellation control shader", true },
993 { "tessellation evaluation shader", false },
994 { "geometry shader", true },
995 { "fragment shader", false },
996};
997
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -0700998// For given pipelineLayout verify that the setLayout at slot.first
999// has the requested binding at slot.second
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001000static bool
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001001has_descriptor_binding(layer_data* my_data,
1002 vector<VkDescriptorSetLayout>* pipelineLayout,
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001003 std::pair<unsigned, unsigned> slot)
1004{
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001005 if (!pipelineLayout)
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001006 return false;
1007
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001008 if (slot.first >= pipelineLayout->size())
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001009 return false;
1010
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001011 auto set = my_data->descriptorSetLayoutMap[(*pipelineLayout)[slot.first]]->bindings;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001012
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001013 return (set.find(slot.second) != set.end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001014}
1015
1016static uint32_t get_shader_stage_id(VkShaderStageFlagBits stage)
1017{
1018 uint32_t bit_pos = u_ffs(stage);
1019 return bit_pos-1;
1020}
1021
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001022// Block of code at start here for managing/tracking Pipeline state that this layer cares about
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001023
1024static uint64_t g_drawCount[NUM_DRAW_TYPES] = {0, 0, 0, 0};
1025
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001026// 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 -06001027// Then need to synchronize the accesses based on cmd buffer so that if I'm reading state on one cmd buffer, updates
1028// to that same cmd buffer by separate thread are not changing state from underneath us
1029// Track the last cmd buffer touched by this thread
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001030
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001031// prototype
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001032static GLOBAL_CB_NODE* getCBNode(layer_data*, const VkCommandBuffer);
Tobin Ehlis559c6382015-11-05 09:52:49 -07001033
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06001034static VkBool32 hasDrawCmd(GLOBAL_CB_NODE* pCB)
Tobin Ehlis53eddda2015-07-01 16:46:13 -06001035{
1036 for (uint32_t i=0; i<NUM_DRAW_TYPES; i++) {
1037 if (pCB->drawCount[i])
1038 return VK_TRUE;
1039 }
1040 return VK_FALSE;
1041}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001042
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001043// Check object status for selected flag state
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001044static 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 -06001045{
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001046 // If non-zero enable mask is present, check it against status but if enable_mask
1047 // is 0 then no enable required so we should always just check status
1048 if ((!enable_mask) || (enable_mask & pNode->status)) {
1049 if ((pNode->status & status_mask) != status_flag) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001050 // TODO : How to pass dispatchable objects as srcObject? Here src obj should be cmd buffer
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001051 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 +08001052 "CB object %#" PRIxLEAST64 ": %s", reinterpret_cast<uint64_t>(pNode->commandBuffer), fail_msg);
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001053 }
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001054 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001055 return VK_FALSE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001056}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001057
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001058// Retrieve pipeline node ptr for given pipeline object
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001059static PIPELINE_NODE* getPipeline(layer_data* my_data, const VkPipeline pipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001060{
1061 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08001062 if (my_data->pipelineMap.find(pipeline) == my_data->pipelineMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001063 loader_platform_thread_unlock_mutex(&globalLock);
1064 return NULL;
1065 }
1066 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08001067 return my_data->pipelineMap[pipeline];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001068}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001069
Tobin Ehlisd332f282015-10-02 11:00:56 -06001070// Return VK_TRUE if for a given PSO, the given state enum is dynamic, else return VK_FALSE
1071static VkBool32 isDynamic(const PIPELINE_NODE* pPipeline, const VkDynamicState state)
1072{
1073 if (pPipeline && pPipeline->graphicsPipelineCI.pDynamicState) {
1074 for (uint32_t i=0; i<pPipeline->graphicsPipelineCI.pDynamicState->dynamicStateCount; i++) {
1075 if (state == pPipeline->graphicsPipelineCI.pDynamicState->pDynamicStates[i])
1076 return VK_TRUE;
1077 }
1078 }
1079 return VK_FALSE;
1080}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001081
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001082// Validate state stored as flags at time of draw call
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001083static VkBool32 validate_draw_state_flags(layer_data* my_data, GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06001084 VkBool32 result;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001085 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");
1086 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");
1087 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");
1088 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");
1089 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");
1090 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");
1091 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");
1092 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");
1093 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 -06001094 if (indexedDraw)
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001095 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 -06001096 return result;
1097}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001098
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001099// Verify attachment reference compatibility according to spec
1100// If one array is larger, treat missing elements of shorter array as VK_ATTACHMENT_UNUSED & other array much match this
1101// If both AttachmentReference arrays have requested index, check their corresponding AttachementDescriptions
1102// to make sure that format and samples counts match.
1103// If not, they are not compatible.
1104static bool attachment_references_compatible(const uint32_t index, const VkAttachmentReference* pPrimary, const uint32_t primaryCount, const VkAttachmentDescription* pPrimaryAttachments,
1105 const VkAttachmentReference* pSecondary, const uint32_t secondaryCount, const VkAttachmentDescription* pSecondaryAttachments)
1106{
1107 if (index >= primaryCount) { // Check secondary as if primary is VK_ATTACHMENT_UNUSED
1108 if (VK_ATTACHMENT_UNUSED != pSecondary[index].attachment)
1109 return false;
1110 } else if (index >= secondaryCount) { // Check primary as if secondary is VK_ATTACHMENT_UNUSED
1111 if (VK_ATTACHMENT_UNUSED != pPrimary[index].attachment)
1112 return false;
1113 } else { // format and sample count must match
1114 if ((pPrimaryAttachments[pPrimary[index].attachment].format == pSecondaryAttachments[pSecondary[index].attachment].format) &&
1115 (pPrimaryAttachments[pPrimary[index].attachment].samples == pSecondaryAttachments[pSecondary[index].attachment].samples))
1116 return true;
1117 }
1118 // Format and sample counts didn't match
1119 return false;
1120}
1121
1122// For give primary and secondary RenderPass objects, verify that they're compatible
1123static bool verify_renderpass_compatibility(layer_data* my_data, const VkRenderPass primaryRP, const VkRenderPass secondaryRP, string& errorMsg)
1124{
1125 stringstream errorStr;
1126 if (my_data->renderPassMap.find(primaryRP) == my_data->renderPassMap.end()) {
1127 errorStr << "invalid VkRenderPass (" << primaryRP << ")";
1128 errorMsg = errorStr.str();
1129 return false;
1130 } else if (my_data->renderPassMap.find(secondaryRP) == my_data->renderPassMap.end()) {
1131 errorStr << "invalid VkRenderPass (" << secondaryRP << ")";
1132 errorMsg = errorStr.str();
1133 return false;
1134 }
1135 // Trivial pass case is exact same RP
1136 if (primaryRP == secondaryRP)
1137 return true;
1138 const VkRenderPassCreateInfo* primaryRPCI = my_data->renderPassMap[primaryRP]->pCreateInfo;
1139 const VkRenderPassCreateInfo* secondaryRPCI = my_data->renderPassMap[secondaryRP]->pCreateInfo;
1140 if (primaryRPCI->subpassCount != secondaryRPCI->subpassCount) {
1141 errorStr << "RenderPass for primary cmdBuffer has " << primaryRPCI->subpassCount << " subpasses but renderPass for secondary cmdBuffer has " << secondaryRPCI->subpassCount << " subpasses.";
1142 errorMsg = errorStr.str();
1143 return false;
1144 }
1145 uint32_t spIndex = 0;
1146 for (spIndex = 0; spIndex < primaryRPCI->subpassCount; ++spIndex) {
1147 // For each subpass, verify that corresponding color, input, resolve & depth/stencil attachment references are compatible
1148 uint32_t primaryColorCount = primaryRPCI->pSubpasses[spIndex].colorAttachmentCount;
1149 uint32_t secondaryColorCount = secondaryRPCI->pSubpasses[spIndex].colorAttachmentCount;
1150 uint32_t colorMax = std::max(primaryColorCount, secondaryColorCount);
1151 for (uint32_t cIdx = 0; cIdx < colorMax; ++cIdx) {
1152 if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pColorAttachments, primaryColorCount, primaryRPCI->pAttachments,
1153 secondaryRPCI->pSubpasses[spIndex].pColorAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1154 errorStr << "color attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
1155 errorMsg = errorStr.str();
1156 return false;
1157 } else if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pResolveAttachments, primaryColorCount, primaryRPCI->pAttachments,
1158 secondaryRPCI->pSubpasses[spIndex].pResolveAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1159 errorStr << "resolve attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
1160 errorMsg = errorStr.str();
1161 return false;
1162 } else if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pDepthStencilAttachment, primaryColorCount, primaryRPCI->pAttachments,
1163 secondaryRPCI->pSubpasses[spIndex].pDepthStencilAttachment, secondaryColorCount, secondaryRPCI->pAttachments)) {
1164 errorStr << "depth/stencil attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
1165 errorMsg = errorStr.str();
1166 return false;
1167 }
1168 }
1169 uint32_t primaryInputCount = primaryRPCI->pSubpasses[spIndex].inputAttachmentCount;
1170 uint32_t secondaryInputCount = secondaryRPCI->pSubpasses[spIndex].inputAttachmentCount;
1171 uint32_t inputMax = std::max(primaryInputCount, secondaryInputCount);
1172 for (uint32_t i = 0; i < inputMax; ++i) {
1173 if (!attachment_references_compatible(i, primaryRPCI->pSubpasses[spIndex].pInputAttachments, primaryColorCount, primaryRPCI->pAttachments,
1174 secondaryRPCI->pSubpasses[spIndex].pInputAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1175 errorStr << "input attachments at index " << i << " of subpass index " << spIndex << " are not compatible.";
1176 errorMsg = errorStr.str();
1177 return false;
1178 }
1179 }
1180 }
1181 return true;
1182}
1183
Tobin Ehlis559c6382015-11-05 09:52:49 -07001184// For give SET_NODE, verify that its Set is compatible w/ the setLayout corresponding to pipelineLayout[layoutIndex]
1185static bool verify_set_layout_compatibility(layer_data* my_data, const SET_NODE* pSet, const VkPipelineLayout layout, const uint32_t layoutIndex, string& errorMsg)
1186{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001187 stringstream errorStr;
Tobin Ehlis559c6382015-11-05 09:52:49 -07001188 if (my_data->pipelineLayoutMap.find(layout) == my_data->pipelineLayoutMap.end()) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001189 errorStr << "invalid VkPipelineLayout (" << layout << ")";
1190 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001191 return false;
1192 }
1193 PIPELINE_LAYOUT_NODE pl = my_data->pipelineLayoutMap[layout];
1194 if (layoutIndex >= pl.descriptorSetLayouts.size()) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001195 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;
1196 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001197 return false;
1198 }
1199 // Get the specific setLayout from PipelineLayout that overlaps this set
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001200 LAYOUT_NODE* pLayoutNode = my_data->descriptorSetLayoutMap[pl.descriptorSetLayouts[layoutIndex]];
Tobin Ehlis559c6382015-11-05 09:52:49 -07001201 if (pLayoutNode->layout == pSet->pLayout->layout) { // trivial pass case
1202 return true;
1203 }
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07001204 size_t descriptorCount = pLayoutNode->descriptorTypes.size();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001205 if (descriptorCount != pSet->pLayout->descriptorTypes.size()) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001206 errorStr << "setLayout " << layoutIndex << " from pipelineLayout " << layout << " has " << descriptorCount << " descriptors, but corresponding set being bound has " << pSet->pLayout->descriptorTypes.size() << " descriptors.";
1207 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001208 return false; // trivial fail case
1209 }
1210 // Now need to check set against corresponding pipelineLayout to verify compatibility
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07001211 for (size_t i=0; i<descriptorCount; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07001212 // Need to verify that layouts are identically defined
1213 // TODO : Is below sufficient? Making sure that types & stageFlags match per descriptor
1214 // do we also need to check immutable samplers?
1215 if (pLayoutNode->descriptorTypes[i] != pSet->pLayout->descriptorTypes[i]) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001216 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]) << "'";
1217 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001218 return false;
1219 }
1220 if (pLayoutNode->stageFlags[i] != pSet->pLayout->stageFlags[i]) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001221 errorStr << "stageFlags " << i << " for descriptorSet being bound is " << pSet->pLayout->stageFlags[i] << "' but corresponding descriptor from pipelineLayout has stageFlags " << pLayoutNode->stageFlags[i];
1222 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001223 return false;
1224 }
1225 }
1226 return true;
1227}
1228
Tobin Ehlis88452832015-12-03 09:40:56 -07001229// Validate that the shaders used by the given pipeline
1230// As a side effect this function also records the sets that are actually used by the pipeline
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07001231static VkBool32
Tobin Ehlis88452832015-12-03 09:40:56 -07001232validate_pipeline_shaders(layer_data *my_data, VkDevice dev, PIPELINE_NODE* pPipeline)
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001233{
Tobin Ehlis88452832015-12-03 09:40:56 -07001234 VkGraphicsPipelineCreateInfo const *pCreateInfo = &pPipeline->graphicsPipelineCI;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001235 /* We seem to allow pipeline stages to be specified out of order, so collect and identify them
1236 * before trying to do anything more: */
1237 int vertex_stage = get_shader_stage_id(VK_SHADER_STAGE_VERTEX_BIT);
1238 int geometry_stage = get_shader_stage_id(VK_SHADER_STAGE_GEOMETRY_BIT);
1239 int fragment_stage = get_shader_stage_id(VK_SHADER_STAGE_FRAGMENT_BIT);
1240
1241 shader_module **shaders = new shader_module*[fragment_stage + 1]; /* exclude CS */
1242 memset(shaders, 0, sizeof(shader_module *) * (fragment_stage +1));
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001243 RENDER_PASS_NODE const *rp = 0;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001244 VkPipelineVertexInputStateCreateInfo const *vi = 0;
Mark Youngb20a6a82016-01-07 15:41:43 -07001245 VkBool32 pass = VK_TRUE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001246
1247 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
1248 VkPipelineShaderStageCreateInfo const *pStage = &pCreateInfo->pStages[i];
1249 if (pStage->sType == VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO) {
1250
1251 if ((pStage->stage & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_GEOMETRY_BIT | VK_SHADER_STAGE_FRAGMENT_BIT
1252 | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT)) == 0) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001253 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 -07001254 "Unknown shader stage %d", pStage->stage)) {
Mark Youngb20a6a82016-01-07 15:41:43 -07001255 pass = VK_FALSE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001256 }
1257 }
1258 else {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001259 shader_module *module = my_data->shaderModuleMap[pStage->module];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001260 shaders[get_shader_stage_id(pStage->stage)] = module;
1261
1262 /* validate descriptor set layout against what the spirv module actually uses */
1263 std::map<std::pair<unsigned, unsigned>, interface_var> descriptor_uses;
1264 collect_interface_by_descriptor_slot(my_data, dev, module, spv::StorageClassUniform,
1265 descriptor_uses);
1266
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001267 auto layouts = pCreateInfo->layout != VK_NULL_HANDLE ?
1268 &(my_data->pipelineLayoutMap[pCreateInfo->layout].descriptorSetLayouts) : nullptr;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001269
1270 for (auto it = descriptor_uses.begin(); it != descriptor_uses.end(); it++) {
Tobin Ehlis88452832015-12-03 09:40:56 -07001271 // As a side-effect of this function, capture which sets are used by the pipeline
1272 pPipeline->active_sets.insert(it->first.first);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001273
1274 /* find the matching binding */
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001275 auto found = has_descriptor_binding(my_data, layouts, it->first);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001276
1277 if (!found) {
1278 char type_name[1024];
1279 describe_type(type_name, module, it->second.type_id);
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001280 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 -07001281 SHADER_CHECKER_MISSING_DESCRIPTOR, "SC",
1282 "Shader uses descriptor slot %u.%u (used as type `%s`) but not declared in pipeline layout",
1283 it->first.first, it->first.second, type_name)) {
Mark Youngb20a6a82016-01-07 15:41:43 -07001284 pass = VK_FALSE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001285 }
1286 }
1287 }
1288 }
1289 }
1290 }
1291
1292 if (pCreateInfo->renderPass != VK_NULL_HANDLE)
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001293 rp = my_data->renderPassMap[pCreateInfo->renderPass];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001294
1295 vi = pCreateInfo->pVertexInputState;
1296
1297 if (vi) {
1298 pass = validate_vi_consistency(my_data, dev, vi) && pass;
1299 }
1300
1301 if (shaders[vertex_stage]) {
1302 pass = validate_vi_against_vs_inputs(my_data, dev, vi, shaders[vertex_stage]) && pass;
1303 }
1304
1305 /* TODO: enforce rules about present combinations of shaders */
1306 int producer = get_shader_stage_id(VK_SHADER_STAGE_VERTEX_BIT);
1307 int consumer = get_shader_stage_id(VK_SHADER_STAGE_GEOMETRY_BIT);
1308
1309 while (!shaders[producer] && producer != fragment_stage) {
1310 producer++;
1311 consumer++;
1312 }
1313
1314 for (; producer != fragment_stage && consumer <= fragment_stage; consumer++) {
1315 assert(shaders[producer]);
1316 if (shaders[consumer]) {
1317 pass = validate_interface_between_stages(my_data, dev,
1318 shaders[producer], shader_stage_attribs[producer].name,
1319 shaders[consumer], shader_stage_attribs[consumer].name,
1320 shader_stage_attribs[consumer].arrayed_input) && pass;
1321
1322 producer = consumer;
1323 }
1324 }
1325
1326 if (shaders[fragment_stage] && rp) {
1327 pass = validate_fs_outputs_against_render_pass(my_data, dev, shaders[fragment_stage], rp, pCreateInfo->subpass) && pass;
1328 }
1329
1330 delete shaders;
1331
1332 return pass;
1333}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001334
Tobin Ehlisf6585052015-12-17 11:48:42 -07001335// Return Set node ptr for specified set or else NULL
1336static SET_NODE* getSetNode(layer_data* my_data, const VkDescriptorSet set)
1337{
1338 loader_platform_thread_lock_mutex(&globalLock);
1339 if (my_data->setMap.find(set) == my_data->setMap.end()) {
1340 loader_platform_thread_unlock_mutex(&globalLock);
1341 return NULL;
1342 }
1343 loader_platform_thread_unlock_mutex(&globalLock);
1344 return my_data->setMap[set];
1345}
1346
1347// For the given set, verify that for each dynamic descriptor in that set that its
1348// dynamic offset combined with the offet and range from its descriptor update
1349// do not overflow the size of its buffer being updated
1350static VkBool32 validate_dynamic_offsets(layer_data* my_data, const SET_NODE* pSet)
1351{
1352 VkBool32 result = VK_FALSE;
1353 if (pSet->dynamicOffsets.empty())
1354 return result;
1355
1356 VkWriteDescriptorSet* pWDS = NULL;
1357 uint32_t dynOffsetIndex = 0;
1358 VkDeviceSize bufferSize = 0;
1359 for (uint32_t i=0; i < pSet->descriptorCount; ++i) {
1360 switch (pSet->ppDescriptors[i]->sType) {
1361 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1362 pWDS = (VkWriteDescriptorSet*)pSet->ppDescriptors[i];
1363 if ((pWDS->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
1364 (pWDS->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
1365 for (uint32_t j=0; j<pWDS->descriptorCount; ++j) {
Michael Lentine700b0aa2015-10-30 17:57:32 -07001366 bufferSize = my_data->bufferMap[pWDS->pBufferInfo[j].buffer].create_info->size;
Tobin Ehlisf6585052015-12-17 11:48:42 -07001367 if ((pSet->dynamicOffsets[dynOffsetIndex] + pWDS->pBufferInfo[j].offset + pWDS->pBufferInfo[j].range) > bufferSize) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001368 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 -07001369 "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 ".",
1370 (uint64_t)pSet->set, i, pSet->dynamicOffsets[dynOffsetIndex], pWDS->pBufferInfo[j].offset, pWDS->pBufferInfo[j].range, (uint64_t)pWDS->pBufferInfo[j].buffer, bufferSize);
1371 }
1372 dynOffsetIndex++;
1373 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)
1374 }
1375 }
1376 break;
1377 default: // Currently only shadowing Write update nodes so shouldn't get here
1378 assert(0);
1379 continue;
1380 }
1381 }
1382 return result;
1383}
1384
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001385// Validate overall state at the time of a draw call
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001386static VkBool32 validate_draw_state(layer_data* my_data, GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001387 // First check flag states
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001388 VkBool32 result = validate_draw_state_flags(my_data, pCB, indexedDraw);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001389 PIPELINE_NODE* pPipe = getPipeline(my_data, pCB->lastBoundPipeline);
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001390 // Now complete other state checks
Tobin Ehlise90e66d2015-09-09 13:31:01 -06001391 // TODO : Currently only performing next check if *something* was bound (non-zero last bound)
1392 // There is probably a better way to gate when this check happens, and to know if something *should* have been bound
1393 // We should have that check separately and then gate this check based on that check
Mark Lobodzinski74635932015-12-18 15:35:38 -07001394 if (pPipe) {
1395 if (pCB->lastBoundPipelineLayout) {
1396 string errorString;
1397 for (auto setIndex : pPipe->active_sets) {
1398 // If valid set is not bound throw an error
1399 if ((pCB->boundDescriptorSets.size() <= setIndex) || (!pCB->boundDescriptorSets[setIndex])) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001400 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 -07001401 "VkPipeline %#" PRIxLEAST64 " uses set #%u but that set is not bound.", (uint64_t)pPipe->pipeline, setIndex);
1402 } else if (!verify_set_layout_compatibility(my_data, my_data->setMap[pCB->boundDescriptorSets[setIndex]], pPipe->graphicsPipelineCI.layout, setIndex, errorString)) {
1403 // Set is bound but not compatible w/ overlapping pipelineLayout from PSO
1404 VkDescriptorSet setHandle = my_data->setMap[pCB->boundDescriptorSets[setIndex]]->set;
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001405 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 -07001406 "VkDescriptorSet (%#" PRIxLEAST64 ") bound as set #%u is not compatible with overlapping VkPipelineLayout %#" PRIxLEAST64 " due to: %s",
1407 (uint64_t)setHandle, setIndex, (uint64_t)pPipe->graphicsPipelineCI.layout, errorString.c_str());
Tobin Ehlis43c39c02016-01-11 13:18:40 -07001408 } else { // Valid set is bound and layout compatible, validate that it's updated and verify any dynamic offsets
1409 // Pull the set node
Tobin Ehlisf6585052015-12-17 11:48:42 -07001410 SET_NODE* pSet = getSetNode(my_data, pCB->boundDescriptorSets[setIndex]);
Tobin Ehlis43c39c02016-01-11 13:18:40 -07001411 // Make sure set has been updated
1412 if (!pSet->pUpdateStructs) {
1413 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",
1414 "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);
1415 }
1416 // For each dynamic descriptor, make sure dynamic offset doesn't overstep buffer
Tobin Ehlisf6585052015-12-17 11:48:42 -07001417 result |= validate_dynamic_offsets(my_data, pSet);
Mark Lobodzinski74635932015-12-18 15:35:38 -07001418 }
Tobin Ehlis88452832015-12-03 09:40:56 -07001419 }
1420 }
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07001421
Mark Lobodzinski74635932015-12-18 15:35:38 -07001422 // Verify Vtx binding
1423 if (pPipe->vtxBindingCount > 0) {
1424 VkPipelineVertexInputStateCreateInfo *vtxInCI = &pPipe->vertexInputCI;
1425 for (uint32_t i = 0; i < vtxInCI->vertexBindingDescriptionCount; i++) {
Michael Lentine700b0aa2015-10-30 17:57:32 -07001426 if ((pCB->currentDrawData.buffers.size() < (i+1)) || (pCB->currentDrawData.buffers[i] == VK_NULL_HANDLE)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001427 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 -07001428 "The Pipeline State Object (%#" PRIxLEAST64 ") expects that this Command Buffer's vertex binding Index %d should be set via vkCmdBindVertexBuffers.",
1429 (uint64_t)pCB->lastBoundPipeline, i);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001430
Mark Lobodzinski74635932015-12-18 15:35:38 -07001431 }
1432 }
1433 } else {
Michael Lentine700b0aa2015-10-30 17:57:32 -07001434 if (!pCB->currentDrawData.buffers.empty()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001435 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 -07001436 "DS", "Vertex buffers are bound to command buffer (%#" PRIxLEAST64 ") but no vertex buffers are attached to this Pipeline State Object (%#" PRIxLEAST64 ").",
1437 (uint64_t)pCB->commandBuffer, (uint64_t)pCB->lastBoundPipeline);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06001438 }
1439 }
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07001440
Mark Lobodzinski74635932015-12-18 15:35:38 -07001441 // If Viewport or scissors are dynamic, verify that dynamic count matches PSO count
1442 VkBool32 dynViewport = isDynamic(pPipe, VK_DYNAMIC_STATE_VIEWPORT);
1443 VkBool32 dynScissor = isDynamic(pPipe, VK_DYNAMIC_STATE_SCISSOR);
1444 if (dynViewport) {
1445 if (pCB->viewports.size() != pPipe->graphicsPipelineCI.pViewportState->viewportCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001446 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 -07001447 "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);
1448 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001449 }
Mark Lobodzinski74635932015-12-18 15:35:38 -07001450 if (dynScissor) {
1451 if (pCB->scissors.size() != pPipe->graphicsPipelineCI.pViewportState->scissorCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001452 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 -07001453 "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);
1454 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001455 }
1456 }
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001457 return result;
1458}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001459
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001460// Verify that create state for a pipeline is valid
Tobin Ehlis88452832015-12-03 09:40:56 -07001461static VkBool32 verifyPipelineCreateState(layer_data* my_data, const VkDevice device, PIPELINE_NODE* pPipeline)
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001462{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001463 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski2fd2d032015-12-16 14:25:22 -07001464
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 }
Mark Lobodzinski2fd2d032015-12-16 14:25:22 -07001468
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001469 // VS is required
1470 if (!(pPipeline->active_shaders & VK_SHADER_STAGE_VERTEX_BIT)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001471 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 -06001472 "Invalid Pipeline CreateInfo State: Vtx Shader required");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001473 }
1474 // Either both or neither TC/TE shaders should be defined
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001475 if (((pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) == 0) !=
1476 ((pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) == 0) ) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001477 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 -06001478 "Invalid Pipeline CreateInfo State: TE and TC shaders must be included or excluded as a pair");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001479 }
1480 // Compute shaders should be specified independent of Gfx shaders
1481 if ((pPipeline->active_shaders & VK_SHADER_STAGE_COMPUTE_BIT) &&
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001482 (pPipeline->active_shaders & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT |
1483 VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT | VK_SHADER_STAGE_GEOMETRY_BIT |
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001484 VK_SHADER_STAGE_FRAGMENT_BIT))) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001485 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 -06001486 "Invalid Pipeline CreateInfo State: Do not specify Compute Shader for Gfx Pipeline");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001487 }
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001488 // VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology is only valid for tessellation pipelines.
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001489 // Mismatching primitive topology and tessellation fails graphics pipeline creation.
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001490 if (pPipeline->active_shaders & (VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) &&
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001491 (pPipeline->iaStateCI.topology != VK_PRIMITIVE_TOPOLOGY_PATCH_LIST)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001492 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 +08001493 "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 -06001494 }
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001495 if (pPipeline->iaStateCI.topology == VK_PRIMITIVE_TOPOLOGY_PATCH_LIST) {
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001496 if (~pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001497 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 +08001498 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology is only valid for tessellation pipelines");
Tobin Ehlis912df022015-09-17 08:46:18 -06001499 }
1500 if (!pPipeline->tessStateCI.patchControlPoints || (pPipeline->tessStateCI.patchControlPoints > 32)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001501 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 +08001502 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology used with patchControlPoints value %u."
Tobin Ehlis912df022015-09-17 08:46:18 -06001503 " patchControlPoints should be >0 and <=32.", pPipeline->tessStateCI.patchControlPoints);
1504 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001505 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001506 // Viewport state must be included and viewport and scissor counts should always match
Tobin Ehlise68360f2015-10-01 11:15:13 -06001507 // NOTE : Even if these are flagged as dynamic, counts need to be set correctly for shader compiler
Tobin Ehlisd332f282015-10-02 11:00:56 -06001508 if (!pPipeline->graphicsPipelineCI.pViewportState) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001509 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 -06001510 "Gfx Pipeline pViewportState is null. Even if viewport and scissors are dynamic PSO must include viewportCount and scissorCount in pViewportState.");
1511 } else if (pPipeline->graphicsPipelineCI.pViewportState->scissorCount != pPipeline->graphicsPipelineCI.pViewportState->viewportCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001512 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 -06001513 "Gfx Pipeline viewport count (%u) must match scissor count (%u).", pPipeline->vpStateCI.viewportCount, pPipeline->vpStateCI.scissorCount);
Tobin Ehlisd332f282015-10-02 11:00:56 -06001514 } else {
1515 // If viewport or scissor are not dynamic, then verify that data is appropriate for count
1516 VkBool32 dynViewport = isDynamic(pPipeline, VK_DYNAMIC_STATE_VIEWPORT);
1517 VkBool32 dynScissor = isDynamic(pPipeline, VK_DYNAMIC_STATE_SCISSOR);
1518 if (!dynViewport) {
1519 if (pPipeline->graphicsPipelineCI.pViewportState->viewportCount && !pPipeline->graphicsPipelineCI.pViewportState->pViewports) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001520 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 -07001521 "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 -06001522 }
1523 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001524 if (!dynScissor) {
1525 if (pPipeline->graphicsPipelineCI.pViewportState->scissorCount && !pPipeline->graphicsPipelineCI.pViewportState->pScissors) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001526 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 -07001527 "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 -06001528 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06001529 }
1530 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001531 return skipCall;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001532}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001533
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001534// Init the pipeline mapping info based on pipeline create info LL tree
1535// Threading note : Calls to this function should wrapped in mutex
Tobin Ehlis88452832015-12-03 09:40:56 -07001536// TODO : this should really just be in the constructor for PIPELINE_NODE
Mark Lobodzinski475a2182015-11-10 15:25:01 -07001537static PIPELINE_NODE* initGraphicsPipeline(layer_data* dev_data, const VkGraphicsPipelineCreateInfo* pCreateInfo, PIPELINE_NODE* pBasePipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001538{
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001539 PIPELINE_NODE* pPipeline = new PIPELINE_NODE;
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001540
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001541 if (pBasePipeline) {
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001542 *pPipeline = *pBasePipeline;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001543 }
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001544
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001545 // First init create info
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001546 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001547
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001548 size_t bufferSize = 0;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001549 const VkPipelineVertexInputStateCreateInfo* pVICI = NULL;
Tobin Ehlis5a65cca2015-07-13 13:14:24 -06001550 const VkPipelineColorBlendStateCreateInfo* pCBCI = NULL;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001551
1552 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
1553 const VkPipelineShaderStageCreateInfo *pPSSCI = &pCreateInfo->pStages[i];
1554
Chia-I Wu28e06912015-10-31 00:31:16 +08001555 switch (pPSSCI->stage) {
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001556 case VK_SHADER_STAGE_VERTEX_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001557 memcpy(&pPipeline->vsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1558 pPipeline->active_shaders |= VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001559 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001560 case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001561 memcpy(&pPipeline->tcsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001562 pPipeline->active_shaders |= VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001563 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001564 case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001565 memcpy(&pPipeline->tesCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001566 pPipeline->active_shaders |= VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001567 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001568 case VK_SHADER_STAGE_GEOMETRY_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001569 memcpy(&pPipeline->gsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1570 pPipeline->active_shaders |= VK_SHADER_STAGE_GEOMETRY_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001571 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001572 case VK_SHADER_STAGE_FRAGMENT_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001573 memcpy(&pPipeline->fsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1574 pPipeline->active_shaders |= VK_SHADER_STAGE_FRAGMENT_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001575 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001576 case VK_SHADER_STAGE_COMPUTE_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001577 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
1578 pPipeline->active_shaders |= VK_SHADER_STAGE_COMPUTE_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001579 break;
1580 default:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001581 // TODO : Flag error
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001582 break;
1583 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001584 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001585 // Copy over GraphicsPipelineCreateInfo structure embedded pointers
1586 if (pCreateInfo->stageCount != 0) {
1587 pPipeline->graphicsPipelineCI.pStages = new VkPipelineShaderStageCreateInfo[pCreateInfo->stageCount];
1588 bufferSize = pCreateInfo->stageCount * sizeof(VkPipelineShaderStageCreateInfo);
1589 memcpy((void*)pPipeline->graphicsPipelineCI.pStages, pCreateInfo->pStages, bufferSize);
1590 }
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001591 if (pCreateInfo->pVertexInputState != NULL) {
1592 memcpy((void*)&pPipeline->vertexInputCI, pCreateInfo->pVertexInputState , sizeof(VkPipelineVertexInputStateCreateInfo));
1593 // Copy embedded ptrs
1594 pVICI = pCreateInfo->pVertexInputState;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001595 pPipeline->vtxBindingCount = pVICI->vertexBindingDescriptionCount;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001596 if (pPipeline->vtxBindingCount) {
1597 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
1598 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
1599 memcpy((void*)pPipeline->pVertexBindingDescriptions, pVICI->pVertexBindingDescriptions, bufferSize);
1600 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08001601 pPipeline->vtxAttributeCount = pVICI->vertexAttributeDescriptionCount;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001602 if (pPipeline->vtxAttributeCount) {
1603 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
1604 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
1605 memcpy((void*)pPipeline->pVertexAttributeDescriptions, pVICI->pVertexAttributeDescriptions, bufferSize);
1606 }
1607 pPipeline->graphicsPipelineCI.pVertexInputState = &pPipeline->vertexInputCI;
1608 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001609 if (pCreateInfo->pInputAssemblyState != NULL) {
1610 memcpy((void*)&pPipeline->iaStateCI, pCreateInfo->pInputAssemblyState, sizeof(VkPipelineInputAssemblyStateCreateInfo));
1611 pPipeline->graphicsPipelineCI.pInputAssemblyState = &pPipeline->iaStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001612 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001613 if (pCreateInfo->pTessellationState != NULL) {
1614 memcpy((void*)&pPipeline->tessStateCI, pCreateInfo->pTessellationState, sizeof(VkPipelineTessellationStateCreateInfo));
1615 pPipeline->graphicsPipelineCI.pTessellationState = &pPipeline->tessStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001616 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001617 if (pCreateInfo->pViewportState != NULL) {
1618 memcpy((void*)&pPipeline->vpStateCI, pCreateInfo->pViewportState, sizeof(VkPipelineViewportStateCreateInfo));
1619 pPipeline->graphicsPipelineCI.pViewportState = &pPipeline->vpStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001620 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001621 if (pCreateInfo->pRasterizationState != NULL) {
1622 memcpy((void*)&pPipeline->rsStateCI, pCreateInfo->pRasterizationState, sizeof(VkPipelineRasterizationStateCreateInfo));
1623 pPipeline->graphicsPipelineCI.pRasterizationState = &pPipeline->rsStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001624 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001625 if (pCreateInfo->pMultisampleState != NULL) {
1626 memcpy((void*)&pPipeline->msStateCI, pCreateInfo->pMultisampleState, sizeof(VkPipelineMultisampleStateCreateInfo));
1627 pPipeline->graphicsPipelineCI.pMultisampleState = &pPipeline->msStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001628 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001629 if (pCreateInfo->pDepthStencilState != NULL) {
1630 memcpy((void*)&pPipeline->dsStateCI, pCreateInfo->pDepthStencilState, sizeof(VkPipelineDepthStencilStateCreateInfo));
1631 pPipeline->graphicsPipelineCI.pDepthStencilState = &pPipeline->dsStateCI;
1632 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001633 if (pCreateInfo->pColorBlendState != NULL) {
1634 memcpy((void*)&pPipeline->cbStateCI, pCreateInfo->pColorBlendState, sizeof(VkPipelineColorBlendStateCreateInfo));
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001635 // Copy embedded ptrs
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001636 pCBCI = pCreateInfo->pColorBlendState;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001637 pPipeline->attachmentCount = pCBCI->attachmentCount;
1638 if (pPipeline->attachmentCount) {
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001639 pPipeline->pAttachments = new VkPipelineColorBlendAttachmentState[pPipeline->attachmentCount];
1640 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineColorBlendAttachmentState);
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001641 memcpy((void*)pPipeline->pAttachments, pCBCI->pAttachments, bufferSize);
1642 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001643 pPipeline->graphicsPipelineCI.pColorBlendState = &pPipeline->cbStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001644 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001645 if (pCreateInfo->pDynamicState != NULL) {
1646 memcpy((void*)&pPipeline->dynStateCI, pCreateInfo->pDynamicState, sizeof(VkPipelineDynamicStateCreateInfo));
1647 if (pPipeline->dynStateCI.dynamicStateCount) {
1648 pPipeline->dynStateCI.pDynamicStates = new VkDynamicState[pPipeline->dynStateCI.dynamicStateCount];
1649 bufferSize = pPipeline->dynStateCI.dynamicStateCount * sizeof(VkDynamicState);
1650 memcpy((void*)pPipeline->dynStateCI.pDynamicStates, pCreateInfo->pDynamicState->pDynamicStates, bufferSize);
1651 }
1652 pPipeline->graphicsPipelineCI.pDynamicState = &pPipeline->dynStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001653 }
Tobin Ehlis88452832015-12-03 09:40:56 -07001654 pPipeline->active_sets.clear();
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001655 return pPipeline;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001656}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001657
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001658// Free the Pipeline nodes
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001659static void deletePipelines(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001660{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001661 if (my_data->pipelineMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06001662 return;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001663 for (auto ii=my_data->pipelineMap.begin(); ii!=my_data->pipelineMap.end(); ++ii) {
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001664 if ((*ii).second->graphicsPipelineCI.stageCount != 0) {
1665 delete[] (*ii).second->graphicsPipelineCI.pStages;
1666 }
Tobin Ehlisf313c8b2015-04-01 11:59:08 -06001667 if ((*ii).second->pVertexBindingDescriptions) {
1668 delete[] (*ii).second->pVertexBindingDescriptions;
1669 }
1670 if ((*ii).second->pVertexAttributeDescriptions) {
1671 delete[] (*ii).second->pVertexAttributeDescriptions;
1672 }
1673 if ((*ii).second->pAttachments) {
1674 delete[] (*ii).second->pAttachments;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001675 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001676 if ((*ii).second->dynStateCI.dynamicStateCount != 0) {
1677 delete[] (*ii).second->dynStateCI.pDynamicStates;
1678 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001679 delete (*ii).second;
1680 }
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001681 my_data->pipelineMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001682}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001683
Tobin Ehliseba312c2015-04-01 08:40:34 -06001684// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Chia-I Wu5c17c962015-10-31 00:31:16 +08001685static VkSampleCountFlagBits getNumSamples(layer_data* my_data, const VkPipeline pipeline)
Tobin Ehliseba312c2015-04-01 08:40:34 -06001686{
Chia-I Wue2fc5522015-10-26 20:04:44 +08001687 PIPELINE_NODE* pPipe = my_data->pipelineMap[pipeline];
Tobin Ehlis577188e2015-07-13 14:51:15 -06001688 if (VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001689 return pPipe->msStateCI.rasterizationSamples;
Tobin Ehlis577188e2015-07-13 14:51:15 -06001690 }
Chia-I Wu5c17c962015-10-31 00:31:16 +08001691 return VK_SAMPLE_COUNT_1_BIT;
Tobin Ehliseba312c2015-04-01 08:40:34 -06001692}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001693
Tobin Ehliseba312c2015-04-01 08:40:34 -06001694// Validate state related to the PSO
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001695static VkBool32 validatePipelineState(layer_data* my_data, const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehliseba312c2015-04-01 08:40:34 -06001696{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001697 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06001698 // Verify that any MSAA request in PSO matches sample# in bound FB
Chia-I Wu5c17c962015-10-31 00:31:16 +08001699 VkSampleCountFlagBits psoNumSamples = getNumSamples(my_data, pipeline);
Tobin Ehliseba312c2015-04-01 08:40:34 -06001700 if (pCB->activeRenderPass) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001701 const VkRenderPassCreateInfo* pRPCI = my_data->renderPassMap[pCB->activeRenderPass]->pCreateInfo;
Chia-I Wu08accc62015-07-07 11:50:03 +08001702 const VkSubpassDescription* pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
Chia-I Wu5c17c962015-10-31 00:31:16 +08001703 VkSampleCountFlagBits subpassNumSamples = (VkSampleCountFlagBits) 0;
Chia-I Wu08accc62015-07-07 11:50:03 +08001704 uint32_t i;
1705
Chia-I Wud50a7d72015-10-26 20:48:51 +08001706 for (i = 0; i < pSD->colorAttachmentCount; i++) {
Chia-I Wu5c17c962015-10-31 00:31:16 +08001707 VkSampleCountFlagBits samples;
Chia-I Wu08accc62015-07-07 11:50:03 +08001708
Cody Northropa505dda2015-08-04 11:16:41 -06001709 if (pSD->pColorAttachments[i].attachment == VK_ATTACHMENT_UNUSED)
Chia-I Wu08accc62015-07-07 11:50:03 +08001710 continue;
1711
Cody Northropa505dda2015-08-04 11:16:41 -06001712 samples = pRPCI->pAttachments[pSD->pColorAttachments[i].attachment].samples;
Chia-I Wu5c17c962015-10-31 00:31:16 +08001713 if (subpassNumSamples == (VkSampleCountFlagBits) 0) {
Chia-I Wu08accc62015-07-07 11:50:03 +08001714 subpassNumSamples = samples;
1715 } else if (subpassNumSamples != samples) {
Chia-I Wu5c17c962015-10-31 00:31:16 +08001716 subpassNumSamples = (VkSampleCountFlagBits) -1;
Chia-I Wu08accc62015-07-07 11:50:03 +08001717 break;
1718 }
1719 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08001720 if (pSD->pDepthStencilAttachment && pSD->pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
Chia-I Wu5c17c962015-10-31 00:31:16 +08001721 const VkSampleCountFlagBits samples = pRPCI->pAttachments[pSD->pDepthStencilAttachment->attachment].samples;
1722 if (subpassNumSamples == (VkSampleCountFlagBits) 0)
Chia-I Wu08accc62015-07-07 11:50:03 +08001723 subpassNumSamples = samples;
1724 else if (subpassNumSamples != samples)
Chia-I Wu5c17c962015-10-31 00:31:16 +08001725 subpassNumSamples = (VkSampleCountFlagBits) -1;
Chia-I Wu08accc62015-07-07 11:50:03 +08001726 }
1727
1728 if (psoNumSamples != subpassNumSamples) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001729 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 -06001730 "Num samples mismatch! Binding PSO (%#" PRIxLEAST64 ") with %u samples while current RenderPass (%#" PRIxLEAST64 ") w/ %u samples!",
Chia-I Wue2fc5522015-10-26 20:04:44 +08001731 (uint64_t) pipeline, psoNumSamples, (uint64_t) pCB->activeRenderPass, subpassNumSamples);
Tobin Ehliseba312c2015-04-01 08:40:34 -06001732 }
1733 } else {
1734 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
1735 // Verify and flag error as appropriate
1736 }
1737 // TODO : Add more checks here
1738 } else {
1739 // TODO : Validate non-gfx pipeline updates
1740 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001741 return VK_FALSE;
Tobin Ehliseba312c2015-04-01 08:40:34 -06001742}
1743
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001744// Block of code at start here specifically for managing/tracking DSs
1745
Tobin Ehlis793ad302015-04-03 12:01:11 -06001746// Return Pool node ptr for specified pool or else NULL
Mark Lobodzinski39298632015-11-18 08:38:27 -07001747static DESCRIPTOR_POOL_NODE* getPoolNode(layer_data* my_data, const VkDescriptorPool pool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001748{
1749 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07001750 if (my_data->descriptorPoolMap.find(pool) == my_data->descriptorPoolMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001751 loader_platform_thread_unlock_mutex(&globalLock);
1752 return NULL;
1753 }
1754 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07001755 return my_data->descriptorPoolMap[pool];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001756}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001757
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001758static LAYOUT_NODE* getLayoutNode(layer_data* my_data, const VkDescriptorSetLayout layout) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001759 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001760 if (my_data->descriptorSetLayoutMap.find(layout) == my_data->descriptorSetLayoutMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001761 loader_platform_thread_unlock_mutex(&globalLock);
1762 return NULL;
1763 }
1764 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001765 return my_data->descriptorSetLayoutMap[layout];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001766}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001767
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001768// 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 -06001769static VkBool32 validUpdateStruct(layer_data* my_data, const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001770{
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001771 switch (pUpdateStruct->sType)
1772 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001773 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1774 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001775 return VK_FALSE;
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001776 default:
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001777 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 -06001778 "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 -06001779 }
1780}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001781
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001782// Set count for given update struct in the last parameter
Courtney Goeltzenleuchter085f8dd2015-12-16 16:08:44 -07001783// 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 -06001784static uint32_t getUpdateCount(layer_data* my_data, const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis793ad302015-04-03 12:01:11 -06001785{
1786 switch (pUpdateStruct->sType)
1787 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001788 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
Chia-I Wud50a7d72015-10-26 20:48:51 +08001789 return ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorCount;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001790 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis793ad302015-04-03 12:01:11 -06001791 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wud50a7d72015-10-26 20:48:51 +08001792 return ((VkCopyDescriptorSet*)pUpdateStruct)->descriptorCount;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001793 }
Courtney Goeltzenleuchter7f47bca2015-12-16 16:08:08 -07001794
1795 return 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001796}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001797
Tobin Ehlis793ad302015-04-03 12:01:11 -06001798// For given Layout Node and binding, return index where that binding begins
1799static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
1800{
1801 uint32_t offsetIndex = 0;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001802 for (uint32_t i = 0; i < pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001803 if (pLayout->createInfo.pBindings[i].binding == binding)
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001804 break;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001805 offsetIndex += pLayout->createInfo.pBindings[i].descriptorCount;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001806 }
1807 return offsetIndex;
1808}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001809
Tobin Ehlis793ad302015-04-03 12:01:11 -06001810// For given layout node and binding, return last index that is updated
1811static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
1812{
1813 uint32_t offsetIndex = 0;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001814 for (uint32_t i = 0; i < pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001815 offsetIndex += pLayout->createInfo.pBindings[i].descriptorCount;
1816 if (pLayout->createInfo.pBindings[i].binding == binding)
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001817 break;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001818 }
1819 return offsetIndex-1;
1820}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001821
Tobin Ehlisbaca3ab2015-10-27 12:54:50 -06001822// For given layout and update, return the first overall index of the layout that is updated
Tobin Ehlis8a62e632015-10-27 15:43:38 -06001823static 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 -06001824{
Tobin Ehlisbaca3ab2015-10-27 12:54:50 -06001825 return getBindingStartIndex(pLayout, binding)+arrayIndex;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001826}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001827
Tobin Ehlis8a62e632015-10-27 15:43:38 -06001828// For given layout and update, return the last overall index of the layout that is updated
1829static 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 -06001830{
Tobin Ehlis8a62e632015-10-27 15:43:38 -06001831 uint32_t count = getUpdateCount(my_data, device, pUpdateStruct);
Tobin Ehlisbaca3ab2015-10-27 12:54:50 -06001832 return getBindingStartIndex(pLayout, binding)+arrayIndex+count-1;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001833}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001834
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001835// Verify that the descriptor type in the update struct matches what's expected by the layout
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001836static 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 -06001837{
1838 // First get actual type of update
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001839 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001840 VkDescriptorType actualType;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001841 uint32_t i = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001842 switch (pUpdateStruct->sType)
1843 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001844 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1845 actualType = ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorType;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001846 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001847 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
1848 /* no need to validate */
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001849 return VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001850 break;
1851 default:
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001852 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 -06001853 "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 -06001854 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001855 if (VK_FALSE == skipCall) {
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001856 // Set first stageFlags as reference and verify that all other updates match it
1857 VkShaderStageFlags refStageFlags = pLayout->stageFlags[startIndex];
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001858 for (i = startIndex; i <= endIndex; i++) {
Tobin Ehlis644ff042015-10-20 10:11:55 -06001859 if (pLayout->descriptorTypes[i] != actualType) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001860 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 -06001861 "Write descriptor update has descriptor type %s that does not match overlapping binding descriptor type of %s!",
1862 string_VkDescriptorType(actualType), string_VkDescriptorType(pLayout->descriptorTypes[i]));
1863 }
1864 if (pLayout->stageFlags[i] != refStageFlags) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001865 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 -06001866 "Write descriptor update has stageFlags %x that do not match overlapping binding descriptor stageFlags of %x!",
1867 refStageFlags, pLayout->stageFlags[i]);
Tobin Ehlis483cc352015-09-30 08:30:20 -06001868 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001869 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001870 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001871 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001872}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001873
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001874// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001875// struct into the pNewNode param. Return VK_TRUE if error condition encountered and callback signals early exit.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001876// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001877static VkBool32 shadowUpdateNode(layer_data* my_data, const VkDevice device, GENERIC_HEADER* pUpdate, GENERIC_HEADER** pNewNode)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001878{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001879 VkBool32 skipCall = VK_FALSE;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001880 VkWriteDescriptorSet* pWDS = NULL;
1881 VkCopyDescriptorSet* pCDS = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001882 size_t array_size = 0;
1883 size_t base_array_size = 0;
1884 size_t total_array_size = 0;
1885 size_t baseBuffAddr = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001886 switch (pUpdate->sType)
1887 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001888 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1889 pWDS = new VkWriteDescriptorSet;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001890 *pNewNode = (GENERIC_HEADER*)pWDS;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001891 memcpy(pWDS, pUpdate, sizeof(VkWriteDescriptorSet));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001892
1893 switch (pWDS->descriptorType) {
1894 case VK_DESCRIPTOR_TYPE_SAMPLER:
1895 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
1896 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
1897 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
1898 {
Chia-I Wud50a7d72015-10-26 20:48:51 +08001899 VkDescriptorImageInfo *info = new VkDescriptorImageInfo[pWDS->descriptorCount];
1900 memcpy(info, pWDS->pImageInfo, pWDS->descriptorCount * sizeof(VkDescriptorImageInfo));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001901 pWDS->pImageInfo = info;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001902 }
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001903 break;
1904 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
1905 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
1906 {
Chia-I Wud50a7d72015-10-26 20:48:51 +08001907 VkBufferView *info = new VkBufferView[pWDS->descriptorCount];
1908 memcpy(info, pWDS->pTexelBufferView, pWDS->descriptorCount * sizeof(VkBufferView));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001909 pWDS->pTexelBufferView = info;
1910 }
1911 break;
1912 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
1913 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
1914 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
1915 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
1916 {
Chia-I Wud50a7d72015-10-26 20:48:51 +08001917 VkDescriptorBufferInfo *info = new VkDescriptorBufferInfo[pWDS->descriptorCount];
1918 memcpy(info, pWDS->pBufferInfo, pWDS->descriptorCount * sizeof(VkDescriptorBufferInfo));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001919 pWDS->pBufferInfo = info;
1920 }
1921 break;
1922 default:
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07001923 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001924 break;
1925 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001926 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001927 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
1928 pCDS = new VkCopyDescriptorSet;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001929 *pNewNode = (GENERIC_HEADER*)pCDS;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001930 memcpy(pCDS, pUpdate, sizeof(VkCopyDescriptorSet));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001931 break;
1932 default:
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001933 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 -06001934 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdate->sType), pUpdate->sType))
1935 return VK_TRUE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001936 }
1937 // Make sure that pNext for the end of shadow copy is NULL
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001938 (*pNewNode)->pNext = NULL;
1939 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001940}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001941
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001942// Verify that given sampler is valid
1943static VkBool32 validateSampler(const layer_data* my_data, const VkSampler* pSampler, const VkBool32 immutable)
1944{
1945 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08001946 auto sampIt = my_data->sampleMap.find(*pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001947 if (sampIt == my_data->sampleMap.end()) {
1948 if (!immutable) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001949 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 +08001950 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid sampler %#" PRIxLEAST64, (uint64_t) *pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001951 } else { // immutable
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001952 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 +08001953 "vkUpdateDescriptorSets: Attempt to update descriptor whose binding has an invalid immutable sampler %#" PRIxLEAST64, (uint64_t) *pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001954 }
1955 } else {
1956 // TODO : Any further checks we want to do on the sampler?
1957 }
1958 return skipCall;
1959}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001960
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001961// Verify that given imageView is valid
1962static VkBool32 validateImageView(const layer_data* my_data, const VkImageView* pImageView, const VkImageLayout imageLayout)
1963{
1964 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08001965 auto ivIt = my_data->imageViewMap.find(*pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001966 if (ivIt == my_data->imageViewMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001967 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 +08001968 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid imageView %#" PRIxLEAST64, (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001969 } else {
1970 // Validate that imageLayout is compatible with aspectMask and image format
1971 VkImageAspectFlags aspectMask = ivIt->second->subresourceRange.aspectMask;
Chia-I Wue2fc5522015-10-26 20:04:44 +08001972 VkImage image = ivIt->second->image;
Michael Lentine7b236262015-10-23 12:41:44 -07001973 // TODO : Check here in case we have a bad image
Chia-I Wue2fc5522015-10-26 20:04:44 +08001974 auto imgIt = my_data->imageMap.find(image);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001975 if (imgIt == my_data->imageMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001976 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 -07001977 "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 -06001978 } else {
1979 VkFormat format = (*imgIt).second->format;
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07001980 VkBool32 ds = vk_format_is_depth_or_stencil(format);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001981 switch (imageLayout) {
1982 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
1983 // Only Color bit must be set
1984 if ((aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) != VK_IMAGE_ASPECT_COLOR_BIT) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001985 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 -06001986 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 +08001987 " that does not have VK_IMAGE_ASPECT_COLOR_BIT set.", (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001988 }
1989 // format must NOT be DS
1990 if (ds) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001991 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 -06001992 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 +08001993 " 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 -06001994 }
1995 break;
1996 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
1997 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
1998 // Depth or stencil bit must be set, but both must NOT be set
1999 if (aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) {
2000 if (aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) {
2001 // both must NOT be set
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002002 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, (uint64_t) *pImageView, __LINE__,
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002003 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with imageView %#" PRIxLEAST64 ""
Chia-I Wue2fc5522015-10-26 20:04:44 +08002004 " that has both STENCIL and DEPTH aspects set", (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002005 }
2006 } else if (!(aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)) {
2007 // Neither were set
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002008 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 -06002009 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout %s and imageView %#" PRIxLEAST64 ""
Chia-I Wue2fc5522015-10-26 20:04:44 +08002010 " that does not have STENCIL or DEPTH aspect set.", string_VkImageLayout(imageLayout), (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002011 }
2012 // format must be DS
2013 if (!ds) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002014 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 -06002015 DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout %s and imageView %#" PRIxLEAST64 ""
Chia-I Wue2fc5522015-10-26 20:04:44 +08002016 " 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 -06002017 }
2018 break;
2019 default:
2020 // anything to check for other layouts?
2021 break;
2022 }
2023 }
2024 }
2025 return skipCall;
2026}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002027
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002028// Verify that given bufferView is valid
2029static VkBool32 validateBufferView(const layer_data* my_data, const VkBufferView* pBufferView)
2030{
2031 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002032 auto sampIt = my_data->bufferViewMap.find(*pBufferView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002033 if (sampIt == my_data->bufferViewMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002034 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 +08002035 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid bufferView %#" PRIxLEAST64, (uint64_t) *pBufferView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002036 } else {
2037 // TODO : Any further checks we want to do on the bufferView?
2038 }
2039 return skipCall;
2040}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002041
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002042// Verify that given bufferInfo is valid
2043static VkBool32 validateBufferInfo(const layer_data* my_data, const VkDescriptorBufferInfo* pBufferInfo)
2044{
2045 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002046 auto sampIt = my_data->bufferMap.find(pBufferInfo->buffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002047 if (sampIt == my_data->bufferMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002048 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 +08002049 "vkUpdateDescriptorSets: Attempt to update descriptor where bufferInfo has invalid buffer %#" PRIxLEAST64, (uint64_t) pBufferInfo->buffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002050 } else {
2051 // TODO : Any further checks we want to do on the bufferView?
2052 }
2053 return skipCall;
2054}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002055
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002056static VkBool32 validateUpdateContents(const layer_data* my_data, const VkWriteDescriptorSet *pWDS, const VkDescriptorSetLayoutBinding* pLayoutBinding)
2057{
2058 VkBool32 skipCall = VK_FALSE;
2059 // First verify that for the given Descriptor type, the correct DescriptorInfo data is supplied
2060 VkBufferView* pBufferView = NULL;
2061 const VkSampler* pSampler = NULL;
2062 VkImageView* pImageView = NULL;
2063 VkImageLayout* pImageLayout = NULL;
2064 VkDescriptorBufferInfo* pBufferInfo = NULL;
2065 VkBool32 immutable = VK_FALSE;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002066 uint32_t i = 0;
2067 // For given update type, verify that update contents are correct
2068 switch (pWDS->descriptorType) {
2069 case VK_DESCRIPTOR_TYPE_SAMPLER:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002070 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002071 skipCall |= validateSampler(my_data, &(pWDS->pImageInfo[i].sampler), immutable);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002072 }
2073 break;
2074 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002075 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002076 if (NULL == pLayoutBinding->pImmutableSamplers) {
2077 pSampler = &(pWDS->pImageInfo[i].sampler);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002078 if (immutable) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002079 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 -06002080 "vkUpdateDescriptorSets: Update #%u is not an immutable sampler %#" PRIxLEAST64 ", but previous update(s) from this "
2081 "VkWriteDescriptorSet struct used an immutable sampler. All updates from a single struct must either "
Chia-I Wue2fc5522015-10-26 20:04:44 +08002082 "use immutable or non-immutable samplers.", i, (uint64_t) *pSampler);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002083 }
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002084 } else {
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002085 if (i>0 && !immutable) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002086 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 -06002087 "vkUpdateDescriptorSets: Update #%u is an immutable sampler, but previous update(s) from this "
2088 "VkWriteDescriptorSet struct used a non-immutable sampler. All updates from a single struct must either "
2089 "use immutable or non-immutable samplers.", i);
2090 }
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002091 immutable = VK_TRUE;
2092 pSampler = &(pLayoutBinding->pImmutableSamplers[i]);
2093 }
2094 skipCall |= validateSampler(my_data, pSampler, immutable);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002095 }
2096 // Intentionally fall through here to also validate image stuff
2097 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2098 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
2099 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002100 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002101 skipCall |= validateImageView(my_data, &(pWDS->pImageInfo[i].imageView), pWDS->pImageInfo[i].imageLayout);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002102 }
2103 break;
2104 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2105 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002106 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002107 skipCall |= validateBufferView(my_data, &(pWDS->pTexelBufferView[i]));
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002108 }
2109 break;
2110 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2111 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2112 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2113 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002114 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002115 skipCall |= validateBufferInfo(my_data, &(pWDS->pBufferInfo[i]));
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002116 }
2117 break;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002118 }
2119 return skipCall;
2120}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002121
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002122// update DS mappings based on write and copy update arrays
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08002123static 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 -06002124{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002125 VkBool32 skipCall = VK_FALSE;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002126
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002127 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002128 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002129 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002130 // Validate Write updates
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002131 uint32_t i = 0;
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08002132 for (i=0; i < descriptorWriteCount; i++) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002133 VkDescriptorSet ds = pWDS[i].dstSet;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002134 SET_NODE* pSet = my_data->setMap[ds];
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002135 GENERIC_HEADER* pUpdate = (GENERIC_HEADER*) &pWDS[i];
Tobin Ehlis793ad302015-04-03 12:01:11 -06002136 pLayout = pSet->pLayout;
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002137 // First verify valid update struct
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06002138 if ((skipCall = validUpdateStruct(my_data, device, pUpdate)) == VK_TRUE) {
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002139 break;
2140 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002141 uint32_t binding = 0, endIndex = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002142 binding = pWDS[i].dstBinding;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002143 // Make sure that layout being updated has the binding being updated
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002144 if (pLayout->bindings.find(binding) == pLayout->bindings.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002145 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 -08002146 "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 -06002147 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06002148 // Next verify that update falls within size of given binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002149 endIndex = getUpdateEndIndex(my_data, device, pLayout, binding, pWDS[i].dstArrayElement, pUpdate);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002150 if (getBindingEndIndex(pLayout, binding) < endIndex) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06002151 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002152 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002153 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 -06002154 "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 -06002155 } else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002156 uint32_t startIndex;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002157 startIndex = getUpdateStartIndex(my_data, device, pLayout, binding, pWDS[i].dstArrayElement, pUpdate);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002158 // Layout bindings match w/ update, now verify that update type & stageFlags are the same for entire update
2159 if ((skipCall = validateUpdateConsistency(my_data, device, pLayout, pUpdate, startIndex, endIndex)) == VK_FALSE) {
2160 // The update is within bounds and consistent, but need to make sure contents make sense as well
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002161 if ((skipCall = validateUpdateContents(my_data, &pWDS[i], &pLayout->createInfo.pBindings[binding])) == VK_FALSE) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002162 // Update is good. Save the update info
2163 // Create new update struct for this set's shadow copy
2164 GENERIC_HEADER* pNewNode = NULL;
2165 skipCall |= shadowUpdateNode(my_data, device, pUpdate, &pNewNode);
2166 if (NULL == pNewNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002167 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 -06002168 "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
2169 } else {
2170 // Insert shadow node into LL of updates for this set
2171 pNewNode->pNext = pSet->pUpdateStructs;
2172 pSet->pUpdateStructs = pNewNode;
2173 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002174 for (uint32_t j = startIndex; j <= endIndex; j++) {
2175 assert(j<pSet->descriptorCount);
2176 pSet->ppDescriptors[j] = pNewNode;
2177 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002178 }
2179 }
2180 }
2181 }
2182 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002183 }
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002184 // Now validate copy updates
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08002185 for (i=0; i < descriptorCopyCount; ++i) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002186 SET_NODE *pSrcSet = NULL, *pDstSet = NULL;
2187 LAYOUT_NODE *pSrcLayout = NULL, *pDstLayout = NULL;
2188 uint32_t srcStartIndex = 0, srcEndIndex = 0, dstStartIndex = 0, dstEndIndex = 0;
2189 // For each copy make sure that update falls within given layout and that types match
Chia-I Wue2fc5522015-10-26 20:04:44 +08002190 pSrcSet = my_data->setMap[pCDS[i].srcSet];
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002191 pDstSet = my_data->setMap[pCDS[i].dstSet];
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002192 pSrcLayout = pSrcSet->pLayout;
2193 pDstLayout = pDstSet->pLayout;
2194 // Validate that src binding is valid for src set layout
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002195 if (pSrcLayout->bindings.find(pCDS[i].srcBinding) == pSrcLayout->bindings.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002196 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 -06002197 "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 +08002198 i, pCDS[i].srcBinding, (uint64_t) pSrcLayout->layout, pSrcLayout->createInfo.bindingCount-1);
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002199 } else if (pDstLayout->bindings.find(pCDS[i].dstBinding) == pDstLayout->bindings.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002200 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 +08002201 "Copy descriptor update %u has dstBinding %u which is out of bounds for underlying SetLayout %#" PRIxLEAST64 " which only has bindings 0-%u.",
2202 i, pCDS[i].dstBinding, (uint64_t) pDstLayout->layout, pDstLayout->createInfo.bindingCount-1);
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002203 } else {
2204 // Proceed with validation. Bindings are ok, but make sure update is within bounds of given layout
2205 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 +08002206 dstEndIndex = getUpdateEndIndex(my_data, device, pDstLayout, pCDS[i].dstBinding, pCDS[i].dstArrayElement, (const GENERIC_HEADER*)&(pCDS[i]));
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002207 if (getBindingEndIndex(pSrcLayout, pCDS[i].srcBinding) < srcEndIndex) {
2208 pLayoutCI = &pSrcLayout->createInfo;
2209 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002210 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 -06002211 "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 +08002212 } else if (getBindingEndIndex(pDstLayout, pCDS[i].dstBinding) < dstEndIndex) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002213 pLayoutCI = &pDstLayout->createInfo;
2214 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002215 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 +08002216 "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 -06002217 } else {
2218 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 +08002219 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 +08002220 for (uint32_t j=0; j<pCDS[i].descriptorCount; ++j) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002221 // For copy just make sure that the types match and then perform the update
2222 if (pSrcLayout->descriptorTypes[srcStartIndex+j] != pDstLayout->descriptorTypes[dstStartIndex+j]) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002223 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 -06002224 "Copy descriptor update index %u, update count #%u, has src update descriptor type %s that does not match overlapping dest descriptor type of %s!",
2225 i, j+1, string_VkDescriptorType(pSrcLayout->descriptorTypes[srcStartIndex+j]), string_VkDescriptorType(pDstLayout->descriptorTypes[dstStartIndex+j]));
2226 } else {
2227 // point dst descriptor at corresponding src descriptor
Tobin Ehlisf6585052015-12-17 11:48:42 -07002228 // TODO : This may be a hole. I believe copy should be its own copy,
2229 // otherwise a subsequent write update to src will incorrectly affect the copy
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002230 pDstSet->ppDescriptors[j+dstStartIndex] = pSrcSet->ppDescriptors[j+srcStartIndex];
2231 }
2232 }
2233 }
2234 }
2235 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002236 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002237 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002238}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002239
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002240// Verify that given pool has descriptors that are being requested for allocation
Mark Lobodzinski39298632015-11-18 08:38:27 -07002241static 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 -06002242{
2243 VkBool32 skipCall = VK_FALSE;
2244 uint32_t i = 0, j = 0;
2245 for (i=0; i<count; ++i) {
2246 LAYOUT_NODE* pLayout = getLayoutNode(dev_data, pSetLayouts[i]);
2247 if (NULL == pLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002248 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 +08002249 "Unable to find set layout node for layout %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pSetLayouts[i]);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002250 } else {
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002251 uint32_t typeIndex = 0, poolSizeCount = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002252 for (j=0; j<pLayout->createInfo.bindingCount; ++j) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002253 typeIndex = static_cast<uint32_t>(pLayout->createInfo.pBindings[j].descriptorType);
2254 poolSizeCount = pLayout->createInfo.pBindings[j].descriptorCount;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002255 if (poolSizeCount > pPoolNode->availableDescriptorTypeCount[typeIndex]) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002256 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 -06002257 "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 -07002258 poolSizeCount, string_VkDescriptorType(pLayout->createInfo.pBindings[j].descriptorType), (uint64_t) pPoolNode->pool, pPoolNode->availableDescriptorTypeCount[typeIndex]);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002259 } else { // Decrement available descriptors of this type
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002260 pPoolNode->availableDescriptorTypeCount[typeIndex] -= poolSizeCount;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002261 }
2262 }
2263 }
2264 }
2265 return skipCall;
2266}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002267
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002268// Free the shadowed update node for this Set
2269// NOTE : Calls to this function should be wrapped in mutex
2270static void freeShadowUpdateTree(SET_NODE* pSet)
2271{
2272 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
2273 pSet->pUpdateStructs = NULL;
2274 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
2275 // Clear the descriptor mappings as they will now be invalid
2276 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
2277 while(pShadowUpdate) {
2278 pFreeUpdate = pShadowUpdate;
2279 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
2280 uint32_t index = 0;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002281 VkWriteDescriptorSet * pWDS = NULL;
2282 VkCopyDescriptorSet * pCDS = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002283 void** ppToFree = NULL;
2284 switch (pFreeUpdate->sType)
2285 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002286 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
2287 pWDS = (VkWriteDescriptorSet*)pFreeUpdate;
Tony Barbourb1947942015-11-02 11:46:29 -07002288 switch (pWDS->descriptorType) {
2289 case VK_DESCRIPTOR_TYPE_SAMPLER:
2290 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
2291 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2292 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
2293 {
2294 delete[] pWDS->pImageInfo;
2295 }
2296 break;
2297 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2298 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
2299 {
2300 delete[] pWDS->pTexelBufferView;
2301 }
2302 break;
2303 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2304 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2305 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2306 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
2307 {
2308 delete[] pWDS->pBufferInfo;
2309 }
2310 break;
2311 default:
2312 break;
Courtney Goeltzenleuchteraa132e72015-10-22 15:31:56 -06002313 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002314 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002315 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002316 break;
2317 default:
2318 assert(0);
2319 break;
2320 }
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002321 delete pFreeUpdate;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002322 }
2323}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002324
Tobin Ehlis793ad302015-04-03 12:01:11 -06002325// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002326// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002327static void deletePools(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002328{
Mark Lobodzinski39298632015-11-18 08:38:27 -07002329 if (my_data->descriptorPoolMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06002330 return;
Mark Lobodzinski39298632015-11-18 08:38:27 -07002331 for (auto ii=my_data->descriptorPoolMap.begin(); ii!=my_data->descriptorPoolMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002332 SET_NODE* pSet = (*ii).second->pSets;
2333 SET_NODE* pFreeSet = pSet;
2334 while (pSet) {
2335 pFreeSet = pSet;
2336 pSet = pSet->pNext;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002337 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002338 // Free Update shadow struct tree
2339 freeShadowUpdateTree(pFreeSet);
2340 if (pFreeSet->ppDescriptors) {
Chris Forbes02038792015-06-04 10:49:27 +12002341 delete[] pFreeSet->ppDescriptors;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002342 }
2343 delete pFreeSet;
2344 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002345 delete (*ii).second;
2346 }
Mark Lobodzinski39298632015-11-18 08:38:27 -07002347 my_data->descriptorPoolMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002348}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002349
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002350// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002351// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002352static void deleteLayouts(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002353{
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07002354 if (my_data->descriptorSetLayoutMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06002355 return;
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07002356 for (auto ii=my_data->descriptorSetLayoutMap.begin(); ii!=my_data->descriptorSetLayoutMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002357 LAYOUT_NODE* pLayout = (*ii).second;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002358 if (pLayout->createInfo.pBindings) {
Chia-I Wud50a7d72015-10-26 20:48:51 +08002359 for (uint32_t i=0; i<pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002360 if (pLayout->createInfo.pBindings[i].pImmutableSamplers)
2361 delete[] pLayout->createInfo.pBindings[i].pImmutableSamplers;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002362 }
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002363 delete[] pLayout->createInfo.pBindings;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002364 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002365 delete pLayout;
2366 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07002367 my_data->descriptorSetLayoutMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002368}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002369
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002370// Currently clearing a set is removing all previous updates to that set
2371// TODO : Validate if this is correct clearing behavior
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002372static void clearDescriptorSet(layer_data* my_data, VkDescriptorSet set)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002373{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002374 SET_NODE* pSet = getSetNode(my_data, set);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002375 if (!pSet) {
2376 // TODO : Return error
Tobin Ehlisce132d82015-06-19 15:07:05 -06002377 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002378 loader_platform_thread_lock_mutex(&globalLock);
2379 freeShadowUpdateTree(pSet);
2380 loader_platform_thread_unlock_mutex(&globalLock);
2381 }
2382}
2383
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002384static void clearDescriptorPool(layer_data* my_data, const VkDevice device, const VkDescriptorPool pool, VkDescriptorPoolResetFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002385{
Mark Lobodzinski39298632015-11-18 08:38:27 -07002386 DESCRIPTOR_POOL_NODE* pPool = getPoolNode(my_data, pool);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002387 if (!pPool) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002388 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 +08002389 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkResetDescriptorPool() call", (uint64_t) pool);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002390 } else {
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002391 // TODO: validate flags
Tobin Ehlis793ad302015-04-03 12:01:11 -06002392 // For every set off of this pool, clear it
2393 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002394 while (pSet) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002395 clearDescriptorSet(my_data, pSet->set);
Mark Lobodzinskidcce0792016-01-04 09:40:19 -07002396 pSet = pSet->pNext;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002397 }
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002398 // Reset available count to max count for this pool
2399 for (uint32_t i=0; i<pPool->availableDescriptorTypeCount.size(); ++i) {
2400 pPool->availableDescriptorTypeCount[i] = pPool->maxDescriptorTypeCount[i];
2401 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002402 }
2403}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002404
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002405// For given CB object, fetch associated CB Node from map
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002406static GLOBAL_CB_NODE* getCBNode(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002407{
2408 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002409 if (my_data->commandBufferMap.count(cb) == 0) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002410 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002411 // TODO : How to pass cb as srcObj here?
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002412 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 +08002413 "Attempt to use CommandBuffer %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<uint64_t>(cb));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002414 return NULL;
2415 }
2416 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002417 return my_data->commandBufferMap[cb];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002418}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002419
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002420// Free all CB Nodes
2421// NOTE : Calls to this function should be wrapped in mutex
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002422static void deleteCommandBuffers(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002423{
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002424 if (my_data->commandBufferMap.size() <= 0) {
David Pinedod8f83d82015-04-27 16:36:17 -06002425 return;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002426 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002427 for (auto ii=my_data->commandBufferMap.begin(); ii!=my_data->commandBufferMap.end(); ++ii) {
Courtney Goeltzenleuchterea3117c2015-04-27 15:04:43 -06002428 vector<CMD_NODE*> cmd_node_list = (*ii).second->pCmds;
2429 while (!cmd_node_list.empty()) {
2430 CMD_NODE* cmd_node = cmd_node_list.back();
2431 delete cmd_node;
2432 cmd_node_list.pop_back();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002433 }
2434 delete (*ii).second;
2435 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002436 my_data->commandBufferMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002437}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002438
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002439static 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 -06002440{
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002441 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 -07002442 (uint64_t)cb, __LINE__, DRAWSTATE_NO_BEGIN_COMMAND_BUFFER, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002443 "You must call vkBeginCommandBuffer() before this call to %s", caller_name);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002444}
Michael Lentine3dea6512015-10-28 15:55:18 -07002445
Mark Youngb20a6a82016-01-07 15:41:43 -07002446VkBool32 validateCmdsInCmdBuffer(const layer_data* dev_data, const GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd_type) {
2447 if (!pCB->activeRenderPass) return VK_FALSE;
2448 VkBool32 skip_call = VK_FALSE;
Michael Lentine2e068b22015-12-29 16:05:27 -06002449 if (pCB->activeSubpassContents == VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS && cmd_type != CMD_EXECUTECOMMANDS) {
2450 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
2451 DRAWSTATE_INVALID_COMMAND_BUFFER, "DS", "Commands cannot be called in a subpass using secondary command buffers.");
2452 } else if (pCB->activeSubpassContents == VK_SUBPASS_CONTENTS_INLINE && cmd_type == CMD_EXECUTECOMMANDS) {
2453 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
2454 DRAWSTATE_INVALID_COMMAND_BUFFER, "DS", "vkCmdExecuteCommands() cannot be called in a subpass using inline commands.");
2455 }
Michael Lentine3dea6512015-10-28 15:55:18 -07002456 return skip_call;
2457}
2458
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002459// Add specified CMD to the CmdBuffer in given pCB, flagging errors if CB is not
2460// in the recording state or if there's an issue with the Cmd ordering
2461static 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 -06002462{
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002463 VkBool32 skipCall = VK_FALSE;
2464 if (pCB->state != CB_RECORDING) {
2465 skipCall |= report_error_no_cb_begin(my_data, pCB->commandBuffer, caller_name);
2466 skipCall |= validateCmdsInCmdBuffer(my_data, pCB, cmd);
2467 CMD_NODE* pCmd = new CMD_NODE;
2468 if (pCmd) {
2469 // init cmd node and append to end of cmd LL
2470 memset(pCmd, 0, sizeof(CMD_NODE));
2471 pCmd->cmdNumber = ++pCB->numCmds;
2472 pCmd->type = cmd;
2473 pCB->pCmds.push_back(pCmd);
2474 } else {
2475 // TODO : How to pass cb as srcObj here?
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002476 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 -07002477 "Out of memory while attempting to allocate new CMD_NODE for commandBuffer %#" PRIxLEAST64, reinterpret_cast<uint64_t>(pCB->commandBuffer));
2478 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002479 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002480 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002481}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002482
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002483static void resetCB(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002484{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002485 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002486 if (pCB) {
Courtney Goeltzenleuchter3597a202015-04-27 17:16:56 -06002487 vector<CMD_NODE*> cmd_list = pCB->pCmds;
2488 while (!cmd_list.empty()) {
2489 delete cmd_list.back();
2490 cmd_list.pop_back();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002491 }
Courtney Goeltzenleuchter3597a202015-04-27 17:16:56 -06002492 pCB->pCmds.clear();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06002493 // Reset CB state (need to save createInfo)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002494 VkCommandBufferAllocateInfo saveCBCI = pCB->createInfo;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002495 pCB->commandBuffer = cb;
Tobin Ehlis59278bf2015-08-18 07:10:58 -06002496 pCB->createInfo = saveCBCI;
Michael Lentineabc5e922015-10-12 11:30:14 -05002497 memset(&pCB->beginInfo, 0, sizeof(VkCommandBufferBeginInfo));
2498 pCB->fence = 0;
2499 pCB->numCmds = 0;
2500 memset(pCB->drawCount, 0, NUM_DRAW_TYPES * sizeof(uint64_t));
2501 pCB->state = CB_NEW;
2502 pCB->submitCount = 0;
2503 pCB->status = 0;
2504 pCB->pCmds.clear();
2505 pCB->lastBoundPipeline = 0;
2506 pCB->viewports.clear();
2507 pCB->scissors.clear();
2508 pCB->lineWidth = 0;
2509 pCB->depthBiasConstantFactor = 0;
2510 pCB->depthBiasClamp = 0;
2511 pCB->depthBiasSlopeFactor = 0;
2512 memset(pCB->blendConstants, 0, 4 * sizeof(float));
2513 pCB->minDepthBounds = 0;
2514 pCB->maxDepthBounds = 0;
2515 memset(&pCB->front, 0, sizeof(stencil_data));
2516 memset(&pCB->back, 0, sizeof(stencil_data));
2517 pCB->lastBoundDescriptorSet = 0;
2518 pCB->lastBoundPipelineLayout = 0;
2519 pCB->activeRenderPass = 0;
2520 pCB->activeSubpass = 0;
2521 pCB->framebuffer = 0;
Michael Lentineabc5e922015-10-12 11:30:14 -05002522 pCB->boundDescriptorSets.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07002523 pCB->drawData.clear();
2524 pCB->currentDrawData.buffers.clear();
Michael Lentineabc5e922015-10-12 11:30:14 -05002525 pCB->imageLayoutMap.clear();
Michael Lentineb887b0a2015-12-29 14:12:11 -06002526 pCB->waitedEvents.clear();
2527 pCB->waitedEventsBeforeQueryReset.clear();
2528 pCB->queryToStateMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002529 }
2530}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002531
Tobin Ehlis963a4042015-09-29 08:18:34 -06002532// Set PSO-related status bits for CB, including dynamic state set via PSO
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002533static void set_cb_pso_status(GLOBAL_CB_NODE* pCB, const PIPELINE_NODE* pPipe)
2534{
2535 for (uint32_t i = 0; i < pPipe->cbStateCI.attachmentCount; i++) {
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002536 if (0 != pPipe->pAttachments[i].colorWriteMask) {
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002537 pCB->status |= CBSTATUS_COLOR_BLEND_WRITE_ENABLE;
2538 }
2539 }
2540 if (pPipe->dsStateCI.depthWriteEnable) {
Cody Northrop82485a82015-08-18 15:21:16 -06002541 pCB->status |= CBSTATUS_DEPTH_WRITE_ENABLE;
2542 }
Cody Northrop82485a82015-08-18 15:21:16 -06002543 if (pPipe->dsStateCI.stencilTestEnable) {
2544 pCB->status |= CBSTATUS_STENCIL_TEST_ENABLE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002545 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06002546 // Account for any dynamic state not set via this PSO
2547 if (!pPipe->dynStateCI.dynamicStateCount) { // All state is static
2548 pCB->status = CBSTATUS_ALL;
2549 } else {
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002550 // First consider all state on
2551 // Then unset any state that's noted as dynamic in PSO
2552 // Finally OR that into CB statemask
2553 CBStatusFlags psoDynStateMask = CBSTATUS_ALL;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002554 for (uint32_t i=0; i < pPipe->dynStateCI.dynamicStateCount; i++) {
2555 switch (pPipe->dynStateCI.pDynamicStates[i]) {
2556 case VK_DYNAMIC_STATE_VIEWPORT:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002557 psoDynStateMask &= ~CBSTATUS_VIEWPORT_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002558 break;
2559 case VK_DYNAMIC_STATE_SCISSOR:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002560 psoDynStateMask &= ~CBSTATUS_SCISSOR_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002561 break;
2562 case VK_DYNAMIC_STATE_LINE_WIDTH:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002563 psoDynStateMask &= ~CBSTATUS_LINE_WIDTH_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002564 break;
2565 case VK_DYNAMIC_STATE_DEPTH_BIAS:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002566 psoDynStateMask &= ~CBSTATUS_DEPTH_BIAS_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002567 break;
2568 case VK_DYNAMIC_STATE_BLEND_CONSTANTS:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002569 psoDynStateMask &= ~CBSTATUS_BLEND_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002570 break;
2571 case VK_DYNAMIC_STATE_DEPTH_BOUNDS:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002572 psoDynStateMask &= ~CBSTATUS_DEPTH_BOUNDS_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002573 break;
2574 case VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002575 psoDynStateMask &= ~CBSTATUS_STENCIL_READ_MASK_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002576 break;
2577 case VK_DYNAMIC_STATE_STENCIL_WRITE_MASK:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002578 psoDynStateMask &= ~CBSTATUS_STENCIL_WRITE_MASK_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002579 break;
2580 case VK_DYNAMIC_STATE_STENCIL_REFERENCE:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002581 psoDynStateMask &= ~CBSTATUS_STENCIL_REFERENCE_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002582 break;
2583 default:
2584 // TODO : Flag error here
2585 break;
2586 }
2587 }
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002588 pCB->status |= psoDynStateMask;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002589 }
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002590}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002591
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002592// Print the last bound Gfx Pipeline
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002593static VkBool32 printPipeline(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002594{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002595 VkBool32 skipCall = VK_FALSE;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002596 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002597 if (pCB) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002598 PIPELINE_NODE *pPipeTrav = getPipeline(my_data, pCB->lastBoundPipeline);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002599 if (!pPipeTrav) {
2600 // nothing to print
Tobin Ehlisce132d82015-06-19 15:07:05 -06002601 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002602 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 -08002603 "%s", vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002604 }
2605 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002606 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002607}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002608
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002609// Print details of DS config to stdout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002610static VkBool32 printDSConfig(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002611{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002612 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002613 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 -06002614 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis93f89e82015-06-09 08:39:32 -06002615 if (pCB && pCB->lastBoundDescriptorSet) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002616 SET_NODE* pSet = getSetNode(my_data, pCB->lastBoundDescriptorSet);
Mark Lobodzinski39298632015-11-18 08:38:27 -07002617 DESCRIPTOR_POOL_NODE* pPool = getPoolNode(my_data, pSet->pool);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002618 // Print out pool details
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002619 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 +08002620 "Details for pool %#" PRIxLEAST64 ".", (uint64_t) pPool->pool);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002621 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002622 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 -06002623 "%s", poolStr.c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002624 // Print out set details
2625 char prefix[10];
2626 uint32_t index = 0;
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002627 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 +08002628 "Details for descriptor set %#" PRIxLEAST64 ".", (uint64_t) pSet->set);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002629 LAYOUT_NODE* pLayout = pSet->pLayout;
2630 // Print layout details
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002631 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 -08002632 "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 -06002633 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002634 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002635 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 -06002636 "%s", DSLstr.c_str());
Tobin Ehlis793ad302015-04-03 12:01:11 -06002637 index++;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002638 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
2639 if (pUpdate) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002640 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 +08002641 "Update Chain [UC] for descriptor set %#" PRIxLEAST64 ":", (uint64_t) pSet->set);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002642 sprintf(prefix, " [UC] ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002643 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 -08002644 "%s", dynamic_display(pUpdate, prefix).c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002645 // TODO : If there is a "view" associated with this update, print CI for that view
Tobin Ehlisce132d82015-06-19 15:07:05 -06002646 } else {
Tobin Ehlisbf081f32015-06-15 08:41:17 -06002647 if (0 != pSet->descriptorCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002648 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 +08002649 "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 -06002650 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002651 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 +08002652 "FYI: No descriptors in descriptor set %#" PRIxLEAST64 ".", (uint64_t) pSet->set);
Tobin Ehlisbf081f32015-06-15 08:41:17 -06002653 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002654 }
2655 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002656 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002657}
2658
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002659static void printCB(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002660{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002661 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
David Pinedod8f83d82015-04-27 16:36:17 -06002662 if (pCB && pCB->pCmds.size() > 0) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002663 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 -06002664 "Cmds in CB %p", (void*)cb);
Courtney Goeltzenleuchterba348a92015-04-27 11:16:35 -06002665 vector<CMD_NODE*> pCmds = pCB->pCmds;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002666 for (auto ii=pCmds.begin(); ii!=pCmds.end(); ++ii) {
2667 // TODO : Need to pass cb as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002668 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 -08002669 " CMD#%" PRIu64 ": %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002670 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002671 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002672 // Nothing to print
2673 }
2674}
2675
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002676static VkBool32 synchAndPrintDSConfig(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002677{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002678 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002679 if (!(my_data->report_data->active_flags & VK_DEBUG_REPORT_INFO_BIT_EXT)) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002680 return skipCall;
Mike Stroyanba35e352015-08-12 17:11:28 -06002681 }
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002682 skipCall |= printDSConfig(my_data, cb);
2683 skipCall |= printPipeline(my_data, cb);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002684 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002685}
2686
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002687// Flags validation error if the associated call is made inside a render pass. The apiName
2688// routine should ONLY be called outside a render pass.
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06002689static VkBool32 insideRenderPass(const layer_data* my_data, GLOBAL_CB_NODE *pCB, const char *apiName)
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002690{
2691 VkBool32 inside = VK_FALSE;
2692 if (pCB->activeRenderPass) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002693 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 -07002694 (uint64_t)pCB->commandBuffer, __LINE__, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002695 "%s: It is invalid to issue this call inside an active render pass (%#" PRIxLEAST64 ")",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002696 apiName, (uint64_t) pCB->activeRenderPass);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002697 }
2698 return inside;
2699}
2700
2701// Flags validation error if the associated call is made outside a render pass. The apiName
2702// routine should ONLY be called inside a render pass.
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06002703static VkBool32 outsideRenderPass(const layer_data* my_data, GLOBAL_CB_NODE *pCB, const char *apiName)
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002704{
2705 VkBool32 outside = VK_FALSE;
Mark Lobodzinski74635932015-12-18 15:35:38 -07002706 if (((pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) &&
2707 (!pCB->activeRenderPass)) ||
2708 ((pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) &&
2709 (!pCB->activeRenderPass) &&
2710 !(pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT))) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002711 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 -07002712 (uint64_t)pCB->commandBuffer, __LINE__, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002713 "%s: This call must be issued inside an active render pass.", apiName);
2714 }
2715 return outside;
2716}
2717
Courtney Goeltzenleuchter6d8e8182015-11-25 14:31:49 -07002718static void init_draw_state(layer_data *my_data, const VkAllocationCallbacks *pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002719{
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002720 uint32_t report_flags = 0;
2721 uint32_t debug_action = 0;
2722 FILE *log_output = NULL;
2723 const char *option_str;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002724 VkDebugReportCallbackEXT callback;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002725 // initialize DrawState options
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002726 report_flags = getLayerOptionFlags("DrawStateReportFlags", 0);
2727 getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &debug_action);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002728
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002729 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002730 {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002731 option_str = getLayerOption("DrawStateLogFilename");
Tobin Ehlisb1df55e2015-09-15 09:55:54 -06002732 log_output = getLayerLogOutput(option_str, "DrawState");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002733 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002734 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002735 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002736 dbgInfo.pfnCallback = log_callback;
2737 dbgInfo.pUserData = log_output;
2738 dbgInfo.flags = report_flags;
2739 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002740 my_data->logging_callback.push_back(callback);
2741 }
2742
2743 if (debug_action & VK_DBG_LAYER_ACTION_DEBUG_OUTPUT) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002744 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002745 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002746 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002747 dbgInfo.pfnCallback = win32_debug_output_msg;
2748 dbgInfo.pUserData = log_output;
2749 dbgInfo.flags = report_flags;
2750 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002751 my_data->logging_callback.push_back(callback);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002752 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002753
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002754 if (!globalLockInitialized)
2755 {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002756 loader_platform_thread_create_mutex(&globalLock);
2757 globalLockInitialized = 1;
2758 }
2759}
2760
Chia-I Wu9ab61502015-11-06 06:42:02 +08002761VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance)
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002762{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002763 // TODOSC : Shouldn't need any customization here
Tobin Ehlis0b632332015-10-07 09:38:40 -06002764 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
2765 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002766 VkResult result = pTable->CreateInstance(pCreateInfo, pAllocator, pInstance);
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002767
2768 if (result == VK_SUCCESS) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002769 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
2770 my_data->report_data = debug_report_create_instance(
2771 pTable,
2772 *pInstance,
Jon Ashburnf19916e2016-01-11 13:12:43 -07002773 pCreateInfo->enabledExtensionCount,
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002774 pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchterd02a9642015-06-08 14:58:39 -06002775
Courtney Goeltzenleuchter6d8e8182015-11-25 14:31:49 -07002776 init_draw_state(my_data, pAllocator);
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002777 }
2778 return result;
2779}
2780
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002781/* hook DestroyInstance to remove tableInstanceMap entry */
Chia-I Wu9ab61502015-11-06 06:42:02 +08002782VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator)
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002783{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002784 // TODOSC : Shouldn't need any customization here
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002785 dispatch_key key = get_dispatch_key(instance);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002786 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
2787 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002788 pTable->DestroyInstance(instance, pAllocator);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002789
2790 // Clean up logging callback, if any
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002791 while (my_data->logging_callback.size() > 0) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002792 VkDebugReportCallbackEXT callback = my_data->logging_callback.back();
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002793 layer_destroy_msg_callback(my_data->report_data, callback, pAllocator);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002794 my_data->logging_callback.pop_back();
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002795 }
2796
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06002797 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002798 delete my_data->instance_dispatch_table;
2799 layer_data_map.erase(key);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002800 // TODO : Potential race here with separate threads creating/destroying instance
Tobin Ehlis0b632332015-10-07 09:38:40 -06002801 if (layer_data_map.empty()) {
Mike Stroyanfcb4ba62015-08-18 15:56:18 -06002802 // Release mutex when destroying last instance.
2803 loader_platform_thread_delete_mutex(&globalLock);
2804 globalLockInitialized = 0;
2805 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002806}
2807
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002808static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
2809{
Tony Barbour3b4732f2015-07-13 13:37:24 -06002810 uint32_t i;
Tobin Ehlis0b632332015-10-07 09:38:40 -06002811 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
2812 dev_data->device_extensions.debug_marker_enabled = false;
Michael Lentineabc5e922015-10-12 11:30:14 -05002813 dev_data->device_extensions.wsi_enabled = false;
2814
2815
2816 VkLayerDispatchTable *pDisp = dev_data->device_dispatch_table;
2817 PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr;
2818
Michael Lentineabc5e922015-10-12 11:30:14 -05002819 pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR) gpa(device, "vkCreateSwapchainKHR");
2820 pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR) gpa(device, "vkDestroySwapchainKHR");
2821 pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR) gpa(device, "vkGetSwapchainImagesKHR");
2822 pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR) gpa(device, "vkAcquireNextImageKHR");
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07002823 pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR) gpa(device, "vkQueuePresentKHR");
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002824
Jon Ashburnf19916e2016-01-11 13:12:43 -07002825 for (i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
Ian Elliott05846062015-11-20 14:13:17 -07002826 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) {
Michael Lentineabc5e922015-10-12 11:30:14 -05002827 dev_data->device_extensions.wsi_enabled = true;
2828 }
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002829 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
Jon Ashburneab34492015-06-01 09:37:38 -06002830 /* Found a matching extension name, mark it enabled and init dispatch table*/
Tobin Ehlis0b632332015-10-07 09:38:40 -06002831 dev_data->device_extensions.debug_marker_enabled = true;
Jon Ashburn1d4b1282015-12-10 19:12:21 -07002832 initDebugMarkerTable(device);
2833
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002834 }
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002835 }
2836}
2837
Chia-I Wu9ab61502015-11-06 06:42:02 +08002838VK_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 -06002839{
Tobin Ehlis0b632332015-10-07 09:38:40 -06002840 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08002841 VkResult result = dev_data->device_dispatch_table->CreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002842 // TODOSC : shouldn't need any customization here
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002843 if (result == VK_SUCCESS) {
2844 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002845 dev_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
Jon Ashburn747f2b62015-06-18 15:02:58 -06002846 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002847 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002848 return result;
2849}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002850
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002851// prototype
2852static void deleteRenderPasses(layer_data*);
Chia-I Wu9ab61502015-11-06 06:42:02 +08002853VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002854{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002855 // TODOSC : Shouldn't need any customization here
Jeremy Hayes5d29ce32015-06-19 11:37:38 -06002856 dispatch_key key = get_dispatch_key(device);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002857 layer_data* dev_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002858 // Free all the memory
2859 loader_platform_thread_lock_mutex(&globalLock);
2860 deletePipelines(dev_data);
2861 deleteRenderPasses(dev_data);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002862 deleteCommandBuffers(dev_data);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002863 deletePools(dev_data);
2864 deleteLayouts(dev_data);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002865 dev_data->imageViewMap.clear();
2866 dev_data->imageMap.clear();
2867 dev_data->bufferViewMap.clear();
2868 dev_data->bufferMap.clear();
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002869 loader_platform_thread_unlock_mutex(&globalLock);
2870
Chia-I Wuf7458c52015-10-26 21:10:41 +08002871 dev_data->device_dispatch_table->DestroyDevice(device, pAllocator);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002872 tableDebugMarkerMap.erase(key);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002873 delete dev_data->device_dispatch_table;
2874 layer_data_map.erase(key);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002875}
2876
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07002877static const VkExtensionProperties instance_extensions[] = {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002878 {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002879 VK_EXT_DEBUG_REPORT_EXTENSION_NAME,
2880 VK_EXT_DEBUG_REPORT_REVISION
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002881 }
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06002882};
2883
Chia-I Wu9ab61502015-11-06 06:42:02 +08002884VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002885 const char *pLayerName,
2886 uint32_t *pCount,
2887 VkExtensionProperties* pProperties)
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06002888{
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07002889 return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002890}
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06002891
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07002892static const VkLayerProperties ds_global_layers[] = {
2893 {
Michael Lentine03107b42015-12-11 10:49:51 -08002894 "VK_LAYER_LUNARG_draw_state",
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07002895 VK_API_VERSION,
2896 VK_MAKE_VERSION(0, 1, 0),
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -07002897 "Validation layer: draw_state",
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07002898 }
2899};
2900
Chia-I Wu9ab61502015-11-06 06:42:02 +08002901VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002902 uint32_t *pCount,
2903 VkLayerProperties* pProperties)
2904{
2905 return util_GetLayerProperties(ARRAY_SIZE(ds_global_layers),
2906 ds_global_layers,
2907 pCount, pProperties);
2908}
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06002909
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002910static const VkExtensionProperties ds_device_extensions[] = {
2911 {
2912 DEBUG_MARKER_EXTENSION_NAME,
2913 VK_MAKE_VERSION(0, 1, 0),
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002914 }
2915};
2916
2917static const VkLayerProperties ds_device_layers[] = {
2918 {
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -07002919 "draw_state",
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002920 VK_API_VERSION,
2921 VK_MAKE_VERSION(0, 1, 0),
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -07002922 "Validation layer: draw_state",
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002923 }
2924};
2925
Chia-I Wu9ab61502015-11-06 06:42:02 +08002926VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002927 VkPhysicalDevice physicalDevice,
2928 const char* pLayerName,
2929 uint32_t* pCount,
2930 VkExtensionProperties* pProperties)
2931{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07002932 // DrawState does not have any physical device extensions
Jon Ashburn751c4842015-11-02 17:37:20 -07002933 if (pLayerName == NULL) {
2934 dispatch_key key = get_dispatch_key(physicalDevice);
2935 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07002936 return my_data->instance_dispatch_table->EnumerateDeviceExtensionProperties(
Jon Ashburn751c4842015-11-02 17:37:20 -07002937 physicalDevice,
2938 NULL,
2939 pCount,
2940 pProperties);
2941 } else {
2942 return util_GetExtensionProperties(ARRAY_SIZE(ds_device_extensions),
2943 ds_device_extensions,
2944 pCount, pProperties);
2945 }
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002946}
2947
Chia-I Wu9ab61502015-11-06 06:42:02 +08002948VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002949 VkPhysicalDevice physicalDevice,
2950 uint32_t* pCount,
2951 VkLayerProperties* pProperties)
2952{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07002953 /* DrawState physical device layers are the same as global */
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002954 return util_GetLayerProperties(ARRAY_SIZE(ds_device_layers), ds_device_layers,
2955 pCount, pProperties);
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06002956}
2957
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07002958VkBool32 ValidateCmdBufImageLayouts(VkCommandBuffer cmdBuffer) {
Mark Youngb20a6a82016-01-07 15:41:43 -07002959 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05002960 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
2961 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
2962 for (auto cb_image_data : pCB->imageLayoutMap) {
2963 auto image_data = dev_data->imageLayoutMap.find(cb_image_data.first);
2964 if (image_data == dev_data->imageLayoutMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002965 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 -08002966 "Cannot submit cmd buffer using deleted image %" PRIu64 ".", reinterpret_cast<uint64_t>(cb_image_data.first));
Michael Lentineabc5e922015-10-12 11:30:14 -05002967 } else {
2968 if (dev_data->imageLayoutMap[cb_image_data.first]->layout != cb_image_data.second.initialLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002969 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 -05002970 "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);
2971 }
2972 dev_data->imageLayoutMap[cb_image_data.first]->layout = cb_image_data.second.layout;
2973 }
2974 }
2975 return skip_call;
2976}
2977
Mark Young7a69c302016-01-07 09:48:47 -07002978VkBool32 validateAndIncrementResources(layer_data* my_data, GLOBAL_CB_NODE* pCB) {
Mark Youngb20a6a82016-01-07 15:41:43 -07002979 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07002980 for (auto drawDataElement : pCB->drawData) {
2981 for (auto buffer : drawDataElement.buffers) {
2982 auto buffer_data = my_data->bufferMap.find(buffer);
2983 if (buffer_data == my_data->bufferMap.end()) {
2984 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",
2985 "Cannot submit cmd buffer using deleted buffer %" PRIu64 ".", reinterpret_cast<uint64_t>(buffer));
2986 } else {
2987 buffer_data->second.in_use.fetch_add(1);
2988 }
2989 }
2990 }
Michael Lentine2e068b22015-12-29 16:05:27 -06002991 return skip_call;
Michael Lentine700b0aa2015-10-30 17:57:32 -07002992}
2993
2994void decrementResources(layer_data* my_data, VkCommandBuffer cmdBuffer) {
2995 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cmdBuffer);
2996 for (auto drawDataElement : pCB->drawData) {
2997 for (auto buffer : drawDataElement.buffers) {
2998 auto buffer_data = my_data->bufferMap.find(buffer);
2999 if (buffer_data != my_data->bufferMap.end()) {
3000 buffer_data->second.in_use.fetch_sub(1);
3001 }
3002 }
3003 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003004 for (auto queryStatePair : pCB->queryToStateMap) {
3005 my_data->queryToStateMap[queryStatePair.first] = queryStatePair.second;
3006 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003007}
3008
3009void decrementResources(layer_data* my_data, uint32_t fenceCount, const VkFence* pFences) {
3010 for (uint32_t i = 0; i < fenceCount; ++i) {
3011 auto fence_data = my_data->fenceMap.find(pFences[i]);
3012 if (fence_data == my_data->fenceMap.end() || !fence_data->second.needsSignaled) return;
3013 fence_data->second.needsSignaled = false;
3014 if (fence_data->second.priorFence != VK_NULL_HANDLE) {
3015 decrementResources(my_data, 1, &fence_data->second.priorFence);
3016 }
3017 for (auto cmdBuffer : fence_data->second.cmdBuffers) {
3018 decrementResources(my_data, cmdBuffer);
3019 }
3020 }
3021}
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07003022
Michael Lentine700b0aa2015-10-30 17:57:32 -07003023void decrementResources(layer_data* my_data, VkQueue queue) {
3024 auto queue_data = my_data->queueMap.find(queue);
3025 if (queue_data != my_data->queueMap.end()) {
3026 for (auto cmdBuffer : queue_data->second.untrackedCmdBuffers) {
3027 decrementResources(my_data, cmdBuffer);
3028 }
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07003029 queue_data->second.untrackedCmdBuffers.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07003030 decrementResources(my_data, 1, &queue_data->second.priorFence);
3031 }
3032}
3033
3034void trackCommandBuffers(layer_data* my_data, VkQueue queue, uint32_t cmdBufferCount, const VkCommandBuffer* pCmdBuffers, VkFence fence) {
3035 auto queue_data = my_data->queueMap.find(queue);
3036 if (fence != VK_NULL_HANDLE) {
3037 VkFence priorFence = VK_NULL_HANDLE;
3038 if (queue_data != my_data->queueMap.end()) {
3039 priorFence = queue_data->second.priorFence;
3040 queue_data->second.priorFence = fence;
3041 for (auto cmdBuffer : queue_data->second.untrackedCmdBuffers) {
3042 my_data->fenceMap[fence].cmdBuffers.push_back(cmdBuffer);
3043 }
3044 queue_data->second.untrackedCmdBuffers.clear();
3045 }
3046 my_data->fenceMap[fence].cmdBuffers.clear();
3047 my_data->fenceMap[fence].priorFence = priorFence;
3048 my_data->fenceMap[fence].needsSignaled = true;
3049 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
3050 my_data->fenceMap[fence].cmdBuffers.push_back(pCmdBuffers[i]);
3051 }
3052 } else {
3053 if (queue_data != my_data->queueMap.end()) {
3054 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
3055 queue_data->second.untrackedCmdBuffers.push_back(pCmdBuffers[i]);
3056 }
3057 }
3058 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003059 if (queue_data != my_data->queueMap.end()) {
3060 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
3061 my_data->inFlightCmdBuffers.insert(pCmdBuffers[i]);
3062 }
3063 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003064}
3065
Chia-I Wu9ab61502015-11-06 06:42:02 +08003066VK_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 -06003067{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003068 VkBool32 skipCall = VK_FALSE;
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06003069 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlis0b632332015-10-07 09:38:40 -06003070 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Tobin Ehlis651d9b02015-12-16 05:01:22 -07003071 // TODO : Any pCommandBuffers must have USAGE_SIMULTANEOUS_USE_BIT set or cannot already be executing on device
3072 // Same goes for any secondary CBs under the primary CB
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003073 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08003074 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Michael Lentine15a47882016-01-06 10:05:48 -06003075 for (uint32_t i=0; i < submit->waitSemaphoreCount; ++i) {
3076 if (dev_data->semaphoreSignaledMap[submit->pWaitSemaphores[i]]) {
3077 dev_data->semaphoreSignaledMap[submit->pWaitSemaphores[i]] = 0;
3078 } else {
3079 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",
3080 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
3081 reinterpret_cast<uint64_t>(queue), reinterpret_cast<uint64_t>(submit->pWaitSemaphores[i]));
3082 }
3083 }
3084 for (uint32_t i=0; i < submit->signalSemaphoreCount; ++i) {
3085 dev_data->semaphoreSignaledMap[submit->pSignalSemaphores[i]] = 1;
3086 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08003087 for (uint32_t i=0; i < submit->commandBufferCount; i++) {
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07003088
3089#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
3090 skipCall |= ValidateCmdBufImageLayouts(submit->pCommandBuffers[i]);
3091#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
3092
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003093 // Validate that cmd buffers have been updated
3094 pCB = getCBNode(dev_data, submit->pCommandBuffers[i]);
3095 loader_platform_thread_lock_mutex(&globalLock);
3096 pCB->submitCount++; // increment submit count
Michael Lentine700b0aa2015-10-30 17:57:32 -07003097 skipCall |= validateAndIncrementResources(dev_data, pCB);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003098 if ((pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT) && (pCB->submitCount > 1)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003099 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 -05003100 "CB %#" PRIxLEAST64 " was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted %#" PRIxLEAST64 " times.",
3101 reinterpret_cast<uint64_t>(pCB->commandBuffer), pCB->submitCount);
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003102 }
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003103 if (CB_RECORDED != pCB->state) {
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003104 // Flag error for using CB w/o vkEndCommandBuffer() called
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003105 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 +08003106 "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 -06003107 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003108 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003109 }
Tobin Ehlisc4bdde12015-05-27 14:30:06 -06003110 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06003111 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003112 trackCommandBuffers(dev_data, queue, submit->commandBufferCount, submit->pCommandBuffers, fence);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003113 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003114 if (VK_FALSE == skipCall)
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08003115 return dev_data->device_dispatch_table->QueueSubmit(queue, submitCount, pSubmits, fence);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003116 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003117}
3118
Mark Youngb20a6a82016-01-07 15:41:43 -07003119VkBool32 cleanInFlightCmdBuffer(layer_data* my_data, VkCommandBuffer cmdBuffer) {
3120 VkBool32 skip_call = VK_FALSE;
Michael Lentineb887b0a2015-12-29 14:12:11 -06003121 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cmdBuffer);
3122 for (auto queryEventsPair : pCB->waitedEventsBeforeQueryReset) {
3123 for (auto event : queryEventsPair.second) {
3124 if (my_data->eventMap[event].needsSignaled) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003125 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",
3126 "Cannot get query results on queryPool %" PRIu64 " with index %d which was guarded by unsignaled event %" PRIu64 ".",
Michael Lentineb887b0a2015-12-29 14:12:11 -06003127 reinterpret_cast<uint64_t>(queryEventsPair.first.pool), queryEventsPair.first.index, reinterpret_cast<uint64_t>(event));
3128 }
3129 }
3130 }
3131 return skip_call;
3132}
3133
Michael Lentine700b0aa2015-10-30 17:57:32 -07003134VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence* pFences, VkBool32 waitAll, uint64_t timeout)
3135{
3136 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3137 VkResult result = dev_data->device_dispatch_table->WaitForFences(device, fenceCount, pFences, waitAll, timeout);
Mark Youngb20a6a82016-01-07 15:41:43 -07003138 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003139 if ((waitAll || fenceCount == 1) && result == VK_SUCCESS) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06003140 for (uint32_t i = 0; i < fenceCount; ++i) {
3141 for (auto cmdBuffer : dev_data->fenceMap[pFences[i]].cmdBuffers) {
3142 dev_data->inFlightCmdBuffers.erase(cmdBuffer);
3143 skip_call |= cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3144 }
3145 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003146 decrementResources(dev_data, fenceCount, pFences);
3147 }
Mark Youngb20a6a82016-01-07 15:41:43 -07003148 if (VK_FALSE != skip_call)
Mark Lobodzinskice738852016-01-07 10:04:02 -07003149 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003150 return result;
3151}
3152
3153
3154VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetFenceStatus(VkDevice device, VkFence fence)
3155{
3156 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3157 VkResult result = dev_data->device_dispatch_table->GetFenceStatus(device, fence);
3158 if (result == VK_SUCCESS) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06003159 for (auto cmdBuffer : dev_data->fenceMap[fence].cmdBuffers) {
3160 dev_data->inFlightCmdBuffers.erase(cmdBuffer);
3161 cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3162 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003163 decrementResources(dev_data, 1, &fence);
3164 }
3165 return result;
3166}
3167
3168VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue* pQueue)
3169{
3170 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3171 dev_data->device_dispatch_table->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue);
3172 dev_data->deviceMap[device].queues.push_back(*pQueue);
3173 dev_data->queueMap[*pQueue].device = device;
3174}
3175
3176VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueueWaitIdle(VkQueue queue)
3177{
3178 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
3179 decrementResources(dev_data, queue);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003180 for (auto cmdBuffer : dev_data->inFlightCmdBuffers) {
3181 cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3182 }
3183 dev_data->inFlightCmdBuffers.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07003184 return dev_data->device_dispatch_table->QueueWaitIdle(queue);
3185}
3186
3187VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkDeviceWaitIdle(VkDevice device)
3188{
3189 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3190 auto device_data = dev_data->deviceMap.find(device);
3191 if (device_data != dev_data->deviceMap.end()) {
3192 for (auto queue : device_data->second.queues) {
3193 decrementResources(dev_data, queue);
3194 }
3195 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003196 for (auto cmdBuffer : dev_data->inFlightCmdBuffers) {
3197 cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3198 }
3199 dev_data->inFlightCmdBuffers.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07003200 return dev_data->device_dispatch_table->DeviceWaitIdle(device);
3201}
3202
Chia-I Wu9ab61502015-11-06 06:42:02 +08003203VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003204{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003205 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 -06003206 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003207}
3208
Chia-I Wu9ab61502015-11-06 06:42:02 +08003209VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySemaphore(VkDevice device, VkSemaphore semaphore, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003210{
Michael Lentine15a47882016-01-06 10:05:48 -06003211 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3212 dev_data->device_dispatch_table->DestroySemaphore(device, semaphore, pAllocator);
3213 dev_data->semaphoreSignaledMap.erase(semaphore);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003214 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003215}
3216
Chia-I Wu9ab61502015-11-06 06:42:02 +08003217VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003218{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003219 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 -06003220 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003221}
3222
Chia-I Wu9ab61502015-11-06 06:42:02 +08003223VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003224{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003225 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 -06003226 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003227}
3228
Mark Lobodzinskice738852016-01-07 10:04:02 -07003229VKAPI_ATTR VkResult VKAPI_CALL vkGetQueryPoolResults(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount,
Michael Lentineb887b0a2015-12-29 14:12:11 -06003230 size_t dataSize, void* pData, VkDeviceSize stride, VkQueryResultFlags flags) {
3231 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3232 unordered_map<QueryObject, vector<VkCommandBuffer>> queriesInFlight;
3233 GLOBAL_CB_NODE* pCB = nullptr;
3234 for (auto cmdBuffer : dev_data->inFlightCmdBuffers) {
3235 pCB = getCBNode(dev_data, cmdBuffer);
3236 for (auto queryStatePair : pCB->queryToStateMap) {
3237 queriesInFlight[queryStatePair.first].push_back(cmdBuffer);
3238 }
3239 }
Mark Youngb20a6a82016-01-07 15:41:43 -07003240 VkBool32 skip_call = VK_FALSE;
Michael Lentineb887b0a2015-12-29 14:12:11 -06003241 for (uint32_t i = 0; i < queryCount; ++i) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003242 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06003243 auto queryElement = queriesInFlight.find(query);
3244 auto queryToStateElement = dev_data->queryToStateMap.find(query);
3245 if (queryToStateElement != dev_data->queryToStateMap.end()) {
3246 }
3247 // Available and in flight
3248 if(queryElement != queriesInFlight.end() && queryToStateElement != dev_data->queryToStateMap.end() && queryToStateElement->second) {
3249 for (auto cmdBuffer : queryElement->second) {
3250 pCB = getCBNode(dev_data, cmdBuffer);
3251 auto queryEventElement = pCB->waitedEventsBeforeQueryReset.find(query);
3252 if (queryEventElement == pCB->waitedEventsBeforeQueryReset.end()) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003253 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT, 0, __LINE__,
3254 DRAWSTATE_INVALID_QUERY, "DS", "Cannot get query results on queryPool %" PRIu64 " with index %d which is in flight.",
3255 reinterpret_cast<uint64_t>(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003256 } else {
3257 for (auto event : queryEventElement->second) {
3258 dev_data->eventMap[event].needsSignaled = true;
3259 }
3260 }
3261 }
3262 // Unavailable and in flight
3263 } else if (queryElement != queriesInFlight.end() && queryToStateElement != dev_data->queryToStateMap.end() && !queryToStateElement->second) {
3264 // TODO : Can there be the same query in use by multiple command buffers in flight?
3265 bool make_available = false;
3266 for (auto cmdBuffer : queryElement->second) {
3267 pCB = getCBNode(dev_data, cmdBuffer);
3268 make_available |= pCB->queryToStateMap[query];
3269 }
3270 if (!(((flags & VK_QUERY_RESULT_PARTIAL_BIT) || (flags & VK_QUERY_RESULT_WAIT_BIT)) && make_available)) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003271 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 -06003272 "Cannot get query results on queryPool %" PRIu64 " with index %d which is unavailable.",
Mark Lobodzinskice738852016-01-07 10:04:02 -07003273 reinterpret_cast<uint64_t>(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003274 }
3275 // Unavailable
3276 } else if (queryToStateElement != dev_data->queryToStateMap.end() && !queryToStateElement->second) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003277 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 -06003278 "Cannot get query results on queryPool %" PRIu64 " with index %d which is unavailable.",
Mark Lobodzinskice738852016-01-07 10:04:02 -07003279 reinterpret_cast<uint64_t>(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003280 // Unitialized
3281 } else if (queryToStateElement == dev_data->queryToStateMap.end()) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003282 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 -06003283 "Cannot get query results on queryPool %" PRIu64 " with index %d which is uninitialized.",
Mark Lobodzinskice738852016-01-07 10:04:02 -07003284 reinterpret_cast<uint64_t>(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003285 }
3286 }
3287 if (skip_call)
Mark Lobodzinskice738852016-01-07 10:04:02 -07003288 return VK_ERROR_VALIDATION_FAILED_EXT;
3289 return dev_data->device_dispatch_table->GetQueryPoolResults(device, queryPool, firstQuery, queryCount, dataSize, pData, stride, flags);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003290}
3291
Mark Young7a69c302016-01-07 09:48:47 -07003292VkBool32 validateIdleBuffer(const layer_data* my_data, VkBuffer buffer) {
Mark Youngb20a6a82016-01-07 15:41:43 -07003293 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003294 auto buffer_data = my_data->bufferMap.find(buffer);
3295 if (buffer_data == my_data->bufferMap.end()) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06003296 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 -07003297 "Cannot free buffer %" PRIxLEAST64 " that has not been allocated.", reinterpret_cast<uint64_t>(buffer));
3298 } else {
3299 if (buffer_data->second.in_use.load()) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06003300 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 -07003301 "Cannot free buffer %" PRIxLEAST64 " that is in use by a command buffer.", reinterpret_cast<uint64_t>(buffer));
3302
3303 }
3304 }
3305 return skip_call;
3306}
3307
Chia-I Wu9ab61502015-11-06 06:42:02 +08003308VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003309{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003310 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07003311 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003312 if (!validateIdleBuffer(dev_data, buffer)) {
3313 dev_data->device_dispatch_table->DestroyBuffer(device, buffer, pAllocator);
3314 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08003315 dev_data->bufferMap.erase(buffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003316}
3317
Chia-I Wu9ab61502015-11-06 06:42:02 +08003318VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBufferView(VkDevice device, VkBufferView bufferView, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003319{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003320 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003321 dev_data->device_dispatch_table->DestroyBufferView(device, bufferView, pAllocator);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003322 dev_data->bufferViewMap.erase(bufferView);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003323}
3324
Chia-I Wu9ab61502015-11-06 06:42:02 +08003325VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003326{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003327 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003328 dev_data->device_dispatch_table->DestroyImage(device, image, pAllocator);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003329 dev_data->imageMap.erase(image);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003330}
3331
Chia-I Wu9ab61502015-11-06 06:42:02 +08003332VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyImageView(VkDevice device, VkImageView imageView, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003333{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003334 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 -06003335 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003336}
3337
Chia-I Wu9ab61502015-11-06 06:42:02 +08003338VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003339{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003340 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 -06003341 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003342}
3343
Chia-I Wu9ab61502015-11-06 06:42:02 +08003344VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyPipeline(VkDevice device, VkPipeline pipeline, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003345{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003346 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 -06003347 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003348}
3349
Chia-I Wu9ab61502015-11-06 06:42:02 +08003350VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003351{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003352 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 -06003353 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003354}
3355
Chia-I Wu9ab61502015-11-06 06:42:02 +08003356VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySampler(VkDevice device, VkSampler sampler, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003357{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003358 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 -06003359 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003360}
3361
Chia-I Wu9ab61502015-11-06 06:42:02 +08003362VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003363{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003364 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 -06003365 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003366}
3367
Chia-I Wu9ab61502015-11-06 06:42:02 +08003368VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003369{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003370 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 -06003371 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003372}
3373
Chia-I Wu9ab61502015-11-06 06:42:02 +08003374VK_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 -06003375{
Mark Lobodzinski39298632015-11-18 08:38:27 -07003376 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3377
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07003378 for (uint32_t i = 0; i < count; i++) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003379 // Delete CB information structure, and remove from commandBufferMap
3380 auto cb = dev_data->commandBufferMap.find(pCommandBuffers[i]);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003381 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003382 if (cb != dev_data->commandBufferMap.end()) {
3383 delete (*cb).second;
3384 dev_data->commandBufferMap.erase(cb);
3385 }
3386
3387 // Remove commandBuffer reference from commandPoolMap
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003388 dev_data->commandPoolMap[commandPool].commandBuffers.remove(pCommandBuffers[i]);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003389 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003390 }
3391
3392 dev_data->device_dispatch_table->FreeCommandBuffers(device, commandPool, count, pCommandBuffers);
3393}
3394
3395VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkCommandPool* pCommandPool)
3396{
3397 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3398
3399 VkResult result = dev_data->device_dispatch_table->CreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
3400
3401 if (VK_SUCCESS == result) {
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003402 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003403 dev_data->commandPoolMap[*pCommandPool].createFlags = pCreateInfo->flags;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003404 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003405 }
3406 return result;
3407}
3408
3409VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks* pAllocator)
3410{
3411 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003412 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003413
3414 // Must remove cmdpool from cmdpoolmap, after removing all cmdbuffers in its list from the commandPoolMap
3415 if (dev_data->commandPoolMap.find(commandPool) != dev_data->commandPoolMap.end()) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003416 for (auto poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.begin(); poolCb != dev_data->commandPoolMap[commandPool].commandBuffers.end();) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003417 auto del_cb = dev_data->commandBufferMap.find(*poolCb);
3418 delete (*del_cb).second; // delete CB info structure
3419 dev_data->commandBufferMap.erase(del_cb); // Remove this command buffer from cbMap
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003420 poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.erase(poolCb); // Remove CB reference from commandPoolMap's list
Mark Lobodzinski39298632015-11-18 08:38:27 -07003421 }
3422 }
3423 dev_data->commandPoolMap.erase(commandPool);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003424
3425 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003426 dev_data->device_dispatch_table->DestroyCommandPool(device, commandPool, pAllocator);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003427}
3428
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003429VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandPool(
3430 VkDevice device,
3431 VkCommandPool commandPool,
3432 VkCommandPoolResetFlags flags)
3433{
3434 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003435 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003436
3437 result = dev_data->device_dispatch_table->ResetCommandPool(device, commandPool, flags);
3438 // Reset all of the CBs allocated from this pool
3439 if (VK_SUCCESS == result) {
3440 auto it = dev_data->commandPoolMap[commandPool].commandBuffers.begin();
3441 while (it != dev_data->commandPoolMap[commandPool].commandBuffers.end()) {
3442 resetCB(dev_data, (*it));
3443 ++it;
3444 }
3445 }
3446 return result;
3447}
3448
Chia-I Wu9ab61502015-11-06 06:42:02 +08003449VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003450{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003451 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 -06003452 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003453}
3454
Chia-I Wu9ab61502015-11-06 06:42:02 +08003455VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003456{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003457 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 -06003458 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003459}
3460
Chia-I Wu9ab61502015-11-06 06:42:02 +08003461VK_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 -06003462{
3463 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003464 VkResult result = dev_data->device_dispatch_table->CreateBuffer(device, pCreateInfo, pAllocator, pBuffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003465 if (VK_SUCCESS == result) {
3466 loader_platform_thread_lock_mutex(&globalLock);
3467 // 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 -07003468 dev_data->bufferMap[*pBuffer].create_info = unique_ptr<VkBufferCreateInfo>(new VkBufferCreateInfo(*pCreateInfo));
3469 dev_data->bufferMap[*pBuffer].in_use.store(0);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003470 loader_platform_thread_unlock_mutex(&globalLock);
3471 }
3472 return result;
3473}
3474
Chia-I Wu9ab61502015-11-06 06:42:02 +08003475VK_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 -06003476{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003477 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003478 VkResult result = dev_data->device_dispatch_table->CreateBufferView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003479 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003480 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003481 dev_data->bufferViewMap[*pView] = unique_ptr<VkBufferViewCreateInfo>(new VkBufferViewCreateInfo(*pCreateInfo));
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003482 loader_platform_thread_unlock_mutex(&globalLock);
3483 }
3484 return result;
3485}
3486
Chia-I Wu9ab61502015-11-06 06:42:02 +08003487VK_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 -06003488{
3489 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003490 VkResult result = dev_data->device_dispatch_table->CreateImage(device, pCreateInfo, pAllocator, pImage);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003491 if (VK_SUCCESS == result) {
Michael Lentineabc5e922015-10-12 11:30:14 -05003492 IMAGE_NODE* image_node = new IMAGE_NODE;
3493 image_node->layout = pCreateInfo->initialLayout;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003494 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003495 dev_data->imageMap[*pImage] = unique_ptr<VkImageCreateInfo>(new VkImageCreateInfo(*pCreateInfo));
Michael Lentineabc5e922015-10-12 11:30:14 -05003496 dev_data->imageLayoutMap[*pImage] = image_node;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003497 loader_platform_thread_unlock_mutex(&globalLock);
3498 }
3499 return result;
3500}
3501
Chia-I Wu9ab61502015-11-06 06:42:02 +08003502VK_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 -06003503{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003504 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003505 VkResult result = dev_data->device_dispatch_table->CreateImageView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003506 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003507 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003508 dev_data->imageViewMap[*pView] = unique_ptr<VkImageViewCreateInfo>(new VkImageViewCreateInfo(*pCreateInfo));
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003509 loader_platform_thread_unlock_mutex(&globalLock);
3510 }
3511 return result;
3512}
3513
Jon Ashburnc669cc62015-07-09 15:02:25 -06003514//TODO handle pipeline caches
Chia-I Wu9ab61502015-11-06 06:42:02 +08003515VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineCache(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003516 VkDevice device,
3517 const VkPipelineCacheCreateInfo* pCreateInfo,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003518 const VkAllocationCallbacks* pAllocator,
Jon Ashburnc669cc62015-07-09 15:02:25 -06003519 VkPipelineCache* pPipelineCache)
3520{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003521 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003522 VkResult result = dev_data->device_dispatch_table->CreatePipelineCache(device, pCreateInfo, pAllocator, pPipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003523 return result;
3524}
3525
Chia-I Wu9ab61502015-11-06 06:42:02 +08003526VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineCache(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003527 VkDevice device,
Chia-I Wuf7458c52015-10-26 21:10:41 +08003528 VkPipelineCache pipelineCache,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003529 const VkAllocationCallbacks* pAllocator)
Jon Ashburnc669cc62015-07-09 15:02:25 -06003530{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003531 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003532 dev_data->device_dispatch_table->DestroyPipelineCache(device, pipelineCache, pAllocator);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003533}
3534
Chia-I Wu9ab61502015-11-06 06:42:02 +08003535VKAPI_ATTR VkResult VKAPI_CALL vkGetPipelineCacheData(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003536 VkDevice device,
3537 VkPipelineCache pipelineCache,
Chia-I Wub16facd2015-10-26 19:17:06 +08003538 size_t* pDataSize,
Jon Ashburnc669cc62015-07-09 15:02:25 -06003539 void* pData)
3540{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003541 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wub16facd2015-10-26 19:17:06 +08003542 VkResult result = dev_data->device_dispatch_table->GetPipelineCacheData(device, pipelineCache, pDataSize, pData);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003543 return result;
3544}
3545
Chia-I Wu9ab61502015-11-06 06:42:02 +08003546VKAPI_ATTR VkResult VKAPI_CALL vkMergePipelineCaches(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003547 VkDevice device,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003548 VkPipelineCache dstCache,
Jon Ashburnc669cc62015-07-09 15:02:25 -06003549 uint32_t srcCacheCount,
3550 const VkPipelineCache* pSrcCaches)
3551{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003552 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003553 VkResult result = dev_data->device_dispatch_table->MergePipelineCaches(device, dstCache, srcCacheCount, pSrcCaches);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003554 return result;
3555}
3556
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003557VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateGraphicsPipelines(
3558 VkDevice device,
3559 VkPipelineCache pipelineCache,
3560 uint32_t count,
3561 const VkGraphicsPipelineCreateInfo *pCreateInfos,
3562 const VkAllocationCallbacks *pAllocator,
3563 VkPipeline *pPipelines)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003564{
Courtney Goeltzenleuchtered894072015-09-04 13:39:59 -06003565 VkResult result = VK_SUCCESS;
Tobin Ehlis11efc302015-09-16 10:33:53 -06003566 //TODO What to do with pipelineCache?
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003567 // The order of operations here is a little convoluted but gets the job done
3568 // 1. Pipeline create state is first shadowed into PIPELINE_NODE struct
3569 // 2. Create state is then validated (which uses flags setup during shadowing)
3570 // 3. If everything looks good, we'll then create the pipeline and add NODE to pipelineMap
Tobin Ehlis11efc302015-09-16 10:33:53 -06003571 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis65399772015-09-17 16:33:58 -06003572 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
3573 vector<PIPELINE_NODE*> pPipeNode(count);
Tobin Ehlis0b632332015-10-07 09:38:40 -06003574 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003575
Tobin Ehlis11efc302015-09-16 10:33:53 -06003576 uint32_t i=0;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003577 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003578
Tobin Ehlis11efc302015-09-16 10:33:53 -06003579 for (i=0; i<count; i++) {
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003580 pPipeNode[i] = initGraphicsPipeline(dev_data, &pCreateInfos[i], NULL);
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06003581 skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
Tobin Ehlis11efc302015-09-16 10:33:53 -06003582 }
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003583
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003584 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003585
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07003586 if (VK_FALSE == skipCall) {
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003587 result = dev_data->device_dispatch_table->CreateGraphicsPipelines(device,
3588 pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003589 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis11efc302015-09-16 10:33:53 -06003590 for (i=0; i<count; i++) {
3591 pPipeNode[i]->pipeline = pPipelines[i];
Chia-I Wue2fc5522015-10-26 20:04:44 +08003592 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
Tobin Ehlis11efc302015-09-16 10:33:53 -06003593 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003594 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisce132d82015-06-19 15:07:05 -06003595 } else {
Tobin Ehlis11efc302015-09-16 10:33:53 -06003596 for (i=0; i<count; i++) {
3597 if (pPipeNode[i]) {
3598 // If we allocated a pipeNode, need to clean it up here
3599 delete[] pPipeNode[i]->pVertexBindingDescriptions;
3600 delete[] pPipeNode[i]->pVertexAttributeDescriptions;
3601 delete[] pPipeNode[i]->pAttachments;
3602 delete pPipeNode[i];
3603 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003604 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003605 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003606 }
Courtney Goeltzenleuchtere2aaad02015-04-13 16:16:04 -06003607 return result;
3608}
3609
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003610VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateComputePipelines(
3611 VkDevice device,
3612 VkPipelineCache pipelineCache,
3613 uint32_t count,
3614 const VkComputePipelineCreateInfo *pCreateInfos,
3615 const VkAllocationCallbacks *pAllocator,
3616 VkPipeline *pPipelines)
3617{
3618 VkResult result = VK_SUCCESS;
3619 VkBool32 skipCall = VK_FALSE;
3620
3621 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
3622 vector<PIPELINE_NODE*> pPipeNode(count);
3623 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3624
3625 uint32_t i=0;
3626 loader_platform_thread_lock_mutex(&globalLock);
3627 for (i=0; i<count; i++) {
3628 // TODO: Verify compute stage bits
3629
3630 // Create and initialize internal tracking data structure
3631 pPipeNode[i] = new PIPELINE_NODE;
3632 memset((void*)pPipeNode[i], 0, sizeof(PIPELINE_NODE));
3633 memcpy(&pPipeNode[i]->computePipelineCI, (const void*)&pCreateInfos[i], sizeof(VkComputePipelineCreateInfo));
3634
3635 // TODO: Add Compute Pipeline Verification
3636 // skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
3637 }
3638 loader_platform_thread_unlock_mutex(&globalLock);
3639
3640 if (VK_FALSE == skipCall) {
3641 result = dev_data->device_dispatch_table->CreateComputePipelines(device, pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
3642 loader_platform_thread_lock_mutex(&globalLock);
3643 for (i=0; i<count; i++) {
3644 pPipeNode[i]->pipeline = pPipelines[i];
3645 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
3646 }
3647 loader_platform_thread_unlock_mutex(&globalLock);
3648 } else {
3649 for (i=0; i<count; i++) {
3650 if (pPipeNode[i]) {
3651 // Clean up any locally allocated data structures
3652 delete pPipeNode[i];
3653 }
3654 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003655 return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003656 }
3657 return result;
3658}
3659
Chia-I Wu9ab61502015-11-06 06:42:02 +08003660VK_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 -06003661{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003662 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003663 VkResult result = dev_data->device_dispatch_table->CreateSampler(device, pCreateInfo, pAllocator, pSampler);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003664 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003665 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003666 dev_data->sampleMap[*pSampler] = unique_ptr<SAMPLER_NODE>(new SAMPLER_NODE(pSampler, pCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003667 loader_platform_thread_unlock_mutex(&globalLock);
3668 }
3669 return result;
3670}
3671
Chia-I Wu9ab61502015-11-06 06:42:02 +08003672VK_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 -06003673{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003674 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003675 VkResult result = dev_data->device_dispatch_table->CreateDescriptorSetLayout(device, pCreateInfo, pAllocator, pSetLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003676 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003677 // TODOSC : Capture layout bindings set
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003678 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
3679 if (NULL == pNewNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003680 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 -06003681 "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003682 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003683 }
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06003684 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003685 pNewNode->createInfo.pBindings = new VkDescriptorSetLayoutBinding[pCreateInfo->bindingCount];
3686 memcpy((void*)pNewNode->createInfo.pBindings, pCreateInfo->pBindings, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->bindingCount);
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003687 // g++ does not like reserve with size 0
3688 if (pCreateInfo->bindingCount)
3689 pNewNode->bindings.reserve(pCreateInfo->bindingCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003690 uint32_t totalCount = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003691 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003692 if (!pNewNode->bindings.insert(pCreateInfo->pBindings[i].binding).second) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003693 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 +08003694 "duplicated binding number in VkDescriptorSetLayoutBinding"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003695 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003696 }
3697
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003698 totalCount += pCreateInfo->pBindings[i].descriptorCount;
3699 if (pCreateInfo->pBindings[i].pImmutableSamplers) {
3700 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBindings[i].pImmutableSamplers;
3701 *ppIS = new VkSampler[pCreateInfo->pBindings[i].descriptorCount];
3702 memcpy(*ppIS, pCreateInfo->pBindings[i].pImmutableSamplers, pCreateInfo->pBindings[i].descriptorCount*sizeof(VkSampler));
Tobin Ehlis793ad302015-04-03 12:01:11 -06003703 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003704 }
Tobin Ehlis43c39c02016-01-11 13:18:40 -07003705 pNewNode->layout = *pSetLayout;
3706 pNewNode->startIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003707 if (totalCount > 0) {
Cody Northrop43751cc2015-10-26 14:07:35 -06003708 pNewNode->descriptorTypes.resize(totalCount);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06003709 pNewNode->stageFlags.resize(totalCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003710 uint32_t offset = 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06003711 uint32_t j = 0;
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07003712 VkDescriptorType dType;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003713 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003714 dType = pCreateInfo->pBindings[i].descriptorType;
3715 for (j = 0; j < pCreateInfo->pBindings[i].descriptorCount; j++) {
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07003716 pNewNode->descriptorTypes[offset + j] = dType;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003717 pNewNode->stageFlags[offset + j] = pCreateInfo->pBindings[i].stageFlags;
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07003718 if ((dType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
3719 (dType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
3720 pNewNode->dynamicDescriptorCount++;
3721 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003722 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06003723 offset += j;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003724 }
Tobin Ehlis43c39c02016-01-11 13:18:40 -07003725 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
3726 } else { // no descriptors
3727 pNewNode->endIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003728 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003729 // Put new node at Head of global Layer list
3730 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07003731 dev_data->descriptorSetLayoutMap[*pSetLayout] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003732 loader_platform_thread_unlock_mutex(&globalLock);
3733 }
3734 return result;
3735}
3736
Chia-I Wu9ab61502015-11-06 06:42:02 +08003737VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003738{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003739 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003740 VkResult result = dev_data->device_dispatch_table->CreatePipelineLayout(device, pCreateInfo, pAllocator, pPipelineLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003741 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003742 // TODOSC : Merge capture of the setLayouts per pipeline
Tobin Ehlis559c6382015-11-05 09:52:49 -07003743 PIPELINE_LAYOUT_NODE& plNode = dev_data->pipelineLayoutMap[*pPipelineLayout];
Chia-I Wud50a7d72015-10-26 20:48:51 +08003744 plNode.descriptorSetLayouts.resize(pCreateInfo->setLayoutCount);
Tobin Ehlis644ff042015-10-20 10:11:55 -06003745 uint32_t i = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003746 for (i=0; i<pCreateInfo->setLayoutCount; ++i) {
Tobin Ehlis644ff042015-10-20 10:11:55 -06003747 plNode.descriptorSetLayouts[i] = pCreateInfo->pSetLayouts[i];
3748 }
Cody Northrop43751cc2015-10-26 14:07:35 -06003749 plNode.pushConstantRanges.resize(pCreateInfo->pushConstantRangeCount);
Tobin Ehlis644ff042015-10-20 10:11:55 -06003750 for (i=0; i<pCreateInfo->pushConstantRangeCount; ++i) {
3751 plNode.pushConstantRanges[i] = pCreateInfo->pPushConstantRanges[i];
3752 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06003753 }
3754 return result;
3755}
3756
Chia-I Wu9ab61502015-11-06 06:42:02 +08003757VK_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 -06003758{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003759 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003760 VkResult result = dev_data->device_dispatch_table->CreateDescriptorPool(device, pCreateInfo, pAllocator, pDescriptorPool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003761 if (VK_SUCCESS == result) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06003762 // Insert this pool into Global Pool LL at head
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003763 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 +08003764 "Created Descriptor Pool %#" PRIxLEAST64, (uint64_t) *pDescriptorPool))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003765 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003766 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003767 DESCRIPTOR_POOL_NODE* pNewNode = new DESCRIPTOR_POOL_NODE(*pDescriptorPool, pCreateInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003768 if (NULL == pNewNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003769 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 -07003770 "Out of memory while attempting to allocate DESCRIPTOR_POOL_NODE in vkCreateDescriptorPool()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003771 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisce132d82015-06-19 15:07:05 -06003772 } else {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003773 dev_data->descriptorPoolMap[*pDescriptorPool] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003774 }
3775 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisce132d82015-06-19 15:07:05 -06003776 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06003777 // Need to do anything if pool create fails?
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003778 }
3779 return result;
3780}
3781
Chia-I Wu9ab61502015-11-06 06:42:02 +08003782VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorPoolResetFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003783{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003784 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003785 VkResult result = dev_data->device_dispatch_table->ResetDescriptorPool(device, descriptorPool, flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003786 if (VK_SUCCESS == result) {
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003787 clearDescriptorPool(dev_data, device, descriptorPool, flags);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003788 }
3789 return result;
3790}
3791
Chia-I Wu9ab61502015-11-06 06:42:02 +08003792VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo* pAllocateInfo, VkDescriptorSet* pDescriptorSets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003793{
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003794 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis0b632332015-10-07 09:38:40 -06003795 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003796 // Verify that requested descriptorSets are available in pool
Mark Lobodzinski39298632015-11-18 08:38:27 -07003797 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003798 if (!pPoolNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003799 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 +08003800 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003801 } else { // Make sure pool has all the available descriptors before calling down chain
Jon Ashburnf19916e2016-01-11 13:12:43 -07003802 skipCall |= validate_descriptor_availability_in_pool(dev_data, pPoolNode, pAllocateInfo->descriptorSetCount, pAllocateInfo->pSetLayouts);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003803 }
3804 if (skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003805 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003806 VkResult result = dev_data->device_dispatch_table->AllocateDescriptorSets(device, pAllocateInfo, pDescriptorSets);
Cody Northrop1e4f8022015-08-03 12:47:29 -06003807 if (VK_SUCCESS == result) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003808 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003809 if (pPoolNode) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07003810 if (pAllocateInfo->descriptorSetCount == 0) {
3811 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 +08003812 "AllocateDescriptorSets called with 0 count");
Cody Northrop1e4f8022015-08-03 12:47:29 -06003813 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07003814 for (uint32_t i = 0; i < pAllocateInfo->descriptorSetCount; i++) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003815 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 +08003816 "Created Descriptor Set %#" PRIxLEAST64, (uint64_t) pDescriptorSets[i]);
Tobin Ehlis793ad302015-04-03 12:01:11 -06003817 // Create new set node and add to head of pool nodes
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003818 SET_NODE* pNewNode = new SET_NODE;
3819 if (NULL == pNewNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003820 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 +08003821 "Out of memory while attempting to allocate SET_NODE in vkAllocateDescriptorSets()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003822 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisce132d82015-06-19 15:07:05 -06003823 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003824 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlis8b5b28c2015-10-19 12:09:13 -06003825 // TODO : Pool should store a total count of each type of Descriptor available
3826 // When descriptors are allocated, decrement the count and validate here
3827 // that the count doesn't go below 0. One reset/free need to bump count back up.
Tobin Ehlis793ad302015-04-03 12:01:11 -06003828 // Insert set at head of Set LL for this pool
3829 pNewNode->pNext = pPoolNode->pSets;
3830 pPoolNode->pSets = pNewNode;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003831 LAYOUT_NODE* pLayout = getLayoutNode(dev_data, pAllocateInfo->pSetLayouts[i]);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003832 if (NULL == pLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003833 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 +08003834 "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 -07003835 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003836 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06003837 pNewNode->pLayout = pLayout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003838 pNewNode->pool = pAllocateInfo->descriptorPool;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003839 pNewNode->set = pDescriptorSets[i];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003840 pNewNode->descriptorCount = pLayout->endIndex + 1;
3841 if (pNewNode->descriptorCount) {
3842 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
3843 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
3844 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
3845 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08003846 dev_data->setMap[pDescriptorSets[i]] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003847 }
3848 }
3849 }
3850 }
3851 return result;
3852}
3853
Chia-I Wu9ab61502015-11-06 06:42:02 +08003854VK_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 -06003855{
Tobin Ehlise735c692015-10-08 13:13:50 -06003856 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis0b632332015-10-07 09:38:40 -06003857 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003858 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, descriptorPool);
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003859 if (pPoolNode && !(VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT & pPoolNode->createInfo.flags)) {
3860 // Can't Free from a NON_FREE pool
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003861 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 -06003862 "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 -06003863 }
Mark Youngb20a6a82016-01-07 15:41:43 -07003864 if (VK_FALSE != skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003865 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis0b632332015-10-07 09:38:40 -06003866 VkResult result = dev_data->device_dispatch_table->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003867 if (VK_SUCCESS == result) {
3868 // For each freed descriptor add it back into the pool as available
3869 for (uint32_t i=0; i<count; ++i) {
Chia-I Wue2fc5522015-10-26 20:04:44 +08003870 SET_NODE* pSet = dev_data->setMap[pDescriptorSets[i]]; // getSetNode() without locking
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003871 LAYOUT_NODE* pLayout = pSet->pLayout;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003872 uint32_t typeIndex = 0, poolSizeCount = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003873 for (uint32_t j=0; j<pLayout->createInfo.bindingCount; ++j) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003874 typeIndex = static_cast<uint32_t>(pLayout->createInfo.pBindings[j].descriptorType);
3875 poolSizeCount = pLayout->createInfo.pBindings[j].descriptorCount;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003876 pPoolNode->availableDescriptorTypeCount[typeIndex] += poolSizeCount;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003877 }
3878 }
3879 }
3880 // TODO : Any other clean-up or book-keeping to do here?
Tony Barbour34ec6922015-07-10 10:50:45 -06003881 return result;
3882}
3883
Chia-I Wu9ab61502015-11-06 06:42:02 +08003884VK_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 -06003885{
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06003886 // 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 -06003887 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08003888 if (!dsUpdate(dev_data, device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies)) {
3889 dev_data->device_dispatch_table->UpdateDescriptorSets(device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies);
Jon Ashburn3950e1b2015-05-20 09:00:28 -06003890 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003891}
3892
Chia-I Wu9ab61502015-11-06 06:42:02 +08003893VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo* pCreateInfo, VkCommandBuffer* pCommandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003894{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003895 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003896 VkResult result = dev_data->device_dispatch_table->AllocateCommandBuffers(device, pCreateInfo, pCommandBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003897 if (VK_SUCCESS == result) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07003898 for (uint32_t i = 0; i < pCreateInfo->commandBufferCount; i++) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003899 // Validate command pool
3900 if (dev_data->commandPoolMap.find(pCreateInfo->commandPool) != dev_data->commandPoolMap.end()) {
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003901 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003902 // Add command buffer to its commandPool map
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003903 dev_data->commandPoolMap[pCreateInfo->commandPool].commandBuffers.push_back(pCommandBuffer[i]);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003904 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
3905 // Add command buffer to map
3906 dev_data->commandBufferMap[pCommandBuffer[i]] = pCB;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003907 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003908 resetCB(dev_data, pCommandBuffer[i]);
3909 pCB->commandBuffer = pCommandBuffer[i];
3910 pCB->createInfo = *pCreateInfo;
Mark Lobodzinski39298632015-11-18 08:38:27 -07003911 }
3912 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003913 }
3914 return result;
3915}
3916
Chia-I Wu9ab61502015-11-06 06:42:02 +08003917VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo* pBeginInfo)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003918{
Mark Youngb20a6a82016-01-07 15:41:43 -07003919 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003920 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06003921 // Validate command buffer level
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003922 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06003923 if (pCB) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07003924 if (pCB->createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
3925 // Secondary Command Buffer
Tobin Ehlis61b36f32015-12-16 08:19:42 -07003926 // TODO : Add check here from spec "If commandBuffer is a secondary command buffer and either the
3927 // occlusionQueryEnable member of pBeginInfo is VK_FALSE, or the precise occlusion queries feature
3928 // is not enabled, the queryFlags member of pBeginInfo must not contain VK_QUERY_CONTROL_PRECISE_BIT"
Jon Ashburnf19916e2016-01-11 13:12:43 -07003929 const VkCommandBufferInheritanceInfo *pInfo = pBeginInfo->pInheritanceInfo;
Tobin Ehlis651d9b02015-12-16 05:01:22 -07003930 if (pBeginInfo->flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07003931 if (!pInfo->renderPass) { // renderpass should NOT be null for an Secondary CB
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003932 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 -07003933 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) must specify a valid renderpass parameter.", (void*)commandBuffer);
3934 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07003935 if (!pInfo->framebuffer) { // framebuffer may be null for an Secondary CB, but this affects perf
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003936 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 -07003937 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) may perform better if a valid framebuffer parameter is specified.", (void*)commandBuffer);
3938 } else {
3939 string errorString = "";
Jon Ashburnf19916e2016-01-11 13:12:43 -07003940 VkRenderPass fbRP = dev_data->frameBufferMap[pInfo->framebuffer]->renderPass;
3941 if (!verify_renderpass_compatibility(dev_data, fbRP, pInfo->renderPass, errorString)) {
Tobin Ehlis651d9b02015-12-16 05:01:22 -07003942 // renderPass that framebuffer was created with must be compatible with local renderPass
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003943 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 -07003944 "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 -07003945 (void*)commandBuffer, (uint64_t)pInfo->renderPass, (uint64_t)pInfo->framebuffer, (uint64_t)fbRP, errorString.c_str());
Tobin Ehlis651d9b02015-12-16 05:01:22 -07003946 }
3947 }
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06003948 }
3949 }
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003950 pCB->beginInfo = *pBeginInfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003951 if (CB_RECORDING == pCB->state) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003952 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 -07003953 "vkBeginCommandBuffer(): Cannot call Begin on CB (%#" PRIxLEAST64 ") in the RECORDING state. Must first call vkEndCommandBuffer().", (uint64_t)commandBuffer);
3954 } else if (CB_RECORDED == pCB->state) {
3955 VkCommandPool cmdPool = pCB->createInfo.commandPool;
3956 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003957 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 -07003958 __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003959 "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.",
3960 (uint64_t) commandBuffer, (uint64_t) cmdPool);
3961 }
3962 }
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003963 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003964 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 +08003965 "In vkBeginCommandBuffer() and unable to find CommandBuffer Node for CB %p!", (void*)commandBuffer);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06003966 }
Mark Youngb20a6a82016-01-07 15:41:43 -07003967 if (VK_FALSE != skipCall) {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003968 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter5fe086f2015-09-04 15:03:52 -06003969 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003970 VkResult result = dev_data->device_dispatch_table->BeginCommandBuffer(commandBuffer, pBeginInfo);
Mark Lobodzinski29b8d5a2015-11-12 16:14:04 -07003971 if ((VK_SUCCESS == result) && (pCB != NULL)) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07003972 if (CB_RECORDED == pCB->state) { resetCB(dev_data, commandBuffer); } pCB->state = CB_RECORDING; }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003973 return result;
3974}
3975
Chia-I Wu9ab61502015-11-06 06:42:02 +08003976VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEndCommandBuffer(VkCommandBuffer commandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003977{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003978 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchtered894072015-09-04 13:39:59 -06003979 VkResult result = VK_SUCCESS;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003980 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3981 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis9c536442015-06-19 13:00:59 -06003982 if (pCB) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003983 if (pCB->state != CB_RECORDING) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003984 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkEndCommandBuffer()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003985 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003986 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003987 if (VK_FALSE == skipCall) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003988 result = dev_data->device_dispatch_table->EndCommandBuffer(commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003989 if (VK_SUCCESS == result) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003990 pCB->state = CB_RECORDED;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003991 // Reset CB status flags
3992 pCB->status = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003993 printCB(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003994 }
3995 } else {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003996 result = VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003997 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003998 return result;
3999}
4000
Chia-I Wu9ab61502015-11-06 06:42:02 +08004001VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004002{
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004003 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004004 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004005 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
4006 VkCommandPool cmdPool = pCB->createInfo.commandPool;
4007 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004008 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 -07004009 __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004010 "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.",
4011 (uint64_t) commandBuffer, (uint64_t) cmdPool);
4012 }
Mark Youngb20a6a82016-01-07 15:41:43 -07004013 if (skipCall != VK_FALSE)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004014 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004015 VkResult result = dev_data->device_dispatch_table->ResetCommandBuffer(commandBuffer, flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004016 if (VK_SUCCESS == result) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004017 resetCB(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004018 }
4019 return result;
4020}
4021
Chia-I Wu9ab61502015-11-06 06:42:02 +08004022VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004023{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004024 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004025 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4026 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004027 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004028 skipCall |= addCmd(dev_data, pCB, CMD_BINDPIPELINE, "vkCmdBindPipeline()");
4029 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
4030 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 -07004031 __LINE__, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004032 "Incorrectly binding compute pipeline (%#" PRIxLEAST64 ") during active RenderPass (%#" PRIxLEAST64 ")",
4033 (uint64_t) pipeline, (uint64_t) pCB->activeRenderPass);
4034 } else if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
4035 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdBindPipeline");
4036 }
4037
4038 PIPELINE_NODE* pPN = getPipeline(dev_data, pipeline);
4039 if (pPN) {
4040 pCB->lastBoundPipeline = pipeline;
4041 loader_platform_thread_lock_mutex(&globalLock);
4042 set_cb_pso_status(pCB, pPN);
4043 loader_platform_thread_unlock_mutex(&globalLock);
4044 skipCall |= validatePipelineState(dev_data, pCB, pipelineBindPoint, pipeline);
Tobin Ehlisce132d82015-06-19 15:07:05 -06004045 } else {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004046 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 -07004047 (uint64_t) pipeline, __LINE__, DRAWSTATE_INVALID_PIPELINE, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004048 "Attempt to bind Pipeline %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<uint64_t>(pipeline));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004049 }
4050 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004051 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004052 dev_data->device_dispatch_table->CmdBindPipeline(commandBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004053}
4054
Chia-I Wu9ab61502015-11-06 06:42:02 +08004055VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetViewport(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004056 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004057 uint32_t firstViewport,
4058 uint32_t viewportCount,
4059 const VkViewport* pViewports)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004060{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004061 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004062 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4063 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004064 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004065 skipCall |= addCmd(dev_data, pCB, CMD_SETVIEWPORTSTATE, "vkCmdSetViewport()");
4066 loader_platform_thread_lock_mutex(&globalLock);
4067 pCB->status |= CBSTATUS_VIEWPORT_SET;
4068 pCB->viewports.resize(viewportCount);
4069 memcpy(pCB->viewports.data(), pViewports, viewportCount * sizeof(VkViewport));
4070 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004071 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004072 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004073 dev_data->device_dispatch_table->CmdSetViewport(commandBuffer, firstViewport, viewportCount, pViewports);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004074}
4075
Chia-I Wu9ab61502015-11-06 06:42:02 +08004076VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetScissor(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004077 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004078 uint32_t firstScissor,
4079 uint32_t scissorCount,
4080 const VkRect2D* pScissors)
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004081{
4082 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004083 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4084 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004085 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004086 skipCall |= addCmd(dev_data, pCB, CMD_SETSCISSORSTATE, "vkCmdSetScissor()");
4087 loader_platform_thread_lock_mutex(&globalLock);
4088 pCB->status |= CBSTATUS_SCISSOR_SET;
4089 pCB->scissors.resize(scissorCount);
4090 memcpy(pCB->scissors.data(), pScissors, scissorCount * sizeof(VkRect2D));
4091 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004092 }
4093 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004094 dev_data->device_dispatch_table->CmdSetScissor(commandBuffer, firstScissor, scissorCount, pScissors);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004095}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004096
Chia-I Wu9ab61502015-11-06 06:42:02 +08004097VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004098{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004099 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004100 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4101 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004102 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004103 skipCall |= addCmd(dev_data, pCB, CMD_SETLINEWIDTHSTATE, "vkCmdSetLineWidth()");
4104 /* TODO: Do we still need this lock? */
4105 loader_platform_thread_lock_mutex(&globalLock);
4106 pCB->status |= CBSTATUS_LINE_WIDTH_SET;
4107 pCB->lineWidth = lineWidth;
4108 loader_platform_thread_unlock_mutex(&globalLock);
Cody Northrop12365112015-08-17 11:10:49 -06004109 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004110 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004111 dev_data->device_dispatch_table->CmdSetLineWidth(commandBuffer, lineWidth);
Cody Northrop12365112015-08-17 11:10:49 -06004112}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004113
Chia-I Wu9ab61502015-11-06 06:42:02 +08004114VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBias(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004115 VkCommandBuffer commandBuffer,
Chia-I Wud8c946a2015-10-26 19:08:09 +08004116 float depthBiasConstantFactor,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004117 float depthBiasClamp,
Chia-I Wud8c946a2015-10-26 19:08:09 +08004118 float depthBiasSlopeFactor)
Cody Northrop12365112015-08-17 11:10:49 -06004119{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004120 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004121 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4122 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northrop12365112015-08-17 11:10:49 -06004123 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004124 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBIASSTATE, "vkCmdSetDepthBias()");
4125 pCB->status |= CBSTATUS_DEPTH_BIAS_SET;
4126 pCB->depthBiasConstantFactor = depthBiasConstantFactor;
4127 pCB->depthBiasClamp = depthBiasClamp;
4128 pCB->depthBiasSlopeFactor = depthBiasSlopeFactor;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004129 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004130 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004131 dev_data->device_dispatch_table->CmdSetDepthBias(commandBuffer, depthBiasConstantFactor, depthBiasClamp, depthBiasSlopeFactor);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004132}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004133
Chia-I Wu9ab61502015-11-06 06:42:02 +08004134VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4])
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004135{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004136 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004137 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4138 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004139 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004140 skipCall |= addCmd(dev_data, pCB, CMD_SETBLENDSTATE, "vkCmdSetBlendConstants()");
4141 pCB->status |= CBSTATUS_BLEND_SET;
4142 memcpy(pCB->blendConstants, blendConstants, 4 * sizeof(float));
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004143 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004144 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004145 dev_data->device_dispatch_table->CmdSetBlendConstants(commandBuffer, blendConstants);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004146}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004147
Chia-I Wu9ab61502015-11-06 06:42:02 +08004148VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBounds(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004149 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004150 float minDepthBounds,
4151 float maxDepthBounds)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004152{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004153 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004154 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4155 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004156 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004157 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBOUNDSSTATE, "vkCmdSetDepthBounds()");
4158 pCB->status |= CBSTATUS_DEPTH_BOUNDS_SET;
4159 pCB->minDepthBounds = minDepthBounds;
4160 pCB->maxDepthBounds = maxDepthBounds;
Cody Northrop82485a82015-08-18 15:21:16 -06004161 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004162 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004163 dev_data->device_dispatch_table->CmdSetDepthBounds(commandBuffer, minDepthBounds, maxDepthBounds);
Cody Northrop82485a82015-08-18 15:21:16 -06004164}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004165
Chia-I Wu9ab61502015-11-06 06:42:02 +08004166VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilCompareMask(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004167 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004168 VkStencilFaceFlags faceMask,
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004169 uint32_t compareMask)
Cody Northrop82485a82015-08-18 15:21:16 -06004170{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004171 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004172 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4173 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northrop82485a82015-08-18 15:21:16 -06004174 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004175 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREADMASKSTATE, "vkCmdSetStencilCompareMask()");
4176 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4177 pCB->front.compareMask = compareMask;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004178 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004179 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4180 pCB->back.compareMask = compareMask;
4181 }
4182 /* TODO: Do we need to track front and back separately? */
4183 /* TODO: We aren't capturing the faceMask, do we need to? */
4184 pCB->status |= CBSTATUS_STENCIL_READ_MASK_SET;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004185 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004186 if (VK_FALSE == skipCall)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004187 dev_data->device_dispatch_table->CmdSetStencilCompareMask(commandBuffer, faceMask, compareMask);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004188}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004189
Chia-I Wu9ab61502015-11-06 06:42:02 +08004190VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilWriteMask(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004191 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004192 VkStencilFaceFlags faceMask,
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004193 uint32_t writeMask)
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004194{
4195 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004196 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4197 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004198 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004199 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILWRITEMASKSTATE, "vkCmdSetStencilWriteMask()");
4200 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4201 pCB->front.writeMask = writeMask;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004202 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004203 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4204 pCB->back.writeMask = writeMask;
4205 }
4206 pCB->status |= CBSTATUS_STENCIL_WRITE_MASK_SET;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004207 }
4208 if (VK_FALSE == skipCall)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004209 dev_data->device_dispatch_table->CmdSetStencilWriteMask(commandBuffer, faceMask, writeMask);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004210}
4211
Chia-I Wu9ab61502015-11-06 06:42:02 +08004212VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilReference(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004213 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004214 VkStencilFaceFlags faceMask,
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004215 uint32_t reference)
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004216{
4217 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004218 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4219 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004220 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004221 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREFERENCESTATE, "vkCmdSetStencilReference()");
4222 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4223 pCB->front.reference = reference;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004224 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004225 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4226 pCB->back.reference = reference;
4227 }
4228 pCB->status |= CBSTATUS_STENCIL_REFERENCE_SET;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004229 }
4230 if (VK_FALSE == skipCall)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004231 dev_data->device_dispatch_table->CmdSetStencilReference(commandBuffer, faceMask, reference);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004232}
4233
Chia-I Wu9ab61502015-11-06 06:42:02 +08004234VK_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 -06004235{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004236 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004237 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4238 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004239 if (pCB) {
Tobin Ehlisf6585052015-12-17 11:48:42 -07004240 if (pCB->state == CB_RECORDING) {
4241 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004242 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 -07004243 "Incorrectly binding compute DescriptorSets during active RenderPass (%#" PRIxLEAST64 ")", (uint64_t) pCB->activeRenderPass);
4244 } else if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
4245 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdBindDescriptorSets");
Mark Lobodzinski74635932015-12-18 15:35:38 -07004246 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07004247 if (VK_FALSE == skipCall) {
4248 // Track total count of dynamic descriptor types to make sure we have an offset for each one
4249 uint32_t totalDynamicDescriptors = 0;
4250 string errorString = "";
4251 uint32_t lastSetIndex = firstSet+setCount-1;
4252 if (lastSetIndex >= pCB->boundDescriptorSets.size())
Tobin Ehlis559c6382015-11-05 09:52:49 -07004253 pCB->boundDescriptorSets.resize(lastSetIndex+1);
Tobin Ehlisf6585052015-12-17 11:48:42 -07004254 VkDescriptorSet oldFinalBoundSet = pCB->boundDescriptorSets[lastSetIndex];
4255 for (uint32_t i=0; i<setCount; i++) {
4256 SET_NODE* pSet = getSetNode(dev_data, pDescriptorSets[i]);
4257 if (pSet) {
4258 loader_platform_thread_lock_mutex(&globalLock);
4259 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
4260 pCB->lastBoundPipelineLayout = layout;
4261 pCB->boundDescriptorSets[i+firstSet] = pDescriptorSets[i];
4262 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004263 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 -07004264 "DS %#" PRIxLEAST64 " bound on pipeline %s", (uint64_t) pDescriptorSets[i], string_VkPipelineBindPoint(pipelineBindPoint));
Tobin Ehlis43c39c02016-01-11 13:18:40 -07004265 if (!pSet->pUpdateStructs && (pSet->descriptorCount != 0)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004266 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 -07004267 "DS %#" PRIxLEAST64 " bound but it was never updated. You may want to either update it or not bind it.", (uint64_t) pDescriptorSets[i]);
4268 }
4269 // Verify that set being bound is compatible with overlapping setLayout of pipelineLayout
4270 if (!verify_set_layout_compatibility(dev_data, pSet, layout, i+firstSet, errorString)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004271 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 -07004272 "descriptorSet #%u being bound is not compatible with overlapping layout in pipelineLayout due to: %s", i, errorString.c_str());
4273 }
4274 if (pSet->pLayout->dynamicDescriptorCount) {
4275 // First make sure we won't overstep bounds of pDynamicOffsets array
4276 if ((totalDynamicDescriptors + pSet->pLayout->dynamicDescriptorCount) > dynamicOffsetCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004277 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 -07004278 "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.",
4279 i, (uint64_t) pDescriptorSets[i], pSet->pLayout->dynamicDescriptorCount, (dynamicOffsetCount - totalDynamicDescriptors));
4280 } else { // Store dynamic offsets with the set
4281 const uint32_t* pStartDynOffset = pDynamicOffsets + totalDynamicDescriptors;
4282 pSet->dynamicOffsets.assign(pStartDynOffset, pStartDynOffset + pSet->pLayout->dynamicDescriptorCount);
4283 totalDynamicDescriptors += pSet->pLayout->dynamicDescriptorCount;
4284 }
4285 }
4286 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004287 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 -07004288 "Attempt to bind DS %#" PRIxLEAST64 " that doesn't exist!", (uint64_t) pDescriptorSets[i]);
4289 }
4290 }
4291 skipCall |= addCmd(dev_data, pCB, CMD_BINDDESCRIPTORSETS, "vkCmdBindDescrsiptorSets()");
4292 // For any previously bound sets, need to set them to "invalid" if they were disturbed by this update
4293 if (firstSet > 0) { // Check set #s below the first bound set
4294 for (uint32_t i=0; i<firstSet; ++i) {
4295 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 -07004296 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 -07004297 "DescriptorSetDS %#" PRIxLEAST64 " previously bound as set #%u was disturbed by newly bound pipelineLayout (%#" PRIxLEAST64 ")", (uint64_t) pCB->boundDescriptorSets[i], i, (uint64_t) layout);
4298 pCB->boundDescriptorSets[i] = VK_NULL_HANDLE;
4299 }
4300 }
4301 }
4302 // Check if newly last bound set invalidates any remaining bound sets
4303 if ((pCB->boundDescriptorSets.size()-1) > (lastSetIndex)) {
4304 if (oldFinalBoundSet && !verify_set_layout_compatibility(dev_data, dev_data->setMap[oldFinalBoundSet], layout, lastSetIndex, errorString)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004305 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 -07004306 "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);
4307 pCB->boundDescriptorSets.resize(lastSetIndex+1);
4308 }
4309 }
4310 // dynamicOffsetCount must equal the total number of dynamic descriptors in the sets being bound
4311 if (totalDynamicDescriptors != dynamicOffsetCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004312 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 -07004313 "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 -07004314 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004315 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07004316 } else {
4317 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindDescriptorSets()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004318 }
4319 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004320 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004321 dev_data->device_dispatch_table->CmdBindDescriptorSets(commandBuffer, pipelineBindPoint, layout, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004322}
4323
Chia-I Wu9ab61502015-11-06 06:42:02 +08004324VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004325{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004326 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004327 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4328 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004329 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004330 skipCall |= addCmd(dev_data, pCB, CMD_BINDINDEXBUFFER, "vkCmdBindIndexBuffer()");
4331 VkDeviceSize offset_align = 0;
4332 switch (indexType) {
4333 case VK_INDEX_TYPE_UINT16:
4334 offset_align = 2;
4335 break;
4336 case VK_INDEX_TYPE_UINT32:
4337 offset_align = 4;
4338 break;
4339 default:
4340 // ParamChecker should catch bad enum, we'll also throw alignment error below if offset_align stays 0
4341 break;
4342 }
4343 if (!offset_align || (offset % offset_align)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004344 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 -07004345 "vkCmdBindIndexBuffer() offset (%#" PRIxLEAST64 ") does not fall on alignment (%s) boundary.", offset, string_VkIndexType(indexType));
Tobin Ehlis9c536442015-06-19 13:00:59 -06004346 }
Tobin Ehlisc4c23182015-09-17 12:24:13 -06004347 pCB->status |= CBSTATUS_INDEX_BUFFER_BOUND;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004348 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004349 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004350 dev_data->device_dispatch_table->CmdBindIndexBuffer(commandBuffer, buffer, offset, indexType);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004351}
4352
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07004353void updateResourceTracking(GLOBAL_CB_NODE* pCB, uint32_t firstBinding, uint32_t bindingCount, const VkBuffer* pBuffers) {
4354 uint32_t end = firstBinding + bindingCount;
Michael Lentine700b0aa2015-10-30 17:57:32 -07004355 if (pCB->currentDrawData.buffers.size() < end) {
4356 pCB->currentDrawData.buffers.resize(end);
4357 }
4358 for (uint32_t i = 0; i < bindingCount; ++i) {
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07004359 pCB->currentDrawData.buffers[i + firstBinding] = pBuffers[i];
Michael Lentine700b0aa2015-10-30 17:57:32 -07004360 }
4361}
4362
4363void updateResourceTrackingOnDraw(GLOBAL_CB_NODE* pCB) {
4364 pCB->drawData.push_back(pCB->currentDrawData);
4365}
4366
Chia-I Wu9ab61502015-11-06 06:42:02 +08004367VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindVertexBuffers(
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07004368 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004369 uint32_t firstBinding,
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06004370 uint32_t bindingCount,
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07004371 const VkBuffer *pBuffers,
4372 const VkDeviceSize *pOffsets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004373{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004374 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004375 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4376 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004377 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004378 addCmd(dev_data, pCB, CMD_BINDVERTEXBUFFER, "vkCmdBindVertexBuffer()");
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07004379 updateResourceTracking(pCB, firstBinding, bindingCount, pBuffers);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004380 } else {
Mark Youngad779052016-01-06 14:26:04 -07004381 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindVertexBuffer()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004382 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004383 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004384 dev_data->device_dispatch_table->CmdBindVertexBuffers(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004385}
4386
Chia-I Wu9ab61502015-11-06 06:42:02 +08004387VK_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 -06004388{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004389 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004390 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4391 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004392 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004393 skipCall |= addCmd(dev_data, pCB, CMD_DRAW, "vkCmdDraw()");
4394 pCB->drawCount[DRAW]++;
4395 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
4396 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004397 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 -07004398 "vkCmdDraw() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW]++);
4399 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004400 if (VK_FALSE == skipCall) {
4401 updateResourceTrackingOnDraw(pCB);
4402 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004403 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDraw");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004404 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004405 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004406 dev_data->device_dispatch_table->CmdDraw(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004407}
4408
Chia-I Wu9ab61502015-11-06 06:42:02 +08004409VK_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 -06004410{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004411 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4412 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004413 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004414 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004415 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXED, "vkCmdDrawIndexed()");
4416 pCB->drawCount[DRAW_INDEXED]++;
4417 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
4418 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004419 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 -07004420 "vkCmdDrawIndexed() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED]++);
4421 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004422 if (VK_FALSE == skipCall) {
4423 updateResourceTrackingOnDraw(pCB);
4424 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004425 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexed");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004426 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004427 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004428 dev_data->device_dispatch_table->CmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004429}
4430
Chia-I Wu9ab61502015-11-06 06:42:02 +08004431VK_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 -06004432{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004433 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4434 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004435 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004436 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004437 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDIRECT, "vkCmdDrawIndirect()");
4438 pCB->drawCount[DRAW_INDIRECT]++;
4439 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
4440 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004441 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 -07004442 "vkCmdDrawIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
4443 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004444 if (VK_FALSE == skipCall) {
4445 updateResourceTrackingOnDraw(pCB);
4446 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004447 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndirect");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004448 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004449 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004450 dev_data->device_dispatch_table->CmdDrawIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004451}
4452
Chia-I Wu9ab61502015-11-06 06:42:02 +08004453VK_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 -06004454{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004455 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004456 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4457 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004458 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004459 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXEDINDIRECT, "vkCmdDrawIndexedIndirect()");
4460 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
4461 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
4462 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004463 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 -07004464 "vkCmdDrawIndexedIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
4465 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004466 if (VK_FALSE == skipCall) {
4467 updateResourceTrackingOnDraw(pCB);
4468 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004469 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexedIndirect");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004470 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004471 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004472 dev_data->device_dispatch_table->CmdDrawIndexedIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004473}
4474
Chia-I Wu9ab61502015-11-06 06:42:02 +08004475VK_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 -06004476{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004477 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004478 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4479 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004480 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004481 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCH, "vkCmdDispatch()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004482 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatch");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004483 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004484 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004485 dev_data->device_dispatch_table->CmdDispatch(commandBuffer, x, y, z);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004486}
4487
Chia-I Wu9ab61502015-11-06 06:42:02 +08004488VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004489{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004490 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004491 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4492 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004493 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004494 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCHINDIRECT, "vkCmdDispatchIndirect()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004495 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatchIndirect");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004496 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004497 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004498 dev_data->device_dispatch_table->CmdDispatchIndirect(commandBuffer, buffer, offset);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004499}
4500
Chia-I Wu9ab61502015-11-06 06:42:02 +08004501VK_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 -06004502{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004503 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004504 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4505 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004506 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004507 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFER, "vkCmdCopyBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004508 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004509 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004510 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004511 dev_data->device_dispatch_table->CmdCopyBuffer(commandBuffer, srcBuffer, dstBuffer, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004512}
4513
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07004514VkBool32 VerifySourceImageLayout(VkCommandBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout) {
Mark Youngb20a6a82016-01-07 15:41:43 -07004515 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07004516
4517#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4518 // TODO: Fix -- initialLayout may have been set in a previous command buffer
4519 return skip_call;
4520#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4521
Michael Lentineabc5e922015-10-12 11:30:14 -05004522 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4523 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4524 auto src_image_element = pCB->imageLayoutMap.find(srcImage);
4525 if (src_image_element == pCB->imageLayoutMap.end()) {
4526 pCB->imageLayoutMap[srcImage].initialLayout = srcImageLayout;
4527 pCB->imageLayoutMap[srcImage].layout = srcImageLayout;
Mark Youngb20a6a82016-01-07 15:41:43 -07004528 return VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05004529 }
4530 if (src_image_element->second.layout != srcImageLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004531 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 -05004532 "Cannot copy from an image whose source layout is %d and doesn't match the current layout %d.", srcImageLayout, src_image_element->second.layout);
4533 }
4534 if (srcImageLayout != VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL) {
4535 if (srcImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004536 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004537 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 -05004538 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Michael Lentineabc5e922015-10-12 11:30:14 -05004539 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004540 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 -05004541 "Layout for input image is %d but can only be TRANSFER_SRC_OPTIMAL or GENERAL.", srcImageLayout);
Michael Lentineabc5e922015-10-12 11:30:14 -05004542 }
4543 }
4544 return skip_call;
4545}
4546
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07004547VkBool32 VerifyDestImageLayout(VkCommandBuffer cmdBuffer, VkImage destImage, VkImageLayout destImageLayout) {
Mark Youngb20a6a82016-01-07 15:41:43 -07004548 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07004549
4550#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4551 // TODO: Fix -- initialLayout may have been set in a previous command buffer
4552 return skip_call;
4553#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4554
Michael Lentineabc5e922015-10-12 11:30:14 -05004555 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4556 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4557 auto dest_image_element = pCB->imageLayoutMap.find(destImage);
4558 if (dest_image_element == pCB->imageLayoutMap.end()) {
4559 pCB->imageLayoutMap[destImage].initialLayout = destImageLayout;
4560 pCB->imageLayoutMap[destImage].layout = destImageLayout;
Mark Youngb20a6a82016-01-07 15:41:43 -07004561 return VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05004562 }
4563 if (dest_image_element->second.layout != destImageLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004564 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 -05004565 "Cannot copy from an image whose dest layout is %d and doesn't match the current layout %d.", destImageLayout, dest_image_element->second.layout);
4566 }
4567 if (destImageLayout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) {
4568 if (destImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004569 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004570 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 -05004571 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
4572 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004573 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 -05004574 "Layout for output image is %d but can only be TRANSFER_DST_OPTIMAL or GENERAL.", destImageLayout);
4575 }
4576 }
4577 return skip_call;
4578}
4579
Chia-I Wu9ab61502015-11-06 06:42:02 +08004580VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004581 VkImage srcImage,
4582 VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004583 VkImage dstImage,
4584 VkImageLayout dstImageLayout,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004585 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004586{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004587 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004588 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4589 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004590 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004591 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGE, "vkCmdCopyImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004592 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImage");
Michael Lentineabc5e922015-10-12 11:30:14 -05004593 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
4594 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004595 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004596 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004597 dev_data->device_dispatch_table->CmdCopyImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004598}
4599
Chia-I Wu9ab61502015-11-06 06:42:02 +08004600VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBlitImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004601 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004602 VkImage dstImage, VkImageLayout dstImageLayout,
Mark Lobodzinskiee5eef12015-05-22 14:43:25 -05004603 uint32_t regionCount, const VkImageBlit* pRegions,
Chia-I Wub99df442015-10-26 16:49:32 +08004604 VkFilter filter)
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004605{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004606 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004607 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4608 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004609 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004610 skipCall |= addCmd(dev_data, pCB, CMD_BLITIMAGE, "vkCmdBlitImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004611 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBlitImage");
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004612 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004613 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004614 dev_data->device_dispatch_table->CmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter);
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004615}
4616
Chia-I Wu9ab61502015-11-06 06:42:02 +08004617VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004618 VkBuffer srcBuffer,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004619 VkImage dstImage, VkImageLayout dstImageLayout,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004620 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004621{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004622 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004623 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4624 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004625 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004626 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFERTOIMAGE, "vkCmdCopyBufferToImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004627 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBufferToImage");
Michael Lentineabc5e922015-10-12 11:30:14 -05004628 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004629 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004630 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004631 dev_data->device_dispatch_table->CmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004632}
4633
Chia-I Wu9ab61502015-11-06 06:42:02 +08004634VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004635 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004636 VkBuffer dstBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004637 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004638{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004639 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004640 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4641 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004642 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004643 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGETOBUFFER, "vkCmdCopyImageToBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004644 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImageToBuffer");
Michael Lentineabc5e922015-10-12 11:30:14 -05004645 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004646 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004647 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004648 dev_data->device_dispatch_table->CmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004649}
4650
Chia-I Wu9ab61502015-11-06 06:42:02 +08004651VK_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 -06004652{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004653 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004654 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4655 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004656 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004657 skipCall |= addCmd(dev_data, pCB, CMD_UPDATEBUFFER, "vkCmdUpdateBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004658 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyUpdateBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004659 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004660 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004661 dev_data->device_dispatch_table->CmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004662}
4663
Chia-I Wu9ab61502015-11-06 06:42:02 +08004664VK_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 -06004665{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004666 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004667 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4668 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004669 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004670 skipCall |= addCmd(dev_data, pCB, CMD_FILLBUFFER, "vkCmdFillBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004671 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyFillBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004672 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004673 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004674 dev_data->device_dispatch_table->CmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004675}
4676
Chia-I Wu9ab61502015-11-06 06:42:02 +08004677VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearAttachments(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004678 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004679 uint32_t attachmentCount,
4680 const VkClearAttachment* pAttachments,
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004681 uint32_t rectCount,
Courtney Goeltzenleuchter4ca43f62015-10-15 18:22:08 -06004682 const VkClearRect* pRects)
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004683{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004684 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004685 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4686 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004687 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004688 skipCall |= addCmd(dev_data, pCB, CMD_CLEARATTACHMENTS, "vkCmdClearAttachments()");
4689 // Warn if this is issued prior to Draw Cmd and clearing the entire attachment
4690 if (!hasDrawCmd(pCB) &&
4691 (pCB->activeRenderPassBeginInfo.renderArea.extent.width == pRects[0].rect.extent.width) &&
4692 (pCB->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) {
4693 // TODO : commandBuffer should be srcObj
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004694 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 -07004695 "vkCmdClearAttachments() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
4696 " 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 -06004697 }
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004698 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdClearAttachments");
4699 }
4700
4701 // Validate that attachment is in reference list of active subpass
4702 if (pCB->activeRenderPass) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07004703 const VkRenderPassCreateInfo *pRPCI = dev_data->renderPassMap[pCB->activeRenderPass]->pCreateInfo;
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004704 const VkSubpassDescription *pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
4705
4706 for (uint32_t attachment_idx = 0; attachment_idx < attachmentCount; attachment_idx++) {
4707 const VkClearAttachment *attachment = &pAttachments[attachment_idx];
4708 if (attachment->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) {
4709 VkBool32 found = VK_FALSE;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004710 for (uint32_t i = 0; i < pSD->colorAttachmentCount; i++) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004711 if (attachment->colorAttachment == pSD->pColorAttachments[i].attachment) {
4712 found = VK_TRUE;
4713 break;
4714 }
4715 }
4716 if (VK_FALSE == found) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004717 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 -07004718 (uint64_t)commandBuffer, __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004719 "vkCmdClearAttachments() attachment index %d not found in attachment reference array of active subpass %d",
4720 attachment->colorAttachment, pCB->activeSubpass);
4721 }
4722 } else if (attachment->aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) {
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07004723 if (!pSD->pDepthStencilAttachment || // Says no DS will be used in active subpass
Mark Lobodzinski2fd355a2015-11-18 08:58:31 -07004724 (pSD->pDepthStencilAttachment->attachment == VK_ATTACHMENT_UNUSED)) { // Says no DS will be used in active subpass
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07004725
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004726 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 -07004727 (uint64_t)commandBuffer, __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07004728 "vkCmdClearAttachments() attachment index %d does not match depthStencilAttachment.attachment (%d) found in active subpass %d",
4729 attachment->colorAttachment,
4730 (pSD->pDepthStencilAttachment) ? pSD->pDepthStencilAttachment->attachment : VK_ATTACHMENT_UNUSED,
4731 pCB->activeSubpass);
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004732 }
4733 }
4734 }
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004735 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004736 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004737 dev_data->device_dispatch_table->CmdClearAttachments(commandBuffer, attachmentCount, pAttachments, rectCount, pRects);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004738}
4739
Chia-I Wu9ab61502015-11-06 06:42:02 +08004740VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearColorImage(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004741 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06004742 VkImage image, VkImageLayout imageLayout,
Chris Forbesf0796e12015-06-24 14:34:53 +12004743 const VkClearColorValue *pColor,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06004744 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004745{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004746 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004747 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4748 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004749 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004750 skipCall |= addCmd(dev_data, pCB, CMD_CLEARCOLORIMAGE, "vkCmdClearColorImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004751 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearColorImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004752 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004753 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004754 dev_data->device_dispatch_table->CmdClearColorImage(commandBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004755}
4756
Chia-I Wu9ab61502015-11-06 06:42:02 +08004757VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearDepthStencilImage(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004758 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter45df9e12015-09-15 18:03:22 -06004759 VkImage image, VkImageLayout imageLayout,
4760 const VkClearDepthStencilValue *pDepthStencil,
4761 uint32_t rangeCount,
4762 const VkImageSubresourceRange* pRanges)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004763{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004764 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004765 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4766 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004767 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004768 skipCall |= addCmd(dev_data, pCB, CMD_CLEARDEPTHSTENCILIMAGE, "vkCmdClearDepthStencilImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004769 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearDepthStencilImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004770 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004771 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004772 dev_data->device_dispatch_table->CmdClearDepthStencilImage(commandBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004773}
4774
Chia-I Wu9ab61502015-11-06 06:42:02 +08004775VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResolveImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004776 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004777 VkImage dstImage, VkImageLayout dstImageLayout,
Tony Barbour6865d4a2015-04-13 15:02:52 -06004778 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004779{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004780 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004781 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4782 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004783 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004784 skipCall |= addCmd(dev_data, pCB, CMD_RESOLVEIMAGE, "vkCmdResolveImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004785 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResolveImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004786 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004787 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004788 dev_data->device_dispatch_table->CmdResolveImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004789}
4790
Chia-I Wu9ab61502015-11-06 06:42:02 +08004791VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004792{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004793 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004794 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4795 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004796 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004797 skipCall |= addCmd(dev_data, pCB, CMD_SETEVENT, "vkCmdSetEvent()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004798 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdSetEvent");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004799 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004800 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004801 dev_data->device_dispatch_table->CmdSetEvent(commandBuffer, event, stageMask);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004802}
4803
Chia-I Wu9ab61502015-11-06 06:42:02 +08004804VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004805{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004806 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004807 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4808 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004809 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004810 skipCall |= addCmd(dev_data, pCB, CMD_RESETEVENT, "vkCmdResetEvent()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004811 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResetEvent");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004812 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004813 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004814 dev_data->device_dispatch_table->CmdResetEvent(commandBuffer, event, stageMask);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004815}
4816
Jon Ashburnf19916e2016-01-11 13:12:43 -07004817VkBool32 TransitionImageLayouts(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const VkImageMemoryBarrier* pImgMemBarriers) {
Michael Lentineabc5e922015-10-12 11:30:14 -05004818 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4819 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Mark Youngb20a6a82016-01-07 15:41:43 -07004820 VkBool32 skip = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07004821
4822#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4823 // TODO: Fix -- pay attention to image subresource ranges -- not all subresources transition at the same time
4824 return skip;
4825#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4826
Michael Lentineabc5e922015-10-12 11:30:14 -05004827 for (uint32_t i = 0; i < memBarrierCount; ++i) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004828 auto mem_barrier = &pImgMemBarriers[i];
Michael Lentineabc5e922015-10-12 11:30:14 -05004829 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004830 auto image_data = pCB->imageLayoutMap.find(mem_barrier->image);
Michael Lentineabc5e922015-10-12 11:30:14 -05004831 if (image_data == pCB->imageLayoutMap.end()) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004832 pCB->imageLayoutMap[mem_barrier->image].initialLayout = mem_barrier->oldLayout;
4833 pCB->imageLayoutMap[mem_barrier->image].layout = mem_barrier->newLayout;
Michael Lentineabc5e922015-10-12 11:30:14 -05004834 } else {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004835 if (image_data->second.layout != mem_barrier->oldLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004836 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 -07004837 "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 -05004838 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07004839 image_data->second.layout = mem_barrier->newLayout;
Michael Lentineabc5e922015-10-12 11:30:14 -05004840 }
4841 }
4842 }
4843 return skip;
4844}
4845
Mark Lobodzinskia3a86112016-01-05 17:17:55 -07004846// Print readable FlagBits in FlagMask
4847std::string string_VkAccessFlags(VkAccessFlags accessMask)
4848{
4849 std::string result;
4850 std::string separator;
4851
4852 if (accessMask == 0) {
4853 result = "[None]";
4854 } else {
4855 result = "[";
4856 for (auto i = 0; i < 32; i++) {
4857 if (accessMask & (1 << i)) {
4858 result = result + separator + string_VkAccessFlagBits((VkAccessFlagBits)(1 << i));
4859 separator = " | ";
4860 }
4861 }
4862 result = result + "]";
4863 }
4864 return result;
4865}
4866
Michael Lentine97eb7462015-11-20 09:48:52 -08004867// AccessFlags MUST have 'required_bit' set, and may have one or more of 'optional_bits' set.
4868// If required_bit is zero, accessMask must have at least one of 'optional_bits' set
Mark Lobodzinskifd740fc2016-01-06 12:56:29 -07004869// TODO: Add tracking to ensure that at least one barrier has been set for these layout transitions
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004870VkBool32 ValidateMaskBits(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout,
4871 VkAccessFlags required_bit, VkAccessFlags optional_bits, const char* type) {
Mark Youngb20a6a82016-01-07 15:41:43 -07004872 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004873
Michael Lentine97eb7462015-11-20 09:48:52 -08004874 if ((accessMask & required_bit) || (!required_bit && (accessMask & optional_bits))) {
4875 if (accessMask & !(required_bit | optional_bits)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004876 // TODO: Verify against Valid Use
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004877 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 -07004878 "Additional bits in %s accessMask %d %s are specified when layout is %s.",
4879 type, accessMask, string_VkAccessFlags(accessMask).c_str(), string_VkImageLayout(layout));
Michael Lentineecc32b72015-10-16 18:08:09 -05004880 }
4881 } else {
Michael Lentine97eb7462015-11-20 09:48:52 -08004882 if (!required_bit) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004883 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 -07004884 "%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 -07004885 type, accessMask, string_VkAccessFlags(accessMask).c_str(), optional_bits,
4886 string_VkAccessFlags(optional_bits).c_str(), string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08004887 } else {
Mark Lobodzinskif2cc2a52016-01-05 13:35:29 -07004888 std::string opt_bits;
4889 if (optional_bits != 0) {
4890 opt_bits = "and may have optional bits " + std::to_string(optional_bits) + ' ' + string_VkAccessFlags(optional_bits);
4891 }
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004892 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 -07004893 "%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 -07004894 type, accessMask, string_VkAccessFlags(accessMask).c_str(),
4895 required_bit, string_VkAccessFlags(required_bit).c_str(),
Mark Lobodzinskif2cc2a52016-01-05 13:35:29 -07004896 opt_bits.c_str(), string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08004897 }
Michael Lentineecc32b72015-10-16 18:08:09 -05004898 }
4899 return skip_call;
4900}
4901
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004902VkBool32 ValidateMaskBitsFromLayouts(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout, const char* type) {
Mark Youngb20a6a82016-01-07 15:41:43 -07004903 VkBool32 skip_call = VK_FALSE;
Michael Lentine97eb7462015-11-20 09:48:52 -08004904 switch (layout) {
4905 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004906 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 -08004907 break;
Michael Lentineecc32b72015-10-16 18:08:09 -05004908 }
Michael Lentine97eb7462015-11-20 09:48:52 -08004909 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004910 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 -08004911 break;
Michael Lentineecc32b72015-10-16 18:08:09 -05004912 }
Michael Lentine97eb7462015-11-20 09:48:52 -08004913 case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004914 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_WRITE_BIT, 0, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08004915 break;
4916 }
4917 case VK_IMAGE_LAYOUT_PREINITIALIZED: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004918 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_HOST_WRITE_BIT, 0, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08004919 break;
4920 }
4921 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004922 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 -08004923 break;
4924 }
4925 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004926 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 -08004927 break;
4928 }
4929 case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004930 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_READ_BIT, 0, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08004931 break;
4932 }
4933 case VK_IMAGE_LAYOUT_UNDEFINED: {
4934 if (accessMask != 0) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004935 // TODO: Verify against Valid Use section spec
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004936 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 -07004937 "Additional bits in %s accessMask %d %s are specified when layout is %s.", type, accessMask, string_VkAccessFlags(accessMask).c_str(),
4938 string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08004939 }
4940 break;
4941 }
4942 case VK_IMAGE_LAYOUT_GENERAL:
4943 default: {
4944 break;
4945 }
Michael Lentineecc32b72015-10-16 18:08:09 -05004946 }
4947 return skip_call;
4948}
4949
Jon Ashburnf19916e2016-01-11 13:12:43 -07004950VkBool32 ValidateBarriers(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const VkMemoryBarrier* pMemBarriers, uint32_t imageMemBarrierCount, const VkImageMemoryBarrier *pImageMemBarriers)
4951{
Mark Youngb20a6a82016-01-07 15:41:43 -07004952 VkBool32 skip_call = VK_FALSE;
Michael Lentine48930b82015-10-15 17:07:00 -05004953 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4954 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4955 if (pCB->activeRenderPass && memBarrierCount) {
4956 for (uint32_t i = 0; i < memBarrierCount; ++i) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004957 auto mem_barrier = &pMemBarriers[i];
Michael Lentine48930b82015-10-15 17:07:00 -05004958 if (mem_barrier && mem_barrier->sType != VK_STRUCTURE_TYPE_MEMORY_BARRIER) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004959 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 -05004960 "Image or Buffers Barriers cannot be used during a render pass.");
4961 }
4962 }
4963 if (!dev_data->renderPassMap[pCB->activeRenderPass]->hasSelfDependency[pCB->activeSubpass]) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004964 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 -05004965 "Barriers cannot be set during subpass %d with no self dependency specified.", pCB->activeSubpass);
4966 }
4967 }
Mark Lobodzinski73a37ec2015-11-20 09:27:27 -07004968
Jon Ashburnf19916e2016-01-11 13:12:43 -07004969 for (uint32_t i = 0; i < imageMemBarrierCount; ++i) {
4970 auto mem_barrier = &pImageMemBarriers[i];
Michael Lentineecc32b72015-10-16 18:08:09 -05004971 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004972 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, mem_barrier->srcAccessMask, mem_barrier->oldLayout, "Source");
4973 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, mem_barrier->dstAccessMask, mem_barrier->newLayout, "Dest");
Michael Lentineecc32b72015-10-16 18:08:09 -05004974 }
4975 }
Mark Lobodzinski3cba24a2015-12-03 15:42:32 -07004976
Michael Lentine48930b82015-10-15 17:07:00 -05004977 return skip_call;
4978}
4979
Jon Ashburnf19916e2016-01-11 13:12:43 -07004980VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdWaitEvents(
4981 VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent* pEvents,
4982 VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask,
4983 uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers,
4984 uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers,
4985 uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004986{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004987 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004988 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4989 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004990 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06004991 for (uint32_t i = 0; i < eventCount; ++i) {
4992 pCB->waitedEvents.push_back(pEvents[i]);
4993 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07004994 if (pCB->state == CB_RECORDING) {
4995 skipCall |= addCmd(dev_data, pCB, CMD_WAITEVENTS, "vkCmdWaitEvents()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06004996 } else {
4997 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdWaitEvents()");
4998 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07004999 skipCall |= TransitionImageLayouts(commandBuffer, imageMemoryBarrierCount, pImageMemoryBarriers);
5000 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, pMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005001 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005002 if (VK_FALSE == skipCall)
Jon Ashburnf19916e2016-01-11 13:12:43 -07005003 dev_data->device_dispatch_table->CmdWaitEvents(commandBuffer, eventCount, pEvents, sourceStageMask, dstStageMask,
5004 memoryBarrierCount, pMemoryBarriers,
5005 bufferMemoryBarrierCount, pBufferMemoryBarriers,
5006 imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005007}
5008
Jon Ashburnf19916e2016-01-11 13:12:43 -07005009VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdPipelineBarrier(
5010 VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask,
5011 VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags,
5012 uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers,
5013 uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers,
5014 uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005015{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005016 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005017 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5018 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005019 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005020 skipCall |= addCmd(dev_data, pCB, CMD_PIPELINEBARRIER, "vkCmdPipelineBarrier()");
Jon Ashburnf19916e2016-01-11 13:12:43 -07005021 skipCall |= TransitionImageLayouts(commandBuffer, imageMemoryBarrierCount, pImageMemoryBarriers);
5022 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, pMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005023 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005024 if (VK_FALSE == skipCall)
Jon Ashburnf19916e2016-01-11 13:12:43 -07005025 dev_data->device_dispatch_table->CmdPipelineBarrier(commandBuffer, srcStageMask, dstStageMask, dependencyFlags,
5026 memoryBarrierCount, pMemoryBarriers,
5027 bufferMemoryBarrierCount, pBufferMemoryBarriers,
5028 imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005029}
5030
Chia-I Wu9ab61502015-11-06 06:42:02 +08005031VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005032{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005033 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005034 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5035 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005036 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005037 skipCall |= addCmd(dev_data, pCB, CMD_BEGINQUERY, "vkCmdBeginQuery()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005038 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005039 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005040 dev_data->device_dispatch_table->CmdBeginQuery(commandBuffer, queryPool, slot, flags);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005041}
5042
Chia-I Wu9ab61502015-11-06 06:42:02 +08005043VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005044{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005045 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005046 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5047 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005048 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005049 QueryObject query = {queryPool, slot};
5050 pCB->queryToStateMap[query] = 1;
Mark Lobodzinskice738852016-01-07 10:04:02 -07005051 if (pCB->state == CB_RECORDING) {
5052 skipCall |= addCmd(dev_data, pCB, CMD_ENDQUERY, "VkCmdEndQuery()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005053 } else {
5054 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdEndQuery()");
5055 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005056 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005057 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005058 dev_data->device_dispatch_table->CmdEndQuery(commandBuffer, queryPool, slot);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005059}
5060
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005061VK_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 -06005062{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005063 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005064 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5065 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005066 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005067 for (uint32_t i = 0; i < queryCount; i++) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005068 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06005069 pCB->waitedEventsBeforeQueryReset[query] = pCB->waitedEvents;
5070 pCB->queryToStateMap[query] = 0;
5071 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005072 if (pCB->state == CB_RECORDING) {
5073 skipCall |= addCmd(dev_data, pCB, CMD_RESETQUERYPOOL, "VkCmdResetQueryPool()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005074 } else {
5075 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdResetQueryPool()");
5076 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005077 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdQueryPool");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005078 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005079 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005080 dev_data->device_dispatch_table->CmdResetQueryPool(commandBuffer, queryPool, firstQuery, queryCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005081}
5082
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005083VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005084 uint32_t queryCount, VkBuffer dstBuffer, VkDeviceSize dstOffset,
Chia-I Wuccc93a72015-10-26 18:36:20 +08005085 VkDeviceSize stride, VkQueryResultFlags flags)
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005086{
5087 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005088 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5089 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005090 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005091 for (uint32_t i = 0; i < queryCount; i++) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005092 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06005093 if(!pCB->queryToStateMap[query]) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005094 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_QUERY, "DS",
5095 "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 -06005096 }
5097 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005098 if (pCB->state == CB_RECORDING) {
5099 skipCall |= addCmd(dev_data, pCB, CMD_COPYQUERYPOOLRESULTS, "vkCmdCopyQueryPoolResults()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005100 } else {
5101 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdCopyQueryPoolResults()");
5102 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005103 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyQueryPoolResults");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005104 }
5105 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005106 dev_data->device_dispatch_table->CmdCopyQueryPoolResults(commandBuffer, queryPool,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005107 firstQuery, queryCount, dstBuffer, dstOffset, stride, flags);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005108}
5109
Chia-I Wu9ab61502015-11-06 06:42:02 +08005110VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005111{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005112 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005113 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5114 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005115 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005116 QueryObject query = {queryPool, slot};
5117 pCB->queryToStateMap[query] = 1;
Mark Lobodzinskice738852016-01-07 10:04:02 -07005118 if (pCB->state == CB_RECORDING) {
5119 skipCall |= addCmd(dev_data, pCB, CMD_WRITETIMESTAMP, "vkCmdWriteTimestamp()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005120 } else {
5121 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdWriteTimestamp()");
5122 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005123 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005124 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005125 dev_data->device_dispatch_table->CmdWriteTimestamp(commandBuffer, pipelineStage, queryPool, slot);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005126}
5127
Chia-I Wu9ab61502015-11-06 06:42:02 +08005128VK_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 -06005129{
Tobin Ehlis0b632332015-10-07 09:38:40 -06005130 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005131 VkResult result = dev_data->device_dispatch_table->CreateFramebuffer(device, pCreateInfo, pAllocator, pFramebuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005132 if (VK_SUCCESS == result) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06005133 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06005134 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +08005135 if (pCreateInfo->pAttachments) {
Courtney Goeltzenleuchter5861a1b2015-09-01 17:30:39 -06005136 localFBCI->pAttachments = new VkImageView[localFBCI->attachmentCount];
5137 memcpy((void*)localFBCI->pAttachments, pCreateInfo->pAttachments, localFBCI->attachmentCount*sizeof(VkImageView));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005138 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08005139 dev_data->frameBufferMap[*pFramebuffer] = localFBCI;
Tobin Ehliseba312c2015-04-01 08:40:34 -06005140 }
5141 return result;
5142}
5143
Michael Lentineb6986752015-10-06 14:56:18 -07005144// Store the DAG.
5145struct DAGNode {
5146 uint32_t pass;
5147 std::vector<uint32_t> prev;
5148 std::vector<uint32_t> next;
5149};
5150
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005151VkBool32 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 -07005152 // If we have already checked this node we have not found a dependency path so return false.
5153 if (processed_nodes.count(index))
Mark Youngb20a6a82016-01-07 15:41:43 -07005154 return VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005155 processed_nodes.insert(index);
5156 const DAGNode& node = subpass_to_node[index];
5157 // Look for a dependency path. If one exists return true else recurse on the previous nodes.
5158 if (std::find(node.prev.begin(), node.prev.end(), dependent) == node.prev.end()) {
5159 for (auto elem : node.prev) {
5160 if (FindDependency(elem, dependent, subpass_to_node, processed_nodes))
Mark Youngb20a6a82016-01-07 15:41:43 -07005161 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005162 }
5163 } else {
Mark Youngb20a6a82016-01-07 15:41:43 -07005164 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005165 }
Mark Youngb20a6a82016-01-07 15:41:43 -07005166 return VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005167}
5168
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005169VkBool32 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 -07005170 VkBool32 result = VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005171 // Loop through all subpasses that share the same attachment and make sure a dependency exists
5172 for (uint32_t k = 0; k < dependent_subpasses.size(); ++k) {
5173 if (subpass == dependent_subpasses[k])
5174 continue;
5175 const DAGNode& node = subpass_to_node[subpass];
5176 // Check for a specified dependency between the two nodes. If one exists we are done.
5177 auto prev_elem = std::find(node.prev.begin(), node.prev.end(), dependent_subpasses[k]);
5178 auto next_elem = std::find(node.next.begin(), node.next.end(), dependent_subpasses[k]);
5179 if (prev_elem == node.prev.end() && next_elem == node.next.end()) {
5180 // If no dependency exits an implicit dependency still might. If so, warn and if not throw an error.
5181 std::unordered_set<uint32_t> processed_nodes;
5182 if (FindDependency(subpass, dependent_subpasses[k], subpass_to_node, processed_nodes) ||
5183 FindDependency(dependent_subpasses[k], subpass, subpass_to_node, processed_nodes)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005184 // TODO: Verify against Valid Use section of spec
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005185 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 -07005186 "A dependency between subpasses %d and %d must exist but only an implicit one is specified.",
5187 subpass, dependent_subpasses[k]);
5188 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005189 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 -07005190 "A dependency between subpasses %d and %d must exist but one is not specified.",
5191 subpass, dependent_subpasses[k]);
Mark Youngb20a6a82016-01-07 15:41:43 -07005192 result = VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005193 }
5194 }
5195 }
5196 return result;
5197}
5198
Jon Ashburnf19916e2016-01-11 13:12:43 -07005199VkBool32 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 -07005200 const DAGNode& node = subpass_to_node[index];
5201 // If this node writes to the attachment return true as next nodes need to preserve the attachment.
5202 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005203 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005204 if (attachment == subpass.pColorAttachments[j].attachment)
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005205 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005206 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005207 if (subpass.pDepthStencilAttachment &&
5208 subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
5209 if (attachment == subpass.pDepthStencilAttachment->attachment)
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005210 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005211 }
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005212 VkBool32 result = VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005213 // Loop through previous nodes and see if any of them write to the attachment.
5214 for (auto elem : node.prev) {
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005215 result |= CheckPreserved(my_data, device, pCreateInfo, elem, attachment, subpass_to_node, depth + 1, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005216 }
5217 // If the attachment was written to by a previous node than this node needs to preserve it.
5218 if (result && depth > 0) {
5219 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Mark Youngb20a6a82016-01-07 15:41:43 -07005220 VkBool32 has_preserved = VK_FALSE;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005221 for (uint32_t j = 0; j < subpass.preserveAttachmentCount; ++j) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005222 if (subpass.pPreserveAttachments[j] == attachment) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005223 has_preserved = VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005224 break;
5225 }
5226 }
Mark Youngb20a6a82016-01-07 15:41:43 -07005227 if (has_preserved == VK_FALSE) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005228 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 -07005229 "Attachment %d is used by a later subpass and must be preserved in subpass %d.", attachment, index);
5230 }
5231 }
5232 return result;
5233}
5234
Michael Lentineb4979492015-12-22 11:36:14 -06005235VkBool32 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 -07005236 VkBool32 skip_call = VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005237 std::vector<std::vector<uint32_t>> output_attachment_to_subpass(pCreateInfo->attachmentCount);
5238 std::vector<std::vector<uint32_t>> input_attachment_to_subpass(pCreateInfo->attachmentCount);
Michael Lentineb6986752015-10-06 14:56:18 -07005239 // Find for each attachment the subpasses that use them.
5240 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5241 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005242 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005243 input_attachment_to_subpass[subpass.pInputAttachments[j].attachment].push_back(i);
5244 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08005245 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005246 output_attachment_to_subpass[subpass.pColorAttachments[j].attachment].push_back(i);
5247 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005248 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
5249 output_attachment_to_subpass[subpass.pDepthStencilAttachment->attachment].push_back(i);
Michael Lentineb6986752015-10-06 14:56:18 -07005250 }
5251 }
5252 // If there is a dependency needed make sure one exists
5253 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5254 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
5255 // If the attachment is an input then all subpasses that output must have a dependency relationship
Chia-I Wud50a7d72015-10-26 20:48:51 +08005256 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005257 const uint32_t& attachment = subpass.pInputAttachments[j].attachment;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005258 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005259 }
5260 // 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 +08005261 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005262 const uint32_t& attachment = subpass.pColorAttachments[j].attachment;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005263 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
5264 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005265 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005266 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
5267 const uint32_t& attachment = subpass.pDepthStencilAttachment->attachment;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005268 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
5269 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005270 }
5271 }
5272 // Loop through implicit dependencies, if this pass reads make sure the attachment is preserved for all passes after it was written.
5273 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5274 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005275 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005276 CheckPreserved(my_data, device, pCreateInfo, i, subpass.pInputAttachments[j].attachment, subpass_to_node, 0, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005277 }
5278 }
5279 return skip_call;
5280}
5281
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005282VkBool32 ValidateLayouts(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005283 VkBool32 skip = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005284
5285#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
5286 return skip;
5287#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5288
Michael Lentineabc5e922015-10-12 11:30:14 -05005289 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5290 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
5291 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
5292 if (subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL &&
5293 subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) {
5294 if (subpass.pInputAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005295 // 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 -07005296 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 -05005297 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
5298 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005299 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 -05005300 "Layout for input attachment is %d but can only be READ_ONLY_OPTIMAL or GENERAL.", subpass.pInputAttachments[j].attachment);
5301 }
5302 }
5303 }
5304 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
5305 if (subpass.pColorAttachments[j].layout != VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) {
5306 if (subpass.pColorAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005307 // 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 -07005308 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 -05005309 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
5310 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005311 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 -05005312 "Layout for color attachment is %d but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.", subpass.pColorAttachments[j].attachment);
5313 }
5314 }
5315 }
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005316 if ((subpass.pDepthStencilAttachment != NULL) &&
5317 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
Michael Lentineabc5e922015-10-12 11:30:14 -05005318 if (subpass.pDepthStencilAttachment->layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) {
5319 if (subpass.pDepthStencilAttachment->layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005320 // 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 -07005321 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 -05005322 "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL.");
5323 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005324 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 -05005325 "Layout for depth attachment is %d but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL.", subpass.pDepthStencilAttachment->attachment);
5326 }
5327 }
5328 }
5329 }
5330 return skip;
5331}
5332
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005333VkBool32 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 -07005334 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05005335 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5336 DAGNode& subpass_node = subpass_to_node[i];
5337 subpass_node.pass = i;
5338 }
5339 for (uint32_t i = 0; i < pCreateInfo->dependencyCount; ++i) {
5340 const VkSubpassDependency& dependency = pCreateInfo->pDependencies[i];
5341 if (dependency.srcSubpass > dependency.dstSubpass) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005342 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 -05005343 "Depedency graph must be specified such that an earlier pass cannot depend on a later pass.");
Michael Lentine48930b82015-10-15 17:07:00 -05005344 } else if (dependency.srcSubpass == dependency.dstSubpass) {
5345 has_self_dependency[dependency.srcSubpass] = true;
Michael Lentineabc5e922015-10-12 11:30:14 -05005346 }
5347 subpass_to_node[dependency.dstSubpass].prev.push_back(dependency.srcSubpass);
5348 subpass_to_node[dependency.srcSubpass].next.push_back(dependency.dstSubpass);
5349 }
5350 return skip_call;
5351}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005352// TODOSC : Add intercept of vkCreateShaderModule
Michael Lentineabc5e922015-10-12 11:30:14 -05005353
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005354VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateShaderModule(
5355 VkDevice device,
5356 const VkShaderModuleCreateInfo *pCreateInfo,
5357 const VkAllocationCallbacks* pAllocator,
5358 VkShaderModule *pShaderModule)
5359{
5360 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07005361 VkBool32 skip_call = VK_FALSE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005362 if (!shader_is_spirv(pCreateInfo)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005363 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 -07005364 /* dev */ 0, __LINE__, SHADER_CHECKER_NON_SPIRV_SHADER, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005365 "Shader is not SPIR-V");
5366 }
5367
Mark Youngb20a6a82016-01-07 15:41:43 -07005368 if (VK_FALSE != skip_call)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005369 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005370
5371 VkResult res = my_data->device_dispatch_table->CreateShaderModule(device, pCreateInfo, pAllocator, pShaderModule);
5372
5373 if (res == VK_SUCCESS) {
5374 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005375 my_data->shaderModuleMap[*pShaderModule] = new shader_module(pCreateInfo);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005376 loader_platform_thread_unlock_mutex(&globalLock);
5377 }
5378 return res;
5379}
5380
Chia-I Wu9ab61502015-11-06 06:42:02 +08005381VK_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 -06005382{
Mark Youngb20a6a82016-01-07 15:41:43 -07005383 VkBool32 skip_call = VK_FALSE;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005384 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentineabc5e922015-10-12 11:30:14 -05005385 // Create DAG
Michael Lentine48930b82015-10-15 17:07:00 -05005386 std::vector<bool> has_self_dependency(pCreateInfo->subpassCount);
Michael Lentineabc5e922015-10-12 11:30:14 -05005387 std::vector<DAGNode> subpass_to_node(pCreateInfo->subpassCount);
Michael Lentine48930b82015-10-15 17:07:00 -05005388 skip_call |= CreatePassDAG(dev_data, device, pCreateInfo, subpass_to_node, has_self_dependency);
Michael Lentineabc5e922015-10-12 11:30:14 -05005389 // Validate using DAG
5390 skip_call |= ValidateDependencies(dev_data, device, pCreateInfo, subpass_to_node);
5391 skip_call |= ValidateLayouts(dev_data, device, pCreateInfo);
Mark Youngb20a6a82016-01-07 15:41:43 -07005392 if (VK_FALSE != skip_call) {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005393 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentineb6986752015-10-06 14:56:18 -07005394 }
Chia-I Wuf7458c52015-10-26 21:10:41 +08005395 VkResult result = dev_data->device_dispatch_table->CreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005396 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005397 // TODOSC : Merge in tracking of renderpass from ShaderChecker
Tobin Ehliseba312c2015-04-01 08:40:34 -06005398 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06005399 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +08005400 if (pCreateInfo->pAttachments) {
5401 localRPCI->pAttachments = new VkAttachmentDescription[localRPCI->attachmentCount];
5402 memcpy((void*)localRPCI->pAttachments, pCreateInfo->pAttachments, localRPCI->attachmentCount*sizeof(VkAttachmentDescription));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005403 }
Chia-I Wu08accc62015-07-07 11:50:03 +08005404 if (pCreateInfo->pSubpasses) {
5405 localRPCI->pSubpasses = new VkSubpassDescription[localRPCI->subpassCount];
5406 memcpy((void*)localRPCI->pSubpasses, pCreateInfo->pSubpasses, localRPCI->subpassCount*sizeof(VkSubpassDescription));
5407
5408 for (uint32_t i = 0; i < localRPCI->subpassCount; i++) {
5409 VkSubpassDescription *subpass = (VkSubpassDescription *) &localRPCI->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005410 const uint32_t attachmentCount = subpass->inputAttachmentCount +
5411 subpass->colorAttachmentCount * (1 + (subpass->pResolveAttachments?1:0)) +
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005412 ((subpass->pDepthStencilAttachment) ? 1 : 0) + subpass->preserveAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005413 VkAttachmentReference *attachments = new VkAttachmentReference[attachmentCount];
5414
Cody Northropa505dda2015-08-04 11:16:41 -06005415 memcpy(attachments, subpass->pInputAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005416 sizeof(attachments[0]) * subpass->inputAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005417 subpass->pInputAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005418 attachments += subpass->inputAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005419
Cody Northropa505dda2015-08-04 11:16:41 -06005420 memcpy(attachments, subpass->pColorAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005421 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005422 subpass->pColorAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005423 attachments += subpass->colorAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005424
Cody Northropa505dda2015-08-04 11:16:41 -06005425 if (subpass->pResolveAttachments) {
5426 memcpy(attachments, subpass->pResolveAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005427 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005428 subpass->pResolveAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005429 attachments += subpass->colorAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005430 }
5431
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005432 if (subpass->pDepthStencilAttachment) {
5433 memcpy(attachments, subpass->pDepthStencilAttachment,
5434 sizeof(attachments[0]) * 1);
5435 subpass->pDepthStencilAttachment = attachments;
5436 attachments += 1;
5437 }
5438
Cody Northropa505dda2015-08-04 11:16:41 -06005439 memcpy(attachments, subpass->pPreserveAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005440 sizeof(attachments[0]) * subpass->preserveAttachmentCount);
Jon Ashburnf19916e2016-01-11 13:12:43 -07005441 subpass->pPreserveAttachments = &attachments->attachment;
Chia-I Wu08accc62015-07-07 11:50:03 +08005442 }
Tobin Ehliseba312c2015-04-01 08:40:34 -06005443 }
Chia-I Wu08accc62015-07-07 11:50:03 +08005444 if (pCreateInfo->pDependencies) {
5445 localRPCI->pDependencies = new VkSubpassDependency[localRPCI->dependencyCount];
5446 memcpy((void*)localRPCI->pDependencies, pCreateInfo->pDependencies, localRPCI->dependencyCount*sizeof(VkSubpassDependency));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005447 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005448 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005449 dev_data->renderPassMap[*pRenderPass] = new RENDER_PASS_NODE(localRPCI);
Michael Lentine48930b82015-10-15 17:07:00 -05005450 dev_data->renderPassMap[*pRenderPass]->hasSelfDependency = has_self_dependency;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005451 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehliseba312c2015-04-01 08:40:34 -06005452 }
5453 return result;
5454}
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005455// Free the renderpass shadow
5456static void deleteRenderPasses(layer_data* my_data)
5457{
5458 if (my_data->renderPassMap.size() <= 0)
5459 return;
5460 for (auto ii=my_data->renderPassMap.begin(); ii!=my_data->renderPassMap.end(); ++ii) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005461 const VkRenderPassCreateInfo* pRenderPassInfo = (*ii).second->pCreateInfo;
Michael Lentine48930b82015-10-15 17:07:00 -05005462 if (pRenderPassInfo->pAttachments) {
5463 delete[] pRenderPassInfo->pAttachments;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005464 }
Michael Lentine48930b82015-10-15 17:07:00 -05005465 if (pRenderPassInfo->pSubpasses) {
5466 for (uint32_t i=0; i<pRenderPassInfo->subpassCount; ++i) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005467 // Attachements are all allocated in a block, so just need to
5468 // find the first non-null one to delete
Michael Lentine48930b82015-10-15 17:07:00 -05005469 if (pRenderPassInfo->pSubpasses[i].pInputAttachments) {
5470 delete[] pRenderPassInfo->pSubpasses[i].pInputAttachments;
5471 } else if (pRenderPassInfo->pSubpasses[i].pColorAttachments) {
5472 delete[] pRenderPassInfo->pSubpasses[i].pColorAttachments;
5473 } else if (pRenderPassInfo->pSubpasses[i].pResolveAttachments) {
5474 delete[] pRenderPassInfo->pSubpasses[i].pResolveAttachments;
5475 } else if (pRenderPassInfo->pSubpasses[i].pPreserveAttachments) {
5476 delete[] pRenderPassInfo->pSubpasses[i].pPreserveAttachments;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005477 }
5478 }
Michael Lentine48930b82015-10-15 17:07:00 -05005479 delete[] pRenderPassInfo->pSubpasses;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005480 }
Michael Lentine48930b82015-10-15 17:07:00 -05005481 if (pRenderPassInfo->pDependencies) {
5482 delete[] pRenderPassInfo->pDependencies;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005483 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005484 delete pRenderPassInfo;
Michael Lentine48930b82015-10-15 17:07:00 -05005485 delete (*ii).second;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005486 }
5487 my_data->renderPassMap.clear();
5488}
Michael Lentineabc5e922015-10-12 11:30:14 -05005489
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005490VkBool32 VerifyFramebufferAndRenderPassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005491 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05005492 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5493 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005494 const VkRenderPassCreateInfo* pRenderPassInfo = dev_data->renderPassMap[pRenderPassBegin->renderPass]->pCreateInfo;
Michael Lentineabc5e922015-10-12 11:30:14 -05005495 const VkFramebufferCreateInfo* pFramebufferInfo = dev_data->frameBufferMap[pRenderPassBegin->framebuffer];
5496 if (pRenderPassInfo->attachmentCount != pFramebufferInfo->attachmentCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005497 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 -05005498 "You cannot start a render pass using a framebuffer with a different number of attachments.");
5499 }
5500 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
5501 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
5502 const VkImage& image = dev_data->imageViewMap[image_view]->image;
5503 auto image_data = pCB->imageLayoutMap.find(image);
5504 if (image_data == pCB->imageLayoutMap.end()) {
5505 pCB->imageLayoutMap[image].initialLayout = pRenderPassInfo->pAttachments[i].initialLayout;
5506 pCB->imageLayoutMap[image].layout = pRenderPassInfo->pAttachments[i].initialLayout;
5507 } else if (pRenderPassInfo->pAttachments[i].initialLayout != image_data->second.layout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005508 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 -05005509 "You cannot start a render pass using attachment %i where the intial layout differs from the starting layout.", i);
5510 }
5511 }
5512 return skip_call;
5513}
5514
5515void TransitionSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, const int subpass_index) {
5516 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5517 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5518 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
5519 if (render_pass_data == dev_data->renderPassMap.end()) {
5520 return;
5521 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005522 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
Michael Lentineabc5e922015-10-12 11:30:14 -05005523 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
5524 if (framebuffer_data == dev_data->frameBufferMap.end()) {
5525 return;
5526 }
5527 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
5528 const VkSubpassDescription& subpass = pRenderPassInfo->pSubpasses[subpass_index];
5529 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
5530 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pInputAttachments[j].attachment];
5531 auto image_view_data = dev_data->imageViewMap.find(image_view);
5532 if (image_view_data != dev_data->imageViewMap.end()) {
5533 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5534 if (image_layout != pCB->imageLayoutMap.end()) {
5535 image_layout->second.layout = subpass.pInputAttachments[j].layout;
5536 }
5537 }
5538 }
5539 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
5540 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pColorAttachments[j].attachment];
5541 auto image_view_data = dev_data->imageViewMap.find(image_view);
5542 if (image_view_data != dev_data->imageViewMap.end()) {
5543 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5544 if (image_layout != pCB->imageLayoutMap.end()) {
5545 image_layout->second.layout = subpass.pColorAttachments[j].layout;
5546 }
5547 }
5548 }
Michael Lentine3dea6512015-10-28 15:55:18 -07005549 if ((subpass.pDepthStencilAttachment != NULL) &&
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005550 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
Michael Lentineabc5e922015-10-12 11:30:14 -05005551 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pDepthStencilAttachment->attachment];
5552 auto image_view_data = dev_data->imageViewMap.find(image_view);
5553 if (image_view_data != dev_data->imageViewMap.end()) {
5554 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5555 if (image_layout != pCB->imageLayoutMap.end()) {
5556 image_layout->second.layout = subpass.pDepthStencilAttachment->layout;
5557 }
5558 }
5559 }
5560}
5561
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005562VkBool32 validatePrimaryCommandBuffer(const layer_data* my_data, const GLOBAL_CB_NODE* pCB, const std::string& cmd_name) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005563 VkBool32 skip_call = VK_FALSE;
Michael Lentine3dea6512015-10-28 15:55:18 -07005564 if (pCB->createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005565 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 -07005566 "Cannot execute command %s on a secondary command buffer.", cmd_name.c_str());
5567 }
5568 return skip_call;
5569}
5570
Michael Lentineabc5e922015-10-12 11:30:14 -05005571void TransitionFinalSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
5572 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5573 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5574 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
5575 if (render_pass_data == dev_data->renderPassMap.end()) {
5576 return;
5577 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005578 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
Michael Lentineabc5e922015-10-12 11:30:14 -05005579 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
5580 if (framebuffer_data == dev_data->frameBufferMap.end()) {
5581 return;
5582 }
5583 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
5584 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
5585 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
5586 auto image_view_data = dev_data->imageViewMap.find(image_view);
5587 if (image_view_data != dev_data->imageViewMap.end()) {
5588 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5589 if (image_layout != pCB->imageLayoutMap.end()) {
5590 image_layout->second.layout = pRenderPassInfo->pAttachments[i].finalLayout;
5591 }
5592 }
5593 }
5594}
5595
Chia-I Wu9ab61502015-11-06 06:42:02 +08005596VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, VkSubpassContents contents)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005597{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005598 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005599 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5600 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005601 if (pCB) {
Tobin Ehlis259730a2015-06-23 16:13:03 -06005602 if (pRenderPassBegin && pRenderPassBegin->renderPass) {
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005603 skipCall |= VerifyFramebufferAndRenderPassLayouts(commandBuffer, pRenderPassBegin);
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005604 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBeginRenderPass");
Michael Lentine3dea6512015-10-28 15:55:18 -07005605 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdBeginRenderPass");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005606 skipCall |= addCmd(dev_data, pCB, CMD_BEGINRENDERPASS, "vkCmdBeginRenderPass()");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005607 pCB->activeRenderPass = pRenderPassBegin->renderPass;
Michael Lentineabc5e922015-10-12 11:30:14 -05005608 // This is a shallow copy as that is all that is needed for now
5609 pCB->activeRenderPassBeginInfo = *pRenderPassBegin;
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005610 pCB->activeSubpass = 0;
Michael Lentine2e068b22015-12-29 16:05:27 -06005611 pCB->activeSubpassContents = contents;
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005612 pCB->framebuffer = pRenderPassBegin->framebuffer;
Tobin Ehlis502480b2015-06-24 15:53:07 -06005613 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005614 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 -06005615 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tony Barbourbadda992015-04-06 11:09:26 -06005616 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005617 }
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005618 if (VK_FALSE == skipCall) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005619 dev_data->device_dispatch_table->CmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents);
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005620 // This is a shallow copy as that is all that is needed for now
5621 dev_data->renderPassBeginInfo = *pRenderPassBegin;
5622 dev_data->currentSubpass = 0;
5623 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005624}
5625
Chia-I Wu9ab61502015-11-06 06:42:02 +08005626VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents)
Chia-I Wu08accc62015-07-07 11:50:03 +08005627{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005628 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005629 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5630 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Michael Lentineabc5e922015-10-12 11:30:14 -05005631 TransitionSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo, ++dev_data->currentSubpass);
Chia-I Wu08accc62015-07-07 11:50:03 +08005632 if (pCB) {
Michael Lentine3dea6512015-10-28 15:55:18 -07005633 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdNextSubpass");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005634 skipCall |= addCmd(dev_data, pCB, CMD_NEXTSUBPASS, "vkCmdNextSubpass()");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005635 pCB->activeSubpass++;
Michael Lentine2e068b22015-12-29 16:05:27 -06005636 pCB->activeSubpassContents = contents;
Tony Barbourfc5bb6f2016-01-12 11:16:52 -07005637 TransitionSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo, pCB->activeSubpass);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005638 if (pCB->lastBoundPipeline) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005639 skipCall |= validatePipelineState(dev_data, pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Chia-I Wu08accc62015-07-07 11:50:03 +08005640 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005641 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdNextSubpass");
Chia-I Wu08accc62015-07-07 11:50:03 +08005642 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005643 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005644 dev_data->device_dispatch_table->CmdNextSubpass(commandBuffer, contents);
Chia-I Wu08accc62015-07-07 11:50:03 +08005645}
5646
Chia-I Wu9ab61502015-11-06 06:42:02 +08005647VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndRenderPass(VkCommandBuffer commandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005648{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005649 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005650 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5651 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Michael Lentineabc5e922015-10-12 11:30:14 -05005652 TransitionFinalSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005653 if (pCB) {
Michael Lentine3dea6512015-10-28 15:55:18 -07005654 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdEndRenderpass");
Michael Lentine3dea6512015-10-28 15:55:18 -07005655 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdEndRenderPass");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005656 skipCall |= addCmd(dev_data, pCB, CMD_ENDRENDERPASS, "vkCmdEndRenderPass()");
Michael Lentineabc5e922015-10-12 11:30:14 -05005657 TransitionFinalSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005658 pCB->activeRenderPass = 0;
5659 pCB->activeSubpass = 0;
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005660 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005661 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005662 dev_data->device_dispatch_table->CmdEndRenderPass(commandBuffer);
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005663}
5664
Chia-I Wu9ab61502015-11-06 06:42:02 +08005665VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount, const VkCommandBuffer* pCommandBuffers)
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005666{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005667 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005668 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5669 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005670 if (pCB) {
Tobin Ehlis651d9b02015-12-16 05:01:22 -07005671 // TODO : If secondary CB was not created w/ *_USAGE_SIMULTANEOUS_USE_BIT it cannot be used more than once in given primary CB
5672 // ALSO if secondary w/o this flag is set in primary, then primary must not be pending execution more than once at a time
5673 // 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 -06005674 GLOBAL_CB_NODE* pSubCB = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005675 for (uint32_t i=0; i<commandBuffersCount; i++) {
5676 pSubCB = getCBNode(dev_data, pCommandBuffers[i]);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06005677 if (!pSubCB) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005678 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 +08005679 "vkCmdExecuteCommands() called w/ invalid Cmd Buffer %p in element %u of pCommandBuffers array.", (void*)pCommandBuffers[i], i);
5680 } else if (VK_COMMAND_BUFFER_LEVEL_PRIMARY == pSubCB->createInfo.level) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005681 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 +08005682 "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 -07005683 } else if (pCB->activeRenderPass) { // Secondary CB w/i RenderPass must have *CONTINUE_BIT set
5684 if (!(pSubCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005685 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 -07005686 "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);
5687 }
5688 string errorString = "";
Jon Ashburnf19916e2016-01-11 13:12:43 -07005689 if (!verify_renderpass_compatibility(dev_data, pCB->activeRenderPass, pSubCB->beginInfo.pInheritanceInfo->renderPass, errorString)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005690 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 -07005691 "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 -07005692 (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 -07005693 }
5694 // If framebuffer for secondary CB is not NULL, then it must match FB from vkCmdBeginRenderPass()
5695 // 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 -07005696 if (pSubCB->beginInfo.pInheritanceInfo->framebuffer) {
5697 if (pSubCB->beginInfo.pInheritanceInfo->framebuffer != pCB->activeRenderPassBeginInfo.framebuffer) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005698 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 -07005699 "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 -07005700 (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 -07005701 }
5702 }
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06005703 }
5704 }
Michael Lentine3dea6512015-10-28 15:55:18 -07005705 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdExecuteComands");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005706 skipCall |= addCmd(dev_data, pCB, CMD_EXECUTECOMMANDS, "vkCmdExecuteComands()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005707 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005708 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005709 dev_data->device_dispatch_table->CmdExecuteCommands(commandBuffer, commandBuffersCount, pCommandBuffers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005710}
5711
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005712VkBool32 ValidateMapImageLayouts(VkDevice device, VkDeviceMemory mem) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005713 VkBool32 skip_call = VK_FALSE;
Michael Lentine7b236262015-10-23 12:41:44 -07005714 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5715 auto mem_data = dev_data->memImageMap.find(mem);
5716 if (mem_data != dev_data->memImageMap.end()) {
5717 auto image_data = dev_data->imageLayoutMap.find(mem_data->second);
5718 if (image_data != dev_data->imageLayoutMap.end()) {
5719 if (image_data->second->layout != VK_IMAGE_LAYOUT_PREINITIALIZED && image_data->second->layout != VK_IMAGE_LAYOUT_GENERAL) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005720 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 -07005721 "Cannot map an image with layout %d. Only GENERAL or PREINITIALIZED are supported.", image_data->second->layout);
5722 }
5723 }
5724 }
5725 return skip_call;
5726}
5727
Chia-I Wu9ab61502015-11-06 06:42:02 +08005728VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkMapMemory(
Michael Lentine7b236262015-10-23 12:41:44 -07005729 VkDevice device,
5730 VkDeviceMemory mem,
5731 VkDeviceSize offset,
5732 VkDeviceSize size,
5733 VkFlags flags,
5734 void **ppData)
5735{
5736 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005737
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005738 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005739#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
5740 skip_call = ValidateMapImageLayouts(device, mem);
5741#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5742
Michael Lentine7b236262015-10-23 12:41:44 -07005743 if (VK_FALSE == skip_call) {
5744 return dev_data->device_dispatch_table->MapMemory(device, mem, offset, size, flags, ppData);
5745 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005746 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine7b236262015-10-23 12:41:44 -07005747}
5748
Chia-I Wu9ab61502015-11-06 06:42:02 +08005749VKAPI_ATTR VkResult VKAPI_CALL vkBindImageMemory(
Michael Lentine7b236262015-10-23 12:41:44 -07005750 VkDevice device,
5751 VkImage image,
5752 VkDeviceMemory mem,
5753 VkDeviceSize memOffset)
5754{
5755 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5756 VkResult result = dev_data->device_dispatch_table->BindImageMemory(device, image, mem, memOffset);
5757 loader_platform_thread_lock_mutex(&globalLock);
5758 dev_data->memImageMap[mem] = image;
5759 loader_platform_thread_unlock_mutex(&globalLock);
5760 return result;
5761}
5762
Michael Lentineb887b0a2015-12-29 14:12:11 -06005763
5764VKAPI_ATTR VkResult VKAPI_CALL vkSetEvent(VkDevice device, VkEvent event) {
5765 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5766 dev_data->eventMap[event].needsSignaled = false;
5767 VkResult result = dev_data->device_dispatch_table->SetEvent(device, event);
5768 return result;
5769}
5770
Michael Lentine15a47882016-01-06 10:05:48 -06005771VKAPI_ATTR VkResult VKAPI_CALL vkQueueBindSparse(
5772 VkQueue queue,
5773 uint32_t bindInfoCount,
5774 const VkBindSparseInfo* pBindInfo,
5775 VkFence fence)
5776{
5777 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07005778 VkBool32 skip_call = VK_FALSE;
Michael Lentine15a47882016-01-06 10:05:48 -06005779
5780 for (uint32_t bindIdx=0; bindIdx < bindInfoCount; ++bindIdx) {
5781 const VkBindSparseInfo& bindInfo = pBindInfo[bindIdx];
5782 for (uint32_t i=0; i < bindInfo.waitSemaphoreCount; ++i) {
5783 if (dev_data->semaphoreSignaledMap[bindInfo.pWaitSemaphores[i]]) {
5784 dev_data->semaphoreSignaledMap[bindInfo.pWaitSemaphores[i]] = 0;
5785 } else {
5786 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",
5787 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
5788 reinterpret_cast<uint64_t>(queue), reinterpret_cast<uint64_t>(bindInfo.pWaitSemaphores[i]));
5789 }
5790 }
5791 for (uint32_t i=0; i < bindInfo.signalSemaphoreCount; ++i) {
5792 dev_data->semaphoreSignaledMap[bindInfo.pSignalSemaphores[i]] = 1;
5793 }
5794 }
5795
Mark Youngb20a6a82016-01-07 15:41:43 -07005796 if (VK_FALSE == skip_call)
Michael Lentine15a47882016-01-06 10:05:48 -06005797 return dev_data->device_dispatch_table->QueueBindSparse(queue, bindInfoCount, pBindInfo, fence);
Mark Youngb20a6a82016-01-07 15:41:43 -07005798 else
5799 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine15a47882016-01-06 10:05:48 -06005800}
5801
5802VKAPI_ATTR VkResult VKAPI_CALL vkCreateSemaphore(
5803 VkDevice device,
5804 const VkSemaphoreCreateInfo* pCreateInfo,
5805 const VkAllocationCallbacks* pAllocator,
5806 VkSemaphore* pSemaphore)
5807{
5808 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5809 VkResult result = dev_data->device_dispatch_table->CreateSemaphore(device, pCreateInfo, pAllocator, pSemaphore);
5810 if (result == VK_SUCCESS) {
5811 dev_data->semaphoreSignaledMap[*pSemaphore] = 0;
5812 }
Tobin Ehlis51b78af2016-01-06 10:27:47 -07005813 return result;
Michael Lentine15a47882016-01-06 10:05:48 -06005814}
5815
Chia-I Wu9ab61502015-11-06 06:42:02 +08005816VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(
Michael Lentineabc5e922015-10-12 11:30:14 -05005817 VkDevice device,
5818 const VkSwapchainCreateInfoKHR *pCreateInfo,
Ian Elliott05846062015-11-20 14:13:17 -07005819 const VkAllocationCallbacks *pAllocator,
Michael Lentineabc5e922015-10-12 11:30:14 -05005820 VkSwapchainKHR *pSwapchain)
5821{
5822 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott05846062015-11-20 14:13:17 -07005823 VkResult result = dev_data->device_dispatch_table->CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
Michael Lentineabc5e922015-10-12 11:30:14 -05005824
5825 if (VK_SUCCESS == result) {
5826 SWAPCHAIN_NODE *swapchain_data = new SWAPCHAIN_NODE;
5827 loader_platform_thread_lock_mutex(&globalLock);
5828 dev_data->device_extensions.swapchainMap[*pSwapchain] = swapchain_data;
5829 loader_platform_thread_unlock_mutex(&globalLock);
5830 }
5831
5832 return result;
5833}
5834
Ian Elliott05846062015-11-20 14:13:17 -07005835VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR(
Michael Lentineabc5e922015-10-12 11:30:14 -05005836 VkDevice device,
Ian Elliott05846062015-11-20 14:13:17 -07005837 VkSwapchainKHR swapchain,
5838 const VkAllocationCallbacks *pAllocator)
Michael Lentineabc5e922015-10-12 11:30:14 -05005839{
5840 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentineabc5e922015-10-12 11:30:14 -05005841
5842 loader_platform_thread_lock_mutex(&globalLock);
5843 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(swapchain);
5844 if (swapchain_data != dev_data->device_extensions.swapchainMap.end()) {
5845 if (swapchain_data->second->images.size() > 0) {
5846 for (auto swapchain_image : swapchain_data->second->images) {
5847 auto image_item = dev_data->imageLayoutMap.find(swapchain_image);
5848 if (image_item != dev_data->imageLayoutMap.end())
5849 dev_data->imageLayoutMap.erase(image_item);
5850 }
5851 }
5852 delete swapchain_data->second;
5853 dev_data->device_extensions.swapchainMap.erase(swapchain);
5854 }
5855 loader_platform_thread_unlock_mutex(&globalLock);
Ian Elliott05846062015-11-20 14:13:17 -07005856 return dev_data->device_dispatch_table->DestroySwapchainKHR(device, swapchain, pAllocator);
Michael Lentineabc5e922015-10-12 11:30:14 -05005857}
5858
Chia-I Wu9ab61502015-11-06 06:42:02 +08005859VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR(
Michael Lentineabc5e922015-10-12 11:30:14 -05005860 VkDevice device,
5861 VkSwapchainKHR swapchain,
5862 uint32_t* pCount,
5863 VkImage* pSwapchainImages)
5864{
5865 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5866 VkResult result = dev_data->device_dispatch_table->GetSwapchainImagesKHR(device, swapchain, pCount, pSwapchainImages);
5867
5868 if (result == VK_SUCCESS && pSwapchainImages != NULL) {
5869 // This should never happen and is checked by param checker.
5870 if (!pCount) return result;
5871 for (uint32_t i = 0; i < *pCount; ++i) {
5872 IMAGE_NODE* image_node = new IMAGE_NODE;
5873 image_node->layout = VK_IMAGE_LAYOUT_UNDEFINED;
5874 loader_platform_thread_lock_mutex(&globalLock);
5875 dev_data->device_extensions.swapchainMap[swapchain]->images.push_back(pSwapchainImages[i]);
5876 dev_data->imageLayoutMap[pSwapchainImages[i]] = image_node;
5877 loader_platform_thread_unlock_mutex(&globalLock);
5878 }
5879 }
5880 return result;
5881}
5882
Ian Elliott05846062015-11-20 14:13:17 -07005883VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo)
Michael Lentineabc5e922015-10-12 11:30:14 -05005884{
5885 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07005886 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05005887
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005888#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentineabc5e922015-10-12 11:30:14 -05005889 if (pPresentInfo) {
Michael Lentine15a47882016-01-06 10:05:48 -06005890 for (uint32_t i=0; i < pPresentInfo->waitSemaphoreCount; ++i) {
5891 if (dev_data->semaphoreSignaledMap[pPresentInfo->pWaitSemaphores[i]]) {
5892 dev_data->semaphoreSignaledMap[pPresentInfo->pWaitSemaphores[i]] = 0;
5893 } else {
5894 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",
5895 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
5896 reinterpret_cast<uint64_t>(queue), reinterpret_cast<uint64_t>(pPresentInfo->pWaitSemaphores[i]));
5897 }
5898 }
Michael Lentineabc5e922015-10-12 11:30:14 -05005899 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
Ian Elliott05846062015-11-20 14:13:17 -07005900 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(pPresentInfo->pSwapchains[i]);
5901 if (swapchain_data != dev_data->device_extensions.swapchainMap.end() && pPresentInfo->pImageIndices[i] < swapchain_data->second->images.size()) {
5902 VkImage image = swapchain_data->second->images[pPresentInfo->pImageIndices[i]];
Michael Lentineabc5e922015-10-12 11:30:14 -05005903 auto image_data = dev_data->imageLayoutMap.find(image);
5904 if (image_data != dev_data->imageLayoutMap.end()) {
Ian Elliott05846062015-11-20 14:13:17 -07005905 if (image_data->second->layout != VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005906 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 -05005907 "Images passed to present must be in layout PRESENT_SOURCE_KHR but is in %d", image_data->second->layout);
5908 }
5909 }
5910 }
5911 }
5912 }
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005913#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentineabc5e922015-10-12 11:30:14 -05005914
5915 if (VK_FALSE == skip_call)
5916 return dev_data->device_dispatch_table->QueuePresentKHR(queue, pPresentInfo);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005917 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentineabc5e922015-10-12 11:30:14 -05005918}
5919
Michael Lentine15a47882016-01-06 10:05:48 -06005920VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImageKHR(
5921 VkDevice device,
5922 VkSwapchainKHR swapchain,
5923 uint64_t timeout,
5924 VkSemaphore semaphore,
5925 VkFence fence,
5926 uint32_t* pImageIndex)
5927{
5928 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5929 VkResult result = dev_data->device_dispatch_table->AcquireNextImageKHR(device, swapchain, timeout, semaphore, fence, pImageIndex);
5930 dev_data->semaphoreSignaledMap[semaphore] = 1;
Tobin Ehlis51b78af2016-01-06 10:27:47 -07005931 return result;
Michael Lentine15a47882016-01-06 10:05:48 -06005932}
5933
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005934VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(
5935 VkInstance instance,
5936 const VkDebugReportCallbackCreateInfoEXT* pCreateInfo,
5937 const VkAllocationCallbacks* pAllocator,
5938 VkDebugReportCallbackEXT* pMsgCallback)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005939{
Tobin Ehlis0b632332015-10-07 09:38:40 -06005940 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07005941 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005942 VkResult res = pTable->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06005943 if (VK_SUCCESS == res) {
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07005944 res = layer_create_msg_callback(my_data->report_data, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06005945 }
5946 return res;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005947}
5948
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005949VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07005950 VkInstance instance,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005951 VkDebugReportCallbackEXT msgCallback,
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07005952 const VkAllocationCallbacks* pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005953{
Tobin Ehlis0b632332015-10-07 09:38:40 -06005954 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07005955 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005956 pTable->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07005957 layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005958}
5959
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005960VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDebugReportMessageEXT(
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07005961 VkInstance instance,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005962 VkDebugReportFlagsEXT flags,
5963 VkDebugReportObjectTypeEXT objType,
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07005964 uint64_t object,
5965 size_t location,
5966 int32_t msgCode,
5967 const char* pLayerPrefix,
5968 const char* pMsg)
5969{
5970 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005971 my_data->instance_dispatch_table->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg);
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07005972}
5973
Chia-I Wu9ab61502015-11-06 06:42:02 +08005974VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerBegin(VkCommandBuffer commandBuffer, const char* pMarker)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005975{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005976 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005977 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5978 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis0b632332015-10-07 09:38:40 -06005979 if (!dev_data->device_extensions.debug_marker_enabled) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005980 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 -06005981 "Attempt to use CmdDbgMarkerBegin but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06005982 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06005983 } else if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005984 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKERBEGIN, "vkCmdDbgMarkerBegin()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005985 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005986 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005987 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerBegin(commandBuffer, pMarker);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005988}
5989
Chia-I Wu9ab61502015-11-06 06:42:02 +08005990VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerEnd(VkCommandBuffer commandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005991{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005992 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005993 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5994 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis0b632332015-10-07 09:38:40 -06005995 if (!dev_data->device_extensions.debug_marker_enabled) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005996 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 -06005997 "Attempt to use CmdDbgMarkerEnd but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06005998 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06005999 } else if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07006000 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKEREND, "vkCmdDbgMarkerEnd()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006001 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006002 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006003 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerEnd(commandBuffer);
Jon Ashburneab34492015-06-01 09:37:38 -06006004}
6005
Chia-I Wu9ab61502015-11-06 06:42:02 +08006006VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006007{
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06006008 if (dev == NULL)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006009 return NULL;
Jon Ashburn3950e1b2015-05-20 09:00:28 -06006010
Tobin Ehlis0b632332015-10-07 09:38:40 -06006011 layer_data *dev_data;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006012 /* loader uses this to force layer initialization; device object is wrapped */
6013 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
Tobin Ehlis0b632332015-10-07 09:38:40 -06006014 VkBaseLayerObject* wrapped_dev = (VkBaseLayerObject*) dev;
6015 dev_data = get_my_data_ptr(get_dispatch_key(wrapped_dev->baseObject), layer_data_map);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06006016 dev_data->device_dispatch_table = new VkLayerDispatchTable;
6017 layer_initialize_dispatch_table(dev_data->device_dispatch_table, wrapped_dev);
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006018 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006019 }
Tobin Ehlis0b632332015-10-07 09:38:40 -06006020 dev_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map);
Courtney Goeltzenleuchterca173b82015-06-25 18:01:43 -06006021 if (!strcmp(funcName, "vkCreateDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006022 return (PFN_vkVoidFunction) vkCreateDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006023 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006024 return (PFN_vkVoidFunction) vkDestroyDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006025 if (!strcmp(funcName, "vkQueueSubmit"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006026 return (PFN_vkVoidFunction) vkQueueSubmit;
Michael Lentine700b0aa2015-10-30 17:57:32 -07006027 if (!strcmp(funcName, "vkWaitForFences"))
6028 return (PFN_vkVoidFunction) vkWaitForFences;
6029 if (!strcmp(funcName, "vkGetFenceStatus"))
6030 return (PFN_vkVoidFunction) vkGetFenceStatus;
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07006031 if (!strcmp(funcName, "vkQueueWaitIdle"))
6032 return (PFN_vkVoidFunction) vkQueueWaitIdle;
6033 if (!strcmp(funcName, "vkDeviceWaitIdle"))
6034 return (PFN_vkVoidFunction) vkDeviceWaitIdle;
Michael Lentine700b0aa2015-10-30 17:57:32 -07006035 if (!strcmp(funcName, "vkGetDeviceQueue"))
6036 return (PFN_vkVoidFunction) vkGetDeviceQueue;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006037 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006038 return (PFN_vkVoidFunction) vkDestroyInstance;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006039 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006040 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006041 if (!strcmp(funcName, "vkDestroyFence"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006042 return (PFN_vkVoidFunction) vkDestroyFence;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006043 if (!strcmp(funcName, "vkDestroySemaphore"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006044 return (PFN_vkVoidFunction) vkDestroySemaphore;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006045 if (!strcmp(funcName, "vkDestroyEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006046 return (PFN_vkVoidFunction) vkDestroyEvent;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006047 if (!strcmp(funcName, "vkDestroyQueryPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006048 return (PFN_vkVoidFunction) vkDestroyQueryPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006049 if (!strcmp(funcName, "vkDestroyBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006050 return (PFN_vkVoidFunction) vkDestroyBuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006051 if (!strcmp(funcName, "vkDestroyBufferView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006052 return (PFN_vkVoidFunction) vkDestroyBufferView;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006053 if (!strcmp(funcName, "vkDestroyImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006054 return (PFN_vkVoidFunction) vkDestroyImage;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006055 if (!strcmp(funcName, "vkDestroyImageView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006056 return (PFN_vkVoidFunction) vkDestroyImageView;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006057 if (!strcmp(funcName, "vkDestroyShaderModule"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006058 return (PFN_vkVoidFunction) vkDestroyShaderModule;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006059 if (!strcmp(funcName, "vkDestroyPipeline"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006060 return (PFN_vkVoidFunction) vkDestroyPipeline;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006061 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006062 return (PFN_vkVoidFunction) vkDestroyPipelineLayout;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006063 if (!strcmp(funcName, "vkDestroySampler"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006064 return (PFN_vkVoidFunction) vkDestroySampler;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006065 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006066 return (PFN_vkVoidFunction) vkDestroyDescriptorSetLayout;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006067 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006068 return (PFN_vkVoidFunction) vkDestroyDescriptorPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006069 if (!strcmp(funcName, "vkDestroyFramebuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006070 return (PFN_vkVoidFunction) vkDestroyFramebuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006071 if (!strcmp(funcName, "vkDestroyRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006072 return (PFN_vkVoidFunction) vkDestroyRenderPass;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006073 if (!strcmp(funcName, "vkCreateBuffer"))
6074 return (PFN_vkVoidFunction) vkCreateBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006075 if (!strcmp(funcName, "vkCreateBufferView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006076 return (PFN_vkVoidFunction) vkCreateBufferView;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006077 if (!strcmp(funcName, "vkCreateImage"))
6078 return (PFN_vkVoidFunction) vkCreateImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006079 if (!strcmp(funcName, "vkCreateImageView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006080 return (PFN_vkVoidFunction) vkCreateImageView;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006081 if (!strcmp(funcName, "CreatePipelineCache"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006082 return (PFN_vkVoidFunction) vkCreatePipelineCache;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006083 if (!strcmp(funcName, "DestroyPipelineCache"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006084 return (PFN_vkVoidFunction) vkDestroyPipelineCache;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006085 if (!strcmp(funcName, "GetPipelineCacheData"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006086 return (PFN_vkVoidFunction) vkGetPipelineCacheData;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006087 if (!strcmp(funcName, "MergePipelineCaches"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006088 return (PFN_vkVoidFunction) vkMergePipelineCaches;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006089 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006090 return (PFN_vkVoidFunction) vkCreateGraphicsPipelines;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07006091 if (!strcmp(funcName, "vkCreateComputePipelines"))
6092 return (PFN_vkVoidFunction) vkCreateComputePipelines;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006093 if (!strcmp(funcName, "vkCreateSampler"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006094 return (PFN_vkVoidFunction) vkCreateSampler;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006095 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006096 return (PFN_vkVoidFunction) vkCreateDescriptorSetLayout;
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05006097 if (!strcmp(funcName, "vkCreatePipelineLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006098 return (PFN_vkVoidFunction) vkCreatePipelineLayout;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006099 if (!strcmp(funcName, "vkCreateDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006100 return (PFN_vkVoidFunction) vkCreateDescriptorPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006101 if (!strcmp(funcName, "vkResetDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006102 return (PFN_vkVoidFunction) vkResetDescriptorPool;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006103 if (!strcmp(funcName, "vkAllocateDescriptorSets"))
6104 return (PFN_vkVoidFunction) vkAllocateDescriptorSets;
Tobin Ehlise735c692015-10-08 13:13:50 -06006105 if (!strcmp(funcName, "vkFreeDescriptorSets"))
6106 return (PFN_vkVoidFunction) vkFreeDescriptorSets;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08006107 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006108 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
Mark Lobodzinski39298632015-11-18 08:38:27 -07006109 if (!strcmp(funcName, "vkCreateCommandPool"))
6110 return (PFN_vkVoidFunction) vkCreateCommandPool;
6111 if (!strcmp(funcName, "vkDestroyCommandPool"))
6112 return (PFN_vkVoidFunction) vkDestroyCommandPool;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006113 if (!strcmp(funcName, "vkResetCommandPool"))
6114 return (PFN_vkVoidFunction) vkResetCommandPool;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006115 if (!strcmp(funcName, "vkAllocateCommandBuffers"))
6116 return (PFN_vkVoidFunction) vkAllocateCommandBuffers;
Mark Lobodzinski39298632015-11-18 08:38:27 -07006117 if (!strcmp(funcName, "vkFreeCommandBuffers"))
6118 return (PFN_vkVoidFunction) vkFreeCommandBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006119 if (!strcmp(funcName, "vkBeginCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006120 return (PFN_vkVoidFunction) vkBeginCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006121 if (!strcmp(funcName, "vkEndCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006122 return (PFN_vkVoidFunction) vkEndCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006123 if (!strcmp(funcName, "vkResetCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006124 return (PFN_vkVoidFunction) vkResetCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006125 if (!strcmp(funcName, "vkCmdBindPipeline"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006126 return (PFN_vkVoidFunction) vkCmdBindPipeline;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06006127 if (!strcmp(funcName, "vkCmdSetViewport"))
6128 return (PFN_vkVoidFunction) vkCmdSetViewport;
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06006129 if (!strcmp(funcName, "vkCmdSetScissor"))
6130 return (PFN_vkVoidFunction) vkCmdSetScissor;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06006131 if (!strcmp(funcName, "vkCmdSetLineWidth"))
6132 return (PFN_vkVoidFunction) vkCmdSetLineWidth;
6133 if (!strcmp(funcName, "vkCmdSetDepthBias"))
6134 return (PFN_vkVoidFunction) vkCmdSetDepthBias;
6135 if (!strcmp(funcName, "vkCmdSetBlendConstants"))
6136 return (PFN_vkVoidFunction) vkCmdSetBlendConstants;
6137 if (!strcmp(funcName, "vkCmdSetDepthBounds"))
6138 return (PFN_vkVoidFunction) vkCmdSetDepthBounds;
6139 if (!strcmp(funcName, "vkCmdSetStencilCompareMask"))
6140 return (PFN_vkVoidFunction) vkCmdSetStencilCompareMask;
6141 if (!strcmp(funcName, "vkCmdSetStencilWriteMask"))
6142 return (PFN_vkVoidFunction) vkCmdSetStencilWriteMask;
6143 if (!strcmp(funcName, "vkCmdSetStencilReference"))
6144 return (PFN_vkVoidFunction) vkCmdSetStencilReference;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006145 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006146 return (PFN_vkVoidFunction) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06006147 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006148 return (PFN_vkVoidFunction) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006149 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006150 return (PFN_vkVoidFunction) vkCmdBindIndexBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006151 if (!strcmp(funcName, "vkCmdDraw"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006152 return (PFN_vkVoidFunction) vkCmdDraw;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006153 if (!strcmp(funcName, "vkCmdDrawIndexed"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006154 return (PFN_vkVoidFunction) vkCmdDrawIndexed;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006155 if (!strcmp(funcName, "vkCmdDrawIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006156 return (PFN_vkVoidFunction) vkCmdDrawIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006157 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006158 return (PFN_vkVoidFunction) vkCmdDrawIndexedIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006159 if (!strcmp(funcName, "vkCmdDispatch"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006160 return (PFN_vkVoidFunction) vkCmdDispatch;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006161 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006162 return (PFN_vkVoidFunction) vkCmdDispatchIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006163 if (!strcmp(funcName, "vkCmdCopyBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006164 return (PFN_vkVoidFunction) vkCmdCopyBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006165 if (!strcmp(funcName, "vkCmdCopyImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006166 return (PFN_vkVoidFunction) vkCmdCopyImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006167 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006168 return (PFN_vkVoidFunction) vkCmdCopyBufferToImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006169 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006170 return (PFN_vkVoidFunction) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006171 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006172 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006173 if (!strcmp(funcName, "vkCmdFillBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006174 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006175 if (!strcmp(funcName, "vkCmdClearColorImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006176 return (PFN_vkVoidFunction) vkCmdClearColorImage;
Chris Forbesd9be82b2015-06-22 17:21:59 +12006177 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006178 return (PFN_vkVoidFunction) vkCmdClearDepthStencilImage;
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06006179 if (!strcmp(funcName, "vkCmdClearAttachments"))
6180 return (PFN_vkVoidFunction) vkCmdClearAttachments;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006181 if (!strcmp(funcName, "vkCmdResolveImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006182 return (PFN_vkVoidFunction) vkCmdResolveImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006183 if (!strcmp(funcName, "vkCmdSetEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006184 return (PFN_vkVoidFunction) vkCmdSetEvent;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006185 if (!strcmp(funcName, "vkCmdResetEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006186 return (PFN_vkVoidFunction) vkCmdResetEvent;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006187 if (!strcmp(funcName, "vkCmdWaitEvents"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006188 return (PFN_vkVoidFunction) vkCmdWaitEvents;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006189 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006190 return (PFN_vkVoidFunction) vkCmdPipelineBarrier;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006191 if (!strcmp(funcName, "vkCmdBeginQuery"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006192 return (PFN_vkVoidFunction) vkCmdBeginQuery;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006193 if (!strcmp(funcName, "vkCmdEndQuery"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006194 return (PFN_vkVoidFunction) vkCmdEndQuery;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006195 if (!strcmp(funcName, "vkCmdResetQueryPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006196 return (PFN_vkVoidFunction) vkCmdResetQueryPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006197 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006198 return (PFN_vkVoidFunction) vkCmdWriteTimestamp;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006199 if (!strcmp(funcName, "vkCreateFramebuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006200 return (PFN_vkVoidFunction) vkCreateFramebuffer;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006201 if (!strcmp(funcName, "vkCreateShaderModule"))
6202 return (PFN_vkVoidFunction) vkCreateShaderModule;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006203 if (!strcmp(funcName, "vkCreateRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006204 return (PFN_vkVoidFunction) vkCreateRenderPass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006205 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006206 return (PFN_vkVoidFunction) vkCmdBeginRenderPass;
Chia-I Wu08accc62015-07-07 11:50:03 +08006207 if (!strcmp(funcName, "vkCmdNextSubpass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006208 return (PFN_vkVoidFunction) vkCmdNextSubpass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006209 if (!strcmp(funcName, "vkCmdEndRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006210 return (PFN_vkVoidFunction) vkCmdEndRenderPass;
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06006211 if (!strcmp(funcName, "vkCmdExecuteCommands"))
6212 return (PFN_vkVoidFunction) vkCmdExecuteCommands;
Michael Lentineb887b0a2015-12-29 14:12:11 -06006213 if (!strcmp(funcName, "vkSetEvent"))
6214 return (PFN_vkVoidFunction) vkSetEvent;
Michael Lentine7b236262015-10-23 12:41:44 -07006215 if (!strcmp(funcName, "vkMapMemory"))
6216 return (PFN_vkVoidFunction) vkMapMemory;
Michael Lentineb887b0a2015-12-29 14:12:11 -06006217 if (!strcmp(funcName, "vkGetQueryPoolResults"))
6218 return (PFN_vkVoidFunction) vkGetQueryPoolResults;
Michael Lentine15a47882016-01-06 10:05:48 -06006219 if (!strcmp(funcName, "vkBindImageMemory"))
6220 return (PFN_vkVoidFunction) vkBindImageMemory;
6221 if (!strcmp(funcName, "vkQueueBindSparse"))
6222 return (PFN_vkVoidFunction) vkQueueBindSparse;
6223 if (!strcmp(funcName, "vkCreateSemaphore"))
6224 return (PFN_vkVoidFunction) vkCreateSemaphore;
Jon Ashburneab34492015-06-01 09:37:38 -06006225
Michael Lentineabc5e922015-10-12 11:30:14 -05006226 if (dev_data->device_extensions.wsi_enabled)
6227 {
6228 if (!strcmp(funcName, "vkCreateSwapchainKHR"))
6229 return (PFN_vkVoidFunction) vkCreateSwapchainKHR;
6230 if (!strcmp(funcName, "vkDestroySwapchainKHR"))
6231 return (PFN_vkVoidFunction) vkDestroySwapchainKHR;
6232 if (!strcmp(funcName, "vkGetSwapchainImagesKHR"))
6233 return (PFN_vkVoidFunction) vkGetSwapchainImagesKHR;
Michael Lentine15a47882016-01-06 10:05:48 -06006234 if (!strcmp(funcName, "vkAcquireNextImageKHR"))
6235 return (PFN_vkVoidFunction) vkAcquireNextImageKHR;
Michael Lentineabc5e922015-10-12 11:30:14 -05006236 if (!strcmp(funcName, "vkQueuePresentKHR"))
6237 return (PFN_vkVoidFunction) vkQueuePresentKHR;
6238 }
6239
Tobin Ehlis0b632332015-10-07 09:38:40 -06006240 VkLayerDispatchTable* pTable = dev_data->device_dispatch_table;
6241 if (dev_data->device_extensions.debug_marker_enabled)
Jon Ashburn8fd08252015-05-28 16:25:02 -06006242 {
Jon Ashburn747f2b62015-06-18 15:02:58 -06006243 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006244 return (PFN_vkVoidFunction) vkCmdDbgMarkerBegin;
Jon Ashburn747f2b62015-06-18 15:02:58 -06006245 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006246 return (PFN_vkVoidFunction) vkCmdDbgMarkerEnd;
Jon Ashburneab34492015-06-01 09:37:38 -06006247 }
6248 {
Jon Ashburn8fd08252015-05-28 16:25:02 -06006249 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006250 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006251 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburnf6b33db2015-05-05 14:22:52 -06006252 }
6253}
6254
Chia-I Wu9ab61502015-11-06 06:42:02 +08006255VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Jon Ashburnf6b33db2015-05-05 14:22:52 -06006256{
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006257 PFN_vkVoidFunction fptr;
Jon Ashburnf6b33db2015-05-05 14:22:52 -06006258 if (instance == NULL)
6259 return NULL;
6260
Tobin Ehlis0b632332015-10-07 09:38:40 -06006261 layer_data* my_data;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006262 /* loader uses this to force layer initialization; instance object is wrapped */
6263 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
Tobin Ehlis0b632332015-10-07 09:38:40 -06006264 VkBaseLayerObject* wrapped_inst = (VkBaseLayerObject*) instance;
6265 my_data = get_my_data_ptr(get_dispatch_key(wrapped_inst->baseObject), layer_data_map);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06006266 my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
6267 layer_init_instance_dispatch_table(my_data->instance_dispatch_table, wrapped_inst);
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006268 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006269 }
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06006270 if (!strcmp(funcName, "vkCreateInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006271 return (PFN_vkVoidFunction) vkCreateInstance;
Jon Ashburn3950e1b2015-05-20 09:00:28 -06006272 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006273 return (PFN_vkVoidFunction) vkDestroyInstance;
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -06006274 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
6275 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
6276 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
6277 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
6278 if (!strcmp(funcName, "vkEnumerateDeviceLayerProperties"))
6279 return (PFN_vkVoidFunction) vkEnumerateDeviceLayerProperties;
6280 if (!strcmp(funcName, "vkEnumerateDeviceExtensionProperties"))
6281 return (PFN_vkVoidFunction) vkEnumerateDeviceExtensionProperties;
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06006282
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006283 my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06006284 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06006285 if (fptr)
6286 return fptr;
6287
Jon Ashburn8fd08252015-05-28 16:25:02 -06006288 {
Tobin Ehlis0b632332015-10-07 09:38:40 -06006289 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006290 if (pTable->GetInstanceProcAddr == NULL)
Jon Ashburnf6b33db2015-05-05 14:22:52 -06006291 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006292 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006293 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006294}