blob: c9e34bcbcf932a86fe9006051aa0870785edeb0d [file] [log] [blame]
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001/*
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002 *
Courtney Goeltzenleuchterfcbe16f2015-10-29 13:50:34 -06003 * Copyright (C) 2015 Valve Corporation
Michael Lentineb6986752015-10-06 14:56:18 -07004 * Copyright (C) 2015 Google, Inc.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060023 *
Tobin Ehlis88452832015-12-03 09:40:56 -070024 * Author: Cody Northrop <cnorthrop@google.com>
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060025 * Author: Michael Lentine <mlentine@google.com>
Tobin Ehlis88452832015-12-03 09:40:56 -070026 * Author: Tobin Ehlis <tobine@google.com>
27 * Author: Chia-I Wu <olv@google.com>
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070028 * Author: Chris Forbes <chrisf@ijw.co.nz>
Mark Lobodzinski78da8cb2015-12-28 15:51:07 -070029 * Author: Mark Lobodzinski <mark@lunarg.com>
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060030 */
31
Mark Lobodzinski78da8cb2015-12-28 15:51:07 -070032// Allow use of STL min and max functions in Windows
33#define NOMINMAX
34
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060035#include <stdio.h>
36#include <stdlib.h>
37#include <string.h>
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070038#include <assert.h>
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060039#include <unordered_map>
Michael Lentineb6986752015-10-06 14:56:18 -070040#include <unordered_set>
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070041#include <map>
42#include <string>
43#include <iostream>
44#include <algorithm>
Mark Lobodzinski39298632015-11-18 08:38:27 -070045#include <list>
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070046#include <spirv.hpp>
Tobin Ehlis88452832015-12-03 09:40:56 -070047#include <set>
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060048
Tobin Ehlisb835d1b2015-07-03 10:34:49 -060049#include "vk_loader_platform.h"
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060050#include "vk_dispatch_table_helper.h"
51#include "vk_struct_string_helper_cpp.h"
Tony Barbour18f71552015-04-22 11:36:22 -060052#if defined(__GNUC__)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060053#pragma GCC diagnostic ignored "-Wwrite-strings"
Tony Barbour18f71552015-04-22 11:36:22 -060054#endif
Tony Barbour18f71552015-04-22 11:36:22 -060055#if defined(__GNUC__)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060056#pragma GCC diagnostic warning "-Wwrite-strings"
Tony Barbour18f71552015-04-22 11:36:22 -060057#endif
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060058#include "vk_struct_size_helper.h"
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060059#include "draw_state.h"
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -060060#include "vk_layer_config.h"
Michael Lentine97eb7462015-11-20 09:48:52 -080061#include "vulkan/vk_debug_marker_layer.h"
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -060062#include "vk_layer_table.h"
63#include "vk_layer_debug_marker_table.h"
64#include "vk_layer_data.h"
65#include "vk_layer_logging.h"
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -060066#include "vk_layer_extension_utils.h"
Tobin Ehlisa1c28562015-10-23 16:00:08 -060067#include "vk_layer_utils.h"
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060068
Mark Lobodzinski31e5f282015-11-30 16:48:53 -070069// This definition controls whether image layout transitions are enabled/disabled.
70// disable until corner cases are fixed
71#define DISABLE_IMAGE_LAYOUT_VALIDATION
72
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070073using std::unordered_map;
74using std::unordered_set;
75
Tobin Ehlisac0ef842015-12-14 13:46:38 -070076// Track command pools and their command buffers
77struct CMD_POOL_INFO {
78 VkCommandPoolCreateFlags createFlags;
79 list<VkCommandBuffer> commandBuffers; // list container of cmd buffers allocated from this pool
80};
81
Tobin Ehlis0b632332015-10-07 09:38:40 -060082struct devExts {
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -070083 VkBool32 debug_marker_enabled;
Michael Lentineabc5e922015-10-12 11:30:14 -050084 VkBool32 wsi_enabled;
85 unordered_map<VkSwapchainKHR, SWAPCHAIN_NODE*> swapchainMap;
Tobin Ehlis0b632332015-10-07 09:38:40 -060086};
87
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070088// fwd decls
89struct shader_module;
90struct render_pass;
91
Cody Northrop55443ef2015-09-28 15:09:32 -060092struct layer_data {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -070093 debug_report_data* report_data;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070094 std::vector<VkDebugReportCallbackEXT> logging_callback;
Tobin Ehlis0b632332015-10-07 09:38:40 -060095 VkLayerDispatchTable* device_dispatch_table;
96 VkLayerInstanceDispatchTable* instance_dispatch_table;
97 devExts device_extensions;
Tobin Ehlisae82e7f2016-01-20 16:23:37 -070098 vector<VkQueue> queues; // all queues under given device
Michael Lentineb887b0a2015-12-29 14:12:11 -060099 unordered_set<VkCommandBuffer> inFlightCmdBuffers;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -0600100 // Layer specific data
Mark Lobodzinski39298632015-11-18 08:38:27 -0700101 unordered_map<VkSampler, unique_ptr<SAMPLER_NODE>> sampleMap;
102 unordered_map<VkImageView, unique_ptr<VkImageViewCreateInfo>> imageViewMap;
103 unordered_map<VkImage, unique_ptr<VkImageCreateInfo>> imageMap;
104 unordered_map<VkBufferView, unique_ptr<VkBufferViewCreateInfo>> bufferViewMap;
Michael Lentine700b0aa2015-10-30 17:57:32 -0700105 unordered_map<VkBuffer, BUFFER_NODE> bufferMap;
Mark Lobodzinski39298632015-11-18 08:38:27 -0700106 unordered_map<VkPipeline, PIPELINE_NODE*> pipelineMap;
Tobin Ehlisac0ef842015-12-14 13:46:38 -0700107 unordered_map<VkCommandPool, CMD_POOL_INFO> commandPoolMap;
Mark Lobodzinski39298632015-11-18 08:38:27 -0700108 unordered_map<VkDescriptorPool, DESCRIPTOR_POOL_NODE*> descriptorPoolMap;
109 unordered_map<VkDescriptorSet, SET_NODE*> setMap;
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -0700110 unordered_map<VkDescriptorSetLayout, LAYOUT_NODE*> descriptorSetLayoutMap;
Mark Lobodzinski39298632015-11-18 08:38:27 -0700111 unordered_map<VkPipelineLayout, PIPELINE_LAYOUT_NODE> pipelineLayoutMap;
112 unordered_map<VkDeviceMemory, VkImage> memImageMap;
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -0700113 unordered_map<VkFence, FENCE_NODE> fenceMap;
114 unordered_map<VkQueue, QUEUE_NODE> queueMap;
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]; }
Mark Youngd652d132016-01-25 13:37:06 -0700149 uint32_t offset() { return (uint32_t)(it - zero); }
Chris Forbesc7e2e202016-01-18 08:56:40 +1300150
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",
Mark Youngee3f3a22016-01-25 12:18:32 -07001124 "CB object %#" PRIxLEAST64 ": %s", (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
Tobin Ehlis75cd1c52016-01-21 10:21:04 -07002047 auto imgIt = my_data->imageLayoutMap.find(image);
2048 if (imgIt == my_data->imageLayoutMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002049 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 -07002050 "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 -06002051 } else {
2052 VkFormat format = (*imgIt).second->format;
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07002053 VkBool32 ds = vk_format_is_depth_or_stencil(format);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002054 switch (imageLayout) {
2055 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
2056 // Only Color bit must be set
2057 if ((aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) != VK_IMAGE_ASPECT_COLOR_BIT) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002058 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 -06002059 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 +08002060 " that does not have VK_IMAGE_ASPECT_COLOR_BIT set.", (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002061 }
2062 // format must NOT be DS
2063 if (ds) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002064 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 -06002065 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 +08002066 " 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 -06002067 }
2068 break;
2069 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
2070 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
2071 // Depth or stencil bit must be set, but both must NOT be set
2072 if (aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) {
2073 if (aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) {
2074 // both must NOT be set
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002075 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 -06002076 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with imageView %#" PRIxLEAST64 ""
Chia-I Wue2fc5522015-10-26 20:04:44 +08002077 " that has both STENCIL and DEPTH aspects set", (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002078 }
2079 } else if (!(aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)) {
2080 // Neither were set
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002081 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 -06002082 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout %s and imageView %#" PRIxLEAST64 ""
Chia-I Wue2fc5522015-10-26 20:04:44 +08002083 " that does not have STENCIL or DEPTH aspect set.", string_VkImageLayout(imageLayout), (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002084 }
2085 // format must be DS
2086 if (!ds) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002087 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 -06002088 DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout %s and imageView %#" PRIxLEAST64 ""
Chia-I Wue2fc5522015-10-26 20:04:44 +08002089 " 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 -06002090 }
2091 break;
2092 default:
2093 // anything to check for other layouts?
2094 break;
2095 }
2096 }
2097 }
2098 return skipCall;
2099}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002100
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002101// Verify that given bufferView is valid
2102static VkBool32 validateBufferView(const layer_data* my_data, const VkBufferView* pBufferView)
2103{
2104 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002105 auto sampIt = my_data->bufferViewMap.find(*pBufferView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002106 if (sampIt == my_data->bufferViewMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002107 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 +08002108 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid bufferView %#" PRIxLEAST64, (uint64_t) *pBufferView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002109 } else {
2110 // TODO : Any further checks we want to do on the bufferView?
2111 }
2112 return skipCall;
2113}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002114
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002115// Verify that given bufferInfo is valid
2116static VkBool32 validateBufferInfo(const layer_data* my_data, const VkDescriptorBufferInfo* pBufferInfo)
2117{
2118 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002119 auto sampIt = my_data->bufferMap.find(pBufferInfo->buffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002120 if (sampIt == my_data->bufferMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002121 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 +08002122 "vkUpdateDescriptorSets: Attempt to update descriptor where bufferInfo has invalid buffer %#" PRIxLEAST64, (uint64_t) pBufferInfo->buffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002123 } else {
2124 // TODO : Any further checks we want to do on the bufferView?
2125 }
2126 return skipCall;
2127}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002128
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002129static VkBool32 validateUpdateContents(const layer_data* my_data, const VkWriteDescriptorSet *pWDS, const VkDescriptorSetLayoutBinding* pLayoutBinding)
2130{
2131 VkBool32 skipCall = VK_FALSE;
2132 // First verify that for the given Descriptor type, the correct DescriptorInfo data is supplied
2133 VkBufferView* pBufferView = NULL;
2134 const VkSampler* pSampler = NULL;
2135 VkImageView* pImageView = NULL;
2136 VkImageLayout* pImageLayout = NULL;
2137 VkDescriptorBufferInfo* pBufferInfo = NULL;
2138 VkBool32 immutable = VK_FALSE;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002139 uint32_t i = 0;
2140 // For given update type, verify that update contents are correct
2141 switch (pWDS->descriptorType) {
2142 case VK_DESCRIPTOR_TYPE_SAMPLER:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002143 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002144 skipCall |= validateSampler(my_data, &(pWDS->pImageInfo[i].sampler), immutable);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002145 }
2146 break;
2147 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002148 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002149 if (NULL == pLayoutBinding->pImmutableSamplers) {
2150 pSampler = &(pWDS->pImageInfo[i].sampler);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002151 if (immutable) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002152 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT, (uint64_t) *pSampler, __LINE__, DRAWSTATE_INCONSISTENT_IMMUTABLE_SAMPLER_UPDATE, "DS",
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002153 "vkUpdateDescriptorSets: Update #%u is not an immutable sampler %#" PRIxLEAST64 ", but previous update(s) from this "
2154 "VkWriteDescriptorSet struct used an immutable sampler. All updates from a single struct must either "
Chia-I Wue2fc5522015-10-26 20:04:44 +08002155 "use immutable or non-immutable samplers.", i, (uint64_t) *pSampler);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002156 }
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002157 } else {
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002158 if (i>0 && !immutable) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002159 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 -06002160 "vkUpdateDescriptorSets: Update #%u is an immutable sampler, but previous update(s) from this "
2161 "VkWriteDescriptorSet struct used a non-immutable sampler. All updates from a single struct must either "
2162 "use immutable or non-immutable samplers.", i);
2163 }
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002164 immutable = VK_TRUE;
2165 pSampler = &(pLayoutBinding->pImmutableSamplers[i]);
2166 }
2167 skipCall |= validateSampler(my_data, pSampler, immutable);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002168 }
2169 // Intentionally fall through here to also validate image stuff
2170 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2171 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
2172 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002173 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002174 skipCall |= validateImageView(my_data, &(pWDS->pImageInfo[i].imageView), pWDS->pImageInfo[i].imageLayout);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002175 }
2176 break;
2177 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2178 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002179 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002180 skipCall |= validateBufferView(my_data, &(pWDS->pTexelBufferView[i]));
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002181 }
2182 break;
2183 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2184 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2185 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2186 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002187 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002188 skipCall |= validateBufferInfo(my_data, &(pWDS->pBufferInfo[i]));
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002189 }
2190 break;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002191 }
2192 return skipCall;
2193}
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002194// Validate that given set is valid and that it's not being used by an in-flight CmdBuffer
2195// func_str is the name of the calling function
2196// Return VK_FALSE if no errors occur
2197// Return VK_TRUE if validation error occurs and callback returns VK_TRUE (to skip upcoming API call down the chain)
2198VkBool32 validateIdleDescriptorSet(const layer_data* my_data, VkDescriptorSet set, std::string func_str) {
2199 VkBool32 skip_call = VK_FALSE;
2200 auto set_node = my_data->setMap.find(set);
2201 if (set_node == my_data->setMap.end()) {
Mark Youngee3f3a22016-01-25 12:18:32 -07002202 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t)(set), __LINE__, DRAWSTATE_DOUBLE_DESTROY, "DS",
2203 "Cannot call %s() on descriptor set %" PRIxLEAST64 " that has not been allocated.", func_str.c_str(), (uint64_t)(set));
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002204 } else {
2205 if (set_node->second->in_use.load()) {
Mark Youngee3f3a22016-01-25 12:18:32 -07002206 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t)(set), __LINE__, DRAWSTATE_OBJECT_INUSE, "DS",
2207 "Cannot call %s() on descriptor set %" PRIxLEAST64 " that is in use by a command buffer.", func_str.c_str(), (uint64_t)(set));
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002208 }
2209 }
2210 return skip_call;
2211}
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002212// update DS mappings based on write and copy update arrays
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08002213static 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 -06002214{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002215 VkBool32 skipCall = VK_FALSE;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002216
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002217 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002218 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002219 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002220 // Validate Write updates
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002221 uint32_t i = 0;
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08002222 for (i=0; i < descriptorWriteCount; i++) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002223 VkDescriptorSet ds = pWDS[i].dstSet;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002224 SET_NODE* pSet = my_data->setMap[ds];
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002225 // Set being updated cannot be in-flight
2226 if ((skipCall = validateIdleDescriptorSet(my_data, ds, "VkUpdateDescriptorSets")) == VK_TRUE)
2227 return skipCall;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002228 GENERIC_HEADER* pUpdate = (GENERIC_HEADER*) &pWDS[i];
Tobin Ehlis793ad302015-04-03 12:01:11 -06002229 pLayout = pSet->pLayout;
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002230 // First verify valid update struct
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06002231 if ((skipCall = validUpdateStruct(my_data, device, pUpdate)) == VK_TRUE) {
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002232 break;
2233 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002234 uint32_t binding = 0, endIndex = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002235 binding = pWDS[i].dstBinding;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002236 // Make sure that layout being updated has the binding being updated
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002237 if (pLayout->bindings.find(binding) == pLayout->bindings.end()) {
Mark Young93ecb1d2016-01-13 13:47:16 -07002238 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t)(ds), __LINE__, DRAWSTATE_INVALID_UPDATE_INDEX, "DS",
2239 "Descriptor Set %" PRIu64 " does not have binding to match update binding %u for update type %s!", (uint64_t)(ds), binding, string_VkStructureType(pUpdate->sType));
Tobin Ehlis9c536442015-06-19 13:00:59 -06002240 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06002241 // Next verify that update falls within size of given binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002242 endIndex = getUpdateEndIndex(my_data, device, pLayout, binding, pWDS[i].dstArrayElement, pUpdate);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002243 if (getBindingEndIndex(pLayout, binding) < endIndex) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06002244 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002245 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Mark Young93ecb1d2016-01-13 13:47:16 -07002246 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 -06002247 "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 -06002248 } else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002249 uint32_t startIndex;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002250 startIndex = getUpdateStartIndex(my_data, device, pLayout, binding, pWDS[i].dstArrayElement, pUpdate);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002251 // Layout bindings match w/ update, now verify that update type & stageFlags are the same for entire update
2252 if ((skipCall = validateUpdateConsistency(my_data, device, pLayout, pUpdate, startIndex, endIndex)) == VK_FALSE) {
2253 // The update is within bounds and consistent, but need to make sure contents make sense as well
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002254 if ((skipCall = validateUpdateContents(my_data, &pWDS[i], &pLayout->createInfo.pBindings[binding])) == VK_FALSE) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002255 // Update is good. Save the update info
2256 // Create new update struct for this set's shadow copy
2257 GENERIC_HEADER* pNewNode = NULL;
2258 skipCall |= shadowUpdateNode(my_data, device, pUpdate, &pNewNode);
2259 if (NULL == pNewNode) {
Mark Young93ecb1d2016-01-13 13:47:16 -07002260 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 -06002261 "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
2262 } else {
2263 // Insert shadow node into LL of updates for this set
2264 pNewNode->pNext = pSet->pUpdateStructs;
2265 pSet->pUpdateStructs = pNewNode;
2266 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002267 for (uint32_t j = startIndex; j <= endIndex; j++) {
2268 assert(j<pSet->descriptorCount);
2269 pSet->ppDescriptors[j] = pNewNode;
2270 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002271 }
2272 }
2273 }
2274 }
2275 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002276 }
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002277 // Now validate copy updates
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08002278 for (i=0; i < descriptorCopyCount; ++i) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002279 SET_NODE *pSrcSet = NULL, *pDstSet = NULL;
2280 LAYOUT_NODE *pSrcLayout = NULL, *pDstLayout = NULL;
2281 uint32_t srcStartIndex = 0, srcEndIndex = 0, dstStartIndex = 0, dstEndIndex = 0;
2282 // For each copy make sure that update falls within given layout and that types match
Chia-I Wue2fc5522015-10-26 20:04:44 +08002283 pSrcSet = my_data->setMap[pCDS[i].srcSet];
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002284 pDstSet = my_data->setMap[pCDS[i].dstSet];
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002285 // Set being updated cannot be in-flight
2286 if ((skipCall = validateIdleDescriptorSet(my_data, pDstSet->set, "VkUpdateDescriptorSets")) == VK_TRUE)
2287 return skipCall;
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002288 pSrcLayout = pSrcSet->pLayout;
2289 pDstLayout = pDstSet->pLayout;
2290 // Validate that src binding is valid for src set layout
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002291 if (pSrcLayout->bindings.find(pCDS[i].srcBinding) == pSrcLayout->bindings.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002292 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 -06002293 "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 +08002294 i, pCDS[i].srcBinding, (uint64_t) pSrcLayout->layout, pSrcLayout->createInfo.bindingCount-1);
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002295 } else if (pDstLayout->bindings.find(pCDS[i].dstBinding) == pDstLayout->bindings.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002296 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 +08002297 "Copy descriptor update %u has dstBinding %u which is out of bounds for underlying SetLayout %#" PRIxLEAST64 " which only has bindings 0-%u.",
2298 i, pCDS[i].dstBinding, (uint64_t) pDstLayout->layout, pDstLayout->createInfo.bindingCount-1);
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002299 } else {
2300 // Proceed with validation. Bindings are ok, but make sure update is within bounds of given layout
2301 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 +08002302 dstEndIndex = getUpdateEndIndex(my_data, device, pDstLayout, pCDS[i].dstBinding, pCDS[i].dstArrayElement, (const GENERIC_HEADER*)&(pCDS[i]));
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002303 if (getBindingEndIndex(pSrcLayout, pCDS[i].srcBinding) < srcEndIndex) {
2304 pLayoutCI = &pSrcLayout->createInfo;
2305 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002306 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 -06002307 "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 +08002308 } else if (getBindingEndIndex(pDstLayout, pCDS[i].dstBinding) < dstEndIndex) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002309 pLayoutCI = &pDstLayout->createInfo;
2310 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002311 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 +08002312 "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 -06002313 } else {
2314 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 +08002315 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 +08002316 for (uint32_t j=0; j<pCDS[i].descriptorCount; ++j) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002317 // For copy just make sure that the types match and then perform the update
2318 if (pSrcLayout->descriptorTypes[srcStartIndex+j] != pDstLayout->descriptorTypes[dstStartIndex+j]) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002319 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 -06002320 "Copy descriptor update index %u, update count #%u, has src update descriptor type %s that does not match overlapping dest descriptor type of %s!",
2321 i, j+1, string_VkDescriptorType(pSrcLayout->descriptorTypes[srcStartIndex+j]), string_VkDescriptorType(pDstLayout->descriptorTypes[dstStartIndex+j]));
2322 } else {
2323 // point dst descriptor at corresponding src descriptor
Tobin Ehlisf6585052015-12-17 11:48:42 -07002324 // TODO : This may be a hole. I believe copy should be its own copy,
2325 // otherwise a subsequent write update to src will incorrectly affect the copy
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002326 pDstSet->ppDescriptors[j+dstStartIndex] = pSrcSet->ppDescriptors[j+srcStartIndex];
2327 }
2328 }
2329 }
2330 }
2331 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002332 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002333 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002334}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002335
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002336// Verify that given pool has descriptors that are being requested for allocation
Mark Lobodzinski39298632015-11-18 08:38:27 -07002337static 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 -06002338{
2339 VkBool32 skipCall = VK_FALSE;
2340 uint32_t i = 0, j = 0;
2341 for (i=0; i<count; ++i) {
2342 LAYOUT_NODE* pLayout = getLayoutNode(dev_data, pSetLayouts[i]);
2343 if (NULL == pLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002344 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 +08002345 "Unable to find set layout node for layout %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pSetLayouts[i]);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002346 } else {
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002347 uint32_t typeIndex = 0, poolSizeCount = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002348 for (j=0; j<pLayout->createInfo.bindingCount; ++j) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002349 typeIndex = static_cast<uint32_t>(pLayout->createInfo.pBindings[j].descriptorType);
2350 poolSizeCount = pLayout->createInfo.pBindings[j].descriptorCount;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002351 if (poolSizeCount > pPoolNode->availableDescriptorTypeCount[typeIndex]) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002352 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 -06002353 "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 -07002354 poolSizeCount, string_VkDescriptorType(pLayout->createInfo.pBindings[j].descriptorType), (uint64_t) pPoolNode->pool, pPoolNode->availableDescriptorTypeCount[typeIndex]);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002355 } else { // Decrement available descriptors of this type
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002356 pPoolNode->availableDescriptorTypeCount[typeIndex] -= poolSizeCount;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002357 }
2358 }
2359 }
2360 }
2361 return skipCall;
2362}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002363
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002364// Free the shadowed update node for this Set
2365// NOTE : Calls to this function should be wrapped in mutex
2366static void freeShadowUpdateTree(SET_NODE* pSet)
2367{
2368 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
2369 pSet->pUpdateStructs = NULL;
2370 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
2371 // Clear the descriptor mappings as they will now be invalid
2372 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
2373 while(pShadowUpdate) {
2374 pFreeUpdate = pShadowUpdate;
2375 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
2376 uint32_t index = 0;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002377 VkWriteDescriptorSet * pWDS = NULL;
2378 VkCopyDescriptorSet * pCDS = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002379 void** ppToFree = NULL;
2380 switch (pFreeUpdate->sType)
2381 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002382 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
2383 pWDS = (VkWriteDescriptorSet*)pFreeUpdate;
Tony Barbourb1947942015-11-02 11:46:29 -07002384 switch (pWDS->descriptorType) {
2385 case VK_DESCRIPTOR_TYPE_SAMPLER:
2386 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
2387 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2388 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
2389 {
2390 delete[] pWDS->pImageInfo;
2391 }
2392 break;
2393 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2394 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
2395 {
2396 delete[] pWDS->pTexelBufferView;
2397 }
2398 break;
2399 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2400 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2401 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2402 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
2403 {
2404 delete[] pWDS->pBufferInfo;
2405 }
2406 break;
2407 default:
2408 break;
Courtney Goeltzenleuchteraa132e72015-10-22 15:31:56 -06002409 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002410 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002411 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002412 break;
2413 default:
2414 assert(0);
2415 break;
2416 }
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002417 delete pFreeUpdate;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002418 }
2419}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002420
Tobin Ehlis793ad302015-04-03 12:01:11 -06002421// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002422// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002423static void deletePools(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002424{
Mark Lobodzinski39298632015-11-18 08:38:27 -07002425 if (my_data->descriptorPoolMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06002426 return;
Mark Lobodzinski39298632015-11-18 08:38:27 -07002427 for (auto ii=my_data->descriptorPoolMap.begin(); ii!=my_data->descriptorPoolMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002428 SET_NODE* pSet = (*ii).second->pSets;
2429 SET_NODE* pFreeSet = pSet;
2430 while (pSet) {
2431 pFreeSet = pSet;
2432 pSet = pSet->pNext;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002433 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002434 // Free Update shadow struct tree
2435 freeShadowUpdateTree(pFreeSet);
2436 if (pFreeSet->ppDescriptors) {
Chris Forbes02038792015-06-04 10:49:27 +12002437 delete[] pFreeSet->ppDescriptors;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002438 }
2439 delete pFreeSet;
2440 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002441 delete (*ii).second;
2442 }
Mark Lobodzinski39298632015-11-18 08:38:27 -07002443 my_data->descriptorPoolMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002444}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002445
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002446// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002447// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002448static void deleteLayouts(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002449{
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07002450 if (my_data->descriptorSetLayoutMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06002451 return;
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07002452 for (auto ii=my_data->descriptorSetLayoutMap.begin(); ii!=my_data->descriptorSetLayoutMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002453 LAYOUT_NODE* pLayout = (*ii).second;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002454 if (pLayout->createInfo.pBindings) {
Chia-I Wud50a7d72015-10-26 20:48:51 +08002455 for (uint32_t i=0; i<pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002456 if (pLayout->createInfo.pBindings[i].pImmutableSamplers)
2457 delete[] pLayout->createInfo.pBindings[i].pImmutableSamplers;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002458 }
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002459 delete[] pLayout->createInfo.pBindings;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002460 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002461 delete pLayout;
2462 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07002463 my_data->descriptorSetLayoutMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002464}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002465
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002466// Currently clearing a set is removing all previous updates to that set
2467// TODO : Validate if this is correct clearing behavior
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002468static void clearDescriptorSet(layer_data* my_data, VkDescriptorSet set)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002469{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002470 SET_NODE* pSet = getSetNode(my_data, set);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002471 if (!pSet) {
2472 // TODO : Return error
Tobin Ehlisce132d82015-06-19 15:07:05 -06002473 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002474 loader_platform_thread_lock_mutex(&globalLock);
2475 freeShadowUpdateTree(pSet);
2476 loader_platform_thread_unlock_mutex(&globalLock);
2477 }
2478}
2479
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002480static void clearDescriptorPool(layer_data* my_data, const VkDevice device, const VkDescriptorPool pool, VkDescriptorPoolResetFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002481{
Mark Lobodzinski39298632015-11-18 08:38:27 -07002482 DESCRIPTOR_POOL_NODE* pPool = getPoolNode(my_data, pool);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002483 if (!pPool) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002484 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 +08002485 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkResetDescriptorPool() call", (uint64_t) pool);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002486 } else {
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002487 // TODO: validate flags
Tobin Ehlis793ad302015-04-03 12:01:11 -06002488 // For every set off of this pool, clear it
2489 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002490 while (pSet) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002491 clearDescriptorSet(my_data, pSet->set);
Mark Lobodzinskidcce0792016-01-04 09:40:19 -07002492 pSet = pSet->pNext;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002493 }
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002494 // Reset available count to max count for this pool
2495 for (uint32_t i=0; i<pPool->availableDescriptorTypeCount.size(); ++i) {
2496 pPool->availableDescriptorTypeCount[i] = pPool->maxDescriptorTypeCount[i];
2497 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002498 }
2499}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002500
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002501// For given CB object, fetch associated CB Node from map
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002502static GLOBAL_CB_NODE* getCBNode(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002503{
2504 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002505 if (my_data->commandBufferMap.count(cb) == 0) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002506 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002507 // TODO : How to pass cb as srcObj here?
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002508 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",
Mark Youngee3f3a22016-01-25 12:18:32 -07002509 "Attempt to use CommandBuffer %#" PRIxLEAST64 " that doesn't exist!", (uint64_t)(cb));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002510 return NULL;
2511 }
2512 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002513 return my_data->commandBufferMap[cb];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002514}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002515
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002516// Free all CB Nodes
2517// NOTE : Calls to this function should be wrapped in mutex
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002518static void deleteCommandBuffers(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002519{
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002520 if (my_data->commandBufferMap.size() <= 0) {
David Pinedod8f83d82015-04-27 16:36:17 -06002521 return;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002522 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002523 for (auto ii=my_data->commandBufferMap.begin(); ii!=my_data->commandBufferMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002524 delete (*ii).second;
2525 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002526 my_data->commandBufferMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002527}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002528
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002529static 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 -06002530{
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002531 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 -07002532 (uint64_t)cb, __LINE__, DRAWSTATE_NO_BEGIN_COMMAND_BUFFER, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002533 "You must call vkBeginCommandBuffer() before this call to %s", caller_name);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002534}
Michael Lentine3dea6512015-10-28 15:55:18 -07002535
Mark Youngb20a6a82016-01-07 15:41:43 -07002536VkBool32 validateCmdsInCmdBuffer(const layer_data* dev_data, const GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd_type) {
2537 if (!pCB->activeRenderPass) return VK_FALSE;
2538 VkBool32 skip_call = VK_FALSE;
Michael Lentine2e068b22015-12-29 16:05:27 -06002539 if (pCB->activeSubpassContents == VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS && cmd_type != CMD_EXECUTECOMMANDS) {
2540 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
2541 DRAWSTATE_INVALID_COMMAND_BUFFER, "DS", "Commands cannot be called in a subpass using secondary command buffers.");
2542 } else if (pCB->activeSubpassContents == VK_SUBPASS_CONTENTS_INLINE && cmd_type == CMD_EXECUTECOMMANDS) {
2543 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
2544 DRAWSTATE_INVALID_COMMAND_BUFFER, "DS", "vkCmdExecuteCommands() cannot be called in a subpass using inline commands.");
2545 }
Michael Lentine3dea6512015-10-28 15:55:18 -07002546 return skip_call;
2547}
2548
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002549// Add specified CMD to the CmdBuffer in given pCB, flagging errors if CB is not
2550// in the recording state or if there's an issue with the Cmd ordering
2551static 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 -06002552{
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002553 VkBool32 skipCall = VK_FALSE;
2554 if (pCB->state != CB_RECORDING) {
2555 skipCall |= report_error_no_cb_begin(my_data, pCB->commandBuffer, caller_name);
2556 skipCall |= validateCmdsInCmdBuffer(my_data, pCB, cmd);
Tobin Ehlis9a874302016-01-20 10:25:29 -07002557 CMD_NODE cmdNode = {};
2558 // init cmd node and append to end of cmd LL
2559 cmdNode.cmdNumber = ++pCB->numCmds;
2560 cmdNode.type = cmd;
2561 pCB->cmds.push_back(cmdNode);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002562 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002563 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002564}
Tobin Ehlisef694652016-01-19 12:03:34 -07002565// Reset the command buffer state
2566// Maintain the createInfo and set state to CB_NEW, but clear all other state
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002567static void resetCB(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002568{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002569 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002570 if (pCB) {
Tobin Ehlis9a874302016-01-20 10:25:29 -07002571 pCB->cmds.clear();
Tobin Ehlisef694652016-01-19 12:03:34 -07002572 // Reset CB state (note that createInfo is not cleared)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002573 pCB->commandBuffer = cb;
Michael Lentineabc5e922015-10-12 11:30:14 -05002574 memset(&pCB->beginInfo, 0, sizeof(VkCommandBufferBeginInfo));
Tobin Ehliscd5bfd82016-01-19 13:12:52 -07002575 memset(&pCB->inheritanceInfo, 0, sizeof(VkCommandBufferInheritanceInfo));
Michael Lentineabc5e922015-10-12 11:30:14 -05002576 pCB->fence = 0;
2577 pCB->numCmds = 0;
2578 memset(pCB->drawCount, 0, NUM_DRAW_TYPES * sizeof(uint64_t));
2579 pCB->state = CB_NEW;
2580 pCB->submitCount = 0;
2581 pCB->status = 0;
Michael Lentineabc5e922015-10-12 11:30:14 -05002582 pCB->lastBoundPipeline = 0;
2583 pCB->viewports.clear();
2584 pCB->scissors.clear();
2585 pCB->lineWidth = 0;
2586 pCB->depthBiasConstantFactor = 0;
2587 pCB->depthBiasClamp = 0;
2588 pCB->depthBiasSlopeFactor = 0;
2589 memset(pCB->blendConstants, 0, 4 * sizeof(float));
2590 pCB->minDepthBounds = 0;
2591 pCB->maxDepthBounds = 0;
2592 memset(&pCB->front, 0, sizeof(stencil_data));
2593 memset(&pCB->back, 0, sizeof(stencil_data));
2594 pCB->lastBoundDescriptorSet = 0;
2595 pCB->lastBoundPipelineLayout = 0;
2596 pCB->activeRenderPass = 0;
2597 pCB->activeSubpass = 0;
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002598 pCB->activeSets.clear();
Michael Lentineabc5e922015-10-12 11:30:14 -05002599 pCB->framebuffer = 0;
Michael Lentineabc5e922015-10-12 11:30:14 -05002600 pCB->boundDescriptorSets.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07002601 pCB->drawData.clear();
2602 pCB->currentDrawData.buffers.clear();
Michael Lentineabc5e922015-10-12 11:30:14 -05002603 pCB->imageLayoutMap.clear();
Michael Lentineb887b0a2015-12-29 14:12:11 -06002604 pCB->waitedEvents.clear();
2605 pCB->waitedEventsBeforeQueryReset.clear();
2606 pCB->queryToStateMap.clear();
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07002607 pCB->secondaryCommandBuffers.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002608 }
2609}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002610
Tobin Ehlis963a4042015-09-29 08:18:34 -06002611// Set PSO-related status bits for CB, including dynamic state set via PSO
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002612static void set_cb_pso_status(GLOBAL_CB_NODE* pCB, const PIPELINE_NODE* pPipe)
2613{
2614 for (uint32_t i = 0; i < pPipe->cbStateCI.attachmentCount; i++) {
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002615 if (0 != pPipe->pAttachments[i].colorWriteMask) {
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002616 pCB->status |= CBSTATUS_COLOR_BLEND_WRITE_ENABLE;
2617 }
2618 }
2619 if (pPipe->dsStateCI.depthWriteEnable) {
Cody Northrop82485a82015-08-18 15:21:16 -06002620 pCB->status |= CBSTATUS_DEPTH_WRITE_ENABLE;
2621 }
Cody Northrop82485a82015-08-18 15:21:16 -06002622 if (pPipe->dsStateCI.stencilTestEnable) {
2623 pCB->status |= CBSTATUS_STENCIL_TEST_ENABLE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002624 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06002625 // Account for any dynamic state not set via this PSO
2626 if (!pPipe->dynStateCI.dynamicStateCount) { // All state is static
2627 pCB->status = CBSTATUS_ALL;
2628 } else {
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002629 // First consider all state on
2630 // Then unset any state that's noted as dynamic in PSO
2631 // Finally OR that into CB statemask
2632 CBStatusFlags psoDynStateMask = CBSTATUS_ALL;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002633 for (uint32_t i=0; i < pPipe->dynStateCI.dynamicStateCount; i++) {
2634 switch (pPipe->dynStateCI.pDynamicStates[i]) {
2635 case VK_DYNAMIC_STATE_VIEWPORT:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002636 psoDynStateMask &= ~CBSTATUS_VIEWPORT_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002637 break;
2638 case VK_DYNAMIC_STATE_SCISSOR:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002639 psoDynStateMask &= ~CBSTATUS_SCISSOR_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002640 break;
2641 case VK_DYNAMIC_STATE_LINE_WIDTH:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002642 psoDynStateMask &= ~CBSTATUS_LINE_WIDTH_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002643 break;
2644 case VK_DYNAMIC_STATE_DEPTH_BIAS:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002645 psoDynStateMask &= ~CBSTATUS_DEPTH_BIAS_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002646 break;
2647 case VK_DYNAMIC_STATE_BLEND_CONSTANTS:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002648 psoDynStateMask &= ~CBSTATUS_BLEND_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002649 break;
2650 case VK_DYNAMIC_STATE_DEPTH_BOUNDS:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002651 psoDynStateMask &= ~CBSTATUS_DEPTH_BOUNDS_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002652 break;
2653 case VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002654 psoDynStateMask &= ~CBSTATUS_STENCIL_READ_MASK_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002655 break;
2656 case VK_DYNAMIC_STATE_STENCIL_WRITE_MASK:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002657 psoDynStateMask &= ~CBSTATUS_STENCIL_WRITE_MASK_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002658 break;
2659 case VK_DYNAMIC_STATE_STENCIL_REFERENCE:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002660 psoDynStateMask &= ~CBSTATUS_STENCIL_REFERENCE_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002661 break;
2662 default:
2663 // TODO : Flag error here
2664 break;
2665 }
2666 }
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002667 pCB->status |= psoDynStateMask;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002668 }
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002669}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002670
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002671// Print the last bound Gfx Pipeline
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002672static VkBool32 printPipeline(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002673{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002674 VkBool32 skipCall = VK_FALSE;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002675 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002676 if (pCB) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002677 PIPELINE_NODE *pPipeTrav = getPipeline(my_data, pCB->lastBoundPipeline);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002678 if (!pPipeTrav) {
2679 // nothing to print
Tobin Ehlisce132d82015-06-19 15:07:05 -06002680 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002681 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 -08002682 "%s", vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002683 }
2684 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002685 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002686}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002687
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002688// Print details of DS config to stdout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002689static VkBool32 printDSConfig(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002690{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002691 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002692 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 -06002693 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis93f89e82015-06-09 08:39:32 -06002694 if (pCB && pCB->lastBoundDescriptorSet) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002695 SET_NODE* pSet = getSetNode(my_data, pCB->lastBoundDescriptorSet);
Mark Lobodzinski39298632015-11-18 08:38:27 -07002696 DESCRIPTOR_POOL_NODE* pPool = getPoolNode(my_data, pSet->pool);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002697 // Print out pool details
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002698 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 +08002699 "Details for pool %#" PRIxLEAST64 ".", (uint64_t) pPool->pool);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002700 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002701 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 -06002702 "%s", poolStr.c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002703 // Print out set details
2704 char prefix[10];
2705 uint32_t index = 0;
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002706 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 +08002707 "Details for descriptor set %#" PRIxLEAST64 ".", (uint64_t) pSet->set);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002708 LAYOUT_NODE* pLayout = pSet->pLayout;
2709 // Print layout details
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002710 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
Mark Young93ecb1d2016-01-13 13:47:16 -07002711 "Layout #%u, (object %#" PRIxLEAST64 ") for DS %#" PRIxLEAST64 ".", index+1, (uint64_t)(pLayout->layout), (uint64_t)(pSet->set));
Tobin Ehlis793ad302015-04-03 12:01:11 -06002712 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002713 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002714 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 -06002715 "%s", DSLstr.c_str());
Tobin Ehlis793ad302015-04-03 12:01:11 -06002716 index++;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002717 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
2718 if (pUpdate) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002719 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 +08002720 "Update Chain [UC] for descriptor set %#" PRIxLEAST64 ":", (uint64_t) pSet->set);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002721 sprintf(prefix, " [UC] ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002722 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 -08002723 "%s", dynamic_display(pUpdate, prefix).c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002724 // TODO : If there is a "view" associated with this update, print CI for that view
Tobin Ehlisce132d82015-06-19 15:07:05 -06002725 } else {
Tobin Ehlisbf081f32015-06-15 08:41:17 -06002726 if (0 != pSet->descriptorCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002727 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 +08002728 "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 -06002729 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002730 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 +08002731 "FYI: No descriptors in descriptor set %#" PRIxLEAST64 ".", (uint64_t) pSet->set);
Tobin Ehlisbf081f32015-06-15 08:41:17 -06002732 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002733 }
2734 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002735 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002736}
2737
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002738static void printCB(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002739{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002740 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis9a874302016-01-20 10:25:29 -07002741 if (pCB && pCB->cmds.size() > 0) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002742 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 -06002743 "Cmds in CB %p", (void*)cb);
Tobin Ehlis9a874302016-01-20 10:25:29 -07002744 vector<CMD_NODE> cmds = pCB->cmds;
2745 for (auto ii=cmds.begin(); ii!=cmds.end(); ++ii) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002746 // TODO : Need to pass cb as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002747 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 -07002748 " CMD#%" PRIu64 ": %s", (*ii).cmdNumber, cmdTypeToString((*ii).type).c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002749 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002750 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002751 // Nothing to print
2752 }
2753}
2754
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002755static VkBool32 synchAndPrintDSConfig(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002756{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002757 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002758 if (!(my_data->report_data->active_flags & VK_DEBUG_REPORT_INFO_BIT_EXT)) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002759 return skipCall;
Mike Stroyanba35e352015-08-12 17:11:28 -06002760 }
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002761 skipCall |= printDSConfig(my_data, cb);
2762 skipCall |= printPipeline(my_data, cb);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002763 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002764}
2765
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002766// Flags validation error if the associated call is made inside a render pass. The apiName
2767// routine should ONLY be called outside a render pass.
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06002768static VkBool32 insideRenderPass(const layer_data* my_data, GLOBAL_CB_NODE *pCB, const char *apiName)
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002769{
2770 VkBool32 inside = VK_FALSE;
2771 if (pCB->activeRenderPass) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002772 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 -07002773 (uint64_t)pCB->commandBuffer, __LINE__, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002774 "%s: It is invalid to issue this call inside an active render pass (%#" PRIxLEAST64 ")",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002775 apiName, (uint64_t) pCB->activeRenderPass);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002776 }
2777 return inside;
2778}
2779
2780// Flags validation error if the associated call is made outside a render pass. The apiName
2781// routine should ONLY be called inside a render pass.
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06002782static VkBool32 outsideRenderPass(const layer_data* my_data, GLOBAL_CB_NODE *pCB, const char *apiName)
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002783{
2784 VkBool32 outside = VK_FALSE;
Mark Lobodzinski74635932015-12-18 15:35:38 -07002785 if (((pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) &&
2786 (!pCB->activeRenderPass)) ||
2787 ((pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) &&
2788 (!pCB->activeRenderPass) &&
2789 !(pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT))) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002790 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 -07002791 (uint64_t)pCB->commandBuffer, __LINE__, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002792 "%s: This call must be issued inside an active render pass.", apiName);
2793 }
2794 return outside;
2795}
2796
Courtney Goeltzenleuchter6d8e8182015-11-25 14:31:49 -07002797static void init_draw_state(layer_data *my_data, const VkAllocationCallbacks *pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002798{
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002799 uint32_t report_flags = 0;
2800 uint32_t debug_action = 0;
2801 FILE *log_output = NULL;
2802 const char *option_str;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002803 VkDebugReportCallbackEXT callback;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002804 // initialize DrawState options
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002805 report_flags = getLayerOptionFlags("DrawStateReportFlags", 0);
2806 getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &debug_action);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002807
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002808 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002809 {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002810 option_str = getLayerOption("DrawStateLogFilename");
Tobin Ehlisb1df55e2015-09-15 09:55:54 -06002811 log_output = getLayerLogOutput(option_str, "DrawState");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002812 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002813 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002814 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002815 dbgInfo.pfnCallback = log_callback;
2816 dbgInfo.pUserData = log_output;
2817 dbgInfo.flags = report_flags;
2818 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002819 my_data->logging_callback.push_back(callback);
2820 }
2821
2822 if (debug_action & VK_DBG_LAYER_ACTION_DEBUG_OUTPUT) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002823 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002824 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002825 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002826 dbgInfo.pfnCallback = win32_debug_output_msg;
2827 dbgInfo.pUserData = log_output;
2828 dbgInfo.flags = report_flags;
2829 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002830 my_data->logging_callback.push_back(callback);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002831 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002832
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002833 if (!globalLockInitialized)
2834 {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002835 loader_platform_thread_create_mutex(&globalLock);
2836 globalLockInitialized = 1;
2837 }
2838}
2839
Chia-I Wu9ab61502015-11-06 06:42:02 +08002840VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance)
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002841{
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07002842 VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002843
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07002844 assert(chain_info->u.pLayerInfo);
2845 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
2846 PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance) fpGetInstanceProcAddr(NULL, "vkCreateInstance");
2847 if (fpCreateInstance == NULL) {
2848 return VK_ERROR_INITIALIZATION_FAILED;
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002849 }
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07002850
2851 // Advance the link info for the next element on the chain
2852 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
2853
2854 VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
2855 if (result != VK_SUCCESS)
2856 return result;
2857
2858 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
2859 my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
2860 layer_init_instance_dispatch_table(*pInstance, my_data->instance_dispatch_table, fpGetInstanceProcAddr);
2861
2862 my_data->report_data = debug_report_create_instance(
2863 my_data->instance_dispatch_table,
2864 *pInstance,
2865 pCreateInfo->enabledExtensionCount,
2866 pCreateInfo->ppEnabledExtensionNames);
2867
2868 init_draw_state(my_data, pAllocator);
2869
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002870 return result;
2871}
2872
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002873/* hook DestroyInstance to remove tableInstanceMap entry */
Chia-I Wu9ab61502015-11-06 06:42:02 +08002874VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator)
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002875{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002876 // TODOSC : Shouldn't need any customization here
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002877 dispatch_key key = get_dispatch_key(instance);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002878 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
2879 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002880 pTable->DestroyInstance(instance, pAllocator);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002881
2882 // Clean up logging callback, if any
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002883 while (my_data->logging_callback.size() > 0) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002884 VkDebugReportCallbackEXT callback = my_data->logging_callback.back();
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002885 layer_destroy_msg_callback(my_data->report_data, callback, pAllocator);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002886 my_data->logging_callback.pop_back();
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002887 }
2888
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06002889 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002890 delete my_data->instance_dispatch_table;
2891 layer_data_map.erase(key);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002892 // TODO : Potential race here with separate threads creating/destroying instance
Tobin Ehlis0b632332015-10-07 09:38:40 -06002893 if (layer_data_map.empty()) {
Mike Stroyanfcb4ba62015-08-18 15:56:18 -06002894 // Release mutex when destroying last instance.
2895 loader_platform_thread_delete_mutex(&globalLock);
2896 globalLockInitialized = 0;
2897 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002898}
2899
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002900static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
2901{
Tony Barbour3b4732f2015-07-13 13:37:24 -06002902 uint32_t i;
Tobin Ehlis0b632332015-10-07 09:38:40 -06002903 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
2904 dev_data->device_extensions.debug_marker_enabled = false;
Michael Lentineabc5e922015-10-12 11:30:14 -05002905 dev_data->device_extensions.wsi_enabled = false;
2906
2907
2908 VkLayerDispatchTable *pDisp = dev_data->device_dispatch_table;
2909 PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr;
2910
Michael Lentineabc5e922015-10-12 11:30:14 -05002911 pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR) gpa(device, "vkCreateSwapchainKHR");
2912 pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR) gpa(device, "vkDestroySwapchainKHR");
2913 pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR) gpa(device, "vkGetSwapchainImagesKHR");
2914 pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR) gpa(device, "vkAcquireNextImageKHR");
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07002915 pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR) gpa(device, "vkQueuePresentKHR");
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002916
Jon Ashburnf19916e2016-01-11 13:12:43 -07002917 for (i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
Ian Elliott05846062015-11-20 14:13:17 -07002918 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) {
Michael Lentineabc5e922015-10-12 11:30:14 -05002919 dev_data->device_extensions.wsi_enabled = true;
2920 }
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002921 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
Jon Ashburneab34492015-06-01 09:37:38 -06002922 /* Found a matching extension name, mark it enabled and init dispatch table*/
Tobin Ehlis0b632332015-10-07 09:38:40 -06002923 dev_data->device_extensions.debug_marker_enabled = true;
Jon Ashburn1d4b1282015-12-10 19:12:21 -07002924 initDebugMarkerTable(device);
2925
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002926 }
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002927 }
2928}
2929
Chia-I Wu9ab61502015-11-06 06:42:02 +08002930VK_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 -06002931{
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07002932 VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
Mark Lobodzinski941aea92016-01-13 10:23:15 -07002933
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07002934 assert(chain_info->u.pLayerInfo);
2935 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
2936 PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr;
2937 PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice) fpGetInstanceProcAddr(NULL, "vkCreateDevice");
2938 if (fpCreateDevice == NULL) {
2939 return VK_ERROR_INITIALIZATION_FAILED;
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002940 }
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07002941
2942 // Advance the link info for the next element on the chain
2943 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
2944
2945 VkResult result = fpCreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
2946 if (result != VK_SUCCESS) {
2947 return result;
2948 }
2949
2950 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
2951 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
2952
2953 // Setup device dispatch table
2954 my_device_data->device_dispatch_table = new VkLayerDispatchTable;
2955 layer_init_device_dispatch_table(*pDevice, my_device_data->device_dispatch_table, fpGetDeviceProcAddr);
2956
2957 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
2958 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
2959 // Get physical device limits for this device
2960 my_instance_data->instance_dispatch_table->GetPhysicalDeviceProperties(gpu, &(my_instance_data->physDevPropertyMap[*pDevice]));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002961 return result;
2962}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002963
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002964// prototype
2965static void deleteRenderPasses(layer_data*);
Chia-I Wu9ab61502015-11-06 06:42:02 +08002966VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002967{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002968 // TODOSC : Shouldn't need any customization here
Jeremy Hayes5d29ce32015-06-19 11:37:38 -06002969 dispatch_key key = get_dispatch_key(device);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002970 layer_data* dev_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002971 // Free all the memory
2972 loader_platform_thread_lock_mutex(&globalLock);
2973 deletePipelines(dev_data);
2974 deleteRenderPasses(dev_data);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002975 deleteCommandBuffers(dev_data);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002976 deletePools(dev_data);
2977 deleteLayouts(dev_data);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002978 dev_data->imageViewMap.clear();
2979 dev_data->imageMap.clear();
2980 dev_data->bufferViewMap.clear();
2981 dev_data->bufferMap.clear();
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002982 loader_platform_thread_unlock_mutex(&globalLock);
2983
Chia-I Wuf7458c52015-10-26 21:10:41 +08002984 dev_data->device_dispatch_table->DestroyDevice(device, pAllocator);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002985 tableDebugMarkerMap.erase(key);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002986 delete dev_data->device_dispatch_table;
2987 layer_data_map.erase(key);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002988}
2989
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07002990static const VkExtensionProperties instance_extensions[] = {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002991 {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002992 VK_EXT_DEBUG_REPORT_EXTENSION_NAME,
Courtney Goeltzenleuchterb69cd592016-01-19 16:08:39 -07002993 VK_EXT_DEBUG_REPORT_SPEC_VERSION
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002994 }
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06002995};
2996
Chia-I Wu9ab61502015-11-06 06:42:02 +08002997VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002998 const char *pLayerName,
2999 uint32_t *pCount,
3000 VkExtensionProperties* pProperties)
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06003001{
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07003002 return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003003}
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06003004
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07003005static const VkLayerProperties ds_global_layers[] = {
3006 {
Michael Lentine03107b42015-12-11 10:49:51 -08003007 "VK_LAYER_LUNARG_draw_state",
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07003008 VK_API_VERSION,
3009 VK_MAKE_VERSION(0, 1, 0),
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -07003010 "Validation layer: draw_state",
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07003011 }
3012};
3013
Chia-I Wu9ab61502015-11-06 06:42:02 +08003014VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003015 uint32_t *pCount,
3016 VkLayerProperties* pProperties)
3017{
3018 return util_GetLayerProperties(ARRAY_SIZE(ds_global_layers),
3019 ds_global_layers,
3020 pCount, pProperties);
3021}
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06003022
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003023static const VkExtensionProperties ds_device_extensions[] = {
3024 {
3025 DEBUG_MARKER_EXTENSION_NAME,
3026 VK_MAKE_VERSION(0, 1, 0),
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003027 }
3028};
3029
3030static const VkLayerProperties ds_device_layers[] = {
3031 {
Michael Lentine1f8d4412016-01-19 14:19:38 -06003032 "VK_LAYER_LUNARG_draw_state",
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003033 VK_API_VERSION,
3034 VK_MAKE_VERSION(0, 1, 0),
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -07003035 "Validation layer: draw_state",
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003036 }
3037};
3038
Chia-I Wu9ab61502015-11-06 06:42:02 +08003039VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003040 VkPhysicalDevice physicalDevice,
3041 const char* pLayerName,
3042 uint32_t* pCount,
3043 VkExtensionProperties* pProperties)
3044{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003045 // DrawState does not have any physical device extensions
Jon Ashburn751c4842015-11-02 17:37:20 -07003046 if (pLayerName == NULL) {
3047 dispatch_key key = get_dispatch_key(physicalDevice);
3048 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003049 return my_data->instance_dispatch_table->EnumerateDeviceExtensionProperties(
Jon Ashburn751c4842015-11-02 17:37:20 -07003050 physicalDevice,
3051 NULL,
3052 pCount,
3053 pProperties);
3054 } else {
3055 return util_GetExtensionProperties(ARRAY_SIZE(ds_device_extensions),
3056 ds_device_extensions,
3057 pCount, pProperties);
3058 }
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003059}
3060
Chia-I Wu9ab61502015-11-06 06:42:02 +08003061VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003062 VkPhysicalDevice physicalDevice,
3063 uint32_t* pCount,
3064 VkLayerProperties* pProperties)
3065{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003066 /* DrawState physical device layers are the same as global */
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003067 return util_GetLayerProperties(ARRAY_SIZE(ds_device_layers), ds_device_layers,
3068 pCount, pProperties);
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06003069}
3070
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07003071VkBool32 ValidateCmdBufImageLayouts(VkCommandBuffer cmdBuffer) {
Mark Youngb20a6a82016-01-07 15:41:43 -07003072 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05003073 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
3074 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
3075 for (auto cb_image_data : pCB->imageLayoutMap) {
3076 auto image_data = dev_data->imageLayoutMap.find(cb_image_data.first);
3077 if (image_data == dev_data->imageLayoutMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003078 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",
Mark Young93ecb1d2016-01-13 13:47:16 -07003079 "Cannot submit cmd buffer using deleted image %" PRIu64 ".", (uint64_t)(cb_image_data.first));
Michael Lentineabc5e922015-10-12 11:30:14 -05003080 } else {
3081 if (dev_data->imageLayoutMap[cb_image_data.first]->layout != cb_image_data.second.initialLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003082 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 -05003083 "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);
3084 }
3085 dev_data->imageLayoutMap[cb_image_data.first]->layout = cb_image_data.second.layout;
3086 }
3087 }
3088 return skip_call;
3089}
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07003090// Descriptor sets are unique vs. other resources in that they may be consumed at bind time:
3091// From spec section on vkCmdBindDescriptorSets - The descriptor set contents bound by a call
3092// to vkCmdBindDescriptorSets may be consumed during host execution of the command, or during
3093// shader execution of the resulting draws, or any time in between.
3094VkBool32 validateAndIncrementDescriptorSets(layer_data* my_data, GLOBAL_CB_NODE* pCB) {
3095 VkBool32 skip_call = VK_FALSE;
3096 // Verify that any active sets for this CB are valid and mark them in use
3097 for (auto set : pCB->activeSets) {
3098 auto setNode = my_data->setMap.find(set);
3099 if (setNode == my_data->setMap.end()) {
Mark Youngee3f3a22016-01-25 12:18:32 -07003100 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t)(set), __LINE__, DRAWSTATE_INVALID_DESCRIPTOR_SET, "DS",
3101 "Cannot submit cmd buffer using deleted descriptor set %" PRIu64 ".", (uint64_t)(set));
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07003102 } else {
3103 setNode->second->in_use.fetch_add(1);
3104 }
3105 }
3106 return skip_call;
3107}
Michael Lentineabc5e922015-10-12 11:30:14 -05003108
Mark Young7a69c302016-01-07 09:48:47 -07003109VkBool32 validateAndIncrementResources(layer_data* my_data, GLOBAL_CB_NODE* pCB) {
Mark Youngb20a6a82016-01-07 15:41:43 -07003110 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003111 for (auto drawDataElement : pCB->drawData) {
3112 for (auto buffer : drawDataElement.buffers) {
3113 auto buffer_data = my_data->bufferMap.find(buffer);
3114 if (buffer_data == my_data->bufferMap.end()) {
Mark Young93ecb1d2016-01-13 13:47:16 -07003115 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, (uint64_t)(buffer), __LINE__, DRAWSTATE_INVALID_BUFFER, "DS",
3116 "Cannot submit cmd buffer using deleted buffer %" PRIu64 ".", (uint64_t)(buffer));
Michael Lentine700b0aa2015-10-30 17:57:32 -07003117 } else {
3118 buffer_data->second.in_use.fetch_add(1);
3119 }
3120 }
3121 }
Michael Lentine2e068b22015-12-29 16:05:27 -06003122 return skip_call;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003123}
3124
3125void decrementResources(layer_data* my_data, VkCommandBuffer cmdBuffer) {
3126 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cmdBuffer);
3127 for (auto drawDataElement : pCB->drawData) {
3128 for (auto buffer : drawDataElement.buffers) {
3129 auto buffer_data = my_data->bufferMap.find(buffer);
3130 if (buffer_data != my_data->bufferMap.end()) {
3131 buffer_data->second.in_use.fetch_sub(1);
3132 }
3133 }
3134 }
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07003135 for (auto set : pCB->activeSets) {
3136 auto setNode = my_data->setMap.find(set);
3137 if (setNode != my_data->setMap.end()) {
3138 setNode->second->in_use.fetch_sub(1);
3139 }
3140 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003141 for (auto queryStatePair : pCB->queryToStateMap) {
3142 my_data->queryToStateMap[queryStatePair.first] = queryStatePair.second;
3143 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003144}
3145
3146void decrementResources(layer_data* my_data, uint32_t fenceCount, const VkFence* pFences) {
3147 for (uint32_t i = 0; i < fenceCount; ++i) {
3148 auto fence_data = my_data->fenceMap.find(pFences[i]);
3149 if (fence_data == my_data->fenceMap.end() || !fence_data->second.needsSignaled) return;
3150 fence_data->second.needsSignaled = false;
3151 if (fence_data->second.priorFence != VK_NULL_HANDLE) {
3152 decrementResources(my_data, 1, &fence_data->second.priorFence);
3153 }
3154 for (auto cmdBuffer : fence_data->second.cmdBuffers) {
3155 decrementResources(my_data, cmdBuffer);
3156 }
3157 }
3158}
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07003159
Michael Lentine700b0aa2015-10-30 17:57:32 -07003160void decrementResources(layer_data* my_data, VkQueue queue) {
3161 auto queue_data = my_data->queueMap.find(queue);
3162 if (queue_data != my_data->queueMap.end()) {
3163 for (auto cmdBuffer : queue_data->second.untrackedCmdBuffers) {
3164 decrementResources(my_data, cmdBuffer);
3165 }
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07003166 queue_data->second.untrackedCmdBuffers.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07003167 decrementResources(my_data, 1, &queue_data->second.priorFence);
3168 }
3169}
3170
3171void trackCommandBuffers(layer_data* my_data, VkQueue queue, uint32_t cmdBufferCount, const VkCommandBuffer* pCmdBuffers, VkFence fence) {
3172 auto queue_data = my_data->queueMap.find(queue);
3173 if (fence != VK_NULL_HANDLE) {
3174 VkFence priorFence = VK_NULL_HANDLE;
3175 if (queue_data != my_data->queueMap.end()) {
3176 priorFence = queue_data->second.priorFence;
3177 queue_data->second.priorFence = fence;
3178 for (auto cmdBuffer : queue_data->second.untrackedCmdBuffers) {
3179 my_data->fenceMap[fence].cmdBuffers.push_back(cmdBuffer);
3180 }
3181 queue_data->second.untrackedCmdBuffers.clear();
3182 }
3183 my_data->fenceMap[fence].cmdBuffers.clear();
3184 my_data->fenceMap[fence].priorFence = priorFence;
3185 my_data->fenceMap[fence].needsSignaled = true;
3186 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003187 for (auto secondaryCmdBuffer : my_data->commandBufferMap[pCmdBuffers[i]]->secondaryCommandBuffers) {
3188 my_data->fenceMap[fence].cmdBuffers.push_back(secondaryCmdBuffer);
3189 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003190 my_data->fenceMap[fence].cmdBuffers.push_back(pCmdBuffers[i]);
3191 }
3192 } else {
3193 if (queue_data != my_data->queueMap.end()) {
3194 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003195 for (auto secondaryCmdBuffer : my_data->commandBufferMap[pCmdBuffers[i]]->secondaryCommandBuffers) {
3196 queue_data->second.untrackedCmdBuffers.push_back(secondaryCmdBuffer);
3197 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003198 queue_data->second.untrackedCmdBuffers.push_back(pCmdBuffers[i]);
3199 }
3200 }
3201 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003202 if (queue_data != my_data->queueMap.end()) {
3203 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003204 // Add cmdBuffers to both the global set and queue set
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003205 for (auto secondaryCmdBuffer : my_data->commandBufferMap[pCmdBuffers[i]]->secondaryCommandBuffers) {
3206 my_data->inFlightCmdBuffers.insert(secondaryCmdBuffer);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003207 my_data->queueMap[queue].inFlightCmdBuffers.insert(secondaryCmdBuffer);
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003208 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003209 my_data->inFlightCmdBuffers.insert(pCmdBuffers[i]);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003210 my_data->queueMap[queue].inFlightCmdBuffers.insert(pCmdBuffers[i]);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003211 }
3212 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003213}
3214
Chia-I Wu9ab61502015-11-06 06:42:02 +08003215VK_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 -06003216{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003217 VkBool32 skipCall = VK_FALSE;
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06003218 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlis0b632332015-10-07 09:38:40 -06003219 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003220 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08003221 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Michael Lentine15a47882016-01-06 10:05:48 -06003222 for (uint32_t i=0; i < submit->waitSemaphoreCount; ++i) {
3223 if (dev_data->semaphoreSignaledMap[submit->pWaitSemaphores[i]]) {
3224 dev_data->semaphoreSignaledMap[submit->pWaitSemaphores[i]] = 0;
3225 } else {
3226 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",
3227 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
Mark Youngee3f3a22016-01-25 12:18:32 -07003228 (uint64_t)(queue), (uint64_t)(submit->pWaitSemaphores[i]));
Michael Lentine15a47882016-01-06 10:05:48 -06003229 }
3230 }
3231 for (uint32_t i=0; i < submit->signalSemaphoreCount; ++i) {
3232 dev_data->semaphoreSignaledMap[submit->pSignalSemaphores[i]] = 1;
3233 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08003234 for (uint32_t i=0; i < submit->commandBufferCount; i++) {
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07003235
3236#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
3237 skipCall |= ValidateCmdBufImageLayouts(submit->pCommandBuffers[i]);
3238#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
3239
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003240 // Validate that cmd buffers have been updated
3241 pCB = getCBNode(dev_data, submit->pCommandBuffers[i]);
3242 loader_platform_thread_lock_mutex(&globalLock);
3243 pCB->submitCount++; // increment submit count
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003244 // Track in-use for resources off of primary and any secondary CBs
Michael Lentine700b0aa2015-10-30 17:57:32 -07003245 skipCall |= validateAndIncrementResources(dev_data, pCB);
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003246 if (!pCB->secondaryCommandBuffers.empty()) {
3247 for (auto secondaryCmdBuffer : pCB->secondaryCommandBuffers) {
3248 skipCall |= validateAndIncrementResources(dev_data, dev_data->commandBufferMap[secondaryCmdBuffer]);
3249 }
3250 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003251 if ((pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT) && (pCB->submitCount > 1)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003252 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 -05003253 "CB %#" PRIxLEAST64 " was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted %#" PRIxLEAST64 " times.",
Mark Youngee3f3a22016-01-25 12:18:32 -07003254 (uint64_t)(pCB->commandBuffer), pCB->submitCount);
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003255 }
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003256 if (CB_RECORDED != pCB->state) {
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003257 // Flag error for using CB w/o vkEndCommandBuffer() called
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003258 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",
Mark Youngee3f3a22016-01-25 12:18:32 -07003259 "You must call vkEndCommandBuffer() on CB %#" PRIxLEAST64 " before this call to vkQueueSubmit()!", (uint64_t)(pCB->commandBuffer));
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003260 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003261 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003262 }
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003263 // If USAGE_SIMULTANEOUS_USE_BIT not set then CB cannot already be executing on device
3264 if (!(pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT)) {
3265 if (dev_data->inFlightCmdBuffers.find(pCB->commandBuffer) != dev_data->inFlightCmdBuffers.end()) {
Mark Youngee3f3a22016-01-25 12:18:32 -07003266 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)(pCB->commandBuffer), __LINE__, DRAWSTATE_INVALID_CB_SIMULTANEOUS_USE, "DS",
3267 "Attempt to simultaneously execute CB %#" PRIxLEAST64 " w/o VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!", (uint64_t)(pCB->commandBuffer));
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003268 }
3269 }
Tobin Ehlisc4bdde12015-05-27 14:30:06 -06003270 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06003271 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003272 trackCommandBuffers(dev_data, queue, submit->commandBufferCount, submit->pCommandBuffers, fence);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003273 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003274 if (VK_FALSE == skipCall)
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08003275 return dev_data->device_dispatch_table->QueueSubmit(queue, submitCount, pSubmits, fence);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003276 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003277}
3278
Mark Youngb20a6a82016-01-07 15:41:43 -07003279VkBool32 cleanInFlightCmdBuffer(layer_data* my_data, VkCommandBuffer cmdBuffer) {
3280 VkBool32 skip_call = VK_FALSE;
Michael Lentineb887b0a2015-12-29 14:12:11 -06003281 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cmdBuffer);
Mark Lobodzinskia9e7c042016-01-25 14:27:49 -07003282 if (pCB) {
3283 for (auto queryEventsPair : pCB->waitedEventsBeforeQueryReset) {
3284 for (auto event : queryEventsPair.second) {
3285 if (my_data->eventMap[event].needsSignaled) {
3286 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",
3287 "Cannot get query results on queryPool %" PRIu64 " with index %d which was guarded by unsignaled event %" PRIu64 ".",
3288 (uint64_t)(queryEventsPair.first.pool), queryEventsPair.first.index, (uint64_t)(event));
3289 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003290 }
3291 }
3292 }
3293 return skip_call;
3294}
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003295// Remove given cmd_buffer from inFlight set for given queue
3296// If cmd_buffer is not inFlight on any other queues, also remove it from global inFlight set
3297static inline void removeInFlightCmdBuffer(layer_data* dev_data, VkQueue queue, VkCommandBuffer cmd_buffer)
3298{
3299 dev_data->queueMap[queue].inFlightCmdBuffers.erase(cmd_buffer);
3300 // Pull it off of global list initially, but if we find it in any other queue list, add it back in
3301 dev_data->inFlightCmdBuffers.erase(cmd_buffer);
3302 for (auto q : dev_data->queues) {
3303 if ((q != queue) && (dev_data->queueMap[q].inFlightCmdBuffers.find(cmd_buffer) != dev_data->queueMap[q].inFlightCmdBuffers.end())) {
3304 dev_data->inFlightCmdBuffers.insert(cmd_buffer);
3305 break;
3306 }
3307 }
3308}
Michael Lentineb887b0a2015-12-29 14:12:11 -06003309
Michael Lentine700b0aa2015-10-30 17:57:32 -07003310VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence* pFences, VkBool32 waitAll, uint64_t timeout)
3311{
3312 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3313 VkResult result = dev_data->device_dispatch_table->WaitForFences(device, fenceCount, pFences, waitAll, timeout);
Mark Youngb20a6a82016-01-07 15:41:43 -07003314 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003315 if ((waitAll || fenceCount == 1) && result == VK_SUCCESS) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06003316 for (uint32_t i = 0; i < fenceCount; ++i) {
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003317 VkQueue fence_queue = dev_data->fenceMap[pFences[i]].queue;
Michael Lentineb887b0a2015-12-29 14:12:11 -06003318 for (auto cmdBuffer : dev_data->fenceMap[pFences[i]].cmdBuffers) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06003319 skip_call |= cleanInFlightCmdBuffer(dev_data, cmdBuffer);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003320 removeInFlightCmdBuffer(dev_data, fence_queue, cmdBuffer);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003321 }
3322 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003323 decrementResources(dev_data, fenceCount, pFences);
3324 }
Mark Youngb20a6a82016-01-07 15:41:43 -07003325 if (VK_FALSE != skip_call)
Mark Lobodzinskice738852016-01-07 10:04:02 -07003326 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003327 return result;
3328}
3329
3330
3331VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetFenceStatus(VkDevice device, VkFence fence)
3332{
3333 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3334 VkResult result = dev_data->device_dispatch_table->GetFenceStatus(device, fence);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003335 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003336 if (result == VK_SUCCESS) {
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003337 auto fence_queue = dev_data->fenceMap[fence].queue;
Michael Lentineb887b0a2015-12-29 14:12:11 -06003338 for (auto cmdBuffer : dev_data->fenceMap[fence].cmdBuffers) {
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003339 skip_call |= cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3340 removeInFlightCmdBuffer(dev_data, fence_queue, cmdBuffer);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003341 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003342 decrementResources(dev_data, 1, &fence);
3343 }
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003344 if (VK_FALSE != skip_call)
3345 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003346 return result;
3347}
3348
3349VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue* pQueue)
3350{
3351 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3352 dev_data->device_dispatch_table->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003353 dev_data->queues.push_back(*pQueue);
Michael Lentine700b0aa2015-10-30 17:57:32 -07003354 dev_data->queueMap[*pQueue].device = device;
3355}
3356
3357VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueueWaitIdle(VkQueue queue)
3358{
3359 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
3360 decrementResources(dev_data, queue);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003361 VkBool32 skip_call = VK_FALSE;
3362 // Iterate over local set since we erase set members as we go in for loop
3363 auto local_cb_set = dev_data->queueMap[queue].inFlightCmdBuffers;
3364 for (auto cmdBuffer : local_cb_set) {
3365 skip_call |= cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3366 removeInFlightCmdBuffer(dev_data, queue, cmdBuffer);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003367 }
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003368 dev_data->queueMap[queue].inFlightCmdBuffers.clear();
3369 if (VK_FALSE != skip_call)
3370 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003371 return dev_data->device_dispatch_table->QueueWaitIdle(queue);
3372}
3373
3374VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkDeviceWaitIdle(VkDevice device)
3375{
3376 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003377 for (auto queue : dev_data->queues) {
3378 decrementResources(dev_data, queue);
3379 // Clear all of the queue inFlightCmdBuffers (global set cleared below)
3380 dev_data->queueMap[queue].inFlightCmdBuffers.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07003381 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003382 for (auto cmdBuffer : dev_data->inFlightCmdBuffers) {
3383 cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3384 }
3385 dev_data->inFlightCmdBuffers.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07003386 return dev_data->device_dispatch_table->DeviceWaitIdle(device);
3387}
3388
Chia-I Wu9ab61502015-11-06 06:42:02 +08003389VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003390{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003391 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 -06003392 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003393}
3394
Chia-I Wu9ab61502015-11-06 06:42:02 +08003395VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySemaphore(VkDevice device, VkSemaphore semaphore, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003396{
Michael Lentine15a47882016-01-06 10:05:48 -06003397 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3398 dev_data->device_dispatch_table->DestroySemaphore(device, semaphore, pAllocator);
3399 dev_data->semaphoreSignaledMap.erase(semaphore);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003400 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003401}
3402
Chia-I Wu9ab61502015-11-06 06:42:02 +08003403VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003404{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003405 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 -06003406 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003407}
3408
Chia-I Wu9ab61502015-11-06 06:42:02 +08003409VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003410{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003411 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 -06003412 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003413}
3414
Mark Lobodzinskice738852016-01-07 10:04:02 -07003415VKAPI_ATTR VkResult VKAPI_CALL vkGetQueryPoolResults(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount,
Michael Lentineb887b0a2015-12-29 14:12:11 -06003416 size_t dataSize, void* pData, VkDeviceSize stride, VkQueryResultFlags flags) {
3417 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3418 unordered_map<QueryObject, vector<VkCommandBuffer>> queriesInFlight;
3419 GLOBAL_CB_NODE* pCB = nullptr;
3420 for (auto cmdBuffer : dev_data->inFlightCmdBuffers) {
3421 pCB = getCBNode(dev_data, cmdBuffer);
3422 for (auto queryStatePair : pCB->queryToStateMap) {
3423 queriesInFlight[queryStatePair.first].push_back(cmdBuffer);
3424 }
3425 }
Mark Youngb20a6a82016-01-07 15:41:43 -07003426 VkBool32 skip_call = VK_FALSE;
Michael Lentineb887b0a2015-12-29 14:12:11 -06003427 for (uint32_t i = 0; i < queryCount; ++i) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003428 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06003429 auto queryElement = queriesInFlight.find(query);
3430 auto queryToStateElement = dev_data->queryToStateMap.find(query);
3431 if (queryToStateElement != dev_data->queryToStateMap.end()) {
3432 }
3433 // Available and in flight
3434 if(queryElement != queriesInFlight.end() && queryToStateElement != dev_data->queryToStateMap.end() && queryToStateElement->second) {
3435 for (auto cmdBuffer : queryElement->second) {
3436 pCB = getCBNode(dev_data, cmdBuffer);
3437 auto queryEventElement = pCB->waitedEventsBeforeQueryReset.find(query);
3438 if (queryEventElement == pCB->waitedEventsBeforeQueryReset.end()) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003439 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT, 0, __LINE__,
3440 DRAWSTATE_INVALID_QUERY, "DS", "Cannot get query results on queryPool %" PRIu64 " with index %d which is in flight.",
Mark Young93ecb1d2016-01-13 13:47:16 -07003441 (uint64_t)(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003442 } else {
3443 for (auto event : queryEventElement->second) {
3444 dev_data->eventMap[event].needsSignaled = true;
3445 }
3446 }
3447 }
3448 // Unavailable and in flight
3449 } else if (queryElement != queriesInFlight.end() && queryToStateElement != dev_data->queryToStateMap.end() && !queryToStateElement->second) {
3450 // TODO : Can there be the same query in use by multiple command buffers in flight?
3451 bool make_available = false;
3452 for (auto cmdBuffer : queryElement->second) {
3453 pCB = getCBNode(dev_data, cmdBuffer);
3454 make_available |= pCB->queryToStateMap[query];
3455 }
3456 if (!(((flags & VK_QUERY_RESULT_PARTIAL_BIT) || (flags & VK_QUERY_RESULT_WAIT_BIT)) && make_available)) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003457 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 -06003458 "Cannot get query results on queryPool %" PRIu64 " with index %d which is unavailable.",
Mark Young93ecb1d2016-01-13 13:47:16 -07003459 (uint64_t)(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003460 }
3461 // Unavailable
3462 } else if (queryToStateElement != dev_data->queryToStateMap.end() && !queryToStateElement->second) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003463 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 -06003464 "Cannot get query results on queryPool %" PRIu64 " with index %d which is unavailable.",
Mark Young93ecb1d2016-01-13 13:47:16 -07003465 (uint64_t)(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003466 // Unitialized
3467 } else if (queryToStateElement == dev_data->queryToStateMap.end()) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003468 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 -06003469 "Cannot get query results on queryPool %" PRIu64 " with index %d which is uninitialized.",
Mark Young93ecb1d2016-01-13 13:47:16 -07003470 (uint64_t)(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003471 }
3472 }
3473 if (skip_call)
Mark Lobodzinskice738852016-01-07 10:04:02 -07003474 return VK_ERROR_VALIDATION_FAILED_EXT;
3475 return dev_data->device_dispatch_table->GetQueryPoolResults(device, queryPool, firstQuery, queryCount, dataSize, pData, stride, flags);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003476}
3477
Mark Young7a69c302016-01-07 09:48:47 -07003478VkBool32 validateIdleBuffer(const layer_data* my_data, VkBuffer buffer) {
Mark Youngb20a6a82016-01-07 15:41:43 -07003479 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003480 auto buffer_data = my_data->bufferMap.find(buffer);
3481 if (buffer_data == my_data->bufferMap.end()) {
Mark Young93ecb1d2016-01-13 13:47:16 -07003482 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, (uint64_t)(buffer), __LINE__, DRAWSTATE_DOUBLE_DESTROY, "DS",
3483 "Cannot free buffer %" PRIxLEAST64 " that has not been allocated.", (uint64_t)(buffer));
Michael Lentine700b0aa2015-10-30 17:57:32 -07003484 } else {
3485 if (buffer_data->second.in_use.load()) {
Mark Young93ecb1d2016-01-13 13:47:16 -07003486 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, (uint64_t)(buffer), __LINE__, DRAWSTATE_OBJECT_INUSE, "DS",
3487 "Cannot free buffer %" PRIxLEAST64 " that is in use by a command buffer.", (uint64_t)(buffer));
Michael Lentine700b0aa2015-10-30 17:57:32 -07003488 }
3489 }
3490 return skip_call;
3491}
3492
Chia-I Wu9ab61502015-11-06 06:42:02 +08003493VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003494{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003495 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07003496 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003497 if (!validateIdleBuffer(dev_data, buffer)) {
3498 dev_data->device_dispatch_table->DestroyBuffer(device, buffer, pAllocator);
3499 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08003500 dev_data->bufferMap.erase(buffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003501}
3502
Chia-I Wu9ab61502015-11-06 06:42:02 +08003503VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBufferView(VkDevice device, VkBufferView bufferView, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003504{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003505 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003506 dev_data->device_dispatch_table->DestroyBufferView(device, bufferView, pAllocator);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003507 dev_data->bufferViewMap.erase(bufferView);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003508}
3509
Chia-I Wu9ab61502015-11-06 06:42:02 +08003510VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003511{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003512 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003513 dev_data->device_dispatch_table->DestroyImage(device, image, pAllocator);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003514 dev_data->imageMap.erase(image);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003515}
3516
Chia-I Wu9ab61502015-11-06 06:42:02 +08003517VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyImageView(VkDevice device, VkImageView imageView, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003518{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003519 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 -06003520 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003521}
3522
Chia-I Wu9ab61502015-11-06 06:42:02 +08003523VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003524{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003525 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 -06003526 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003527}
3528
Chia-I Wu9ab61502015-11-06 06:42:02 +08003529VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyPipeline(VkDevice device, VkPipeline pipeline, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003530{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003531 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 -06003532 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003533}
3534
Chia-I Wu9ab61502015-11-06 06:42:02 +08003535VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003536{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003537 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 -06003538 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003539}
3540
Chia-I Wu9ab61502015-11-06 06:42:02 +08003541VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySampler(VkDevice device, VkSampler sampler, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003542{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003543 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 -06003544 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003545}
3546
Chia-I Wu9ab61502015-11-06 06:42:02 +08003547VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003548{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003549 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 -06003550 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003551}
3552
Chia-I Wu9ab61502015-11-06 06:42:02 +08003553VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003554{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003555 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 -06003556 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003557}
3558
Chia-I Wu9ab61502015-11-06 06:42:02 +08003559VK_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 -06003560{
Mark Lobodzinski39298632015-11-18 08:38:27 -07003561 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3562
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07003563 for (uint32_t i = 0; i < count; i++) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003564 // Delete CB information structure, and remove from commandBufferMap
3565 auto cb = dev_data->commandBufferMap.find(pCommandBuffers[i]);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003566 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003567 if (cb != dev_data->commandBufferMap.end()) {
3568 delete (*cb).second;
3569 dev_data->commandBufferMap.erase(cb);
3570 }
3571
3572 // Remove commandBuffer reference from commandPoolMap
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003573 dev_data->commandPoolMap[commandPool].commandBuffers.remove(pCommandBuffers[i]);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003574 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003575 }
3576
3577 dev_data->device_dispatch_table->FreeCommandBuffers(device, commandPool, count, pCommandBuffers);
3578}
3579
3580VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkCommandPool* pCommandPool)
3581{
3582 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3583
3584 VkResult result = dev_data->device_dispatch_table->CreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
3585
3586 if (VK_SUCCESS == result) {
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003587 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003588 dev_data->commandPoolMap[*pCommandPool].createFlags = pCreateInfo->flags;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003589 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003590 }
3591 return result;
3592}
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07003593// Destroy commandPool along with all of the commandBuffers allocated from that pool
Mark Lobodzinski39298632015-11-18 08:38:27 -07003594VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks* pAllocator)
3595{
3596 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003597 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003598
3599 // Must remove cmdpool from cmdpoolmap, after removing all cmdbuffers in its list from the commandPoolMap
3600 if (dev_data->commandPoolMap.find(commandPool) != dev_data->commandPoolMap.end()) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003601 for (auto poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.begin(); poolCb != dev_data->commandPoolMap[commandPool].commandBuffers.end();) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003602 auto del_cb = dev_data->commandBufferMap.find(*poolCb);
3603 delete (*del_cb).second; // delete CB info structure
3604 dev_data->commandBufferMap.erase(del_cb); // Remove this command buffer from cbMap
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003605 poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.erase(poolCb); // Remove CB reference from commandPoolMap's list
Mark Lobodzinski39298632015-11-18 08:38:27 -07003606 }
3607 }
3608 dev_data->commandPoolMap.erase(commandPool);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003609
3610 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003611 dev_data->device_dispatch_table->DestroyCommandPool(device, commandPool, pAllocator);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003612}
3613
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003614VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandPool(
3615 VkDevice device,
3616 VkCommandPool commandPool,
3617 VkCommandPoolResetFlags flags)
3618{
3619 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003620 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003621
3622 result = dev_data->device_dispatch_table->ResetCommandPool(device, commandPool, flags);
3623 // Reset all of the CBs allocated from this pool
3624 if (VK_SUCCESS == result) {
3625 auto it = dev_data->commandPoolMap[commandPool].commandBuffers.begin();
3626 while (it != dev_data->commandPoolMap[commandPool].commandBuffers.end()) {
3627 resetCB(dev_data, (*it));
3628 ++it;
3629 }
3630 }
3631 return result;
3632}
3633
Chia-I Wu9ab61502015-11-06 06:42:02 +08003634VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003635{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003636 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 -06003637 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003638}
3639
Chia-I Wu9ab61502015-11-06 06:42:02 +08003640VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003641{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003642 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 -06003643 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003644}
3645
Chia-I Wu9ab61502015-11-06 06:42:02 +08003646VK_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 -06003647{
3648 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003649 VkResult result = dev_data->device_dispatch_table->CreateBuffer(device, pCreateInfo, pAllocator, pBuffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003650 if (VK_SUCCESS == result) {
3651 loader_platform_thread_lock_mutex(&globalLock);
3652 // 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 -07003653 dev_data->bufferMap[*pBuffer].create_info = unique_ptr<VkBufferCreateInfo>(new VkBufferCreateInfo(*pCreateInfo));
3654 dev_data->bufferMap[*pBuffer].in_use.store(0);
Tobin Ehlisa1c28562015-10-23 16:00:08 -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 vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkBufferView* 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->CreateBufferView(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->bufferViewMap[*pView] = unique_ptr<VkBufferViewCreateInfo>(new VkBufferViewCreateInfo(*pCreateInfo));
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003667 loader_platform_thread_unlock_mutex(&globalLock);
3668 }
3669 return result;
3670}
3671
Chia-I Wu9ab61502015-11-06 06:42:02 +08003672VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateImage(VkDevice device, const VkImageCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkImage* pImage)
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003673{
3674 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003675 VkResult result = dev_data->device_dispatch_table->CreateImage(device, pCreateInfo, pAllocator, pImage);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003676 if (VK_SUCCESS == result) {
Michael Lentineabc5e922015-10-12 11:30:14 -05003677 IMAGE_NODE* image_node = new IMAGE_NODE;
3678 image_node->layout = pCreateInfo->initialLayout;
Tobin Ehlis75cd1c52016-01-21 10:21:04 -07003679 image_node->format = pCreateInfo->format;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003680 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003681 dev_data->imageMap[*pImage] = unique_ptr<VkImageCreateInfo>(new VkImageCreateInfo(*pCreateInfo));
Michael Lentineabc5e922015-10-12 11:30:14 -05003682 dev_data->imageLayoutMap[*pImage] = image_node;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003683 loader_platform_thread_unlock_mutex(&globalLock);
3684 }
3685 return result;
3686}
3687
Chia-I Wu9ab61502015-11-06 06:42:02 +08003688VK_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 -06003689{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003690 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003691 VkResult result = dev_data->device_dispatch_table->CreateImageView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003692 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003693 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003694 dev_data->imageViewMap[*pView] = unique_ptr<VkImageViewCreateInfo>(new VkImageViewCreateInfo(*pCreateInfo));
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003695 loader_platform_thread_unlock_mutex(&globalLock);
3696 }
3697 return result;
3698}
3699
Jon Ashburnc669cc62015-07-09 15:02:25 -06003700//TODO handle pipeline caches
Chia-I Wu9ab61502015-11-06 06:42:02 +08003701VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineCache(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003702 VkDevice device,
3703 const VkPipelineCacheCreateInfo* pCreateInfo,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003704 const VkAllocationCallbacks* pAllocator,
Jon Ashburnc669cc62015-07-09 15:02:25 -06003705 VkPipelineCache* pPipelineCache)
3706{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003707 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003708 VkResult result = dev_data->device_dispatch_table->CreatePipelineCache(device, pCreateInfo, pAllocator, pPipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003709 return result;
3710}
3711
Chia-I Wu9ab61502015-11-06 06:42:02 +08003712VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineCache(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003713 VkDevice device,
Chia-I Wuf7458c52015-10-26 21:10:41 +08003714 VkPipelineCache pipelineCache,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003715 const VkAllocationCallbacks* pAllocator)
Jon Ashburnc669cc62015-07-09 15:02:25 -06003716{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003717 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003718 dev_data->device_dispatch_table->DestroyPipelineCache(device, pipelineCache, pAllocator);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003719}
3720
Chia-I Wu9ab61502015-11-06 06:42:02 +08003721VKAPI_ATTR VkResult VKAPI_CALL vkGetPipelineCacheData(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003722 VkDevice device,
3723 VkPipelineCache pipelineCache,
Chia-I Wub16facd2015-10-26 19:17:06 +08003724 size_t* pDataSize,
Jon Ashburnc669cc62015-07-09 15:02:25 -06003725 void* pData)
3726{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003727 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wub16facd2015-10-26 19:17:06 +08003728 VkResult result = dev_data->device_dispatch_table->GetPipelineCacheData(device, pipelineCache, pDataSize, pData);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003729 return result;
3730}
3731
Chia-I Wu9ab61502015-11-06 06:42:02 +08003732VKAPI_ATTR VkResult VKAPI_CALL vkMergePipelineCaches(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003733 VkDevice device,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003734 VkPipelineCache dstCache,
Jon Ashburnc669cc62015-07-09 15:02:25 -06003735 uint32_t srcCacheCount,
3736 const VkPipelineCache* pSrcCaches)
3737{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003738 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003739 VkResult result = dev_data->device_dispatch_table->MergePipelineCaches(device, dstCache, srcCacheCount, pSrcCaches);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003740 return result;
3741}
3742
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003743VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateGraphicsPipelines(
3744 VkDevice device,
3745 VkPipelineCache pipelineCache,
3746 uint32_t count,
3747 const VkGraphicsPipelineCreateInfo *pCreateInfos,
3748 const VkAllocationCallbacks *pAllocator,
3749 VkPipeline *pPipelines)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003750{
Courtney Goeltzenleuchtered894072015-09-04 13:39:59 -06003751 VkResult result = VK_SUCCESS;
Tobin Ehlis11efc302015-09-16 10:33:53 -06003752 //TODO What to do with pipelineCache?
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003753 // The order of operations here is a little convoluted but gets the job done
3754 // 1. Pipeline create state is first shadowed into PIPELINE_NODE struct
3755 // 2. Create state is then validated (which uses flags setup during shadowing)
3756 // 3. If everything looks good, we'll then create the pipeline and add NODE to pipelineMap
Tobin Ehlis11efc302015-09-16 10:33:53 -06003757 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis65399772015-09-17 16:33:58 -06003758 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
3759 vector<PIPELINE_NODE*> pPipeNode(count);
Tobin Ehlis0b632332015-10-07 09:38:40 -06003760 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003761
Tobin Ehlis11efc302015-09-16 10:33:53 -06003762 uint32_t i=0;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003763 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003764
Tobin Ehlis11efc302015-09-16 10:33:53 -06003765 for (i=0; i<count; i++) {
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003766 pPipeNode[i] = initGraphicsPipeline(dev_data, &pCreateInfos[i], NULL);
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06003767 skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
Tobin Ehlis11efc302015-09-16 10:33:53 -06003768 }
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003769
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003770 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003771
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07003772 if (VK_FALSE == skipCall) {
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003773 result = dev_data->device_dispatch_table->CreateGraphicsPipelines(device,
3774 pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003775 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis11efc302015-09-16 10:33:53 -06003776 for (i=0; i<count; i++) {
3777 pPipeNode[i]->pipeline = pPipelines[i];
Chia-I Wue2fc5522015-10-26 20:04:44 +08003778 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
Tobin Ehlis11efc302015-09-16 10:33:53 -06003779 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003780 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisce132d82015-06-19 15:07:05 -06003781 } else {
Tobin Ehlis11efc302015-09-16 10:33:53 -06003782 for (i=0; i<count; i++) {
3783 if (pPipeNode[i]) {
3784 // If we allocated a pipeNode, need to clean it up here
3785 delete[] pPipeNode[i]->pVertexBindingDescriptions;
3786 delete[] pPipeNode[i]->pVertexAttributeDescriptions;
3787 delete[] pPipeNode[i]->pAttachments;
3788 delete pPipeNode[i];
3789 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003790 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003791 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003792 }
Courtney Goeltzenleuchtere2aaad02015-04-13 16:16:04 -06003793 return result;
3794}
3795
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003796VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateComputePipelines(
3797 VkDevice device,
3798 VkPipelineCache pipelineCache,
3799 uint32_t count,
3800 const VkComputePipelineCreateInfo *pCreateInfos,
3801 const VkAllocationCallbacks *pAllocator,
3802 VkPipeline *pPipelines)
3803{
3804 VkResult result = VK_SUCCESS;
3805 VkBool32 skipCall = VK_FALSE;
3806
3807 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
3808 vector<PIPELINE_NODE*> pPipeNode(count);
3809 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3810
3811 uint32_t i=0;
3812 loader_platform_thread_lock_mutex(&globalLock);
3813 for (i=0; i<count; i++) {
3814 // TODO: Verify compute stage bits
3815
3816 // Create and initialize internal tracking data structure
3817 pPipeNode[i] = new PIPELINE_NODE;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003818 memcpy(&pPipeNode[i]->computePipelineCI, (const void*)&pCreateInfos[i], sizeof(VkComputePipelineCreateInfo));
3819
3820 // TODO: Add Compute Pipeline Verification
3821 // skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
3822 }
3823 loader_platform_thread_unlock_mutex(&globalLock);
3824
3825 if (VK_FALSE == skipCall) {
3826 result = dev_data->device_dispatch_table->CreateComputePipelines(device, pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
3827 loader_platform_thread_lock_mutex(&globalLock);
3828 for (i=0; i<count; i++) {
3829 pPipeNode[i]->pipeline = pPipelines[i];
3830 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
3831 }
3832 loader_platform_thread_unlock_mutex(&globalLock);
3833 } else {
3834 for (i=0; i<count; i++) {
3835 if (pPipeNode[i]) {
3836 // Clean up any locally allocated data structures
3837 delete pPipeNode[i];
3838 }
3839 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003840 return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003841 }
3842 return result;
3843}
3844
Chia-I Wu9ab61502015-11-06 06:42:02 +08003845VK_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 -06003846{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003847 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003848 VkResult result = dev_data->device_dispatch_table->CreateSampler(device, pCreateInfo, pAllocator, pSampler);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003849 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003850 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003851 dev_data->sampleMap[*pSampler] = unique_ptr<SAMPLER_NODE>(new SAMPLER_NODE(pSampler, pCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003852 loader_platform_thread_unlock_mutex(&globalLock);
3853 }
3854 return result;
3855}
3856
Chia-I Wu9ab61502015-11-06 06:42:02 +08003857VK_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 -06003858{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003859 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003860 VkResult result = dev_data->device_dispatch_table->CreateDescriptorSetLayout(device, pCreateInfo, pAllocator, pSetLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003861 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003862 // TODOSC : Capture layout bindings set
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003863 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
3864 if (NULL == pNewNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003865 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 -06003866 "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003867 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003868 }
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06003869 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003870 pNewNode->createInfo.pBindings = new VkDescriptorSetLayoutBinding[pCreateInfo->bindingCount];
3871 memcpy((void*)pNewNode->createInfo.pBindings, pCreateInfo->pBindings, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->bindingCount);
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003872 // g++ does not like reserve with size 0
3873 if (pCreateInfo->bindingCount)
3874 pNewNode->bindings.reserve(pCreateInfo->bindingCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003875 uint32_t totalCount = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003876 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003877 if (!pNewNode->bindings.insert(pCreateInfo->pBindings[i].binding).second) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003878 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 +08003879 "duplicated binding number in VkDescriptorSetLayoutBinding"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003880 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003881 }
3882
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003883 totalCount += pCreateInfo->pBindings[i].descriptorCount;
3884 if (pCreateInfo->pBindings[i].pImmutableSamplers) {
3885 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBindings[i].pImmutableSamplers;
3886 *ppIS = new VkSampler[pCreateInfo->pBindings[i].descriptorCount];
3887 memcpy(*ppIS, pCreateInfo->pBindings[i].pImmutableSamplers, pCreateInfo->pBindings[i].descriptorCount*sizeof(VkSampler));
Tobin Ehlis793ad302015-04-03 12:01:11 -06003888 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003889 }
Tobin Ehlis43c39c02016-01-11 13:18:40 -07003890 pNewNode->layout = *pSetLayout;
3891 pNewNode->startIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003892 if (totalCount > 0) {
Cody Northrop43751cc2015-10-26 14:07:35 -06003893 pNewNode->descriptorTypes.resize(totalCount);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06003894 pNewNode->stageFlags.resize(totalCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003895 uint32_t offset = 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06003896 uint32_t j = 0;
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07003897 VkDescriptorType dType;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003898 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003899 dType = pCreateInfo->pBindings[i].descriptorType;
3900 for (j = 0; j < pCreateInfo->pBindings[i].descriptorCount; j++) {
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07003901 pNewNode->descriptorTypes[offset + j] = dType;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003902 pNewNode->stageFlags[offset + j] = pCreateInfo->pBindings[i].stageFlags;
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07003903 if ((dType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
3904 (dType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
3905 pNewNode->dynamicDescriptorCount++;
3906 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003907 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06003908 offset += j;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003909 }
Tobin Ehlis43c39c02016-01-11 13:18:40 -07003910 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
3911 } else { // no descriptors
3912 pNewNode->endIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003913 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003914 // Put new node at Head of global Layer list
3915 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07003916 dev_data->descriptorSetLayoutMap[*pSetLayout] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003917 loader_platform_thread_unlock_mutex(&globalLock);
3918 }
3919 return result;
3920}
3921
Chia-I Wu9ab61502015-11-06 06:42:02 +08003922VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003923{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003924 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003925 VkResult result = dev_data->device_dispatch_table->CreatePipelineLayout(device, pCreateInfo, pAllocator, pPipelineLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003926 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003927 // TODOSC : Merge capture of the setLayouts per pipeline
Tobin Ehlis559c6382015-11-05 09:52:49 -07003928 PIPELINE_LAYOUT_NODE& plNode = dev_data->pipelineLayoutMap[*pPipelineLayout];
Chia-I Wud50a7d72015-10-26 20:48:51 +08003929 plNode.descriptorSetLayouts.resize(pCreateInfo->setLayoutCount);
Tobin Ehlis644ff042015-10-20 10:11:55 -06003930 uint32_t i = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003931 for (i=0; i<pCreateInfo->setLayoutCount; ++i) {
Tobin Ehlis644ff042015-10-20 10:11:55 -06003932 plNode.descriptorSetLayouts[i] = pCreateInfo->pSetLayouts[i];
3933 }
Cody Northrop43751cc2015-10-26 14:07:35 -06003934 plNode.pushConstantRanges.resize(pCreateInfo->pushConstantRangeCount);
Tobin Ehlis644ff042015-10-20 10:11:55 -06003935 for (i=0; i<pCreateInfo->pushConstantRangeCount; ++i) {
3936 plNode.pushConstantRanges[i] = pCreateInfo->pPushConstantRanges[i];
3937 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06003938 }
3939 return result;
3940}
3941
Chia-I Wu9ab61502015-11-06 06:42:02 +08003942VK_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 -06003943{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003944 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003945 VkResult result = dev_data->device_dispatch_table->CreateDescriptorPool(device, pCreateInfo, pAllocator, pDescriptorPool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003946 if (VK_SUCCESS == result) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06003947 // Insert this pool into Global Pool LL at head
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003948 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 +08003949 "Created Descriptor Pool %#" PRIxLEAST64, (uint64_t) *pDescriptorPool))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003950 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003951 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003952 DESCRIPTOR_POOL_NODE* pNewNode = new DESCRIPTOR_POOL_NODE(*pDescriptorPool, pCreateInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003953 if (NULL == pNewNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003954 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 -07003955 "Out of memory while attempting to allocate DESCRIPTOR_POOL_NODE in vkCreateDescriptorPool()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003956 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisce132d82015-06-19 15:07:05 -06003957 } else {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003958 dev_data->descriptorPoolMap[*pDescriptorPool] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003959 }
3960 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisce132d82015-06-19 15:07:05 -06003961 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06003962 // Need to do anything if pool create fails?
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003963 }
3964 return result;
3965}
3966
Chia-I Wu9ab61502015-11-06 06:42:02 +08003967VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorPoolResetFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003968{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003969 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003970 VkResult result = dev_data->device_dispatch_table->ResetDescriptorPool(device, descriptorPool, flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003971 if (VK_SUCCESS == result) {
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003972 clearDescriptorPool(dev_data, device, descriptorPool, flags);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003973 }
3974 return result;
3975}
3976
Chia-I Wu9ab61502015-11-06 06:42:02 +08003977VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo* pAllocateInfo, VkDescriptorSet* pDescriptorSets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003978{
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003979 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis0b632332015-10-07 09:38:40 -06003980 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003981 // Verify that requested descriptorSets are available in pool
Mark Lobodzinski39298632015-11-18 08:38:27 -07003982 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003983 if (!pPoolNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003984 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 +08003985 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003986 } else { // Make sure pool has all the available descriptors before calling down chain
Jon Ashburnf19916e2016-01-11 13:12:43 -07003987 skipCall |= validate_descriptor_availability_in_pool(dev_data, pPoolNode, pAllocateInfo->descriptorSetCount, pAllocateInfo->pSetLayouts);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003988 }
3989 if (skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003990 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003991 VkResult result = dev_data->device_dispatch_table->AllocateDescriptorSets(device, pAllocateInfo, pDescriptorSets);
Cody Northrop1e4f8022015-08-03 12:47:29 -06003992 if (VK_SUCCESS == result) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003993 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003994 if (pPoolNode) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07003995 if (pAllocateInfo->descriptorSetCount == 0) {
3996 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 +08003997 "AllocateDescriptorSets called with 0 count");
Cody Northrop1e4f8022015-08-03 12:47:29 -06003998 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07003999 for (uint32_t i = 0; i < pAllocateInfo->descriptorSetCount; i++) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004000 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 +08004001 "Created Descriptor Set %#" PRIxLEAST64, (uint64_t) pDescriptorSets[i]);
Tobin Ehlis793ad302015-04-03 12:01:11 -06004002 // Create new set node and add to head of pool nodes
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004003 SET_NODE* pNewNode = new SET_NODE;
4004 if (NULL == pNewNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004005 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 +08004006 "Out of memory while attempting to allocate SET_NODE in vkAllocateDescriptorSets()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004007 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisce132d82015-06-19 15:07:05 -06004008 } else {
Tobin Ehlis8b5b28c2015-10-19 12:09:13 -06004009 // TODO : Pool should store a total count of each type of Descriptor available
4010 // When descriptors are allocated, decrement the count and validate here
4011 // that the count doesn't go below 0. One reset/free need to bump count back up.
Tobin Ehlis793ad302015-04-03 12:01:11 -06004012 // Insert set at head of Set LL for this pool
4013 pNewNode->pNext = pPoolNode->pSets;
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07004014 pNewNode->in_use.store(0);
Tobin Ehlis793ad302015-04-03 12:01:11 -06004015 pPoolNode->pSets = pNewNode;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004016 LAYOUT_NODE* pLayout = getLayoutNode(dev_data, pAllocateInfo->pSetLayouts[i]);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004017 if (NULL == pLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004018 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 +08004019 "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 -07004020 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004021 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06004022 pNewNode->pLayout = pLayout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004023 pNewNode->pool = pAllocateInfo->descriptorPool;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004024 pNewNode->set = pDescriptorSets[i];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004025 pNewNode->descriptorCount = pLayout->endIndex + 1;
4026 if (pNewNode->descriptorCount) {
4027 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
4028 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
4029 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
4030 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08004031 dev_data->setMap[pDescriptorSets[i]] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004032 }
4033 }
4034 }
4035 }
4036 return result;
4037}
4038
Chia-I Wu9ab61502015-11-06 06:42:02 +08004039VK_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 -06004040{
Tobin Ehlise735c692015-10-08 13:13:50 -06004041 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis0b632332015-10-07 09:38:40 -06004042 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07004043 // Make sure that no sets being destroyed are in-flight
4044 for (uint32_t i=0; i<count; ++i)
4045 skipCall |= validateIdleDescriptorSet(dev_data, pDescriptorSets[i], "vkFreeDesriptorSets");
Mark Lobodzinski39298632015-11-18 08:38:27 -07004046 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, descriptorPool);
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004047 if (pPoolNode && !(VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT & pPoolNode->createInfo.flags)) {
4048 // Can't Free from a NON_FREE pool
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004049 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 -06004050 "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 -06004051 }
Mark Youngb20a6a82016-01-07 15:41:43 -07004052 if (VK_FALSE != skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004053 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis0b632332015-10-07 09:38:40 -06004054 VkResult result = dev_data->device_dispatch_table->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004055 if (VK_SUCCESS == result) {
4056 // For each freed descriptor add it back into the pool as available
4057 for (uint32_t i=0; i<count; ++i) {
Chia-I Wue2fc5522015-10-26 20:04:44 +08004058 SET_NODE* pSet = dev_data->setMap[pDescriptorSets[i]]; // getSetNode() without locking
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004059 LAYOUT_NODE* pLayout = pSet->pLayout;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004060 uint32_t typeIndex = 0, poolSizeCount = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004061 for (uint32_t j=0; j<pLayout->createInfo.bindingCount; ++j) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07004062 typeIndex = static_cast<uint32_t>(pLayout->createInfo.pBindings[j].descriptorType);
4063 poolSizeCount = pLayout->createInfo.pBindings[j].descriptorCount;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004064 pPoolNode->availableDescriptorTypeCount[typeIndex] += poolSizeCount;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004065 }
4066 }
4067 }
4068 // TODO : Any other clean-up or book-keeping to do here?
Tony Barbour34ec6922015-07-10 10:50:45 -06004069 return result;
4070}
4071
Chia-I Wu9ab61502015-11-06 06:42:02 +08004072VK_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 -06004073{
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06004074 // 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 -06004075 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08004076 if (!dsUpdate(dev_data, device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies)) {
4077 dev_data->device_dispatch_table->UpdateDescriptorSets(device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies);
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004078 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004079}
4080
Chia-I Wu9ab61502015-11-06 06:42:02 +08004081VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo* pCreateInfo, VkCommandBuffer* pCommandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004082{
Tobin Ehlis0b632332015-10-07 09:38:40 -06004083 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004084 VkResult result = dev_data->device_dispatch_table->AllocateCommandBuffers(device, pCreateInfo, pCommandBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004085 if (VK_SUCCESS == result) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004086 for (uint32_t i = 0; i < pCreateInfo->commandBufferCount; i++) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07004087 // Validate command pool
4088 if (dev_data->commandPoolMap.find(pCreateInfo->commandPool) != dev_data->commandPoolMap.end()) {
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07004089 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07004090 // Add command buffer to its commandPool map
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004091 dev_data->commandPoolMap[pCreateInfo->commandPool].commandBuffers.push_back(pCommandBuffer[i]);
Mark Lobodzinski39298632015-11-18 08:38:27 -07004092 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
4093 // Add command buffer to map
4094 dev_data->commandBufferMap[pCommandBuffer[i]] = pCB;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07004095 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07004096 resetCB(dev_data, pCommandBuffer[i]);
4097 pCB->commandBuffer = pCommandBuffer[i];
4098 pCB->createInfo = *pCreateInfo;
Mark Lobodzinski941aea92016-01-13 10:23:15 -07004099 pCB->device = device;
Mark Lobodzinski39298632015-11-18 08:38:27 -07004100 }
4101 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004102 }
4103 return result;
4104}
4105
Chia-I Wu9ab61502015-11-06 06:42:02 +08004106VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo* pBeginInfo)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004107{
Mark Youngb20a6a82016-01-07 15:41:43 -07004108 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004109 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004110 // Validate command buffer level
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004111 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004112 if (pCB) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004113 if (pCB->createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
4114 // Secondary Command Buffer
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004115 // TODO : Add check here from spec "If commandBuffer is a secondary command buffer and either the
4116 // occlusionQueryEnable member of pBeginInfo is VK_FALSE, or the precise occlusion queries feature
4117 // is not enabled, the queryFlags member of pBeginInfo must not contain VK_QUERY_CONTROL_PRECISE_BIT"
Jon Ashburnf19916e2016-01-11 13:12:43 -07004118 const VkCommandBufferInheritanceInfo *pInfo = pBeginInfo->pInheritanceInfo;
Tobin Ehlis651d9b02015-12-16 05:01:22 -07004119 if (pBeginInfo->flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004120 if (!pInfo->renderPass) { // renderpass should NOT be null for an Secondary CB
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004121 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 -07004122 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) must specify a valid renderpass parameter.", (void*)commandBuffer);
4123 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07004124 if (!pInfo->framebuffer) { // framebuffer may be null for an Secondary CB, but this affects perf
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004125 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 -07004126 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) may perform better if a valid framebuffer parameter is specified.", (void*)commandBuffer);
4127 } else {
4128 string errorString = "";
Jon Ashburnf19916e2016-01-11 13:12:43 -07004129 VkRenderPass fbRP = dev_data->frameBufferMap[pInfo->framebuffer]->renderPass;
4130 if (!verify_renderpass_compatibility(dev_data, fbRP, pInfo->renderPass, errorString)) {
Tobin Ehlis651d9b02015-12-16 05:01:22 -07004131 // renderPass that framebuffer was created with must be compatible with local renderPass
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004132 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 -07004133 "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 -07004134 (void*)commandBuffer, (uint64_t)pInfo->renderPass, (uint64_t)pInfo->framebuffer, (uint64_t)fbRP, errorString.c_str());
Tobin Ehlis651d9b02015-12-16 05:01:22 -07004135 }
4136 }
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004137 }
4138 }
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004139 if (CB_RECORDING == pCB->state) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004140 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 -07004141 "vkBeginCommandBuffer(): Cannot call Begin on CB (%#" PRIxLEAST64 ") in the RECORDING state. Must first call vkEndCommandBuffer().", (uint64_t)commandBuffer);
4142 } else if (CB_RECORDED == pCB->state) {
4143 VkCommandPool cmdPool = pCB->createInfo.commandPool;
4144 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004145 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 -07004146 __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004147 "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.",
4148 (uint64_t) commandBuffer, (uint64_t) cmdPool);
4149 }
Tobin Ehlisef694652016-01-19 12:03:34 -07004150 resetCB(dev_data, commandBuffer);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004151 }
Tobin Ehlisef694652016-01-19 12:03:34 -07004152 // Set updated state here in case implicit reset occurs above
4153 pCB->state = CB_RECORDING;
4154 pCB->beginInfo = *pBeginInfo;
Tobin Ehliscd5bfd82016-01-19 13:12:52 -07004155
4156 if (pCB->beginInfo.pInheritanceInfo) {
4157 pCB->inheritanceInfo = *(pCB->beginInfo.pInheritanceInfo);
4158 pCB->beginInfo.pInheritanceInfo = &pCB->inheritanceInfo;
4159 }
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004160 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004161 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 +08004162 "In vkBeginCommandBuffer() and unable to find CommandBuffer Node for CB %p!", (void*)commandBuffer);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004163 }
Mark Youngb20a6a82016-01-07 15:41:43 -07004164 if (VK_FALSE != skipCall) {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004165 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter5fe086f2015-09-04 15:03:52 -06004166 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004167 VkResult result = dev_data->device_dispatch_table->BeginCommandBuffer(commandBuffer, pBeginInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004168 return result;
4169}
4170
Chia-I Wu9ab61502015-11-06 06:42:02 +08004171VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEndCommandBuffer(VkCommandBuffer commandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004172{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004173 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchtered894072015-09-04 13:39:59 -06004174 VkResult result = VK_SUCCESS;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004175 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4176 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004177 if (pCB) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004178 if (pCB->state != CB_RECORDING) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004179 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkEndCommandBuffer()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004180 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004181 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004182 if (VK_FALSE == skipCall) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004183 result = dev_data->device_dispatch_table->EndCommandBuffer(commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004184 if (VK_SUCCESS == result) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004185 pCB->state = CB_RECORDED;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004186 // Reset CB status flags
4187 pCB->status = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004188 printCB(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004189 }
4190 } else {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004191 result = VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004192 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004193 return result;
4194}
4195
Chia-I Wu9ab61502015-11-06 06:42:02 +08004196VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004197{
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004198 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004199 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004200 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
4201 VkCommandPool cmdPool = pCB->createInfo.commandPool;
4202 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004203 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 -07004204 __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004205 "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.",
4206 (uint64_t) commandBuffer, (uint64_t) cmdPool);
4207 }
Mark Youngb20a6a82016-01-07 15:41:43 -07004208 if (skipCall != VK_FALSE)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004209 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004210 VkResult result = dev_data->device_dispatch_table->ResetCommandBuffer(commandBuffer, flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004211 if (VK_SUCCESS == result) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004212 resetCB(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004213 }
4214 return result;
4215}
4216
Chia-I Wu9ab61502015-11-06 06:42:02 +08004217VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004218{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004219 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004220 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4221 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004222 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004223 skipCall |= addCmd(dev_data, pCB, CMD_BINDPIPELINE, "vkCmdBindPipeline()");
4224 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
4225 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 -07004226 __LINE__, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004227 "Incorrectly binding compute pipeline (%#" PRIxLEAST64 ") during active RenderPass (%#" PRIxLEAST64 ")",
4228 (uint64_t) pipeline, (uint64_t) pCB->activeRenderPass);
4229 } else if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
4230 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdBindPipeline");
4231 }
4232
4233 PIPELINE_NODE* pPN = getPipeline(dev_data, pipeline);
4234 if (pPN) {
4235 pCB->lastBoundPipeline = pipeline;
4236 loader_platform_thread_lock_mutex(&globalLock);
4237 set_cb_pso_status(pCB, pPN);
4238 loader_platform_thread_unlock_mutex(&globalLock);
4239 skipCall |= validatePipelineState(dev_data, pCB, pipelineBindPoint, pipeline);
Tobin Ehlisce132d82015-06-19 15:07:05 -06004240 } else {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004241 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 -07004242 (uint64_t) pipeline, __LINE__, DRAWSTATE_INVALID_PIPELINE, "DS",
Mark Young93ecb1d2016-01-13 13:47:16 -07004243 "Attempt to bind Pipeline %#" PRIxLEAST64 " that doesn't exist!", (uint64_t)(pipeline));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004244 }
4245 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004246 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004247 dev_data->device_dispatch_table->CmdBindPipeline(commandBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004248}
4249
Chia-I Wu9ab61502015-11-06 06:42:02 +08004250VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetViewport(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004251 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004252 uint32_t firstViewport,
4253 uint32_t viewportCount,
4254 const VkViewport* pViewports)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004255{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004256 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004257 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4258 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004259 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004260 skipCall |= addCmd(dev_data, pCB, CMD_SETVIEWPORTSTATE, "vkCmdSetViewport()");
4261 loader_platform_thread_lock_mutex(&globalLock);
4262 pCB->status |= CBSTATUS_VIEWPORT_SET;
4263 pCB->viewports.resize(viewportCount);
4264 memcpy(pCB->viewports.data(), pViewports, viewportCount * sizeof(VkViewport));
4265 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004266 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004267 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004268 dev_data->device_dispatch_table->CmdSetViewport(commandBuffer, firstViewport, viewportCount, pViewports);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004269}
4270
Chia-I Wu9ab61502015-11-06 06:42:02 +08004271VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetScissor(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004272 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004273 uint32_t firstScissor,
4274 uint32_t scissorCount,
4275 const VkRect2D* pScissors)
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004276{
4277 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004278 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4279 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004280 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004281 skipCall |= addCmd(dev_data, pCB, CMD_SETSCISSORSTATE, "vkCmdSetScissor()");
4282 loader_platform_thread_lock_mutex(&globalLock);
4283 pCB->status |= CBSTATUS_SCISSOR_SET;
4284 pCB->scissors.resize(scissorCount);
4285 memcpy(pCB->scissors.data(), pScissors, scissorCount * sizeof(VkRect2D));
4286 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004287 }
4288 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004289 dev_data->device_dispatch_table->CmdSetScissor(commandBuffer, firstScissor, scissorCount, pScissors);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004290}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004291
Chia-I Wu9ab61502015-11-06 06:42:02 +08004292VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004293{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004294 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004295 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4296 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004297 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004298 skipCall |= addCmd(dev_data, pCB, CMD_SETLINEWIDTHSTATE, "vkCmdSetLineWidth()");
4299 /* TODO: Do we still need this lock? */
4300 loader_platform_thread_lock_mutex(&globalLock);
4301 pCB->status |= CBSTATUS_LINE_WIDTH_SET;
4302 pCB->lineWidth = lineWidth;
4303 loader_platform_thread_unlock_mutex(&globalLock);
Cody Northrop12365112015-08-17 11:10:49 -06004304 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004305 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004306 dev_data->device_dispatch_table->CmdSetLineWidth(commandBuffer, lineWidth);
Cody Northrop12365112015-08-17 11:10:49 -06004307}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004308
Chia-I Wu9ab61502015-11-06 06:42:02 +08004309VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBias(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004310 VkCommandBuffer commandBuffer,
Chia-I Wud8c946a2015-10-26 19:08:09 +08004311 float depthBiasConstantFactor,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004312 float depthBiasClamp,
Chia-I Wud8c946a2015-10-26 19:08:09 +08004313 float depthBiasSlopeFactor)
Cody Northrop12365112015-08-17 11:10:49 -06004314{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004315 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004316 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4317 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northrop12365112015-08-17 11:10:49 -06004318 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004319 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBIASSTATE, "vkCmdSetDepthBias()");
4320 pCB->status |= CBSTATUS_DEPTH_BIAS_SET;
4321 pCB->depthBiasConstantFactor = depthBiasConstantFactor;
4322 pCB->depthBiasClamp = depthBiasClamp;
4323 pCB->depthBiasSlopeFactor = depthBiasSlopeFactor;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004324 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004325 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004326 dev_data->device_dispatch_table->CmdSetDepthBias(commandBuffer, depthBiasConstantFactor, depthBiasClamp, depthBiasSlopeFactor);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004327}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004328
Chia-I Wu9ab61502015-11-06 06:42:02 +08004329VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4])
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004330{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004331 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004332 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4333 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004334 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004335 skipCall |= addCmd(dev_data, pCB, CMD_SETBLENDSTATE, "vkCmdSetBlendConstants()");
4336 pCB->status |= CBSTATUS_BLEND_SET;
4337 memcpy(pCB->blendConstants, blendConstants, 4 * sizeof(float));
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004338 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004339 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004340 dev_data->device_dispatch_table->CmdSetBlendConstants(commandBuffer, blendConstants);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004341}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004342
Chia-I Wu9ab61502015-11-06 06:42:02 +08004343VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBounds(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004344 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004345 float minDepthBounds,
4346 float maxDepthBounds)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004347{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004348 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004349 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4350 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004351 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004352 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBOUNDSSTATE, "vkCmdSetDepthBounds()");
4353 pCB->status |= CBSTATUS_DEPTH_BOUNDS_SET;
4354 pCB->minDepthBounds = minDepthBounds;
4355 pCB->maxDepthBounds = maxDepthBounds;
Cody Northrop82485a82015-08-18 15:21:16 -06004356 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004357 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004358 dev_data->device_dispatch_table->CmdSetDepthBounds(commandBuffer, minDepthBounds, maxDepthBounds);
Cody Northrop82485a82015-08-18 15:21:16 -06004359}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004360
Chia-I Wu9ab61502015-11-06 06:42:02 +08004361VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilCompareMask(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004362 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004363 VkStencilFaceFlags faceMask,
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004364 uint32_t compareMask)
Cody Northrop82485a82015-08-18 15:21:16 -06004365{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004366 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004367 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4368 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northrop82485a82015-08-18 15:21:16 -06004369 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004370 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREADMASKSTATE, "vkCmdSetStencilCompareMask()");
4371 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4372 pCB->front.compareMask = compareMask;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004373 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004374 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4375 pCB->back.compareMask = compareMask;
4376 }
4377 /* TODO: Do we need to track front and back separately? */
4378 /* TODO: We aren't capturing the faceMask, do we need to? */
4379 pCB->status |= CBSTATUS_STENCIL_READ_MASK_SET;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004380 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004381 if (VK_FALSE == skipCall)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004382 dev_data->device_dispatch_table->CmdSetStencilCompareMask(commandBuffer, faceMask, compareMask);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004383}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004384
Chia-I Wu9ab61502015-11-06 06:42:02 +08004385VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilWriteMask(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004386 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004387 VkStencilFaceFlags faceMask,
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004388 uint32_t writeMask)
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004389{
4390 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004391 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4392 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004393 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004394 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILWRITEMASKSTATE, "vkCmdSetStencilWriteMask()");
4395 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4396 pCB->front.writeMask = writeMask;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004397 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004398 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4399 pCB->back.writeMask = writeMask;
4400 }
4401 pCB->status |= CBSTATUS_STENCIL_WRITE_MASK_SET;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004402 }
4403 if (VK_FALSE == skipCall)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004404 dev_data->device_dispatch_table->CmdSetStencilWriteMask(commandBuffer, faceMask, writeMask);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004405}
4406
Chia-I Wu9ab61502015-11-06 06:42:02 +08004407VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilReference(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004408 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004409 VkStencilFaceFlags faceMask,
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004410 uint32_t reference)
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004411{
4412 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004413 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4414 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004415 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004416 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREFERENCESTATE, "vkCmdSetStencilReference()");
4417 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4418 pCB->front.reference = reference;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004419 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004420 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4421 pCB->back.reference = reference;
4422 }
4423 pCB->status |= CBSTATUS_STENCIL_REFERENCE_SET;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004424 }
4425 if (VK_FALSE == skipCall)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004426 dev_data->device_dispatch_table->CmdSetStencilReference(commandBuffer, faceMask, reference);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004427}
4428
Chia-I Wu9ab61502015-11-06 06:42:02 +08004429VK_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 -06004430{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004431 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004432 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4433 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004434 if (pCB) {
Tobin Ehlisf6585052015-12-17 11:48:42 -07004435 if (pCB->state == CB_RECORDING) {
4436 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004437 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 -07004438 "Incorrectly binding compute DescriptorSets during active RenderPass (%#" PRIxLEAST64 ")", (uint64_t) pCB->activeRenderPass);
4439 } else if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
4440 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdBindDescriptorSets");
Mark Lobodzinski74635932015-12-18 15:35:38 -07004441 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07004442 if (VK_FALSE == skipCall) {
4443 // Track total count of dynamic descriptor types to make sure we have an offset for each one
4444 uint32_t totalDynamicDescriptors = 0;
4445 string errorString = "";
4446 uint32_t lastSetIndex = firstSet+setCount-1;
4447 if (lastSetIndex >= pCB->boundDescriptorSets.size())
Tobin Ehlis559c6382015-11-05 09:52:49 -07004448 pCB->boundDescriptorSets.resize(lastSetIndex+1);
Tobin Ehlisf6585052015-12-17 11:48:42 -07004449 VkDescriptorSet oldFinalBoundSet = pCB->boundDescriptorSets[lastSetIndex];
4450 for (uint32_t i=0; i<setCount; i++) {
4451 SET_NODE* pSet = getSetNode(dev_data, pDescriptorSets[i]);
4452 if (pSet) {
4453 loader_platform_thread_lock_mutex(&globalLock);
4454 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
4455 pCB->lastBoundPipelineLayout = layout;
4456 pCB->boundDescriptorSets[i+firstSet] = pDescriptorSets[i];
4457 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004458 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 -07004459 "DS %#" PRIxLEAST64 " bound on pipeline %s", (uint64_t) pDescriptorSets[i], string_VkPipelineBindPoint(pipelineBindPoint));
Tobin Ehlis43c39c02016-01-11 13:18:40 -07004460 if (!pSet->pUpdateStructs && (pSet->descriptorCount != 0)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004461 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 -07004462 "DS %#" PRIxLEAST64 " bound but it was never updated. You may want to either update it or not bind it.", (uint64_t) pDescriptorSets[i]);
4463 }
4464 // Verify that set being bound is compatible with overlapping setLayout of pipelineLayout
4465 if (!verify_set_layout_compatibility(dev_data, pSet, layout, i+firstSet, errorString)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004466 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 -07004467 "descriptorSet #%u being bound is not compatible with overlapping layout in pipelineLayout due to: %s", i, errorString.c_str());
4468 }
4469 if (pSet->pLayout->dynamicDescriptorCount) {
4470 // First make sure we won't overstep bounds of pDynamicOffsets array
4471 if ((totalDynamicDescriptors + pSet->pLayout->dynamicDescriptorCount) > dynamicOffsetCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004472 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 -07004473 "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.",
4474 i, (uint64_t) pDescriptorSets[i], pSet->pLayout->dynamicDescriptorCount, (dynamicOffsetCount - totalDynamicDescriptors));
Mark Lobodzinski941aea92016-01-13 10:23:15 -07004475 } else { // Validate and store dynamic offsets with the set
4476 // Validate Dynamic Offset Minimums
4477 uint32_t cur_dyn_offset = totalDynamicDescriptors;
4478 for (uint32_t d = 0; d < pSet->descriptorCount; d++) {
4479 if (pSet->pLayout->descriptorTypes[i] == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) {
4480 if (vk_safe_modulo(pDynamicOffsets[cur_dyn_offset], dev_data->physDevPropertyMap[pCB->device].limits.minUniformBufferOffsetAlignment) != 0) {
4481 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0,
4482 __LINE__, DRAWSTATE_INVALID_UNIFORM_BUFFER_OFFSET, "DS",
4483 "vkCmdBindDescriptorSets(): pDynamicOffsets[%d] is %d but must be a multiple of device limit minUniformBufferOffsetAlignment %#" PRIxLEAST64,
4484 cur_dyn_offset, pDynamicOffsets[cur_dyn_offset], dev_data->physDevPropertyMap[pCB->device].limits.minUniformBufferOffsetAlignment);
4485 }
4486 cur_dyn_offset++;
4487 } else if (pSet->pLayout->descriptorTypes[i] == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC) {
4488 if (vk_safe_modulo(pDynamicOffsets[cur_dyn_offset], dev_data->physDevPropertyMap[pCB->device].limits.minStorageBufferOffsetAlignment) != 0) {
4489 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0,
4490 __LINE__, DRAWSTATE_INVALID_STORAGE_BUFFER_OFFSET, "DS",
4491 "vkCmdBindDescriptorSets(): pDynamicOffsets[%d] is %d but must be a multiple of device limit minStorageBufferOffsetAlignment %#" PRIxLEAST64,
4492 cur_dyn_offset, pDynamicOffsets[cur_dyn_offset], dev_data->physDevPropertyMap[pCB->device].limits.minStorageBufferOffsetAlignment);
4493 }
4494 cur_dyn_offset++;
4495 }
4496 }
4497 // Store offsets
Tobin Ehlisf6585052015-12-17 11:48:42 -07004498 const uint32_t* pStartDynOffset = pDynamicOffsets + totalDynamicDescriptors;
4499 pSet->dynamicOffsets.assign(pStartDynOffset, pStartDynOffset + pSet->pLayout->dynamicDescriptorCount);
4500 totalDynamicDescriptors += pSet->pLayout->dynamicDescriptorCount;
4501 }
4502 }
4503 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004504 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 -07004505 "Attempt to bind DS %#" PRIxLEAST64 " that doesn't exist!", (uint64_t) pDescriptorSets[i]);
4506 }
4507 }
4508 skipCall |= addCmd(dev_data, pCB, CMD_BINDDESCRIPTORSETS, "vkCmdBindDescrsiptorSets()");
4509 // For any previously bound sets, need to set them to "invalid" if they were disturbed by this update
4510 if (firstSet > 0) { // Check set #s below the first bound set
4511 for (uint32_t i=0; i<firstSet; ++i) {
4512 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 -07004513 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 -07004514 "DescriptorSetDS %#" PRIxLEAST64 " previously bound as set #%u was disturbed by newly bound pipelineLayout (%#" PRIxLEAST64 ")", (uint64_t) pCB->boundDescriptorSets[i], i, (uint64_t) layout);
4515 pCB->boundDescriptorSets[i] = VK_NULL_HANDLE;
4516 }
4517 }
4518 }
4519 // Check if newly last bound set invalidates any remaining bound sets
4520 if ((pCB->boundDescriptorSets.size()-1) > (lastSetIndex)) {
4521 if (oldFinalBoundSet && !verify_set_layout_compatibility(dev_data, dev_data->setMap[oldFinalBoundSet], layout, lastSetIndex, errorString)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004522 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 -07004523 "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);
4524 pCB->boundDescriptorSets.resize(lastSetIndex+1);
4525 }
4526 }
4527 // dynamicOffsetCount must equal the total number of dynamic descriptors in the sets being bound
4528 if (totalDynamicDescriptors != dynamicOffsetCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004529 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 -07004530 "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 -07004531 }
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07004532 validateAndIncrementDescriptorSets(dev_data, pCB);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004533 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07004534 } else {
4535 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindDescriptorSets()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004536 }
4537 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004538 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004539 dev_data->device_dispatch_table->CmdBindDescriptorSets(commandBuffer, pipelineBindPoint, layout, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004540}
4541
Chia-I Wu9ab61502015-11-06 06:42:02 +08004542VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004543{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004544 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004545 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4546 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004547 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004548 skipCall |= addCmd(dev_data, pCB, CMD_BINDINDEXBUFFER, "vkCmdBindIndexBuffer()");
4549 VkDeviceSize offset_align = 0;
4550 switch (indexType) {
4551 case VK_INDEX_TYPE_UINT16:
4552 offset_align = 2;
4553 break;
4554 case VK_INDEX_TYPE_UINT32:
4555 offset_align = 4;
4556 break;
4557 default:
4558 // ParamChecker should catch bad enum, we'll also throw alignment error below if offset_align stays 0
4559 break;
4560 }
4561 if (!offset_align || (offset % offset_align)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004562 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 -07004563 "vkCmdBindIndexBuffer() offset (%#" PRIxLEAST64 ") does not fall on alignment (%s) boundary.", offset, string_VkIndexType(indexType));
Tobin Ehlis9c536442015-06-19 13:00:59 -06004564 }
Tobin Ehlisc4c23182015-09-17 12:24:13 -06004565 pCB->status |= CBSTATUS_INDEX_BUFFER_BOUND;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004566 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004567 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004568 dev_data->device_dispatch_table->CmdBindIndexBuffer(commandBuffer, buffer, offset, indexType);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004569}
4570
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07004571void updateResourceTracking(GLOBAL_CB_NODE* pCB, uint32_t firstBinding, uint32_t bindingCount, const VkBuffer* pBuffers) {
4572 uint32_t end = firstBinding + bindingCount;
Michael Lentine700b0aa2015-10-30 17:57:32 -07004573 if (pCB->currentDrawData.buffers.size() < end) {
4574 pCB->currentDrawData.buffers.resize(end);
4575 }
4576 for (uint32_t i = 0; i < bindingCount; ++i) {
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07004577 pCB->currentDrawData.buffers[i + firstBinding] = pBuffers[i];
Michael Lentine700b0aa2015-10-30 17:57:32 -07004578 }
4579}
4580
4581void updateResourceTrackingOnDraw(GLOBAL_CB_NODE* pCB) {
4582 pCB->drawData.push_back(pCB->currentDrawData);
4583}
4584
Chia-I Wu9ab61502015-11-06 06:42:02 +08004585VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindVertexBuffers(
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07004586 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004587 uint32_t firstBinding,
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06004588 uint32_t bindingCount,
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07004589 const VkBuffer *pBuffers,
4590 const VkDeviceSize *pOffsets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004591{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004592 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004593 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4594 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004595 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004596 addCmd(dev_data, pCB, CMD_BINDVERTEXBUFFER, "vkCmdBindVertexBuffer()");
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07004597 updateResourceTracking(pCB, firstBinding, bindingCount, pBuffers);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004598 } else {
Mark Youngad779052016-01-06 14:26:04 -07004599 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindVertexBuffer()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004600 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004601 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004602 dev_data->device_dispatch_table->CmdBindVertexBuffers(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004603}
4604
Chia-I Wu9ab61502015-11-06 06:42:02 +08004605VK_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 -06004606{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004607 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004608 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4609 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004610 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004611 skipCall |= addCmd(dev_data, pCB, CMD_DRAW, "vkCmdDraw()");
4612 pCB->drawCount[DRAW]++;
4613 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
4614 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004615 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 -07004616 "vkCmdDraw() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW]++);
4617 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004618 if (VK_FALSE == skipCall) {
4619 updateResourceTrackingOnDraw(pCB);
4620 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004621 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDraw");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004622 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004623 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004624 dev_data->device_dispatch_table->CmdDraw(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004625}
4626
Chia-I Wu9ab61502015-11-06 06:42:02 +08004627VK_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 -06004628{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004629 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4630 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004631 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004632 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004633 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXED, "vkCmdDrawIndexed()");
4634 pCB->drawCount[DRAW_INDEXED]++;
4635 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
4636 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004637 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 -07004638 "vkCmdDrawIndexed() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED]++);
4639 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004640 if (VK_FALSE == skipCall) {
4641 updateResourceTrackingOnDraw(pCB);
4642 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004643 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexed");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004644 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004645 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004646 dev_data->device_dispatch_table->CmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004647}
4648
Chia-I Wu9ab61502015-11-06 06:42:02 +08004649VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004650{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004651 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4652 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004653 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004654 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004655 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDIRECT, "vkCmdDrawIndirect()");
4656 pCB->drawCount[DRAW_INDIRECT]++;
4657 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
4658 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004659 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 -07004660 "vkCmdDrawIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
4661 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004662 if (VK_FALSE == skipCall) {
4663 updateResourceTrackingOnDraw(pCB);
4664 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004665 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndirect");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004666 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004667 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004668 dev_data->device_dispatch_table->CmdDrawIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004669}
4670
Chia-I Wu9ab61502015-11-06 06:42:02 +08004671VK_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 -06004672{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004673 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004674 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4675 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004676 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004677 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXEDINDIRECT, "vkCmdDrawIndexedIndirect()");
4678 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
4679 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
4680 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004681 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 -07004682 "vkCmdDrawIndexedIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
4683 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004684 if (VK_FALSE == skipCall) {
4685 updateResourceTrackingOnDraw(pCB);
4686 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004687 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexedIndirect");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004688 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004689 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004690 dev_data->device_dispatch_table->CmdDrawIndexedIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004691}
4692
Chia-I Wu9ab61502015-11-06 06:42:02 +08004693VK_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 -06004694{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004695 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004696 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4697 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004698 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004699 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCH, "vkCmdDispatch()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004700 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatch");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004701 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004702 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004703 dev_data->device_dispatch_table->CmdDispatch(commandBuffer, x, y, z);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004704}
4705
Chia-I Wu9ab61502015-11-06 06:42:02 +08004706VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004707{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004708 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004709 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4710 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004711 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004712 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCHINDIRECT, "vkCmdDispatchIndirect()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004713 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatchIndirect");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004714 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004715 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004716 dev_data->device_dispatch_table->CmdDispatchIndirect(commandBuffer, buffer, offset);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004717}
4718
Chia-I Wu9ab61502015-11-06 06:42:02 +08004719VK_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 -06004720{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004721 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004722 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4723 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004724 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004725 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFER, "vkCmdCopyBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004726 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004727 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004728 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004729 dev_data->device_dispatch_table->CmdCopyBuffer(commandBuffer, srcBuffer, dstBuffer, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004730}
4731
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07004732VkBool32 VerifySourceImageLayout(VkCommandBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout) {
Mark Youngb20a6a82016-01-07 15:41:43 -07004733 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07004734
4735#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4736 // TODO: Fix -- initialLayout may have been set in a previous command buffer
4737 return skip_call;
4738#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4739
Michael Lentineabc5e922015-10-12 11:30:14 -05004740 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4741 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4742 auto src_image_element = pCB->imageLayoutMap.find(srcImage);
4743 if (src_image_element == pCB->imageLayoutMap.end()) {
4744 pCB->imageLayoutMap[srcImage].initialLayout = srcImageLayout;
4745 pCB->imageLayoutMap[srcImage].layout = srcImageLayout;
Mark Youngb20a6a82016-01-07 15:41:43 -07004746 return VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05004747 }
4748 if (src_image_element->second.layout != srcImageLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004749 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 -05004750 "Cannot copy from an image whose source layout is %d and doesn't match the current layout %d.", srcImageLayout, src_image_element->second.layout);
4751 }
4752 if (srcImageLayout != VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL) {
4753 if (srcImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004754 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004755 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 -05004756 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Michael Lentineabc5e922015-10-12 11:30:14 -05004757 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004758 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 -05004759 "Layout for input image is %d but can only be TRANSFER_SRC_OPTIMAL or GENERAL.", srcImageLayout);
Michael Lentineabc5e922015-10-12 11:30:14 -05004760 }
4761 }
4762 return skip_call;
4763}
4764
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07004765VkBool32 VerifyDestImageLayout(VkCommandBuffer cmdBuffer, VkImage destImage, VkImageLayout destImageLayout) {
Mark Youngb20a6a82016-01-07 15:41:43 -07004766 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07004767
4768#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4769 // TODO: Fix -- initialLayout may have been set in a previous command buffer
4770 return skip_call;
4771#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4772
Michael Lentineabc5e922015-10-12 11:30:14 -05004773 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4774 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4775 auto dest_image_element = pCB->imageLayoutMap.find(destImage);
4776 if (dest_image_element == pCB->imageLayoutMap.end()) {
4777 pCB->imageLayoutMap[destImage].initialLayout = destImageLayout;
4778 pCB->imageLayoutMap[destImage].layout = destImageLayout;
Mark Youngb20a6a82016-01-07 15:41:43 -07004779 return VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05004780 }
4781 if (dest_image_element->second.layout != destImageLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004782 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 -05004783 "Cannot copy from an image whose dest layout is %d and doesn't match the current layout %d.", destImageLayout, dest_image_element->second.layout);
4784 }
4785 if (destImageLayout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) {
4786 if (destImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004787 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004788 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 -05004789 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
4790 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004791 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 -05004792 "Layout for output image is %d but can only be TRANSFER_DST_OPTIMAL or GENERAL.", destImageLayout);
4793 }
4794 }
4795 return skip_call;
4796}
4797
Chia-I Wu9ab61502015-11-06 06:42:02 +08004798VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004799 VkImage srcImage,
4800 VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004801 VkImage dstImage,
4802 VkImageLayout dstImageLayout,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004803 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004804{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004805 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004806 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4807 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004808 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004809 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGE, "vkCmdCopyImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004810 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImage");
Michael Lentineabc5e922015-10-12 11:30:14 -05004811 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
4812 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004813 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004814 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004815 dev_data->device_dispatch_table->CmdCopyImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004816}
4817
Chia-I Wu9ab61502015-11-06 06:42:02 +08004818VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBlitImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004819 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004820 VkImage dstImage, VkImageLayout dstImageLayout,
Mark Lobodzinskiee5eef12015-05-22 14:43:25 -05004821 uint32_t regionCount, const VkImageBlit* pRegions,
Chia-I Wub99df442015-10-26 16:49:32 +08004822 VkFilter filter)
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004823{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004824 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004825 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4826 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004827 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004828 skipCall |= addCmd(dev_data, pCB, CMD_BLITIMAGE, "vkCmdBlitImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004829 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBlitImage");
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004830 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004831 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004832 dev_data->device_dispatch_table->CmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter);
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004833}
4834
Chia-I Wu9ab61502015-11-06 06:42:02 +08004835VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004836 VkBuffer srcBuffer,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004837 VkImage dstImage, VkImageLayout dstImageLayout,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004838 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004839{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004840 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004841 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4842 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004843 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004844 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFERTOIMAGE, "vkCmdCopyBufferToImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004845 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBufferToImage");
Michael Lentineabc5e922015-10-12 11:30:14 -05004846 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004847 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004848 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004849 dev_data->device_dispatch_table->CmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004850}
4851
Chia-I Wu9ab61502015-11-06 06:42:02 +08004852VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004853 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004854 VkBuffer dstBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004855 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004856{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004857 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004858 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4859 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004860 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004861 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGETOBUFFER, "vkCmdCopyImageToBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004862 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImageToBuffer");
Michael Lentineabc5e922015-10-12 11:30:14 -05004863 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004864 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004865 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004866 dev_data->device_dispatch_table->CmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004867}
4868
Chia-I Wu9ab61502015-11-06 06:42:02 +08004869VK_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 -06004870{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004871 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004872 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4873 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004874 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004875 skipCall |= addCmd(dev_data, pCB, CMD_UPDATEBUFFER, "vkCmdUpdateBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004876 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyUpdateBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004877 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004878 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004879 dev_data->device_dispatch_table->CmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004880}
4881
Chia-I Wu9ab61502015-11-06 06:42:02 +08004882VK_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 -06004883{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004884 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004885 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4886 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004887 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004888 skipCall |= addCmd(dev_data, pCB, CMD_FILLBUFFER, "vkCmdFillBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004889 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyFillBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004890 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004891 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004892 dev_data->device_dispatch_table->CmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004893}
4894
Chia-I Wu9ab61502015-11-06 06:42:02 +08004895VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearAttachments(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004896 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004897 uint32_t attachmentCount,
4898 const VkClearAttachment* pAttachments,
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004899 uint32_t rectCount,
Courtney Goeltzenleuchter4ca43f62015-10-15 18:22:08 -06004900 const VkClearRect* pRects)
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004901{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004902 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004903 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4904 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004905 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004906 skipCall |= addCmd(dev_data, pCB, CMD_CLEARATTACHMENTS, "vkCmdClearAttachments()");
4907 // Warn if this is issued prior to Draw Cmd and clearing the entire attachment
4908 if (!hasDrawCmd(pCB) &&
4909 (pCB->activeRenderPassBeginInfo.renderArea.extent.width == pRects[0].rect.extent.width) &&
4910 (pCB->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) {
4911 // TODO : commandBuffer should be srcObj
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004912 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 -07004913 "vkCmdClearAttachments() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
Mark Youngee3f3a22016-01-25 12:18:32 -07004914 " It is recommended you use RenderPass LOAD_OP_CLEAR on Attachments prior to any Draw.", (uint64_t)(commandBuffer));
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004915 }
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004916 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdClearAttachments");
4917 }
4918
4919 // Validate that attachment is in reference list of active subpass
4920 if (pCB->activeRenderPass) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07004921 const VkRenderPassCreateInfo *pRPCI = dev_data->renderPassMap[pCB->activeRenderPass]->pCreateInfo;
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004922 const VkSubpassDescription *pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
4923
4924 for (uint32_t attachment_idx = 0; attachment_idx < attachmentCount; attachment_idx++) {
4925 const VkClearAttachment *attachment = &pAttachments[attachment_idx];
4926 if (attachment->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) {
4927 VkBool32 found = VK_FALSE;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004928 for (uint32_t i = 0; i < pSD->colorAttachmentCount; i++) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004929 if (attachment->colorAttachment == pSD->pColorAttachments[i].attachment) {
4930 found = VK_TRUE;
4931 break;
4932 }
4933 }
4934 if (VK_FALSE == found) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004935 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 -07004936 (uint64_t)commandBuffer, __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004937 "vkCmdClearAttachments() attachment index %d not found in attachment reference array of active subpass %d",
4938 attachment->colorAttachment, pCB->activeSubpass);
4939 }
4940 } else if (attachment->aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) {
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07004941 if (!pSD->pDepthStencilAttachment || // Says no DS will be used in active subpass
Mark Lobodzinski2fd355a2015-11-18 08:58:31 -07004942 (pSD->pDepthStencilAttachment->attachment == VK_ATTACHMENT_UNUSED)) { // Says no DS will be used in active subpass
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07004943
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004944 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 -07004945 (uint64_t)commandBuffer, __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07004946 "vkCmdClearAttachments() attachment index %d does not match depthStencilAttachment.attachment (%d) found in active subpass %d",
4947 attachment->colorAttachment,
4948 (pSD->pDepthStencilAttachment) ? pSD->pDepthStencilAttachment->attachment : VK_ATTACHMENT_UNUSED,
4949 pCB->activeSubpass);
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004950 }
4951 }
4952 }
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004953 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004954 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004955 dev_data->device_dispatch_table->CmdClearAttachments(commandBuffer, attachmentCount, pAttachments, rectCount, pRects);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004956}
4957
Chia-I Wu9ab61502015-11-06 06:42:02 +08004958VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearColorImage(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004959 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06004960 VkImage image, VkImageLayout imageLayout,
Chris Forbesf0796e12015-06-24 14:34:53 +12004961 const VkClearColorValue *pColor,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06004962 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004963{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004964 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004965 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4966 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004967 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004968 skipCall |= addCmd(dev_data, pCB, CMD_CLEARCOLORIMAGE, "vkCmdClearColorImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004969 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearColorImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004970 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004971 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004972 dev_data->device_dispatch_table->CmdClearColorImage(commandBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004973}
4974
Chia-I Wu9ab61502015-11-06 06:42:02 +08004975VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearDepthStencilImage(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004976 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter45df9e12015-09-15 18:03:22 -06004977 VkImage image, VkImageLayout imageLayout,
4978 const VkClearDepthStencilValue *pDepthStencil,
4979 uint32_t rangeCount,
4980 const VkImageSubresourceRange* pRanges)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004981{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004982 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004983 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4984 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004985 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004986 skipCall |= addCmd(dev_data, pCB, CMD_CLEARDEPTHSTENCILIMAGE, "vkCmdClearDepthStencilImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004987 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearDepthStencilImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004988 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004989 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004990 dev_data->device_dispatch_table->CmdClearDepthStencilImage(commandBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004991}
4992
Chia-I Wu9ab61502015-11-06 06:42:02 +08004993VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResolveImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004994 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004995 VkImage dstImage, VkImageLayout dstImageLayout,
Tony Barbour6865d4a2015-04-13 15:02:52 -06004996 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004997{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004998 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004999 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5000 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005001 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005002 skipCall |= addCmd(dev_data, pCB, CMD_RESOLVEIMAGE, "vkCmdResolveImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005003 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResolveImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005004 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005005 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005006 dev_data->device_dispatch_table->CmdResolveImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005007}
5008
Chia-I Wu9ab61502015-11-06 06:42:02 +08005009VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005010{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005011 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005012 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5013 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005014 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005015 skipCall |= addCmd(dev_data, pCB, CMD_SETEVENT, "vkCmdSetEvent()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005016 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdSetEvent");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005017 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005018 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005019 dev_data->device_dispatch_table->CmdSetEvent(commandBuffer, event, stageMask);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005020}
5021
Chia-I Wu9ab61502015-11-06 06:42:02 +08005022VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005023{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005024 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005025 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5026 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005027 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005028 skipCall |= addCmd(dev_data, pCB, CMD_RESETEVENT, "vkCmdResetEvent()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005029 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResetEvent");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005030 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005031 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005032 dev_data->device_dispatch_table->CmdResetEvent(commandBuffer, event, stageMask);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005033}
5034
Jon Ashburnf19916e2016-01-11 13:12:43 -07005035VkBool32 TransitionImageLayouts(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const VkImageMemoryBarrier* pImgMemBarriers) {
Michael Lentineabc5e922015-10-12 11:30:14 -05005036 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5037 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Mark Youngb20a6a82016-01-07 15:41:43 -07005038 VkBool32 skip = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005039
5040#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
5041 // TODO: Fix -- pay attention to image subresource ranges -- not all subresources transition at the same time
5042 return skip;
5043#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5044
Michael Lentineabc5e922015-10-12 11:30:14 -05005045 for (uint32_t i = 0; i < memBarrierCount; ++i) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005046 auto mem_barrier = &pImgMemBarriers[i];
Michael Lentineabc5e922015-10-12 11:30:14 -05005047 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005048 auto image_data = pCB->imageLayoutMap.find(mem_barrier->image);
Michael Lentineabc5e922015-10-12 11:30:14 -05005049 if (image_data == pCB->imageLayoutMap.end()) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005050 pCB->imageLayoutMap[mem_barrier->image].initialLayout = mem_barrier->oldLayout;
5051 pCB->imageLayoutMap[mem_barrier->image].layout = mem_barrier->newLayout;
Michael Lentineabc5e922015-10-12 11:30:14 -05005052 } else {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005053 if (image_data->second.layout != mem_barrier->oldLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005054 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 -07005055 "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 -05005056 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07005057 image_data->second.layout = mem_barrier->newLayout;
Michael Lentineabc5e922015-10-12 11:30:14 -05005058 }
5059 }
5060 }
5061 return skip;
5062}
5063
Mark Lobodzinskia3a86112016-01-05 17:17:55 -07005064// Print readable FlagBits in FlagMask
5065std::string string_VkAccessFlags(VkAccessFlags accessMask)
5066{
5067 std::string result;
5068 std::string separator;
5069
5070 if (accessMask == 0) {
5071 result = "[None]";
5072 } else {
5073 result = "[";
5074 for (auto i = 0; i < 32; i++) {
5075 if (accessMask & (1 << i)) {
5076 result = result + separator + string_VkAccessFlagBits((VkAccessFlagBits)(1 << i));
5077 separator = " | ";
5078 }
5079 }
5080 result = result + "]";
5081 }
5082 return result;
5083}
5084
Michael Lentine97eb7462015-11-20 09:48:52 -08005085// AccessFlags MUST have 'required_bit' set, and may have one or more of 'optional_bits' set.
5086// If required_bit is zero, accessMask must have at least one of 'optional_bits' set
Mark Lobodzinskifd740fc2016-01-06 12:56:29 -07005087// TODO: Add tracking to ensure that at least one barrier has been set for these layout transitions
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005088VkBool32 ValidateMaskBits(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout,
5089 VkAccessFlags required_bit, VkAccessFlags optional_bits, const char* type) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005090 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005091
Michael Lentine97eb7462015-11-20 09:48:52 -08005092 if ((accessMask & required_bit) || (!required_bit && (accessMask & optional_bits))) {
5093 if (accessMask & !(required_bit | optional_bits)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005094 // TODO: Verify against Valid Use
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005095 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 -07005096 "Additional bits in %s accessMask %d %s are specified when layout is %s.",
5097 type, accessMask, string_VkAccessFlags(accessMask).c_str(), string_VkImageLayout(layout));
Michael Lentineecc32b72015-10-16 18:08:09 -05005098 }
5099 } else {
Michael Lentine97eb7462015-11-20 09:48:52 -08005100 if (!required_bit) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005101 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 -07005102 "%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 -07005103 type, accessMask, string_VkAccessFlags(accessMask).c_str(), optional_bits,
5104 string_VkAccessFlags(optional_bits).c_str(), string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08005105 } else {
Mark Lobodzinskif2cc2a52016-01-05 13:35:29 -07005106 std::string opt_bits;
5107 if (optional_bits != 0) {
Michael Lentine6bd4f122016-01-19 14:00:53 -06005108 std::stringstream ss;
5109 ss << optional_bits;
5110 opt_bits = "and may have optional bits " + ss.str() + ' ' + string_VkAccessFlags(optional_bits);
Mark Lobodzinskif2cc2a52016-01-05 13:35:29 -07005111 }
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005112 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 -07005113 "%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 -07005114 type, accessMask, string_VkAccessFlags(accessMask).c_str(),
5115 required_bit, string_VkAccessFlags(required_bit).c_str(),
Mark Lobodzinskif2cc2a52016-01-05 13:35:29 -07005116 opt_bits.c_str(), string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08005117 }
Michael Lentineecc32b72015-10-16 18:08:09 -05005118 }
5119 return skip_call;
5120}
5121
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005122VkBool32 ValidateMaskBitsFromLayouts(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout, const char* type) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005123 VkBool32 skip_call = VK_FALSE;
Michael Lentine97eb7462015-11-20 09:48:52 -08005124 switch (layout) {
5125 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005126 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 -08005127 break;
Michael Lentineecc32b72015-10-16 18:08:09 -05005128 }
Michael Lentine97eb7462015-11-20 09:48:52 -08005129 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005130 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 -08005131 break;
Michael Lentineecc32b72015-10-16 18:08:09 -05005132 }
Michael Lentine97eb7462015-11-20 09:48:52 -08005133 case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005134 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_WRITE_BIT, 0, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08005135 break;
5136 }
5137 case VK_IMAGE_LAYOUT_PREINITIALIZED: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005138 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_HOST_WRITE_BIT, 0, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08005139 break;
5140 }
5141 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005142 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 -08005143 break;
5144 }
5145 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005146 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 -08005147 break;
5148 }
5149 case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005150 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_READ_BIT, 0, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08005151 break;
5152 }
5153 case VK_IMAGE_LAYOUT_UNDEFINED: {
5154 if (accessMask != 0) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005155 // TODO: Verify against Valid Use section spec
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005156 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 -07005157 "Additional bits in %s accessMask %d %s are specified when layout is %s.", type, accessMask, string_VkAccessFlags(accessMask).c_str(),
5158 string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08005159 }
5160 break;
5161 }
5162 case VK_IMAGE_LAYOUT_GENERAL:
5163 default: {
5164 break;
5165 }
Michael Lentineecc32b72015-10-16 18:08:09 -05005166 }
5167 return skip_call;
5168}
5169
Jon Ashburnf19916e2016-01-11 13:12:43 -07005170VkBool32 ValidateBarriers(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const VkMemoryBarrier* pMemBarriers, uint32_t imageMemBarrierCount, const VkImageMemoryBarrier *pImageMemBarriers)
5171{
Mark Youngb20a6a82016-01-07 15:41:43 -07005172 VkBool32 skip_call = VK_FALSE;
Michael Lentine48930b82015-10-15 17:07:00 -05005173 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5174 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5175 if (pCB->activeRenderPass && memBarrierCount) {
5176 for (uint32_t i = 0; i < memBarrierCount; ++i) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005177 auto mem_barrier = &pMemBarriers[i];
Michael Lentine48930b82015-10-15 17:07:00 -05005178 if (mem_barrier && mem_barrier->sType != VK_STRUCTURE_TYPE_MEMORY_BARRIER) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005179 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 -05005180 "Image or Buffers Barriers cannot be used during a render pass.");
5181 }
5182 }
5183 if (!dev_data->renderPassMap[pCB->activeRenderPass]->hasSelfDependency[pCB->activeSubpass]) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005184 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 -05005185 "Barriers cannot be set during subpass %d with no self dependency specified.", pCB->activeSubpass);
5186 }
5187 }
Mark Lobodzinski73a37ec2015-11-20 09:27:27 -07005188
Jon Ashburnf19916e2016-01-11 13:12:43 -07005189 for (uint32_t i = 0; i < imageMemBarrierCount; ++i) {
5190 auto mem_barrier = &pImageMemBarriers[i];
Michael Lentineecc32b72015-10-16 18:08:09 -05005191 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005192 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, mem_barrier->srcAccessMask, mem_barrier->oldLayout, "Source");
5193 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, mem_barrier->dstAccessMask, mem_barrier->newLayout, "Dest");
Michael Lentineecc32b72015-10-16 18:08:09 -05005194 }
5195 }
Mark Lobodzinski3cba24a2015-12-03 15:42:32 -07005196
Michael Lentine48930b82015-10-15 17:07:00 -05005197 return skip_call;
5198}
5199
Jon Ashburnf19916e2016-01-11 13:12:43 -07005200VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdWaitEvents(
5201 VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent* pEvents,
5202 VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask,
5203 uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers,
5204 uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers,
5205 uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005206{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005207 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005208 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5209 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005210 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005211 for (uint32_t i = 0; i < eventCount; ++i) {
5212 pCB->waitedEvents.push_back(pEvents[i]);
5213 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005214 if (pCB->state == CB_RECORDING) {
5215 skipCall |= addCmd(dev_data, pCB, CMD_WAITEVENTS, "vkCmdWaitEvents()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005216 } else {
5217 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdWaitEvents()");
5218 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07005219 skipCall |= TransitionImageLayouts(commandBuffer, imageMemoryBarrierCount, pImageMemoryBarriers);
5220 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, pMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005221 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005222 if (VK_FALSE == skipCall)
Jon Ashburnf19916e2016-01-11 13:12:43 -07005223 dev_data->device_dispatch_table->CmdWaitEvents(commandBuffer, eventCount, pEvents, sourceStageMask, dstStageMask,
5224 memoryBarrierCount, pMemoryBarriers,
5225 bufferMemoryBarrierCount, pBufferMemoryBarriers,
5226 imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005227}
5228
Jon Ashburnf19916e2016-01-11 13:12:43 -07005229VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdPipelineBarrier(
5230 VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask,
5231 VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags,
5232 uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers,
5233 uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers,
5234 uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005235{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005236 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005237 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5238 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005239 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005240 skipCall |= addCmd(dev_data, pCB, CMD_PIPELINEBARRIER, "vkCmdPipelineBarrier()");
Jon Ashburnf19916e2016-01-11 13:12:43 -07005241 skipCall |= TransitionImageLayouts(commandBuffer, imageMemoryBarrierCount, pImageMemoryBarriers);
5242 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, pMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005243 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005244 if (VK_FALSE == skipCall)
Jon Ashburnf19916e2016-01-11 13:12:43 -07005245 dev_data->device_dispatch_table->CmdPipelineBarrier(commandBuffer, srcStageMask, dstStageMask, dependencyFlags,
5246 memoryBarrierCount, pMemoryBarriers,
5247 bufferMemoryBarrierCount, pBufferMemoryBarriers,
5248 imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005249}
5250
Chia-I Wu9ab61502015-11-06 06:42:02 +08005251VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
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) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005257 skipCall |= addCmd(dev_data, pCB, CMD_BEGINQUERY, "vkCmdBeginQuery()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005258 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005259 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005260 dev_data->device_dispatch_table->CmdBeginQuery(commandBuffer, queryPool, slot, flags);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005261}
5262
Chia-I Wu9ab61502015-11-06 06:42:02 +08005263VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005264{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005265 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005266 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5267 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005268 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005269 QueryObject query = {queryPool, slot};
5270 pCB->queryToStateMap[query] = 1;
Mark Lobodzinskice738852016-01-07 10:04:02 -07005271 if (pCB->state == CB_RECORDING) {
5272 skipCall |= addCmd(dev_data, pCB, CMD_ENDQUERY, "VkCmdEndQuery()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005273 } else {
5274 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdEndQuery()");
5275 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005276 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005277 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005278 dev_data->device_dispatch_table->CmdEndQuery(commandBuffer, queryPool, slot);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005279}
5280
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005281VK_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 -06005282{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005283 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005284 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5285 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005286 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005287 for (uint32_t i = 0; i < queryCount; i++) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005288 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06005289 pCB->waitedEventsBeforeQueryReset[query] = pCB->waitedEvents;
5290 pCB->queryToStateMap[query] = 0;
5291 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005292 if (pCB->state == CB_RECORDING) {
5293 skipCall |= addCmd(dev_data, pCB, CMD_RESETQUERYPOOL, "VkCmdResetQueryPool()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005294 } else {
5295 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdResetQueryPool()");
5296 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005297 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdQueryPool");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005298 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005299 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005300 dev_data->device_dispatch_table->CmdResetQueryPool(commandBuffer, queryPool, firstQuery, queryCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005301}
5302
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005303VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005304 uint32_t queryCount, VkBuffer dstBuffer, VkDeviceSize dstOffset,
Chia-I Wuccc93a72015-10-26 18:36:20 +08005305 VkDeviceSize stride, VkQueryResultFlags flags)
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005306{
5307 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005308 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5309 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005310 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005311 for (uint32_t i = 0; i < queryCount; i++) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005312 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06005313 if(!pCB->queryToStateMap[query]) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005314 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_QUERY, "DS",
Mark Young93ecb1d2016-01-13 13:47:16 -07005315 "Requesting a copy from query to buffer with invalid query: queryPool %" PRIu64 ", index %d", (uint64_t)(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06005316 }
5317 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005318 if (pCB->state == CB_RECORDING) {
5319 skipCall |= addCmd(dev_data, pCB, CMD_COPYQUERYPOOLRESULTS, "vkCmdCopyQueryPoolResults()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005320 } else {
5321 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdCopyQueryPoolResults()");
5322 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005323 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyQueryPoolResults");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005324 }
5325 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005326 dev_data->device_dispatch_table->CmdCopyQueryPoolResults(commandBuffer, queryPool,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005327 firstQuery, queryCount, dstBuffer, dstOffset, stride, flags);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005328}
5329
Chia-I Wu9ab61502015-11-06 06:42:02 +08005330VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005331{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005332 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005333 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5334 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005335 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005336 QueryObject query = {queryPool, slot};
5337 pCB->queryToStateMap[query] = 1;
Mark Lobodzinskice738852016-01-07 10:04:02 -07005338 if (pCB->state == CB_RECORDING) {
5339 skipCall |= addCmd(dev_data, pCB, CMD_WRITETIMESTAMP, "vkCmdWriteTimestamp()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005340 } else {
5341 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdWriteTimestamp()");
5342 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005343 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005344 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005345 dev_data->device_dispatch_table->CmdWriteTimestamp(commandBuffer, pipelineStage, queryPool, slot);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005346}
5347
Chia-I Wu9ab61502015-11-06 06:42:02 +08005348VK_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 -06005349{
Tobin Ehlis0b632332015-10-07 09:38:40 -06005350 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005351 VkResult result = dev_data->device_dispatch_table->CreateFramebuffer(device, pCreateInfo, pAllocator, pFramebuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005352 if (VK_SUCCESS == result) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06005353 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06005354 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +08005355 if (pCreateInfo->pAttachments) {
Courtney Goeltzenleuchter5861a1b2015-09-01 17:30:39 -06005356 localFBCI->pAttachments = new VkImageView[localFBCI->attachmentCount];
5357 memcpy((void*)localFBCI->pAttachments, pCreateInfo->pAttachments, localFBCI->attachmentCount*sizeof(VkImageView));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005358 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08005359 dev_data->frameBufferMap[*pFramebuffer] = localFBCI;
Tobin Ehliseba312c2015-04-01 08:40:34 -06005360 }
5361 return result;
5362}
5363
Michael Lentineb6986752015-10-06 14:56:18 -07005364// Store the DAG.
5365struct DAGNode {
5366 uint32_t pass;
5367 std::vector<uint32_t> prev;
5368 std::vector<uint32_t> next;
5369};
5370
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005371VkBool32 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 -07005372 // If we have already checked this node we have not found a dependency path so return false.
5373 if (processed_nodes.count(index))
Mark Youngb20a6a82016-01-07 15:41:43 -07005374 return VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005375 processed_nodes.insert(index);
5376 const DAGNode& node = subpass_to_node[index];
5377 // Look for a dependency path. If one exists return true else recurse on the previous nodes.
5378 if (std::find(node.prev.begin(), node.prev.end(), dependent) == node.prev.end()) {
5379 for (auto elem : node.prev) {
5380 if (FindDependency(elem, dependent, subpass_to_node, processed_nodes))
Mark Youngb20a6a82016-01-07 15:41:43 -07005381 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005382 }
5383 } else {
Mark Youngb20a6a82016-01-07 15:41:43 -07005384 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005385 }
Mark Youngb20a6a82016-01-07 15:41:43 -07005386 return VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005387}
5388
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005389VkBool32 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 -07005390 VkBool32 result = VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005391 // Loop through all subpasses that share the same attachment and make sure a dependency exists
5392 for (uint32_t k = 0; k < dependent_subpasses.size(); ++k) {
5393 if (subpass == dependent_subpasses[k])
5394 continue;
5395 const DAGNode& node = subpass_to_node[subpass];
5396 // Check for a specified dependency between the two nodes. If one exists we are done.
5397 auto prev_elem = std::find(node.prev.begin(), node.prev.end(), dependent_subpasses[k]);
5398 auto next_elem = std::find(node.next.begin(), node.next.end(), dependent_subpasses[k]);
5399 if (prev_elem == node.prev.end() && next_elem == node.next.end()) {
5400 // If no dependency exits an implicit dependency still might. If so, warn and if not throw an error.
5401 std::unordered_set<uint32_t> processed_nodes;
5402 if (FindDependency(subpass, dependent_subpasses[k], subpass_to_node, processed_nodes) ||
5403 FindDependency(dependent_subpasses[k], subpass, subpass_to_node, processed_nodes)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005404 // TODO: Verify against Valid Use section of spec
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005405 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 -07005406 "A dependency between subpasses %d and %d must exist but only an implicit one is specified.",
5407 subpass, dependent_subpasses[k]);
5408 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005409 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 -07005410 "A dependency between subpasses %d and %d must exist but one is not specified.",
5411 subpass, dependent_subpasses[k]);
Mark Youngb20a6a82016-01-07 15:41:43 -07005412 result = VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005413 }
5414 }
5415 }
5416 return result;
5417}
5418
Jon Ashburnf19916e2016-01-11 13:12:43 -07005419VkBool32 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 -07005420 const DAGNode& node = subpass_to_node[index];
5421 // If this node writes to the attachment return true as next nodes need to preserve the attachment.
5422 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005423 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005424 if (attachment == subpass.pColorAttachments[j].attachment)
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005425 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005426 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005427 if (subpass.pDepthStencilAttachment &&
5428 subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
5429 if (attachment == subpass.pDepthStencilAttachment->attachment)
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005430 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005431 }
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005432 VkBool32 result = VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005433 // Loop through previous nodes and see if any of them write to the attachment.
5434 for (auto elem : node.prev) {
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005435 result |= CheckPreserved(my_data, device, pCreateInfo, elem, attachment, subpass_to_node, depth + 1, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005436 }
5437 // If the attachment was written to by a previous node than this node needs to preserve it.
5438 if (result && depth > 0) {
5439 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Mark Youngb20a6a82016-01-07 15:41:43 -07005440 VkBool32 has_preserved = VK_FALSE;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005441 for (uint32_t j = 0; j < subpass.preserveAttachmentCount; ++j) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005442 if (subpass.pPreserveAttachments[j] == attachment) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005443 has_preserved = VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005444 break;
5445 }
5446 }
Mark Youngb20a6a82016-01-07 15:41:43 -07005447 if (has_preserved == VK_FALSE) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005448 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 -07005449 "Attachment %d is used by a later subpass and must be preserved in subpass %d.", attachment, index);
5450 }
5451 }
5452 return result;
5453}
5454
Michael Lentineb4979492015-12-22 11:36:14 -06005455VkBool32 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 -07005456 VkBool32 skip_call = VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005457 std::vector<std::vector<uint32_t>> output_attachment_to_subpass(pCreateInfo->attachmentCount);
5458 std::vector<std::vector<uint32_t>> input_attachment_to_subpass(pCreateInfo->attachmentCount);
Michael Lentineb6986752015-10-06 14:56:18 -07005459 // Find for each attachment the subpasses that use them.
5460 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5461 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005462 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005463 input_attachment_to_subpass[subpass.pInputAttachments[j].attachment].push_back(i);
5464 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08005465 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005466 output_attachment_to_subpass[subpass.pColorAttachments[j].attachment].push_back(i);
5467 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005468 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
5469 output_attachment_to_subpass[subpass.pDepthStencilAttachment->attachment].push_back(i);
Michael Lentineb6986752015-10-06 14:56:18 -07005470 }
5471 }
5472 // If there is a dependency needed make sure one exists
5473 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5474 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
5475 // If the attachment is an input then all subpasses that output must have a dependency relationship
Chia-I Wud50a7d72015-10-26 20:48:51 +08005476 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005477 const uint32_t& attachment = subpass.pInputAttachments[j].attachment;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005478 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005479 }
5480 // 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 +08005481 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005482 const uint32_t& attachment = subpass.pColorAttachments[j].attachment;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005483 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
5484 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005485 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005486 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
5487 const uint32_t& attachment = subpass.pDepthStencilAttachment->attachment;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005488 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
5489 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005490 }
5491 }
5492 // Loop through implicit dependencies, if this pass reads make sure the attachment is preserved for all passes after it was written.
5493 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5494 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005495 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005496 CheckPreserved(my_data, device, pCreateInfo, i, subpass.pInputAttachments[j].attachment, subpass_to_node, 0, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005497 }
5498 }
5499 return skip_call;
5500}
5501
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005502VkBool32 ValidateLayouts(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005503 VkBool32 skip = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005504
5505#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
5506 return skip;
5507#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5508
Michael Lentineabc5e922015-10-12 11:30:14 -05005509 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5510 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
5511 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
5512 if (subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL &&
5513 subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) {
5514 if (subpass.pInputAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005515 // 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 -07005516 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 -05005517 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
5518 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005519 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 -05005520 "Layout for input attachment is %d but can only be READ_ONLY_OPTIMAL or GENERAL.", subpass.pInputAttachments[j].attachment);
5521 }
5522 }
5523 }
5524 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
5525 if (subpass.pColorAttachments[j].layout != VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) {
5526 if (subpass.pColorAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005527 // 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 -07005528 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 -05005529 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
5530 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005531 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 -05005532 "Layout for color attachment is %d but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.", subpass.pColorAttachments[j].attachment);
5533 }
5534 }
5535 }
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005536 if ((subpass.pDepthStencilAttachment != NULL) &&
5537 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
Michael Lentineabc5e922015-10-12 11:30:14 -05005538 if (subpass.pDepthStencilAttachment->layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) {
5539 if (subpass.pDepthStencilAttachment->layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005540 // 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 -07005541 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 -05005542 "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL.");
5543 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005544 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 -05005545 "Layout for depth attachment is %d but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL.", subpass.pDepthStencilAttachment->attachment);
5546 }
5547 }
5548 }
5549 }
5550 return skip;
5551}
5552
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005553VkBool32 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 -07005554 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05005555 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5556 DAGNode& subpass_node = subpass_to_node[i];
5557 subpass_node.pass = i;
5558 }
5559 for (uint32_t i = 0; i < pCreateInfo->dependencyCount; ++i) {
5560 const VkSubpassDependency& dependency = pCreateInfo->pDependencies[i];
Michael Lentine6bd4f122016-01-19 14:00:53 -06005561 if (dependency.srcSubpass > dependency.dstSubpass && dependency.srcSubpass != VK_SUBPASS_EXTERNAL && dependency.dstSubpass != VK_SUBPASS_EXTERNAL) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005562 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 -05005563 "Depedency graph must be specified such that an earlier pass cannot depend on a later pass.");
Michael Lentine6bd4f122016-01-19 14:00:53 -06005564 } else if (dependency.srcSubpass == VK_SUBPASS_EXTERNAL && dependency.dstSubpass == VK_SUBPASS_EXTERNAL) {
5565 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
5566 "The src and dest subpasses cannot both be external.");
Michael Lentine48930b82015-10-15 17:07:00 -05005567 } else if (dependency.srcSubpass == dependency.dstSubpass) {
5568 has_self_dependency[dependency.srcSubpass] = true;
Michael Lentineabc5e922015-10-12 11:30:14 -05005569 }
Michael Lentine6bd4f122016-01-19 14:00:53 -06005570 if (dependency.dstSubpass != VK_SUBPASS_EXTERNAL) {
5571 subpass_to_node[dependency.dstSubpass].prev.push_back(dependency.srcSubpass);
5572 }
5573 if (dependency.srcSubpass != VK_SUBPASS_EXTERNAL) {
5574 subpass_to_node[dependency.srcSubpass].next.push_back(dependency.dstSubpass);
5575 }
Michael Lentineabc5e922015-10-12 11:30:14 -05005576 }
5577 return skip_call;
5578}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005579// TODOSC : Add intercept of vkCreateShaderModule
Michael Lentineabc5e922015-10-12 11:30:14 -05005580
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005581VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateShaderModule(
5582 VkDevice device,
5583 const VkShaderModuleCreateInfo *pCreateInfo,
5584 const VkAllocationCallbacks* pAllocator,
5585 VkShaderModule *pShaderModule)
5586{
5587 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07005588 VkBool32 skip_call = VK_FALSE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005589 if (!shader_is_spirv(pCreateInfo)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005590 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 -07005591 /* dev */ 0, __LINE__, SHADER_CHECKER_NON_SPIRV_SHADER, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005592 "Shader is not SPIR-V");
5593 }
5594
Mark Youngb20a6a82016-01-07 15:41:43 -07005595 if (VK_FALSE != skip_call)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005596 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005597
5598 VkResult res = my_data->device_dispatch_table->CreateShaderModule(device, pCreateInfo, pAllocator, pShaderModule);
5599
5600 if (res == VK_SUCCESS) {
5601 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005602 my_data->shaderModuleMap[*pShaderModule] = new shader_module(pCreateInfo);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005603 loader_platform_thread_unlock_mutex(&globalLock);
5604 }
5605 return res;
5606}
5607
Chia-I Wu9ab61502015-11-06 06:42:02 +08005608VK_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 -06005609{
Mark Youngb20a6a82016-01-07 15:41:43 -07005610 VkBool32 skip_call = VK_FALSE;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005611 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentineabc5e922015-10-12 11:30:14 -05005612 // Create DAG
Michael Lentine48930b82015-10-15 17:07:00 -05005613 std::vector<bool> has_self_dependency(pCreateInfo->subpassCount);
Michael Lentineabc5e922015-10-12 11:30:14 -05005614 std::vector<DAGNode> subpass_to_node(pCreateInfo->subpassCount);
Michael Lentine48930b82015-10-15 17:07:00 -05005615 skip_call |= CreatePassDAG(dev_data, device, pCreateInfo, subpass_to_node, has_self_dependency);
Michael Lentineabc5e922015-10-12 11:30:14 -05005616 // Validate using DAG
5617 skip_call |= ValidateDependencies(dev_data, device, pCreateInfo, subpass_to_node);
5618 skip_call |= ValidateLayouts(dev_data, device, pCreateInfo);
Mark Youngb20a6a82016-01-07 15:41:43 -07005619 if (VK_FALSE != skip_call) {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005620 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentineb6986752015-10-06 14:56:18 -07005621 }
Chia-I Wuf7458c52015-10-26 21:10:41 +08005622 VkResult result = dev_data->device_dispatch_table->CreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005623 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005624 // TODOSC : Merge in tracking of renderpass from ShaderChecker
Tobin Ehliseba312c2015-04-01 08:40:34 -06005625 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06005626 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +08005627 if (pCreateInfo->pAttachments) {
5628 localRPCI->pAttachments = new VkAttachmentDescription[localRPCI->attachmentCount];
5629 memcpy((void*)localRPCI->pAttachments, pCreateInfo->pAttachments, localRPCI->attachmentCount*sizeof(VkAttachmentDescription));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005630 }
Chia-I Wu08accc62015-07-07 11:50:03 +08005631 if (pCreateInfo->pSubpasses) {
5632 localRPCI->pSubpasses = new VkSubpassDescription[localRPCI->subpassCount];
5633 memcpy((void*)localRPCI->pSubpasses, pCreateInfo->pSubpasses, localRPCI->subpassCount*sizeof(VkSubpassDescription));
5634
5635 for (uint32_t i = 0; i < localRPCI->subpassCount; i++) {
5636 VkSubpassDescription *subpass = (VkSubpassDescription *) &localRPCI->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005637 const uint32_t attachmentCount = subpass->inputAttachmentCount +
5638 subpass->colorAttachmentCount * (1 + (subpass->pResolveAttachments?1:0)) +
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005639 ((subpass->pDepthStencilAttachment) ? 1 : 0) + subpass->preserveAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005640 VkAttachmentReference *attachments = new VkAttachmentReference[attachmentCount];
5641
Cody Northropa505dda2015-08-04 11:16:41 -06005642 memcpy(attachments, subpass->pInputAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005643 sizeof(attachments[0]) * subpass->inputAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005644 subpass->pInputAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005645 attachments += subpass->inputAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005646
Cody Northropa505dda2015-08-04 11:16:41 -06005647 memcpy(attachments, subpass->pColorAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005648 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005649 subpass->pColorAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005650 attachments += subpass->colorAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005651
Cody Northropa505dda2015-08-04 11:16:41 -06005652 if (subpass->pResolveAttachments) {
5653 memcpy(attachments, subpass->pResolveAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005654 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005655 subpass->pResolveAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005656 attachments += subpass->colorAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005657 }
5658
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005659 if (subpass->pDepthStencilAttachment) {
5660 memcpy(attachments, subpass->pDepthStencilAttachment,
5661 sizeof(attachments[0]) * 1);
5662 subpass->pDepthStencilAttachment = attachments;
5663 attachments += 1;
5664 }
5665
Cody Northropa505dda2015-08-04 11:16:41 -06005666 memcpy(attachments, subpass->pPreserveAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005667 sizeof(attachments[0]) * subpass->preserveAttachmentCount);
Jon Ashburnf19916e2016-01-11 13:12:43 -07005668 subpass->pPreserveAttachments = &attachments->attachment;
Chia-I Wu08accc62015-07-07 11:50:03 +08005669 }
Tobin Ehliseba312c2015-04-01 08:40:34 -06005670 }
Chia-I Wu08accc62015-07-07 11:50:03 +08005671 if (pCreateInfo->pDependencies) {
5672 localRPCI->pDependencies = new VkSubpassDependency[localRPCI->dependencyCount];
5673 memcpy((void*)localRPCI->pDependencies, pCreateInfo->pDependencies, localRPCI->dependencyCount*sizeof(VkSubpassDependency));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005674 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005675 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005676 dev_data->renderPassMap[*pRenderPass] = new RENDER_PASS_NODE(localRPCI);
Michael Lentine48930b82015-10-15 17:07:00 -05005677 dev_data->renderPassMap[*pRenderPass]->hasSelfDependency = has_self_dependency;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005678 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehliseba312c2015-04-01 08:40:34 -06005679 }
5680 return result;
5681}
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005682// Free the renderpass shadow
5683static void deleteRenderPasses(layer_data* my_data)
5684{
5685 if (my_data->renderPassMap.size() <= 0)
5686 return;
5687 for (auto ii=my_data->renderPassMap.begin(); ii!=my_data->renderPassMap.end(); ++ii) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005688 const VkRenderPassCreateInfo* pRenderPassInfo = (*ii).second->pCreateInfo;
Michael Lentine48930b82015-10-15 17:07:00 -05005689 if (pRenderPassInfo->pAttachments) {
5690 delete[] pRenderPassInfo->pAttachments;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005691 }
Michael Lentine48930b82015-10-15 17:07:00 -05005692 if (pRenderPassInfo->pSubpasses) {
5693 for (uint32_t i=0; i<pRenderPassInfo->subpassCount; ++i) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005694 // Attachements are all allocated in a block, so just need to
5695 // find the first non-null one to delete
Michael Lentine48930b82015-10-15 17:07:00 -05005696 if (pRenderPassInfo->pSubpasses[i].pInputAttachments) {
5697 delete[] pRenderPassInfo->pSubpasses[i].pInputAttachments;
5698 } else if (pRenderPassInfo->pSubpasses[i].pColorAttachments) {
5699 delete[] pRenderPassInfo->pSubpasses[i].pColorAttachments;
5700 } else if (pRenderPassInfo->pSubpasses[i].pResolveAttachments) {
5701 delete[] pRenderPassInfo->pSubpasses[i].pResolveAttachments;
5702 } else if (pRenderPassInfo->pSubpasses[i].pPreserveAttachments) {
5703 delete[] pRenderPassInfo->pSubpasses[i].pPreserveAttachments;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005704 }
5705 }
Michael Lentine48930b82015-10-15 17:07:00 -05005706 delete[] pRenderPassInfo->pSubpasses;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005707 }
Michael Lentine48930b82015-10-15 17:07:00 -05005708 if (pRenderPassInfo->pDependencies) {
5709 delete[] pRenderPassInfo->pDependencies;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005710 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005711 delete pRenderPassInfo;
Michael Lentine48930b82015-10-15 17:07:00 -05005712 delete (*ii).second;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005713 }
5714 my_data->renderPassMap.clear();
5715}
Michael Lentineabc5e922015-10-12 11:30:14 -05005716
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005717VkBool32 VerifyFramebufferAndRenderPassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005718 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05005719 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5720 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005721 const VkRenderPassCreateInfo* pRenderPassInfo = dev_data->renderPassMap[pRenderPassBegin->renderPass]->pCreateInfo;
Michael Lentineabc5e922015-10-12 11:30:14 -05005722 const VkFramebufferCreateInfo* pFramebufferInfo = dev_data->frameBufferMap[pRenderPassBegin->framebuffer];
5723 if (pRenderPassInfo->attachmentCount != pFramebufferInfo->attachmentCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005724 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 -05005725 "You cannot start a render pass using a framebuffer with a different number of attachments.");
5726 }
5727 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
5728 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
5729 const VkImage& image = dev_data->imageViewMap[image_view]->image;
5730 auto image_data = pCB->imageLayoutMap.find(image);
5731 if (image_data == pCB->imageLayoutMap.end()) {
5732 pCB->imageLayoutMap[image].initialLayout = pRenderPassInfo->pAttachments[i].initialLayout;
5733 pCB->imageLayoutMap[image].layout = pRenderPassInfo->pAttachments[i].initialLayout;
5734 } else if (pRenderPassInfo->pAttachments[i].initialLayout != image_data->second.layout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005735 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 -05005736 "You cannot start a render pass using attachment %i where the intial layout differs from the starting layout.", i);
5737 }
5738 }
5739 return skip_call;
5740}
5741
5742void TransitionSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, const int subpass_index) {
5743 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5744 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5745 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
5746 if (render_pass_data == dev_data->renderPassMap.end()) {
5747 return;
5748 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005749 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
Michael Lentineabc5e922015-10-12 11:30:14 -05005750 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
5751 if (framebuffer_data == dev_data->frameBufferMap.end()) {
5752 return;
5753 }
5754 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
5755 const VkSubpassDescription& subpass = pRenderPassInfo->pSubpasses[subpass_index];
5756 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
5757 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pInputAttachments[j].attachment];
5758 auto image_view_data = dev_data->imageViewMap.find(image_view);
5759 if (image_view_data != dev_data->imageViewMap.end()) {
5760 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5761 if (image_layout != pCB->imageLayoutMap.end()) {
5762 image_layout->second.layout = subpass.pInputAttachments[j].layout;
5763 }
5764 }
5765 }
5766 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
5767 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pColorAttachments[j].attachment];
5768 auto image_view_data = dev_data->imageViewMap.find(image_view);
5769 if (image_view_data != dev_data->imageViewMap.end()) {
5770 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5771 if (image_layout != pCB->imageLayoutMap.end()) {
5772 image_layout->second.layout = subpass.pColorAttachments[j].layout;
5773 }
5774 }
5775 }
Michael Lentine3dea6512015-10-28 15:55:18 -07005776 if ((subpass.pDepthStencilAttachment != NULL) &&
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005777 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
Michael Lentineabc5e922015-10-12 11:30:14 -05005778 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pDepthStencilAttachment->attachment];
5779 auto image_view_data = dev_data->imageViewMap.find(image_view);
5780 if (image_view_data != dev_data->imageViewMap.end()) {
5781 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5782 if (image_layout != pCB->imageLayoutMap.end()) {
5783 image_layout->second.layout = subpass.pDepthStencilAttachment->layout;
5784 }
5785 }
5786 }
5787}
5788
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005789VkBool32 validatePrimaryCommandBuffer(const layer_data* my_data, const GLOBAL_CB_NODE* pCB, const std::string& cmd_name) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005790 VkBool32 skip_call = VK_FALSE;
Michael Lentine3dea6512015-10-28 15:55:18 -07005791 if (pCB->createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005792 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 -07005793 "Cannot execute command %s on a secondary command buffer.", cmd_name.c_str());
5794 }
5795 return skip_call;
5796}
5797
Michael Lentineabc5e922015-10-12 11:30:14 -05005798void TransitionFinalSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
5799 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5800 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5801 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
5802 if (render_pass_data == dev_data->renderPassMap.end()) {
5803 return;
5804 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005805 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
Michael Lentineabc5e922015-10-12 11:30:14 -05005806 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
5807 if (framebuffer_data == dev_data->frameBufferMap.end()) {
5808 return;
5809 }
5810 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
5811 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
5812 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
5813 auto image_view_data = dev_data->imageViewMap.find(image_view);
5814 if (image_view_data != dev_data->imageViewMap.end()) {
5815 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5816 if (image_layout != pCB->imageLayoutMap.end()) {
5817 image_layout->second.layout = pRenderPassInfo->pAttachments[i].finalLayout;
5818 }
5819 }
5820 }
5821}
5822
Chia-I Wu9ab61502015-11-06 06:42:02 +08005823VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, VkSubpassContents contents)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005824{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005825 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005826 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5827 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005828 if (pCB) {
Tobin Ehlis259730a2015-06-23 16:13:03 -06005829 if (pRenderPassBegin && pRenderPassBegin->renderPass) {
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005830 skipCall |= VerifyFramebufferAndRenderPassLayouts(commandBuffer, pRenderPassBegin);
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005831 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBeginRenderPass");
Michael Lentine3dea6512015-10-28 15:55:18 -07005832 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdBeginRenderPass");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005833 skipCall |= addCmd(dev_data, pCB, CMD_BEGINRENDERPASS, "vkCmdBeginRenderPass()");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005834 pCB->activeRenderPass = pRenderPassBegin->renderPass;
Michael Lentineabc5e922015-10-12 11:30:14 -05005835 // This is a shallow copy as that is all that is needed for now
5836 pCB->activeRenderPassBeginInfo = *pRenderPassBegin;
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005837 pCB->activeSubpass = 0;
Michael Lentine2e068b22015-12-29 16:05:27 -06005838 pCB->activeSubpassContents = contents;
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005839 pCB->framebuffer = pRenderPassBegin->framebuffer;
Tobin Ehlis502480b2015-06-24 15:53:07 -06005840 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005841 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 -06005842 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tony Barbourbadda992015-04-06 11:09:26 -06005843 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005844 }
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005845 if (VK_FALSE == skipCall) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005846 dev_data->device_dispatch_table->CmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents);
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005847 // This is a shallow copy as that is all that is needed for now
5848 dev_data->renderPassBeginInfo = *pRenderPassBegin;
5849 dev_data->currentSubpass = 0;
5850 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005851}
5852
Chia-I Wu9ab61502015-11-06 06:42:02 +08005853VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents)
Chia-I Wu08accc62015-07-07 11:50:03 +08005854{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005855 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005856 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5857 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Michael Lentineabc5e922015-10-12 11:30:14 -05005858 TransitionSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo, ++dev_data->currentSubpass);
Chia-I Wu08accc62015-07-07 11:50:03 +08005859 if (pCB) {
Michael Lentine3dea6512015-10-28 15:55:18 -07005860 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdNextSubpass");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005861 skipCall |= addCmd(dev_data, pCB, CMD_NEXTSUBPASS, "vkCmdNextSubpass()");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005862 pCB->activeSubpass++;
Michael Lentine2e068b22015-12-29 16:05:27 -06005863 pCB->activeSubpassContents = contents;
Tony Barbourfc5bb6f2016-01-12 11:16:52 -07005864 TransitionSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo, pCB->activeSubpass);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005865 if (pCB->lastBoundPipeline) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005866 skipCall |= validatePipelineState(dev_data, pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Chia-I Wu08accc62015-07-07 11:50:03 +08005867 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005868 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdNextSubpass");
Chia-I Wu08accc62015-07-07 11:50:03 +08005869 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005870 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005871 dev_data->device_dispatch_table->CmdNextSubpass(commandBuffer, contents);
Chia-I Wu08accc62015-07-07 11:50:03 +08005872}
5873
Chia-I Wu9ab61502015-11-06 06:42:02 +08005874VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndRenderPass(VkCommandBuffer commandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005875{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005876 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005877 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5878 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Michael Lentineabc5e922015-10-12 11:30:14 -05005879 TransitionFinalSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005880 if (pCB) {
Michael Lentine3dea6512015-10-28 15:55:18 -07005881 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdEndRenderpass");
Michael Lentine3dea6512015-10-28 15:55:18 -07005882 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdEndRenderPass");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005883 skipCall |= addCmd(dev_data, pCB, CMD_ENDRENDERPASS, "vkCmdEndRenderPass()");
Michael Lentineabc5e922015-10-12 11:30:14 -05005884 TransitionFinalSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005885 pCB->activeRenderPass = 0;
5886 pCB->activeSubpass = 0;
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005887 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005888 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005889 dev_data->device_dispatch_table->CmdEndRenderPass(commandBuffer);
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005890}
5891
Chia-I Wu9ab61502015-11-06 06:42:02 +08005892VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount, const VkCommandBuffer* pCommandBuffers)
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005893{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005894 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005895 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5896 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005897 if (pCB) {
Tobin Ehlis651d9b02015-12-16 05:01:22 -07005898 // TODO : If secondary CB was not created w/ *_USAGE_SIMULTANEOUS_USE_BIT it cannot be used more than once in given primary CB
5899 // ALSO if secondary w/o this flag is set in primary, then primary must not be pending execution more than once at a time
5900 // 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 -06005901 GLOBAL_CB_NODE* pSubCB = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005902 for (uint32_t i=0; i<commandBuffersCount; i++) {
5903 pSubCB = getCBNode(dev_data, pCommandBuffers[i]);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06005904 if (!pSubCB) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005905 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 +08005906 "vkCmdExecuteCommands() called w/ invalid Cmd Buffer %p in element %u of pCommandBuffers array.", (void*)pCommandBuffers[i], i);
5907 } else if (VK_COMMAND_BUFFER_LEVEL_PRIMARY == pSubCB->createInfo.level) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005908 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 +08005909 "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 -07005910 } else if (pCB->activeRenderPass) { // Secondary CB w/i RenderPass must have *CONTINUE_BIT set
5911 if (!(pSubCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005912 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 -07005913 "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);
5914 }
5915 string errorString = "";
Jon Ashburnf19916e2016-01-11 13:12:43 -07005916 if (!verify_renderpass_compatibility(dev_data, pCB->activeRenderPass, pSubCB->beginInfo.pInheritanceInfo->renderPass, errorString)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005917 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 -07005918 "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 -07005919 (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 -07005920 }
5921 // If framebuffer for secondary CB is not NULL, then it must match FB from vkCmdBeginRenderPass()
5922 // 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 -07005923 if (pSubCB->beginInfo.pInheritanceInfo->framebuffer) {
5924 if (pSubCB->beginInfo.pInheritanceInfo->framebuffer != pCB->activeRenderPassBeginInfo.framebuffer) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005925 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 -07005926 "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 -07005927 (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 -07005928 }
5929 }
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06005930 }
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07005931 // Secondary cmdBuffers are considered pending execution starting w/ being recorded
5932 if (!(pSubCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT)) {
5933 if (dev_data->inFlightCmdBuffers.find(pSubCB->commandBuffer) != dev_data->inFlightCmdBuffers.end()) {
Mark Youngee3f3a22016-01-25 12:18:32 -07005934 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)(pCB->commandBuffer), __LINE__, DRAWSTATE_INVALID_CB_SIMULTANEOUS_USE, "DS",
5935 "Attempt to simultaneously execute CB %#" PRIxLEAST64 " w/o VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!", (uint64_t)(pCB->commandBuffer));
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07005936 }
5937 if (pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT) {
5938 // Warn that non-simultaneous secondary cmd buffer renders primary non-simultaneous
Mark Youngee3f3a22016-01-25 12:18:32 -07005939 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)(pCommandBuffers[i]), __LINE__, DRAWSTATE_INVALID_CB_SIMULTANEOUS_USE, "DS",
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07005940 "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.",
Mark Youngee3f3a22016-01-25 12:18:32 -07005941 (uint64_t)(pCommandBuffers[i]), (uint64_t)(pCB->commandBuffer));
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07005942 pCB->beginInfo.flags &= ~VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
5943 }
5944 }
5945 pCB->secondaryCommandBuffers.insert(pSubCB->commandBuffer);
5946 dev_data->inFlightCmdBuffers.insert(pSubCB->commandBuffer);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06005947 }
Michael Lentine3dea6512015-10-28 15:55:18 -07005948 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdExecuteComands");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005949 skipCall |= addCmd(dev_data, pCB, CMD_EXECUTECOMMANDS, "vkCmdExecuteComands()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005950 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005951 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005952 dev_data->device_dispatch_table->CmdExecuteCommands(commandBuffer, commandBuffersCount, pCommandBuffers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005953}
5954
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005955VkBool32 ValidateMapImageLayouts(VkDevice device, VkDeviceMemory mem) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005956 VkBool32 skip_call = VK_FALSE;
Michael Lentine7b236262015-10-23 12:41:44 -07005957 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5958 auto mem_data = dev_data->memImageMap.find(mem);
5959 if (mem_data != dev_data->memImageMap.end()) {
5960 auto image_data = dev_data->imageLayoutMap.find(mem_data->second);
5961 if (image_data != dev_data->imageLayoutMap.end()) {
5962 if (image_data->second->layout != VK_IMAGE_LAYOUT_PREINITIALIZED && image_data->second->layout != VK_IMAGE_LAYOUT_GENERAL) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005963 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 -07005964 "Cannot map an image with layout %d. Only GENERAL or PREINITIALIZED are supported.", image_data->second->layout);
5965 }
5966 }
5967 }
5968 return skip_call;
5969}
5970
Chia-I Wu9ab61502015-11-06 06:42:02 +08005971VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkMapMemory(
Michael Lentine7b236262015-10-23 12:41:44 -07005972 VkDevice device,
5973 VkDeviceMemory mem,
5974 VkDeviceSize offset,
5975 VkDeviceSize size,
5976 VkFlags flags,
5977 void **ppData)
5978{
5979 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005980
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005981 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005982#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
5983 skip_call = ValidateMapImageLayouts(device, mem);
5984#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5985
Michael Lentine7b236262015-10-23 12:41:44 -07005986 if (VK_FALSE == skip_call) {
5987 return dev_data->device_dispatch_table->MapMemory(device, mem, offset, size, flags, ppData);
5988 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005989 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine7b236262015-10-23 12:41:44 -07005990}
5991
Chia-I Wu9ab61502015-11-06 06:42:02 +08005992VKAPI_ATTR VkResult VKAPI_CALL vkBindImageMemory(
Michael Lentine7b236262015-10-23 12:41:44 -07005993 VkDevice device,
5994 VkImage image,
5995 VkDeviceMemory mem,
5996 VkDeviceSize memOffset)
5997{
5998 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5999 VkResult result = dev_data->device_dispatch_table->BindImageMemory(device, image, mem, memOffset);
6000 loader_platform_thread_lock_mutex(&globalLock);
6001 dev_data->memImageMap[mem] = image;
6002 loader_platform_thread_unlock_mutex(&globalLock);
6003 return result;
6004}
6005
Michael Lentineb887b0a2015-12-29 14:12:11 -06006006
6007VKAPI_ATTR VkResult VKAPI_CALL vkSetEvent(VkDevice device, VkEvent event) {
6008 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6009 dev_data->eventMap[event].needsSignaled = false;
6010 VkResult result = dev_data->device_dispatch_table->SetEvent(device, event);
6011 return result;
6012}
6013
Michael Lentine15a47882016-01-06 10:05:48 -06006014VKAPI_ATTR VkResult VKAPI_CALL vkQueueBindSparse(
6015 VkQueue queue,
6016 uint32_t bindInfoCount,
6017 const VkBindSparseInfo* pBindInfo,
6018 VkFence fence)
6019{
6020 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07006021 VkBool32 skip_call = VK_FALSE;
Michael Lentine15a47882016-01-06 10:05:48 -06006022
6023 for (uint32_t bindIdx=0; bindIdx < bindInfoCount; ++bindIdx) {
6024 const VkBindSparseInfo& bindInfo = pBindInfo[bindIdx];
6025 for (uint32_t i=0; i < bindInfo.waitSemaphoreCount; ++i) {
6026 if (dev_data->semaphoreSignaledMap[bindInfo.pWaitSemaphores[i]]) {
6027 dev_data->semaphoreSignaledMap[bindInfo.pWaitSemaphores[i]] = 0;
6028 } else {
6029 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",
6030 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
Mark Youngee3f3a22016-01-25 12:18:32 -07006031 (uint64_t)(queue), (uint64_t)(bindInfo.pWaitSemaphores[i]));
Michael Lentine15a47882016-01-06 10:05:48 -06006032 }
6033 }
6034 for (uint32_t i=0; i < bindInfo.signalSemaphoreCount; ++i) {
6035 dev_data->semaphoreSignaledMap[bindInfo.pSignalSemaphores[i]] = 1;
6036 }
6037 }
6038
Mark Youngb20a6a82016-01-07 15:41:43 -07006039 if (VK_FALSE == skip_call)
Michael Lentine15a47882016-01-06 10:05:48 -06006040 return dev_data->device_dispatch_table->QueueBindSparse(queue, bindInfoCount, pBindInfo, fence);
Mark Youngb20a6a82016-01-07 15:41:43 -07006041 else
6042 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine15a47882016-01-06 10:05:48 -06006043}
6044
6045VKAPI_ATTR VkResult VKAPI_CALL vkCreateSemaphore(
6046 VkDevice device,
6047 const VkSemaphoreCreateInfo* pCreateInfo,
6048 const VkAllocationCallbacks* pAllocator,
6049 VkSemaphore* pSemaphore)
6050{
6051 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6052 VkResult result = dev_data->device_dispatch_table->CreateSemaphore(device, pCreateInfo, pAllocator, pSemaphore);
6053 if (result == VK_SUCCESS) {
6054 dev_data->semaphoreSignaledMap[*pSemaphore] = 0;
6055 }
Tobin Ehlis51b78af2016-01-06 10:27:47 -07006056 return result;
Michael Lentine15a47882016-01-06 10:05:48 -06006057}
6058
Chia-I Wu9ab61502015-11-06 06:42:02 +08006059VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(
Michael Lentineabc5e922015-10-12 11:30:14 -05006060 VkDevice device,
6061 const VkSwapchainCreateInfoKHR *pCreateInfo,
Ian Elliott05846062015-11-20 14:13:17 -07006062 const VkAllocationCallbacks *pAllocator,
Michael Lentineabc5e922015-10-12 11:30:14 -05006063 VkSwapchainKHR *pSwapchain)
6064{
6065 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott05846062015-11-20 14:13:17 -07006066 VkResult result = dev_data->device_dispatch_table->CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
Michael Lentineabc5e922015-10-12 11:30:14 -05006067
6068 if (VK_SUCCESS == result) {
Tobin Ehlis75cd1c52016-01-21 10:21:04 -07006069 SWAPCHAIN_NODE *swapchain_data = new SWAPCHAIN_NODE(pCreateInfo);
Michael Lentineabc5e922015-10-12 11:30:14 -05006070 loader_platform_thread_lock_mutex(&globalLock);
6071 dev_data->device_extensions.swapchainMap[*pSwapchain] = swapchain_data;
6072 loader_platform_thread_unlock_mutex(&globalLock);
6073 }
6074
6075 return result;
6076}
6077
Ian Elliott05846062015-11-20 14:13:17 -07006078VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR(
Michael Lentineabc5e922015-10-12 11:30:14 -05006079 VkDevice device,
Ian Elliott05846062015-11-20 14:13:17 -07006080 VkSwapchainKHR swapchain,
6081 const VkAllocationCallbacks *pAllocator)
Michael Lentineabc5e922015-10-12 11:30:14 -05006082{
6083 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentineabc5e922015-10-12 11:30:14 -05006084
6085 loader_platform_thread_lock_mutex(&globalLock);
6086 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(swapchain);
6087 if (swapchain_data != dev_data->device_extensions.swapchainMap.end()) {
6088 if (swapchain_data->second->images.size() > 0) {
6089 for (auto swapchain_image : swapchain_data->second->images) {
6090 auto image_item = dev_data->imageLayoutMap.find(swapchain_image);
6091 if (image_item != dev_data->imageLayoutMap.end())
6092 dev_data->imageLayoutMap.erase(image_item);
6093 }
6094 }
6095 delete swapchain_data->second;
6096 dev_data->device_extensions.swapchainMap.erase(swapchain);
6097 }
6098 loader_platform_thread_unlock_mutex(&globalLock);
Ian Elliott05846062015-11-20 14:13:17 -07006099 return dev_data->device_dispatch_table->DestroySwapchainKHR(device, swapchain, pAllocator);
Michael Lentineabc5e922015-10-12 11:30:14 -05006100}
6101
Chia-I Wu9ab61502015-11-06 06:42:02 +08006102VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR(
Michael Lentineabc5e922015-10-12 11:30:14 -05006103 VkDevice device,
6104 VkSwapchainKHR swapchain,
6105 uint32_t* pCount,
6106 VkImage* pSwapchainImages)
6107{
6108 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6109 VkResult result = dev_data->device_dispatch_table->GetSwapchainImagesKHR(device, swapchain, pCount, pSwapchainImages);
6110
6111 if (result == VK_SUCCESS && pSwapchainImages != NULL) {
6112 // This should never happen and is checked by param checker.
6113 if (!pCount) return result;
6114 for (uint32_t i = 0; i < *pCount; ++i) {
6115 IMAGE_NODE* image_node = new IMAGE_NODE;
6116 image_node->layout = VK_IMAGE_LAYOUT_UNDEFINED;
6117 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis75cd1c52016-01-21 10:21:04 -07006118 auto swapchain_node = dev_data->device_extensions.swapchainMap[swapchain];
6119 image_node->format = swapchain_node->createInfo.imageFormat;
6120 swapchain_node->images.push_back(pSwapchainImages[i]);
Michael Lentineabc5e922015-10-12 11:30:14 -05006121 dev_data->imageLayoutMap[pSwapchainImages[i]] = image_node;
6122 loader_platform_thread_unlock_mutex(&globalLock);
6123 }
6124 }
6125 return result;
6126}
6127
Ian Elliott05846062015-11-20 14:13:17 -07006128VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo)
Michael Lentineabc5e922015-10-12 11:30:14 -05006129{
6130 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07006131 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05006132
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006133#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentineabc5e922015-10-12 11:30:14 -05006134 if (pPresentInfo) {
Michael Lentine15a47882016-01-06 10:05:48 -06006135 for (uint32_t i=0; i < pPresentInfo->waitSemaphoreCount; ++i) {
6136 if (dev_data->semaphoreSignaledMap[pPresentInfo->pWaitSemaphores[i]]) {
6137 dev_data->semaphoreSignaledMap[pPresentInfo->pWaitSemaphores[i]] = 0;
6138 } else {
6139 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",
6140 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
Mark Youngee3f3a22016-01-25 12:18:32 -07006141 (uint64_t)(queue), (uint64_t)(pPresentInfo->pWaitSemaphores[i]));
Michael Lentine15a47882016-01-06 10:05:48 -06006142 }
6143 }
Michael Lentineabc5e922015-10-12 11:30:14 -05006144 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
Ian Elliott05846062015-11-20 14:13:17 -07006145 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(pPresentInfo->pSwapchains[i]);
6146 if (swapchain_data != dev_data->device_extensions.swapchainMap.end() && pPresentInfo->pImageIndices[i] < swapchain_data->second->images.size()) {
6147 VkImage image = swapchain_data->second->images[pPresentInfo->pImageIndices[i]];
Michael Lentineabc5e922015-10-12 11:30:14 -05006148 auto image_data = dev_data->imageLayoutMap.find(image);
6149 if (image_data != dev_data->imageLayoutMap.end()) {
Ian Elliott05846062015-11-20 14:13:17 -07006150 if (image_data->second->layout != VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07006151 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 -05006152 "Images passed to present must be in layout PRESENT_SOURCE_KHR but is in %d", image_data->second->layout);
6153 }
6154 }
6155 }
6156 }
6157 }
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006158#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentineabc5e922015-10-12 11:30:14 -05006159
6160 if (VK_FALSE == skip_call)
6161 return dev_data->device_dispatch_table->QueuePresentKHR(queue, pPresentInfo);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07006162 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentineabc5e922015-10-12 11:30:14 -05006163}
6164
Michael Lentine15a47882016-01-06 10:05:48 -06006165VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImageKHR(
6166 VkDevice device,
6167 VkSwapchainKHR swapchain,
6168 uint64_t timeout,
6169 VkSemaphore semaphore,
6170 VkFence fence,
6171 uint32_t* pImageIndex)
6172{
6173 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6174 VkResult result = dev_data->device_dispatch_table->AcquireNextImageKHR(device, swapchain, timeout, semaphore, fence, pImageIndex);
6175 dev_data->semaphoreSignaledMap[semaphore] = 1;
Tobin Ehlis51b78af2016-01-06 10:27:47 -07006176 return result;
Michael Lentine15a47882016-01-06 10:05:48 -06006177}
6178
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006179VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(
6180 VkInstance instance,
6181 const VkDebugReportCallbackCreateInfoEXT* pCreateInfo,
6182 const VkAllocationCallbacks* pAllocator,
6183 VkDebugReportCallbackEXT* pMsgCallback)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006184{
Tobin Ehlis0b632332015-10-07 09:38:40 -06006185 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006186 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006187 VkResult res = pTable->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06006188 if (VK_SUCCESS == res) {
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006189 res = layer_create_msg_callback(my_data->report_data, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06006190 }
6191 return res;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006192}
6193
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006194VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006195 VkInstance instance,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006196 VkDebugReportCallbackEXT msgCallback,
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006197 const VkAllocationCallbacks* pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006198{
Tobin Ehlis0b632332015-10-07 09:38:40 -06006199 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006200 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006201 pTable->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006202 layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006203}
6204
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006205VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDebugReportMessageEXT(
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07006206 VkInstance instance,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006207 VkDebugReportFlagsEXT flags,
6208 VkDebugReportObjectTypeEXT objType,
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07006209 uint64_t object,
6210 size_t location,
6211 int32_t msgCode,
6212 const char* pLayerPrefix,
6213 const char* pMsg)
6214{
6215 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006216 my_data->instance_dispatch_table->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg);
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07006217}
6218
Chia-I Wu9ab61502015-11-06 06:42:02 +08006219VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerBegin(VkCommandBuffer commandBuffer, const char* pMarker)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006220{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006221 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006222 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
6223 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis0b632332015-10-07 09:38:40 -06006224 if (!dev_data->device_extensions.debug_marker_enabled) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07006225 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 -06006226 "Attempt to use CmdDbgMarkerBegin but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06006227 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06006228 } else if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07006229 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKERBEGIN, "vkCmdDbgMarkerBegin()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006230 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006231 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006232 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerBegin(commandBuffer, pMarker);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006233}
6234
Chia-I Wu9ab61502015-11-06 06:42:02 +08006235VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerEnd(VkCommandBuffer commandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006236{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006237 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006238 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
6239 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis0b632332015-10-07 09:38:40 -06006240 if (!dev_data->device_extensions.debug_marker_enabled) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07006241 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 -06006242 "Attempt to use CmdDbgMarkerEnd but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06006243 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06006244 } else if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07006245 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKEREND, "vkCmdDbgMarkerEnd()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006246 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006247 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006248 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerEnd(commandBuffer);
Jon Ashburneab34492015-06-01 09:37:38 -06006249}
6250
Chia-I Wu9ab61502015-11-06 06:42:02 +08006251VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006252{
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006253 if (!strcmp(funcName, "vkGetDeviceProcAddr"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006254 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006255 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006256 return (PFN_vkVoidFunction) vkDestroyDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006257 if (!strcmp(funcName, "vkQueueSubmit"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006258 return (PFN_vkVoidFunction) vkQueueSubmit;
Michael Lentine700b0aa2015-10-30 17:57:32 -07006259 if (!strcmp(funcName, "vkWaitForFences"))
6260 return (PFN_vkVoidFunction) vkWaitForFences;
6261 if (!strcmp(funcName, "vkGetFenceStatus"))
6262 return (PFN_vkVoidFunction) vkGetFenceStatus;
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07006263 if (!strcmp(funcName, "vkQueueWaitIdle"))
6264 return (PFN_vkVoidFunction) vkQueueWaitIdle;
6265 if (!strcmp(funcName, "vkDeviceWaitIdle"))
6266 return (PFN_vkVoidFunction) vkDeviceWaitIdle;
Michael Lentine700b0aa2015-10-30 17:57:32 -07006267 if (!strcmp(funcName, "vkGetDeviceQueue"))
6268 return (PFN_vkVoidFunction) vkGetDeviceQueue;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006269 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006270 return (PFN_vkVoidFunction) vkDestroyInstance;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006271 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006272 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006273 if (!strcmp(funcName, "vkDestroyFence"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006274 return (PFN_vkVoidFunction) vkDestroyFence;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006275 if (!strcmp(funcName, "vkDestroySemaphore"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006276 return (PFN_vkVoidFunction) vkDestroySemaphore;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006277 if (!strcmp(funcName, "vkDestroyEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006278 return (PFN_vkVoidFunction) vkDestroyEvent;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006279 if (!strcmp(funcName, "vkDestroyQueryPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006280 return (PFN_vkVoidFunction) vkDestroyQueryPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006281 if (!strcmp(funcName, "vkDestroyBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006282 return (PFN_vkVoidFunction) vkDestroyBuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006283 if (!strcmp(funcName, "vkDestroyBufferView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006284 return (PFN_vkVoidFunction) vkDestroyBufferView;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006285 if (!strcmp(funcName, "vkDestroyImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006286 return (PFN_vkVoidFunction) vkDestroyImage;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006287 if (!strcmp(funcName, "vkDestroyImageView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006288 return (PFN_vkVoidFunction) vkDestroyImageView;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006289 if (!strcmp(funcName, "vkDestroyShaderModule"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006290 return (PFN_vkVoidFunction) vkDestroyShaderModule;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006291 if (!strcmp(funcName, "vkDestroyPipeline"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006292 return (PFN_vkVoidFunction) vkDestroyPipeline;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006293 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006294 return (PFN_vkVoidFunction) vkDestroyPipelineLayout;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006295 if (!strcmp(funcName, "vkDestroySampler"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006296 return (PFN_vkVoidFunction) vkDestroySampler;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006297 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006298 return (PFN_vkVoidFunction) vkDestroyDescriptorSetLayout;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006299 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006300 return (PFN_vkVoidFunction) vkDestroyDescriptorPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006301 if (!strcmp(funcName, "vkDestroyFramebuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006302 return (PFN_vkVoidFunction) vkDestroyFramebuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006303 if (!strcmp(funcName, "vkDestroyRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006304 return (PFN_vkVoidFunction) vkDestroyRenderPass;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006305 if (!strcmp(funcName, "vkCreateBuffer"))
6306 return (PFN_vkVoidFunction) vkCreateBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006307 if (!strcmp(funcName, "vkCreateBufferView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006308 return (PFN_vkVoidFunction) vkCreateBufferView;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006309 if (!strcmp(funcName, "vkCreateImage"))
6310 return (PFN_vkVoidFunction) vkCreateImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006311 if (!strcmp(funcName, "vkCreateImageView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006312 return (PFN_vkVoidFunction) vkCreateImageView;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006313 if (!strcmp(funcName, "CreatePipelineCache"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006314 return (PFN_vkVoidFunction) vkCreatePipelineCache;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006315 if (!strcmp(funcName, "DestroyPipelineCache"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006316 return (PFN_vkVoidFunction) vkDestroyPipelineCache;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006317 if (!strcmp(funcName, "GetPipelineCacheData"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006318 return (PFN_vkVoidFunction) vkGetPipelineCacheData;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006319 if (!strcmp(funcName, "MergePipelineCaches"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006320 return (PFN_vkVoidFunction) vkMergePipelineCaches;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006321 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006322 return (PFN_vkVoidFunction) vkCreateGraphicsPipelines;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07006323 if (!strcmp(funcName, "vkCreateComputePipelines"))
6324 return (PFN_vkVoidFunction) vkCreateComputePipelines;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006325 if (!strcmp(funcName, "vkCreateSampler"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006326 return (PFN_vkVoidFunction) vkCreateSampler;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006327 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006328 return (PFN_vkVoidFunction) vkCreateDescriptorSetLayout;
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05006329 if (!strcmp(funcName, "vkCreatePipelineLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006330 return (PFN_vkVoidFunction) vkCreatePipelineLayout;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006331 if (!strcmp(funcName, "vkCreateDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006332 return (PFN_vkVoidFunction) vkCreateDescriptorPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006333 if (!strcmp(funcName, "vkResetDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006334 return (PFN_vkVoidFunction) vkResetDescriptorPool;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006335 if (!strcmp(funcName, "vkAllocateDescriptorSets"))
6336 return (PFN_vkVoidFunction) vkAllocateDescriptorSets;
Tobin Ehlise735c692015-10-08 13:13:50 -06006337 if (!strcmp(funcName, "vkFreeDescriptorSets"))
6338 return (PFN_vkVoidFunction) vkFreeDescriptorSets;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08006339 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006340 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
Mark Lobodzinski39298632015-11-18 08:38:27 -07006341 if (!strcmp(funcName, "vkCreateCommandPool"))
6342 return (PFN_vkVoidFunction) vkCreateCommandPool;
6343 if (!strcmp(funcName, "vkDestroyCommandPool"))
6344 return (PFN_vkVoidFunction) vkDestroyCommandPool;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006345 if (!strcmp(funcName, "vkResetCommandPool"))
6346 return (PFN_vkVoidFunction) vkResetCommandPool;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006347 if (!strcmp(funcName, "vkAllocateCommandBuffers"))
6348 return (PFN_vkVoidFunction) vkAllocateCommandBuffers;
Mark Lobodzinski39298632015-11-18 08:38:27 -07006349 if (!strcmp(funcName, "vkFreeCommandBuffers"))
6350 return (PFN_vkVoidFunction) vkFreeCommandBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006351 if (!strcmp(funcName, "vkBeginCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006352 return (PFN_vkVoidFunction) vkBeginCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006353 if (!strcmp(funcName, "vkEndCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006354 return (PFN_vkVoidFunction) vkEndCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006355 if (!strcmp(funcName, "vkResetCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006356 return (PFN_vkVoidFunction) vkResetCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006357 if (!strcmp(funcName, "vkCmdBindPipeline"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006358 return (PFN_vkVoidFunction) vkCmdBindPipeline;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06006359 if (!strcmp(funcName, "vkCmdSetViewport"))
6360 return (PFN_vkVoidFunction) vkCmdSetViewport;
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06006361 if (!strcmp(funcName, "vkCmdSetScissor"))
6362 return (PFN_vkVoidFunction) vkCmdSetScissor;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06006363 if (!strcmp(funcName, "vkCmdSetLineWidth"))
6364 return (PFN_vkVoidFunction) vkCmdSetLineWidth;
6365 if (!strcmp(funcName, "vkCmdSetDepthBias"))
6366 return (PFN_vkVoidFunction) vkCmdSetDepthBias;
6367 if (!strcmp(funcName, "vkCmdSetBlendConstants"))
6368 return (PFN_vkVoidFunction) vkCmdSetBlendConstants;
6369 if (!strcmp(funcName, "vkCmdSetDepthBounds"))
6370 return (PFN_vkVoidFunction) vkCmdSetDepthBounds;
6371 if (!strcmp(funcName, "vkCmdSetStencilCompareMask"))
6372 return (PFN_vkVoidFunction) vkCmdSetStencilCompareMask;
6373 if (!strcmp(funcName, "vkCmdSetStencilWriteMask"))
6374 return (PFN_vkVoidFunction) vkCmdSetStencilWriteMask;
6375 if (!strcmp(funcName, "vkCmdSetStencilReference"))
6376 return (PFN_vkVoidFunction) vkCmdSetStencilReference;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006377 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006378 return (PFN_vkVoidFunction) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06006379 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006380 return (PFN_vkVoidFunction) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006381 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006382 return (PFN_vkVoidFunction) vkCmdBindIndexBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006383 if (!strcmp(funcName, "vkCmdDraw"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006384 return (PFN_vkVoidFunction) vkCmdDraw;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006385 if (!strcmp(funcName, "vkCmdDrawIndexed"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006386 return (PFN_vkVoidFunction) vkCmdDrawIndexed;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006387 if (!strcmp(funcName, "vkCmdDrawIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006388 return (PFN_vkVoidFunction) vkCmdDrawIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006389 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006390 return (PFN_vkVoidFunction) vkCmdDrawIndexedIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006391 if (!strcmp(funcName, "vkCmdDispatch"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006392 return (PFN_vkVoidFunction) vkCmdDispatch;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006393 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006394 return (PFN_vkVoidFunction) vkCmdDispatchIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006395 if (!strcmp(funcName, "vkCmdCopyBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006396 return (PFN_vkVoidFunction) vkCmdCopyBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006397 if (!strcmp(funcName, "vkCmdCopyImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006398 return (PFN_vkVoidFunction) vkCmdCopyImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006399 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006400 return (PFN_vkVoidFunction) vkCmdCopyBufferToImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006401 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006402 return (PFN_vkVoidFunction) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006403 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006404 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006405 if (!strcmp(funcName, "vkCmdFillBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006406 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006407 if (!strcmp(funcName, "vkCmdClearColorImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006408 return (PFN_vkVoidFunction) vkCmdClearColorImage;
Chris Forbesd9be82b2015-06-22 17:21:59 +12006409 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006410 return (PFN_vkVoidFunction) vkCmdClearDepthStencilImage;
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06006411 if (!strcmp(funcName, "vkCmdClearAttachments"))
6412 return (PFN_vkVoidFunction) vkCmdClearAttachments;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006413 if (!strcmp(funcName, "vkCmdResolveImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006414 return (PFN_vkVoidFunction) vkCmdResolveImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006415 if (!strcmp(funcName, "vkCmdSetEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006416 return (PFN_vkVoidFunction) vkCmdSetEvent;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006417 if (!strcmp(funcName, "vkCmdResetEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006418 return (PFN_vkVoidFunction) vkCmdResetEvent;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006419 if (!strcmp(funcName, "vkCmdWaitEvents"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006420 return (PFN_vkVoidFunction) vkCmdWaitEvents;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006421 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006422 return (PFN_vkVoidFunction) vkCmdPipelineBarrier;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006423 if (!strcmp(funcName, "vkCmdBeginQuery"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006424 return (PFN_vkVoidFunction) vkCmdBeginQuery;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006425 if (!strcmp(funcName, "vkCmdEndQuery"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006426 return (PFN_vkVoidFunction) vkCmdEndQuery;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006427 if (!strcmp(funcName, "vkCmdResetQueryPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006428 return (PFN_vkVoidFunction) vkCmdResetQueryPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006429 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006430 return (PFN_vkVoidFunction) vkCmdWriteTimestamp;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006431 if (!strcmp(funcName, "vkCreateFramebuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006432 return (PFN_vkVoidFunction) vkCreateFramebuffer;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006433 if (!strcmp(funcName, "vkCreateShaderModule"))
6434 return (PFN_vkVoidFunction) vkCreateShaderModule;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006435 if (!strcmp(funcName, "vkCreateRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006436 return (PFN_vkVoidFunction) vkCreateRenderPass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006437 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006438 return (PFN_vkVoidFunction) vkCmdBeginRenderPass;
Chia-I Wu08accc62015-07-07 11:50:03 +08006439 if (!strcmp(funcName, "vkCmdNextSubpass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006440 return (PFN_vkVoidFunction) vkCmdNextSubpass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006441 if (!strcmp(funcName, "vkCmdEndRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006442 return (PFN_vkVoidFunction) vkCmdEndRenderPass;
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06006443 if (!strcmp(funcName, "vkCmdExecuteCommands"))
6444 return (PFN_vkVoidFunction) vkCmdExecuteCommands;
Michael Lentineb887b0a2015-12-29 14:12:11 -06006445 if (!strcmp(funcName, "vkSetEvent"))
6446 return (PFN_vkVoidFunction) vkSetEvent;
Michael Lentine7b236262015-10-23 12:41:44 -07006447 if (!strcmp(funcName, "vkMapMemory"))
6448 return (PFN_vkVoidFunction) vkMapMemory;
Michael Lentineb887b0a2015-12-29 14:12:11 -06006449 if (!strcmp(funcName, "vkGetQueryPoolResults"))
6450 return (PFN_vkVoidFunction) vkGetQueryPoolResults;
Michael Lentine15a47882016-01-06 10:05:48 -06006451 if (!strcmp(funcName, "vkBindImageMemory"))
6452 return (PFN_vkVoidFunction) vkBindImageMemory;
6453 if (!strcmp(funcName, "vkQueueBindSparse"))
6454 return (PFN_vkVoidFunction) vkQueueBindSparse;
6455 if (!strcmp(funcName, "vkCreateSemaphore"))
6456 return (PFN_vkVoidFunction) vkCreateSemaphore;
Jon Ashburneab34492015-06-01 09:37:38 -06006457
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006458 if (dev == NULL)
6459 return NULL;
6460
6461 layer_data *dev_data;
6462 dev_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map);
6463
Michael Lentineabc5e922015-10-12 11:30:14 -05006464 if (dev_data->device_extensions.wsi_enabled)
6465 {
6466 if (!strcmp(funcName, "vkCreateSwapchainKHR"))
6467 return (PFN_vkVoidFunction) vkCreateSwapchainKHR;
6468 if (!strcmp(funcName, "vkDestroySwapchainKHR"))
6469 return (PFN_vkVoidFunction) vkDestroySwapchainKHR;
6470 if (!strcmp(funcName, "vkGetSwapchainImagesKHR"))
6471 return (PFN_vkVoidFunction) vkGetSwapchainImagesKHR;
Michael Lentine15a47882016-01-06 10:05:48 -06006472 if (!strcmp(funcName, "vkAcquireNextImageKHR"))
6473 return (PFN_vkVoidFunction) vkAcquireNextImageKHR;
Michael Lentineabc5e922015-10-12 11:30:14 -05006474 if (!strcmp(funcName, "vkQueuePresentKHR"))
6475 return (PFN_vkVoidFunction) vkQueuePresentKHR;
6476 }
6477
Tobin Ehlis0b632332015-10-07 09:38:40 -06006478 VkLayerDispatchTable* pTable = dev_data->device_dispatch_table;
6479 if (dev_data->device_extensions.debug_marker_enabled)
Jon Ashburn8fd08252015-05-28 16:25:02 -06006480 {
Jon Ashburn747f2b62015-06-18 15:02:58 -06006481 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006482 return (PFN_vkVoidFunction) vkCmdDbgMarkerBegin;
Jon Ashburn747f2b62015-06-18 15:02:58 -06006483 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006484 return (PFN_vkVoidFunction) vkCmdDbgMarkerEnd;
Jon Ashburneab34492015-06-01 09:37:38 -06006485 }
6486 {
Jon Ashburn8fd08252015-05-28 16:25:02 -06006487 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006488 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006489 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburnf6b33db2015-05-05 14:22:52 -06006490 }
6491}
6492
Chia-I Wu9ab61502015-11-06 06:42:02 +08006493VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Jon Ashburnf6b33db2015-05-05 14:22:52 -06006494{
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006495 if (!strcmp(funcName, "vkGetInstanceProcAddr"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006496 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006497 if (!strcmp(funcName, "vkGetDeviceProcAddr"))
6498 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06006499 if (!strcmp(funcName, "vkCreateInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006500 return (PFN_vkVoidFunction) vkCreateInstance;
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006501 if (!strcmp(funcName, "vkCreateDevice"))
6502 return (PFN_vkVoidFunction) vkCreateDevice;
Jon Ashburn3950e1b2015-05-20 09:00:28 -06006503 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006504 return (PFN_vkVoidFunction) vkDestroyInstance;
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -06006505 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
6506 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
6507 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
6508 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
6509 if (!strcmp(funcName, "vkEnumerateDeviceLayerProperties"))
6510 return (PFN_vkVoidFunction) vkEnumerateDeviceLayerProperties;
6511 if (!strcmp(funcName, "vkEnumerateDeviceExtensionProperties"))
6512 return (PFN_vkVoidFunction) vkEnumerateDeviceExtensionProperties;
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06006513
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006514 if (instance == NULL)
6515 return NULL;
6516
6517 PFN_vkVoidFunction fptr;
6518
6519 layer_data* my_data;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006520 my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06006521 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06006522 if (fptr)
6523 return fptr;
6524
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006525 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
6526 if (pTable->GetInstanceProcAddr == NULL)
6527 return NULL;
6528 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006529}