blob: f8c7208863385d9574baecdf1e6bea65c7ce7b87 [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;
Mark Lobodzinski941aea92016-01-13 10:23:15 -0700126 unordered_map<VkDevice, VkPhysicalDeviceProperties> physDevPropertyMap;
Cody Northrop55443ef2015-09-28 15:09:32 -0600127
128 layer_data() :
129 report_data(nullptr),
Tobin Ehlis0b632332015-10-07 09:38:40 -0600130 device_dispatch_table(nullptr),
131 instance_dispatch_table(nullptr),
132 device_extensions()
Cody Northrop55443ef2015-09-28 15:09:32 -0600133 {};
134};
Michael Lentine15a47882016-01-06 10:05:48 -0600135
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700136// Code imported from ShaderChecker
137static void
Chris Forbes79b37f82016-01-18 08:56:09 +1300138build_type_def_index(shader_module *);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700139
Chris Forbesc7e2e202016-01-18 08:56:40 +1300140// A forward iterator over spirv instructions. Provides easy access to len, opcode, and content words
141// without the caller needing to care too much about the physical SPIRV module layout.
142struct spirv_inst_iter {
143 std::vector<uint32_t>::const_iterator zero;
144 std::vector<uint32_t>::const_iterator it;
145
146 uint32_t len() { return *it >> 16; }
147 uint32_t opcode() { return *it & 0x0ffffu; }
148 uint32_t const & word(unsigned n) { return it[n]; }
149 uint32_t offset() { return it - zero; }
150
151 spirv_inst_iter(std::vector<uint32_t>::const_iterator zero,
152 std::vector<uint32_t>::const_iterator it) : zero(zero), it(it) {}
153
154 bool operator== (spirv_inst_iter const & other) {
155 return it == other.it;
156 }
157
158 bool operator!= (spirv_inst_iter const & other) {
159 return it != other.it;
160 }
161
162 spirv_inst_iter operator++ (int) { /* x++ */
163 spirv_inst_iter ii = *this;
164 it += len();
165 return ii;
166 }
167
168 spirv_inst_iter operator++ () { /* ++x; */
169 it += len();
170 return *this;
171 }
172
173 /* The iterator and the value are the same thing. */
174 spirv_inst_iter & operator* () { return *this; }
175 spirv_inst_iter const & operator* () const { return *this; }
176};
177
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700178struct shader_module {
179 /* the spirv image itself */
180 vector<uint32_t> words;
181 /* a mapping of <id> to the first word of its def. this is useful because walking type
182 * trees requires jumping all over the instruction stream.
183 */
184 unordered_map<unsigned, unsigned> type_def_index;
185
186 shader_module(VkShaderModuleCreateInfo const *pCreateInfo) :
187 words((uint32_t *)pCreateInfo->pCode, (uint32_t *)pCreateInfo->pCode + pCreateInfo->codeSize / sizeof(uint32_t)),
188 type_def_index() {
189
Chris Forbes79b37f82016-01-18 08:56:09 +1300190 build_type_def_index(this);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700191 }
Chris Forbesc7e2e202016-01-18 08:56:40 +1300192
193 /* expose begin() / end() to enable range-based for */
194 spirv_inst_iter begin() const { return spirv_inst_iter(words.begin(), words.begin() + 5); } /* first insn */
195 spirv_inst_iter end() const { return spirv_inst_iter(words.begin(), words.end()); } /* just past last insn */
196 /* given an offset into the module, produce an iterator there. */
197 spirv_inst_iter at(unsigned offset) const { return spirv_inst_iter(words.begin(), words.begin() + offset); }
Chris Forbes1257f912016-01-18 12:07:01 +1300198
199 spirv_inst_iter get_type_def(unsigned type_id) const {
200 auto it = type_def_index.find(type_id);
201 if (it == type_def_index.end()) {
202 return end();
203 }
204 return at(it->second);
205 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700206};
207
Tobin Ehlisb212dfc2015-10-07 15:40:22 -0600208// TODO : Do we need to guard access to layer_data_map w/ lock?
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -0700209static unordered_map<void*, layer_data*> layer_data_map;
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -0600210
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600211static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
212// TODO : This can be much smarter, using separate locks for separate global data
213static int globalLockInitialized = 0;
214static loader_platform_thread_mutex globalLock;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600215#define MAX_TID 513
216static loader_platform_thread_id g_tidMapping[MAX_TID] = {0};
217static uint32_t g_maxTID = 0;
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600218
219template layer_data *get_my_data_ptr<layer_data>(
220 void *data_key,
221 std::unordered_map<void *, layer_data *> &data_map);
222
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600223// Map actual TID to an index value and return that index
224// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs
225static uint32_t getTIDIndex() {
226 loader_platform_thread_id tid = loader_platform_get_thread_id();
227 for (uint32_t i = 0; i < g_maxTID; i++) {
228 if (tid == g_tidMapping[i])
229 return i;
230 }
231 // Don't yet have mapping, set it and return newly set index
232 uint32_t retVal = (uint32_t) g_maxTID;
233 g_tidMapping[g_maxTID++] = tid;
234 assert(g_maxTID < MAX_TID);
235 return retVal;
236}
Tobin Ehlis559c6382015-11-05 09:52:49 -0700237
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600238// Return a string representation of CMD_TYPE enum
239static string cmdTypeToString(CMD_TYPE cmd)
240{
241 switch (cmd)
242 {
243 case CMD_BINDPIPELINE:
244 return "CMD_BINDPIPELINE";
245 case CMD_BINDPIPELINEDELTA:
246 return "CMD_BINDPIPELINEDELTA";
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600247 case CMD_SETVIEWPORTSTATE:
248 return "CMD_SETVIEWPORTSTATE";
249 case CMD_SETLINEWIDTHSTATE:
250 return "CMD_SETLINEWIDTHSTATE";
251 case CMD_SETDEPTHBIASSTATE:
252 return "CMD_SETDEPTHBIASSTATE";
253 case CMD_SETBLENDSTATE:
254 return "CMD_SETBLENDSTATE";
255 case CMD_SETDEPTHBOUNDSSTATE:
256 return "CMD_SETDEPTHBOUNDSSTATE";
257 case CMD_SETSTENCILREADMASKSTATE:
258 return "CMD_SETSTENCILREADMASKSTATE";
259 case CMD_SETSTENCILWRITEMASKSTATE:
260 return "CMD_SETSTENCILWRITEMASKSTATE";
261 case CMD_SETSTENCILREFERENCESTATE:
262 return "CMD_SETSTENCILREFERENCESTATE";
Tobin Ehlis793ad302015-04-03 12:01:11 -0600263 case CMD_BINDDESCRIPTORSETS:
264 return "CMD_BINDDESCRIPTORSETS";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600265 case CMD_BINDINDEXBUFFER:
266 return "CMD_BINDINDEXBUFFER";
267 case CMD_BINDVERTEXBUFFER:
268 return "CMD_BINDVERTEXBUFFER";
269 case CMD_DRAW:
270 return "CMD_DRAW";
271 case CMD_DRAWINDEXED:
272 return "CMD_DRAWINDEXED";
273 case CMD_DRAWINDIRECT:
274 return "CMD_DRAWINDIRECT";
275 case CMD_DRAWINDEXEDINDIRECT:
276 return "CMD_DRAWINDEXEDINDIRECT";
277 case CMD_DISPATCH:
278 return "CMD_DISPATCH";
279 case CMD_DISPATCHINDIRECT:
280 return "CMD_DISPATCHINDIRECT";
281 case CMD_COPYBUFFER:
282 return "CMD_COPYBUFFER";
283 case CMD_COPYIMAGE:
284 return "CMD_COPYIMAGE";
Tobin Ehlis793ad302015-04-03 12:01:11 -0600285 case CMD_BLITIMAGE:
286 return "CMD_BLITIMAGE";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600287 case CMD_COPYBUFFERTOIMAGE:
288 return "CMD_COPYBUFFERTOIMAGE";
289 case CMD_COPYIMAGETOBUFFER:
290 return "CMD_COPYIMAGETOBUFFER";
291 case CMD_CLONEIMAGEDATA:
292 return "CMD_CLONEIMAGEDATA";
293 case CMD_UPDATEBUFFER:
294 return "CMD_UPDATEBUFFER";
295 case CMD_FILLBUFFER:
296 return "CMD_FILLBUFFER";
297 case CMD_CLEARCOLORIMAGE:
298 return "CMD_CLEARCOLORIMAGE";
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -0600299 case CMD_CLEARATTACHMENTS:
Tobin Ehlis53eddda2015-07-01 16:46:13 -0600300 return "CMD_CLEARCOLORATTACHMENT";
301 case CMD_CLEARDEPTHSTENCILIMAGE:
302 return "CMD_CLEARDEPTHSTENCILIMAGE";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600303 case CMD_RESOLVEIMAGE:
304 return "CMD_RESOLVEIMAGE";
305 case CMD_SETEVENT:
306 return "CMD_SETEVENT";
307 case CMD_RESETEVENT:
308 return "CMD_RESETEVENT";
309 case CMD_WAITEVENTS:
310 return "CMD_WAITEVENTS";
311 case CMD_PIPELINEBARRIER:
312 return "CMD_PIPELINEBARRIER";
313 case CMD_BEGINQUERY:
314 return "CMD_BEGINQUERY";
315 case CMD_ENDQUERY:
316 return "CMD_ENDQUERY";
317 case CMD_RESETQUERYPOOL:
318 return "CMD_RESETQUERYPOOL";
Mark Lobodzinski5495d132015-09-30 16:19:16 -0600319 case CMD_COPYQUERYPOOLRESULTS:
320 return "CMD_COPYQUERYPOOLRESULTS";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600321 case CMD_WRITETIMESTAMP:
322 return "CMD_WRITETIMESTAMP";
323 case CMD_INITATOMICCOUNTERS:
324 return "CMD_INITATOMICCOUNTERS";
325 case CMD_LOADATOMICCOUNTERS:
326 return "CMD_LOADATOMICCOUNTERS";
327 case CMD_SAVEATOMICCOUNTERS:
328 return "CMD_SAVEATOMICCOUNTERS";
329 case CMD_BEGINRENDERPASS:
330 return "CMD_BEGINRENDERPASS";
331 case CMD_ENDRENDERPASS:
332 return "CMD_ENDRENDERPASS";
333 case CMD_DBGMARKERBEGIN:
334 return "CMD_DBGMARKERBEGIN";
335 case CMD_DBGMARKEREND:
336 return "CMD_DBGMARKEREND";
337 default:
338 return "UNKNOWN";
339 }
340}
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700341
342// SPIRV utility functions
343static void
Chris Forbes79b37f82016-01-18 08:56:09 +1300344build_type_def_index(shader_module *module)
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700345{
Chris Forbesc7e2e202016-01-18 08:56:40 +1300346 for (auto insn : *module) {
347 switch (insn.opcode()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700348 case spv::OpTypeVoid:
349 case spv::OpTypeBool:
350 case spv::OpTypeInt:
351 case spv::OpTypeFloat:
352 case spv::OpTypeVector:
353 case spv::OpTypeMatrix:
354 case spv::OpTypeImage:
355 case spv::OpTypeSampler:
356 case spv::OpTypeSampledImage:
357 case spv::OpTypeArray:
358 case spv::OpTypeRuntimeArray:
359 case spv::OpTypeStruct:
360 case spv::OpTypeOpaque:
361 case spv::OpTypePointer:
362 case spv::OpTypeFunction:
363 case spv::OpTypeEvent:
364 case spv::OpTypeDeviceEvent:
365 case spv::OpTypeReserveId:
366 case spv::OpTypeQueue:
367 case spv::OpTypePipe:
Chris Forbesc7e2e202016-01-18 08:56:40 +1300368 module->type_def_index[insn.word(1)] = insn.offset();
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700369 break;
370
371 default:
372 /* We only care about type definitions */
373 break;
374 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700375 }
376}
377
378bool
379shader_is_spirv(VkShaderModuleCreateInfo const *pCreateInfo)
380{
381 uint32_t *words = (uint32_t *)pCreateInfo->pCode;
382 size_t sizeInWords = pCreateInfo->codeSize / sizeof(uint32_t);
383
384 /* Just validate that the header makes sense. */
385 return sizeInWords >= 5 && words[0] == spv::MagicNumber && words[1] == spv::Version;
386}
387
388static char const *
389storage_class_name(unsigned sc)
390{
391 switch (sc) {
392 case spv::StorageClassInput: return "input";
393 case spv::StorageClassOutput: return "output";
394 case spv::StorageClassUniformConstant: return "const uniform";
395 case spv::StorageClassUniform: return "uniform";
396 case spv::StorageClassWorkgroup: return "workgroup local";
397 case spv::StorageClassCrossWorkgroup: return "workgroup global";
398 case spv::StorageClassPrivate: return "private global";
399 case spv::StorageClassFunction: return "function";
400 case spv::StorageClassGeneric: return "generic";
401 case spv::StorageClassAtomicCounter: return "atomic counter";
402 case spv::StorageClassImage: return "image";
403 default: return "unknown";
404 }
405}
406
407/* returns ptr to null terminator */
408static char *
409describe_type(char *dst, shader_module const *src, unsigned type)
410{
Chris Forbes1257f912016-01-18 12:07:01 +1300411 auto insn = src->get_type_def(type);
412 assert(insn != src->end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700413
Chris Forbes1257f912016-01-18 12:07:01 +1300414 switch (insn.opcode()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700415 case spv::OpTypeBool:
416 return dst + sprintf(dst, "bool");
417 case spv::OpTypeInt:
Chris Forbes1257f912016-01-18 12:07:01 +1300418 return dst + sprintf(dst, "%cint%d", insn.word(3) ? 's' : 'u', insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700419 case spv::OpTypeFloat:
Chris Forbes1257f912016-01-18 12:07:01 +1300420 return dst + sprintf(dst, "float%d", insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700421 case spv::OpTypeVector:
Chris Forbes1257f912016-01-18 12:07:01 +1300422 dst += sprintf(dst, "vec%d of ", insn.word(3));
423 return describe_type(dst, src, insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700424 case spv::OpTypeMatrix:
Chris Forbes1257f912016-01-18 12:07:01 +1300425 dst += sprintf(dst, "mat%d of ", insn.word(3));
426 return describe_type(dst, src, insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700427 case spv::OpTypeArray:
Chris Forbes1257f912016-01-18 12:07:01 +1300428 dst += sprintf(dst, "arr[%d] of ", insn.word(3));
429 return describe_type(dst, src, insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700430 case spv::OpTypePointer:
Chris Forbes1257f912016-01-18 12:07:01 +1300431 dst += sprintf(dst, "ptr to %s ", storage_class_name(insn.word(2)));
432 return describe_type(dst, src, insn.word(3));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700433 case spv::OpTypeStruct:
434 {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700435 dst += sprintf(dst, "struct of (");
Chris Forbes1257f912016-01-18 12:07:01 +1300436 for (unsigned i = 2; i < insn.len(); i++) {
437 dst = describe_type(dst, src, insn.word(i));
438 dst += sprintf(dst, i == insn.len()-1 ? ")" : ", ");
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700439 }
440 return dst;
441 }
442 case spv::OpTypeSampler:
443 return dst + sprintf(dst, "sampler");
444 default:
445 return dst + sprintf(dst, "oddtype");
446 }
447}
448
449static bool
450types_match(shader_module const *a, shader_module const *b, unsigned a_type, unsigned b_type, bool b_arrayed)
451{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700452 /* walk two type trees together, and complain about differences */
Chris Forbes1257f912016-01-18 12:07:01 +1300453 auto a_insn = a->get_type_def(a_type);
454 auto b_insn = b->get_type_def(b_type);
455 assert(a_insn != a->end());
456 assert(b_insn != b->end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700457
Chris Forbes1257f912016-01-18 12:07:01 +1300458 if (b_arrayed && b_insn.opcode() == spv::OpTypeArray) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700459 /* we probably just found the extra level of arrayness in b_type: compare the type inside it to a_type */
Chris Forbes1257f912016-01-18 12:07:01 +1300460 return types_match(a, b, a_type, b_insn.word(2), false);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700461 }
462
Chris Forbes1257f912016-01-18 12:07:01 +1300463 if (a_insn.opcode() != b_insn.opcode()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700464 return false;
465 }
466
Chris Forbes1257f912016-01-18 12:07:01 +1300467 switch (a_insn.opcode()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700468 /* if b_arrayed and we hit a leaf type, then we can't match -- there's nowhere for the extra OpTypeArray to be! */
469 case spv::OpTypeBool:
470 return true && !b_arrayed;
471 case spv::OpTypeInt:
472 /* match on width, signedness */
Chris Forbes1257f912016-01-18 12:07:01 +1300473 return a_insn.word(2) == b_insn.word(2) && a_insn.word(3) == b_insn.word(3) && !b_arrayed;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700474 case spv::OpTypeFloat:
475 /* match on width */
Chris Forbes1257f912016-01-18 12:07:01 +1300476 return a_insn.word(2) == b_insn.word(2) && !b_arrayed;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700477 case spv::OpTypeVector:
478 case spv::OpTypeMatrix:
479 case spv::OpTypeArray:
480 /* match on element type, count. these all have the same layout. we don't get here if
481 * b_arrayed -- that is handled above. */
Chris Forbes1257f912016-01-18 12:07:01 +1300482 return !b_arrayed && types_match(a, b, a_insn.word(2), b_insn.word(2), b_arrayed) && a_insn.word(3) == b_insn.word(3);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700483 case spv::OpTypeStruct:
484 /* match on all element types */
485 {
486 if (b_arrayed) {
487 /* for the purposes of matching different levels of arrayness, structs are leaves. */
488 return false;
489 }
490
Chris Forbes1257f912016-01-18 12:07:01 +1300491 if (a_insn.len() != b_insn.len()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700492 return false; /* structs cannot match if member counts differ */
493 }
494
Chris Forbes1257f912016-01-18 12:07:01 +1300495 for (unsigned i = 2; i < a_insn.len(); i++) {
496 if (!types_match(a, b, a_insn.word(i), b_insn.word(i), b_arrayed)) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700497 return false;
498 }
499 }
500
501 return true;
502 }
503 case spv::OpTypePointer:
504 /* match on pointee type. storage class is expected to differ */
Chris Forbes1257f912016-01-18 12:07:01 +1300505 return types_match(a, b, a_insn.word(3), b_insn.word(3), b_arrayed);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700506
507 default:
508 /* remaining types are CLisms, or may not appear in the interfaces we
509 * are interested in. Just claim no match.
510 */
511 return false;
512
513 }
514}
515
516static int
517value_or_default(std::unordered_map<unsigned, unsigned> const &map, unsigned id, int def)
518{
519 auto it = map.find(id);
520 if (it == map.end())
521 return def;
522 else
523 return it->second;
524}
525
526
527static unsigned
528get_locations_consumed_by_type(shader_module const *src, unsigned type, bool strip_array_level)
529{
Chris Forbes1257f912016-01-18 12:07:01 +1300530 auto insn = src->get_type_def(type);
531 assert(insn != src->end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700532
Chris Forbesc7e2e202016-01-18 08:56:40 +1300533 switch (insn.opcode()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700534 case spv::OpTypePointer:
535 /* see through the ptr -- this is only ever at the toplevel for graphics shaders;
536 * we're never actually passing pointers around. */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300537 return get_locations_consumed_by_type(src, insn.word(3), strip_array_level);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700538 case spv::OpTypeArray:
539 if (strip_array_level) {
Chris Forbesc7e2e202016-01-18 08:56:40 +1300540 return get_locations_consumed_by_type(src, insn.word(2), false);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700541 }
542 else {
Chris Forbesc7e2e202016-01-18 08:56:40 +1300543 return insn.word(3) * get_locations_consumed_by_type(src, insn.word(2), false);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700544 }
545 case spv::OpTypeMatrix:
546 /* num locations is the dimension * element size */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300547 return insn.word(3) * get_locations_consumed_by_type(src, insn.word(2), false);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700548 default:
549 /* everything else is just 1. */
550 return 1;
551
552 /* TODO: extend to handle 64bit scalar types, whose vectors may need
553 * multiple locations. */
554 }
555}
556
557
558struct interface_var {
559 uint32_t id;
560 uint32_t type_id;
561 uint32_t offset;
562 /* TODO: collect the name, too? Isn't required to be present. */
563};
564
Chris Forbesa3e85f62016-01-15 14:53:11 +1300565
566static void
567collect_interface_block_members(layer_data *my_data, VkDevice dev,
568 shader_module const *src,
569 std::map<uint32_t, interface_var> &out,
570 std::map<uint32_t, interface_var> &builtins_out,
571 std::unordered_map<unsigned, unsigned> const &blocks,
572 bool is_array_of_verts,
573 uint32_t id,
574 uint32_t type_id)
575{
576 /* Walk down the type_id presented, trying to determine whether it's actually an interface block. */
Chris Forbes1257f912016-01-18 12:07:01 +1300577 auto type = src->get_type_def(type_id);
578
Chris Forbesa3e85f62016-01-15 14:53:11 +1300579 while (true) {
580
Chris Forbes1257f912016-01-18 12:07:01 +1300581 if (type.opcode() == spv::OpTypePointer) {
582 type = src->get_type_def(type.word(3));
Chris Forbesa3e85f62016-01-15 14:53:11 +1300583 }
Chris Forbes1257f912016-01-18 12:07:01 +1300584 else if (type.opcode() == spv::OpTypeArray && is_array_of_verts) {
585 type = src->get_type_def(type.word(2));
Chris Forbesa3e85f62016-01-15 14:53:11 +1300586 is_array_of_verts = false;
587 }
Chris Forbes1257f912016-01-18 12:07:01 +1300588 else if (type.opcode() == spv::OpTypeStruct) {
589 if (blocks.find(type.word(1)) == blocks.end()) {
Chris Forbesa3e85f62016-01-15 14:53:11 +1300590 /* This isn't an interface block. */
591 return;
592 }
593 else {
594 /* We have found the correct type. Walk its members. */
595 break;
596 }
597 }
598 else {
599 /* not an interface block */
600 return;
601 }
602 }
603
Chris Forbes1257f912016-01-18 12:07:01 +1300604 /* Walk all the OpMemberDecorate for type's result id. */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300605 for (auto insn : *src) {
Chris Forbes1257f912016-01-18 12:07:01 +1300606 if (insn.opcode() == spv::OpMemberDecorate && insn.word(1) == type.word(1)) {
Chris Forbesc7e2e202016-01-18 08:56:40 +1300607 unsigned member_index = insn.word(2);
Chris Forbes1257f912016-01-18 12:07:01 +1300608 unsigned member_type_id = type.word(2 + member_index);
Chris Forbesa3e85f62016-01-15 14:53:11 +1300609
Chris Forbesc7e2e202016-01-18 08:56:40 +1300610 if (insn.word(3) == spv::DecorationLocation) {
611 unsigned location = insn.word(4);
Chris Forbesa3e85f62016-01-15 14:53:11 +1300612 unsigned num_locations = get_locations_consumed_by_type(src, member_type_id, false);
613 for (unsigned int offset = 0; offset < num_locations; offset++) {
614 interface_var v;
615 v.id = id;
616 /* TODO: member index in interface_var too? */
617 v.type_id = member_type_id;
618 v.offset = offset;
619 out[location + offset] = v;
620 }
621 }
Chris Forbesc7e2e202016-01-18 08:56:40 +1300622 else if (insn.word(3) == spv::DecorationBuiltIn) {
623 unsigned builtin = insn.word(4);
Chris Forbesa3e85f62016-01-15 14:53:11 +1300624 interface_var v;
625 v.id = id;
626 v.type_id = member_type_id;
627 v.offset = 0;
628 builtins_out[builtin] = v;
629 }
630 }
Chris Forbesa3e85f62016-01-15 14:53:11 +1300631 }
632}
633
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700634static void
635collect_interface_by_location(layer_data *my_data, VkDevice dev,
636 shader_module const *src, spv::StorageClass sinterface,
637 std::map<uint32_t, interface_var> &out,
638 std::map<uint32_t, interface_var> &builtins_out,
639 bool is_array_of_verts)
640{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700641 std::unordered_map<unsigned, unsigned> var_locations;
642 std::unordered_map<unsigned, unsigned> var_builtins;
Chris Forbesa3e85f62016-01-15 14:53:11 +1300643 std::unordered_map<unsigned, unsigned> blocks;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700644
Chris Forbesc7e2e202016-01-18 08:56:40 +1300645 for (auto insn : *src) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700646
647 /* We consider two interface models: SSO rendezvous-by-location, and
648 * builtins. Complain about anything that fits neither model.
649 */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300650 if (insn.opcode() == spv::OpDecorate) {
651 if (insn.word(2) == spv::DecorationLocation) {
652 var_locations[insn.word(1)] = insn.word(3);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700653 }
654
Chris Forbesc7e2e202016-01-18 08:56:40 +1300655 if (insn.word(2) == spv::DecorationBuiltIn) {
656 var_builtins[insn.word(1)] = insn.word(3);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700657 }
Chris Forbesa3e85f62016-01-15 14:53:11 +1300658
Chris Forbesc7e2e202016-01-18 08:56:40 +1300659 if (insn.word(2) == spv::DecorationBlock) {
660 blocks[insn.word(1)] = 1;
Chris Forbesa3e85f62016-01-15 14:53:11 +1300661 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700662 }
663
664 /* TODO: handle grouped decorations */
665 /* TODO: handle index=1 dual source outputs from FS -- two vars will
666 * have the same location, and we DONT want to clobber. */
667
Chris Forbesc7e2e202016-01-18 08:56:40 +1300668 else if (insn.opcode() == spv::OpVariable && insn.word(3) == sinterface) {
669 unsigned id = insn.word(2);
670 unsigned type = insn.word(1);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700671
Chris Forbesc7e2e202016-01-18 08:56:40 +1300672 int location = value_or_default(var_locations, id, -1);
673 int builtin = value_or_default(var_builtins, id, -1);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700674
Chris Forbesf5020cf2016-01-13 09:29:31 +1300675 /* All variables and interface block members in the Input or Output storage classes
676 * must be decorated with either a builtin or an explicit location.
677 *
678 * TODO: integrate the interface block support here. For now, don't complain --
679 * a valid SPIRV module will only hit this path for the interface block case, as the
680 * individual members of the type are decorated, rather than variable declarations.
681 */
682
683 if (location != -1) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700684 /* A user-defined interface variable, with a location. Where a variable
685 * occupied multiple locations, emit one result for each. */
686 unsigned num_locations = get_locations_consumed_by_type(src, type,
687 is_array_of_verts);
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -0700688 for (unsigned int offset = 0; offset < num_locations; offset++) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700689 interface_var v;
690 v.id = id;
691 v.type_id = type;
692 v.offset = offset;
693 out[location + offset] = v;
694 }
695 }
Chris Forbesf5020cf2016-01-13 09:29:31 +1300696 else if (builtin != -1) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700697 /* A builtin interface variable */
698 /* Note that since builtin interface variables do not consume numbered
699 * locations, there is no larger-than-vec4 consideration as above
700 */
701 interface_var v;
702 v.id = id;
703 v.type_id = type;
704 v.offset = 0;
705 builtins_out[builtin] = v;
706 }
Chris Forbesa3e85f62016-01-15 14:53:11 +1300707 else {
708 /* An interface block instance */
709 collect_interface_block_members(my_data, dev, src, out, builtins_out,
710 blocks, is_array_of_verts, id, type);
711 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700712 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700713 }
714}
715
716static void
717collect_interface_by_descriptor_slot(layer_data *my_data, VkDevice dev,
718 shader_module const *src, spv::StorageClass sinterface,
719 std::map<std::pair<unsigned, unsigned>, interface_var> &out)
720{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700721
722 std::unordered_map<unsigned, unsigned> var_sets;
723 std::unordered_map<unsigned, unsigned> var_bindings;
724
Chris Forbesc7e2e202016-01-18 08:56:40 +1300725 for (auto insn : *src) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700726 /* All variables in the Uniform or UniformConstant storage classes are required to be decorated with both
727 * DecorationDescriptorSet and DecorationBinding.
728 */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300729 if (insn.opcode() == spv::OpDecorate) {
730 if (insn.word(2) == spv::DecorationDescriptorSet) {
731 var_sets[insn.word(1)] = insn.word(3);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700732 }
733
Chris Forbesc7e2e202016-01-18 08:56:40 +1300734 if (insn.word(2) == spv::DecorationBinding) {
735 var_bindings[insn.word(1)] = insn.word(3);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700736 }
737 }
738
Chris Forbesc7e2e202016-01-18 08:56:40 +1300739 else if (insn.opcode() == spv::OpVariable &&
740 (insn.word(3) == spv::StorageClassUniform ||
741 insn.word(3) == spv::StorageClassUniformConstant)) {
742 unsigned set = value_or_default(var_sets, insn.word(2), 0);
743 unsigned binding = value_or_default(var_bindings, insn.word(2), 0);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700744
745 auto existing_it = out.find(std::make_pair(set, binding));
746 if (existing_it != out.end()) {
747 /* conflict within spv image */
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700748 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 -0700749 SHADER_CHECKER_INCONSISTENT_SPIRV, "SC",
750 "var %d (type %d) in %s interface in descriptor slot (%u,%u) conflicts with existing definition",
Chris Forbesc7e2e202016-01-18 08:56:40 +1300751 insn.word(2), insn.word(1), storage_class_name(sinterface),
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700752 existing_it->first.first, existing_it->first.second);
753 }
754
755 interface_var v;
Chris Forbesc7e2e202016-01-18 08:56:40 +1300756 v.id = insn.word(2);
757 v.type_id = insn.word(1);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700758 out[std::make_pair(set, binding)] = v;
759 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700760 }
761}
762
763static bool
764validate_interface_between_stages(layer_data *my_data, VkDevice dev,
765 shader_module const *producer, char const *producer_name,
766 shader_module const *consumer, char const *consumer_name,
767 bool consumer_arrayed_input)
768{
769 std::map<uint32_t, interface_var> outputs;
770 std::map<uint32_t, interface_var> inputs;
771
772 std::map<uint32_t, interface_var> builtin_outputs;
773 std::map<uint32_t, interface_var> builtin_inputs;
774
775 bool pass = true;
776
777 collect_interface_by_location(my_data, dev, producer, spv::StorageClassOutput, outputs, builtin_outputs, false);
778 collect_interface_by_location(my_data, dev, consumer, spv::StorageClassInput, inputs, builtin_inputs,
779 consumer_arrayed_input);
780
781 auto a_it = outputs.begin();
782 auto b_it = inputs.begin();
783
784 /* maps sorted by key (location); walk them together to find mismatches */
785 while ((outputs.size() > 0 && a_it != outputs.end()) || ( inputs.size() && b_it != inputs.end())) {
786 bool a_at_end = outputs.size() == 0 || a_it == outputs.end();
787 bool b_at_end = inputs.size() == 0 || b_it == inputs.end();
788 auto a_first = a_at_end ? 0 : a_it->first;
789 auto b_first = b_at_end ? 0 : b_it->first;
790
791 if (b_at_end || ((!a_at_end) && (a_first < b_first))) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700792 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 -0700793 "%s writes to output location %d which is not consumed by %s", producer_name, a_first, consumer_name)) {
794 pass = false;
795 }
796 a_it++;
797 }
798 else if (a_at_end || a_first > b_first) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700799 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 -0700800 "%s consumes input location %d which is not written by %s", consumer_name, b_first, producer_name)) {
801 pass = false;
802 }
803 b_it++;
804 }
805 else {
806 if (types_match(producer, consumer, a_it->second.type_id, b_it->second.type_id, consumer_arrayed_input)) {
807 /* OK! */
808 }
809 else {
810 char producer_type[1024];
811 char consumer_type[1024];
812 describe_type(producer_type, producer, a_it->second.type_id);
813 describe_type(consumer_type, consumer, b_it->second.type_id);
814
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700815 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 -0700816 "Type mismatch on location %d: '%s' vs '%s'", a_it->first, producer_type, consumer_type)) {
817 pass = false;
818 }
819 }
820 a_it++;
821 b_it++;
822 }
823 }
824
825 return pass;
826}
827
828enum FORMAT_TYPE {
829 FORMAT_TYPE_UNDEFINED,
830 FORMAT_TYPE_FLOAT, /* UNORM, SNORM, FLOAT, USCALED, SSCALED, SRGB -- anything we consider float in the shader */
831 FORMAT_TYPE_SINT,
832 FORMAT_TYPE_UINT,
833};
834
835static unsigned
836get_format_type(VkFormat fmt) {
837 switch (fmt) {
838 case VK_FORMAT_UNDEFINED:
839 return FORMAT_TYPE_UNDEFINED;
840 case VK_FORMAT_R8_SINT:
841 case VK_FORMAT_R8G8_SINT:
842 case VK_FORMAT_R8G8B8_SINT:
843 case VK_FORMAT_R8G8B8A8_SINT:
844 case VK_FORMAT_R16_SINT:
845 case VK_FORMAT_R16G16_SINT:
846 case VK_FORMAT_R16G16B16_SINT:
847 case VK_FORMAT_R16G16B16A16_SINT:
848 case VK_FORMAT_R32_SINT:
849 case VK_FORMAT_R32G32_SINT:
850 case VK_FORMAT_R32G32B32_SINT:
851 case VK_FORMAT_R32G32B32A32_SINT:
852 case VK_FORMAT_B8G8R8_SINT:
853 case VK_FORMAT_B8G8R8A8_SINT:
854 case VK_FORMAT_A2B10G10R10_SINT_PACK32:
855 case VK_FORMAT_A2R10G10B10_SINT_PACK32:
856 return FORMAT_TYPE_SINT;
857 case VK_FORMAT_R8_UINT:
858 case VK_FORMAT_R8G8_UINT:
859 case VK_FORMAT_R8G8B8_UINT:
860 case VK_FORMAT_R8G8B8A8_UINT:
861 case VK_FORMAT_R16_UINT:
862 case VK_FORMAT_R16G16_UINT:
863 case VK_FORMAT_R16G16B16_UINT:
864 case VK_FORMAT_R16G16B16A16_UINT:
865 case VK_FORMAT_R32_UINT:
866 case VK_FORMAT_R32G32_UINT:
867 case VK_FORMAT_R32G32B32_UINT:
868 case VK_FORMAT_R32G32B32A32_UINT:
869 case VK_FORMAT_B8G8R8_UINT:
870 case VK_FORMAT_B8G8R8A8_UINT:
871 case VK_FORMAT_A2B10G10R10_UINT_PACK32:
872 case VK_FORMAT_A2R10G10B10_UINT_PACK32:
873 return FORMAT_TYPE_UINT;
874 default:
875 return FORMAT_TYPE_FLOAT;
876 }
877}
878
879/* characterizes a SPIR-V type appearing in an interface to a FF stage,
880 * for comparison to a VkFormat's characterization above. */
881static unsigned
882get_fundamental_type(shader_module const *src, unsigned type)
883{
Chris Forbes1257f912016-01-18 12:07:01 +1300884 auto insn = src->get_type_def(type);
885 assert(insn != src->end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700886
Chris Forbes1257f912016-01-18 12:07:01 +1300887 switch (insn.opcode()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700888 case spv::OpTypeInt:
Chris Forbes1257f912016-01-18 12:07:01 +1300889 return insn.word(3) ? FORMAT_TYPE_SINT : FORMAT_TYPE_UINT;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700890 case spv::OpTypeFloat:
891 return FORMAT_TYPE_FLOAT;
892 case spv::OpTypeVector:
Chris Forbes1257f912016-01-18 12:07:01 +1300893 return get_fundamental_type(src, insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700894 case spv::OpTypeMatrix:
Chris Forbes1257f912016-01-18 12:07:01 +1300895 return get_fundamental_type(src, insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700896 case spv::OpTypeArray:
Chris Forbes1257f912016-01-18 12:07:01 +1300897 return get_fundamental_type(src, insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700898 case spv::OpTypePointer:
Chris Forbes1257f912016-01-18 12:07:01 +1300899 return get_fundamental_type(src, insn.word(3));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700900 default:
901 return FORMAT_TYPE_UNDEFINED;
902 }
903}
904
905static bool
906validate_vi_consistency(layer_data *my_data, VkDevice dev, VkPipelineVertexInputStateCreateInfo const *vi)
907{
908 /* walk the binding descriptions, which describe the step rate and stride of each vertex buffer.
909 * each binding should be specified only once.
910 */
911 std::unordered_map<uint32_t, VkVertexInputBindingDescription const *> bindings;
912 bool pass = true;
913
914 for (unsigned i = 0; i < vi->vertexBindingDescriptionCount; i++) {
915 auto desc = &vi->pVertexBindingDescriptions[i];
916 auto & binding = bindings[desc->binding];
917 if (binding) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700918 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 -0700919 "Duplicate vertex input binding descriptions for binding %d", desc->binding)) {
920 pass = false;
921 }
922 }
923 else {
924 binding = desc;
925 }
926 }
927
928 return pass;
929}
930
931static bool
932validate_vi_against_vs_inputs(layer_data *my_data, VkDevice dev, VkPipelineVertexInputStateCreateInfo const *vi, shader_module const *vs)
933{
934 std::map<uint32_t, interface_var> inputs;
935 /* we collect builtin inputs, but they will never appear in the VI state --
936 * the vs builtin inputs are generated in the pipeline, not sourced from buffers (VertexID, etc)
937 */
938 std::map<uint32_t, interface_var> builtin_inputs;
939 bool pass = true;
940
941 collect_interface_by_location(my_data, dev, vs, spv::StorageClassInput, inputs, builtin_inputs, false);
942
943 /* Build index by location */
944 std::map<uint32_t, VkVertexInputAttributeDescription const *> attribs;
945 if (vi) {
946 for (unsigned i = 0; i < vi->vertexAttributeDescriptionCount; i++)
947 attribs[vi->pVertexAttributeDescriptions[i].location] = &vi->pVertexAttributeDescriptions[i];
948 }
949
950 auto it_a = attribs.begin();
951 auto it_b = inputs.begin();
952
953 while ((attribs.size() > 0 && it_a != attribs.end()) || (inputs.size() > 0 && it_b != inputs.end())) {
954 bool a_at_end = attribs.size() == 0 || it_a == attribs.end();
955 bool b_at_end = inputs.size() == 0 || it_b == inputs.end();
956 auto a_first = a_at_end ? 0 : it_a->first;
957 auto b_first = b_at_end ? 0 : it_b->first;
Chris Forbes7d83cd52016-01-15 11:32:03 +1300958 if (!a_at_end && (b_at_end || a_first < b_first)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700959 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 -0700960 "Vertex attribute at location %d not consumed by VS", a_first)) {
961 pass = false;
962 }
963 it_a++;
964 }
Chris Forbes7d83cd52016-01-15 11:32:03 +1300965 else if (!b_at_end && (a_at_end || b_first < a_first)) {
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_INPUT_NOT_PRODUCED, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700967 "VS consumes input at location %d but not provided", b_first)) {
968 pass = false;
969 }
970 it_b++;
971 }
972 else {
973 unsigned attrib_type = get_format_type(it_a->second->format);
974 unsigned input_type = get_fundamental_type(vs, it_b->second.type_id);
975
976 /* type checking */
977 if (attrib_type != FORMAT_TYPE_UNDEFINED && input_type != FORMAT_TYPE_UNDEFINED && attrib_type != input_type) {
978 char vs_type[1024];
979 describe_type(vs_type, vs, it_b->second.type_id);
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700980 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 -0700981 "Attribute type of `%s` at location %d does not match VS input type of `%s`",
982 string_VkFormat(it_a->second->format), a_first, vs_type)) {
983 pass = false;
984 }
985 }
986
987 /* OK! */
988 it_a++;
989 it_b++;
990 }
991 }
992
993 return pass;
994}
995
996static bool
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -0700997validate_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 -0700998{
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -0700999 const std::vector<VkFormat> &color_formats = rp->subpassColorFormats[subpass];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001000 std::map<uint32_t, interface_var> outputs;
1001 std::map<uint32_t, interface_var> builtin_outputs;
1002 bool pass = true;
1003
1004 /* TODO: dual source blend index (spv::DecIndex, zero if not provided) */
1005
1006 collect_interface_by_location(my_data, dev, fs, spv::StorageClassOutput, outputs, builtin_outputs, false);
1007
1008 auto it = outputs.begin();
1009 uint32_t attachment = 0;
1010
1011 /* Walk attachment list and outputs together -- this is a little overpowered since attachments
1012 * are currently dense, but the parallel with matching between shader stages is nice.
1013 */
1014
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001015 while ((outputs.size() > 0 && it != outputs.end()) || attachment < color_formats.size()) {
1016 if (attachment == color_formats.size() || ( it != outputs.end() && it->first < attachment)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001017 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 -07001018 "FS writes to output location %d with no matching attachment", it->first)) {
1019 pass = false;
1020 }
1021 it++;
1022 }
1023 else if (it == outputs.end() || it->first > attachment) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001024 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 -07001025 "Attachment %d not written by FS", attachment)) {
1026 pass = false;
1027 }
1028 attachment++;
1029 }
1030 else {
1031 unsigned output_type = get_fundamental_type(fs, it->second.type_id);
1032 unsigned att_type = get_format_type(color_formats[attachment]);
1033
1034 /* type checking */
1035 if (att_type != FORMAT_TYPE_UNDEFINED && output_type != FORMAT_TYPE_UNDEFINED && att_type != output_type) {
1036 char fs_type[1024];
1037 describe_type(fs_type, fs, it->second.type_id);
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001038 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 -07001039 "Attachment %d of type `%s` does not match FS output type of `%s`",
1040 attachment, string_VkFormat(color_formats[attachment]), fs_type)) {
1041 pass = false;
1042 }
1043 }
1044
1045 /* OK! */
1046 it++;
1047 attachment++;
1048 }
1049 }
1050
1051 return pass;
1052}
1053
1054
1055struct shader_stage_attributes {
1056 char const * const name;
1057 bool arrayed_input;
1058};
1059
1060
1061static shader_stage_attributes
1062shader_stage_attribs[] = {
1063 { "vertex shader", false },
1064 { "tessellation control shader", true },
1065 { "tessellation evaluation shader", false },
1066 { "geometry shader", true },
1067 { "fragment shader", false },
1068};
1069
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001070// For given pipelineLayout verify that the setLayout at slot.first
1071// has the requested binding at slot.second
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001072static bool
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001073has_descriptor_binding(layer_data* my_data,
1074 vector<VkDescriptorSetLayout>* pipelineLayout,
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001075 std::pair<unsigned, unsigned> slot)
1076{
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001077 if (!pipelineLayout)
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001078 return false;
1079
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001080 if (slot.first >= pipelineLayout->size())
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001081 return false;
1082
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001083 auto set = my_data->descriptorSetLayoutMap[(*pipelineLayout)[slot.first]]->bindings;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001084
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001085 return (set.find(slot.second) != set.end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001086}
1087
1088static uint32_t get_shader_stage_id(VkShaderStageFlagBits stage)
1089{
1090 uint32_t bit_pos = u_ffs(stage);
1091 return bit_pos-1;
1092}
1093
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001094// Block of code at start here for managing/tracking Pipeline state that this layer cares about
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001095
1096static uint64_t g_drawCount[NUM_DRAW_TYPES] = {0, 0, 0, 0};
1097
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001098// 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 -06001099// Then need to synchronize the accesses based on cmd buffer so that if I'm reading state on one cmd buffer, updates
1100// to that same cmd buffer by separate thread are not changing state from underneath us
1101// Track the last cmd buffer touched by this thread
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001102
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001103// prototype
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001104static GLOBAL_CB_NODE* getCBNode(layer_data*, const VkCommandBuffer);
Tobin Ehlis559c6382015-11-05 09:52:49 -07001105
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06001106static VkBool32 hasDrawCmd(GLOBAL_CB_NODE* pCB)
Tobin Ehlis53eddda2015-07-01 16:46:13 -06001107{
1108 for (uint32_t i=0; i<NUM_DRAW_TYPES; i++) {
1109 if (pCB->drawCount[i])
1110 return VK_TRUE;
1111 }
1112 return VK_FALSE;
1113}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001114
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001115// Check object status for selected flag state
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001116static 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 -06001117{
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001118 // If non-zero enable mask is present, check it against status but if enable_mask
1119 // is 0 then no enable required so we should always just check status
1120 if ((!enable_mask) || (enable_mask & pNode->status)) {
1121 if ((pNode->status & status_mask) != status_flag) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001122 // TODO : How to pass dispatchable objects as srcObject? Here src obj should be cmd buffer
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001123 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 +08001124 "CB object %#" PRIxLEAST64 ": %s", reinterpret_cast<uint64_t>(pNode->commandBuffer), fail_msg);
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001125 }
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001126 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001127 return VK_FALSE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001128}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001129
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001130// Retrieve pipeline node ptr for given pipeline object
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001131static PIPELINE_NODE* getPipeline(layer_data* my_data, const VkPipeline pipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001132{
1133 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08001134 if (my_data->pipelineMap.find(pipeline) == my_data->pipelineMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001135 loader_platform_thread_unlock_mutex(&globalLock);
1136 return NULL;
1137 }
1138 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08001139 return my_data->pipelineMap[pipeline];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001140}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001141
Tobin Ehlisd332f282015-10-02 11:00:56 -06001142// Return VK_TRUE if for a given PSO, the given state enum is dynamic, else return VK_FALSE
1143static VkBool32 isDynamic(const PIPELINE_NODE* pPipeline, const VkDynamicState state)
1144{
1145 if (pPipeline && pPipeline->graphicsPipelineCI.pDynamicState) {
1146 for (uint32_t i=0; i<pPipeline->graphicsPipelineCI.pDynamicState->dynamicStateCount; i++) {
1147 if (state == pPipeline->graphicsPipelineCI.pDynamicState->pDynamicStates[i])
1148 return VK_TRUE;
1149 }
1150 }
1151 return VK_FALSE;
1152}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001153
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001154// Validate state stored as flags at time of draw call
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001155static VkBool32 validate_draw_state_flags(layer_data* my_data, GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06001156 VkBool32 result;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001157 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");
1158 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");
1159 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");
1160 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");
1161 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");
1162 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");
1163 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");
1164 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");
1165 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 -06001166 if (indexedDraw)
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001167 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 -06001168 return result;
1169}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001170
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001171// Verify attachment reference compatibility according to spec
1172// If one array is larger, treat missing elements of shorter array as VK_ATTACHMENT_UNUSED & other array much match this
1173// If both AttachmentReference arrays have requested index, check their corresponding AttachementDescriptions
1174// to make sure that format and samples counts match.
1175// If not, they are not compatible.
1176static bool attachment_references_compatible(const uint32_t index, const VkAttachmentReference* pPrimary, const uint32_t primaryCount, const VkAttachmentDescription* pPrimaryAttachments,
1177 const VkAttachmentReference* pSecondary, const uint32_t secondaryCount, const VkAttachmentDescription* pSecondaryAttachments)
1178{
1179 if (index >= primaryCount) { // Check secondary as if primary is VK_ATTACHMENT_UNUSED
1180 if (VK_ATTACHMENT_UNUSED != pSecondary[index].attachment)
1181 return false;
1182 } else if (index >= secondaryCount) { // Check primary as if secondary is VK_ATTACHMENT_UNUSED
1183 if (VK_ATTACHMENT_UNUSED != pPrimary[index].attachment)
1184 return false;
1185 } else { // format and sample count must match
1186 if ((pPrimaryAttachments[pPrimary[index].attachment].format == pSecondaryAttachments[pSecondary[index].attachment].format) &&
1187 (pPrimaryAttachments[pPrimary[index].attachment].samples == pSecondaryAttachments[pSecondary[index].attachment].samples))
1188 return true;
1189 }
1190 // Format and sample counts didn't match
1191 return false;
1192}
1193
1194// For give primary and secondary RenderPass objects, verify that they're compatible
1195static bool verify_renderpass_compatibility(layer_data* my_data, const VkRenderPass primaryRP, const VkRenderPass secondaryRP, string& errorMsg)
1196{
1197 stringstream errorStr;
1198 if (my_data->renderPassMap.find(primaryRP) == my_data->renderPassMap.end()) {
1199 errorStr << "invalid VkRenderPass (" << primaryRP << ")";
1200 errorMsg = errorStr.str();
1201 return false;
1202 } else if (my_data->renderPassMap.find(secondaryRP) == my_data->renderPassMap.end()) {
1203 errorStr << "invalid VkRenderPass (" << secondaryRP << ")";
1204 errorMsg = errorStr.str();
1205 return false;
1206 }
1207 // Trivial pass case is exact same RP
1208 if (primaryRP == secondaryRP)
1209 return true;
1210 const VkRenderPassCreateInfo* primaryRPCI = my_data->renderPassMap[primaryRP]->pCreateInfo;
1211 const VkRenderPassCreateInfo* secondaryRPCI = my_data->renderPassMap[secondaryRP]->pCreateInfo;
1212 if (primaryRPCI->subpassCount != secondaryRPCI->subpassCount) {
1213 errorStr << "RenderPass for primary cmdBuffer has " << primaryRPCI->subpassCount << " subpasses but renderPass for secondary cmdBuffer has " << secondaryRPCI->subpassCount << " subpasses.";
1214 errorMsg = errorStr.str();
1215 return false;
1216 }
1217 uint32_t spIndex = 0;
1218 for (spIndex = 0; spIndex < primaryRPCI->subpassCount; ++spIndex) {
1219 // For each subpass, verify that corresponding color, input, resolve & depth/stencil attachment references are compatible
1220 uint32_t primaryColorCount = primaryRPCI->pSubpasses[spIndex].colorAttachmentCount;
1221 uint32_t secondaryColorCount = secondaryRPCI->pSubpasses[spIndex].colorAttachmentCount;
1222 uint32_t colorMax = std::max(primaryColorCount, secondaryColorCount);
1223 for (uint32_t cIdx = 0; cIdx < colorMax; ++cIdx) {
1224 if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pColorAttachments, primaryColorCount, primaryRPCI->pAttachments,
1225 secondaryRPCI->pSubpasses[spIndex].pColorAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1226 errorStr << "color attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
1227 errorMsg = errorStr.str();
1228 return false;
1229 } else if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pResolveAttachments, primaryColorCount, primaryRPCI->pAttachments,
1230 secondaryRPCI->pSubpasses[spIndex].pResolveAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1231 errorStr << "resolve attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
1232 errorMsg = errorStr.str();
1233 return false;
1234 } else if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pDepthStencilAttachment, primaryColorCount, primaryRPCI->pAttachments,
1235 secondaryRPCI->pSubpasses[spIndex].pDepthStencilAttachment, secondaryColorCount, secondaryRPCI->pAttachments)) {
1236 errorStr << "depth/stencil attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
1237 errorMsg = errorStr.str();
1238 return false;
1239 }
1240 }
1241 uint32_t primaryInputCount = primaryRPCI->pSubpasses[spIndex].inputAttachmentCount;
1242 uint32_t secondaryInputCount = secondaryRPCI->pSubpasses[spIndex].inputAttachmentCount;
1243 uint32_t inputMax = std::max(primaryInputCount, secondaryInputCount);
1244 for (uint32_t i = 0; i < inputMax; ++i) {
1245 if (!attachment_references_compatible(i, primaryRPCI->pSubpasses[spIndex].pInputAttachments, primaryColorCount, primaryRPCI->pAttachments,
1246 secondaryRPCI->pSubpasses[spIndex].pInputAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1247 errorStr << "input attachments at index " << i << " of subpass index " << spIndex << " are not compatible.";
1248 errorMsg = errorStr.str();
1249 return false;
1250 }
1251 }
1252 }
1253 return true;
1254}
1255
Tobin Ehlis559c6382015-11-05 09:52:49 -07001256// For give SET_NODE, verify that its Set is compatible w/ the setLayout corresponding to pipelineLayout[layoutIndex]
1257static bool verify_set_layout_compatibility(layer_data* my_data, const SET_NODE* pSet, const VkPipelineLayout layout, const uint32_t layoutIndex, string& errorMsg)
1258{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001259 stringstream errorStr;
Tobin Ehlis559c6382015-11-05 09:52:49 -07001260 if (my_data->pipelineLayoutMap.find(layout) == my_data->pipelineLayoutMap.end()) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001261 errorStr << "invalid VkPipelineLayout (" << layout << ")";
1262 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001263 return false;
1264 }
1265 PIPELINE_LAYOUT_NODE pl = my_data->pipelineLayoutMap[layout];
1266 if (layoutIndex >= pl.descriptorSetLayouts.size()) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001267 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;
1268 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001269 return false;
1270 }
1271 // Get the specific setLayout from PipelineLayout that overlaps this set
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001272 LAYOUT_NODE* pLayoutNode = my_data->descriptorSetLayoutMap[pl.descriptorSetLayouts[layoutIndex]];
Tobin Ehlis559c6382015-11-05 09:52:49 -07001273 if (pLayoutNode->layout == pSet->pLayout->layout) { // trivial pass case
1274 return true;
1275 }
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07001276 size_t descriptorCount = pLayoutNode->descriptorTypes.size();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001277 if (descriptorCount != pSet->pLayout->descriptorTypes.size()) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001278 errorStr << "setLayout " << layoutIndex << " from pipelineLayout " << layout << " has " << descriptorCount << " descriptors, but corresponding set being bound has " << pSet->pLayout->descriptorTypes.size() << " descriptors.";
1279 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001280 return false; // trivial fail case
1281 }
1282 // Now need to check set against corresponding pipelineLayout to verify compatibility
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07001283 for (size_t i=0; i<descriptorCount; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07001284 // Need to verify that layouts are identically defined
1285 // TODO : Is below sufficient? Making sure that types & stageFlags match per descriptor
1286 // do we also need to check immutable samplers?
1287 if (pLayoutNode->descriptorTypes[i] != pSet->pLayout->descriptorTypes[i]) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001288 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]) << "'";
1289 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001290 return false;
1291 }
1292 if (pLayoutNode->stageFlags[i] != pSet->pLayout->stageFlags[i]) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001293 errorStr << "stageFlags " << i << " for descriptorSet being bound is " << pSet->pLayout->stageFlags[i] << "' but corresponding descriptor from pipelineLayout has stageFlags " << pLayoutNode->stageFlags[i];
1294 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001295 return false;
1296 }
1297 }
1298 return true;
1299}
1300
Tobin Ehlis88452832015-12-03 09:40:56 -07001301// Validate that the shaders used by the given pipeline
1302// As a side effect this function also records the sets that are actually used by the pipeline
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07001303static VkBool32
Tobin Ehlis88452832015-12-03 09:40:56 -07001304validate_pipeline_shaders(layer_data *my_data, VkDevice dev, PIPELINE_NODE* pPipeline)
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001305{
Tobin Ehlis88452832015-12-03 09:40:56 -07001306 VkGraphicsPipelineCreateInfo const *pCreateInfo = &pPipeline->graphicsPipelineCI;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001307 /* We seem to allow pipeline stages to be specified out of order, so collect and identify them
1308 * before trying to do anything more: */
1309 int vertex_stage = get_shader_stage_id(VK_SHADER_STAGE_VERTEX_BIT);
1310 int geometry_stage = get_shader_stage_id(VK_SHADER_STAGE_GEOMETRY_BIT);
1311 int fragment_stage = get_shader_stage_id(VK_SHADER_STAGE_FRAGMENT_BIT);
1312
1313 shader_module **shaders = new shader_module*[fragment_stage + 1]; /* exclude CS */
1314 memset(shaders, 0, sizeof(shader_module *) * (fragment_stage +1));
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001315 RENDER_PASS_NODE const *rp = 0;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001316 VkPipelineVertexInputStateCreateInfo const *vi = 0;
Mark Youngb20a6a82016-01-07 15:41:43 -07001317 VkBool32 pass = VK_TRUE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001318
1319 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
1320 VkPipelineShaderStageCreateInfo const *pStage = &pCreateInfo->pStages[i];
1321 if (pStage->sType == VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO) {
1322
1323 if ((pStage->stage & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_GEOMETRY_BIT | VK_SHADER_STAGE_FRAGMENT_BIT
1324 | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT)) == 0) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001325 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 -07001326 "Unknown shader stage %d", pStage->stage)) {
Mark Youngb20a6a82016-01-07 15:41:43 -07001327 pass = VK_FALSE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001328 }
1329 }
1330 else {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001331 shader_module *module = my_data->shaderModuleMap[pStage->module];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001332 shaders[get_shader_stage_id(pStage->stage)] = module;
1333
1334 /* validate descriptor set layout against what the spirv module actually uses */
1335 std::map<std::pair<unsigned, unsigned>, interface_var> descriptor_uses;
1336 collect_interface_by_descriptor_slot(my_data, dev, module, spv::StorageClassUniform,
1337 descriptor_uses);
1338
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001339 auto layouts = pCreateInfo->layout != VK_NULL_HANDLE ?
1340 &(my_data->pipelineLayoutMap[pCreateInfo->layout].descriptorSetLayouts) : nullptr;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001341
1342 for (auto it = descriptor_uses.begin(); it != descriptor_uses.end(); it++) {
Tobin Ehlis88452832015-12-03 09:40:56 -07001343 // As a side-effect of this function, capture which sets are used by the pipeline
1344 pPipeline->active_sets.insert(it->first.first);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001345
1346 /* find the matching binding */
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001347 auto found = has_descriptor_binding(my_data, layouts, it->first);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001348
1349 if (!found) {
1350 char type_name[1024];
1351 describe_type(type_name, module, it->second.type_id);
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001352 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 -07001353 SHADER_CHECKER_MISSING_DESCRIPTOR, "SC",
1354 "Shader uses descriptor slot %u.%u (used as type `%s`) but not declared in pipeline layout",
1355 it->first.first, it->first.second, type_name)) {
Mark Youngb20a6a82016-01-07 15:41:43 -07001356 pass = VK_FALSE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001357 }
1358 }
1359 }
1360 }
1361 }
1362 }
1363
1364 if (pCreateInfo->renderPass != VK_NULL_HANDLE)
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001365 rp = my_data->renderPassMap[pCreateInfo->renderPass];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001366
1367 vi = pCreateInfo->pVertexInputState;
1368
1369 if (vi) {
1370 pass = validate_vi_consistency(my_data, dev, vi) && pass;
1371 }
1372
1373 if (shaders[vertex_stage]) {
1374 pass = validate_vi_against_vs_inputs(my_data, dev, vi, shaders[vertex_stage]) && pass;
1375 }
1376
1377 /* TODO: enforce rules about present combinations of shaders */
1378 int producer = get_shader_stage_id(VK_SHADER_STAGE_VERTEX_BIT);
1379 int consumer = get_shader_stage_id(VK_SHADER_STAGE_GEOMETRY_BIT);
1380
1381 while (!shaders[producer] && producer != fragment_stage) {
1382 producer++;
1383 consumer++;
1384 }
1385
1386 for (; producer != fragment_stage && consumer <= fragment_stage; consumer++) {
1387 assert(shaders[producer]);
1388 if (shaders[consumer]) {
1389 pass = validate_interface_between_stages(my_data, dev,
1390 shaders[producer], shader_stage_attribs[producer].name,
1391 shaders[consumer], shader_stage_attribs[consumer].name,
1392 shader_stage_attribs[consumer].arrayed_input) && pass;
1393
1394 producer = consumer;
1395 }
1396 }
1397
1398 if (shaders[fragment_stage] && rp) {
1399 pass = validate_fs_outputs_against_render_pass(my_data, dev, shaders[fragment_stage], rp, pCreateInfo->subpass) && pass;
1400 }
1401
Chris Forbes47f4f6f2015-12-17 17:10:19 +13001402 delete [] shaders;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001403
1404 return pass;
1405}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001406
Tobin Ehlisf6585052015-12-17 11:48:42 -07001407// Return Set node ptr for specified set or else NULL
1408static SET_NODE* getSetNode(layer_data* my_data, const VkDescriptorSet set)
1409{
1410 loader_platform_thread_lock_mutex(&globalLock);
1411 if (my_data->setMap.find(set) == my_data->setMap.end()) {
1412 loader_platform_thread_unlock_mutex(&globalLock);
1413 return NULL;
1414 }
1415 loader_platform_thread_unlock_mutex(&globalLock);
1416 return my_data->setMap[set];
1417}
1418
1419// For the given set, verify that for each dynamic descriptor in that set that its
1420// dynamic offset combined with the offet and range from its descriptor update
1421// do not overflow the size of its buffer being updated
1422static VkBool32 validate_dynamic_offsets(layer_data* my_data, const SET_NODE* pSet)
1423{
1424 VkBool32 result = VK_FALSE;
1425 if (pSet->dynamicOffsets.empty())
1426 return result;
1427
1428 VkWriteDescriptorSet* pWDS = NULL;
1429 uint32_t dynOffsetIndex = 0;
1430 VkDeviceSize bufferSize = 0;
1431 for (uint32_t i=0; i < pSet->descriptorCount; ++i) {
1432 switch (pSet->ppDescriptors[i]->sType) {
1433 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1434 pWDS = (VkWriteDescriptorSet*)pSet->ppDescriptors[i];
1435 if ((pWDS->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
1436 (pWDS->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
1437 for (uint32_t j=0; j<pWDS->descriptorCount; ++j) {
Michael Lentine700b0aa2015-10-30 17:57:32 -07001438 bufferSize = my_data->bufferMap[pWDS->pBufferInfo[j].buffer].create_info->size;
Tobin Ehlisf6585052015-12-17 11:48:42 -07001439 if ((pSet->dynamicOffsets[dynOffsetIndex] + pWDS->pBufferInfo[j].offset + pWDS->pBufferInfo[j].range) > bufferSize) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001440 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 -07001441 "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 ".",
1442 (uint64_t)pSet->set, i, pSet->dynamicOffsets[dynOffsetIndex], pWDS->pBufferInfo[j].offset, pWDS->pBufferInfo[j].range, (uint64_t)pWDS->pBufferInfo[j].buffer, bufferSize);
1443 }
1444 dynOffsetIndex++;
1445 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)
1446 }
1447 }
1448 break;
1449 default: // Currently only shadowing Write update nodes so shouldn't get here
1450 assert(0);
1451 continue;
1452 }
1453 }
1454 return result;
1455}
1456
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001457// Validate overall state at the time of a draw call
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001458static VkBool32 validate_draw_state(layer_data* my_data, GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001459 // First check flag states
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001460 VkBool32 result = validate_draw_state_flags(my_data, pCB, indexedDraw);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001461 PIPELINE_NODE* pPipe = getPipeline(my_data, pCB->lastBoundPipeline);
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001462 // Now complete other state checks
Tobin Ehlise90e66d2015-09-09 13:31:01 -06001463 // TODO : Currently only performing next check if *something* was bound (non-zero last bound)
1464 // There is probably a better way to gate when this check happens, and to know if something *should* have been bound
1465 // We should have that check separately and then gate this check based on that check
Mark Lobodzinski74635932015-12-18 15:35:38 -07001466 if (pPipe) {
1467 if (pCB->lastBoundPipelineLayout) {
1468 string errorString;
1469 for (auto setIndex : pPipe->active_sets) {
1470 // If valid set is not bound throw an error
1471 if ((pCB->boundDescriptorSets.size() <= setIndex) || (!pCB->boundDescriptorSets[setIndex])) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001472 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 -07001473 "VkPipeline %#" PRIxLEAST64 " uses set #%u but that set is not bound.", (uint64_t)pPipe->pipeline, setIndex);
1474 } else if (!verify_set_layout_compatibility(my_data, my_data->setMap[pCB->boundDescriptorSets[setIndex]], pPipe->graphicsPipelineCI.layout, setIndex, errorString)) {
1475 // Set is bound but not compatible w/ overlapping pipelineLayout from PSO
1476 VkDescriptorSet setHandle = my_data->setMap[pCB->boundDescriptorSets[setIndex]]->set;
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001477 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 -07001478 "VkDescriptorSet (%#" PRIxLEAST64 ") bound as set #%u is not compatible with overlapping VkPipelineLayout %#" PRIxLEAST64 " due to: %s",
1479 (uint64_t)setHandle, setIndex, (uint64_t)pPipe->graphicsPipelineCI.layout, errorString.c_str());
Tobin Ehlis43c39c02016-01-11 13:18:40 -07001480 } else { // Valid set is bound and layout compatible, validate that it's updated and verify any dynamic offsets
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07001481 // Add this set as a valid set for this CB
1482 pCB->activeSets.insert(pCB->boundDescriptorSets[setIndex]);
Tobin Ehlis43c39c02016-01-11 13:18:40 -07001483 // Pull the set node
Tobin Ehlisf6585052015-12-17 11:48:42 -07001484 SET_NODE* pSet = getSetNode(my_data, pCB->boundDescriptorSets[setIndex]);
Tobin Ehlis43c39c02016-01-11 13:18:40 -07001485 // Make sure set has been updated
1486 if (!pSet->pUpdateStructs) {
1487 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pSet->set, __LINE__, DRAWSTATE_DESCRIPTOR_SET_NOT_UPDATED, "DS",
1488 "DS %#" PRIxLEAST64 " bound but it was never updated. It is now being used to draw so this will result in undefined behavior.", (uint64_t) pSet->set);
1489 }
1490 // For each dynamic descriptor, make sure dynamic offset doesn't overstep buffer
Tobin Ehlisf6585052015-12-17 11:48:42 -07001491 result |= validate_dynamic_offsets(my_data, pSet);
Mark Lobodzinski74635932015-12-18 15:35:38 -07001492 }
Tobin Ehlis88452832015-12-03 09:40:56 -07001493 }
1494 }
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07001495
Mark Lobodzinski74635932015-12-18 15:35:38 -07001496 // Verify Vtx binding
1497 if (pPipe->vtxBindingCount > 0) {
1498 VkPipelineVertexInputStateCreateInfo *vtxInCI = &pPipe->vertexInputCI;
1499 for (uint32_t i = 0; i < vtxInCI->vertexBindingDescriptionCount; i++) {
Michael Lentine700b0aa2015-10-30 17:57:32 -07001500 if ((pCB->currentDrawData.buffers.size() < (i+1)) || (pCB->currentDrawData.buffers[i] == VK_NULL_HANDLE)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001501 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 -07001502 "The Pipeline State Object (%#" PRIxLEAST64 ") expects that this Command Buffer's vertex binding Index %d should be set via vkCmdBindVertexBuffers.",
1503 (uint64_t)pCB->lastBoundPipeline, i);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001504
Mark Lobodzinski74635932015-12-18 15:35:38 -07001505 }
1506 }
1507 } else {
Michael Lentine700b0aa2015-10-30 17:57:32 -07001508 if (!pCB->currentDrawData.buffers.empty()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001509 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 -07001510 "DS", "Vertex buffers are bound to command buffer (%#" PRIxLEAST64 ") but no vertex buffers are attached to this Pipeline State Object (%#" PRIxLEAST64 ").",
1511 (uint64_t)pCB->commandBuffer, (uint64_t)pCB->lastBoundPipeline);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06001512 }
1513 }
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07001514
Mark Lobodzinski74635932015-12-18 15:35:38 -07001515 // If Viewport or scissors are dynamic, verify that dynamic count matches PSO count
1516 VkBool32 dynViewport = isDynamic(pPipe, VK_DYNAMIC_STATE_VIEWPORT);
1517 VkBool32 dynScissor = isDynamic(pPipe, VK_DYNAMIC_STATE_SCISSOR);
1518 if (dynViewport) {
1519 if (pCB->viewports.size() != pPipe->graphicsPipelineCI.pViewportState->viewportCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001520 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 -07001521 "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);
1522 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001523 }
Mark Lobodzinski74635932015-12-18 15:35:38 -07001524 if (dynScissor) {
1525 if (pCB->scissors.size() != pPipe->graphicsPipelineCI.pViewportState->scissorCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001526 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 -07001527 "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);
1528 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001529 }
1530 }
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001531 return result;
1532}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001533
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001534// Verify that create state for a pipeline is valid
Tobin Ehlis88452832015-12-03 09:40:56 -07001535static VkBool32 verifyPipelineCreateState(layer_data* my_data, const VkDevice device, PIPELINE_NODE* pPipeline)
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001536{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001537 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski2fd2d032015-12-16 14:25:22 -07001538
Tobin Ehlis88452832015-12-03 09:40:56 -07001539 if (!validate_pipeline_shaders(my_data, device, pPipeline)) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001540 skipCall = VK_TRUE;
1541 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001542 // VS is required
1543 if (!(pPipeline->active_shaders & VK_SHADER_STAGE_VERTEX_BIT)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001544 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 -06001545 "Invalid Pipeline CreateInfo State: Vtx Shader required");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001546 }
1547 // Either both or neither TC/TE shaders should be defined
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001548 if (((pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) == 0) !=
1549 ((pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) == 0) ) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001550 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 -06001551 "Invalid Pipeline CreateInfo State: TE and TC shaders must be included or excluded as a pair");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001552 }
1553 // Compute shaders should be specified independent of Gfx shaders
1554 if ((pPipeline->active_shaders & VK_SHADER_STAGE_COMPUTE_BIT) &&
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001555 (pPipeline->active_shaders & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT |
1556 VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT | VK_SHADER_STAGE_GEOMETRY_BIT |
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001557 VK_SHADER_STAGE_FRAGMENT_BIT))) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001558 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 -06001559 "Invalid Pipeline CreateInfo State: Do not specify Compute Shader for Gfx Pipeline");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001560 }
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001561 // VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology is only valid for tessellation pipelines.
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001562 // Mismatching primitive topology and tessellation fails graphics pipeline creation.
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001563 if (pPipeline->active_shaders & (VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) &&
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001564 (pPipeline->iaStateCI.topology != VK_PRIMITIVE_TOPOLOGY_PATCH_LIST)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001565 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 +08001566 "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 -06001567 }
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001568 if (pPipeline->iaStateCI.topology == VK_PRIMITIVE_TOPOLOGY_PATCH_LIST) {
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001569 if (~pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001570 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 +08001571 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology is only valid for tessellation pipelines");
Tobin Ehlis912df022015-09-17 08:46:18 -06001572 }
1573 if (!pPipeline->tessStateCI.patchControlPoints || (pPipeline->tessStateCI.patchControlPoints > 32)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001574 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 +08001575 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology used with patchControlPoints value %u."
Tobin Ehlis912df022015-09-17 08:46:18 -06001576 " patchControlPoints should be >0 and <=32.", pPipeline->tessStateCI.patchControlPoints);
1577 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001578 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001579 // Viewport state must be included and viewport and scissor counts should always match
Tobin Ehlise68360f2015-10-01 11:15:13 -06001580 // NOTE : Even if these are flagged as dynamic, counts need to be set correctly for shader compiler
Tobin Ehlisd332f282015-10-02 11:00:56 -06001581 if (!pPipeline->graphicsPipelineCI.pViewportState) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001582 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 -06001583 "Gfx Pipeline pViewportState is null. Even if viewport and scissors are dynamic PSO must include viewportCount and scissorCount in pViewportState.");
1584 } else if (pPipeline->graphicsPipelineCI.pViewportState->scissorCount != pPipeline->graphicsPipelineCI.pViewportState->viewportCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001585 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 -06001586 "Gfx Pipeline viewport count (%u) must match scissor count (%u).", pPipeline->vpStateCI.viewportCount, pPipeline->vpStateCI.scissorCount);
Tobin Ehlisd332f282015-10-02 11:00:56 -06001587 } else {
1588 // If viewport or scissor are not dynamic, then verify that data is appropriate for count
1589 VkBool32 dynViewport = isDynamic(pPipeline, VK_DYNAMIC_STATE_VIEWPORT);
1590 VkBool32 dynScissor = isDynamic(pPipeline, VK_DYNAMIC_STATE_SCISSOR);
1591 if (!dynViewport) {
1592 if (pPipeline->graphicsPipelineCI.pViewportState->viewportCount && !pPipeline->graphicsPipelineCI.pViewportState->pViewports) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001593 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 -07001594 "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 -06001595 }
1596 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001597 if (!dynScissor) {
1598 if (pPipeline->graphicsPipelineCI.pViewportState->scissorCount && !pPipeline->graphicsPipelineCI.pViewportState->pScissors) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001599 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 -07001600 "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 -06001601 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06001602 }
1603 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001604 return skipCall;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001605}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001606
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001607// Init the pipeline mapping info based on pipeline create info LL tree
1608// Threading note : Calls to this function should wrapped in mutex
Tobin Ehlis88452832015-12-03 09:40:56 -07001609// TODO : this should really just be in the constructor for PIPELINE_NODE
Mark Lobodzinski475a2182015-11-10 15:25:01 -07001610static PIPELINE_NODE* initGraphicsPipeline(layer_data* dev_data, const VkGraphicsPipelineCreateInfo* pCreateInfo, PIPELINE_NODE* pBasePipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001611{
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001612 PIPELINE_NODE* pPipeline = new PIPELINE_NODE;
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001613
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001614 if (pBasePipeline) {
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001615 *pPipeline = *pBasePipeline;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001616 }
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001617
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001618 // First init create info
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001619 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001620
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001621 size_t bufferSize = 0;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001622 const VkPipelineVertexInputStateCreateInfo* pVICI = NULL;
Tobin Ehlis5a65cca2015-07-13 13:14:24 -06001623 const VkPipelineColorBlendStateCreateInfo* pCBCI = NULL;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001624
1625 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
1626 const VkPipelineShaderStageCreateInfo *pPSSCI = &pCreateInfo->pStages[i];
1627
Chia-I Wu28e06912015-10-31 00:31:16 +08001628 switch (pPSSCI->stage) {
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001629 case VK_SHADER_STAGE_VERTEX_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001630 memcpy(&pPipeline->vsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1631 pPipeline->active_shaders |= VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001632 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001633 case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001634 memcpy(&pPipeline->tcsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001635 pPipeline->active_shaders |= VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001636 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001637 case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001638 memcpy(&pPipeline->tesCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001639 pPipeline->active_shaders |= VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001640 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001641 case VK_SHADER_STAGE_GEOMETRY_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001642 memcpy(&pPipeline->gsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1643 pPipeline->active_shaders |= VK_SHADER_STAGE_GEOMETRY_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001644 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001645 case VK_SHADER_STAGE_FRAGMENT_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001646 memcpy(&pPipeline->fsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1647 pPipeline->active_shaders |= VK_SHADER_STAGE_FRAGMENT_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001648 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001649 case VK_SHADER_STAGE_COMPUTE_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001650 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
1651 pPipeline->active_shaders |= VK_SHADER_STAGE_COMPUTE_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001652 break;
1653 default:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001654 // TODO : Flag error
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001655 break;
1656 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001657 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001658 // Copy over GraphicsPipelineCreateInfo structure embedded pointers
1659 if (pCreateInfo->stageCount != 0) {
1660 pPipeline->graphicsPipelineCI.pStages = new VkPipelineShaderStageCreateInfo[pCreateInfo->stageCount];
1661 bufferSize = pCreateInfo->stageCount * sizeof(VkPipelineShaderStageCreateInfo);
1662 memcpy((void*)pPipeline->graphicsPipelineCI.pStages, pCreateInfo->pStages, bufferSize);
1663 }
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001664 if (pCreateInfo->pVertexInputState != NULL) {
1665 memcpy((void*)&pPipeline->vertexInputCI, pCreateInfo->pVertexInputState , sizeof(VkPipelineVertexInputStateCreateInfo));
1666 // Copy embedded ptrs
1667 pVICI = pCreateInfo->pVertexInputState;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001668 pPipeline->vtxBindingCount = pVICI->vertexBindingDescriptionCount;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001669 if (pPipeline->vtxBindingCount) {
1670 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
1671 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
1672 memcpy((void*)pPipeline->pVertexBindingDescriptions, pVICI->pVertexBindingDescriptions, bufferSize);
1673 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08001674 pPipeline->vtxAttributeCount = pVICI->vertexAttributeDescriptionCount;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001675 if (pPipeline->vtxAttributeCount) {
1676 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
1677 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
1678 memcpy((void*)pPipeline->pVertexAttributeDescriptions, pVICI->pVertexAttributeDescriptions, bufferSize);
1679 }
1680 pPipeline->graphicsPipelineCI.pVertexInputState = &pPipeline->vertexInputCI;
1681 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001682 if (pCreateInfo->pInputAssemblyState != NULL) {
1683 memcpy((void*)&pPipeline->iaStateCI, pCreateInfo->pInputAssemblyState, sizeof(VkPipelineInputAssemblyStateCreateInfo));
1684 pPipeline->graphicsPipelineCI.pInputAssemblyState = &pPipeline->iaStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001685 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001686 if (pCreateInfo->pTessellationState != NULL) {
1687 memcpy((void*)&pPipeline->tessStateCI, pCreateInfo->pTessellationState, sizeof(VkPipelineTessellationStateCreateInfo));
1688 pPipeline->graphicsPipelineCI.pTessellationState = &pPipeline->tessStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001689 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001690 if (pCreateInfo->pViewportState != NULL) {
1691 memcpy((void*)&pPipeline->vpStateCI, pCreateInfo->pViewportState, sizeof(VkPipelineViewportStateCreateInfo));
1692 pPipeline->graphicsPipelineCI.pViewportState = &pPipeline->vpStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001693 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001694 if (pCreateInfo->pRasterizationState != NULL) {
1695 memcpy((void*)&pPipeline->rsStateCI, pCreateInfo->pRasterizationState, sizeof(VkPipelineRasterizationStateCreateInfo));
1696 pPipeline->graphicsPipelineCI.pRasterizationState = &pPipeline->rsStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001697 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001698 if (pCreateInfo->pMultisampleState != NULL) {
1699 memcpy((void*)&pPipeline->msStateCI, pCreateInfo->pMultisampleState, sizeof(VkPipelineMultisampleStateCreateInfo));
1700 pPipeline->graphicsPipelineCI.pMultisampleState = &pPipeline->msStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001701 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001702 if (pCreateInfo->pDepthStencilState != NULL) {
1703 memcpy((void*)&pPipeline->dsStateCI, pCreateInfo->pDepthStencilState, sizeof(VkPipelineDepthStencilStateCreateInfo));
1704 pPipeline->graphicsPipelineCI.pDepthStencilState = &pPipeline->dsStateCI;
1705 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001706 if (pCreateInfo->pColorBlendState != NULL) {
1707 memcpy((void*)&pPipeline->cbStateCI, pCreateInfo->pColorBlendState, sizeof(VkPipelineColorBlendStateCreateInfo));
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001708 // Copy embedded ptrs
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001709 pCBCI = pCreateInfo->pColorBlendState;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001710 pPipeline->attachmentCount = pCBCI->attachmentCount;
1711 if (pPipeline->attachmentCount) {
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001712 pPipeline->pAttachments = new VkPipelineColorBlendAttachmentState[pPipeline->attachmentCount];
1713 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineColorBlendAttachmentState);
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001714 memcpy((void*)pPipeline->pAttachments, pCBCI->pAttachments, bufferSize);
1715 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001716 pPipeline->graphicsPipelineCI.pColorBlendState = &pPipeline->cbStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001717 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001718 if (pCreateInfo->pDynamicState != NULL) {
1719 memcpy((void*)&pPipeline->dynStateCI, pCreateInfo->pDynamicState, sizeof(VkPipelineDynamicStateCreateInfo));
1720 if (pPipeline->dynStateCI.dynamicStateCount) {
1721 pPipeline->dynStateCI.pDynamicStates = new VkDynamicState[pPipeline->dynStateCI.dynamicStateCount];
1722 bufferSize = pPipeline->dynStateCI.dynamicStateCount * sizeof(VkDynamicState);
1723 memcpy((void*)pPipeline->dynStateCI.pDynamicStates, pCreateInfo->pDynamicState->pDynamicStates, bufferSize);
1724 }
1725 pPipeline->graphicsPipelineCI.pDynamicState = &pPipeline->dynStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001726 }
Tobin Ehlis88452832015-12-03 09:40:56 -07001727 pPipeline->active_sets.clear();
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001728 return pPipeline;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001729}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001730
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001731// Free the Pipeline nodes
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001732static void deletePipelines(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001733{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001734 if (my_data->pipelineMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06001735 return;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001736 for (auto ii=my_data->pipelineMap.begin(); ii!=my_data->pipelineMap.end(); ++ii) {
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001737 if ((*ii).second->graphicsPipelineCI.stageCount != 0) {
1738 delete[] (*ii).second->graphicsPipelineCI.pStages;
1739 }
Tobin Ehlisf313c8b2015-04-01 11:59:08 -06001740 if ((*ii).second->pVertexBindingDescriptions) {
1741 delete[] (*ii).second->pVertexBindingDescriptions;
1742 }
1743 if ((*ii).second->pVertexAttributeDescriptions) {
1744 delete[] (*ii).second->pVertexAttributeDescriptions;
1745 }
1746 if ((*ii).second->pAttachments) {
1747 delete[] (*ii).second->pAttachments;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001748 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001749 if ((*ii).second->dynStateCI.dynamicStateCount != 0) {
1750 delete[] (*ii).second->dynStateCI.pDynamicStates;
1751 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001752 delete (*ii).second;
1753 }
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001754 my_data->pipelineMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001755}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001756
Tobin Ehliseba312c2015-04-01 08:40:34 -06001757// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Chia-I Wu5c17c962015-10-31 00:31:16 +08001758static VkSampleCountFlagBits getNumSamples(layer_data* my_data, const VkPipeline pipeline)
Tobin Ehliseba312c2015-04-01 08:40:34 -06001759{
Chia-I Wue2fc5522015-10-26 20:04:44 +08001760 PIPELINE_NODE* pPipe = my_data->pipelineMap[pipeline];
Tobin Ehlis577188e2015-07-13 14:51:15 -06001761 if (VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001762 return pPipe->msStateCI.rasterizationSamples;
Tobin Ehlis577188e2015-07-13 14:51:15 -06001763 }
Chia-I Wu5c17c962015-10-31 00:31:16 +08001764 return VK_SAMPLE_COUNT_1_BIT;
Tobin Ehliseba312c2015-04-01 08:40:34 -06001765}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001766
Tobin Ehliseba312c2015-04-01 08:40:34 -06001767// Validate state related to the PSO
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001768static VkBool32 validatePipelineState(layer_data* my_data, const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehliseba312c2015-04-01 08:40:34 -06001769{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001770 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06001771 // Verify that any MSAA request in PSO matches sample# in bound FB
Chia-I Wu5c17c962015-10-31 00:31:16 +08001772 VkSampleCountFlagBits psoNumSamples = getNumSamples(my_data, pipeline);
Tobin Ehliseba312c2015-04-01 08:40:34 -06001773 if (pCB->activeRenderPass) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001774 const VkRenderPassCreateInfo* pRPCI = my_data->renderPassMap[pCB->activeRenderPass]->pCreateInfo;
Chia-I Wu08accc62015-07-07 11:50:03 +08001775 const VkSubpassDescription* pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
Chia-I Wu5c17c962015-10-31 00:31:16 +08001776 VkSampleCountFlagBits subpassNumSamples = (VkSampleCountFlagBits) 0;
Chia-I Wu08accc62015-07-07 11:50:03 +08001777 uint32_t i;
1778
Chia-I Wud50a7d72015-10-26 20:48:51 +08001779 for (i = 0; i < pSD->colorAttachmentCount; i++) {
Chia-I Wu5c17c962015-10-31 00:31:16 +08001780 VkSampleCountFlagBits samples;
Chia-I Wu08accc62015-07-07 11:50:03 +08001781
Cody Northropa505dda2015-08-04 11:16:41 -06001782 if (pSD->pColorAttachments[i].attachment == VK_ATTACHMENT_UNUSED)
Chia-I Wu08accc62015-07-07 11:50:03 +08001783 continue;
1784
Cody Northropa505dda2015-08-04 11:16:41 -06001785 samples = pRPCI->pAttachments[pSD->pColorAttachments[i].attachment].samples;
Chia-I Wu5c17c962015-10-31 00:31:16 +08001786 if (subpassNumSamples == (VkSampleCountFlagBits) 0) {
Chia-I Wu08accc62015-07-07 11:50:03 +08001787 subpassNumSamples = samples;
1788 } else if (subpassNumSamples != samples) {
Chia-I Wu5c17c962015-10-31 00:31:16 +08001789 subpassNumSamples = (VkSampleCountFlagBits) -1;
Chia-I Wu08accc62015-07-07 11:50:03 +08001790 break;
1791 }
1792 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08001793 if (pSD->pDepthStencilAttachment && pSD->pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
Chia-I Wu5c17c962015-10-31 00:31:16 +08001794 const VkSampleCountFlagBits samples = pRPCI->pAttachments[pSD->pDepthStencilAttachment->attachment].samples;
1795 if (subpassNumSamples == (VkSampleCountFlagBits) 0)
Chia-I Wu08accc62015-07-07 11:50:03 +08001796 subpassNumSamples = samples;
1797 else if (subpassNumSamples != samples)
Chia-I Wu5c17c962015-10-31 00:31:16 +08001798 subpassNumSamples = (VkSampleCountFlagBits) -1;
Chia-I Wu08accc62015-07-07 11:50:03 +08001799 }
1800
1801 if (psoNumSamples != subpassNumSamples) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001802 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 -06001803 "Num samples mismatch! Binding PSO (%#" PRIxLEAST64 ") with %u samples while current RenderPass (%#" PRIxLEAST64 ") w/ %u samples!",
Chia-I Wue2fc5522015-10-26 20:04:44 +08001804 (uint64_t) pipeline, psoNumSamples, (uint64_t) pCB->activeRenderPass, subpassNumSamples);
Tobin Ehliseba312c2015-04-01 08:40:34 -06001805 }
1806 } else {
1807 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
1808 // Verify and flag error as appropriate
1809 }
1810 // TODO : Add more checks here
1811 } else {
1812 // TODO : Validate non-gfx pipeline updates
1813 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001814 return VK_FALSE;
Tobin Ehliseba312c2015-04-01 08:40:34 -06001815}
1816
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001817// Block of code at start here specifically for managing/tracking DSs
1818
Tobin Ehlis793ad302015-04-03 12:01:11 -06001819// Return Pool node ptr for specified pool or else NULL
Mark Lobodzinski39298632015-11-18 08:38:27 -07001820static DESCRIPTOR_POOL_NODE* getPoolNode(layer_data* my_data, const VkDescriptorPool pool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001821{
1822 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07001823 if (my_data->descriptorPoolMap.find(pool) == my_data->descriptorPoolMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001824 loader_platform_thread_unlock_mutex(&globalLock);
1825 return NULL;
1826 }
1827 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07001828 return my_data->descriptorPoolMap[pool];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001829}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001830
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001831static LAYOUT_NODE* getLayoutNode(layer_data* my_data, const VkDescriptorSetLayout layout) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001832 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001833 if (my_data->descriptorSetLayoutMap.find(layout) == my_data->descriptorSetLayoutMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001834 loader_platform_thread_unlock_mutex(&globalLock);
1835 return NULL;
1836 }
1837 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001838 return my_data->descriptorSetLayoutMap[layout];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001839}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001840
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001841// 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 -06001842static VkBool32 validUpdateStruct(layer_data* my_data, const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001843{
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001844 switch (pUpdateStruct->sType)
1845 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001846 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1847 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001848 return VK_FALSE;
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001849 default:
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001850 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 -06001851 "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 -06001852 }
1853}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001854
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001855// Set count for given update struct in the last parameter
Courtney Goeltzenleuchter085f8dd2015-12-16 16:08:44 -07001856// 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 -06001857static uint32_t getUpdateCount(layer_data* my_data, const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis793ad302015-04-03 12:01:11 -06001858{
1859 switch (pUpdateStruct->sType)
1860 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001861 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
Chia-I Wud50a7d72015-10-26 20:48:51 +08001862 return ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorCount;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001863 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis793ad302015-04-03 12:01:11 -06001864 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wud50a7d72015-10-26 20:48:51 +08001865 return ((VkCopyDescriptorSet*)pUpdateStruct)->descriptorCount;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001866 }
Courtney Goeltzenleuchter7f47bca2015-12-16 16:08:08 -07001867
1868 return 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001869}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001870
Tobin Ehlis793ad302015-04-03 12:01:11 -06001871// For given Layout Node and binding, return index where that binding begins
1872static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
1873{
1874 uint32_t offsetIndex = 0;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001875 for (uint32_t i = 0; i < pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001876 if (pLayout->createInfo.pBindings[i].binding == binding)
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001877 break;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001878 offsetIndex += pLayout->createInfo.pBindings[i].descriptorCount;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001879 }
1880 return offsetIndex;
1881}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001882
Tobin Ehlis793ad302015-04-03 12:01:11 -06001883// For given layout node and binding, return last index that is updated
1884static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
1885{
1886 uint32_t offsetIndex = 0;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001887 for (uint32_t i = 0; i < pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001888 offsetIndex += pLayout->createInfo.pBindings[i].descriptorCount;
1889 if (pLayout->createInfo.pBindings[i].binding == binding)
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001890 break;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001891 }
1892 return offsetIndex-1;
1893}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001894
Tobin Ehlisbaca3ab2015-10-27 12:54:50 -06001895// For given layout and update, return the first overall index of the layout that is updated
Tobin Ehlis8a62e632015-10-27 15:43:38 -06001896static 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 -06001897{
Tobin Ehlisbaca3ab2015-10-27 12:54:50 -06001898 return getBindingStartIndex(pLayout, binding)+arrayIndex;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001899}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001900
Tobin Ehlis8a62e632015-10-27 15:43:38 -06001901// For given layout and update, return the last overall index of the layout that is updated
1902static 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 -06001903{
Tobin Ehlis8a62e632015-10-27 15:43:38 -06001904 uint32_t count = getUpdateCount(my_data, device, pUpdateStruct);
Tobin Ehlisbaca3ab2015-10-27 12:54:50 -06001905 return getBindingStartIndex(pLayout, binding)+arrayIndex+count-1;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001906}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001907
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001908// Verify that the descriptor type in the update struct matches what's expected by the layout
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001909static 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 -06001910{
1911 // First get actual type of update
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001912 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001913 VkDescriptorType actualType;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001914 uint32_t i = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001915 switch (pUpdateStruct->sType)
1916 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001917 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1918 actualType = ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorType;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001919 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001920 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
1921 /* no need to validate */
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001922 return VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001923 break;
1924 default:
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001925 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 -06001926 "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 -06001927 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001928 if (VK_FALSE == skipCall) {
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001929 // Set first stageFlags as reference and verify that all other updates match it
1930 VkShaderStageFlags refStageFlags = pLayout->stageFlags[startIndex];
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001931 for (i = startIndex; i <= endIndex; i++) {
Tobin Ehlis644ff042015-10-20 10:11:55 -06001932 if (pLayout->descriptorTypes[i] != actualType) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001933 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 -06001934 "Write descriptor update has descriptor type %s that does not match overlapping binding descriptor type of %s!",
1935 string_VkDescriptorType(actualType), string_VkDescriptorType(pLayout->descriptorTypes[i]));
1936 }
1937 if (pLayout->stageFlags[i] != refStageFlags) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001938 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 -06001939 "Write descriptor update has stageFlags %x that do not match overlapping binding descriptor stageFlags of %x!",
1940 refStageFlags, pLayout->stageFlags[i]);
Tobin Ehlis483cc352015-09-30 08:30:20 -06001941 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001942 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001943 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001944 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001945}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001946
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001947// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001948// struct into the pNewNode param. Return VK_TRUE if error condition encountered and callback signals early exit.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001949// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001950static VkBool32 shadowUpdateNode(layer_data* my_data, const VkDevice device, GENERIC_HEADER* pUpdate, GENERIC_HEADER** pNewNode)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001951{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001952 VkBool32 skipCall = VK_FALSE;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001953 VkWriteDescriptorSet* pWDS = NULL;
1954 VkCopyDescriptorSet* pCDS = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001955 size_t array_size = 0;
1956 size_t base_array_size = 0;
1957 size_t total_array_size = 0;
1958 size_t baseBuffAddr = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001959 switch (pUpdate->sType)
1960 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001961 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1962 pWDS = new VkWriteDescriptorSet;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001963 *pNewNode = (GENERIC_HEADER*)pWDS;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001964 memcpy(pWDS, pUpdate, sizeof(VkWriteDescriptorSet));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001965
1966 switch (pWDS->descriptorType) {
1967 case VK_DESCRIPTOR_TYPE_SAMPLER:
1968 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
1969 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
1970 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
1971 {
Chia-I Wud50a7d72015-10-26 20:48:51 +08001972 VkDescriptorImageInfo *info = new VkDescriptorImageInfo[pWDS->descriptorCount];
1973 memcpy(info, pWDS->pImageInfo, pWDS->descriptorCount * sizeof(VkDescriptorImageInfo));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001974 pWDS->pImageInfo = info;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001975 }
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001976 break;
1977 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
1978 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
1979 {
Chia-I Wud50a7d72015-10-26 20:48:51 +08001980 VkBufferView *info = new VkBufferView[pWDS->descriptorCount];
1981 memcpy(info, pWDS->pTexelBufferView, pWDS->descriptorCount * sizeof(VkBufferView));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001982 pWDS->pTexelBufferView = info;
1983 }
1984 break;
1985 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
1986 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
1987 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
1988 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
1989 {
Chia-I Wud50a7d72015-10-26 20:48:51 +08001990 VkDescriptorBufferInfo *info = new VkDescriptorBufferInfo[pWDS->descriptorCount];
1991 memcpy(info, pWDS->pBufferInfo, pWDS->descriptorCount * sizeof(VkDescriptorBufferInfo));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001992 pWDS->pBufferInfo = info;
1993 }
1994 break;
1995 default:
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07001996 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001997 break;
1998 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001999 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002000 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
2001 pCDS = new VkCopyDescriptorSet;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002002 *pNewNode = (GENERIC_HEADER*)pCDS;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002003 memcpy(pCDS, pUpdate, sizeof(VkCopyDescriptorSet));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002004 break;
2005 default:
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002006 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 -06002007 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdate->sType), pUpdate->sType))
2008 return VK_TRUE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002009 }
2010 // Make sure that pNext for the end of shadow copy is NULL
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002011 (*pNewNode)->pNext = NULL;
2012 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002013}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002014
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002015// Verify that given sampler is valid
2016static VkBool32 validateSampler(const layer_data* my_data, const VkSampler* pSampler, const VkBool32 immutable)
2017{
2018 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002019 auto sampIt = my_data->sampleMap.find(*pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002020 if (sampIt == my_data->sampleMap.end()) {
2021 if (!immutable) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002022 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 +08002023 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid sampler %#" PRIxLEAST64, (uint64_t) *pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002024 } else { // immutable
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002025 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 +08002026 "vkUpdateDescriptorSets: Attempt to update descriptor whose binding has an invalid immutable sampler %#" PRIxLEAST64, (uint64_t) *pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002027 }
2028 } else {
2029 // TODO : Any further checks we want to do on the sampler?
2030 }
2031 return skipCall;
2032}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002033
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002034// Verify that given imageView is valid
2035static VkBool32 validateImageView(const layer_data* my_data, const VkImageView* pImageView, const VkImageLayout imageLayout)
2036{
2037 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002038 auto ivIt = my_data->imageViewMap.find(*pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002039 if (ivIt == my_data->imageViewMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002040 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 +08002041 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid imageView %#" PRIxLEAST64, (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002042 } else {
2043 // Validate that imageLayout is compatible with aspectMask and image format
2044 VkImageAspectFlags aspectMask = ivIt->second->subresourceRange.aspectMask;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002045 VkImage image = ivIt->second->image;
Michael Lentine7b236262015-10-23 12:41:44 -07002046 // TODO : Check here in case we have a bad image
Chia-I Wue2fc5522015-10-26 20:04:44 +08002047 auto imgIt = my_data->imageMap.find(image);
Tobin Ehlis47026a22016-01-19 08:36:40 -07002048 auto swapChainImageIt = my_data->imageLayoutMap.find(image);
2049 if ((imgIt == my_data->imageMap.end()) && (swapChainImageIt == my_data->imageLayoutMap.end())) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002050 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 -07002051 "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 -06002052 } else {
2053 VkFormat format = (*imgIt).second->format;
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07002054 VkBool32 ds = vk_format_is_depth_or_stencil(format);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002055 switch (imageLayout) {
2056 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
2057 // Only Color bit must be set
2058 if ((aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) != VK_IMAGE_ASPECT_COLOR_BIT) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002059 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 -06002060 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 +08002061 " that does not have VK_IMAGE_ASPECT_COLOR_BIT set.", (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002062 }
2063 // format must NOT be DS
2064 if (ds) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002065 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 -06002066 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 +08002067 " 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 -06002068 }
2069 break;
2070 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
2071 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
2072 // Depth or stencil bit must be set, but both must NOT be set
2073 if (aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) {
2074 if (aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) {
2075 // both must NOT be set
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002076 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 -06002077 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with imageView %#" PRIxLEAST64 ""
Chia-I Wue2fc5522015-10-26 20:04:44 +08002078 " that has both STENCIL and DEPTH aspects set", (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002079 }
2080 } else if (!(aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)) {
2081 // Neither were set
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002082 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 -06002083 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout %s and imageView %#" PRIxLEAST64 ""
Chia-I Wue2fc5522015-10-26 20:04:44 +08002084 " that does not have STENCIL or DEPTH aspect set.", string_VkImageLayout(imageLayout), (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002085 }
2086 // format must be DS
2087 if (!ds) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002088 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 -06002089 DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout %s and imageView %#" PRIxLEAST64 ""
Chia-I Wue2fc5522015-10-26 20:04:44 +08002090 " 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 -06002091 }
2092 break;
2093 default:
2094 // anything to check for other layouts?
2095 break;
2096 }
2097 }
2098 }
2099 return skipCall;
2100}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002101
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002102// Verify that given bufferView is valid
2103static VkBool32 validateBufferView(const layer_data* my_data, const VkBufferView* pBufferView)
2104{
2105 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002106 auto sampIt = my_data->bufferViewMap.find(*pBufferView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002107 if (sampIt == my_data->bufferViewMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002108 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 +08002109 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid bufferView %#" PRIxLEAST64, (uint64_t) *pBufferView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002110 } else {
2111 // TODO : Any further checks we want to do on the bufferView?
2112 }
2113 return skipCall;
2114}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002115
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002116// Verify that given bufferInfo is valid
2117static VkBool32 validateBufferInfo(const layer_data* my_data, const VkDescriptorBufferInfo* pBufferInfo)
2118{
2119 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002120 auto sampIt = my_data->bufferMap.find(pBufferInfo->buffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002121 if (sampIt == my_data->bufferMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002122 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 +08002123 "vkUpdateDescriptorSets: Attempt to update descriptor where bufferInfo has invalid buffer %#" PRIxLEAST64, (uint64_t) pBufferInfo->buffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002124 } else {
2125 // TODO : Any further checks we want to do on the bufferView?
2126 }
2127 return skipCall;
2128}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002129
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002130static VkBool32 validateUpdateContents(const layer_data* my_data, const VkWriteDescriptorSet *pWDS, const VkDescriptorSetLayoutBinding* pLayoutBinding)
2131{
2132 VkBool32 skipCall = VK_FALSE;
2133 // First verify that for the given Descriptor type, the correct DescriptorInfo data is supplied
2134 VkBufferView* pBufferView = NULL;
2135 const VkSampler* pSampler = NULL;
2136 VkImageView* pImageView = NULL;
2137 VkImageLayout* pImageLayout = NULL;
2138 VkDescriptorBufferInfo* pBufferInfo = NULL;
2139 VkBool32 immutable = VK_FALSE;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002140 uint32_t i = 0;
2141 // For given update type, verify that update contents are correct
2142 switch (pWDS->descriptorType) {
2143 case VK_DESCRIPTOR_TYPE_SAMPLER:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002144 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002145 skipCall |= validateSampler(my_data, &(pWDS->pImageInfo[i].sampler), immutable);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002146 }
2147 break;
2148 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002149 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002150 if (NULL == pLayoutBinding->pImmutableSamplers) {
2151 pSampler = &(pWDS->pImageInfo[i].sampler);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002152 if (immutable) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002153 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT, (uint64_t) *pSampler, __LINE__, DRAWSTATE_INCONSISTENT_IMMUTABLE_SAMPLER_UPDATE, "DS",
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002154 "vkUpdateDescriptorSets: Update #%u is not an immutable sampler %#" PRIxLEAST64 ", but previous update(s) from this "
2155 "VkWriteDescriptorSet struct used an immutable sampler. All updates from a single struct must either "
Chia-I Wue2fc5522015-10-26 20:04:44 +08002156 "use immutable or non-immutable samplers.", i, (uint64_t) *pSampler);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002157 }
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002158 } else {
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002159 if (i>0 && !immutable) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002160 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 -06002161 "vkUpdateDescriptorSets: Update #%u is an immutable sampler, but previous update(s) from this "
2162 "VkWriteDescriptorSet struct used a non-immutable sampler. All updates from a single struct must either "
2163 "use immutable or non-immutable samplers.", i);
2164 }
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002165 immutable = VK_TRUE;
2166 pSampler = &(pLayoutBinding->pImmutableSamplers[i]);
2167 }
2168 skipCall |= validateSampler(my_data, pSampler, immutable);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002169 }
2170 // Intentionally fall through here to also validate image stuff
2171 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2172 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
2173 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002174 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002175 skipCall |= validateImageView(my_data, &(pWDS->pImageInfo[i].imageView), pWDS->pImageInfo[i].imageLayout);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002176 }
2177 break;
2178 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2179 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002180 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002181 skipCall |= validateBufferView(my_data, &(pWDS->pTexelBufferView[i]));
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002182 }
2183 break;
2184 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2185 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2186 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2187 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002188 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002189 skipCall |= validateBufferInfo(my_data, &(pWDS->pBufferInfo[i]));
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002190 }
2191 break;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002192 }
2193 return skipCall;
2194}
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002195// Validate that given set is valid and that it's not being used by an in-flight CmdBuffer
2196// func_str is the name of the calling function
2197// Return VK_FALSE if no errors occur
2198// Return VK_TRUE if validation error occurs and callback returns VK_TRUE (to skip upcoming API call down the chain)
2199VkBool32 validateIdleDescriptorSet(const layer_data* my_data, VkDescriptorSet set, std::string func_str) {
2200 VkBool32 skip_call = VK_FALSE;
2201 auto set_node = my_data->setMap.find(set);
2202 if (set_node == my_data->setMap.end()) {
2203 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, reinterpret_cast<uint64_t>(set), __LINE__, DRAWSTATE_DOUBLE_DESTROY, "DS",
2204 "Cannot call %s() on descriptor set %" PRIxLEAST64 " that has not been allocated.", func_str.c_str(), reinterpret_cast<uint64_t>(set));
2205 } else {
2206 if (set_node->second->in_use.load()) {
2207 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, reinterpret_cast<uint64_t>(set), __LINE__, DRAWSTATE_OBJECT_INUSE, "DS",
2208 "Cannot call %s() on descriptor set %" PRIxLEAST64 " that is in use by a command buffer.", func_str.c_str(), reinterpret_cast<uint64_t>(set));
2209 }
2210 }
2211 return skip_call;
2212}
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002213// update DS mappings based on write and copy update arrays
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08002214static 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 -06002215{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002216 VkBool32 skipCall = VK_FALSE;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002217
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002218 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002219 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002220 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002221 // Validate Write updates
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002222 uint32_t i = 0;
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08002223 for (i=0; i < descriptorWriteCount; i++) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002224 VkDescriptorSet ds = pWDS[i].dstSet;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002225 SET_NODE* pSet = my_data->setMap[ds];
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002226 // Set being updated cannot be in-flight
2227 if ((skipCall = validateIdleDescriptorSet(my_data, ds, "VkUpdateDescriptorSets")) == VK_TRUE)
2228 return skipCall;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002229 GENERIC_HEADER* pUpdate = (GENERIC_HEADER*) &pWDS[i];
Tobin Ehlis793ad302015-04-03 12:01:11 -06002230 pLayout = pSet->pLayout;
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002231 // First verify valid update struct
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06002232 if ((skipCall = validUpdateStruct(my_data, device, pUpdate)) == VK_TRUE) {
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002233 break;
2234 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002235 uint32_t binding = 0, endIndex = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002236 binding = pWDS[i].dstBinding;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002237 // Make sure that layout being updated has the binding being updated
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002238 if (pLayout->bindings.find(binding) == pLayout->bindings.end()) {
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002239 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, reinterpret_cast<uint64_t>(ds), __LINE__, DRAWSTATE_INVALID_UPDATE_INDEX, "DS",
Michael Lentine010f4692015-11-03 16:19:46 -08002240 "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 -06002241 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06002242 // Next verify that update falls within size of given binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002243 endIndex = getUpdateEndIndex(my_data, device, pLayout, binding, pWDS[i].dstArrayElement, pUpdate);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002244 if (getBindingEndIndex(pLayout, binding) < endIndex) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06002245 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002246 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002247 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 -06002248 "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 -06002249 } else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002250 uint32_t startIndex;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002251 startIndex = getUpdateStartIndex(my_data, device, pLayout, binding, pWDS[i].dstArrayElement, pUpdate);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002252 // Layout bindings match w/ update, now verify that update type & stageFlags are the same for entire update
2253 if ((skipCall = validateUpdateConsistency(my_data, device, pLayout, pUpdate, startIndex, endIndex)) == VK_FALSE) {
2254 // The update is within bounds and consistent, but need to make sure contents make sense as well
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002255 if ((skipCall = validateUpdateContents(my_data, &pWDS[i], &pLayout->createInfo.pBindings[binding])) == VK_FALSE) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002256 // Update is good. Save the update info
2257 // Create new update struct for this set's shadow copy
2258 GENERIC_HEADER* pNewNode = NULL;
2259 skipCall |= shadowUpdateNode(my_data, device, pUpdate, &pNewNode);
2260 if (NULL == pNewNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002261 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 -06002262 "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
2263 } else {
2264 // Insert shadow node into LL of updates for this set
2265 pNewNode->pNext = pSet->pUpdateStructs;
2266 pSet->pUpdateStructs = pNewNode;
2267 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002268 for (uint32_t j = startIndex; j <= endIndex; j++) {
2269 assert(j<pSet->descriptorCount);
2270 pSet->ppDescriptors[j] = pNewNode;
2271 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002272 }
2273 }
2274 }
2275 }
2276 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002277 }
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002278 // Now validate copy updates
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08002279 for (i=0; i < descriptorCopyCount; ++i) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002280 SET_NODE *pSrcSet = NULL, *pDstSet = NULL;
2281 LAYOUT_NODE *pSrcLayout = NULL, *pDstLayout = NULL;
2282 uint32_t srcStartIndex = 0, srcEndIndex = 0, dstStartIndex = 0, dstEndIndex = 0;
2283 // For each copy make sure that update falls within given layout and that types match
Chia-I Wue2fc5522015-10-26 20:04:44 +08002284 pSrcSet = my_data->setMap[pCDS[i].srcSet];
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002285 pDstSet = my_data->setMap[pCDS[i].dstSet];
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002286 // Set being updated cannot be in-flight
2287 if ((skipCall = validateIdleDescriptorSet(my_data, pDstSet->set, "VkUpdateDescriptorSets")) == VK_TRUE)
2288 return skipCall;
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002289 pSrcLayout = pSrcSet->pLayout;
2290 pDstLayout = pDstSet->pLayout;
2291 // Validate that src binding is valid for src set layout
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002292 if (pSrcLayout->bindings.find(pCDS[i].srcBinding) == pSrcLayout->bindings.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002293 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 -06002294 "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 +08002295 i, pCDS[i].srcBinding, (uint64_t) pSrcLayout->layout, pSrcLayout->createInfo.bindingCount-1);
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002296 } else if (pDstLayout->bindings.find(pCDS[i].dstBinding) == pDstLayout->bindings.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002297 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 +08002298 "Copy descriptor update %u has dstBinding %u which is out of bounds for underlying SetLayout %#" PRIxLEAST64 " which only has bindings 0-%u.",
2299 i, pCDS[i].dstBinding, (uint64_t) pDstLayout->layout, pDstLayout->createInfo.bindingCount-1);
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002300 } else {
2301 // Proceed with validation. Bindings are ok, but make sure update is within bounds of given layout
2302 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 +08002303 dstEndIndex = getUpdateEndIndex(my_data, device, pDstLayout, pCDS[i].dstBinding, pCDS[i].dstArrayElement, (const GENERIC_HEADER*)&(pCDS[i]));
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002304 if (getBindingEndIndex(pSrcLayout, pCDS[i].srcBinding) < srcEndIndex) {
2305 pLayoutCI = &pSrcLayout->createInfo;
2306 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002307 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 -06002308 "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 +08002309 } else if (getBindingEndIndex(pDstLayout, pCDS[i].dstBinding) < dstEndIndex) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002310 pLayoutCI = &pDstLayout->createInfo;
2311 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002312 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 +08002313 "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 -06002314 } else {
2315 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 +08002316 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 +08002317 for (uint32_t j=0; j<pCDS[i].descriptorCount; ++j) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002318 // For copy just make sure that the types match and then perform the update
2319 if (pSrcLayout->descriptorTypes[srcStartIndex+j] != pDstLayout->descriptorTypes[dstStartIndex+j]) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002320 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 -06002321 "Copy descriptor update index %u, update count #%u, has src update descriptor type %s that does not match overlapping dest descriptor type of %s!",
2322 i, j+1, string_VkDescriptorType(pSrcLayout->descriptorTypes[srcStartIndex+j]), string_VkDescriptorType(pDstLayout->descriptorTypes[dstStartIndex+j]));
2323 } else {
2324 // point dst descriptor at corresponding src descriptor
Tobin Ehlisf6585052015-12-17 11:48:42 -07002325 // TODO : This may be a hole. I believe copy should be its own copy,
2326 // otherwise a subsequent write update to src will incorrectly affect the copy
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002327 pDstSet->ppDescriptors[j+dstStartIndex] = pSrcSet->ppDescriptors[j+srcStartIndex];
2328 }
2329 }
2330 }
2331 }
2332 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002333 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002334 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002335}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002336
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002337// Verify that given pool has descriptors that are being requested for allocation
Mark Lobodzinski39298632015-11-18 08:38:27 -07002338static 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 -06002339{
2340 VkBool32 skipCall = VK_FALSE;
2341 uint32_t i = 0, j = 0;
2342 for (i=0; i<count; ++i) {
2343 LAYOUT_NODE* pLayout = getLayoutNode(dev_data, pSetLayouts[i]);
2344 if (NULL == pLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002345 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 +08002346 "Unable to find set layout node for layout %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pSetLayouts[i]);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002347 } else {
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002348 uint32_t typeIndex = 0, poolSizeCount = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002349 for (j=0; j<pLayout->createInfo.bindingCount; ++j) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002350 typeIndex = static_cast<uint32_t>(pLayout->createInfo.pBindings[j].descriptorType);
2351 poolSizeCount = pLayout->createInfo.pBindings[j].descriptorCount;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002352 if (poolSizeCount > pPoolNode->availableDescriptorTypeCount[typeIndex]) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002353 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 -06002354 "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 -07002355 poolSizeCount, string_VkDescriptorType(pLayout->createInfo.pBindings[j].descriptorType), (uint64_t) pPoolNode->pool, pPoolNode->availableDescriptorTypeCount[typeIndex]);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002356 } else { // Decrement available descriptors of this type
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002357 pPoolNode->availableDescriptorTypeCount[typeIndex] -= poolSizeCount;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002358 }
2359 }
2360 }
2361 }
2362 return skipCall;
2363}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002364
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002365// Free the shadowed update node for this Set
2366// NOTE : Calls to this function should be wrapped in mutex
2367static void freeShadowUpdateTree(SET_NODE* pSet)
2368{
2369 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
2370 pSet->pUpdateStructs = NULL;
2371 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
2372 // Clear the descriptor mappings as they will now be invalid
2373 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
2374 while(pShadowUpdate) {
2375 pFreeUpdate = pShadowUpdate;
2376 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
2377 uint32_t index = 0;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002378 VkWriteDescriptorSet * pWDS = NULL;
2379 VkCopyDescriptorSet * pCDS = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002380 void** ppToFree = NULL;
2381 switch (pFreeUpdate->sType)
2382 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002383 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
2384 pWDS = (VkWriteDescriptorSet*)pFreeUpdate;
Tony Barbourb1947942015-11-02 11:46:29 -07002385 switch (pWDS->descriptorType) {
2386 case VK_DESCRIPTOR_TYPE_SAMPLER:
2387 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
2388 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2389 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
2390 {
2391 delete[] pWDS->pImageInfo;
2392 }
2393 break;
2394 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2395 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
2396 {
2397 delete[] pWDS->pTexelBufferView;
2398 }
2399 break;
2400 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2401 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2402 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2403 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
2404 {
2405 delete[] pWDS->pBufferInfo;
2406 }
2407 break;
2408 default:
2409 break;
Courtney Goeltzenleuchteraa132e72015-10-22 15:31:56 -06002410 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002411 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002412 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002413 break;
2414 default:
2415 assert(0);
2416 break;
2417 }
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002418 delete pFreeUpdate;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002419 }
2420}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002421
Tobin Ehlis793ad302015-04-03 12:01:11 -06002422// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002423// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002424static void deletePools(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002425{
Mark Lobodzinski39298632015-11-18 08:38:27 -07002426 if (my_data->descriptorPoolMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06002427 return;
Mark Lobodzinski39298632015-11-18 08:38:27 -07002428 for (auto ii=my_data->descriptorPoolMap.begin(); ii!=my_data->descriptorPoolMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002429 SET_NODE* pSet = (*ii).second->pSets;
2430 SET_NODE* pFreeSet = pSet;
2431 while (pSet) {
2432 pFreeSet = pSet;
2433 pSet = pSet->pNext;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002434 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002435 // Free Update shadow struct tree
2436 freeShadowUpdateTree(pFreeSet);
2437 if (pFreeSet->ppDescriptors) {
Chris Forbes02038792015-06-04 10:49:27 +12002438 delete[] pFreeSet->ppDescriptors;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002439 }
2440 delete pFreeSet;
2441 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002442 delete (*ii).second;
2443 }
Mark Lobodzinski39298632015-11-18 08:38:27 -07002444 my_data->descriptorPoolMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002445}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002446
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002447// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002448// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002449static void deleteLayouts(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002450{
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07002451 if (my_data->descriptorSetLayoutMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06002452 return;
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07002453 for (auto ii=my_data->descriptorSetLayoutMap.begin(); ii!=my_data->descriptorSetLayoutMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002454 LAYOUT_NODE* pLayout = (*ii).second;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002455 if (pLayout->createInfo.pBindings) {
Chia-I Wud50a7d72015-10-26 20:48:51 +08002456 for (uint32_t i=0; i<pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002457 if (pLayout->createInfo.pBindings[i].pImmutableSamplers)
2458 delete[] pLayout->createInfo.pBindings[i].pImmutableSamplers;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002459 }
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002460 delete[] pLayout->createInfo.pBindings;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002461 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002462 delete pLayout;
2463 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07002464 my_data->descriptorSetLayoutMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002465}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002466
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002467// Currently clearing a set is removing all previous updates to that set
2468// TODO : Validate if this is correct clearing behavior
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002469static void clearDescriptorSet(layer_data* my_data, VkDescriptorSet set)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002470{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002471 SET_NODE* pSet = getSetNode(my_data, set);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002472 if (!pSet) {
2473 // TODO : Return error
Tobin Ehlisce132d82015-06-19 15:07:05 -06002474 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002475 loader_platform_thread_lock_mutex(&globalLock);
2476 freeShadowUpdateTree(pSet);
2477 loader_platform_thread_unlock_mutex(&globalLock);
2478 }
2479}
2480
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002481static void clearDescriptorPool(layer_data* my_data, const VkDevice device, const VkDescriptorPool pool, VkDescriptorPoolResetFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002482{
Mark Lobodzinski39298632015-11-18 08:38:27 -07002483 DESCRIPTOR_POOL_NODE* pPool = getPoolNode(my_data, pool);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002484 if (!pPool) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002485 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 +08002486 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkResetDescriptorPool() call", (uint64_t) pool);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002487 } else {
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002488 // TODO: validate flags
Tobin Ehlis793ad302015-04-03 12:01:11 -06002489 // For every set off of this pool, clear it
2490 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002491 while (pSet) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002492 clearDescriptorSet(my_data, pSet->set);
Mark Lobodzinskidcce0792016-01-04 09:40:19 -07002493 pSet = pSet->pNext;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002494 }
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002495 // Reset available count to max count for this pool
2496 for (uint32_t i=0; i<pPool->availableDescriptorTypeCount.size(); ++i) {
2497 pPool->availableDescriptorTypeCount[i] = pPool->maxDescriptorTypeCount[i];
2498 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002499 }
2500}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002501
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002502// For given CB object, fetch associated CB Node from map
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002503static GLOBAL_CB_NODE* getCBNode(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002504{
2505 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002506 if (my_data->commandBufferMap.count(cb) == 0) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002507 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002508 // TODO : How to pass cb as srcObj here?
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002509 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 +08002510 "Attempt to use CommandBuffer %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<uint64_t>(cb));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002511 return NULL;
2512 }
2513 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002514 return my_data->commandBufferMap[cb];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002515}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002516
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002517// Free all CB Nodes
2518// NOTE : Calls to this function should be wrapped in mutex
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002519static void deleteCommandBuffers(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002520{
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002521 if (my_data->commandBufferMap.size() <= 0) {
David Pinedod8f83d82015-04-27 16:36:17 -06002522 return;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002523 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002524 for (auto ii=my_data->commandBufferMap.begin(); ii!=my_data->commandBufferMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002525 delete (*ii).second;
2526 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002527 my_data->commandBufferMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002528}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002529
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002530static 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 -06002531{
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002532 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 -07002533 (uint64_t)cb, __LINE__, DRAWSTATE_NO_BEGIN_COMMAND_BUFFER, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002534 "You must call vkBeginCommandBuffer() before this call to %s", caller_name);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002535}
Michael Lentine3dea6512015-10-28 15:55:18 -07002536
Mark Youngb20a6a82016-01-07 15:41:43 -07002537VkBool32 validateCmdsInCmdBuffer(const layer_data* dev_data, const GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd_type) {
2538 if (!pCB->activeRenderPass) return VK_FALSE;
2539 VkBool32 skip_call = VK_FALSE;
Michael Lentine2e068b22015-12-29 16:05:27 -06002540 if (pCB->activeSubpassContents == VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS && cmd_type != CMD_EXECUTECOMMANDS) {
2541 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
2542 DRAWSTATE_INVALID_COMMAND_BUFFER, "DS", "Commands cannot be called in a subpass using secondary command buffers.");
2543 } else if (pCB->activeSubpassContents == VK_SUBPASS_CONTENTS_INLINE && cmd_type == CMD_EXECUTECOMMANDS) {
2544 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
2545 DRAWSTATE_INVALID_COMMAND_BUFFER, "DS", "vkCmdExecuteCommands() cannot be called in a subpass using inline commands.");
2546 }
Michael Lentine3dea6512015-10-28 15:55:18 -07002547 return skip_call;
2548}
2549
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002550// Add specified CMD to the CmdBuffer in given pCB, flagging errors if CB is not
2551// in the recording state or if there's an issue with the Cmd ordering
2552static 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 -06002553{
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002554 VkBool32 skipCall = VK_FALSE;
2555 if (pCB->state != CB_RECORDING) {
2556 skipCall |= report_error_no_cb_begin(my_data, pCB->commandBuffer, caller_name);
2557 skipCall |= validateCmdsInCmdBuffer(my_data, pCB, cmd);
Tobin Ehlis9a874302016-01-20 10:25:29 -07002558 CMD_NODE cmdNode = {};
2559 // init cmd node and append to end of cmd LL
2560 cmdNode.cmdNumber = ++pCB->numCmds;
2561 cmdNode.type = cmd;
2562 pCB->cmds.push_back(cmdNode);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002563 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002564 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002565}
Tobin Ehlisef694652016-01-19 12:03:34 -07002566// Reset the command buffer state
2567// Maintain the createInfo and set state to CB_NEW, but clear all other state
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002568static void resetCB(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002569{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002570 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002571 if (pCB) {
Tobin Ehlis9a874302016-01-20 10:25:29 -07002572 pCB->cmds.clear();
Tobin Ehlisef694652016-01-19 12:03:34 -07002573 // Reset CB state (note that createInfo is not cleared)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002574 pCB->commandBuffer = cb;
Michael Lentineabc5e922015-10-12 11:30:14 -05002575 memset(&pCB->beginInfo, 0, sizeof(VkCommandBufferBeginInfo));
Tobin Ehliscd5bfd82016-01-19 13:12:52 -07002576 memset(&pCB->inheritanceInfo, 0, sizeof(VkCommandBufferInheritanceInfo));
Michael Lentineabc5e922015-10-12 11:30:14 -05002577 pCB->fence = 0;
2578 pCB->numCmds = 0;
2579 memset(pCB->drawCount, 0, NUM_DRAW_TYPES * sizeof(uint64_t));
2580 pCB->state = CB_NEW;
2581 pCB->submitCount = 0;
2582 pCB->status = 0;
Michael Lentineabc5e922015-10-12 11:30:14 -05002583 pCB->lastBoundPipeline = 0;
2584 pCB->viewports.clear();
2585 pCB->scissors.clear();
2586 pCB->lineWidth = 0;
2587 pCB->depthBiasConstantFactor = 0;
2588 pCB->depthBiasClamp = 0;
2589 pCB->depthBiasSlopeFactor = 0;
2590 memset(pCB->blendConstants, 0, 4 * sizeof(float));
2591 pCB->minDepthBounds = 0;
2592 pCB->maxDepthBounds = 0;
2593 memset(&pCB->front, 0, sizeof(stencil_data));
2594 memset(&pCB->back, 0, sizeof(stencil_data));
2595 pCB->lastBoundDescriptorSet = 0;
2596 pCB->lastBoundPipelineLayout = 0;
2597 pCB->activeRenderPass = 0;
2598 pCB->activeSubpass = 0;
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002599 pCB->activeSets.clear();
Michael Lentineabc5e922015-10-12 11:30:14 -05002600 pCB->framebuffer = 0;
Michael Lentineabc5e922015-10-12 11:30:14 -05002601 pCB->boundDescriptorSets.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07002602 pCB->drawData.clear();
2603 pCB->currentDrawData.buffers.clear();
Michael Lentineabc5e922015-10-12 11:30:14 -05002604 pCB->imageLayoutMap.clear();
Michael Lentineb887b0a2015-12-29 14:12:11 -06002605 pCB->waitedEvents.clear();
2606 pCB->waitedEventsBeforeQueryReset.clear();
2607 pCB->queryToStateMap.clear();
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07002608 pCB->secondaryCommandBuffers.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002609 }
2610}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002611
Tobin Ehlis963a4042015-09-29 08:18:34 -06002612// Set PSO-related status bits for CB, including dynamic state set via PSO
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002613static void set_cb_pso_status(GLOBAL_CB_NODE* pCB, const PIPELINE_NODE* pPipe)
2614{
2615 for (uint32_t i = 0; i < pPipe->cbStateCI.attachmentCount; i++) {
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002616 if (0 != pPipe->pAttachments[i].colorWriteMask) {
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002617 pCB->status |= CBSTATUS_COLOR_BLEND_WRITE_ENABLE;
2618 }
2619 }
2620 if (pPipe->dsStateCI.depthWriteEnable) {
Cody Northrop82485a82015-08-18 15:21:16 -06002621 pCB->status |= CBSTATUS_DEPTH_WRITE_ENABLE;
2622 }
Cody Northrop82485a82015-08-18 15:21:16 -06002623 if (pPipe->dsStateCI.stencilTestEnable) {
2624 pCB->status |= CBSTATUS_STENCIL_TEST_ENABLE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002625 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06002626 // Account for any dynamic state not set via this PSO
2627 if (!pPipe->dynStateCI.dynamicStateCount) { // All state is static
2628 pCB->status = CBSTATUS_ALL;
2629 } else {
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002630 // First consider all state on
2631 // Then unset any state that's noted as dynamic in PSO
2632 // Finally OR that into CB statemask
2633 CBStatusFlags psoDynStateMask = CBSTATUS_ALL;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002634 for (uint32_t i=0; i < pPipe->dynStateCI.dynamicStateCount; i++) {
2635 switch (pPipe->dynStateCI.pDynamicStates[i]) {
2636 case VK_DYNAMIC_STATE_VIEWPORT:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002637 psoDynStateMask &= ~CBSTATUS_VIEWPORT_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002638 break;
2639 case VK_DYNAMIC_STATE_SCISSOR:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002640 psoDynStateMask &= ~CBSTATUS_SCISSOR_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002641 break;
2642 case VK_DYNAMIC_STATE_LINE_WIDTH:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002643 psoDynStateMask &= ~CBSTATUS_LINE_WIDTH_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002644 break;
2645 case VK_DYNAMIC_STATE_DEPTH_BIAS:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002646 psoDynStateMask &= ~CBSTATUS_DEPTH_BIAS_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002647 break;
2648 case VK_DYNAMIC_STATE_BLEND_CONSTANTS:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002649 psoDynStateMask &= ~CBSTATUS_BLEND_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002650 break;
2651 case VK_DYNAMIC_STATE_DEPTH_BOUNDS:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002652 psoDynStateMask &= ~CBSTATUS_DEPTH_BOUNDS_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002653 break;
2654 case VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002655 psoDynStateMask &= ~CBSTATUS_STENCIL_READ_MASK_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002656 break;
2657 case VK_DYNAMIC_STATE_STENCIL_WRITE_MASK:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002658 psoDynStateMask &= ~CBSTATUS_STENCIL_WRITE_MASK_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002659 break;
2660 case VK_DYNAMIC_STATE_STENCIL_REFERENCE:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002661 psoDynStateMask &= ~CBSTATUS_STENCIL_REFERENCE_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002662 break;
2663 default:
2664 // TODO : Flag error here
2665 break;
2666 }
2667 }
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002668 pCB->status |= psoDynStateMask;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002669 }
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002670}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002671
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002672// Print the last bound Gfx Pipeline
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002673static VkBool32 printPipeline(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002674{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002675 VkBool32 skipCall = VK_FALSE;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002676 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002677 if (pCB) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002678 PIPELINE_NODE *pPipeTrav = getPipeline(my_data, pCB->lastBoundPipeline);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002679 if (!pPipeTrav) {
2680 // nothing to print
Tobin Ehlisce132d82015-06-19 15:07:05 -06002681 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002682 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 -08002683 "%s", vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002684 }
2685 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002686 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002687}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002688
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002689// Print details of DS config to stdout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002690static VkBool32 printDSConfig(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002691{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002692 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002693 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 -06002694 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis93f89e82015-06-09 08:39:32 -06002695 if (pCB && pCB->lastBoundDescriptorSet) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002696 SET_NODE* pSet = getSetNode(my_data, pCB->lastBoundDescriptorSet);
Mark Lobodzinski39298632015-11-18 08:38:27 -07002697 DESCRIPTOR_POOL_NODE* pPool = getPoolNode(my_data, pSet->pool);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002698 // Print out pool details
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002699 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 +08002700 "Details for pool %#" PRIxLEAST64 ".", (uint64_t) pPool->pool);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002701 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002702 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 -06002703 "%s", poolStr.c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002704 // Print out set details
2705 char prefix[10];
2706 uint32_t index = 0;
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002707 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 +08002708 "Details for descriptor set %#" PRIxLEAST64 ".", (uint64_t) pSet->set);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002709 LAYOUT_NODE* pLayout = pSet->pLayout;
2710 // Print layout details
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002711 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 -08002712 "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 -06002713 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002714 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002715 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 -06002716 "%s", DSLstr.c_str());
Tobin Ehlis793ad302015-04-03 12:01:11 -06002717 index++;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002718 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
2719 if (pUpdate) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002720 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 +08002721 "Update Chain [UC] for descriptor set %#" PRIxLEAST64 ":", (uint64_t) pSet->set);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002722 sprintf(prefix, " [UC] ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002723 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 -08002724 "%s", dynamic_display(pUpdate, prefix).c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002725 // TODO : If there is a "view" associated with this update, print CI for that view
Tobin Ehlisce132d82015-06-19 15:07:05 -06002726 } else {
Tobin Ehlisbf081f32015-06-15 08:41:17 -06002727 if (0 != pSet->descriptorCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002728 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 +08002729 "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 -06002730 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002731 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 +08002732 "FYI: No descriptors in descriptor set %#" PRIxLEAST64 ".", (uint64_t) pSet->set);
Tobin Ehlisbf081f32015-06-15 08:41:17 -06002733 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002734 }
2735 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002736 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002737}
2738
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002739static void printCB(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002740{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002741 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis9a874302016-01-20 10:25:29 -07002742 if (pCB && pCB->cmds.size() > 0) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002743 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 -06002744 "Cmds in CB %p", (void*)cb);
Tobin Ehlis9a874302016-01-20 10:25:29 -07002745 vector<CMD_NODE> cmds = pCB->cmds;
2746 for (auto ii=cmds.begin(); ii!=cmds.end(); ++ii) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002747 // TODO : Need to pass cb as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002748 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",
Tobin Ehlis9a874302016-01-20 10:25:29 -07002749 " CMD#%" PRIu64 ": %s", (*ii).cmdNumber, cmdTypeToString((*ii).type).c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002750 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002751 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002752 // Nothing to print
2753 }
2754}
2755
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002756static VkBool32 synchAndPrintDSConfig(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002757{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002758 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002759 if (!(my_data->report_data->active_flags & VK_DEBUG_REPORT_INFO_BIT_EXT)) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002760 return skipCall;
Mike Stroyanba35e352015-08-12 17:11:28 -06002761 }
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002762 skipCall |= printDSConfig(my_data, cb);
2763 skipCall |= printPipeline(my_data, cb);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002764 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002765}
2766
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002767// Flags validation error if the associated call is made inside a render pass. The apiName
2768// routine should ONLY be called outside a render pass.
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06002769static VkBool32 insideRenderPass(const layer_data* my_data, GLOBAL_CB_NODE *pCB, const char *apiName)
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002770{
2771 VkBool32 inside = VK_FALSE;
2772 if (pCB->activeRenderPass) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002773 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 -07002774 (uint64_t)pCB->commandBuffer, __LINE__, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002775 "%s: It is invalid to issue this call inside an active render pass (%#" PRIxLEAST64 ")",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002776 apiName, (uint64_t) pCB->activeRenderPass);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002777 }
2778 return inside;
2779}
2780
2781// Flags validation error if the associated call is made outside a render pass. The apiName
2782// routine should ONLY be called inside a render pass.
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06002783static VkBool32 outsideRenderPass(const layer_data* my_data, GLOBAL_CB_NODE *pCB, const char *apiName)
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002784{
2785 VkBool32 outside = VK_FALSE;
Mark Lobodzinski74635932015-12-18 15:35:38 -07002786 if (((pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) &&
2787 (!pCB->activeRenderPass)) ||
2788 ((pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) &&
2789 (!pCB->activeRenderPass) &&
2790 !(pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT))) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002791 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 -07002792 (uint64_t)pCB->commandBuffer, __LINE__, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002793 "%s: This call must be issued inside an active render pass.", apiName);
2794 }
2795 return outside;
2796}
2797
Courtney Goeltzenleuchter6d8e8182015-11-25 14:31:49 -07002798static void init_draw_state(layer_data *my_data, const VkAllocationCallbacks *pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002799{
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002800 uint32_t report_flags = 0;
2801 uint32_t debug_action = 0;
2802 FILE *log_output = NULL;
2803 const char *option_str;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002804 VkDebugReportCallbackEXT callback;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002805 // initialize DrawState options
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002806 report_flags = getLayerOptionFlags("DrawStateReportFlags", 0);
2807 getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &debug_action);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002808
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002809 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002810 {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002811 option_str = getLayerOption("DrawStateLogFilename");
Tobin Ehlisb1df55e2015-09-15 09:55:54 -06002812 log_output = getLayerLogOutput(option_str, "DrawState");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002813 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002814 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002815 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002816 dbgInfo.pfnCallback = log_callback;
2817 dbgInfo.pUserData = log_output;
2818 dbgInfo.flags = report_flags;
2819 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002820 my_data->logging_callback.push_back(callback);
2821 }
2822
2823 if (debug_action & VK_DBG_LAYER_ACTION_DEBUG_OUTPUT) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002824 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002825 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002826 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002827 dbgInfo.pfnCallback = win32_debug_output_msg;
2828 dbgInfo.pUserData = log_output;
2829 dbgInfo.flags = report_flags;
2830 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002831 my_data->logging_callback.push_back(callback);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002832 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002833
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002834 if (!globalLockInitialized)
2835 {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002836 loader_platform_thread_create_mutex(&globalLock);
2837 globalLockInitialized = 1;
2838 }
2839}
2840
Chia-I Wu9ab61502015-11-06 06:42:02 +08002841VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance)
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002842{
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07002843 VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002844
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07002845 assert(chain_info->u.pLayerInfo);
2846 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
2847 PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance) fpGetInstanceProcAddr(NULL, "vkCreateInstance");
2848 if (fpCreateInstance == NULL) {
2849 return VK_ERROR_INITIALIZATION_FAILED;
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002850 }
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07002851
2852 // Advance the link info for the next element on the chain
2853 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
2854
2855 VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
2856 if (result != VK_SUCCESS)
2857 return result;
2858
2859 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
2860 my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
2861 layer_init_instance_dispatch_table(*pInstance, my_data->instance_dispatch_table, fpGetInstanceProcAddr);
2862
2863 my_data->report_data = debug_report_create_instance(
2864 my_data->instance_dispatch_table,
2865 *pInstance,
2866 pCreateInfo->enabledExtensionCount,
2867 pCreateInfo->ppEnabledExtensionNames);
2868
2869 init_draw_state(my_data, pAllocator);
2870
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002871 return result;
2872}
2873
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002874/* hook DestroyInstance to remove tableInstanceMap entry */
Chia-I Wu9ab61502015-11-06 06:42:02 +08002875VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator)
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002876{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002877 // TODOSC : Shouldn't need any customization here
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002878 dispatch_key key = get_dispatch_key(instance);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002879 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
2880 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002881 pTable->DestroyInstance(instance, pAllocator);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002882
2883 // Clean up logging callback, if any
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002884 while (my_data->logging_callback.size() > 0) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002885 VkDebugReportCallbackEXT callback = my_data->logging_callback.back();
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002886 layer_destroy_msg_callback(my_data->report_data, callback, pAllocator);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002887 my_data->logging_callback.pop_back();
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002888 }
2889
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06002890 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002891 delete my_data->instance_dispatch_table;
2892 layer_data_map.erase(key);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002893 // TODO : Potential race here with separate threads creating/destroying instance
Tobin Ehlis0b632332015-10-07 09:38:40 -06002894 if (layer_data_map.empty()) {
Mike Stroyanfcb4ba62015-08-18 15:56:18 -06002895 // Release mutex when destroying last instance.
2896 loader_platform_thread_delete_mutex(&globalLock);
2897 globalLockInitialized = 0;
2898 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002899}
2900
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002901static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
2902{
Tony Barbour3b4732f2015-07-13 13:37:24 -06002903 uint32_t i;
Tobin Ehlis0b632332015-10-07 09:38:40 -06002904 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
2905 dev_data->device_extensions.debug_marker_enabled = false;
Michael Lentineabc5e922015-10-12 11:30:14 -05002906 dev_data->device_extensions.wsi_enabled = false;
2907
2908
2909 VkLayerDispatchTable *pDisp = dev_data->device_dispatch_table;
2910 PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr;
2911
Michael Lentineabc5e922015-10-12 11:30:14 -05002912 pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR) gpa(device, "vkCreateSwapchainKHR");
2913 pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR) gpa(device, "vkDestroySwapchainKHR");
2914 pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR) gpa(device, "vkGetSwapchainImagesKHR");
2915 pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR) gpa(device, "vkAcquireNextImageKHR");
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07002916 pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR) gpa(device, "vkQueuePresentKHR");
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002917
Jon Ashburnf19916e2016-01-11 13:12:43 -07002918 for (i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
Ian Elliott05846062015-11-20 14:13:17 -07002919 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) {
Michael Lentineabc5e922015-10-12 11:30:14 -05002920 dev_data->device_extensions.wsi_enabled = true;
2921 }
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002922 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
Jon Ashburneab34492015-06-01 09:37:38 -06002923 /* Found a matching extension name, mark it enabled and init dispatch table*/
Tobin Ehlis0b632332015-10-07 09:38:40 -06002924 dev_data->device_extensions.debug_marker_enabled = true;
Jon Ashburn1d4b1282015-12-10 19:12:21 -07002925 initDebugMarkerTable(device);
2926
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002927 }
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002928 }
2929}
2930
Chia-I Wu9ab61502015-11-06 06:42:02 +08002931VK_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 -06002932{
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07002933 VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
Mark Lobodzinski941aea92016-01-13 10:23:15 -07002934
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07002935 assert(chain_info->u.pLayerInfo);
2936 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
2937 PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr;
2938 PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice) fpGetInstanceProcAddr(NULL, "vkCreateDevice");
2939 if (fpCreateDevice == NULL) {
2940 return VK_ERROR_INITIALIZATION_FAILED;
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002941 }
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07002942
2943 // Advance the link info for the next element on the chain
2944 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
2945
2946 VkResult result = fpCreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
2947 if (result != VK_SUCCESS) {
2948 return result;
2949 }
2950
2951 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
2952 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
2953
2954 // Setup device dispatch table
2955 my_device_data->device_dispatch_table = new VkLayerDispatchTable;
2956 layer_init_device_dispatch_table(*pDevice, my_device_data->device_dispatch_table, fpGetDeviceProcAddr);
2957
2958 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
2959 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
2960 // Get physical device limits for this device
2961 my_instance_data->instance_dispatch_table->GetPhysicalDeviceProperties(gpu, &(my_instance_data->physDevPropertyMap[*pDevice]));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002962 return result;
2963}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002964
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002965// prototype
2966static void deleteRenderPasses(layer_data*);
Chia-I Wu9ab61502015-11-06 06:42:02 +08002967VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002968{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002969 // TODOSC : Shouldn't need any customization here
Jeremy Hayes5d29ce32015-06-19 11:37:38 -06002970 dispatch_key key = get_dispatch_key(device);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002971 layer_data* dev_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002972 // Free all the memory
2973 loader_platform_thread_lock_mutex(&globalLock);
2974 deletePipelines(dev_data);
2975 deleteRenderPasses(dev_data);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002976 deleteCommandBuffers(dev_data);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002977 deletePools(dev_data);
2978 deleteLayouts(dev_data);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002979 dev_data->imageViewMap.clear();
2980 dev_data->imageMap.clear();
2981 dev_data->bufferViewMap.clear();
2982 dev_data->bufferMap.clear();
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002983 loader_platform_thread_unlock_mutex(&globalLock);
2984
Chia-I Wuf7458c52015-10-26 21:10:41 +08002985 dev_data->device_dispatch_table->DestroyDevice(device, pAllocator);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002986 tableDebugMarkerMap.erase(key);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002987 delete dev_data->device_dispatch_table;
2988 layer_data_map.erase(key);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002989}
2990
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07002991static const VkExtensionProperties instance_extensions[] = {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002992 {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002993 VK_EXT_DEBUG_REPORT_EXTENSION_NAME,
Courtney Goeltzenleuchterb69cd592016-01-19 16:08:39 -07002994 VK_EXT_DEBUG_REPORT_SPEC_VERSION
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002995 }
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06002996};
2997
Chia-I Wu9ab61502015-11-06 06:42:02 +08002998VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002999 const char *pLayerName,
3000 uint32_t *pCount,
3001 VkExtensionProperties* pProperties)
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06003002{
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07003003 return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003004}
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06003005
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07003006static const VkLayerProperties ds_global_layers[] = {
3007 {
Michael Lentine03107b42015-12-11 10:49:51 -08003008 "VK_LAYER_LUNARG_draw_state",
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07003009 VK_API_VERSION,
3010 VK_MAKE_VERSION(0, 1, 0),
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -07003011 "Validation layer: draw_state",
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07003012 }
3013};
3014
Chia-I Wu9ab61502015-11-06 06:42:02 +08003015VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003016 uint32_t *pCount,
3017 VkLayerProperties* pProperties)
3018{
3019 return util_GetLayerProperties(ARRAY_SIZE(ds_global_layers),
3020 ds_global_layers,
3021 pCount, pProperties);
3022}
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06003023
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003024static const VkExtensionProperties ds_device_extensions[] = {
3025 {
3026 DEBUG_MARKER_EXTENSION_NAME,
3027 VK_MAKE_VERSION(0, 1, 0),
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003028 }
3029};
3030
3031static const VkLayerProperties ds_device_layers[] = {
3032 {
Michael Lentine1f8d4412016-01-19 14:19:38 -06003033 "VK_LAYER_LUNARG_draw_state",
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003034 VK_API_VERSION,
3035 VK_MAKE_VERSION(0, 1, 0),
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -07003036 "Validation layer: draw_state",
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003037 }
3038};
3039
Chia-I Wu9ab61502015-11-06 06:42:02 +08003040VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003041 VkPhysicalDevice physicalDevice,
3042 const char* pLayerName,
3043 uint32_t* pCount,
3044 VkExtensionProperties* pProperties)
3045{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003046 // DrawState does not have any physical device extensions
Jon Ashburn751c4842015-11-02 17:37:20 -07003047 if (pLayerName == NULL) {
3048 dispatch_key key = get_dispatch_key(physicalDevice);
3049 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003050 return my_data->instance_dispatch_table->EnumerateDeviceExtensionProperties(
Jon Ashburn751c4842015-11-02 17:37:20 -07003051 physicalDevice,
3052 NULL,
3053 pCount,
3054 pProperties);
3055 } else {
3056 return util_GetExtensionProperties(ARRAY_SIZE(ds_device_extensions),
3057 ds_device_extensions,
3058 pCount, pProperties);
3059 }
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003060}
3061
Chia-I Wu9ab61502015-11-06 06:42:02 +08003062VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003063 VkPhysicalDevice physicalDevice,
3064 uint32_t* pCount,
3065 VkLayerProperties* pProperties)
3066{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003067 /* DrawState physical device layers are the same as global */
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003068 return util_GetLayerProperties(ARRAY_SIZE(ds_device_layers), ds_device_layers,
3069 pCount, pProperties);
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06003070}
3071
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07003072VkBool32 ValidateCmdBufImageLayouts(VkCommandBuffer cmdBuffer) {
Mark Youngb20a6a82016-01-07 15:41:43 -07003073 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05003074 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
3075 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
3076 for (auto cb_image_data : pCB->imageLayoutMap) {
3077 auto image_data = dev_data->imageLayoutMap.find(cb_image_data.first);
3078 if (image_data == dev_data->imageLayoutMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003079 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 -08003080 "Cannot submit cmd buffer using deleted image %" PRIu64 ".", reinterpret_cast<uint64_t>(cb_image_data.first));
Michael Lentineabc5e922015-10-12 11:30:14 -05003081 } else {
3082 if (dev_data->imageLayoutMap[cb_image_data.first]->layout != cb_image_data.second.initialLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003083 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 -05003084 "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);
3085 }
3086 dev_data->imageLayoutMap[cb_image_data.first]->layout = cb_image_data.second.layout;
3087 }
3088 }
3089 return skip_call;
3090}
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07003091// Descriptor sets are unique vs. other resources in that they may be consumed at bind time:
3092// From spec section on vkCmdBindDescriptorSets - The descriptor set contents bound by a call
3093// to vkCmdBindDescriptorSets may be consumed during host execution of the command, or during
3094// shader execution of the resulting draws, or any time in between.
3095VkBool32 validateAndIncrementDescriptorSets(layer_data* my_data, GLOBAL_CB_NODE* pCB) {
3096 VkBool32 skip_call = VK_FALSE;
3097 // Verify that any active sets for this CB are valid and mark them in use
3098 for (auto set : pCB->activeSets) {
3099 auto setNode = my_data->setMap.find(set);
3100 if (setNode == my_data->setMap.end()) {
3101 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, reinterpret_cast<uint64_t>(set), __LINE__, DRAWSTATE_INVALID_DESCRIPTOR_SET, "DS",
3102 "Cannot submit cmd buffer using deleted descriptor set %" PRIu64 ".", reinterpret_cast<uint64_t>(set));
3103 } else {
3104 setNode->second->in_use.fetch_add(1);
3105 }
3106 }
3107 return skip_call;
3108}
Michael Lentineabc5e922015-10-12 11:30:14 -05003109
Mark Young7a69c302016-01-07 09:48:47 -07003110VkBool32 validateAndIncrementResources(layer_data* my_data, GLOBAL_CB_NODE* pCB) {
Mark Youngb20a6a82016-01-07 15:41:43 -07003111 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003112 for (auto drawDataElement : pCB->drawData) {
3113 for (auto buffer : drawDataElement.buffers) {
3114 auto buffer_data = my_data->bufferMap.find(buffer);
3115 if (buffer_data == my_data->bufferMap.end()) {
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07003116 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, reinterpret_cast<uint64_t>(buffer), __LINE__, DRAWSTATE_INVALID_BUFFER, "DS",
Michael Lentine700b0aa2015-10-30 17:57:32 -07003117 "Cannot submit cmd buffer using deleted buffer %" PRIu64 ".", reinterpret_cast<uint64_t>(buffer));
3118 } else {
3119 buffer_data->second.in_use.fetch_add(1);
3120 }
3121 }
3122 }
Michael Lentine2e068b22015-12-29 16:05:27 -06003123 return skip_call;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003124}
3125
3126void decrementResources(layer_data* my_data, VkCommandBuffer cmdBuffer) {
3127 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cmdBuffer);
3128 for (auto drawDataElement : pCB->drawData) {
3129 for (auto buffer : drawDataElement.buffers) {
3130 auto buffer_data = my_data->bufferMap.find(buffer);
3131 if (buffer_data != my_data->bufferMap.end()) {
3132 buffer_data->second.in_use.fetch_sub(1);
3133 }
3134 }
3135 }
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07003136 for (auto set : pCB->activeSets) {
3137 auto setNode = my_data->setMap.find(set);
3138 if (setNode != my_data->setMap.end()) {
3139 setNode->second->in_use.fetch_sub(1);
3140 }
3141 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003142 for (auto queryStatePair : pCB->queryToStateMap) {
3143 my_data->queryToStateMap[queryStatePair.first] = queryStatePair.second;
3144 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003145}
3146
3147void decrementResources(layer_data* my_data, uint32_t fenceCount, const VkFence* pFences) {
3148 for (uint32_t i = 0; i < fenceCount; ++i) {
3149 auto fence_data = my_data->fenceMap.find(pFences[i]);
3150 if (fence_data == my_data->fenceMap.end() || !fence_data->second.needsSignaled) return;
3151 fence_data->second.needsSignaled = false;
3152 if (fence_data->second.priorFence != VK_NULL_HANDLE) {
3153 decrementResources(my_data, 1, &fence_data->second.priorFence);
3154 }
3155 for (auto cmdBuffer : fence_data->second.cmdBuffers) {
3156 decrementResources(my_data, cmdBuffer);
3157 }
3158 }
3159}
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07003160
Michael Lentine700b0aa2015-10-30 17:57:32 -07003161void decrementResources(layer_data* my_data, VkQueue queue) {
3162 auto queue_data = my_data->queueMap.find(queue);
3163 if (queue_data != my_data->queueMap.end()) {
3164 for (auto cmdBuffer : queue_data->second.untrackedCmdBuffers) {
3165 decrementResources(my_data, cmdBuffer);
3166 }
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07003167 queue_data->second.untrackedCmdBuffers.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07003168 decrementResources(my_data, 1, &queue_data->second.priorFence);
3169 }
3170}
3171
3172void trackCommandBuffers(layer_data* my_data, VkQueue queue, uint32_t cmdBufferCount, const VkCommandBuffer* pCmdBuffers, VkFence fence) {
3173 auto queue_data = my_data->queueMap.find(queue);
3174 if (fence != VK_NULL_HANDLE) {
3175 VkFence priorFence = VK_NULL_HANDLE;
3176 if (queue_data != my_data->queueMap.end()) {
3177 priorFence = queue_data->second.priorFence;
3178 queue_data->second.priorFence = fence;
3179 for (auto cmdBuffer : queue_data->second.untrackedCmdBuffers) {
3180 my_data->fenceMap[fence].cmdBuffers.push_back(cmdBuffer);
3181 }
3182 queue_data->second.untrackedCmdBuffers.clear();
3183 }
3184 my_data->fenceMap[fence].cmdBuffers.clear();
3185 my_data->fenceMap[fence].priorFence = priorFence;
3186 my_data->fenceMap[fence].needsSignaled = true;
3187 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003188 for (auto secondaryCmdBuffer : my_data->commandBufferMap[pCmdBuffers[i]]->secondaryCommandBuffers) {
3189 my_data->fenceMap[fence].cmdBuffers.push_back(secondaryCmdBuffer);
3190 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003191 my_data->fenceMap[fence].cmdBuffers.push_back(pCmdBuffers[i]);
3192 }
3193 } else {
3194 if (queue_data != my_data->queueMap.end()) {
3195 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003196 for (auto secondaryCmdBuffer : my_data->commandBufferMap[pCmdBuffers[i]]->secondaryCommandBuffers) {
3197 queue_data->second.untrackedCmdBuffers.push_back(secondaryCmdBuffer);
3198 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003199 queue_data->second.untrackedCmdBuffers.push_back(pCmdBuffers[i]);
3200 }
3201 }
3202 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003203 if (queue_data != my_data->queueMap.end()) {
3204 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003205 for (auto secondaryCmdBuffer : my_data->commandBufferMap[pCmdBuffers[i]]->secondaryCommandBuffers) {
3206 my_data->inFlightCmdBuffers.insert(secondaryCmdBuffer);
3207 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003208 my_data->inFlightCmdBuffers.insert(pCmdBuffers[i]);
3209 }
3210 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003211}
3212
Chia-I Wu9ab61502015-11-06 06:42:02 +08003213VK_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 -06003214{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003215 VkBool32 skipCall = VK_FALSE;
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06003216 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlis0b632332015-10-07 09:38:40 -06003217 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003218 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08003219 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Michael Lentine15a47882016-01-06 10:05:48 -06003220 for (uint32_t i=0; i < submit->waitSemaphoreCount; ++i) {
3221 if (dev_data->semaphoreSignaledMap[submit->pWaitSemaphores[i]]) {
3222 dev_data->semaphoreSignaledMap[submit->pWaitSemaphores[i]] = 0;
3223 } else {
3224 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",
3225 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
3226 reinterpret_cast<uint64_t>(queue), reinterpret_cast<uint64_t>(submit->pWaitSemaphores[i]));
3227 }
3228 }
3229 for (uint32_t i=0; i < submit->signalSemaphoreCount; ++i) {
3230 dev_data->semaphoreSignaledMap[submit->pSignalSemaphores[i]] = 1;
3231 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08003232 for (uint32_t i=0; i < submit->commandBufferCount; i++) {
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07003233
3234#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
3235 skipCall |= ValidateCmdBufImageLayouts(submit->pCommandBuffers[i]);
3236#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
3237
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003238 // Validate that cmd buffers have been updated
3239 pCB = getCBNode(dev_data, submit->pCommandBuffers[i]);
3240 loader_platform_thread_lock_mutex(&globalLock);
3241 pCB->submitCount++; // increment submit count
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003242 // Track in-use for resources off of primary and any secondary CBs
Michael Lentine700b0aa2015-10-30 17:57:32 -07003243 skipCall |= validateAndIncrementResources(dev_data, pCB);
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003244 if (!pCB->secondaryCommandBuffers.empty()) {
3245 for (auto secondaryCmdBuffer : pCB->secondaryCommandBuffers) {
3246 skipCall |= validateAndIncrementResources(dev_data, dev_data->commandBufferMap[secondaryCmdBuffer]);
3247 }
3248 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003249 if ((pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT) && (pCB->submitCount > 1)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003250 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 -05003251 "CB %#" PRIxLEAST64 " was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted %#" PRIxLEAST64 " times.",
3252 reinterpret_cast<uint64_t>(pCB->commandBuffer), pCB->submitCount);
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003253 }
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003254 if (CB_RECORDED != pCB->state) {
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003255 // Flag error for using CB w/o vkEndCommandBuffer() called
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003256 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 +08003257 "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 -06003258 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003259 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003260 }
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003261 // If USAGE_SIMULTANEOUS_USE_BIT not set then CB cannot already be executing on device
3262 if (!(pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT)) {
3263 if (dev_data->inFlightCmdBuffers.find(pCB->commandBuffer) != dev_data->inFlightCmdBuffers.end()) {
3264 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, reinterpret_cast<uint64_t>(pCB->commandBuffer), __LINE__, DRAWSTATE_INVALID_CB_SIMULTANEOUS_USE, "DS",
3265 "Attempt to simultaneously execute CB %#" PRIxLEAST64 " w/o VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!", reinterpret_cast<uint64_t>(pCB->commandBuffer));
3266 }
3267 }
Tobin Ehlisc4bdde12015-05-27 14:30:06 -06003268 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06003269 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003270 trackCommandBuffers(dev_data, queue, submit->commandBufferCount, submit->pCommandBuffers, fence);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003271 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003272 if (VK_FALSE == skipCall)
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08003273 return dev_data->device_dispatch_table->QueueSubmit(queue, submitCount, pSubmits, fence);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003274 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003275}
3276
Mark Youngb20a6a82016-01-07 15:41:43 -07003277VkBool32 cleanInFlightCmdBuffer(layer_data* my_data, VkCommandBuffer cmdBuffer) {
3278 VkBool32 skip_call = VK_FALSE;
Michael Lentineb887b0a2015-12-29 14:12:11 -06003279 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cmdBuffer);
3280 for (auto queryEventsPair : pCB->waitedEventsBeforeQueryReset) {
3281 for (auto event : queryEventsPair.second) {
3282 if (my_data->eventMap[event].needsSignaled) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003283 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",
3284 "Cannot get query results on queryPool %" PRIu64 " with index %d which was guarded by unsignaled event %" PRIu64 ".",
Michael Lentineb887b0a2015-12-29 14:12:11 -06003285 reinterpret_cast<uint64_t>(queryEventsPair.first.pool), queryEventsPair.first.index, reinterpret_cast<uint64_t>(event));
3286 }
3287 }
3288 }
3289 return skip_call;
3290}
3291
Michael Lentine700b0aa2015-10-30 17:57:32 -07003292VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence* pFences, VkBool32 waitAll, uint64_t timeout)
3293{
3294 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3295 VkResult result = dev_data->device_dispatch_table->WaitForFences(device, fenceCount, pFences, waitAll, timeout);
Mark Youngb20a6a82016-01-07 15:41:43 -07003296 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003297 if ((waitAll || fenceCount == 1) && result == VK_SUCCESS) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06003298 for (uint32_t i = 0; i < fenceCount; ++i) {
3299 for (auto cmdBuffer : dev_data->fenceMap[pFences[i]].cmdBuffers) {
3300 dev_data->inFlightCmdBuffers.erase(cmdBuffer);
3301 skip_call |= cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3302 }
3303 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003304 decrementResources(dev_data, fenceCount, pFences);
3305 }
Mark Youngb20a6a82016-01-07 15:41:43 -07003306 if (VK_FALSE != skip_call)
Mark Lobodzinskice738852016-01-07 10:04:02 -07003307 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003308 return result;
3309}
3310
3311
3312VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetFenceStatus(VkDevice device, VkFence fence)
3313{
3314 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3315 VkResult result = dev_data->device_dispatch_table->GetFenceStatus(device, fence);
3316 if (result == VK_SUCCESS) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06003317 for (auto cmdBuffer : dev_data->fenceMap[fence].cmdBuffers) {
3318 dev_data->inFlightCmdBuffers.erase(cmdBuffer);
3319 cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3320 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003321 decrementResources(dev_data, 1, &fence);
3322 }
3323 return result;
3324}
3325
3326VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue* pQueue)
3327{
3328 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3329 dev_data->device_dispatch_table->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue);
3330 dev_data->deviceMap[device].queues.push_back(*pQueue);
3331 dev_data->queueMap[*pQueue].device = device;
3332}
3333
3334VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueueWaitIdle(VkQueue queue)
3335{
3336 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
3337 decrementResources(dev_data, queue);
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003338 // TODO : Is this a bug? Can't clear all device CmdBuffers on QueueWaitIdle
Michael Lentineb887b0a2015-12-29 14:12:11 -06003339 for (auto cmdBuffer : dev_data->inFlightCmdBuffers) {
3340 cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3341 }
3342 dev_data->inFlightCmdBuffers.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07003343 return dev_data->device_dispatch_table->QueueWaitIdle(queue);
3344}
3345
3346VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkDeviceWaitIdle(VkDevice device)
3347{
3348 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3349 auto device_data = dev_data->deviceMap.find(device);
3350 if (device_data != dev_data->deviceMap.end()) {
3351 for (auto queue : device_data->second.queues) {
3352 decrementResources(dev_data, queue);
3353 }
3354 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003355 for (auto cmdBuffer : dev_data->inFlightCmdBuffers) {
3356 cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3357 }
3358 dev_data->inFlightCmdBuffers.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07003359 return dev_data->device_dispatch_table->DeviceWaitIdle(device);
3360}
3361
Chia-I Wu9ab61502015-11-06 06:42:02 +08003362VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003363{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003364 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 -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 vkDestroySemaphore(VkDevice device, VkSemaphore semaphore, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003369{
Michael Lentine15a47882016-01-06 10:05:48 -06003370 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3371 dev_data->device_dispatch_table->DestroySemaphore(device, semaphore, pAllocator);
3372 dev_data->semaphoreSignaledMap.erase(semaphore);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003373 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003374}
3375
Chia-I Wu9ab61502015-11-06 06:42:02 +08003376VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003377{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003378 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 -06003379 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003380}
3381
Chia-I Wu9ab61502015-11-06 06:42:02 +08003382VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003383{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003384 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 -06003385 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003386}
3387
Mark Lobodzinskice738852016-01-07 10:04:02 -07003388VKAPI_ATTR VkResult VKAPI_CALL vkGetQueryPoolResults(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount,
Michael Lentineb887b0a2015-12-29 14:12:11 -06003389 size_t dataSize, void* pData, VkDeviceSize stride, VkQueryResultFlags flags) {
3390 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3391 unordered_map<QueryObject, vector<VkCommandBuffer>> queriesInFlight;
3392 GLOBAL_CB_NODE* pCB = nullptr;
3393 for (auto cmdBuffer : dev_data->inFlightCmdBuffers) {
3394 pCB = getCBNode(dev_data, cmdBuffer);
3395 for (auto queryStatePair : pCB->queryToStateMap) {
3396 queriesInFlight[queryStatePair.first].push_back(cmdBuffer);
3397 }
3398 }
Mark Youngb20a6a82016-01-07 15:41:43 -07003399 VkBool32 skip_call = VK_FALSE;
Michael Lentineb887b0a2015-12-29 14:12:11 -06003400 for (uint32_t i = 0; i < queryCount; ++i) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003401 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06003402 auto queryElement = queriesInFlight.find(query);
3403 auto queryToStateElement = dev_data->queryToStateMap.find(query);
3404 if (queryToStateElement != dev_data->queryToStateMap.end()) {
3405 }
3406 // Available and in flight
3407 if(queryElement != queriesInFlight.end() && queryToStateElement != dev_data->queryToStateMap.end() && queryToStateElement->second) {
3408 for (auto cmdBuffer : queryElement->second) {
3409 pCB = getCBNode(dev_data, cmdBuffer);
3410 auto queryEventElement = pCB->waitedEventsBeforeQueryReset.find(query);
3411 if (queryEventElement == pCB->waitedEventsBeforeQueryReset.end()) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003412 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT, 0, __LINE__,
3413 DRAWSTATE_INVALID_QUERY, "DS", "Cannot get query results on queryPool %" PRIu64 " with index %d which is in flight.",
3414 reinterpret_cast<uint64_t>(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003415 } else {
3416 for (auto event : queryEventElement->second) {
3417 dev_data->eventMap[event].needsSignaled = true;
3418 }
3419 }
3420 }
3421 // Unavailable and in flight
3422 } else if (queryElement != queriesInFlight.end() && queryToStateElement != dev_data->queryToStateMap.end() && !queryToStateElement->second) {
3423 // TODO : Can there be the same query in use by multiple command buffers in flight?
3424 bool make_available = false;
3425 for (auto cmdBuffer : queryElement->second) {
3426 pCB = getCBNode(dev_data, cmdBuffer);
3427 make_available |= pCB->queryToStateMap[query];
3428 }
3429 if (!(((flags & VK_QUERY_RESULT_PARTIAL_BIT) || (flags & VK_QUERY_RESULT_WAIT_BIT)) && make_available)) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003430 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 -06003431 "Cannot get query results on queryPool %" PRIu64 " with index %d which is unavailable.",
Mark Lobodzinskice738852016-01-07 10:04:02 -07003432 reinterpret_cast<uint64_t>(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003433 }
3434 // Unavailable
3435 } else if (queryToStateElement != dev_data->queryToStateMap.end() && !queryToStateElement->second) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003436 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 -06003437 "Cannot get query results on queryPool %" PRIu64 " with index %d which is unavailable.",
Mark Lobodzinskice738852016-01-07 10:04:02 -07003438 reinterpret_cast<uint64_t>(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003439 // Unitialized
3440 } else if (queryToStateElement == dev_data->queryToStateMap.end()) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003441 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 -06003442 "Cannot get query results on queryPool %" PRIu64 " with index %d which is uninitialized.",
Mark Lobodzinskice738852016-01-07 10:04:02 -07003443 reinterpret_cast<uint64_t>(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003444 }
3445 }
3446 if (skip_call)
Mark Lobodzinskice738852016-01-07 10:04:02 -07003447 return VK_ERROR_VALIDATION_FAILED_EXT;
3448 return dev_data->device_dispatch_table->GetQueryPoolResults(device, queryPool, firstQuery, queryCount, dataSize, pData, stride, flags);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003449}
3450
Mark Young7a69c302016-01-07 09:48:47 -07003451VkBool32 validateIdleBuffer(const layer_data* my_data, VkBuffer buffer) {
Mark Youngb20a6a82016-01-07 15:41:43 -07003452 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003453 auto buffer_data = my_data->bufferMap.find(buffer);
3454 if (buffer_data == my_data->bufferMap.end()) {
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07003455 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, reinterpret_cast<uint64_t>(buffer), __LINE__, DRAWSTATE_DOUBLE_DESTROY, "DS",
Michael Lentine700b0aa2015-10-30 17:57:32 -07003456 "Cannot free buffer %" PRIxLEAST64 " that has not been allocated.", reinterpret_cast<uint64_t>(buffer));
3457 } else {
3458 if (buffer_data->second.in_use.load()) {
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07003459 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, reinterpret_cast<uint64_t>(buffer), __LINE__, DRAWSTATE_OBJECT_INUSE, "DS",
Michael Lentine700b0aa2015-10-30 17:57:32 -07003460 "Cannot free buffer %" PRIxLEAST64 " that is in use by a command buffer.", reinterpret_cast<uint64_t>(buffer));
Michael Lentine700b0aa2015-10-30 17:57:32 -07003461 }
3462 }
3463 return skip_call;
3464}
3465
Chia-I Wu9ab61502015-11-06 06:42:02 +08003466VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003467{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003468 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07003469 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003470 if (!validateIdleBuffer(dev_data, buffer)) {
3471 dev_data->device_dispatch_table->DestroyBuffer(device, buffer, pAllocator);
3472 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08003473 dev_data->bufferMap.erase(buffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003474}
3475
Chia-I Wu9ab61502015-11-06 06:42:02 +08003476VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBufferView(VkDevice device, VkBufferView bufferView, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003477{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003478 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003479 dev_data->device_dispatch_table->DestroyBufferView(device, bufferView, pAllocator);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003480 dev_data->bufferViewMap.erase(bufferView);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003481}
3482
Chia-I Wu9ab61502015-11-06 06:42:02 +08003483VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003484{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003485 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003486 dev_data->device_dispatch_table->DestroyImage(device, image, pAllocator);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003487 dev_data->imageMap.erase(image);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003488}
3489
Chia-I Wu9ab61502015-11-06 06:42:02 +08003490VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyImageView(VkDevice device, VkImageView imageView, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003491{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003492 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 -06003493 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003494}
3495
Chia-I Wu9ab61502015-11-06 06:42:02 +08003496VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003497{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003498 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 -06003499 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003500}
3501
Chia-I Wu9ab61502015-11-06 06:42:02 +08003502VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyPipeline(VkDevice device, VkPipeline pipeline, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003503{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003504 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 -06003505 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003506}
3507
Chia-I Wu9ab61502015-11-06 06:42:02 +08003508VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003509{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003510 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 -06003511 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003512}
3513
Chia-I Wu9ab61502015-11-06 06:42:02 +08003514VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySampler(VkDevice device, VkSampler sampler, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003515{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003516 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 -06003517 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003518}
3519
Chia-I Wu9ab61502015-11-06 06:42:02 +08003520VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003521{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003522 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 -06003523 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003524}
3525
Chia-I Wu9ab61502015-11-06 06:42:02 +08003526VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003527{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003528 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 -06003529 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003530}
3531
Chia-I Wu9ab61502015-11-06 06:42:02 +08003532VK_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 -06003533{
Mark Lobodzinski39298632015-11-18 08:38:27 -07003534 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3535
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07003536 for (uint32_t i = 0; i < count; i++) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003537 // Delete CB information structure, and remove from commandBufferMap
3538 auto cb = dev_data->commandBufferMap.find(pCommandBuffers[i]);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003539 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003540 if (cb != dev_data->commandBufferMap.end()) {
3541 delete (*cb).second;
3542 dev_data->commandBufferMap.erase(cb);
3543 }
3544
3545 // Remove commandBuffer reference from commandPoolMap
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003546 dev_data->commandPoolMap[commandPool].commandBuffers.remove(pCommandBuffers[i]);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003547 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003548 }
3549
3550 dev_data->device_dispatch_table->FreeCommandBuffers(device, commandPool, count, pCommandBuffers);
3551}
3552
3553VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkCommandPool* pCommandPool)
3554{
3555 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3556
3557 VkResult result = dev_data->device_dispatch_table->CreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
3558
3559 if (VK_SUCCESS == result) {
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003560 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003561 dev_data->commandPoolMap[*pCommandPool].createFlags = pCreateInfo->flags;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003562 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003563 }
3564 return result;
3565}
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07003566// Destroy commandPool along with all of the commandBuffers allocated from that pool
Mark Lobodzinski39298632015-11-18 08:38:27 -07003567VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks* pAllocator)
3568{
3569 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003570 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003571
3572 // Must remove cmdpool from cmdpoolmap, after removing all cmdbuffers in its list from the commandPoolMap
3573 if (dev_data->commandPoolMap.find(commandPool) != dev_data->commandPoolMap.end()) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003574 for (auto poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.begin(); poolCb != dev_data->commandPoolMap[commandPool].commandBuffers.end();) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003575 auto del_cb = dev_data->commandBufferMap.find(*poolCb);
3576 delete (*del_cb).second; // delete CB info structure
3577 dev_data->commandBufferMap.erase(del_cb); // Remove this command buffer from cbMap
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003578 poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.erase(poolCb); // Remove CB reference from commandPoolMap's list
Mark Lobodzinski39298632015-11-18 08:38:27 -07003579 }
3580 }
3581 dev_data->commandPoolMap.erase(commandPool);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003582
3583 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003584 dev_data->device_dispatch_table->DestroyCommandPool(device, commandPool, pAllocator);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003585}
3586
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003587VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandPool(
3588 VkDevice device,
3589 VkCommandPool commandPool,
3590 VkCommandPoolResetFlags flags)
3591{
3592 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003593 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003594
3595 result = dev_data->device_dispatch_table->ResetCommandPool(device, commandPool, flags);
3596 // Reset all of the CBs allocated from this pool
3597 if (VK_SUCCESS == result) {
3598 auto it = dev_data->commandPoolMap[commandPool].commandBuffers.begin();
3599 while (it != dev_data->commandPoolMap[commandPool].commandBuffers.end()) {
3600 resetCB(dev_data, (*it));
3601 ++it;
3602 }
3603 }
3604 return result;
3605}
3606
Chia-I Wu9ab61502015-11-06 06:42:02 +08003607VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003608{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003609 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 -06003610 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003611}
3612
Chia-I Wu9ab61502015-11-06 06:42:02 +08003613VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003614{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003615 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 -06003616 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003617}
3618
Chia-I Wu9ab61502015-11-06 06:42:02 +08003619VK_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 -06003620{
3621 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003622 VkResult result = dev_data->device_dispatch_table->CreateBuffer(device, pCreateInfo, pAllocator, pBuffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003623 if (VK_SUCCESS == result) {
3624 loader_platform_thread_lock_mutex(&globalLock);
3625 // 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 -07003626 dev_data->bufferMap[*pBuffer].create_info = unique_ptr<VkBufferCreateInfo>(new VkBufferCreateInfo(*pCreateInfo));
3627 dev_data->bufferMap[*pBuffer].in_use.store(0);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003628 loader_platform_thread_unlock_mutex(&globalLock);
3629 }
3630 return result;
3631}
3632
Chia-I Wu9ab61502015-11-06 06:42:02 +08003633VK_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 -06003634{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003635 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003636 VkResult result = dev_data->device_dispatch_table->CreateBufferView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003637 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003638 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003639 dev_data->bufferViewMap[*pView] = unique_ptr<VkBufferViewCreateInfo>(new VkBufferViewCreateInfo(*pCreateInfo));
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003640 loader_platform_thread_unlock_mutex(&globalLock);
3641 }
3642 return result;
3643}
3644
Chia-I Wu9ab61502015-11-06 06:42:02 +08003645VK_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 -06003646{
3647 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003648 VkResult result = dev_data->device_dispatch_table->CreateImage(device, pCreateInfo, pAllocator, pImage);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003649 if (VK_SUCCESS == result) {
Michael Lentineabc5e922015-10-12 11:30:14 -05003650 IMAGE_NODE* image_node = new IMAGE_NODE;
3651 image_node->layout = pCreateInfo->initialLayout;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003652 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003653 dev_data->imageMap[*pImage] = unique_ptr<VkImageCreateInfo>(new VkImageCreateInfo(*pCreateInfo));
Michael Lentineabc5e922015-10-12 11:30:14 -05003654 dev_data->imageLayoutMap[*pImage] = image_node;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003655 loader_platform_thread_unlock_mutex(&globalLock);
3656 }
3657 return result;
3658}
3659
Chia-I Wu9ab61502015-11-06 06:42:02 +08003660VK_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 -06003661{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003662 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003663 VkResult result = dev_data->device_dispatch_table->CreateImageView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003664 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003665 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003666 dev_data->imageViewMap[*pView] = unique_ptr<VkImageViewCreateInfo>(new VkImageViewCreateInfo(*pCreateInfo));
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003667 loader_platform_thread_unlock_mutex(&globalLock);
3668 }
3669 return result;
3670}
3671
Jon Ashburnc669cc62015-07-09 15:02:25 -06003672//TODO handle pipeline caches
Chia-I Wu9ab61502015-11-06 06:42:02 +08003673VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineCache(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003674 VkDevice device,
3675 const VkPipelineCacheCreateInfo* pCreateInfo,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003676 const VkAllocationCallbacks* pAllocator,
Jon Ashburnc669cc62015-07-09 15:02:25 -06003677 VkPipelineCache* pPipelineCache)
3678{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003679 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003680 VkResult result = dev_data->device_dispatch_table->CreatePipelineCache(device, pCreateInfo, pAllocator, pPipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003681 return result;
3682}
3683
Chia-I Wu9ab61502015-11-06 06:42:02 +08003684VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineCache(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003685 VkDevice device,
Chia-I Wuf7458c52015-10-26 21:10:41 +08003686 VkPipelineCache pipelineCache,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003687 const VkAllocationCallbacks* pAllocator)
Jon Ashburnc669cc62015-07-09 15:02:25 -06003688{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003689 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003690 dev_data->device_dispatch_table->DestroyPipelineCache(device, pipelineCache, pAllocator);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003691}
3692
Chia-I Wu9ab61502015-11-06 06:42:02 +08003693VKAPI_ATTR VkResult VKAPI_CALL vkGetPipelineCacheData(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003694 VkDevice device,
3695 VkPipelineCache pipelineCache,
Chia-I Wub16facd2015-10-26 19:17:06 +08003696 size_t* pDataSize,
Jon Ashburnc669cc62015-07-09 15:02:25 -06003697 void* pData)
3698{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003699 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wub16facd2015-10-26 19:17:06 +08003700 VkResult result = dev_data->device_dispatch_table->GetPipelineCacheData(device, pipelineCache, pDataSize, pData);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003701 return result;
3702}
3703
Chia-I Wu9ab61502015-11-06 06:42:02 +08003704VKAPI_ATTR VkResult VKAPI_CALL vkMergePipelineCaches(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003705 VkDevice device,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003706 VkPipelineCache dstCache,
Jon Ashburnc669cc62015-07-09 15:02:25 -06003707 uint32_t srcCacheCount,
3708 const VkPipelineCache* pSrcCaches)
3709{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003710 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003711 VkResult result = dev_data->device_dispatch_table->MergePipelineCaches(device, dstCache, srcCacheCount, pSrcCaches);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003712 return result;
3713}
3714
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003715VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateGraphicsPipelines(
3716 VkDevice device,
3717 VkPipelineCache pipelineCache,
3718 uint32_t count,
3719 const VkGraphicsPipelineCreateInfo *pCreateInfos,
3720 const VkAllocationCallbacks *pAllocator,
3721 VkPipeline *pPipelines)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003722{
Courtney Goeltzenleuchtered894072015-09-04 13:39:59 -06003723 VkResult result = VK_SUCCESS;
Tobin Ehlis11efc302015-09-16 10:33:53 -06003724 //TODO What to do with pipelineCache?
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003725 // The order of operations here is a little convoluted but gets the job done
3726 // 1. Pipeline create state is first shadowed into PIPELINE_NODE struct
3727 // 2. Create state is then validated (which uses flags setup during shadowing)
3728 // 3. If everything looks good, we'll then create the pipeline and add NODE to pipelineMap
Tobin Ehlis11efc302015-09-16 10:33:53 -06003729 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis65399772015-09-17 16:33:58 -06003730 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
3731 vector<PIPELINE_NODE*> pPipeNode(count);
Tobin Ehlis0b632332015-10-07 09:38:40 -06003732 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003733
Tobin Ehlis11efc302015-09-16 10:33:53 -06003734 uint32_t i=0;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003735 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003736
Tobin Ehlis11efc302015-09-16 10:33:53 -06003737 for (i=0; i<count; i++) {
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003738 pPipeNode[i] = initGraphicsPipeline(dev_data, &pCreateInfos[i], NULL);
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06003739 skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
Tobin Ehlis11efc302015-09-16 10:33:53 -06003740 }
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003741
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003742 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003743
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07003744 if (VK_FALSE == skipCall) {
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003745 result = dev_data->device_dispatch_table->CreateGraphicsPipelines(device,
3746 pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003747 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis11efc302015-09-16 10:33:53 -06003748 for (i=0; i<count; i++) {
3749 pPipeNode[i]->pipeline = pPipelines[i];
Chia-I Wue2fc5522015-10-26 20:04:44 +08003750 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
Tobin Ehlis11efc302015-09-16 10:33:53 -06003751 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003752 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisce132d82015-06-19 15:07:05 -06003753 } else {
Tobin Ehlis11efc302015-09-16 10:33:53 -06003754 for (i=0; i<count; i++) {
3755 if (pPipeNode[i]) {
3756 // If we allocated a pipeNode, need to clean it up here
3757 delete[] pPipeNode[i]->pVertexBindingDescriptions;
3758 delete[] pPipeNode[i]->pVertexAttributeDescriptions;
3759 delete[] pPipeNode[i]->pAttachments;
3760 delete pPipeNode[i];
3761 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003762 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003763 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003764 }
Courtney Goeltzenleuchtere2aaad02015-04-13 16:16:04 -06003765 return result;
3766}
3767
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003768VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateComputePipelines(
3769 VkDevice device,
3770 VkPipelineCache pipelineCache,
3771 uint32_t count,
3772 const VkComputePipelineCreateInfo *pCreateInfos,
3773 const VkAllocationCallbacks *pAllocator,
3774 VkPipeline *pPipelines)
3775{
3776 VkResult result = VK_SUCCESS;
3777 VkBool32 skipCall = VK_FALSE;
3778
3779 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
3780 vector<PIPELINE_NODE*> pPipeNode(count);
3781 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3782
3783 uint32_t i=0;
3784 loader_platform_thread_lock_mutex(&globalLock);
3785 for (i=0; i<count; i++) {
3786 // TODO: Verify compute stage bits
3787
3788 // Create and initialize internal tracking data structure
3789 pPipeNode[i] = new PIPELINE_NODE;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003790 memcpy(&pPipeNode[i]->computePipelineCI, (const void*)&pCreateInfos[i], sizeof(VkComputePipelineCreateInfo));
3791
3792 // TODO: Add Compute Pipeline Verification
3793 // skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
3794 }
3795 loader_platform_thread_unlock_mutex(&globalLock);
3796
3797 if (VK_FALSE == skipCall) {
3798 result = dev_data->device_dispatch_table->CreateComputePipelines(device, pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
3799 loader_platform_thread_lock_mutex(&globalLock);
3800 for (i=0; i<count; i++) {
3801 pPipeNode[i]->pipeline = pPipelines[i];
3802 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
3803 }
3804 loader_platform_thread_unlock_mutex(&globalLock);
3805 } else {
3806 for (i=0; i<count; i++) {
3807 if (pPipeNode[i]) {
3808 // Clean up any locally allocated data structures
3809 delete pPipeNode[i];
3810 }
3811 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003812 return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003813 }
3814 return result;
3815}
3816
Chia-I Wu9ab61502015-11-06 06:42:02 +08003817VK_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 -06003818{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003819 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003820 VkResult result = dev_data->device_dispatch_table->CreateSampler(device, pCreateInfo, pAllocator, pSampler);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003821 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003822 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003823 dev_data->sampleMap[*pSampler] = unique_ptr<SAMPLER_NODE>(new SAMPLER_NODE(pSampler, pCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003824 loader_platform_thread_unlock_mutex(&globalLock);
3825 }
3826 return result;
3827}
3828
Chia-I Wu9ab61502015-11-06 06:42:02 +08003829VK_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 -06003830{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003831 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003832 VkResult result = dev_data->device_dispatch_table->CreateDescriptorSetLayout(device, pCreateInfo, pAllocator, pSetLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003833 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003834 // TODOSC : Capture layout bindings set
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003835 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
3836 if (NULL == pNewNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003837 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 -06003838 "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003839 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003840 }
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06003841 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003842 pNewNode->createInfo.pBindings = new VkDescriptorSetLayoutBinding[pCreateInfo->bindingCount];
3843 memcpy((void*)pNewNode->createInfo.pBindings, pCreateInfo->pBindings, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->bindingCount);
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003844 // g++ does not like reserve with size 0
3845 if (pCreateInfo->bindingCount)
3846 pNewNode->bindings.reserve(pCreateInfo->bindingCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003847 uint32_t totalCount = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003848 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003849 if (!pNewNode->bindings.insert(pCreateInfo->pBindings[i].binding).second) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003850 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 +08003851 "duplicated binding number in VkDescriptorSetLayoutBinding"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003852 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003853 }
3854
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003855 totalCount += pCreateInfo->pBindings[i].descriptorCount;
3856 if (pCreateInfo->pBindings[i].pImmutableSamplers) {
3857 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBindings[i].pImmutableSamplers;
3858 *ppIS = new VkSampler[pCreateInfo->pBindings[i].descriptorCount];
3859 memcpy(*ppIS, pCreateInfo->pBindings[i].pImmutableSamplers, pCreateInfo->pBindings[i].descriptorCount*sizeof(VkSampler));
Tobin Ehlis793ad302015-04-03 12:01:11 -06003860 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003861 }
Tobin Ehlis43c39c02016-01-11 13:18:40 -07003862 pNewNode->layout = *pSetLayout;
3863 pNewNode->startIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003864 if (totalCount > 0) {
Cody Northrop43751cc2015-10-26 14:07:35 -06003865 pNewNode->descriptorTypes.resize(totalCount);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06003866 pNewNode->stageFlags.resize(totalCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003867 uint32_t offset = 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06003868 uint32_t j = 0;
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07003869 VkDescriptorType dType;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003870 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003871 dType = pCreateInfo->pBindings[i].descriptorType;
3872 for (j = 0; j < pCreateInfo->pBindings[i].descriptorCount; j++) {
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07003873 pNewNode->descriptorTypes[offset + j] = dType;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003874 pNewNode->stageFlags[offset + j] = pCreateInfo->pBindings[i].stageFlags;
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07003875 if ((dType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
3876 (dType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
3877 pNewNode->dynamicDescriptorCount++;
3878 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003879 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06003880 offset += j;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003881 }
Tobin Ehlis43c39c02016-01-11 13:18:40 -07003882 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
3883 } else { // no descriptors
3884 pNewNode->endIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003885 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003886 // Put new node at Head of global Layer list
3887 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07003888 dev_data->descriptorSetLayoutMap[*pSetLayout] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003889 loader_platform_thread_unlock_mutex(&globalLock);
3890 }
3891 return result;
3892}
3893
Chia-I Wu9ab61502015-11-06 06:42:02 +08003894VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003895{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003896 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003897 VkResult result = dev_data->device_dispatch_table->CreatePipelineLayout(device, pCreateInfo, pAllocator, pPipelineLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003898 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003899 // TODOSC : Merge capture of the setLayouts per pipeline
Tobin Ehlis559c6382015-11-05 09:52:49 -07003900 PIPELINE_LAYOUT_NODE& plNode = dev_data->pipelineLayoutMap[*pPipelineLayout];
Chia-I Wud50a7d72015-10-26 20:48:51 +08003901 plNode.descriptorSetLayouts.resize(pCreateInfo->setLayoutCount);
Tobin Ehlis644ff042015-10-20 10:11:55 -06003902 uint32_t i = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003903 for (i=0; i<pCreateInfo->setLayoutCount; ++i) {
Tobin Ehlis644ff042015-10-20 10:11:55 -06003904 plNode.descriptorSetLayouts[i] = pCreateInfo->pSetLayouts[i];
3905 }
Cody Northrop43751cc2015-10-26 14:07:35 -06003906 plNode.pushConstantRanges.resize(pCreateInfo->pushConstantRangeCount);
Tobin Ehlis644ff042015-10-20 10:11:55 -06003907 for (i=0; i<pCreateInfo->pushConstantRangeCount; ++i) {
3908 plNode.pushConstantRanges[i] = pCreateInfo->pPushConstantRanges[i];
3909 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06003910 }
3911 return result;
3912}
3913
Chia-I Wu9ab61502015-11-06 06:42:02 +08003914VK_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 -06003915{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003916 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003917 VkResult result = dev_data->device_dispatch_table->CreateDescriptorPool(device, pCreateInfo, pAllocator, pDescriptorPool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003918 if (VK_SUCCESS == result) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06003919 // Insert this pool into Global Pool LL at head
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003920 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 +08003921 "Created Descriptor Pool %#" PRIxLEAST64, (uint64_t) *pDescriptorPool))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003922 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003923 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003924 DESCRIPTOR_POOL_NODE* pNewNode = new DESCRIPTOR_POOL_NODE(*pDescriptorPool, pCreateInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003925 if (NULL == pNewNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003926 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 -07003927 "Out of memory while attempting to allocate DESCRIPTOR_POOL_NODE in vkCreateDescriptorPool()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003928 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisce132d82015-06-19 15:07:05 -06003929 } else {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003930 dev_data->descriptorPoolMap[*pDescriptorPool] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003931 }
3932 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisce132d82015-06-19 15:07:05 -06003933 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06003934 // Need to do anything if pool create fails?
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003935 }
3936 return result;
3937}
3938
Chia-I Wu9ab61502015-11-06 06:42:02 +08003939VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorPoolResetFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003940{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003941 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003942 VkResult result = dev_data->device_dispatch_table->ResetDescriptorPool(device, descriptorPool, flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003943 if (VK_SUCCESS == result) {
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003944 clearDescriptorPool(dev_data, device, descriptorPool, flags);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003945 }
3946 return result;
3947}
3948
Chia-I Wu9ab61502015-11-06 06:42:02 +08003949VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo* pAllocateInfo, VkDescriptorSet* pDescriptorSets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003950{
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003951 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis0b632332015-10-07 09:38:40 -06003952 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003953 // Verify that requested descriptorSets are available in pool
Mark Lobodzinski39298632015-11-18 08:38:27 -07003954 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003955 if (!pPoolNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003956 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 +08003957 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003958 } else { // Make sure pool has all the available descriptors before calling down chain
Jon Ashburnf19916e2016-01-11 13:12:43 -07003959 skipCall |= validate_descriptor_availability_in_pool(dev_data, pPoolNode, pAllocateInfo->descriptorSetCount, pAllocateInfo->pSetLayouts);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003960 }
3961 if (skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003962 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003963 VkResult result = dev_data->device_dispatch_table->AllocateDescriptorSets(device, pAllocateInfo, pDescriptorSets);
Cody Northrop1e4f8022015-08-03 12:47:29 -06003964 if (VK_SUCCESS == result) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003965 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003966 if (pPoolNode) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07003967 if (pAllocateInfo->descriptorSetCount == 0) {
3968 log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, pAllocateInfo->descriptorSetCount, __LINE__, DRAWSTATE_NONE, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003969 "AllocateDescriptorSets called with 0 count");
Cody Northrop1e4f8022015-08-03 12:47:29 -06003970 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07003971 for (uint32_t i = 0; i < pAllocateInfo->descriptorSetCount; i++) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003972 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 +08003973 "Created Descriptor Set %#" PRIxLEAST64, (uint64_t) pDescriptorSets[i]);
Tobin Ehlis793ad302015-04-03 12:01:11 -06003974 // Create new set node and add to head of pool nodes
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003975 SET_NODE* pNewNode = new SET_NODE;
3976 if (NULL == pNewNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003977 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 +08003978 "Out of memory while attempting to allocate SET_NODE in vkAllocateDescriptorSets()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003979 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisce132d82015-06-19 15:07:05 -06003980 } else {
Tobin Ehlis8b5b28c2015-10-19 12:09:13 -06003981 // TODO : Pool should store a total count of each type of Descriptor available
3982 // When descriptors are allocated, decrement the count and validate here
3983 // that the count doesn't go below 0. One reset/free need to bump count back up.
Tobin Ehlis793ad302015-04-03 12:01:11 -06003984 // Insert set at head of Set LL for this pool
3985 pNewNode->pNext = pPoolNode->pSets;
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07003986 pNewNode->in_use.store(0);
Tobin Ehlis793ad302015-04-03 12:01:11 -06003987 pPoolNode->pSets = pNewNode;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003988 LAYOUT_NODE* pLayout = getLayoutNode(dev_data, pAllocateInfo->pSetLayouts[i]);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003989 if (NULL == pLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003990 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 +08003991 "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 -07003992 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003993 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06003994 pNewNode->pLayout = pLayout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003995 pNewNode->pool = pAllocateInfo->descriptorPool;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003996 pNewNode->set = pDescriptorSets[i];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003997 pNewNode->descriptorCount = pLayout->endIndex + 1;
3998 if (pNewNode->descriptorCount) {
3999 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
4000 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
4001 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
4002 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08004003 dev_data->setMap[pDescriptorSets[i]] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004004 }
4005 }
4006 }
4007 }
4008 return result;
4009}
4010
Chia-I Wu9ab61502015-11-06 06:42:02 +08004011VK_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 -06004012{
Tobin Ehlise735c692015-10-08 13:13:50 -06004013 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis0b632332015-10-07 09:38:40 -06004014 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07004015 // Make sure that no sets being destroyed are in-flight
4016 for (uint32_t i=0; i<count; ++i)
4017 skipCall |= validateIdleDescriptorSet(dev_data, pDescriptorSets[i], "vkFreeDesriptorSets");
Mark Lobodzinski39298632015-11-18 08:38:27 -07004018 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, descriptorPool);
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004019 if (pPoolNode && !(VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT & pPoolNode->createInfo.flags)) {
4020 // Can't Free from a NON_FREE pool
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004021 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 -06004022 "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 -06004023 }
Mark Youngb20a6a82016-01-07 15:41:43 -07004024 if (VK_FALSE != skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004025 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis0b632332015-10-07 09:38:40 -06004026 VkResult result = dev_data->device_dispatch_table->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004027 if (VK_SUCCESS == result) {
4028 // For each freed descriptor add it back into the pool as available
4029 for (uint32_t i=0; i<count; ++i) {
Chia-I Wue2fc5522015-10-26 20:04:44 +08004030 SET_NODE* pSet = dev_data->setMap[pDescriptorSets[i]]; // getSetNode() without locking
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004031 LAYOUT_NODE* pLayout = pSet->pLayout;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004032 uint32_t typeIndex = 0, poolSizeCount = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004033 for (uint32_t j=0; j<pLayout->createInfo.bindingCount; ++j) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07004034 typeIndex = static_cast<uint32_t>(pLayout->createInfo.pBindings[j].descriptorType);
4035 poolSizeCount = pLayout->createInfo.pBindings[j].descriptorCount;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004036 pPoolNode->availableDescriptorTypeCount[typeIndex] += poolSizeCount;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004037 }
4038 }
4039 }
4040 // TODO : Any other clean-up or book-keeping to do here?
Tony Barbour34ec6922015-07-10 10:50:45 -06004041 return result;
4042}
4043
Chia-I Wu9ab61502015-11-06 06:42:02 +08004044VK_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 -06004045{
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06004046 // 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 -06004047 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08004048 if (!dsUpdate(dev_data, device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies)) {
4049 dev_data->device_dispatch_table->UpdateDescriptorSets(device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies);
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004050 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004051}
4052
Chia-I Wu9ab61502015-11-06 06:42:02 +08004053VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo* pCreateInfo, VkCommandBuffer* pCommandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004054{
Tobin Ehlis0b632332015-10-07 09:38:40 -06004055 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004056 VkResult result = dev_data->device_dispatch_table->AllocateCommandBuffers(device, pCreateInfo, pCommandBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004057 if (VK_SUCCESS == result) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004058 for (uint32_t i = 0; i < pCreateInfo->commandBufferCount; i++) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07004059 // Validate command pool
4060 if (dev_data->commandPoolMap.find(pCreateInfo->commandPool) != dev_data->commandPoolMap.end()) {
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07004061 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07004062 // Add command buffer to its commandPool map
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004063 dev_data->commandPoolMap[pCreateInfo->commandPool].commandBuffers.push_back(pCommandBuffer[i]);
Mark Lobodzinski39298632015-11-18 08:38:27 -07004064 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
4065 // Add command buffer to map
4066 dev_data->commandBufferMap[pCommandBuffer[i]] = pCB;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07004067 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07004068 resetCB(dev_data, pCommandBuffer[i]);
4069 pCB->commandBuffer = pCommandBuffer[i];
4070 pCB->createInfo = *pCreateInfo;
Mark Lobodzinski941aea92016-01-13 10:23:15 -07004071 pCB->device = device;
Mark Lobodzinski39298632015-11-18 08:38:27 -07004072 }
4073 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004074 }
4075 return result;
4076}
4077
Chia-I Wu9ab61502015-11-06 06:42:02 +08004078VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo* pBeginInfo)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004079{
Mark Youngb20a6a82016-01-07 15:41:43 -07004080 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004081 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004082 // Validate command buffer level
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004083 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004084 if (pCB) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004085 if (pCB->createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
4086 // Secondary Command Buffer
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004087 // TODO : Add check here from spec "If commandBuffer is a secondary command buffer and either the
4088 // occlusionQueryEnable member of pBeginInfo is VK_FALSE, or the precise occlusion queries feature
4089 // is not enabled, the queryFlags member of pBeginInfo must not contain VK_QUERY_CONTROL_PRECISE_BIT"
Jon Ashburnf19916e2016-01-11 13:12:43 -07004090 const VkCommandBufferInheritanceInfo *pInfo = pBeginInfo->pInheritanceInfo;
Tobin Ehlis651d9b02015-12-16 05:01:22 -07004091 if (pBeginInfo->flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004092 if (!pInfo->renderPass) { // renderpass should NOT be null for an Secondary CB
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004093 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 -07004094 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) must specify a valid renderpass parameter.", (void*)commandBuffer);
4095 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07004096 if (!pInfo->framebuffer) { // framebuffer may be null for an Secondary CB, but this affects perf
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004097 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 -07004098 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) may perform better if a valid framebuffer parameter is specified.", (void*)commandBuffer);
4099 } else {
4100 string errorString = "";
Jon Ashburnf19916e2016-01-11 13:12:43 -07004101 VkRenderPass fbRP = dev_data->frameBufferMap[pInfo->framebuffer]->renderPass;
4102 if (!verify_renderpass_compatibility(dev_data, fbRP, pInfo->renderPass, errorString)) {
Tobin Ehlis651d9b02015-12-16 05:01:22 -07004103 // renderPass that framebuffer was created with must be compatible with local renderPass
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004104 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 -07004105 "vkBeginCommandBuffer(): Secondary Command Buffer (%p) renderPass (%#" PRIxLEAST64 ") is incompatible w/ framebuffer (%#" PRIxLEAST64 ") w/ render pass (%#" PRIxLEAST64 ") due to: %s",
Jon Ashburnf19916e2016-01-11 13:12:43 -07004106 (void*)commandBuffer, (uint64_t)pInfo->renderPass, (uint64_t)pInfo->framebuffer, (uint64_t)fbRP, errorString.c_str());
Tobin Ehlis651d9b02015-12-16 05:01:22 -07004107 }
4108 }
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004109 }
4110 }
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004111 if (CB_RECORDING == pCB->state) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004112 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 -07004113 "vkBeginCommandBuffer(): Cannot call Begin on CB (%#" PRIxLEAST64 ") in the RECORDING state. Must first call vkEndCommandBuffer().", (uint64_t)commandBuffer);
4114 } else if (CB_RECORDED == pCB->state) {
4115 VkCommandPool cmdPool = pCB->createInfo.commandPool;
4116 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004117 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 -07004118 __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004119 "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.",
4120 (uint64_t) commandBuffer, (uint64_t) cmdPool);
4121 }
Tobin Ehlisef694652016-01-19 12:03:34 -07004122 resetCB(dev_data, commandBuffer);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004123 }
Tobin Ehlisef694652016-01-19 12:03:34 -07004124 // Set updated state here in case implicit reset occurs above
4125 pCB->state = CB_RECORDING;
4126 pCB->beginInfo = *pBeginInfo;
Tobin Ehliscd5bfd82016-01-19 13:12:52 -07004127
4128 if (pCB->beginInfo.pInheritanceInfo) {
4129 pCB->inheritanceInfo = *(pCB->beginInfo.pInheritanceInfo);
4130 pCB->beginInfo.pInheritanceInfo = &pCB->inheritanceInfo;
4131 }
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004132 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004133 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 +08004134 "In vkBeginCommandBuffer() and unable to find CommandBuffer Node for CB %p!", (void*)commandBuffer);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004135 }
Mark Youngb20a6a82016-01-07 15:41:43 -07004136 if (VK_FALSE != skipCall) {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004137 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter5fe086f2015-09-04 15:03:52 -06004138 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004139 VkResult result = dev_data->device_dispatch_table->BeginCommandBuffer(commandBuffer, pBeginInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004140 return result;
4141}
4142
Chia-I Wu9ab61502015-11-06 06:42:02 +08004143VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEndCommandBuffer(VkCommandBuffer commandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004144{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004145 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchtered894072015-09-04 13:39:59 -06004146 VkResult result = VK_SUCCESS;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004147 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4148 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004149 if (pCB) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004150 if (pCB->state != CB_RECORDING) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004151 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkEndCommandBuffer()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004152 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004153 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004154 if (VK_FALSE == skipCall) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004155 result = dev_data->device_dispatch_table->EndCommandBuffer(commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004156 if (VK_SUCCESS == result) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004157 pCB->state = CB_RECORDED;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004158 // Reset CB status flags
4159 pCB->status = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004160 printCB(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004161 }
4162 } else {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004163 result = VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004164 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004165 return result;
4166}
4167
Chia-I Wu9ab61502015-11-06 06:42:02 +08004168VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004169{
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004170 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004171 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004172 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
4173 VkCommandPool cmdPool = pCB->createInfo.commandPool;
4174 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004175 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 -07004176 __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004177 "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.",
4178 (uint64_t) commandBuffer, (uint64_t) cmdPool);
4179 }
Mark Youngb20a6a82016-01-07 15:41:43 -07004180 if (skipCall != VK_FALSE)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004181 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004182 VkResult result = dev_data->device_dispatch_table->ResetCommandBuffer(commandBuffer, flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004183 if (VK_SUCCESS == result) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004184 resetCB(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004185 }
4186 return result;
4187}
4188
Chia-I Wu9ab61502015-11-06 06:42:02 +08004189VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004190{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004191 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004192 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4193 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004194 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004195 skipCall |= addCmd(dev_data, pCB, CMD_BINDPIPELINE, "vkCmdBindPipeline()");
4196 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
4197 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 -07004198 __LINE__, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004199 "Incorrectly binding compute pipeline (%#" PRIxLEAST64 ") during active RenderPass (%#" PRIxLEAST64 ")",
4200 (uint64_t) pipeline, (uint64_t) pCB->activeRenderPass);
4201 } else if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
4202 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdBindPipeline");
4203 }
4204
4205 PIPELINE_NODE* pPN = getPipeline(dev_data, pipeline);
4206 if (pPN) {
4207 pCB->lastBoundPipeline = pipeline;
4208 loader_platform_thread_lock_mutex(&globalLock);
4209 set_cb_pso_status(pCB, pPN);
4210 loader_platform_thread_unlock_mutex(&globalLock);
4211 skipCall |= validatePipelineState(dev_data, pCB, pipelineBindPoint, pipeline);
Tobin Ehlisce132d82015-06-19 15:07:05 -06004212 } else {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004213 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 -07004214 (uint64_t) pipeline, __LINE__, DRAWSTATE_INVALID_PIPELINE, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004215 "Attempt to bind Pipeline %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<uint64_t>(pipeline));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004216 }
4217 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004218 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004219 dev_data->device_dispatch_table->CmdBindPipeline(commandBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004220}
4221
Chia-I Wu9ab61502015-11-06 06:42:02 +08004222VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetViewport(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004223 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004224 uint32_t firstViewport,
4225 uint32_t viewportCount,
4226 const VkViewport* pViewports)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004227{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004228 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004229 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4230 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004231 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004232 skipCall |= addCmd(dev_data, pCB, CMD_SETVIEWPORTSTATE, "vkCmdSetViewport()");
4233 loader_platform_thread_lock_mutex(&globalLock);
4234 pCB->status |= CBSTATUS_VIEWPORT_SET;
4235 pCB->viewports.resize(viewportCount);
4236 memcpy(pCB->viewports.data(), pViewports, viewportCount * sizeof(VkViewport));
4237 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004238 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004239 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004240 dev_data->device_dispatch_table->CmdSetViewport(commandBuffer, firstViewport, viewportCount, pViewports);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004241}
4242
Chia-I Wu9ab61502015-11-06 06:42:02 +08004243VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetScissor(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004244 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004245 uint32_t firstScissor,
4246 uint32_t scissorCount,
4247 const VkRect2D* pScissors)
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004248{
4249 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004250 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4251 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004252 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004253 skipCall |= addCmd(dev_data, pCB, CMD_SETSCISSORSTATE, "vkCmdSetScissor()");
4254 loader_platform_thread_lock_mutex(&globalLock);
4255 pCB->status |= CBSTATUS_SCISSOR_SET;
4256 pCB->scissors.resize(scissorCount);
4257 memcpy(pCB->scissors.data(), pScissors, scissorCount * sizeof(VkRect2D));
4258 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004259 }
4260 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004261 dev_data->device_dispatch_table->CmdSetScissor(commandBuffer, firstScissor, scissorCount, pScissors);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004262}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004263
Chia-I Wu9ab61502015-11-06 06:42:02 +08004264VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004265{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004266 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004267 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4268 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004269 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004270 skipCall |= addCmd(dev_data, pCB, CMD_SETLINEWIDTHSTATE, "vkCmdSetLineWidth()");
4271 /* TODO: Do we still need this lock? */
4272 loader_platform_thread_lock_mutex(&globalLock);
4273 pCB->status |= CBSTATUS_LINE_WIDTH_SET;
4274 pCB->lineWidth = lineWidth;
4275 loader_platform_thread_unlock_mutex(&globalLock);
Cody Northrop12365112015-08-17 11:10:49 -06004276 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004277 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004278 dev_data->device_dispatch_table->CmdSetLineWidth(commandBuffer, lineWidth);
Cody Northrop12365112015-08-17 11:10:49 -06004279}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004280
Chia-I Wu9ab61502015-11-06 06:42:02 +08004281VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBias(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004282 VkCommandBuffer commandBuffer,
Chia-I Wud8c946a2015-10-26 19:08:09 +08004283 float depthBiasConstantFactor,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004284 float depthBiasClamp,
Chia-I Wud8c946a2015-10-26 19:08:09 +08004285 float depthBiasSlopeFactor)
Cody Northrop12365112015-08-17 11:10:49 -06004286{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004287 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004288 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4289 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northrop12365112015-08-17 11:10:49 -06004290 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004291 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBIASSTATE, "vkCmdSetDepthBias()");
4292 pCB->status |= CBSTATUS_DEPTH_BIAS_SET;
4293 pCB->depthBiasConstantFactor = depthBiasConstantFactor;
4294 pCB->depthBiasClamp = depthBiasClamp;
4295 pCB->depthBiasSlopeFactor = depthBiasSlopeFactor;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004296 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004297 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004298 dev_data->device_dispatch_table->CmdSetDepthBias(commandBuffer, depthBiasConstantFactor, depthBiasClamp, depthBiasSlopeFactor);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004299}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004300
Chia-I Wu9ab61502015-11-06 06:42:02 +08004301VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4])
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004302{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004303 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004304 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4305 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004306 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004307 skipCall |= addCmd(dev_data, pCB, CMD_SETBLENDSTATE, "vkCmdSetBlendConstants()");
4308 pCB->status |= CBSTATUS_BLEND_SET;
4309 memcpy(pCB->blendConstants, blendConstants, 4 * sizeof(float));
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004310 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004311 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004312 dev_data->device_dispatch_table->CmdSetBlendConstants(commandBuffer, blendConstants);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004313}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004314
Chia-I Wu9ab61502015-11-06 06:42:02 +08004315VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBounds(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004316 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004317 float minDepthBounds,
4318 float maxDepthBounds)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004319{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004320 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004321 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4322 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004323 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004324 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBOUNDSSTATE, "vkCmdSetDepthBounds()");
4325 pCB->status |= CBSTATUS_DEPTH_BOUNDS_SET;
4326 pCB->minDepthBounds = minDepthBounds;
4327 pCB->maxDepthBounds = maxDepthBounds;
Cody Northrop82485a82015-08-18 15:21:16 -06004328 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004329 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004330 dev_data->device_dispatch_table->CmdSetDepthBounds(commandBuffer, minDepthBounds, maxDepthBounds);
Cody Northrop82485a82015-08-18 15:21:16 -06004331}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004332
Chia-I Wu9ab61502015-11-06 06:42:02 +08004333VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilCompareMask(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004334 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004335 VkStencilFaceFlags faceMask,
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004336 uint32_t compareMask)
Cody Northrop82485a82015-08-18 15:21:16 -06004337{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004338 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004339 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4340 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northrop82485a82015-08-18 15:21:16 -06004341 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004342 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREADMASKSTATE, "vkCmdSetStencilCompareMask()");
4343 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4344 pCB->front.compareMask = compareMask;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004345 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004346 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4347 pCB->back.compareMask = compareMask;
4348 }
4349 /* TODO: Do we need to track front and back separately? */
4350 /* TODO: We aren't capturing the faceMask, do we need to? */
4351 pCB->status |= CBSTATUS_STENCIL_READ_MASK_SET;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004352 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004353 if (VK_FALSE == skipCall)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004354 dev_data->device_dispatch_table->CmdSetStencilCompareMask(commandBuffer, faceMask, compareMask);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004355}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004356
Chia-I Wu9ab61502015-11-06 06:42:02 +08004357VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilWriteMask(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004358 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004359 VkStencilFaceFlags faceMask,
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004360 uint32_t writeMask)
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004361{
4362 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004363 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4364 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004365 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004366 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILWRITEMASKSTATE, "vkCmdSetStencilWriteMask()");
4367 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4368 pCB->front.writeMask = writeMask;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004369 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004370 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4371 pCB->back.writeMask = writeMask;
4372 }
4373 pCB->status |= CBSTATUS_STENCIL_WRITE_MASK_SET;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004374 }
4375 if (VK_FALSE == skipCall)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004376 dev_data->device_dispatch_table->CmdSetStencilWriteMask(commandBuffer, faceMask, writeMask);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004377}
4378
Chia-I Wu9ab61502015-11-06 06:42:02 +08004379VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilReference(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004380 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004381 VkStencilFaceFlags faceMask,
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004382 uint32_t reference)
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004383{
4384 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004385 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4386 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004387 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004388 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREFERENCESTATE, "vkCmdSetStencilReference()");
4389 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4390 pCB->front.reference = reference;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004391 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004392 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4393 pCB->back.reference = reference;
4394 }
4395 pCB->status |= CBSTATUS_STENCIL_REFERENCE_SET;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004396 }
4397 if (VK_FALSE == skipCall)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004398 dev_data->device_dispatch_table->CmdSetStencilReference(commandBuffer, faceMask, reference);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004399}
4400
Chia-I Wu9ab61502015-11-06 06:42:02 +08004401VK_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 -06004402{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004403 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004404 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4405 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004406 if (pCB) {
Tobin Ehlisf6585052015-12-17 11:48:42 -07004407 if (pCB->state == CB_RECORDING) {
4408 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004409 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 -07004410 "Incorrectly binding compute DescriptorSets during active RenderPass (%#" PRIxLEAST64 ")", (uint64_t) pCB->activeRenderPass);
4411 } else if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
4412 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdBindDescriptorSets");
Mark Lobodzinski74635932015-12-18 15:35:38 -07004413 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07004414 if (VK_FALSE == skipCall) {
4415 // Track total count of dynamic descriptor types to make sure we have an offset for each one
4416 uint32_t totalDynamicDescriptors = 0;
4417 string errorString = "";
4418 uint32_t lastSetIndex = firstSet+setCount-1;
4419 if (lastSetIndex >= pCB->boundDescriptorSets.size())
Tobin Ehlis559c6382015-11-05 09:52:49 -07004420 pCB->boundDescriptorSets.resize(lastSetIndex+1);
Tobin Ehlisf6585052015-12-17 11:48:42 -07004421 VkDescriptorSet oldFinalBoundSet = pCB->boundDescriptorSets[lastSetIndex];
4422 for (uint32_t i=0; i<setCount; i++) {
4423 SET_NODE* pSet = getSetNode(dev_data, pDescriptorSets[i]);
4424 if (pSet) {
4425 loader_platform_thread_lock_mutex(&globalLock);
4426 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
4427 pCB->lastBoundPipelineLayout = layout;
4428 pCB->boundDescriptorSets[i+firstSet] = pDescriptorSets[i];
4429 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004430 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 -07004431 "DS %#" PRIxLEAST64 " bound on pipeline %s", (uint64_t) pDescriptorSets[i], string_VkPipelineBindPoint(pipelineBindPoint));
Tobin Ehlis43c39c02016-01-11 13:18:40 -07004432 if (!pSet->pUpdateStructs && (pSet->descriptorCount != 0)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004433 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 -07004434 "DS %#" PRIxLEAST64 " bound but it was never updated. You may want to either update it or not bind it.", (uint64_t) pDescriptorSets[i]);
4435 }
4436 // Verify that set being bound is compatible with overlapping setLayout of pipelineLayout
4437 if (!verify_set_layout_compatibility(dev_data, pSet, layout, i+firstSet, errorString)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004438 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 -07004439 "descriptorSet #%u being bound is not compatible with overlapping layout in pipelineLayout due to: %s", i, errorString.c_str());
4440 }
4441 if (pSet->pLayout->dynamicDescriptorCount) {
4442 // First make sure we won't overstep bounds of pDynamicOffsets array
4443 if ((totalDynamicDescriptors + pSet->pLayout->dynamicDescriptorCount) > dynamicOffsetCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004444 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 -07004445 "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.",
4446 i, (uint64_t) pDescriptorSets[i], pSet->pLayout->dynamicDescriptorCount, (dynamicOffsetCount - totalDynamicDescriptors));
Mark Lobodzinski941aea92016-01-13 10:23:15 -07004447 } else { // Validate and store dynamic offsets with the set
4448 // Validate Dynamic Offset Minimums
4449 uint32_t cur_dyn_offset = totalDynamicDescriptors;
4450 for (uint32_t d = 0; d < pSet->descriptorCount; d++) {
4451 if (pSet->pLayout->descriptorTypes[i] == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) {
4452 if (vk_safe_modulo(pDynamicOffsets[cur_dyn_offset], dev_data->physDevPropertyMap[pCB->device].limits.minUniformBufferOffsetAlignment) != 0) {
4453 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0,
4454 __LINE__, DRAWSTATE_INVALID_UNIFORM_BUFFER_OFFSET, "DS",
4455 "vkCmdBindDescriptorSets(): pDynamicOffsets[%d] is %d but must be a multiple of device limit minUniformBufferOffsetAlignment %#" PRIxLEAST64,
4456 cur_dyn_offset, pDynamicOffsets[cur_dyn_offset], dev_data->physDevPropertyMap[pCB->device].limits.minUniformBufferOffsetAlignment);
4457 }
4458 cur_dyn_offset++;
4459 } else if (pSet->pLayout->descriptorTypes[i] == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC) {
4460 if (vk_safe_modulo(pDynamicOffsets[cur_dyn_offset], dev_data->physDevPropertyMap[pCB->device].limits.minStorageBufferOffsetAlignment) != 0) {
4461 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0,
4462 __LINE__, DRAWSTATE_INVALID_STORAGE_BUFFER_OFFSET, "DS",
4463 "vkCmdBindDescriptorSets(): pDynamicOffsets[%d] is %d but must be a multiple of device limit minStorageBufferOffsetAlignment %#" PRIxLEAST64,
4464 cur_dyn_offset, pDynamicOffsets[cur_dyn_offset], dev_data->physDevPropertyMap[pCB->device].limits.minStorageBufferOffsetAlignment);
4465 }
4466 cur_dyn_offset++;
4467 }
4468 }
4469 // Store offsets
Tobin Ehlisf6585052015-12-17 11:48:42 -07004470 const uint32_t* pStartDynOffset = pDynamicOffsets + totalDynamicDescriptors;
4471 pSet->dynamicOffsets.assign(pStartDynOffset, pStartDynOffset + pSet->pLayout->dynamicDescriptorCount);
4472 totalDynamicDescriptors += pSet->pLayout->dynamicDescriptorCount;
4473 }
4474 }
4475 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004476 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 -07004477 "Attempt to bind DS %#" PRIxLEAST64 " that doesn't exist!", (uint64_t) pDescriptorSets[i]);
4478 }
4479 }
4480 skipCall |= addCmd(dev_data, pCB, CMD_BINDDESCRIPTORSETS, "vkCmdBindDescrsiptorSets()");
4481 // For any previously bound sets, need to set them to "invalid" if they were disturbed by this update
4482 if (firstSet > 0) { // Check set #s below the first bound set
4483 for (uint32_t i=0; i<firstSet; ++i) {
4484 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 -07004485 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 -07004486 "DescriptorSetDS %#" PRIxLEAST64 " previously bound as set #%u was disturbed by newly bound pipelineLayout (%#" PRIxLEAST64 ")", (uint64_t) pCB->boundDescriptorSets[i], i, (uint64_t) layout);
4487 pCB->boundDescriptorSets[i] = VK_NULL_HANDLE;
4488 }
4489 }
4490 }
4491 // Check if newly last bound set invalidates any remaining bound sets
4492 if ((pCB->boundDescriptorSets.size()-1) > (lastSetIndex)) {
4493 if (oldFinalBoundSet && !verify_set_layout_compatibility(dev_data, dev_data->setMap[oldFinalBoundSet], layout, lastSetIndex, errorString)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004494 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 -07004495 "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);
4496 pCB->boundDescriptorSets.resize(lastSetIndex+1);
4497 }
4498 }
4499 // dynamicOffsetCount must equal the total number of dynamic descriptors in the sets being bound
4500 if (totalDynamicDescriptors != dynamicOffsetCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004501 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 -07004502 "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 -07004503 }
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07004504 validateAndIncrementDescriptorSets(dev_data, pCB);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004505 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07004506 } else {
4507 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindDescriptorSets()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004508 }
4509 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004510 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004511 dev_data->device_dispatch_table->CmdBindDescriptorSets(commandBuffer, pipelineBindPoint, layout, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004512}
4513
Chia-I Wu9ab61502015-11-06 06:42:02 +08004514VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004515{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004516 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004517 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4518 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004519 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004520 skipCall |= addCmd(dev_data, pCB, CMD_BINDINDEXBUFFER, "vkCmdBindIndexBuffer()");
4521 VkDeviceSize offset_align = 0;
4522 switch (indexType) {
4523 case VK_INDEX_TYPE_UINT16:
4524 offset_align = 2;
4525 break;
4526 case VK_INDEX_TYPE_UINT32:
4527 offset_align = 4;
4528 break;
4529 default:
4530 // ParamChecker should catch bad enum, we'll also throw alignment error below if offset_align stays 0
4531 break;
4532 }
4533 if (!offset_align || (offset % offset_align)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004534 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 -07004535 "vkCmdBindIndexBuffer() offset (%#" PRIxLEAST64 ") does not fall on alignment (%s) boundary.", offset, string_VkIndexType(indexType));
Tobin Ehlis9c536442015-06-19 13:00:59 -06004536 }
Tobin Ehlisc4c23182015-09-17 12:24:13 -06004537 pCB->status |= CBSTATUS_INDEX_BUFFER_BOUND;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004538 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004539 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004540 dev_data->device_dispatch_table->CmdBindIndexBuffer(commandBuffer, buffer, offset, indexType);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004541}
4542
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07004543void updateResourceTracking(GLOBAL_CB_NODE* pCB, uint32_t firstBinding, uint32_t bindingCount, const VkBuffer* pBuffers) {
4544 uint32_t end = firstBinding + bindingCount;
Michael Lentine700b0aa2015-10-30 17:57:32 -07004545 if (pCB->currentDrawData.buffers.size() < end) {
4546 pCB->currentDrawData.buffers.resize(end);
4547 }
4548 for (uint32_t i = 0; i < bindingCount; ++i) {
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07004549 pCB->currentDrawData.buffers[i + firstBinding] = pBuffers[i];
Michael Lentine700b0aa2015-10-30 17:57:32 -07004550 }
4551}
4552
4553void updateResourceTrackingOnDraw(GLOBAL_CB_NODE* pCB) {
4554 pCB->drawData.push_back(pCB->currentDrawData);
4555}
4556
Chia-I Wu9ab61502015-11-06 06:42:02 +08004557VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindVertexBuffers(
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07004558 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004559 uint32_t firstBinding,
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06004560 uint32_t bindingCount,
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07004561 const VkBuffer *pBuffers,
4562 const VkDeviceSize *pOffsets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004563{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004564 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004565 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4566 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004567 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004568 addCmd(dev_data, pCB, CMD_BINDVERTEXBUFFER, "vkCmdBindVertexBuffer()");
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07004569 updateResourceTracking(pCB, firstBinding, bindingCount, pBuffers);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004570 } else {
Mark Youngad779052016-01-06 14:26:04 -07004571 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindVertexBuffer()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004572 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004573 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004574 dev_data->device_dispatch_table->CmdBindVertexBuffers(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004575}
4576
Chia-I Wu9ab61502015-11-06 06:42:02 +08004577VK_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 -06004578{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004579 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004580 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4581 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004582 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004583 skipCall |= addCmd(dev_data, pCB, CMD_DRAW, "vkCmdDraw()");
4584 pCB->drawCount[DRAW]++;
4585 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
4586 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004587 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 -07004588 "vkCmdDraw() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW]++);
4589 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004590 if (VK_FALSE == skipCall) {
4591 updateResourceTrackingOnDraw(pCB);
4592 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004593 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDraw");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004594 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004595 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004596 dev_data->device_dispatch_table->CmdDraw(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004597}
4598
Chia-I Wu9ab61502015-11-06 06:42:02 +08004599VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL 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 -06004600{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004601 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4602 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004603 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004604 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004605 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXED, "vkCmdDrawIndexed()");
4606 pCB->drawCount[DRAW_INDEXED]++;
4607 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
4608 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004609 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 -07004610 "vkCmdDrawIndexed() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED]++);
4611 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004612 if (VK_FALSE == skipCall) {
4613 updateResourceTrackingOnDraw(pCB);
4614 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004615 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexed");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004616 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004617 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004618 dev_data->device_dispatch_table->CmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004619}
4620
Chia-I Wu9ab61502015-11-06 06:42:02 +08004621VK_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 -06004622{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004623 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4624 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004625 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004626 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004627 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDIRECT, "vkCmdDrawIndirect()");
4628 pCB->drawCount[DRAW_INDIRECT]++;
4629 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
4630 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004631 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 -07004632 "vkCmdDrawIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
4633 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004634 if (VK_FALSE == skipCall) {
4635 updateResourceTrackingOnDraw(pCB);
4636 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004637 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndirect");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004638 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004639 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004640 dev_data->device_dispatch_table->CmdDrawIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004641}
4642
Chia-I Wu9ab61502015-11-06 06:42:02 +08004643VK_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 -06004644{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004645 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004646 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4647 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004648 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004649 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXEDINDIRECT, "vkCmdDrawIndexedIndirect()");
4650 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
4651 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
4652 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004653 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 -07004654 "vkCmdDrawIndexedIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
4655 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004656 if (VK_FALSE == skipCall) {
4657 updateResourceTrackingOnDraw(pCB);
4658 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004659 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexedIndirect");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004660 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004661 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004662 dev_data->device_dispatch_table->CmdDrawIndexedIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004663}
4664
Chia-I Wu9ab61502015-11-06 06:42:02 +08004665VK_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 -06004666{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004667 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004668 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4669 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004670 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004671 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCH, "vkCmdDispatch()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004672 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatch");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004673 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004674 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004675 dev_data->device_dispatch_table->CmdDispatch(commandBuffer, x, y, z);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004676}
4677
Chia-I Wu9ab61502015-11-06 06:42:02 +08004678VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004679{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004680 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004681 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4682 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004683 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004684 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCHINDIRECT, "vkCmdDispatchIndirect()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004685 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatchIndirect");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004686 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004687 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004688 dev_data->device_dispatch_table->CmdDispatchIndirect(commandBuffer, buffer, offset);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004689}
4690
Chia-I Wu9ab61502015-11-06 06:42:02 +08004691VK_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 -06004692{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004693 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004694 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4695 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004696 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004697 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFER, "vkCmdCopyBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004698 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004699 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004700 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004701 dev_data->device_dispatch_table->CmdCopyBuffer(commandBuffer, srcBuffer, dstBuffer, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004702}
4703
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07004704VkBool32 VerifySourceImageLayout(VkCommandBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout) {
Mark Youngb20a6a82016-01-07 15:41:43 -07004705 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07004706
4707#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4708 // TODO: Fix -- initialLayout may have been set in a previous command buffer
4709 return skip_call;
4710#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4711
Michael Lentineabc5e922015-10-12 11:30:14 -05004712 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4713 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4714 auto src_image_element = pCB->imageLayoutMap.find(srcImage);
4715 if (src_image_element == pCB->imageLayoutMap.end()) {
4716 pCB->imageLayoutMap[srcImage].initialLayout = srcImageLayout;
4717 pCB->imageLayoutMap[srcImage].layout = srcImageLayout;
Mark Youngb20a6a82016-01-07 15:41:43 -07004718 return VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05004719 }
4720 if (src_image_element->second.layout != srcImageLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004721 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 -05004722 "Cannot copy from an image whose source layout is %d and doesn't match the current layout %d.", srcImageLayout, src_image_element->second.layout);
4723 }
4724 if (srcImageLayout != VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL) {
4725 if (srcImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004726 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004727 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 -05004728 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Michael Lentineabc5e922015-10-12 11:30:14 -05004729 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004730 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 -05004731 "Layout for input image is %d but can only be TRANSFER_SRC_OPTIMAL or GENERAL.", srcImageLayout);
Michael Lentineabc5e922015-10-12 11:30:14 -05004732 }
4733 }
4734 return skip_call;
4735}
4736
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07004737VkBool32 VerifyDestImageLayout(VkCommandBuffer cmdBuffer, VkImage destImage, VkImageLayout destImageLayout) {
Mark Youngb20a6a82016-01-07 15:41:43 -07004738 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07004739
4740#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4741 // TODO: Fix -- initialLayout may have been set in a previous command buffer
4742 return skip_call;
4743#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4744
Michael Lentineabc5e922015-10-12 11:30:14 -05004745 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4746 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4747 auto dest_image_element = pCB->imageLayoutMap.find(destImage);
4748 if (dest_image_element == pCB->imageLayoutMap.end()) {
4749 pCB->imageLayoutMap[destImage].initialLayout = destImageLayout;
4750 pCB->imageLayoutMap[destImage].layout = destImageLayout;
Mark Youngb20a6a82016-01-07 15:41:43 -07004751 return VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05004752 }
4753 if (dest_image_element->second.layout != destImageLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004754 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 -05004755 "Cannot copy from an image whose dest layout is %d and doesn't match the current layout %d.", destImageLayout, dest_image_element->second.layout);
4756 }
4757 if (destImageLayout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) {
4758 if (destImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004759 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004760 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 -05004761 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
4762 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004763 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 -05004764 "Layout for output image is %d but can only be TRANSFER_DST_OPTIMAL or GENERAL.", destImageLayout);
4765 }
4766 }
4767 return skip_call;
4768}
4769
Chia-I Wu9ab61502015-11-06 06:42:02 +08004770VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004771 VkImage srcImage,
4772 VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004773 VkImage dstImage,
4774 VkImageLayout dstImageLayout,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004775 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004776{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004777 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004778 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4779 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004780 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004781 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGE, "vkCmdCopyImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004782 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImage");
Michael Lentineabc5e922015-10-12 11:30:14 -05004783 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
4784 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004785 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004786 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004787 dev_data->device_dispatch_table->CmdCopyImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004788}
4789
Chia-I Wu9ab61502015-11-06 06:42:02 +08004790VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBlitImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004791 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004792 VkImage dstImage, VkImageLayout dstImageLayout,
Mark Lobodzinskiee5eef12015-05-22 14:43:25 -05004793 uint32_t regionCount, const VkImageBlit* pRegions,
Chia-I Wub99df442015-10-26 16:49:32 +08004794 VkFilter filter)
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004795{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004796 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004797 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4798 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004799 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004800 skipCall |= addCmd(dev_data, pCB, CMD_BLITIMAGE, "vkCmdBlitImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004801 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBlitImage");
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004802 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004803 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004804 dev_data->device_dispatch_table->CmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter);
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004805}
4806
Chia-I Wu9ab61502015-11-06 06:42:02 +08004807VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004808 VkBuffer srcBuffer,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004809 VkImage dstImage, VkImageLayout dstImageLayout,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004810 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004811{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004812 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004813 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4814 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004815 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004816 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFERTOIMAGE, "vkCmdCopyBufferToImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004817 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBufferToImage");
Michael Lentineabc5e922015-10-12 11:30:14 -05004818 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004819 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004820 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004821 dev_data->device_dispatch_table->CmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004822}
4823
Chia-I Wu9ab61502015-11-06 06:42:02 +08004824VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004825 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004826 VkBuffer dstBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004827 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004828{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004829 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004830 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4831 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004832 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004833 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGETOBUFFER, "vkCmdCopyImageToBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004834 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImageToBuffer");
Michael Lentineabc5e922015-10-12 11:30:14 -05004835 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004836 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004837 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004838 dev_data->device_dispatch_table->CmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004839}
4840
Chia-I Wu9ab61502015-11-06 06:42:02 +08004841VK_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 -06004842{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004843 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004844 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4845 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004846 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004847 skipCall |= addCmd(dev_data, pCB, CMD_UPDATEBUFFER, "vkCmdUpdateBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004848 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyUpdateBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004849 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004850 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004851 dev_data->device_dispatch_table->CmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004852}
4853
Chia-I Wu9ab61502015-11-06 06:42:02 +08004854VK_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 -06004855{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004856 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004857 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4858 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004859 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004860 skipCall |= addCmd(dev_data, pCB, CMD_FILLBUFFER, "vkCmdFillBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004861 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyFillBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004862 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004863 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004864 dev_data->device_dispatch_table->CmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004865}
4866
Chia-I Wu9ab61502015-11-06 06:42:02 +08004867VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearAttachments(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004868 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004869 uint32_t attachmentCount,
4870 const VkClearAttachment* pAttachments,
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004871 uint32_t rectCount,
Courtney Goeltzenleuchter4ca43f62015-10-15 18:22:08 -06004872 const VkClearRect* pRects)
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004873{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004874 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004875 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4876 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004877 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004878 skipCall |= addCmd(dev_data, pCB, CMD_CLEARATTACHMENTS, "vkCmdClearAttachments()");
4879 // Warn if this is issued prior to Draw Cmd and clearing the entire attachment
4880 if (!hasDrawCmd(pCB) &&
4881 (pCB->activeRenderPassBeginInfo.renderArea.extent.width == pRects[0].rect.extent.width) &&
4882 (pCB->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) {
4883 // TODO : commandBuffer should be srcObj
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004884 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 -07004885 "vkCmdClearAttachments() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
4886 " 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 -06004887 }
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004888 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdClearAttachments");
4889 }
4890
4891 // Validate that attachment is in reference list of active subpass
4892 if (pCB->activeRenderPass) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07004893 const VkRenderPassCreateInfo *pRPCI = dev_data->renderPassMap[pCB->activeRenderPass]->pCreateInfo;
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004894 const VkSubpassDescription *pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
4895
4896 for (uint32_t attachment_idx = 0; attachment_idx < attachmentCount; attachment_idx++) {
4897 const VkClearAttachment *attachment = &pAttachments[attachment_idx];
4898 if (attachment->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) {
4899 VkBool32 found = VK_FALSE;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004900 for (uint32_t i = 0; i < pSD->colorAttachmentCount; i++) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004901 if (attachment->colorAttachment == pSD->pColorAttachments[i].attachment) {
4902 found = VK_TRUE;
4903 break;
4904 }
4905 }
4906 if (VK_FALSE == found) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004907 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 -07004908 (uint64_t)commandBuffer, __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004909 "vkCmdClearAttachments() attachment index %d not found in attachment reference array of active subpass %d",
4910 attachment->colorAttachment, pCB->activeSubpass);
4911 }
4912 } else if (attachment->aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) {
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07004913 if (!pSD->pDepthStencilAttachment || // Says no DS will be used in active subpass
Mark Lobodzinski2fd355a2015-11-18 08:58:31 -07004914 (pSD->pDepthStencilAttachment->attachment == VK_ATTACHMENT_UNUSED)) { // Says no DS will be used in active subpass
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07004915
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004916 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 -07004917 (uint64_t)commandBuffer, __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07004918 "vkCmdClearAttachments() attachment index %d does not match depthStencilAttachment.attachment (%d) found in active subpass %d",
4919 attachment->colorAttachment,
4920 (pSD->pDepthStencilAttachment) ? pSD->pDepthStencilAttachment->attachment : VK_ATTACHMENT_UNUSED,
4921 pCB->activeSubpass);
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004922 }
4923 }
4924 }
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004925 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004926 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004927 dev_data->device_dispatch_table->CmdClearAttachments(commandBuffer, attachmentCount, pAttachments, rectCount, pRects);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004928}
4929
Chia-I Wu9ab61502015-11-06 06:42:02 +08004930VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearColorImage(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004931 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06004932 VkImage image, VkImageLayout imageLayout,
Chris Forbesf0796e12015-06-24 14:34:53 +12004933 const VkClearColorValue *pColor,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06004934 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004935{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004936 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004937 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4938 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004939 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004940 skipCall |= addCmd(dev_data, pCB, CMD_CLEARCOLORIMAGE, "vkCmdClearColorImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004941 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearColorImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004942 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004943 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004944 dev_data->device_dispatch_table->CmdClearColorImage(commandBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004945}
4946
Chia-I Wu9ab61502015-11-06 06:42:02 +08004947VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearDepthStencilImage(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004948 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter45df9e12015-09-15 18:03:22 -06004949 VkImage image, VkImageLayout imageLayout,
4950 const VkClearDepthStencilValue *pDepthStencil,
4951 uint32_t rangeCount,
4952 const VkImageSubresourceRange* pRanges)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004953{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004954 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004955 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4956 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004957 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004958 skipCall |= addCmd(dev_data, pCB, CMD_CLEARDEPTHSTENCILIMAGE, "vkCmdClearDepthStencilImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004959 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearDepthStencilImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004960 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004961 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004962 dev_data->device_dispatch_table->CmdClearDepthStencilImage(commandBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004963}
4964
Chia-I Wu9ab61502015-11-06 06:42:02 +08004965VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResolveImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004966 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004967 VkImage dstImage, VkImageLayout dstImageLayout,
Tony Barbour6865d4a2015-04-13 15:02:52 -06004968 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004969{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004970 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004971 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4972 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004973 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004974 skipCall |= addCmd(dev_data, pCB, CMD_RESOLVEIMAGE, "vkCmdResolveImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004975 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResolveImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004976 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004977 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004978 dev_data->device_dispatch_table->CmdResolveImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004979}
4980
Chia-I Wu9ab61502015-11-06 06:42:02 +08004981VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004982{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004983 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004984 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4985 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004986 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004987 skipCall |= addCmd(dev_data, pCB, CMD_SETEVENT, "vkCmdSetEvent()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004988 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdSetEvent");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004989 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004990 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004991 dev_data->device_dispatch_table->CmdSetEvent(commandBuffer, event, stageMask);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004992}
4993
Chia-I Wu9ab61502015-11-06 06:42:02 +08004994VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004995{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004996 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004997 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4998 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004999 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005000 skipCall |= addCmd(dev_data, pCB, CMD_RESETEVENT, "vkCmdResetEvent()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005001 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResetEvent");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005002 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005003 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005004 dev_data->device_dispatch_table->CmdResetEvent(commandBuffer, event, stageMask);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005005}
5006
Jon Ashburnf19916e2016-01-11 13:12:43 -07005007VkBool32 TransitionImageLayouts(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const VkImageMemoryBarrier* pImgMemBarriers) {
Michael Lentineabc5e922015-10-12 11:30:14 -05005008 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5009 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Mark Youngb20a6a82016-01-07 15:41:43 -07005010 VkBool32 skip = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005011
5012#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
5013 // TODO: Fix -- pay attention to image subresource ranges -- not all subresources transition at the same time
5014 return skip;
5015#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5016
Michael Lentineabc5e922015-10-12 11:30:14 -05005017 for (uint32_t i = 0; i < memBarrierCount; ++i) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005018 auto mem_barrier = &pImgMemBarriers[i];
Michael Lentineabc5e922015-10-12 11:30:14 -05005019 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005020 auto image_data = pCB->imageLayoutMap.find(mem_barrier->image);
Michael Lentineabc5e922015-10-12 11:30:14 -05005021 if (image_data == pCB->imageLayoutMap.end()) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005022 pCB->imageLayoutMap[mem_barrier->image].initialLayout = mem_barrier->oldLayout;
5023 pCB->imageLayoutMap[mem_barrier->image].layout = mem_barrier->newLayout;
Michael Lentineabc5e922015-10-12 11:30:14 -05005024 } else {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005025 if (image_data->second.layout != mem_barrier->oldLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005026 skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Jon Ashburnf19916e2016-01-11 13:12:43 -07005027 "You cannot transition the layout from %d when current layout is %d.", mem_barrier->oldLayout, image_data->second.layout);
Michael Lentineabc5e922015-10-12 11:30:14 -05005028 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07005029 image_data->second.layout = mem_barrier->newLayout;
Michael Lentineabc5e922015-10-12 11:30:14 -05005030 }
5031 }
5032 }
5033 return skip;
5034}
5035
Mark Lobodzinskia3a86112016-01-05 17:17:55 -07005036// Print readable FlagBits in FlagMask
5037std::string string_VkAccessFlags(VkAccessFlags accessMask)
5038{
5039 std::string result;
5040 std::string separator;
5041
5042 if (accessMask == 0) {
5043 result = "[None]";
5044 } else {
5045 result = "[";
5046 for (auto i = 0; i < 32; i++) {
5047 if (accessMask & (1 << i)) {
5048 result = result + separator + string_VkAccessFlagBits((VkAccessFlagBits)(1 << i));
5049 separator = " | ";
5050 }
5051 }
5052 result = result + "]";
5053 }
5054 return result;
5055}
5056
Michael Lentine97eb7462015-11-20 09:48:52 -08005057// AccessFlags MUST have 'required_bit' set, and may have one or more of 'optional_bits' set.
5058// If required_bit is zero, accessMask must have at least one of 'optional_bits' set
Mark Lobodzinskifd740fc2016-01-06 12:56:29 -07005059// TODO: Add tracking to ensure that at least one barrier has been set for these layout transitions
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005060VkBool32 ValidateMaskBits(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout,
5061 VkAccessFlags required_bit, VkAccessFlags optional_bits, const char* type) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005062 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005063
Michael Lentine97eb7462015-11-20 09:48:52 -08005064 if ((accessMask & required_bit) || (!required_bit && (accessMask & optional_bits))) {
5065 if (accessMask & !(required_bit | optional_bits)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005066 // TODO: Verify against Valid Use
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005067 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 -07005068 "Additional bits in %s accessMask %d %s are specified when layout is %s.",
5069 type, accessMask, string_VkAccessFlags(accessMask).c_str(), string_VkImageLayout(layout));
Michael Lentineecc32b72015-10-16 18:08:09 -05005070 }
5071 } else {
Michael Lentine97eb7462015-11-20 09:48:52 -08005072 if (!required_bit) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005073 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 -07005074 "%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 -07005075 type, accessMask, string_VkAccessFlags(accessMask).c_str(), optional_bits,
5076 string_VkAccessFlags(optional_bits).c_str(), string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08005077 } else {
Mark Lobodzinskif2cc2a52016-01-05 13:35:29 -07005078 std::string opt_bits;
5079 if (optional_bits != 0) {
5080 opt_bits = "and may have optional bits " + std::to_string(optional_bits) + ' ' + string_VkAccessFlags(optional_bits);
5081 }
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005082 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 -07005083 "%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 -07005084 type, accessMask, string_VkAccessFlags(accessMask).c_str(),
5085 required_bit, string_VkAccessFlags(required_bit).c_str(),
Mark Lobodzinskif2cc2a52016-01-05 13:35:29 -07005086 opt_bits.c_str(), string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08005087 }
Michael Lentineecc32b72015-10-16 18:08:09 -05005088 }
5089 return skip_call;
5090}
5091
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005092VkBool32 ValidateMaskBitsFromLayouts(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout, const char* type) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005093 VkBool32 skip_call = VK_FALSE;
Michael Lentine97eb7462015-11-20 09:48:52 -08005094 switch (layout) {
5095 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005096 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 -08005097 break;
Michael Lentineecc32b72015-10-16 18:08:09 -05005098 }
Michael Lentine97eb7462015-11-20 09:48:52 -08005099 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005100 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 -08005101 break;
Michael Lentineecc32b72015-10-16 18:08:09 -05005102 }
Michael Lentine97eb7462015-11-20 09:48:52 -08005103 case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005104 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_WRITE_BIT, 0, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08005105 break;
5106 }
5107 case VK_IMAGE_LAYOUT_PREINITIALIZED: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005108 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_HOST_WRITE_BIT, 0, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08005109 break;
5110 }
5111 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005112 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 -08005113 break;
5114 }
5115 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005116 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 -08005117 break;
5118 }
5119 case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005120 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_READ_BIT, 0, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08005121 break;
5122 }
5123 case VK_IMAGE_LAYOUT_UNDEFINED: {
5124 if (accessMask != 0) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005125 // TODO: Verify against Valid Use section spec
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005126 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 -07005127 "Additional bits in %s accessMask %d %s are specified when layout is %s.", type, accessMask, string_VkAccessFlags(accessMask).c_str(),
5128 string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08005129 }
5130 break;
5131 }
5132 case VK_IMAGE_LAYOUT_GENERAL:
5133 default: {
5134 break;
5135 }
Michael Lentineecc32b72015-10-16 18:08:09 -05005136 }
5137 return skip_call;
5138}
5139
Jon Ashburnf19916e2016-01-11 13:12:43 -07005140VkBool32 ValidateBarriers(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const VkMemoryBarrier* pMemBarriers, uint32_t imageMemBarrierCount, const VkImageMemoryBarrier *pImageMemBarriers)
5141{
Mark Youngb20a6a82016-01-07 15:41:43 -07005142 VkBool32 skip_call = VK_FALSE;
Michael Lentine48930b82015-10-15 17:07:00 -05005143 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5144 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5145 if (pCB->activeRenderPass && memBarrierCount) {
5146 for (uint32_t i = 0; i < memBarrierCount; ++i) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005147 auto mem_barrier = &pMemBarriers[i];
Michael Lentine48930b82015-10-15 17:07:00 -05005148 if (mem_barrier && mem_barrier->sType != VK_STRUCTURE_TYPE_MEMORY_BARRIER) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005149 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 -05005150 "Image or Buffers Barriers cannot be used during a render pass.");
5151 }
5152 }
5153 if (!dev_data->renderPassMap[pCB->activeRenderPass]->hasSelfDependency[pCB->activeSubpass]) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005154 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 -05005155 "Barriers cannot be set during subpass %d with no self dependency specified.", pCB->activeSubpass);
5156 }
5157 }
Mark Lobodzinski73a37ec2015-11-20 09:27:27 -07005158
Jon Ashburnf19916e2016-01-11 13:12:43 -07005159 for (uint32_t i = 0; i < imageMemBarrierCount; ++i) {
5160 auto mem_barrier = &pImageMemBarriers[i];
Michael Lentineecc32b72015-10-16 18:08:09 -05005161 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005162 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, mem_barrier->srcAccessMask, mem_barrier->oldLayout, "Source");
5163 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, mem_barrier->dstAccessMask, mem_barrier->newLayout, "Dest");
Michael Lentineecc32b72015-10-16 18:08:09 -05005164 }
5165 }
Mark Lobodzinski3cba24a2015-12-03 15:42:32 -07005166
Michael Lentine48930b82015-10-15 17:07:00 -05005167 return skip_call;
5168}
5169
Jon Ashburnf19916e2016-01-11 13:12:43 -07005170VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdWaitEvents(
5171 VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent* pEvents,
5172 VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask,
5173 uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers,
5174 uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers,
5175 uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005176{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005177 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005178 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5179 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005180 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005181 for (uint32_t i = 0; i < eventCount; ++i) {
5182 pCB->waitedEvents.push_back(pEvents[i]);
5183 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005184 if (pCB->state == CB_RECORDING) {
5185 skipCall |= addCmd(dev_data, pCB, CMD_WAITEVENTS, "vkCmdWaitEvents()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005186 } else {
5187 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdWaitEvents()");
5188 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07005189 skipCall |= TransitionImageLayouts(commandBuffer, imageMemoryBarrierCount, pImageMemoryBarriers);
5190 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, pMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005191 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005192 if (VK_FALSE == skipCall)
Jon Ashburnf19916e2016-01-11 13:12:43 -07005193 dev_data->device_dispatch_table->CmdWaitEvents(commandBuffer, eventCount, pEvents, sourceStageMask, dstStageMask,
5194 memoryBarrierCount, pMemoryBarriers,
5195 bufferMemoryBarrierCount, pBufferMemoryBarriers,
5196 imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005197}
5198
Jon Ashburnf19916e2016-01-11 13:12:43 -07005199VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdPipelineBarrier(
5200 VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask,
5201 VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags,
5202 uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers,
5203 uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers,
5204 uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005205{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005206 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005207 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5208 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005209 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005210 skipCall |= addCmd(dev_data, pCB, CMD_PIPELINEBARRIER, "vkCmdPipelineBarrier()");
Jon Ashburnf19916e2016-01-11 13:12:43 -07005211 skipCall |= TransitionImageLayouts(commandBuffer, imageMemoryBarrierCount, pImageMemoryBarriers);
5212 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, pMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005213 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005214 if (VK_FALSE == skipCall)
Jon Ashburnf19916e2016-01-11 13:12:43 -07005215 dev_data->device_dispatch_table->CmdPipelineBarrier(commandBuffer, srcStageMask, dstStageMask, dependencyFlags,
5216 memoryBarrierCount, pMemoryBarriers,
5217 bufferMemoryBarrierCount, pBufferMemoryBarriers,
5218 imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005219}
5220
Chia-I Wu9ab61502015-11-06 06:42:02 +08005221VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005222{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005223 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005224 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5225 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005226 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005227 skipCall |= addCmd(dev_data, pCB, CMD_BEGINQUERY, "vkCmdBeginQuery()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005228 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005229 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005230 dev_data->device_dispatch_table->CmdBeginQuery(commandBuffer, queryPool, slot, flags);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005231}
5232
Chia-I Wu9ab61502015-11-06 06:42:02 +08005233VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005234{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005235 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005236 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5237 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005238 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005239 QueryObject query = {queryPool, slot};
5240 pCB->queryToStateMap[query] = 1;
Mark Lobodzinskice738852016-01-07 10:04:02 -07005241 if (pCB->state == CB_RECORDING) {
5242 skipCall |= addCmd(dev_data, pCB, CMD_ENDQUERY, "VkCmdEndQuery()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005243 } else {
5244 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdEndQuery()");
5245 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005246 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005247 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005248 dev_data->device_dispatch_table->CmdEndQuery(commandBuffer, queryPool, slot);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005249}
5250
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005251VK_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 -06005252{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005253 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005254 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5255 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005256 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005257 for (uint32_t i = 0; i < queryCount; i++) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005258 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06005259 pCB->waitedEventsBeforeQueryReset[query] = pCB->waitedEvents;
5260 pCB->queryToStateMap[query] = 0;
5261 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005262 if (pCB->state == CB_RECORDING) {
5263 skipCall |= addCmd(dev_data, pCB, CMD_RESETQUERYPOOL, "VkCmdResetQueryPool()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005264 } else {
5265 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdResetQueryPool()");
5266 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005267 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdQueryPool");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005268 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005269 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005270 dev_data->device_dispatch_table->CmdResetQueryPool(commandBuffer, queryPool, firstQuery, queryCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005271}
5272
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005273VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005274 uint32_t queryCount, VkBuffer dstBuffer, VkDeviceSize dstOffset,
Chia-I Wuccc93a72015-10-26 18:36:20 +08005275 VkDeviceSize stride, VkQueryResultFlags flags)
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005276{
5277 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005278 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5279 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005280 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005281 for (uint32_t i = 0; i < queryCount; i++) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005282 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06005283 if(!pCB->queryToStateMap[query]) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005284 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_QUERY, "DS",
5285 "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 -06005286 }
5287 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005288 if (pCB->state == CB_RECORDING) {
5289 skipCall |= addCmd(dev_data, pCB, CMD_COPYQUERYPOOLRESULTS, "vkCmdCopyQueryPoolResults()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005290 } else {
5291 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdCopyQueryPoolResults()");
5292 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005293 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyQueryPoolResults");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005294 }
5295 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005296 dev_data->device_dispatch_table->CmdCopyQueryPoolResults(commandBuffer, queryPool,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005297 firstQuery, queryCount, dstBuffer, dstOffset, stride, flags);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005298}
5299
Chia-I Wu9ab61502015-11-06 06:42:02 +08005300VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005301{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005302 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005303 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5304 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005305 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005306 QueryObject query = {queryPool, slot};
5307 pCB->queryToStateMap[query] = 1;
Mark Lobodzinskice738852016-01-07 10:04:02 -07005308 if (pCB->state == CB_RECORDING) {
5309 skipCall |= addCmd(dev_data, pCB, CMD_WRITETIMESTAMP, "vkCmdWriteTimestamp()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005310 } else {
5311 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdWriteTimestamp()");
5312 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005313 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005314 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005315 dev_data->device_dispatch_table->CmdWriteTimestamp(commandBuffer, pipelineStage, queryPool, slot);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005316}
5317
Chia-I Wu9ab61502015-11-06 06:42:02 +08005318VK_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 -06005319{
Tobin Ehlis0b632332015-10-07 09:38:40 -06005320 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005321 VkResult result = dev_data->device_dispatch_table->CreateFramebuffer(device, pCreateInfo, pAllocator, pFramebuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005322 if (VK_SUCCESS == result) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06005323 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06005324 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +08005325 if (pCreateInfo->pAttachments) {
Courtney Goeltzenleuchter5861a1b2015-09-01 17:30:39 -06005326 localFBCI->pAttachments = new VkImageView[localFBCI->attachmentCount];
5327 memcpy((void*)localFBCI->pAttachments, pCreateInfo->pAttachments, localFBCI->attachmentCount*sizeof(VkImageView));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005328 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08005329 dev_data->frameBufferMap[*pFramebuffer] = localFBCI;
Tobin Ehliseba312c2015-04-01 08:40:34 -06005330 }
5331 return result;
5332}
5333
Michael Lentineb6986752015-10-06 14:56:18 -07005334// Store the DAG.
5335struct DAGNode {
5336 uint32_t pass;
5337 std::vector<uint32_t> prev;
5338 std::vector<uint32_t> next;
5339};
5340
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005341VkBool32 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 -07005342 // If we have already checked this node we have not found a dependency path so return false.
5343 if (processed_nodes.count(index))
Mark Youngb20a6a82016-01-07 15:41:43 -07005344 return VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005345 processed_nodes.insert(index);
5346 const DAGNode& node = subpass_to_node[index];
5347 // Look for a dependency path. If one exists return true else recurse on the previous nodes.
5348 if (std::find(node.prev.begin(), node.prev.end(), dependent) == node.prev.end()) {
5349 for (auto elem : node.prev) {
5350 if (FindDependency(elem, dependent, subpass_to_node, processed_nodes))
Mark Youngb20a6a82016-01-07 15:41:43 -07005351 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005352 }
5353 } else {
Mark Youngb20a6a82016-01-07 15:41:43 -07005354 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005355 }
Mark Youngb20a6a82016-01-07 15:41:43 -07005356 return VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005357}
5358
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005359VkBool32 CheckDependencyExists(const layer_data* my_data, VkDevice device, const int subpass, const std::vector<uint32_t>& dependent_subpasses, const std::vector<DAGNode>& subpass_to_node, VkBool32& skip_call) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005360 VkBool32 result = VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005361 // Loop through all subpasses that share the same attachment and make sure a dependency exists
5362 for (uint32_t k = 0; k < dependent_subpasses.size(); ++k) {
5363 if (subpass == dependent_subpasses[k])
5364 continue;
5365 const DAGNode& node = subpass_to_node[subpass];
5366 // Check for a specified dependency between the two nodes. If one exists we are done.
5367 auto prev_elem = std::find(node.prev.begin(), node.prev.end(), dependent_subpasses[k]);
5368 auto next_elem = std::find(node.next.begin(), node.next.end(), dependent_subpasses[k]);
5369 if (prev_elem == node.prev.end() && next_elem == node.next.end()) {
5370 // If no dependency exits an implicit dependency still might. If so, warn and if not throw an error.
5371 std::unordered_set<uint32_t> processed_nodes;
5372 if (FindDependency(subpass, dependent_subpasses[k], subpass_to_node, processed_nodes) ||
5373 FindDependency(dependent_subpasses[k], subpass, subpass_to_node, processed_nodes)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005374 // TODO: Verify against Valid Use section of spec
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005375 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 -07005376 "A dependency between subpasses %d and %d must exist but only an implicit one is specified.",
5377 subpass, dependent_subpasses[k]);
5378 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005379 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 -07005380 "A dependency between subpasses %d and %d must exist but one is not specified.",
5381 subpass, dependent_subpasses[k]);
Mark Youngb20a6a82016-01-07 15:41:43 -07005382 result = VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005383 }
5384 }
5385 }
5386 return result;
5387}
5388
Jon Ashburnf19916e2016-01-11 13:12:43 -07005389VkBool32 CheckPreserved(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, const int index, const uint32_t attachment, const std::vector<DAGNode>& subpass_to_node, int depth, VkBool32& skip_call) {
Michael Lentineb6986752015-10-06 14:56:18 -07005390 const DAGNode& node = subpass_to_node[index];
5391 // If this node writes to the attachment return true as next nodes need to preserve the attachment.
5392 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005393 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005394 if (attachment == subpass.pColorAttachments[j].attachment)
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005395 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005396 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005397 if (subpass.pDepthStencilAttachment &&
5398 subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
5399 if (attachment == subpass.pDepthStencilAttachment->attachment)
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005400 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005401 }
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005402 VkBool32 result = VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005403 // Loop through previous nodes and see if any of them write to the attachment.
5404 for (auto elem : node.prev) {
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005405 result |= CheckPreserved(my_data, device, pCreateInfo, elem, attachment, subpass_to_node, depth + 1, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005406 }
5407 // If the attachment was written to by a previous node than this node needs to preserve it.
5408 if (result && depth > 0) {
5409 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Mark Youngb20a6a82016-01-07 15:41:43 -07005410 VkBool32 has_preserved = VK_FALSE;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005411 for (uint32_t j = 0; j < subpass.preserveAttachmentCount; ++j) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005412 if (subpass.pPreserveAttachments[j] == attachment) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005413 has_preserved = VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005414 break;
5415 }
5416 }
Mark Youngb20a6a82016-01-07 15:41:43 -07005417 if (has_preserved == VK_FALSE) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005418 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 -07005419 "Attachment %d is used by a later subpass and must be preserved in subpass %d.", attachment, index);
5420 }
5421 }
5422 return result;
5423}
5424
Michael Lentineb4979492015-12-22 11:36:14 -06005425VkBool32 ValidateDependencies(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, const std::vector<DAGNode>& subpass_to_node) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005426 VkBool32 skip_call = VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005427 std::vector<std::vector<uint32_t>> output_attachment_to_subpass(pCreateInfo->attachmentCount);
5428 std::vector<std::vector<uint32_t>> input_attachment_to_subpass(pCreateInfo->attachmentCount);
Michael Lentineb6986752015-10-06 14:56:18 -07005429 // Find for each attachment the subpasses that use them.
5430 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5431 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005432 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005433 input_attachment_to_subpass[subpass.pInputAttachments[j].attachment].push_back(i);
5434 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08005435 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005436 output_attachment_to_subpass[subpass.pColorAttachments[j].attachment].push_back(i);
5437 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005438 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
5439 output_attachment_to_subpass[subpass.pDepthStencilAttachment->attachment].push_back(i);
Michael Lentineb6986752015-10-06 14:56:18 -07005440 }
5441 }
5442 // If there is a dependency needed make sure one exists
5443 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5444 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
5445 // If the attachment is an input then all subpasses that output must have a dependency relationship
Chia-I Wud50a7d72015-10-26 20:48:51 +08005446 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005447 const uint32_t& attachment = subpass.pInputAttachments[j].attachment;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005448 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005449 }
5450 // 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 +08005451 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005452 const uint32_t& attachment = subpass.pColorAttachments[j].attachment;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005453 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
5454 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005455 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005456 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
5457 const uint32_t& attachment = subpass.pDepthStencilAttachment->attachment;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005458 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
5459 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005460 }
5461 }
5462 // Loop through implicit dependencies, if this pass reads make sure the attachment is preserved for all passes after it was written.
5463 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5464 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005465 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005466 CheckPreserved(my_data, device, pCreateInfo, i, subpass.pInputAttachments[j].attachment, subpass_to_node, 0, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005467 }
5468 }
5469 return skip_call;
5470}
5471
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005472VkBool32 ValidateLayouts(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005473 VkBool32 skip = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005474
5475#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
5476 return skip;
5477#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5478
Michael Lentineabc5e922015-10-12 11:30:14 -05005479 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5480 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
5481 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
5482 if (subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL &&
5483 subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) {
5484 if (subpass.pInputAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005485 // 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 -07005486 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 -05005487 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
5488 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005489 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 -05005490 "Layout for input attachment is %d but can only be READ_ONLY_OPTIMAL or GENERAL.", subpass.pInputAttachments[j].attachment);
5491 }
5492 }
5493 }
5494 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
5495 if (subpass.pColorAttachments[j].layout != VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) {
5496 if (subpass.pColorAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005497 // 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 -07005498 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 -05005499 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
5500 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005501 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 -05005502 "Layout for color attachment is %d but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.", subpass.pColorAttachments[j].attachment);
5503 }
5504 }
5505 }
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005506 if ((subpass.pDepthStencilAttachment != NULL) &&
5507 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
Michael Lentineabc5e922015-10-12 11:30:14 -05005508 if (subpass.pDepthStencilAttachment->layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) {
5509 if (subpass.pDepthStencilAttachment->layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005510 // 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 -07005511 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 -05005512 "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL.");
5513 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005514 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 -05005515 "Layout for depth attachment is %d but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL.", subpass.pDepthStencilAttachment->attachment);
5516 }
5517 }
5518 }
5519 }
5520 return skip;
5521}
5522
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005523VkBool32 CreatePassDAG(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, std::vector<DAGNode>& subpass_to_node, std::vector<bool>& has_self_dependency) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005524 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05005525 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5526 DAGNode& subpass_node = subpass_to_node[i];
5527 subpass_node.pass = i;
5528 }
5529 for (uint32_t i = 0; i < pCreateInfo->dependencyCount; ++i) {
5530 const VkSubpassDependency& dependency = pCreateInfo->pDependencies[i];
5531 if (dependency.srcSubpass > dependency.dstSubpass) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005532 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 -05005533 "Depedency graph must be specified such that an earlier pass cannot depend on a later pass.");
Michael Lentine48930b82015-10-15 17:07:00 -05005534 } else if (dependency.srcSubpass == dependency.dstSubpass) {
5535 has_self_dependency[dependency.srcSubpass] = true;
Michael Lentineabc5e922015-10-12 11:30:14 -05005536 }
5537 subpass_to_node[dependency.dstSubpass].prev.push_back(dependency.srcSubpass);
5538 subpass_to_node[dependency.srcSubpass].next.push_back(dependency.dstSubpass);
5539 }
5540 return skip_call;
5541}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005542// TODOSC : Add intercept of vkCreateShaderModule
Michael Lentineabc5e922015-10-12 11:30:14 -05005543
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005544VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateShaderModule(
5545 VkDevice device,
5546 const VkShaderModuleCreateInfo *pCreateInfo,
5547 const VkAllocationCallbacks* pAllocator,
5548 VkShaderModule *pShaderModule)
5549{
5550 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07005551 VkBool32 skip_call = VK_FALSE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005552 if (!shader_is_spirv(pCreateInfo)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005553 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 -07005554 /* dev */ 0, __LINE__, SHADER_CHECKER_NON_SPIRV_SHADER, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005555 "Shader is not SPIR-V");
5556 }
5557
Mark Youngb20a6a82016-01-07 15:41:43 -07005558 if (VK_FALSE != skip_call)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005559 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005560
5561 VkResult res = my_data->device_dispatch_table->CreateShaderModule(device, pCreateInfo, pAllocator, pShaderModule);
5562
5563 if (res == VK_SUCCESS) {
5564 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005565 my_data->shaderModuleMap[*pShaderModule] = new shader_module(pCreateInfo);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005566 loader_platform_thread_unlock_mutex(&globalLock);
5567 }
5568 return res;
5569}
5570
Chia-I Wu9ab61502015-11-06 06:42:02 +08005571VK_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 -06005572{
Mark Youngb20a6a82016-01-07 15:41:43 -07005573 VkBool32 skip_call = VK_FALSE;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005574 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentineabc5e922015-10-12 11:30:14 -05005575 // Create DAG
Michael Lentine48930b82015-10-15 17:07:00 -05005576 std::vector<bool> has_self_dependency(pCreateInfo->subpassCount);
Michael Lentineabc5e922015-10-12 11:30:14 -05005577 std::vector<DAGNode> subpass_to_node(pCreateInfo->subpassCount);
Michael Lentine48930b82015-10-15 17:07:00 -05005578 skip_call |= CreatePassDAG(dev_data, device, pCreateInfo, subpass_to_node, has_self_dependency);
Michael Lentineabc5e922015-10-12 11:30:14 -05005579 // Validate using DAG
5580 skip_call |= ValidateDependencies(dev_data, device, pCreateInfo, subpass_to_node);
5581 skip_call |= ValidateLayouts(dev_data, device, pCreateInfo);
Mark Youngb20a6a82016-01-07 15:41:43 -07005582 if (VK_FALSE != skip_call) {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005583 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentineb6986752015-10-06 14:56:18 -07005584 }
Chia-I Wuf7458c52015-10-26 21:10:41 +08005585 VkResult result = dev_data->device_dispatch_table->CreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005586 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005587 // TODOSC : Merge in tracking of renderpass from ShaderChecker
Tobin Ehliseba312c2015-04-01 08:40:34 -06005588 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06005589 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +08005590 if (pCreateInfo->pAttachments) {
5591 localRPCI->pAttachments = new VkAttachmentDescription[localRPCI->attachmentCount];
5592 memcpy((void*)localRPCI->pAttachments, pCreateInfo->pAttachments, localRPCI->attachmentCount*sizeof(VkAttachmentDescription));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005593 }
Chia-I Wu08accc62015-07-07 11:50:03 +08005594 if (pCreateInfo->pSubpasses) {
5595 localRPCI->pSubpasses = new VkSubpassDescription[localRPCI->subpassCount];
5596 memcpy((void*)localRPCI->pSubpasses, pCreateInfo->pSubpasses, localRPCI->subpassCount*sizeof(VkSubpassDescription));
5597
5598 for (uint32_t i = 0; i < localRPCI->subpassCount; i++) {
5599 VkSubpassDescription *subpass = (VkSubpassDescription *) &localRPCI->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005600 const uint32_t attachmentCount = subpass->inputAttachmentCount +
5601 subpass->colorAttachmentCount * (1 + (subpass->pResolveAttachments?1:0)) +
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005602 ((subpass->pDepthStencilAttachment) ? 1 : 0) + subpass->preserveAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005603 VkAttachmentReference *attachments = new VkAttachmentReference[attachmentCount];
5604
Cody Northropa505dda2015-08-04 11:16:41 -06005605 memcpy(attachments, subpass->pInputAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005606 sizeof(attachments[0]) * subpass->inputAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005607 subpass->pInputAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005608 attachments += subpass->inputAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005609
Cody Northropa505dda2015-08-04 11:16:41 -06005610 memcpy(attachments, subpass->pColorAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005611 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005612 subpass->pColorAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005613 attachments += subpass->colorAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005614
Cody Northropa505dda2015-08-04 11:16:41 -06005615 if (subpass->pResolveAttachments) {
5616 memcpy(attachments, subpass->pResolveAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005617 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005618 subpass->pResolveAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005619 attachments += subpass->colorAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005620 }
5621
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005622 if (subpass->pDepthStencilAttachment) {
5623 memcpy(attachments, subpass->pDepthStencilAttachment,
5624 sizeof(attachments[0]) * 1);
5625 subpass->pDepthStencilAttachment = attachments;
5626 attachments += 1;
5627 }
5628
Cody Northropa505dda2015-08-04 11:16:41 -06005629 memcpy(attachments, subpass->pPreserveAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005630 sizeof(attachments[0]) * subpass->preserveAttachmentCount);
Jon Ashburnf19916e2016-01-11 13:12:43 -07005631 subpass->pPreserveAttachments = &attachments->attachment;
Chia-I Wu08accc62015-07-07 11:50:03 +08005632 }
Tobin Ehliseba312c2015-04-01 08:40:34 -06005633 }
Chia-I Wu08accc62015-07-07 11:50:03 +08005634 if (pCreateInfo->pDependencies) {
5635 localRPCI->pDependencies = new VkSubpassDependency[localRPCI->dependencyCount];
5636 memcpy((void*)localRPCI->pDependencies, pCreateInfo->pDependencies, localRPCI->dependencyCount*sizeof(VkSubpassDependency));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005637 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005638 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005639 dev_data->renderPassMap[*pRenderPass] = new RENDER_PASS_NODE(localRPCI);
Michael Lentine48930b82015-10-15 17:07:00 -05005640 dev_data->renderPassMap[*pRenderPass]->hasSelfDependency = has_self_dependency;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005641 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehliseba312c2015-04-01 08:40:34 -06005642 }
5643 return result;
5644}
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005645// Free the renderpass shadow
5646static void deleteRenderPasses(layer_data* my_data)
5647{
5648 if (my_data->renderPassMap.size() <= 0)
5649 return;
5650 for (auto ii=my_data->renderPassMap.begin(); ii!=my_data->renderPassMap.end(); ++ii) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005651 const VkRenderPassCreateInfo* pRenderPassInfo = (*ii).second->pCreateInfo;
Michael Lentine48930b82015-10-15 17:07:00 -05005652 if (pRenderPassInfo->pAttachments) {
5653 delete[] pRenderPassInfo->pAttachments;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005654 }
Michael Lentine48930b82015-10-15 17:07:00 -05005655 if (pRenderPassInfo->pSubpasses) {
5656 for (uint32_t i=0; i<pRenderPassInfo->subpassCount; ++i) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005657 // Attachements are all allocated in a block, so just need to
5658 // find the first non-null one to delete
Michael Lentine48930b82015-10-15 17:07:00 -05005659 if (pRenderPassInfo->pSubpasses[i].pInputAttachments) {
5660 delete[] pRenderPassInfo->pSubpasses[i].pInputAttachments;
5661 } else if (pRenderPassInfo->pSubpasses[i].pColorAttachments) {
5662 delete[] pRenderPassInfo->pSubpasses[i].pColorAttachments;
5663 } else if (pRenderPassInfo->pSubpasses[i].pResolveAttachments) {
5664 delete[] pRenderPassInfo->pSubpasses[i].pResolveAttachments;
5665 } else if (pRenderPassInfo->pSubpasses[i].pPreserveAttachments) {
5666 delete[] pRenderPassInfo->pSubpasses[i].pPreserveAttachments;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005667 }
5668 }
Michael Lentine48930b82015-10-15 17:07:00 -05005669 delete[] pRenderPassInfo->pSubpasses;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005670 }
Michael Lentine48930b82015-10-15 17:07:00 -05005671 if (pRenderPassInfo->pDependencies) {
5672 delete[] pRenderPassInfo->pDependencies;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005673 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005674 delete pRenderPassInfo;
Michael Lentine48930b82015-10-15 17:07:00 -05005675 delete (*ii).second;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005676 }
5677 my_data->renderPassMap.clear();
5678}
Michael Lentineabc5e922015-10-12 11:30:14 -05005679
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005680VkBool32 VerifyFramebufferAndRenderPassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005681 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05005682 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5683 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005684 const VkRenderPassCreateInfo* pRenderPassInfo = dev_data->renderPassMap[pRenderPassBegin->renderPass]->pCreateInfo;
Michael Lentineabc5e922015-10-12 11:30:14 -05005685 const VkFramebufferCreateInfo* pFramebufferInfo = dev_data->frameBufferMap[pRenderPassBegin->framebuffer];
5686 if (pRenderPassInfo->attachmentCount != pFramebufferInfo->attachmentCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005687 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 -05005688 "You cannot start a render pass using a framebuffer with a different number of attachments.");
5689 }
5690 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
5691 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
5692 const VkImage& image = dev_data->imageViewMap[image_view]->image;
5693 auto image_data = pCB->imageLayoutMap.find(image);
5694 if (image_data == pCB->imageLayoutMap.end()) {
5695 pCB->imageLayoutMap[image].initialLayout = pRenderPassInfo->pAttachments[i].initialLayout;
5696 pCB->imageLayoutMap[image].layout = pRenderPassInfo->pAttachments[i].initialLayout;
5697 } else if (pRenderPassInfo->pAttachments[i].initialLayout != image_data->second.layout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005698 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 -05005699 "You cannot start a render pass using attachment %i where the intial layout differs from the starting layout.", i);
5700 }
5701 }
5702 return skip_call;
5703}
5704
5705void TransitionSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, const int subpass_index) {
5706 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5707 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5708 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
5709 if (render_pass_data == dev_data->renderPassMap.end()) {
5710 return;
5711 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005712 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
Michael Lentineabc5e922015-10-12 11:30:14 -05005713 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
5714 if (framebuffer_data == dev_data->frameBufferMap.end()) {
5715 return;
5716 }
5717 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
5718 const VkSubpassDescription& subpass = pRenderPassInfo->pSubpasses[subpass_index];
5719 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
5720 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pInputAttachments[j].attachment];
5721 auto image_view_data = dev_data->imageViewMap.find(image_view);
5722 if (image_view_data != dev_data->imageViewMap.end()) {
5723 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5724 if (image_layout != pCB->imageLayoutMap.end()) {
5725 image_layout->second.layout = subpass.pInputAttachments[j].layout;
5726 }
5727 }
5728 }
5729 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
5730 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pColorAttachments[j].attachment];
5731 auto image_view_data = dev_data->imageViewMap.find(image_view);
5732 if (image_view_data != dev_data->imageViewMap.end()) {
5733 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5734 if (image_layout != pCB->imageLayoutMap.end()) {
5735 image_layout->second.layout = subpass.pColorAttachments[j].layout;
5736 }
5737 }
5738 }
Michael Lentine3dea6512015-10-28 15:55:18 -07005739 if ((subpass.pDepthStencilAttachment != NULL) &&
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005740 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
Michael Lentineabc5e922015-10-12 11:30:14 -05005741 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pDepthStencilAttachment->attachment];
5742 auto image_view_data = dev_data->imageViewMap.find(image_view);
5743 if (image_view_data != dev_data->imageViewMap.end()) {
5744 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5745 if (image_layout != pCB->imageLayoutMap.end()) {
5746 image_layout->second.layout = subpass.pDepthStencilAttachment->layout;
5747 }
5748 }
5749 }
5750}
5751
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005752VkBool32 validatePrimaryCommandBuffer(const layer_data* my_data, const GLOBAL_CB_NODE* pCB, const std::string& cmd_name) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005753 VkBool32 skip_call = VK_FALSE;
Michael Lentine3dea6512015-10-28 15:55:18 -07005754 if (pCB->createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005755 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 -07005756 "Cannot execute command %s on a secondary command buffer.", cmd_name.c_str());
5757 }
5758 return skip_call;
5759}
5760
Michael Lentineabc5e922015-10-12 11:30:14 -05005761void TransitionFinalSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
5762 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5763 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5764 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
5765 if (render_pass_data == dev_data->renderPassMap.end()) {
5766 return;
5767 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005768 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
Michael Lentineabc5e922015-10-12 11:30:14 -05005769 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
5770 if (framebuffer_data == dev_data->frameBufferMap.end()) {
5771 return;
5772 }
5773 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
5774 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
5775 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
5776 auto image_view_data = dev_data->imageViewMap.find(image_view);
5777 if (image_view_data != dev_data->imageViewMap.end()) {
5778 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5779 if (image_layout != pCB->imageLayoutMap.end()) {
5780 image_layout->second.layout = pRenderPassInfo->pAttachments[i].finalLayout;
5781 }
5782 }
5783 }
5784}
5785
Chia-I Wu9ab61502015-11-06 06:42:02 +08005786VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, VkSubpassContents contents)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005787{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005788 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005789 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5790 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005791 if (pCB) {
Tobin Ehlis259730a2015-06-23 16:13:03 -06005792 if (pRenderPassBegin && pRenderPassBegin->renderPass) {
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005793 skipCall |= VerifyFramebufferAndRenderPassLayouts(commandBuffer, pRenderPassBegin);
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005794 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBeginRenderPass");
Michael Lentine3dea6512015-10-28 15:55:18 -07005795 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdBeginRenderPass");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005796 skipCall |= addCmd(dev_data, pCB, CMD_BEGINRENDERPASS, "vkCmdBeginRenderPass()");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005797 pCB->activeRenderPass = pRenderPassBegin->renderPass;
Michael Lentineabc5e922015-10-12 11:30:14 -05005798 // This is a shallow copy as that is all that is needed for now
5799 pCB->activeRenderPassBeginInfo = *pRenderPassBegin;
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005800 pCB->activeSubpass = 0;
Michael Lentine2e068b22015-12-29 16:05:27 -06005801 pCB->activeSubpassContents = contents;
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005802 pCB->framebuffer = pRenderPassBegin->framebuffer;
Tobin Ehlis502480b2015-06-24 15:53:07 -06005803 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005804 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 -06005805 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tony Barbourbadda992015-04-06 11:09:26 -06005806 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005807 }
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005808 if (VK_FALSE == skipCall) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005809 dev_data->device_dispatch_table->CmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents);
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005810 // This is a shallow copy as that is all that is needed for now
5811 dev_data->renderPassBeginInfo = *pRenderPassBegin;
5812 dev_data->currentSubpass = 0;
5813 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005814}
5815
Chia-I Wu9ab61502015-11-06 06:42:02 +08005816VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents)
Chia-I Wu08accc62015-07-07 11:50:03 +08005817{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005818 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005819 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5820 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Michael Lentineabc5e922015-10-12 11:30:14 -05005821 TransitionSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo, ++dev_data->currentSubpass);
Chia-I Wu08accc62015-07-07 11:50:03 +08005822 if (pCB) {
Michael Lentine3dea6512015-10-28 15:55:18 -07005823 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdNextSubpass");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005824 skipCall |= addCmd(dev_data, pCB, CMD_NEXTSUBPASS, "vkCmdNextSubpass()");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005825 pCB->activeSubpass++;
Michael Lentine2e068b22015-12-29 16:05:27 -06005826 pCB->activeSubpassContents = contents;
Tony Barbourfc5bb6f2016-01-12 11:16:52 -07005827 TransitionSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo, pCB->activeSubpass);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005828 if (pCB->lastBoundPipeline) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005829 skipCall |= validatePipelineState(dev_data, pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Chia-I Wu08accc62015-07-07 11:50:03 +08005830 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005831 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdNextSubpass");
Chia-I Wu08accc62015-07-07 11:50:03 +08005832 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005833 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005834 dev_data->device_dispatch_table->CmdNextSubpass(commandBuffer, contents);
Chia-I Wu08accc62015-07-07 11:50:03 +08005835}
5836
Chia-I Wu9ab61502015-11-06 06:42:02 +08005837VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndRenderPass(VkCommandBuffer commandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005838{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005839 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005840 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5841 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Michael Lentineabc5e922015-10-12 11:30:14 -05005842 TransitionFinalSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005843 if (pCB) {
Michael Lentine3dea6512015-10-28 15:55:18 -07005844 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdEndRenderpass");
Michael Lentine3dea6512015-10-28 15:55:18 -07005845 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdEndRenderPass");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005846 skipCall |= addCmd(dev_data, pCB, CMD_ENDRENDERPASS, "vkCmdEndRenderPass()");
Michael Lentineabc5e922015-10-12 11:30:14 -05005847 TransitionFinalSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005848 pCB->activeRenderPass = 0;
5849 pCB->activeSubpass = 0;
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005850 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005851 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005852 dev_data->device_dispatch_table->CmdEndRenderPass(commandBuffer);
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005853}
5854
Chia-I Wu9ab61502015-11-06 06:42:02 +08005855VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount, const VkCommandBuffer* pCommandBuffers)
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005856{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005857 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005858 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5859 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005860 if (pCB) {
Tobin Ehlis651d9b02015-12-16 05:01:22 -07005861 // TODO : If secondary CB was not created w/ *_USAGE_SIMULTANEOUS_USE_BIT it cannot be used more than once in given primary CB
5862 // ALSO if secondary w/o this flag is set in primary, then primary must not be pending execution more than once at a time
5863 // 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 -06005864 GLOBAL_CB_NODE* pSubCB = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005865 for (uint32_t i=0; i<commandBuffersCount; i++) {
5866 pSubCB = getCBNode(dev_data, pCommandBuffers[i]);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06005867 if (!pSubCB) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005868 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 +08005869 "vkCmdExecuteCommands() called w/ invalid Cmd Buffer %p in element %u of pCommandBuffers array.", (void*)pCommandBuffers[i], i);
5870 } else if (VK_COMMAND_BUFFER_LEVEL_PRIMARY == pSubCB->createInfo.level) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005871 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 +08005872 "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 -07005873 } else if (pCB->activeRenderPass) { // Secondary CB w/i RenderPass must have *CONTINUE_BIT set
5874 if (!(pSubCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005875 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 -07005876 "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);
5877 }
5878 string errorString = "";
Jon Ashburnf19916e2016-01-11 13:12:43 -07005879 if (!verify_renderpass_compatibility(dev_data, pCB->activeRenderPass, pSubCB->beginInfo.pInheritanceInfo->renderPass, errorString)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005880 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 -07005881 "vkCmdExecuteCommands(): Secondary Command Buffer (%p) w/ render pass (%#" PRIxLEAST64 ") is incompatible w/ primary command buffer (%p) w/ render pass (%#" PRIxLEAST64 ") due to: %s",
Jon Ashburnf19916e2016-01-11 13:12:43 -07005882 (void*)pCommandBuffers[i], (uint64_t)pSubCB->beginInfo.pInheritanceInfo->renderPass, (void*)commandBuffer, (uint64_t)pCB->activeRenderPass, errorString.c_str());
Tobin Ehlis651d9b02015-12-16 05:01:22 -07005883 }
5884 // If framebuffer for secondary CB is not NULL, then it must match FB from vkCmdBeginRenderPass()
5885 // that this CB will be executed in AND framebuffer must have been created w/ RP compatible w/ renderpass
Jon Ashburnf19916e2016-01-11 13:12:43 -07005886 if (pSubCB->beginInfo.pInheritanceInfo->framebuffer) {
5887 if (pSubCB->beginInfo.pInheritanceInfo->framebuffer != pCB->activeRenderPassBeginInfo.framebuffer) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005888 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 -07005889 "vkCmdExecuteCommands(): Secondary Command Buffer (%p) references framebuffer (%#" PRIxLEAST64 ") that does not match framebuffer (%#" PRIxLEAST64 ") in active renderpass (%#" PRIxLEAST64 ").",
Jon Ashburnf19916e2016-01-11 13:12:43 -07005890 (void*)pCommandBuffers[i], (uint64_t)pSubCB->beginInfo.pInheritanceInfo->framebuffer, (uint64_t)pCB->activeRenderPassBeginInfo.framebuffer, (uint64_t)pCB->activeRenderPass);
Tobin Ehlis651d9b02015-12-16 05:01:22 -07005891 }
5892 }
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06005893 }
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07005894 // Secondary cmdBuffers are considered pending execution starting w/ being recorded
5895 if (!(pSubCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT)) {
5896 if (dev_data->inFlightCmdBuffers.find(pSubCB->commandBuffer) != dev_data->inFlightCmdBuffers.end()) {
5897 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, reinterpret_cast<uint64_t>(pCB->commandBuffer), __LINE__, DRAWSTATE_INVALID_CB_SIMULTANEOUS_USE, "DS",
5898 "Attempt to simultaneously execute CB %#" PRIxLEAST64 " w/o VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!", reinterpret_cast<uint64_t>(pCB->commandBuffer));
5899 }
5900 if (pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT) {
5901 // Warn that non-simultaneous secondary cmd buffer renders primary non-simultaneous
5902 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, reinterpret_cast<uint64_t>(pCommandBuffers[i]), __LINE__, DRAWSTATE_INVALID_CB_SIMULTANEOUS_USE, "DS",
5903 "vkCmdExecuteCommands(): Secondary Command Buffer (%#" PRIxLEAST64 ") does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and will cause primary command buffer (%#" PRIxLEAST64 ") to be treated as if it does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set, even though it does.",
5904 reinterpret_cast<uint64_t>(pCommandBuffers[i]), reinterpret_cast<uint64_t>(pCB->commandBuffer));
5905 pCB->beginInfo.flags &= ~VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
5906 }
5907 }
5908 pCB->secondaryCommandBuffers.insert(pSubCB->commandBuffer);
5909 dev_data->inFlightCmdBuffers.insert(pSubCB->commandBuffer);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06005910 }
Michael Lentine3dea6512015-10-28 15:55:18 -07005911 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdExecuteComands");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005912 skipCall |= addCmd(dev_data, pCB, CMD_EXECUTECOMMANDS, "vkCmdExecuteComands()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005913 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005914 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005915 dev_data->device_dispatch_table->CmdExecuteCommands(commandBuffer, commandBuffersCount, pCommandBuffers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005916}
5917
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005918VkBool32 ValidateMapImageLayouts(VkDevice device, VkDeviceMemory mem) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005919 VkBool32 skip_call = VK_FALSE;
Michael Lentine7b236262015-10-23 12:41:44 -07005920 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5921 auto mem_data = dev_data->memImageMap.find(mem);
5922 if (mem_data != dev_data->memImageMap.end()) {
5923 auto image_data = dev_data->imageLayoutMap.find(mem_data->second);
5924 if (image_data != dev_data->imageLayoutMap.end()) {
5925 if (image_data->second->layout != VK_IMAGE_LAYOUT_PREINITIALIZED && image_data->second->layout != VK_IMAGE_LAYOUT_GENERAL) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005926 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 -07005927 "Cannot map an image with layout %d. Only GENERAL or PREINITIALIZED are supported.", image_data->second->layout);
5928 }
5929 }
5930 }
5931 return skip_call;
5932}
5933
Chia-I Wu9ab61502015-11-06 06:42:02 +08005934VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkMapMemory(
Michael Lentine7b236262015-10-23 12:41:44 -07005935 VkDevice device,
5936 VkDeviceMemory mem,
5937 VkDeviceSize offset,
5938 VkDeviceSize size,
5939 VkFlags flags,
5940 void **ppData)
5941{
5942 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005943
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005944 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005945#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
5946 skip_call = ValidateMapImageLayouts(device, mem);
5947#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5948
Michael Lentine7b236262015-10-23 12:41:44 -07005949 if (VK_FALSE == skip_call) {
5950 return dev_data->device_dispatch_table->MapMemory(device, mem, offset, size, flags, ppData);
5951 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005952 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine7b236262015-10-23 12:41:44 -07005953}
5954
Chia-I Wu9ab61502015-11-06 06:42:02 +08005955VKAPI_ATTR VkResult VKAPI_CALL vkBindImageMemory(
Michael Lentine7b236262015-10-23 12:41:44 -07005956 VkDevice device,
5957 VkImage image,
5958 VkDeviceMemory mem,
5959 VkDeviceSize memOffset)
5960{
5961 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5962 VkResult result = dev_data->device_dispatch_table->BindImageMemory(device, image, mem, memOffset);
5963 loader_platform_thread_lock_mutex(&globalLock);
5964 dev_data->memImageMap[mem] = image;
5965 loader_platform_thread_unlock_mutex(&globalLock);
5966 return result;
5967}
5968
Michael Lentineb887b0a2015-12-29 14:12:11 -06005969
5970VKAPI_ATTR VkResult VKAPI_CALL vkSetEvent(VkDevice device, VkEvent event) {
5971 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5972 dev_data->eventMap[event].needsSignaled = false;
5973 VkResult result = dev_data->device_dispatch_table->SetEvent(device, event);
5974 return result;
5975}
5976
Michael Lentine15a47882016-01-06 10:05:48 -06005977VKAPI_ATTR VkResult VKAPI_CALL vkQueueBindSparse(
5978 VkQueue queue,
5979 uint32_t bindInfoCount,
5980 const VkBindSparseInfo* pBindInfo,
5981 VkFence fence)
5982{
5983 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07005984 VkBool32 skip_call = VK_FALSE;
Michael Lentine15a47882016-01-06 10:05:48 -06005985
5986 for (uint32_t bindIdx=0; bindIdx < bindInfoCount; ++bindIdx) {
5987 const VkBindSparseInfo& bindInfo = pBindInfo[bindIdx];
5988 for (uint32_t i=0; i < bindInfo.waitSemaphoreCount; ++i) {
5989 if (dev_data->semaphoreSignaledMap[bindInfo.pWaitSemaphores[i]]) {
5990 dev_data->semaphoreSignaledMap[bindInfo.pWaitSemaphores[i]] = 0;
5991 } else {
5992 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",
5993 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
5994 reinterpret_cast<uint64_t>(queue), reinterpret_cast<uint64_t>(bindInfo.pWaitSemaphores[i]));
5995 }
5996 }
5997 for (uint32_t i=0; i < bindInfo.signalSemaphoreCount; ++i) {
5998 dev_data->semaphoreSignaledMap[bindInfo.pSignalSemaphores[i]] = 1;
5999 }
6000 }
6001
Mark Youngb20a6a82016-01-07 15:41:43 -07006002 if (VK_FALSE == skip_call)
Michael Lentine15a47882016-01-06 10:05:48 -06006003 return dev_data->device_dispatch_table->QueueBindSparse(queue, bindInfoCount, pBindInfo, fence);
Mark Youngb20a6a82016-01-07 15:41:43 -07006004 else
6005 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine15a47882016-01-06 10:05:48 -06006006}
6007
6008VKAPI_ATTR VkResult VKAPI_CALL vkCreateSemaphore(
6009 VkDevice device,
6010 const VkSemaphoreCreateInfo* pCreateInfo,
6011 const VkAllocationCallbacks* pAllocator,
6012 VkSemaphore* pSemaphore)
6013{
6014 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6015 VkResult result = dev_data->device_dispatch_table->CreateSemaphore(device, pCreateInfo, pAllocator, pSemaphore);
6016 if (result == VK_SUCCESS) {
6017 dev_data->semaphoreSignaledMap[*pSemaphore] = 0;
6018 }
Tobin Ehlis51b78af2016-01-06 10:27:47 -07006019 return result;
Michael Lentine15a47882016-01-06 10:05:48 -06006020}
6021
Chia-I Wu9ab61502015-11-06 06:42:02 +08006022VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(
Michael Lentineabc5e922015-10-12 11:30:14 -05006023 VkDevice device,
6024 const VkSwapchainCreateInfoKHR *pCreateInfo,
Ian Elliott05846062015-11-20 14:13:17 -07006025 const VkAllocationCallbacks *pAllocator,
Michael Lentineabc5e922015-10-12 11:30:14 -05006026 VkSwapchainKHR *pSwapchain)
6027{
6028 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott05846062015-11-20 14:13:17 -07006029 VkResult result = dev_data->device_dispatch_table->CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
Michael Lentineabc5e922015-10-12 11:30:14 -05006030
6031 if (VK_SUCCESS == result) {
6032 SWAPCHAIN_NODE *swapchain_data = new SWAPCHAIN_NODE;
6033 loader_platform_thread_lock_mutex(&globalLock);
6034 dev_data->device_extensions.swapchainMap[*pSwapchain] = swapchain_data;
6035 loader_platform_thread_unlock_mutex(&globalLock);
6036 }
6037
6038 return result;
6039}
6040
Ian Elliott05846062015-11-20 14:13:17 -07006041VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR(
Michael Lentineabc5e922015-10-12 11:30:14 -05006042 VkDevice device,
Ian Elliott05846062015-11-20 14:13:17 -07006043 VkSwapchainKHR swapchain,
6044 const VkAllocationCallbacks *pAllocator)
Michael Lentineabc5e922015-10-12 11:30:14 -05006045{
6046 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentineabc5e922015-10-12 11:30:14 -05006047
6048 loader_platform_thread_lock_mutex(&globalLock);
6049 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(swapchain);
6050 if (swapchain_data != dev_data->device_extensions.swapchainMap.end()) {
6051 if (swapchain_data->second->images.size() > 0) {
6052 for (auto swapchain_image : swapchain_data->second->images) {
6053 auto image_item = dev_data->imageLayoutMap.find(swapchain_image);
6054 if (image_item != dev_data->imageLayoutMap.end())
6055 dev_data->imageLayoutMap.erase(image_item);
6056 }
6057 }
6058 delete swapchain_data->second;
6059 dev_data->device_extensions.swapchainMap.erase(swapchain);
6060 }
6061 loader_platform_thread_unlock_mutex(&globalLock);
Ian Elliott05846062015-11-20 14:13:17 -07006062 return dev_data->device_dispatch_table->DestroySwapchainKHR(device, swapchain, pAllocator);
Michael Lentineabc5e922015-10-12 11:30:14 -05006063}
6064
Chia-I Wu9ab61502015-11-06 06:42:02 +08006065VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR(
Michael Lentineabc5e922015-10-12 11:30:14 -05006066 VkDevice device,
6067 VkSwapchainKHR swapchain,
6068 uint32_t* pCount,
6069 VkImage* pSwapchainImages)
6070{
6071 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6072 VkResult result = dev_data->device_dispatch_table->GetSwapchainImagesKHR(device, swapchain, pCount, pSwapchainImages);
6073
6074 if (result == VK_SUCCESS && pSwapchainImages != NULL) {
6075 // This should never happen and is checked by param checker.
6076 if (!pCount) return result;
6077 for (uint32_t i = 0; i < *pCount; ++i) {
6078 IMAGE_NODE* image_node = new IMAGE_NODE;
6079 image_node->layout = VK_IMAGE_LAYOUT_UNDEFINED;
6080 loader_platform_thread_lock_mutex(&globalLock);
6081 dev_data->device_extensions.swapchainMap[swapchain]->images.push_back(pSwapchainImages[i]);
6082 dev_data->imageLayoutMap[pSwapchainImages[i]] = image_node;
6083 loader_platform_thread_unlock_mutex(&globalLock);
6084 }
6085 }
6086 return result;
6087}
6088
Ian Elliott05846062015-11-20 14:13:17 -07006089VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo)
Michael Lentineabc5e922015-10-12 11:30:14 -05006090{
6091 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07006092 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05006093
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006094#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentineabc5e922015-10-12 11:30:14 -05006095 if (pPresentInfo) {
Michael Lentine15a47882016-01-06 10:05:48 -06006096 for (uint32_t i=0; i < pPresentInfo->waitSemaphoreCount; ++i) {
6097 if (dev_data->semaphoreSignaledMap[pPresentInfo->pWaitSemaphores[i]]) {
6098 dev_data->semaphoreSignaledMap[pPresentInfo->pWaitSemaphores[i]] = 0;
6099 } else {
6100 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",
6101 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
6102 reinterpret_cast<uint64_t>(queue), reinterpret_cast<uint64_t>(pPresentInfo->pWaitSemaphores[i]));
6103 }
6104 }
Michael Lentineabc5e922015-10-12 11:30:14 -05006105 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
Ian Elliott05846062015-11-20 14:13:17 -07006106 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(pPresentInfo->pSwapchains[i]);
6107 if (swapchain_data != dev_data->device_extensions.swapchainMap.end() && pPresentInfo->pImageIndices[i] < swapchain_data->second->images.size()) {
6108 VkImage image = swapchain_data->second->images[pPresentInfo->pImageIndices[i]];
Michael Lentineabc5e922015-10-12 11:30:14 -05006109 auto image_data = dev_data->imageLayoutMap.find(image);
6110 if (image_data != dev_data->imageLayoutMap.end()) {
Ian Elliott05846062015-11-20 14:13:17 -07006111 if (image_data->second->layout != VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07006112 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 -05006113 "Images passed to present must be in layout PRESENT_SOURCE_KHR but is in %d", image_data->second->layout);
6114 }
6115 }
6116 }
6117 }
6118 }
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006119#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentineabc5e922015-10-12 11:30:14 -05006120
6121 if (VK_FALSE == skip_call)
6122 return dev_data->device_dispatch_table->QueuePresentKHR(queue, pPresentInfo);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07006123 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentineabc5e922015-10-12 11:30:14 -05006124}
6125
Michael Lentine15a47882016-01-06 10:05:48 -06006126VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImageKHR(
6127 VkDevice device,
6128 VkSwapchainKHR swapchain,
6129 uint64_t timeout,
6130 VkSemaphore semaphore,
6131 VkFence fence,
6132 uint32_t* pImageIndex)
6133{
6134 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6135 VkResult result = dev_data->device_dispatch_table->AcquireNextImageKHR(device, swapchain, timeout, semaphore, fence, pImageIndex);
6136 dev_data->semaphoreSignaledMap[semaphore] = 1;
Tobin Ehlis51b78af2016-01-06 10:27:47 -07006137 return result;
Michael Lentine15a47882016-01-06 10:05:48 -06006138}
6139
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006140VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(
6141 VkInstance instance,
6142 const VkDebugReportCallbackCreateInfoEXT* pCreateInfo,
6143 const VkAllocationCallbacks* pAllocator,
6144 VkDebugReportCallbackEXT* pMsgCallback)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006145{
Tobin Ehlis0b632332015-10-07 09:38:40 -06006146 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006147 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006148 VkResult res = pTable->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06006149 if (VK_SUCCESS == res) {
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006150 res = layer_create_msg_callback(my_data->report_data, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06006151 }
6152 return res;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006153}
6154
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006155VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006156 VkInstance instance,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006157 VkDebugReportCallbackEXT msgCallback,
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006158 const VkAllocationCallbacks* pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006159{
Tobin Ehlis0b632332015-10-07 09:38:40 -06006160 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006161 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006162 pTable->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006163 layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006164}
6165
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006166VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDebugReportMessageEXT(
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07006167 VkInstance instance,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006168 VkDebugReportFlagsEXT flags,
6169 VkDebugReportObjectTypeEXT objType,
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07006170 uint64_t object,
6171 size_t location,
6172 int32_t msgCode,
6173 const char* pLayerPrefix,
6174 const char* pMsg)
6175{
6176 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006177 my_data->instance_dispatch_table->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg);
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07006178}
6179
Chia-I Wu9ab61502015-11-06 06:42:02 +08006180VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerBegin(VkCommandBuffer commandBuffer, const char* pMarker)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006181{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006182 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006183 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
6184 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis0b632332015-10-07 09:38:40 -06006185 if (!dev_data->device_extensions.debug_marker_enabled) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07006186 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 -06006187 "Attempt to use CmdDbgMarkerBegin but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06006188 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06006189 } else if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07006190 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKERBEGIN, "vkCmdDbgMarkerBegin()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006191 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006192 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006193 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerBegin(commandBuffer, pMarker);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006194}
6195
Chia-I Wu9ab61502015-11-06 06:42:02 +08006196VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerEnd(VkCommandBuffer commandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006197{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006198 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006199 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
6200 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis0b632332015-10-07 09:38:40 -06006201 if (!dev_data->device_extensions.debug_marker_enabled) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07006202 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 -06006203 "Attempt to use CmdDbgMarkerEnd but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06006204 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06006205 } else if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07006206 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKEREND, "vkCmdDbgMarkerEnd()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006207 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006208 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006209 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerEnd(commandBuffer);
Jon Ashburneab34492015-06-01 09:37:38 -06006210}
6211
Chia-I Wu9ab61502015-11-06 06:42:02 +08006212VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006213{
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006214 if (!strcmp(funcName, "vkGetDeviceProcAddr"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006215 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006216 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006217 return (PFN_vkVoidFunction) vkDestroyDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006218 if (!strcmp(funcName, "vkQueueSubmit"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006219 return (PFN_vkVoidFunction) vkQueueSubmit;
Michael Lentine700b0aa2015-10-30 17:57:32 -07006220 if (!strcmp(funcName, "vkWaitForFences"))
6221 return (PFN_vkVoidFunction) vkWaitForFences;
6222 if (!strcmp(funcName, "vkGetFenceStatus"))
6223 return (PFN_vkVoidFunction) vkGetFenceStatus;
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07006224 if (!strcmp(funcName, "vkQueueWaitIdle"))
6225 return (PFN_vkVoidFunction) vkQueueWaitIdle;
6226 if (!strcmp(funcName, "vkDeviceWaitIdle"))
6227 return (PFN_vkVoidFunction) vkDeviceWaitIdle;
Michael Lentine700b0aa2015-10-30 17:57:32 -07006228 if (!strcmp(funcName, "vkGetDeviceQueue"))
6229 return (PFN_vkVoidFunction) vkGetDeviceQueue;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006230 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006231 return (PFN_vkVoidFunction) vkDestroyInstance;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006232 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006233 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006234 if (!strcmp(funcName, "vkDestroyFence"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006235 return (PFN_vkVoidFunction) vkDestroyFence;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006236 if (!strcmp(funcName, "vkDestroySemaphore"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006237 return (PFN_vkVoidFunction) vkDestroySemaphore;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006238 if (!strcmp(funcName, "vkDestroyEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006239 return (PFN_vkVoidFunction) vkDestroyEvent;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006240 if (!strcmp(funcName, "vkDestroyQueryPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006241 return (PFN_vkVoidFunction) vkDestroyQueryPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006242 if (!strcmp(funcName, "vkDestroyBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006243 return (PFN_vkVoidFunction) vkDestroyBuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006244 if (!strcmp(funcName, "vkDestroyBufferView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006245 return (PFN_vkVoidFunction) vkDestroyBufferView;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006246 if (!strcmp(funcName, "vkDestroyImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006247 return (PFN_vkVoidFunction) vkDestroyImage;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006248 if (!strcmp(funcName, "vkDestroyImageView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006249 return (PFN_vkVoidFunction) vkDestroyImageView;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006250 if (!strcmp(funcName, "vkDestroyShaderModule"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006251 return (PFN_vkVoidFunction) vkDestroyShaderModule;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006252 if (!strcmp(funcName, "vkDestroyPipeline"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006253 return (PFN_vkVoidFunction) vkDestroyPipeline;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006254 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006255 return (PFN_vkVoidFunction) vkDestroyPipelineLayout;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006256 if (!strcmp(funcName, "vkDestroySampler"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006257 return (PFN_vkVoidFunction) vkDestroySampler;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006258 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006259 return (PFN_vkVoidFunction) vkDestroyDescriptorSetLayout;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006260 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006261 return (PFN_vkVoidFunction) vkDestroyDescriptorPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006262 if (!strcmp(funcName, "vkDestroyFramebuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006263 return (PFN_vkVoidFunction) vkDestroyFramebuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006264 if (!strcmp(funcName, "vkDestroyRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006265 return (PFN_vkVoidFunction) vkDestroyRenderPass;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006266 if (!strcmp(funcName, "vkCreateBuffer"))
6267 return (PFN_vkVoidFunction) vkCreateBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006268 if (!strcmp(funcName, "vkCreateBufferView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006269 return (PFN_vkVoidFunction) vkCreateBufferView;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006270 if (!strcmp(funcName, "vkCreateImage"))
6271 return (PFN_vkVoidFunction) vkCreateImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006272 if (!strcmp(funcName, "vkCreateImageView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006273 return (PFN_vkVoidFunction) vkCreateImageView;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006274 if (!strcmp(funcName, "CreatePipelineCache"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006275 return (PFN_vkVoidFunction) vkCreatePipelineCache;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006276 if (!strcmp(funcName, "DestroyPipelineCache"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006277 return (PFN_vkVoidFunction) vkDestroyPipelineCache;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006278 if (!strcmp(funcName, "GetPipelineCacheData"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006279 return (PFN_vkVoidFunction) vkGetPipelineCacheData;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006280 if (!strcmp(funcName, "MergePipelineCaches"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006281 return (PFN_vkVoidFunction) vkMergePipelineCaches;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006282 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006283 return (PFN_vkVoidFunction) vkCreateGraphicsPipelines;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07006284 if (!strcmp(funcName, "vkCreateComputePipelines"))
6285 return (PFN_vkVoidFunction) vkCreateComputePipelines;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006286 if (!strcmp(funcName, "vkCreateSampler"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006287 return (PFN_vkVoidFunction) vkCreateSampler;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006288 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006289 return (PFN_vkVoidFunction) vkCreateDescriptorSetLayout;
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05006290 if (!strcmp(funcName, "vkCreatePipelineLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006291 return (PFN_vkVoidFunction) vkCreatePipelineLayout;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006292 if (!strcmp(funcName, "vkCreateDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006293 return (PFN_vkVoidFunction) vkCreateDescriptorPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006294 if (!strcmp(funcName, "vkResetDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006295 return (PFN_vkVoidFunction) vkResetDescriptorPool;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006296 if (!strcmp(funcName, "vkAllocateDescriptorSets"))
6297 return (PFN_vkVoidFunction) vkAllocateDescriptorSets;
Tobin Ehlise735c692015-10-08 13:13:50 -06006298 if (!strcmp(funcName, "vkFreeDescriptorSets"))
6299 return (PFN_vkVoidFunction) vkFreeDescriptorSets;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08006300 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006301 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
Mark Lobodzinski39298632015-11-18 08:38:27 -07006302 if (!strcmp(funcName, "vkCreateCommandPool"))
6303 return (PFN_vkVoidFunction) vkCreateCommandPool;
6304 if (!strcmp(funcName, "vkDestroyCommandPool"))
6305 return (PFN_vkVoidFunction) vkDestroyCommandPool;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006306 if (!strcmp(funcName, "vkResetCommandPool"))
6307 return (PFN_vkVoidFunction) vkResetCommandPool;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006308 if (!strcmp(funcName, "vkAllocateCommandBuffers"))
6309 return (PFN_vkVoidFunction) vkAllocateCommandBuffers;
Mark Lobodzinski39298632015-11-18 08:38:27 -07006310 if (!strcmp(funcName, "vkFreeCommandBuffers"))
6311 return (PFN_vkVoidFunction) vkFreeCommandBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006312 if (!strcmp(funcName, "vkBeginCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006313 return (PFN_vkVoidFunction) vkBeginCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006314 if (!strcmp(funcName, "vkEndCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006315 return (PFN_vkVoidFunction) vkEndCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006316 if (!strcmp(funcName, "vkResetCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006317 return (PFN_vkVoidFunction) vkResetCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006318 if (!strcmp(funcName, "vkCmdBindPipeline"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006319 return (PFN_vkVoidFunction) vkCmdBindPipeline;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06006320 if (!strcmp(funcName, "vkCmdSetViewport"))
6321 return (PFN_vkVoidFunction) vkCmdSetViewport;
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06006322 if (!strcmp(funcName, "vkCmdSetScissor"))
6323 return (PFN_vkVoidFunction) vkCmdSetScissor;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06006324 if (!strcmp(funcName, "vkCmdSetLineWidth"))
6325 return (PFN_vkVoidFunction) vkCmdSetLineWidth;
6326 if (!strcmp(funcName, "vkCmdSetDepthBias"))
6327 return (PFN_vkVoidFunction) vkCmdSetDepthBias;
6328 if (!strcmp(funcName, "vkCmdSetBlendConstants"))
6329 return (PFN_vkVoidFunction) vkCmdSetBlendConstants;
6330 if (!strcmp(funcName, "vkCmdSetDepthBounds"))
6331 return (PFN_vkVoidFunction) vkCmdSetDepthBounds;
6332 if (!strcmp(funcName, "vkCmdSetStencilCompareMask"))
6333 return (PFN_vkVoidFunction) vkCmdSetStencilCompareMask;
6334 if (!strcmp(funcName, "vkCmdSetStencilWriteMask"))
6335 return (PFN_vkVoidFunction) vkCmdSetStencilWriteMask;
6336 if (!strcmp(funcName, "vkCmdSetStencilReference"))
6337 return (PFN_vkVoidFunction) vkCmdSetStencilReference;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006338 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006339 return (PFN_vkVoidFunction) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06006340 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006341 return (PFN_vkVoidFunction) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006342 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006343 return (PFN_vkVoidFunction) vkCmdBindIndexBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006344 if (!strcmp(funcName, "vkCmdDraw"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006345 return (PFN_vkVoidFunction) vkCmdDraw;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006346 if (!strcmp(funcName, "vkCmdDrawIndexed"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006347 return (PFN_vkVoidFunction) vkCmdDrawIndexed;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006348 if (!strcmp(funcName, "vkCmdDrawIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006349 return (PFN_vkVoidFunction) vkCmdDrawIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006350 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006351 return (PFN_vkVoidFunction) vkCmdDrawIndexedIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006352 if (!strcmp(funcName, "vkCmdDispatch"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006353 return (PFN_vkVoidFunction) vkCmdDispatch;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006354 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006355 return (PFN_vkVoidFunction) vkCmdDispatchIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006356 if (!strcmp(funcName, "vkCmdCopyBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006357 return (PFN_vkVoidFunction) vkCmdCopyBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006358 if (!strcmp(funcName, "vkCmdCopyImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006359 return (PFN_vkVoidFunction) vkCmdCopyImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006360 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006361 return (PFN_vkVoidFunction) vkCmdCopyBufferToImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006362 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006363 return (PFN_vkVoidFunction) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006364 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006365 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006366 if (!strcmp(funcName, "vkCmdFillBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006367 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006368 if (!strcmp(funcName, "vkCmdClearColorImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006369 return (PFN_vkVoidFunction) vkCmdClearColorImage;
Chris Forbesd9be82b2015-06-22 17:21:59 +12006370 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006371 return (PFN_vkVoidFunction) vkCmdClearDepthStencilImage;
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06006372 if (!strcmp(funcName, "vkCmdClearAttachments"))
6373 return (PFN_vkVoidFunction) vkCmdClearAttachments;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006374 if (!strcmp(funcName, "vkCmdResolveImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006375 return (PFN_vkVoidFunction) vkCmdResolveImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006376 if (!strcmp(funcName, "vkCmdSetEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006377 return (PFN_vkVoidFunction) vkCmdSetEvent;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006378 if (!strcmp(funcName, "vkCmdResetEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006379 return (PFN_vkVoidFunction) vkCmdResetEvent;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006380 if (!strcmp(funcName, "vkCmdWaitEvents"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006381 return (PFN_vkVoidFunction) vkCmdWaitEvents;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006382 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006383 return (PFN_vkVoidFunction) vkCmdPipelineBarrier;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006384 if (!strcmp(funcName, "vkCmdBeginQuery"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006385 return (PFN_vkVoidFunction) vkCmdBeginQuery;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006386 if (!strcmp(funcName, "vkCmdEndQuery"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006387 return (PFN_vkVoidFunction) vkCmdEndQuery;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006388 if (!strcmp(funcName, "vkCmdResetQueryPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006389 return (PFN_vkVoidFunction) vkCmdResetQueryPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006390 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006391 return (PFN_vkVoidFunction) vkCmdWriteTimestamp;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006392 if (!strcmp(funcName, "vkCreateFramebuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006393 return (PFN_vkVoidFunction) vkCreateFramebuffer;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006394 if (!strcmp(funcName, "vkCreateShaderModule"))
6395 return (PFN_vkVoidFunction) vkCreateShaderModule;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006396 if (!strcmp(funcName, "vkCreateRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006397 return (PFN_vkVoidFunction) vkCreateRenderPass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006398 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006399 return (PFN_vkVoidFunction) vkCmdBeginRenderPass;
Chia-I Wu08accc62015-07-07 11:50:03 +08006400 if (!strcmp(funcName, "vkCmdNextSubpass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006401 return (PFN_vkVoidFunction) vkCmdNextSubpass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006402 if (!strcmp(funcName, "vkCmdEndRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006403 return (PFN_vkVoidFunction) vkCmdEndRenderPass;
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06006404 if (!strcmp(funcName, "vkCmdExecuteCommands"))
6405 return (PFN_vkVoidFunction) vkCmdExecuteCommands;
Michael Lentineb887b0a2015-12-29 14:12:11 -06006406 if (!strcmp(funcName, "vkSetEvent"))
6407 return (PFN_vkVoidFunction) vkSetEvent;
Michael Lentine7b236262015-10-23 12:41:44 -07006408 if (!strcmp(funcName, "vkMapMemory"))
6409 return (PFN_vkVoidFunction) vkMapMemory;
Michael Lentineb887b0a2015-12-29 14:12:11 -06006410 if (!strcmp(funcName, "vkGetQueryPoolResults"))
6411 return (PFN_vkVoidFunction) vkGetQueryPoolResults;
Michael Lentine15a47882016-01-06 10:05:48 -06006412 if (!strcmp(funcName, "vkBindImageMemory"))
6413 return (PFN_vkVoidFunction) vkBindImageMemory;
6414 if (!strcmp(funcName, "vkQueueBindSparse"))
6415 return (PFN_vkVoidFunction) vkQueueBindSparse;
6416 if (!strcmp(funcName, "vkCreateSemaphore"))
6417 return (PFN_vkVoidFunction) vkCreateSemaphore;
Jon Ashburneab34492015-06-01 09:37:38 -06006418
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006419 if (dev == NULL)
6420 return NULL;
6421
6422 layer_data *dev_data;
6423 dev_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map);
6424
Michael Lentineabc5e922015-10-12 11:30:14 -05006425 if (dev_data->device_extensions.wsi_enabled)
6426 {
6427 if (!strcmp(funcName, "vkCreateSwapchainKHR"))
6428 return (PFN_vkVoidFunction) vkCreateSwapchainKHR;
6429 if (!strcmp(funcName, "vkDestroySwapchainKHR"))
6430 return (PFN_vkVoidFunction) vkDestroySwapchainKHR;
6431 if (!strcmp(funcName, "vkGetSwapchainImagesKHR"))
6432 return (PFN_vkVoidFunction) vkGetSwapchainImagesKHR;
Michael Lentine15a47882016-01-06 10:05:48 -06006433 if (!strcmp(funcName, "vkAcquireNextImageKHR"))
6434 return (PFN_vkVoidFunction) vkAcquireNextImageKHR;
Michael Lentineabc5e922015-10-12 11:30:14 -05006435 if (!strcmp(funcName, "vkQueuePresentKHR"))
6436 return (PFN_vkVoidFunction) vkQueuePresentKHR;
6437 }
6438
Tobin Ehlis0b632332015-10-07 09:38:40 -06006439 VkLayerDispatchTable* pTable = dev_data->device_dispatch_table;
6440 if (dev_data->device_extensions.debug_marker_enabled)
Jon Ashburn8fd08252015-05-28 16:25:02 -06006441 {
Jon Ashburn747f2b62015-06-18 15:02:58 -06006442 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006443 return (PFN_vkVoidFunction) vkCmdDbgMarkerBegin;
Jon Ashburn747f2b62015-06-18 15:02:58 -06006444 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006445 return (PFN_vkVoidFunction) vkCmdDbgMarkerEnd;
Jon Ashburneab34492015-06-01 09:37:38 -06006446 }
6447 {
Jon Ashburn8fd08252015-05-28 16:25:02 -06006448 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006449 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006450 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburnf6b33db2015-05-05 14:22:52 -06006451 }
6452}
6453
Chia-I Wu9ab61502015-11-06 06:42:02 +08006454VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Jon Ashburnf6b33db2015-05-05 14:22:52 -06006455{
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006456 if (!strcmp(funcName, "vkGetInstanceProcAddr"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006457 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006458 if (!strcmp(funcName, "vkGetDeviceProcAddr"))
6459 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06006460 if (!strcmp(funcName, "vkCreateInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006461 return (PFN_vkVoidFunction) vkCreateInstance;
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006462 if (!strcmp(funcName, "vkCreateDevice"))
6463 return (PFN_vkVoidFunction) vkCreateDevice;
Jon Ashburn3950e1b2015-05-20 09:00:28 -06006464 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006465 return (PFN_vkVoidFunction) vkDestroyInstance;
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -06006466 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
6467 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
6468 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
6469 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
6470 if (!strcmp(funcName, "vkEnumerateDeviceLayerProperties"))
6471 return (PFN_vkVoidFunction) vkEnumerateDeviceLayerProperties;
6472 if (!strcmp(funcName, "vkEnumerateDeviceExtensionProperties"))
6473 return (PFN_vkVoidFunction) vkEnumerateDeviceExtensionProperties;
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06006474
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006475 if (instance == NULL)
6476 return NULL;
6477
6478 PFN_vkVoidFunction fptr;
6479
6480 layer_data* my_data;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006481 my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06006482 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06006483 if (fptr)
6484 return fptr;
6485
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006486 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
6487 if (pTable->GetInstanceProcAddr == NULL)
6488 return NULL;
6489 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006490}