blob: b18e772a48b92fbfd5cdcd62e03d5645eff0801a [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;
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07001245 VkBool32 pass = 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)) {
1255 pass = false;
1256 }
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)) {
1284 pass = false;
1285 }
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 Ehlisf6585052015-12-17 11:48:42 -07001408 } else { // Valid set is bound and layout compatible, validate any dynamic offsets
1409 // Pull the set node, and for each dynamic descriptor, make sure dynamic offset doesn't overstep buffer
1410 SET_NODE* pSet = getSetNode(my_data, pCB->boundDescriptorSets[setIndex]);
1411 result |= validate_dynamic_offsets(my_data, pSet);
Mark Lobodzinski74635932015-12-18 15:35:38 -07001412 }
Tobin Ehlis88452832015-12-03 09:40:56 -07001413 }
1414 }
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07001415
Mark Lobodzinski74635932015-12-18 15:35:38 -07001416 // Verify Vtx binding
1417 if (pPipe->vtxBindingCount > 0) {
1418 VkPipelineVertexInputStateCreateInfo *vtxInCI = &pPipe->vertexInputCI;
1419 for (uint32_t i = 0; i < vtxInCI->vertexBindingDescriptionCount; i++) {
Michael Lentine700b0aa2015-10-30 17:57:32 -07001420 if ((pCB->currentDrawData.buffers.size() < (i+1)) || (pCB->currentDrawData.buffers[i] == VK_NULL_HANDLE)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001421 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 -07001422 "The Pipeline State Object (%#" PRIxLEAST64 ") expects that this Command Buffer's vertex binding Index %d should be set via vkCmdBindVertexBuffers.",
1423 (uint64_t)pCB->lastBoundPipeline, i);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001424
Mark Lobodzinski74635932015-12-18 15:35:38 -07001425 }
1426 }
1427 } else {
Michael Lentine700b0aa2015-10-30 17:57:32 -07001428 if (!pCB->currentDrawData.buffers.empty()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001429 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 -07001430 "DS", "Vertex buffers are bound to command buffer (%#" PRIxLEAST64 ") but no vertex buffers are attached to this Pipeline State Object (%#" PRIxLEAST64 ").",
1431 (uint64_t)pCB->commandBuffer, (uint64_t)pCB->lastBoundPipeline);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06001432 }
1433 }
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07001434
Mark Lobodzinski74635932015-12-18 15:35:38 -07001435 // If Viewport or scissors are dynamic, verify that dynamic count matches PSO count
1436 VkBool32 dynViewport = isDynamic(pPipe, VK_DYNAMIC_STATE_VIEWPORT);
1437 VkBool32 dynScissor = isDynamic(pPipe, VK_DYNAMIC_STATE_SCISSOR);
1438 if (dynViewport) {
1439 if (pCB->viewports.size() != pPipe->graphicsPipelineCI.pViewportState->viewportCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001440 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 -07001441 "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);
1442 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001443 }
Mark Lobodzinski74635932015-12-18 15:35:38 -07001444 if (dynScissor) {
1445 if (pCB->scissors.size() != pPipe->graphicsPipelineCI.pViewportState->scissorCount) {
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 scissorCount from vkCmdSetScissor() is " PRINTF_SIZE_T_SPECIFIER ", but PSO scissorCount is %u. These counts must match.", pCB->scissors.size(), pPipe->graphicsPipelineCI.pViewportState->scissorCount);
1448 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001449 }
1450 }
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001451 return result;
1452}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001453
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001454// Verify that create state for a pipeline is valid
Tobin Ehlis88452832015-12-03 09:40:56 -07001455static VkBool32 verifyPipelineCreateState(layer_data* my_data, const VkDevice device, PIPELINE_NODE* pPipeline)
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001456{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001457 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski2fd2d032015-12-16 14:25:22 -07001458
Tobin Ehlis88452832015-12-03 09:40:56 -07001459 if (!validate_pipeline_shaders(my_data, device, pPipeline)) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001460 skipCall = VK_TRUE;
1461 }
Mark Lobodzinski2fd2d032015-12-16 14:25:22 -07001462
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001463 // VS is required
1464 if (!(pPipeline->active_shaders & VK_SHADER_STAGE_VERTEX_BIT)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001465 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 -06001466 "Invalid Pipeline CreateInfo State: Vtx Shader required");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001467 }
1468 // Either both or neither TC/TE shaders should be defined
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001469 if (((pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) == 0) !=
1470 ((pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) == 0) ) {
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: TE and TC shaders must be included or excluded as a pair");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001473 }
1474 // Compute shaders should be specified independent of Gfx shaders
1475 if ((pPipeline->active_shaders & VK_SHADER_STAGE_COMPUTE_BIT) &&
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001476 (pPipeline->active_shaders & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT |
1477 VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT | VK_SHADER_STAGE_GEOMETRY_BIT |
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001478 VK_SHADER_STAGE_FRAGMENT_BIT))) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001479 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 -06001480 "Invalid Pipeline CreateInfo State: Do not specify Compute Shader for Gfx Pipeline");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001481 }
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001482 // VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology is only valid for tessellation pipelines.
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001483 // Mismatching primitive topology and tessellation fails graphics pipeline creation.
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001484 if (pPipeline->active_shaders & (VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) &&
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001485 (pPipeline->iaStateCI.topology != VK_PRIMITIVE_TOPOLOGY_PATCH_LIST)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001486 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 +08001487 "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 -06001488 }
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001489 if (pPipeline->iaStateCI.topology == VK_PRIMITIVE_TOPOLOGY_PATCH_LIST) {
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001490 if (~pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001491 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001492 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology is only valid for tessellation pipelines");
Tobin Ehlis912df022015-09-17 08:46:18 -06001493 }
1494 if (!pPipeline->tessStateCI.patchControlPoints || (pPipeline->tessStateCI.patchControlPoints > 32)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001495 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 +08001496 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology used with patchControlPoints value %u."
Tobin Ehlis912df022015-09-17 08:46:18 -06001497 " patchControlPoints should be >0 and <=32.", pPipeline->tessStateCI.patchControlPoints);
1498 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001499 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001500 // Viewport state must be included and viewport and scissor counts should always match
Tobin Ehlise68360f2015-10-01 11:15:13 -06001501 // NOTE : Even if these are flagged as dynamic, counts need to be set correctly for shader compiler
Tobin Ehlisd332f282015-10-02 11:00:56 -06001502 if (!pPipeline->graphicsPipelineCI.pViewportState) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001503 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 -06001504 "Gfx Pipeline pViewportState is null. Even if viewport and scissors are dynamic PSO must include viewportCount and scissorCount in pViewportState.");
1505 } else if (pPipeline->graphicsPipelineCI.pViewportState->scissorCount != pPipeline->graphicsPipelineCI.pViewportState->viewportCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001506 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 -06001507 "Gfx Pipeline viewport count (%u) must match scissor count (%u).", pPipeline->vpStateCI.viewportCount, pPipeline->vpStateCI.scissorCount);
Tobin Ehlisd332f282015-10-02 11:00:56 -06001508 } else {
1509 // If viewport or scissor are not dynamic, then verify that data is appropriate for count
1510 VkBool32 dynViewport = isDynamic(pPipeline, VK_DYNAMIC_STATE_VIEWPORT);
1511 VkBool32 dynScissor = isDynamic(pPipeline, VK_DYNAMIC_STATE_SCISSOR);
1512 if (!dynViewport) {
1513 if (pPipeline->graphicsPipelineCI.pViewportState->viewportCount && !pPipeline->graphicsPipelineCI.pViewportState->pViewports) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001514 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 -07001515 "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 -06001516 }
1517 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001518 if (!dynScissor) {
1519 if (pPipeline->graphicsPipelineCI.pViewportState->scissorCount && !pPipeline->graphicsPipelineCI.pViewportState->pScissors) {
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 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 -06001522 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06001523 }
1524 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001525 return skipCall;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001526}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001527
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001528// Init the pipeline mapping info based on pipeline create info LL tree
1529// Threading note : Calls to this function should wrapped in mutex
Tobin Ehlis88452832015-12-03 09:40:56 -07001530// TODO : this should really just be in the constructor for PIPELINE_NODE
Mark Lobodzinski475a2182015-11-10 15:25:01 -07001531static PIPELINE_NODE* initGraphicsPipeline(layer_data* dev_data, const VkGraphicsPipelineCreateInfo* pCreateInfo, PIPELINE_NODE* pBasePipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001532{
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001533 PIPELINE_NODE* pPipeline = new PIPELINE_NODE;
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001534
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001535 if (pBasePipeline) {
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001536 *pPipeline = *pBasePipeline;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001537 }
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001538
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001539 // First init create info
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001540 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001541
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001542 size_t bufferSize = 0;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001543 const VkPipelineVertexInputStateCreateInfo* pVICI = NULL;
Tobin Ehlis5a65cca2015-07-13 13:14:24 -06001544 const VkPipelineColorBlendStateCreateInfo* pCBCI = NULL;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001545
1546 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
1547 const VkPipelineShaderStageCreateInfo *pPSSCI = &pCreateInfo->pStages[i];
1548
Chia-I Wu28e06912015-10-31 00:31:16 +08001549 switch (pPSSCI->stage) {
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001550 case VK_SHADER_STAGE_VERTEX_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001551 memcpy(&pPipeline->vsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1552 pPipeline->active_shaders |= VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001553 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001554 case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001555 memcpy(&pPipeline->tcsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001556 pPipeline->active_shaders |= VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001557 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001558 case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001559 memcpy(&pPipeline->tesCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001560 pPipeline->active_shaders |= VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001561 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001562 case VK_SHADER_STAGE_GEOMETRY_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001563 memcpy(&pPipeline->gsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1564 pPipeline->active_shaders |= VK_SHADER_STAGE_GEOMETRY_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001565 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001566 case VK_SHADER_STAGE_FRAGMENT_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001567 memcpy(&pPipeline->fsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1568 pPipeline->active_shaders |= VK_SHADER_STAGE_FRAGMENT_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001569 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001570 case VK_SHADER_STAGE_COMPUTE_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001571 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
1572 pPipeline->active_shaders |= VK_SHADER_STAGE_COMPUTE_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001573 break;
1574 default:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001575 // TODO : Flag error
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001576 break;
1577 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001578 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001579 // Copy over GraphicsPipelineCreateInfo structure embedded pointers
1580 if (pCreateInfo->stageCount != 0) {
1581 pPipeline->graphicsPipelineCI.pStages = new VkPipelineShaderStageCreateInfo[pCreateInfo->stageCount];
1582 bufferSize = pCreateInfo->stageCount * sizeof(VkPipelineShaderStageCreateInfo);
1583 memcpy((void*)pPipeline->graphicsPipelineCI.pStages, pCreateInfo->pStages, bufferSize);
1584 }
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001585 if (pCreateInfo->pVertexInputState != NULL) {
1586 memcpy((void*)&pPipeline->vertexInputCI, pCreateInfo->pVertexInputState , sizeof(VkPipelineVertexInputStateCreateInfo));
1587 // Copy embedded ptrs
1588 pVICI = pCreateInfo->pVertexInputState;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001589 pPipeline->vtxBindingCount = pVICI->vertexBindingDescriptionCount;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001590 if (pPipeline->vtxBindingCount) {
1591 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
1592 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
1593 memcpy((void*)pPipeline->pVertexBindingDescriptions, pVICI->pVertexBindingDescriptions, bufferSize);
1594 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08001595 pPipeline->vtxAttributeCount = pVICI->vertexAttributeDescriptionCount;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001596 if (pPipeline->vtxAttributeCount) {
1597 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
1598 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
1599 memcpy((void*)pPipeline->pVertexAttributeDescriptions, pVICI->pVertexAttributeDescriptions, bufferSize);
1600 }
1601 pPipeline->graphicsPipelineCI.pVertexInputState = &pPipeline->vertexInputCI;
1602 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001603 if (pCreateInfo->pInputAssemblyState != NULL) {
1604 memcpy((void*)&pPipeline->iaStateCI, pCreateInfo->pInputAssemblyState, sizeof(VkPipelineInputAssemblyStateCreateInfo));
1605 pPipeline->graphicsPipelineCI.pInputAssemblyState = &pPipeline->iaStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001606 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001607 if (pCreateInfo->pTessellationState != NULL) {
1608 memcpy((void*)&pPipeline->tessStateCI, pCreateInfo->pTessellationState, sizeof(VkPipelineTessellationStateCreateInfo));
1609 pPipeline->graphicsPipelineCI.pTessellationState = &pPipeline->tessStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001610 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001611 if (pCreateInfo->pViewportState != NULL) {
1612 memcpy((void*)&pPipeline->vpStateCI, pCreateInfo->pViewportState, sizeof(VkPipelineViewportStateCreateInfo));
1613 pPipeline->graphicsPipelineCI.pViewportState = &pPipeline->vpStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001614 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001615 if (pCreateInfo->pRasterizationState != NULL) {
1616 memcpy((void*)&pPipeline->rsStateCI, pCreateInfo->pRasterizationState, sizeof(VkPipelineRasterizationStateCreateInfo));
1617 pPipeline->graphicsPipelineCI.pRasterizationState = &pPipeline->rsStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001618 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001619 if (pCreateInfo->pMultisampleState != NULL) {
1620 memcpy((void*)&pPipeline->msStateCI, pCreateInfo->pMultisampleState, sizeof(VkPipelineMultisampleStateCreateInfo));
1621 pPipeline->graphicsPipelineCI.pMultisampleState = &pPipeline->msStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001622 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001623 if (pCreateInfo->pDepthStencilState != NULL) {
1624 memcpy((void*)&pPipeline->dsStateCI, pCreateInfo->pDepthStencilState, sizeof(VkPipelineDepthStencilStateCreateInfo));
1625 pPipeline->graphicsPipelineCI.pDepthStencilState = &pPipeline->dsStateCI;
1626 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001627 if (pCreateInfo->pColorBlendState != NULL) {
1628 memcpy((void*)&pPipeline->cbStateCI, pCreateInfo->pColorBlendState, sizeof(VkPipelineColorBlendStateCreateInfo));
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001629 // Copy embedded ptrs
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001630 pCBCI = pCreateInfo->pColorBlendState;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001631 pPipeline->attachmentCount = pCBCI->attachmentCount;
1632 if (pPipeline->attachmentCount) {
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001633 pPipeline->pAttachments = new VkPipelineColorBlendAttachmentState[pPipeline->attachmentCount];
1634 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineColorBlendAttachmentState);
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001635 memcpy((void*)pPipeline->pAttachments, pCBCI->pAttachments, bufferSize);
1636 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001637 pPipeline->graphicsPipelineCI.pColorBlendState = &pPipeline->cbStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001638 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001639 if (pCreateInfo->pDynamicState != NULL) {
1640 memcpy((void*)&pPipeline->dynStateCI, pCreateInfo->pDynamicState, sizeof(VkPipelineDynamicStateCreateInfo));
1641 if (pPipeline->dynStateCI.dynamicStateCount) {
1642 pPipeline->dynStateCI.pDynamicStates = new VkDynamicState[pPipeline->dynStateCI.dynamicStateCount];
1643 bufferSize = pPipeline->dynStateCI.dynamicStateCount * sizeof(VkDynamicState);
1644 memcpy((void*)pPipeline->dynStateCI.pDynamicStates, pCreateInfo->pDynamicState->pDynamicStates, bufferSize);
1645 }
1646 pPipeline->graphicsPipelineCI.pDynamicState = &pPipeline->dynStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001647 }
Tobin Ehlis88452832015-12-03 09:40:56 -07001648 pPipeline->active_sets.clear();
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001649 return pPipeline;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001650}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001651
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001652// Free the Pipeline nodes
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001653static void deletePipelines(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001654{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001655 if (my_data->pipelineMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06001656 return;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001657 for (auto ii=my_data->pipelineMap.begin(); ii!=my_data->pipelineMap.end(); ++ii) {
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001658 if ((*ii).second->graphicsPipelineCI.stageCount != 0) {
1659 delete[] (*ii).second->graphicsPipelineCI.pStages;
1660 }
Tobin Ehlisf313c8b2015-04-01 11:59:08 -06001661 if ((*ii).second->pVertexBindingDescriptions) {
1662 delete[] (*ii).second->pVertexBindingDescriptions;
1663 }
1664 if ((*ii).second->pVertexAttributeDescriptions) {
1665 delete[] (*ii).second->pVertexAttributeDescriptions;
1666 }
1667 if ((*ii).second->pAttachments) {
1668 delete[] (*ii).second->pAttachments;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001669 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001670 if ((*ii).second->dynStateCI.dynamicStateCount != 0) {
1671 delete[] (*ii).second->dynStateCI.pDynamicStates;
1672 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001673 delete (*ii).second;
1674 }
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001675 my_data->pipelineMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001676}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001677
Tobin Ehliseba312c2015-04-01 08:40:34 -06001678// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Chia-I Wu5c17c962015-10-31 00:31:16 +08001679static VkSampleCountFlagBits getNumSamples(layer_data* my_data, const VkPipeline pipeline)
Tobin Ehliseba312c2015-04-01 08:40:34 -06001680{
Chia-I Wue2fc5522015-10-26 20:04:44 +08001681 PIPELINE_NODE* pPipe = my_data->pipelineMap[pipeline];
Tobin Ehlis577188e2015-07-13 14:51:15 -06001682 if (VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001683 return pPipe->msStateCI.rasterizationSamples;
Tobin Ehlis577188e2015-07-13 14:51:15 -06001684 }
Chia-I Wu5c17c962015-10-31 00:31:16 +08001685 return VK_SAMPLE_COUNT_1_BIT;
Tobin Ehliseba312c2015-04-01 08:40:34 -06001686}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001687
Tobin Ehliseba312c2015-04-01 08:40:34 -06001688// Validate state related to the PSO
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001689static VkBool32 validatePipelineState(layer_data* my_data, const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehliseba312c2015-04-01 08:40:34 -06001690{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001691 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06001692 // Verify that any MSAA request in PSO matches sample# in bound FB
Chia-I Wu5c17c962015-10-31 00:31:16 +08001693 VkSampleCountFlagBits psoNumSamples = getNumSamples(my_data, pipeline);
Tobin Ehliseba312c2015-04-01 08:40:34 -06001694 if (pCB->activeRenderPass) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001695 const VkRenderPassCreateInfo* pRPCI = my_data->renderPassMap[pCB->activeRenderPass]->pCreateInfo;
Chia-I Wu08accc62015-07-07 11:50:03 +08001696 const VkSubpassDescription* pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
Chia-I Wu5c17c962015-10-31 00:31:16 +08001697 VkSampleCountFlagBits subpassNumSamples = (VkSampleCountFlagBits) 0;
Chia-I Wu08accc62015-07-07 11:50:03 +08001698 uint32_t i;
1699
Chia-I Wud50a7d72015-10-26 20:48:51 +08001700 for (i = 0; i < pSD->colorAttachmentCount; i++) {
Chia-I Wu5c17c962015-10-31 00:31:16 +08001701 VkSampleCountFlagBits samples;
Chia-I Wu08accc62015-07-07 11:50:03 +08001702
Cody Northropa505dda2015-08-04 11:16:41 -06001703 if (pSD->pColorAttachments[i].attachment == VK_ATTACHMENT_UNUSED)
Chia-I Wu08accc62015-07-07 11:50:03 +08001704 continue;
1705
Cody Northropa505dda2015-08-04 11:16:41 -06001706 samples = pRPCI->pAttachments[pSD->pColorAttachments[i].attachment].samples;
Chia-I Wu5c17c962015-10-31 00:31:16 +08001707 if (subpassNumSamples == (VkSampleCountFlagBits) 0) {
Chia-I Wu08accc62015-07-07 11:50:03 +08001708 subpassNumSamples = samples;
1709 } else if (subpassNumSamples != samples) {
Chia-I Wu5c17c962015-10-31 00:31:16 +08001710 subpassNumSamples = (VkSampleCountFlagBits) -1;
Chia-I Wu08accc62015-07-07 11:50:03 +08001711 break;
1712 }
1713 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08001714 if (pSD->pDepthStencilAttachment && pSD->pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
Chia-I Wu5c17c962015-10-31 00:31:16 +08001715 const VkSampleCountFlagBits samples = pRPCI->pAttachments[pSD->pDepthStencilAttachment->attachment].samples;
1716 if (subpassNumSamples == (VkSampleCountFlagBits) 0)
Chia-I Wu08accc62015-07-07 11:50:03 +08001717 subpassNumSamples = samples;
1718 else if (subpassNumSamples != samples)
Chia-I Wu5c17c962015-10-31 00:31:16 +08001719 subpassNumSamples = (VkSampleCountFlagBits) -1;
Chia-I Wu08accc62015-07-07 11:50:03 +08001720 }
1721
1722 if (psoNumSamples != subpassNumSamples) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001723 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 -06001724 "Num samples mismatch! Binding PSO (%#" PRIxLEAST64 ") with %u samples while current RenderPass (%#" PRIxLEAST64 ") w/ %u samples!",
Chia-I Wue2fc5522015-10-26 20:04:44 +08001725 (uint64_t) pipeline, psoNumSamples, (uint64_t) pCB->activeRenderPass, subpassNumSamples);
Tobin Ehliseba312c2015-04-01 08:40:34 -06001726 }
1727 } else {
1728 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
1729 // Verify and flag error as appropriate
1730 }
1731 // TODO : Add more checks here
1732 } else {
1733 // TODO : Validate non-gfx pipeline updates
1734 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001735 return VK_FALSE;
Tobin Ehliseba312c2015-04-01 08:40:34 -06001736}
1737
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001738// Block of code at start here specifically for managing/tracking DSs
1739
Tobin Ehlis793ad302015-04-03 12:01:11 -06001740// Return Pool node ptr for specified pool or else NULL
Mark Lobodzinski39298632015-11-18 08:38:27 -07001741static DESCRIPTOR_POOL_NODE* getPoolNode(layer_data* my_data, const VkDescriptorPool pool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001742{
1743 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07001744 if (my_data->descriptorPoolMap.find(pool) == my_data->descriptorPoolMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001745 loader_platform_thread_unlock_mutex(&globalLock);
1746 return NULL;
1747 }
1748 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07001749 return my_data->descriptorPoolMap[pool];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001750}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001751
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001752static LAYOUT_NODE* getLayoutNode(layer_data* my_data, const VkDescriptorSetLayout layout) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001753 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001754 if (my_data->descriptorSetLayoutMap.find(layout) == my_data->descriptorSetLayoutMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001755 loader_platform_thread_unlock_mutex(&globalLock);
1756 return NULL;
1757 }
1758 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001759 return my_data->descriptorSetLayoutMap[layout];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001760}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001761
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001762// 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 -06001763static VkBool32 validUpdateStruct(layer_data* my_data, const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001764{
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001765 switch (pUpdateStruct->sType)
1766 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001767 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1768 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001769 return VK_FALSE;
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001770 default:
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001771 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 -06001772 "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 -06001773 }
1774}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001775
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001776// Set count for given update struct in the last parameter
Courtney Goeltzenleuchter085f8dd2015-12-16 16:08:44 -07001777// 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 -06001778static uint32_t getUpdateCount(layer_data* my_data, const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis793ad302015-04-03 12:01:11 -06001779{
1780 switch (pUpdateStruct->sType)
1781 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001782 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
Chia-I Wud50a7d72015-10-26 20:48:51 +08001783 return ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorCount;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001784 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis793ad302015-04-03 12:01:11 -06001785 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wud50a7d72015-10-26 20:48:51 +08001786 return ((VkCopyDescriptorSet*)pUpdateStruct)->descriptorCount;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001787 }
Courtney Goeltzenleuchter7f47bca2015-12-16 16:08:08 -07001788
1789 return 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001790}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001791
Tobin Ehlis793ad302015-04-03 12:01:11 -06001792// For given Layout Node and binding, return index where that binding begins
1793static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
1794{
1795 uint32_t offsetIndex = 0;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001796 for (uint32_t i = 0; i < pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001797 if (pLayout->createInfo.pBindings[i].binding == binding)
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001798 break;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001799 offsetIndex += pLayout->createInfo.pBindings[i].descriptorCount;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001800 }
1801 return offsetIndex;
1802}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001803
Tobin Ehlis793ad302015-04-03 12:01:11 -06001804// For given layout node and binding, return last index that is updated
1805static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
1806{
1807 uint32_t offsetIndex = 0;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001808 for (uint32_t i = 0; i < pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001809 offsetIndex += pLayout->createInfo.pBindings[i].descriptorCount;
1810 if (pLayout->createInfo.pBindings[i].binding == binding)
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001811 break;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001812 }
1813 return offsetIndex-1;
1814}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001815
Tobin Ehlisbaca3ab2015-10-27 12:54:50 -06001816// For given layout and update, return the first overall index of the layout that is updated
Tobin Ehlis8a62e632015-10-27 15:43:38 -06001817static 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 -06001818{
Tobin Ehlisbaca3ab2015-10-27 12:54:50 -06001819 return getBindingStartIndex(pLayout, binding)+arrayIndex;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001820}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001821
Tobin Ehlis8a62e632015-10-27 15:43:38 -06001822// For given layout and update, return the last overall index of the layout that is updated
1823static 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 -06001824{
Tobin Ehlis8a62e632015-10-27 15:43:38 -06001825 uint32_t count = getUpdateCount(my_data, device, pUpdateStruct);
Tobin Ehlisbaca3ab2015-10-27 12:54:50 -06001826 return getBindingStartIndex(pLayout, binding)+arrayIndex+count-1;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001827}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001828
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001829// Verify that the descriptor type in the update struct matches what's expected by the layout
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001830static 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 -06001831{
1832 // First get actual type of update
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001833 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001834 VkDescriptorType actualType;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001835 uint32_t i = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001836 switch (pUpdateStruct->sType)
1837 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001838 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1839 actualType = ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorType;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001840 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001841 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
1842 /* no need to validate */
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001843 return VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001844 break;
1845 default:
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001846 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 -06001847 "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 -06001848 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001849 if (VK_FALSE == skipCall) {
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001850 // Set first stageFlags as reference and verify that all other updates match it
1851 VkShaderStageFlags refStageFlags = pLayout->stageFlags[startIndex];
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001852 for (i = startIndex; i <= endIndex; i++) {
Tobin Ehlis644ff042015-10-20 10:11:55 -06001853 if (pLayout->descriptorTypes[i] != actualType) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001854 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 -06001855 "Write descriptor update has descriptor type %s that does not match overlapping binding descriptor type of %s!",
1856 string_VkDescriptorType(actualType), string_VkDescriptorType(pLayout->descriptorTypes[i]));
1857 }
1858 if (pLayout->stageFlags[i] != refStageFlags) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001859 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_DESCRIPTOR_STAGEFLAGS_MISMATCH, "DS",
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001860 "Write descriptor update has stageFlags %x that do not match overlapping binding descriptor stageFlags of %x!",
1861 refStageFlags, pLayout->stageFlags[i]);
Tobin Ehlis483cc352015-09-30 08:30:20 -06001862 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001863 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001864 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001865 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001866}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001867
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001868// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001869// struct into the pNewNode param. Return VK_TRUE if error condition encountered and callback signals early exit.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001870// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001871static VkBool32 shadowUpdateNode(layer_data* my_data, const VkDevice device, GENERIC_HEADER* pUpdate, GENERIC_HEADER** pNewNode)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001872{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001873 VkBool32 skipCall = VK_FALSE;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001874 VkWriteDescriptorSet* pWDS = NULL;
1875 VkCopyDescriptorSet* pCDS = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001876 size_t array_size = 0;
1877 size_t base_array_size = 0;
1878 size_t total_array_size = 0;
1879 size_t baseBuffAddr = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001880 switch (pUpdate->sType)
1881 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001882 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1883 pWDS = new VkWriteDescriptorSet;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001884 *pNewNode = (GENERIC_HEADER*)pWDS;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001885 memcpy(pWDS, pUpdate, sizeof(VkWriteDescriptorSet));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001886
1887 switch (pWDS->descriptorType) {
1888 case VK_DESCRIPTOR_TYPE_SAMPLER:
1889 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
1890 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
1891 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
1892 {
Chia-I Wud50a7d72015-10-26 20:48:51 +08001893 VkDescriptorImageInfo *info = new VkDescriptorImageInfo[pWDS->descriptorCount];
1894 memcpy(info, pWDS->pImageInfo, pWDS->descriptorCount * sizeof(VkDescriptorImageInfo));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001895 pWDS->pImageInfo = info;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001896 }
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001897 break;
1898 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
1899 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
1900 {
Chia-I Wud50a7d72015-10-26 20:48:51 +08001901 VkBufferView *info = new VkBufferView[pWDS->descriptorCount];
1902 memcpy(info, pWDS->pTexelBufferView, pWDS->descriptorCount * sizeof(VkBufferView));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001903 pWDS->pTexelBufferView = info;
1904 }
1905 break;
1906 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
1907 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
1908 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
1909 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
1910 {
Chia-I Wud50a7d72015-10-26 20:48:51 +08001911 VkDescriptorBufferInfo *info = new VkDescriptorBufferInfo[pWDS->descriptorCount];
1912 memcpy(info, pWDS->pBufferInfo, pWDS->descriptorCount * sizeof(VkDescriptorBufferInfo));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001913 pWDS->pBufferInfo = info;
1914 }
1915 break;
1916 default:
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07001917 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001918 break;
1919 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001920 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001921 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
1922 pCDS = new VkCopyDescriptorSet;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001923 *pNewNode = (GENERIC_HEADER*)pCDS;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001924 memcpy(pCDS, pUpdate, sizeof(VkCopyDescriptorSet));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001925 break;
1926 default:
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001927 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 -06001928 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdate->sType), pUpdate->sType))
1929 return VK_TRUE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001930 }
1931 // Make sure that pNext for the end of shadow copy is NULL
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001932 (*pNewNode)->pNext = NULL;
1933 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001934}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001935
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001936// Verify that given sampler is valid
1937static VkBool32 validateSampler(const layer_data* my_data, const VkSampler* pSampler, const VkBool32 immutable)
1938{
1939 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08001940 auto sampIt = my_data->sampleMap.find(*pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001941 if (sampIt == my_data->sampleMap.end()) {
1942 if (!immutable) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001943 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 +08001944 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid sampler %#" PRIxLEAST64, (uint64_t) *pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001945 } else { // immutable
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001946 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 +08001947 "vkUpdateDescriptorSets: Attempt to update descriptor whose binding has an invalid immutable sampler %#" PRIxLEAST64, (uint64_t) *pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001948 }
1949 } else {
1950 // TODO : Any further checks we want to do on the sampler?
1951 }
1952 return skipCall;
1953}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001954
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001955// Verify that given imageView is valid
1956static VkBool32 validateImageView(const layer_data* my_data, const VkImageView* pImageView, const VkImageLayout imageLayout)
1957{
1958 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08001959 auto ivIt = my_data->imageViewMap.find(*pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001960 if (ivIt == my_data->imageViewMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001961 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 +08001962 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid imageView %#" PRIxLEAST64, (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001963 } else {
1964 // Validate that imageLayout is compatible with aspectMask and image format
1965 VkImageAspectFlags aspectMask = ivIt->second->subresourceRange.aspectMask;
Chia-I Wue2fc5522015-10-26 20:04:44 +08001966 VkImage image = ivIt->second->image;
Michael Lentine7b236262015-10-23 12:41:44 -07001967 // TODO : Check here in case we have a bad image
Chia-I Wue2fc5522015-10-26 20:04:44 +08001968 auto imgIt = my_data->imageMap.find(image);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001969 if (imgIt == my_data->imageMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001970 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 -07001971 "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 -06001972 } else {
1973 VkFormat format = (*imgIt).second->format;
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07001974 VkBool32 ds = vk_format_is_depth_or_stencil(format);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001975 switch (imageLayout) {
1976 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
1977 // Only Color bit must be set
1978 if ((aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) != VK_IMAGE_ASPECT_COLOR_BIT) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001979 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, (uint64_t) *pImageView, __LINE__,
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001980 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 +08001981 " that does not have VK_IMAGE_ASPECT_COLOR_BIT set.", (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001982 }
1983 // format must NOT be DS
1984 if (ds) {
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_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 +08001987 " 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 -06001988 }
1989 break;
1990 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
1991 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
1992 // Depth or stencil bit must be set, but both must NOT be set
1993 if (aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) {
1994 if (aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) {
1995 // both must NOT be set
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001996 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, (uint64_t) *pImageView, __LINE__,
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001997 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with imageView %#" PRIxLEAST64 ""
Chia-I Wue2fc5522015-10-26 20:04:44 +08001998 " that has both STENCIL and DEPTH aspects set", (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001999 }
2000 } else if (!(aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)) {
2001 // Neither were 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 layout %s and imageView %#" PRIxLEAST64 ""
Chia-I Wue2fc5522015-10-26 20:04:44 +08002004 " that does not have STENCIL or DEPTH aspect set.", string_VkImageLayout(imageLayout), (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002005 }
2006 // format must be DS
2007 if (!ds) {
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_IMAGEVIEW_DESCRIPTOR_ERROR, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout %s and imageView %#" PRIxLEAST64 ""
Chia-I Wue2fc5522015-10-26 20:04:44 +08002010 " 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 -06002011 }
2012 break;
2013 default:
2014 // anything to check for other layouts?
2015 break;
2016 }
2017 }
2018 }
2019 return skipCall;
2020}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002021
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002022// Verify that given bufferView is valid
2023static VkBool32 validateBufferView(const layer_data* my_data, const VkBufferView* pBufferView)
2024{
2025 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002026 auto sampIt = my_data->bufferViewMap.find(*pBufferView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002027 if (sampIt == my_data->bufferViewMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002028 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 +08002029 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid bufferView %#" PRIxLEAST64, (uint64_t) *pBufferView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002030 } else {
2031 // TODO : Any further checks we want to do on the bufferView?
2032 }
2033 return skipCall;
2034}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002035
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002036// Verify that given bufferInfo is valid
2037static VkBool32 validateBufferInfo(const layer_data* my_data, const VkDescriptorBufferInfo* pBufferInfo)
2038{
2039 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002040 auto sampIt = my_data->bufferMap.find(pBufferInfo->buffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002041 if (sampIt == my_data->bufferMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002042 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 +08002043 "vkUpdateDescriptorSets: Attempt to update descriptor where bufferInfo has invalid buffer %#" PRIxLEAST64, (uint64_t) pBufferInfo->buffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002044 } else {
2045 // TODO : Any further checks we want to do on the bufferView?
2046 }
2047 return skipCall;
2048}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002049
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002050static VkBool32 validateUpdateContents(const layer_data* my_data, const VkWriteDescriptorSet *pWDS, const VkDescriptorSetLayoutBinding* pLayoutBinding)
2051{
2052 VkBool32 skipCall = VK_FALSE;
2053 // First verify that for the given Descriptor type, the correct DescriptorInfo data is supplied
2054 VkBufferView* pBufferView = NULL;
2055 const VkSampler* pSampler = NULL;
2056 VkImageView* pImageView = NULL;
2057 VkImageLayout* pImageLayout = NULL;
2058 VkDescriptorBufferInfo* pBufferInfo = NULL;
2059 VkBool32 immutable = VK_FALSE;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002060 uint32_t i = 0;
2061 // For given update type, verify that update contents are correct
2062 switch (pWDS->descriptorType) {
2063 case VK_DESCRIPTOR_TYPE_SAMPLER:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002064 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002065 skipCall |= validateSampler(my_data, &(pWDS->pImageInfo[i].sampler), immutable);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002066 }
2067 break;
2068 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002069 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002070 if (NULL == pLayoutBinding->pImmutableSamplers) {
2071 pSampler = &(pWDS->pImageInfo[i].sampler);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002072 if (immutable) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002073 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 -06002074 "vkUpdateDescriptorSets: Update #%u is not an immutable sampler %#" PRIxLEAST64 ", but previous update(s) from this "
2075 "VkWriteDescriptorSet struct used an immutable sampler. All updates from a single struct must either "
Chia-I Wue2fc5522015-10-26 20:04:44 +08002076 "use immutable or non-immutable samplers.", i, (uint64_t) *pSampler);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002077 }
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002078 } else {
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002079 if (i>0 && !immutable) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002080 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 -06002081 "vkUpdateDescriptorSets: Update #%u is an immutable sampler, but previous update(s) from this "
2082 "VkWriteDescriptorSet struct used a non-immutable sampler. All updates from a single struct must either "
2083 "use immutable or non-immutable samplers.", i);
2084 }
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002085 immutable = VK_TRUE;
2086 pSampler = &(pLayoutBinding->pImmutableSamplers[i]);
2087 }
2088 skipCall |= validateSampler(my_data, pSampler, immutable);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002089 }
2090 // Intentionally fall through here to also validate image stuff
2091 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2092 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
2093 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002094 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002095 skipCall |= validateImageView(my_data, &(pWDS->pImageInfo[i].imageView), pWDS->pImageInfo[i].imageLayout);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002096 }
2097 break;
2098 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2099 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
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 |= validateBufferView(my_data, &(pWDS->pTexelBufferView[i]));
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002102 }
2103 break;
2104 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2105 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2106 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2107 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002108 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002109 skipCall |= validateBufferInfo(my_data, &(pWDS->pBufferInfo[i]));
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002110 }
2111 break;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002112 }
2113 return skipCall;
2114}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002115
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002116// update DS mappings based on write and copy update arrays
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08002117static 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 -06002118{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002119 VkBool32 skipCall = VK_FALSE;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002120
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002121 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002122 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002123 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002124 // Validate Write updates
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002125 uint32_t i = 0;
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08002126 for (i=0; i < descriptorWriteCount; i++) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002127 VkDescriptorSet ds = pWDS[i].dstSet;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002128 SET_NODE* pSet = my_data->setMap[ds];
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002129 GENERIC_HEADER* pUpdate = (GENERIC_HEADER*) &pWDS[i];
Tobin Ehlis793ad302015-04-03 12:01:11 -06002130 pLayout = pSet->pLayout;
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002131 // First verify valid update struct
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06002132 if ((skipCall = validUpdateStruct(my_data, device, pUpdate)) == VK_TRUE) {
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002133 break;
2134 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002135 uint32_t binding = 0, endIndex = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002136 binding = pWDS[i].dstBinding;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002137 // Make sure that layout being updated has the binding being updated
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002138 if (pLayout->bindings.find(binding) == pLayout->bindings.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002139 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 -08002140 "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 -06002141 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06002142 // Next verify that update falls within size of given binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002143 endIndex = getUpdateEndIndex(my_data, device, pLayout, binding, pWDS[i].dstArrayElement, pUpdate);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002144 if (getBindingEndIndex(pLayout, binding) < endIndex) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06002145 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002146 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002147 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 -06002148 "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 -06002149 } else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002150 uint32_t startIndex;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002151 startIndex = getUpdateStartIndex(my_data, device, pLayout, binding, pWDS[i].dstArrayElement, pUpdate);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002152 // Layout bindings match w/ update, now verify that update type & stageFlags are the same for entire update
2153 if ((skipCall = validateUpdateConsistency(my_data, device, pLayout, pUpdate, startIndex, endIndex)) == VK_FALSE) {
2154 // The update is within bounds and consistent, but need to make sure contents make sense as well
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002155 if ((skipCall = validateUpdateContents(my_data, &pWDS[i], &pLayout->createInfo.pBindings[binding])) == VK_FALSE) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002156 // Update is good. Save the update info
2157 // Create new update struct for this set's shadow copy
2158 GENERIC_HEADER* pNewNode = NULL;
2159 skipCall |= shadowUpdateNode(my_data, device, pUpdate, &pNewNode);
2160 if (NULL == pNewNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002161 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 -06002162 "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
2163 } else {
2164 // Insert shadow node into LL of updates for this set
2165 pNewNode->pNext = pSet->pUpdateStructs;
2166 pSet->pUpdateStructs = pNewNode;
2167 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002168 for (uint32_t j = startIndex; j <= endIndex; j++) {
2169 assert(j<pSet->descriptorCount);
2170 pSet->ppDescriptors[j] = pNewNode;
2171 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002172 }
2173 }
2174 }
2175 }
2176 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002177 }
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002178 // Now validate copy updates
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08002179 for (i=0; i < descriptorCopyCount; ++i) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002180 SET_NODE *pSrcSet = NULL, *pDstSet = NULL;
2181 LAYOUT_NODE *pSrcLayout = NULL, *pDstLayout = NULL;
2182 uint32_t srcStartIndex = 0, srcEndIndex = 0, dstStartIndex = 0, dstEndIndex = 0;
2183 // For each copy make sure that update falls within given layout and that types match
Chia-I Wue2fc5522015-10-26 20:04:44 +08002184 pSrcSet = my_data->setMap[pCDS[i].srcSet];
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002185 pDstSet = my_data->setMap[pCDS[i].dstSet];
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002186 pSrcLayout = pSrcSet->pLayout;
2187 pDstLayout = pDstSet->pLayout;
2188 // Validate that src binding is valid for src set layout
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002189 if (pSrcLayout->bindings.find(pCDS[i].srcBinding) == pSrcLayout->bindings.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002190 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 -06002191 "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 +08002192 i, pCDS[i].srcBinding, (uint64_t) pSrcLayout->layout, pSrcLayout->createInfo.bindingCount-1);
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002193 } else if (pDstLayout->bindings.find(pCDS[i].dstBinding) == pDstLayout->bindings.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002194 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 +08002195 "Copy descriptor update %u has dstBinding %u which is out of bounds for underlying SetLayout %#" PRIxLEAST64 " which only has bindings 0-%u.",
2196 i, pCDS[i].dstBinding, (uint64_t) pDstLayout->layout, pDstLayout->createInfo.bindingCount-1);
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002197 } else {
2198 // Proceed with validation. Bindings are ok, but make sure update is within bounds of given layout
2199 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 +08002200 dstEndIndex = getUpdateEndIndex(my_data, device, pDstLayout, pCDS[i].dstBinding, pCDS[i].dstArrayElement, (const GENERIC_HEADER*)&(pCDS[i]));
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002201 if (getBindingEndIndex(pSrcLayout, pCDS[i].srcBinding) < srcEndIndex) {
2202 pLayoutCI = &pSrcLayout->createInfo;
2203 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002204 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 -06002205 "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 +08002206 } else if (getBindingEndIndex(pDstLayout, pCDS[i].dstBinding) < dstEndIndex) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002207 pLayoutCI = &pDstLayout->createInfo;
2208 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002209 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pDstSet->set, __LINE__, DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002210 "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 -06002211 } else {
2212 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 +08002213 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 +08002214 for (uint32_t j=0; j<pCDS[i].descriptorCount; ++j) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002215 // For copy just make sure that the types match and then perform the update
2216 if (pSrcLayout->descriptorTypes[srcStartIndex+j] != pDstLayout->descriptorTypes[dstStartIndex+j]) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002217 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 -06002218 "Copy descriptor update index %u, update count #%u, has src update descriptor type %s that does not match overlapping dest descriptor type of %s!",
2219 i, j+1, string_VkDescriptorType(pSrcLayout->descriptorTypes[srcStartIndex+j]), string_VkDescriptorType(pDstLayout->descriptorTypes[dstStartIndex+j]));
2220 } else {
2221 // point dst descriptor at corresponding src descriptor
Tobin Ehlisf6585052015-12-17 11:48:42 -07002222 // TODO : This may be a hole. I believe copy should be its own copy,
2223 // otherwise a subsequent write update to src will incorrectly affect the copy
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002224 pDstSet->ppDescriptors[j+dstStartIndex] = pSrcSet->ppDescriptors[j+srcStartIndex];
2225 }
2226 }
2227 }
2228 }
2229 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002230 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002231 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002232}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002233
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002234// Verify that given pool has descriptors that are being requested for allocation
Mark Lobodzinski39298632015-11-18 08:38:27 -07002235static 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 -06002236{
2237 VkBool32 skipCall = VK_FALSE;
2238 uint32_t i = 0, j = 0;
2239 for (i=0; i<count; ++i) {
2240 LAYOUT_NODE* pLayout = getLayoutNode(dev_data, pSetLayouts[i]);
2241 if (NULL == pLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002242 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 +08002243 "Unable to find set layout node for layout %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pSetLayouts[i]);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002244 } else {
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002245 uint32_t typeIndex = 0, poolSizeCount = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002246 for (j=0; j<pLayout->createInfo.bindingCount; ++j) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002247 typeIndex = static_cast<uint32_t>(pLayout->createInfo.pBindings[j].descriptorType);
2248 poolSizeCount = pLayout->createInfo.pBindings[j].descriptorCount;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002249 if (poolSizeCount > pPoolNode->availableDescriptorTypeCount[typeIndex]) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002250 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 -06002251 "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 -07002252 poolSizeCount, string_VkDescriptorType(pLayout->createInfo.pBindings[j].descriptorType), (uint64_t) pPoolNode->pool, pPoolNode->availableDescriptorTypeCount[typeIndex]);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002253 } else { // Decrement available descriptors of this type
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002254 pPoolNode->availableDescriptorTypeCount[typeIndex] -= poolSizeCount;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002255 }
2256 }
2257 }
2258 }
2259 return skipCall;
2260}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002261
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002262// Free the shadowed update node for this Set
2263// NOTE : Calls to this function should be wrapped in mutex
2264static void freeShadowUpdateTree(SET_NODE* pSet)
2265{
2266 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
2267 pSet->pUpdateStructs = NULL;
2268 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
2269 // Clear the descriptor mappings as they will now be invalid
2270 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
2271 while(pShadowUpdate) {
2272 pFreeUpdate = pShadowUpdate;
2273 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
2274 uint32_t index = 0;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002275 VkWriteDescriptorSet * pWDS = NULL;
2276 VkCopyDescriptorSet * pCDS = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002277 void** ppToFree = NULL;
2278 switch (pFreeUpdate->sType)
2279 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002280 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
2281 pWDS = (VkWriteDescriptorSet*)pFreeUpdate;
Tony Barbourb1947942015-11-02 11:46:29 -07002282 switch (pWDS->descriptorType) {
2283 case VK_DESCRIPTOR_TYPE_SAMPLER:
2284 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
2285 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2286 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
2287 {
2288 delete[] pWDS->pImageInfo;
2289 }
2290 break;
2291 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2292 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
2293 {
2294 delete[] pWDS->pTexelBufferView;
2295 }
2296 break;
2297 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2298 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2299 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2300 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
2301 {
2302 delete[] pWDS->pBufferInfo;
2303 }
2304 break;
2305 default:
2306 break;
Courtney Goeltzenleuchteraa132e72015-10-22 15:31:56 -06002307 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002308 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002309 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002310 break;
2311 default:
2312 assert(0);
2313 break;
2314 }
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002315 delete pFreeUpdate;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002316 }
2317}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002318
Tobin Ehlis793ad302015-04-03 12:01:11 -06002319// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002320// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002321static void deletePools(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002322{
Mark Lobodzinski39298632015-11-18 08:38:27 -07002323 if (my_data->descriptorPoolMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06002324 return;
Mark Lobodzinski39298632015-11-18 08:38:27 -07002325 for (auto ii=my_data->descriptorPoolMap.begin(); ii!=my_data->descriptorPoolMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002326 SET_NODE* pSet = (*ii).second->pSets;
2327 SET_NODE* pFreeSet = pSet;
2328 while (pSet) {
2329 pFreeSet = pSet;
2330 pSet = pSet->pNext;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002331 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002332 // Free Update shadow struct tree
2333 freeShadowUpdateTree(pFreeSet);
2334 if (pFreeSet->ppDescriptors) {
Chris Forbes02038792015-06-04 10:49:27 +12002335 delete[] pFreeSet->ppDescriptors;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002336 }
2337 delete pFreeSet;
2338 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002339 delete (*ii).second;
2340 }
Mark Lobodzinski39298632015-11-18 08:38:27 -07002341 my_data->descriptorPoolMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002342}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002343
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002344// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002345// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002346static void deleteLayouts(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002347{
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07002348 if (my_data->descriptorSetLayoutMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06002349 return;
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07002350 for (auto ii=my_data->descriptorSetLayoutMap.begin(); ii!=my_data->descriptorSetLayoutMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002351 LAYOUT_NODE* pLayout = (*ii).second;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002352 if (pLayout->createInfo.pBindings) {
Chia-I Wud50a7d72015-10-26 20:48:51 +08002353 for (uint32_t i=0; i<pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002354 if (pLayout->createInfo.pBindings[i].pImmutableSamplers)
2355 delete[] pLayout->createInfo.pBindings[i].pImmutableSamplers;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002356 }
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002357 delete[] pLayout->createInfo.pBindings;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002358 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002359 delete pLayout;
2360 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07002361 my_data->descriptorSetLayoutMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002362}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002363
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002364// Currently clearing a set is removing all previous updates to that set
2365// TODO : Validate if this is correct clearing behavior
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002366static void clearDescriptorSet(layer_data* my_data, VkDescriptorSet set)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002367{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002368 SET_NODE* pSet = getSetNode(my_data, set);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002369 if (!pSet) {
2370 // TODO : Return error
Tobin Ehlisce132d82015-06-19 15:07:05 -06002371 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002372 loader_platform_thread_lock_mutex(&globalLock);
2373 freeShadowUpdateTree(pSet);
2374 loader_platform_thread_unlock_mutex(&globalLock);
2375 }
2376}
2377
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002378static void clearDescriptorPool(layer_data* my_data, const VkDevice device, const VkDescriptorPool pool, VkDescriptorPoolResetFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002379{
Mark Lobodzinski39298632015-11-18 08:38:27 -07002380 DESCRIPTOR_POOL_NODE* pPool = getPoolNode(my_data, pool);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002381 if (!pPool) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002382 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 +08002383 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkResetDescriptorPool() call", (uint64_t) pool);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002384 } else {
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002385 // TODO: validate flags
Tobin Ehlis793ad302015-04-03 12:01:11 -06002386 // For every set off of this pool, clear it
2387 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002388 while (pSet) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002389 clearDescriptorSet(my_data, pSet->set);
Mark Lobodzinskidcce0792016-01-04 09:40:19 -07002390 pSet = pSet->pNext;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002391 }
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002392 // Reset available count to max count for this pool
2393 for (uint32_t i=0; i<pPool->availableDescriptorTypeCount.size(); ++i) {
2394 pPool->availableDescriptorTypeCount[i] = pPool->maxDescriptorTypeCount[i];
2395 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002396 }
2397}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002398
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002399// For given CB object, fetch associated CB Node from map
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002400static GLOBAL_CB_NODE* getCBNode(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002401{
2402 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002403 if (my_data->commandBufferMap.count(cb) == 0) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002404 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002405 // TODO : How to pass cb as srcObj here?
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002406 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 +08002407 "Attempt to use CommandBuffer %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<uint64_t>(cb));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002408 return NULL;
2409 }
2410 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002411 return my_data->commandBufferMap[cb];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002412}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002413
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002414// Free all CB Nodes
2415// NOTE : Calls to this function should be wrapped in mutex
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002416static void deleteCommandBuffers(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002417{
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002418 if (my_data->commandBufferMap.size() <= 0) {
David Pinedod8f83d82015-04-27 16:36:17 -06002419 return;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002420 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002421 for (auto ii=my_data->commandBufferMap.begin(); ii!=my_data->commandBufferMap.end(); ++ii) {
Courtney Goeltzenleuchterea3117c2015-04-27 15:04:43 -06002422 vector<CMD_NODE*> cmd_node_list = (*ii).second->pCmds;
2423 while (!cmd_node_list.empty()) {
2424 CMD_NODE* cmd_node = cmd_node_list.back();
2425 delete cmd_node;
2426 cmd_node_list.pop_back();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002427 }
2428 delete (*ii).second;
2429 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002430 my_data->commandBufferMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002431}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002432
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002433static 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 -06002434{
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002435 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 -07002436 (uint64_t)cb, __LINE__, DRAWSTATE_NO_BEGIN_COMMAND_BUFFER, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002437 "You must call vkBeginCommandBuffer() before this call to %s", caller_name);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002438}
Michael Lentine3dea6512015-10-28 15:55:18 -07002439
Michael Lentine2e068b22015-12-29 16:05:27 -06002440bool validateCmdsInCmdBuffer(const layer_data* dev_data, const GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd_type) {
2441 if (!pCB->activeRenderPass) return false;
2442 bool skip_call = false;
2443 if (pCB->activeSubpassContents == VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS && cmd_type != CMD_EXECUTECOMMANDS) {
2444 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
2445 DRAWSTATE_INVALID_COMMAND_BUFFER, "DS", "Commands cannot be called in a subpass using secondary command buffers.");
2446 } else if (pCB->activeSubpassContents == VK_SUBPASS_CONTENTS_INLINE && cmd_type == CMD_EXECUTECOMMANDS) {
2447 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
2448 DRAWSTATE_INVALID_COMMAND_BUFFER, "DS", "vkCmdExecuteCommands() cannot be called in a subpass using inline commands.");
2449 }
Michael Lentine3dea6512015-10-28 15:55:18 -07002450 return skip_call;
2451}
2452
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002453// Add specified CMD to the CmdBuffer in given pCB, flagging errors if CB is not
2454// in the recording state or if there's an issue with the Cmd ordering
2455static 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 -06002456{
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002457 VkBool32 skipCall = VK_FALSE;
2458 if (pCB->state != CB_RECORDING) {
2459 skipCall |= report_error_no_cb_begin(my_data, pCB->commandBuffer, caller_name);
2460 skipCall |= validateCmdsInCmdBuffer(my_data, pCB, cmd);
2461 CMD_NODE* pCmd = new CMD_NODE;
2462 if (pCmd) {
2463 // init cmd node and append to end of cmd LL
2464 memset(pCmd, 0, sizeof(CMD_NODE));
2465 pCmd->cmdNumber = ++pCB->numCmds;
2466 pCmd->type = cmd;
2467 pCB->pCmds.push_back(pCmd);
2468 } else {
2469 // TODO : How to pass cb as srcObj here?
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002470 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 -07002471 "Out of memory while attempting to allocate new CMD_NODE for commandBuffer %#" PRIxLEAST64, reinterpret_cast<uint64_t>(pCB->commandBuffer));
2472 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002473 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002474 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002475}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002476
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002477static void resetCB(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002478{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002479 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002480 if (pCB) {
Courtney Goeltzenleuchter3597a202015-04-27 17:16:56 -06002481 vector<CMD_NODE*> cmd_list = pCB->pCmds;
2482 while (!cmd_list.empty()) {
2483 delete cmd_list.back();
2484 cmd_list.pop_back();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002485 }
Courtney Goeltzenleuchter3597a202015-04-27 17:16:56 -06002486 pCB->pCmds.clear();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06002487 // Reset CB state (need to save createInfo)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002488 VkCommandBufferAllocateInfo saveCBCI = pCB->createInfo;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002489 pCB->commandBuffer = cb;
Tobin Ehlis59278bf2015-08-18 07:10:58 -06002490 pCB->createInfo = saveCBCI;
Michael Lentineabc5e922015-10-12 11:30:14 -05002491 memset(&pCB->beginInfo, 0, sizeof(VkCommandBufferBeginInfo));
2492 pCB->fence = 0;
2493 pCB->numCmds = 0;
2494 memset(pCB->drawCount, 0, NUM_DRAW_TYPES * sizeof(uint64_t));
2495 pCB->state = CB_NEW;
2496 pCB->submitCount = 0;
2497 pCB->status = 0;
2498 pCB->pCmds.clear();
2499 pCB->lastBoundPipeline = 0;
2500 pCB->viewports.clear();
2501 pCB->scissors.clear();
2502 pCB->lineWidth = 0;
2503 pCB->depthBiasConstantFactor = 0;
2504 pCB->depthBiasClamp = 0;
2505 pCB->depthBiasSlopeFactor = 0;
2506 memset(pCB->blendConstants, 0, 4 * sizeof(float));
2507 pCB->minDepthBounds = 0;
2508 pCB->maxDepthBounds = 0;
2509 memset(&pCB->front, 0, sizeof(stencil_data));
2510 memset(&pCB->back, 0, sizeof(stencil_data));
2511 pCB->lastBoundDescriptorSet = 0;
2512 pCB->lastBoundPipelineLayout = 0;
2513 pCB->activeRenderPass = 0;
2514 pCB->activeSubpass = 0;
2515 pCB->framebuffer = 0;
Michael Lentineabc5e922015-10-12 11:30:14 -05002516 pCB->boundDescriptorSets.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07002517 pCB->drawData.clear();
2518 pCB->currentDrawData.buffers.clear();
Michael Lentineabc5e922015-10-12 11:30:14 -05002519 pCB->imageLayoutMap.clear();
Michael Lentineb887b0a2015-12-29 14:12:11 -06002520 pCB->waitedEvents.clear();
2521 pCB->waitedEventsBeforeQueryReset.clear();
2522 pCB->queryToStateMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002523 }
2524}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002525
Tobin Ehlis963a4042015-09-29 08:18:34 -06002526// Set PSO-related status bits for CB, including dynamic state set via PSO
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002527static void set_cb_pso_status(GLOBAL_CB_NODE* pCB, const PIPELINE_NODE* pPipe)
2528{
2529 for (uint32_t i = 0; i < pPipe->cbStateCI.attachmentCount; i++) {
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002530 if (0 != pPipe->pAttachments[i].colorWriteMask) {
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002531 pCB->status |= CBSTATUS_COLOR_BLEND_WRITE_ENABLE;
2532 }
2533 }
2534 if (pPipe->dsStateCI.depthWriteEnable) {
Cody Northrop82485a82015-08-18 15:21:16 -06002535 pCB->status |= CBSTATUS_DEPTH_WRITE_ENABLE;
2536 }
Cody Northrop82485a82015-08-18 15:21:16 -06002537 if (pPipe->dsStateCI.stencilTestEnable) {
2538 pCB->status |= CBSTATUS_STENCIL_TEST_ENABLE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002539 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06002540 // Account for any dynamic state not set via this PSO
2541 if (!pPipe->dynStateCI.dynamicStateCount) { // All state is static
2542 pCB->status = CBSTATUS_ALL;
2543 } else {
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002544 // First consider all state on
2545 // Then unset any state that's noted as dynamic in PSO
2546 // Finally OR that into CB statemask
2547 CBStatusFlags psoDynStateMask = CBSTATUS_ALL;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002548 for (uint32_t i=0; i < pPipe->dynStateCI.dynamicStateCount; i++) {
2549 switch (pPipe->dynStateCI.pDynamicStates[i]) {
2550 case VK_DYNAMIC_STATE_VIEWPORT:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002551 psoDynStateMask &= ~CBSTATUS_VIEWPORT_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002552 break;
2553 case VK_DYNAMIC_STATE_SCISSOR:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002554 psoDynStateMask &= ~CBSTATUS_SCISSOR_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002555 break;
2556 case VK_DYNAMIC_STATE_LINE_WIDTH:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002557 psoDynStateMask &= ~CBSTATUS_LINE_WIDTH_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002558 break;
2559 case VK_DYNAMIC_STATE_DEPTH_BIAS:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002560 psoDynStateMask &= ~CBSTATUS_DEPTH_BIAS_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002561 break;
2562 case VK_DYNAMIC_STATE_BLEND_CONSTANTS:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002563 psoDynStateMask &= ~CBSTATUS_BLEND_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002564 break;
2565 case VK_DYNAMIC_STATE_DEPTH_BOUNDS:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002566 psoDynStateMask &= ~CBSTATUS_DEPTH_BOUNDS_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002567 break;
2568 case VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002569 psoDynStateMask &= ~CBSTATUS_STENCIL_READ_MASK_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002570 break;
2571 case VK_DYNAMIC_STATE_STENCIL_WRITE_MASK:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002572 psoDynStateMask &= ~CBSTATUS_STENCIL_WRITE_MASK_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002573 break;
2574 case VK_DYNAMIC_STATE_STENCIL_REFERENCE:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002575 psoDynStateMask &= ~CBSTATUS_STENCIL_REFERENCE_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002576 break;
2577 default:
2578 // TODO : Flag error here
2579 break;
2580 }
2581 }
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002582 pCB->status |= psoDynStateMask;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002583 }
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002584}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002585
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002586// Print the last bound Gfx Pipeline
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002587static VkBool32 printPipeline(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002588{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002589 VkBool32 skipCall = VK_FALSE;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002590 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002591 if (pCB) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002592 PIPELINE_NODE *pPipeTrav = getPipeline(my_data, pCB->lastBoundPipeline);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002593 if (!pPipeTrav) {
2594 // nothing to print
Tobin Ehlisce132d82015-06-19 15:07:05 -06002595 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002596 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 -08002597 "%s", vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002598 }
2599 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002600 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002601}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002602
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002603// Print details of DS config to stdout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002604static VkBool32 printDSConfig(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002605{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002606 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002607 char ds_config_str[1024*256] = {0}; // TODO : Currently making this buffer HUGE w/o overrun protection. Need to be smarter, start smaller, and grow as needed.
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002608 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis93f89e82015-06-09 08:39:32 -06002609 if (pCB && pCB->lastBoundDescriptorSet) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002610 SET_NODE* pSet = getSetNode(my_data, pCB->lastBoundDescriptorSet);
Mark Lobodzinski39298632015-11-18 08:38:27 -07002611 DESCRIPTOR_POOL_NODE* pPool = getPoolNode(my_data, pSet->pool);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002612 // Print out pool details
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002613 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 +08002614 "Details for pool %#" PRIxLEAST64 ".", (uint64_t) pPool->pool);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002615 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002616 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 -06002617 "%s", poolStr.c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002618 // Print out set details
2619 char prefix[10];
2620 uint32_t index = 0;
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002621 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002622 "Details for descriptor set %#" PRIxLEAST64 ".", (uint64_t) pSet->set);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002623 LAYOUT_NODE* pLayout = pSet->pLayout;
2624 // Print layout details
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002625 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 -08002626 "Layout #%u, (object %#" PRIxLEAST64 ") for DS %#" PRIxLEAST64 ".", index+1, reinterpret_cast<uint64_t>(pLayout->layout), reinterpret_cast<uint64_t>(pSet->set));
Tobin Ehlis793ad302015-04-03 12:01:11 -06002627 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002628 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002629 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 -06002630 "%s", DSLstr.c_str());
Tobin Ehlis793ad302015-04-03 12:01:11 -06002631 index++;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002632 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
2633 if (pUpdate) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002634 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002635 "Update Chain [UC] for descriptor set %#" PRIxLEAST64 ":", (uint64_t) pSet->set);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002636 sprintf(prefix, " [UC] ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002637 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 -08002638 "%s", dynamic_display(pUpdate, prefix).c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002639 // TODO : If there is a "view" associated with this update, print CI for that view
Tobin Ehlisce132d82015-06-19 15:07:05 -06002640 } else {
Tobin Ehlisbf081f32015-06-15 08:41:17 -06002641 if (0 != pSet->descriptorCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002642 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002643 "No Update Chain for descriptor set %#" PRIxLEAST64 " which has %u descriptors (vkUpdateDescriptors has not been called)", (uint64_t) pSet->set, pSet->descriptorCount);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002644 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002645 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 +08002646 "FYI: No descriptors in descriptor set %#" PRIxLEAST64 ".", (uint64_t) pSet->set);
Tobin Ehlisbf081f32015-06-15 08:41:17 -06002647 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002648 }
2649 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002650 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002651}
2652
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002653static void printCB(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002654{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002655 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
David Pinedod8f83d82015-04-27 16:36:17 -06002656 if (pCB && pCB->pCmds.size() > 0) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002657 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 -06002658 "Cmds in CB %p", (void*)cb);
Courtney Goeltzenleuchterba348a92015-04-27 11:16:35 -06002659 vector<CMD_NODE*> pCmds = pCB->pCmds;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002660 for (auto ii=pCmds.begin(); ii!=pCmds.end(); ++ii) {
2661 // TODO : Need to pass cb as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002662 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 -08002663 " CMD#%" PRIu64 ": %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002664 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002665 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002666 // Nothing to print
2667 }
2668}
2669
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002670static VkBool32 synchAndPrintDSConfig(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002671{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002672 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002673 if (!(my_data->report_data->active_flags & VK_DEBUG_REPORT_INFO_BIT_EXT)) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002674 return skipCall;
Mike Stroyanba35e352015-08-12 17:11:28 -06002675 }
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002676 skipCall |= printDSConfig(my_data, cb);
2677 skipCall |= printPipeline(my_data, cb);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002678 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002679}
2680
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002681// Flags validation error if the associated call is made inside a render pass. The apiName
2682// routine should ONLY be called outside a render pass.
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06002683static VkBool32 insideRenderPass(const layer_data* my_data, GLOBAL_CB_NODE *pCB, const char *apiName)
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002684{
2685 VkBool32 inside = VK_FALSE;
2686 if (pCB->activeRenderPass) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002687 inside = log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002688 (uint64_t)pCB->commandBuffer, __LINE__, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002689 "%s: It is invalid to issue this call inside an active render pass (%#" PRIxLEAST64 ")",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002690 apiName, (uint64_t) pCB->activeRenderPass);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002691 }
2692 return inside;
2693}
2694
2695// Flags validation error if the associated call is made outside a render pass. The apiName
2696// routine should ONLY be called inside a render pass.
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06002697static VkBool32 outsideRenderPass(const layer_data* my_data, GLOBAL_CB_NODE *pCB, const char *apiName)
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002698{
2699 VkBool32 outside = VK_FALSE;
Mark Lobodzinski74635932015-12-18 15:35:38 -07002700 if (((pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) &&
2701 (!pCB->activeRenderPass)) ||
2702 ((pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) &&
2703 (!pCB->activeRenderPass) &&
2704 !(pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT))) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002705 outside = log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002706 (uint64_t)pCB->commandBuffer, __LINE__, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002707 "%s: This call must be issued inside an active render pass.", apiName);
2708 }
2709 return outside;
2710}
2711
Courtney Goeltzenleuchter6d8e8182015-11-25 14:31:49 -07002712static void init_draw_state(layer_data *my_data, const VkAllocationCallbacks *pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002713{
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002714 uint32_t report_flags = 0;
2715 uint32_t debug_action = 0;
2716 FILE *log_output = NULL;
2717 const char *option_str;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002718 VkDebugReportCallbackEXT callback;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002719 // initialize DrawState options
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002720 report_flags = getLayerOptionFlags("DrawStateReportFlags", 0);
2721 getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &debug_action);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002722
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002723 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002724 {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002725 option_str = getLayerOption("DrawStateLogFilename");
Tobin Ehlisb1df55e2015-09-15 09:55:54 -06002726 log_output = getLayerLogOutput(option_str, "DrawState");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002727 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002728 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002729 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002730 dbgInfo.pfnCallback = log_callback;
2731 dbgInfo.pUserData = log_output;
2732 dbgInfo.flags = report_flags;
2733 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002734 my_data->logging_callback.push_back(callback);
2735 }
2736
2737 if (debug_action & VK_DBG_LAYER_ACTION_DEBUG_OUTPUT) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002738 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002739 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002740 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002741 dbgInfo.pfnCallback = win32_debug_output_msg;
2742 dbgInfo.pUserData = log_output;
2743 dbgInfo.flags = report_flags;
2744 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002745 my_data->logging_callback.push_back(callback);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002746 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002747
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002748 if (!globalLockInitialized)
2749 {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002750 loader_platform_thread_create_mutex(&globalLock);
2751 globalLockInitialized = 1;
2752 }
2753}
2754
Chia-I Wu9ab61502015-11-06 06:42:02 +08002755VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance)
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002756{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002757 // TODOSC : Shouldn't need any customization here
Tobin Ehlis0b632332015-10-07 09:38:40 -06002758 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
2759 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002760 VkResult result = pTable->CreateInstance(pCreateInfo, pAllocator, pInstance);
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002761
2762 if (result == VK_SUCCESS) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002763 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
2764 my_data->report_data = debug_report_create_instance(
2765 pTable,
2766 *pInstance,
Chia-I Wud50a7d72015-10-26 20:48:51 +08002767 pCreateInfo->enabledExtensionNameCount,
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002768 pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchterd02a9642015-06-08 14:58:39 -06002769
Courtney Goeltzenleuchter6d8e8182015-11-25 14:31:49 -07002770 init_draw_state(my_data, pAllocator);
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002771 }
2772 return result;
2773}
2774
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002775/* hook DestroyInstance to remove tableInstanceMap entry */
Chia-I Wu9ab61502015-11-06 06:42:02 +08002776VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator)
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002777{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002778 // TODOSC : Shouldn't need any customization here
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002779 dispatch_key key = get_dispatch_key(instance);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002780 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
2781 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002782 pTable->DestroyInstance(instance, pAllocator);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002783
2784 // Clean up logging callback, if any
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002785 while (my_data->logging_callback.size() > 0) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002786 VkDebugReportCallbackEXT callback = my_data->logging_callback.back();
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002787 layer_destroy_msg_callback(my_data->report_data, callback, pAllocator);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002788 my_data->logging_callback.pop_back();
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002789 }
2790
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06002791 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002792 delete my_data->instance_dispatch_table;
2793 layer_data_map.erase(key);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002794 // TODO : Potential race here with separate threads creating/destroying instance
Tobin Ehlis0b632332015-10-07 09:38:40 -06002795 if (layer_data_map.empty()) {
Mike Stroyanfcb4ba62015-08-18 15:56:18 -06002796 // Release mutex when destroying last instance.
2797 loader_platform_thread_delete_mutex(&globalLock);
2798 globalLockInitialized = 0;
2799 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002800}
2801
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002802static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
2803{
Tony Barbour3b4732f2015-07-13 13:37:24 -06002804 uint32_t i;
Tobin Ehlis0b632332015-10-07 09:38:40 -06002805 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
2806 dev_data->device_extensions.debug_marker_enabled = false;
Michael Lentineabc5e922015-10-12 11:30:14 -05002807 dev_data->device_extensions.wsi_enabled = false;
2808
2809
2810 VkLayerDispatchTable *pDisp = dev_data->device_dispatch_table;
2811 PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr;
2812
Michael Lentineabc5e922015-10-12 11:30:14 -05002813 pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR) gpa(device, "vkCreateSwapchainKHR");
2814 pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR) gpa(device, "vkDestroySwapchainKHR");
2815 pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR) gpa(device, "vkGetSwapchainImagesKHR");
2816 pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR) gpa(device, "vkAcquireNextImageKHR");
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07002817 pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR) gpa(device, "vkQueuePresentKHR");
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002818
Chia-I Wud50a7d72015-10-26 20:48:51 +08002819 for (i = 0; i < pCreateInfo->enabledExtensionNameCount; i++) {
Ian Elliott05846062015-11-20 14:13:17 -07002820 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) {
Michael Lentineabc5e922015-10-12 11:30:14 -05002821 dev_data->device_extensions.wsi_enabled = true;
2822 }
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002823 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
Jon Ashburneab34492015-06-01 09:37:38 -06002824 /* Found a matching extension name, mark it enabled and init dispatch table*/
Tobin Ehlis0b632332015-10-07 09:38:40 -06002825 dev_data->device_extensions.debug_marker_enabled = true;
Jon Ashburn1d4b1282015-12-10 19:12:21 -07002826 initDebugMarkerTable(device);
2827
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002828 }
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002829 }
2830}
2831
Chia-I Wu9ab61502015-11-06 06:42:02 +08002832VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDevice* pDevice)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002833{
Tobin Ehlis0b632332015-10-07 09:38:40 -06002834 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08002835 VkResult result = dev_data->device_dispatch_table->CreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002836 // TODOSC : shouldn't need any customization here
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002837 if (result == VK_SUCCESS) {
2838 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002839 dev_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
Jon Ashburn747f2b62015-06-18 15:02:58 -06002840 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002841 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002842 return result;
2843}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002844
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002845// prototype
2846static void deleteRenderPasses(layer_data*);
Chia-I Wu9ab61502015-11-06 06:42:02 +08002847VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002848{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002849 // TODOSC : Shouldn't need any customization here
Jeremy Hayes5d29ce32015-06-19 11:37:38 -06002850 dispatch_key key = get_dispatch_key(device);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002851 layer_data* dev_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002852 // Free all the memory
2853 loader_platform_thread_lock_mutex(&globalLock);
2854 deletePipelines(dev_data);
2855 deleteRenderPasses(dev_data);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002856 deleteCommandBuffers(dev_data);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002857 deletePools(dev_data);
2858 deleteLayouts(dev_data);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002859 dev_data->imageViewMap.clear();
2860 dev_data->imageMap.clear();
2861 dev_data->bufferViewMap.clear();
2862 dev_data->bufferMap.clear();
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002863 loader_platform_thread_unlock_mutex(&globalLock);
2864
Chia-I Wuf7458c52015-10-26 21:10:41 +08002865 dev_data->device_dispatch_table->DestroyDevice(device, pAllocator);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002866 tableDebugMarkerMap.erase(key);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002867 delete dev_data->device_dispatch_table;
2868 layer_data_map.erase(key);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002869}
2870
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07002871static const VkExtensionProperties instance_extensions[] = {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002872 {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002873 VK_EXT_DEBUG_REPORT_EXTENSION_NAME,
2874 VK_EXT_DEBUG_REPORT_REVISION
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002875 }
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06002876};
2877
Chia-I Wu9ab61502015-11-06 06:42:02 +08002878VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002879 const char *pLayerName,
2880 uint32_t *pCount,
2881 VkExtensionProperties* pProperties)
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06002882{
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07002883 return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002884}
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06002885
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07002886static const VkLayerProperties ds_global_layers[] = {
2887 {
Michael Lentine03107b42015-12-11 10:49:51 -08002888 "VK_LAYER_LUNARG_draw_state",
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07002889 VK_API_VERSION,
2890 VK_MAKE_VERSION(0, 1, 0),
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -07002891 "Validation layer: draw_state",
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07002892 }
2893};
2894
Chia-I Wu9ab61502015-11-06 06:42:02 +08002895VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002896 uint32_t *pCount,
2897 VkLayerProperties* pProperties)
2898{
2899 return util_GetLayerProperties(ARRAY_SIZE(ds_global_layers),
2900 ds_global_layers,
2901 pCount, pProperties);
2902}
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06002903
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002904static const VkExtensionProperties ds_device_extensions[] = {
2905 {
2906 DEBUG_MARKER_EXTENSION_NAME,
2907 VK_MAKE_VERSION(0, 1, 0),
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002908 }
2909};
2910
2911static const VkLayerProperties ds_device_layers[] = {
2912 {
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -07002913 "draw_state",
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002914 VK_API_VERSION,
2915 VK_MAKE_VERSION(0, 1, 0),
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -07002916 "Validation layer: draw_state",
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002917 }
2918};
2919
Chia-I Wu9ab61502015-11-06 06:42:02 +08002920VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002921 VkPhysicalDevice physicalDevice,
2922 const char* pLayerName,
2923 uint32_t* pCount,
2924 VkExtensionProperties* pProperties)
2925{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07002926 // DrawState does not have any physical device extensions
Jon Ashburn751c4842015-11-02 17:37:20 -07002927 if (pLayerName == NULL) {
2928 dispatch_key key = get_dispatch_key(physicalDevice);
2929 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07002930 return my_data->instance_dispatch_table->EnumerateDeviceExtensionProperties(
Jon Ashburn751c4842015-11-02 17:37:20 -07002931 physicalDevice,
2932 NULL,
2933 pCount,
2934 pProperties);
2935 } else {
2936 return util_GetExtensionProperties(ARRAY_SIZE(ds_device_extensions),
2937 ds_device_extensions,
2938 pCount, pProperties);
2939 }
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002940}
2941
Chia-I Wu9ab61502015-11-06 06:42:02 +08002942VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002943 VkPhysicalDevice physicalDevice,
2944 uint32_t* pCount,
2945 VkLayerProperties* pProperties)
2946{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07002947 /* DrawState physical device layers are the same as global */
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002948 return util_GetLayerProperties(ARRAY_SIZE(ds_device_layers), ds_device_layers,
2949 pCount, pProperties);
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06002950}
2951
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07002952VkBool32 ValidateCmdBufImageLayouts(VkCommandBuffer cmdBuffer) {
2953 VkBool32 skip_call = false;
Michael Lentineabc5e922015-10-12 11:30:14 -05002954 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
2955 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
2956 for (auto cb_image_data : pCB->imageLayoutMap) {
2957 auto image_data = dev_data->imageLayoutMap.find(cb_image_data.first);
2958 if (image_data == dev_data->imageLayoutMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002959 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 -08002960 "Cannot submit cmd buffer using deleted image %" PRIu64 ".", reinterpret_cast<uint64_t>(cb_image_data.first));
Michael Lentineabc5e922015-10-12 11:30:14 -05002961 } else {
2962 if (dev_data->imageLayoutMap[cb_image_data.first]->layout != cb_image_data.second.initialLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002963 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 -05002964 "Cannot submit cmd buffer using image with layout %d when first use is %d.", dev_data->imageLayoutMap[cb_image_data.first]->layout, cb_image_data.second.initialLayout);
2965 }
2966 dev_data->imageLayoutMap[cb_image_data.first]->layout = cb_image_data.second.layout;
2967 }
2968 }
2969 return skip_call;
2970}
2971
Mark Young7a69c302016-01-07 09:48:47 -07002972VkBool32 validateAndIncrementResources(layer_data* my_data, GLOBAL_CB_NODE* pCB) {
2973 VkBool32 skip_call = false;
Michael Lentine700b0aa2015-10-30 17:57:32 -07002974 for (auto drawDataElement : pCB->drawData) {
2975 for (auto buffer : drawDataElement.buffers) {
2976 auto buffer_data = my_data->bufferMap.find(buffer);
2977 if (buffer_data == my_data->bufferMap.end()) {
2978 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",
2979 "Cannot submit cmd buffer using deleted buffer %" PRIu64 ".", reinterpret_cast<uint64_t>(buffer));
2980 } else {
2981 buffer_data->second.in_use.fetch_add(1);
2982 }
2983 }
2984 }
Michael Lentine2e068b22015-12-29 16:05:27 -06002985 return skip_call;
Michael Lentine700b0aa2015-10-30 17:57:32 -07002986}
2987
2988void decrementResources(layer_data* my_data, VkCommandBuffer cmdBuffer) {
2989 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cmdBuffer);
2990 for (auto drawDataElement : pCB->drawData) {
2991 for (auto buffer : drawDataElement.buffers) {
2992 auto buffer_data = my_data->bufferMap.find(buffer);
2993 if (buffer_data != my_data->bufferMap.end()) {
2994 buffer_data->second.in_use.fetch_sub(1);
2995 }
2996 }
2997 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06002998 for (auto queryStatePair : pCB->queryToStateMap) {
2999 my_data->queryToStateMap[queryStatePair.first] = queryStatePair.second;
3000 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003001}
3002
3003void decrementResources(layer_data* my_data, uint32_t fenceCount, const VkFence* pFences) {
3004 for (uint32_t i = 0; i < fenceCount; ++i) {
3005 auto fence_data = my_data->fenceMap.find(pFences[i]);
3006 if (fence_data == my_data->fenceMap.end() || !fence_data->second.needsSignaled) return;
3007 fence_data->second.needsSignaled = false;
3008 if (fence_data->second.priorFence != VK_NULL_HANDLE) {
3009 decrementResources(my_data, 1, &fence_data->second.priorFence);
3010 }
3011 for (auto cmdBuffer : fence_data->second.cmdBuffers) {
3012 decrementResources(my_data, cmdBuffer);
3013 }
3014 }
3015}
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07003016
Michael Lentine700b0aa2015-10-30 17:57:32 -07003017void decrementResources(layer_data* my_data, VkQueue queue) {
3018 auto queue_data = my_data->queueMap.find(queue);
3019 if (queue_data != my_data->queueMap.end()) {
3020 for (auto cmdBuffer : queue_data->second.untrackedCmdBuffers) {
3021 decrementResources(my_data, cmdBuffer);
3022 }
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07003023 queue_data->second.untrackedCmdBuffers.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07003024 decrementResources(my_data, 1, &queue_data->second.priorFence);
3025 }
3026}
3027
3028void trackCommandBuffers(layer_data* my_data, VkQueue queue, uint32_t cmdBufferCount, const VkCommandBuffer* pCmdBuffers, VkFence fence) {
3029 auto queue_data = my_data->queueMap.find(queue);
3030 if (fence != VK_NULL_HANDLE) {
3031 VkFence priorFence = VK_NULL_HANDLE;
3032 if (queue_data != my_data->queueMap.end()) {
3033 priorFence = queue_data->second.priorFence;
3034 queue_data->second.priorFence = fence;
3035 for (auto cmdBuffer : queue_data->second.untrackedCmdBuffers) {
3036 my_data->fenceMap[fence].cmdBuffers.push_back(cmdBuffer);
3037 }
3038 queue_data->second.untrackedCmdBuffers.clear();
3039 }
3040 my_data->fenceMap[fence].cmdBuffers.clear();
3041 my_data->fenceMap[fence].priorFence = priorFence;
3042 my_data->fenceMap[fence].needsSignaled = true;
3043 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
3044 my_data->fenceMap[fence].cmdBuffers.push_back(pCmdBuffers[i]);
3045 }
3046 } else {
3047 if (queue_data != my_data->queueMap.end()) {
3048 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
3049 queue_data->second.untrackedCmdBuffers.push_back(pCmdBuffers[i]);
3050 }
3051 }
3052 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003053 if (queue_data != my_data->queueMap.end()) {
3054 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
3055 my_data->inFlightCmdBuffers.insert(pCmdBuffers[i]);
3056 }
3057 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003058}
3059
Chia-I Wu9ab61502015-11-06 06:42:02 +08003060VK_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 -06003061{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003062 VkBool32 skipCall = VK_FALSE;
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06003063 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlis0b632332015-10-07 09:38:40 -06003064 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Tobin Ehlis651d9b02015-12-16 05:01:22 -07003065 // TODO : Any pCommandBuffers must have USAGE_SIMULTANEOUS_USE_BIT set or cannot already be executing on device
3066 // Same goes for any secondary CBs under the primary CB
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003067 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08003068 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Michael Lentine15a47882016-01-06 10:05:48 -06003069 for (uint32_t i=0; i < submit->waitSemaphoreCount; ++i) {
3070 if (dev_data->semaphoreSignaledMap[submit->pWaitSemaphores[i]]) {
3071 dev_data->semaphoreSignaledMap[submit->pWaitSemaphores[i]] = 0;
3072 } else {
3073 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",
3074 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
3075 reinterpret_cast<uint64_t>(queue), reinterpret_cast<uint64_t>(submit->pWaitSemaphores[i]));
3076 }
3077 }
3078 for (uint32_t i=0; i < submit->signalSemaphoreCount; ++i) {
3079 dev_data->semaphoreSignaledMap[submit->pSignalSemaphores[i]] = 1;
3080 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08003081 for (uint32_t i=0; i < submit->commandBufferCount; i++) {
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07003082
3083#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
3084 skipCall |= ValidateCmdBufImageLayouts(submit->pCommandBuffers[i]);
3085#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
3086
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003087 // Validate that cmd buffers have been updated
3088 pCB = getCBNode(dev_data, submit->pCommandBuffers[i]);
3089 loader_platform_thread_lock_mutex(&globalLock);
3090 pCB->submitCount++; // increment submit count
Michael Lentine700b0aa2015-10-30 17:57:32 -07003091 skipCall |= validateAndIncrementResources(dev_data, pCB);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003092 if ((pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT) && (pCB->submitCount > 1)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003093 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 -05003094 "CB %#" PRIxLEAST64 " was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted %#" PRIxLEAST64 " times.",
3095 reinterpret_cast<uint64_t>(pCB->commandBuffer), pCB->submitCount);
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003096 }
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003097 if (CB_RECORDED != pCB->state) {
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003098 // Flag error for using CB w/o vkEndCommandBuffer() called
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_NO_END_COMMAND_BUFFER, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003100 "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 -06003101 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003102 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003103 }
Tobin Ehlisc4bdde12015-05-27 14:30:06 -06003104 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06003105 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003106 trackCommandBuffers(dev_data, queue, submit->commandBufferCount, submit->pCommandBuffers, fence);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003107 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003108 if (VK_FALSE == skipCall)
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08003109 return dev_data->device_dispatch_table->QueueSubmit(queue, submitCount, pSubmits, fence);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003110 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003111}
3112
Michael Lentineb887b0a2015-12-29 14:12:11 -06003113bool cleanInFlightCmdBuffer(layer_data* my_data, VkCommandBuffer cmdBuffer) {
3114 bool skip_call = false;
3115 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cmdBuffer);
3116 for (auto queryEventsPair : pCB->waitedEventsBeforeQueryReset) {
3117 for (auto event : queryEventsPair.second) {
3118 if (my_data->eventMap[event].needsSignaled) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003119 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",
3120 "Cannot get query results on queryPool %" PRIu64 " with index %d which was guarded by unsignaled event %" PRIu64 ".",
Michael Lentineb887b0a2015-12-29 14:12:11 -06003121 reinterpret_cast<uint64_t>(queryEventsPair.first.pool), queryEventsPair.first.index, reinterpret_cast<uint64_t>(event));
3122 }
3123 }
3124 }
3125 return skip_call;
3126}
3127
Michael Lentine700b0aa2015-10-30 17:57:32 -07003128VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence* pFences, VkBool32 waitAll, uint64_t timeout)
3129{
3130 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3131 VkResult result = dev_data->device_dispatch_table->WaitForFences(device, fenceCount, pFences, waitAll, timeout);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003132 bool skip_call = false;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003133 if ((waitAll || fenceCount == 1) && result == VK_SUCCESS) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06003134 for (uint32_t i = 0; i < fenceCount; ++i) {
3135 for (auto cmdBuffer : dev_data->fenceMap[pFences[i]].cmdBuffers) {
3136 dev_data->inFlightCmdBuffers.erase(cmdBuffer);
3137 skip_call |= cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3138 }
3139 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003140 decrementResources(dev_data, fenceCount, pFences);
3141 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003142 if (skip_call)
Mark Lobodzinskice738852016-01-07 10:04:02 -07003143 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003144 return result;
3145}
3146
3147
3148VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetFenceStatus(VkDevice device, VkFence fence)
3149{
3150 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3151 VkResult result = dev_data->device_dispatch_table->GetFenceStatus(device, fence);
3152 if (result == VK_SUCCESS) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06003153 for (auto cmdBuffer : dev_data->fenceMap[fence].cmdBuffers) {
3154 dev_data->inFlightCmdBuffers.erase(cmdBuffer);
3155 cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3156 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003157 decrementResources(dev_data, 1, &fence);
3158 }
3159 return result;
3160}
3161
3162VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue* pQueue)
3163{
3164 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3165 dev_data->device_dispatch_table->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue);
3166 dev_data->deviceMap[device].queues.push_back(*pQueue);
3167 dev_data->queueMap[*pQueue].device = device;
3168}
3169
3170VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueueWaitIdle(VkQueue queue)
3171{
3172 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
3173 decrementResources(dev_data, queue);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003174 for (auto cmdBuffer : dev_data->inFlightCmdBuffers) {
3175 cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3176 }
3177 dev_data->inFlightCmdBuffers.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07003178 return dev_data->device_dispatch_table->QueueWaitIdle(queue);
3179}
3180
3181VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkDeviceWaitIdle(VkDevice device)
3182{
3183 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3184 auto device_data = dev_data->deviceMap.find(device);
3185 if (device_data != dev_data->deviceMap.end()) {
3186 for (auto queue : device_data->second.queues) {
3187 decrementResources(dev_data, queue);
3188 }
3189 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003190 for (auto cmdBuffer : dev_data->inFlightCmdBuffers) {
3191 cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3192 }
3193 dev_data->inFlightCmdBuffers.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07003194 return dev_data->device_dispatch_table->DeviceWaitIdle(device);
3195}
3196
Chia-I Wu9ab61502015-11-06 06:42:02 +08003197VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003198{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003199 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 -06003200 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003201}
3202
Chia-I Wu9ab61502015-11-06 06:42:02 +08003203VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySemaphore(VkDevice device, VkSemaphore semaphore, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003204{
Michael Lentine15a47882016-01-06 10:05:48 -06003205 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3206 dev_data->device_dispatch_table->DestroySemaphore(device, semaphore, pAllocator);
3207 dev_data->semaphoreSignaledMap.erase(semaphore);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003208 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003209}
3210
Chia-I Wu9ab61502015-11-06 06:42:02 +08003211VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003212{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003213 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 -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 vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool, 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->DestroyQueryPool(device, queryPool, 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
Mark Lobodzinskice738852016-01-07 10:04:02 -07003223VKAPI_ATTR VkResult VKAPI_CALL vkGetQueryPoolResults(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount,
Michael Lentineb887b0a2015-12-29 14:12:11 -06003224 size_t dataSize, void* pData, VkDeviceSize stride, VkQueryResultFlags flags) {
3225 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3226 unordered_map<QueryObject, vector<VkCommandBuffer>> queriesInFlight;
3227 GLOBAL_CB_NODE* pCB = nullptr;
3228 for (auto cmdBuffer : dev_data->inFlightCmdBuffers) {
3229 pCB = getCBNode(dev_data, cmdBuffer);
3230 for (auto queryStatePair : pCB->queryToStateMap) {
3231 queriesInFlight[queryStatePair.first].push_back(cmdBuffer);
3232 }
3233 }
3234 bool skip_call = false;
3235 for (uint32_t i = 0; i < queryCount; ++i) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003236 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06003237 auto queryElement = queriesInFlight.find(query);
3238 auto queryToStateElement = dev_data->queryToStateMap.find(query);
3239 if (queryToStateElement != dev_data->queryToStateMap.end()) {
3240 }
3241 // Available and in flight
3242 if(queryElement != queriesInFlight.end() && queryToStateElement != dev_data->queryToStateMap.end() && queryToStateElement->second) {
3243 for (auto cmdBuffer : queryElement->second) {
3244 pCB = getCBNode(dev_data, cmdBuffer);
3245 auto queryEventElement = pCB->waitedEventsBeforeQueryReset.find(query);
3246 if (queryEventElement == pCB->waitedEventsBeforeQueryReset.end()) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003247 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT, 0, __LINE__,
3248 DRAWSTATE_INVALID_QUERY, "DS", "Cannot get query results on queryPool %" PRIu64 " with index %d which is in flight.",
3249 reinterpret_cast<uint64_t>(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003250 } else {
3251 for (auto event : queryEventElement->second) {
3252 dev_data->eventMap[event].needsSignaled = true;
3253 }
3254 }
3255 }
3256 // Unavailable and in flight
3257 } else if (queryElement != queriesInFlight.end() && queryToStateElement != dev_data->queryToStateMap.end() && !queryToStateElement->second) {
3258 // TODO : Can there be the same query in use by multiple command buffers in flight?
3259 bool make_available = false;
3260 for (auto cmdBuffer : queryElement->second) {
3261 pCB = getCBNode(dev_data, cmdBuffer);
3262 make_available |= pCB->queryToStateMap[query];
3263 }
3264 if (!(((flags & VK_QUERY_RESULT_PARTIAL_BIT) || (flags & VK_QUERY_RESULT_WAIT_BIT)) && make_available)) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003265 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 -06003266 "Cannot get query results on queryPool %" PRIu64 " with index %d which is unavailable.",
Mark Lobodzinskice738852016-01-07 10:04:02 -07003267 reinterpret_cast<uint64_t>(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003268 }
3269 // Unavailable
3270 } else if (queryToStateElement != dev_data->queryToStateMap.end() && !queryToStateElement->second) {
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 // Unitialized
3275 } else if (queryToStateElement == dev_data->queryToStateMap.end()) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003276 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT, 0, __LINE__, DRAWSTATE_INVALID_QUERY, "DS",
Michael Lentineb887b0a2015-12-29 14:12:11 -06003277 "Cannot get query results on queryPool %" PRIu64 " with index %d which is uninitialized.",
Mark Lobodzinskice738852016-01-07 10:04:02 -07003278 reinterpret_cast<uint64_t>(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003279 }
3280 }
3281 if (skip_call)
Mark Lobodzinskice738852016-01-07 10:04:02 -07003282 return VK_ERROR_VALIDATION_FAILED_EXT;
3283 return dev_data->device_dispatch_table->GetQueryPoolResults(device, queryPool, firstQuery, queryCount, dataSize, pData, stride, flags);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003284}
3285
Mark Young7a69c302016-01-07 09:48:47 -07003286VkBool32 validateIdleBuffer(const layer_data* my_data, VkBuffer buffer) {
3287 VkBool32 skip_call = false;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003288 auto buffer_data = my_data->bufferMap.find(buffer);
3289 if (buffer_data == my_data->bufferMap.end()) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06003290 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 -07003291 "Cannot free buffer %" PRIxLEAST64 " that has not been allocated.", reinterpret_cast<uint64_t>(buffer));
3292 } else {
3293 if (buffer_data->second.in_use.load()) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06003294 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 -07003295 "Cannot free buffer %" PRIxLEAST64 " that is in use by a command buffer.", reinterpret_cast<uint64_t>(buffer));
3296
3297 }
3298 }
3299 return skip_call;
3300}
3301
Chia-I Wu9ab61502015-11-06 06:42:02 +08003302VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003303{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003304 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Young7a69c302016-01-07 09:48:47 -07003305 VkBool32 skip_call = false;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003306 if (!validateIdleBuffer(dev_data, buffer)) {
3307 dev_data->device_dispatch_table->DestroyBuffer(device, buffer, pAllocator);
3308 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08003309 dev_data->bufferMap.erase(buffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003310}
3311
Chia-I Wu9ab61502015-11-06 06:42:02 +08003312VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBufferView(VkDevice device, VkBufferView bufferView, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003313{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003314 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003315 dev_data->device_dispatch_table->DestroyBufferView(device, bufferView, pAllocator);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003316 dev_data->bufferViewMap.erase(bufferView);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003317}
3318
Chia-I Wu9ab61502015-11-06 06:42:02 +08003319VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003320{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003321 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003322 dev_data->device_dispatch_table->DestroyImage(device, image, pAllocator);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003323 dev_data->imageMap.erase(image);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003324}
3325
Chia-I Wu9ab61502015-11-06 06:42:02 +08003326VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyImageView(VkDevice device, VkImageView imageView, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003327{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003328 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 -06003329 // TODO : Clean up any internal data structures using this obj.
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 vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule, 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->DestroyShaderModule(device, shaderModule, 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 vkDestroyPipeline(VkDevice device, VkPipeline pipeline, 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->DestroyPipeline(device, pipeline, 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 vkDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout, 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->DestroyPipelineLayout(device, pipelineLayout, 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 vkDestroySampler(VkDevice device, VkSampler sampler, 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->DestroySampler(device, sampler, 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 vkDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout, 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->DestroyDescriptorSetLayout(device, descriptorSetLayout, 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 vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, 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->DestroyDescriptorPool(device, descriptorPool, 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 vkFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t count, const VkCommandBuffer *pCommandBuffers)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003369{
Mark Lobodzinski39298632015-11-18 08:38:27 -07003370 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3371
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07003372 for (uint32_t i = 0; i < count; i++) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003373 // Delete CB information structure, and remove from commandBufferMap
3374 auto cb = dev_data->commandBufferMap.find(pCommandBuffers[i]);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003375 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003376 if (cb != dev_data->commandBufferMap.end()) {
3377 delete (*cb).second;
3378 dev_data->commandBufferMap.erase(cb);
3379 }
3380
3381 // Remove commandBuffer reference from commandPoolMap
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003382 dev_data->commandPoolMap[commandPool].commandBuffers.remove(pCommandBuffers[i]);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003383 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003384 }
3385
3386 dev_data->device_dispatch_table->FreeCommandBuffers(device, commandPool, count, pCommandBuffers);
3387}
3388
3389VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkCommandPool* pCommandPool)
3390{
3391 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3392
3393 VkResult result = dev_data->device_dispatch_table->CreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
3394
3395 if (VK_SUCCESS == result) {
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003396 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003397 dev_data->commandPoolMap[*pCommandPool].createFlags = pCreateInfo->flags;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003398 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003399 }
3400 return result;
3401}
3402
3403VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks* pAllocator)
3404{
3405 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003406 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003407
3408 // Must remove cmdpool from cmdpoolmap, after removing all cmdbuffers in its list from the commandPoolMap
3409 if (dev_data->commandPoolMap.find(commandPool) != dev_data->commandPoolMap.end()) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003410 for (auto poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.begin(); poolCb != dev_data->commandPoolMap[commandPool].commandBuffers.end();) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003411 auto del_cb = dev_data->commandBufferMap.find(*poolCb);
3412 delete (*del_cb).second; // delete CB info structure
3413 dev_data->commandBufferMap.erase(del_cb); // Remove this command buffer from cbMap
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003414 poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.erase(poolCb); // Remove CB reference from commandPoolMap's list
Mark Lobodzinski39298632015-11-18 08:38:27 -07003415 }
3416 }
3417 dev_data->commandPoolMap.erase(commandPool);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003418
3419 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003420 dev_data->device_dispatch_table->DestroyCommandPool(device, commandPool, pAllocator);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003421}
3422
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003423VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandPool(
3424 VkDevice device,
3425 VkCommandPool commandPool,
3426 VkCommandPoolResetFlags flags)
3427{
3428 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003429 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003430
3431 result = dev_data->device_dispatch_table->ResetCommandPool(device, commandPool, flags);
3432 // Reset all of the CBs allocated from this pool
3433 if (VK_SUCCESS == result) {
3434 auto it = dev_data->commandPoolMap[commandPool].commandBuffers.begin();
3435 while (it != dev_data->commandPoolMap[commandPool].commandBuffers.end()) {
3436 resetCB(dev_data, (*it));
3437 ++it;
3438 }
3439 }
3440 return result;
3441}
3442
Chia-I Wu9ab61502015-11-06 06:42:02 +08003443VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003444{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003445 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 -06003446 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003447}
3448
Chia-I Wu9ab61502015-11-06 06:42:02 +08003449VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass, 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->DestroyRenderPass(device, renderPass, pAllocator);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003452 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003453}
3454
Chia-I Wu9ab61502015-11-06 06:42:02 +08003455VK_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 -06003456{
3457 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003458 VkResult result = dev_data->device_dispatch_table->CreateBuffer(device, pCreateInfo, pAllocator, pBuffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003459 if (VK_SUCCESS == result) {
3460 loader_platform_thread_lock_mutex(&globalLock);
3461 // 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 -07003462 dev_data->bufferMap[*pBuffer].create_info = unique_ptr<VkBufferCreateInfo>(new VkBufferCreateInfo(*pCreateInfo));
3463 dev_data->bufferMap[*pBuffer].in_use.store(0);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003464 loader_platform_thread_unlock_mutex(&globalLock);
3465 }
3466 return result;
3467}
3468
Chia-I Wu9ab61502015-11-06 06:42:02 +08003469VK_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 -06003470{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003471 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003472 VkResult result = dev_data->device_dispatch_table->CreateBufferView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003473 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003474 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003475 dev_data->bufferViewMap[*pView] = unique_ptr<VkBufferViewCreateInfo>(new VkBufferViewCreateInfo(*pCreateInfo));
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003476 loader_platform_thread_unlock_mutex(&globalLock);
3477 }
3478 return result;
3479}
3480
Chia-I Wu9ab61502015-11-06 06:42:02 +08003481VK_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 -06003482{
3483 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003484 VkResult result = dev_data->device_dispatch_table->CreateImage(device, pCreateInfo, pAllocator, pImage);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003485 if (VK_SUCCESS == result) {
Michael Lentineabc5e922015-10-12 11:30:14 -05003486 IMAGE_NODE* image_node = new IMAGE_NODE;
3487 image_node->layout = pCreateInfo->initialLayout;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003488 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003489 dev_data->imageMap[*pImage] = unique_ptr<VkImageCreateInfo>(new VkImageCreateInfo(*pCreateInfo));
Michael Lentineabc5e922015-10-12 11:30:14 -05003490 dev_data->imageLayoutMap[*pImage] = image_node;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003491 loader_platform_thread_unlock_mutex(&globalLock);
3492 }
3493 return result;
3494}
3495
Chia-I Wu9ab61502015-11-06 06:42:02 +08003496VK_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 -06003497{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003498 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003499 VkResult result = dev_data->device_dispatch_table->CreateImageView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003500 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003501 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003502 dev_data->imageViewMap[*pView] = unique_ptr<VkImageViewCreateInfo>(new VkImageViewCreateInfo(*pCreateInfo));
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003503 loader_platform_thread_unlock_mutex(&globalLock);
3504 }
3505 return result;
3506}
3507
Jon Ashburnc669cc62015-07-09 15:02:25 -06003508//TODO handle pipeline caches
Chia-I Wu9ab61502015-11-06 06:42:02 +08003509VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineCache(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003510 VkDevice device,
3511 const VkPipelineCacheCreateInfo* pCreateInfo,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003512 const VkAllocationCallbacks* pAllocator,
Jon Ashburnc669cc62015-07-09 15:02:25 -06003513 VkPipelineCache* pPipelineCache)
3514{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003515 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003516 VkResult result = dev_data->device_dispatch_table->CreatePipelineCache(device, pCreateInfo, pAllocator, pPipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003517 return result;
3518}
3519
Chia-I Wu9ab61502015-11-06 06:42:02 +08003520VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineCache(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003521 VkDevice device,
Chia-I Wuf7458c52015-10-26 21:10:41 +08003522 VkPipelineCache pipelineCache,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003523 const VkAllocationCallbacks* pAllocator)
Jon Ashburnc669cc62015-07-09 15:02:25 -06003524{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003525 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003526 dev_data->device_dispatch_table->DestroyPipelineCache(device, pipelineCache, pAllocator);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003527}
3528
Chia-I Wu9ab61502015-11-06 06:42:02 +08003529VKAPI_ATTR VkResult VKAPI_CALL vkGetPipelineCacheData(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003530 VkDevice device,
3531 VkPipelineCache pipelineCache,
Chia-I Wub16facd2015-10-26 19:17:06 +08003532 size_t* pDataSize,
Jon Ashburnc669cc62015-07-09 15:02:25 -06003533 void* pData)
3534{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003535 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wub16facd2015-10-26 19:17:06 +08003536 VkResult result = dev_data->device_dispatch_table->GetPipelineCacheData(device, pipelineCache, pDataSize, pData);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003537 return result;
3538}
3539
Chia-I Wu9ab61502015-11-06 06:42:02 +08003540VKAPI_ATTR VkResult VKAPI_CALL vkMergePipelineCaches(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003541 VkDevice device,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003542 VkPipelineCache dstCache,
Jon Ashburnc669cc62015-07-09 15:02:25 -06003543 uint32_t srcCacheCount,
3544 const VkPipelineCache* pSrcCaches)
3545{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003546 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003547 VkResult result = dev_data->device_dispatch_table->MergePipelineCaches(device, dstCache, srcCacheCount, pSrcCaches);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003548 return result;
3549}
3550
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003551VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateGraphicsPipelines(
3552 VkDevice device,
3553 VkPipelineCache pipelineCache,
3554 uint32_t count,
3555 const VkGraphicsPipelineCreateInfo *pCreateInfos,
3556 const VkAllocationCallbacks *pAllocator,
3557 VkPipeline *pPipelines)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003558{
Courtney Goeltzenleuchtered894072015-09-04 13:39:59 -06003559 VkResult result = VK_SUCCESS;
Tobin Ehlis11efc302015-09-16 10:33:53 -06003560 //TODO What to do with pipelineCache?
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003561 // The order of operations here is a little convoluted but gets the job done
3562 // 1. Pipeline create state is first shadowed into PIPELINE_NODE struct
3563 // 2. Create state is then validated (which uses flags setup during shadowing)
3564 // 3. If everything looks good, we'll then create the pipeline and add NODE to pipelineMap
Tobin Ehlis11efc302015-09-16 10:33:53 -06003565 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis65399772015-09-17 16:33:58 -06003566 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
3567 vector<PIPELINE_NODE*> pPipeNode(count);
Tobin Ehlis0b632332015-10-07 09:38:40 -06003568 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003569
Tobin Ehlis11efc302015-09-16 10:33:53 -06003570 uint32_t i=0;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003571 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003572
Tobin Ehlis11efc302015-09-16 10:33:53 -06003573 for (i=0; i<count; i++) {
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003574 pPipeNode[i] = initGraphicsPipeline(dev_data, &pCreateInfos[i], NULL);
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06003575 skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
Tobin Ehlis11efc302015-09-16 10:33:53 -06003576 }
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003577
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003578 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003579
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07003580 if (VK_FALSE == skipCall) {
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003581 result = dev_data->device_dispatch_table->CreateGraphicsPipelines(device,
3582 pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003583 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis11efc302015-09-16 10:33:53 -06003584 for (i=0; i<count; i++) {
3585 pPipeNode[i]->pipeline = pPipelines[i];
Chia-I Wue2fc5522015-10-26 20:04:44 +08003586 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
Tobin Ehlis11efc302015-09-16 10:33:53 -06003587 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003588 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisce132d82015-06-19 15:07:05 -06003589 } else {
Tobin Ehlis11efc302015-09-16 10:33:53 -06003590 for (i=0; i<count; i++) {
3591 if (pPipeNode[i]) {
3592 // If we allocated a pipeNode, need to clean it up here
3593 delete[] pPipeNode[i]->pVertexBindingDescriptions;
3594 delete[] pPipeNode[i]->pVertexAttributeDescriptions;
3595 delete[] pPipeNode[i]->pAttachments;
3596 delete pPipeNode[i];
3597 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003598 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003599 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003600 }
Courtney Goeltzenleuchtere2aaad02015-04-13 16:16:04 -06003601 return result;
3602}
3603
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003604VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateComputePipelines(
3605 VkDevice device,
3606 VkPipelineCache pipelineCache,
3607 uint32_t count,
3608 const VkComputePipelineCreateInfo *pCreateInfos,
3609 const VkAllocationCallbacks *pAllocator,
3610 VkPipeline *pPipelines)
3611{
3612 VkResult result = VK_SUCCESS;
3613 VkBool32 skipCall = VK_FALSE;
3614
3615 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
3616 vector<PIPELINE_NODE*> pPipeNode(count);
3617 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3618
3619 uint32_t i=0;
3620 loader_platform_thread_lock_mutex(&globalLock);
3621 for (i=0; i<count; i++) {
3622 // TODO: Verify compute stage bits
3623
3624 // Create and initialize internal tracking data structure
3625 pPipeNode[i] = new PIPELINE_NODE;
3626 memset((void*)pPipeNode[i], 0, sizeof(PIPELINE_NODE));
3627 memcpy(&pPipeNode[i]->computePipelineCI, (const void*)&pCreateInfos[i], sizeof(VkComputePipelineCreateInfo));
3628
3629 // TODO: Add Compute Pipeline Verification
3630 // skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
3631 }
3632 loader_platform_thread_unlock_mutex(&globalLock);
3633
3634 if (VK_FALSE == skipCall) {
3635 result = dev_data->device_dispatch_table->CreateComputePipelines(device, pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
3636 loader_platform_thread_lock_mutex(&globalLock);
3637 for (i=0; i<count; i++) {
3638 pPipeNode[i]->pipeline = pPipelines[i];
3639 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
3640 }
3641 loader_platform_thread_unlock_mutex(&globalLock);
3642 } else {
3643 for (i=0; i<count; i++) {
3644 if (pPipeNode[i]) {
3645 // Clean up any locally allocated data structures
3646 delete pPipeNode[i];
3647 }
3648 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003649 return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003650 }
3651 return result;
3652}
3653
Chia-I Wu9ab61502015-11-06 06:42:02 +08003654VK_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 -06003655{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003656 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003657 VkResult result = dev_data->device_dispatch_table->CreateSampler(device, pCreateInfo, pAllocator, pSampler);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003658 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003659 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003660 dev_data->sampleMap[*pSampler] = unique_ptr<SAMPLER_NODE>(new SAMPLER_NODE(pSampler, pCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003661 loader_platform_thread_unlock_mutex(&globalLock);
3662 }
3663 return result;
3664}
3665
Chia-I Wu9ab61502015-11-06 06:42:02 +08003666VK_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 -06003667{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003668 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003669 VkResult result = dev_data->device_dispatch_table->CreateDescriptorSetLayout(device, pCreateInfo, pAllocator, pSetLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003670 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003671 // TODOSC : Capture layout bindings set
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003672 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
3673 if (NULL == pNewNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003674 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 -06003675 "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003676 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003677 }
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06003678 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003679 pNewNode->createInfo.pBindings = new VkDescriptorSetLayoutBinding[pCreateInfo->bindingCount];
3680 memcpy((void*)pNewNode->createInfo.pBindings, pCreateInfo->pBindings, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->bindingCount);
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003681 // g++ does not like reserve with size 0
3682 if (pCreateInfo->bindingCount)
3683 pNewNode->bindings.reserve(pCreateInfo->bindingCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003684 uint32_t totalCount = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003685 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003686 if (!pNewNode->bindings.insert(pCreateInfo->pBindings[i].binding).second) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003687 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 +08003688 "duplicated binding number in VkDescriptorSetLayoutBinding"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003689 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003690 }
3691
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003692 totalCount += pCreateInfo->pBindings[i].descriptorCount;
3693 if (pCreateInfo->pBindings[i].pImmutableSamplers) {
3694 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBindings[i].pImmutableSamplers;
3695 *ppIS = new VkSampler[pCreateInfo->pBindings[i].descriptorCount];
3696 memcpy(*ppIS, pCreateInfo->pBindings[i].pImmutableSamplers, pCreateInfo->pBindings[i].descriptorCount*sizeof(VkSampler));
Tobin Ehlis793ad302015-04-03 12:01:11 -06003697 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003698 }
3699 if (totalCount > 0) {
Cody Northrop43751cc2015-10-26 14:07:35 -06003700 pNewNode->descriptorTypes.resize(totalCount);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06003701 pNewNode->stageFlags.resize(totalCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003702 uint32_t offset = 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06003703 uint32_t j = 0;
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07003704 VkDescriptorType dType;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003705 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003706 dType = pCreateInfo->pBindings[i].descriptorType;
3707 for (j = 0; j < pCreateInfo->pBindings[i].descriptorCount; j++) {
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07003708 pNewNode->descriptorTypes[offset + j] = dType;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003709 pNewNode->stageFlags[offset + j] = pCreateInfo->pBindings[i].stageFlags;
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07003710 if ((dType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
3711 (dType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
3712 pNewNode->dynamicDescriptorCount++;
3713 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003714 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06003715 offset += j;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003716 }
3717 }
3718 pNewNode->layout = *pSetLayout;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003719 pNewNode->startIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003720 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
3721 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003722 // Put new node at Head of global Layer list
3723 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07003724 dev_data->descriptorSetLayoutMap[*pSetLayout] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003725 loader_platform_thread_unlock_mutex(&globalLock);
3726 }
3727 return result;
3728}
3729
Chia-I Wu9ab61502015-11-06 06:42:02 +08003730VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003731{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003732 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003733 VkResult result = dev_data->device_dispatch_table->CreatePipelineLayout(device, pCreateInfo, pAllocator, pPipelineLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003734 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003735 // TODOSC : Merge capture of the setLayouts per pipeline
Tobin Ehlis559c6382015-11-05 09:52:49 -07003736 PIPELINE_LAYOUT_NODE& plNode = dev_data->pipelineLayoutMap[*pPipelineLayout];
Chia-I Wud50a7d72015-10-26 20:48:51 +08003737 plNode.descriptorSetLayouts.resize(pCreateInfo->setLayoutCount);
Tobin Ehlis644ff042015-10-20 10:11:55 -06003738 uint32_t i = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003739 for (i=0; i<pCreateInfo->setLayoutCount; ++i) {
Tobin Ehlis644ff042015-10-20 10:11:55 -06003740 plNode.descriptorSetLayouts[i] = pCreateInfo->pSetLayouts[i];
3741 }
Cody Northrop43751cc2015-10-26 14:07:35 -06003742 plNode.pushConstantRanges.resize(pCreateInfo->pushConstantRangeCount);
Tobin Ehlis644ff042015-10-20 10:11:55 -06003743 for (i=0; i<pCreateInfo->pushConstantRangeCount; ++i) {
3744 plNode.pushConstantRanges[i] = pCreateInfo->pPushConstantRanges[i];
3745 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06003746 }
3747 return result;
3748}
3749
Chia-I Wu9ab61502015-11-06 06:42:02 +08003750VK_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 -06003751{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003752 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003753 VkResult result = dev_data->device_dispatch_table->CreateDescriptorPool(device, pCreateInfo, pAllocator, pDescriptorPool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003754 if (VK_SUCCESS == result) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06003755 // Insert this pool into Global Pool LL at head
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003756 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 +08003757 "Created Descriptor Pool %#" PRIxLEAST64, (uint64_t) *pDescriptorPool))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003758 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003759 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003760 DESCRIPTOR_POOL_NODE* pNewNode = new DESCRIPTOR_POOL_NODE(*pDescriptorPool, pCreateInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003761 if (NULL == pNewNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003762 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 -07003763 "Out of memory while attempting to allocate DESCRIPTOR_POOL_NODE in vkCreateDescriptorPool()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003764 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisce132d82015-06-19 15:07:05 -06003765 } else {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003766 dev_data->descriptorPoolMap[*pDescriptorPool] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003767 }
3768 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisce132d82015-06-19 15:07:05 -06003769 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06003770 // Need to do anything if pool create fails?
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003771 }
3772 return result;
3773}
3774
Chia-I Wu9ab61502015-11-06 06:42:02 +08003775VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorPoolResetFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003776{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003777 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003778 VkResult result = dev_data->device_dispatch_table->ResetDescriptorPool(device, descriptorPool, flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003779 if (VK_SUCCESS == result) {
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003780 clearDescriptorPool(dev_data, device, descriptorPool, flags);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003781 }
3782 return result;
3783}
3784
Chia-I Wu9ab61502015-11-06 06:42:02 +08003785VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo* pAllocateInfo, VkDescriptorSet* pDescriptorSets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003786{
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003787 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis0b632332015-10-07 09:38:40 -06003788 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003789 // Verify that requested descriptorSets are available in pool
Mark Lobodzinski39298632015-11-18 08:38:27 -07003790 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003791 if (!pPoolNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003792 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 +08003793 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003794 } else { // Make sure pool has all the available descriptors before calling down chain
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003795 skipCall |= validate_descriptor_availability_in_pool(dev_data, pPoolNode, pAllocateInfo->setLayoutCount, pAllocateInfo->pSetLayouts);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003796 }
3797 if (skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003798 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003799 VkResult result = dev_data->device_dispatch_table->AllocateDescriptorSets(device, pAllocateInfo, pDescriptorSets);
Cody Northrop1e4f8022015-08-03 12:47:29 -06003800 if (VK_SUCCESS == result) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003801 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003802 if (pPoolNode) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003803 if (pAllocateInfo->setLayoutCount == 0) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003804 log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, pAllocateInfo->setLayoutCount, __LINE__, DRAWSTATE_NONE, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003805 "AllocateDescriptorSets called with 0 count");
Cody Northrop1e4f8022015-08-03 12:47:29 -06003806 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003807 for (uint32_t i = 0; i < pAllocateInfo->setLayoutCount; i++) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003808 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 +08003809 "Created Descriptor Set %#" PRIxLEAST64, (uint64_t) pDescriptorSets[i]);
Tobin Ehlis793ad302015-04-03 12:01:11 -06003810 // Create new set node and add to head of pool nodes
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003811 SET_NODE* pNewNode = new SET_NODE;
3812 if (NULL == pNewNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003813 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 +08003814 "Out of memory while attempting to allocate SET_NODE in vkAllocateDescriptorSets()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003815 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisce132d82015-06-19 15:07:05 -06003816 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003817 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlis8b5b28c2015-10-19 12:09:13 -06003818 // TODO : Pool should store a total count of each type of Descriptor available
3819 // When descriptors are allocated, decrement the count and validate here
3820 // that the count doesn't go below 0. One reset/free need to bump count back up.
Tobin Ehlis793ad302015-04-03 12:01:11 -06003821 // Insert set at head of Set LL for this pool
3822 pNewNode->pNext = pPoolNode->pSets;
3823 pPoolNode->pSets = pNewNode;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003824 LAYOUT_NODE* pLayout = getLayoutNode(dev_data, pAllocateInfo->pSetLayouts[i]);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003825 if (NULL == pLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003826 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 +08003827 "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 -07003828 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003829 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06003830 pNewNode->pLayout = pLayout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003831 pNewNode->pool = pAllocateInfo->descriptorPool;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003832 pNewNode->set = pDescriptorSets[i];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003833 pNewNode->descriptorCount = pLayout->endIndex + 1;
3834 if (pNewNode->descriptorCount) {
3835 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
3836 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
3837 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
3838 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08003839 dev_data->setMap[pDescriptorSets[i]] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003840 }
3841 }
3842 }
3843 }
3844 return result;
3845}
3846
Chia-I Wu9ab61502015-11-06 06:42:02 +08003847VK_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 -06003848{
Tobin Ehlise735c692015-10-08 13:13:50 -06003849 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis0b632332015-10-07 09:38:40 -06003850 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003851 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, descriptorPool);
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003852 if (pPoolNode && !(VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT & pPoolNode->createInfo.flags)) {
3853 // Can't Free from a NON_FREE pool
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003854 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 -06003855 "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 -06003856 }
3857 if (skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003858 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis0b632332015-10-07 09:38:40 -06003859 VkResult result = dev_data->device_dispatch_table->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003860 if (VK_SUCCESS == result) {
3861 // For each freed descriptor add it back into the pool as available
3862 for (uint32_t i=0; i<count; ++i) {
Chia-I Wue2fc5522015-10-26 20:04:44 +08003863 SET_NODE* pSet = dev_data->setMap[pDescriptorSets[i]]; // getSetNode() without locking
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003864 LAYOUT_NODE* pLayout = pSet->pLayout;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003865 uint32_t typeIndex = 0, poolSizeCount = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003866 for (uint32_t j=0; j<pLayout->createInfo.bindingCount; ++j) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003867 typeIndex = static_cast<uint32_t>(pLayout->createInfo.pBindings[j].descriptorType);
3868 poolSizeCount = pLayout->createInfo.pBindings[j].descriptorCount;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003869 pPoolNode->availableDescriptorTypeCount[typeIndex] += poolSizeCount;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003870 }
3871 }
3872 }
3873 // TODO : Any other clean-up or book-keeping to do here?
Tony Barbour34ec6922015-07-10 10:50:45 -06003874 return result;
3875}
3876
Chia-I Wu9ab61502015-11-06 06:42:02 +08003877VK_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 -06003878{
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06003879 // 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 -06003880 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08003881 if (!dsUpdate(dev_data, device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies)) {
3882 dev_data->device_dispatch_table->UpdateDescriptorSets(device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies);
Jon Ashburn3950e1b2015-05-20 09:00:28 -06003883 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003884}
3885
Chia-I Wu9ab61502015-11-06 06:42:02 +08003886VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo* pCreateInfo, VkCommandBuffer* pCommandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003887{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003888 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003889 VkResult result = dev_data->device_dispatch_table->AllocateCommandBuffers(device, pCreateInfo, pCommandBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003890 if (VK_SUCCESS == result) {
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07003891 for (uint32_t i = 0; i < pCreateInfo->bufferCount; i++) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003892 // Validate command pool
3893 if (dev_data->commandPoolMap.find(pCreateInfo->commandPool) != dev_data->commandPoolMap.end()) {
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003894 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003895 // Add command buffer to its commandPool map
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003896 dev_data->commandPoolMap[pCreateInfo->commandPool].commandBuffers.push_back(pCommandBuffer[i]);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003897 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
3898 // Add command buffer to map
3899 dev_data->commandBufferMap[pCommandBuffer[i]] = pCB;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003900 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003901 resetCB(dev_data, pCommandBuffer[i]);
3902 pCB->commandBuffer = pCommandBuffer[i];
3903 pCB->createInfo = *pCreateInfo;
Mark Lobodzinski39298632015-11-18 08:38:27 -07003904 }
3905 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003906 }
3907 return result;
3908}
3909
Chia-I Wu9ab61502015-11-06 06:42:02 +08003910VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo* pBeginInfo)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003911{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003912 VkBool32 skipCall = false;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003913 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06003914 // Validate command buffer level
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003915 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06003916 if (pCB) {
Mark Lobodzinski85881c72015-11-19 13:22:11 -07003917 if (pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
Chia-I Wue2fc5522015-10-26 20:04:44 +08003918 if (pBeginInfo->renderPass || pBeginInfo->framebuffer) {
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06003919 // These should be NULL for a Primary CB
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003920 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 Ehlis75f6fa92015-12-16 07:17:23 -07003921 "vkBeginCommandBuffer(): Primary Command Buffer (%p) may not specify framebuffer or renderpass parameters.", (void*)commandBuffer);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06003922 }
Tobin Ehlis75f6fa92015-12-16 07:17:23 -07003923 } else { // Secondary Command Buffer
Tobin Ehlis61b36f32015-12-16 08:19:42 -07003924 // TODO : Add check here from spec "If commandBuffer is a secondary command buffer and either the
3925 // occlusionQueryEnable member of pBeginInfo is VK_FALSE, or the precise occlusion queries feature
3926 // is not enabled, the queryFlags member of pBeginInfo must not contain VK_QUERY_CONTROL_PRECISE_BIT"
Tobin Ehlis651d9b02015-12-16 05:01:22 -07003927 if (pBeginInfo->flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT) {
3928 if (!pBeginInfo->renderPass) { // renderpass should NOT be null for an Secondary CB
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003929 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 -07003930 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) must specify a valid renderpass parameter.", (void*)commandBuffer);
3931 }
3932 if (!pBeginInfo->framebuffer) { // framebuffer may be null for an Secondary CB, but this affects perf
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003933 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 -07003934 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) may perform better if a valid framebuffer parameter is specified.", (void*)commandBuffer);
3935 } else {
3936 string errorString = "";
3937 VkRenderPass fbRP = dev_data->frameBufferMap[pBeginInfo->framebuffer]->renderPass;
3938 if (!verify_renderpass_compatibility(dev_data, fbRP, pBeginInfo->renderPass, errorString)) {
3939 // renderPass that framebuffer was created with must be compatible with local renderPass
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003940 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 -07003941 "vkBeginCommandBuffer(): Secondary Command Buffer (%p) renderPass (%#" PRIxLEAST64 ") is incompatible w/ framebuffer (%#" PRIxLEAST64 ") w/ render pass (%#" PRIxLEAST64 ") due to: %s",
3942 (void*)commandBuffer, (uint64_t)pBeginInfo->renderPass, (uint64_t)pBeginInfo->framebuffer, (uint64_t)fbRP, errorString.c_str());
3943 }
3944 }
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06003945 }
3946 }
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003947 pCB->beginInfo = *pBeginInfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003948 if (CB_RECORDING == pCB->state) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003949 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 -07003950 "vkBeginCommandBuffer(): Cannot call Begin on CB (%#" PRIxLEAST64 ") in the RECORDING state. Must first call vkEndCommandBuffer().", (uint64_t)commandBuffer);
3951 } else if (CB_RECORDED == pCB->state) {
3952 VkCommandPool cmdPool = pCB->createInfo.commandPool;
3953 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003954 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 -07003955 __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003956 "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.",
3957 (uint64_t) commandBuffer, (uint64_t) cmdPool);
3958 }
3959 }
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003960 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003961 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 +08003962 "In vkBeginCommandBuffer() and unable to find CommandBuffer Node for CB %p!", (void*)commandBuffer);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06003963 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003964 if (skipCall) {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003965 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter5fe086f2015-09-04 15:03:52 -06003966 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003967 VkResult result = dev_data->device_dispatch_table->BeginCommandBuffer(commandBuffer, pBeginInfo);
Mark Lobodzinski29b8d5a2015-11-12 16:14:04 -07003968 if ((VK_SUCCESS == result) && (pCB != NULL)) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07003969 if (CB_RECORDED == pCB->state) { resetCB(dev_data, commandBuffer); } pCB->state = CB_RECORDING; }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003970 return result;
3971}
3972
Chia-I Wu9ab61502015-11-06 06:42:02 +08003973VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEndCommandBuffer(VkCommandBuffer commandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003974{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003975 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchtered894072015-09-04 13:39:59 -06003976 VkResult result = VK_SUCCESS;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003977 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
3978 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis9c536442015-06-19 13:00:59 -06003979 if (pCB) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003980 if (pCB->state != CB_RECORDING) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003981 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkEndCommandBuffer()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003982 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003983 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003984 if (VK_FALSE == skipCall) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003985 result = dev_data->device_dispatch_table->EndCommandBuffer(commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003986 if (VK_SUCCESS == result) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003987 pCB->state = CB_RECORDED;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003988 // Reset CB status flags
3989 pCB->status = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003990 printCB(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003991 }
3992 } else {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003993 result = VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003994 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003995 return result;
3996}
3997
Chia-I Wu9ab61502015-11-06 06:42:02 +08003998VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003999{
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004000 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004001 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004002 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
4003 VkCommandPool cmdPool = pCB->createInfo.commandPool;
4004 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004005 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 -07004006 __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004007 "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.",
4008 (uint64_t) commandBuffer, (uint64_t) cmdPool);
4009 }
4010 if (skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004011 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004012 VkResult result = dev_data->device_dispatch_table->ResetCommandBuffer(commandBuffer, flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004013 if (VK_SUCCESS == result) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004014 resetCB(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004015 }
4016 return result;
4017}
4018
Chia-I Wu9ab61502015-11-06 06:42:02 +08004019VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004020{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004021 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004022 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4023 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004024 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004025 skipCall |= addCmd(dev_data, pCB, CMD_BINDPIPELINE, "vkCmdBindPipeline()");
4026 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
4027 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 -07004028 __LINE__, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004029 "Incorrectly binding compute pipeline (%#" PRIxLEAST64 ") during active RenderPass (%#" PRIxLEAST64 ")",
4030 (uint64_t) pipeline, (uint64_t) pCB->activeRenderPass);
4031 } else if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
4032 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdBindPipeline");
4033 }
4034
4035 PIPELINE_NODE* pPN = getPipeline(dev_data, pipeline);
4036 if (pPN) {
4037 pCB->lastBoundPipeline = pipeline;
4038 loader_platform_thread_lock_mutex(&globalLock);
4039 set_cb_pso_status(pCB, pPN);
4040 loader_platform_thread_unlock_mutex(&globalLock);
4041 skipCall |= validatePipelineState(dev_data, pCB, pipelineBindPoint, pipeline);
Tobin Ehlisce132d82015-06-19 15:07:05 -06004042 } else {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004043 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 -07004044 (uint64_t) pipeline, __LINE__, DRAWSTATE_INVALID_PIPELINE, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004045 "Attempt to bind Pipeline %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<uint64_t>(pipeline));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004046 }
4047 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004048 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004049 dev_data->device_dispatch_table->CmdBindPipeline(commandBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004050}
4051
Chia-I Wu9ab61502015-11-06 06:42:02 +08004052VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetViewport(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004053 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004054 uint32_t firstViewport,
4055 uint32_t viewportCount,
4056 const VkViewport* pViewports)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004057{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004058 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004059 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4060 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004061 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004062 skipCall |= addCmd(dev_data, pCB, CMD_SETVIEWPORTSTATE, "vkCmdSetViewport()");
4063 loader_platform_thread_lock_mutex(&globalLock);
4064 pCB->status |= CBSTATUS_VIEWPORT_SET;
4065 pCB->viewports.resize(viewportCount);
4066 memcpy(pCB->viewports.data(), pViewports, viewportCount * sizeof(VkViewport));
4067 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004068 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004069 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004070 dev_data->device_dispatch_table->CmdSetViewport(commandBuffer, firstViewport, viewportCount, pViewports);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004071}
4072
Chia-I Wu9ab61502015-11-06 06:42:02 +08004073VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetScissor(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004074 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004075 uint32_t firstScissor,
4076 uint32_t scissorCount,
4077 const VkRect2D* pScissors)
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004078{
4079 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004080 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4081 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004082 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004083 skipCall |= addCmd(dev_data, pCB, CMD_SETSCISSORSTATE, "vkCmdSetScissor()");
4084 loader_platform_thread_lock_mutex(&globalLock);
4085 pCB->status |= CBSTATUS_SCISSOR_SET;
4086 pCB->scissors.resize(scissorCount);
4087 memcpy(pCB->scissors.data(), pScissors, scissorCount * sizeof(VkRect2D));
4088 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004089 }
4090 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004091 dev_data->device_dispatch_table->CmdSetScissor(commandBuffer, firstScissor, scissorCount, pScissors);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004092}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004093
Chia-I Wu9ab61502015-11-06 06:42:02 +08004094VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004095{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004096 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004097 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4098 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004099 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004100 skipCall |= addCmd(dev_data, pCB, CMD_SETLINEWIDTHSTATE, "vkCmdSetLineWidth()");
4101 /* TODO: Do we still need this lock? */
4102 loader_platform_thread_lock_mutex(&globalLock);
4103 pCB->status |= CBSTATUS_LINE_WIDTH_SET;
4104 pCB->lineWidth = lineWidth;
4105 loader_platform_thread_unlock_mutex(&globalLock);
Cody Northrop12365112015-08-17 11:10:49 -06004106 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004107 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004108 dev_data->device_dispatch_table->CmdSetLineWidth(commandBuffer, lineWidth);
Cody Northrop12365112015-08-17 11:10:49 -06004109}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004110
Chia-I Wu9ab61502015-11-06 06:42:02 +08004111VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBias(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004112 VkCommandBuffer commandBuffer,
Chia-I Wud8c946a2015-10-26 19:08:09 +08004113 float depthBiasConstantFactor,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004114 float depthBiasClamp,
Chia-I Wud8c946a2015-10-26 19:08:09 +08004115 float depthBiasSlopeFactor)
Cody Northrop12365112015-08-17 11:10:49 -06004116{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004117 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004118 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4119 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northrop12365112015-08-17 11:10:49 -06004120 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004121 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBIASSTATE, "vkCmdSetDepthBias()");
4122 pCB->status |= CBSTATUS_DEPTH_BIAS_SET;
4123 pCB->depthBiasConstantFactor = depthBiasConstantFactor;
4124 pCB->depthBiasClamp = depthBiasClamp;
4125 pCB->depthBiasSlopeFactor = depthBiasSlopeFactor;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004126 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004127 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004128 dev_data->device_dispatch_table->CmdSetDepthBias(commandBuffer, depthBiasConstantFactor, depthBiasClamp, depthBiasSlopeFactor);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004129}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004130
Chia-I Wu9ab61502015-11-06 06:42:02 +08004131VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4])
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004132{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004133 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004134 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4135 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004136 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004137 skipCall |= addCmd(dev_data, pCB, CMD_SETBLENDSTATE, "vkCmdSetBlendConstants()");
4138 pCB->status |= CBSTATUS_BLEND_SET;
4139 memcpy(pCB->blendConstants, blendConstants, 4 * sizeof(float));
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004140 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004141 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004142 dev_data->device_dispatch_table->CmdSetBlendConstants(commandBuffer, blendConstants);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004143}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004144
Chia-I Wu9ab61502015-11-06 06:42:02 +08004145VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBounds(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004146 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004147 float minDepthBounds,
4148 float maxDepthBounds)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004149{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004150 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004151 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4152 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004153 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004154 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBOUNDSSTATE, "vkCmdSetDepthBounds()");
4155 pCB->status |= CBSTATUS_DEPTH_BOUNDS_SET;
4156 pCB->minDepthBounds = minDepthBounds;
4157 pCB->maxDepthBounds = maxDepthBounds;
Cody Northrop82485a82015-08-18 15:21:16 -06004158 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004159 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004160 dev_data->device_dispatch_table->CmdSetDepthBounds(commandBuffer, minDepthBounds, maxDepthBounds);
Cody Northrop82485a82015-08-18 15:21:16 -06004161}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004162
Chia-I Wu9ab61502015-11-06 06:42:02 +08004163VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilCompareMask(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004164 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004165 VkStencilFaceFlags faceMask,
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004166 uint32_t compareMask)
Cody Northrop82485a82015-08-18 15:21:16 -06004167{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004168 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004169 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4170 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northrop82485a82015-08-18 15:21:16 -06004171 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004172 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREADMASKSTATE, "vkCmdSetStencilCompareMask()");
4173 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4174 pCB->front.compareMask = compareMask;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004175 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004176 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4177 pCB->back.compareMask = compareMask;
4178 }
4179 /* TODO: Do we need to track front and back separately? */
4180 /* TODO: We aren't capturing the faceMask, do we need to? */
4181 pCB->status |= CBSTATUS_STENCIL_READ_MASK_SET;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004182 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004183 if (VK_FALSE == skipCall)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004184 dev_data->device_dispatch_table->CmdSetStencilCompareMask(commandBuffer, faceMask, compareMask);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004185}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004186
Chia-I Wu9ab61502015-11-06 06:42:02 +08004187VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilWriteMask(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004188 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004189 VkStencilFaceFlags faceMask,
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004190 uint32_t writeMask)
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004191{
4192 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004193 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4194 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004195 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004196 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILWRITEMASKSTATE, "vkCmdSetStencilWriteMask()");
4197 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4198 pCB->front.writeMask = writeMask;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004199 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004200 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4201 pCB->back.writeMask = writeMask;
4202 }
4203 pCB->status |= CBSTATUS_STENCIL_WRITE_MASK_SET;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004204 }
4205 if (VK_FALSE == skipCall)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004206 dev_data->device_dispatch_table->CmdSetStencilWriteMask(commandBuffer, faceMask, writeMask);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004207}
4208
Chia-I Wu9ab61502015-11-06 06:42:02 +08004209VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilReference(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004210 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004211 VkStencilFaceFlags faceMask,
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004212 uint32_t reference)
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004213{
4214 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004215 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4216 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004217 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004218 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREFERENCESTATE, "vkCmdSetStencilReference()");
4219 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4220 pCB->front.reference = reference;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004221 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004222 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4223 pCB->back.reference = reference;
4224 }
4225 pCB->status |= CBSTATUS_STENCIL_REFERENCE_SET;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004226 }
4227 if (VK_FALSE == skipCall)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004228 dev_data->device_dispatch_table->CmdSetStencilReference(commandBuffer, faceMask, reference);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004229}
4230
Chia-I Wu9ab61502015-11-06 06:42:02 +08004231VK_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 -06004232{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004233 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004234 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4235 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004236 if (pCB) {
Tobin Ehlisf6585052015-12-17 11:48:42 -07004237 if (pCB->state == CB_RECORDING) {
4238 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004239 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 -07004240 "Incorrectly binding compute DescriptorSets during active RenderPass (%#" PRIxLEAST64 ")", (uint64_t) pCB->activeRenderPass);
4241 } else if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
4242 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdBindDescriptorSets");
Mark Lobodzinski74635932015-12-18 15:35:38 -07004243 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07004244 if (VK_FALSE == skipCall) {
4245 // Track total count of dynamic descriptor types to make sure we have an offset for each one
4246 uint32_t totalDynamicDescriptors = 0;
4247 string errorString = "";
4248 uint32_t lastSetIndex = firstSet+setCount-1;
4249 if (lastSetIndex >= pCB->boundDescriptorSets.size())
Tobin Ehlis559c6382015-11-05 09:52:49 -07004250 pCB->boundDescriptorSets.resize(lastSetIndex+1);
Tobin Ehlisf6585052015-12-17 11:48:42 -07004251 VkDescriptorSet oldFinalBoundSet = pCB->boundDescriptorSets[lastSetIndex];
4252 for (uint32_t i=0; i<setCount; i++) {
4253 SET_NODE* pSet = getSetNode(dev_data, pDescriptorSets[i]);
4254 if (pSet) {
4255 loader_platform_thread_lock_mutex(&globalLock);
4256 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
4257 pCB->lastBoundPipelineLayout = layout;
4258 pCB->boundDescriptorSets[i+firstSet] = pDescriptorSets[i];
4259 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004260 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 -07004261 "DS %#" PRIxLEAST64 " bound on pipeline %s", (uint64_t) pDescriptorSets[i], string_VkPipelineBindPoint(pipelineBindPoint));
4262 if (!pSet->pUpdateStructs) {
4263 // TODO: Verify against Valid Usage
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004264 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 -07004265 "DS %#" PRIxLEAST64 " bound but it was never updated. You may want to either update it or not bind it.", (uint64_t) pDescriptorSets[i]);
4266 }
4267 // Verify that set being bound is compatible with overlapping setLayout of pipelineLayout
4268 if (!verify_set_layout_compatibility(dev_data, pSet, layout, i+firstSet, errorString)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004269 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 -07004270 "descriptorSet #%u being bound is not compatible with overlapping layout in pipelineLayout due to: %s", i, errorString.c_str());
4271 }
4272 if (pSet->pLayout->dynamicDescriptorCount) {
4273 // First make sure we won't overstep bounds of pDynamicOffsets array
4274 if ((totalDynamicDescriptors + pSet->pLayout->dynamicDescriptorCount) > dynamicOffsetCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004275 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 -07004276 "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.",
4277 i, (uint64_t) pDescriptorSets[i], pSet->pLayout->dynamicDescriptorCount, (dynamicOffsetCount - totalDynamicDescriptors));
4278 } else { // Store dynamic offsets with the set
4279 const uint32_t* pStartDynOffset = pDynamicOffsets + totalDynamicDescriptors;
4280 pSet->dynamicOffsets.assign(pStartDynOffset, pStartDynOffset + pSet->pLayout->dynamicDescriptorCount);
4281 totalDynamicDescriptors += pSet->pLayout->dynamicDescriptorCount;
4282 }
4283 }
4284 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004285 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 -07004286 "Attempt to bind DS %#" PRIxLEAST64 " that doesn't exist!", (uint64_t) pDescriptorSets[i]);
4287 }
4288 }
4289 skipCall |= addCmd(dev_data, pCB, CMD_BINDDESCRIPTORSETS, "vkCmdBindDescrsiptorSets()");
4290 // For any previously bound sets, need to set them to "invalid" if they were disturbed by this update
4291 if (firstSet > 0) { // Check set #s below the first bound set
4292 for (uint32_t i=0; i<firstSet; ++i) {
4293 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 -07004294 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 -07004295 "DescriptorSetDS %#" PRIxLEAST64 " previously bound as set #%u was disturbed by newly bound pipelineLayout (%#" PRIxLEAST64 ")", (uint64_t) pCB->boundDescriptorSets[i], i, (uint64_t) layout);
4296 pCB->boundDescriptorSets[i] = VK_NULL_HANDLE;
4297 }
4298 }
4299 }
4300 // Check if newly last bound set invalidates any remaining bound sets
4301 if ((pCB->boundDescriptorSets.size()-1) > (lastSetIndex)) {
4302 if (oldFinalBoundSet && !verify_set_layout_compatibility(dev_data, dev_data->setMap[oldFinalBoundSet], layout, lastSetIndex, errorString)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004303 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 -07004304 "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);
4305 pCB->boundDescriptorSets.resize(lastSetIndex+1);
4306 }
4307 }
4308 // dynamicOffsetCount must equal the total number of dynamic descriptors in the sets being bound
4309 if (totalDynamicDescriptors != dynamicOffsetCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004310 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 -07004311 "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 -07004312 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004313 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07004314 } else {
4315 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindDescriptorSets()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004316 }
4317 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004318 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004319 dev_data->device_dispatch_table->CmdBindDescriptorSets(commandBuffer, pipelineBindPoint, layout, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004320}
4321
Chia-I Wu9ab61502015-11-06 06:42:02 +08004322VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004323{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004324 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004325 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4326 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004327 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004328 skipCall |= addCmd(dev_data, pCB, CMD_BINDINDEXBUFFER, "vkCmdBindIndexBuffer()");
4329 VkDeviceSize offset_align = 0;
4330 switch (indexType) {
4331 case VK_INDEX_TYPE_UINT16:
4332 offset_align = 2;
4333 break;
4334 case VK_INDEX_TYPE_UINT32:
4335 offset_align = 4;
4336 break;
4337 default:
4338 // ParamChecker should catch bad enum, we'll also throw alignment error below if offset_align stays 0
4339 break;
4340 }
4341 if (!offset_align || (offset % offset_align)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004342 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 -07004343 "vkCmdBindIndexBuffer() offset (%#" PRIxLEAST64 ") does not fall on alignment (%s) boundary.", offset, string_VkIndexType(indexType));
Tobin Ehlis9c536442015-06-19 13:00:59 -06004344 }
Tobin Ehlisc4c23182015-09-17 12:24:13 -06004345 pCB->status |= CBSTATUS_INDEX_BUFFER_BOUND;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004346 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004347 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004348 dev_data->device_dispatch_table->CmdBindIndexBuffer(commandBuffer, buffer, offset, indexType);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004349}
4350
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07004351void updateResourceTracking(GLOBAL_CB_NODE* pCB, uint32_t firstBinding, uint32_t bindingCount, const VkBuffer* pBuffers) {
4352 uint32_t end = firstBinding + bindingCount;
Michael Lentine700b0aa2015-10-30 17:57:32 -07004353 if (pCB->currentDrawData.buffers.size() < end) {
4354 pCB->currentDrawData.buffers.resize(end);
4355 }
4356 for (uint32_t i = 0; i < bindingCount; ++i) {
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07004357 pCB->currentDrawData.buffers[i + firstBinding] = pBuffers[i];
Michael Lentine700b0aa2015-10-30 17:57:32 -07004358 }
4359}
4360
4361void updateResourceTrackingOnDraw(GLOBAL_CB_NODE* pCB) {
4362 pCB->drawData.push_back(pCB->currentDrawData);
4363}
4364
Chia-I Wu9ab61502015-11-06 06:42:02 +08004365VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindVertexBuffers(
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07004366 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004367 uint32_t firstBinding,
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06004368 uint32_t bindingCount,
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07004369 const VkBuffer *pBuffers,
4370 const VkDeviceSize *pOffsets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004371{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004372 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004373 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4374 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004375 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004376 addCmd(dev_data, pCB, CMD_BINDVERTEXBUFFER, "vkCmdBindVertexBuffer()");
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07004377 updateResourceTracking(pCB, firstBinding, bindingCount, pBuffers);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004378 } else {
Mark Youngad779052016-01-06 14:26:04 -07004379 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindVertexBuffer()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004380 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004381 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004382 dev_data->device_dispatch_table->CmdBindVertexBuffers(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004383}
4384
Chia-I Wu9ab61502015-11-06 06:42:02 +08004385VK_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 -06004386{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004387 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004388 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4389 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004390 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004391 skipCall |= addCmd(dev_data, pCB, CMD_DRAW, "vkCmdDraw()");
4392 pCB->drawCount[DRAW]++;
4393 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
4394 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004395 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 -07004396 "vkCmdDraw() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW]++);
4397 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004398 if (VK_FALSE == skipCall) {
4399 updateResourceTrackingOnDraw(pCB);
4400 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004401 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDraw");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004402 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004403 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004404 dev_data->device_dispatch_table->CmdDraw(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004405}
4406
Chia-I Wu9ab61502015-11-06 06:42:02 +08004407VK_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 -06004408{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004409 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4410 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004411 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004412 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004413 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXED, "vkCmdDrawIndexed()");
4414 pCB->drawCount[DRAW_INDEXED]++;
4415 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
4416 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004417 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 -07004418 "vkCmdDrawIndexed() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED]++);
4419 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004420 if (VK_FALSE == skipCall) {
4421 updateResourceTrackingOnDraw(pCB);
4422 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004423 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexed");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004424 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004425 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004426 dev_data->device_dispatch_table->CmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004427}
4428
Chia-I Wu9ab61502015-11-06 06:42:02 +08004429VK_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 -06004430{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004431 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4432 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004433 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004434 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004435 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDIRECT, "vkCmdDrawIndirect()");
4436 pCB->drawCount[DRAW_INDIRECT]++;
4437 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
4438 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004439 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 -07004440 "vkCmdDrawIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
4441 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004442 if (VK_FALSE == skipCall) {
4443 updateResourceTrackingOnDraw(pCB);
4444 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004445 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndirect");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004446 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004447 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004448 dev_data->device_dispatch_table->CmdDrawIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004449}
4450
Chia-I Wu9ab61502015-11-06 06:42:02 +08004451VK_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 -06004452{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004453 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004454 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4455 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004456 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004457 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXEDINDIRECT, "vkCmdDrawIndexedIndirect()");
4458 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
4459 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
4460 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004461 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 -07004462 "vkCmdDrawIndexedIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
4463 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004464 if (VK_FALSE == skipCall) {
4465 updateResourceTrackingOnDraw(pCB);
4466 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004467 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexedIndirect");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004468 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004469 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004470 dev_data->device_dispatch_table->CmdDrawIndexedIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004471}
4472
Chia-I Wu9ab61502015-11-06 06:42:02 +08004473VK_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 -06004474{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004475 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004476 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4477 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004478 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004479 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCH, "vkCmdDispatch()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004480 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatch");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004481 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004482 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004483 dev_data->device_dispatch_table->CmdDispatch(commandBuffer, x, y, z);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004484}
4485
Chia-I Wu9ab61502015-11-06 06:42:02 +08004486VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004487{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004488 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004489 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4490 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004491 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004492 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCHINDIRECT, "vkCmdDispatchIndirect()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004493 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatchIndirect");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004494 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004495 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004496 dev_data->device_dispatch_table->CmdDispatchIndirect(commandBuffer, buffer, offset);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004497}
4498
Chia-I Wu9ab61502015-11-06 06:42:02 +08004499VK_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 -06004500{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004501 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004502 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4503 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004504 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004505 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFER, "vkCmdCopyBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004506 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004507 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004508 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004509 dev_data->device_dispatch_table->CmdCopyBuffer(commandBuffer, srcBuffer, dstBuffer, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004510}
4511
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07004512VkBool32 VerifySourceImageLayout(VkCommandBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout) {
4513 VkBool32 skip_call = false;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07004514
4515#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4516 // TODO: Fix -- initialLayout may have been set in a previous command buffer
4517 return skip_call;
4518#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4519
Michael Lentineabc5e922015-10-12 11:30:14 -05004520 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4521 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4522 auto src_image_element = pCB->imageLayoutMap.find(srcImage);
4523 if (src_image_element == pCB->imageLayoutMap.end()) {
4524 pCB->imageLayoutMap[srcImage].initialLayout = srcImageLayout;
4525 pCB->imageLayoutMap[srcImage].layout = srcImageLayout;
4526 return false;
4527 }
4528 if (src_image_element->second.layout != srcImageLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004529 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 -05004530 "Cannot copy from an image whose source layout is %d and doesn't match the current layout %d.", srcImageLayout, src_image_element->second.layout);
4531 }
4532 if (srcImageLayout != VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL) {
4533 if (srcImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004534 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004535 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 -05004536 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Michael Lentineabc5e922015-10-12 11:30:14 -05004537 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004538 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 -05004539 "Layout for input image is %d but can only be TRANSFER_SRC_OPTIMAL or GENERAL.", srcImageLayout);
Michael Lentineabc5e922015-10-12 11:30:14 -05004540 }
4541 }
4542 return skip_call;
4543}
4544
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07004545VkBool32 VerifyDestImageLayout(VkCommandBuffer cmdBuffer, VkImage destImage, VkImageLayout destImageLayout) {
4546 VkBool32 skip_call = false;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07004547
4548#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4549 // TODO: Fix -- initialLayout may have been set in a previous command buffer
4550 return skip_call;
4551#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4552
Michael Lentineabc5e922015-10-12 11:30:14 -05004553 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4554 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4555 auto dest_image_element = pCB->imageLayoutMap.find(destImage);
4556 if (dest_image_element == pCB->imageLayoutMap.end()) {
4557 pCB->imageLayoutMap[destImage].initialLayout = destImageLayout;
4558 pCB->imageLayoutMap[destImage].layout = destImageLayout;
4559 return false;
4560 }
4561 if (dest_image_element->second.layout != destImageLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004562 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 -05004563 "Cannot copy from an image whose dest layout is %d and doesn't match the current layout %d.", destImageLayout, dest_image_element->second.layout);
4564 }
4565 if (destImageLayout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) {
4566 if (destImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004567 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004568 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 -05004569 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
4570 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004571 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 -05004572 "Layout for output image is %d but can only be TRANSFER_DST_OPTIMAL or GENERAL.", destImageLayout);
4573 }
4574 }
4575 return skip_call;
4576}
4577
Chia-I Wu9ab61502015-11-06 06:42:02 +08004578VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004579 VkImage srcImage,
4580 VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004581 VkImage dstImage,
4582 VkImageLayout dstImageLayout,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004583 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004584{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004585 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004586 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4587 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004588 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004589 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGE, "vkCmdCopyImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004590 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImage");
Michael Lentineabc5e922015-10-12 11:30:14 -05004591 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
4592 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004593 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004594 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004595 dev_data->device_dispatch_table->CmdCopyImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004596}
4597
Chia-I Wu9ab61502015-11-06 06:42:02 +08004598VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBlitImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004599 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004600 VkImage dstImage, VkImageLayout dstImageLayout,
Mark Lobodzinskiee5eef12015-05-22 14:43:25 -05004601 uint32_t regionCount, const VkImageBlit* pRegions,
Chia-I Wub99df442015-10-26 16:49:32 +08004602 VkFilter filter)
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004603{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004604 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004605 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4606 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004607 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004608 skipCall |= addCmd(dev_data, pCB, CMD_BLITIMAGE, "vkCmdBlitImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004609 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBlitImage");
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004610 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004611 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004612 dev_data->device_dispatch_table->CmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter);
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004613}
4614
Chia-I Wu9ab61502015-11-06 06:42:02 +08004615VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004616 VkBuffer srcBuffer,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004617 VkImage dstImage, VkImageLayout dstImageLayout,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004618 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004619{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004620 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004621 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4622 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004623 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004624 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFERTOIMAGE, "vkCmdCopyBufferToImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004625 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBufferToImage");
Michael Lentineabc5e922015-10-12 11:30:14 -05004626 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004627 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004628 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004629 dev_data->device_dispatch_table->CmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004630}
4631
Chia-I Wu9ab61502015-11-06 06:42:02 +08004632VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004633 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004634 VkBuffer dstBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004635 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004636{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004637 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004638 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4639 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004640 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004641 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGETOBUFFER, "vkCmdCopyImageToBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004642 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImageToBuffer");
Michael Lentineabc5e922015-10-12 11:30:14 -05004643 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004644 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004645 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004646 dev_data->device_dispatch_table->CmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004647}
4648
Chia-I Wu9ab61502015-11-06 06:42:02 +08004649VK_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 -06004650{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004651 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004652 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4653 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004654 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004655 skipCall |= addCmd(dev_data, pCB, CMD_UPDATEBUFFER, "vkCmdUpdateBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004656 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyUpdateBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004657 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004658 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004659 dev_data->device_dispatch_table->CmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004660}
4661
Chia-I Wu9ab61502015-11-06 06:42:02 +08004662VK_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 -06004663{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004664 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004665 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4666 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004667 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004668 skipCall |= addCmd(dev_data, pCB, CMD_FILLBUFFER, "vkCmdFillBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004669 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyFillBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004670 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004671 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004672 dev_data->device_dispatch_table->CmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004673}
4674
Chia-I Wu9ab61502015-11-06 06:42:02 +08004675VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearAttachments(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004676 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004677 uint32_t attachmentCount,
4678 const VkClearAttachment* pAttachments,
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004679 uint32_t rectCount,
Courtney Goeltzenleuchter4ca43f62015-10-15 18:22:08 -06004680 const VkClearRect* pRects)
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004681{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004682 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004683 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4684 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004685 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004686 skipCall |= addCmd(dev_data, pCB, CMD_CLEARATTACHMENTS, "vkCmdClearAttachments()");
4687 // Warn if this is issued prior to Draw Cmd and clearing the entire attachment
4688 if (!hasDrawCmd(pCB) &&
4689 (pCB->activeRenderPassBeginInfo.renderArea.extent.width == pRects[0].rect.extent.width) &&
4690 (pCB->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) {
4691 // TODO : commandBuffer should be srcObj
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004692 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 -07004693 "vkCmdClearAttachments() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
4694 " 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 -06004695 }
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004696 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdClearAttachments");
4697 }
4698
4699 // Validate that attachment is in reference list of active subpass
4700 if (pCB->activeRenderPass) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07004701 const VkRenderPassCreateInfo *pRPCI = dev_data->renderPassMap[pCB->activeRenderPass]->pCreateInfo;
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004702 const VkSubpassDescription *pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
4703
4704 for (uint32_t attachment_idx = 0; attachment_idx < attachmentCount; attachment_idx++) {
4705 const VkClearAttachment *attachment = &pAttachments[attachment_idx];
4706 if (attachment->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) {
4707 VkBool32 found = VK_FALSE;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004708 for (uint32_t i = 0; i < pSD->colorAttachmentCount; i++) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004709 if (attachment->colorAttachment == pSD->pColorAttachments[i].attachment) {
4710 found = VK_TRUE;
4711 break;
4712 }
4713 }
4714 if (VK_FALSE == found) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004715 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 -07004716 (uint64_t)commandBuffer, __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004717 "vkCmdClearAttachments() attachment index %d not found in attachment reference array of active subpass %d",
4718 attachment->colorAttachment, pCB->activeSubpass);
4719 }
4720 } else if (attachment->aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) {
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07004721 if (!pSD->pDepthStencilAttachment || // Says no DS will be used in active subpass
Mark Lobodzinski2fd355a2015-11-18 08:58:31 -07004722 (pSD->pDepthStencilAttachment->attachment == VK_ATTACHMENT_UNUSED)) { // Says no DS will be used in active subpass
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07004723
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004724 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 -07004725 (uint64_t)commandBuffer, __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07004726 "vkCmdClearAttachments() attachment index %d does not match depthStencilAttachment.attachment (%d) found in active subpass %d",
4727 attachment->colorAttachment,
4728 (pSD->pDepthStencilAttachment) ? pSD->pDepthStencilAttachment->attachment : VK_ATTACHMENT_UNUSED,
4729 pCB->activeSubpass);
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004730 }
4731 }
4732 }
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004733 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004734 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004735 dev_data->device_dispatch_table->CmdClearAttachments(commandBuffer, attachmentCount, pAttachments, rectCount, pRects);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004736}
4737
Chia-I Wu9ab61502015-11-06 06:42:02 +08004738VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearColorImage(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004739 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06004740 VkImage image, VkImageLayout imageLayout,
Chris Forbesf0796e12015-06-24 14:34:53 +12004741 const VkClearColorValue *pColor,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06004742 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004743{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004744 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004745 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4746 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004747 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004748 skipCall |= addCmd(dev_data, pCB, CMD_CLEARCOLORIMAGE, "vkCmdClearColorImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004749 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearColorImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004750 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004751 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004752 dev_data->device_dispatch_table->CmdClearColorImage(commandBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004753}
4754
Chia-I Wu9ab61502015-11-06 06:42:02 +08004755VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearDepthStencilImage(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004756 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter45df9e12015-09-15 18:03:22 -06004757 VkImage image, VkImageLayout imageLayout,
4758 const VkClearDepthStencilValue *pDepthStencil,
4759 uint32_t rangeCount,
4760 const VkImageSubresourceRange* pRanges)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004761{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004762 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004763 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4764 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004765 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004766 skipCall |= addCmd(dev_data, pCB, CMD_CLEARDEPTHSTENCILIMAGE, "vkCmdClearDepthStencilImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004767 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearDepthStencilImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004768 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004769 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004770 dev_data->device_dispatch_table->CmdClearDepthStencilImage(commandBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004771}
4772
Chia-I Wu9ab61502015-11-06 06:42:02 +08004773VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResolveImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004774 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004775 VkImage dstImage, VkImageLayout dstImageLayout,
Tony Barbour6865d4a2015-04-13 15:02:52 -06004776 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004777{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004778 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004779 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4780 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004781 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004782 skipCall |= addCmd(dev_data, pCB, CMD_RESOLVEIMAGE, "vkCmdResolveImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004783 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResolveImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004784 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004785 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004786 dev_data->device_dispatch_table->CmdResolveImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004787}
4788
Chia-I Wu9ab61502015-11-06 06:42:02 +08004789VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004790{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004791 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004792 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4793 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004794 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004795 skipCall |= addCmd(dev_data, pCB, CMD_SETEVENT, "vkCmdSetEvent()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004796 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdSetEvent");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004797 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004798 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004799 dev_data->device_dispatch_table->CmdSetEvent(commandBuffer, event, stageMask);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004800}
4801
Chia-I Wu9ab61502015-11-06 06:42:02 +08004802VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004803{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004804 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004805 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4806 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004807 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004808 skipCall |= addCmd(dev_data, pCB, CMD_RESETEVENT, "vkCmdResetEvent()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004809 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResetEvent");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004810 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004811 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004812 dev_data->device_dispatch_table->CmdResetEvent(commandBuffer, event, stageMask);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004813}
4814
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07004815VkBool32 TransitionImageLayouts(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const void* const* ppMemBarriers) {
Michael Lentineabc5e922015-10-12 11:30:14 -05004816 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4817 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07004818 VkBool32 skip = false;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07004819
4820#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4821 // TODO: Fix -- pay attention to image subresource ranges -- not all subresources transition at the same time
4822 return skip;
4823#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4824
Michael Lentineabc5e922015-10-12 11:30:14 -05004825 for (uint32_t i = 0; i < memBarrierCount; ++i) {
4826 auto mem_barrier = reinterpret_cast<const VkMemoryBarrier*>(ppMemBarriers[i]);
4827 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
4828 auto image_mem_barrier = reinterpret_cast<const VkImageMemoryBarrier*>(mem_barrier);
4829 auto image_data = pCB->imageLayoutMap.find(image_mem_barrier->image);
4830 if (image_data == pCB->imageLayoutMap.end()) {
4831 pCB->imageLayoutMap[image_mem_barrier->image].initialLayout = image_mem_barrier->oldLayout;
4832 pCB->imageLayoutMap[image_mem_barrier->image].layout = image_mem_barrier->newLayout;
4833 } else {
4834 if (image_data->second.layout != image_mem_barrier->oldLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004835 skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Courtney Goeltzenleuchterb19042e2015-11-25 11:38:54 -07004836 "You cannot transition the layout from %d when current layout is %d.", image_mem_barrier->oldLayout, image_data->second.layout);
Michael Lentineabc5e922015-10-12 11:30:14 -05004837 }
4838 image_data->second.layout = image_mem_barrier->newLayout;
4839 }
4840 }
4841 }
4842 return skip;
4843}
4844
Mark Lobodzinskia3a86112016-01-05 17:17:55 -07004845// Print readable FlagBits in FlagMask
4846std::string string_VkAccessFlags(VkAccessFlags accessMask)
4847{
4848 std::string result;
4849 std::string separator;
4850
4851 if (accessMask == 0) {
4852 result = "[None]";
4853 } else {
4854 result = "[";
4855 for (auto i = 0; i < 32; i++) {
4856 if (accessMask & (1 << i)) {
4857 result = result + separator + string_VkAccessFlagBits((VkAccessFlagBits)(1 << i));
4858 separator = " | ";
4859 }
4860 }
4861 result = result + "]";
4862 }
4863 return result;
4864}
4865
Michael Lentine97eb7462015-11-20 09:48:52 -08004866// AccessFlags MUST have 'required_bit' set, and may have one or more of 'optional_bits' set.
4867// If required_bit is zero, accessMask must have at least one of 'optional_bits' set
Mark Lobodzinskifd740fc2016-01-06 12:56:29 -07004868// TODO: Add tracking to ensure that at least one barrier has been set for these layout transitions
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004869VkBool32 ValidateMaskBits(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout,
4870 VkAccessFlags required_bit, VkAccessFlags optional_bits, const char* type) {
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07004871 VkBool32 skip_call = false;
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004872
Michael Lentine97eb7462015-11-20 09:48:52 -08004873 if ((accessMask & required_bit) || (!required_bit && (accessMask & optional_bits))) {
4874 if (accessMask & !(required_bit | optional_bits)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004875 // TODO: Verify against Valid Use
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004876 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004877 "Additional bits in %s accessMask %d %s are specified when layout is %s.",
4878 type, accessMask, string_VkAccessFlags(accessMask).c_str(), string_VkImageLayout(layout));
Michael Lentineecc32b72015-10-16 18:08:09 -05004879 }
4880 } else {
Michael Lentine97eb7462015-11-20 09:48:52 -08004881 if (!required_bit) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004882 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
Mark Lobodzinskifd740fc2016-01-06 12:56:29 -07004883 "%s AccessMask %d %s must contain at least one of access bits %d %s when layout is %s, unless the app has previously added a barrier for this transition.",
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004884 type, accessMask, string_VkAccessFlags(accessMask).c_str(), optional_bits,
4885 string_VkAccessFlags(optional_bits).c_str(), string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08004886 } else {
Mark Lobodzinskif2cc2a52016-01-05 13:35:29 -07004887 std::string opt_bits;
4888 if (optional_bits != 0) {
4889 opt_bits = "and may have optional bits " + std::to_string(optional_bits) + ' ' + string_VkAccessFlags(optional_bits);
4890 }
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004891 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
Mark Lobodzinskifd740fc2016-01-06 12:56:29 -07004892 "%s AccessMask %d %s must have required access bit %d %s %s when layout is %s, unless the app has previously added a barrier for this transition.",
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004893 type, accessMask, string_VkAccessFlags(accessMask).c_str(),
4894 required_bit, string_VkAccessFlags(required_bit).c_str(),
Mark Lobodzinskif2cc2a52016-01-05 13:35:29 -07004895 opt_bits.c_str(), string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08004896 }
Michael Lentineecc32b72015-10-16 18:08:09 -05004897 }
4898 return skip_call;
4899}
4900
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004901VkBool32 ValidateMaskBitsFromLayouts(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout, const char* type) {
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07004902 VkBool32 skip_call = false;
Michael Lentine97eb7462015-11-20 09:48:52 -08004903 switch (layout) {
4904 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004905 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_COLOR_ATTACHMENT_READ_BIT, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08004906 break;
Michael Lentineecc32b72015-10-16 18:08:09 -05004907 }
Michael Lentine97eb7462015-11-20 09:48:52 -08004908 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004909 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08004910 break;
Michael Lentineecc32b72015-10-16 18:08:09 -05004911 }
Michael Lentine97eb7462015-11-20 09:48:52 -08004912 case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004913 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_WRITE_BIT, 0, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08004914 break;
4915 }
4916 case VK_IMAGE_LAYOUT_PREINITIALIZED: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004917 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_HOST_WRITE_BIT, 0, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08004918 break;
4919 }
4920 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004921 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, 0, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08004922 break;
4923 }
4924 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004925 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, 0, VK_ACCESS_INPUT_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08004926 break;
4927 }
4928 case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004929 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_READ_BIT, 0, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08004930 break;
4931 }
4932 case VK_IMAGE_LAYOUT_UNDEFINED: {
4933 if (accessMask != 0) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004934 // TODO: Verify against Valid Use section spec
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004935 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004936 "Additional bits in %s accessMask %d %s are specified when layout is %s.", type, accessMask, string_VkAccessFlags(accessMask).c_str(),
4937 string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08004938 }
4939 break;
4940 }
4941 case VK_IMAGE_LAYOUT_GENERAL:
4942 default: {
4943 break;
4944 }
Michael Lentineecc32b72015-10-16 18:08:09 -05004945 }
4946 return skip_call;
4947}
4948
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07004949VkBool32 ValidateBarriers(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const void* const* ppMemBarriers) {
4950 VkBool32 skip_call = false;
Michael Lentine48930b82015-10-15 17:07:00 -05004951 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4952 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4953 if (pCB->activeRenderPass && memBarrierCount) {
4954 for (uint32_t i = 0; i < memBarrierCount; ++i) {
4955 auto mem_barrier = reinterpret_cast<const VkMemoryBarrier*>(ppMemBarriers[i]);
4956 if (mem_barrier && mem_barrier->sType != VK_STRUCTURE_TYPE_MEMORY_BARRIER) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004957 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 -05004958 "Image or Buffers Barriers cannot be used during a render pass.");
4959 }
4960 }
4961 if (!dev_data->renderPassMap[pCB->activeRenderPass]->hasSelfDependency[pCB->activeSubpass]) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004962 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 -05004963 "Barriers cannot be set during subpass %d with no self dependency specified.", pCB->activeSubpass);
4964 }
4965 }
Mark Lobodzinski73a37ec2015-11-20 09:27:27 -07004966
Michael Lentineecc32b72015-10-16 18:08:09 -05004967 for (uint32_t i = 0; i < memBarrierCount; ++i) {
4968 auto mem_barrier = reinterpret_cast<const VkMemoryBarrier*>(ppMemBarriers[i]);
4969 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
4970 auto image_mem_barrier = reinterpret_cast<const VkImageMemoryBarrier*>(mem_barrier);
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004971 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, image_mem_barrier->srcAccessMask, image_mem_barrier->oldLayout, "Source");
4972 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, image_mem_barrier->dstAccessMask, image_mem_barrier->newLayout, "Dest");
Michael Lentineecc32b72015-10-16 18:08:09 -05004973 }
4974 }
Mark Lobodzinski3cba24a2015-12-03 15:42:32 -07004975
Michael Lentine48930b82015-10-15 17:07:00 -05004976 return skip_call;
4977}
4978
Chia-I Wu9ab61502015-11-06 06:42:02 +08004979VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent* pEvents, VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask, uint32_t memoryBarrierCount, const void* const* ppMemoryBarriers)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004980{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004981 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004982 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4983 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004984 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06004985 for (uint32_t i = 0; i < eventCount; ++i) {
4986 pCB->waitedEvents.push_back(pEvents[i]);
4987 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07004988 if (pCB->state == CB_RECORDING) {
4989 skipCall |= addCmd(dev_data, pCB, CMD_WAITEVENTS, "vkCmdWaitEvents()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06004990 } else {
4991 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdWaitEvents()");
4992 }
Michael Lentineabc5e922015-10-12 11:30:14 -05004993 skipCall |= TransitionImageLayouts(commandBuffer, memoryBarrierCount, ppMemoryBarriers);
Michael Lentine48930b82015-10-15 17:07:00 -05004994 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, ppMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004995 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004996 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004997 dev_data->device_dispatch_table->CmdWaitEvents(commandBuffer, eventCount, pEvents, sourceStageMask, dstStageMask, memoryBarrierCount, ppMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004998}
4999
Chia-I Wu9ab61502015-11-06 06:42:02 +08005000VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, uint32_t memoryBarrierCount, const void* const* ppMemoryBarriers)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005001{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005002 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005003 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5004 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005005 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005006 skipCall |= addCmd(dev_data, pCB, CMD_PIPELINEBARRIER, "vkCmdPipelineBarrier()");
Michael Lentineabc5e922015-10-12 11:30:14 -05005007 skipCall |= TransitionImageLayouts(commandBuffer, memoryBarrierCount, ppMemoryBarriers);
Michael Lentine48930b82015-10-15 17:07:00 -05005008 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, ppMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005009 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005010 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005011 dev_data->device_dispatch_table->CmdPipelineBarrier(commandBuffer, srcStageMask, dstStageMask, dependencyFlags, memoryBarrierCount, ppMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005012}
5013
Chia-I Wu9ab61502015-11-06 06:42:02 +08005014VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
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_BEGINQUERY, "vkCmdBeginQuery()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005021 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005022 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005023 dev_data->device_dispatch_table->CmdBeginQuery(commandBuffer, queryPool, slot, flags);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005024}
5025
Chia-I Wu9ab61502015-11-06 06:42:02 +08005026VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005027{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005028 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005029 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5030 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005031 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005032 QueryObject query = {queryPool, slot};
5033 pCB->queryToStateMap[query] = 1;
Mark Lobodzinskice738852016-01-07 10:04:02 -07005034 if (pCB->state == CB_RECORDING) {
5035 skipCall |= addCmd(dev_data, pCB, CMD_ENDQUERY, "VkCmdEndQuery()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005036 } else {
5037 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdEndQuery()");
5038 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005039 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005040 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005041 dev_data->device_dispatch_table->CmdEndQuery(commandBuffer, queryPool, slot);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005042}
5043
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005044VK_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 -06005045{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005046 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005047 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5048 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005049 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005050 for (uint32_t i = 0; i < queryCount; i++) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005051 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06005052 pCB->waitedEventsBeforeQueryReset[query] = pCB->waitedEvents;
5053 pCB->queryToStateMap[query] = 0;
5054 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005055 if (pCB->state == CB_RECORDING) {
5056 skipCall |= addCmd(dev_data, pCB, CMD_RESETQUERYPOOL, "VkCmdResetQueryPool()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005057 } else {
5058 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdResetQueryPool()");
5059 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005060 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdQueryPool");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005061 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005062 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005063 dev_data->device_dispatch_table->CmdResetQueryPool(commandBuffer, queryPool, firstQuery, queryCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005064}
5065
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005066VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005067 uint32_t queryCount, VkBuffer dstBuffer, VkDeviceSize dstOffset,
Chia-I Wuccc93a72015-10-26 18:36:20 +08005068 VkDeviceSize stride, VkQueryResultFlags flags)
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005069{
5070 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005071 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5072 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005073 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005074 for (uint32_t i = 0; i < queryCount; i++) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005075 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06005076 if(!pCB->queryToStateMap[query]) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005077 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_QUERY, "DS",
5078 "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 -06005079 }
5080 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005081 if (pCB->state == CB_RECORDING) {
5082 skipCall |= addCmd(dev_data, pCB, CMD_COPYQUERYPOOLRESULTS, "vkCmdCopyQueryPoolResults()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005083 } else {
5084 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdCopyQueryPoolResults()");
5085 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005086 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyQueryPoolResults");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005087 }
5088 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005089 dev_data->device_dispatch_table->CmdCopyQueryPoolResults(commandBuffer, queryPool,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005090 firstQuery, queryCount, dstBuffer, dstOffset, stride, flags);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005091}
5092
Chia-I Wu9ab61502015-11-06 06:42:02 +08005093VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005094{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005095 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005096 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5097 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005098 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005099 QueryObject query = {queryPool, slot};
5100 pCB->queryToStateMap[query] = 1;
Mark Lobodzinskice738852016-01-07 10:04:02 -07005101 if (pCB->state == CB_RECORDING) {
5102 skipCall |= addCmd(dev_data, pCB, CMD_WRITETIMESTAMP, "vkCmdWriteTimestamp()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005103 } else {
5104 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdWriteTimestamp()");
5105 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005106 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005107 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005108 dev_data->device_dispatch_table->CmdWriteTimestamp(commandBuffer, pipelineStage, queryPool, slot);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005109}
5110
Chia-I Wu9ab61502015-11-06 06:42:02 +08005111VK_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 -06005112{
Tobin Ehlis0b632332015-10-07 09:38:40 -06005113 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005114 VkResult result = dev_data->device_dispatch_table->CreateFramebuffer(device, pCreateInfo, pAllocator, pFramebuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005115 if (VK_SUCCESS == result) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06005116 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06005117 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +08005118 if (pCreateInfo->pAttachments) {
Courtney Goeltzenleuchter5861a1b2015-09-01 17:30:39 -06005119 localFBCI->pAttachments = new VkImageView[localFBCI->attachmentCount];
5120 memcpy((void*)localFBCI->pAttachments, pCreateInfo->pAttachments, localFBCI->attachmentCount*sizeof(VkImageView));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005121 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08005122 dev_data->frameBufferMap[*pFramebuffer] = localFBCI;
Tobin Ehliseba312c2015-04-01 08:40:34 -06005123 }
5124 return result;
5125}
5126
Michael Lentineb6986752015-10-06 14:56:18 -07005127// Store the DAG.
5128struct DAGNode {
5129 uint32_t pass;
5130 std::vector<uint32_t> prev;
5131 std::vector<uint32_t> next;
5132};
5133
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005134VkBool32 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 -07005135 // If we have already checked this node we have not found a dependency path so return false.
5136 if (processed_nodes.count(index))
5137 return false;
5138 processed_nodes.insert(index);
5139 const DAGNode& node = subpass_to_node[index];
5140 // Look for a dependency path. If one exists return true else recurse on the previous nodes.
5141 if (std::find(node.prev.begin(), node.prev.end(), dependent) == node.prev.end()) {
5142 for (auto elem : node.prev) {
5143 if (FindDependency(elem, dependent, subpass_to_node, processed_nodes))
5144 return true;
5145 }
5146 } else {
5147 return true;
5148 }
5149 return false;
5150}
5151
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005152VkBool32 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) {
5153 VkBool32 result = true;
Michael Lentineb6986752015-10-06 14:56:18 -07005154 // Loop through all subpasses that share the same attachment and make sure a dependency exists
5155 for (uint32_t k = 0; k < dependent_subpasses.size(); ++k) {
5156 if (subpass == dependent_subpasses[k])
5157 continue;
5158 const DAGNode& node = subpass_to_node[subpass];
5159 // Check for a specified dependency between the two nodes. If one exists we are done.
5160 auto prev_elem = std::find(node.prev.begin(), node.prev.end(), dependent_subpasses[k]);
5161 auto next_elem = std::find(node.next.begin(), node.next.end(), dependent_subpasses[k]);
5162 if (prev_elem == node.prev.end() && next_elem == node.next.end()) {
5163 // If no dependency exits an implicit dependency still might. If so, warn and if not throw an error.
5164 std::unordered_set<uint32_t> processed_nodes;
5165 if (FindDependency(subpass, dependent_subpasses[k], subpass_to_node, processed_nodes) ||
5166 FindDependency(dependent_subpasses[k], subpass, subpass_to_node, processed_nodes)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005167 // TODO: Verify against Valid Use section of spec
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005168 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 -07005169 "A dependency between subpasses %d and %d must exist but only an implicit one is specified.",
5170 subpass, dependent_subpasses[k]);
5171 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005172 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 -07005173 "A dependency between subpasses %d and %d must exist but one is not specified.",
5174 subpass, dependent_subpasses[k]);
5175 result = false;
5176 }
5177 }
5178 }
5179 return result;
5180}
5181
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005182VkBool32 CheckPreserved(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, const int index, const int attachment, const std::vector<DAGNode>& subpass_to_node, int depth, VkBool32& skip_call) {
Michael Lentineb6986752015-10-06 14:56:18 -07005183 const DAGNode& node = subpass_to_node[index];
5184 // If this node writes to the attachment return true as next nodes need to preserve the attachment.
5185 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005186 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005187 if (attachment == subpass.pColorAttachments[j].attachment)
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005188 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005189 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005190 if (subpass.pDepthStencilAttachment &&
5191 subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
5192 if (attachment == subpass.pDepthStencilAttachment->attachment)
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005193 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005194 }
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005195 VkBool32 result = VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005196 // Loop through previous nodes and see if any of them write to the attachment.
5197 for (auto elem : node.prev) {
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005198 result |= CheckPreserved(my_data, device, pCreateInfo, elem, attachment, subpass_to_node, depth + 1, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005199 }
5200 // If the attachment was written to by a previous node than this node needs to preserve it.
5201 if (result && depth > 0) {
5202 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005203 VkBool32 has_preserved = false;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005204 for (uint32_t j = 0; j < subpass.preserveAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005205 if (subpass.pPreserveAttachments[j].attachment == attachment) {
5206 has_preserved = true;
5207 break;
5208 }
5209 }
5210 if (!has_preserved) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005211 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 -07005212 "Attachment %d is used by a later subpass and must be preserved in subpass %d.", attachment, index);
5213 }
5214 }
5215 return result;
5216}
5217
Michael Lentineb4979492015-12-22 11:36:14 -06005218VkBool32 ValidateDependencies(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, const std::vector<DAGNode>& subpass_to_node) {
5219 VkBool32 skip_call = false;
Michael Lentineb6986752015-10-06 14:56:18 -07005220 std::vector<std::vector<uint32_t>> output_attachment_to_subpass(pCreateInfo->attachmentCount);
5221 std::vector<std::vector<uint32_t>> input_attachment_to_subpass(pCreateInfo->attachmentCount);
Michael Lentineb6986752015-10-06 14:56:18 -07005222 // Find for each attachment the subpasses that use them.
5223 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5224 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005225 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005226 input_attachment_to_subpass[subpass.pInputAttachments[j].attachment].push_back(i);
5227 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08005228 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005229 output_attachment_to_subpass[subpass.pColorAttachments[j].attachment].push_back(i);
5230 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005231 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
5232 output_attachment_to_subpass[subpass.pDepthStencilAttachment->attachment].push_back(i);
Michael Lentineb6986752015-10-06 14:56:18 -07005233 }
5234 }
5235 // If there is a dependency needed make sure one exists
5236 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5237 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
5238 // If the attachment is an input then all subpasses that output must have a dependency relationship
Chia-I Wud50a7d72015-10-26 20:48:51 +08005239 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005240 const uint32_t& attachment = subpass.pInputAttachments[j].attachment;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005241 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005242 }
5243 // 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 +08005244 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005245 const uint32_t& attachment = subpass.pColorAttachments[j].attachment;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005246 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
5247 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005248 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005249 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
5250 const uint32_t& attachment = subpass.pDepthStencilAttachment->attachment;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005251 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
5252 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005253 }
5254 }
5255 // Loop through implicit dependencies, if this pass reads make sure the attachment is preserved for all passes after it was written.
5256 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5257 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005258 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005259 CheckPreserved(my_data, device, pCreateInfo, i, subpass.pInputAttachments[j].attachment, subpass_to_node, 0, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005260 }
5261 }
5262 return skip_call;
5263}
5264
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005265VkBool32 ValidateLayouts(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo) {
5266 VkBool32 skip = false;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005267
5268#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
5269 return skip;
5270#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5271
Michael Lentineabc5e922015-10-12 11:30:14 -05005272 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5273 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
5274 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
5275 if (subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL &&
5276 subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) {
5277 if (subpass.pInputAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005278 // 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 -07005279 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 -05005280 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
5281 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005282 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 -05005283 "Layout for input attachment is %d but can only be READ_ONLY_OPTIMAL or GENERAL.", subpass.pInputAttachments[j].attachment);
5284 }
5285 }
5286 }
5287 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
5288 if (subpass.pColorAttachments[j].layout != VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) {
5289 if (subpass.pColorAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005290 // 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 -07005291 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 -05005292 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
5293 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005294 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 -05005295 "Layout for color attachment is %d but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.", subpass.pColorAttachments[j].attachment);
5296 }
5297 }
5298 }
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005299 if ((subpass.pDepthStencilAttachment != NULL) &&
5300 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
Michael Lentineabc5e922015-10-12 11:30:14 -05005301 if (subpass.pDepthStencilAttachment->layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) {
5302 if (subpass.pDepthStencilAttachment->layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005303 // 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 -07005304 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 -05005305 "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL.");
5306 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005307 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 -05005308 "Layout for depth attachment is %d but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL.", subpass.pDepthStencilAttachment->attachment);
5309 }
5310 }
5311 }
5312 }
5313 return skip;
5314}
5315
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005316VkBool32 CreatePassDAG(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, std::vector<DAGNode>& subpass_to_node, std::vector<bool>& has_self_dependency) {
5317 VkBool32 skip_call = false;
Michael Lentineabc5e922015-10-12 11:30:14 -05005318 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5319 DAGNode& subpass_node = subpass_to_node[i];
5320 subpass_node.pass = i;
5321 }
5322 for (uint32_t i = 0; i < pCreateInfo->dependencyCount; ++i) {
5323 const VkSubpassDependency& dependency = pCreateInfo->pDependencies[i];
5324 if (dependency.srcSubpass > dependency.dstSubpass) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005325 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 -05005326 "Depedency graph must be specified such that an earlier pass cannot depend on a later pass.");
Michael Lentine48930b82015-10-15 17:07:00 -05005327 } else if (dependency.srcSubpass == dependency.dstSubpass) {
5328 has_self_dependency[dependency.srcSubpass] = true;
Michael Lentineabc5e922015-10-12 11:30:14 -05005329 }
5330 subpass_to_node[dependency.dstSubpass].prev.push_back(dependency.srcSubpass);
5331 subpass_to_node[dependency.srcSubpass].next.push_back(dependency.dstSubpass);
5332 }
5333 return skip_call;
5334}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005335// TODOSC : Add intercept of vkCreateShaderModule
Michael Lentineabc5e922015-10-12 11:30:14 -05005336
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005337VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateShaderModule(
5338 VkDevice device,
5339 const VkShaderModuleCreateInfo *pCreateInfo,
5340 const VkAllocationCallbacks* pAllocator,
5341 VkShaderModule *pShaderModule)
5342{
5343 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005344 VkBool32 skip_call = false;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005345 if (!shader_is_spirv(pCreateInfo)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005346 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 -07005347 /* dev */ 0, __LINE__, SHADER_CHECKER_NON_SPIRV_SHADER, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005348 "Shader is not SPIR-V");
5349 }
5350
5351 if (skip_call)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005352 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005353
5354 VkResult res = my_data->device_dispatch_table->CreateShaderModule(device, pCreateInfo, pAllocator, pShaderModule);
5355
5356 if (res == VK_SUCCESS) {
5357 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005358 my_data->shaderModuleMap[*pShaderModule] = new shader_module(pCreateInfo);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005359 loader_platform_thread_unlock_mutex(&globalLock);
5360 }
5361 return res;
5362}
5363
Chia-I Wu9ab61502015-11-06 06:42:02 +08005364VK_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 -06005365{
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005366 VkBool32 skip_call = false;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005367 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentineabc5e922015-10-12 11:30:14 -05005368 // Create DAG
Michael Lentine48930b82015-10-15 17:07:00 -05005369 std::vector<bool> has_self_dependency(pCreateInfo->subpassCount);
Michael Lentineabc5e922015-10-12 11:30:14 -05005370 std::vector<DAGNode> subpass_to_node(pCreateInfo->subpassCount);
Michael Lentine48930b82015-10-15 17:07:00 -05005371 skip_call |= CreatePassDAG(dev_data, device, pCreateInfo, subpass_to_node, has_self_dependency);
Michael Lentineabc5e922015-10-12 11:30:14 -05005372 // Validate using DAG
5373 skip_call |= ValidateDependencies(dev_data, device, pCreateInfo, subpass_to_node);
5374 skip_call |= ValidateLayouts(dev_data, device, pCreateInfo);
5375 if (skip_call) {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005376 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentineb6986752015-10-06 14:56:18 -07005377 }
Chia-I Wuf7458c52015-10-26 21:10:41 +08005378 VkResult result = dev_data->device_dispatch_table->CreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005379 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005380 // TODOSC : Merge in tracking of renderpass from ShaderChecker
Tobin Ehliseba312c2015-04-01 08:40:34 -06005381 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06005382 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +08005383 if (pCreateInfo->pAttachments) {
5384 localRPCI->pAttachments = new VkAttachmentDescription[localRPCI->attachmentCount];
5385 memcpy((void*)localRPCI->pAttachments, pCreateInfo->pAttachments, localRPCI->attachmentCount*sizeof(VkAttachmentDescription));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005386 }
Chia-I Wu08accc62015-07-07 11:50:03 +08005387 if (pCreateInfo->pSubpasses) {
5388 localRPCI->pSubpasses = new VkSubpassDescription[localRPCI->subpassCount];
5389 memcpy((void*)localRPCI->pSubpasses, pCreateInfo->pSubpasses, localRPCI->subpassCount*sizeof(VkSubpassDescription));
5390
5391 for (uint32_t i = 0; i < localRPCI->subpassCount; i++) {
5392 VkSubpassDescription *subpass = (VkSubpassDescription *) &localRPCI->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005393 const uint32_t attachmentCount = subpass->inputAttachmentCount +
5394 subpass->colorAttachmentCount * (1 + (subpass->pResolveAttachments?1:0)) +
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005395 ((subpass->pDepthStencilAttachment) ? 1 : 0) + subpass->preserveAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005396 VkAttachmentReference *attachments = new VkAttachmentReference[attachmentCount];
5397
Cody Northropa505dda2015-08-04 11:16:41 -06005398 memcpy(attachments, subpass->pInputAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005399 sizeof(attachments[0]) * subpass->inputAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005400 subpass->pInputAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005401 attachments += subpass->inputAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005402
Cody Northropa505dda2015-08-04 11:16:41 -06005403 memcpy(attachments, subpass->pColorAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005404 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005405 subpass->pColorAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005406 attachments += subpass->colorAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005407
Cody Northropa505dda2015-08-04 11:16:41 -06005408 if (subpass->pResolveAttachments) {
5409 memcpy(attachments, subpass->pResolveAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005410 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005411 subpass->pResolveAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005412 attachments += subpass->colorAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005413 }
5414
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005415 if (subpass->pDepthStencilAttachment) {
5416 memcpy(attachments, subpass->pDepthStencilAttachment,
5417 sizeof(attachments[0]) * 1);
5418 subpass->pDepthStencilAttachment = attachments;
5419 attachments += 1;
5420 }
5421
Cody Northropa505dda2015-08-04 11:16:41 -06005422 memcpy(attachments, subpass->pPreserveAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005423 sizeof(attachments[0]) * subpass->preserveAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005424 subpass->pPreserveAttachments = attachments;
Chia-I Wu08accc62015-07-07 11:50:03 +08005425 }
Tobin Ehliseba312c2015-04-01 08:40:34 -06005426 }
Chia-I Wu08accc62015-07-07 11:50:03 +08005427 if (pCreateInfo->pDependencies) {
5428 localRPCI->pDependencies = new VkSubpassDependency[localRPCI->dependencyCount];
5429 memcpy((void*)localRPCI->pDependencies, pCreateInfo->pDependencies, localRPCI->dependencyCount*sizeof(VkSubpassDependency));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005430 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005431 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005432 dev_data->renderPassMap[*pRenderPass] = new RENDER_PASS_NODE(localRPCI);
Michael Lentine48930b82015-10-15 17:07:00 -05005433 dev_data->renderPassMap[*pRenderPass]->hasSelfDependency = has_self_dependency;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005434 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehliseba312c2015-04-01 08:40:34 -06005435 }
5436 return result;
5437}
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005438// Free the renderpass shadow
5439static void deleteRenderPasses(layer_data* my_data)
5440{
5441 if (my_data->renderPassMap.size() <= 0)
5442 return;
5443 for (auto ii=my_data->renderPassMap.begin(); ii!=my_data->renderPassMap.end(); ++ii) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005444 const VkRenderPassCreateInfo* pRenderPassInfo = (*ii).second->pCreateInfo;
Michael Lentine48930b82015-10-15 17:07:00 -05005445 if (pRenderPassInfo->pAttachments) {
5446 delete[] pRenderPassInfo->pAttachments;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005447 }
Michael Lentine48930b82015-10-15 17:07:00 -05005448 if (pRenderPassInfo->pSubpasses) {
5449 for (uint32_t i=0; i<pRenderPassInfo->subpassCount; ++i) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005450 // Attachements are all allocated in a block, so just need to
5451 // find the first non-null one to delete
Michael Lentine48930b82015-10-15 17:07:00 -05005452 if (pRenderPassInfo->pSubpasses[i].pInputAttachments) {
5453 delete[] pRenderPassInfo->pSubpasses[i].pInputAttachments;
5454 } else if (pRenderPassInfo->pSubpasses[i].pColorAttachments) {
5455 delete[] pRenderPassInfo->pSubpasses[i].pColorAttachments;
5456 } else if (pRenderPassInfo->pSubpasses[i].pResolveAttachments) {
5457 delete[] pRenderPassInfo->pSubpasses[i].pResolveAttachments;
5458 } else if (pRenderPassInfo->pSubpasses[i].pPreserveAttachments) {
5459 delete[] pRenderPassInfo->pSubpasses[i].pPreserveAttachments;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005460 }
5461 }
Michael Lentine48930b82015-10-15 17:07:00 -05005462 delete[] pRenderPassInfo->pSubpasses;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005463 }
Michael Lentine48930b82015-10-15 17:07:00 -05005464 if (pRenderPassInfo->pDependencies) {
5465 delete[] pRenderPassInfo->pDependencies;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005466 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005467 delete pRenderPassInfo;
Michael Lentine48930b82015-10-15 17:07:00 -05005468 delete (*ii).second;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005469 }
5470 my_data->renderPassMap.clear();
5471}
Michael Lentineabc5e922015-10-12 11:30:14 -05005472
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005473VkBool32 VerifyFramebufferAndRenderPassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
5474 VkBool32 skip_call = false;
Michael Lentineabc5e922015-10-12 11:30:14 -05005475 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5476 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005477 const VkRenderPassCreateInfo* pRenderPassInfo = dev_data->renderPassMap[pRenderPassBegin->renderPass]->pCreateInfo;
Michael Lentineabc5e922015-10-12 11:30:14 -05005478 const VkFramebufferCreateInfo* pFramebufferInfo = dev_data->frameBufferMap[pRenderPassBegin->framebuffer];
5479 if (pRenderPassInfo->attachmentCount != pFramebufferInfo->attachmentCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005480 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 -05005481 "You cannot start a render pass using a framebuffer with a different number of attachments.");
5482 }
5483 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
5484 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
5485 const VkImage& image = dev_data->imageViewMap[image_view]->image;
5486 auto image_data = pCB->imageLayoutMap.find(image);
5487 if (image_data == pCB->imageLayoutMap.end()) {
5488 pCB->imageLayoutMap[image].initialLayout = pRenderPassInfo->pAttachments[i].initialLayout;
5489 pCB->imageLayoutMap[image].layout = pRenderPassInfo->pAttachments[i].initialLayout;
5490 } else if (pRenderPassInfo->pAttachments[i].initialLayout != image_data->second.layout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005491 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 -05005492 "You cannot start a render pass using attachment %i where the intial layout differs from the starting layout.", i);
5493 }
5494 }
5495 return skip_call;
5496}
5497
5498void TransitionSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, const int subpass_index) {
5499 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5500 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5501 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
5502 if (render_pass_data == dev_data->renderPassMap.end()) {
5503 return;
5504 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005505 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
Michael Lentineabc5e922015-10-12 11:30:14 -05005506 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
5507 if (framebuffer_data == dev_data->frameBufferMap.end()) {
5508 return;
5509 }
5510 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
5511 const VkSubpassDescription& subpass = pRenderPassInfo->pSubpasses[subpass_index];
5512 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
5513 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pInputAttachments[j].attachment];
5514 auto image_view_data = dev_data->imageViewMap.find(image_view);
5515 if (image_view_data != dev_data->imageViewMap.end()) {
5516 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5517 if (image_layout != pCB->imageLayoutMap.end()) {
5518 image_layout->second.layout = subpass.pInputAttachments[j].layout;
5519 }
5520 }
5521 }
5522 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
5523 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pColorAttachments[j].attachment];
5524 auto image_view_data = dev_data->imageViewMap.find(image_view);
5525 if (image_view_data != dev_data->imageViewMap.end()) {
5526 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5527 if (image_layout != pCB->imageLayoutMap.end()) {
5528 image_layout->second.layout = subpass.pColorAttachments[j].layout;
5529 }
5530 }
5531 }
Michael Lentine3dea6512015-10-28 15:55:18 -07005532 if ((subpass.pDepthStencilAttachment != NULL) &&
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005533 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
Michael Lentineabc5e922015-10-12 11:30:14 -05005534 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pDepthStencilAttachment->attachment];
5535 auto image_view_data = dev_data->imageViewMap.find(image_view);
5536 if (image_view_data != dev_data->imageViewMap.end()) {
5537 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5538 if (image_layout != pCB->imageLayoutMap.end()) {
5539 image_layout->second.layout = subpass.pDepthStencilAttachment->layout;
5540 }
5541 }
5542 }
5543}
5544
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005545VkBool32 validatePrimaryCommandBuffer(const layer_data* my_data, const GLOBAL_CB_NODE* pCB, const std::string& cmd_name) {
5546 VkBool32 skip_call = false;
Michael Lentine3dea6512015-10-28 15:55:18 -07005547 if (pCB->createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005548 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 -07005549 "Cannot execute command %s on a secondary command buffer.", cmd_name.c_str());
5550 }
5551 return skip_call;
5552}
5553
Michael Lentineabc5e922015-10-12 11:30:14 -05005554void TransitionFinalSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
5555 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5556 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5557 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
5558 if (render_pass_data == dev_data->renderPassMap.end()) {
5559 return;
5560 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005561 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
Michael Lentineabc5e922015-10-12 11:30:14 -05005562 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
5563 if (framebuffer_data == dev_data->frameBufferMap.end()) {
5564 return;
5565 }
5566 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
5567 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
5568 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
5569 auto image_view_data = dev_data->imageViewMap.find(image_view);
5570 if (image_view_data != dev_data->imageViewMap.end()) {
5571 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5572 if (image_layout != pCB->imageLayoutMap.end()) {
5573 image_layout->second.layout = pRenderPassInfo->pAttachments[i].finalLayout;
5574 }
5575 }
5576 }
5577}
5578
Chia-I Wu9ab61502015-11-06 06:42:02 +08005579VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, VkSubpassContents contents)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005580{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005581 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005582 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5583 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005584 if (pCB) {
Tobin Ehlis259730a2015-06-23 16:13:03 -06005585 if (pRenderPassBegin && pRenderPassBegin->renderPass) {
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005586 skipCall |= VerifyFramebufferAndRenderPassLayouts(commandBuffer, pRenderPassBegin);
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005587 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBeginRenderPass");
Michael Lentine3dea6512015-10-28 15:55:18 -07005588 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdBeginRenderPass");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005589 skipCall |= addCmd(dev_data, pCB, CMD_BEGINRENDERPASS, "vkCmdBeginRenderPass()");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005590 pCB->activeRenderPass = pRenderPassBegin->renderPass;
Michael Lentineabc5e922015-10-12 11:30:14 -05005591 // This is a shallow copy as that is all that is needed for now
5592 pCB->activeRenderPassBeginInfo = *pRenderPassBegin;
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005593 pCB->activeSubpass = 0;
Michael Lentine2e068b22015-12-29 16:05:27 -06005594 pCB->activeSubpassContents = contents;
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005595 pCB->framebuffer = pRenderPassBegin->framebuffer;
Tobin Ehlis502480b2015-06-24 15:53:07 -06005596 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005597 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 -06005598 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tony Barbourbadda992015-04-06 11:09:26 -06005599 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005600 }
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005601 if (VK_FALSE == skipCall) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005602 dev_data->device_dispatch_table->CmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents);
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005603 // This is a shallow copy as that is all that is needed for now
5604 dev_data->renderPassBeginInfo = *pRenderPassBegin;
5605 dev_data->currentSubpass = 0;
5606 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005607}
5608
Chia-I Wu9ab61502015-11-06 06:42:02 +08005609VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents)
Chia-I Wu08accc62015-07-07 11:50:03 +08005610{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005611 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005612 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5613 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Michael Lentineabc5e922015-10-12 11:30:14 -05005614 TransitionSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo, ++dev_data->currentSubpass);
Chia-I Wu08accc62015-07-07 11:50:03 +08005615 if (pCB) {
Michael Lentine3dea6512015-10-28 15:55:18 -07005616 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdNextSubpass");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005617 skipCall |= addCmd(dev_data, pCB, CMD_NEXTSUBPASS, "vkCmdNextSubpass()");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005618 pCB->activeSubpass++;
Michael Lentine2e068b22015-12-29 16:05:27 -06005619 pCB->activeSubpassContents = contents;
5620 TransitionSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo, ++pCB->activeSubpass);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005621 if (pCB->lastBoundPipeline) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005622 skipCall |= validatePipelineState(dev_data, pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Chia-I Wu08accc62015-07-07 11:50:03 +08005623 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005624 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdNextSubpass");
Chia-I Wu08accc62015-07-07 11:50:03 +08005625 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005626 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005627 dev_data->device_dispatch_table->CmdNextSubpass(commandBuffer, contents);
Chia-I Wu08accc62015-07-07 11:50:03 +08005628}
5629
Chia-I Wu9ab61502015-11-06 06:42:02 +08005630VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndRenderPass(VkCommandBuffer commandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005631{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005632 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005633 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5634 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Michael Lentineabc5e922015-10-12 11:30:14 -05005635 TransitionFinalSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005636 if (pCB) {
Michael Lentine3dea6512015-10-28 15:55:18 -07005637 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdEndRenderpass");
Michael Lentine3dea6512015-10-28 15:55:18 -07005638 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdEndRenderPass");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005639 skipCall |= addCmd(dev_data, pCB, CMD_ENDRENDERPASS, "vkCmdEndRenderPass()");
Michael Lentineabc5e922015-10-12 11:30:14 -05005640 TransitionFinalSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005641 pCB->activeRenderPass = 0;
5642 pCB->activeSubpass = 0;
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005643 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005644 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005645 dev_data->device_dispatch_table->CmdEndRenderPass(commandBuffer);
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005646}
5647
Chia-I Wu9ab61502015-11-06 06:42:02 +08005648VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount, const VkCommandBuffer* pCommandBuffers)
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005649{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005650 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005651 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5652 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005653 if (pCB) {
Tobin Ehlis651d9b02015-12-16 05:01:22 -07005654 // TODO : If secondary CB was not created w/ *_USAGE_SIMULTANEOUS_USE_BIT it cannot be used more than once in given primary CB
5655 // ALSO if secondary w/o this flag is set in primary, then primary must not be pending execution more than once at a time
5656 // 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 -06005657 GLOBAL_CB_NODE* pSubCB = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005658 for (uint32_t i=0; i<commandBuffersCount; i++) {
5659 pSubCB = getCBNode(dev_data, pCommandBuffers[i]);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06005660 if (!pSubCB) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005661 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 +08005662 "vkCmdExecuteCommands() called w/ invalid Cmd Buffer %p in element %u of pCommandBuffers array.", (void*)pCommandBuffers[i], i);
5663 } else if (VK_COMMAND_BUFFER_LEVEL_PRIMARY == pSubCB->createInfo.level) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005664 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 +08005665 "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 -07005666 } else if (pCB->activeRenderPass) { // Secondary CB w/i RenderPass must have *CONTINUE_BIT set
5667 if (!(pSubCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005668 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 -07005669 "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);
5670 }
5671 string errorString = "";
5672 if (!verify_renderpass_compatibility(dev_data, pCB->activeRenderPass, pSubCB->beginInfo.renderPass, errorString)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005673 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 -07005674 "vkCmdExecuteCommands(): Secondary Command Buffer (%p) w/ render pass (%#" PRIxLEAST64 ") is incompatible w/ primary command buffer (%p) w/ render pass (%#" PRIxLEAST64 ") due to: %s",
5675 (void*)pCommandBuffers[i], (uint64_t)pSubCB->beginInfo.renderPass, (void*)commandBuffer, (uint64_t)pCB->activeRenderPass, errorString.c_str());
5676 }
5677 // If framebuffer for secondary CB is not NULL, then it must match FB from vkCmdBeginRenderPass()
5678 // that this CB will be executed in AND framebuffer must have been created w/ RP compatible w/ renderpass
5679 if (pSubCB->beginInfo.framebuffer) {
5680 if (pSubCB->beginInfo.framebuffer != pCB->activeRenderPassBeginInfo.framebuffer) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005681 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 -07005682 "vkCmdExecuteCommands(): Secondary Command Buffer (%p) references framebuffer (%#" PRIxLEAST64 ") that does not match framebuffer (%#" PRIxLEAST64 ") in active renderpass (%#" PRIxLEAST64 ").",
5683 (void*)pCommandBuffers[i], (uint64_t)pSubCB->beginInfo.framebuffer, (uint64_t)pCB->activeRenderPassBeginInfo.framebuffer, (uint64_t)pCB->activeRenderPass);
5684 }
5685 }
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06005686 }
5687 }
Michael Lentine3dea6512015-10-28 15:55:18 -07005688 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdExecuteComands");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005689 skipCall |= addCmd(dev_data, pCB, CMD_EXECUTECOMMANDS, "vkCmdExecuteComands()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005690 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005691 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005692 dev_data->device_dispatch_table->CmdExecuteCommands(commandBuffer, commandBuffersCount, pCommandBuffers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005693}
5694
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005695VkBool32 ValidateMapImageLayouts(VkDevice device, VkDeviceMemory mem) {
5696 VkBool32 skip_call = false;
Michael Lentine7b236262015-10-23 12:41:44 -07005697 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5698 auto mem_data = dev_data->memImageMap.find(mem);
5699 if (mem_data != dev_data->memImageMap.end()) {
5700 auto image_data = dev_data->imageLayoutMap.find(mem_data->second);
5701 if (image_data != dev_data->imageLayoutMap.end()) {
5702 if (image_data->second->layout != VK_IMAGE_LAYOUT_PREINITIALIZED && image_data->second->layout != VK_IMAGE_LAYOUT_GENERAL) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005703 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 -07005704 "Cannot map an image with layout %d. Only GENERAL or PREINITIALIZED are supported.", image_data->second->layout);
5705 }
5706 }
5707 }
5708 return skip_call;
5709}
5710
Chia-I Wu9ab61502015-11-06 06:42:02 +08005711VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkMapMemory(
Michael Lentine7b236262015-10-23 12:41:44 -07005712 VkDevice device,
5713 VkDeviceMemory mem,
5714 VkDeviceSize offset,
5715 VkDeviceSize size,
5716 VkFlags flags,
5717 void **ppData)
5718{
5719 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005720
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005721 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005722#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
5723 skip_call = ValidateMapImageLayouts(device, mem);
5724#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5725
Michael Lentine7b236262015-10-23 12:41:44 -07005726 if (VK_FALSE == skip_call) {
5727 return dev_data->device_dispatch_table->MapMemory(device, mem, offset, size, flags, ppData);
5728 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005729 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine7b236262015-10-23 12:41:44 -07005730}
5731
Chia-I Wu9ab61502015-11-06 06:42:02 +08005732VKAPI_ATTR VkResult VKAPI_CALL vkBindImageMemory(
Michael Lentine7b236262015-10-23 12:41:44 -07005733 VkDevice device,
5734 VkImage image,
5735 VkDeviceMemory mem,
5736 VkDeviceSize memOffset)
5737{
5738 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5739 VkResult result = dev_data->device_dispatch_table->BindImageMemory(device, image, mem, memOffset);
5740 loader_platform_thread_lock_mutex(&globalLock);
5741 dev_data->memImageMap[mem] = image;
5742 loader_platform_thread_unlock_mutex(&globalLock);
5743 return result;
5744}
5745
Michael Lentineb887b0a2015-12-29 14:12:11 -06005746
5747VKAPI_ATTR VkResult VKAPI_CALL vkSetEvent(VkDevice device, VkEvent event) {
5748 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5749 dev_data->eventMap[event].needsSignaled = false;
5750 VkResult result = dev_data->device_dispatch_table->SetEvent(device, event);
5751 return result;
5752}
5753
Michael Lentine15a47882016-01-06 10:05:48 -06005754VKAPI_ATTR VkResult VKAPI_CALL vkQueueBindSparse(
5755 VkQueue queue,
5756 uint32_t bindInfoCount,
5757 const VkBindSparseInfo* pBindInfo,
5758 VkFence fence)
5759{
5760 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
5761 bool skip_call = false;
5762
5763 for (uint32_t bindIdx=0; bindIdx < bindInfoCount; ++bindIdx) {
5764 const VkBindSparseInfo& bindInfo = pBindInfo[bindIdx];
5765 for (uint32_t i=0; i < bindInfo.waitSemaphoreCount; ++i) {
5766 if (dev_data->semaphoreSignaledMap[bindInfo.pWaitSemaphores[i]]) {
5767 dev_data->semaphoreSignaledMap[bindInfo.pWaitSemaphores[i]] = 0;
5768 } else {
5769 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",
5770 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
5771 reinterpret_cast<uint64_t>(queue), reinterpret_cast<uint64_t>(bindInfo.pWaitSemaphores[i]));
5772 }
5773 }
5774 for (uint32_t i=0; i < bindInfo.signalSemaphoreCount; ++i) {
5775 dev_data->semaphoreSignaledMap[bindInfo.pSignalSemaphores[i]] = 1;
5776 }
5777 }
5778
5779 if (!skip_call)
5780 return dev_data->device_dispatch_table->QueueBindSparse(queue, bindInfoCount, pBindInfo, fence);
5781}
5782
5783VKAPI_ATTR VkResult VKAPI_CALL vkCreateSemaphore(
5784 VkDevice device,
5785 const VkSemaphoreCreateInfo* pCreateInfo,
5786 const VkAllocationCallbacks* pAllocator,
5787 VkSemaphore* pSemaphore)
5788{
5789 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5790 VkResult result = dev_data->device_dispatch_table->CreateSemaphore(device, pCreateInfo, pAllocator, pSemaphore);
5791 if (result == VK_SUCCESS) {
5792 dev_data->semaphoreSignaledMap[*pSemaphore] = 0;
5793 }
5794}
5795
Chia-I Wu9ab61502015-11-06 06:42:02 +08005796VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(
Michael Lentineabc5e922015-10-12 11:30:14 -05005797 VkDevice device,
5798 const VkSwapchainCreateInfoKHR *pCreateInfo,
Ian Elliott05846062015-11-20 14:13:17 -07005799 const VkAllocationCallbacks *pAllocator,
Michael Lentineabc5e922015-10-12 11:30:14 -05005800 VkSwapchainKHR *pSwapchain)
5801{
5802 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott05846062015-11-20 14:13:17 -07005803 VkResult result = dev_data->device_dispatch_table->CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
Michael Lentineabc5e922015-10-12 11:30:14 -05005804
5805 if (VK_SUCCESS == result) {
5806 SWAPCHAIN_NODE *swapchain_data = new SWAPCHAIN_NODE;
5807 loader_platform_thread_lock_mutex(&globalLock);
5808 dev_data->device_extensions.swapchainMap[*pSwapchain] = swapchain_data;
5809 loader_platform_thread_unlock_mutex(&globalLock);
5810 }
5811
5812 return result;
5813}
5814
Ian Elliott05846062015-11-20 14:13:17 -07005815VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR(
Michael Lentineabc5e922015-10-12 11:30:14 -05005816 VkDevice device,
Ian Elliott05846062015-11-20 14:13:17 -07005817 VkSwapchainKHR swapchain,
5818 const VkAllocationCallbacks *pAllocator)
Michael Lentineabc5e922015-10-12 11:30:14 -05005819{
5820 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentineabc5e922015-10-12 11:30:14 -05005821
5822 loader_platform_thread_lock_mutex(&globalLock);
5823 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(swapchain);
5824 if (swapchain_data != dev_data->device_extensions.swapchainMap.end()) {
5825 if (swapchain_data->second->images.size() > 0) {
5826 for (auto swapchain_image : swapchain_data->second->images) {
5827 auto image_item = dev_data->imageLayoutMap.find(swapchain_image);
5828 if (image_item != dev_data->imageLayoutMap.end())
5829 dev_data->imageLayoutMap.erase(image_item);
5830 }
5831 }
5832 delete swapchain_data->second;
5833 dev_data->device_extensions.swapchainMap.erase(swapchain);
5834 }
5835 loader_platform_thread_unlock_mutex(&globalLock);
Ian Elliott05846062015-11-20 14:13:17 -07005836 return dev_data->device_dispatch_table->DestroySwapchainKHR(device, swapchain, pAllocator);
Michael Lentineabc5e922015-10-12 11:30:14 -05005837}
5838
Chia-I Wu9ab61502015-11-06 06:42:02 +08005839VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR(
Michael Lentineabc5e922015-10-12 11:30:14 -05005840 VkDevice device,
5841 VkSwapchainKHR swapchain,
5842 uint32_t* pCount,
5843 VkImage* pSwapchainImages)
5844{
5845 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5846 VkResult result = dev_data->device_dispatch_table->GetSwapchainImagesKHR(device, swapchain, pCount, pSwapchainImages);
5847
5848 if (result == VK_SUCCESS && pSwapchainImages != NULL) {
5849 // This should never happen and is checked by param checker.
5850 if (!pCount) return result;
5851 for (uint32_t i = 0; i < *pCount; ++i) {
5852 IMAGE_NODE* image_node = new IMAGE_NODE;
5853 image_node->layout = VK_IMAGE_LAYOUT_UNDEFINED;
5854 loader_platform_thread_lock_mutex(&globalLock);
5855 dev_data->device_extensions.swapchainMap[swapchain]->images.push_back(pSwapchainImages[i]);
5856 dev_data->imageLayoutMap[pSwapchainImages[i]] = image_node;
5857 loader_platform_thread_unlock_mutex(&globalLock);
5858 }
5859 }
5860 return result;
5861}
5862
Ian Elliott05846062015-11-20 14:13:17 -07005863VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo)
Michael Lentineabc5e922015-10-12 11:30:14 -05005864{
5865 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005866 VkBool32 skip_call = false;
Michael Lentineabc5e922015-10-12 11:30:14 -05005867
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005868#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentineabc5e922015-10-12 11:30:14 -05005869 if (pPresentInfo) {
Michael Lentine15a47882016-01-06 10:05:48 -06005870 for (uint32_t i=0; i < pPresentInfo->waitSemaphoreCount; ++i) {
5871 if (dev_data->semaphoreSignaledMap[pPresentInfo->pWaitSemaphores[i]]) {
5872 dev_data->semaphoreSignaledMap[pPresentInfo->pWaitSemaphores[i]] = 0;
5873 } else {
5874 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",
5875 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
5876 reinterpret_cast<uint64_t>(queue), reinterpret_cast<uint64_t>(pPresentInfo->pWaitSemaphores[i]));
5877 }
5878 }
Michael Lentineabc5e922015-10-12 11:30:14 -05005879 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
Ian Elliott05846062015-11-20 14:13:17 -07005880 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(pPresentInfo->pSwapchains[i]);
5881 if (swapchain_data != dev_data->device_extensions.swapchainMap.end() && pPresentInfo->pImageIndices[i] < swapchain_data->second->images.size()) {
5882 VkImage image = swapchain_data->second->images[pPresentInfo->pImageIndices[i]];
Michael Lentineabc5e922015-10-12 11:30:14 -05005883 auto image_data = dev_data->imageLayoutMap.find(image);
5884 if (image_data != dev_data->imageLayoutMap.end()) {
Ian Elliott05846062015-11-20 14:13:17 -07005885 if (image_data->second->layout != VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005886 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 -05005887 "Images passed to present must be in layout PRESENT_SOURCE_KHR but is in %d", image_data->second->layout);
5888 }
5889 }
5890 }
5891 }
5892 }
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005893#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentineabc5e922015-10-12 11:30:14 -05005894
5895 if (VK_FALSE == skip_call)
5896 return dev_data->device_dispatch_table->QueuePresentKHR(queue, pPresentInfo);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005897 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentineabc5e922015-10-12 11:30:14 -05005898}
5899
Michael Lentine15a47882016-01-06 10:05:48 -06005900VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImageKHR(
5901 VkDevice device,
5902 VkSwapchainKHR swapchain,
5903 uint64_t timeout,
5904 VkSemaphore semaphore,
5905 VkFence fence,
5906 uint32_t* pImageIndex)
5907{
5908 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5909 VkResult result = dev_data->device_dispatch_table->AcquireNextImageKHR(device, swapchain, timeout, semaphore, fence, pImageIndex);
5910 dev_data->semaphoreSignaledMap[semaphore] = 1;
5911}
5912
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005913VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(
5914 VkInstance instance,
5915 const VkDebugReportCallbackCreateInfoEXT* pCreateInfo,
5916 const VkAllocationCallbacks* pAllocator,
5917 VkDebugReportCallbackEXT* pMsgCallback)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005918{
Tobin Ehlis0b632332015-10-07 09:38:40 -06005919 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07005920 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005921 VkResult res = pTable->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06005922 if (VK_SUCCESS == res) {
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07005923 res = layer_create_msg_callback(my_data->report_data, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06005924 }
5925 return res;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005926}
5927
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005928VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07005929 VkInstance instance,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005930 VkDebugReportCallbackEXT msgCallback,
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07005931 const VkAllocationCallbacks* pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005932{
Tobin Ehlis0b632332015-10-07 09:38:40 -06005933 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07005934 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005935 pTable->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07005936 layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005937}
5938
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005939VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDebugReportMessageEXT(
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07005940 VkInstance instance,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005941 VkDebugReportFlagsEXT flags,
5942 VkDebugReportObjectTypeEXT objType,
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07005943 uint64_t object,
5944 size_t location,
5945 int32_t msgCode,
5946 const char* pLayerPrefix,
5947 const char* pMsg)
5948{
5949 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005950 my_data->instance_dispatch_table->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg);
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07005951}
5952
Chia-I Wu9ab61502015-11-06 06:42:02 +08005953VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerBegin(VkCommandBuffer commandBuffer, const char* pMarker)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005954{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005955 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005956 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5957 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis0b632332015-10-07 09:38:40 -06005958 if (!dev_data->device_extensions.debug_marker_enabled) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005959 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 -06005960 "Attempt to use CmdDbgMarkerBegin but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06005961 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06005962 } else if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005963 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKERBEGIN, "vkCmdDbgMarkerBegin()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005964 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005965 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005966 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerBegin(commandBuffer, pMarker);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005967}
5968
Chia-I Wu9ab61502015-11-06 06:42:02 +08005969VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerEnd(VkCommandBuffer commandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005970{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005971 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005972 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5973 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis0b632332015-10-07 09:38:40 -06005974 if (!dev_data->device_extensions.debug_marker_enabled) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005975 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 -06005976 "Attempt to use CmdDbgMarkerEnd but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06005977 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06005978 } else if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005979 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKEREND, "vkCmdDbgMarkerEnd()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005980 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005981 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005982 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerEnd(commandBuffer);
Jon Ashburneab34492015-06-01 09:37:38 -06005983}
5984
Chia-I Wu9ab61502015-11-06 06:42:02 +08005985VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005986{
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06005987 if (dev == NULL)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005988 return NULL;
Jon Ashburn3950e1b2015-05-20 09:00:28 -06005989
Tobin Ehlis0b632332015-10-07 09:38:40 -06005990 layer_data *dev_data;
Jon Ashburn8fd08252015-05-28 16:25:02 -06005991 /* loader uses this to force layer initialization; device object is wrapped */
5992 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
Tobin Ehlis0b632332015-10-07 09:38:40 -06005993 VkBaseLayerObject* wrapped_dev = (VkBaseLayerObject*) dev;
5994 dev_data = get_my_data_ptr(get_dispatch_key(wrapped_dev->baseObject), layer_data_map);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005995 dev_data->device_dispatch_table = new VkLayerDispatchTable;
5996 layer_initialize_dispatch_table(dev_data->device_dispatch_table, wrapped_dev);
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06005997 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -06005998 }
Tobin Ehlis0b632332015-10-07 09:38:40 -06005999 dev_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map);
Courtney Goeltzenleuchterca173b82015-06-25 18:01:43 -06006000 if (!strcmp(funcName, "vkCreateDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006001 return (PFN_vkVoidFunction) vkCreateDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006002 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006003 return (PFN_vkVoidFunction) vkDestroyDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006004 if (!strcmp(funcName, "vkQueueSubmit"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006005 return (PFN_vkVoidFunction) vkQueueSubmit;
Michael Lentine700b0aa2015-10-30 17:57:32 -07006006 if (!strcmp(funcName, "vkWaitForFences"))
6007 return (PFN_vkVoidFunction) vkWaitForFences;
6008 if (!strcmp(funcName, "vkGetFenceStatus"))
6009 return (PFN_vkVoidFunction) vkGetFenceStatus;
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07006010 if (!strcmp(funcName, "vkQueueWaitIdle"))
6011 return (PFN_vkVoidFunction) vkQueueWaitIdle;
6012 if (!strcmp(funcName, "vkDeviceWaitIdle"))
6013 return (PFN_vkVoidFunction) vkDeviceWaitIdle;
Michael Lentine700b0aa2015-10-30 17:57:32 -07006014 if (!strcmp(funcName, "vkGetDeviceQueue"))
6015 return (PFN_vkVoidFunction) vkGetDeviceQueue;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006016 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006017 return (PFN_vkVoidFunction) vkDestroyInstance;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006018 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006019 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006020 if (!strcmp(funcName, "vkDestroyFence"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006021 return (PFN_vkVoidFunction) vkDestroyFence;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006022 if (!strcmp(funcName, "vkDestroySemaphore"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006023 return (PFN_vkVoidFunction) vkDestroySemaphore;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006024 if (!strcmp(funcName, "vkDestroyEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006025 return (PFN_vkVoidFunction) vkDestroyEvent;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006026 if (!strcmp(funcName, "vkDestroyQueryPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006027 return (PFN_vkVoidFunction) vkDestroyQueryPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006028 if (!strcmp(funcName, "vkDestroyBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006029 return (PFN_vkVoidFunction) vkDestroyBuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006030 if (!strcmp(funcName, "vkDestroyBufferView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006031 return (PFN_vkVoidFunction) vkDestroyBufferView;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006032 if (!strcmp(funcName, "vkDestroyImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006033 return (PFN_vkVoidFunction) vkDestroyImage;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006034 if (!strcmp(funcName, "vkDestroyImageView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006035 return (PFN_vkVoidFunction) vkDestroyImageView;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006036 if (!strcmp(funcName, "vkDestroyShaderModule"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006037 return (PFN_vkVoidFunction) vkDestroyShaderModule;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006038 if (!strcmp(funcName, "vkDestroyPipeline"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006039 return (PFN_vkVoidFunction) vkDestroyPipeline;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006040 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006041 return (PFN_vkVoidFunction) vkDestroyPipelineLayout;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006042 if (!strcmp(funcName, "vkDestroySampler"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006043 return (PFN_vkVoidFunction) vkDestroySampler;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006044 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006045 return (PFN_vkVoidFunction) vkDestroyDescriptorSetLayout;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006046 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006047 return (PFN_vkVoidFunction) vkDestroyDescriptorPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006048 if (!strcmp(funcName, "vkDestroyFramebuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006049 return (PFN_vkVoidFunction) vkDestroyFramebuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006050 if (!strcmp(funcName, "vkDestroyRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006051 return (PFN_vkVoidFunction) vkDestroyRenderPass;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006052 if (!strcmp(funcName, "vkCreateBuffer"))
6053 return (PFN_vkVoidFunction) vkCreateBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006054 if (!strcmp(funcName, "vkCreateBufferView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006055 return (PFN_vkVoidFunction) vkCreateBufferView;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006056 if (!strcmp(funcName, "vkCreateImage"))
6057 return (PFN_vkVoidFunction) vkCreateImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006058 if (!strcmp(funcName, "vkCreateImageView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006059 return (PFN_vkVoidFunction) vkCreateImageView;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006060 if (!strcmp(funcName, "CreatePipelineCache"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006061 return (PFN_vkVoidFunction) vkCreatePipelineCache;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006062 if (!strcmp(funcName, "DestroyPipelineCache"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006063 return (PFN_vkVoidFunction) vkDestroyPipelineCache;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006064 if (!strcmp(funcName, "GetPipelineCacheData"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006065 return (PFN_vkVoidFunction) vkGetPipelineCacheData;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006066 if (!strcmp(funcName, "MergePipelineCaches"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006067 return (PFN_vkVoidFunction) vkMergePipelineCaches;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006068 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006069 return (PFN_vkVoidFunction) vkCreateGraphicsPipelines;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07006070 if (!strcmp(funcName, "vkCreateComputePipelines"))
6071 return (PFN_vkVoidFunction) vkCreateComputePipelines;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006072 if (!strcmp(funcName, "vkCreateSampler"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006073 return (PFN_vkVoidFunction) vkCreateSampler;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006074 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006075 return (PFN_vkVoidFunction) vkCreateDescriptorSetLayout;
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05006076 if (!strcmp(funcName, "vkCreatePipelineLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006077 return (PFN_vkVoidFunction) vkCreatePipelineLayout;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006078 if (!strcmp(funcName, "vkCreateDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006079 return (PFN_vkVoidFunction) vkCreateDescriptorPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006080 if (!strcmp(funcName, "vkResetDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006081 return (PFN_vkVoidFunction) vkResetDescriptorPool;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006082 if (!strcmp(funcName, "vkAllocateDescriptorSets"))
6083 return (PFN_vkVoidFunction) vkAllocateDescriptorSets;
Tobin Ehlise735c692015-10-08 13:13:50 -06006084 if (!strcmp(funcName, "vkFreeDescriptorSets"))
6085 return (PFN_vkVoidFunction) vkFreeDescriptorSets;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08006086 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006087 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
Mark Lobodzinski39298632015-11-18 08:38:27 -07006088 if (!strcmp(funcName, "vkCreateCommandPool"))
6089 return (PFN_vkVoidFunction) vkCreateCommandPool;
6090 if (!strcmp(funcName, "vkDestroyCommandPool"))
6091 return (PFN_vkVoidFunction) vkDestroyCommandPool;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006092 if (!strcmp(funcName, "vkResetCommandPool"))
6093 return (PFN_vkVoidFunction) vkResetCommandPool;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006094 if (!strcmp(funcName, "vkAllocateCommandBuffers"))
6095 return (PFN_vkVoidFunction) vkAllocateCommandBuffers;
Mark Lobodzinski39298632015-11-18 08:38:27 -07006096 if (!strcmp(funcName, "vkFreeCommandBuffers"))
6097 return (PFN_vkVoidFunction) vkFreeCommandBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006098 if (!strcmp(funcName, "vkBeginCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006099 return (PFN_vkVoidFunction) vkBeginCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006100 if (!strcmp(funcName, "vkEndCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006101 return (PFN_vkVoidFunction) vkEndCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006102 if (!strcmp(funcName, "vkResetCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006103 return (PFN_vkVoidFunction) vkResetCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006104 if (!strcmp(funcName, "vkCmdBindPipeline"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006105 return (PFN_vkVoidFunction) vkCmdBindPipeline;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06006106 if (!strcmp(funcName, "vkCmdSetViewport"))
6107 return (PFN_vkVoidFunction) vkCmdSetViewport;
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06006108 if (!strcmp(funcName, "vkCmdSetScissor"))
6109 return (PFN_vkVoidFunction) vkCmdSetScissor;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06006110 if (!strcmp(funcName, "vkCmdSetLineWidth"))
6111 return (PFN_vkVoidFunction) vkCmdSetLineWidth;
6112 if (!strcmp(funcName, "vkCmdSetDepthBias"))
6113 return (PFN_vkVoidFunction) vkCmdSetDepthBias;
6114 if (!strcmp(funcName, "vkCmdSetBlendConstants"))
6115 return (PFN_vkVoidFunction) vkCmdSetBlendConstants;
6116 if (!strcmp(funcName, "vkCmdSetDepthBounds"))
6117 return (PFN_vkVoidFunction) vkCmdSetDepthBounds;
6118 if (!strcmp(funcName, "vkCmdSetStencilCompareMask"))
6119 return (PFN_vkVoidFunction) vkCmdSetStencilCompareMask;
6120 if (!strcmp(funcName, "vkCmdSetStencilWriteMask"))
6121 return (PFN_vkVoidFunction) vkCmdSetStencilWriteMask;
6122 if (!strcmp(funcName, "vkCmdSetStencilReference"))
6123 return (PFN_vkVoidFunction) vkCmdSetStencilReference;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006124 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006125 return (PFN_vkVoidFunction) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06006126 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006127 return (PFN_vkVoidFunction) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006128 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006129 return (PFN_vkVoidFunction) vkCmdBindIndexBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006130 if (!strcmp(funcName, "vkCmdDraw"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006131 return (PFN_vkVoidFunction) vkCmdDraw;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006132 if (!strcmp(funcName, "vkCmdDrawIndexed"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006133 return (PFN_vkVoidFunction) vkCmdDrawIndexed;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006134 if (!strcmp(funcName, "vkCmdDrawIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006135 return (PFN_vkVoidFunction) vkCmdDrawIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006136 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006137 return (PFN_vkVoidFunction) vkCmdDrawIndexedIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006138 if (!strcmp(funcName, "vkCmdDispatch"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006139 return (PFN_vkVoidFunction) vkCmdDispatch;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006140 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006141 return (PFN_vkVoidFunction) vkCmdDispatchIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006142 if (!strcmp(funcName, "vkCmdCopyBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006143 return (PFN_vkVoidFunction) vkCmdCopyBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006144 if (!strcmp(funcName, "vkCmdCopyImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006145 return (PFN_vkVoidFunction) vkCmdCopyImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006146 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006147 return (PFN_vkVoidFunction) vkCmdCopyBufferToImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006148 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006149 return (PFN_vkVoidFunction) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006150 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006151 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006152 if (!strcmp(funcName, "vkCmdFillBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006153 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006154 if (!strcmp(funcName, "vkCmdClearColorImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006155 return (PFN_vkVoidFunction) vkCmdClearColorImage;
Chris Forbesd9be82b2015-06-22 17:21:59 +12006156 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006157 return (PFN_vkVoidFunction) vkCmdClearDepthStencilImage;
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06006158 if (!strcmp(funcName, "vkCmdClearAttachments"))
6159 return (PFN_vkVoidFunction) vkCmdClearAttachments;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006160 if (!strcmp(funcName, "vkCmdResolveImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006161 return (PFN_vkVoidFunction) vkCmdResolveImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006162 if (!strcmp(funcName, "vkCmdSetEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006163 return (PFN_vkVoidFunction) vkCmdSetEvent;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006164 if (!strcmp(funcName, "vkCmdResetEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006165 return (PFN_vkVoidFunction) vkCmdResetEvent;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006166 if (!strcmp(funcName, "vkCmdWaitEvents"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006167 return (PFN_vkVoidFunction) vkCmdWaitEvents;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006168 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006169 return (PFN_vkVoidFunction) vkCmdPipelineBarrier;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006170 if (!strcmp(funcName, "vkCmdBeginQuery"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006171 return (PFN_vkVoidFunction) vkCmdBeginQuery;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006172 if (!strcmp(funcName, "vkCmdEndQuery"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006173 return (PFN_vkVoidFunction) vkCmdEndQuery;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006174 if (!strcmp(funcName, "vkCmdResetQueryPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006175 return (PFN_vkVoidFunction) vkCmdResetQueryPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006176 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006177 return (PFN_vkVoidFunction) vkCmdWriteTimestamp;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006178 if (!strcmp(funcName, "vkCreateFramebuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006179 return (PFN_vkVoidFunction) vkCreateFramebuffer;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006180 if (!strcmp(funcName, "vkCreateShaderModule"))
6181 return (PFN_vkVoidFunction) vkCreateShaderModule;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006182 if (!strcmp(funcName, "vkCreateRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006183 return (PFN_vkVoidFunction) vkCreateRenderPass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006184 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006185 return (PFN_vkVoidFunction) vkCmdBeginRenderPass;
Chia-I Wu08accc62015-07-07 11:50:03 +08006186 if (!strcmp(funcName, "vkCmdNextSubpass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006187 return (PFN_vkVoidFunction) vkCmdNextSubpass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006188 if (!strcmp(funcName, "vkCmdEndRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006189 return (PFN_vkVoidFunction) vkCmdEndRenderPass;
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06006190 if (!strcmp(funcName, "vkCmdExecuteCommands"))
6191 return (PFN_vkVoidFunction) vkCmdExecuteCommands;
Michael Lentineb887b0a2015-12-29 14:12:11 -06006192 if (!strcmp(funcName, "vkSetEvent"))
6193 return (PFN_vkVoidFunction) vkSetEvent;
Michael Lentine7b236262015-10-23 12:41:44 -07006194 if (!strcmp(funcName, "vkMapMemory"))
6195 return (PFN_vkVoidFunction) vkMapMemory;
Michael Lentineb887b0a2015-12-29 14:12:11 -06006196 if (!strcmp(funcName, "vkGetQueryPoolResults"))
6197 return (PFN_vkVoidFunction) vkGetQueryPoolResults;
Michael Lentine15a47882016-01-06 10:05:48 -06006198 if (!strcmp(funcName, "vkBindImageMemory"))
6199 return (PFN_vkVoidFunction) vkBindImageMemory;
6200 if (!strcmp(funcName, "vkQueueBindSparse"))
6201 return (PFN_vkVoidFunction) vkQueueBindSparse;
6202 if (!strcmp(funcName, "vkCreateSemaphore"))
6203 return (PFN_vkVoidFunction) vkCreateSemaphore;
Jon Ashburneab34492015-06-01 09:37:38 -06006204
Michael Lentineabc5e922015-10-12 11:30:14 -05006205 if (dev_data->device_extensions.wsi_enabled)
6206 {
6207 if (!strcmp(funcName, "vkCreateSwapchainKHR"))
6208 return (PFN_vkVoidFunction) vkCreateSwapchainKHR;
6209 if (!strcmp(funcName, "vkDestroySwapchainKHR"))
6210 return (PFN_vkVoidFunction) vkDestroySwapchainKHR;
6211 if (!strcmp(funcName, "vkGetSwapchainImagesKHR"))
6212 return (PFN_vkVoidFunction) vkGetSwapchainImagesKHR;
Michael Lentine15a47882016-01-06 10:05:48 -06006213 if (!strcmp(funcName, "vkAcquireNextImageKHR"))
6214 return (PFN_vkVoidFunction) vkAcquireNextImageKHR;
Michael Lentineabc5e922015-10-12 11:30:14 -05006215 if (!strcmp(funcName, "vkQueuePresentKHR"))
6216 return (PFN_vkVoidFunction) vkQueuePresentKHR;
6217 }
6218
Tobin Ehlis0b632332015-10-07 09:38:40 -06006219 VkLayerDispatchTable* pTable = dev_data->device_dispatch_table;
6220 if (dev_data->device_extensions.debug_marker_enabled)
Jon Ashburn8fd08252015-05-28 16:25:02 -06006221 {
Jon Ashburn747f2b62015-06-18 15:02:58 -06006222 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006223 return (PFN_vkVoidFunction) vkCmdDbgMarkerBegin;
Jon Ashburn747f2b62015-06-18 15:02:58 -06006224 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006225 return (PFN_vkVoidFunction) vkCmdDbgMarkerEnd;
Jon Ashburneab34492015-06-01 09:37:38 -06006226 }
6227 {
Jon Ashburn8fd08252015-05-28 16:25:02 -06006228 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006229 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006230 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburnf6b33db2015-05-05 14:22:52 -06006231 }
6232}
6233
Chia-I Wu9ab61502015-11-06 06:42:02 +08006234VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Jon Ashburnf6b33db2015-05-05 14:22:52 -06006235{
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006236 PFN_vkVoidFunction fptr;
Jon Ashburnf6b33db2015-05-05 14:22:52 -06006237 if (instance == NULL)
6238 return NULL;
6239
Tobin Ehlis0b632332015-10-07 09:38:40 -06006240 layer_data* my_data;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006241 /* loader uses this to force layer initialization; instance object is wrapped */
6242 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
Tobin Ehlis0b632332015-10-07 09:38:40 -06006243 VkBaseLayerObject* wrapped_inst = (VkBaseLayerObject*) instance;
6244 my_data = get_my_data_ptr(get_dispatch_key(wrapped_inst->baseObject), layer_data_map);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06006245 my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
6246 layer_init_instance_dispatch_table(my_data->instance_dispatch_table, wrapped_inst);
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006247 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006248 }
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06006249 if (!strcmp(funcName, "vkCreateInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006250 return (PFN_vkVoidFunction) vkCreateInstance;
Jon Ashburn3950e1b2015-05-20 09:00:28 -06006251 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006252 return (PFN_vkVoidFunction) vkDestroyInstance;
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -06006253 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
6254 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
6255 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
6256 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
6257 if (!strcmp(funcName, "vkEnumerateDeviceLayerProperties"))
6258 return (PFN_vkVoidFunction) vkEnumerateDeviceLayerProperties;
6259 if (!strcmp(funcName, "vkEnumerateDeviceExtensionProperties"))
6260 return (PFN_vkVoidFunction) vkEnumerateDeviceExtensionProperties;
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06006261
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006262 my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06006263 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06006264 if (fptr)
6265 return fptr;
6266
Jon Ashburn8fd08252015-05-28 16:25:02 -06006267 {
Tobin Ehlis0b632332015-10-07 09:38:40 -06006268 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006269 if (pTable->GetInstanceProcAddr == NULL)
Jon Ashburnf6b33db2015-05-05 14:22:52 -06006270 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006271 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006272 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006273}