blob: d50fbaa08324aa79c7a5356d07fb429a82bddd06 [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]; }
149 uint32_t offset() { return it - zero; }
150
151 spirv_inst_iter(std::vector<uint32_t>::const_iterator zero,
152 std::vector<uint32_t>::const_iterator it) : zero(zero), it(it) {}
153
154 bool operator== (spirv_inst_iter const & other) {
155 return it == other.it;
156 }
157
158 bool operator!= (spirv_inst_iter const & other) {
159 return it != other.it;
160 }
161
162 spirv_inst_iter operator++ (int) { /* x++ */
163 spirv_inst_iter ii = *this;
164 it += len();
165 return ii;
166 }
167
168 spirv_inst_iter operator++ () { /* ++x; */
169 it += len();
170 return *this;
171 }
172
173 /* The iterator and the value are the same thing. */
174 spirv_inst_iter & operator* () { return *this; }
175 spirv_inst_iter const & operator* () const { return *this; }
176};
177
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700178struct shader_module {
179 /* the spirv image itself */
180 vector<uint32_t> words;
181 /* a mapping of <id> to the first word of its def. this is useful because walking type
182 * trees requires jumping all over the instruction stream.
183 */
184 unordered_map<unsigned, unsigned> type_def_index;
185
186 shader_module(VkShaderModuleCreateInfo const *pCreateInfo) :
187 words((uint32_t *)pCreateInfo->pCode, (uint32_t *)pCreateInfo->pCode + pCreateInfo->codeSize / sizeof(uint32_t)),
188 type_def_index() {
189
Chris Forbes79b37f82016-01-18 08:56:09 +1300190 build_type_def_index(this);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700191 }
Chris Forbesc7e2e202016-01-18 08:56:40 +1300192
193 /* expose begin() / end() to enable range-based for */
194 spirv_inst_iter begin() const { return spirv_inst_iter(words.begin(), words.begin() + 5); } /* first insn */
195 spirv_inst_iter end() const { return spirv_inst_iter(words.begin(), words.end()); } /* just past last insn */
196 /* given an offset into the module, produce an iterator there. */
197 spirv_inst_iter at(unsigned offset) const { return spirv_inst_iter(words.begin(), words.begin() + offset); }
Chris Forbes1257f912016-01-18 12:07:01 +1300198
199 spirv_inst_iter get_type_def(unsigned type_id) const {
200 auto it = type_def_index.find(type_id);
201 if (it == type_def_index.end()) {
202 return end();
203 }
204 return at(it->second);
205 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700206};
207
Tobin Ehlisb212dfc2015-10-07 15:40:22 -0600208// TODO : Do we need to guard access to layer_data_map w/ lock?
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -0700209static unordered_map<void*, layer_data*> layer_data_map;
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -0600210
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600211static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
212// TODO : This can be much smarter, using separate locks for separate global data
213static int globalLockInitialized = 0;
214static loader_platform_thread_mutex globalLock;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600215#define MAX_TID 513
216static loader_platform_thread_id g_tidMapping[MAX_TID] = {0};
217static uint32_t g_maxTID = 0;
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600218
219template layer_data *get_my_data_ptr<layer_data>(
220 void *data_key,
221 std::unordered_map<void *, layer_data *> &data_map);
222
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600223// Map actual TID to an index value and return that index
224// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs
225static uint32_t getTIDIndex() {
226 loader_platform_thread_id tid = loader_platform_get_thread_id();
227 for (uint32_t i = 0; i < g_maxTID; i++) {
228 if (tid == g_tidMapping[i])
229 return i;
230 }
231 // Don't yet have mapping, set it and return newly set index
232 uint32_t retVal = (uint32_t) g_maxTID;
233 g_tidMapping[g_maxTID++] = tid;
234 assert(g_maxTID < MAX_TID);
235 return retVal;
236}
Tobin Ehlis559c6382015-11-05 09:52:49 -0700237
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600238// Return a string representation of CMD_TYPE enum
239static string cmdTypeToString(CMD_TYPE cmd)
240{
241 switch (cmd)
242 {
243 case CMD_BINDPIPELINE:
244 return "CMD_BINDPIPELINE";
245 case CMD_BINDPIPELINEDELTA:
246 return "CMD_BINDPIPELINEDELTA";
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600247 case CMD_SETVIEWPORTSTATE:
248 return "CMD_SETVIEWPORTSTATE";
249 case CMD_SETLINEWIDTHSTATE:
250 return "CMD_SETLINEWIDTHSTATE";
251 case CMD_SETDEPTHBIASSTATE:
252 return "CMD_SETDEPTHBIASSTATE";
253 case CMD_SETBLENDSTATE:
254 return "CMD_SETBLENDSTATE";
255 case CMD_SETDEPTHBOUNDSSTATE:
256 return "CMD_SETDEPTHBOUNDSSTATE";
257 case CMD_SETSTENCILREADMASKSTATE:
258 return "CMD_SETSTENCILREADMASKSTATE";
259 case CMD_SETSTENCILWRITEMASKSTATE:
260 return "CMD_SETSTENCILWRITEMASKSTATE";
261 case CMD_SETSTENCILREFERENCESTATE:
262 return "CMD_SETSTENCILREFERENCESTATE";
Tobin Ehlis793ad302015-04-03 12:01:11 -0600263 case CMD_BINDDESCRIPTORSETS:
264 return "CMD_BINDDESCRIPTORSETS";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600265 case CMD_BINDINDEXBUFFER:
266 return "CMD_BINDINDEXBUFFER";
267 case CMD_BINDVERTEXBUFFER:
268 return "CMD_BINDVERTEXBUFFER";
269 case CMD_DRAW:
270 return "CMD_DRAW";
271 case CMD_DRAWINDEXED:
272 return "CMD_DRAWINDEXED";
273 case CMD_DRAWINDIRECT:
274 return "CMD_DRAWINDIRECT";
275 case CMD_DRAWINDEXEDINDIRECT:
276 return "CMD_DRAWINDEXEDINDIRECT";
277 case CMD_DISPATCH:
278 return "CMD_DISPATCH";
279 case CMD_DISPATCHINDIRECT:
280 return "CMD_DISPATCHINDIRECT";
281 case CMD_COPYBUFFER:
282 return "CMD_COPYBUFFER";
283 case CMD_COPYIMAGE:
284 return "CMD_COPYIMAGE";
Tobin Ehlis793ad302015-04-03 12:01:11 -0600285 case CMD_BLITIMAGE:
286 return "CMD_BLITIMAGE";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600287 case CMD_COPYBUFFERTOIMAGE:
288 return "CMD_COPYBUFFERTOIMAGE";
289 case CMD_COPYIMAGETOBUFFER:
290 return "CMD_COPYIMAGETOBUFFER";
291 case CMD_CLONEIMAGEDATA:
292 return "CMD_CLONEIMAGEDATA";
293 case CMD_UPDATEBUFFER:
294 return "CMD_UPDATEBUFFER";
295 case CMD_FILLBUFFER:
296 return "CMD_FILLBUFFER";
297 case CMD_CLEARCOLORIMAGE:
298 return "CMD_CLEARCOLORIMAGE";
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -0600299 case CMD_CLEARATTACHMENTS:
Tobin Ehlis53eddda2015-07-01 16:46:13 -0600300 return "CMD_CLEARCOLORATTACHMENT";
301 case CMD_CLEARDEPTHSTENCILIMAGE:
302 return "CMD_CLEARDEPTHSTENCILIMAGE";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600303 case CMD_RESOLVEIMAGE:
304 return "CMD_RESOLVEIMAGE";
305 case CMD_SETEVENT:
306 return "CMD_SETEVENT";
307 case CMD_RESETEVENT:
308 return "CMD_RESETEVENT";
309 case CMD_WAITEVENTS:
310 return "CMD_WAITEVENTS";
311 case CMD_PIPELINEBARRIER:
312 return "CMD_PIPELINEBARRIER";
313 case CMD_BEGINQUERY:
314 return "CMD_BEGINQUERY";
315 case CMD_ENDQUERY:
316 return "CMD_ENDQUERY";
317 case CMD_RESETQUERYPOOL:
318 return "CMD_RESETQUERYPOOL";
Mark Lobodzinski5495d132015-09-30 16:19:16 -0600319 case CMD_COPYQUERYPOOLRESULTS:
320 return "CMD_COPYQUERYPOOLRESULTS";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600321 case CMD_WRITETIMESTAMP:
322 return "CMD_WRITETIMESTAMP";
323 case CMD_INITATOMICCOUNTERS:
324 return "CMD_INITATOMICCOUNTERS";
325 case CMD_LOADATOMICCOUNTERS:
326 return "CMD_LOADATOMICCOUNTERS";
327 case CMD_SAVEATOMICCOUNTERS:
328 return "CMD_SAVEATOMICCOUNTERS";
329 case CMD_BEGINRENDERPASS:
330 return "CMD_BEGINRENDERPASS";
331 case CMD_ENDRENDERPASS:
332 return "CMD_ENDRENDERPASS";
333 case CMD_DBGMARKERBEGIN:
334 return "CMD_DBGMARKERBEGIN";
335 case CMD_DBGMARKEREND:
336 return "CMD_DBGMARKEREND";
337 default:
338 return "UNKNOWN";
339 }
340}
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700341
342// SPIRV utility functions
343static void
Chris Forbes79b37f82016-01-18 08:56:09 +1300344build_type_def_index(shader_module *module)
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700345{
Chris Forbesc7e2e202016-01-18 08:56:40 +1300346 for (auto insn : *module) {
347 switch (insn.opcode()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700348 case spv::OpTypeVoid:
349 case spv::OpTypeBool:
350 case spv::OpTypeInt:
351 case spv::OpTypeFloat:
352 case spv::OpTypeVector:
353 case spv::OpTypeMatrix:
354 case spv::OpTypeImage:
355 case spv::OpTypeSampler:
356 case spv::OpTypeSampledImage:
357 case spv::OpTypeArray:
358 case spv::OpTypeRuntimeArray:
359 case spv::OpTypeStruct:
360 case spv::OpTypeOpaque:
361 case spv::OpTypePointer:
362 case spv::OpTypeFunction:
363 case spv::OpTypeEvent:
364 case spv::OpTypeDeviceEvent:
365 case spv::OpTypeReserveId:
366 case spv::OpTypeQueue:
367 case spv::OpTypePipe:
Chris Forbesc7e2e202016-01-18 08:56:40 +1300368 module->type_def_index[insn.word(1)] = insn.offset();
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700369 break;
370
371 default:
372 /* We only care about type definitions */
373 break;
374 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700375 }
376}
377
378bool
379shader_is_spirv(VkShaderModuleCreateInfo const *pCreateInfo)
380{
381 uint32_t *words = (uint32_t *)pCreateInfo->pCode;
382 size_t sizeInWords = pCreateInfo->codeSize / sizeof(uint32_t);
383
384 /* Just validate that the header makes sense. */
385 return sizeInWords >= 5 && words[0] == spv::MagicNumber && words[1] == spv::Version;
386}
387
388static char const *
389storage_class_name(unsigned sc)
390{
391 switch (sc) {
392 case spv::StorageClassInput: return "input";
393 case spv::StorageClassOutput: return "output";
394 case spv::StorageClassUniformConstant: return "const uniform";
395 case spv::StorageClassUniform: return "uniform";
396 case spv::StorageClassWorkgroup: return "workgroup local";
397 case spv::StorageClassCrossWorkgroup: return "workgroup global";
398 case spv::StorageClassPrivate: return "private global";
399 case spv::StorageClassFunction: return "function";
400 case spv::StorageClassGeneric: return "generic";
401 case spv::StorageClassAtomicCounter: return "atomic counter";
402 case spv::StorageClassImage: return "image";
403 default: return "unknown";
404 }
405}
406
407/* returns ptr to null terminator */
408static char *
409describe_type(char *dst, shader_module const *src, unsigned type)
410{
Chris Forbes1257f912016-01-18 12:07:01 +1300411 auto insn = src->get_type_def(type);
412 assert(insn != src->end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700413
Chris Forbes1257f912016-01-18 12:07:01 +1300414 switch (insn.opcode()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700415 case spv::OpTypeBool:
416 return dst + sprintf(dst, "bool");
417 case spv::OpTypeInt:
Chris Forbes1257f912016-01-18 12:07:01 +1300418 return dst + sprintf(dst, "%cint%d", insn.word(3) ? 's' : 'u', insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700419 case spv::OpTypeFloat:
Chris Forbes1257f912016-01-18 12:07:01 +1300420 return dst + sprintf(dst, "float%d", insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700421 case spv::OpTypeVector:
Chris Forbes1257f912016-01-18 12:07:01 +1300422 dst += sprintf(dst, "vec%d of ", insn.word(3));
423 return describe_type(dst, src, insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700424 case spv::OpTypeMatrix:
Chris Forbes1257f912016-01-18 12:07:01 +1300425 dst += sprintf(dst, "mat%d of ", insn.word(3));
426 return describe_type(dst, src, insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700427 case spv::OpTypeArray:
Chris Forbes1257f912016-01-18 12:07:01 +1300428 dst += sprintf(dst, "arr[%d] of ", insn.word(3));
429 return describe_type(dst, src, insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700430 case spv::OpTypePointer:
Chris Forbes1257f912016-01-18 12:07:01 +1300431 dst += sprintf(dst, "ptr to %s ", storage_class_name(insn.word(2)));
432 return describe_type(dst, src, insn.word(3));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700433 case spv::OpTypeStruct:
434 {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700435 dst += sprintf(dst, "struct of (");
Chris Forbes1257f912016-01-18 12:07:01 +1300436 for (unsigned i = 2; i < insn.len(); i++) {
437 dst = describe_type(dst, src, insn.word(i));
438 dst += sprintf(dst, i == insn.len()-1 ? ")" : ", ");
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700439 }
440 return dst;
441 }
442 case spv::OpTypeSampler:
443 return dst + sprintf(dst, "sampler");
444 default:
445 return dst + sprintf(dst, "oddtype");
446 }
447}
448
449static bool
450types_match(shader_module const *a, shader_module const *b, unsigned a_type, unsigned b_type, bool b_arrayed)
451{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700452 /* walk two type trees together, and complain about differences */
Chris Forbes1257f912016-01-18 12:07:01 +1300453 auto a_insn = a->get_type_def(a_type);
454 auto b_insn = b->get_type_def(b_type);
455 assert(a_insn != a->end());
456 assert(b_insn != b->end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700457
Chris Forbes1257f912016-01-18 12:07:01 +1300458 if (b_arrayed && b_insn.opcode() == spv::OpTypeArray) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700459 /* we probably just found the extra level of arrayness in b_type: compare the type inside it to a_type */
Chris Forbes1257f912016-01-18 12:07:01 +1300460 return types_match(a, b, a_type, b_insn.word(2), false);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700461 }
462
Chris Forbes1257f912016-01-18 12:07:01 +1300463 if (a_insn.opcode() != b_insn.opcode()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700464 return false;
465 }
466
Chris Forbes1257f912016-01-18 12:07:01 +1300467 switch (a_insn.opcode()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700468 /* if b_arrayed and we hit a leaf type, then we can't match -- there's nowhere for the extra OpTypeArray to be! */
469 case spv::OpTypeBool:
470 return true && !b_arrayed;
471 case spv::OpTypeInt:
472 /* match on width, signedness */
Chris Forbes1257f912016-01-18 12:07:01 +1300473 return a_insn.word(2) == b_insn.word(2) && a_insn.word(3) == b_insn.word(3) && !b_arrayed;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700474 case spv::OpTypeFloat:
475 /* match on width */
Chris Forbes1257f912016-01-18 12:07:01 +1300476 return a_insn.word(2) == b_insn.word(2) && !b_arrayed;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700477 case spv::OpTypeVector:
478 case spv::OpTypeMatrix:
479 case spv::OpTypeArray:
480 /* match on element type, count. these all have the same layout. we don't get here if
481 * b_arrayed -- that is handled above. */
Chris Forbes1257f912016-01-18 12:07:01 +1300482 return !b_arrayed && types_match(a, b, a_insn.word(2), b_insn.word(2), b_arrayed) && a_insn.word(3) == b_insn.word(3);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700483 case spv::OpTypeStruct:
484 /* match on all element types */
485 {
486 if (b_arrayed) {
487 /* for the purposes of matching different levels of arrayness, structs are leaves. */
488 return false;
489 }
490
Chris Forbes1257f912016-01-18 12:07:01 +1300491 if (a_insn.len() != b_insn.len()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700492 return false; /* structs cannot match if member counts differ */
493 }
494
Chris Forbes1257f912016-01-18 12:07:01 +1300495 for (unsigned i = 2; i < a_insn.len(); i++) {
496 if (!types_match(a, b, a_insn.word(i), b_insn.word(i), b_arrayed)) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700497 return false;
498 }
499 }
500
501 return true;
502 }
503 case spv::OpTypePointer:
504 /* match on pointee type. storage class is expected to differ */
Chris Forbes1257f912016-01-18 12:07:01 +1300505 return types_match(a, b, a_insn.word(3), b_insn.word(3), b_arrayed);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700506
507 default:
508 /* remaining types are CLisms, or may not appear in the interfaces we
509 * are interested in. Just claim no match.
510 */
511 return false;
512
513 }
514}
515
516static int
517value_or_default(std::unordered_map<unsigned, unsigned> const &map, unsigned id, int def)
518{
519 auto it = map.find(id);
520 if (it == map.end())
521 return def;
522 else
523 return it->second;
524}
525
526
527static unsigned
528get_locations_consumed_by_type(shader_module const *src, unsigned type, bool strip_array_level)
529{
Chris Forbes1257f912016-01-18 12:07:01 +1300530 auto insn = src->get_type_def(type);
531 assert(insn != src->end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700532
Chris Forbesc7e2e202016-01-18 08:56:40 +1300533 switch (insn.opcode()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700534 case spv::OpTypePointer:
535 /* see through the ptr -- this is only ever at the toplevel for graphics shaders;
536 * we're never actually passing pointers around. */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300537 return get_locations_consumed_by_type(src, insn.word(3), strip_array_level);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700538 case spv::OpTypeArray:
539 if (strip_array_level) {
Chris Forbesc7e2e202016-01-18 08:56:40 +1300540 return get_locations_consumed_by_type(src, insn.word(2), false);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700541 }
542 else {
Chris Forbesc7e2e202016-01-18 08:56:40 +1300543 return insn.word(3) * get_locations_consumed_by_type(src, insn.word(2), false);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700544 }
545 case spv::OpTypeMatrix:
546 /* num locations is the dimension * element size */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300547 return insn.word(3) * get_locations_consumed_by_type(src, insn.word(2), false);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700548 default:
549 /* everything else is just 1. */
550 return 1;
551
552 /* TODO: extend to handle 64bit scalar types, whose vectors may need
553 * multiple locations. */
554 }
555}
556
557
558struct interface_var {
559 uint32_t id;
560 uint32_t type_id;
561 uint32_t offset;
562 /* TODO: collect the name, too? Isn't required to be present. */
563};
564
Chris Forbesa3e85f62016-01-15 14:53:11 +1300565
566static void
567collect_interface_block_members(layer_data *my_data, VkDevice dev,
568 shader_module const *src,
569 std::map<uint32_t, interface_var> &out,
570 std::map<uint32_t, interface_var> &builtins_out,
571 std::unordered_map<unsigned, unsigned> const &blocks,
572 bool is_array_of_verts,
573 uint32_t id,
574 uint32_t type_id)
575{
576 /* Walk down the type_id presented, trying to determine whether it's actually an interface block. */
Chris Forbes1257f912016-01-18 12:07:01 +1300577 auto type = src->get_type_def(type_id);
578
Chris Forbesa3e85f62016-01-15 14:53:11 +1300579 while (true) {
580
Chris Forbes1257f912016-01-18 12:07:01 +1300581 if (type.opcode() == spv::OpTypePointer) {
582 type = src->get_type_def(type.word(3));
Chris Forbesa3e85f62016-01-15 14:53:11 +1300583 }
Chris Forbes1257f912016-01-18 12:07:01 +1300584 else if (type.opcode() == spv::OpTypeArray && is_array_of_verts) {
585 type = src->get_type_def(type.word(2));
Chris Forbesa3e85f62016-01-15 14:53:11 +1300586 is_array_of_verts = false;
587 }
Chris Forbes1257f912016-01-18 12:07:01 +1300588 else if (type.opcode() == spv::OpTypeStruct) {
589 if (blocks.find(type.word(1)) == blocks.end()) {
Chris Forbesa3e85f62016-01-15 14:53:11 +1300590 /* This isn't an interface block. */
591 return;
592 }
593 else {
594 /* We have found the correct type. Walk its members. */
595 break;
596 }
597 }
598 else {
599 /* not an interface block */
600 return;
601 }
602 }
603
Chris Forbes1257f912016-01-18 12:07:01 +1300604 /* Walk all the OpMemberDecorate for type's result id. */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300605 for (auto insn : *src) {
Chris Forbes1257f912016-01-18 12:07:01 +1300606 if (insn.opcode() == spv::OpMemberDecorate && insn.word(1) == type.word(1)) {
Chris Forbesc7e2e202016-01-18 08:56:40 +1300607 unsigned member_index = insn.word(2);
Chris Forbes1257f912016-01-18 12:07:01 +1300608 unsigned member_type_id = type.word(2 + member_index);
Chris Forbesa3e85f62016-01-15 14:53:11 +1300609
Chris Forbesc7e2e202016-01-18 08:56:40 +1300610 if (insn.word(3) == spv::DecorationLocation) {
611 unsigned location = insn.word(4);
Chris Forbesa3e85f62016-01-15 14:53:11 +1300612 unsigned num_locations = get_locations_consumed_by_type(src, member_type_id, false);
613 for (unsigned int offset = 0; offset < num_locations; offset++) {
614 interface_var v;
615 v.id = id;
616 /* TODO: member index in interface_var too? */
617 v.type_id = member_type_id;
618 v.offset = offset;
619 out[location + offset] = v;
620 }
621 }
Chris Forbesc7e2e202016-01-18 08:56:40 +1300622 else if (insn.word(3) == spv::DecorationBuiltIn) {
623 unsigned builtin = insn.word(4);
Chris Forbesa3e85f62016-01-15 14:53:11 +1300624 interface_var v;
625 v.id = id;
626 v.type_id = member_type_id;
627 v.offset = 0;
628 builtins_out[builtin] = v;
629 }
630 }
Chris Forbesa3e85f62016-01-15 14:53:11 +1300631 }
632}
633
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700634static void
635collect_interface_by_location(layer_data *my_data, VkDevice dev,
636 shader_module const *src, spv::StorageClass sinterface,
637 std::map<uint32_t, interface_var> &out,
638 std::map<uint32_t, interface_var> &builtins_out,
639 bool is_array_of_verts)
640{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700641 std::unordered_map<unsigned, unsigned> var_locations;
642 std::unordered_map<unsigned, unsigned> var_builtins;
Chris Forbesa3e85f62016-01-15 14:53:11 +1300643 std::unordered_map<unsigned, unsigned> blocks;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700644
Chris Forbesc7e2e202016-01-18 08:56:40 +1300645 for (auto insn : *src) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700646
647 /* We consider two interface models: SSO rendezvous-by-location, and
648 * builtins. Complain about anything that fits neither model.
649 */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300650 if (insn.opcode() == spv::OpDecorate) {
651 if (insn.word(2) == spv::DecorationLocation) {
652 var_locations[insn.word(1)] = insn.word(3);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700653 }
654
Chris Forbesc7e2e202016-01-18 08:56:40 +1300655 if (insn.word(2) == spv::DecorationBuiltIn) {
656 var_builtins[insn.word(1)] = insn.word(3);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700657 }
Chris Forbesa3e85f62016-01-15 14:53:11 +1300658
Chris Forbesc7e2e202016-01-18 08:56:40 +1300659 if (insn.word(2) == spv::DecorationBlock) {
660 blocks[insn.word(1)] = 1;
Chris Forbesa3e85f62016-01-15 14:53:11 +1300661 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700662 }
663
664 /* TODO: handle grouped decorations */
665 /* TODO: handle index=1 dual source outputs from FS -- two vars will
666 * have the same location, and we DONT want to clobber. */
667
Chris Forbesc7e2e202016-01-18 08:56:40 +1300668 else if (insn.opcode() == spv::OpVariable && insn.word(3) == sinterface) {
669 unsigned id = insn.word(2);
670 unsigned type = insn.word(1);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700671
Chris Forbesc7e2e202016-01-18 08:56:40 +1300672 int location = value_or_default(var_locations, id, -1);
673 int builtin = value_or_default(var_builtins, id, -1);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700674
Chris Forbesf5020cf2016-01-13 09:29:31 +1300675 /* All variables and interface block members in the Input or Output storage classes
676 * must be decorated with either a builtin or an explicit location.
677 *
678 * TODO: integrate the interface block support here. For now, don't complain --
679 * a valid SPIRV module will only hit this path for the interface block case, as the
680 * individual members of the type are decorated, rather than variable declarations.
681 */
682
683 if (location != -1) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700684 /* A user-defined interface variable, with a location. Where a variable
685 * occupied multiple locations, emit one result for each. */
686 unsigned num_locations = get_locations_consumed_by_type(src, type,
687 is_array_of_verts);
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -0700688 for (unsigned int offset = 0; offset < num_locations; offset++) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700689 interface_var v;
690 v.id = id;
691 v.type_id = type;
692 v.offset = offset;
693 out[location + offset] = v;
694 }
695 }
Chris Forbesf5020cf2016-01-13 09:29:31 +1300696 else if (builtin != -1) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700697 /* A builtin interface variable */
698 /* Note that since builtin interface variables do not consume numbered
699 * locations, there is no larger-than-vec4 consideration as above
700 */
701 interface_var v;
702 v.id = id;
703 v.type_id = type;
704 v.offset = 0;
705 builtins_out[builtin] = v;
706 }
Chris Forbesa3e85f62016-01-15 14:53:11 +1300707 else {
708 /* An interface block instance */
709 collect_interface_block_members(my_data, dev, src, out, builtins_out,
710 blocks, is_array_of_verts, id, type);
711 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700712 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700713 }
714}
715
716static void
717collect_interface_by_descriptor_slot(layer_data *my_data, VkDevice dev,
718 shader_module const *src, spv::StorageClass sinterface,
719 std::map<std::pair<unsigned, unsigned>, interface_var> &out)
720{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700721
722 std::unordered_map<unsigned, unsigned> var_sets;
723 std::unordered_map<unsigned, unsigned> var_bindings;
724
Chris Forbesc7e2e202016-01-18 08:56:40 +1300725 for (auto insn : *src) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700726 /* All variables in the Uniform or UniformConstant storage classes are required to be decorated with both
727 * DecorationDescriptorSet and DecorationBinding.
728 */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300729 if (insn.opcode() == spv::OpDecorate) {
730 if (insn.word(2) == spv::DecorationDescriptorSet) {
731 var_sets[insn.word(1)] = insn.word(3);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700732 }
733
Chris Forbesc7e2e202016-01-18 08:56:40 +1300734 if (insn.word(2) == spv::DecorationBinding) {
735 var_bindings[insn.word(1)] = insn.word(3);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700736 }
737 }
738
Chris Forbesc7e2e202016-01-18 08:56:40 +1300739 else if (insn.opcode() == spv::OpVariable &&
740 (insn.word(3) == spv::StorageClassUniform ||
741 insn.word(3) == spv::StorageClassUniformConstant)) {
742 unsigned set = value_or_default(var_sets, insn.word(2), 0);
743 unsigned binding = value_or_default(var_bindings, insn.word(2), 0);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700744
745 auto existing_it = out.find(std::make_pair(set, binding));
746 if (existing_it != out.end()) {
747 /* conflict within spv image */
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700748 log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__,
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700749 SHADER_CHECKER_INCONSISTENT_SPIRV, "SC",
750 "var %d (type %d) in %s interface in descriptor slot (%u,%u) conflicts with existing definition",
Chris Forbesc7e2e202016-01-18 08:56:40 +1300751 insn.word(2), insn.word(1), storage_class_name(sinterface),
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700752 existing_it->first.first, existing_it->first.second);
753 }
754
755 interface_var v;
Chris Forbesc7e2e202016-01-18 08:56:40 +1300756 v.id = insn.word(2);
757 v.type_id = insn.word(1);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700758 out[std::make_pair(set, binding)] = v;
759 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700760 }
761}
762
763static bool
764validate_interface_between_stages(layer_data *my_data, VkDevice dev,
765 shader_module const *producer, char const *producer_name,
766 shader_module const *consumer, char const *consumer_name,
767 bool consumer_arrayed_input)
768{
769 std::map<uint32_t, interface_var> outputs;
770 std::map<uint32_t, interface_var> inputs;
771
772 std::map<uint32_t, interface_var> builtin_outputs;
773 std::map<uint32_t, interface_var> builtin_inputs;
774
775 bool pass = true;
776
777 collect_interface_by_location(my_data, dev, producer, spv::StorageClassOutput, outputs, builtin_outputs, false);
778 collect_interface_by_location(my_data, dev, consumer, spv::StorageClassInput, inputs, builtin_inputs,
779 consumer_arrayed_input);
780
781 auto a_it = outputs.begin();
782 auto b_it = inputs.begin();
783
784 /* maps sorted by key (location); walk them together to find mismatches */
785 while ((outputs.size() > 0 && a_it != outputs.end()) || ( inputs.size() && b_it != inputs.end())) {
786 bool a_at_end = outputs.size() == 0 || a_it == outputs.end();
787 bool b_at_end = inputs.size() == 0 || b_it == inputs.end();
788 auto a_first = a_at_end ? 0 : a_it->first;
789 auto b_first = b_at_end ? 0 : b_it->first;
790
791 if (b_at_end || ((!a_at_end) && (a_first < b_first))) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700792 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__, SHADER_CHECKER_OUTPUT_NOT_CONSUMED, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700793 "%s writes to output location %d which is not consumed by %s", producer_name, a_first, consumer_name)) {
794 pass = false;
795 }
796 a_it++;
797 }
798 else if (a_at_end || a_first > b_first) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700799 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__, SHADER_CHECKER_INPUT_NOT_PRODUCED, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700800 "%s consumes input location %d which is not written by %s", consumer_name, b_first, producer_name)) {
801 pass = false;
802 }
803 b_it++;
804 }
805 else {
806 if (types_match(producer, consumer, a_it->second.type_id, b_it->second.type_id, consumer_arrayed_input)) {
807 /* OK! */
808 }
809 else {
810 char producer_type[1024];
811 char consumer_type[1024];
812 describe_type(producer_type, producer, a_it->second.type_id);
813 describe_type(consumer_type, consumer, b_it->second.type_id);
814
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700815 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__, SHADER_CHECKER_INTERFACE_TYPE_MISMATCH, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700816 "Type mismatch on location %d: '%s' vs '%s'", a_it->first, producer_type, consumer_type)) {
817 pass = false;
818 }
819 }
820 a_it++;
821 b_it++;
822 }
823 }
824
825 return pass;
826}
827
828enum FORMAT_TYPE {
829 FORMAT_TYPE_UNDEFINED,
830 FORMAT_TYPE_FLOAT, /* UNORM, SNORM, FLOAT, USCALED, SSCALED, SRGB -- anything we consider float in the shader */
831 FORMAT_TYPE_SINT,
832 FORMAT_TYPE_UINT,
833};
834
835static unsigned
836get_format_type(VkFormat fmt) {
837 switch (fmt) {
838 case VK_FORMAT_UNDEFINED:
839 return FORMAT_TYPE_UNDEFINED;
840 case VK_FORMAT_R8_SINT:
841 case VK_FORMAT_R8G8_SINT:
842 case VK_FORMAT_R8G8B8_SINT:
843 case VK_FORMAT_R8G8B8A8_SINT:
844 case VK_FORMAT_R16_SINT:
845 case VK_FORMAT_R16G16_SINT:
846 case VK_FORMAT_R16G16B16_SINT:
847 case VK_FORMAT_R16G16B16A16_SINT:
848 case VK_FORMAT_R32_SINT:
849 case VK_FORMAT_R32G32_SINT:
850 case VK_FORMAT_R32G32B32_SINT:
851 case VK_FORMAT_R32G32B32A32_SINT:
852 case VK_FORMAT_B8G8R8_SINT:
853 case VK_FORMAT_B8G8R8A8_SINT:
854 case VK_FORMAT_A2B10G10R10_SINT_PACK32:
855 case VK_FORMAT_A2R10G10B10_SINT_PACK32:
856 return FORMAT_TYPE_SINT;
857 case VK_FORMAT_R8_UINT:
858 case VK_FORMAT_R8G8_UINT:
859 case VK_FORMAT_R8G8B8_UINT:
860 case VK_FORMAT_R8G8B8A8_UINT:
861 case VK_FORMAT_R16_UINT:
862 case VK_FORMAT_R16G16_UINT:
863 case VK_FORMAT_R16G16B16_UINT:
864 case VK_FORMAT_R16G16B16A16_UINT:
865 case VK_FORMAT_R32_UINT:
866 case VK_FORMAT_R32G32_UINT:
867 case VK_FORMAT_R32G32B32_UINT:
868 case VK_FORMAT_R32G32B32A32_UINT:
869 case VK_FORMAT_B8G8R8_UINT:
870 case VK_FORMAT_B8G8R8A8_UINT:
871 case VK_FORMAT_A2B10G10R10_UINT_PACK32:
872 case VK_FORMAT_A2R10G10B10_UINT_PACK32:
873 return FORMAT_TYPE_UINT;
874 default:
875 return FORMAT_TYPE_FLOAT;
876 }
877}
878
879/* characterizes a SPIR-V type appearing in an interface to a FF stage,
880 * for comparison to a VkFormat's characterization above. */
881static unsigned
882get_fundamental_type(shader_module const *src, unsigned type)
883{
Chris Forbes1257f912016-01-18 12:07:01 +1300884 auto insn = src->get_type_def(type);
885 assert(insn != src->end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700886
Chris Forbes1257f912016-01-18 12:07:01 +1300887 switch (insn.opcode()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700888 case spv::OpTypeInt:
Chris Forbes1257f912016-01-18 12:07:01 +1300889 return insn.word(3) ? FORMAT_TYPE_SINT : FORMAT_TYPE_UINT;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700890 case spv::OpTypeFloat:
891 return FORMAT_TYPE_FLOAT;
892 case spv::OpTypeVector:
Chris Forbes1257f912016-01-18 12:07:01 +1300893 return get_fundamental_type(src, insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700894 case spv::OpTypeMatrix:
Chris Forbes1257f912016-01-18 12:07:01 +1300895 return get_fundamental_type(src, insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700896 case spv::OpTypeArray:
Chris Forbes1257f912016-01-18 12:07:01 +1300897 return get_fundamental_type(src, insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700898 case spv::OpTypePointer:
Chris Forbes1257f912016-01-18 12:07:01 +1300899 return get_fundamental_type(src, insn.word(3));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700900 default:
901 return FORMAT_TYPE_UNDEFINED;
902 }
903}
904
905static bool
906validate_vi_consistency(layer_data *my_data, VkDevice dev, VkPipelineVertexInputStateCreateInfo const *vi)
907{
908 /* walk the binding descriptions, which describe the step rate and stride of each vertex buffer.
909 * each binding should be specified only once.
910 */
911 std::unordered_map<uint32_t, VkVertexInputBindingDescription const *> bindings;
912 bool pass = true;
913
914 for (unsigned i = 0; i < vi->vertexBindingDescriptionCount; i++) {
915 auto desc = &vi->pVertexBindingDescriptions[i];
916 auto & binding = bindings[desc->binding];
917 if (binding) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700918 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__, SHADER_CHECKER_INCONSISTENT_VI, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700919 "Duplicate vertex input binding descriptions for binding %d", desc->binding)) {
920 pass = false;
921 }
922 }
923 else {
924 binding = desc;
925 }
926 }
927
928 return pass;
929}
930
931static bool
932validate_vi_against_vs_inputs(layer_data *my_data, VkDevice dev, VkPipelineVertexInputStateCreateInfo const *vi, shader_module const *vs)
933{
934 std::map<uint32_t, interface_var> inputs;
935 /* we collect builtin inputs, but they will never appear in the VI state --
936 * the vs builtin inputs are generated in the pipeline, not sourced from buffers (VertexID, etc)
937 */
938 std::map<uint32_t, interface_var> builtin_inputs;
939 bool pass = true;
940
941 collect_interface_by_location(my_data, dev, vs, spv::StorageClassInput, inputs, builtin_inputs, false);
942
943 /* Build index by location */
944 std::map<uint32_t, VkVertexInputAttributeDescription const *> attribs;
945 if (vi) {
946 for (unsigned i = 0; i < vi->vertexAttributeDescriptionCount; i++)
947 attribs[vi->pVertexAttributeDescriptions[i].location] = &vi->pVertexAttributeDescriptions[i];
948 }
949
950 auto it_a = attribs.begin();
951 auto it_b = inputs.begin();
952
953 while ((attribs.size() > 0 && it_a != attribs.end()) || (inputs.size() > 0 && it_b != inputs.end())) {
954 bool a_at_end = attribs.size() == 0 || it_a == attribs.end();
955 bool b_at_end = inputs.size() == 0 || it_b == inputs.end();
956 auto a_first = a_at_end ? 0 : it_a->first;
957 auto b_first = b_at_end ? 0 : it_b->first;
Chris Forbes7d83cd52016-01-15 11:32:03 +1300958 if (!a_at_end && (b_at_end || a_first < b_first)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700959 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__, SHADER_CHECKER_OUTPUT_NOT_CONSUMED, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700960 "Vertex attribute at location %d not consumed by VS", a_first)) {
961 pass = false;
962 }
963 it_a++;
964 }
Chris Forbes7d83cd52016-01-15 11:32:03 +1300965 else if (!b_at_end && (a_at_end || b_first < a_first)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700966 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__, SHADER_CHECKER_INPUT_NOT_PRODUCED, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700967 "VS consumes input at location %d but not provided", b_first)) {
968 pass = false;
969 }
970 it_b++;
971 }
972 else {
973 unsigned attrib_type = get_format_type(it_a->second->format);
974 unsigned input_type = get_fundamental_type(vs, it_b->second.type_id);
975
976 /* type checking */
977 if (attrib_type != FORMAT_TYPE_UNDEFINED && input_type != FORMAT_TYPE_UNDEFINED && attrib_type != input_type) {
978 char vs_type[1024];
979 describe_type(vs_type, vs, it_b->second.type_id);
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700980 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__, SHADER_CHECKER_INTERFACE_TYPE_MISMATCH, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700981 "Attribute type of `%s` at location %d does not match VS input type of `%s`",
982 string_VkFormat(it_a->second->format), a_first, vs_type)) {
983 pass = false;
984 }
985 }
986
987 /* OK! */
988 it_a++;
989 it_b++;
990 }
991 }
992
993 return pass;
994}
995
996static bool
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -0700997validate_fs_outputs_against_render_pass(layer_data *my_data, VkDevice dev, shader_module const *fs, RENDER_PASS_NODE const *rp, uint32_t subpass)
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700998{
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -0700999 const std::vector<VkFormat> &color_formats = rp->subpassColorFormats[subpass];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001000 std::map<uint32_t, interface_var> outputs;
1001 std::map<uint32_t, interface_var> builtin_outputs;
1002 bool pass = true;
1003
1004 /* TODO: dual source blend index (spv::DecIndex, zero if not provided) */
1005
1006 collect_interface_by_location(my_data, dev, fs, spv::StorageClassOutput, outputs, builtin_outputs, false);
1007
1008 auto it = outputs.begin();
1009 uint32_t attachment = 0;
1010
1011 /* Walk attachment list and outputs together -- this is a little overpowered since attachments
1012 * are currently dense, but the parallel with matching between shader stages is nice.
1013 */
1014
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001015 while ((outputs.size() > 0 && it != outputs.end()) || attachment < color_formats.size()) {
1016 if (attachment == color_formats.size() || ( it != outputs.end() && it->first < attachment)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001017 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__, SHADER_CHECKER_OUTPUT_NOT_CONSUMED, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001018 "FS writes to output location %d with no matching attachment", it->first)) {
1019 pass = false;
1020 }
1021 it++;
1022 }
1023 else if (it == outputs.end() || it->first > attachment) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001024 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__, SHADER_CHECKER_INPUT_NOT_PRODUCED, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001025 "Attachment %d not written by FS", attachment)) {
1026 pass = false;
1027 }
1028 attachment++;
1029 }
1030 else {
1031 unsigned output_type = get_fundamental_type(fs, it->second.type_id);
1032 unsigned att_type = get_format_type(color_formats[attachment]);
1033
1034 /* type checking */
1035 if (att_type != FORMAT_TYPE_UNDEFINED && output_type != FORMAT_TYPE_UNDEFINED && att_type != output_type) {
1036 char fs_type[1024];
1037 describe_type(fs_type, fs, it->second.type_id);
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001038 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__, SHADER_CHECKER_INTERFACE_TYPE_MISMATCH, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001039 "Attachment %d of type `%s` does not match FS output type of `%s`",
1040 attachment, string_VkFormat(color_formats[attachment]), fs_type)) {
1041 pass = false;
1042 }
1043 }
1044
1045 /* OK! */
1046 it++;
1047 attachment++;
1048 }
1049 }
1050
1051 return pass;
1052}
1053
1054
1055struct shader_stage_attributes {
1056 char const * const name;
1057 bool arrayed_input;
1058};
1059
1060
1061static shader_stage_attributes
1062shader_stage_attribs[] = {
1063 { "vertex shader", false },
1064 { "tessellation control shader", true },
1065 { "tessellation evaluation shader", false },
1066 { "geometry shader", true },
1067 { "fragment shader", false },
1068};
1069
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001070// For given pipelineLayout verify that the setLayout at slot.first
1071// has the requested binding at slot.second
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001072static bool
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001073has_descriptor_binding(layer_data* my_data,
1074 vector<VkDescriptorSetLayout>* pipelineLayout,
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001075 std::pair<unsigned, unsigned> slot)
1076{
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001077 if (!pipelineLayout)
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001078 return false;
1079
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001080 if (slot.first >= pipelineLayout->size())
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001081 return false;
1082
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001083 auto set = my_data->descriptorSetLayoutMap[(*pipelineLayout)[slot.first]]->bindings;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001084
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001085 return (set.find(slot.second) != set.end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001086}
1087
1088static uint32_t get_shader_stage_id(VkShaderStageFlagBits stage)
1089{
1090 uint32_t bit_pos = u_ffs(stage);
1091 return bit_pos-1;
1092}
1093
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001094// Block of code at start here for managing/tracking Pipeline state that this layer cares about
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001095
1096static uint64_t g_drawCount[NUM_DRAW_TYPES] = {0, 0, 0, 0};
1097
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001098// TODO : Should be tracking lastBound per commandBuffer and when draws occur, report based on that cmd buffer lastBound
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001099// Then need to synchronize the accesses based on cmd buffer so that if I'm reading state on one cmd buffer, updates
1100// to that same cmd buffer by separate thread are not changing state from underneath us
1101// Track the last cmd buffer touched by this thread
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001102
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001103// prototype
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001104static GLOBAL_CB_NODE* getCBNode(layer_data*, const VkCommandBuffer);
Tobin Ehlis559c6382015-11-05 09:52:49 -07001105
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06001106static VkBool32 hasDrawCmd(GLOBAL_CB_NODE* pCB)
Tobin Ehlis53eddda2015-07-01 16:46:13 -06001107{
1108 for (uint32_t i=0; i<NUM_DRAW_TYPES; i++) {
1109 if (pCB->drawCount[i])
1110 return VK_TRUE;
1111 }
1112 return VK_FALSE;
1113}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001114
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001115// Check object status for selected flag state
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001116static VkBool32 validate_status(layer_data* my_data, GLOBAL_CB_NODE* pNode, CBStatusFlags enable_mask, CBStatusFlags status_mask, CBStatusFlags status_flag, VkFlags msg_flags, DRAW_STATE_ERROR error_code, const char* fail_msg)
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001117{
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001118 // If non-zero enable mask is present, check it against status but if enable_mask
1119 // is 0 then no enable required so we should always just check status
1120 if ((!enable_mask) || (enable_mask & pNode->status)) {
1121 if ((pNode->status & status_mask) != status_flag) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001122 // TODO : How to pass dispatchable objects as srcObject? Here src obj should be cmd buffer
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001123 return log_msg(my_data->report_data, msg_flags, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, error_code, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001124 "CB object %#" PRIxLEAST64 ": %s", reinterpret_cast<uint64_t>(pNode->commandBuffer), fail_msg);
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001125 }
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001126 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001127 return VK_FALSE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001128}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001129
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001130// Retrieve pipeline node ptr for given pipeline object
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001131static PIPELINE_NODE* getPipeline(layer_data* my_data, const VkPipeline pipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001132{
1133 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08001134 if (my_data->pipelineMap.find(pipeline) == my_data->pipelineMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001135 loader_platform_thread_unlock_mutex(&globalLock);
1136 return NULL;
1137 }
1138 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08001139 return my_data->pipelineMap[pipeline];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001140}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001141
Tobin Ehlisd332f282015-10-02 11:00:56 -06001142// Return VK_TRUE if for a given PSO, the given state enum is dynamic, else return VK_FALSE
1143static VkBool32 isDynamic(const PIPELINE_NODE* pPipeline, const VkDynamicState state)
1144{
1145 if (pPipeline && pPipeline->graphicsPipelineCI.pDynamicState) {
1146 for (uint32_t i=0; i<pPipeline->graphicsPipelineCI.pDynamicState->dynamicStateCount; i++) {
1147 if (state == pPipeline->graphicsPipelineCI.pDynamicState->pDynamicStates[i])
1148 return VK_TRUE;
1149 }
1150 }
1151 return VK_FALSE;
1152}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001153
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001154// Validate state stored as flags at time of draw call
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001155static VkBool32 validate_draw_state_flags(layer_data* my_data, GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06001156 VkBool32 result;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001157 result = validate_status(my_data, pCB, CBSTATUS_NONE, CBSTATUS_VIEWPORT_SET, CBSTATUS_VIEWPORT_SET, VK_DEBUG_REPORT_ERROR_BIT_EXT, DRAWSTATE_VIEWPORT_NOT_BOUND, "Dynamic viewport state not set for this command buffer");
1158 result |= validate_status(my_data, pCB, CBSTATUS_NONE, CBSTATUS_SCISSOR_SET, CBSTATUS_SCISSOR_SET, VK_DEBUG_REPORT_ERROR_BIT_EXT, DRAWSTATE_SCISSOR_NOT_BOUND, "Dynamic scissor state not set for this command buffer");
1159 result |= validate_status(my_data, pCB, CBSTATUS_NONE, CBSTATUS_LINE_WIDTH_SET, CBSTATUS_LINE_WIDTH_SET, VK_DEBUG_REPORT_ERROR_BIT_EXT, DRAWSTATE_LINE_WIDTH_NOT_BOUND, "Dynamic line width state not set for this command buffer");
1160 result |= validate_status(my_data, pCB, CBSTATUS_NONE, CBSTATUS_DEPTH_BIAS_SET, CBSTATUS_DEPTH_BIAS_SET, VK_DEBUG_REPORT_ERROR_BIT_EXT, DRAWSTATE_DEPTH_BIAS_NOT_BOUND, "Dynamic depth bias state not set for this command buffer");
1161 result |= validate_status(my_data, pCB, CBSTATUS_COLOR_BLEND_WRITE_ENABLE, CBSTATUS_BLEND_SET, CBSTATUS_BLEND_SET, VK_DEBUG_REPORT_ERROR_BIT_EXT, DRAWSTATE_BLEND_NOT_BOUND, "Dynamic blend object state not set for this command buffer");
1162 result |= validate_status(my_data, pCB, CBSTATUS_DEPTH_WRITE_ENABLE, CBSTATUS_DEPTH_BOUNDS_SET, CBSTATUS_DEPTH_BOUNDS_SET, VK_DEBUG_REPORT_ERROR_BIT_EXT, DRAWSTATE_DEPTH_BOUNDS_NOT_BOUND, "Dynamic depth bounds state not set for this command buffer");
1163 result |= validate_status(my_data, pCB, CBSTATUS_STENCIL_TEST_ENABLE, CBSTATUS_STENCIL_READ_MASK_SET, CBSTATUS_STENCIL_READ_MASK_SET, VK_DEBUG_REPORT_ERROR_BIT_EXT, DRAWSTATE_STENCIL_NOT_BOUND, "Dynamic stencil read mask state not set for this command buffer");
1164 result |= validate_status(my_data, pCB, CBSTATUS_STENCIL_TEST_ENABLE, CBSTATUS_STENCIL_WRITE_MASK_SET, CBSTATUS_STENCIL_WRITE_MASK_SET, VK_DEBUG_REPORT_ERROR_BIT_EXT, DRAWSTATE_STENCIL_NOT_BOUND, "Dynamic stencil write mask state not set for this command buffer");
1165 result |= validate_status(my_data, pCB, CBSTATUS_STENCIL_TEST_ENABLE, CBSTATUS_STENCIL_REFERENCE_SET, CBSTATUS_STENCIL_REFERENCE_SET, VK_DEBUG_REPORT_ERROR_BIT_EXT, DRAWSTATE_STENCIL_NOT_BOUND, "Dynamic stencil reference state not set for this command buffer");
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001166 if (indexedDraw)
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001167 result |= validate_status(my_data, pCB, CBSTATUS_NONE, CBSTATUS_INDEX_BUFFER_BOUND, CBSTATUS_INDEX_BUFFER_BOUND, VK_DEBUG_REPORT_ERROR_BIT_EXT, DRAWSTATE_INDEX_BUFFER_NOT_BOUND, "Index buffer object not bound to this command buffer when Indexed Draw attempted");
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001168 return result;
1169}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001170
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001171// Verify attachment reference compatibility according to spec
1172// If one array is larger, treat missing elements of shorter array as VK_ATTACHMENT_UNUSED & other array much match this
1173// If both AttachmentReference arrays have requested index, check their corresponding AttachementDescriptions
1174// to make sure that format and samples counts match.
1175// If not, they are not compatible.
1176static bool attachment_references_compatible(const uint32_t index, const VkAttachmentReference* pPrimary, const uint32_t primaryCount, const VkAttachmentDescription* pPrimaryAttachments,
1177 const VkAttachmentReference* pSecondary, const uint32_t secondaryCount, const VkAttachmentDescription* pSecondaryAttachments)
1178{
1179 if (index >= primaryCount) { // Check secondary as if primary is VK_ATTACHMENT_UNUSED
1180 if (VK_ATTACHMENT_UNUSED != pSecondary[index].attachment)
1181 return false;
1182 } else if (index >= secondaryCount) { // Check primary as if secondary is VK_ATTACHMENT_UNUSED
1183 if (VK_ATTACHMENT_UNUSED != pPrimary[index].attachment)
1184 return false;
1185 } else { // format and sample count must match
1186 if ((pPrimaryAttachments[pPrimary[index].attachment].format == pSecondaryAttachments[pSecondary[index].attachment].format) &&
1187 (pPrimaryAttachments[pPrimary[index].attachment].samples == pSecondaryAttachments[pSecondary[index].attachment].samples))
1188 return true;
1189 }
1190 // Format and sample counts didn't match
1191 return false;
1192}
1193
1194// For give primary and secondary RenderPass objects, verify that they're compatible
1195static bool verify_renderpass_compatibility(layer_data* my_data, const VkRenderPass primaryRP, const VkRenderPass secondaryRP, string& errorMsg)
1196{
1197 stringstream errorStr;
1198 if (my_data->renderPassMap.find(primaryRP) == my_data->renderPassMap.end()) {
1199 errorStr << "invalid VkRenderPass (" << primaryRP << ")";
1200 errorMsg = errorStr.str();
1201 return false;
1202 } else if (my_data->renderPassMap.find(secondaryRP) == my_data->renderPassMap.end()) {
1203 errorStr << "invalid VkRenderPass (" << secondaryRP << ")";
1204 errorMsg = errorStr.str();
1205 return false;
1206 }
1207 // Trivial pass case is exact same RP
1208 if (primaryRP == secondaryRP)
1209 return true;
1210 const VkRenderPassCreateInfo* primaryRPCI = my_data->renderPassMap[primaryRP]->pCreateInfo;
1211 const VkRenderPassCreateInfo* secondaryRPCI = my_data->renderPassMap[secondaryRP]->pCreateInfo;
1212 if (primaryRPCI->subpassCount != secondaryRPCI->subpassCount) {
1213 errorStr << "RenderPass for primary cmdBuffer has " << primaryRPCI->subpassCount << " subpasses but renderPass for secondary cmdBuffer has " << secondaryRPCI->subpassCount << " subpasses.";
1214 errorMsg = errorStr.str();
1215 return false;
1216 }
1217 uint32_t spIndex = 0;
1218 for (spIndex = 0; spIndex < primaryRPCI->subpassCount; ++spIndex) {
1219 // For each subpass, verify that corresponding color, input, resolve & depth/stencil attachment references are compatible
1220 uint32_t primaryColorCount = primaryRPCI->pSubpasses[spIndex].colorAttachmentCount;
1221 uint32_t secondaryColorCount = secondaryRPCI->pSubpasses[spIndex].colorAttachmentCount;
1222 uint32_t colorMax = std::max(primaryColorCount, secondaryColorCount);
1223 for (uint32_t cIdx = 0; cIdx < colorMax; ++cIdx) {
1224 if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pColorAttachments, primaryColorCount, primaryRPCI->pAttachments,
1225 secondaryRPCI->pSubpasses[spIndex].pColorAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1226 errorStr << "color attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
1227 errorMsg = errorStr.str();
1228 return false;
1229 } else if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pResolveAttachments, primaryColorCount, primaryRPCI->pAttachments,
1230 secondaryRPCI->pSubpasses[spIndex].pResolveAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1231 errorStr << "resolve attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
1232 errorMsg = errorStr.str();
1233 return false;
1234 } else if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pDepthStencilAttachment, primaryColorCount, primaryRPCI->pAttachments,
1235 secondaryRPCI->pSubpasses[spIndex].pDepthStencilAttachment, secondaryColorCount, secondaryRPCI->pAttachments)) {
1236 errorStr << "depth/stencil attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
1237 errorMsg = errorStr.str();
1238 return false;
1239 }
1240 }
1241 uint32_t primaryInputCount = primaryRPCI->pSubpasses[spIndex].inputAttachmentCount;
1242 uint32_t secondaryInputCount = secondaryRPCI->pSubpasses[spIndex].inputAttachmentCount;
1243 uint32_t inputMax = std::max(primaryInputCount, secondaryInputCount);
1244 for (uint32_t i = 0; i < inputMax; ++i) {
1245 if (!attachment_references_compatible(i, primaryRPCI->pSubpasses[spIndex].pInputAttachments, primaryColorCount, primaryRPCI->pAttachments,
1246 secondaryRPCI->pSubpasses[spIndex].pInputAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1247 errorStr << "input attachments at index " << i << " of subpass index " << spIndex << " are not compatible.";
1248 errorMsg = errorStr.str();
1249 return false;
1250 }
1251 }
1252 }
1253 return true;
1254}
1255
Tobin Ehlis559c6382015-11-05 09:52:49 -07001256// For give SET_NODE, verify that its Set is compatible w/ the setLayout corresponding to pipelineLayout[layoutIndex]
1257static bool verify_set_layout_compatibility(layer_data* my_data, const SET_NODE* pSet, const VkPipelineLayout layout, const uint32_t layoutIndex, string& errorMsg)
1258{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001259 stringstream errorStr;
Tobin Ehlis559c6382015-11-05 09:52:49 -07001260 if (my_data->pipelineLayoutMap.find(layout) == my_data->pipelineLayoutMap.end()) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001261 errorStr << "invalid VkPipelineLayout (" << layout << ")";
1262 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001263 return false;
1264 }
1265 PIPELINE_LAYOUT_NODE pl = my_data->pipelineLayoutMap[layout];
1266 if (layoutIndex >= pl.descriptorSetLayouts.size()) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001267 errorStr << "VkPipelineLayout (" << layout << ") only contains " << pl.descriptorSetLayouts.size() << " setLayouts corresponding to sets 0-" << pl.descriptorSetLayouts.size()-1 << ", but you're attempting to bind set to index " << layoutIndex;
1268 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001269 return false;
1270 }
1271 // Get the specific setLayout from PipelineLayout that overlaps this set
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001272 LAYOUT_NODE* pLayoutNode = my_data->descriptorSetLayoutMap[pl.descriptorSetLayouts[layoutIndex]];
Tobin Ehlis559c6382015-11-05 09:52:49 -07001273 if (pLayoutNode->layout == pSet->pLayout->layout) { // trivial pass case
1274 return true;
1275 }
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07001276 size_t descriptorCount = pLayoutNode->descriptorTypes.size();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001277 if (descriptorCount != pSet->pLayout->descriptorTypes.size()) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001278 errorStr << "setLayout " << layoutIndex << " from pipelineLayout " << layout << " has " << descriptorCount << " descriptors, but corresponding set being bound has " << pSet->pLayout->descriptorTypes.size() << " descriptors.";
1279 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001280 return false; // trivial fail case
1281 }
1282 // Now need to check set against corresponding pipelineLayout to verify compatibility
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07001283 for (size_t i=0; i<descriptorCount; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07001284 // Need to verify that layouts are identically defined
1285 // TODO : Is below sufficient? Making sure that types & stageFlags match per descriptor
1286 // do we also need to check immutable samplers?
1287 if (pLayoutNode->descriptorTypes[i] != pSet->pLayout->descriptorTypes[i]) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001288 errorStr << "descriptor " << i << " for descriptorSet being bound is type '" << string_VkDescriptorType(pSet->pLayout->descriptorTypes[i]) << "' but corresponding descriptor from pipelineLayout is type '" << string_VkDescriptorType(pLayoutNode->descriptorTypes[i]) << "'";
1289 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001290 return false;
1291 }
1292 if (pLayoutNode->stageFlags[i] != pSet->pLayout->stageFlags[i]) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001293 errorStr << "stageFlags " << i << " for descriptorSet being bound is " << pSet->pLayout->stageFlags[i] << "' but corresponding descriptor from pipelineLayout has stageFlags " << pLayoutNode->stageFlags[i];
1294 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001295 return false;
1296 }
1297 }
1298 return true;
1299}
1300
Tobin Ehlis88452832015-12-03 09:40:56 -07001301// Validate that the shaders used by the given pipeline
1302// As a side effect this function also records the sets that are actually used by the pipeline
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07001303static VkBool32
Tobin Ehlis88452832015-12-03 09:40:56 -07001304validate_pipeline_shaders(layer_data *my_data, VkDevice dev, PIPELINE_NODE* pPipeline)
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001305{
Tobin Ehlis88452832015-12-03 09:40:56 -07001306 VkGraphicsPipelineCreateInfo const *pCreateInfo = &pPipeline->graphicsPipelineCI;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001307 /* We seem to allow pipeline stages to be specified out of order, so collect and identify them
1308 * before trying to do anything more: */
1309 int vertex_stage = get_shader_stage_id(VK_SHADER_STAGE_VERTEX_BIT);
1310 int geometry_stage = get_shader_stage_id(VK_SHADER_STAGE_GEOMETRY_BIT);
1311 int fragment_stage = get_shader_stage_id(VK_SHADER_STAGE_FRAGMENT_BIT);
1312
1313 shader_module **shaders = new shader_module*[fragment_stage + 1]; /* exclude CS */
1314 memset(shaders, 0, sizeof(shader_module *) * (fragment_stage +1));
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001315 RENDER_PASS_NODE const *rp = 0;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001316 VkPipelineVertexInputStateCreateInfo const *vi = 0;
Mark Youngb20a6a82016-01-07 15:41:43 -07001317 VkBool32 pass = VK_TRUE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001318
1319 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
1320 VkPipelineShaderStageCreateInfo const *pStage = &pCreateInfo->pStages[i];
1321 if (pStage->sType == VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO) {
1322
1323 if ((pStage->stage & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_GEOMETRY_BIT | VK_SHADER_STAGE_FRAGMENT_BIT
1324 | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT)) == 0) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001325 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__, SHADER_CHECKER_UNKNOWN_STAGE, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001326 "Unknown shader stage %d", pStage->stage)) {
Mark Youngb20a6a82016-01-07 15:41:43 -07001327 pass = VK_FALSE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001328 }
1329 }
1330 else {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001331 shader_module *module = my_data->shaderModuleMap[pStage->module];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001332 shaders[get_shader_stage_id(pStage->stage)] = module;
1333
1334 /* validate descriptor set layout against what the spirv module actually uses */
1335 std::map<std::pair<unsigned, unsigned>, interface_var> descriptor_uses;
1336 collect_interface_by_descriptor_slot(my_data, dev, module, spv::StorageClassUniform,
1337 descriptor_uses);
1338
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001339 auto layouts = pCreateInfo->layout != VK_NULL_HANDLE ?
1340 &(my_data->pipelineLayoutMap[pCreateInfo->layout].descriptorSetLayouts) : nullptr;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001341
1342 for (auto it = descriptor_uses.begin(); it != descriptor_uses.end(); it++) {
Tobin Ehlis88452832015-12-03 09:40:56 -07001343 // As a side-effect of this function, capture which sets are used by the pipeline
1344 pPipeline->active_sets.insert(it->first.first);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001345
1346 /* find the matching binding */
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001347 auto found = has_descriptor_binding(my_data, layouts, it->first);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001348
1349 if (!found) {
1350 char type_name[1024];
1351 describe_type(type_name, module, it->second.type_id);
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001352 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__,
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001353 SHADER_CHECKER_MISSING_DESCRIPTOR, "SC",
1354 "Shader uses descriptor slot %u.%u (used as type `%s`) but not declared in pipeline layout",
1355 it->first.first, it->first.second, type_name)) {
Mark Youngb20a6a82016-01-07 15:41:43 -07001356 pass = VK_FALSE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001357 }
1358 }
1359 }
1360 }
1361 }
1362 }
1363
1364 if (pCreateInfo->renderPass != VK_NULL_HANDLE)
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001365 rp = my_data->renderPassMap[pCreateInfo->renderPass];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001366
1367 vi = pCreateInfo->pVertexInputState;
1368
1369 if (vi) {
1370 pass = validate_vi_consistency(my_data, dev, vi) && pass;
1371 }
1372
1373 if (shaders[vertex_stage]) {
1374 pass = validate_vi_against_vs_inputs(my_data, dev, vi, shaders[vertex_stage]) && pass;
1375 }
1376
1377 /* TODO: enforce rules about present combinations of shaders */
1378 int producer = get_shader_stage_id(VK_SHADER_STAGE_VERTEX_BIT);
1379 int consumer = get_shader_stage_id(VK_SHADER_STAGE_GEOMETRY_BIT);
1380
1381 while (!shaders[producer] && producer != fragment_stage) {
1382 producer++;
1383 consumer++;
1384 }
1385
1386 for (; producer != fragment_stage && consumer <= fragment_stage; consumer++) {
1387 assert(shaders[producer]);
1388 if (shaders[consumer]) {
1389 pass = validate_interface_between_stages(my_data, dev,
1390 shaders[producer], shader_stage_attribs[producer].name,
1391 shaders[consumer], shader_stage_attribs[consumer].name,
1392 shader_stage_attribs[consumer].arrayed_input) && pass;
1393
1394 producer = consumer;
1395 }
1396 }
1397
1398 if (shaders[fragment_stage] && rp) {
1399 pass = validate_fs_outputs_against_render_pass(my_data, dev, shaders[fragment_stage], rp, pCreateInfo->subpass) && pass;
1400 }
1401
Chris Forbes47f4f6f2015-12-17 17:10:19 +13001402 delete [] shaders;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001403
1404 return pass;
1405}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001406
Tobin Ehlisf6585052015-12-17 11:48:42 -07001407// Return Set node ptr for specified set or else NULL
1408static SET_NODE* getSetNode(layer_data* my_data, const VkDescriptorSet set)
1409{
1410 loader_platform_thread_lock_mutex(&globalLock);
1411 if (my_data->setMap.find(set) == my_data->setMap.end()) {
1412 loader_platform_thread_unlock_mutex(&globalLock);
1413 return NULL;
1414 }
1415 loader_platform_thread_unlock_mutex(&globalLock);
1416 return my_data->setMap[set];
1417}
1418
1419// For the given set, verify that for each dynamic descriptor in that set that its
1420// dynamic offset combined with the offet and range from its descriptor update
1421// do not overflow the size of its buffer being updated
1422static VkBool32 validate_dynamic_offsets(layer_data* my_data, const SET_NODE* pSet)
1423{
1424 VkBool32 result = VK_FALSE;
1425 if (pSet->dynamicOffsets.empty())
1426 return result;
1427
1428 VkWriteDescriptorSet* pWDS = NULL;
1429 uint32_t dynOffsetIndex = 0;
1430 VkDeviceSize bufferSize = 0;
1431 for (uint32_t i=0; i < pSet->descriptorCount; ++i) {
1432 switch (pSet->ppDescriptors[i]->sType) {
1433 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1434 pWDS = (VkWriteDescriptorSet*)pSet->ppDescriptors[i];
1435 if ((pWDS->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
1436 (pWDS->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
1437 for (uint32_t j=0; j<pWDS->descriptorCount; ++j) {
Michael Lentine700b0aa2015-10-30 17:57:32 -07001438 bufferSize = my_data->bufferMap[pWDS->pBufferInfo[j].buffer].create_info->size;
Tobin Ehlisf6585052015-12-17 11:48:42 -07001439 if ((pSet->dynamicOffsets[dynOffsetIndex] + pWDS->pBufferInfo[j].offset + pWDS->pBufferInfo[j].range) > bufferSize) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001440 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t)pSet->set, __LINE__, DRAWSTATE_DYNAMIC_OFFSET_OVERFLOW, "DS",
Tobin Ehlisf6585052015-12-17 11:48:42 -07001441 "VkDescriptorSet (%#" PRIxLEAST64 ") bound as set #%u has dynamic offset %u. Combined with offet %#" PRIxLEAST64 " and range %#" PRIxLEAST64 " from its update, this oversteps its buffer (%#" PRIxLEAST64 ") which has a size of %#" PRIxLEAST64 ".",
1442 (uint64_t)pSet->set, i, pSet->dynamicOffsets[dynOffsetIndex], pWDS->pBufferInfo[j].offset, pWDS->pBufferInfo[j].range, (uint64_t)pWDS->pBufferInfo[j].buffer, bufferSize);
1443 }
1444 dynOffsetIndex++;
1445 i += j; // Advance i to end of this set of descriptors (++i at end of for loop will move 1 index past last of these descriptors)
1446 }
1447 }
1448 break;
1449 default: // Currently only shadowing Write update nodes so shouldn't get here
1450 assert(0);
1451 continue;
1452 }
1453 }
1454 return result;
1455}
1456
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001457// Validate overall state at the time of a draw call
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001458static VkBool32 validate_draw_state(layer_data* my_data, GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001459 // First check flag states
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001460 VkBool32 result = validate_draw_state_flags(my_data, pCB, indexedDraw);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001461 PIPELINE_NODE* pPipe = getPipeline(my_data, pCB->lastBoundPipeline);
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001462 // Now complete other state checks
Tobin Ehlise90e66d2015-09-09 13:31:01 -06001463 // TODO : Currently only performing next check if *something* was bound (non-zero last bound)
1464 // There is probably a better way to gate when this check happens, and to know if something *should* have been bound
1465 // We should have that check separately and then gate this check based on that check
Mark Lobodzinski74635932015-12-18 15:35:38 -07001466 if (pPipe) {
1467 if (pCB->lastBoundPipelineLayout) {
1468 string errorString;
1469 for (auto setIndex : pPipe->active_sets) {
1470 // If valid set is not bound throw an error
1471 if ((pCB->boundDescriptorSets.size() <= setIndex) || (!pCB->boundDescriptorSets[setIndex])) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001472 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_DESCRIPTOR_SET_NOT_BOUND, "DS",
Mark Lobodzinski74635932015-12-18 15:35:38 -07001473 "VkPipeline %#" PRIxLEAST64 " uses set #%u but that set is not bound.", (uint64_t)pPipe->pipeline, setIndex);
1474 } else if (!verify_set_layout_compatibility(my_data, my_data->setMap[pCB->boundDescriptorSets[setIndex]], pPipe->graphicsPipelineCI.layout, setIndex, errorString)) {
1475 // Set is bound but not compatible w/ overlapping pipelineLayout from PSO
1476 VkDescriptorSet setHandle = my_data->setMap[pCB->boundDescriptorSets[setIndex]]->set;
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001477 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t)setHandle, __LINE__, DRAWSTATE_PIPELINE_LAYOUTS_INCOMPATIBLE, "DS",
Mark Lobodzinski74635932015-12-18 15:35:38 -07001478 "VkDescriptorSet (%#" PRIxLEAST64 ") bound as set #%u is not compatible with overlapping VkPipelineLayout %#" PRIxLEAST64 " due to: %s",
1479 (uint64_t)setHandle, setIndex, (uint64_t)pPipe->graphicsPipelineCI.layout, errorString.c_str());
Tobin Ehlis43c39c02016-01-11 13:18:40 -07001480 } else { // Valid set is bound and layout compatible, validate that it's updated and verify any dynamic offsets
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07001481 // Add this set as a valid set for this CB
1482 pCB->activeSets.insert(pCB->boundDescriptorSets[setIndex]);
Tobin Ehlis43c39c02016-01-11 13:18:40 -07001483 // Pull the set node
Tobin Ehlisf6585052015-12-17 11:48:42 -07001484 SET_NODE* pSet = getSetNode(my_data, pCB->boundDescriptorSets[setIndex]);
Tobin Ehlis43c39c02016-01-11 13:18:40 -07001485 // Make sure set has been updated
1486 if (!pSet->pUpdateStructs) {
1487 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pSet->set, __LINE__, DRAWSTATE_DESCRIPTOR_SET_NOT_UPDATED, "DS",
1488 "DS %#" PRIxLEAST64 " bound but it was never updated. It is now being used to draw so this will result in undefined behavior.", (uint64_t) pSet->set);
1489 }
1490 // For each dynamic descriptor, make sure dynamic offset doesn't overstep buffer
Tobin Ehlisf6585052015-12-17 11:48:42 -07001491 result |= validate_dynamic_offsets(my_data, pSet);
Mark Lobodzinski74635932015-12-18 15:35:38 -07001492 }
Tobin Ehlis88452832015-12-03 09:40:56 -07001493 }
1494 }
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07001495
Mark Lobodzinski74635932015-12-18 15:35:38 -07001496 // Verify Vtx binding
1497 if (pPipe->vtxBindingCount > 0) {
1498 VkPipelineVertexInputStateCreateInfo *vtxInCI = &pPipe->vertexInputCI;
1499 for (uint32_t i = 0; i < vtxInCI->vertexBindingDescriptionCount; i++) {
Michael Lentine700b0aa2015-10-30 17:57:32 -07001500 if ((pCB->currentDrawData.buffers.size() < (i+1)) || (pCB->currentDrawData.buffers[i] == VK_NULL_HANDLE)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001501 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS",
Mark Lobodzinski74635932015-12-18 15:35:38 -07001502 "The Pipeline State Object (%#" PRIxLEAST64 ") expects that this Command Buffer's vertex binding Index %d should be set via vkCmdBindVertexBuffers.",
1503 (uint64_t)pCB->lastBoundPipeline, i);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001504
Mark Lobodzinski74635932015-12-18 15:35:38 -07001505 }
1506 }
1507 } else {
Michael Lentine700b0aa2015-10-30 17:57:32 -07001508 if (!pCB->currentDrawData.buffers.empty()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001509 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS,
Mark Lobodzinski74635932015-12-18 15:35:38 -07001510 "DS", "Vertex buffers are bound to command buffer (%#" PRIxLEAST64 ") but no vertex buffers are attached to this Pipeline State Object (%#" PRIxLEAST64 ").",
1511 (uint64_t)pCB->commandBuffer, (uint64_t)pCB->lastBoundPipeline);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06001512 }
1513 }
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07001514
Mark Lobodzinski74635932015-12-18 15:35:38 -07001515 // If Viewport or scissors are dynamic, verify that dynamic count matches PSO count
1516 VkBool32 dynViewport = isDynamic(pPipe, VK_DYNAMIC_STATE_VIEWPORT);
1517 VkBool32 dynScissor = isDynamic(pPipe, VK_DYNAMIC_STATE_SCISSOR);
1518 if (dynViewport) {
1519 if (pCB->viewports.size() != pPipe->graphicsPipelineCI.pViewportState->viewportCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001520 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
Mark Lobodzinski74635932015-12-18 15:35:38 -07001521 "Dynamic viewportCount from vkCmdSetViewport() is " PRINTF_SIZE_T_SPECIFIER ", but PSO viewportCount is %u. These counts must match.", pCB->viewports.size(), pPipe->graphicsPipelineCI.pViewportState->viewportCount);
1522 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001523 }
Mark Lobodzinski74635932015-12-18 15:35:38 -07001524 if (dynScissor) {
1525 if (pCB->scissors.size() != pPipe->graphicsPipelineCI.pViewportState->scissorCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001526 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
Mark Lobodzinski74635932015-12-18 15:35:38 -07001527 "Dynamic scissorCount from vkCmdSetScissor() is " PRINTF_SIZE_T_SPECIFIER ", but PSO scissorCount is %u. These counts must match.", pCB->scissors.size(), pPipe->graphicsPipelineCI.pViewportState->scissorCount);
1528 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001529 }
1530 }
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001531 return result;
1532}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001533
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001534// Verify that create state for a pipeline is valid
Tobin Ehlis88452832015-12-03 09:40:56 -07001535static VkBool32 verifyPipelineCreateState(layer_data* my_data, const VkDevice device, PIPELINE_NODE* pPipeline)
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001536{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001537 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski2fd2d032015-12-16 14:25:22 -07001538
Tobin Ehlis88452832015-12-03 09:40:56 -07001539 if (!validate_pipeline_shaders(my_data, device, pPipeline)) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001540 skipCall = VK_TRUE;
1541 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001542 // VS is required
1543 if (!(pPipeline->active_shaders & VK_SHADER_STAGE_VERTEX_BIT)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001544 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001545 "Invalid Pipeline CreateInfo State: Vtx Shader required");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001546 }
1547 // Either both or neither TC/TE shaders should be defined
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001548 if (((pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) == 0) !=
1549 ((pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) == 0) ) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001550 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001551 "Invalid Pipeline CreateInfo State: TE and TC shaders must be included or excluded as a pair");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001552 }
1553 // Compute shaders should be specified independent of Gfx shaders
1554 if ((pPipeline->active_shaders & VK_SHADER_STAGE_COMPUTE_BIT) &&
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001555 (pPipeline->active_shaders & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT |
1556 VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT | VK_SHADER_STAGE_GEOMETRY_BIT |
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001557 VK_SHADER_STAGE_FRAGMENT_BIT))) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001558 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001559 "Invalid Pipeline CreateInfo State: Do not specify Compute Shader for Gfx Pipeline");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001560 }
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001561 // VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology is only valid for tessellation pipelines.
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001562 // Mismatching primitive topology and tessellation fails graphics pipeline creation.
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001563 if (pPipeline->active_shaders & (VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) &&
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001564 (pPipeline->iaStateCI.topology != VK_PRIMITIVE_TOPOLOGY_PATCH_LIST)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001565 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001566 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH_LIST must be set as IA topology for tessellation pipelines");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001567 }
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001568 if (pPipeline->iaStateCI.topology == VK_PRIMITIVE_TOPOLOGY_PATCH_LIST) {
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001569 if (~pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001570 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001571 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology is only valid for tessellation pipelines");
Tobin Ehlis912df022015-09-17 08:46:18 -06001572 }
1573 if (!pPipeline->tessStateCI.patchControlPoints || (pPipeline->tessStateCI.patchControlPoints > 32)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001574 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001575 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology used with patchControlPoints value %u."
Tobin Ehlis912df022015-09-17 08:46:18 -06001576 " patchControlPoints should be >0 and <=32.", pPipeline->tessStateCI.patchControlPoints);
1577 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001578 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001579 // Viewport state must be included and viewport and scissor counts should always match
Tobin Ehlise68360f2015-10-01 11:15:13 -06001580 // NOTE : Even if these are flagged as dynamic, counts need to be set correctly for shader compiler
Tobin Ehlisd332f282015-10-02 11:00:56 -06001581 if (!pPipeline->graphicsPipelineCI.pViewportState) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001582 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
Tobin Ehlisd332f282015-10-02 11:00:56 -06001583 "Gfx Pipeline pViewportState is null. Even if viewport and scissors are dynamic PSO must include viewportCount and scissorCount in pViewportState.");
1584 } else if (pPipeline->graphicsPipelineCI.pViewportState->scissorCount != pPipeline->graphicsPipelineCI.pViewportState->viewportCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001585 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
Tobin Ehlise68360f2015-10-01 11:15:13 -06001586 "Gfx Pipeline viewport count (%u) must match scissor count (%u).", pPipeline->vpStateCI.viewportCount, pPipeline->vpStateCI.scissorCount);
Tobin Ehlisd332f282015-10-02 11:00:56 -06001587 } else {
1588 // If viewport or scissor are not dynamic, then verify that data is appropriate for count
1589 VkBool32 dynViewport = isDynamic(pPipeline, VK_DYNAMIC_STATE_VIEWPORT);
1590 VkBool32 dynScissor = isDynamic(pPipeline, VK_DYNAMIC_STATE_SCISSOR);
1591 if (!dynViewport) {
1592 if (pPipeline->graphicsPipelineCI.pViewportState->viewportCount && !pPipeline->graphicsPipelineCI.pViewportState->pViewports) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001593 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
Courtney Goeltzenleuchterb19042e2015-11-25 11:38:54 -07001594 "Gfx Pipeline viewportCount is %u, but pViewports is NULL. For non-zero viewportCount, you must either include pViewports data, or include viewport in pDynamicState and set it with vkCmdSetViewport().", pPipeline->graphicsPipelineCI.pViewportState->viewportCount);
Tobin Ehlise68360f2015-10-01 11:15:13 -06001595 }
1596 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001597 if (!dynScissor) {
1598 if (pPipeline->graphicsPipelineCI.pViewportState->scissorCount && !pPipeline->graphicsPipelineCI.pViewportState->pScissors) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001599 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
Courtney Goeltzenleuchterb19042e2015-11-25 11:38:54 -07001600 "Gfx Pipeline scissorCount is %u, but pScissors is NULL. For non-zero scissorCount, you must either include pScissors data, or include scissor in pDynamicState and set it with vkCmdSetScissor().", pPipeline->graphicsPipelineCI.pViewportState->scissorCount);
Tobin Ehlisd332f282015-10-02 11:00:56 -06001601 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06001602 }
1603 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001604 return skipCall;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001605}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001606
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001607// Init the pipeline mapping info based on pipeline create info LL tree
1608// Threading note : Calls to this function should wrapped in mutex
Tobin Ehlis88452832015-12-03 09:40:56 -07001609// TODO : this should really just be in the constructor for PIPELINE_NODE
Mark Lobodzinski475a2182015-11-10 15:25:01 -07001610static PIPELINE_NODE* initGraphicsPipeline(layer_data* dev_data, const VkGraphicsPipelineCreateInfo* pCreateInfo, PIPELINE_NODE* pBasePipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001611{
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001612 PIPELINE_NODE* pPipeline = new PIPELINE_NODE;
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001613
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001614 if (pBasePipeline) {
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001615 *pPipeline = *pBasePipeline;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001616 }
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001617
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001618 // First init create info
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001619 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001620
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001621 size_t bufferSize = 0;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001622 const VkPipelineVertexInputStateCreateInfo* pVICI = NULL;
Tobin Ehlis5a65cca2015-07-13 13:14:24 -06001623 const VkPipelineColorBlendStateCreateInfo* pCBCI = NULL;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001624
1625 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
1626 const VkPipelineShaderStageCreateInfo *pPSSCI = &pCreateInfo->pStages[i];
1627
Chia-I Wu28e06912015-10-31 00:31:16 +08001628 switch (pPSSCI->stage) {
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001629 case VK_SHADER_STAGE_VERTEX_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001630 memcpy(&pPipeline->vsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1631 pPipeline->active_shaders |= VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001632 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001633 case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001634 memcpy(&pPipeline->tcsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001635 pPipeline->active_shaders |= VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001636 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001637 case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001638 memcpy(&pPipeline->tesCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001639 pPipeline->active_shaders |= VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001640 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001641 case VK_SHADER_STAGE_GEOMETRY_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001642 memcpy(&pPipeline->gsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1643 pPipeline->active_shaders |= VK_SHADER_STAGE_GEOMETRY_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001644 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001645 case VK_SHADER_STAGE_FRAGMENT_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001646 memcpy(&pPipeline->fsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1647 pPipeline->active_shaders |= VK_SHADER_STAGE_FRAGMENT_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001648 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001649 case VK_SHADER_STAGE_COMPUTE_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001650 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
1651 pPipeline->active_shaders |= VK_SHADER_STAGE_COMPUTE_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001652 break;
1653 default:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001654 // TODO : Flag error
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001655 break;
1656 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001657 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001658 // Copy over GraphicsPipelineCreateInfo structure embedded pointers
1659 if (pCreateInfo->stageCount != 0) {
1660 pPipeline->graphicsPipelineCI.pStages = new VkPipelineShaderStageCreateInfo[pCreateInfo->stageCount];
1661 bufferSize = pCreateInfo->stageCount * sizeof(VkPipelineShaderStageCreateInfo);
1662 memcpy((void*)pPipeline->graphicsPipelineCI.pStages, pCreateInfo->pStages, bufferSize);
1663 }
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001664 if (pCreateInfo->pVertexInputState != NULL) {
1665 memcpy((void*)&pPipeline->vertexInputCI, pCreateInfo->pVertexInputState , sizeof(VkPipelineVertexInputStateCreateInfo));
1666 // Copy embedded ptrs
1667 pVICI = pCreateInfo->pVertexInputState;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001668 pPipeline->vtxBindingCount = pVICI->vertexBindingDescriptionCount;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001669 if (pPipeline->vtxBindingCount) {
1670 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
1671 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
1672 memcpy((void*)pPipeline->pVertexBindingDescriptions, pVICI->pVertexBindingDescriptions, bufferSize);
1673 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08001674 pPipeline->vtxAttributeCount = pVICI->vertexAttributeDescriptionCount;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001675 if (pPipeline->vtxAttributeCount) {
1676 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
1677 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
1678 memcpy((void*)pPipeline->pVertexAttributeDescriptions, pVICI->pVertexAttributeDescriptions, bufferSize);
1679 }
1680 pPipeline->graphicsPipelineCI.pVertexInputState = &pPipeline->vertexInputCI;
1681 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001682 if (pCreateInfo->pInputAssemblyState != NULL) {
1683 memcpy((void*)&pPipeline->iaStateCI, pCreateInfo->pInputAssemblyState, sizeof(VkPipelineInputAssemblyStateCreateInfo));
1684 pPipeline->graphicsPipelineCI.pInputAssemblyState = &pPipeline->iaStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001685 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001686 if (pCreateInfo->pTessellationState != NULL) {
1687 memcpy((void*)&pPipeline->tessStateCI, pCreateInfo->pTessellationState, sizeof(VkPipelineTessellationStateCreateInfo));
1688 pPipeline->graphicsPipelineCI.pTessellationState = &pPipeline->tessStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001689 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001690 if (pCreateInfo->pViewportState != NULL) {
1691 memcpy((void*)&pPipeline->vpStateCI, pCreateInfo->pViewportState, sizeof(VkPipelineViewportStateCreateInfo));
1692 pPipeline->graphicsPipelineCI.pViewportState = &pPipeline->vpStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001693 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001694 if (pCreateInfo->pRasterizationState != NULL) {
1695 memcpy((void*)&pPipeline->rsStateCI, pCreateInfo->pRasterizationState, sizeof(VkPipelineRasterizationStateCreateInfo));
1696 pPipeline->graphicsPipelineCI.pRasterizationState = &pPipeline->rsStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001697 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001698 if (pCreateInfo->pMultisampleState != NULL) {
1699 memcpy((void*)&pPipeline->msStateCI, pCreateInfo->pMultisampleState, sizeof(VkPipelineMultisampleStateCreateInfo));
1700 pPipeline->graphicsPipelineCI.pMultisampleState = &pPipeline->msStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001701 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001702 if (pCreateInfo->pDepthStencilState != NULL) {
1703 memcpy((void*)&pPipeline->dsStateCI, pCreateInfo->pDepthStencilState, sizeof(VkPipelineDepthStencilStateCreateInfo));
1704 pPipeline->graphicsPipelineCI.pDepthStencilState = &pPipeline->dsStateCI;
1705 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001706 if (pCreateInfo->pColorBlendState != NULL) {
1707 memcpy((void*)&pPipeline->cbStateCI, pCreateInfo->pColorBlendState, sizeof(VkPipelineColorBlendStateCreateInfo));
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001708 // Copy embedded ptrs
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001709 pCBCI = pCreateInfo->pColorBlendState;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001710 pPipeline->attachmentCount = pCBCI->attachmentCount;
1711 if (pPipeline->attachmentCount) {
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001712 pPipeline->pAttachments = new VkPipelineColorBlendAttachmentState[pPipeline->attachmentCount];
1713 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineColorBlendAttachmentState);
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001714 memcpy((void*)pPipeline->pAttachments, pCBCI->pAttachments, bufferSize);
1715 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001716 pPipeline->graphicsPipelineCI.pColorBlendState = &pPipeline->cbStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001717 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001718 if (pCreateInfo->pDynamicState != NULL) {
1719 memcpy((void*)&pPipeline->dynStateCI, pCreateInfo->pDynamicState, sizeof(VkPipelineDynamicStateCreateInfo));
1720 if (pPipeline->dynStateCI.dynamicStateCount) {
1721 pPipeline->dynStateCI.pDynamicStates = new VkDynamicState[pPipeline->dynStateCI.dynamicStateCount];
1722 bufferSize = pPipeline->dynStateCI.dynamicStateCount * sizeof(VkDynamicState);
1723 memcpy((void*)pPipeline->dynStateCI.pDynamicStates, pCreateInfo->pDynamicState->pDynamicStates, bufferSize);
1724 }
1725 pPipeline->graphicsPipelineCI.pDynamicState = &pPipeline->dynStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001726 }
Tobin Ehlis88452832015-12-03 09:40:56 -07001727 pPipeline->active_sets.clear();
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001728 return pPipeline;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001729}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001730
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001731// Free the Pipeline nodes
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001732static void deletePipelines(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001733{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001734 if (my_data->pipelineMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06001735 return;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001736 for (auto ii=my_data->pipelineMap.begin(); ii!=my_data->pipelineMap.end(); ++ii) {
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001737 if ((*ii).second->graphicsPipelineCI.stageCount != 0) {
1738 delete[] (*ii).second->graphicsPipelineCI.pStages;
1739 }
Tobin Ehlisf313c8b2015-04-01 11:59:08 -06001740 if ((*ii).second->pVertexBindingDescriptions) {
1741 delete[] (*ii).second->pVertexBindingDescriptions;
1742 }
1743 if ((*ii).second->pVertexAttributeDescriptions) {
1744 delete[] (*ii).second->pVertexAttributeDescriptions;
1745 }
1746 if ((*ii).second->pAttachments) {
1747 delete[] (*ii).second->pAttachments;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001748 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001749 if ((*ii).second->dynStateCI.dynamicStateCount != 0) {
1750 delete[] (*ii).second->dynStateCI.pDynamicStates;
1751 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001752 delete (*ii).second;
1753 }
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001754 my_data->pipelineMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001755}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001756
Tobin Ehliseba312c2015-04-01 08:40:34 -06001757// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Chia-I Wu5c17c962015-10-31 00:31:16 +08001758static VkSampleCountFlagBits getNumSamples(layer_data* my_data, const VkPipeline pipeline)
Tobin Ehliseba312c2015-04-01 08:40:34 -06001759{
Chia-I Wue2fc5522015-10-26 20:04:44 +08001760 PIPELINE_NODE* pPipe = my_data->pipelineMap[pipeline];
Tobin Ehlis577188e2015-07-13 14:51:15 -06001761 if (VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001762 return pPipe->msStateCI.rasterizationSamples;
Tobin Ehlis577188e2015-07-13 14:51:15 -06001763 }
Chia-I Wu5c17c962015-10-31 00:31:16 +08001764 return VK_SAMPLE_COUNT_1_BIT;
Tobin Ehliseba312c2015-04-01 08:40:34 -06001765}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001766
Tobin Ehliseba312c2015-04-01 08:40:34 -06001767// Validate state related to the PSO
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001768static VkBool32 validatePipelineState(layer_data* my_data, const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehliseba312c2015-04-01 08:40:34 -06001769{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001770 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06001771 // Verify that any MSAA request in PSO matches sample# in bound FB
Chia-I Wu5c17c962015-10-31 00:31:16 +08001772 VkSampleCountFlagBits psoNumSamples = getNumSamples(my_data, pipeline);
Tobin Ehliseba312c2015-04-01 08:40:34 -06001773 if (pCB->activeRenderPass) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001774 const VkRenderPassCreateInfo* pRPCI = my_data->renderPassMap[pCB->activeRenderPass]->pCreateInfo;
Chia-I Wu08accc62015-07-07 11:50:03 +08001775 const VkSubpassDescription* pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
Chia-I Wu5c17c962015-10-31 00:31:16 +08001776 VkSampleCountFlagBits subpassNumSamples = (VkSampleCountFlagBits) 0;
Chia-I Wu08accc62015-07-07 11:50:03 +08001777 uint32_t i;
1778
Chia-I Wud50a7d72015-10-26 20:48:51 +08001779 for (i = 0; i < pSD->colorAttachmentCount; i++) {
Chia-I Wu5c17c962015-10-31 00:31:16 +08001780 VkSampleCountFlagBits samples;
Chia-I Wu08accc62015-07-07 11:50:03 +08001781
Cody Northropa505dda2015-08-04 11:16:41 -06001782 if (pSD->pColorAttachments[i].attachment == VK_ATTACHMENT_UNUSED)
Chia-I Wu08accc62015-07-07 11:50:03 +08001783 continue;
1784
Cody Northropa505dda2015-08-04 11:16:41 -06001785 samples = pRPCI->pAttachments[pSD->pColorAttachments[i].attachment].samples;
Chia-I Wu5c17c962015-10-31 00:31:16 +08001786 if (subpassNumSamples == (VkSampleCountFlagBits) 0) {
Chia-I Wu08accc62015-07-07 11:50:03 +08001787 subpassNumSamples = samples;
1788 } else if (subpassNumSamples != samples) {
Chia-I Wu5c17c962015-10-31 00:31:16 +08001789 subpassNumSamples = (VkSampleCountFlagBits) -1;
Chia-I Wu08accc62015-07-07 11:50:03 +08001790 break;
1791 }
1792 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08001793 if (pSD->pDepthStencilAttachment && pSD->pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
Chia-I Wu5c17c962015-10-31 00:31:16 +08001794 const VkSampleCountFlagBits samples = pRPCI->pAttachments[pSD->pDepthStencilAttachment->attachment].samples;
1795 if (subpassNumSamples == (VkSampleCountFlagBits) 0)
Chia-I Wu08accc62015-07-07 11:50:03 +08001796 subpassNumSamples = samples;
1797 else if (subpassNumSamples != samples)
Chia-I Wu5c17c962015-10-31 00:31:16 +08001798 subpassNumSamples = (VkSampleCountFlagBits) -1;
Chia-I Wu08accc62015-07-07 11:50:03 +08001799 }
1800
1801 if (psoNumSamples != subpassNumSamples) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001802 return log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, (uint64_t) pipeline, __LINE__, DRAWSTATE_NUM_SAMPLES_MISMATCH, "DS",
Mark Lobodzinski5495d132015-09-30 16:19:16 -06001803 "Num samples mismatch! Binding PSO (%#" PRIxLEAST64 ") with %u samples while current RenderPass (%#" PRIxLEAST64 ") w/ %u samples!",
Chia-I Wue2fc5522015-10-26 20:04:44 +08001804 (uint64_t) pipeline, psoNumSamples, (uint64_t) pCB->activeRenderPass, subpassNumSamples);
Tobin Ehliseba312c2015-04-01 08:40:34 -06001805 }
1806 } else {
1807 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
1808 // Verify and flag error as appropriate
1809 }
1810 // TODO : Add more checks here
1811 } else {
1812 // TODO : Validate non-gfx pipeline updates
1813 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001814 return VK_FALSE;
Tobin Ehliseba312c2015-04-01 08:40:34 -06001815}
1816
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001817// Block of code at start here specifically for managing/tracking DSs
1818
Tobin Ehlis793ad302015-04-03 12:01:11 -06001819// Return Pool node ptr for specified pool or else NULL
Mark Lobodzinski39298632015-11-18 08:38:27 -07001820static DESCRIPTOR_POOL_NODE* getPoolNode(layer_data* my_data, const VkDescriptorPool pool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001821{
1822 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07001823 if (my_data->descriptorPoolMap.find(pool) == my_data->descriptorPoolMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001824 loader_platform_thread_unlock_mutex(&globalLock);
1825 return NULL;
1826 }
1827 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07001828 return my_data->descriptorPoolMap[pool];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001829}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001830
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001831static LAYOUT_NODE* getLayoutNode(layer_data* my_data, const VkDescriptorSetLayout layout) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001832 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001833 if (my_data->descriptorSetLayoutMap.find(layout) == my_data->descriptorSetLayoutMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001834 loader_platform_thread_unlock_mutex(&globalLock);
1835 return NULL;
1836 }
1837 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001838 return my_data->descriptorSetLayoutMap[layout];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001839}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001840
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001841// Return VK_FALSE if update struct is of valid type, otherwise flag error and return code from callback
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001842static VkBool32 validUpdateStruct(layer_data* my_data, const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001843{
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001844 switch (pUpdateStruct->sType)
1845 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001846 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1847 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001848 return VK_FALSE;
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001849 default:
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001850 return log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001851 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001852 }
1853}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001854
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001855// Set count for given update struct in the last parameter
Courtney Goeltzenleuchter085f8dd2015-12-16 16:08:44 -07001856// Return value of skipCall, which is only VK_TRUE if error occurs and callback signals execution to cease
Tobin Ehlisbaca3ab2015-10-27 12:54:50 -06001857static uint32_t getUpdateCount(layer_data* my_data, const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis793ad302015-04-03 12:01:11 -06001858{
1859 switch (pUpdateStruct->sType)
1860 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001861 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
Chia-I Wud50a7d72015-10-26 20:48:51 +08001862 return ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorCount;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001863 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis793ad302015-04-03 12:01:11 -06001864 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wud50a7d72015-10-26 20:48:51 +08001865 return ((VkCopyDescriptorSet*)pUpdateStruct)->descriptorCount;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001866 }
Courtney Goeltzenleuchter7f47bca2015-12-16 16:08:08 -07001867
1868 return 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001869}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001870
Tobin Ehlis793ad302015-04-03 12:01:11 -06001871// For given Layout Node and binding, return index where that binding begins
1872static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
1873{
1874 uint32_t offsetIndex = 0;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001875 for (uint32_t i = 0; i < pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001876 if (pLayout->createInfo.pBindings[i].binding == binding)
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001877 break;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001878 offsetIndex += pLayout->createInfo.pBindings[i].descriptorCount;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001879 }
1880 return offsetIndex;
1881}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001882
Tobin Ehlis793ad302015-04-03 12:01:11 -06001883// For given layout node and binding, return last index that is updated
1884static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
1885{
1886 uint32_t offsetIndex = 0;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001887 for (uint32_t i = 0; i < pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001888 offsetIndex += pLayout->createInfo.pBindings[i].descriptorCount;
1889 if (pLayout->createInfo.pBindings[i].binding == binding)
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001890 break;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001891 }
1892 return offsetIndex-1;
1893}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001894
Tobin Ehlisbaca3ab2015-10-27 12:54:50 -06001895// For given layout and update, return the first overall index of the layout that is updated
Tobin Ehlis8a62e632015-10-27 15:43:38 -06001896static uint32_t getUpdateStartIndex(layer_data* my_data, const VkDevice device, const LAYOUT_NODE* pLayout, const uint32_t binding, const uint32_t arrayIndex, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis793ad302015-04-03 12:01:11 -06001897{
Tobin Ehlisbaca3ab2015-10-27 12:54:50 -06001898 return getBindingStartIndex(pLayout, binding)+arrayIndex;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001899}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001900
Tobin Ehlis8a62e632015-10-27 15:43:38 -06001901// For given layout and update, return the last overall index of the layout that is updated
1902static uint32_t getUpdateEndIndex(layer_data* my_data, const VkDevice device, const LAYOUT_NODE* pLayout, const uint32_t binding, const uint32_t arrayIndex, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis793ad302015-04-03 12:01:11 -06001903{
Tobin Ehlis8a62e632015-10-27 15:43:38 -06001904 uint32_t count = getUpdateCount(my_data, device, pUpdateStruct);
Tobin Ehlisbaca3ab2015-10-27 12:54:50 -06001905 return getBindingStartIndex(pLayout, binding)+arrayIndex+count-1;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001906}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001907
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001908// Verify that the descriptor type in the update struct matches what's expected by the layout
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001909static VkBool32 validateUpdateConsistency(layer_data* my_data, const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct, uint32_t startIndex, uint32_t endIndex)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001910{
1911 // First get actual type of update
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001912 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001913 VkDescriptorType actualType;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001914 uint32_t i = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001915 switch (pUpdateStruct->sType)
1916 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001917 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1918 actualType = ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorType;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001919 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001920 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
1921 /* no need to validate */
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001922 return VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001923 break;
1924 default:
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001925 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001926 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001927 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001928 if (VK_FALSE == skipCall) {
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001929 // Set first stageFlags as reference and verify that all other updates match it
1930 VkShaderStageFlags refStageFlags = pLayout->stageFlags[startIndex];
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001931 for (i = startIndex; i <= endIndex; i++) {
Tobin Ehlis644ff042015-10-20 10:11:55 -06001932 if (pLayout->descriptorTypes[i] != actualType) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001933 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, "DS",
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001934 "Write descriptor update has descriptor type %s that does not match overlapping binding descriptor type of %s!",
1935 string_VkDescriptorType(actualType), string_VkDescriptorType(pLayout->descriptorTypes[i]));
1936 }
1937 if (pLayout->stageFlags[i] != refStageFlags) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001938 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_DESCRIPTOR_STAGEFLAGS_MISMATCH, "DS",
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001939 "Write descriptor update has stageFlags %x that do not match overlapping binding descriptor stageFlags of %x!",
1940 refStageFlags, pLayout->stageFlags[i]);
Tobin Ehlis483cc352015-09-30 08:30:20 -06001941 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001942 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001943 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001944 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001945}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001946
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001947// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001948// struct into the pNewNode param. Return VK_TRUE if error condition encountered and callback signals early exit.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001949// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001950static VkBool32 shadowUpdateNode(layer_data* my_data, const VkDevice device, GENERIC_HEADER* pUpdate, GENERIC_HEADER** pNewNode)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001951{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001952 VkBool32 skipCall = VK_FALSE;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001953 VkWriteDescriptorSet* pWDS = NULL;
1954 VkCopyDescriptorSet* pCDS = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001955 size_t array_size = 0;
1956 size_t base_array_size = 0;
1957 size_t total_array_size = 0;
1958 size_t baseBuffAddr = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001959 switch (pUpdate->sType)
1960 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001961 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1962 pWDS = new VkWriteDescriptorSet;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001963 *pNewNode = (GENERIC_HEADER*)pWDS;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001964 memcpy(pWDS, pUpdate, sizeof(VkWriteDescriptorSet));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001965
1966 switch (pWDS->descriptorType) {
1967 case VK_DESCRIPTOR_TYPE_SAMPLER:
1968 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
1969 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
1970 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
1971 {
Chia-I Wud50a7d72015-10-26 20:48:51 +08001972 VkDescriptorImageInfo *info = new VkDescriptorImageInfo[pWDS->descriptorCount];
1973 memcpy(info, pWDS->pImageInfo, pWDS->descriptorCount * sizeof(VkDescriptorImageInfo));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001974 pWDS->pImageInfo = info;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001975 }
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001976 break;
1977 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
1978 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
1979 {
Chia-I Wud50a7d72015-10-26 20:48:51 +08001980 VkBufferView *info = new VkBufferView[pWDS->descriptorCount];
1981 memcpy(info, pWDS->pTexelBufferView, pWDS->descriptorCount * sizeof(VkBufferView));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001982 pWDS->pTexelBufferView = info;
1983 }
1984 break;
1985 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
1986 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
1987 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
1988 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
1989 {
Chia-I Wud50a7d72015-10-26 20:48:51 +08001990 VkDescriptorBufferInfo *info = new VkDescriptorBufferInfo[pWDS->descriptorCount];
1991 memcpy(info, pWDS->pBufferInfo, pWDS->descriptorCount * sizeof(VkDescriptorBufferInfo));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001992 pWDS->pBufferInfo = info;
1993 }
1994 break;
1995 default:
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07001996 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001997 break;
1998 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001999 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002000 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
2001 pCDS = new VkCopyDescriptorSet;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002002 *pNewNode = (GENERIC_HEADER*)pCDS;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002003 memcpy(pCDS, pUpdate, sizeof(VkCopyDescriptorSet));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002004 break;
2005 default:
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002006 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002007 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdate->sType), pUpdate->sType))
2008 return VK_TRUE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002009 }
2010 // Make sure that pNext for the end of shadow copy is NULL
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002011 (*pNewNode)->pNext = NULL;
2012 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002013}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002014
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002015// Verify that given sampler is valid
2016static VkBool32 validateSampler(const layer_data* my_data, const VkSampler* pSampler, const VkBool32 immutable)
2017{
2018 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002019 auto sampIt = my_data->sampleMap.find(*pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002020 if (sampIt == my_data->sampleMap.end()) {
2021 if (!immutable) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002022 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT, (uint64_t) *pSampler, __LINE__, DRAWSTATE_SAMPLER_DESCRIPTOR_ERROR, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002023 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid sampler %#" PRIxLEAST64, (uint64_t) *pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002024 } else { // immutable
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002025 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT, (uint64_t) *pSampler, __LINE__, DRAWSTATE_SAMPLER_DESCRIPTOR_ERROR, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002026 "vkUpdateDescriptorSets: Attempt to update descriptor whose binding has an invalid immutable sampler %#" PRIxLEAST64, (uint64_t) *pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002027 }
2028 } else {
2029 // TODO : Any further checks we want to do on the sampler?
2030 }
2031 return skipCall;
2032}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002033
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002034// Verify that given imageView is valid
2035static VkBool32 validateImageView(const layer_data* my_data, const VkImageView* pImageView, const VkImageLayout imageLayout)
2036{
2037 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002038 auto ivIt = my_data->imageViewMap.find(*pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002039 if (ivIt == my_data->imageViewMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002040 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, (uint64_t) *pImageView, __LINE__, DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002041 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid imageView %#" PRIxLEAST64, (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002042 } else {
2043 // Validate that imageLayout is compatible with aspectMask and image format
2044 VkImageAspectFlags aspectMask = ivIt->second->subresourceRange.aspectMask;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002045 VkImage image = ivIt->second->image;
Michael Lentine7b236262015-10-23 12:41:44 -07002046 // TODO : Check here in case we have a bad image
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()) {
2202 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, reinterpret_cast<uint64_t>(set), __LINE__, DRAWSTATE_DOUBLE_DESTROY, "DS",
2203 "Cannot call %s() on descriptor set %" PRIxLEAST64 " that has not been allocated.", func_str.c_str(), reinterpret_cast<uint64_t>(set));
2204 } else {
2205 if (set_node->second->in_use.load()) {
2206 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, reinterpret_cast<uint64_t>(set), __LINE__, DRAWSTATE_OBJECT_INUSE, "DS",
2207 "Cannot call %s() on descriptor set %" PRIxLEAST64 " that is in use by a command buffer.", func_str.c_str(), reinterpret_cast<uint64_t>(set));
2208 }
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()) {
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002238 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, reinterpret_cast<uint64_t>(ds), __LINE__, DRAWSTATE_INVALID_UPDATE_INDEX, "DS",
Michael Lentine010f4692015-11-03 16:19:46 -08002239 "Descriptor Set %" PRIu64 " does not have binding to match update binding %u for update type %s!", reinterpret_cast<uint64_t>(ds), binding, string_VkStructureType(pUpdate->sType));
Tobin Ehlis9c536442015-06-19 13:00:59 -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 Lobodzinskib01451b2016-01-04 13:18:10 -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 Lobodzinskib01451b2016-01-04 13:18:10 -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",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002509 "Attempt to use CommandBuffer %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<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",
Michael Lentine010f4692015-11-03 16:19:46 -08002711 "Layout #%u, (object %#" PRIxLEAST64 ") for DS %#" PRIxLEAST64 ".", index+1, reinterpret_cast<uint64_t>(pLayout->layout), reinterpret_cast<uint64_t>(pSet->set));
Tobin Ehlis793ad302015-04-03 12:01:11 -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",
Michael Lentine010f4692015-11-03 16:19:46 -08003079 "Cannot submit cmd buffer using deleted image %" PRIu64 ".", reinterpret_cast<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()) {
3100 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, reinterpret_cast<uint64_t>(set), __LINE__, DRAWSTATE_INVALID_DESCRIPTOR_SET, "DS",
3101 "Cannot submit cmd buffer using deleted descriptor set %" PRIu64 ".", reinterpret_cast<uint64_t>(set));
3102 } 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()) {
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07003115 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, reinterpret_cast<uint64_t>(buffer), __LINE__, DRAWSTATE_INVALID_BUFFER, "DS",
Michael Lentine700b0aa2015-10-30 17:57:32 -07003116 "Cannot submit cmd buffer using deleted buffer %" PRIu64 ".", reinterpret_cast<uint64_t>(buffer));
3117 } 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.",
3228 reinterpret_cast<uint64_t>(queue), reinterpret_cast<uint64_t>(submit->pWaitSemaphores[i]));
3229 }
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.",
3254 reinterpret_cast<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",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003259 "You must call vkEndCommandBuffer() on CB %#" PRIxLEAST64 " before this call to vkQueueSubmit()!", reinterpret_cast<uint64_t>(pCB->commandBuffer));
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -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()) {
3266 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, reinterpret_cast<uint64_t>(pCB->commandBuffer), __LINE__, DRAWSTATE_INVALID_CB_SIMULTANEOUS_USE, "DS",
3267 "Attempt to simultaneously execute CB %#" PRIxLEAST64 " w/o VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!", reinterpret_cast<uint64_t>(pCB->commandBuffer));
3268 }
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);
3282 for (auto queryEventsPair : pCB->waitedEventsBeforeQueryReset) {
3283 for (auto event : queryEventsPair.second) {
3284 if (my_data->eventMap[event].needsSignaled) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003285 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",
3286 "Cannot get query results on queryPool %" PRIu64 " with index %d which was guarded by unsignaled event %" PRIu64 ".",
Michael Lentineb887b0a2015-12-29 14:12:11 -06003287 reinterpret_cast<uint64_t>(queryEventsPair.first.pool), queryEventsPair.first.index, reinterpret_cast<uint64_t>(event));
3288 }
3289 }
3290 }
3291 return skip_call;
3292}
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003293// Remove given cmd_buffer from inFlight set for given queue
3294// If cmd_buffer is not inFlight on any other queues, also remove it from global inFlight set
3295static inline void removeInFlightCmdBuffer(layer_data* dev_data, VkQueue queue, VkCommandBuffer cmd_buffer)
3296{
3297 dev_data->queueMap[queue].inFlightCmdBuffers.erase(cmd_buffer);
3298 // Pull it off of global list initially, but if we find it in any other queue list, add it back in
3299 dev_data->inFlightCmdBuffers.erase(cmd_buffer);
3300 for (auto q : dev_data->queues) {
3301 if ((q != queue) && (dev_data->queueMap[q].inFlightCmdBuffers.find(cmd_buffer) != dev_data->queueMap[q].inFlightCmdBuffers.end())) {
3302 dev_data->inFlightCmdBuffers.insert(cmd_buffer);
3303 break;
3304 }
3305 }
3306}
Michael Lentineb887b0a2015-12-29 14:12:11 -06003307
Michael Lentine700b0aa2015-10-30 17:57:32 -07003308VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence* pFences, VkBool32 waitAll, uint64_t timeout)
3309{
3310 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3311 VkResult result = dev_data->device_dispatch_table->WaitForFences(device, fenceCount, pFences, waitAll, timeout);
Mark Youngb20a6a82016-01-07 15:41:43 -07003312 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003313 if ((waitAll || fenceCount == 1) && result == VK_SUCCESS) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06003314 for (uint32_t i = 0; i < fenceCount; ++i) {
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003315 VkQueue fence_queue = dev_data->fenceMap[pFences[i]].queue;
Michael Lentineb887b0a2015-12-29 14:12:11 -06003316 for (auto cmdBuffer : dev_data->fenceMap[pFences[i]].cmdBuffers) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06003317 skip_call |= cleanInFlightCmdBuffer(dev_data, cmdBuffer);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003318 removeInFlightCmdBuffer(dev_data, fence_queue, cmdBuffer);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003319 }
3320 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003321 decrementResources(dev_data, fenceCount, pFences);
3322 }
Mark Youngb20a6a82016-01-07 15:41:43 -07003323 if (VK_FALSE != skip_call)
Mark Lobodzinskice738852016-01-07 10:04:02 -07003324 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003325 return result;
3326}
3327
3328
3329VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetFenceStatus(VkDevice device, VkFence fence)
3330{
3331 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3332 VkResult result = dev_data->device_dispatch_table->GetFenceStatus(device, fence);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003333 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003334 if (result == VK_SUCCESS) {
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003335 auto fence_queue = dev_data->fenceMap[fence].queue;
Michael Lentineb887b0a2015-12-29 14:12:11 -06003336 for (auto cmdBuffer : dev_data->fenceMap[fence].cmdBuffers) {
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003337 skip_call |= cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3338 removeInFlightCmdBuffer(dev_data, fence_queue, cmdBuffer);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003339 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003340 decrementResources(dev_data, 1, &fence);
3341 }
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003342 if (VK_FALSE != skip_call)
3343 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003344 return result;
3345}
3346
3347VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue* pQueue)
3348{
3349 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3350 dev_data->device_dispatch_table->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003351 dev_data->queues.push_back(*pQueue);
Michael Lentine700b0aa2015-10-30 17:57:32 -07003352 dev_data->queueMap[*pQueue].device = device;
3353}
3354
3355VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueueWaitIdle(VkQueue queue)
3356{
3357 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
3358 decrementResources(dev_data, queue);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003359 VkBool32 skip_call = VK_FALSE;
3360 // Iterate over local set since we erase set members as we go in for loop
3361 auto local_cb_set = dev_data->queueMap[queue].inFlightCmdBuffers;
3362 for (auto cmdBuffer : local_cb_set) {
3363 skip_call |= cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3364 removeInFlightCmdBuffer(dev_data, queue, cmdBuffer);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003365 }
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003366 dev_data->queueMap[queue].inFlightCmdBuffers.clear();
3367 if (VK_FALSE != skip_call)
3368 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003369 return dev_data->device_dispatch_table->QueueWaitIdle(queue);
3370}
3371
3372VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkDeviceWaitIdle(VkDevice device)
3373{
3374 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003375 for (auto queue : dev_data->queues) {
3376 decrementResources(dev_data, queue);
3377 // Clear all of the queue inFlightCmdBuffers (global set cleared below)
3378 dev_data->queueMap[queue].inFlightCmdBuffers.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07003379 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003380 for (auto cmdBuffer : dev_data->inFlightCmdBuffers) {
3381 cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3382 }
3383 dev_data->inFlightCmdBuffers.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07003384 return dev_data->device_dispatch_table->DeviceWaitIdle(device);
3385}
3386
Chia-I Wu9ab61502015-11-06 06:42:02 +08003387VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003388{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003389 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 -06003390 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003391}
3392
Chia-I Wu9ab61502015-11-06 06:42:02 +08003393VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySemaphore(VkDevice device, VkSemaphore semaphore, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003394{
Michael Lentine15a47882016-01-06 10:05:48 -06003395 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3396 dev_data->device_dispatch_table->DestroySemaphore(device, semaphore, pAllocator);
3397 dev_data->semaphoreSignaledMap.erase(semaphore);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003398 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003399}
3400
Chia-I Wu9ab61502015-11-06 06:42:02 +08003401VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003402{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003403 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 -06003404 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003405}
3406
Chia-I Wu9ab61502015-11-06 06:42:02 +08003407VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003408{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003409 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 -06003410 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003411}
3412
Mark Lobodzinskice738852016-01-07 10:04:02 -07003413VKAPI_ATTR VkResult VKAPI_CALL vkGetQueryPoolResults(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount,
Michael Lentineb887b0a2015-12-29 14:12:11 -06003414 size_t dataSize, void* pData, VkDeviceSize stride, VkQueryResultFlags flags) {
3415 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3416 unordered_map<QueryObject, vector<VkCommandBuffer>> queriesInFlight;
3417 GLOBAL_CB_NODE* pCB = nullptr;
3418 for (auto cmdBuffer : dev_data->inFlightCmdBuffers) {
3419 pCB = getCBNode(dev_data, cmdBuffer);
3420 for (auto queryStatePair : pCB->queryToStateMap) {
3421 queriesInFlight[queryStatePair.first].push_back(cmdBuffer);
3422 }
3423 }
Mark Youngb20a6a82016-01-07 15:41:43 -07003424 VkBool32 skip_call = VK_FALSE;
Michael Lentineb887b0a2015-12-29 14:12:11 -06003425 for (uint32_t i = 0; i < queryCount; ++i) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003426 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06003427 auto queryElement = queriesInFlight.find(query);
3428 auto queryToStateElement = dev_data->queryToStateMap.find(query);
3429 if (queryToStateElement != dev_data->queryToStateMap.end()) {
3430 }
3431 // Available and in flight
3432 if(queryElement != queriesInFlight.end() && queryToStateElement != dev_data->queryToStateMap.end() && queryToStateElement->second) {
3433 for (auto cmdBuffer : queryElement->second) {
3434 pCB = getCBNode(dev_data, cmdBuffer);
3435 auto queryEventElement = pCB->waitedEventsBeforeQueryReset.find(query);
3436 if (queryEventElement == pCB->waitedEventsBeforeQueryReset.end()) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003437 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT, 0, __LINE__,
3438 DRAWSTATE_INVALID_QUERY, "DS", "Cannot get query results on queryPool %" PRIu64 " with index %d which is in flight.",
3439 reinterpret_cast<uint64_t>(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003440 } else {
3441 for (auto event : queryEventElement->second) {
3442 dev_data->eventMap[event].needsSignaled = true;
3443 }
3444 }
3445 }
3446 // Unavailable and in flight
3447 } else if (queryElement != queriesInFlight.end() && queryToStateElement != dev_data->queryToStateMap.end() && !queryToStateElement->second) {
3448 // TODO : Can there be the same query in use by multiple command buffers in flight?
3449 bool make_available = false;
3450 for (auto cmdBuffer : queryElement->second) {
3451 pCB = getCBNode(dev_data, cmdBuffer);
3452 make_available |= pCB->queryToStateMap[query];
3453 }
3454 if (!(((flags & VK_QUERY_RESULT_PARTIAL_BIT) || (flags & VK_QUERY_RESULT_WAIT_BIT)) && make_available)) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003455 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 -06003456 "Cannot get query results on queryPool %" PRIu64 " with index %d which is unavailable.",
Mark Lobodzinskice738852016-01-07 10:04:02 -07003457 reinterpret_cast<uint64_t>(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003458 }
3459 // Unavailable
3460 } else if (queryToStateElement != dev_data->queryToStateMap.end() && !queryToStateElement->second) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003461 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 -06003462 "Cannot get query results on queryPool %" PRIu64 " with index %d which is unavailable.",
Mark Lobodzinskice738852016-01-07 10:04:02 -07003463 reinterpret_cast<uint64_t>(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003464 // Unitialized
3465 } else if (queryToStateElement == dev_data->queryToStateMap.end()) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003466 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 -06003467 "Cannot get query results on queryPool %" PRIu64 " with index %d which is uninitialized.",
Mark Lobodzinskice738852016-01-07 10:04:02 -07003468 reinterpret_cast<uint64_t>(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003469 }
3470 }
3471 if (skip_call)
Mark Lobodzinskice738852016-01-07 10:04:02 -07003472 return VK_ERROR_VALIDATION_FAILED_EXT;
3473 return dev_data->device_dispatch_table->GetQueryPoolResults(device, queryPool, firstQuery, queryCount, dataSize, pData, stride, flags);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003474}
3475
Mark Young7a69c302016-01-07 09:48:47 -07003476VkBool32 validateIdleBuffer(const layer_data* my_data, VkBuffer buffer) {
Mark Youngb20a6a82016-01-07 15:41:43 -07003477 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003478 auto buffer_data = my_data->bufferMap.find(buffer);
3479 if (buffer_data == my_data->bufferMap.end()) {
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07003480 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, reinterpret_cast<uint64_t>(buffer), __LINE__, DRAWSTATE_DOUBLE_DESTROY, "DS",
Michael Lentine700b0aa2015-10-30 17:57:32 -07003481 "Cannot free buffer %" PRIxLEAST64 " that has not been allocated.", reinterpret_cast<uint64_t>(buffer));
3482 } else {
3483 if (buffer_data->second.in_use.load()) {
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07003484 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, reinterpret_cast<uint64_t>(buffer), __LINE__, DRAWSTATE_OBJECT_INUSE, "DS",
Michael Lentine700b0aa2015-10-30 17:57:32 -07003485 "Cannot free buffer %" PRIxLEAST64 " that is in use by a command buffer.", reinterpret_cast<uint64_t>(buffer));
Michael Lentine700b0aa2015-10-30 17:57:32 -07003486 }
3487 }
3488 return skip_call;
3489}
3490
Chia-I Wu9ab61502015-11-06 06:42:02 +08003491VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003492{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003493 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07003494 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003495 if (!validateIdleBuffer(dev_data, buffer)) {
3496 dev_data->device_dispatch_table->DestroyBuffer(device, buffer, pAllocator);
3497 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08003498 dev_data->bufferMap.erase(buffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003499}
3500
Chia-I Wu9ab61502015-11-06 06:42:02 +08003501VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBufferView(VkDevice device, VkBufferView bufferView, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003502{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003503 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003504 dev_data->device_dispatch_table->DestroyBufferView(device, bufferView, pAllocator);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003505 dev_data->bufferViewMap.erase(bufferView);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003506}
3507
Chia-I Wu9ab61502015-11-06 06:42:02 +08003508VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003509{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003510 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003511 dev_data->device_dispatch_table->DestroyImage(device, image, pAllocator);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003512 dev_data->imageMap.erase(image);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003513}
3514
Chia-I Wu9ab61502015-11-06 06:42:02 +08003515VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyImageView(VkDevice device, VkImageView imageView, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003516{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003517 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 -06003518 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003519}
3520
Chia-I Wu9ab61502015-11-06 06:42:02 +08003521VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003522{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003523 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 -06003524 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003525}
3526
Chia-I Wu9ab61502015-11-06 06:42:02 +08003527VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyPipeline(VkDevice device, VkPipeline pipeline, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003528{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003529 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 -06003530 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003531}
3532
Chia-I Wu9ab61502015-11-06 06:42:02 +08003533VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003534{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003535 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 -06003536 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003537}
3538
Chia-I Wu9ab61502015-11-06 06:42:02 +08003539VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySampler(VkDevice device, VkSampler sampler, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003540{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003541 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 -06003542 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003543}
3544
Chia-I Wu9ab61502015-11-06 06:42:02 +08003545VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003546{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003547 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 -06003548 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003549}
3550
Chia-I Wu9ab61502015-11-06 06:42:02 +08003551VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003552{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003553 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 -06003554 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003555}
3556
Chia-I Wu9ab61502015-11-06 06:42:02 +08003557VK_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 -06003558{
Mark Lobodzinski39298632015-11-18 08:38:27 -07003559 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3560
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07003561 for (uint32_t i = 0; i < count; i++) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003562 // Delete CB information structure, and remove from commandBufferMap
3563 auto cb = dev_data->commandBufferMap.find(pCommandBuffers[i]);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003564 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003565 if (cb != dev_data->commandBufferMap.end()) {
3566 delete (*cb).second;
3567 dev_data->commandBufferMap.erase(cb);
3568 }
3569
3570 // Remove commandBuffer reference from commandPoolMap
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003571 dev_data->commandPoolMap[commandPool].commandBuffers.remove(pCommandBuffers[i]);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003572 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003573 }
3574
3575 dev_data->device_dispatch_table->FreeCommandBuffers(device, commandPool, count, pCommandBuffers);
3576}
3577
3578VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkCommandPool* pCommandPool)
3579{
3580 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3581
3582 VkResult result = dev_data->device_dispatch_table->CreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
3583
3584 if (VK_SUCCESS == result) {
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003585 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003586 dev_data->commandPoolMap[*pCommandPool].createFlags = pCreateInfo->flags;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003587 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003588 }
3589 return result;
3590}
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07003591// Destroy commandPool along with all of the commandBuffers allocated from that pool
Mark Lobodzinski39298632015-11-18 08:38:27 -07003592VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks* pAllocator)
3593{
3594 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003595 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003596
3597 // Must remove cmdpool from cmdpoolmap, after removing all cmdbuffers in its list from the commandPoolMap
3598 if (dev_data->commandPoolMap.find(commandPool) != dev_data->commandPoolMap.end()) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003599 for (auto poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.begin(); poolCb != dev_data->commandPoolMap[commandPool].commandBuffers.end();) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003600 auto del_cb = dev_data->commandBufferMap.find(*poolCb);
3601 delete (*del_cb).second; // delete CB info structure
3602 dev_data->commandBufferMap.erase(del_cb); // Remove this command buffer from cbMap
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003603 poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.erase(poolCb); // Remove CB reference from commandPoolMap's list
Mark Lobodzinski39298632015-11-18 08:38:27 -07003604 }
3605 }
3606 dev_data->commandPoolMap.erase(commandPool);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003607
3608 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003609 dev_data->device_dispatch_table->DestroyCommandPool(device, commandPool, pAllocator);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003610}
3611
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003612VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandPool(
3613 VkDevice device,
3614 VkCommandPool commandPool,
3615 VkCommandPoolResetFlags flags)
3616{
3617 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003618 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003619
3620 result = dev_data->device_dispatch_table->ResetCommandPool(device, commandPool, flags);
3621 // Reset all of the CBs allocated from this pool
3622 if (VK_SUCCESS == result) {
3623 auto it = dev_data->commandPoolMap[commandPool].commandBuffers.begin();
3624 while (it != dev_data->commandPoolMap[commandPool].commandBuffers.end()) {
3625 resetCB(dev_data, (*it));
3626 ++it;
3627 }
3628 }
3629 return result;
3630}
3631
Chia-I Wu9ab61502015-11-06 06:42:02 +08003632VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003633{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003634 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 -06003635 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003636}
3637
Chia-I Wu9ab61502015-11-06 06:42:02 +08003638VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003639{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003640 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 -06003641 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003642}
3643
Chia-I Wu9ab61502015-11-06 06:42:02 +08003644VK_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 -06003645{
3646 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003647 VkResult result = dev_data->device_dispatch_table->CreateBuffer(device, pCreateInfo, pAllocator, pBuffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003648 if (VK_SUCCESS == result) {
3649 loader_platform_thread_lock_mutex(&globalLock);
3650 // 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 -07003651 dev_data->bufferMap[*pBuffer].create_info = unique_ptr<VkBufferCreateInfo>(new VkBufferCreateInfo(*pCreateInfo));
3652 dev_data->bufferMap[*pBuffer].in_use.store(0);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003653 loader_platform_thread_unlock_mutex(&globalLock);
3654 }
3655 return result;
3656}
3657
Chia-I Wu9ab61502015-11-06 06:42:02 +08003658VK_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 -06003659{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003660 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003661 VkResult result = dev_data->device_dispatch_table->CreateBufferView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003662 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003663 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003664 dev_data->bufferViewMap[*pView] = unique_ptr<VkBufferViewCreateInfo>(new VkBufferViewCreateInfo(*pCreateInfo));
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003665 loader_platform_thread_unlock_mutex(&globalLock);
3666 }
3667 return result;
3668}
3669
Chia-I Wu9ab61502015-11-06 06:42:02 +08003670VK_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 -06003671{
3672 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003673 VkResult result = dev_data->device_dispatch_table->CreateImage(device, pCreateInfo, pAllocator, pImage);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003674 if (VK_SUCCESS == result) {
Michael Lentineabc5e922015-10-12 11:30:14 -05003675 IMAGE_NODE* image_node = new IMAGE_NODE;
3676 image_node->layout = pCreateInfo->initialLayout;
Tobin Ehlis75cd1c52016-01-21 10:21:04 -07003677 image_node->format = pCreateInfo->format;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003678 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003679 dev_data->imageMap[*pImage] = unique_ptr<VkImageCreateInfo>(new VkImageCreateInfo(*pCreateInfo));
Michael Lentineabc5e922015-10-12 11:30:14 -05003680 dev_data->imageLayoutMap[*pImage] = image_node;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003681 loader_platform_thread_unlock_mutex(&globalLock);
3682 }
3683 return result;
3684}
3685
Chia-I Wu9ab61502015-11-06 06:42:02 +08003686VK_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 -06003687{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003688 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003689 VkResult result = dev_data->device_dispatch_table->CreateImageView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003690 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003691 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003692 dev_data->imageViewMap[*pView] = unique_ptr<VkImageViewCreateInfo>(new VkImageViewCreateInfo(*pCreateInfo));
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003693 loader_platform_thread_unlock_mutex(&globalLock);
3694 }
3695 return result;
3696}
3697
Jon Ashburnc669cc62015-07-09 15:02:25 -06003698//TODO handle pipeline caches
Chia-I Wu9ab61502015-11-06 06:42:02 +08003699VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineCache(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003700 VkDevice device,
3701 const VkPipelineCacheCreateInfo* pCreateInfo,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003702 const VkAllocationCallbacks* pAllocator,
Jon Ashburnc669cc62015-07-09 15:02:25 -06003703 VkPipelineCache* pPipelineCache)
3704{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003705 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003706 VkResult result = dev_data->device_dispatch_table->CreatePipelineCache(device, pCreateInfo, pAllocator, pPipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003707 return result;
3708}
3709
Chia-I Wu9ab61502015-11-06 06:42:02 +08003710VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineCache(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003711 VkDevice device,
Chia-I Wuf7458c52015-10-26 21:10:41 +08003712 VkPipelineCache pipelineCache,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003713 const VkAllocationCallbacks* pAllocator)
Jon Ashburnc669cc62015-07-09 15:02:25 -06003714{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003715 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003716 dev_data->device_dispatch_table->DestroyPipelineCache(device, pipelineCache, pAllocator);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003717}
3718
Chia-I Wu9ab61502015-11-06 06:42:02 +08003719VKAPI_ATTR VkResult VKAPI_CALL vkGetPipelineCacheData(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003720 VkDevice device,
3721 VkPipelineCache pipelineCache,
Chia-I Wub16facd2015-10-26 19:17:06 +08003722 size_t* pDataSize,
Jon Ashburnc669cc62015-07-09 15:02:25 -06003723 void* pData)
3724{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003725 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wub16facd2015-10-26 19:17:06 +08003726 VkResult result = dev_data->device_dispatch_table->GetPipelineCacheData(device, pipelineCache, pDataSize, pData);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003727 return result;
3728}
3729
Chia-I Wu9ab61502015-11-06 06:42:02 +08003730VKAPI_ATTR VkResult VKAPI_CALL vkMergePipelineCaches(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003731 VkDevice device,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003732 VkPipelineCache dstCache,
Jon Ashburnc669cc62015-07-09 15:02:25 -06003733 uint32_t srcCacheCount,
3734 const VkPipelineCache* pSrcCaches)
3735{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003736 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003737 VkResult result = dev_data->device_dispatch_table->MergePipelineCaches(device, dstCache, srcCacheCount, pSrcCaches);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003738 return result;
3739}
3740
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003741VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateGraphicsPipelines(
3742 VkDevice device,
3743 VkPipelineCache pipelineCache,
3744 uint32_t count,
3745 const VkGraphicsPipelineCreateInfo *pCreateInfos,
3746 const VkAllocationCallbacks *pAllocator,
3747 VkPipeline *pPipelines)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003748{
Courtney Goeltzenleuchtered894072015-09-04 13:39:59 -06003749 VkResult result = VK_SUCCESS;
Tobin Ehlis11efc302015-09-16 10:33:53 -06003750 //TODO What to do with pipelineCache?
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003751 // The order of operations here is a little convoluted but gets the job done
3752 // 1. Pipeline create state is first shadowed into PIPELINE_NODE struct
3753 // 2. Create state is then validated (which uses flags setup during shadowing)
3754 // 3. If everything looks good, we'll then create the pipeline and add NODE to pipelineMap
Tobin Ehlis11efc302015-09-16 10:33:53 -06003755 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis65399772015-09-17 16:33:58 -06003756 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
3757 vector<PIPELINE_NODE*> pPipeNode(count);
Tobin Ehlis0b632332015-10-07 09:38:40 -06003758 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003759
Tobin Ehlis11efc302015-09-16 10:33:53 -06003760 uint32_t i=0;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003761 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003762
Tobin Ehlis11efc302015-09-16 10:33:53 -06003763 for (i=0; i<count; i++) {
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003764 pPipeNode[i] = initGraphicsPipeline(dev_data, &pCreateInfos[i], NULL);
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06003765 skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
Tobin Ehlis11efc302015-09-16 10:33:53 -06003766 }
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003767
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003768 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003769
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07003770 if (VK_FALSE == skipCall) {
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003771 result = dev_data->device_dispatch_table->CreateGraphicsPipelines(device,
3772 pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003773 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis11efc302015-09-16 10:33:53 -06003774 for (i=0; i<count; i++) {
3775 pPipeNode[i]->pipeline = pPipelines[i];
Chia-I Wue2fc5522015-10-26 20:04:44 +08003776 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
Tobin Ehlis11efc302015-09-16 10:33:53 -06003777 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003778 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisce132d82015-06-19 15:07:05 -06003779 } else {
Tobin Ehlis11efc302015-09-16 10:33:53 -06003780 for (i=0; i<count; i++) {
3781 if (pPipeNode[i]) {
3782 // If we allocated a pipeNode, need to clean it up here
3783 delete[] pPipeNode[i]->pVertexBindingDescriptions;
3784 delete[] pPipeNode[i]->pVertexAttributeDescriptions;
3785 delete[] pPipeNode[i]->pAttachments;
3786 delete pPipeNode[i];
3787 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003788 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003789 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003790 }
Courtney Goeltzenleuchtere2aaad02015-04-13 16:16:04 -06003791 return result;
3792}
3793
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003794VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateComputePipelines(
3795 VkDevice device,
3796 VkPipelineCache pipelineCache,
3797 uint32_t count,
3798 const VkComputePipelineCreateInfo *pCreateInfos,
3799 const VkAllocationCallbacks *pAllocator,
3800 VkPipeline *pPipelines)
3801{
3802 VkResult result = VK_SUCCESS;
3803 VkBool32 skipCall = VK_FALSE;
3804
3805 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
3806 vector<PIPELINE_NODE*> pPipeNode(count);
3807 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3808
3809 uint32_t i=0;
3810 loader_platform_thread_lock_mutex(&globalLock);
3811 for (i=0; i<count; i++) {
3812 // TODO: Verify compute stage bits
3813
3814 // Create and initialize internal tracking data structure
3815 pPipeNode[i] = new PIPELINE_NODE;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003816 memcpy(&pPipeNode[i]->computePipelineCI, (const void*)&pCreateInfos[i], sizeof(VkComputePipelineCreateInfo));
3817
3818 // TODO: Add Compute Pipeline Verification
3819 // skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
3820 }
3821 loader_platform_thread_unlock_mutex(&globalLock);
3822
3823 if (VK_FALSE == skipCall) {
3824 result = dev_data->device_dispatch_table->CreateComputePipelines(device, pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
3825 loader_platform_thread_lock_mutex(&globalLock);
3826 for (i=0; i<count; i++) {
3827 pPipeNode[i]->pipeline = pPipelines[i];
3828 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
3829 }
3830 loader_platform_thread_unlock_mutex(&globalLock);
3831 } else {
3832 for (i=0; i<count; i++) {
3833 if (pPipeNode[i]) {
3834 // Clean up any locally allocated data structures
3835 delete pPipeNode[i];
3836 }
3837 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003838 return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003839 }
3840 return result;
3841}
3842
Chia-I Wu9ab61502015-11-06 06:42:02 +08003843VK_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 -06003844{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003845 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003846 VkResult result = dev_data->device_dispatch_table->CreateSampler(device, pCreateInfo, pAllocator, pSampler);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003847 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003848 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003849 dev_data->sampleMap[*pSampler] = unique_ptr<SAMPLER_NODE>(new SAMPLER_NODE(pSampler, pCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003850 loader_platform_thread_unlock_mutex(&globalLock);
3851 }
3852 return result;
3853}
3854
Chia-I Wu9ab61502015-11-06 06:42:02 +08003855VK_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 -06003856{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003857 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003858 VkResult result = dev_data->device_dispatch_table->CreateDescriptorSetLayout(device, pCreateInfo, pAllocator, pSetLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003859 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003860 // TODOSC : Capture layout bindings set
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003861 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
3862 if (NULL == pNewNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003863 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 -06003864 "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003865 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003866 }
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06003867 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003868 pNewNode->createInfo.pBindings = new VkDescriptorSetLayoutBinding[pCreateInfo->bindingCount];
3869 memcpy((void*)pNewNode->createInfo.pBindings, pCreateInfo->pBindings, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->bindingCount);
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003870 // g++ does not like reserve with size 0
3871 if (pCreateInfo->bindingCount)
3872 pNewNode->bindings.reserve(pCreateInfo->bindingCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003873 uint32_t totalCount = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003874 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003875 if (!pNewNode->bindings.insert(pCreateInfo->pBindings[i].binding).second) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003876 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 +08003877 "duplicated binding number in VkDescriptorSetLayoutBinding"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003878 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003879 }
3880
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003881 totalCount += pCreateInfo->pBindings[i].descriptorCount;
3882 if (pCreateInfo->pBindings[i].pImmutableSamplers) {
3883 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBindings[i].pImmutableSamplers;
3884 *ppIS = new VkSampler[pCreateInfo->pBindings[i].descriptorCount];
3885 memcpy(*ppIS, pCreateInfo->pBindings[i].pImmutableSamplers, pCreateInfo->pBindings[i].descriptorCount*sizeof(VkSampler));
Tobin Ehlis793ad302015-04-03 12:01:11 -06003886 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003887 }
Tobin Ehlis43c39c02016-01-11 13:18:40 -07003888 pNewNode->layout = *pSetLayout;
3889 pNewNode->startIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003890 if (totalCount > 0) {
Cody Northrop43751cc2015-10-26 14:07:35 -06003891 pNewNode->descriptorTypes.resize(totalCount);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06003892 pNewNode->stageFlags.resize(totalCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003893 uint32_t offset = 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06003894 uint32_t j = 0;
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07003895 VkDescriptorType dType;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003896 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003897 dType = pCreateInfo->pBindings[i].descriptorType;
3898 for (j = 0; j < pCreateInfo->pBindings[i].descriptorCount; j++) {
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07003899 pNewNode->descriptorTypes[offset + j] = dType;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003900 pNewNode->stageFlags[offset + j] = pCreateInfo->pBindings[i].stageFlags;
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07003901 if ((dType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
3902 (dType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
3903 pNewNode->dynamicDescriptorCount++;
3904 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003905 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06003906 offset += j;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003907 }
Tobin Ehlis43c39c02016-01-11 13:18:40 -07003908 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
3909 } else { // no descriptors
3910 pNewNode->endIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003911 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003912 // Put new node at Head of global Layer list
3913 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07003914 dev_data->descriptorSetLayoutMap[*pSetLayout] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003915 loader_platform_thread_unlock_mutex(&globalLock);
3916 }
3917 return result;
3918}
3919
Chia-I Wu9ab61502015-11-06 06:42:02 +08003920VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003921{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003922 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003923 VkResult result = dev_data->device_dispatch_table->CreatePipelineLayout(device, pCreateInfo, pAllocator, pPipelineLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003924 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003925 // TODOSC : Merge capture of the setLayouts per pipeline
Tobin Ehlis559c6382015-11-05 09:52:49 -07003926 PIPELINE_LAYOUT_NODE& plNode = dev_data->pipelineLayoutMap[*pPipelineLayout];
Chia-I Wud50a7d72015-10-26 20:48:51 +08003927 plNode.descriptorSetLayouts.resize(pCreateInfo->setLayoutCount);
Tobin Ehlis644ff042015-10-20 10:11:55 -06003928 uint32_t i = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003929 for (i=0; i<pCreateInfo->setLayoutCount; ++i) {
Tobin Ehlis644ff042015-10-20 10:11:55 -06003930 plNode.descriptorSetLayouts[i] = pCreateInfo->pSetLayouts[i];
3931 }
Cody Northrop43751cc2015-10-26 14:07:35 -06003932 plNode.pushConstantRanges.resize(pCreateInfo->pushConstantRangeCount);
Tobin Ehlis644ff042015-10-20 10:11:55 -06003933 for (i=0; i<pCreateInfo->pushConstantRangeCount; ++i) {
3934 plNode.pushConstantRanges[i] = pCreateInfo->pPushConstantRanges[i];
3935 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06003936 }
3937 return result;
3938}
3939
Chia-I Wu9ab61502015-11-06 06:42:02 +08003940VK_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 -06003941{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003942 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003943 VkResult result = dev_data->device_dispatch_table->CreateDescriptorPool(device, pCreateInfo, pAllocator, pDescriptorPool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003944 if (VK_SUCCESS == result) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06003945 // Insert this pool into Global Pool LL at head
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003946 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 +08003947 "Created Descriptor Pool %#" PRIxLEAST64, (uint64_t) *pDescriptorPool))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003948 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003949 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003950 DESCRIPTOR_POOL_NODE* pNewNode = new DESCRIPTOR_POOL_NODE(*pDescriptorPool, pCreateInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003951 if (NULL == pNewNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003952 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 -07003953 "Out of memory while attempting to allocate DESCRIPTOR_POOL_NODE in vkCreateDescriptorPool()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003954 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisce132d82015-06-19 15:07:05 -06003955 } else {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003956 dev_data->descriptorPoolMap[*pDescriptorPool] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003957 }
3958 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisce132d82015-06-19 15:07:05 -06003959 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06003960 // Need to do anything if pool create fails?
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003961 }
3962 return result;
3963}
3964
Chia-I Wu9ab61502015-11-06 06:42:02 +08003965VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorPoolResetFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003966{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003967 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003968 VkResult result = dev_data->device_dispatch_table->ResetDescriptorPool(device, descriptorPool, flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003969 if (VK_SUCCESS == result) {
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003970 clearDescriptorPool(dev_data, device, descriptorPool, flags);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003971 }
3972 return result;
3973}
3974
Chia-I Wu9ab61502015-11-06 06:42:02 +08003975VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo* pAllocateInfo, VkDescriptorSet* pDescriptorSets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003976{
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003977 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis0b632332015-10-07 09:38:40 -06003978 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003979 // Verify that requested descriptorSets are available in pool
Mark Lobodzinski39298632015-11-18 08:38:27 -07003980 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003981 if (!pPoolNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003982 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 +08003983 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003984 } else { // Make sure pool has all the available descriptors before calling down chain
Jon Ashburnf19916e2016-01-11 13:12:43 -07003985 skipCall |= validate_descriptor_availability_in_pool(dev_data, pPoolNode, pAllocateInfo->descriptorSetCount, pAllocateInfo->pSetLayouts);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003986 }
3987 if (skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003988 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003989 VkResult result = dev_data->device_dispatch_table->AllocateDescriptorSets(device, pAllocateInfo, pDescriptorSets);
Cody Northrop1e4f8022015-08-03 12:47:29 -06003990 if (VK_SUCCESS == result) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003991 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003992 if (pPoolNode) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07003993 if (pAllocateInfo->descriptorSetCount == 0) {
3994 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 +08003995 "AllocateDescriptorSets called with 0 count");
Cody Northrop1e4f8022015-08-03 12:47:29 -06003996 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07003997 for (uint32_t i = 0; i < pAllocateInfo->descriptorSetCount; i++) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003998 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 +08003999 "Created Descriptor Set %#" PRIxLEAST64, (uint64_t) pDescriptorSets[i]);
Tobin Ehlis793ad302015-04-03 12:01:11 -06004000 // Create new set node and add to head of pool nodes
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004001 SET_NODE* pNewNode = new SET_NODE;
4002 if (NULL == pNewNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004003 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 +08004004 "Out of memory while attempting to allocate SET_NODE in vkAllocateDescriptorSets()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004005 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisce132d82015-06-19 15:07:05 -06004006 } else {
Tobin Ehlis8b5b28c2015-10-19 12:09:13 -06004007 // TODO : Pool should store a total count of each type of Descriptor available
4008 // When descriptors are allocated, decrement the count and validate here
4009 // that the count doesn't go below 0. One reset/free need to bump count back up.
Tobin Ehlis793ad302015-04-03 12:01:11 -06004010 // Insert set at head of Set LL for this pool
4011 pNewNode->pNext = pPoolNode->pSets;
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07004012 pNewNode->in_use.store(0);
Tobin Ehlis793ad302015-04-03 12:01:11 -06004013 pPoolNode->pSets = pNewNode;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004014 LAYOUT_NODE* pLayout = getLayoutNode(dev_data, pAllocateInfo->pSetLayouts[i]);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004015 if (NULL == pLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004016 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 +08004017 "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 -07004018 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004019 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06004020 pNewNode->pLayout = pLayout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004021 pNewNode->pool = pAllocateInfo->descriptorPool;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004022 pNewNode->set = pDescriptorSets[i];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004023 pNewNode->descriptorCount = pLayout->endIndex + 1;
4024 if (pNewNode->descriptorCount) {
4025 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
4026 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
4027 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
4028 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08004029 dev_data->setMap[pDescriptorSets[i]] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004030 }
4031 }
4032 }
4033 }
4034 return result;
4035}
4036
Chia-I Wu9ab61502015-11-06 06:42:02 +08004037VK_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 -06004038{
Tobin Ehlise735c692015-10-08 13:13:50 -06004039 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis0b632332015-10-07 09:38:40 -06004040 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07004041 // Make sure that no sets being destroyed are in-flight
4042 for (uint32_t i=0; i<count; ++i)
4043 skipCall |= validateIdleDescriptorSet(dev_data, pDescriptorSets[i], "vkFreeDesriptorSets");
Mark Lobodzinski39298632015-11-18 08:38:27 -07004044 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, descriptorPool);
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004045 if (pPoolNode && !(VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT & pPoolNode->createInfo.flags)) {
4046 // Can't Free from a NON_FREE pool
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004047 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 -06004048 "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 -06004049 }
Mark Youngb20a6a82016-01-07 15:41:43 -07004050 if (VK_FALSE != skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004051 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis0b632332015-10-07 09:38:40 -06004052 VkResult result = dev_data->device_dispatch_table->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004053 if (VK_SUCCESS == result) {
4054 // For each freed descriptor add it back into the pool as available
4055 for (uint32_t i=0; i<count; ++i) {
Chia-I Wue2fc5522015-10-26 20:04:44 +08004056 SET_NODE* pSet = dev_data->setMap[pDescriptorSets[i]]; // getSetNode() without locking
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004057 LAYOUT_NODE* pLayout = pSet->pLayout;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004058 uint32_t typeIndex = 0, poolSizeCount = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004059 for (uint32_t j=0; j<pLayout->createInfo.bindingCount; ++j) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07004060 typeIndex = static_cast<uint32_t>(pLayout->createInfo.pBindings[j].descriptorType);
4061 poolSizeCount = pLayout->createInfo.pBindings[j].descriptorCount;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004062 pPoolNode->availableDescriptorTypeCount[typeIndex] += poolSizeCount;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004063 }
4064 }
4065 }
4066 // TODO : Any other clean-up or book-keeping to do here?
Tony Barbour34ec6922015-07-10 10:50:45 -06004067 return result;
4068}
4069
Chia-I Wu9ab61502015-11-06 06:42:02 +08004070VK_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 -06004071{
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06004072 // 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 -06004073 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08004074 if (!dsUpdate(dev_data, device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies)) {
4075 dev_data->device_dispatch_table->UpdateDescriptorSets(device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies);
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004076 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004077}
4078
Chia-I Wu9ab61502015-11-06 06:42:02 +08004079VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo* pCreateInfo, VkCommandBuffer* pCommandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004080{
Tobin Ehlis0b632332015-10-07 09:38:40 -06004081 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004082 VkResult result = dev_data->device_dispatch_table->AllocateCommandBuffers(device, pCreateInfo, pCommandBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004083 if (VK_SUCCESS == result) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004084 for (uint32_t i = 0; i < pCreateInfo->commandBufferCount; i++) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07004085 // Validate command pool
4086 if (dev_data->commandPoolMap.find(pCreateInfo->commandPool) != dev_data->commandPoolMap.end()) {
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07004087 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07004088 // Add command buffer to its commandPool map
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004089 dev_data->commandPoolMap[pCreateInfo->commandPool].commandBuffers.push_back(pCommandBuffer[i]);
Mark Lobodzinski39298632015-11-18 08:38:27 -07004090 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
4091 // Add command buffer to map
4092 dev_data->commandBufferMap[pCommandBuffer[i]] = pCB;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07004093 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07004094 resetCB(dev_data, pCommandBuffer[i]);
4095 pCB->commandBuffer = pCommandBuffer[i];
4096 pCB->createInfo = *pCreateInfo;
Mark Lobodzinski941aea92016-01-13 10:23:15 -07004097 pCB->device = device;
Mark Lobodzinski39298632015-11-18 08:38:27 -07004098 }
4099 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004100 }
4101 return result;
4102}
4103
Chia-I Wu9ab61502015-11-06 06:42:02 +08004104VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo* pBeginInfo)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004105{
Mark Youngb20a6a82016-01-07 15:41:43 -07004106 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004107 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004108 // Validate command buffer level
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004109 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004110 if (pCB) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004111 if (pCB->createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
4112 // Secondary Command Buffer
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004113 // TODO : Add check here from spec "If commandBuffer is a secondary command buffer and either the
4114 // occlusionQueryEnable member of pBeginInfo is VK_FALSE, or the precise occlusion queries feature
4115 // is not enabled, the queryFlags member of pBeginInfo must not contain VK_QUERY_CONTROL_PRECISE_BIT"
Jon Ashburnf19916e2016-01-11 13:12:43 -07004116 const VkCommandBufferInheritanceInfo *pInfo = pBeginInfo->pInheritanceInfo;
Tobin Ehlis651d9b02015-12-16 05:01:22 -07004117 if (pBeginInfo->flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004118 if (!pInfo->renderPass) { // renderpass should NOT be null for an Secondary CB
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004119 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 -07004120 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) must specify a valid renderpass parameter.", (void*)commandBuffer);
4121 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07004122 if (!pInfo->framebuffer) { // framebuffer may be null for an Secondary CB, but this affects perf
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004123 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 -07004124 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) may perform better if a valid framebuffer parameter is specified.", (void*)commandBuffer);
4125 } else {
4126 string errorString = "";
Jon Ashburnf19916e2016-01-11 13:12:43 -07004127 VkRenderPass fbRP = dev_data->frameBufferMap[pInfo->framebuffer]->renderPass;
4128 if (!verify_renderpass_compatibility(dev_data, fbRP, pInfo->renderPass, errorString)) {
Tobin Ehlis651d9b02015-12-16 05:01:22 -07004129 // renderPass that framebuffer was created with must be compatible with local renderPass
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004130 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 -07004131 "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 -07004132 (void*)commandBuffer, (uint64_t)pInfo->renderPass, (uint64_t)pInfo->framebuffer, (uint64_t)fbRP, errorString.c_str());
Tobin Ehlis651d9b02015-12-16 05:01:22 -07004133 }
4134 }
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004135 }
4136 }
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004137 if (CB_RECORDING == pCB->state) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004138 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 -07004139 "vkBeginCommandBuffer(): Cannot call Begin on CB (%#" PRIxLEAST64 ") in the RECORDING state. Must first call vkEndCommandBuffer().", (uint64_t)commandBuffer);
4140 } else if (CB_RECORDED == pCB->state) {
4141 VkCommandPool cmdPool = pCB->createInfo.commandPool;
4142 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004143 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 -07004144 __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004145 "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.",
4146 (uint64_t) commandBuffer, (uint64_t) cmdPool);
4147 }
Tobin Ehlisef694652016-01-19 12:03:34 -07004148 resetCB(dev_data, commandBuffer);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004149 }
Tobin Ehlisef694652016-01-19 12:03:34 -07004150 // Set updated state here in case implicit reset occurs above
4151 pCB->state = CB_RECORDING;
4152 pCB->beginInfo = *pBeginInfo;
Tobin Ehliscd5bfd82016-01-19 13:12:52 -07004153
4154 if (pCB->beginInfo.pInheritanceInfo) {
4155 pCB->inheritanceInfo = *(pCB->beginInfo.pInheritanceInfo);
4156 pCB->beginInfo.pInheritanceInfo = &pCB->inheritanceInfo;
4157 }
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004158 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004159 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 +08004160 "In vkBeginCommandBuffer() and unable to find CommandBuffer Node for CB %p!", (void*)commandBuffer);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004161 }
Mark Youngb20a6a82016-01-07 15:41:43 -07004162 if (VK_FALSE != skipCall) {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004163 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter5fe086f2015-09-04 15:03:52 -06004164 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004165 VkResult result = dev_data->device_dispatch_table->BeginCommandBuffer(commandBuffer, pBeginInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004166 return result;
4167}
4168
Chia-I Wu9ab61502015-11-06 06:42:02 +08004169VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEndCommandBuffer(VkCommandBuffer commandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004170{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004171 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchtered894072015-09-04 13:39:59 -06004172 VkResult result = VK_SUCCESS;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004173 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4174 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004175 if (pCB) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004176 if (pCB->state != CB_RECORDING) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004177 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkEndCommandBuffer()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004178 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004179 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004180 if (VK_FALSE == skipCall) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004181 result = dev_data->device_dispatch_table->EndCommandBuffer(commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004182 if (VK_SUCCESS == result) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004183 pCB->state = CB_RECORDED;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004184 // Reset CB status flags
4185 pCB->status = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004186 printCB(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004187 }
4188 } else {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004189 result = VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004190 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004191 return result;
4192}
4193
Chia-I Wu9ab61502015-11-06 06:42:02 +08004194VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004195{
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004196 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004197 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004198 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
4199 VkCommandPool cmdPool = pCB->createInfo.commandPool;
4200 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004201 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 -07004202 __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004203 "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.",
4204 (uint64_t) commandBuffer, (uint64_t) cmdPool);
4205 }
Mark Youngb20a6a82016-01-07 15:41:43 -07004206 if (skipCall != VK_FALSE)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004207 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004208 VkResult result = dev_data->device_dispatch_table->ResetCommandBuffer(commandBuffer, flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004209 if (VK_SUCCESS == result) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004210 resetCB(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004211 }
4212 return result;
4213}
4214
Chia-I Wu9ab61502015-11-06 06:42:02 +08004215VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004216{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004217 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004218 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4219 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004220 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004221 skipCall |= addCmd(dev_data, pCB, CMD_BINDPIPELINE, "vkCmdBindPipeline()");
4222 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
4223 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 -07004224 __LINE__, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004225 "Incorrectly binding compute pipeline (%#" PRIxLEAST64 ") during active RenderPass (%#" PRIxLEAST64 ")",
4226 (uint64_t) pipeline, (uint64_t) pCB->activeRenderPass);
4227 } else if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
4228 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdBindPipeline");
4229 }
4230
4231 PIPELINE_NODE* pPN = getPipeline(dev_data, pipeline);
4232 if (pPN) {
4233 pCB->lastBoundPipeline = pipeline;
4234 loader_platform_thread_lock_mutex(&globalLock);
4235 set_cb_pso_status(pCB, pPN);
4236 loader_platform_thread_unlock_mutex(&globalLock);
4237 skipCall |= validatePipelineState(dev_data, pCB, pipelineBindPoint, pipeline);
Tobin Ehlisce132d82015-06-19 15:07:05 -06004238 } else {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004239 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 -07004240 (uint64_t) pipeline, __LINE__, DRAWSTATE_INVALID_PIPELINE, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004241 "Attempt to bind Pipeline %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<uint64_t>(pipeline));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004242 }
4243 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004244 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004245 dev_data->device_dispatch_table->CmdBindPipeline(commandBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004246}
4247
Chia-I Wu9ab61502015-11-06 06:42:02 +08004248VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetViewport(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004249 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004250 uint32_t firstViewport,
4251 uint32_t viewportCount,
4252 const VkViewport* pViewports)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004253{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004254 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004255 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4256 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004257 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004258 skipCall |= addCmd(dev_data, pCB, CMD_SETVIEWPORTSTATE, "vkCmdSetViewport()");
4259 loader_platform_thread_lock_mutex(&globalLock);
4260 pCB->status |= CBSTATUS_VIEWPORT_SET;
4261 pCB->viewports.resize(viewportCount);
4262 memcpy(pCB->viewports.data(), pViewports, viewportCount * sizeof(VkViewport));
4263 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004264 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004265 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004266 dev_data->device_dispatch_table->CmdSetViewport(commandBuffer, firstViewport, viewportCount, pViewports);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004267}
4268
Chia-I Wu9ab61502015-11-06 06:42:02 +08004269VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetScissor(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004270 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004271 uint32_t firstScissor,
4272 uint32_t scissorCount,
4273 const VkRect2D* pScissors)
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004274{
4275 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004276 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4277 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004278 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004279 skipCall |= addCmd(dev_data, pCB, CMD_SETSCISSORSTATE, "vkCmdSetScissor()");
4280 loader_platform_thread_lock_mutex(&globalLock);
4281 pCB->status |= CBSTATUS_SCISSOR_SET;
4282 pCB->scissors.resize(scissorCount);
4283 memcpy(pCB->scissors.data(), pScissors, scissorCount * sizeof(VkRect2D));
4284 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004285 }
4286 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004287 dev_data->device_dispatch_table->CmdSetScissor(commandBuffer, firstScissor, scissorCount, pScissors);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004288}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004289
Chia-I Wu9ab61502015-11-06 06:42:02 +08004290VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004291{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004292 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004293 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4294 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004295 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004296 skipCall |= addCmd(dev_data, pCB, CMD_SETLINEWIDTHSTATE, "vkCmdSetLineWidth()");
4297 /* TODO: Do we still need this lock? */
4298 loader_platform_thread_lock_mutex(&globalLock);
4299 pCB->status |= CBSTATUS_LINE_WIDTH_SET;
4300 pCB->lineWidth = lineWidth;
4301 loader_platform_thread_unlock_mutex(&globalLock);
Cody Northrop12365112015-08-17 11:10:49 -06004302 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004303 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004304 dev_data->device_dispatch_table->CmdSetLineWidth(commandBuffer, lineWidth);
Cody Northrop12365112015-08-17 11:10:49 -06004305}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004306
Chia-I Wu9ab61502015-11-06 06:42:02 +08004307VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBias(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004308 VkCommandBuffer commandBuffer,
Chia-I Wud8c946a2015-10-26 19:08:09 +08004309 float depthBiasConstantFactor,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004310 float depthBiasClamp,
Chia-I Wud8c946a2015-10-26 19:08:09 +08004311 float depthBiasSlopeFactor)
Cody Northrop12365112015-08-17 11:10:49 -06004312{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004313 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004314 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4315 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northrop12365112015-08-17 11:10:49 -06004316 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004317 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBIASSTATE, "vkCmdSetDepthBias()");
4318 pCB->status |= CBSTATUS_DEPTH_BIAS_SET;
4319 pCB->depthBiasConstantFactor = depthBiasConstantFactor;
4320 pCB->depthBiasClamp = depthBiasClamp;
4321 pCB->depthBiasSlopeFactor = depthBiasSlopeFactor;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004322 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004323 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004324 dev_data->device_dispatch_table->CmdSetDepthBias(commandBuffer, depthBiasConstantFactor, depthBiasClamp, depthBiasSlopeFactor);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004325}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004326
Chia-I Wu9ab61502015-11-06 06:42:02 +08004327VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4])
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004328{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004329 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004330 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4331 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004332 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004333 skipCall |= addCmd(dev_data, pCB, CMD_SETBLENDSTATE, "vkCmdSetBlendConstants()");
4334 pCB->status |= CBSTATUS_BLEND_SET;
4335 memcpy(pCB->blendConstants, blendConstants, 4 * sizeof(float));
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004336 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004337 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004338 dev_data->device_dispatch_table->CmdSetBlendConstants(commandBuffer, blendConstants);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004339}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004340
Chia-I Wu9ab61502015-11-06 06:42:02 +08004341VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBounds(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004342 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004343 float minDepthBounds,
4344 float maxDepthBounds)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004345{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004346 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004347 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4348 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004349 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004350 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBOUNDSSTATE, "vkCmdSetDepthBounds()");
4351 pCB->status |= CBSTATUS_DEPTH_BOUNDS_SET;
4352 pCB->minDepthBounds = minDepthBounds;
4353 pCB->maxDepthBounds = maxDepthBounds;
Cody Northrop82485a82015-08-18 15:21:16 -06004354 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004355 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004356 dev_data->device_dispatch_table->CmdSetDepthBounds(commandBuffer, minDepthBounds, maxDepthBounds);
Cody Northrop82485a82015-08-18 15:21:16 -06004357}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004358
Chia-I Wu9ab61502015-11-06 06:42:02 +08004359VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilCompareMask(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004360 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004361 VkStencilFaceFlags faceMask,
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004362 uint32_t compareMask)
Cody Northrop82485a82015-08-18 15:21:16 -06004363{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004364 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004365 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4366 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northrop82485a82015-08-18 15:21:16 -06004367 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004368 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREADMASKSTATE, "vkCmdSetStencilCompareMask()");
4369 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4370 pCB->front.compareMask = compareMask;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004371 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004372 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4373 pCB->back.compareMask = compareMask;
4374 }
4375 /* TODO: Do we need to track front and back separately? */
4376 /* TODO: We aren't capturing the faceMask, do we need to? */
4377 pCB->status |= CBSTATUS_STENCIL_READ_MASK_SET;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004378 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004379 if (VK_FALSE == skipCall)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004380 dev_data->device_dispatch_table->CmdSetStencilCompareMask(commandBuffer, faceMask, compareMask);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004381}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004382
Chia-I Wu9ab61502015-11-06 06:42:02 +08004383VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilWriteMask(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004384 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004385 VkStencilFaceFlags faceMask,
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004386 uint32_t writeMask)
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004387{
4388 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004389 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4390 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004391 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004392 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILWRITEMASKSTATE, "vkCmdSetStencilWriteMask()");
4393 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4394 pCB->front.writeMask = writeMask;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004395 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004396 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4397 pCB->back.writeMask = writeMask;
4398 }
4399 pCB->status |= CBSTATUS_STENCIL_WRITE_MASK_SET;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004400 }
4401 if (VK_FALSE == skipCall)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004402 dev_data->device_dispatch_table->CmdSetStencilWriteMask(commandBuffer, faceMask, writeMask);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004403}
4404
Chia-I Wu9ab61502015-11-06 06:42:02 +08004405VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilReference(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004406 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004407 VkStencilFaceFlags faceMask,
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004408 uint32_t reference)
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004409{
4410 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004411 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4412 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004413 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004414 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREFERENCESTATE, "vkCmdSetStencilReference()");
4415 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4416 pCB->front.reference = reference;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004417 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004418 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4419 pCB->back.reference = reference;
4420 }
4421 pCB->status |= CBSTATUS_STENCIL_REFERENCE_SET;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004422 }
4423 if (VK_FALSE == skipCall)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004424 dev_data->device_dispatch_table->CmdSetStencilReference(commandBuffer, faceMask, reference);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004425}
4426
Chia-I Wu9ab61502015-11-06 06:42:02 +08004427VK_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 -06004428{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004429 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004430 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4431 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004432 if (pCB) {
Tobin Ehlisf6585052015-12-17 11:48:42 -07004433 if (pCB->state == CB_RECORDING) {
4434 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004435 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 -07004436 "Incorrectly binding compute DescriptorSets during active RenderPass (%#" PRIxLEAST64 ")", (uint64_t) pCB->activeRenderPass);
4437 } else if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
4438 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdBindDescriptorSets");
Mark Lobodzinski74635932015-12-18 15:35:38 -07004439 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07004440 if (VK_FALSE == skipCall) {
4441 // Track total count of dynamic descriptor types to make sure we have an offset for each one
4442 uint32_t totalDynamicDescriptors = 0;
4443 string errorString = "";
4444 uint32_t lastSetIndex = firstSet+setCount-1;
4445 if (lastSetIndex >= pCB->boundDescriptorSets.size())
Tobin Ehlis559c6382015-11-05 09:52:49 -07004446 pCB->boundDescriptorSets.resize(lastSetIndex+1);
Tobin Ehlisf6585052015-12-17 11:48:42 -07004447 VkDescriptorSet oldFinalBoundSet = pCB->boundDescriptorSets[lastSetIndex];
4448 for (uint32_t i=0; i<setCount; i++) {
4449 SET_NODE* pSet = getSetNode(dev_data, pDescriptorSets[i]);
4450 if (pSet) {
4451 loader_platform_thread_lock_mutex(&globalLock);
4452 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
4453 pCB->lastBoundPipelineLayout = layout;
4454 pCB->boundDescriptorSets[i+firstSet] = pDescriptorSets[i];
4455 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004456 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 -07004457 "DS %#" PRIxLEAST64 " bound on pipeline %s", (uint64_t) pDescriptorSets[i], string_VkPipelineBindPoint(pipelineBindPoint));
Tobin Ehlis43c39c02016-01-11 13:18:40 -07004458 if (!pSet->pUpdateStructs && (pSet->descriptorCount != 0)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004459 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 -07004460 "DS %#" PRIxLEAST64 " bound but it was never updated. You may want to either update it or not bind it.", (uint64_t) pDescriptorSets[i]);
4461 }
4462 // Verify that set being bound is compatible with overlapping setLayout of pipelineLayout
4463 if (!verify_set_layout_compatibility(dev_data, pSet, layout, i+firstSet, errorString)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004464 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 -07004465 "descriptorSet #%u being bound is not compatible with overlapping layout in pipelineLayout due to: %s", i, errorString.c_str());
4466 }
4467 if (pSet->pLayout->dynamicDescriptorCount) {
4468 // First make sure we won't overstep bounds of pDynamicOffsets array
4469 if ((totalDynamicDescriptors + pSet->pLayout->dynamicDescriptorCount) > dynamicOffsetCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004470 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 -07004471 "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.",
4472 i, (uint64_t) pDescriptorSets[i], pSet->pLayout->dynamicDescriptorCount, (dynamicOffsetCount - totalDynamicDescriptors));
Mark Lobodzinski941aea92016-01-13 10:23:15 -07004473 } else { // Validate and store dynamic offsets with the set
4474 // Validate Dynamic Offset Minimums
4475 uint32_t cur_dyn_offset = totalDynamicDescriptors;
4476 for (uint32_t d = 0; d < pSet->descriptorCount; d++) {
4477 if (pSet->pLayout->descriptorTypes[i] == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) {
4478 if (vk_safe_modulo(pDynamicOffsets[cur_dyn_offset], dev_data->physDevPropertyMap[pCB->device].limits.minUniformBufferOffsetAlignment) != 0) {
4479 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0,
4480 __LINE__, DRAWSTATE_INVALID_UNIFORM_BUFFER_OFFSET, "DS",
4481 "vkCmdBindDescriptorSets(): pDynamicOffsets[%d] is %d but must be a multiple of device limit minUniformBufferOffsetAlignment %#" PRIxLEAST64,
4482 cur_dyn_offset, pDynamicOffsets[cur_dyn_offset], dev_data->physDevPropertyMap[pCB->device].limits.minUniformBufferOffsetAlignment);
4483 }
4484 cur_dyn_offset++;
4485 } else if (pSet->pLayout->descriptorTypes[i] == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC) {
4486 if (vk_safe_modulo(pDynamicOffsets[cur_dyn_offset], dev_data->physDevPropertyMap[pCB->device].limits.minStorageBufferOffsetAlignment) != 0) {
4487 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0,
4488 __LINE__, DRAWSTATE_INVALID_STORAGE_BUFFER_OFFSET, "DS",
4489 "vkCmdBindDescriptorSets(): pDynamicOffsets[%d] is %d but must be a multiple of device limit minStorageBufferOffsetAlignment %#" PRIxLEAST64,
4490 cur_dyn_offset, pDynamicOffsets[cur_dyn_offset], dev_data->physDevPropertyMap[pCB->device].limits.minStorageBufferOffsetAlignment);
4491 }
4492 cur_dyn_offset++;
4493 }
4494 }
4495 // Store offsets
Tobin Ehlisf6585052015-12-17 11:48:42 -07004496 const uint32_t* pStartDynOffset = pDynamicOffsets + totalDynamicDescriptors;
4497 pSet->dynamicOffsets.assign(pStartDynOffset, pStartDynOffset + pSet->pLayout->dynamicDescriptorCount);
4498 totalDynamicDescriptors += pSet->pLayout->dynamicDescriptorCount;
4499 }
4500 }
4501 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004502 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 -07004503 "Attempt to bind DS %#" PRIxLEAST64 " that doesn't exist!", (uint64_t) pDescriptorSets[i]);
4504 }
4505 }
4506 skipCall |= addCmd(dev_data, pCB, CMD_BINDDESCRIPTORSETS, "vkCmdBindDescrsiptorSets()");
4507 // For any previously bound sets, need to set them to "invalid" if they were disturbed by this update
4508 if (firstSet > 0) { // Check set #s below the first bound set
4509 for (uint32_t i=0; i<firstSet; ++i) {
4510 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 -07004511 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 -07004512 "DescriptorSetDS %#" PRIxLEAST64 " previously bound as set #%u was disturbed by newly bound pipelineLayout (%#" PRIxLEAST64 ")", (uint64_t) pCB->boundDescriptorSets[i], i, (uint64_t) layout);
4513 pCB->boundDescriptorSets[i] = VK_NULL_HANDLE;
4514 }
4515 }
4516 }
4517 // Check if newly last bound set invalidates any remaining bound sets
4518 if ((pCB->boundDescriptorSets.size()-1) > (lastSetIndex)) {
4519 if (oldFinalBoundSet && !verify_set_layout_compatibility(dev_data, dev_data->setMap[oldFinalBoundSet], layout, lastSetIndex, errorString)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004520 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 -07004521 "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);
4522 pCB->boundDescriptorSets.resize(lastSetIndex+1);
4523 }
4524 }
4525 // dynamicOffsetCount must equal the total number of dynamic descriptors in the sets being bound
4526 if (totalDynamicDescriptors != dynamicOffsetCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004527 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 -07004528 "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 -07004529 }
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07004530 validateAndIncrementDescriptorSets(dev_data, pCB);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004531 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07004532 } else {
4533 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindDescriptorSets()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004534 }
4535 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004536 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004537 dev_data->device_dispatch_table->CmdBindDescriptorSets(commandBuffer, pipelineBindPoint, layout, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004538}
4539
Chia-I Wu9ab61502015-11-06 06:42:02 +08004540VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004541{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004542 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004543 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4544 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004545 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004546 skipCall |= addCmd(dev_data, pCB, CMD_BINDINDEXBUFFER, "vkCmdBindIndexBuffer()");
4547 VkDeviceSize offset_align = 0;
4548 switch (indexType) {
4549 case VK_INDEX_TYPE_UINT16:
4550 offset_align = 2;
4551 break;
4552 case VK_INDEX_TYPE_UINT32:
4553 offset_align = 4;
4554 break;
4555 default:
4556 // ParamChecker should catch bad enum, we'll also throw alignment error below if offset_align stays 0
4557 break;
4558 }
4559 if (!offset_align || (offset % offset_align)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004560 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 -07004561 "vkCmdBindIndexBuffer() offset (%#" PRIxLEAST64 ") does not fall on alignment (%s) boundary.", offset, string_VkIndexType(indexType));
Tobin Ehlis9c536442015-06-19 13:00:59 -06004562 }
Tobin Ehlisc4c23182015-09-17 12:24:13 -06004563 pCB->status |= CBSTATUS_INDEX_BUFFER_BOUND;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004564 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004565 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004566 dev_data->device_dispatch_table->CmdBindIndexBuffer(commandBuffer, buffer, offset, indexType);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004567}
4568
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07004569void updateResourceTracking(GLOBAL_CB_NODE* pCB, uint32_t firstBinding, uint32_t bindingCount, const VkBuffer* pBuffers) {
4570 uint32_t end = firstBinding + bindingCount;
Michael Lentine700b0aa2015-10-30 17:57:32 -07004571 if (pCB->currentDrawData.buffers.size() < end) {
4572 pCB->currentDrawData.buffers.resize(end);
4573 }
4574 for (uint32_t i = 0; i < bindingCount; ++i) {
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07004575 pCB->currentDrawData.buffers[i + firstBinding] = pBuffers[i];
Michael Lentine700b0aa2015-10-30 17:57:32 -07004576 }
4577}
4578
4579void updateResourceTrackingOnDraw(GLOBAL_CB_NODE* pCB) {
4580 pCB->drawData.push_back(pCB->currentDrawData);
4581}
4582
Chia-I Wu9ab61502015-11-06 06:42:02 +08004583VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindVertexBuffers(
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07004584 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004585 uint32_t firstBinding,
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06004586 uint32_t bindingCount,
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07004587 const VkBuffer *pBuffers,
4588 const VkDeviceSize *pOffsets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004589{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004590 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004591 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4592 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004593 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004594 addCmd(dev_data, pCB, CMD_BINDVERTEXBUFFER, "vkCmdBindVertexBuffer()");
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07004595 updateResourceTracking(pCB, firstBinding, bindingCount, pBuffers);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004596 } else {
Mark Youngad779052016-01-06 14:26:04 -07004597 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindVertexBuffer()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004598 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004599 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004600 dev_data->device_dispatch_table->CmdBindVertexBuffers(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004601}
4602
Chia-I Wu9ab61502015-11-06 06:42:02 +08004603VK_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 -06004604{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004605 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004606 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4607 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004608 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004609 skipCall |= addCmd(dev_data, pCB, CMD_DRAW, "vkCmdDraw()");
4610 pCB->drawCount[DRAW]++;
4611 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
4612 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004613 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 -07004614 "vkCmdDraw() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW]++);
4615 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004616 if (VK_FALSE == skipCall) {
4617 updateResourceTrackingOnDraw(pCB);
4618 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004619 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDraw");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004620 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004621 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004622 dev_data->device_dispatch_table->CmdDraw(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004623}
4624
Chia-I Wu9ab61502015-11-06 06:42:02 +08004625VK_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 -06004626{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004627 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4628 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004629 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004630 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004631 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXED, "vkCmdDrawIndexed()");
4632 pCB->drawCount[DRAW_INDEXED]++;
4633 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
4634 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004635 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 -07004636 "vkCmdDrawIndexed() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED]++);
4637 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004638 if (VK_FALSE == skipCall) {
4639 updateResourceTrackingOnDraw(pCB);
4640 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004641 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexed");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004642 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004643 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004644 dev_data->device_dispatch_table->CmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004645}
4646
Chia-I Wu9ab61502015-11-06 06:42:02 +08004647VK_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 -06004648{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004649 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4650 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004651 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004652 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004653 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDIRECT, "vkCmdDrawIndirect()");
4654 pCB->drawCount[DRAW_INDIRECT]++;
4655 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
4656 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004657 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 -07004658 "vkCmdDrawIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
4659 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004660 if (VK_FALSE == skipCall) {
4661 updateResourceTrackingOnDraw(pCB);
4662 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004663 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndirect");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004664 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004665 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004666 dev_data->device_dispatch_table->CmdDrawIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004667}
4668
Chia-I Wu9ab61502015-11-06 06:42:02 +08004669VK_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 -06004670{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004671 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004672 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4673 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004674 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004675 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXEDINDIRECT, "vkCmdDrawIndexedIndirect()");
4676 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
4677 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
4678 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004679 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 -07004680 "vkCmdDrawIndexedIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
4681 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004682 if (VK_FALSE == skipCall) {
4683 updateResourceTrackingOnDraw(pCB);
4684 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004685 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexedIndirect");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004686 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004687 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004688 dev_data->device_dispatch_table->CmdDrawIndexedIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004689}
4690
Chia-I Wu9ab61502015-11-06 06:42:02 +08004691VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004692{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004693 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004694 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4695 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004696 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004697 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCH, "vkCmdDispatch()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004698 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatch");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004699 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004700 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004701 dev_data->device_dispatch_table->CmdDispatch(commandBuffer, x, y, z);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004702}
4703
Chia-I Wu9ab61502015-11-06 06:42:02 +08004704VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004705{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004706 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004707 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4708 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004709 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004710 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCHINDIRECT, "vkCmdDispatchIndirect()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004711 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatchIndirect");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004712 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004713 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004714 dev_data->device_dispatch_table->CmdDispatchIndirect(commandBuffer, buffer, offset);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004715}
4716
Chia-I Wu9ab61502015-11-06 06:42:02 +08004717VK_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 -06004718{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004719 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004720 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4721 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004722 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004723 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFER, "vkCmdCopyBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004724 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004725 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004726 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004727 dev_data->device_dispatch_table->CmdCopyBuffer(commandBuffer, srcBuffer, dstBuffer, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004728}
4729
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07004730VkBool32 VerifySourceImageLayout(VkCommandBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout) {
Mark Youngb20a6a82016-01-07 15:41:43 -07004731 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07004732
4733#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4734 // TODO: Fix -- initialLayout may have been set in a previous command buffer
4735 return skip_call;
4736#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4737
Michael Lentineabc5e922015-10-12 11:30:14 -05004738 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4739 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4740 auto src_image_element = pCB->imageLayoutMap.find(srcImage);
4741 if (src_image_element == pCB->imageLayoutMap.end()) {
4742 pCB->imageLayoutMap[srcImage].initialLayout = srcImageLayout;
4743 pCB->imageLayoutMap[srcImage].layout = srcImageLayout;
Mark Youngb20a6a82016-01-07 15:41:43 -07004744 return VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05004745 }
4746 if (src_image_element->second.layout != srcImageLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004747 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 -05004748 "Cannot copy from an image whose source layout is %d and doesn't match the current layout %d.", srcImageLayout, src_image_element->second.layout);
4749 }
4750 if (srcImageLayout != VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL) {
4751 if (srcImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004752 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004753 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 -05004754 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Michael Lentineabc5e922015-10-12 11:30:14 -05004755 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004756 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 -05004757 "Layout for input image is %d but can only be TRANSFER_SRC_OPTIMAL or GENERAL.", srcImageLayout);
Michael Lentineabc5e922015-10-12 11:30:14 -05004758 }
4759 }
4760 return skip_call;
4761}
4762
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07004763VkBool32 VerifyDestImageLayout(VkCommandBuffer cmdBuffer, VkImage destImage, VkImageLayout destImageLayout) {
Mark Youngb20a6a82016-01-07 15:41:43 -07004764 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07004765
4766#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4767 // TODO: Fix -- initialLayout may have been set in a previous command buffer
4768 return skip_call;
4769#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4770
Michael Lentineabc5e922015-10-12 11:30:14 -05004771 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4772 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4773 auto dest_image_element = pCB->imageLayoutMap.find(destImage);
4774 if (dest_image_element == pCB->imageLayoutMap.end()) {
4775 pCB->imageLayoutMap[destImage].initialLayout = destImageLayout;
4776 pCB->imageLayoutMap[destImage].layout = destImageLayout;
Mark Youngb20a6a82016-01-07 15:41:43 -07004777 return VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05004778 }
4779 if (dest_image_element->second.layout != destImageLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004780 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 -05004781 "Cannot copy from an image whose dest layout is %d and doesn't match the current layout %d.", destImageLayout, dest_image_element->second.layout);
4782 }
4783 if (destImageLayout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) {
4784 if (destImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004785 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004786 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 -05004787 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
4788 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004789 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 -05004790 "Layout for output image is %d but can only be TRANSFER_DST_OPTIMAL or GENERAL.", destImageLayout);
4791 }
4792 }
4793 return skip_call;
4794}
4795
Chia-I Wu9ab61502015-11-06 06:42:02 +08004796VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004797 VkImage srcImage,
4798 VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004799 VkImage dstImage,
4800 VkImageLayout dstImageLayout,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004801 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004802{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004803 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004804 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4805 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004806 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004807 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGE, "vkCmdCopyImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004808 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImage");
Michael Lentineabc5e922015-10-12 11:30:14 -05004809 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
4810 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004811 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004812 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004813 dev_data->device_dispatch_table->CmdCopyImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004814}
4815
Chia-I Wu9ab61502015-11-06 06:42:02 +08004816VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBlitImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004817 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004818 VkImage dstImage, VkImageLayout dstImageLayout,
Mark Lobodzinskiee5eef12015-05-22 14:43:25 -05004819 uint32_t regionCount, const VkImageBlit* pRegions,
Chia-I Wub99df442015-10-26 16:49:32 +08004820 VkFilter filter)
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004821{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004822 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004823 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4824 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004825 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004826 skipCall |= addCmd(dev_data, pCB, CMD_BLITIMAGE, "vkCmdBlitImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004827 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBlitImage");
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004828 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004829 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004830 dev_data->device_dispatch_table->CmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter);
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004831}
4832
Chia-I Wu9ab61502015-11-06 06:42:02 +08004833VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004834 VkBuffer srcBuffer,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004835 VkImage dstImage, VkImageLayout dstImageLayout,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004836 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004837{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004838 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004839 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4840 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004841 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004842 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFERTOIMAGE, "vkCmdCopyBufferToImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004843 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBufferToImage");
Michael Lentineabc5e922015-10-12 11:30:14 -05004844 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004845 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004846 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004847 dev_data->device_dispatch_table->CmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004848}
4849
Chia-I Wu9ab61502015-11-06 06:42:02 +08004850VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004851 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004852 VkBuffer dstBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004853 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004854{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004855 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004856 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4857 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004858 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004859 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGETOBUFFER, "vkCmdCopyImageToBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004860 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImageToBuffer");
Michael Lentineabc5e922015-10-12 11:30:14 -05004861 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004862 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004863 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004864 dev_data->device_dispatch_table->CmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004865}
4866
Chia-I Wu9ab61502015-11-06 06:42:02 +08004867VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize dataSize, const uint32_t* pData)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004868{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004869 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004870 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4871 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004872 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004873 skipCall |= addCmd(dev_data, pCB, CMD_UPDATEBUFFER, "vkCmdUpdateBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004874 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyUpdateBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004875 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004876 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004877 dev_data->device_dispatch_table->CmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004878}
4879
Chia-I Wu9ab61502015-11-06 06:42:02 +08004880VK_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 -06004881{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004882 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004883 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4884 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004885 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004886 skipCall |= addCmd(dev_data, pCB, CMD_FILLBUFFER, "vkCmdFillBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004887 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyFillBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004888 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004889 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004890 dev_data->device_dispatch_table->CmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004891}
4892
Chia-I Wu9ab61502015-11-06 06:42:02 +08004893VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearAttachments(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004894 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004895 uint32_t attachmentCount,
4896 const VkClearAttachment* pAttachments,
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004897 uint32_t rectCount,
Courtney Goeltzenleuchter4ca43f62015-10-15 18:22:08 -06004898 const VkClearRect* pRects)
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004899{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004900 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004901 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4902 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004903 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004904 skipCall |= addCmd(dev_data, pCB, CMD_CLEARATTACHMENTS, "vkCmdClearAttachments()");
4905 // Warn if this is issued prior to Draw Cmd and clearing the entire attachment
4906 if (!hasDrawCmd(pCB) &&
4907 (pCB->activeRenderPassBeginInfo.renderArea.extent.width == pRects[0].rect.extent.width) &&
4908 (pCB->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) {
4909 // TODO : commandBuffer should be srcObj
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004910 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 -07004911 "vkCmdClearAttachments() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
4912 " It is recommended you use RenderPass LOAD_OP_CLEAR on Attachments prior to any Draw.", reinterpret_cast<uint64_t>(commandBuffer));
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004913 }
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004914 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdClearAttachments");
4915 }
4916
4917 // Validate that attachment is in reference list of active subpass
4918 if (pCB->activeRenderPass) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07004919 const VkRenderPassCreateInfo *pRPCI = dev_data->renderPassMap[pCB->activeRenderPass]->pCreateInfo;
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004920 const VkSubpassDescription *pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
4921
4922 for (uint32_t attachment_idx = 0; attachment_idx < attachmentCount; attachment_idx++) {
4923 const VkClearAttachment *attachment = &pAttachments[attachment_idx];
4924 if (attachment->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) {
4925 VkBool32 found = VK_FALSE;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004926 for (uint32_t i = 0; i < pSD->colorAttachmentCount; i++) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004927 if (attachment->colorAttachment == pSD->pColorAttachments[i].attachment) {
4928 found = VK_TRUE;
4929 break;
4930 }
4931 }
4932 if (VK_FALSE == found) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004933 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 -07004934 (uint64_t)commandBuffer, __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004935 "vkCmdClearAttachments() attachment index %d not found in attachment reference array of active subpass %d",
4936 attachment->colorAttachment, pCB->activeSubpass);
4937 }
4938 } else if (attachment->aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) {
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07004939 if (!pSD->pDepthStencilAttachment || // Says no DS will be used in active subpass
Mark Lobodzinski2fd355a2015-11-18 08:58:31 -07004940 (pSD->pDepthStencilAttachment->attachment == VK_ATTACHMENT_UNUSED)) { // Says no DS will be used in active subpass
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07004941
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004942 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 -07004943 (uint64_t)commandBuffer, __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07004944 "vkCmdClearAttachments() attachment index %d does not match depthStencilAttachment.attachment (%d) found in active subpass %d",
4945 attachment->colorAttachment,
4946 (pSD->pDepthStencilAttachment) ? pSD->pDepthStencilAttachment->attachment : VK_ATTACHMENT_UNUSED,
4947 pCB->activeSubpass);
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004948 }
4949 }
4950 }
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004951 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004952 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004953 dev_data->device_dispatch_table->CmdClearAttachments(commandBuffer, attachmentCount, pAttachments, rectCount, pRects);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004954}
4955
Chia-I Wu9ab61502015-11-06 06:42:02 +08004956VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearColorImage(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004957 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06004958 VkImage image, VkImageLayout imageLayout,
Chris Forbesf0796e12015-06-24 14:34:53 +12004959 const VkClearColorValue *pColor,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06004960 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004961{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004962 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004963 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4964 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004965 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004966 skipCall |= addCmd(dev_data, pCB, CMD_CLEARCOLORIMAGE, "vkCmdClearColorImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004967 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearColorImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004968 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004969 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004970 dev_data->device_dispatch_table->CmdClearColorImage(commandBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004971}
4972
Chia-I Wu9ab61502015-11-06 06:42:02 +08004973VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearDepthStencilImage(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004974 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter45df9e12015-09-15 18:03:22 -06004975 VkImage image, VkImageLayout imageLayout,
4976 const VkClearDepthStencilValue *pDepthStencil,
4977 uint32_t rangeCount,
4978 const VkImageSubresourceRange* pRanges)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004979{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004980 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004981 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4982 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004983 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004984 skipCall |= addCmd(dev_data, pCB, CMD_CLEARDEPTHSTENCILIMAGE, "vkCmdClearDepthStencilImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004985 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearDepthStencilImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004986 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004987 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004988 dev_data->device_dispatch_table->CmdClearDepthStencilImage(commandBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004989}
4990
Chia-I Wu9ab61502015-11-06 06:42:02 +08004991VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResolveImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004992 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004993 VkImage dstImage, VkImageLayout dstImageLayout,
Tony Barbour6865d4a2015-04-13 15:02:52 -06004994 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004995{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004996 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004997 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4998 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004999 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005000 skipCall |= addCmd(dev_data, pCB, CMD_RESOLVEIMAGE, "vkCmdResolveImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005001 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResolveImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005002 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005003 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005004 dev_data->device_dispatch_table->CmdResolveImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005005}
5006
Chia-I Wu9ab61502015-11-06 06:42:02 +08005007VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005008{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005009 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005010 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5011 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005012 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005013 skipCall |= addCmd(dev_data, pCB, CMD_SETEVENT, "vkCmdSetEvent()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005014 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdSetEvent");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005015 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005016 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005017 dev_data->device_dispatch_table->CmdSetEvent(commandBuffer, event, stageMask);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005018}
5019
Chia-I Wu9ab61502015-11-06 06:42:02 +08005020VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005021{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005022 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005023 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5024 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005025 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005026 skipCall |= addCmd(dev_data, pCB, CMD_RESETEVENT, "vkCmdResetEvent()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005027 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResetEvent");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005028 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005029 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005030 dev_data->device_dispatch_table->CmdResetEvent(commandBuffer, event, stageMask);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005031}
5032
Jon Ashburnf19916e2016-01-11 13:12:43 -07005033VkBool32 TransitionImageLayouts(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const VkImageMemoryBarrier* pImgMemBarriers) {
Michael Lentineabc5e922015-10-12 11:30:14 -05005034 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5035 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Mark Youngb20a6a82016-01-07 15:41:43 -07005036 VkBool32 skip = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005037
5038#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
5039 // TODO: Fix -- pay attention to image subresource ranges -- not all subresources transition at the same time
5040 return skip;
5041#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5042
Michael Lentineabc5e922015-10-12 11:30:14 -05005043 for (uint32_t i = 0; i < memBarrierCount; ++i) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005044 auto mem_barrier = &pImgMemBarriers[i];
Michael Lentineabc5e922015-10-12 11:30:14 -05005045 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005046 auto image_data = pCB->imageLayoutMap.find(mem_barrier->image);
Michael Lentineabc5e922015-10-12 11:30:14 -05005047 if (image_data == pCB->imageLayoutMap.end()) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005048 pCB->imageLayoutMap[mem_barrier->image].initialLayout = mem_barrier->oldLayout;
5049 pCB->imageLayoutMap[mem_barrier->image].layout = mem_barrier->newLayout;
Michael Lentineabc5e922015-10-12 11:30:14 -05005050 } else {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005051 if (image_data->second.layout != mem_barrier->oldLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005052 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 -07005053 "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 -05005054 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07005055 image_data->second.layout = mem_barrier->newLayout;
Michael Lentineabc5e922015-10-12 11:30:14 -05005056 }
5057 }
5058 }
5059 return skip;
5060}
5061
Mark Lobodzinskia3a86112016-01-05 17:17:55 -07005062// Print readable FlagBits in FlagMask
5063std::string string_VkAccessFlags(VkAccessFlags accessMask)
5064{
5065 std::string result;
5066 std::string separator;
5067
5068 if (accessMask == 0) {
5069 result = "[None]";
5070 } else {
5071 result = "[";
5072 for (auto i = 0; i < 32; i++) {
5073 if (accessMask & (1 << i)) {
5074 result = result + separator + string_VkAccessFlagBits((VkAccessFlagBits)(1 << i));
5075 separator = " | ";
5076 }
5077 }
5078 result = result + "]";
5079 }
5080 return result;
5081}
5082
Michael Lentine97eb7462015-11-20 09:48:52 -08005083// AccessFlags MUST have 'required_bit' set, and may have one or more of 'optional_bits' set.
5084// If required_bit is zero, accessMask must have at least one of 'optional_bits' set
Mark Lobodzinskifd740fc2016-01-06 12:56:29 -07005085// TODO: Add tracking to ensure that at least one barrier has been set for these layout transitions
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005086VkBool32 ValidateMaskBits(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout,
5087 VkAccessFlags required_bit, VkAccessFlags optional_bits, const char* type) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005088 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005089
Michael Lentine97eb7462015-11-20 09:48:52 -08005090 if ((accessMask & required_bit) || (!required_bit && (accessMask & optional_bits))) {
5091 if (accessMask & !(required_bit | optional_bits)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005092 // TODO: Verify against Valid Use
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005093 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 -07005094 "Additional bits in %s accessMask %d %s are specified when layout is %s.",
5095 type, accessMask, string_VkAccessFlags(accessMask).c_str(), string_VkImageLayout(layout));
Michael Lentineecc32b72015-10-16 18:08:09 -05005096 }
5097 } else {
Michael Lentine97eb7462015-11-20 09:48:52 -08005098 if (!required_bit) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005099 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 -07005100 "%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 -07005101 type, accessMask, string_VkAccessFlags(accessMask).c_str(), optional_bits,
5102 string_VkAccessFlags(optional_bits).c_str(), string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08005103 } else {
Mark Lobodzinskif2cc2a52016-01-05 13:35:29 -07005104 std::string opt_bits;
5105 if (optional_bits != 0) {
Michael Lentine6bd4f122016-01-19 14:00:53 -06005106 std::stringstream ss;
5107 ss << optional_bits;
5108 opt_bits = "and may have optional bits " + ss.str() + ' ' + string_VkAccessFlags(optional_bits);
Mark Lobodzinskif2cc2a52016-01-05 13:35:29 -07005109 }
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005110 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 -07005111 "%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 -07005112 type, accessMask, string_VkAccessFlags(accessMask).c_str(),
5113 required_bit, string_VkAccessFlags(required_bit).c_str(),
Mark Lobodzinskif2cc2a52016-01-05 13:35:29 -07005114 opt_bits.c_str(), string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08005115 }
Michael Lentineecc32b72015-10-16 18:08:09 -05005116 }
5117 return skip_call;
5118}
5119
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005120VkBool32 ValidateMaskBitsFromLayouts(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout, const char* type) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005121 VkBool32 skip_call = VK_FALSE;
Michael Lentine97eb7462015-11-20 09:48:52 -08005122 switch (layout) {
5123 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005124 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 -08005125 break;
Michael Lentineecc32b72015-10-16 18:08:09 -05005126 }
Michael Lentine97eb7462015-11-20 09:48:52 -08005127 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005128 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 -08005129 break;
Michael Lentineecc32b72015-10-16 18:08:09 -05005130 }
Michael Lentine97eb7462015-11-20 09:48:52 -08005131 case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005132 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_WRITE_BIT, 0, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08005133 break;
5134 }
5135 case VK_IMAGE_LAYOUT_PREINITIALIZED: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005136 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_HOST_WRITE_BIT, 0, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08005137 break;
5138 }
5139 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005140 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 -08005141 break;
5142 }
5143 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005144 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 -08005145 break;
5146 }
5147 case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005148 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_READ_BIT, 0, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08005149 break;
5150 }
5151 case VK_IMAGE_LAYOUT_UNDEFINED: {
5152 if (accessMask != 0) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005153 // TODO: Verify against Valid Use section spec
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005154 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 -07005155 "Additional bits in %s accessMask %d %s are specified when layout is %s.", type, accessMask, string_VkAccessFlags(accessMask).c_str(),
5156 string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08005157 }
5158 break;
5159 }
5160 case VK_IMAGE_LAYOUT_GENERAL:
5161 default: {
5162 break;
5163 }
Michael Lentineecc32b72015-10-16 18:08:09 -05005164 }
5165 return skip_call;
5166}
5167
Jon Ashburnf19916e2016-01-11 13:12:43 -07005168VkBool32 ValidateBarriers(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const VkMemoryBarrier* pMemBarriers, uint32_t imageMemBarrierCount, const VkImageMemoryBarrier *pImageMemBarriers)
5169{
Mark Youngb20a6a82016-01-07 15:41:43 -07005170 VkBool32 skip_call = VK_FALSE;
Michael Lentine48930b82015-10-15 17:07:00 -05005171 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5172 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5173 if (pCB->activeRenderPass && memBarrierCount) {
5174 for (uint32_t i = 0; i < memBarrierCount; ++i) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005175 auto mem_barrier = &pMemBarriers[i];
Michael Lentine48930b82015-10-15 17:07:00 -05005176 if (mem_barrier && mem_barrier->sType != VK_STRUCTURE_TYPE_MEMORY_BARRIER) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005177 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 -05005178 "Image or Buffers Barriers cannot be used during a render pass.");
5179 }
5180 }
5181 if (!dev_data->renderPassMap[pCB->activeRenderPass]->hasSelfDependency[pCB->activeSubpass]) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005182 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 -05005183 "Barriers cannot be set during subpass %d with no self dependency specified.", pCB->activeSubpass);
5184 }
5185 }
Mark Lobodzinski73a37ec2015-11-20 09:27:27 -07005186
Jon Ashburnf19916e2016-01-11 13:12:43 -07005187 for (uint32_t i = 0; i < imageMemBarrierCount; ++i) {
5188 auto mem_barrier = &pImageMemBarriers[i];
Michael Lentineecc32b72015-10-16 18:08:09 -05005189 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005190 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, mem_barrier->srcAccessMask, mem_barrier->oldLayout, "Source");
5191 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, mem_barrier->dstAccessMask, mem_barrier->newLayout, "Dest");
Michael Lentineecc32b72015-10-16 18:08:09 -05005192 }
5193 }
Mark Lobodzinski3cba24a2015-12-03 15:42:32 -07005194
Michael Lentine48930b82015-10-15 17:07:00 -05005195 return skip_call;
5196}
5197
Jon Ashburnf19916e2016-01-11 13:12:43 -07005198VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdWaitEvents(
5199 VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent* pEvents,
5200 VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask,
5201 uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers,
5202 uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers,
5203 uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005204{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005205 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005206 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5207 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005208 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005209 for (uint32_t i = 0; i < eventCount; ++i) {
5210 pCB->waitedEvents.push_back(pEvents[i]);
5211 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005212 if (pCB->state == CB_RECORDING) {
5213 skipCall |= addCmd(dev_data, pCB, CMD_WAITEVENTS, "vkCmdWaitEvents()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005214 } else {
5215 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdWaitEvents()");
5216 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07005217 skipCall |= TransitionImageLayouts(commandBuffer, imageMemoryBarrierCount, pImageMemoryBarriers);
5218 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, pMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005219 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005220 if (VK_FALSE == skipCall)
Jon Ashburnf19916e2016-01-11 13:12:43 -07005221 dev_data->device_dispatch_table->CmdWaitEvents(commandBuffer, eventCount, pEvents, sourceStageMask, dstStageMask,
5222 memoryBarrierCount, pMemoryBarriers,
5223 bufferMemoryBarrierCount, pBufferMemoryBarriers,
5224 imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005225}
5226
Jon Ashburnf19916e2016-01-11 13:12:43 -07005227VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdPipelineBarrier(
5228 VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask,
5229 VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags,
5230 uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers,
5231 uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers,
5232 uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005233{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005234 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005235 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5236 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005237 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005238 skipCall |= addCmd(dev_data, pCB, CMD_PIPELINEBARRIER, "vkCmdPipelineBarrier()");
Jon Ashburnf19916e2016-01-11 13:12:43 -07005239 skipCall |= TransitionImageLayouts(commandBuffer, imageMemoryBarrierCount, pImageMemoryBarriers);
5240 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, pMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005241 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005242 if (VK_FALSE == skipCall)
Jon Ashburnf19916e2016-01-11 13:12:43 -07005243 dev_data->device_dispatch_table->CmdPipelineBarrier(commandBuffer, srcStageMask, dstStageMask, dependencyFlags,
5244 memoryBarrierCount, pMemoryBarriers,
5245 bufferMemoryBarrierCount, pBufferMemoryBarriers,
5246 imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005247}
5248
Chia-I Wu9ab61502015-11-06 06:42:02 +08005249VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005250{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005251 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005252 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5253 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005254 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005255 skipCall |= addCmd(dev_data, pCB, CMD_BEGINQUERY, "vkCmdBeginQuery()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005256 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005257 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005258 dev_data->device_dispatch_table->CmdBeginQuery(commandBuffer, queryPool, slot, flags);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005259}
5260
Chia-I Wu9ab61502015-11-06 06:42:02 +08005261VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005262{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005263 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005264 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5265 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005266 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005267 QueryObject query = {queryPool, slot};
5268 pCB->queryToStateMap[query] = 1;
Mark Lobodzinskice738852016-01-07 10:04:02 -07005269 if (pCB->state == CB_RECORDING) {
5270 skipCall |= addCmd(dev_data, pCB, CMD_ENDQUERY, "VkCmdEndQuery()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005271 } else {
5272 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdEndQuery()");
5273 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005274 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005275 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005276 dev_data->device_dispatch_table->CmdEndQuery(commandBuffer, queryPool, slot);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005277}
5278
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005279VK_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 -06005280{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005281 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005282 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5283 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005284 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005285 for (uint32_t i = 0; i < queryCount; i++) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005286 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06005287 pCB->waitedEventsBeforeQueryReset[query] = pCB->waitedEvents;
5288 pCB->queryToStateMap[query] = 0;
5289 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005290 if (pCB->state == CB_RECORDING) {
5291 skipCall |= addCmd(dev_data, pCB, CMD_RESETQUERYPOOL, "VkCmdResetQueryPool()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005292 } else {
5293 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdResetQueryPool()");
5294 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005295 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdQueryPool");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005296 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005297 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005298 dev_data->device_dispatch_table->CmdResetQueryPool(commandBuffer, queryPool, firstQuery, queryCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005299}
5300
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005301VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005302 uint32_t queryCount, VkBuffer dstBuffer, VkDeviceSize dstOffset,
Chia-I Wuccc93a72015-10-26 18:36:20 +08005303 VkDeviceSize stride, VkQueryResultFlags flags)
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005304{
5305 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005306 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5307 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005308 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005309 for (uint32_t i = 0; i < queryCount; i++) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005310 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06005311 if(!pCB->queryToStateMap[query]) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005312 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_QUERY, "DS",
5313 "Requesting a copy from query to buffer with invalid query: queryPool %" PRIu64 ", index %d", reinterpret_cast<uint64_t>(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06005314 }
5315 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005316 if (pCB->state == CB_RECORDING) {
5317 skipCall |= addCmd(dev_data, pCB, CMD_COPYQUERYPOOLRESULTS, "vkCmdCopyQueryPoolResults()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005318 } else {
5319 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdCopyQueryPoolResults()");
5320 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005321 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyQueryPoolResults");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005322 }
5323 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005324 dev_data->device_dispatch_table->CmdCopyQueryPoolResults(commandBuffer, queryPool,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005325 firstQuery, queryCount, dstBuffer, dstOffset, stride, flags);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005326}
5327
Chia-I Wu9ab61502015-11-06 06:42:02 +08005328VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005329{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005330 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005331 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5332 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005333 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005334 QueryObject query = {queryPool, slot};
5335 pCB->queryToStateMap[query] = 1;
Mark Lobodzinskice738852016-01-07 10:04:02 -07005336 if (pCB->state == CB_RECORDING) {
5337 skipCall |= addCmd(dev_data, pCB, CMD_WRITETIMESTAMP, "vkCmdWriteTimestamp()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005338 } else {
5339 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdWriteTimestamp()");
5340 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005341 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005342 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005343 dev_data->device_dispatch_table->CmdWriteTimestamp(commandBuffer, pipelineStage, queryPool, slot);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005344}
5345
Chia-I Wu9ab61502015-11-06 06:42:02 +08005346VK_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 -06005347{
Tobin Ehlis0b632332015-10-07 09:38:40 -06005348 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005349 VkResult result = dev_data->device_dispatch_table->CreateFramebuffer(device, pCreateInfo, pAllocator, pFramebuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005350 if (VK_SUCCESS == result) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06005351 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06005352 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +08005353 if (pCreateInfo->pAttachments) {
Courtney Goeltzenleuchter5861a1b2015-09-01 17:30:39 -06005354 localFBCI->pAttachments = new VkImageView[localFBCI->attachmentCount];
5355 memcpy((void*)localFBCI->pAttachments, pCreateInfo->pAttachments, localFBCI->attachmentCount*sizeof(VkImageView));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005356 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08005357 dev_data->frameBufferMap[*pFramebuffer] = localFBCI;
Tobin Ehliseba312c2015-04-01 08:40:34 -06005358 }
5359 return result;
5360}
5361
Michael Lentineb6986752015-10-06 14:56:18 -07005362// Store the DAG.
5363struct DAGNode {
5364 uint32_t pass;
5365 std::vector<uint32_t> prev;
5366 std::vector<uint32_t> next;
5367};
5368
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005369VkBool32 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 -07005370 // If we have already checked this node we have not found a dependency path so return false.
5371 if (processed_nodes.count(index))
Mark Youngb20a6a82016-01-07 15:41:43 -07005372 return VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005373 processed_nodes.insert(index);
5374 const DAGNode& node = subpass_to_node[index];
5375 // Look for a dependency path. If one exists return true else recurse on the previous nodes.
5376 if (std::find(node.prev.begin(), node.prev.end(), dependent) == node.prev.end()) {
5377 for (auto elem : node.prev) {
5378 if (FindDependency(elem, dependent, subpass_to_node, processed_nodes))
Mark Youngb20a6a82016-01-07 15:41:43 -07005379 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005380 }
5381 } else {
Mark Youngb20a6a82016-01-07 15:41:43 -07005382 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005383 }
Mark Youngb20a6a82016-01-07 15:41:43 -07005384 return VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005385}
5386
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005387VkBool32 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 -07005388 VkBool32 result = VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005389 // Loop through all subpasses that share the same attachment and make sure a dependency exists
5390 for (uint32_t k = 0; k < dependent_subpasses.size(); ++k) {
5391 if (subpass == dependent_subpasses[k])
5392 continue;
5393 const DAGNode& node = subpass_to_node[subpass];
5394 // Check for a specified dependency between the two nodes. If one exists we are done.
5395 auto prev_elem = std::find(node.prev.begin(), node.prev.end(), dependent_subpasses[k]);
5396 auto next_elem = std::find(node.next.begin(), node.next.end(), dependent_subpasses[k]);
5397 if (prev_elem == node.prev.end() && next_elem == node.next.end()) {
5398 // If no dependency exits an implicit dependency still might. If so, warn and if not throw an error.
5399 std::unordered_set<uint32_t> processed_nodes;
5400 if (FindDependency(subpass, dependent_subpasses[k], subpass_to_node, processed_nodes) ||
5401 FindDependency(dependent_subpasses[k], subpass, subpass_to_node, processed_nodes)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005402 // TODO: Verify against Valid Use section of spec
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005403 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 -07005404 "A dependency between subpasses %d and %d must exist but only an implicit one is specified.",
5405 subpass, dependent_subpasses[k]);
5406 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005407 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 -07005408 "A dependency between subpasses %d and %d must exist but one is not specified.",
5409 subpass, dependent_subpasses[k]);
Mark Youngb20a6a82016-01-07 15:41:43 -07005410 result = VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005411 }
5412 }
5413 }
5414 return result;
5415}
5416
Jon Ashburnf19916e2016-01-11 13:12:43 -07005417VkBool32 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 -07005418 const DAGNode& node = subpass_to_node[index];
5419 // If this node writes to the attachment return true as next nodes need to preserve the attachment.
5420 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005421 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005422 if (attachment == subpass.pColorAttachments[j].attachment)
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005423 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005424 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005425 if (subpass.pDepthStencilAttachment &&
5426 subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
5427 if (attachment == subpass.pDepthStencilAttachment->attachment)
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005428 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005429 }
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005430 VkBool32 result = VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005431 // Loop through previous nodes and see if any of them write to the attachment.
5432 for (auto elem : node.prev) {
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005433 result |= CheckPreserved(my_data, device, pCreateInfo, elem, attachment, subpass_to_node, depth + 1, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005434 }
5435 // If the attachment was written to by a previous node than this node needs to preserve it.
5436 if (result && depth > 0) {
5437 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Mark Youngb20a6a82016-01-07 15:41:43 -07005438 VkBool32 has_preserved = VK_FALSE;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005439 for (uint32_t j = 0; j < subpass.preserveAttachmentCount; ++j) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005440 if (subpass.pPreserveAttachments[j] == attachment) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005441 has_preserved = VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005442 break;
5443 }
5444 }
Mark Youngb20a6a82016-01-07 15:41:43 -07005445 if (has_preserved == VK_FALSE) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005446 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 -07005447 "Attachment %d is used by a later subpass and must be preserved in subpass %d.", attachment, index);
5448 }
5449 }
5450 return result;
5451}
5452
Michael Lentineb4979492015-12-22 11:36:14 -06005453VkBool32 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 -07005454 VkBool32 skip_call = VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005455 std::vector<std::vector<uint32_t>> output_attachment_to_subpass(pCreateInfo->attachmentCount);
5456 std::vector<std::vector<uint32_t>> input_attachment_to_subpass(pCreateInfo->attachmentCount);
Michael Lentineb6986752015-10-06 14:56:18 -07005457 // Find for each attachment the subpasses that use them.
5458 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5459 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005460 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005461 input_attachment_to_subpass[subpass.pInputAttachments[j].attachment].push_back(i);
5462 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08005463 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005464 output_attachment_to_subpass[subpass.pColorAttachments[j].attachment].push_back(i);
5465 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005466 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
5467 output_attachment_to_subpass[subpass.pDepthStencilAttachment->attachment].push_back(i);
Michael Lentineb6986752015-10-06 14:56:18 -07005468 }
5469 }
5470 // If there is a dependency needed make sure one exists
5471 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5472 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
5473 // If the attachment is an input then all subpasses that output must have a dependency relationship
Chia-I Wud50a7d72015-10-26 20:48:51 +08005474 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005475 const uint32_t& attachment = subpass.pInputAttachments[j].attachment;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005476 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005477 }
5478 // 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 +08005479 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005480 const uint32_t& attachment = subpass.pColorAttachments[j].attachment;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005481 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
5482 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005483 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005484 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
5485 const uint32_t& attachment = subpass.pDepthStencilAttachment->attachment;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005486 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
5487 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005488 }
5489 }
5490 // Loop through implicit dependencies, if this pass reads make sure the attachment is preserved for all passes after it was written.
5491 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5492 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005493 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005494 CheckPreserved(my_data, device, pCreateInfo, i, subpass.pInputAttachments[j].attachment, subpass_to_node, 0, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005495 }
5496 }
5497 return skip_call;
5498}
5499
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005500VkBool32 ValidateLayouts(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005501 VkBool32 skip = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005502
5503#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
5504 return skip;
5505#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5506
Michael Lentineabc5e922015-10-12 11:30:14 -05005507 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5508 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
5509 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
5510 if (subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL &&
5511 subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) {
5512 if (subpass.pInputAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005513 // 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 -07005514 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 -05005515 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
5516 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005517 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 -05005518 "Layout for input attachment is %d but can only be READ_ONLY_OPTIMAL or GENERAL.", subpass.pInputAttachments[j].attachment);
5519 }
5520 }
5521 }
5522 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
5523 if (subpass.pColorAttachments[j].layout != VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) {
5524 if (subpass.pColorAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005525 // 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 -07005526 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 -05005527 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
5528 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005529 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 -05005530 "Layout for color attachment is %d but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.", subpass.pColorAttachments[j].attachment);
5531 }
5532 }
5533 }
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005534 if ((subpass.pDepthStencilAttachment != NULL) &&
5535 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
Michael Lentineabc5e922015-10-12 11:30:14 -05005536 if (subpass.pDepthStencilAttachment->layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) {
5537 if (subpass.pDepthStencilAttachment->layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005538 // 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 -07005539 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 -05005540 "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL.");
5541 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005542 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 -05005543 "Layout for depth attachment is %d but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL.", subpass.pDepthStencilAttachment->attachment);
5544 }
5545 }
5546 }
5547 }
5548 return skip;
5549}
5550
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005551VkBool32 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 -07005552 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05005553 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5554 DAGNode& subpass_node = subpass_to_node[i];
5555 subpass_node.pass = i;
5556 }
5557 for (uint32_t i = 0; i < pCreateInfo->dependencyCount; ++i) {
5558 const VkSubpassDependency& dependency = pCreateInfo->pDependencies[i];
Michael Lentine6bd4f122016-01-19 14:00:53 -06005559 if (dependency.srcSubpass > dependency.dstSubpass && dependency.srcSubpass != VK_SUBPASS_EXTERNAL && dependency.dstSubpass != VK_SUBPASS_EXTERNAL) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005560 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 -05005561 "Depedency graph must be specified such that an earlier pass cannot depend on a later pass.");
Michael Lentine6bd4f122016-01-19 14:00:53 -06005562 } else if (dependency.srcSubpass == VK_SUBPASS_EXTERNAL && dependency.dstSubpass == VK_SUBPASS_EXTERNAL) {
5563 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
5564 "The src and dest subpasses cannot both be external.");
Michael Lentine48930b82015-10-15 17:07:00 -05005565 } else if (dependency.srcSubpass == dependency.dstSubpass) {
5566 has_self_dependency[dependency.srcSubpass] = true;
Michael Lentineabc5e922015-10-12 11:30:14 -05005567 }
Michael Lentine6bd4f122016-01-19 14:00:53 -06005568 if (dependency.dstSubpass != VK_SUBPASS_EXTERNAL) {
5569 subpass_to_node[dependency.dstSubpass].prev.push_back(dependency.srcSubpass);
5570 }
5571 if (dependency.srcSubpass != VK_SUBPASS_EXTERNAL) {
5572 subpass_to_node[dependency.srcSubpass].next.push_back(dependency.dstSubpass);
5573 }
Michael Lentineabc5e922015-10-12 11:30:14 -05005574 }
5575 return skip_call;
5576}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005577// TODOSC : Add intercept of vkCreateShaderModule
Michael Lentineabc5e922015-10-12 11:30:14 -05005578
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005579VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateShaderModule(
5580 VkDevice device,
5581 const VkShaderModuleCreateInfo *pCreateInfo,
5582 const VkAllocationCallbacks* pAllocator,
5583 VkShaderModule *pShaderModule)
5584{
5585 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07005586 VkBool32 skip_call = VK_FALSE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005587 if (!shader_is_spirv(pCreateInfo)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005588 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 -07005589 /* dev */ 0, __LINE__, SHADER_CHECKER_NON_SPIRV_SHADER, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005590 "Shader is not SPIR-V");
5591 }
5592
Mark Youngb20a6a82016-01-07 15:41:43 -07005593 if (VK_FALSE != skip_call)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005594 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005595
5596 VkResult res = my_data->device_dispatch_table->CreateShaderModule(device, pCreateInfo, pAllocator, pShaderModule);
5597
5598 if (res == VK_SUCCESS) {
5599 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005600 my_data->shaderModuleMap[*pShaderModule] = new shader_module(pCreateInfo);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005601 loader_platform_thread_unlock_mutex(&globalLock);
5602 }
5603 return res;
5604}
5605
Chia-I Wu9ab61502015-11-06 06:42:02 +08005606VK_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 -06005607{
Mark Youngb20a6a82016-01-07 15:41:43 -07005608 VkBool32 skip_call = VK_FALSE;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005609 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentineabc5e922015-10-12 11:30:14 -05005610 // Create DAG
Michael Lentine48930b82015-10-15 17:07:00 -05005611 std::vector<bool> has_self_dependency(pCreateInfo->subpassCount);
Michael Lentineabc5e922015-10-12 11:30:14 -05005612 std::vector<DAGNode> subpass_to_node(pCreateInfo->subpassCount);
Michael Lentine48930b82015-10-15 17:07:00 -05005613 skip_call |= CreatePassDAG(dev_data, device, pCreateInfo, subpass_to_node, has_self_dependency);
Michael Lentineabc5e922015-10-12 11:30:14 -05005614 // Validate using DAG
5615 skip_call |= ValidateDependencies(dev_data, device, pCreateInfo, subpass_to_node);
5616 skip_call |= ValidateLayouts(dev_data, device, pCreateInfo);
Mark Youngb20a6a82016-01-07 15:41:43 -07005617 if (VK_FALSE != skip_call) {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005618 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentineb6986752015-10-06 14:56:18 -07005619 }
Chia-I Wuf7458c52015-10-26 21:10:41 +08005620 VkResult result = dev_data->device_dispatch_table->CreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005621 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005622 // TODOSC : Merge in tracking of renderpass from ShaderChecker
Tobin Ehliseba312c2015-04-01 08:40:34 -06005623 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06005624 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +08005625 if (pCreateInfo->pAttachments) {
5626 localRPCI->pAttachments = new VkAttachmentDescription[localRPCI->attachmentCount];
5627 memcpy((void*)localRPCI->pAttachments, pCreateInfo->pAttachments, localRPCI->attachmentCount*sizeof(VkAttachmentDescription));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005628 }
Chia-I Wu08accc62015-07-07 11:50:03 +08005629 if (pCreateInfo->pSubpasses) {
5630 localRPCI->pSubpasses = new VkSubpassDescription[localRPCI->subpassCount];
5631 memcpy((void*)localRPCI->pSubpasses, pCreateInfo->pSubpasses, localRPCI->subpassCount*sizeof(VkSubpassDescription));
5632
5633 for (uint32_t i = 0; i < localRPCI->subpassCount; i++) {
5634 VkSubpassDescription *subpass = (VkSubpassDescription *) &localRPCI->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005635 const uint32_t attachmentCount = subpass->inputAttachmentCount +
5636 subpass->colorAttachmentCount * (1 + (subpass->pResolveAttachments?1:0)) +
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005637 ((subpass->pDepthStencilAttachment) ? 1 : 0) + subpass->preserveAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005638 VkAttachmentReference *attachments = new VkAttachmentReference[attachmentCount];
5639
Cody Northropa505dda2015-08-04 11:16:41 -06005640 memcpy(attachments, subpass->pInputAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005641 sizeof(attachments[0]) * subpass->inputAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005642 subpass->pInputAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005643 attachments += subpass->inputAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005644
Cody Northropa505dda2015-08-04 11:16:41 -06005645 memcpy(attachments, subpass->pColorAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005646 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005647 subpass->pColorAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005648 attachments += subpass->colorAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005649
Cody Northropa505dda2015-08-04 11:16:41 -06005650 if (subpass->pResolveAttachments) {
5651 memcpy(attachments, subpass->pResolveAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005652 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005653 subpass->pResolveAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005654 attachments += subpass->colorAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005655 }
5656
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005657 if (subpass->pDepthStencilAttachment) {
5658 memcpy(attachments, subpass->pDepthStencilAttachment,
5659 sizeof(attachments[0]) * 1);
5660 subpass->pDepthStencilAttachment = attachments;
5661 attachments += 1;
5662 }
5663
Cody Northropa505dda2015-08-04 11:16:41 -06005664 memcpy(attachments, subpass->pPreserveAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005665 sizeof(attachments[0]) * subpass->preserveAttachmentCount);
Jon Ashburnf19916e2016-01-11 13:12:43 -07005666 subpass->pPreserveAttachments = &attachments->attachment;
Chia-I Wu08accc62015-07-07 11:50:03 +08005667 }
Tobin Ehliseba312c2015-04-01 08:40:34 -06005668 }
Chia-I Wu08accc62015-07-07 11:50:03 +08005669 if (pCreateInfo->pDependencies) {
5670 localRPCI->pDependencies = new VkSubpassDependency[localRPCI->dependencyCount];
5671 memcpy((void*)localRPCI->pDependencies, pCreateInfo->pDependencies, localRPCI->dependencyCount*sizeof(VkSubpassDependency));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005672 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005673 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005674 dev_data->renderPassMap[*pRenderPass] = new RENDER_PASS_NODE(localRPCI);
Michael Lentine48930b82015-10-15 17:07:00 -05005675 dev_data->renderPassMap[*pRenderPass]->hasSelfDependency = has_self_dependency;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005676 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehliseba312c2015-04-01 08:40:34 -06005677 }
5678 return result;
5679}
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005680// Free the renderpass shadow
5681static void deleteRenderPasses(layer_data* my_data)
5682{
5683 if (my_data->renderPassMap.size() <= 0)
5684 return;
5685 for (auto ii=my_data->renderPassMap.begin(); ii!=my_data->renderPassMap.end(); ++ii) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005686 const VkRenderPassCreateInfo* pRenderPassInfo = (*ii).second->pCreateInfo;
Michael Lentine48930b82015-10-15 17:07:00 -05005687 if (pRenderPassInfo->pAttachments) {
5688 delete[] pRenderPassInfo->pAttachments;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005689 }
Michael Lentine48930b82015-10-15 17:07:00 -05005690 if (pRenderPassInfo->pSubpasses) {
5691 for (uint32_t i=0; i<pRenderPassInfo->subpassCount; ++i) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005692 // Attachements are all allocated in a block, so just need to
5693 // find the first non-null one to delete
Michael Lentine48930b82015-10-15 17:07:00 -05005694 if (pRenderPassInfo->pSubpasses[i].pInputAttachments) {
5695 delete[] pRenderPassInfo->pSubpasses[i].pInputAttachments;
5696 } else if (pRenderPassInfo->pSubpasses[i].pColorAttachments) {
5697 delete[] pRenderPassInfo->pSubpasses[i].pColorAttachments;
5698 } else if (pRenderPassInfo->pSubpasses[i].pResolveAttachments) {
5699 delete[] pRenderPassInfo->pSubpasses[i].pResolveAttachments;
5700 } else if (pRenderPassInfo->pSubpasses[i].pPreserveAttachments) {
5701 delete[] pRenderPassInfo->pSubpasses[i].pPreserveAttachments;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005702 }
5703 }
Michael Lentine48930b82015-10-15 17:07:00 -05005704 delete[] pRenderPassInfo->pSubpasses;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005705 }
Michael Lentine48930b82015-10-15 17:07:00 -05005706 if (pRenderPassInfo->pDependencies) {
5707 delete[] pRenderPassInfo->pDependencies;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005708 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005709 delete pRenderPassInfo;
Michael Lentine48930b82015-10-15 17:07:00 -05005710 delete (*ii).second;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005711 }
5712 my_data->renderPassMap.clear();
5713}
Michael Lentineabc5e922015-10-12 11:30:14 -05005714
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005715VkBool32 VerifyFramebufferAndRenderPassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005716 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05005717 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5718 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005719 const VkRenderPassCreateInfo* pRenderPassInfo = dev_data->renderPassMap[pRenderPassBegin->renderPass]->pCreateInfo;
Michael Lentineabc5e922015-10-12 11:30:14 -05005720 const VkFramebufferCreateInfo* pFramebufferInfo = dev_data->frameBufferMap[pRenderPassBegin->framebuffer];
5721 if (pRenderPassInfo->attachmentCount != pFramebufferInfo->attachmentCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005722 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 -05005723 "You cannot start a render pass using a framebuffer with a different number of attachments.");
5724 }
5725 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
5726 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
5727 const VkImage& image = dev_data->imageViewMap[image_view]->image;
5728 auto image_data = pCB->imageLayoutMap.find(image);
5729 if (image_data == pCB->imageLayoutMap.end()) {
5730 pCB->imageLayoutMap[image].initialLayout = pRenderPassInfo->pAttachments[i].initialLayout;
5731 pCB->imageLayoutMap[image].layout = pRenderPassInfo->pAttachments[i].initialLayout;
5732 } else if (pRenderPassInfo->pAttachments[i].initialLayout != image_data->second.layout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005733 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 -05005734 "You cannot start a render pass using attachment %i where the intial layout differs from the starting layout.", i);
5735 }
5736 }
5737 return skip_call;
5738}
5739
5740void TransitionSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, const int subpass_index) {
5741 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5742 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5743 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
5744 if (render_pass_data == dev_data->renderPassMap.end()) {
5745 return;
5746 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005747 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
Michael Lentineabc5e922015-10-12 11:30:14 -05005748 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
5749 if (framebuffer_data == dev_data->frameBufferMap.end()) {
5750 return;
5751 }
5752 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
5753 const VkSubpassDescription& subpass = pRenderPassInfo->pSubpasses[subpass_index];
5754 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
5755 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pInputAttachments[j].attachment];
5756 auto image_view_data = dev_data->imageViewMap.find(image_view);
5757 if (image_view_data != dev_data->imageViewMap.end()) {
5758 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5759 if (image_layout != pCB->imageLayoutMap.end()) {
5760 image_layout->second.layout = subpass.pInputAttachments[j].layout;
5761 }
5762 }
5763 }
5764 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
5765 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pColorAttachments[j].attachment];
5766 auto image_view_data = dev_data->imageViewMap.find(image_view);
5767 if (image_view_data != dev_data->imageViewMap.end()) {
5768 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5769 if (image_layout != pCB->imageLayoutMap.end()) {
5770 image_layout->second.layout = subpass.pColorAttachments[j].layout;
5771 }
5772 }
5773 }
Michael Lentine3dea6512015-10-28 15:55:18 -07005774 if ((subpass.pDepthStencilAttachment != NULL) &&
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005775 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
Michael Lentineabc5e922015-10-12 11:30:14 -05005776 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pDepthStencilAttachment->attachment];
5777 auto image_view_data = dev_data->imageViewMap.find(image_view);
5778 if (image_view_data != dev_data->imageViewMap.end()) {
5779 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5780 if (image_layout != pCB->imageLayoutMap.end()) {
5781 image_layout->second.layout = subpass.pDepthStencilAttachment->layout;
5782 }
5783 }
5784 }
5785}
5786
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005787VkBool32 validatePrimaryCommandBuffer(const layer_data* my_data, const GLOBAL_CB_NODE* pCB, const std::string& cmd_name) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005788 VkBool32 skip_call = VK_FALSE;
Michael Lentine3dea6512015-10-28 15:55:18 -07005789 if (pCB->createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005790 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 -07005791 "Cannot execute command %s on a secondary command buffer.", cmd_name.c_str());
5792 }
5793 return skip_call;
5794}
5795
Michael Lentineabc5e922015-10-12 11:30:14 -05005796void TransitionFinalSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
5797 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5798 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5799 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
5800 if (render_pass_data == dev_data->renderPassMap.end()) {
5801 return;
5802 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005803 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
Michael Lentineabc5e922015-10-12 11:30:14 -05005804 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
5805 if (framebuffer_data == dev_data->frameBufferMap.end()) {
5806 return;
5807 }
5808 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
5809 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
5810 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
5811 auto image_view_data = dev_data->imageViewMap.find(image_view);
5812 if (image_view_data != dev_data->imageViewMap.end()) {
5813 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5814 if (image_layout != pCB->imageLayoutMap.end()) {
5815 image_layout->second.layout = pRenderPassInfo->pAttachments[i].finalLayout;
5816 }
5817 }
5818 }
5819}
5820
Chia-I Wu9ab61502015-11-06 06:42:02 +08005821VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, VkSubpassContents contents)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005822{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005823 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005824 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5825 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005826 if (pCB) {
Tobin Ehlis259730a2015-06-23 16:13:03 -06005827 if (pRenderPassBegin && pRenderPassBegin->renderPass) {
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005828 skipCall |= VerifyFramebufferAndRenderPassLayouts(commandBuffer, pRenderPassBegin);
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005829 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBeginRenderPass");
Michael Lentine3dea6512015-10-28 15:55:18 -07005830 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdBeginRenderPass");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005831 skipCall |= addCmd(dev_data, pCB, CMD_BEGINRENDERPASS, "vkCmdBeginRenderPass()");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005832 pCB->activeRenderPass = pRenderPassBegin->renderPass;
Michael Lentineabc5e922015-10-12 11:30:14 -05005833 // This is a shallow copy as that is all that is needed for now
5834 pCB->activeRenderPassBeginInfo = *pRenderPassBegin;
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005835 pCB->activeSubpass = 0;
Michael Lentine2e068b22015-12-29 16:05:27 -06005836 pCB->activeSubpassContents = contents;
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005837 pCB->framebuffer = pRenderPassBegin->framebuffer;
Tobin Ehlis502480b2015-06-24 15:53:07 -06005838 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005839 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 -06005840 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tony Barbourbadda992015-04-06 11:09:26 -06005841 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005842 }
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005843 if (VK_FALSE == skipCall) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005844 dev_data->device_dispatch_table->CmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents);
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005845 // This is a shallow copy as that is all that is needed for now
5846 dev_data->renderPassBeginInfo = *pRenderPassBegin;
5847 dev_data->currentSubpass = 0;
5848 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005849}
5850
Chia-I Wu9ab61502015-11-06 06:42:02 +08005851VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents)
Chia-I Wu08accc62015-07-07 11:50:03 +08005852{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005853 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005854 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5855 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Michael Lentineabc5e922015-10-12 11:30:14 -05005856 TransitionSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo, ++dev_data->currentSubpass);
Chia-I Wu08accc62015-07-07 11:50:03 +08005857 if (pCB) {
Michael Lentine3dea6512015-10-28 15:55:18 -07005858 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdNextSubpass");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005859 skipCall |= addCmd(dev_data, pCB, CMD_NEXTSUBPASS, "vkCmdNextSubpass()");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005860 pCB->activeSubpass++;
Michael Lentine2e068b22015-12-29 16:05:27 -06005861 pCB->activeSubpassContents = contents;
Tony Barbourfc5bb6f2016-01-12 11:16:52 -07005862 TransitionSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo, pCB->activeSubpass);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005863 if (pCB->lastBoundPipeline) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005864 skipCall |= validatePipelineState(dev_data, pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Chia-I Wu08accc62015-07-07 11:50:03 +08005865 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005866 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdNextSubpass");
Chia-I Wu08accc62015-07-07 11:50:03 +08005867 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005868 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005869 dev_data->device_dispatch_table->CmdNextSubpass(commandBuffer, contents);
Chia-I Wu08accc62015-07-07 11:50:03 +08005870}
5871
Chia-I Wu9ab61502015-11-06 06:42:02 +08005872VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndRenderPass(VkCommandBuffer commandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005873{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005874 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005875 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5876 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Michael Lentineabc5e922015-10-12 11:30:14 -05005877 TransitionFinalSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005878 if (pCB) {
Michael Lentine3dea6512015-10-28 15:55:18 -07005879 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdEndRenderpass");
Michael Lentine3dea6512015-10-28 15:55:18 -07005880 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdEndRenderPass");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005881 skipCall |= addCmd(dev_data, pCB, CMD_ENDRENDERPASS, "vkCmdEndRenderPass()");
Michael Lentineabc5e922015-10-12 11:30:14 -05005882 TransitionFinalSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005883 pCB->activeRenderPass = 0;
5884 pCB->activeSubpass = 0;
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005885 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005886 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005887 dev_data->device_dispatch_table->CmdEndRenderPass(commandBuffer);
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005888}
5889
Chia-I Wu9ab61502015-11-06 06:42:02 +08005890VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount, const VkCommandBuffer* pCommandBuffers)
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005891{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005892 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005893 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5894 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005895 if (pCB) {
Tobin Ehlis651d9b02015-12-16 05:01:22 -07005896 // TODO : If secondary CB was not created w/ *_USAGE_SIMULTANEOUS_USE_BIT it cannot be used more than once in given primary CB
5897 // ALSO if secondary w/o this flag is set in primary, then primary must not be pending execution more than once at a time
5898 // 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 -06005899 GLOBAL_CB_NODE* pSubCB = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005900 for (uint32_t i=0; i<commandBuffersCount; i++) {
5901 pSubCB = getCBNode(dev_data, pCommandBuffers[i]);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06005902 if (!pSubCB) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005903 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 +08005904 "vkCmdExecuteCommands() called w/ invalid Cmd Buffer %p in element %u of pCommandBuffers array.", (void*)pCommandBuffers[i], i);
5905 } else if (VK_COMMAND_BUFFER_LEVEL_PRIMARY == pSubCB->createInfo.level) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005906 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 +08005907 "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 -07005908 } else if (pCB->activeRenderPass) { // Secondary CB w/i RenderPass must have *CONTINUE_BIT set
5909 if (!(pSubCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005910 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 -07005911 "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);
5912 }
5913 string errorString = "";
Jon Ashburnf19916e2016-01-11 13:12:43 -07005914 if (!verify_renderpass_compatibility(dev_data, pCB->activeRenderPass, pSubCB->beginInfo.pInheritanceInfo->renderPass, errorString)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005915 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 -07005916 "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 -07005917 (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 -07005918 }
5919 // If framebuffer for secondary CB is not NULL, then it must match FB from vkCmdBeginRenderPass()
5920 // 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 -07005921 if (pSubCB->beginInfo.pInheritanceInfo->framebuffer) {
5922 if (pSubCB->beginInfo.pInheritanceInfo->framebuffer != pCB->activeRenderPassBeginInfo.framebuffer) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005923 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 -07005924 "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 -07005925 (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 -07005926 }
5927 }
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06005928 }
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07005929 // Secondary cmdBuffers are considered pending execution starting w/ being recorded
5930 if (!(pSubCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT)) {
5931 if (dev_data->inFlightCmdBuffers.find(pSubCB->commandBuffer) != dev_data->inFlightCmdBuffers.end()) {
5932 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, reinterpret_cast<uint64_t>(pCB->commandBuffer), __LINE__, DRAWSTATE_INVALID_CB_SIMULTANEOUS_USE, "DS",
5933 "Attempt to simultaneously execute CB %#" PRIxLEAST64 " w/o VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!", reinterpret_cast<uint64_t>(pCB->commandBuffer));
5934 }
5935 if (pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT) {
5936 // Warn that non-simultaneous secondary cmd buffer renders primary non-simultaneous
5937 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, reinterpret_cast<uint64_t>(pCommandBuffers[i]), __LINE__, DRAWSTATE_INVALID_CB_SIMULTANEOUS_USE, "DS",
5938 "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.",
5939 reinterpret_cast<uint64_t>(pCommandBuffers[i]), reinterpret_cast<uint64_t>(pCB->commandBuffer));
5940 pCB->beginInfo.flags &= ~VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
5941 }
5942 }
5943 pCB->secondaryCommandBuffers.insert(pSubCB->commandBuffer);
5944 dev_data->inFlightCmdBuffers.insert(pSubCB->commandBuffer);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06005945 }
Michael Lentine3dea6512015-10-28 15:55:18 -07005946 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdExecuteComands");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005947 skipCall |= addCmd(dev_data, pCB, CMD_EXECUTECOMMANDS, "vkCmdExecuteComands()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005948 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005949 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005950 dev_data->device_dispatch_table->CmdExecuteCommands(commandBuffer, commandBuffersCount, pCommandBuffers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005951}
5952
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005953VkBool32 ValidateMapImageLayouts(VkDevice device, VkDeviceMemory mem) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005954 VkBool32 skip_call = VK_FALSE;
Michael Lentine7b236262015-10-23 12:41:44 -07005955 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5956 auto mem_data = dev_data->memImageMap.find(mem);
5957 if (mem_data != dev_data->memImageMap.end()) {
5958 auto image_data = dev_data->imageLayoutMap.find(mem_data->second);
5959 if (image_data != dev_data->imageLayoutMap.end()) {
5960 if (image_data->second->layout != VK_IMAGE_LAYOUT_PREINITIALIZED && image_data->second->layout != VK_IMAGE_LAYOUT_GENERAL) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005961 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 -07005962 "Cannot map an image with layout %d. Only GENERAL or PREINITIALIZED are supported.", image_data->second->layout);
5963 }
5964 }
5965 }
5966 return skip_call;
5967}
5968
Chia-I Wu9ab61502015-11-06 06:42:02 +08005969VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkMapMemory(
Michael Lentine7b236262015-10-23 12:41:44 -07005970 VkDevice device,
5971 VkDeviceMemory mem,
5972 VkDeviceSize offset,
5973 VkDeviceSize size,
5974 VkFlags flags,
5975 void **ppData)
5976{
5977 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005978
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005979 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005980#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
5981 skip_call = ValidateMapImageLayouts(device, mem);
5982#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5983
Michael Lentine7b236262015-10-23 12:41:44 -07005984 if (VK_FALSE == skip_call) {
5985 return dev_data->device_dispatch_table->MapMemory(device, mem, offset, size, flags, ppData);
5986 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005987 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine7b236262015-10-23 12:41:44 -07005988}
5989
Chia-I Wu9ab61502015-11-06 06:42:02 +08005990VKAPI_ATTR VkResult VKAPI_CALL vkBindImageMemory(
Michael Lentine7b236262015-10-23 12:41:44 -07005991 VkDevice device,
5992 VkImage image,
5993 VkDeviceMemory mem,
5994 VkDeviceSize memOffset)
5995{
5996 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5997 VkResult result = dev_data->device_dispatch_table->BindImageMemory(device, image, mem, memOffset);
5998 loader_platform_thread_lock_mutex(&globalLock);
5999 dev_data->memImageMap[mem] = image;
6000 loader_platform_thread_unlock_mutex(&globalLock);
6001 return result;
6002}
6003
Michael Lentineb887b0a2015-12-29 14:12:11 -06006004
6005VKAPI_ATTR VkResult VKAPI_CALL vkSetEvent(VkDevice device, VkEvent event) {
6006 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6007 dev_data->eventMap[event].needsSignaled = false;
6008 VkResult result = dev_data->device_dispatch_table->SetEvent(device, event);
6009 return result;
6010}
6011
Michael Lentine15a47882016-01-06 10:05:48 -06006012VKAPI_ATTR VkResult VKAPI_CALL vkQueueBindSparse(
6013 VkQueue queue,
6014 uint32_t bindInfoCount,
6015 const VkBindSparseInfo* pBindInfo,
6016 VkFence fence)
6017{
6018 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07006019 VkBool32 skip_call = VK_FALSE;
Michael Lentine15a47882016-01-06 10:05:48 -06006020
6021 for (uint32_t bindIdx=0; bindIdx < bindInfoCount; ++bindIdx) {
6022 const VkBindSparseInfo& bindInfo = pBindInfo[bindIdx];
6023 for (uint32_t i=0; i < bindInfo.waitSemaphoreCount; ++i) {
6024 if (dev_data->semaphoreSignaledMap[bindInfo.pWaitSemaphores[i]]) {
6025 dev_data->semaphoreSignaledMap[bindInfo.pWaitSemaphores[i]] = 0;
6026 } else {
6027 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",
6028 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
6029 reinterpret_cast<uint64_t>(queue), reinterpret_cast<uint64_t>(bindInfo.pWaitSemaphores[i]));
6030 }
6031 }
6032 for (uint32_t i=0; i < bindInfo.signalSemaphoreCount; ++i) {
6033 dev_data->semaphoreSignaledMap[bindInfo.pSignalSemaphores[i]] = 1;
6034 }
6035 }
6036
Mark Youngb20a6a82016-01-07 15:41:43 -07006037 if (VK_FALSE == skip_call)
Michael Lentine15a47882016-01-06 10:05:48 -06006038 return dev_data->device_dispatch_table->QueueBindSparse(queue, bindInfoCount, pBindInfo, fence);
Mark Youngb20a6a82016-01-07 15:41:43 -07006039 else
6040 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine15a47882016-01-06 10:05:48 -06006041}
6042
6043VKAPI_ATTR VkResult VKAPI_CALL vkCreateSemaphore(
6044 VkDevice device,
6045 const VkSemaphoreCreateInfo* pCreateInfo,
6046 const VkAllocationCallbacks* pAllocator,
6047 VkSemaphore* pSemaphore)
6048{
6049 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6050 VkResult result = dev_data->device_dispatch_table->CreateSemaphore(device, pCreateInfo, pAllocator, pSemaphore);
6051 if (result == VK_SUCCESS) {
6052 dev_data->semaphoreSignaledMap[*pSemaphore] = 0;
6053 }
Tobin Ehlis51b78af2016-01-06 10:27:47 -07006054 return result;
Michael Lentine15a47882016-01-06 10:05:48 -06006055}
6056
Chia-I Wu9ab61502015-11-06 06:42:02 +08006057VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(
Michael Lentineabc5e922015-10-12 11:30:14 -05006058 VkDevice device,
6059 const VkSwapchainCreateInfoKHR *pCreateInfo,
Ian Elliott05846062015-11-20 14:13:17 -07006060 const VkAllocationCallbacks *pAllocator,
Michael Lentineabc5e922015-10-12 11:30:14 -05006061 VkSwapchainKHR *pSwapchain)
6062{
6063 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott05846062015-11-20 14:13:17 -07006064 VkResult result = dev_data->device_dispatch_table->CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
Michael Lentineabc5e922015-10-12 11:30:14 -05006065
6066 if (VK_SUCCESS == result) {
Tobin Ehlis75cd1c52016-01-21 10:21:04 -07006067 SWAPCHAIN_NODE *swapchain_data = new SWAPCHAIN_NODE(pCreateInfo);
Michael Lentineabc5e922015-10-12 11:30:14 -05006068 loader_platform_thread_lock_mutex(&globalLock);
6069 dev_data->device_extensions.swapchainMap[*pSwapchain] = swapchain_data;
6070 loader_platform_thread_unlock_mutex(&globalLock);
6071 }
6072
6073 return result;
6074}
6075
Ian Elliott05846062015-11-20 14:13:17 -07006076VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR(
Michael Lentineabc5e922015-10-12 11:30:14 -05006077 VkDevice device,
Ian Elliott05846062015-11-20 14:13:17 -07006078 VkSwapchainKHR swapchain,
6079 const VkAllocationCallbacks *pAllocator)
Michael Lentineabc5e922015-10-12 11:30:14 -05006080{
6081 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentineabc5e922015-10-12 11:30:14 -05006082
6083 loader_platform_thread_lock_mutex(&globalLock);
6084 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(swapchain);
6085 if (swapchain_data != dev_data->device_extensions.swapchainMap.end()) {
6086 if (swapchain_data->second->images.size() > 0) {
6087 for (auto swapchain_image : swapchain_data->second->images) {
6088 auto image_item = dev_data->imageLayoutMap.find(swapchain_image);
6089 if (image_item != dev_data->imageLayoutMap.end())
6090 dev_data->imageLayoutMap.erase(image_item);
6091 }
6092 }
6093 delete swapchain_data->second;
6094 dev_data->device_extensions.swapchainMap.erase(swapchain);
6095 }
6096 loader_platform_thread_unlock_mutex(&globalLock);
Ian Elliott05846062015-11-20 14:13:17 -07006097 return dev_data->device_dispatch_table->DestroySwapchainKHR(device, swapchain, pAllocator);
Michael Lentineabc5e922015-10-12 11:30:14 -05006098}
6099
Chia-I Wu9ab61502015-11-06 06:42:02 +08006100VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR(
Michael Lentineabc5e922015-10-12 11:30:14 -05006101 VkDevice device,
6102 VkSwapchainKHR swapchain,
6103 uint32_t* pCount,
6104 VkImage* pSwapchainImages)
6105{
6106 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6107 VkResult result = dev_data->device_dispatch_table->GetSwapchainImagesKHR(device, swapchain, pCount, pSwapchainImages);
6108
6109 if (result == VK_SUCCESS && pSwapchainImages != NULL) {
6110 // This should never happen and is checked by param checker.
6111 if (!pCount) return result;
6112 for (uint32_t i = 0; i < *pCount; ++i) {
6113 IMAGE_NODE* image_node = new IMAGE_NODE;
6114 image_node->layout = VK_IMAGE_LAYOUT_UNDEFINED;
6115 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis75cd1c52016-01-21 10:21:04 -07006116 auto swapchain_node = dev_data->device_extensions.swapchainMap[swapchain];
6117 image_node->format = swapchain_node->createInfo.imageFormat;
6118 swapchain_node->images.push_back(pSwapchainImages[i]);
Michael Lentineabc5e922015-10-12 11:30:14 -05006119 dev_data->imageLayoutMap[pSwapchainImages[i]] = image_node;
6120 loader_platform_thread_unlock_mutex(&globalLock);
6121 }
6122 }
6123 return result;
6124}
6125
Ian Elliott05846062015-11-20 14:13:17 -07006126VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo)
Michael Lentineabc5e922015-10-12 11:30:14 -05006127{
6128 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07006129 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05006130
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006131#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentineabc5e922015-10-12 11:30:14 -05006132 if (pPresentInfo) {
Michael Lentine15a47882016-01-06 10:05:48 -06006133 for (uint32_t i=0; i < pPresentInfo->waitSemaphoreCount; ++i) {
6134 if (dev_data->semaphoreSignaledMap[pPresentInfo->pWaitSemaphores[i]]) {
6135 dev_data->semaphoreSignaledMap[pPresentInfo->pWaitSemaphores[i]] = 0;
6136 } else {
6137 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",
6138 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
6139 reinterpret_cast<uint64_t>(queue), reinterpret_cast<uint64_t>(pPresentInfo->pWaitSemaphores[i]));
6140 }
6141 }
Michael Lentineabc5e922015-10-12 11:30:14 -05006142 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
Ian Elliott05846062015-11-20 14:13:17 -07006143 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(pPresentInfo->pSwapchains[i]);
6144 if (swapchain_data != dev_data->device_extensions.swapchainMap.end() && pPresentInfo->pImageIndices[i] < swapchain_data->second->images.size()) {
6145 VkImage image = swapchain_data->second->images[pPresentInfo->pImageIndices[i]];
Michael Lentineabc5e922015-10-12 11:30:14 -05006146 auto image_data = dev_data->imageLayoutMap.find(image);
6147 if (image_data != dev_data->imageLayoutMap.end()) {
Ian Elliott05846062015-11-20 14:13:17 -07006148 if (image_data->second->layout != VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07006149 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 -05006150 "Images passed to present must be in layout PRESENT_SOURCE_KHR but is in %d", image_data->second->layout);
6151 }
6152 }
6153 }
6154 }
6155 }
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006156#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentineabc5e922015-10-12 11:30:14 -05006157
6158 if (VK_FALSE == skip_call)
6159 return dev_data->device_dispatch_table->QueuePresentKHR(queue, pPresentInfo);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07006160 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentineabc5e922015-10-12 11:30:14 -05006161}
6162
Michael Lentine15a47882016-01-06 10:05:48 -06006163VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImageKHR(
6164 VkDevice device,
6165 VkSwapchainKHR swapchain,
6166 uint64_t timeout,
6167 VkSemaphore semaphore,
6168 VkFence fence,
6169 uint32_t* pImageIndex)
6170{
6171 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6172 VkResult result = dev_data->device_dispatch_table->AcquireNextImageKHR(device, swapchain, timeout, semaphore, fence, pImageIndex);
6173 dev_data->semaphoreSignaledMap[semaphore] = 1;
Tobin Ehlis51b78af2016-01-06 10:27:47 -07006174 return result;
Michael Lentine15a47882016-01-06 10:05:48 -06006175}
6176
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006177VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(
6178 VkInstance instance,
6179 const VkDebugReportCallbackCreateInfoEXT* pCreateInfo,
6180 const VkAllocationCallbacks* pAllocator,
6181 VkDebugReportCallbackEXT* pMsgCallback)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006182{
Tobin Ehlis0b632332015-10-07 09:38:40 -06006183 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006184 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006185 VkResult res = pTable->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06006186 if (VK_SUCCESS == res) {
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006187 res = layer_create_msg_callback(my_data->report_data, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06006188 }
6189 return res;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006190}
6191
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006192VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006193 VkInstance instance,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006194 VkDebugReportCallbackEXT msgCallback,
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006195 const VkAllocationCallbacks* pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006196{
Tobin Ehlis0b632332015-10-07 09:38:40 -06006197 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006198 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006199 pTable->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006200 layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006201}
6202
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006203VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDebugReportMessageEXT(
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07006204 VkInstance instance,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006205 VkDebugReportFlagsEXT flags,
6206 VkDebugReportObjectTypeEXT objType,
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07006207 uint64_t object,
6208 size_t location,
6209 int32_t msgCode,
6210 const char* pLayerPrefix,
6211 const char* pMsg)
6212{
6213 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006214 my_data->instance_dispatch_table->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg);
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07006215}
6216
Chia-I Wu9ab61502015-11-06 06:42:02 +08006217VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerBegin(VkCommandBuffer commandBuffer, const char* pMarker)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006218{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006219 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006220 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
6221 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis0b632332015-10-07 09:38:40 -06006222 if (!dev_data->device_extensions.debug_marker_enabled) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07006223 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 -06006224 "Attempt to use CmdDbgMarkerBegin but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06006225 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06006226 } else if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07006227 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKERBEGIN, "vkCmdDbgMarkerBegin()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006228 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006229 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006230 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerBegin(commandBuffer, pMarker);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006231}
6232
Chia-I Wu9ab61502015-11-06 06:42:02 +08006233VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerEnd(VkCommandBuffer commandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006234{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006235 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006236 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
6237 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis0b632332015-10-07 09:38:40 -06006238 if (!dev_data->device_extensions.debug_marker_enabled) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07006239 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 -06006240 "Attempt to use CmdDbgMarkerEnd but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06006241 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06006242 } else if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07006243 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKEREND, "vkCmdDbgMarkerEnd()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006244 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006245 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006246 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerEnd(commandBuffer);
Jon Ashburneab34492015-06-01 09:37:38 -06006247}
6248
Chia-I Wu9ab61502015-11-06 06:42:02 +08006249VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006250{
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006251 if (!strcmp(funcName, "vkGetDeviceProcAddr"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006252 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006253 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006254 return (PFN_vkVoidFunction) vkDestroyDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006255 if (!strcmp(funcName, "vkQueueSubmit"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006256 return (PFN_vkVoidFunction) vkQueueSubmit;
Michael Lentine700b0aa2015-10-30 17:57:32 -07006257 if (!strcmp(funcName, "vkWaitForFences"))
6258 return (PFN_vkVoidFunction) vkWaitForFences;
6259 if (!strcmp(funcName, "vkGetFenceStatus"))
6260 return (PFN_vkVoidFunction) vkGetFenceStatus;
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07006261 if (!strcmp(funcName, "vkQueueWaitIdle"))
6262 return (PFN_vkVoidFunction) vkQueueWaitIdle;
6263 if (!strcmp(funcName, "vkDeviceWaitIdle"))
6264 return (PFN_vkVoidFunction) vkDeviceWaitIdle;
Michael Lentine700b0aa2015-10-30 17:57:32 -07006265 if (!strcmp(funcName, "vkGetDeviceQueue"))
6266 return (PFN_vkVoidFunction) vkGetDeviceQueue;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006267 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006268 return (PFN_vkVoidFunction) vkDestroyInstance;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006269 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006270 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006271 if (!strcmp(funcName, "vkDestroyFence"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006272 return (PFN_vkVoidFunction) vkDestroyFence;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006273 if (!strcmp(funcName, "vkDestroySemaphore"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006274 return (PFN_vkVoidFunction) vkDestroySemaphore;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006275 if (!strcmp(funcName, "vkDestroyEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006276 return (PFN_vkVoidFunction) vkDestroyEvent;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006277 if (!strcmp(funcName, "vkDestroyQueryPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006278 return (PFN_vkVoidFunction) vkDestroyQueryPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006279 if (!strcmp(funcName, "vkDestroyBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006280 return (PFN_vkVoidFunction) vkDestroyBuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006281 if (!strcmp(funcName, "vkDestroyBufferView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006282 return (PFN_vkVoidFunction) vkDestroyBufferView;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006283 if (!strcmp(funcName, "vkDestroyImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006284 return (PFN_vkVoidFunction) vkDestroyImage;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006285 if (!strcmp(funcName, "vkDestroyImageView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006286 return (PFN_vkVoidFunction) vkDestroyImageView;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006287 if (!strcmp(funcName, "vkDestroyShaderModule"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006288 return (PFN_vkVoidFunction) vkDestroyShaderModule;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006289 if (!strcmp(funcName, "vkDestroyPipeline"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006290 return (PFN_vkVoidFunction) vkDestroyPipeline;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006291 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006292 return (PFN_vkVoidFunction) vkDestroyPipelineLayout;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006293 if (!strcmp(funcName, "vkDestroySampler"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006294 return (PFN_vkVoidFunction) vkDestroySampler;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006295 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006296 return (PFN_vkVoidFunction) vkDestroyDescriptorSetLayout;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006297 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006298 return (PFN_vkVoidFunction) vkDestroyDescriptorPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006299 if (!strcmp(funcName, "vkDestroyFramebuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006300 return (PFN_vkVoidFunction) vkDestroyFramebuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006301 if (!strcmp(funcName, "vkDestroyRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006302 return (PFN_vkVoidFunction) vkDestroyRenderPass;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006303 if (!strcmp(funcName, "vkCreateBuffer"))
6304 return (PFN_vkVoidFunction) vkCreateBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006305 if (!strcmp(funcName, "vkCreateBufferView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006306 return (PFN_vkVoidFunction) vkCreateBufferView;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006307 if (!strcmp(funcName, "vkCreateImage"))
6308 return (PFN_vkVoidFunction) vkCreateImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006309 if (!strcmp(funcName, "vkCreateImageView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006310 return (PFN_vkVoidFunction) vkCreateImageView;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006311 if (!strcmp(funcName, "CreatePipelineCache"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006312 return (PFN_vkVoidFunction) vkCreatePipelineCache;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006313 if (!strcmp(funcName, "DestroyPipelineCache"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006314 return (PFN_vkVoidFunction) vkDestroyPipelineCache;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006315 if (!strcmp(funcName, "GetPipelineCacheData"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006316 return (PFN_vkVoidFunction) vkGetPipelineCacheData;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006317 if (!strcmp(funcName, "MergePipelineCaches"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006318 return (PFN_vkVoidFunction) vkMergePipelineCaches;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006319 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006320 return (PFN_vkVoidFunction) vkCreateGraphicsPipelines;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07006321 if (!strcmp(funcName, "vkCreateComputePipelines"))
6322 return (PFN_vkVoidFunction) vkCreateComputePipelines;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006323 if (!strcmp(funcName, "vkCreateSampler"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006324 return (PFN_vkVoidFunction) vkCreateSampler;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006325 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006326 return (PFN_vkVoidFunction) vkCreateDescriptorSetLayout;
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05006327 if (!strcmp(funcName, "vkCreatePipelineLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006328 return (PFN_vkVoidFunction) vkCreatePipelineLayout;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006329 if (!strcmp(funcName, "vkCreateDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006330 return (PFN_vkVoidFunction) vkCreateDescriptorPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006331 if (!strcmp(funcName, "vkResetDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006332 return (PFN_vkVoidFunction) vkResetDescriptorPool;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006333 if (!strcmp(funcName, "vkAllocateDescriptorSets"))
6334 return (PFN_vkVoidFunction) vkAllocateDescriptorSets;
Tobin Ehlise735c692015-10-08 13:13:50 -06006335 if (!strcmp(funcName, "vkFreeDescriptorSets"))
6336 return (PFN_vkVoidFunction) vkFreeDescriptorSets;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08006337 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006338 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
Mark Lobodzinski39298632015-11-18 08:38:27 -07006339 if (!strcmp(funcName, "vkCreateCommandPool"))
6340 return (PFN_vkVoidFunction) vkCreateCommandPool;
6341 if (!strcmp(funcName, "vkDestroyCommandPool"))
6342 return (PFN_vkVoidFunction) vkDestroyCommandPool;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006343 if (!strcmp(funcName, "vkResetCommandPool"))
6344 return (PFN_vkVoidFunction) vkResetCommandPool;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006345 if (!strcmp(funcName, "vkAllocateCommandBuffers"))
6346 return (PFN_vkVoidFunction) vkAllocateCommandBuffers;
Mark Lobodzinski39298632015-11-18 08:38:27 -07006347 if (!strcmp(funcName, "vkFreeCommandBuffers"))
6348 return (PFN_vkVoidFunction) vkFreeCommandBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006349 if (!strcmp(funcName, "vkBeginCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006350 return (PFN_vkVoidFunction) vkBeginCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006351 if (!strcmp(funcName, "vkEndCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006352 return (PFN_vkVoidFunction) vkEndCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006353 if (!strcmp(funcName, "vkResetCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006354 return (PFN_vkVoidFunction) vkResetCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006355 if (!strcmp(funcName, "vkCmdBindPipeline"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006356 return (PFN_vkVoidFunction) vkCmdBindPipeline;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06006357 if (!strcmp(funcName, "vkCmdSetViewport"))
6358 return (PFN_vkVoidFunction) vkCmdSetViewport;
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06006359 if (!strcmp(funcName, "vkCmdSetScissor"))
6360 return (PFN_vkVoidFunction) vkCmdSetScissor;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06006361 if (!strcmp(funcName, "vkCmdSetLineWidth"))
6362 return (PFN_vkVoidFunction) vkCmdSetLineWidth;
6363 if (!strcmp(funcName, "vkCmdSetDepthBias"))
6364 return (PFN_vkVoidFunction) vkCmdSetDepthBias;
6365 if (!strcmp(funcName, "vkCmdSetBlendConstants"))
6366 return (PFN_vkVoidFunction) vkCmdSetBlendConstants;
6367 if (!strcmp(funcName, "vkCmdSetDepthBounds"))
6368 return (PFN_vkVoidFunction) vkCmdSetDepthBounds;
6369 if (!strcmp(funcName, "vkCmdSetStencilCompareMask"))
6370 return (PFN_vkVoidFunction) vkCmdSetStencilCompareMask;
6371 if (!strcmp(funcName, "vkCmdSetStencilWriteMask"))
6372 return (PFN_vkVoidFunction) vkCmdSetStencilWriteMask;
6373 if (!strcmp(funcName, "vkCmdSetStencilReference"))
6374 return (PFN_vkVoidFunction) vkCmdSetStencilReference;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006375 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006376 return (PFN_vkVoidFunction) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06006377 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006378 return (PFN_vkVoidFunction) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006379 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006380 return (PFN_vkVoidFunction) vkCmdBindIndexBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006381 if (!strcmp(funcName, "vkCmdDraw"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006382 return (PFN_vkVoidFunction) vkCmdDraw;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006383 if (!strcmp(funcName, "vkCmdDrawIndexed"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006384 return (PFN_vkVoidFunction) vkCmdDrawIndexed;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006385 if (!strcmp(funcName, "vkCmdDrawIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006386 return (PFN_vkVoidFunction) vkCmdDrawIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006387 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006388 return (PFN_vkVoidFunction) vkCmdDrawIndexedIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006389 if (!strcmp(funcName, "vkCmdDispatch"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006390 return (PFN_vkVoidFunction) vkCmdDispatch;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006391 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006392 return (PFN_vkVoidFunction) vkCmdDispatchIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006393 if (!strcmp(funcName, "vkCmdCopyBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006394 return (PFN_vkVoidFunction) vkCmdCopyBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006395 if (!strcmp(funcName, "vkCmdCopyImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006396 return (PFN_vkVoidFunction) vkCmdCopyImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006397 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006398 return (PFN_vkVoidFunction) vkCmdCopyBufferToImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006399 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006400 return (PFN_vkVoidFunction) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006401 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006402 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006403 if (!strcmp(funcName, "vkCmdFillBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006404 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006405 if (!strcmp(funcName, "vkCmdClearColorImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006406 return (PFN_vkVoidFunction) vkCmdClearColorImage;
Chris Forbesd9be82b2015-06-22 17:21:59 +12006407 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006408 return (PFN_vkVoidFunction) vkCmdClearDepthStencilImage;
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06006409 if (!strcmp(funcName, "vkCmdClearAttachments"))
6410 return (PFN_vkVoidFunction) vkCmdClearAttachments;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006411 if (!strcmp(funcName, "vkCmdResolveImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006412 return (PFN_vkVoidFunction) vkCmdResolveImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006413 if (!strcmp(funcName, "vkCmdSetEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006414 return (PFN_vkVoidFunction) vkCmdSetEvent;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006415 if (!strcmp(funcName, "vkCmdResetEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006416 return (PFN_vkVoidFunction) vkCmdResetEvent;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006417 if (!strcmp(funcName, "vkCmdWaitEvents"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006418 return (PFN_vkVoidFunction) vkCmdWaitEvents;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006419 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006420 return (PFN_vkVoidFunction) vkCmdPipelineBarrier;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006421 if (!strcmp(funcName, "vkCmdBeginQuery"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006422 return (PFN_vkVoidFunction) vkCmdBeginQuery;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006423 if (!strcmp(funcName, "vkCmdEndQuery"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006424 return (PFN_vkVoidFunction) vkCmdEndQuery;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006425 if (!strcmp(funcName, "vkCmdResetQueryPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006426 return (PFN_vkVoidFunction) vkCmdResetQueryPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006427 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006428 return (PFN_vkVoidFunction) vkCmdWriteTimestamp;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006429 if (!strcmp(funcName, "vkCreateFramebuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006430 return (PFN_vkVoidFunction) vkCreateFramebuffer;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006431 if (!strcmp(funcName, "vkCreateShaderModule"))
6432 return (PFN_vkVoidFunction) vkCreateShaderModule;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006433 if (!strcmp(funcName, "vkCreateRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006434 return (PFN_vkVoidFunction) vkCreateRenderPass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006435 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006436 return (PFN_vkVoidFunction) vkCmdBeginRenderPass;
Chia-I Wu08accc62015-07-07 11:50:03 +08006437 if (!strcmp(funcName, "vkCmdNextSubpass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006438 return (PFN_vkVoidFunction) vkCmdNextSubpass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006439 if (!strcmp(funcName, "vkCmdEndRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006440 return (PFN_vkVoidFunction) vkCmdEndRenderPass;
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06006441 if (!strcmp(funcName, "vkCmdExecuteCommands"))
6442 return (PFN_vkVoidFunction) vkCmdExecuteCommands;
Michael Lentineb887b0a2015-12-29 14:12:11 -06006443 if (!strcmp(funcName, "vkSetEvent"))
6444 return (PFN_vkVoidFunction) vkSetEvent;
Michael Lentine7b236262015-10-23 12:41:44 -07006445 if (!strcmp(funcName, "vkMapMemory"))
6446 return (PFN_vkVoidFunction) vkMapMemory;
Michael Lentineb887b0a2015-12-29 14:12:11 -06006447 if (!strcmp(funcName, "vkGetQueryPoolResults"))
6448 return (PFN_vkVoidFunction) vkGetQueryPoolResults;
Michael Lentine15a47882016-01-06 10:05:48 -06006449 if (!strcmp(funcName, "vkBindImageMemory"))
6450 return (PFN_vkVoidFunction) vkBindImageMemory;
6451 if (!strcmp(funcName, "vkQueueBindSparse"))
6452 return (PFN_vkVoidFunction) vkQueueBindSparse;
6453 if (!strcmp(funcName, "vkCreateSemaphore"))
6454 return (PFN_vkVoidFunction) vkCreateSemaphore;
Jon Ashburneab34492015-06-01 09:37:38 -06006455
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006456 if (dev == NULL)
6457 return NULL;
6458
6459 layer_data *dev_data;
6460 dev_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map);
6461
Michael Lentineabc5e922015-10-12 11:30:14 -05006462 if (dev_data->device_extensions.wsi_enabled)
6463 {
6464 if (!strcmp(funcName, "vkCreateSwapchainKHR"))
6465 return (PFN_vkVoidFunction) vkCreateSwapchainKHR;
6466 if (!strcmp(funcName, "vkDestroySwapchainKHR"))
6467 return (PFN_vkVoidFunction) vkDestroySwapchainKHR;
6468 if (!strcmp(funcName, "vkGetSwapchainImagesKHR"))
6469 return (PFN_vkVoidFunction) vkGetSwapchainImagesKHR;
Michael Lentine15a47882016-01-06 10:05:48 -06006470 if (!strcmp(funcName, "vkAcquireNextImageKHR"))
6471 return (PFN_vkVoidFunction) vkAcquireNextImageKHR;
Michael Lentineabc5e922015-10-12 11:30:14 -05006472 if (!strcmp(funcName, "vkQueuePresentKHR"))
6473 return (PFN_vkVoidFunction) vkQueuePresentKHR;
6474 }
6475
Tobin Ehlis0b632332015-10-07 09:38:40 -06006476 VkLayerDispatchTable* pTable = dev_data->device_dispatch_table;
6477 if (dev_data->device_extensions.debug_marker_enabled)
Jon Ashburn8fd08252015-05-28 16:25:02 -06006478 {
Jon Ashburn747f2b62015-06-18 15:02:58 -06006479 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006480 return (PFN_vkVoidFunction) vkCmdDbgMarkerBegin;
Jon Ashburn747f2b62015-06-18 15:02:58 -06006481 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006482 return (PFN_vkVoidFunction) vkCmdDbgMarkerEnd;
Jon Ashburneab34492015-06-01 09:37:38 -06006483 }
6484 {
Jon Ashburn8fd08252015-05-28 16:25:02 -06006485 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006486 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006487 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburnf6b33db2015-05-05 14:22:52 -06006488 }
6489}
6490
Chia-I Wu9ab61502015-11-06 06:42:02 +08006491VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Jon Ashburnf6b33db2015-05-05 14:22:52 -06006492{
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006493 if (!strcmp(funcName, "vkGetInstanceProcAddr"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006494 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006495 if (!strcmp(funcName, "vkGetDeviceProcAddr"))
6496 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06006497 if (!strcmp(funcName, "vkCreateInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006498 return (PFN_vkVoidFunction) vkCreateInstance;
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006499 if (!strcmp(funcName, "vkCreateDevice"))
6500 return (PFN_vkVoidFunction) vkCreateDevice;
Jon Ashburn3950e1b2015-05-20 09:00:28 -06006501 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006502 return (PFN_vkVoidFunction) vkDestroyInstance;
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -06006503 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
6504 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
6505 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
6506 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
6507 if (!strcmp(funcName, "vkEnumerateDeviceLayerProperties"))
6508 return (PFN_vkVoidFunction) vkEnumerateDeviceLayerProperties;
6509 if (!strcmp(funcName, "vkEnumerateDeviceExtensionProperties"))
6510 return (PFN_vkVoidFunction) vkEnumerateDeviceExtensionProperties;
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06006511
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006512 if (instance == NULL)
6513 return NULL;
6514
6515 PFN_vkVoidFunction fptr;
6516
6517 layer_data* my_data;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006518 my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06006519 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06006520 if (fptr)
6521 return fptr;
6522
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006523 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
6524 if (pTable->GetInstanceProcAddr == NULL)
6525 return NULL;
6526 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006527}