blob: 59978e5f68ad921dc15119244d525d64b551bdfa [file] [log] [blame]
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -07001/* Copyright (c) 2015-2016 The Khronos Group Inc.
2 * Copyright (c) 2015-2016 Valve Corporation
3 * Copyright (c) 2015-2016 LunarG, Inc.
4 * Copyright (C) 2015-2016 Google Inc.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005 *
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -07006 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and/or associated documentation files (the "Materials"), to
8 * deal in the Materials without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Materials, and to permit persons to whom the Materials
11 * are furnished to do so, subject to the following conditions:
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060012 *
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -070013 * The above copyright notice(s) and this permission notice shall be included
14 * in all copies or substantial portions of the Materials.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060015 *
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -070016 * The Materials are Confidential Information as defined by the Khronos
17 * Membership Agreement until designated non-confidential by Khronos, at which
18 * point this condition clause shall be removed.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060019 *
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -070020 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060021 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -070022 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 *
24 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
26 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE
27 * USE OR OTHER DEALINGS IN THE MATERIALS
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060028 *
Tobin Ehlis88452832015-12-03 09:40:56 -070029 * Author: Cody Northrop <cnorthrop@google.com>
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060030 * Author: Michael Lentine <mlentine@google.com>
Tobin Ehlis88452832015-12-03 09:40:56 -070031 * Author: Tobin Ehlis <tobine@google.com>
32 * Author: Chia-I Wu <olv@google.com>
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070033 * Author: Chris Forbes <chrisf@ijw.co.nz>
Mark Lobodzinski78da8cb2015-12-28 15:51:07 -070034 * Author: Mark Lobodzinski <mark@lunarg.com>
Ian Elliott8c8b2662016-01-30 10:57:03 -070035 * Author: Ian Elliott <ianelliott@google.com>
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060036 */
37
Mark Lobodzinski78da8cb2015-12-28 15:51:07 -070038// Allow use of STL min and max functions in Windows
39#define NOMINMAX
40
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060041#include <stdio.h>
42#include <stdlib.h>
43#include <string.h>
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070044#include <assert.h>
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060045#include <unordered_map>
Michael Lentineb6986752015-10-06 14:56:18 -070046#include <unordered_set>
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070047#include <map>
48#include <string>
49#include <iostream>
50#include <algorithm>
Mark Lobodzinski39298632015-11-18 08:38:27 -070051#include <list>
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070052#include <spirv.hpp>
Tobin Ehlis88452832015-12-03 09:40:56 -070053#include <set>
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060054
Tobin Ehlisb835d1b2015-07-03 10:34:49 -060055#include "vk_loader_platform.h"
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060056#include "vk_dispatch_table_helper.h"
57#include "vk_struct_string_helper_cpp.h"
Tony Barbour18f71552015-04-22 11:36:22 -060058#if defined(__GNUC__)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060059#pragma GCC diagnostic ignored "-Wwrite-strings"
Tony Barbour18f71552015-04-22 11:36:22 -060060#endif
Tony Barbour18f71552015-04-22 11:36:22 -060061#if defined(__GNUC__)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060062#pragma GCC diagnostic warning "-Wwrite-strings"
Tony Barbour18f71552015-04-22 11:36:22 -060063#endif
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060064#include "vk_struct_size_helper.h"
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060065#include "draw_state.h"
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -060066#include "vk_layer_config.h"
Michael Lentine97eb7462015-11-20 09:48:52 -080067#include "vulkan/vk_debug_marker_layer.h"
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -060068#include "vk_layer_table.h"
69#include "vk_layer_debug_marker_table.h"
70#include "vk_layer_data.h"
71#include "vk_layer_logging.h"
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -060072#include "vk_layer_extension_utils.h"
Tobin Ehlisa1c28562015-10-23 16:00:08 -060073#include "vk_layer_utils.h"
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060074
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -070075// This definition controls whether image layout transitions are enabled/disabled.
Mark Lobodzinski31e5f282015-11-30 16:48:53 -070076// disable until corner cases are fixed
77#define DISABLE_IMAGE_LAYOUT_VALIDATION
78
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070079using std::unordered_map;
80using std::unordered_set;
81
Tobin Ehlisac0ef842015-12-14 13:46:38 -070082// Track command pools and their command buffers
83struct CMD_POOL_INFO {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -070084 VkCommandPoolCreateFlags createFlags;
Michael Lentine26870f32016-01-26 21:36:08 -060085 uint32_t queueFamilyIndex;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -070086 list<VkCommandBuffer> commandBuffers; // list container of cmd buffers allocated from this pool
Tobin Ehlisac0ef842015-12-14 13:46:38 -070087};
88
Tobin Ehlis0b632332015-10-07 09:38:40 -060089struct devExts {
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -070090 VkBool32 debug_marker_enabled;
Michael Lentineabc5e922015-10-12 11:30:14 -050091 VkBool32 wsi_enabled;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -070092 unordered_map<VkSwapchainKHR, SWAPCHAIN_NODE*> swapchainMap;
Tobin Ehlis0b632332015-10-07 09:38:40 -060093};
94
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070095// fwd decls
96struct shader_module;
97struct render_pass;
98
Cody Northrop55443ef2015-09-28 15:09:32 -060099struct layer_data {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700100 debug_report_data* report_data;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700101 std::vector<VkDebugReportCallbackEXT> logging_callback;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700102 VkLayerDispatchTable* device_dispatch_table;
103 VkLayerInstanceDispatchTable* instance_dispatch_table;
Tobin Ehlis0b632332015-10-07 09:38:40 -0600104 devExts device_extensions;
Tobin Ehlisae82e7f2016-01-20 16:23:37 -0700105 vector<VkQueue> queues; // all queues under given device
Tobin Ehlis74714d22016-01-25 15:24:34 -0800106 // Global set of all cmdBuffers that are inFlight on this device
107 unordered_set<VkCommandBuffer> globalInFlightCmdBuffers;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -0600108 // Layer specific data
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700109 unordered_map<VkSampler, unique_ptr<SAMPLER_NODE>> sampleMap;
110 unordered_map<VkImageView, unique_ptr<VkImageViewCreateInfo>> imageViewMap;
111 unordered_map<VkImage, unique_ptr<VkImageCreateInfo>> imageMap;
112 unordered_map<VkBufferView, unique_ptr<VkBufferViewCreateInfo>> bufferViewMap;
113 unordered_map<VkBuffer, BUFFER_NODE> bufferMap;
114 unordered_map<VkPipeline, PIPELINE_NODE*> pipelineMap;
115 unordered_map<VkCommandPool, CMD_POOL_INFO> commandPoolMap;
116 unordered_map<VkDescriptorPool, DESCRIPTOR_POOL_NODE*> descriptorPoolMap;
117 unordered_map<VkDescriptorSet, SET_NODE*> setMap;
118 unordered_map<VkDescriptorSetLayout, LAYOUT_NODE*> descriptorSetLayoutMap;
119 unordered_map<VkPipelineLayout, PIPELINE_LAYOUT_NODE> pipelineLayoutMap;
120 unordered_map<VkDeviceMemory, VkImage> memImageMap;
121 unordered_map<VkFence, FENCE_NODE> fenceMap;
122 unordered_map<VkQueue, QUEUE_NODE> queueMap;
123 unordered_map<VkEvent, EVENT_NODE> eventMap;
124 unordered_map<QueryObject, bool> queryToStateMap;
125 unordered_map<VkSemaphore, uint32_t> semaphoreSignaledMap;
126 unordered_map<void*, GLOBAL_CB_NODE*> commandBufferMap;
127 unordered_map<VkFramebuffer, VkFramebufferCreateInfo*> frameBufferMap;
128 unordered_map<VkImage, IMAGE_NODE*> imageLayoutMap;
129 unordered_map<VkRenderPass, RENDER_PASS_NODE*> renderPassMap;
130 unordered_map<VkShaderModule, shader_module*> shaderModuleMap;
Michael Lentineabc5e922015-10-12 11:30:14 -0500131 // Current render pass
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700132 VkRenderPassBeginInfo renderPassBeginInfo;
133 uint32_t currentSubpass;
Michael Lentine26870f32016-01-26 21:36:08 -0600134
135 // Device specific data
136 PHYS_DEV_PROPERTIES_NODE physDevProperties;
Cody Northrop55443ef2015-09-28 15:09:32 -0600137
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700138 layer_data() :
139 report_data(nullptr),
140 device_dispatch_table(nullptr),
141 instance_dispatch_table(nullptr),
142 device_extensions()
143 {};
Cody Northrop55443ef2015-09-28 15:09:32 -0600144};
Michael Lentine15a47882016-01-06 10:05:48 -0600145
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700146// Code imported from ShaderChecker
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700147static void
148build_def_index(shader_module *);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700149
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700150// A forward iterator over spirv instructions. Provides easy access to len, opcode, and content words
151// without the caller needing to care too much about the physical SPIRV module layout.
Chris Forbesc7e2e202016-01-18 08:56:40 +1300152struct spirv_inst_iter {
153 std::vector<uint32_t>::const_iterator zero;
154 std::vector<uint32_t>::const_iterator it;
155
156 uint32_t len() { return *it >> 16; }
157 uint32_t opcode() { return *it & 0x0ffffu; }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700158 uint32_t const & word(unsigned n) { return it[n]; }
Mark Youngd652d132016-01-25 13:37:06 -0700159 uint32_t offset() { return (uint32_t)(it - zero); }
Chris Forbesc7e2e202016-01-18 08:56:40 +1300160
161 spirv_inst_iter(std::vector<uint32_t>::const_iterator zero,
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700162 std::vector<uint32_t>::const_iterator it) : zero(zero), it(it) {}
Chris Forbesc7e2e202016-01-18 08:56:40 +1300163
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700164 bool operator== (spirv_inst_iter const & other) {
165 return it == other.it;
166 }
Chris Forbesc7e2e202016-01-18 08:56:40 +1300167
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700168 bool operator!= (spirv_inst_iter const & other) {
169 return it != other.it;
170 }
Chris Forbesc7e2e202016-01-18 08:56:40 +1300171
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700172 spirv_inst_iter operator++ (int) { /* x++ */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300173 spirv_inst_iter ii = *this;
174 it += len();
175 return ii;
176 }
177
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700178 spirv_inst_iter operator++ () { /* ++x; */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300179 it += len();
180 return *this;
181 }
182
183 /* The iterator and the value are the same thing. */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700184 spirv_inst_iter & operator* () { return *this; }
185 spirv_inst_iter const & operator* () const { return *this; }
Chris Forbesc7e2e202016-01-18 08:56:40 +1300186};
187
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700188struct shader_module {
189 /* the spirv image itself */
190 vector<uint32_t> words;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700191 /* a mapping of <id> to the first word of its def. this is useful because walking type
192 * trees, constant expressions, etc requires jumping all over the instruction stream.
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700193 */
Chris Forbes21977d92016-01-26 13:41:39 +1300194 unordered_map<unsigned, unsigned> def_index;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700195
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700196 shader_module(VkShaderModuleCreateInfo const *pCreateInfo) :
197 words((uint32_t *)pCreateInfo->pCode, (uint32_t *)pCreateInfo->pCode + pCreateInfo->codeSize / sizeof(uint32_t)),
198 def_index() {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700199
Chris Forbes21977d92016-01-26 13:41:39 +1300200 build_def_index(this);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700201 }
Chris Forbesc7e2e202016-01-18 08:56:40 +1300202
203 /* expose begin() / end() to enable range-based for */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700204 spirv_inst_iter begin() const { return spirv_inst_iter(words.begin(), words.begin() + 5); } /* first insn */
205 spirv_inst_iter end() const { return spirv_inst_iter(words.begin(), words.end()); } /* just past last insn */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300206 /* given an offset into the module, produce an iterator there. */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700207 spirv_inst_iter at(unsigned offset) const { return spirv_inst_iter(words.begin(), words.begin() + offset); }
Chris Forbes1257f912016-01-18 12:07:01 +1300208
Chris Forbes21977d92016-01-26 13:41:39 +1300209 /* gets an iterator to the definition of an id */
210 spirv_inst_iter get_def(unsigned id) const {
211 auto it = def_index.find(id);
212 if (it == def_index.end()) {
Chris Forbes1257f912016-01-18 12:07:01 +1300213 return end();
214 }
215 return at(it->second);
216 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700217};
218
Tobin Ehlisb212dfc2015-10-07 15:40:22 -0600219// TODO : Do we need to guard access to layer_data_map w/ lock?
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700220static unordered_map<void*, layer_data*> layer_data_map;
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -0600221
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600222static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700223// TODO : This can be much smarter, using separate locks for separate global data
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600224static int globalLockInitialized = 0;
225static loader_platform_thread_mutex globalLock;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600226#define MAX_TID 513
227static loader_platform_thread_id g_tidMapping[MAX_TID] = {0};
228static uint32_t g_maxTID = 0;
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600229
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700230template layer_data *get_my_data_ptr<layer_data>(
231 void *data_key,
232 std::unordered_map<void *, layer_data *> &data_map);
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600233
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600234// Map actual TID to an index value and return that index
235// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs
236static uint32_t getTIDIndex() {
237 loader_platform_thread_id tid = loader_platform_get_thread_id();
238 for (uint32_t i = 0; i < g_maxTID; i++) {
239 if (tid == g_tidMapping[i])
240 return i;
241 }
242 // Don't yet have mapping, set it and return newly set index
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700243 uint32_t retVal = (uint32_t) g_maxTID;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600244 g_tidMapping[g_maxTID++] = tid;
245 assert(g_maxTID < MAX_TID);
246 return retVal;
247}
Tobin Ehlis559c6382015-11-05 09:52:49 -0700248
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600249// Return a string representation of CMD_TYPE enum
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700250static string cmdTypeToString(CMD_TYPE cmd)
251{
252 switch (cmd)
253 {
254 case CMD_BINDPIPELINE:
255 return "CMD_BINDPIPELINE";
256 case CMD_BINDPIPELINEDELTA:
257 return "CMD_BINDPIPELINEDELTA";
258 case CMD_SETVIEWPORTSTATE:
259 return "CMD_SETVIEWPORTSTATE";
260 case CMD_SETLINEWIDTHSTATE:
261 return "CMD_SETLINEWIDTHSTATE";
262 case CMD_SETDEPTHBIASSTATE:
263 return "CMD_SETDEPTHBIASSTATE";
264 case CMD_SETBLENDSTATE:
265 return "CMD_SETBLENDSTATE";
266 case CMD_SETDEPTHBOUNDSSTATE:
267 return "CMD_SETDEPTHBOUNDSSTATE";
268 case CMD_SETSTENCILREADMASKSTATE:
269 return "CMD_SETSTENCILREADMASKSTATE";
270 case CMD_SETSTENCILWRITEMASKSTATE:
271 return "CMD_SETSTENCILWRITEMASKSTATE";
272 case CMD_SETSTENCILREFERENCESTATE:
273 return "CMD_SETSTENCILREFERENCESTATE";
274 case CMD_BINDDESCRIPTORSETS:
275 return "CMD_BINDDESCRIPTORSETS";
276 case CMD_BINDINDEXBUFFER:
277 return "CMD_BINDINDEXBUFFER";
278 case CMD_BINDVERTEXBUFFER:
279 return "CMD_BINDVERTEXBUFFER";
280 case CMD_DRAW:
281 return "CMD_DRAW";
282 case CMD_DRAWINDEXED:
283 return "CMD_DRAWINDEXED";
284 case CMD_DRAWINDIRECT:
285 return "CMD_DRAWINDIRECT";
286 case CMD_DRAWINDEXEDINDIRECT:
287 return "CMD_DRAWINDEXEDINDIRECT";
288 case CMD_DISPATCH:
289 return "CMD_DISPATCH";
290 case CMD_DISPATCHINDIRECT:
291 return "CMD_DISPATCHINDIRECT";
292 case CMD_COPYBUFFER:
293 return "CMD_COPYBUFFER";
294 case CMD_COPYIMAGE:
295 return "CMD_COPYIMAGE";
296 case CMD_BLITIMAGE:
297 return "CMD_BLITIMAGE";
298 case CMD_COPYBUFFERTOIMAGE:
299 return "CMD_COPYBUFFERTOIMAGE";
300 case CMD_COPYIMAGETOBUFFER:
301 return "CMD_COPYIMAGETOBUFFER";
302 case CMD_CLONEIMAGEDATA:
303 return "CMD_CLONEIMAGEDATA";
304 case CMD_UPDATEBUFFER:
305 return "CMD_UPDATEBUFFER";
306 case CMD_FILLBUFFER:
307 return "CMD_FILLBUFFER";
308 case CMD_CLEARCOLORIMAGE:
309 return "CMD_CLEARCOLORIMAGE";
310 case CMD_CLEARATTACHMENTS:
311 return "CMD_CLEARCOLORATTACHMENT";
312 case CMD_CLEARDEPTHSTENCILIMAGE:
313 return "CMD_CLEARDEPTHSTENCILIMAGE";
314 case CMD_RESOLVEIMAGE:
315 return "CMD_RESOLVEIMAGE";
316 case CMD_SETEVENT:
317 return "CMD_SETEVENT";
318 case CMD_RESETEVENT:
319 return "CMD_RESETEVENT";
320 case CMD_WAITEVENTS:
321 return "CMD_WAITEVENTS";
322 case CMD_PIPELINEBARRIER:
323 return "CMD_PIPELINEBARRIER";
324 case CMD_BEGINQUERY:
325 return "CMD_BEGINQUERY";
326 case CMD_ENDQUERY:
327 return "CMD_ENDQUERY";
328 case CMD_RESETQUERYPOOL:
329 return "CMD_RESETQUERYPOOL";
330 case CMD_COPYQUERYPOOLRESULTS:
331 return "CMD_COPYQUERYPOOLRESULTS";
332 case CMD_WRITETIMESTAMP:
333 return "CMD_WRITETIMESTAMP";
334 case CMD_INITATOMICCOUNTERS:
335 return "CMD_INITATOMICCOUNTERS";
336 case CMD_LOADATOMICCOUNTERS:
337 return "CMD_LOADATOMICCOUNTERS";
338 case CMD_SAVEATOMICCOUNTERS:
339 return "CMD_SAVEATOMICCOUNTERS";
340 case CMD_BEGINRENDERPASS:
341 return "CMD_BEGINRENDERPASS";
342 case CMD_ENDRENDERPASS:
343 return "CMD_ENDRENDERPASS";
344 case CMD_DBGMARKERBEGIN:
345 return "CMD_DBGMARKERBEGIN";
346 case CMD_DBGMARKEREND:
347 return "CMD_DBGMARKEREND";
348 default:
349 return "UNKNOWN";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600350 }
351}
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700352
353// SPIRV utility functions
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700354static void
355build_def_index(shader_module *module)
356{
Chris Forbesc7e2e202016-01-18 08:56:40 +1300357 for (auto insn : *module) {
358 switch (insn.opcode()) {
Chris Forbes92b9ab02016-01-26 13:49:27 +1300359 /* Types */
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700360 case spv::OpTypeVoid:
361 case spv::OpTypeBool:
362 case spv::OpTypeInt:
363 case spv::OpTypeFloat:
364 case spv::OpTypeVector:
365 case spv::OpTypeMatrix:
366 case spv::OpTypeImage:
367 case spv::OpTypeSampler:
368 case spv::OpTypeSampledImage:
369 case spv::OpTypeArray:
370 case spv::OpTypeRuntimeArray:
371 case spv::OpTypeStruct:
372 case spv::OpTypeOpaque:
373 case spv::OpTypePointer:
374 case spv::OpTypeFunction:
375 case spv::OpTypeEvent:
376 case spv::OpTypeDeviceEvent:
377 case spv::OpTypeReserveId:
378 case spv::OpTypeQueue:
379 case spv::OpTypePipe:
Chris Forbes21977d92016-01-26 13:41:39 +1300380 module->def_index[insn.word(1)] = insn.offset();
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700381 break;
382
Chris Forbes92b9ab02016-01-26 13:49:27 +1300383 /* Fixed constants */
384 case spv::OpConstantTrue:
385 case spv::OpConstantFalse:
386 case spv::OpConstant:
387 case spv::OpConstantComposite:
388 case spv::OpConstantSampler:
389 case spv::OpConstantNull:
390 module->def_index[insn.word(2)] = insn.offset();
391 break;
392
393 /* Specialization constants */
394 case spv::OpSpecConstantTrue:
395 case spv::OpSpecConstantFalse:
396 case spv::OpSpecConstant:
397 case spv::OpSpecConstantComposite:
398 case spv::OpSpecConstantOp:
399 module->def_index[insn.word(2)] = insn.offset();
400 break;
401
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700402 default:
Chris Forbes92b9ab02016-01-26 13:49:27 +1300403 /* We don't care about any other defs for now. */
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700404 break;
405 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700406 }
407}
408
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700409bool
410shader_is_spirv(VkShaderModuleCreateInfo const *pCreateInfo)
411{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700412 uint32_t *words = (uint32_t *)pCreateInfo->pCode;
413 size_t sizeInWords = pCreateInfo->codeSize / sizeof(uint32_t);
414
415 /* Just validate that the header makes sense. */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700416 return sizeInWords >= 5 && words[0] == spv::MagicNumber && words[1] == spv::Version;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700417}
418
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700419static char const *
420storage_class_name(unsigned sc)
421{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700422 switch (sc) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700423 case spv::StorageClassInput: return "input";
424 case spv::StorageClassOutput: return "output";
425 case spv::StorageClassUniformConstant: return "const uniform";
426 case spv::StorageClassUniform: return "uniform";
427 case spv::StorageClassWorkgroup: return "workgroup local";
428 case spv::StorageClassCrossWorkgroup: return "workgroup global";
429 case spv::StorageClassPrivate: return "private global";
430 case spv::StorageClassFunction: return "function";
431 case spv::StorageClassGeneric: return "generic";
432 case spv::StorageClassAtomicCounter: return "atomic counter";
433 case spv::StorageClassImage: return "image";
434 default: return "unknown";
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700435 }
436}
437
Chris Forbes204207a2016-01-26 14:07:16 +1300438/* get the value of an integral constant */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700439unsigned
440get_constant_value(shader_module const *src, unsigned id)
441{
Chris Forbes204207a2016-01-26 14:07:16 +1300442 auto value = src->get_def(id);
443 assert(value != src->end());
444
445 if (value.opcode() != spv::OpConstant) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700446 /* TODO: Either ensure that the specialization transform is already performed on a module we're
Chris Forbes204207a2016-01-26 14:07:16 +1300447 considering here, OR -- specialize on the fly now.
448 */
449 return 1;
450 }
451
452 return value.word(3);
453}
454
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700455/* returns ptr to null terminator */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700456static char *
457describe_type(char *dst, shader_module const *src, unsigned type)
458{
Chris Forbes21977d92016-01-26 13:41:39 +1300459 auto insn = src->get_def(type);
Chris Forbes1257f912016-01-18 12:07:01 +1300460 assert(insn != src->end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700461
Chris Forbes1257f912016-01-18 12:07:01 +1300462 switch (insn.opcode()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700463 case spv::OpTypeBool:
464 return dst + sprintf(dst, "bool");
465 case spv::OpTypeInt:
466 return dst + sprintf(dst, "%cint%d", insn.word(3) ? 's' : 'u', insn.word(2));
467 case spv::OpTypeFloat:
468 return dst + sprintf(dst, "float%d", insn.word(2));
469 case spv::OpTypeVector:
470 dst += sprintf(dst, "vec%d of ", insn.word(3));
471 return describe_type(dst, src, insn.word(2));
472 case spv::OpTypeMatrix:
473 dst += sprintf(dst, "mat%d of ", insn.word(3));
474 return describe_type(dst, src, insn.word(2));
475 case spv::OpTypeArray:
476 dst += sprintf(dst, "arr[%d] of ", get_constant_value(src, insn.word(3)));
477 return describe_type(dst, src, insn.word(2));
478 case spv::OpTypePointer:
479 dst += sprintf(dst, "ptr to %s ", storage_class_name(insn.word(2)));
480 return describe_type(dst, src, insn.word(3));
481 case spv::OpTypeStruct:
482 {
483 dst += sprintf(dst, "struct of (");
484 for (unsigned i = 2; i < insn.len(); i++) {
485 dst = describe_type(dst, src, insn.word(i));
486 dst += sprintf(dst, i == insn.len()-1 ? ")" : ", ");
487 }
488 return dst;
489 }
490 case spv::OpTypeSampler:
491 return dst + sprintf(dst, "sampler");
492 default:
493 return dst + sprintf(dst, "oddtype");
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700494 }
495}
496
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700497static bool
498types_match(shader_module const *a, shader_module const *b, unsigned a_type, unsigned b_type, bool b_arrayed)
499{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700500 /* walk two type trees together, and complain about differences */
Chris Forbes21977d92016-01-26 13:41:39 +1300501 auto a_insn = a->get_def(a_type);
502 auto b_insn = b->get_def(b_type);
Chris Forbes1257f912016-01-18 12:07:01 +1300503 assert(a_insn != a->end());
504 assert(b_insn != b->end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700505
Chris Forbes1257f912016-01-18 12:07:01 +1300506 if (b_arrayed && b_insn.opcode() == spv::OpTypeArray) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700507 /* 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 +1300508 return types_match(a, b, a_type, b_insn.word(2), false);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700509 }
510
Chris Forbes1257f912016-01-18 12:07:01 +1300511 if (a_insn.opcode() != b_insn.opcode()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700512 return false;
513 }
514
Chris Forbes1257f912016-01-18 12:07:01 +1300515 switch (a_insn.opcode()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700516 /* if b_arrayed and we hit a leaf type, then we can't match -- there's nowhere for the extra OpTypeArray to be! */
517 case spv::OpTypeBool:
518 return true && !b_arrayed;
519 case spv::OpTypeInt:
520 /* match on width, signedness */
521 return a_insn.word(2) == b_insn.word(2) && a_insn.word(3) == b_insn.word(3) && !b_arrayed;
522 case spv::OpTypeFloat:
523 /* match on width */
524 return a_insn.word(2) == b_insn.word(2) && !b_arrayed;
525 case spv::OpTypeVector:
526 case spv::OpTypeMatrix:
527 /* match on element type, count. these all have the same layout. we don't get here if
528 * b_arrayed -- that is handled above. */
529 return !b_arrayed &&
530 types_match(a, b, a_insn.word(2), b_insn.word(2), b_arrayed) &&
531 a_insn.word(3) == b_insn.word(3);
532 case spv::OpTypeArray:
533 /* match on element type, count. these all have the same layout. we don't get here if
534 * b_arrayed. This differs from vector & matrix types in that the array size is the id of a constant instruction,
535 * not a literal within OpTypeArray */
536 return !b_arrayed &&
537 types_match(a, b, a_insn.word(2), b_insn.word(2), b_arrayed) &&
538 get_constant_value(a, a_insn.word(3)) == get_constant_value(b, b_insn.word(3));
539 case spv::OpTypeStruct:
540 /* match on all element types */
541 {
542 if (b_arrayed) {
543 /* for the purposes of matching different levels of arrayness, structs are leaves. */
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700544 return false;
545 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700546
547 if (a_insn.len() != b_insn.len()) {
548 return false; /* structs cannot match if member counts differ */
549 }
550
551 for (unsigned i = 2; i < a_insn.len(); i++) {
552 if (!types_match(a, b, a_insn.word(i), b_insn.word(i), b_arrayed)) {
553 return false;
554 }
555 }
556
557 return true;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700558 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700559 case spv::OpTypePointer:
560 /* match on pointee type. storage class is expected to differ */
561 return types_match(a, b, a_insn.word(3), b_insn.word(3), b_arrayed);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700562
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700563 default:
564 /* remaining types are CLisms, or may not appear in the interfaces we
565 * are interested in. Just claim no match.
566 */
567 return false;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700568
569 }
570}
571
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700572static int
573value_or_default(std::unordered_map<unsigned, unsigned> const &map, unsigned id, int def)
574{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700575 auto it = map.find(id);
576 if (it == map.end())
577 return def;
578 else
579 return it->second;
580}
581
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700582
583static unsigned
584get_locations_consumed_by_type(shader_module const *src, unsigned type, bool strip_array_level)
585{
Chris Forbes21977d92016-01-26 13:41:39 +1300586 auto insn = src->get_def(type);
Chris Forbes1257f912016-01-18 12:07:01 +1300587 assert(insn != src->end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700588
Chris Forbesc7e2e202016-01-18 08:56:40 +1300589 switch (insn.opcode()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700590 case spv::OpTypePointer:
591 /* see through the ptr -- this is only ever at the toplevel for graphics shaders;
592 * we're never actually passing pointers around. */
593 return get_locations_consumed_by_type(src, insn.word(3), strip_array_level);
594 case spv::OpTypeArray:
595 if (strip_array_level) {
596 return get_locations_consumed_by_type(src, insn.word(2), false);
597 }
598 else {
599 return get_constant_value(src, insn.word(3)) * get_locations_consumed_by_type(src, insn.word(2), false);
600 }
601 case spv::OpTypeMatrix:
602 /* num locations is the dimension * element size */
603 return insn.word(3) * get_locations_consumed_by_type(src, insn.word(2), false);
604 default:
605 /* everything else is just 1. */
606 return 1;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700607
608 /* TODO: extend to handle 64bit scalar types, whose vectors may need
609 * multiple locations. */
610 }
611}
612
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700613
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700614struct interface_var {
615 uint32_t id;
616 uint32_t type_id;
617 uint32_t offset;
618 /* TODO: collect the name, too? Isn't required to be present. */
619};
620
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700621
622static void
623collect_interface_block_members(layer_data *my_data, VkDevice dev,
624 shader_module const *src,
625 std::map<uint32_t, interface_var> &out,
626 std::map<uint32_t, interface_var> &builtins_out,
627 std::unordered_map<unsigned, unsigned> const &blocks,
628 bool is_array_of_verts,
629 uint32_t id,
630 uint32_t type_id)
631{
632 /* Walk down the type_id presented, trying to determine whether it's actually an interface block. */
Chris Forbes21977d92016-01-26 13:41:39 +1300633 auto type = src->get_def(type_id);
Chris Forbes1257f912016-01-18 12:07:01 +1300634
Chris Forbesa3e85f62016-01-15 14:53:11 +1300635 while (true) {
636
Chris Forbes1257f912016-01-18 12:07:01 +1300637 if (type.opcode() == spv::OpTypePointer) {
Chris Forbes21977d92016-01-26 13:41:39 +1300638 type = src->get_def(type.word(3));
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700639 }
640 else if (type.opcode() == spv::OpTypeArray && is_array_of_verts) {
Chris Forbes21977d92016-01-26 13:41:39 +1300641 type = src->get_def(type.word(2));
Chris Forbesa3e85f62016-01-15 14:53:11 +1300642 is_array_of_verts = false;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700643 }
644 else if (type.opcode() == spv::OpTypeStruct) {
Chris Forbes1257f912016-01-18 12:07:01 +1300645 if (blocks.find(type.word(1)) == blocks.end()) {
Chris Forbesa3e85f62016-01-15 14:53:11 +1300646 /* This isn't an interface block. */
647 return;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700648 }
649 else {
Chris Forbesa3e85f62016-01-15 14:53:11 +1300650 /* We have found the correct type. Walk its members. */
651 break;
652 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700653 }
654 else {
Chris Forbesa3e85f62016-01-15 14:53:11 +1300655 /* not an interface block */
656 return;
657 }
658 }
659
Chris Forbes1257f912016-01-18 12:07:01 +1300660 /* Walk all the OpMemberDecorate for type's result id. */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300661 for (auto insn : *src) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700662 if (insn.opcode() == spv::OpMemberDecorate && insn.word(1) == type.word(1)) {
Chris Forbesc7e2e202016-01-18 08:56:40 +1300663 unsigned member_index = insn.word(2);
Chris Forbes1257f912016-01-18 12:07:01 +1300664 unsigned member_type_id = type.word(2 + member_index);
Chris Forbesa3e85f62016-01-15 14:53:11 +1300665
Chris Forbesc7e2e202016-01-18 08:56:40 +1300666 if (insn.word(3) == spv::DecorationLocation) {
667 unsigned location = insn.word(4);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700668 unsigned num_locations = get_locations_consumed_by_type(src, member_type_id, false);
669 for (unsigned int offset = 0; offset < num_locations; offset++) {
Chris Forbesa3e85f62016-01-15 14:53:11 +1300670 interface_var v;
671 v.id = id;
672 /* TODO: member index in interface_var too? */
673 v.type_id = member_type_id;
674 v.offset = offset;
675 out[location + offset] = v;
676 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700677 }
678 else if (insn.word(3) == spv::DecorationBuiltIn) {
Chris Forbesc7e2e202016-01-18 08:56:40 +1300679 unsigned builtin = insn.word(4);
Chris Forbesa3e85f62016-01-15 14:53:11 +1300680 interface_var v;
681 v.id = id;
682 v.type_id = member_type_id;
683 v.offset = 0;
684 builtins_out[builtin] = v;
685 }
686 }
Chris Forbesa3e85f62016-01-15 14:53:11 +1300687 }
688}
689
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700690static void
691collect_interface_by_location(layer_data *my_data, VkDevice dev,
692 shader_module const *src, spv::StorageClass sinterface,
693 std::map<uint32_t, interface_var> &out,
694 std::map<uint32_t, interface_var> &builtins_out,
695 bool is_array_of_verts)
696{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700697 std::unordered_map<unsigned, unsigned> var_locations;
698 std::unordered_map<unsigned, unsigned> var_builtins;
Chris Forbesa3e85f62016-01-15 14:53:11 +1300699 std::unordered_map<unsigned, unsigned> blocks;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700700
Chris Forbesc7e2e202016-01-18 08:56:40 +1300701 for (auto insn : *src) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700702
703 /* We consider two interface models: SSO rendezvous-by-location, and
704 * builtins. Complain about anything that fits neither model.
705 */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300706 if (insn.opcode() == spv::OpDecorate) {
707 if (insn.word(2) == spv::DecorationLocation) {
708 var_locations[insn.word(1)] = insn.word(3);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700709 }
710
Chris Forbesc7e2e202016-01-18 08:56:40 +1300711 if (insn.word(2) == spv::DecorationBuiltIn) {
712 var_builtins[insn.word(1)] = insn.word(3);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700713 }
Chris Forbesa3e85f62016-01-15 14:53:11 +1300714
Chris Forbesc7e2e202016-01-18 08:56:40 +1300715 if (insn.word(2) == spv::DecorationBlock) {
716 blocks[insn.word(1)] = 1;
Chris Forbesa3e85f62016-01-15 14:53:11 +1300717 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700718 }
719
720 /* TODO: handle grouped decorations */
721 /* TODO: handle index=1 dual source outputs from FS -- two vars will
722 * have the same location, and we DONT want to clobber. */
723
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700724 else if (insn.opcode() == spv::OpVariable && insn.word(3) == sinterface) {
Chris Forbesc7e2e202016-01-18 08:56:40 +1300725 unsigned id = insn.word(2);
726 unsigned type = insn.word(1);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700727
Chris Forbesc7e2e202016-01-18 08:56:40 +1300728 int location = value_or_default(var_locations, id, -1);
729 int builtin = value_or_default(var_builtins, id, -1);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700730
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700731 /* All variables and interface block members in the Input or Output storage classes
Chris Forbesf5020cf2016-01-13 09:29:31 +1300732 * must be decorated with either a builtin or an explicit location.
733 *
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700734 * TODO: integrate the interface block support here. For now, don't complain --
735 * a valid SPIRV module will only hit this path for the interface block case, as the
736 * individual members of the type are decorated, rather than variable declarations.
Chris Forbesf5020cf2016-01-13 09:29:31 +1300737 */
738
739 if (location != -1) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700740 /* A user-defined interface variable, with a location. Where a variable
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700741 * occupied multiple locations, emit one result for each. */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700742 unsigned num_locations = get_locations_consumed_by_type(src, type,
743 is_array_of_verts);
744 for (unsigned int offset = 0; offset < num_locations; offset++) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700745 interface_var v;
746 v.id = id;
747 v.type_id = type;
748 v.offset = offset;
749 out[location + offset] = v;
750 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700751 }
752 else if (builtin != -1) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700753 /* A builtin interface variable */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700754 /* Note that since builtin interface variables do not consume numbered
755 * locations, there is no larger-than-vec4 consideration as above
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700756 */
757 interface_var v;
758 v.id = id;
759 v.type_id = type;
760 v.offset = 0;
761 builtins_out[builtin] = v;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700762 }
763 else {
Chris Forbesa3e85f62016-01-15 14:53:11 +1300764 /* An interface block instance */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700765 collect_interface_block_members(my_data, dev, src, out, builtins_out,
766 blocks, is_array_of_verts, id, type);
Chris Forbesa3e85f62016-01-15 14:53:11 +1300767 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700768 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700769 }
770}
771
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700772static void
773collect_interface_by_descriptor_slot(layer_data *my_data, VkDevice dev,
774 shader_module const *src, spv::StorageClass sinterface,
775 std::map<std::pair<unsigned, unsigned>, interface_var> &out)
776{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700777
778 std::unordered_map<unsigned, unsigned> var_sets;
779 std::unordered_map<unsigned, unsigned> var_bindings;
780
Chris Forbesc7e2e202016-01-18 08:56:40 +1300781 for (auto insn : *src) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700782 /* All variables in the Uniform or UniformConstant storage classes are required to be decorated with both
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700783 * DecorationDescriptorSet and DecorationBinding.
784 */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300785 if (insn.opcode() == spv::OpDecorate) {
786 if (insn.word(2) == spv::DecorationDescriptorSet) {
787 var_sets[insn.word(1)] = insn.word(3);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700788 }
789
Chris Forbesc7e2e202016-01-18 08:56:40 +1300790 if (insn.word(2) == spv::DecorationBinding) {
791 var_bindings[insn.word(1)] = insn.word(3);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700792 }
793 }
794
Chris Forbesc7e2e202016-01-18 08:56:40 +1300795 else if (insn.opcode() == spv::OpVariable &&
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700796 (insn.word(3) == spv::StorageClassUniform ||
797 insn.word(3) == spv::StorageClassUniformConstant)) {
Chris Forbesc7e2e202016-01-18 08:56:40 +1300798 unsigned set = value_or_default(var_sets, insn.word(2), 0);
799 unsigned binding = value_or_default(var_bindings, insn.word(2), 0);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700800
801 auto existing_it = out.find(std::make_pair(set, binding));
802 if (existing_it != out.end()) {
803 /* conflict within spv image */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700804 log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__,
805 SHADER_CHECKER_INCONSISTENT_SPIRV, "SC",
806 "var %d (type %d) in %s interface in descriptor slot (%u,%u) conflicts with existing definition",
807 insn.word(2), insn.word(1), storage_class_name(sinterface),
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700808 existing_it->first.first, existing_it->first.second);
809 }
810
811 interface_var v;
Chris Forbesc7e2e202016-01-18 08:56:40 +1300812 v.id = insn.word(2);
813 v.type_id = insn.word(1);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700814 out[std::make_pair(set, binding)] = v;
815 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700816 }
817}
818
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700819static bool
820validate_interface_between_stages(layer_data *my_data, VkDevice dev,
821 shader_module const *producer, char const *producer_name,
822 shader_module const *consumer, char const *consumer_name,
823 bool consumer_arrayed_input)
824{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700825 std::map<uint32_t, interface_var> outputs;
826 std::map<uint32_t, interface_var> inputs;
827
828 std::map<uint32_t, interface_var> builtin_outputs;
829 std::map<uint32_t, interface_var> builtin_inputs;
830
831 bool pass = true;
832
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700833 collect_interface_by_location(my_data, dev, producer, spv::StorageClassOutput, outputs, builtin_outputs, false);
834 collect_interface_by_location(my_data, dev, consumer, spv::StorageClassInput, inputs, builtin_inputs,
835 consumer_arrayed_input);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700836
837 auto a_it = outputs.begin();
838 auto b_it = inputs.begin();
839
840 /* maps sorted by key (location); walk them together to find mismatches */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700841 while ((outputs.size() > 0 && a_it != outputs.end()) || ( inputs.size() && b_it != inputs.end())) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700842 bool a_at_end = outputs.size() == 0 || a_it == outputs.end();
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700843 bool b_at_end = inputs.size() == 0 || b_it == inputs.end();
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700844 auto a_first = a_at_end ? 0 : a_it->first;
845 auto b_first = b_at_end ? 0 : b_it->first;
846
847 if (b_at_end || ((!a_at_end) && (a_first < b_first))) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700848 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",
849 "%s writes to output location %d which is not consumed by %s", producer_name, a_first, consumer_name)) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700850 pass = false;
851 }
852 a_it++;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700853 }
854 else if (a_at_end || a_first > b_first) {
855 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",
856 "%s consumes input location %d which is not written by %s", consumer_name, b_first, producer_name)) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700857 pass = false;
858 }
859 b_it++;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700860 }
861 else {
862 if (types_match(producer, consumer, a_it->second.type_id, b_it->second.type_id, consumer_arrayed_input)) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700863 /* OK! */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700864 }
865 else {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700866 char producer_type[1024];
867 char consumer_type[1024];
868 describe_type(producer_type, producer, a_it->second.type_id);
869 describe_type(consumer_type, consumer, b_it->second.type_id);
870
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700871 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",
872 "Type mismatch on location %d: '%s' vs '%s'", a_it->first, producer_type, consumer_type)) {
873 pass = false;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700874 }
875 }
876 a_it++;
877 b_it++;
878 }
879 }
880
881 return pass;
882}
883
884enum FORMAT_TYPE {
885 FORMAT_TYPE_UNDEFINED,
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700886 FORMAT_TYPE_FLOAT, /* UNORM, SNORM, FLOAT, USCALED, SSCALED, SRGB -- anything we consider float in the shader */
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700887 FORMAT_TYPE_SINT,
888 FORMAT_TYPE_UINT,
889};
890
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700891static unsigned
892get_format_type(VkFormat fmt) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700893 switch (fmt) {
894 case VK_FORMAT_UNDEFINED:
895 return FORMAT_TYPE_UNDEFINED;
896 case VK_FORMAT_R8_SINT:
897 case VK_FORMAT_R8G8_SINT:
898 case VK_FORMAT_R8G8B8_SINT:
899 case VK_FORMAT_R8G8B8A8_SINT:
900 case VK_FORMAT_R16_SINT:
901 case VK_FORMAT_R16G16_SINT:
902 case VK_FORMAT_R16G16B16_SINT:
903 case VK_FORMAT_R16G16B16A16_SINT:
904 case VK_FORMAT_R32_SINT:
905 case VK_FORMAT_R32G32_SINT:
906 case VK_FORMAT_R32G32B32_SINT:
907 case VK_FORMAT_R32G32B32A32_SINT:
908 case VK_FORMAT_B8G8R8_SINT:
909 case VK_FORMAT_B8G8R8A8_SINT:
910 case VK_FORMAT_A2B10G10R10_SINT_PACK32:
911 case VK_FORMAT_A2R10G10B10_SINT_PACK32:
912 return FORMAT_TYPE_SINT;
913 case VK_FORMAT_R8_UINT:
914 case VK_FORMAT_R8G8_UINT:
915 case VK_FORMAT_R8G8B8_UINT:
916 case VK_FORMAT_R8G8B8A8_UINT:
917 case VK_FORMAT_R16_UINT:
918 case VK_FORMAT_R16G16_UINT:
919 case VK_FORMAT_R16G16B16_UINT:
920 case VK_FORMAT_R16G16B16A16_UINT:
921 case VK_FORMAT_R32_UINT:
922 case VK_FORMAT_R32G32_UINT:
923 case VK_FORMAT_R32G32B32_UINT:
924 case VK_FORMAT_R32G32B32A32_UINT:
925 case VK_FORMAT_B8G8R8_UINT:
926 case VK_FORMAT_B8G8R8A8_UINT:
927 case VK_FORMAT_A2B10G10R10_UINT_PACK32:
928 case VK_FORMAT_A2R10G10B10_UINT_PACK32:
929 return FORMAT_TYPE_UINT;
930 default:
931 return FORMAT_TYPE_FLOAT;
932 }
933}
934
935/* characterizes a SPIR-V type appearing in an interface to a FF stage,
936 * for comparison to a VkFormat's characterization above. */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700937static unsigned
938get_fundamental_type(shader_module const *src, unsigned type)
939{
Chris Forbes21977d92016-01-26 13:41:39 +1300940 auto insn = src->get_def(type);
Chris Forbes1257f912016-01-18 12:07:01 +1300941 assert(insn != src->end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700942
Chris Forbes1257f912016-01-18 12:07:01 +1300943 switch (insn.opcode()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700944 case spv::OpTypeInt:
945 return insn.word(3) ? FORMAT_TYPE_SINT : FORMAT_TYPE_UINT;
946 case spv::OpTypeFloat:
947 return FORMAT_TYPE_FLOAT;
948 case spv::OpTypeVector:
949 return get_fundamental_type(src, insn.word(2));
950 case spv::OpTypeMatrix:
951 return get_fundamental_type(src, insn.word(2));
952 case spv::OpTypeArray:
953 return get_fundamental_type(src, insn.word(2));
954 case spv::OpTypePointer:
955 return get_fundamental_type(src, insn.word(3));
956 default:
957 return FORMAT_TYPE_UNDEFINED;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700958 }
959}
960
961static bool
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700962validate_vi_consistency(layer_data *my_data, VkDevice dev, VkPipelineVertexInputStateCreateInfo const *vi)
963{
964 /* walk the binding descriptions, which describe the step rate and stride of each vertex buffer.
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700965 * each binding should be specified only once.
966 */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700967 std::unordered_map<uint32_t, VkVertexInputBindingDescription const *> bindings;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700968 bool pass = true;
969
970 for (unsigned i = 0; i < vi->vertexBindingDescriptionCount; i++) {
971 auto desc = &vi->pVertexBindingDescriptions[i];
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700972 auto & binding = bindings[desc->binding];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700973 if (binding) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700974 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",
975 "Duplicate vertex input binding descriptions for binding %d", desc->binding)) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700976 pass = false;
977 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700978 }
979 else {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700980 binding = desc;
981 }
982 }
983
984 return pass;
985}
986
987static bool
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700988validate_vi_against_vs_inputs(layer_data *my_data, VkDevice dev, VkPipelineVertexInputStateCreateInfo const *vi, shader_module const *vs)
989{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700990 std::map<uint32_t, interface_var> inputs;
991 /* we collect builtin inputs, but they will never appear in the VI state --
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700992 * the vs builtin inputs are generated in the pipeline, not sourced from buffers (VertexID, etc)
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700993 */
994 std::map<uint32_t, interface_var> builtin_inputs;
995 bool pass = true;
996
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700997 collect_interface_by_location(my_data, dev, vs, spv::StorageClassInput, inputs, builtin_inputs, false);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700998
999 /* Build index by location */
1000 std::map<uint32_t, VkVertexInputAttributeDescription const *> attribs;
1001 if (vi) {
1002 for (unsigned i = 0; i < vi->vertexAttributeDescriptionCount; i++)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001003 attribs[vi->pVertexAttributeDescriptions[i].location] = &vi->pVertexAttributeDescriptions[i];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001004 }
1005
1006 auto it_a = attribs.begin();
1007 auto it_b = inputs.begin();
1008
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001009 while ((attribs.size() > 0 && it_a != attribs.end()) || (inputs.size() > 0 && it_b != inputs.end())) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001010 bool a_at_end = attribs.size() == 0 || it_a == attribs.end();
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001011 bool b_at_end = inputs.size() == 0 || it_b == inputs.end();
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001012 auto a_first = a_at_end ? 0 : it_a->first;
1013 auto b_first = b_at_end ? 0 : it_b->first;
Chris Forbes7d83cd52016-01-15 11:32:03 +13001014 if (!a_at_end && (b_at_end || a_first < b_first)) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001015 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",
1016 "Vertex attribute at location %d not consumed by VS", a_first)) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001017 pass = false;
1018 }
1019 it_a++;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001020 }
1021 else if (!b_at_end && (a_at_end || b_first < a_first)) {
1022 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",
1023 "VS consumes input at location %d but not provided", b_first)) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001024 pass = false;
1025 }
1026 it_b++;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001027 }
1028 else {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001029 unsigned attrib_type = get_format_type(it_a->second->format);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001030 unsigned input_type = get_fundamental_type(vs, it_b->second.type_id);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001031
1032 /* type checking */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001033 if (attrib_type != FORMAT_TYPE_UNDEFINED && input_type != FORMAT_TYPE_UNDEFINED && attrib_type != input_type) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001034 char vs_type[1024];
1035 describe_type(vs_type, vs, it_b->second.type_id);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001036 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",
1037 "Attribute type of `%s` at location %d does not match VS input type of `%s`",
1038 string_VkFormat(it_a->second->format), a_first, vs_type)) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001039 pass = false;
1040 }
1041 }
1042
1043 /* OK! */
1044 it_a++;
1045 it_b++;
1046 }
1047 }
1048
1049 return pass;
1050}
1051
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001052static bool
1053validate_fs_outputs_against_render_pass(layer_data *my_data, VkDevice dev, shader_module const *fs, RENDER_PASS_NODE const *rp, uint32_t subpass)
1054{
1055 const std::vector<VkFormat> &color_formats = rp->subpassColorFormats[subpass];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001056 std::map<uint32_t, interface_var> outputs;
1057 std::map<uint32_t, interface_var> builtin_outputs;
1058 bool pass = true;
1059
1060 /* TODO: dual source blend index (spv::DecIndex, zero if not provided) */
1061
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001062 collect_interface_by_location(my_data, dev, fs, spv::StorageClassOutput, outputs, builtin_outputs, false);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001063
1064 auto it = outputs.begin();
1065 uint32_t attachment = 0;
1066
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001067 /* Walk attachment list and outputs together -- this is a little overpowered since attachments
1068 * are currently dense, but the parallel with matching between shader stages is nice.
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001069 */
1070
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001071 while ((outputs.size() > 0 && it != outputs.end()) || attachment < color_formats.size()) {
1072 if (attachment == color_formats.size() || ( it != outputs.end() && it->first < attachment)) {
1073 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",
1074 "FS writes to output location %d with no matching attachment", it->first)) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001075 pass = false;
1076 }
1077 it++;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001078 }
1079 else if (it == outputs.end() || it->first > attachment) {
1080 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",
1081 "Attachment %d not written by FS", attachment)) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001082 pass = false;
1083 }
1084 attachment++;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001085 }
1086 else {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001087 unsigned output_type = get_fundamental_type(fs, it->second.type_id);
1088 unsigned att_type = get_format_type(color_formats[attachment]);
1089
1090 /* type checking */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001091 if (att_type != FORMAT_TYPE_UNDEFINED && output_type != FORMAT_TYPE_UNDEFINED && att_type != output_type) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001092 char fs_type[1024];
1093 describe_type(fs_type, fs, it->second.type_id);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001094 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",
1095 "Attachment %d of type `%s` does not match FS output type of `%s`",
1096 attachment, string_VkFormat(color_formats[attachment]), fs_type)) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001097 pass = false;
1098 }
1099 }
1100
1101 /* OK! */
1102 it++;
1103 attachment++;
1104 }
1105 }
1106
1107 return pass;
1108}
1109
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001110
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001111struct shader_stage_attributes {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001112 char const * const name;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001113 bool arrayed_input;
1114};
1115
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001116
1117static shader_stage_attributes
1118shader_stage_attribs[] = {
1119 { "vertex shader", false },
1120 { "tessellation control shader", true },
1121 { "tessellation evaluation shader", false },
1122 { "geometry shader", true },
1123 { "fragment shader", false },
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001124};
1125
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001126// For given pipelineLayout verify that the setLayout at slot.first
1127// has the requested binding at slot.second
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001128static bool
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001129has_descriptor_binding(layer_data* my_data,
1130 vector<VkDescriptorSetLayout>* pipelineLayout,
1131 std::pair<unsigned, unsigned> slot)
1132{
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001133 if (!pipelineLayout)
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001134 return false;
1135
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001136 if (slot.first >= pipelineLayout->size())
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001137 return false;
1138
Tobin Ehlis684924e2016-02-02 09:57:25 -07001139 const auto &bindingMap = my_data->descriptorSetLayoutMap[(*pipelineLayout)[slot.first]]
1140 ->bindingToIndexMap;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001141
Tobin Ehlis684924e2016-02-02 09:57:25 -07001142 return (bindingMap.find(slot.second) != bindingMap.end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001143}
1144
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001145static uint32_t get_shader_stage_id(VkShaderStageFlagBits stage)
1146{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001147 uint32_t bit_pos = u_ffs(stage);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001148 return bit_pos-1;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001149}
1150
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001151// Block of code at start here for managing/tracking Pipeline state that this layer cares about
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001152
1153static uint64_t g_drawCount[NUM_DRAW_TYPES] = {0, 0, 0, 0};
1154
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001155// TODO : Should be tracking lastBound per commandBuffer and when draws occur, report based on that cmd buffer lastBound
1156// Then need to synchronize the accesses based on cmd buffer so that if I'm reading state on one cmd buffer, updates
1157// to that same cmd buffer by separate thread are not changing state from underneath us
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001158// Track the last cmd buffer touched by this thread
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001159
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001160// prototype
Ian Elliott8c8b2662016-01-30 10:57:03 -07001161static GLOBAL_CB_NODE* getCBNode(layer_data*, const VkCommandBuffer, bool doLock = true);
Tobin Ehlis559c6382015-11-05 09:52:49 -07001162
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001163static VkBool32 hasDrawCmd(GLOBAL_CB_NODE* pCB)
1164{
1165 for (uint32_t i=0; i<NUM_DRAW_TYPES; i++) {
Tobin Ehlis53eddda2015-07-01 16:46:13 -06001166 if (pCB->drawCount[i])
1167 return VK_TRUE;
1168 }
1169 return VK_FALSE;
1170}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001171
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001172// Check object status for selected flag state
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001173static 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)
1174{
1175 // If non-zero enable mask is present, check it against status but if enable_mask
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001176 // is 0 then no enable required so we should always just check status
1177 if ((!enable_mask) || (enable_mask & pNode->status)) {
1178 if ((pNode->status & status_mask) != status_flag) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001179 // TODO : How to pass dispatchable objects as srcObject? Here src obj should be cmd buffer
1180 return log_msg(my_data->report_data, msg_flags, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, error_code, "DS",
1181 "CB object %#" PRIxLEAST64 ": %s", (uint64_t)(pNode->commandBuffer), fail_msg);
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001182 }
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001183 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001184 return VK_FALSE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001185}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001186
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001187// Retrieve pipeline node ptr for given pipeline object
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001188static PIPELINE_NODE* getPipeline(layer_data* my_data, const VkPipeline pipeline)
1189{
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001190 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08001191 if (my_data->pipelineMap.find(pipeline) == my_data->pipelineMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001192 loader_platform_thread_unlock_mutex(&globalLock);
1193 return NULL;
1194 }
1195 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08001196 return my_data->pipelineMap[pipeline];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001197}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001198
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001199// Return VK_TRUE if for a given PSO, the given state enum is dynamic, else return VK_FALSE
1200static VkBool32 isDynamic(const PIPELINE_NODE* pPipeline, const VkDynamicState state)
1201{
Tobin Ehlisd332f282015-10-02 11:00:56 -06001202 if (pPipeline && pPipeline->graphicsPipelineCI.pDynamicState) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001203 for (uint32_t i=0; i<pPipeline->graphicsPipelineCI.pDynamicState->dynamicStateCount; i++) {
1204 if (state == pPipeline->graphicsPipelineCI.pDynamicState->pDynamicStates[i])
Tobin Ehlisd332f282015-10-02 11:00:56 -06001205 return VK_TRUE;
1206 }
1207 }
1208 return VK_FALSE;
1209}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001210
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001211// Validate state stored as flags at time of draw call
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001212static VkBool32 validate_draw_state_flags(layer_data* my_data, GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06001213 VkBool32 result;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001214 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");
1215 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");
1216 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");
1217 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");
1218 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");
1219 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");
1220 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");
1221 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");
1222 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 -06001223 if (indexedDraw)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001224 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 -06001225 return result;
1226}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001227
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001228// Verify attachment reference compatibility according to spec
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001229// If one array is larger, treat missing elements of shorter array as VK_ATTACHMENT_UNUSED & other array much match this
1230// If both AttachmentReference arrays have requested index, check their corresponding AttachementDescriptions
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001231// to make sure that format and samples counts match.
1232// If not, they are not compatible.
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001233static bool attachment_references_compatible(const uint32_t index, const VkAttachmentReference* pPrimary, const uint32_t primaryCount, const VkAttachmentDescription* pPrimaryAttachments,
1234 const VkAttachmentReference* pSecondary, const uint32_t secondaryCount, const VkAttachmentDescription* pSecondaryAttachments)
1235{
1236 if (index >= primaryCount) { // Check secondary as if primary is VK_ATTACHMENT_UNUSED
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001237 if (VK_ATTACHMENT_UNUSED != pSecondary[index].attachment)
1238 return false;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001239 } else if (index >= secondaryCount) { // Check primary as if secondary is VK_ATTACHMENT_UNUSED
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001240 if (VK_ATTACHMENT_UNUSED != pPrimary[index].attachment)
1241 return false;
1242 } else { // format and sample count must match
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001243 if ((pPrimaryAttachments[pPrimary[index].attachment].format == pSecondaryAttachments[pSecondary[index].attachment].format) &&
1244 (pPrimaryAttachments[pPrimary[index].attachment].samples == pSecondaryAttachments[pSecondary[index].attachment].samples))
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001245 return true;
1246 }
1247 // Format and sample counts didn't match
1248 return false;
1249}
1250
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001251// For give primary and secondary RenderPass objects, verify that they're compatible
1252static bool verify_renderpass_compatibility(layer_data* my_data, const VkRenderPass primaryRP, const VkRenderPass secondaryRP, string& errorMsg)
1253{
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001254 stringstream errorStr;
Ian Elliott8c8b2662016-01-30 10:57:03 -07001255 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001256 if (my_data->renderPassMap.find(primaryRP) == my_data->renderPassMap.end()) {
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001257 errorStr << "invalid VkRenderPass (" << primaryRP << ")";
1258 errorMsg = errorStr.str();
Ian Elliott8c8b2662016-01-30 10:57:03 -07001259 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001260 return false;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001261 } else if (my_data->renderPassMap.find(secondaryRP) == my_data->renderPassMap.end()) {
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001262 errorStr << "invalid VkRenderPass (" << secondaryRP << ")";
1263 errorMsg = errorStr.str();
Ian Elliott8c8b2662016-01-30 10:57:03 -07001264 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001265 return false;
1266 }
1267 // Trivial pass case is exact same RP
Ian Elliott8c8b2662016-01-30 10:57:03 -07001268 if (primaryRP == secondaryRP) {
1269 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001270 return true;
Ian Elliott8c8b2662016-01-30 10:57:03 -07001271 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001272 const VkRenderPassCreateInfo* primaryRPCI = my_data->renderPassMap[primaryRP]->pCreateInfo;
1273 const VkRenderPassCreateInfo* secondaryRPCI = my_data->renderPassMap[secondaryRP]->pCreateInfo;
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001274 if (primaryRPCI->subpassCount != secondaryRPCI->subpassCount) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001275 errorStr << "RenderPass for primary cmdBuffer has " << primaryRPCI->subpassCount << " subpasses but renderPass for secondary cmdBuffer has " << secondaryRPCI->subpassCount << " subpasses.";
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001276 errorMsg = errorStr.str();
Ian Elliott8c8b2662016-01-30 10:57:03 -07001277 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001278 return false;
1279 }
1280 uint32_t spIndex = 0;
1281 for (spIndex = 0; spIndex < primaryRPCI->subpassCount; ++spIndex) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001282 // For each subpass, verify that corresponding color, input, resolve & depth/stencil attachment references are compatible
1283 uint32_t primaryColorCount = primaryRPCI->pSubpasses[spIndex].colorAttachmentCount;
1284 uint32_t secondaryColorCount = secondaryRPCI->pSubpasses[spIndex].colorAttachmentCount;
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001285 uint32_t colorMax = std::max(primaryColorCount, secondaryColorCount);
1286 for (uint32_t cIdx = 0; cIdx < colorMax; ++cIdx) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001287 if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pColorAttachments, primaryColorCount, primaryRPCI->pAttachments,
1288 secondaryRPCI->pSubpasses[spIndex].pColorAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1289 errorStr << "color attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001290 errorMsg = errorStr.str();
Ian Elliott8c8b2662016-01-30 10:57:03 -07001291 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001292 return false;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001293 } else if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pResolveAttachments, primaryColorCount, primaryRPCI->pAttachments,
1294 secondaryRPCI->pSubpasses[spIndex].pResolveAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1295 errorStr << "resolve attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001296 errorMsg = errorStr.str();
Ian Elliott8c8b2662016-01-30 10:57:03 -07001297 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001298 return false;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001299 } else if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pDepthStencilAttachment, primaryColorCount, primaryRPCI->pAttachments,
1300 secondaryRPCI->pSubpasses[spIndex].pDepthStencilAttachment, secondaryColorCount, secondaryRPCI->pAttachments)) {
1301 errorStr << "depth/stencil attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001302 errorMsg = errorStr.str();
Ian Elliott8c8b2662016-01-30 10:57:03 -07001303 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001304 return false;
1305 }
1306 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001307 uint32_t primaryInputCount = primaryRPCI->pSubpasses[spIndex].inputAttachmentCount;
1308 uint32_t secondaryInputCount = secondaryRPCI->pSubpasses[spIndex].inputAttachmentCount;
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001309 uint32_t inputMax = std::max(primaryInputCount, secondaryInputCount);
1310 for (uint32_t i = 0; i < inputMax; ++i) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001311 if (!attachment_references_compatible(i, primaryRPCI->pSubpasses[spIndex].pInputAttachments, primaryColorCount, primaryRPCI->pAttachments,
1312 secondaryRPCI->pSubpasses[spIndex].pInputAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1313 errorStr << "input attachments at index " << i << " of subpass index " << spIndex << " are not compatible.";
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001314 errorMsg = errorStr.str();
Ian Elliott8c8b2662016-01-30 10:57:03 -07001315 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001316 return false;
1317 }
1318 }
1319 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07001320 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001321 return true;
1322}
1323
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001324// For give SET_NODE, verify that its Set is compatible w/ the setLayout corresponding to pipelineLayout[layoutIndex]
1325static bool verify_set_layout_compatibility(layer_data* my_data, const SET_NODE* pSet, const VkPipelineLayout layout, const uint32_t layoutIndex, string& errorMsg)
1326{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001327 stringstream errorStr;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001328 if (my_data->pipelineLayoutMap.find(layout) == my_data->pipelineLayoutMap.end()) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001329 errorStr << "invalid VkPipelineLayout (" << layout << ")";
1330 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001331 return false;
1332 }
1333 PIPELINE_LAYOUT_NODE pl = my_data->pipelineLayoutMap[layout];
1334 if (layoutIndex >= pl.descriptorSetLayouts.size()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001335 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;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001336 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001337 return false;
1338 }
1339 // Get the specific setLayout from PipelineLayout that overlaps this set
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001340 LAYOUT_NODE* pLayoutNode = my_data->descriptorSetLayoutMap[pl.descriptorSetLayouts[layoutIndex]];
Tobin Ehlis559c6382015-11-05 09:52:49 -07001341 if (pLayoutNode->layout == pSet->pLayout->layout) { // trivial pass case
1342 return true;
1343 }
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07001344 size_t descriptorCount = pLayoutNode->descriptorTypes.size();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001345 if (descriptorCount != pSet->pLayout->descriptorTypes.size()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001346 errorStr << "setLayout " << layoutIndex << " from pipelineLayout " << layout << " has " << descriptorCount << " descriptors, but corresponding set being bound has " << pSet->pLayout->descriptorTypes.size() << " descriptors.";
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001347 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001348 return false; // trivial fail case
1349 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001350 // Now need to check set against corresponding pipelineLayout to verify compatibility
1351 for (size_t i=0; i<descriptorCount; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07001352 // Need to verify that layouts are identically defined
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001353 // TODO : Is below sufficient? Making sure that types & stageFlags match per descriptor
Tobin Ehlis559c6382015-11-05 09:52:49 -07001354 // do we also need to check immutable samplers?
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001355 if (pLayoutNode->descriptorTypes[i] != pSet->pLayout->descriptorTypes[i]) {
1356 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]) << "'";
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001357 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001358 return false;
1359 }
1360 if (pLayoutNode->stageFlags[i] != pSet->pLayout->stageFlags[i]) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001361 errorStr << "stageFlags " << i << " for descriptorSet being bound is " << pSet->pLayout->stageFlags[i] << "' but corresponding descriptor from pipelineLayout has stageFlags " << pLayoutNode->stageFlags[i];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001362 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001363 return false;
1364 }
1365 }
1366 return true;
1367}
1368
Tobin Ehlis88452832015-12-03 09:40:56 -07001369// Validate that the shaders used by the given pipeline
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001370// As a side effect this function also records the sets that are actually used by the pipeline
1371static VkBool32
1372validate_pipeline_shaders(layer_data *my_data, VkDevice dev, PIPELINE_NODE* pPipeline)
1373{
1374 VkGraphicsPipelineCreateInfo const *pCreateInfo = &pPipeline->graphicsPipelineCI;
1375 /* We seem to allow pipeline stages to be specified out of order, so collect and identify them
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001376 * before trying to do anything more: */
1377 int vertex_stage = get_shader_stage_id(VK_SHADER_STAGE_VERTEX_BIT);
1378 int geometry_stage = get_shader_stage_id(VK_SHADER_STAGE_GEOMETRY_BIT);
1379 int fragment_stage = get_shader_stage_id(VK_SHADER_STAGE_FRAGMENT_BIT);
1380
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001381 shader_module **shaders = new shader_module*[fragment_stage + 1]; /* exclude CS */
1382 memset(shaders, 0, sizeof(shader_module *) * (fragment_stage +1));
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001383 RENDER_PASS_NODE const *rp = 0;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001384 VkPipelineVertexInputStateCreateInfo const *vi = 0;
Mark Youngb20a6a82016-01-07 15:41:43 -07001385 VkBool32 pass = VK_TRUE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001386
1387 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001388 VkPipelineShaderStageCreateInfo const *pStage = &pCreateInfo->pStages[i];
1389 if (pStage->sType == VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001390
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001391 if ((pStage->stage & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_GEOMETRY_BIT | VK_SHADER_STAGE_FRAGMENT_BIT
1392 | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT)) == 0) {
1393 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",
1394 "Unknown shader stage %d", pStage->stage)) {
Mark Youngb20a6a82016-01-07 15:41:43 -07001395 pass = VK_FALSE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001396 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001397 }
1398 else {
1399 shader_module *module = my_data->shaderModuleMap[pStage->module];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001400 shaders[get_shader_stage_id(pStage->stage)] = module;
1401
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001402 /* validate descriptor set layout against what the spirv module actually uses */
1403 std::map<std::pair<unsigned, unsigned>, interface_var> descriptor_uses;
1404 collect_interface_by_descriptor_slot(my_data, dev, module, spv::StorageClassUniform,
1405 descriptor_uses);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001406
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001407 auto layouts = pCreateInfo->layout != VK_NULL_HANDLE ?
1408 &(my_data->pipelineLayoutMap[pCreateInfo->layout].descriptorSetLayouts) : nullptr;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001409
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001410 for (auto it = descriptor_uses.begin(); it != descriptor_uses.end(); it++) {
1411 // As a side-effect of this function, capture which sets are used by the pipeline
Tobin Ehlis88452832015-12-03 09:40:56 -07001412 pPipeline->active_sets.insert(it->first.first);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001413
1414 /* find the matching binding */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001415 auto found = has_descriptor_binding(my_data, layouts, it->first);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001416
1417 if (!found) {
1418 char type_name[1024];
1419 describe_type(type_name, module, it->second.type_id);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001420 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__,
1421 SHADER_CHECKER_MISSING_DESCRIPTOR, "SC",
1422 "Shader uses descriptor slot %u.%u (used as type `%s`) but not declared in pipeline layout",
1423 it->first.first, it->first.second, type_name)) {
Mark Youngb20a6a82016-01-07 15:41:43 -07001424 pass = VK_FALSE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001425 }
1426 }
1427 }
1428 }
1429 }
1430 }
1431
1432 if (pCreateInfo->renderPass != VK_NULL_HANDLE)
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001433 rp = my_data->renderPassMap[pCreateInfo->renderPass];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001434
1435 vi = pCreateInfo->pVertexInputState;
1436
1437 if (vi) {
1438 pass = validate_vi_consistency(my_data, dev, vi) && pass;
1439 }
1440
1441 if (shaders[vertex_stage]) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001442 pass = validate_vi_against_vs_inputs(my_data, dev, vi, shaders[vertex_stage]) && pass;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001443 }
1444
1445 /* TODO: enforce rules about present combinations of shaders */
1446 int producer = get_shader_stage_id(VK_SHADER_STAGE_VERTEX_BIT);
1447 int consumer = get_shader_stage_id(VK_SHADER_STAGE_GEOMETRY_BIT);
1448
1449 while (!shaders[producer] && producer != fragment_stage) {
1450 producer++;
1451 consumer++;
1452 }
1453
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001454 for (; producer != fragment_stage && consumer <= fragment_stage; consumer++) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001455 assert(shaders[producer]);
1456 if (shaders[consumer]) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001457 pass = validate_interface_between_stages(my_data, dev,
1458 shaders[producer], shader_stage_attribs[producer].name,
1459 shaders[consumer], shader_stage_attribs[consumer].name,
1460 shader_stage_attribs[consumer].arrayed_input) && pass;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001461
1462 producer = consumer;
1463 }
1464 }
1465
1466 if (shaders[fragment_stage] && rp) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001467 pass = validate_fs_outputs_against_render_pass(my_data, dev, shaders[fragment_stage], rp, pCreateInfo->subpass) && pass;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001468 }
1469
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001470 delete [] shaders;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001471
1472 return pass;
1473}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001474
Tobin Ehlisf6585052015-12-17 11:48:42 -07001475// Return Set node ptr for specified set or else NULL
Ian Elliott8c8b2662016-01-30 10:57:03 -07001476static SET_NODE* getSetNode(layer_data* my_data, const VkDescriptorSet set, bool doLock = true)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001477{
Ian Elliott8c8b2662016-01-30 10:57:03 -07001478 if (doLock) {
1479 loader_platform_thread_lock_mutex(&globalLock);
1480 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07001481 if (my_data->setMap.find(set) == my_data->setMap.end()) {
Ian Elliott8c8b2662016-01-30 10:57:03 -07001482 if (doLock) {
1483 loader_platform_thread_unlock_mutex(&globalLock);
1484 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07001485 return NULL;
1486 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07001487 SET_NODE *rtn = my_data->setMap[set];
1488 if (doLock) {
1489 loader_platform_thread_unlock_mutex(&globalLock);
1490 }
1491 return rtn;
Tobin Ehlisf6585052015-12-17 11:48:42 -07001492}
Tobin Ehlisd2393772016-01-29 11:50:47 -07001493// For the given command buffer, verify that for each set set in activeSetNodes
1494// that any dynamic descriptor in that set has a valid dynamic offset bound.
1495// To be valid, the dynamic offset combined with the offet and range from its
1496// descriptor update must not overflow the size of its buffer being updated
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001497static VkBool32 validate_dynamic_offsets(layer_data* my_data, const GLOBAL_CB_NODE* pCB, const vector<SET_NODE*> activeSetNodes)
1498{
Tobin Ehlisf6585052015-12-17 11:48:42 -07001499 VkBool32 result = VK_FALSE;
Tobin Ehlisf6585052015-12-17 11:48:42 -07001500
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001501 VkWriteDescriptorSet* pWDS = NULL;
Tobin Ehlisf6585052015-12-17 11:48:42 -07001502 uint32_t dynOffsetIndex = 0;
1503 VkDeviceSize bufferSize = 0;
Tobin Ehlisd2393772016-01-29 11:50:47 -07001504 for (auto set_node : activeSetNodes) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001505 for (uint32_t i=0; i < set_node->descriptorCount; ++i) {
Tobin Ehlisd2393772016-01-29 11:50:47 -07001506 switch (set_node->ppDescriptors[i]->sType) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001507 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1508 pWDS = (VkWriteDescriptorSet*)set_node->ppDescriptors[i];
1509 if ((pWDS->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
1510 (pWDS->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
1511 for (uint32_t j=0; j<pWDS->descriptorCount; ++j) {
1512 bufferSize = my_data->bufferMap[pWDS->pBufferInfo[j].buffer].create_info->size;
1513 if ((pCB->dynamicOffsets[dynOffsetIndex] + pWDS->pBufferInfo[j].offset + pWDS->pBufferInfo[j].range) > bufferSize) {
1514 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t)set_node->set, __LINE__, DRAWSTATE_DYNAMIC_OFFSET_OVERFLOW, "DS",
1515 "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 ".",
1516 (uint64_t)set_node->set, i, pCB->dynamicOffsets[dynOffsetIndex], pWDS->pBufferInfo[j].offset, pWDS->pBufferInfo[j].range, (uint64_t)pWDS->pBufferInfo[j].buffer, bufferSize);
1517 }
1518 dynOffsetIndex++;
1519 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)
Tobin Ehlisf6585052015-12-17 11:48:42 -07001520 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07001521 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001522 break;
1523 default: // Currently only shadowing Write update nodes so shouldn't get here
1524 assert(0);
1525 continue;
Tobin Ehlisd2393772016-01-29 11:50:47 -07001526 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07001527 }
1528 }
1529 return result;
1530}
1531
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001532// Validate overall state at the time of a draw call
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001533static VkBool32 validate_draw_state(layer_data* my_data, GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001534 // First check flag states
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001535 VkBool32 result = validate_draw_state_flags(my_data, pCB, indexedDraw);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001536 PIPELINE_NODE* pPipe = getPipeline(my_data, pCB->lastBoundPipeline);
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001537 // Now complete other state checks
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001538 // TODO : Currently only performing next check if *something* was bound (non-zero last bound)
1539 // There is probably a better way to gate when this check happens, and to know if something *should* have been bound
1540 // We should have that check separately and then gate this check based on that check
Mark Lobodzinski74635932015-12-18 15:35:38 -07001541 if (pPipe) {
Tobin Ehlisd2393772016-01-29 11:50:47 -07001542 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski74635932015-12-18 15:35:38 -07001543 if (pCB->lastBoundPipelineLayout) {
1544 string errorString;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001545 // Need a vector (vs. std::set) of active Sets for dynamicOffset validation in case same set bound w/ different offsets
1546 vector<SET_NODE*> activeSetNodes;
Mark Lobodzinski74635932015-12-18 15:35:38 -07001547 for (auto setIndex : pPipe->active_sets) {
1548 // If valid set is not bound throw an error
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001549 if ((pCB->boundDescriptorSets.size() <= setIndex) || (!pCB->boundDescriptorSets[setIndex])) {
1550 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_DESCRIPTOR_SET_NOT_BOUND, "DS",
1551 "VkPipeline %#" PRIxLEAST64 " uses set #%u but that set is not bound.", (uint64_t)pPipe->pipeline, setIndex);
1552 } else if (!verify_set_layout_compatibility(my_data, my_data->setMap[pCB->boundDescriptorSets[setIndex]], pPipe->graphicsPipelineCI.layout, setIndex, errorString)) {
1553 // Set is bound but not compatible w/ overlapping pipelineLayout from PSO
1554 VkDescriptorSet setHandle = my_data->setMap[pCB->boundDescriptorSets[setIndex]]->set;
1555 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",
1556 "VkDescriptorSet (%#" PRIxLEAST64 ") bound as set #%u is not compatible with overlapping VkPipelineLayout %#" PRIxLEAST64 " due to: %s",
1557 (uint64_t)setHandle, setIndex, (uint64_t)pPipe->graphicsPipelineCI.layout, errorString.c_str());
1558 } else { // Valid set is bound and layout compatible, validate that it's updated and verify any dynamic offsets
Tobin Ehlis43c39c02016-01-11 13:18:40 -07001559 // Pull the set node
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001560 SET_NODE* pSet = my_data->setMap[pCB->boundDescriptorSets[setIndex]];
1561 // Save vector of all active sets to verify dynamicOffsets below
Tobin Ehlisd2393772016-01-29 11:50:47 -07001562 activeSetNodes.push_back(pSet);
Tobin Ehlis43c39c02016-01-11 13:18:40 -07001563 // Make sure set has been updated
1564 if (!pSet->pUpdateStructs) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001565 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",
1566 "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);
Tobin Ehlis43c39c02016-01-11 13:18:40 -07001567 }
Mark Lobodzinski74635932015-12-18 15:35:38 -07001568 }
Tobin Ehlis88452832015-12-03 09:40:56 -07001569 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001570 // For each dynamic descriptor, make sure dynamic offset doesn't overstep buffer
Tobin Ehlisd2393772016-01-29 11:50:47 -07001571 if (!pCB->dynamicOffsets.empty())
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001572 result |= validate_dynamic_offsets(my_data, pCB, activeSetNodes);
Tobin Ehlis88452832015-12-03 09:40:56 -07001573 }
Mark Lobodzinski74635932015-12-18 15:35:38 -07001574 // Verify Vtx binding
1575 if (pPipe->vtxBindingCount > 0) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001576 VkPipelineVertexInputStateCreateInfo *vtxInCI = &pPipe->vertexInputCI;
1577 for (uint32_t i = 0; i < vtxInCI->vertexBindingDescriptionCount; i++) {
1578 if ((pCB->currentDrawData.buffers.size() < (i+1)) || (pCB->currentDrawData.buffers[i] == VK_NULL_HANDLE)) {
1579 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS",
1580 "The Pipeline State Object (%#" PRIxLEAST64 ") expects that this Command Buffer's vertex binding Index %d should be set via vkCmdBindVertexBuffers.",
Mark Lobodzinski74635932015-12-18 15:35:38 -07001581 (uint64_t)pCB->lastBoundPipeline, i);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001582
Mark Lobodzinski74635932015-12-18 15:35:38 -07001583 }
1584 }
1585 } else {
Michael Lentine700b0aa2015-10-30 17:57:32 -07001586 if (!pCB->currentDrawData.buffers.empty()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001587 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS,
1588 "DS", "Vertex buffers are bound to command buffer (%#" PRIxLEAST64 ") but no vertex buffers are attached to this Pipeline State Object (%#" PRIxLEAST64 ").",
1589 (uint64_t)pCB->commandBuffer, (uint64_t)pCB->lastBoundPipeline);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06001590 }
1591 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001592 // If Viewport or scissors are dynamic, verify that dynamic count matches PSO count
Mark Lobodzinski74635932015-12-18 15:35:38 -07001593 VkBool32 dynViewport = isDynamic(pPipe, VK_DYNAMIC_STATE_VIEWPORT);
1594 VkBool32 dynScissor = isDynamic(pPipe, VK_DYNAMIC_STATE_SCISSOR);
1595 if (dynViewport) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001596 if (pCB->viewports.size() != pPipe->graphicsPipelineCI.pViewportState->viewportCount) {
1597 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
1598 "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);
Mark Lobodzinski74635932015-12-18 15:35:38 -07001599 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001600 }
Mark Lobodzinski74635932015-12-18 15:35:38 -07001601 if (dynScissor) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001602 if (pCB->scissors.size() != pPipe->graphicsPipelineCI.pViewportState->scissorCount) {
1603 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
1604 "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);
Mark Lobodzinski74635932015-12-18 15:35:38 -07001605 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001606 }
Tobin Ehlisd2393772016-01-29 11:50:47 -07001607 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisd332f282015-10-02 11:00:56 -06001608 }
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001609 return result;
1610}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001611
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001612// Verify that create state for a pipeline is valid
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001613static VkBool32 verifyPipelineCreateState(layer_data* my_data, const VkDevice device, PIPELINE_NODE* pPipeline)
1614{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001615 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski2fd2d032015-12-16 14:25:22 -07001616
Tobin Ehlis88452832015-12-03 09:40:56 -07001617 if (!validate_pipeline_shaders(my_data, device, pPipeline)) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001618 skipCall = VK_TRUE;
1619 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001620 // VS is required
1621 if (!(pPipeline->active_shaders & VK_SHADER_STAGE_VERTEX_BIT)) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001622 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
1623 "Invalid Pipeline CreateInfo State: Vtx Shader required");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001624 }
1625 // Either both or neither TC/TE shaders should be defined
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001626 if (((pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) == 0) !=
1627 ((pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) == 0) ) {
1628 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
1629 "Invalid Pipeline CreateInfo State: TE and TC shaders must be included or excluded as a pair");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001630 }
1631 // Compute shaders should be specified independent of Gfx shaders
1632 if ((pPipeline->active_shaders & VK_SHADER_STAGE_COMPUTE_BIT) &&
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001633 (pPipeline->active_shaders & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT |
1634 VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT | VK_SHADER_STAGE_GEOMETRY_BIT |
1635 VK_SHADER_STAGE_FRAGMENT_BIT))) {
1636 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
1637 "Invalid Pipeline CreateInfo State: Do not specify Compute Shader for Gfx Pipeline");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001638 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001639 // VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology is only valid for tessellation pipelines.
1640 // Mismatching primitive topology and tessellation fails graphics pipeline creation.
1641 if (pPipeline->active_shaders & (VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) &&
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001642 (pPipeline->iaStateCI.topology != VK_PRIMITIVE_TOPOLOGY_PATCH_LIST)) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001643 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
1644 "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 -06001645 }
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001646 if (pPipeline->iaStateCI.topology == VK_PRIMITIVE_TOPOLOGY_PATCH_LIST) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001647 if (~pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) {
1648 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
1649 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology is only valid for tessellation pipelines");
Tobin Ehlis912df022015-09-17 08:46:18 -06001650 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001651 if (!pPipeline->tessStateCI.patchControlPoints || (pPipeline->tessStateCI.patchControlPoints > 32)) {
1652 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
1653 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology used with patchControlPoints value %u."
1654 " patchControlPoints should be >0 and <=32.", pPipeline->tessStateCI.patchControlPoints);
Tobin Ehlis912df022015-09-17 08:46:18 -06001655 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001656 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001657 // Viewport state must be included and viewport and scissor counts should always match
1658 // NOTE : Even if these are flagged as dynamic, counts need to be set correctly for shader compiler
Tobin Ehlisd332f282015-10-02 11:00:56 -06001659 if (!pPipeline->graphicsPipelineCI.pViewportState) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001660 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
1661 "Gfx Pipeline pViewportState is null. Even if viewport and scissors are dynamic PSO must include viewportCount and scissorCount in pViewportState.");
1662 } else if (pPipeline->graphicsPipelineCI.pViewportState->scissorCount != pPipeline->graphicsPipelineCI.pViewportState->viewportCount) {
1663 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
1664 "Gfx Pipeline viewport count (%u) must match scissor count (%u).", pPipeline->vpStateCI.viewportCount, pPipeline->vpStateCI.scissorCount);
Tobin Ehlisd332f282015-10-02 11:00:56 -06001665 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001666 // If viewport or scissor are not dynamic, then verify that data is appropriate for count
Tobin Ehlisd332f282015-10-02 11:00:56 -06001667 VkBool32 dynViewport = isDynamic(pPipeline, VK_DYNAMIC_STATE_VIEWPORT);
1668 VkBool32 dynScissor = isDynamic(pPipeline, VK_DYNAMIC_STATE_SCISSOR);
1669 if (!dynViewport) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001670 if (pPipeline->graphicsPipelineCI.pViewportState->viewportCount && !pPipeline->graphicsPipelineCI.pViewportState->pViewports) {
1671 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
1672 "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 -06001673 }
1674 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001675 if (!dynScissor) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001676 if (pPipeline->graphicsPipelineCI.pViewportState->scissorCount && !pPipeline->graphicsPipelineCI.pViewportState->pScissors) {
1677 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
1678 "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 -06001679 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06001680 }
1681 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001682 return skipCall;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001683}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001684
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001685// Init the pipeline mapping info based on pipeline create info LL tree
1686// Threading note : Calls to this function should wrapped in mutex
Tobin Ehlis88452832015-12-03 09:40:56 -07001687// TODO : this should really just be in the constructor for PIPELINE_NODE
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001688static PIPELINE_NODE* initGraphicsPipeline(layer_data* dev_data, const VkGraphicsPipelineCreateInfo* pCreateInfo, PIPELINE_NODE* pBasePipeline)
1689{
1690 PIPELINE_NODE* pPipeline = new PIPELINE_NODE;
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001691
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001692 if (pBasePipeline) {
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001693 *pPipeline = *pBasePipeline;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001694 }
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001695
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001696 // First init create info
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001697 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001698
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001699 size_t bufferSize = 0;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001700 const VkPipelineVertexInputStateCreateInfo* pVICI = NULL;
1701 const VkPipelineColorBlendStateCreateInfo* pCBCI = NULL;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001702
1703 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001704 const VkPipelineShaderStageCreateInfo *pPSSCI = &pCreateInfo->pStages[i];
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001705
Chia-I Wu28e06912015-10-31 00:31:16 +08001706 switch (pPSSCI->stage) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001707 case VK_SHADER_STAGE_VERTEX_BIT:
1708 memcpy(&pPipeline->vsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1709 pPipeline->active_shaders |= VK_SHADER_STAGE_VERTEX_BIT;
1710 break;
1711 case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT:
1712 memcpy(&pPipeline->tcsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1713 pPipeline->active_shaders |= VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
1714 break;
1715 case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT:
1716 memcpy(&pPipeline->tesCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1717 pPipeline->active_shaders |= VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
1718 break;
1719 case VK_SHADER_STAGE_GEOMETRY_BIT:
1720 memcpy(&pPipeline->gsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1721 pPipeline->active_shaders |= VK_SHADER_STAGE_GEOMETRY_BIT;
1722 break;
1723 case VK_SHADER_STAGE_FRAGMENT_BIT:
1724 memcpy(&pPipeline->fsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1725 pPipeline->active_shaders |= VK_SHADER_STAGE_FRAGMENT_BIT;
1726 break;
1727 case VK_SHADER_STAGE_COMPUTE_BIT:
1728 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
1729 pPipeline->active_shaders |= VK_SHADER_STAGE_COMPUTE_BIT;
1730 break;
1731 default:
1732 // TODO : Flag error
1733 break;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001734 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001735 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001736 // Copy over GraphicsPipelineCreateInfo structure embedded pointers
1737 if (pCreateInfo->stageCount != 0) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001738 pPipeline->graphicsPipelineCI.pStages = new VkPipelineShaderStageCreateInfo[pCreateInfo->stageCount];
1739 bufferSize = pCreateInfo->stageCount * sizeof(VkPipelineShaderStageCreateInfo);
1740 memcpy((void*)pPipeline->graphicsPipelineCI.pStages, pCreateInfo->pStages, bufferSize);
Tobin Ehlis963a4042015-09-29 08:18:34 -06001741 }
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001742 if (pCreateInfo->pVertexInputState != NULL) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001743 memcpy((void*)&pPipeline->vertexInputCI, pCreateInfo->pVertexInputState , sizeof(VkPipelineVertexInputStateCreateInfo));
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001744 // Copy embedded ptrs
1745 pVICI = pCreateInfo->pVertexInputState;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001746 pPipeline->vtxBindingCount = pVICI->vertexBindingDescriptionCount;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001747 if (pPipeline->vtxBindingCount) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001748 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
1749 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
1750 memcpy((void*)pPipeline->pVertexBindingDescriptions, pVICI->pVertexBindingDescriptions, bufferSize);
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001751 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08001752 pPipeline->vtxAttributeCount = pVICI->vertexAttributeDescriptionCount;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001753 if (pPipeline->vtxAttributeCount) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001754 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
1755 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
1756 memcpy((void*)pPipeline->pVertexAttributeDescriptions, pVICI->pVertexAttributeDescriptions, bufferSize);
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001757 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001758 pPipeline->graphicsPipelineCI.pVertexInputState = &pPipeline->vertexInputCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001759 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001760 if (pCreateInfo->pInputAssemblyState != NULL) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001761 memcpy((void*)&pPipeline->iaStateCI, pCreateInfo->pInputAssemblyState, sizeof(VkPipelineInputAssemblyStateCreateInfo));
1762 pPipeline->graphicsPipelineCI.pInputAssemblyState = &pPipeline->iaStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001763 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001764 if (pCreateInfo->pTessellationState != NULL) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001765 memcpy((void*)&pPipeline->tessStateCI, pCreateInfo->pTessellationState, sizeof(VkPipelineTessellationStateCreateInfo));
1766 pPipeline->graphicsPipelineCI.pTessellationState = &pPipeline->tessStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001767 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001768 if (pCreateInfo->pViewportState != NULL) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001769 memcpy((void*)&pPipeline->vpStateCI, pCreateInfo->pViewportState, sizeof(VkPipelineViewportStateCreateInfo));
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001770 pPipeline->graphicsPipelineCI.pViewportState = &pPipeline->vpStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001771 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001772 if (pCreateInfo->pRasterizationState != NULL) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001773 memcpy((void*)&pPipeline->rsStateCI, pCreateInfo->pRasterizationState, sizeof(VkPipelineRasterizationStateCreateInfo));
1774 pPipeline->graphicsPipelineCI.pRasterizationState = &pPipeline->rsStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001775 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001776 if (pCreateInfo->pMultisampleState != NULL) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001777 memcpy((void*)&pPipeline->msStateCI, pCreateInfo->pMultisampleState, sizeof(VkPipelineMultisampleStateCreateInfo));
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001778 pPipeline->graphicsPipelineCI.pMultisampleState = &pPipeline->msStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001779 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001780 if (pCreateInfo->pDepthStencilState != NULL) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001781 memcpy((void*)&pPipeline->dsStateCI, pCreateInfo->pDepthStencilState, sizeof(VkPipelineDepthStencilStateCreateInfo));
1782 pPipeline->graphicsPipelineCI.pDepthStencilState = &pPipeline->dsStateCI;
Tobin Ehlis963a4042015-09-29 08:18:34 -06001783 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001784 if (pCreateInfo->pColorBlendState != NULL) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001785 memcpy((void*)&pPipeline->cbStateCI, pCreateInfo->pColorBlendState, sizeof(VkPipelineColorBlendStateCreateInfo));
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001786 // Copy embedded ptrs
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001787 pCBCI = pCreateInfo->pColorBlendState;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001788 pPipeline->attachmentCount = pCBCI->attachmentCount;
1789 if (pPipeline->attachmentCount) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001790 pPipeline->pAttachments = new VkPipelineColorBlendAttachmentState[pPipeline->attachmentCount];
1791 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineColorBlendAttachmentState);
1792 memcpy((void*)pPipeline->pAttachments, pCBCI->pAttachments, bufferSize);
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001793 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001794 pPipeline->graphicsPipelineCI.pColorBlendState = &pPipeline->cbStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001795 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001796 if (pCreateInfo->pDynamicState != NULL) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001797 memcpy((void*)&pPipeline->dynStateCI, pCreateInfo->pDynamicState, sizeof(VkPipelineDynamicStateCreateInfo));
Tobin Ehlis963a4042015-09-29 08:18:34 -06001798 if (pPipeline->dynStateCI.dynamicStateCount) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001799 pPipeline->dynStateCI.pDynamicStates = new VkDynamicState[pPipeline->dynStateCI.dynamicStateCount];
1800 bufferSize = pPipeline->dynStateCI.dynamicStateCount * sizeof(VkDynamicState);
1801 memcpy((void*)pPipeline->dynStateCI.pDynamicStates, pCreateInfo->pDynamicState->pDynamicStates, bufferSize);
Tobin Ehlis963a4042015-09-29 08:18:34 -06001802 }
1803 pPipeline->graphicsPipelineCI.pDynamicState = &pPipeline->dynStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001804 }
Tobin Ehlis88452832015-12-03 09:40:56 -07001805 pPipeline->active_sets.clear();
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001806 return pPipeline;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001807}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001808
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001809// Free the Pipeline nodes
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001810static void deletePipelines(layer_data* my_data)
1811{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001812 if (my_data->pipelineMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06001813 return;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001814 for (auto ii=my_data->pipelineMap.begin(); ii!=my_data->pipelineMap.end(); ++ii) {
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001815 if ((*ii).second->graphicsPipelineCI.stageCount != 0) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001816 delete[] (*ii).second->graphicsPipelineCI.pStages;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001817 }
Tobin Ehlisf313c8b2015-04-01 11:59:08 -06001818 if ((*ii).second->pVertexBindingDescriptions) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001819 delete[] (*ii).second->pVertexBindingDescriptions;
Tobin Ehlisf313c8b2015-04-01 11:59:08 -06001820 }
1821 if ((*ii).second->pVertexAttributeDescriptions) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001822 delete[] (*ii).second->pVertexAttributeDescriptions;
Tobin Ehlisf313c8b2015-04-01 11:59:08 -06001823 }
1824 if ((*ii).second->pAttachments) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001825 delete[] (*ii).second->pAttachments;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001826 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001827 if ((*ii).second->dynStateCI.dynamicStateCount != 0) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001828 delete[] (*ii).second->dynStateCI.pDynamicStates;
Tobin Ehlis963a4042015-09-29 08:18:34 -06001829 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001830 delete (*ii).second;
1831 }
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001832 my_data->pipelineMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001833}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001834
Tobin Ehliseba312c2015-04-01 08:40:34 -06001835// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001836static VkSampleCountFlagBits getNumSamples(layer_data* my_data, const VkPipeline pipeline)
1837{
Ian Elliott8c8b2662016-01-30 10:57:03 -07001838 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001839 PIPELINE_NODE* pPipe = my_data->pipelineMap[pipeline];
Ian Elliott8c8b2662016-01-30 10:57:03 -07001840 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001841 if (VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001842 return pPipe->msStateCI.rasterizationSamples;
Tobin Ehlis577188e2015-07-13 14:51:15 -06001843 }
Chia-I Wu5c17c962015-10-31 00:31:16 +08001844 return VK_SAMPLE_COUNT_1_BIT;
Tobin Ehliseba312c2015-04-01 08:40:34 -06001845}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001846
Tobin Ehliseba312c2015-04-01 08:40:34 -06001847// Validate state related to the PSO
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001848static VkBool32 validatePipelineState(layer_data* my_data, const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
1849{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001850 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06001851 // Verify that any MSAA request in PSO matches sample# in bound FB
Chia-I Wu5c17c962015-10-31 00:31:16 +08001852 VkSampleCountFlagBits psoNumSamples = getNumSamples(my_data, pipeline);
Tobin Ehliseba312c2015-04-01 08:40:34 -06001853 if (pCB->activeRenderPass) {
Ian Elliott8c8b2662016-01-30 10:57:03 -07001854 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001855 const VkRenderPassCreateInfo* pRPCI = my_data->renderPassMap[pCB->activeRenderPass]->pCreateInfo;
1856 const VkSubpassDescription* pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
Ian Elliott8c8b2662016-01-30 10:57:03 -07001857 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001858 VkSampleCountFlagBits subpassNumSamples = (VkSampleCountFlagBits) 0;
Chia-I Wu08accc62015-07-07 11:50:03 +08001859 uint32_t i;
1860
Chia-I Wud50a7d72015-10-26 20:48:51 +08001861 for (i = 0; i < pSD->colorAttachmentCount; i++) {
Chia-I Wu5c17c962015-10-31 00:31:16 +08001862 VkSampleCountFlagBits samples;
Chia-I Wu08accc62015-07-07 11:50:03 +08001863
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001864 if (pSD->pColorAttachments[i].attachment == VK_ATTACHMENT_UNUSED)
Chia-I Wu08accc62015-07-07 11:50:03 +08001865 continue;
1866
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001867 samples = pRPCI->pAttachments[pSD->pColorAttachments[i].attachment].samples;
1868 if (subpassNumSamples == (VkSampleCountFlagBits) 0) {
Chia-I Wu08accc62015-07-07 11:50:03 +08001869 subpassNumSamples = samples;
1870 } else if (subpassNumSamples != samples) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001871 subpassNumSamples = (VkSampleCountFlagBits) -1;
Chia-I Wu08accc62015-07-07 11:50:03 +08001872 break;
1873 }
1874 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001875 if (pSD->pDepthStencilAttachment && pSD->pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
1876 const VkSampleCountFlagBits samples = pRPCI->pAttachments[pSD->pDepthStencilAttachment->attachment].samples;
1877 if (subpassNumSamples == (VkSampleCountFlagBits) 0)
Chia-I Wu08accc62015-07-07 11:50:03 +08001878 subpassNumSamples = samples;
1879 else if (subpassNumSamples != samples)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001880 subpassNumSamples = (VkSampleCountFlagBits) -1;
Chia-I Wu08accc62015-07-07 11:50:03 +08001881 }
1882
1883 if (psoNumSamples != subpassNumSamples) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001884 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",
1885 "Num samples mismatch! Binding PSO (%#" PRIxLEAST64 ") with %u samples while current RenderPass (%#" PRIxLEAST64 ") w/ %u samples!",
1886 (uint64_t) pipeline, psoNumSamples, (uint64_t) pCB->activeRenderPass, subpassNumSamples);
Tobin Ehliseba312c2015-04-01 08:40:34 -06001887 }
1888 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001889 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
Tobin Ehliseba312c2015-04-01 08:40:34 -06001890 // Verify and flag error as appropriate
1891 }
1892 // TODO : Add more checks here
1893 } else {
1894 // TODO : Validate non-gfx pipeline updates
1895 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001896 return VK_FALSE;
Tobin Ehliseba312c2015-04-01 08:40:34 -06001897}
1898
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001899// Block of code at start here specifically for managing/tracking DSs
1900
Tobin Ehlis793ad302015-04-03 12:01:11 -06001901// Return Pool node ptr for specified pool or else NULL
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001902static DESCRIPTOR_POOL_NODE* getPoolNode(layer_data* my_data, const VkDescriptorPool pool)
1903{
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001904 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001905 if (my_data->descriptorPoolMap.find(pool) == my_data->descriptorPoolMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001906 loader_platform_thread_unlock_mutex(&globalLock);
1907 return NULL;
1908 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07001909 DESCRIPTOR_POOL_NODE *rtn = my_data->descriptorPoolMap[pool];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001910 loader_platform_thread_unlock_mutex(&globalLock);
Ian Elliott8c8b2662016-01-30 10:57:03 -07001911 return rtn;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001912}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001913
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001914static LAYOUT_NODE* getLayoutNode(layer_data* my_data, const VkDescriptorSetLayout layout) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001915 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001916 if (my_data->descriptorSetLayoutMap.find(layout) == my_data->descriptorSetLayoutMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001917 loader_platform_thread_unlock_mutex(&globalLock);
1918 return NULL;
1919 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07001920 LAYOUT_NODE *rtn = my_data->descriptorSetLayoutMap[layout];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001921 loader_platform_thread_unlock_mutex(&globalLock);
Ian Elliott8c8b2662016-01-30 10:57:03 -07001922 return rtn;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001923}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001924
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001925// Return VK_FALSE if update struct is of valid type, otherwise flag error and return code from callback
1926static VkBool32 validUpdateStruct(layer_data* my_data, const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
1927{
1928 switch (pUpdateStruct->sType)
1929 {
1930 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1931 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
1932 return VK_FALSE;
1933 default:
1934 return log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
1935 "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 -06001936 }
1937}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001938
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001939// Set count for given update struct in the last parameter
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001940// Return value of skipCall, which is only VK_TRUE if error occurs and callback signals execution to cease
1941static uint32_t getUpdateCount(layer_data* my_data, const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
1942{
1943 switch (pUpdateStruct->sType)
1944 {
1945 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1946 return ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorCount;
1947 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
1948 // TODO : Need to understand this case better and make sure code is correct
1949 return ((VkCopyDescriptorSet*)pUpdateStruct)->descriptorCount;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001950 }
Courtney Goeltzenleuchter7f47bca2015-12-16 16:08:08 -07001951
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001952 return 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001953}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001954
Tobin Ehlis793ad302015-04-03 12:01:11 -06001955// For given Layout Node and binding, return index where that binding begins
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001956static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
1957{
Tobin Ehlis793ad302015-04-03 12:01:11 -06001958 uint32_t offsetIndex = 0;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001959 for (uint32_t i = 0; i < pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001960 if (pLayout->createInfo.pBindings[i].binding == binding)
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001961 break;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001962 offsetIndex += pLayout->createInfo.pBindings[i].descriptorCount;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001963 }
1964 return offsetIndex;
1965}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001966
Tobin Ehlis793ad302015-04-03 12:01:11 -06001967// For given layout node and binding, return last index that is updated
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001968static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
1969{
Tobin Ehlis793ad302015-04-03 12:01:11 -06001970 uint32_t offsetIndex = 0;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001971 for (uint32_t i = 0; i < pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001972 offsetIndex += pLayout->createInfo.pBindings[i].descriptorCount;
1973 if (pLayout->createInfo.pBindings[i].binding == binding)
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001974 break;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001975 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001976 return offsetIndex-1;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001977}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001978
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001979// For given layout and update, return the first overall index of the layout that is updated
1980static 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)
1981{
1982 return getBindingStartIndex(pLayout, binding)+arrayIndex;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001983}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001984
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001985// For given layout and update, return the last overall index of the layout that is updated
1986static 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)
1987{
Tobin Ehlis8a62e632015-10-27 15:43:38 -06001988 uint32_t count = getUpdateCount(my_data, device, pUpdateStruct);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001989 return getBindingStartIndex(pLayout, binding)+arrayIndex+count-1;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001990}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001991
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001992// Verify that the descriptor type in the update struct matches what's expected by the layout
1993static VkBool32 validateUpdateConsistency(layer_data* my_data, const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct, uint32_t startIndex, uint32_t endIndex)
1994{
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001995 // First get actual type of update
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001996 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001997 VkDescriptorType actualType;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001998 uint32_t i = 0;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001999 switch (pUpdateStruct->sType)
2000 {
2001 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
2002 actualType = ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorType;
2003 break;
2004 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
2005 /* no need to validate */
2006 return VK_FALSE;
2007 break;
2008 default:
2009 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
2010 "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 -06002011 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002012 if (VK_FALSE == skipCall) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002013 // Set first stageFlags as reference and verify that all other updates match it
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002014 VkShaderStageFlags refStageFlags = pLayout->stageFlags[startIndex];
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002015 for (i = startIndex; i <= endIndex; i++) {
Tobin Ehlis644ff042015-10-20 10:11:55 -06002016 if (pLayout->descriptorTypes[i] != actualType) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002017 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, "DS",
2018 "Write descriptor update has descriptor type %s that does not match overlapping binding descriptor type of %s!",
2019 string_VkDescriptorType(actualType), string_VkDescriptorType(pLayout->descriptorTypes[i]));
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002020 }
2021 if (pLayout->stageFlags[i] != refStageFlags) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002022 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_DESCRIPTOR_STAGEFLAGS_MISMATCH, "DS",
2023 "Write descriptor update has stageFlags %x that do not match overlapping binding descriptor stageFlags of %x!",
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002024 refStageFlags, pLayout->stageFlags[i]);
Tobin Ehlis483cc352015-09-30 08:30:20 -06002025 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002026 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002027 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002028 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002029}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002030
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002031// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
2032// struct into the pNewNode param. Return VK_TRUE if error condition encountered and callback signals early exit.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002033// NOTE : Calls to this function should be wrapped in mutex
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002034static VkBool32 shadowUpdateNode(layer_data* my_data, const VkDevice device, GENERIC_HEADER* pUpdate, GENERIC_HEADER** pNewNode)
2035{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002036 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002037 VkWriteDescriptorSet* pWDS = NULL;
2038 VkCopyDescriptorSet* pCDS = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002039 size_t array_size = 0;
2040 size_t base_array_size = 0;
2041 size_t total_array_size = 0;
2042 size_t baseBuffAddr = 0;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002043 switch (pUpdate->sType)
2044 {
2045 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
2046 pWDS = new VkWriteDescriptorSet;
2047 *pNewNode = (GENERIC_HEADER*)pWDS;
2048 memcpy(pWDS, pUpdate, sizeof(VkWriteDescriptorSet));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06002049
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002050 switch (pWDS->descriptorType) {
2051 case VK_DESCRIPTOR_TYPE_SAMPLER:
2052 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
2053 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2054 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
2055 {
2056 VkDescriptorImageInfo *info = new VkDescriptorImageInfo[pWDS->descriptorCount];
2057 memcpy(info, pWDS->pImageInfo, pWDS->descriptorCount * sizeof(VkDescriptorImageInfo));
2058 pWDS->pImageInfo = info;
2059 }
2060 break;
2061 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2062 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
2063 {
2064 VkBufferView *info = new VkBufferView[pWDS->descriptorCount];
2065 memcpy(info, pWDS->pTexelBufferView, pWDS->descriptorCount * sizeof(VkBufferView));
2066 pWDS->pTexelBufferView = info;
2067 }
2068 break;
2069 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2070 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2071 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2072 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
2073 {
2074 VkDescriptorBufferInfo *info = new VkDescriptorBufferInfo[pWDS->descriptorCount];
2075 memcpy(info, pWDS->pBufferInfo, pWDS->descriptorCount * sizeof(VkDescriptorBufferInfo));
2076 pWDS->pBufferInfo = info;
2077 }
2078 break;
2079 default:
2080 return VK_ERROR_VALIDATION_FAILED_EXT;
2081 break;
2082 }
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -07002083 break;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002084 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
2085 pCDS = new VkCopyDescriptorSet;
2086 *pNewNode = (GENERIC_HEADER*)pCDS;
2087 memcpy(pCDS, pUpdate, sizeof(VkCopyDescriptorSet));
2088 break;
2089 default:
2090 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
2091 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdate->sType), pUpdate->sType))
2092 return VK_TRUE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002093 }
2094 // Make sure that pNext for the end of shadow copy is NULL
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002095 (*pNewNode)->pNext = NULL;
2096 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002097}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002098
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002099// Verify that given sampler is valid
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002100static VkBool32 validateSampler(const layer_data* my_data, const VkSampler* pSampler, const VkBool32 immutable)
2101{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002102 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002103 auto sampIt = my_data->sampleMap.find(*pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002104 if (sampIt == my_data->sampleMap.end()) {
2105 if (!immutable) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002106 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",
2107 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid sampler %#" PRIxLEAST64, (uint64_t) *pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002108 } else { // immutable
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002109 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",
2110 "vkUpdateDescriptorSets: Attempt to update descriptor whose binding has an invalid immutable sampler %#" PRIxLEAST64, (uint64_t) *pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002111 }
2112 } else {
2113 // TODO : Any further checks we want to do on the sampler?
2114 }
2115 return skipCall;
2116}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002117
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002118// Verify that given imageView is valid
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002119static VkBool32 validateImageView(const layer_data* my_data, const VkImageView* pImageView, const VkImageLayout imageLayout)
2120{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002121 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002122 auto ivIt = my_data->imageViewMap.find(*pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002123 if (ivIt == my_data->imageViewMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002124 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",
2125 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid imageView %#" PRIxLEAST64, (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002126 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002127 // Validate that imageLayout is compatible with aspectMask and image format
2128 VkImageAspectFlags aspectMask = ivIt->second->subresourceRange.aspectMask;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002129 VkImage image = ivIt->second->image;
Michael Lentine7b236262015-10-23 12:41:44 -07002130 // TODO : Check here in case we have a bad image
Tobin Ehlis75cd1c52016-01-21 10:21:04 -07002131 auto imgIt = my_data->imageLayoutMap.find(image);
2132 if (imgIt == my_data->imageLayoutMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002133 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",
2134 "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 -06002135 } else {
2136 VkFormat format = (*imgIt).second->format;
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07002137 VkBool32 ds = vk_format_is_depth_or_stencil(format);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002138 switch (imageLayout) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002139 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
2140 // Only Color bit must be set
2141 if ((aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) != VK_IMAGE_ASPECT_COLOR_BIT) {
2142 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__,
2143 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL and imageView %#" PRIxLEAST64 ""
2144 " that does not have VK_IMAGE_ASPECT_COLOR_BIT set.", (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002145 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002146 // format must NOT be DS
2147 if (ds) {
2148 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__,
2149 DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL and imageView %#" PRIxLEAST64 ""
2150 " but the image format is %s which is not a color format.", (uint64_t) *pImageView, string_VkFormat(format));
2151 }
2152 break;
2153 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
2154 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
2155 // Depth or stencil bit must be set, but both must NOT be set
2156 if (aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) {
2157 if (aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) {
2158 // both must NOT be set
2159 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__,
2160 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with imageView %#" PRIxLEAST64 ""
2161 " that has both STENCIL and DEPTH aspects set", (uint64_t) *pImageView);
2162 }
2163 } else if (!(aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)) {
2164 // Neither were set
2165 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__,
2166 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout %s and imageView %#" PRIxLEAST64 ""
2167 " that does not have STENCIL or DEPTH aspect set.", string_VkImageLayout(imageLayout), (uint64_t) *pImageView);
2168 }
2169 // format must be DS
2170 if (!ds) {
2171 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__,
2172 DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout %s and imageView %#" PRIxLEAST64 ""
2173 " but the image format is %s which is not a depth/stencil format.", string_VkImageLayout(imageLayout), (uint64_t) *pImageView, string_VkFormat(format));
2174 }
2175 break;
2176 default:
2177 // anything to check for other layouts?
2178 break;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002179 }
2180 }
2181 }
2182 return skipCall;
2183}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002184
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002185// Verify that given bufferView is valid
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002186static VkBool32 validateBufferView(const layer_data* my_data, const VkBufferView* pBufferView)
2187{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002188 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002189 auto sampIt = my_data->bufferViewMap.find(*pBufferView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002190 if (sampIt == my_data->bufferViewMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002191 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",
2192 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid bufferView %#" PRIxLEAST64, (uint64_t) *pBufferView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002193 } else {
2194 // TODO : Any further checks we want to do on the bufferView?
2195 }
2196 return skipCall;
2197}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002198
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002199// Verify that given bufferInfo is valid
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002200static VkBool32 validateBufferInfo(const layer_data* my_data, const VkDescriptorBufferInfo* pBufferInfo)
2201{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002202 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002203 auto sampIt = my_data->bufferMap.find(pBufferInfo->buffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002204 if (sampIt == my_data->bufferMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002205 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",
2206 "vkUpdateDescriptorSets: Attempt to update descriptor where bufferInfo has invalid buffer %#" PRIxLEAST64, (uint64_t) pBufferInfo->buffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002207 } else {
2208 // TODO : Any further checks we want to do on the bufferView?
2209 }
2210 return skipCall;
2211}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002212
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002213static VkBool32 validateUpdateContents(const layer_data* my_data, const VkWriteDescriptorSet *pWDS, const VkDescriptorSetLayoutBinding* pLayoutBinding)
2214{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002215 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002216 // First verify that for the given Descriptor type, the correct DescriptorInfo data is supplied
2217 VkBufferView* pBufferView = NULL;
2218 const VkSampler* pSampler = NULL;
2219 VkImageView* pImageView = NULL;
2220 VkImageLayout* pImageLayout = NULL;
2221 VkDescriptorBufferInfo* pBufferInfo = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002222 VkBool32 immutable = VK_FALSE;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002223 uint32_t i = 0;
2224 // For given update type, verify that update contents are correct
2225 switch (pWDS->descriptorType) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002226 case VK_DESCRIPTOR_TYPE_SAMPLER:
2227 for (i=0; i<pWDS->descriptorCount; ++i) {
2228 skipCall |= validateSampler(my_data, &(pWDS->pImageInfo[i].sampler), immutable);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002229 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002230 break;
2231 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
2232 for (i=0; i<pWDS->descriptorCount; ++i) {
2233 if (NULL == pLayoutBinding->pImmutableSamplers) {
2234 pSampler = &(pWDS->pImageInfo[i].sampler);
2235 if (immutable) {
2236 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",
2237 "vkUpdateDescriptorSets: Update #%u is not an immutable sampler %#" PRIxLEAST64 ", but previous update(s) from this "
2238 "VkWriteDescriptorSet struct used an immutable sampler. All updates from a single struct must either "
2239 "use immutable or non-immutable samplers.", i, (uint64_t) *pSampler);
2240 }
2241 } else {
2242 if (i>0 && !immutable) {
2243 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",
2244 "vkUpdateDescriptorSets: Update #%u is an immutable sampler, but previous update(s) from this "
2245 "VkWriteDescriptorSet struct used a non-immutable sampler. All updates from a single struct must either "
2246 "use immutable or non-immutable samplers.", i);
2247 }
2248 immutable = VK_TRUE;
2249 pSampler = &(pLayoutBinding->pImmutableSamplers[i]);
2250 }
2251 skipCall |= validateSampler(my_data, pSampler, immutable);
2252 }
2253 // Intentionally fall through here to also validate image stuff
2254 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2255 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
2256 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
2257 for (i=0; i<pWDS->descriptorCount; ++i) {
2258 skipCall |= validateImageView(my_data, &(pWDS->pImageInfo[i].imageView), pWDS->pImageInfo[i].imageLayout);
2259 }
2260 break;
2261 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2262 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
2263 for (i=0; i<pWDS->descriptorCount; ++i) {
2264 skipCall |= validateBufferView(my_data, &(pWDS->pTexelBufferView[i]));
2265 }
2266 break;
2267 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2268 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2269 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2270 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
2271 for (i=0; i<pWDS->descriptorCount; ++i) {
2272 skipCall |= validateBufferInfo(my_data, &(pWDS->pBufferInfo[i]));
2273 }
2274 break;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002275 }
2276 return skipCall;
2277}
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002278// Validate that given set is valid and that it's not being used by an in-flight CmdBuffer
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002279// func_str is the name of the calling function
2280// Return VK_FALSE if no errors occur
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002281// Return VK_TRUE if validation error occurs and callback returns VK_TRUE (to skip upcoming API call down the chain)
2282VkBool32 validateIdleDescriptorSet(const layer_data* my_data, VkDescriptorSet set, std::string func_str) {
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002283 VkBool32 skip_call = VK_FALSE;
2284 auto set_node = my_data->setMap.find(set);
2285 if (set_node == my_data->setMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002286 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t)(set), __LINE__, DRAWSTATE_DOUBLE_DESTROY, "DS",
2287 "Cannot call %s() on descriptor set %" PRIxLEAST64 " that has not been allocated.", func_str.c_str(), (uint64_t)(set));
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002288 } else {
2289 if (set_node->second->in_use.load()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002290 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t)(set), __LINE__, DRAWSTATE_OBJECT_INUSE, "DS",
2291 "Cannot call %s() on descriptor set %" PRIxLEAST64 " that is in use by a command buffer.", func_str.c_str(), (uint64_t)(set));
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002292 }
2293 }
2294 return skip_call;
2295}
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002296static void invalidateBoundCmdBuffers(layer_data* dev_data, const SET_NODE* pSet)
2297{
Tobin Ehlise6e574b2016-01-24 23:25:31 -07002298 // Flag any CBs this set is bound to as INVALID
2299 for (auto cb : pSet->boundCmdBuffers) {
2300 auto cb_node = dev_data->commandBufferMap.find(cb);
2301 if (cb_node != dev_data->commandBufferMap.end()) {
2302 cb_node->second->state = CB_INVALID;
2303 }
2304 }
2305}
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002306// update DS mappings based on write and copy update arrays
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002307static VkBool32 dsUpdate(layer_data* my_data, VkDevice device, uint32_t descriptorWriteCount, const VkWriteDescriptorSet* pWDS, uint32_t descriptorCopyCount, const VkCopyDescriptorSet* pCDS)
2308{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002309 VkBool32 skipCall = VK_FALSE;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002310
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002311 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002312 LAYOUT_NODE* pLayout = NULL;
2313 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002314 // Validate Write updates
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002315 uint32_t i = 0;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002316 for (i=0; i < descriptorWriteCount; i++) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002317 VkDescriptorSet ds = pWDS[i].dstSet;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002318 SET_NODE* pSet = my_data->setMap[ds];
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002319 // Set being updated cannot be in-flight
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002320 if ((skipCall = validateIdleDescriptorSet(my_data, ds, "VkUpdateDescriptorSets")) == VK_TRUE)
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002321 return skipCall;
Tobin Ehlise6e574b2016-01-24 23:25:31 -07002322 // If set is bound to any cmdBuffers, mark them invalid
2323 invalidateBoundCmdBuffers(my_data, pSet);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002324 GENERIC_HEADER* pUpdate = (GENERIC_HEADER*) &pWDS[i];
Tobin Ehlis793ad302015-04-03 12:01:11 -06002325 pLayout = pSet->pLayout;
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002326 // First verify valid update struct
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002327 if ((skipCall = validUpdateStruct(my_data, device, pUpdate)) == VK_TRUE) {
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002328 break;
2329 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002330 uint32_t binding = 0, endIndex = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002331 binding = pWDS[i].dstBinding;
Tobin Ehlis684924e2016-02-02 09:57:25 -07002332 auto bindingToIndex = pLayout->bindingToIndexMap.find(binding);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002333 // Make sure that layout being updated has the binding being updated
Tobin Ehlis684924e2016-02-02 09:57:25 -07002334 if (bindingToIndex == pLayout->bindingToIndexMap.end()) {
2335 skipCall |= log_msg(
2336 my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
2337 VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t)(ds),
2338 __LINE__, DRAWSTATE_INVALID_UPDATE_INDEX, "DS",
2339 "Descriptor Set %" PRIu64 " does not have binding to match "
2340 "update binding %u for update type "
2341 "%s!",
2342 (uint64_t)(ds), binding,
2343 string_VkStructureType(pUpdate->sType));
Tobin Ehlis9c536442015-06-19 13:00:59 -06002344 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06002345 // Next verify that update falls within size of given binding
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002346 endIndex = getUpdateEndIndex(my_data, device, pLayout, binding, pWDS[i].dstArrayElement, pUpdate);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002347 if (getBindingEndIndex(pLayout, binding) < endIndex) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06002348 pLayoutCI = &pLayout->createInfo;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002349 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
2350 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",
2351 "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());
2352 } else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002353 uint32_t startIndex;
Tobin Ehlis684924e2016-02-02 09:57:25 -07002354 startIndex =
2355 getUpdateStartIndex(my_data, device, pLayout, binding,
2356 pWDS[i].dstArrayElement, pUpdate);
2357 // Layout bindings match w/ update, now verify that update type
2358 // & stageFlags are the same for entire update
2359 if ((skipCall = validateUpdateConsistency(
2360 my_data, device, pLayout, pUpdate, startIndex,
2361 endIndex)) == VK_FALSE) {
2362 // The update is within bounds and consistent, but need to
2363 // make sure contents make sense as well
2364 if ((skipCall = validateUpdateContents(
2365 my_data, &pWDS[i],
2366 &pLayout->createInfo.pBindings[bindingToIndex->second])) ==
2367 VK_FALSE) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002368 // Update is good. Save the update info
2369 // Create new update struct for this set's shadow copy
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002370 GENERIC_HEADER* pNewNode = NULL;
2371 skipCall |= shadowUpdateNode(my_data, device, pUpdate, &pNewNode);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002372 if (NULL == pNewNode) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002373 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",
2374 "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002375 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002376 // Insert shadow node into LL of updates for this set
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002377 pNewNode->pNext = pSet->pUpdateStructs;
2378 pSet->pUpdateStructs = pNewNode;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002379 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002380 for (uint32_t j = startIndex; j <= endIndex; j++) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002381 assert(j<pSet->descriptorCount);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002382 pSet->ppDescriptors[j] = pNewNode;
2383 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002384 }
2385 }
2386 }
2387 }
2388 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002389 }
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002390 // Now validate copy updates
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002391 for (i=0; i < descriptorCopyCount; ++i) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002392 SET_NODE *pSrcSet = NULL, *pDstSet = NULL;
2393 LAYOUT_NODE *pSrcLayout = NULL, *pDstLayout = NULL;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002394 uint32_t srcStartIndex = 0, srcEndIndex = 0, dstStartIndex = 0, dstEndIndex = 0;
2395 // For each copy make sure that update falls within given layout and that types match
Chia-I Wue2fc5522015-10-26 20:04:44 +08002396 pSrcSet = my_data->setMap[pCDS[i].srcSet];
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002397 pDstSet = my_data->setMap[pCDS[i].dstSet];
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002398 // Set being updated cannot be in-flight
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002399 if ((skipCall = validateIdleDescriptorSet(my_data, pDstSet->set, "VkUpdateDescriptorSets")) == VK_TRUE)
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002400 return skipCall;
Tobin Ehlise6e574b2016-01-24 23:25:31 -07002401 invalidateBoundCmdBuffers(my_data, pDstSet);
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002402 pSrcLayout = pSrcSet->pLayout;
2403 pDstLayout = pDstSet->pLayout;
2404 // Validate that src binding is valid for src set layout
Tobin Ehlis684924e2016-02-02 09:57:25 -07002405 if (pSrcLayout->bindingToIndexMap.find(pCDS[i].srcBinding) ==
2406 pSrcLayout->bindingToIndexMap.end()) {
2407 skipCall |=
2408 log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
2409 VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT,
2410 (uint64_t)pSrcSet->set, __LINE__,
2411 DRAWSTATE_INVALID_UPDATE_INDEX,
2412 "DS", "Copy descriptor update %u has srcBinding %u "
2413 "which is out of bounds for underlying SetLayout "
2414 "%#" PRIxLEAST64 " which only has bindings 0-%u.",
2415 i, pCDS[i].srcBinding, (uint64_t)pSrcLayout->layout,
2416 pSrcLayout->createInfo.bindingCount - 1);
2417 } else if (pDstLayout->bindingToIndexMap.find(pCDS[i].dstBinding) ==
2418 pDstLayout->bindingToIndexMap.end()) {
2419 skipCall |=
2420 log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
2421 VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT,
2422 (uint64_t)pDstSet->set, __LINE__,
2423 DRAWSTATE_INVALID_UPDATE_INDEX,
2424 "DS", "Copy descriptor update %u has dstBinding %u "
2425 "which is out of bounds for underlying SetLayout "
2426 "%#" PRIxLEAST64 " which only has bindings 0-%u.",
2427 i, pCDS[i].dstBinding, (uint64_t)pDstLayout->layout,
2428 pDstLayout->createInfo.bindingCount - 1);
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002429 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002430 // Proceed with validation. Bindings are ok, but make sure update is within bounds of given layout
2431 srcEndIndex = getUpdateEndIndex(my_data, device, pSrcLayout, pCDS[i].srcBinding, pCDS[i].srcArrayElement, (const GENERIC_HEADER*)&(pCDS[i]));
2432 dstEndIndex = getUpdateEndIndex(my_data, device, pDstLayout, pCDS[i].dstBinding, pCDS[i].dstArrayElement, (const GENERIC_HEADER*)&(pCDS[i]));
2433 if (getBindingEndIndex(pSrcLayout, pCDS[i].srcBinding) < srcEndIndex) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002434 pLayoutCI = &pSrcLayout->createInfo;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002435 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
2436 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",
2437 "Copy descriptor src update is out of bounds for matching binding %u in Layout w/ CI:\n%s!", pCDS[i].srcBinding, DSstr.c_str());
2438 } else if (getBindingEndIndex(pDstLayout, pCDS[i].dstBinding) < dstEndIndex) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002439 pLayoutCI = &pDstLayout->createInfo;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002440 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
2441 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",
2442 "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 -06002443 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002444 srcStartIndex = getUpdateStartIndex(my_data, device, pSrcLayout, pCDS[i].srcBinding, pCDS[i].srcArrayElement, (const GENERIC_HEADER*)&(pCDS[i]));
2445 dstStartIndex = getUpdateStartIndex(my_data, device, pDstLayout, pCDS[i].dstBinding, pCDS[i].dstArrayElement, (const GENERIC_HEADER*)&(pCDS[i]));
2446 for (uint32_t j=0; j<pCDS[i].descriptorCount; ++j) {
2447 // For copy just make sure that the types match and then perform the update
2448 if (pSrcLayout->descriptorTypes[srcStartIndex+j] != pDstLayout->descriptorTypes[dstStartIndex+j]) {
2449 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, "DS",
2450 "Copy descriptor update index %u, update count #%u, has src update descriptor type %s that does not match overlapping dest descriptor type of %s!",
2451 i, j+1, string_VkDescriptorType(pSrcLayout->descriptorTypes[srcStartIndex+j]), string_VkDescriptorType(pDstLayout->descriptorTypes[dstStartIndex+j]));
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002452 } else {
2453 // point dst descriptor at corresponding src descriptor
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002454 // TODO : This may be a hole. I believe copy should be its own copy,
2455 // otherwise a subsequent write update to src will incorrectly affect the copy
2456 pDstSet->ppDescriptors[j+dstStartIndex] = pSrcSet->ppDescriptors[j+srcStartIndex];
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002457 }
2458 }
2459 }
2460 }
2461 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002462 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002463 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002464}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002465
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002466// Verify that given pool has descriptors that are being requested for allocation
2467static VkBool32 validate_descriptor_availability_in_pool(layer_data* dev_data, DESCRIPTOR_POOL_NODE* pPoolNode, uint32_t count, const VkDescriptorSetLayout* pSetLayouts)
2468{
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002469 VkBool32 skipCall = VK_FALSE;
2470 uint32_t i = 0, j = 0;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002471 for (i=0; i<count; ++i) {
2472 LAYOUT_NODE* pLayout = getLayoutNode(dev_data, pSetLayouts[i]);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002473 if (NULL == pLayout) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002474 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",
2475 "Unable to find set layout node for layout %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pSetLayouts[i]);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002476 } else {
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002477 uint32_t typeIndex = 0, poolSizeCount = 0;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002478 for (j=0; j<pLayout->createInfo.bindingCount; ++j) {
2479 typeIndex = static_cast<uint32_t>(pLayout->createInfo.pBindings[j].descriptorType);
2480 poolSizeCount = pLayout->createInfo.pBindings[j].descriptorCount;
2481 if (poolSizeCount > pPoolNode->availableDescriptorTypeCount[typeIndex]) {
2482 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",
2483 "Unable to allocate %u descriptors of type %s from pool %#" PRIxLEAST64 ". This pool only has %u descriptors of this type remaining.",
2484 poolSizeCount, string_VkDescriptorType(pLayout->createInfo.pBindings[j].descriptorType), (uint64_t) pPoolNode->pool, pPoolNode->availableDescriptorTypeCount[typeIndex]);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002485 } else { // Decrement available descriptors of this type
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002486 pPoolNode->availableDescriptorTypeCount[typeIndex] -= poolSizeCount;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002487 }
2488 }
2489 }
2490 }
2491 return skipCall;
2492}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002493
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002494// Free the shadowed update node for this Set
2495// NOTE : Calls to this function should be wrapped in mutex
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002496static void freeShadowUpdateTree(SET_NODE* pSet)
2497{
2498 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002499 pSet->pUpdateStructs = NULL;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002500 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002501 // Clear the descriptor mappings as they will now be invalid
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002502 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
2503 while(pShadowUpdate) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002504 pFreeUpdate = pShadowUpdate;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002505 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002506 uint32_t index = 0;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002507 VkWriteDescriptorSet * pWDS = NULL;
2508 VkCopyDescriptorSet * pCDS = NULL;
2509 void** ppToFree = NULL;
2510 switch (pFreeUpdate->sType)
2511 {
2512 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
2513 pWDS = (VkWriteDescriptorSet*)pFreeUpdate;
2514 switch (pWDS->descriptorType) {
2515 case VK_DESCRIPTOR_TYPE_SAMPLER:
2516 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
2517 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2518 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
2519 {
2520 delete[] pWDS->pImageInfo;
2521 }
2522 break;
2523 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2524 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
2525 {
2526 delete[] pWDS->pTexelBufferView;
2527 }
2528 break;
2529 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2530 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2531 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2532 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
2533 {
2534 delete[] pWDS->pBufferInfo;
2535 }
2536 break;
2537 default:
2538 break;
2539 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002540 break;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002541 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
2542 break;
2543 default:
2544 assert(0);
2545 break;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002546 }
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002547 delete pFreeUpdate;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002548 }
2549}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002550
Tobin Ehlis793ad302015-04-03 12:01:11 -06002551// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002552// NOTE : Calls to this function should be wrapped in mutex
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002553static void deletePools(layer_data* my_data)
2554{
Mark Lobodzinski39298632015-11-18 08:38:27 -07002555 if (my_data->descriptorPoolMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06002556 return;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002557 for (auto ii=my_data->descriptorPoolMap.begin(); ii!=my_data->descriptorPoolMap.end(); ++ii) {
2558 SET_NODE* pSet = (*ii).second->pSets;
2559 SET_NODE* pFreeSet = pSet;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002560 while (pSet) {
2561 pFreeSet = pSet;
2562 pSet = pSet->pNext;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002563 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002564 // Free Update shadow struct tree
2565 freeShadowUpdateTree(pFreeSet);
2566 if (pFreeSet->ppDescriptors) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002567 delete[] pFreeSet->ppDescriptors;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002568 }
2569 delete pFreeSet;
2570 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002571 delete (*ii).second;
2572 }
Mark Lobodzinski39298632015-11-18 08:38:27 -07002573 my_data->descriptorPoolMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002574}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002575
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002576// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002577// NOTE : Calls to this function should be wrapped in mutex
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002578static void deleteLayouts(layer_data* my_data)
2579{
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07002580 if (my_data->descriptorSetLayoutMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06002581 return;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002582 for (auto ii=my_data->descriptorSetLayoutMap.begin(); ii!=my_data->descriptorSetLayoutMap.end(); ++ii) {
2583 LAYOUT_NODE* pLayout = (*ii).second;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002584 if (pLayout->createInfo.pBindings) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002585 for (uint32_t i=0; i<pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002586 if (pLayout->createInfo.pBindings[i].pImmutableSamplers)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002587 delete[] pLayout->createInfo.pBindings[i].pImmutableSamplers;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002588 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002589 delete[] pLayout->createInfo.pBindings;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002590 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002591 delete pLayout;
2592 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07002593 my_data->descriptorSetLayoutMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002594}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002595
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002596// Currently clearing a set is removing all previous updates to that set
2597// TODO : Validate if this is correct clearing behavior
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002598static void clearDescriptorSet(layer_data* my_data, VkDescriptorSet set)
2599{
2600 SET_NODE* pSet = getSetNode(my_data, set);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002601 if (!pSet) {
2602 // TODO : Return error
Tobin Ehlisce132d82015-06-19 15:07:05 -06002603 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002604 loader_platform_thread_lock_mutex(&globalLock);
2605 freeShadowUpdateTree(pSet);
2606 loader_platform_thread_unlock_mutex(&globalLock);
2607 }
2608}
2609
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002610static void clearDescriptorPool(layer_data* my_data, const VkDevice device, const VkDescriptorPool pool, VkDescriptorPoolResetFlags flags)
2611{
2612 DESCRIPTOR_POOL_NODE* pPool = getPoolNode(my_data, pool);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002613 if (!pPool) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002614 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",
2615 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkResetDescriptorPool() call", (uint64_t) pool);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002616 } else {
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002617 // TODO: validate flags
Tobin Ehlis793ad302015-04-03 12:01:11 -06002618 // For every set off of this pool, clear it
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002619 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002620 while (pSet) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002621 clearDescriptorSet(my_data, pSet->set);
Mark Lobodzinskidcce0792016-01-04 09:40:19 -07002622 pSet = pSet->pNext;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002623 }
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002624 // Reset available count to max count for this pool
Ian Elliott8c8b2662016-01-30 10:57:03 -07002625 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002626 for (uint32_t i=0; i<pPool->availableDescriptorTypeCount.size(); ++i) {
2627 pPool->availableDescriptorTypeCount[i] = pPool->maxDescriptorTypeCount[i];
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002628 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07002629 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002630 }
2631}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002632
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002633// For given CB object, fetch associated CB Node from map
Ian Elliott8c8b2662016-01-30 10:57:03 -07002634static GLOBAL_CB_NODE* getCBNode(layer_data* my_data, const VkCommandBuffer cb, bool doLock)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002635{
Ian Elliott8c8b2662016-01-30 10:57:03 -07002636 if (doLock) {
2637 loader_platform_thread_lock_mutex(&globalLock);
2638 }
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002639 if (my_data->commandBufferMap.count(cb) == 0) {
Ian Elliott8c8b2662016-01-30 10:57:03 -07002640 if (doLock) {
2641 loader_platform_thread_unlock_mutex(&globalLock);
2642 }
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002643 // TODO : How to pass cb as srcObj here?
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002644 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",
2645 "Attempt to use CommandBuffer %#" PRIxLEAST64 " that doesn't exist!", (uint64_t)(cb));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002646 return NULL;
2647 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07002648 GLOBAL_CB_NODE *rtn = my_data->commandBufferMap[cb];
2649 if (doLock) {
2650 loader_platform_thread_unlock_mutex(&globalLock);
2651 }
2652 return rtn;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002653}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002654
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002655// Free all CB Nodes
2656// NOTE : Calls to this function should be wrapped in mutex
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002657static void deleteCommandBuffers(layer_data* my_data)
2658{
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002659 if (my_data->commandBufferMap.size() <= 0) {
David Pinedod8f83d82015-04-27 16:36:17 -06002660 return;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002661 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002662 for (auto ii=my_data->commandBufferMap.begin(); ii!=my_data->commandBufferMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002663 delete (*ii).second;
2664 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002665 my_data->commandBufferMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002666}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002667
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002668static VkBool32 report_error_no_cb_begin(const layer_data* dev_data, const VkCommandBuffer cb, const char* caller_name)
2669{
2670 return log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2671 (uint64_t)cb, __LINE__, DRAWSTATE_NO_BEGIN_COMMAND_BUFFER, "DS",
2672 "You must call vkBeginCommandBuffer() before this call to %s", caller_name);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002673}
Michael Lentine3dea6512015-10-28 15:55:18 -07002674
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002675VkBool32 validateCmdsInCmdBuffer(const layer_data* dev_data, const GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd_type) {
2676 if (!pCB->activeRenderPass) return VK_FALSE;
Mark Youngb20a6a82016-01-07 15:41:43 -07002677 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002678 if (pCB->activeSubpassContents == VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS && cmd_type != CMD_EXECUTECOMMANDS) {
2679 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
2680 DRAWSTATE_INVALID_COMMAND_BUFFER, "DS", "Commands cannot be called in a subpass using secondary command buffers.");
2681 } else if (pCB->activeSubpassContents == VK_SUBPASS_CONTENTS_INLINE && cmd_type == CMD_EXECUTECOMMANDS) {
2682 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
2683 DRAWSTATE_INVALID_COMMAND_BUFFER, "DS", "vkCmdExecuteCommands() cannot be called in a subpass using inline commands.");
Michael Lentine2e068b22015-12-29 16:05:27 -06002684 }
Michael Lentine3dea6512015-10-28 15:55:18 -07002685 return skip_call;
2686}
2687
Michael Lentine26870f32016-01-26 21:36:08 -06002688static bool checkGraphicsBit(const layer_data* my_data, VkQueueFlags flags, const char* name) {
2689 if (!(flags & VK_QUEUE_GRAPHICS_BIT))
2690 return log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
2691 DRAWSTATE_INVALID_COMMAND_BUFFER, "DS", "Cannot call %s on a command buffer allocated from a pool without graphics capabilities.", name);
2692 return false;
2693}
2694
2695static bool checkComputeBit(const layer_data* my_data, VkQueueFlags flags, const char* name) {
2696 if (!(flags & VK_QUEUE_COMPUTE_BIT))
2697 return log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
2698 DRAWSTATE_INVALID_COMMAND_BUFFER, "DS", "Cannot call %s on a command buffer allocated from a pool without compute capabilities.", name);
2699 return false;
2700}
2701
2702static bool checkGraphicsOrComputeBit(const layer_data* my_data, VkQueueFlags flags, const char* name) {
2703 if (!((flags & VK_QUEUE_GRAPHICS_BIT) || (flags & VK_QUEUE_COMPUTE_BIT)))
2704 return log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
2705 DRAWSTATE_INVALID_COMMAND_BUFFER, "DS", "Cannot call %s on a command buffer allocated from a pool without graphics capabilities.", name);
2706 return false;
2707}
2708
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002709// Add specified CMD to the CmdBuffer in given pCB, flagging errors if CB is not
2710// in the recording state or if there's an issue with the Cmd ordering
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002711static VkBool32 addCmd(const layer_data* my_data, GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd, const char* caller_name)
2712{
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002713 VkBool32 skipCall = VK_FALSE;
Michael Lentine26870f32016-01-26 21:36:08 -06002714 auto pool_data = my_data->commandPoolMap.find(pCB->createInfo.commandPool);
2715 if (pool_data != my_data->commandPoolMap.end()) {
2716 VkQueueFlags flags = my_data->physDevProperties.queue_family_properties[pool_data->second.queueFamilyIndex].queueFlags;
2717 switch (cmd)
2718 {
2719 case CMD_BINDPIPELINE:
2720 case CMD_BINDPIPELINEDELTA:
2721 case CMD_BINDDESCRIPTORSETS:
2722 case CMD_FILLBUFFER:
2723 case CMD_CLEARCOLORIMAGE:
2724 case CMD_SETEVENT:
2725 case CMD_RESETEVENT:
2726 case CMD_WAITEVENTS:
2727 case CMD_BEGINQUERY:
2728 case CMD_ENDQUERY:
2729 case CMD_RESETQUERYPOOL:
2730 case CMD_COPYQUERYPOOLRESULTS:
2731 case CMD_WRITETIMESTAMP:
2732 skipCall |= checkGraphicsOrComputeBit(my_data, flags, cmdTypeToString(cmd).c_str());
2733 break;
2734 case CMD_SETVIEWPORTSTATE:
2735 case CMD_SETSCISSORSTATE:
2736 case CMD_SETLINEWIDTHSTATE:
2737 case CMD_SETDEPTHBIASSTATE:
2738 case CMD_SETBLENDSTATE:
2739 case CMD_SETDEPTHBOUNDSSTATE:
2740 case CMD_SETSTENCILREADMASKSTATE:
2741 case CMD_SETSTENCILWRITEMASKSTATE:
2742 case CMD_SETSTENCILREFERENCESTATE:
2743 case CMD_BINDINDEXBUFFER:
2744 case CMD_BINDVERTEXBUFFER:
2745 case CMD_DRAW:
2746 case CMD_DRAWINDEXED:
2747 case CMD_DRAWINDIRECT:
2748 case CMD_DRAWINDEXEDINDIRECT:
2749 case CMD_BLITIMAGE:
2750 case CMD_CLEARATTACHMENTS:
2751 case CMD_CLEARDEPTHSTENCILIMAGE:
2752 case CMD_RESOLVEIMAGE:
2753 case CMD_BEGINRENDERPASS:
2754 case CMD_NEXTSUBPASS:
2755 case CMD_ENDRENDERPASS:
2756 skipCall |= checkGraphicsBit(my_data, flags, cmdTypeToString(cmd).c_str());
2757 break;
2758 case CMD_DISPATCH:
2759 case CMD_DISPATCHINDIRECT:
2760 skipCall |= checkComputeBit(my_data, flags, cmdTypeToString(cmd).c_str());
2761 break;
2762 case CMD_COPYBUFFER:
2763 case CMD_COPYIMAGE:
2764 case CMD_COPYBUFFERTOIMAGE:
2765 case CMD_COPYIMAGETOBUFFER:
2766 case CMD_CLONEIMAGEDATA:
2767 case CMD_UPDATEBUFFER:
2768 case CMD_PIPELINEBARRIER:
2769 case CMD_EXECUTECOMMANDS:
2770 break;
2771 default:
2772 break;
2773 }
2774 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002775 if (pCB->state != CB_RECORDING) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002776 skipCall |= report_error_no_cb_begin(my_data, pCB->commandBuffer, caller_name);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002777 skipCall |= validateCmdsInCmdBuffer(my_data, pCB, cmd);
Tobin Ehlis9a874302016-01-20 10:25:29 -07002778 CMD_NODE cmdNode = {};
2779 // init cmd node and append to end of cmd LL
2780 cmdNode.cmdNumber = ++pCB->numCmds;
2781 cmdNode.type = cmd;
2782 pCB->cmds.push_back(cmdNode);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002783 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002784 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002785}
Tobin Ehlisef694652016-01-19 12:03:34 -07002786// Reset the command buffer state
2787// Maintain the createInfo and set state to CB_NEW, but clear all other state
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002788static void resetCB(layer_data* my_data, const VkCommandBuffer cb)
2789{
2790 GLOBAL_CB_NODE* pCB = my_data->commandBufferMap[cb];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002791 if (pCB) {
Tobin Ehlis9a874302016-01-20 10:25:29 -07002792 pCB->cmds.clear();
Tobin Ehlisef694652016-01-19 12:03:34 -07002793 // Reset CB state (note that createInfo is not cleared)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002794 pCB->commandBuffer = cb;
Michael Lentineabc5e922015-10-12 11:30:14 -05002795 memset(&pCB->beginInfo, 0, sizeof(VkCommandBufferBeginInfo));
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002796 memset(&pCB->inheritanceInfo, 0, sizeof(VkCommandBufferInheritanceInfo));
Michael Lentineabc5e922015-10-12 11:30:14 -05002797 pCB->fence = 0;
2798 pCB->numCmds = 0;
2799 memset(pCB->drawCount, 0, NUM_DRAW_TYPES * sizeof(uint64_t));
2800 pCB->state = CB_NEW;
2801 pCB->submitCount = 0;
2802 pCB->status = 0;
Michael Lentineabc5e922015-10-12 11:30:14 -05002803 pCB->lastBoundPipeline = 0;
Chris Forbes82c123c2016-02-02 15:45:40 +13002804 pCB->lastVtxBinding = 0;
2805 pCB->boundVtxBuffers.clear();
Michael Lentineabc5e922015-10-12 11:30:14 -05002806 pCB->viewports.clear();
2807 pCB->scissors.clear();
2808 pCB->lineWidth = 0;
2809 pCB->depthBiasConstantFactor = 0;
2810 pCB->depthBiasClamp = 0;
2811 pCB->depthBiasSlopeFactor = 0;
2812 memset(pCB->blendConstants, 0, 4 * sizeof(float));
2813 pCB->minDepthBounds = 0;
2814 pCB->maxDepthBounds = 0;
2815 memset(&pCB->front, 0, sizeof(stencil_data));
2816 memset(&pCB->back, 0, sizeof(stencil_data));
2817 pCB->lastBoundDescriptorSet = 0;
2818 pCB->lastBoundPipelineLayout = 0;
Chris Forbes82c123c2016-02-02 15:45:40 +13002819 memset(&pCB->activeRenderPassBeginInfo, 0, sizeof(pCB->activeRenderPassBeginInfo));
Michael Lentineabc5e922015-10-12 11:30:14 -05002820 pCB->activeRenderPass = 0;
Chris Forbes82c123c2016-02-02 15:45:40 +13002821 pCB->activeSubpassContents = VK_SUBPASS_CONTENTS_INLINE;
Michael Lentineabc5e922015-10-12 11:30:14 -05002822 pCB->activeSubpass = 0;
Chris Forbes82c123c2016-02-02 15:45:40 +13002823 pCB->framebuffer = 0;
Tobin Ehlise6e574b2016-01-24 23:25:31 -07002824 // Before clearing uniqueBoundSets, remove this CB off of its boundCBs
2825 for (auto set : pCB->uniqueBoundSets) {
2826 auto set_node = my_data->setMap.find(set);
2827 if (set_node != my_data->setMap.end()) {
2828 set_node->second->boundCmdBuffers.erase(pCB->commandBuffer);
2829 }
2830 }
2831 pCB->uniqueBoundSets.clear();
Chris Forbes82c123c2016-02-02 15:45:40 +13002832 pCB->destroyedSets.clear();
2833 pCB->updatedSets.clear();
Michael Lentineabc5e922015-10-12 11:30:14 -05002834 pCB->boundDescriptorSets.clear();
Michael Lentineb887b0a2015-12-29 14:12:11 -06002835 pCB->waitedEvents.clear();
2836 pCB->waitedEventsBeforeQueryReset.clear();
2837 pCB->queryToStateMap.clear();
Michael Lentinedc6f8de2016-02-02 18:29:30 -06002838 pCB->activeQueries.clear();
Chris Forbes82c123c2016-02-02 15:45:40 +13002839 pCB->imageLayoutMap.clear();
2840 pCB->drawData.clear();
2841 pCB->currentDrawData.buffers.clear();
Michael Lentined7621bb2016-02-03 10:55:23 -06002842 pCB->primaryCommandBuffer = VK_NULL_HANDLE;
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07002843 pCB->secondaryCommandBuffers.clear();
Chris Forbes82c123c2016-02-02 15:45:40 +13002844 pCB->dynamicOffsets.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002845 }
2846}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002847
Tobin Ehlis963a4042015-09-29 08:18:34 -06002848// Set PSO-related status bits for CB, including dynamic state set via PSO
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002849static void set_cb_pso_status(GLOBAL_CB_NODE* pCB, const PIPELINE_NODE* pPipe)
2850{
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002851 for (uint32_t i = 0; i < pPipe->cbStateCI.attachmentCount; i++) {
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002852 if (0 != pPipe->pAttachments[i].colorWriteMask) {
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002853 pCB->status |= CBSTATUS_COLOR_BLEND_WRITE_ENABLE;
2854 }
2855 }
2856 if (pPipe->dsStateCI.depthWriteEnable) {
Cody Northrop82485a82015-08-18 15:21:16 -06002857 pCB->status |= CBSTATUS_DEPTH_WRITE_ENABLE;
2858 }
Cody Northrop82485a82015-08-18 15:21:16 -06002859 if (pPipe->dsStateCI.stencilTestEnable) {
2860 pCB->status |= CBSTATUS_STENCIL_TEST_ENABLE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002861 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06002862 // Account for any dynamic state not set via this PSO
2863 if (!pPipe->dynStateCI.dynamicStateCount) { // All state is static
2864 pCB->status = CBSTATUS_ALL;
2865 } else {
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002866 // First consider all state on
2867 // Then unset any state that's noted as dynamic in PSO
2868 // Finally OR that into CB statemask
2869 CBStatusFlags psoDynStateMask = CBSTATUS_ALL;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002870 for (uint32_t i=0; i < pPipe->dynStateCI.dynamicStateCount; i++) {
Tobin Ehlis963a4042015-09-29 08:18:34 -06002871 switch (pPipe->dynStateCI.pDynamicStates[i]) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002872 case VK_DYNAMIC_STATE_VIEWPORT:
2873 psoDynStateMask &= ~CBSTATUS_VIEWPORT_SET;
2874 break;
2875 case VK_DYNAMIC_STATE_SCISSOR:
2876 psoDynStateMask &= ~CBSTATUS_SCISSOR_SET;
2877 break;
2878 case VK_DYNAMIC_STATE_LINE_WIDTH:
2879 psoDynStateMask &= ~CBSTATUS_LINE_WIDTH_SET;
2880 break;
2881 case VK_DYNAMIC_STATE_DEPTH_BIAS:
2882 psoDynStateMask &= ~CBSTATUS_DEPTH_BIAS_SET;
2883 break;
2884 case VK_DYNAMIC_STATE_BLEND_CONSTANTS:
2885 psoDynStateMask &= ~CBSTATUS_BLEND_SET;
2886 break;
2887 case VK_DYNAMIC_STATE_DEPTH_BOUNDS:
2888 psoDynStateMask &= ~CBSTATUS_DEPTH_BOUNDS_SET;
2889 break;
2890 case VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK:
2891 psoDynStateMask &= ~CBSTATUS_STENCIL_READ_MASK_SET;
2892 break;
2893 case VK_DYNAMIC_STATE_STENCIL_WRITE_MASK:
2894 psoDynStateMask &= ~CBSTATUS_STENCIL_WRITE_MASK_SET;
2895 break;
2896 case VK_DYNAMIC_STATE_STENCIL_REFERENCE:
2897 psoDynStateMask &= ~CBSTATUS_STENCIL_REFERENCE_SET;
2898 break;
2899 default:
2900 // TODO : Flag error here
2901 break;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002902 }
2903 }
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002904 pCB->status |= psoDynStateMask;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002905 }
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002906}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002907
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002908// Print the last bound Gfx Pipeline
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002909static VkBool32 printPipeline(layer_data* my_data, const VkCommandBuffer cb)
2910{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002911 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002912 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002913 if (pCB) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002914 PIPELINE_NODE *pPipeTrav = getPipeline(my_data, pCB->lastBoundPipeline);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002915 if (!pPipeTrav) {
2916 // nothing to print
Tobin Ehlisce132d82015-06-19 15:07:05 -06002917 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002918 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
2919 "%s", vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002920 }
2921 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002922 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002923}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002924
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002925// Print details of DS config to stdout
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002926static VkBool32 printDSConfig(layer_data* my_data, const VkCommandBuffer cb)
2927{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002928 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002929 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.
2930 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis93f89e82015-06-09 08:39:32 -06002931 if (pCB && pCB->lastBoundDescriptorSet) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002932 SET_NODE* pSet = getSetNode(my_data, pCB->lastBoundDescriptorSet);
2933 DESCRIPTOR_POOL_NODE* pPool = getPoolNode(my_data, pSet->pool);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002934 // Print out pool details
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002935 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
2936 "Details for pool %#" PRIxLEAST64 ".", (uint64_t) pPool->pool);
2937 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
2938 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
2939 "%s", poolStr.c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002940 // Print out set details
2941 char prefix[10];
2942 uint32_t index = 0;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002943 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
2944 "Details for descriptor set %#" PRIxLEAST64 ".", (uint64_t) pSet->set);
2945 LAYOUT_NODE* pLayout = pSet->pLayout;
Tobin Ehlis793ad302015-04-03 12:01:11 -06002946 // Print layout details
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002947 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
2948 "Layout #%u, (object %#" PRIxLEAST64 ") for DS %#" PRIxLEAST64 ".", index+1, (uint64_t)(pLayout->layout), (uint64_t)(pSet->set));
Tobin Ehlis793ad302015-04-03 12:01:11 -06002949 sprintf(prefix, " [L%u] ", index);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002950 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
2951 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
2952 "%s", DSLstr.c_str());
Tobin Ehlis793ad302015-04-03 12:01:11 -06002953 index++;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002954 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002955 if (pUpdate) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002956 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
2957 "Update Chain [UC] for descriptor set %#" PRIxLEAST64 ":", (uint64_t) pSet->set);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002958 sprintf(prefix, " [UC] ");
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002959 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
2960 "%s", dynamic_display(pUpdate, prefix).c_str());
2961 // TODO : If there is a "view" associated with this update, print CI for that view
Tobin Ehlisce132d82015-06-19 15:07:05 -06002962 } else {
Tobin Ehlisbf081f32015-06-15 08:41:17 -06002963 if (0 != pSet->descriptorCount) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002964 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
2965 "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 -06002966 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002967 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
2968 "FYI: No descriptors in descriptor set %#" PRIxLEAST64 ".", (uint64_t) pSet->set);
Tobin Ehlisbf081f32015-06-15 08:41:17 -06002969 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002970 }
2971 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002972 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002973}
2974
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002975static void printCB(layer_data* my_data, const VkCommandBuffer cb)
2976{
2977 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis9a874302016-01-20 10:25:29 -07002978 if (pCB && pCB->cmds.size() > 0) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002979 log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
2980 "Cmds in CB %p", (void*)cb);
Tobin Ehlis9a874302016-01-20 10:25:29 -07002981 vector<CMD_NODE> cmds = pCB->cmds;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002982 for (auto ii=cmds.begin(); ii!=cmds.end(); ++ii) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002983 // TODO : Need to pass cb as srcObj here
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002984 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",
2985 " CMD#%" PRIu64 ": %s", (*ii).cmdNumber, cmdTypeToString((*ii).type).c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002986 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002987 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002988 // Nothing to print
2989 }
2990}
2991
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002992static VkBool32 synchAndPrintDSConfig(layer_data* my_data, const VkCommandBuffer cb)
2993{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002994 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002995 if (!(my_data->report_data->active_flags & VK_DEBUG_REPORT_INFO_BIT_EXT)) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002996 return skipCall;
Mike Stroyanba35e352015-08-12 17:11:28 -06002997 }
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002998 skipCall |= printDSConfig(my_data, cb);
2999 skipCall |= printPipeline(my_data, cb);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003000 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003001}
3002
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003003// Flags validation error if the associated call is made inside a render pass. The apiName
Mark Lobodzinski5495d132015-09-30 16:19:16 -06003004// routine should ONLY be called outside a render pass.
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003005static VkBool32 insideRenderPass(const layer_data* my_data, GLOBAL_CB_NODE *pCB, const char *apiName)
3006{
Mark Lobodzinski5495d132015-09-30 16:19:16 -06003007 VkBool32 inside = VK_FALSE;
3008 if (pCB->activeRenderPass) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003009 inside = log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
3010 (uint64_t)pCB->commandBuffer, __LINE__, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
3011 "%s: It is invalid to issue this call inside an active render pass (%#" PRIxLEAST64 ")",
3012 apiName, (uint64_t) pCB->activeRenderPass);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06003013 }
3014 return inside;
3015}
3016
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003017// Flags validation error if the associated call is made outside a render pass. The apiName
Mark Lobodzinski5495d132015-09-30 16:19:16 -06003018// routine should ONLY be called inside a render pass.
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003019static VkBool32 outsideRenderPass(const layer_data* my_data, GLOBAL_CB_NODE *pCB, const char *apiName)
3020{
Mark Lobodzinski5495d132015-09-30 16:19:16 -06003021 VkBool32 outside = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003022 if (((pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) &&
3023 (!pCB->activeRenderPass)) ||
Mark Lobodzinski74635932015-12-18 15:35:38 -07003024 ((pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) &&
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003025 (!pCB->activeRenderPass) &&
3026 !(pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT))) {
3027 outside = log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
3028 (uint64_t)pCB->commandBuffer, __LINE__, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
3029 "%s: This call must be issued inside an active render pass.", apiName);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06003030 }
3031 return outside;
3032}
3033
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003034static void init_draw_state(layer_data *my_data, const VkAllocationCallbacks *pAllocator)
3035{
Tobin Ehlisa16e8922015-06-16 15:50:44 -06003036 uint32_t report_flags = 0;
3037 uint32_t debug_action = 0;
3038 FILE *log_output = NULL;
3039 const char *option_str;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003040 VkDebugReportCallbackEXT callback;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003041 // initialize DrawState options
Tobin Ehlisa16e8922015-06-16 15:50:44 -06003042 report_flags = getLayerOptionFlags("DrawStateReportFlags", 0);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003043 getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &debug_action);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003044
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003045 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
3046 {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06003047 option_str = getLayerOption("DrawStateLogFilename");
Tobin Ehlisb1df55e2015-09-15 09:55:54 -06003048 log_output = getLayerLogOutput(option_str, "DrawState");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003049 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07003050 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003051 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07003052 dbgInfo.pfnCallback = log_callback;
3053 dbgInfo.pUserData = log_output;
3054 dbgInfo.flags = report_flags;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003055 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06003056 my_data->logging_callback.push_back(callback);
3057 }
3058
3059 if (debug_action & VK_DBG_LAYER_ACTION_DEBUG_OUTPUT) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003060 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07003061 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003062 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07003063 dbgInfo.pfnCallback = win32_debug_output_msg;
3064 dbgInfo.pUserData = log_output;
3065 dbgInfo.flags = report_flags;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003066 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06003067 my_data->logging_callback.push_back(callback);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003068 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003069
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003070 if (!globalLockInitialized)
3071 {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003072 loader_platform_thread_create_mutex(&globalLock);
3073 globalLockInitialized = 1;
3074 }
3075}
3076
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003077VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance)
3078{
3079 VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06003080
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07003081 assert(chain_info->u.pLayerInfo);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003082 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
3083 PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance) fpGetInstanceProcAddr(NULL, "vkCreateInstance");
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07003084 if (fpCreateInstance == NULL) {
3085 return VK_ERROR_INITIALIZATION_FAILED;
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06003086 }
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07003087
3088 // Advance the link info for the next element on the chain
3089 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
3090
3091 VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
3092 if (result != VK_SUCCESS)
3093 return result;
3094
Ian Elliott8c8b2662016-01-30 10:57:03 -07003095 // TBD: Need any locking this early, in case this function is called at the
3096 // same time by more than one thread?
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003097 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07003098 my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003099 layer_init_instance_dispatch_table(*pInstance, my_data->instance_dispatch_table, fpGetInstanceProcAddr);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07003100
3101 my_data->report_data = debug_report_create_instance(
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003102 my_data->instance_dispatch_table,
3103 *pInstance,
3104 pCreateInfo->enabledExtensionCount,
3105 pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07003106
3107 init_draw_state(my_data, pAllocator);
3108
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06003109 return result;
3110}
3111
Jon Ashburn3950e1b2015-05-20 09:00:28 -06003112/* hook DestroyInstance to remove tableInstanceMap entry */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003113VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator)
3114{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003115 // TODOSC : Shouldn't need any customization here
Tobin Ehlisa16e8922015-06-16 15:50:44 -06003116 dispatch_key key = get_dispatch_key(instance);
Ian Elliott8c8b2662016-01-30 10:57:03 -07003117 // TBD: Need any locking this early, in case this function is called at the
3118 // same time by more than one thread?
Tobin Ehlis0b632332015-10-07 09:38:40 -06003119 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
3120 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003121 pTable->DestroyInstance(instance, pAllocator);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06003122
3123 // Clean up logging callback, if any
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06003124 while (my_data->logging_callback.size() > 0) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003125 VkDebugReportCallbackEXT callback = my_data->logging_callback.back();
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07003126 layer_destroy_msg_callback(my_data->report_data, callback, pAllocator);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06003127 my_data->logging_callback.pop_back();
Tobin Ehlisa16e8922015-06-16 15:50:44 -06003128 }
3129
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06003130 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlis0b632332015-10-07 09:38:40 -06003131 delete my_data->instance_dispatch_table;
3132 layer_data_map.erase(key);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003133 // TODO : Potential race here with separate threads creating/destroying instance
Tobin Ehlis0b632332015-10-07 09:38:40 -06003134 if (layer_data_map.empty()) {
Mike Stroyanfcb4ba62015-08-18 15:56:18 -06003135 // Release mutex when destroying last instance.
3136 loader_platform_thread_delete_mutex(&globalLock);
3137 globalLockInitialized = 0;
3138 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06003139}
3140
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003141static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
3142{
Tony Barbour3b4732f2015-07-13 13:37:24 -06003143 uint32_t i;
Ian Elliott8c8b2662016-01-30 10:57:03 -07003144 // TBD: Need any locking, in case this function is called at the same time
3145 // by more than one thread?
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003146 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlis0b632332015-10-07 09:38:40 -06003147 dev_data->device_extensions.debug_marker_enabled = false;
Michael Lentineabc5e922015-10-12 11:30:14 -05003148 dev_data->device_extensions.wsi_enabled = false;
3149
3150
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003151 VkLayerDispatchTable *pDisp = dev_data->device_dispatch_table;
3152 PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr;
3153
3154 pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR) gpa(device, "vkCreateSwapchainKHR");
3155 pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR) gpa(device, "vkDestroySwapchainKHR");
3156 pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR) gpa(device, "vkGetSwapchainImagesKHR");
3157 pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR) gpa(device, "vkAcquireNextImageKHR");
3158 pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR) gpa(device, "vkQueuePresentKHR");
Jon Ashburne68a9ff2015-05-25 14:11:37 -06003159
Jon Ashburnf19916e2016-01-11 13:12:43 -07003160 for (i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003161 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) {
Michael Lentineabc5e922015-10-12 11:30:14 -05003162 dev_data->device_extensions.wsi_enabled = true;
3163 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003164 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
3165 /* Found a matching extension name, mark it enabled and init dispatch table*/
Tobin Ehlis0b632332015-10-07 09:38:40 -06003166 dev_data->device_extensions.debug_marker_enabled = true;
Jon Ashburn1d4b1282015-12-10 19:12:21 -07003167 initDebugMarkerTable(device);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003168
Jon Ashburne68a9ff2015-05-25 14:11:37 -06003169 }
Jon Ashburne68a9ff2015-05-25 14:11:37 -06003170 }
3171}
3172
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003173VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDevice* pDevice)
3174{
3175 VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
Mark Lobodzinski941aea92016-01-13 10:23:15 -07003176
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07003177 assert(chain_info->u.pLayerInfo);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003178 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
3179 PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr;
3180 PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice) fpGetInstanceProcAddr(NULL, "vkCreateDevice");
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07003181 if (fpCreateDevice == NULL) {
3182 return VK_ERROR_INITIALIZATION_FAILED;
Tobin Ehlisa16e8922015-06-16 15:50:44 -06003183 }
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07003184
3185 // Advance the link info for the next element on the chain
3186 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
3187
3188 VkResult result = fpCreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
3189 if (result != VK_SUCCESS) {
3190 return result;
3191 }
3192
Ian Elliott8c8b2662016-01-30 10:57:03 -07003193 // TBD: Need any locking, in case this function is called at the same time
3194 // by more than one thread?
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003195 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
3196 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07003197
3198 // Setup device dispatch table
3199 my_device_data->device_dispatch_table = new VkLayerDispatchTable;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003200 layer_init_device_dispatch_table(*pDevice, my_device_data->device_dispatch_table, fpGetDeviceProcAddr);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07003201
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003202 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07003203 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
3204 // Get physical device limits for this device
Michael Lentine26870f32016-01-26 21:36:08 -06003205 my_instance_data->instance_dispatch_table->GetPhysicalDeviceProperties(gpu, &(my_device_data->physDevProperties.properties));
Michael Lentine7d26c572016-01-28 11:55:28 -06003206 my_instance_data->instance_dispatch_table->GetPhysicalDeviceFeatures(gpu, &(my_device_data->physDevProperties.features));
Michael Lentine26870f32016-01-26 21:36:08 -06003207 uint32_t count;
3208 my_instance_data->instance_dispatch_table->GetPhysicalDeviceQueueFamilyProperties(gpu, &count, nullptr);
3209 my_device_data->physDevProperties.queue_family_properties.resize(count);
3210 my_instance_data->instance_dispatch_table->GetPhysicalDeviceQueueFamilyProperties(gpu, &count, &my_device_data->physDevProperties.queue_family_properties[0]);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003211 return result;
3212}
Tobin Ehlis559c6382015-11-05 09:52:49 -07003213
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06003214// prototype
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003215static void deleteRenderPasses(layer_data*);
3216VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator)
3217{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003218 // TODOSC : Shouldn't need any customization here
Jeremy Hayes5d29ce32015-06-19 11:37:38 -06003219 dispatch_key key = get_dispatch_key(device);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003220 layer_data* dev_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06003221 // Free all the memory
3222 loader_platform_thread_lock_mutex(&globalLock);
3223 deletePipelines(dev_data);
3224 deleteRenderPasses(dev_data);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003225 deleteCommandBuffers(dev_data);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06003226 deletePools(dev_data);
3227 deleteLayouts(dev_data);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003228 dev_data->imageViewMap.clear();
3229 dev_data->imageMap.clear();
3230 dev_data->bufferViewMap.clear();
3231 dev_data->bufferMap.clear();
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06003232 loader_platform_thread_unlock_mutex(&globalLock);
3233
Chia-I Wuf7458c52015-10-26 21:10:41 +08003234 dev_data->device_dispatch_table->DestroyDevice(device, pAllocator);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06003235 tableDebugMarkerMap.erase(key);
Tobin Ehlis0b632332015-10-07 09:38:40 -06003236 delete dev_data->device_dispatch_table;
3237 layer_data_map.erase(key);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003238}
3239
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07003240static const VkExtensionProperties instance_extensions[] = {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003241 {
3242 VK_EXT_DEBUG_REPORT_EXTENSION_NAME,
3243 VK_EXT_DEBUG_REPORT_SPEC_VERSION
3244 }
3245};
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06003246
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003247VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(
3248 const char *pLayerName,
3249 uint32_t *pCount,
3250 VkExtensionProperties* pProperties)
3251{
3252 return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003253}
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06003254
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003255static const VkLayerProperties ds_global_layers[] = {
3256 {
3257 "VK_LAYER_LUNARG_draw_state",
3258 VK_API_VERSION,
3259 VK_MAKE_VERSION(0, 1, 0),
3260 "Validation layer: draw_state",
3261 }
3262};
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07003263
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003264VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(
3265 uint32_t *pCount,
3266 VkLayerProperties* pProperties)
3267{
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003268 return util_GetLayerProperties(ARRAY_SIZE(ds_global_layers),
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003269 ds_global_layers,
3270 pCount, pProperties);
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003271}
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06003272
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003273static const VkExtensionProperties ds_device_extensions[] = {
3274 {
3275 DEBUG_MARKER_EXTENSION_NAME,
3276 VK_MAKE_VERSION(0, 1, 0),
3277 }
3278};
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003279
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003280static const VkLayerProperties ds_device_layers[] = {
3281 {
3282 "VK_LAYER_LUNARG_draw_state",
3283 VK_API_VERSION,
3284 VK_MAKE_VERSION(0, 1, 0),
3285 "Validation layer: draw_state",
3286 }
3287};
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003288
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003289VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(
3290 VkPhysicalDevice physicalDevice,
3291 const char* pLayerName,
3292 uint32_t* pCount,
3293 VkExtensionProperties* pProperties)
3294{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003295 // DrawState does not have any physical device extensions
Jon Ashburn751c4842015-11-02 17:37:20 -07003296 if (pLayerName == NULL) {
3297 dispatch_key key = get_dispatch_key(physicalDevice);
3298 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003299 return my_data->instance_dispatch_table->EnumerateDeviceExtensionProperties(
3300 physicalDevice,
3301 NULL,
3302 pCount,
3303 pProperties);
Jon Ashburn751c4842015-11-02 17:37:20 -07003304 } else {
3305 return util_GetExtensionProperties(ARRAY_SIZE(ds_device_extensions),
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003306 ds_device_extensions,
3307 pCount, pProperties);
Jon Ashburn751c4842015-11-02 17:37:20 -07003308 }
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003309}
3310
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003311VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(
3312 VkPhysicalDevice physicalDevice,
3313 uint32_t* pCount,
3314 VkLayerProperties* pProperties)
3315{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003316 /* DrawState physical device layers are the same as global */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003317 return util_GetLayerProperties(ARRAY_SIZE(ds_device_layers), ds_device_layers,
3318 pCount, pProperties);
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06003319}
3320
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07003321VkBool32 ValidateCmdBufImageLayouts(VkCommandBuffer cmdBuffer) {
Mark Youngb20a6a82016-01-07 15:41:43 -07003322 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003323 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
3324 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Michael Lentineabc5e922015-10-12 11:30:14 -05003325 for (auto cb_image_data : pCB->imageLayoutMap) {
3326 auto image_data = dev_data->imageLayoutMap.find(cb_image_data.first);
3327 if (image_data == dev_data->imageLayoutMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003328 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",
3329 "Cannot submit cmd buffer using deleted image %" PRIu64 ".", (uint64_t)(cb_image_data.first));
Michael Lentineabc5e922015-10-12 11:30:14 -05003330 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003331 if (dev_data->imageLayoutMap[cb_image_data.first]->layout != cb_image_data.second.initialLayout) {
3332 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",
3333 "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);
Michael Lentineabc5e922015-10-12 11:30:14 -05003334 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003335 dev_data->imageLayoutMap[cb_image_data.first]->layout = cb_image_data.second.layout;
Michael Lentineabc5e922015-10-12 11:30:14 -05003336 }
3337 }
3338 return skip_call;
3339}
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003340// Track which resources are in-flight by atomically incrementing their "in_use" count
3341VkBool32 validateAndIncrementResources(layer_data* my_data, GLOBAL_CB_NODE* pCB) {
Mark Youngb20a6a82016-01-07 15:41:43 -07003342 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003343 for (auto drawDataElement : pCB->drawData) {
3344 for (auto buffer : drawDataElement.buffers) {
3345 auto buffer_data = my_data->bufferMap.find(buffer);
3346 if (buffer_data == my_data->bufferMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003347 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, (uint64_t)(buffer), __LINE__, DRAWSTATE_INVALID_BUFFER, "DS",
3348 "Cannot submit cmd buffer using deleted buffer %" PRIu64 ".", (uint64_t)(buffer));
Michael Lentine700b0aa2015-10-30 17:57:32 -07003349 } else {
3350 buffer_data->second.in_use.fetch_add(1);
3351 }
3352 }
3353 }
Tobin Ehlise6e574b2016-01-24 23:25:31 -07003354 for (auto set : pCB->uniqueBoundSets) {
3355 auto setNode = my_data->setMap.find(set);
3356 if (setNode == my_data->setMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003357 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t)(set), __LINE__, DRAWSTATE_INVALID_DESCRIPTOR_SET, "DS",
3358 "Cannot submit cmd buffer using deleted descriptor set %" PRIu64 ".", (uint64_t)(set));
Tobin Ehlise6e574b2016-01-24 23:25:31 -07003359 } else {
3360 setNode->second->in_use.fetch_add(1);
3361 }
3362 }
Michael Lentine2e068b22015-12-29 16:05:27 -06003363 return skip_call;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003364}
3365
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003366void decrementResources(layer_data* my_data, VkCommandBuffer cmdBuffer) {
3367 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cmdBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07003368 for (auto drawDataElement : pCB->drawData) {
3369 for (auto buffer : drawDataElement.buffers) {
3370 auto buffer_data = my_data->bufferMap.find(buffer);
3371 if (buffer_data != my_data->bufferMap.end()) {
3372 buffer_data->second.in_use.fetch_sub(1);
3373 }
3374 }
3375 }
Tobin Ehlise6e574b2016-01-24 23:25:31 -07003376 for (auto set : pCB->uniqueBoundSets) {
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07003377 auto setNode = my_data->setMap.find(set);
3378 if (setNode != my_data->setMap.end()) {
3379 setNode->second->in_use.fetch_sub(1);
3380 }
3381 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003382 for (auto queryStatePair : pCB->queryToStateMap) {
3383 my_data->queryToStateMap[queryStatePair.first] = queryStatePair.second;
3384 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003385}
3386
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003387void decrementResources(layer_data* my_data, uint32_t fenceCount, const VkFence* pFences) {
Michael Lentine700b0aa2015-10-30 17:57:32 -07003388 for (uint32_t i = 0; i < fenceCount; ++i) {
3389 auto fence_data = my_data->fenceMap.find(pFences[i]);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003390 if (fence_data == my_data->fenceMap.end() || !fence_data->second.needsSignaled) return;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003391 fence_data->second.needsSignaled = false;
Michael Lentine37767342016-02-02 22:24:26 -06003392 fence_data->second.in_use.fetch_sub(1);
Michael Lentine700b0aa2015-10-30 17:57:32 -07003393 if (fence_data->second.priorFence != VK_NULL_HANDLE) {
3394 decrementResources(my_data, 1, &fence_data->second.priorFence);
3395 }
3396 for (auto cmdBuffer : fence_data->second.cmdBuffers) {
3397 decrementResources(my_data, cmdBuffer);
3398 }
3399 }
3400}
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07003401
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003402void decrementResources(layer_data* my_data, VkQueue queue) {
Michael Lentine700b0aa2015-10-30 17:57:32 -07003403 auto queue_data = my_data->queueMap.find(queue);
3404 if (queue_data != my_data->queueMap.end()) {
3405 for (auto cmdBuffer : queue_data->second.untrackedCmdBuffers) {
3406 decrementResources(my_data, cmdBuffer);
3407 }
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07003408 queue_data->second.untrackedCmdBuffers.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07003409 decrementResources(my_data, 1, &queue_data->second.priorFence);
3410 }
3411}
3412
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003413void trackCommandBuffers(layer_data* my_data, VkQueue queue, uint32_t cmdBufferCount, const VkCommandBuffer* pCmdBuffers, VkFence fence) {
Michael Lentine700b0aa2015-10-30 17:57:32 -07003414 auto queue_data = my_data->queueMap.find(queue);
3415 if (fence != VK_NULL_HANDLE) {
3416 VkFence priorFence = VK_NULL_HANDLE;
Michael Lentine37767342016-02-02 22:24:26 -06003417 auto fence_data = my_data->fenceMap.find(fence);
3418 if (fence_data == my_data->fenceMap.end()) {
3419 return;
3420 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003421 if (queue_data != my_data->queueMap.end()) {
3422 priorFence = queue_data->second.priorFence;
3423 queue_data->second.priorFence = fence;
3424 for (auto cmdBuffer : queue_data->second.untrackedCmdBuffers) {
Michael Lentine37767342016-02-02 22:24:26 -06003425 fence_data->second.cmdBuffers.push_back(cmdBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07003426 }
3427 queue_data->second.untrackedCmdBuffers.clear();
3428 }
Michael Lentine37767342016-02-02 22:24:26 -06003429 fence_data->second.cmdBuffers.clear();
3430 fence_data->second.priorFence = priorFence;
3431 fence_data->second.needsSignaled = true;
3432 fence_data->second.queue = queue;
3433 fence_data->second.in_use.fetch_add(1);
Michael Lentine700b0aa2015-10-30 17:57:32 -07003434 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
Michael Lentine37767342016-02-02 22:24:26 -06003435 for (auto secondaryCmdBuffer :
3436 my_data->commandBufferMap[pCmdBuffers[i]]
3437 ->secondaryCommandBuffers) {
3438 fence_data->second.cmdBuffers.push_back(
3439 secondaryCmdBuffer);
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003440 }
Michael Lentine37767342016-02-02 22:24:26 -06003441 fence_data->second.cmdBuffers.push_back(pCmdBuffers[i]);
Michael Lentine700b0aa2015-10-30 17:57:32 -07003442 }
3443 } else {
3444 if (queue_data != my_data->queueMap.end()) {
3445 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003446 for (auto secondaryCmdBuffer : my_data->commandBufferMap[pCmdBuffers[i]]->secondaryCommandBuffers) {
3447 queue_data->second.untrackedCmdBuffers.push_back(secondaryCmdBuffer);
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003448 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003449 queue_data->second.untrackedCmdBuffers.push_back(pCmdBuffers[i]);
Michael Lentine700b0aa2015-10-30 17:57:32 -07003450 }
3451 }
3452 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003453 if (queue_data != my_data->queueMap.end()) {
3454 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003455 // Add cmdBuffers to both the global set and queue set
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003456 for (auto secondaryCmdBuffer : my_data->commandBufferMap[pCmdBuffers[i]]->secondaryCommandBuffers) {
Tobin Ehlis74714d22016-01-25 15:24:34 -08003457 my_data->globalInFlightCmdBuffers.insert(secondaryCmdBuffer);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003458 queue_data->second.inFlightCmdBuffers.insert(secondaryCmdBuffer);
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003459 }
Tobin Ehlis74714d22016-01-25 15:24:34 -08003460 my_data->globalInFlightCmdBuffers.insert(pCmdBuffers[i]);
3461 queue_data->second.inFlightCmdBuffers.insert(pCmdBuffers[i]);
3462 }
3463 }
3464}
3465
Michael Lentinec7cf9182016-02-03 09:20:33 -06003466bool validateCommandBufferSimultaneousUse(layer_data *dev_data,
3467 GLOBAL_CB_NODE *pCB) {
3468 bool skip_call = false;
3469 if (dev_data->globalInFlightCmdBuffers.count(pCB->commandBuffer) &&
3470 !(pCB->beginInfo.flags &
3471 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT)) {
3472 skip_call |= log_msg(
3473 dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
3474 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__,
3475 DRAWSTATE_INVALID_FENCE, "DS",
3476 "Command Buffer %#" PRIx64 " is already in use and is not marked "
3477 "for simultaneous use.",
3478 reinterpret_cast<uint64_t>(pCB->commandBuffer));
3479 }
3480 return skip_call;
3481}
3482
3483static VkBool32 validateCommandBufferState(layer_data *dev_data,
3484 GLOBAL_CB_NODE *pCB) {
Tobin Ehlis74714d22016-01-25 15:24:34 -08003485 // Track in-use for resources off of primary and any secondary CBs
3486 VkBool32 skipCall = validateAndIncrementResources(dev_data, pCB);
3487 if (!pCB->secondaryCommandBuffers.empty()) {
3488 for (auto secondaryCmdBuffer : pCB->secondaryCommandBuffers) {
Michael Lentinec7cf9182016-02-03 09:20:33 -06003489 skipCall |= validateAndIncrementResources(
3490 dev_data, dev_data->commandBufferMap[secondaryCmdBuffer]);
3491 GLOBAL_CB_NODE* pSubCB = getCBNode(dev_data, secondaryCmdBuffer);
3492 skipCall |= validateCommandBufferSimultaneousUse(dev_data, pSubCB);
Michael Lentined7621bb2016-02-03 10:55:23 -06003493 if (pSubCB->primaryCommandBuffer != pCB->commandBuffer) {
3494 log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
3495 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0,
3496 __LINE__,
3497 DRAWSTATE_COMMAND_BUFFER_SINGLE_SUBMIT_VIOLATION, "DS",
3498 "CB %#" PRIxLEAST64
3499 " was submitted with secondary buffer %#" PRIxLEAST64
3500 " but that buffer has subsequently been bound to "
3501 "primary cmd buffer %#" PRIxLEAST64 ".",
3502 reinterpret_cast<uint64_t>(pCB->commandBuffer),
3503 reinterpret_cast<uint64_t>(secondaryCmdBuffer),
3504 reinterpret_cast<uint64_t>(
3505 pSubCB->primaryCommandBuffer));
3506 }
Tobin Ehlis74714d22016-01-25 15:24:34 -08003507 }
3508 }
Michael Lentinec7cf9182016-02-03 09:20:33 -06003509 if ((pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT) &&
3510 (pCB->submitCount > 1)) {
3511 skipCall |=
3512 log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
3513 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__,
3514 DRAWSTATE_COMMAND_BUFFER_SINGLE_SUBMIT_VIOLATION, "DS",
3515 "CB %#" PRIxLEAST64
3516 " was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT "
3517 "set, but has been submitted %#" PRIxLEAST64 " times.",
3518 (uint64_t)(pCB->commandBuffer), pCB->submitCount);
Tobin Ehlis74714d22016-01-25 15:24:34 -08003519 }
3520 // Validate that cmd buffers have been updated
3521 if (CB_RECORDED != pCB->state) {
3522 if (CB_INVALID == pCB->state) {
3523 // Inform app of reason CB invalid
3524 if (!pCB->destroyedSets.empty()) {
3525 std::stringstream set_string;
3526 for (auto set : pCB->destroyedSets) {
3527 set_string << " " << set;
3528 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003529 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)(pCB->commandBuffer), __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER, "DS",
3530 "You are submitting command buffer %#" PRIxLEAST64 " that is invalid because it had the following bound descriptor set(s) destroyed: %s", (uint64_t)(pCB->commandBuffer), set_string.str().c_str());
Tobin Ehlis74714d22016-01-25 15:24:34 -08003531 }
3532 if (!pCB->updatedSets.empty()) {
3533 std::stringstream set_string;
3534 for (auto set : pCB->updatedSets) {
3535 set_string << " " << set;
3536 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003537 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)(pCB->commandBuffer), __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER, "DS",
3538 "You are submitting command buffer %#" PRIxLEAST64 " that is invalid because it had the following bound descriptor set(s) updated: %s", (uint64_t)(pCB->commandBuffer), set_string.str().c_str());
Tobin Ehlis74714d22016-01-25 15:24:34 -08003539 }
3540 } else { // Flag error for using CB w/o vkEndCommandBuffer() called
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003541 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)(pCB->commandBuffer), __LINE__, DRAWSTATE_NO_END_COMMAND_BUFFER, "DS",
3542 "You must call vkEndCommandBuffer() on CB %#" PRIxLEAST64 " before this call to vkQueueSubmit()!", (uint64_t)(pCB->commandBuffer));
Tobin Ehlis74714d22016-01-25 15:24:34 -08003543 }
3544 }
Michael Lentine0998ede2016-02-03 14:26:30 -06003545 return skipCall;
3546}
3547
3548static VkBool32 validatePrimaryCommandBufferState(layer_data *dev_data,
3549 GLOBAL_CB_NODE *pCB) {
3550 // Track in-use for resources off of primary and any secondary CBs
3551 VkBool32 skipCall = validateAndIncrementResources(dev_data, pCB);
3552 if (!pCB->secondaryCommandBuffers.empty()) {
3553 for (auto secondaryCmdBuffer : pCB->secondaryCommandBuffers) {
3554 skipCall |= validateAndIncrementResources(
3555 dev_data, dev_data->commandBufferMap[secondaryCmdBuffer]);
3556 }
3557 }
3558 if ((pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT) &&
3559 (pCB->submitCount > 1)) {
3560 skipCall |=
3561 log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
3562 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__,
3563 DRAWSTATE_COMMAND_BUFFER_SINGLE_SUBMIT_VIOLATION, "DS",
3564 "CB %#" PRIxLEAST64
3565 " was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT "
3566 "set, but has been submitted %#" PRIxLEAST64 " times.",
3567 (uint64_t)(pCB->commandBuffer), pCB->submitCount);
3568 }
3569 validateCommandBufferState(dev_data, pCB);
Michael Lentinec7cf9182016-02-03 09:20:33 -06003570 // If USAGE_SIMULTANEOUS_USE_BIT not set then CB cannot already be executing
3571 // on device
3572 skipCall |= validateCommandBufferSimultaneousUse(dev_data, pCB);
Tobin Ehlisceb0b862016-02-01 06:50:57 -08003573 return skipCall;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003574}
3575
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003576VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence fence)
3577{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003578 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003579 GLOBAL_CB_NODE* pCB = NULL;
3580 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07003581 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003582 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08003583 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003584 for (uint32_t i=0; i < submit->waitSemaphoreCount; ++i) {
Michael Lentine15a47882016-01-06 10:05:48 -06003585 if (dev_data->semaphoreSignaledMap[submit->pWaitSemaphores[i]]) {
3586 dev_data->semaphoreSignaledMap[submit->pWaitSemaphores[i]] = 0;
3587 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003588 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",
3589 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
3590 (uint64_t)(queue), (uint64_t)(submit->pWaitSemaphores[i]));
Michael Lentine15a47882016-01-06 10:05:48 -06003591 }
3592 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003593 for (uint32_t i=0; i < submit->signalSemaphoreCount; ++i) {
Michael Lentine15a47882016-01-06 10:05:48 -06003594 dev_data->semaphoreSignaledMap[submit->pSignalSemaphores[i]] = 1;
3595 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003596 for (uint32_t i=0; i < submit->commandBufferCount; i++) {
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07003597#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
Ian Elliott8c8b2662016-01-30 10:57:03 -07003598 skipCall |= ValidateCmdBufImageLayouts(submit->pCommandBuffers[i]);
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07003599#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
3600
Ian Elliott8c8b2662016-01-30 10:57:03 -07003601 pCB = getCBNode(dev_data, submit->pCommandBuffers[i], false);
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003602 pCB->submitCount++; // increment submit count
Michael Lentine0998ede2016-02-03 14:26:30 -06003603 skipCall |= validatePrimaryCommandBufferState(dev_data, pCB);
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06003604 }
Michael Lentine37767342016-02-02 22:24:26 -06003605 if (dev_data->fenceMap[fence].in_use.load()) {
3606 skipCall |= log_msg(
3607 dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
3608 VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT,
Dustin Graves962b01e2016-02-04 11:38:48 -07003609 (uint64_t)(fence), __LINE__,
Michael Lentine37767342016-02-02 22:24:26 -06003610 DRAWSTATE_INVALID_FENCE, "DS",
3611 "Fence %#" PRIx64 " is already in use by another submission.",
Dustin Graves962b01e2016-02-04 11:38:48 -07003612 (uint64_t)(fence));
Michael Lentine37767342016-02-02 22:24:26 -06003613 }
3614 trackCommandBuffers(dev_data, queue, submit->commandBufferCount,
3615 submit->pCommandBuffers, fence);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003616 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07003617 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003618 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003619 return dev_data->device_dispatch_table->QueueSubmit(queue, submitCount, pSubmits, fence);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003620 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003621}
3622
Ian Elliott8c8b2662016-01-30 10:57:03 -07003623// Note: This function assumes that the global lock is held by the calling
3624// thread.
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003625VkBool32 cleanInFlightCmdBuffer(layer_data* my_data, VkCommandBuffer cmdBuffer) {
Mark Youngb20a6a82016-01-07 15:41:43 -07003626 VkBool32 skip_call = VK_FALSE;
Ian Elliott8c8b2662016-01-30 10:57:03 -07003627 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cmdBuffer, false);
Mark Lobodzinskia9e7c042016-01-25 14:27:49 -07003628 if (pCB) {
3629 for (auto queryEventsPair : pCB->waitedEventsBeforeQueryReset) {
3630 for (auto event : queryEventsPair.second) {
3631 if (my_data->eventMap[event].needsSignaled) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003632 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",
3633 "Cannot get query results on queryPool %" PRIu64 " with index %d which was guarded by unsignaled event %" PRIu64 ".",
3634 (uint64_t)(queryEventsPair.first.pool), queryEventsPair.first.index, (uint64_t)(event));
Mark Lobodzinskia9e7c042016-01-25 14:27:49 -07003635 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003636 }
3637 }
3638 }
3639 return skip_call;
3640}
Tobin Ehlis74714d22016-01-25 15:24:34 -08003641// Remove given cmd_buffer from the global inFlight set.
3642// Also, if given queue is valid, then remove the cmd_buffer from that queues
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003643// inFlightCmdBuffer set. Finally, check all other queues and if given cmd_buffer
Tobin Ehlis74714d22016-01-25 15:24:34 -08003644// is still in flight on another queue, add it back into the global set.
Ian Elliott8c8b2662016-01-30 10:57:03 -07003645// Note: This function assumes that the global lock is held by the calling
3646// thread.
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003647static inline void removeInFlightCmdBuffer(layer_data* dev_data, VkCommandBuffer cmd_buffer, VkQueue queue)
3648{
3649 // Pull it off of global list initially, but if we find it in any other queue list, add it back in
Tobin Ehlis74714d22016-01-25 15:24:34 -08003650 dev_data->globalInFlightCmdBuffers.erase(cmd_buffer);
3651 if (dev_data->queueMap.find(queue) != dev_data->queueMap.end()) {
3652 dev_data->queueMap[queue].inFlightCmdBuffers.erase(cmd_buffer);
3653 for (auto q : dev_data->queues) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003654 if ((q != queue) && (dev_data->queueMap[q].inFlightCmdBuffers.find(cmd_buffer) != dev_data->queueMap[q].inFlightCmdBuffers.end())) {
Tobin Ehlis74714d22016-01-25 15:24:34 -08003655 dev_data->globalInFlightCmdBuffers.insert(cmd_buffer);
3656 break;
3657 }
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003658 }
3659 }
3660}
Michael Lentineb887b0a2015-12-29 14:12:11 -06003661
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003662VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence* pFences, VkBool32 waitAll, uint64_t timeout)
3663{
3664 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3665 VkResult result = dev_data->device_dispatch_table->WaitForFences(device, fenceCount, pFences, waitAll, timeout);
Mark Youngb20a6a82016-01-07 15:41:43 -07003666 VkBool32 skip_call = VK_FALSE;
Ian Elliott8c8b2662016-01-30 10:57:03 -07003667 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis74714d22016-01-25 15:24:34 -08003668 if (result == VK_SUCCESS) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003669 // When we know that all fences are complete we can clean/remove their CBs
Tobin Ehlis74714d22016-01-25 15:24:34 -08003670 if (waitAll || fenceCount == 1) {
3671 for (uint32_t i = 0; i < fenceCount; ++i) {
3672 VkQueue fence_queue = dev_data->fenceMap[pFences[i]].queue;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003673 for (auto cmdBuffer : dev_data->fenceMap[pFences[i]].cmdBuffers) {
Tobin Ehlis74714d22016-01-25 15:24:34 -08003674 skip_call |= cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3675 removeInFlightCmdBuffer(dev_data, cmdBuffer, fence_queue);
3676 }
3677 }
3678 decrementResources(dev_data, fenceCount, pFences);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003679 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003680 // NOTE : Alternate case not handled here is when some fences have completed. In
3681 // this case for app to guarantee which fences completed it will have to call
3682 // vkGetFenceStatus() at which point we'll clean/remove their CBs if complete.
Michael Lentine700b0aa2015-10-30 17:57:32 -07003683 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07003684 loader_platform_thread_unlock_mutex(&globalLock);
Mark Youngb20a6a82016-01-07 15:41:43 -07003685 if (VK_FALSE != skip_call)
Mark Lobodzinskice738852016-01-07 10:04:02 -07003686 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003687 return result;
3688}
3689
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003690
3691VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetFenceStatus(VkDevice device, VkFence fence)
3692{
3693 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3694 VkResult result = dev_data->device_dispatch_table->GetFenceStatus(device, fence);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003695 VkBool32 skip_call = VK_FALSE;
Ian Elliott8c8b2662016-01-30 10:57:03 -07003696 loader_platform_thread_lock_mutex(&globalLock);
Michael Lentine700b0aa2015-10-30 17:57:32 -07003697 if (result == VK_SUCCESS) {
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003698 auto fence_queue = dev_data->fenceMap[fence].queue;
Michael Lentineb887b0a2015-12-29 14:12:11 -06003699 for (auto cmdBuffer : dev_data->fenceMap[fence].cmdBuffers) {
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003700 skip_call |= cleanInFlightCmdBuffer(dev_data, cmdBuffer);
Tobin Ehlis74714d22016-01-25 15:24:34 -08003701 removeInFlightCmdBuffer(dev_data, cmdBuffer, fence_queue);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003702 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003703 decrementResources(dev_data, 1, &fence);
3704 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07003705 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003706 if (VK_FALSE != skip_call)
3707 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003708 return result;
3709}
3710
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003711VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue* pQueue)
3712{
3713 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07003714 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003715 dev_data->device_dispatch_table->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003716 dev_data->queues.push_back(*pQueue);
Michael Lentine700b0aa2015-10-30 17:57:32 -07003717 dev_data->queueMap[*pQueue].device = device;
Ian Elliott8c8b2662016-01-30 10:57:03 -07003718 loader_platform_thread_unlock_mutex(&globalLock);
Michael Lentine700b0aa2015-10-30 17:57:32 -07003719}
3720
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003721VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueueWaitIdle(VkQueue queue)
3722{
3723 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Michael Lentine700b0aa2015-10-30 17:57:32 -07003724 decrementResources(dev_data, queue);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003725 VkBool32 skip_call = VK_FALSE;
Ian Elliott8c8b2662016-01-30 10:57:03 -07003726 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003727 // Iterate over local set since we erase set members as we go in for loop
3728 auto local_cb_set = dev_data->queueMap[queue].inFlightCmdBuffers;
3729 for (auto cmdBuffer : local_cb_set) {
3730 skip_call |= cleanInFlightCmdBuffer(dev_data, cmdBuffer);
Tobin Ehlis74714d22016-01-25 15:24:34 -08003731 removeInFlightCmdBuffer(dev_data, cmdBuffer, queue);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003732 }
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003733 dev_data->queueMap[queue].inFlightCmdBuffers.clear();
Ian Elliott8c8b2662016-01-30 10:57:03 -07003734 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003735 if (VK_FALSE != skip_call)
3736 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003737 return dev_data->device_dispatch_table->QueueWaitIdle(queue);
3738}
3739
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003740VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkDeviceWaitIdle(VkDevice device)
3741{
Tobin Ehlis74714d22016-01-25 15:24:34 -08003742 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003743 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07003744 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003745 for (auto queue : dev_data->queues) {
3746 decrementResources(dev_data, queue);
Tobin Ehlis74714d22016-01-25 15:24:34 -08003747 if (dev_data->queueMap.find(queue) != dev_data->queueMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003748 // Clear all of the queue inFlightCmdBuffers (global set cleared below)
Tobin Ehlis74714d22016-01-25 15:24:34 -08003749 dev_data->queueMap[queue].inFlightCmdBuffers.clear();
3750 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003751 }
Tobin Ehlis74714d22016-01-25 15:24:34 -08003752 for (auto cmdBuffer : dev_data->globalInFlightCmdBuffers) {
3753 skip_call |= cleanInFlightCmdBuffer(dev_data, cmdBuffer);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003754 }
Tobin Ehlis74714d22016-01-25 15:24:34 -08003755 dev_data->globalInFlightCmdBuffers.clear();
Ian Elliott8c8b2662016-01-30 10:57:03 -07003756 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis74714d22016-01-25 15:24:34 -08003757 if (VK_FALSE != skip_call)
3758 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003759 return dev_data->device_dispatch_table->DeviceWaitIdle(device);
3760}
3761
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003762VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks* pAllocator)
3763{
3764 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 -06003765 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003766}
3767
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003768VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySemaphore(VkDevice device, VkSemaphore semaphore, const VkAllocationCallbacks* pAllocator)
3769{
3770 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3771 dev_data->device_dispatch_table->DestroySemaphore(device, semaphore, pAllocator);
Ian Elliott8c8b2662016-01-30 10:57:03 -07003772 loader_platform_thread_lock_mutex(&globalLock);
Michael Lentine15a47882016-01-06 10:05:48 -06003773 dev_data->semaphoreSignaledMap.erase(semaphore);
Ian Elliott8c8b2662016-01-30 10:57:03 -07003774 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003775 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003776}
3777
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003778VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks* pAllocator)
3779{
3780 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 -06003781 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003782}
3783
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003784VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool, const VkAllocationCallbacks* pAllocator)
3785{
3786 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 -06003787 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003788}
3789
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003790VKAPI_ATTR VkResult VKAPI_CALL vkGetQueryPoolResults(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount,
3791 size_t dataSize, void* pData, VkDeviceSize stride, VkQueryResultFlags flags) {
3792 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003793 unordered_map<QueryObject, vector<VkCommandBuffer>> queriesInFlight;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003794 GLOBAL_CB_NODE* pCB = nullptr;
Ian Elliott8c8b2662016-01-30 10:57:03 -07003795 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis74714d22016-01-25 15:24:34 -08003796 for (auto cmdBuffer : dev_data->globalInFlightCmdBuffers) {
Ian Elliott8c8b2662016-01-30 10:57:03 -07003797 pCB = getCBNode(dev_data, cmdBuffer, false);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003798 for (auto queryStatePair : pCB->queryToStateMap) {
3799 queriesInFlight[queryStatePair.first].push_back(cmdBuffer);
3800 }
3801 }
Mark Youngb20a6a82016-01-07 15:41:43 -07003802 VkBool32 skip_call = VK_FALSE;
Michael Lentineb887b0a2015-12-29 14:12:11 -06003803 for (uint32_t i = 0; i < queryCount; ++i) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003804 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06003805 auto queryElement = queriesInFlight.find(query);
3806 auto queryToStateElement = dev_data->queryToStateMap.find(query);
3807 if (queryToStateElement != dev_data->queryToStateMap.end()) {
3808 }
3809 // Available and in flight
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003810 if(queryElement != queriesInFlight.end() && queryToStateElement != dev_data->queryToStateMap.end() && queryToStateElement->second) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06003811 for (auto cmdBuffer : queryElement->second) {
Ian Elliott8c8b2662016-01-30 10:57:03 -07003812 pCB = getCBNode(dev_data, cmdBuffer, false);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003813 auto queryEventElement = pCB->waitedEventsBeforeQueryReset.find(query);
3814 if (queryEventElement == pCB->waitedEventsBeforeQueryReset.end()) {
3815 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT, 0, __LINE__,
3816 DRAWSTATE_INVALID_QUERY, "DS", "Cannot get query results on queryPool %" PRIu64 " with index %d which is in flight.",
3817 (uint64_t)(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003818 } else {
3819 for (auto event : queryEventElement->second) {
3820 dev_data->eventMap[event].needsSignaled = true;
3821 }
3822 }
3823 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003824 // Unavailable and in flight
3825 } else if (queryElement != queriesInFlight.end() && queryToStateElement != dev_data->queryToStateMap.end() && !queryToStateElement->second) {
3826 // TODO : Can there be the same query in use by multiple command buffers in flight?
Michael Lentineb887b0a2015-12-29 14:12:11 -06003827 bool make_available = false;
3828 for (auto cmdBuffer : queryElement->second) {
Ian Elliott8c8b2662016-01-30 10:57:03 -07003829 pCB = getCBNode(dev_data, cmdBuffer, false);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003830 make_available |= pCB->queryToStateMap[query];
3831 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003832 if (!(((flags & VK_QUERY_RESULT_PARTIAL_BIT) || (flags & VK_QUERY_RESULT_WAIT_BIT)) && make_available)) {
3833 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",
3834 "Cannot get query results on queryPool %" PRIu64 " with index %d which is unavailable.",
3835 (uint64_t)(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003836 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003837 // Unavailable
3838 } else if (queryToStateElement != dev_data->queryToStateMap.end() && !queryToStateElement->second) {
3839 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",
3840 "Cannot get query results on queryPool %" PRIu64 " with index %d which is unavailable.",
3841 (uint64_t)(queryPool), firstQuery + i);
3842 // Unitialized
Michael Lentineb887b0a2015-12-29 14:12:11 -06003843 } else if (queryToStateElement == dev_data->queryToStateMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003844 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",
3845 "Cannot get query results on queryPool %" PRIu64 " with index %d which is uninitialized.",
3846 (uint64_t)(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003847 }
3848 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07003849 loader_platform_thread_unlock_mutex(&globalLock);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003850 if (skip_call)
Mark Lobodzinskice738852016-01-07 10:04:02 -07003851 return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003852 return dev_data->device_dispatch_table->GetQueryPoolResults(device, queryPool, firstQuery, queryCount, dataSize, pData, stride, flags);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003853}
3854
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003855VkBool32 validateIdleBuffer(const layer_data* my_data, VkBuffer buffer) {
Mark Youngb20a6a82016-01-07 15:41:43 -07003856 VkBool32 skip_call = VK_FALSE;
Ian Elliott8c8b2662016-01-30 10:57:03 -07003857 loader_platform_thread_lock_mutex(&globalLock);
Michael Lentine700b0aa2015-10-30 17:57:32 -07003858 auto buffer_data = my_data->bufferMap.find(buffer);
3859 if (buffer_data == my_data->bufferMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003860 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, (uint64_t)(buffer), __LINE__, DRAWSTATE_DOUBLE_DESTROY, "DS",
3861 "Cannot free buffer %" PRIxLEAST64 " that has not been allocated.", (uint64_t)(buffer));
Michael Lentine700b0aa2015-10-30 17:57:32 -07003862 } else {
3863 if (buffer_data->second.in_use.load()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003864 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, (uint64_t)(buffer), __LINE__, DRAWSTATE_OBJECT_INUSE, "DS",
3865 "Cannot free buffer %" PRIxLEAST64 " that is in use by a command buffer.", (uint64_t)(buffer));
Michael Lentine700b0aa2015-10-30 17:57:32 -07003866 }
3867 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07003868 loader_platform_thread_unlock_mutex(&globalLock);
Michael Lentine700b0aa2015-10-30 17:57:32 -07003869 return skip_call;
3870}
3871
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003872VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks* pAllocator)
3873{
3874 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07003875 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003876 if (!validateIdleBuffer(dev_data, buffer)) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003877 dev_data->device_dispatch_table->DestroyBuffer(device, buffer, pAllocator);
Michael Lentine700b0aa2015-10-30 17:57:32 -07003878 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07003879 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003880 dev_data->bufferMap.erase(buffer);
Ian Elliott8c8b2662016-01-30 10:57:03 -07003881 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003882}
3883
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003884VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBufferView(VkDevice device, VkBufferView bufferView, const VkAllocationCallbacks* pAllocator)
3885{
3886 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3887 dev_data->device_dispatch_table->DestroyBufferView(device, bufferView, pAllocator);
Ian Elliott8c8b2662016-01-30 10:57:03 -07003888 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003889 dev_data->bufferViewMap.erase(bufferView);
Ian Elliott8c8b2662016-01-30 10:57:03 -07003890 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003891}
3892
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003893VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks* pAllocator)
3894{
3895 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003896 dev_data->device_dispatch_table->DestroyImage(device, image, pAllocator);
Ian Elliott8c8b2662016-01-30 10:57:03 -07003897 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003898 dev_data->imageMap.erase(image);
Ian Elliott8c8b2662016-01-30 10:57:03 -07003899 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003900}
3901
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003902VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyImageView(VkDevice device, VkImageView imageView, const VkAllocationCallbacks* pAllocator)
3903{
3904 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 -06003905 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003906}
3907
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003908VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule, const VkAllocationCallbacks* pAllocator)
3909{
3910 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 -06003911 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003912}
3913
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003914VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyPipeline(VkDevice device, VkPipeline pipeline, const VkAllocationCallbacks* pAllocator)
3915{
3916 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 -06003917 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003918}
3919
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003920VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout, const VkAllocationCallbacks* pAllocator)
3921{
3922 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 -06003923 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003924}
3925
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003926VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySampler(VkDevice device, VkSampler sampler, const VkAllocationCallbacks* pAllocator)
3927{
3928 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 -06003929 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003930}
3931
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003932VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout, const VkAllocationCallbacks* pAllocator)
3933{
3934 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 -06003935 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003936}
3937
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003938VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, const VkAllocationCallbacks* pAllocator)
3939{
3940 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 -06003941 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003942}
3943
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003944VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t count, const VkCommandBuffer *pCommandBuffers)
3945{
3946 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003947
Michael Lentine5f6dc4f2016-01-27 20:42:07 -06003948 bool skip_call = false;
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07003949 for (uint32_t i = 0; i < count; i++) {
Tobin Ehlis74714d22016-01-25 15:24:34 -08003950 loader_platform_thread_lock_mutex(&globalLock);
Michael Lentine5f6dc4f2016-01-27 20:42:07 -06003951 if (dev_data->globalInFlightCmdBuffers.count(pCommandBuffers[i])) {
3952 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
3953 reinterpret_cast<uint64_t>(pCommandBuffers[i]), __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
3954 "Attempt to free command buffer (%#" PRIxLEAST64 ") which is in use.", reinterpret_cast<uint64_t>(pCommandBuffers[i]));
3955 }
Mark Lobodzinski39298632015-11-18 08:38:27 -07003956 // Delete CB information structure, and remove from commandBufferMap
3957 auto cb = dev_data->commandBufferMap.find(pCommandBuffers[i]);
3958 if (cb != dev_data->commandBufferMap.end()) {
Tobin Ehlise6e574b2016-01-24 23:25:31 -07003959 // reset prior to delete for data clean-up
3960 resetCB(dev_data, (*cb).second->commandBuffer);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003961 delete (*cb).second;
3962 dev_data->commandBufferMap.erase(cb);
3963 }
3964
3965 // Remove commandBuffer reference from commandPoolMap
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003966 dev_data->commandPoolMap[commandPool].commandBuffers.remove(pCommandBuffers[i]);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003967 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003968 }
3969
Michael Lentine5f6dc4f2016-01-27 20:42:07 -06003970 if (!skip_call)
3971 dev_data->device_dispatch_table->FreeCommandBuffers(device, commandPool, count, pCommandBuffers);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003972}
3973
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003974VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkCommandPool* pCommandPool)
3975{
3976 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003977
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003978 VkResult result = dev_data->device_dispatch_table->CreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003979
3980 if (VK_SUCCESS == result) {
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003981 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003982 dev_data->commandPoolMap[*pCommandPool].createFlags = pCreateInfo->flags;
Michael Lentined1b2a8b2016-02-03 21:20:25 -06003983 dev_data->commandPoolMap[*pCommandPool].queueFamilyIndex = pCreateInfo->queueFamilyIndex;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003984 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003985 }
3986 return result;
3987}
Michael Lentinee063fe42016-01-27 17:52:20 -06003988
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003989VkBool32 validateCommandBuffersNotInUse(const layer_data* dev_data, VkCommandPool commandPool) {
Mark Youngbaa677f2016-01-28 09:36:15 -07003990 VkBool32 skipCall = VK_FALSE;
Michael Lentinee063fe42016-01-27 17:52:20 -06003991 loader_platform_thread_lock_mutex(&globalLock);
3992 auto pool_data = dev_data->commandPoolMap.find(commandPool);
3993 if (pool_data != dev_data->commandPoolMap.end()) {
3994 for (auto cmdBuffer : pool_data->second.commandBuffers) {
Tobin Ehlis74714d22016-01-25 15:24:34 -08003995 if (dev_data->globalInFlightCmdBuffers.count(cmdBuffer)) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003996 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT, (uint64_t)(commandPool),
3997 __LINE__, DRAWSTATE_OBJECT_INUSE, "DS", "Cannot reset command pool %" PRIx64 " when allocated command buffer %" PRIx64 " is in use.",
3998 (uint64_t)(commandPool), (uint64_t)(cmdBuffer));
Michael Lentinee063fe42016-01-27 17:52:20 -06003999 }
4000 }
4001 }
4002 loader_platform_thread_unlock_mutex(&globalLock);
Mark Youngbaa677f2016-01-28 09:36:15 -07004003 return skipCall;
Michael Lentinee063fe42016-01-27 17:52:20 -06004004}
4005
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004006// Destroy commandPool along with all of the commandBuffers allocated from that pool
4007VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks* pAllocator)
4008{
4009 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07004010 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07004011
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004012 // Must remove cmdpool from cmdpoolmap, after removing all cmdbuffers in its list from the commandPoolMap
4013 if (dev_data->commandPoolMap.find(commandPool) != dev_data->commandPoolMap.end()) {
4014 for (auto poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.begin(); poolCb != dev_data->commandPoolMap[commandPool].commandBuffers.end();) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07004015 auto del_cb = dev_data->commandBufferMap.find(*poolCb);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004016 delete (*del_cb).second; // delete CB info structure
4017 dev_data->commandBufferMap.erase(del_cb); // Remove this command buffer from cbMap
4018 poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.erase(poolCb); // Remove CB reference from commandPoolMap's list
Mark Lobodzinski39298632015-11-18 08:38:27 -07004019 }
4020 }
4021 dev_data->commandPoolMap.erase(commandPool);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07004022
4023 loader_platform_thread_unlock_mutex(&globalLock);
Michael Lentinee063fe42016-01-27 17:52:20 -06004024
Mark Youngbaa677f2016-01-28 09:36:15 -07004025 if (VK_TRUE == validateCommandBuffersNotInUse(dev_data, commandPool))
Michael Lentinee063fe42016-01-27 17:52:20 -06004026 return;
4027
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004028 dev_data->device_dispatch_table->DestroyCommandPool(device, commandPool, pAllocator);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004029}
4030
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004031VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandPool(
4032 VkDevice device,
4033 VkCommandPool commandPool,
4034 VkCommandPoolResetFlags flags)
4035{
4036 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4037 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004038
Mark Youngbaa677f2016-01-28 09:36:15 -07004039 if (VK_TRUE == validateCommandBuffersNotInUse(dev_data, commandPool))
Michael Lentined2a7d632016-01-27 17:02:39 -06004040 return VK_ERROR_VALIDATION_FAILED_EXT;
4041
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004042 result = dev_data->device_dispatch_table->ResetCommandPool(device, commandPool, flags);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004043 // Reset all of the CBs allocated from this pool
4044 if (VK_SUCCESS == result) {
Tobin Ehlis74714d22016-01-25 15:24:34 -08004045 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004046 auto it = dev_data->commandPoolMap[commandPool].commandBuffers.begin();
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004047 while (it != dev_data->commandPoolMap[commandPool].commandBuffers.end()) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004048 resetCB(dev_data, (*it));
4049 ++it;
4050 }
Tobin Ehlis74714d22016-01-25 15:24:34 -08004051 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004052 }
4053 return result;
4054}
4055
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004056VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer, const VkAllocationCallbacks* pAllocator)
4057{
4058 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 -06004059 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004060}
4061
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004062VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass, const VkAllocationCallbacks* pAllocator)
4063{
4064 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 -06004065 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004066}
4067
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004068VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateBuffer(VkDevice device, const VkBufferCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkBuffer* pBuffer)
4069{
4070 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4071 VkResult result = dev_data->device_dispatch_table->CreateBuffer(device, pCreateInfo, pAllocator, pBuffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06004072 if (VK_SUCCESS == result) {
4073 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004074 // TODO : This doesn't create deep copy of pQueueFamilyIndices so need to fix that if/when we want that data to be valid
4075 dev_data->bufferMap[*pBuffer].create_info = unique_ptr<VkBufferCreateInfo>(new VkBufferCreateInfo(*pCreateInfo));
Michael Lentine700b0aa2015-10-30 17:57:32 -07004076 dev_data->bufferMap[*pBuffer].in_use.store(0);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06004077 loader_platform_thread_unlock_mutex(&globalLock);
4078 }
4079 return result;
4080}
4081
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004082VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkBufferView* pView)
4083{
4084 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4085 VkResult result = dev_data->device_dispatch_table->CreateBufferView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004086 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004087 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004088 dev_data->bufferViewMap[*pView] = unique_ptr<VkBufferViewCreateInfo>(new VkBufferViewCreateInfo(*pCreateInfo));
Tobin Ehlisa1c28562015-10-23 16:00:08 -06004089 loader_platform_thread_unlock_mutex(&globalLock);
4090 }
4091 return result;
4092}
4093
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004094VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateImage(VkDevice device, const VkImageCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkImage* pImage)
4095{
4096 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4097 VkResult result = dev_data->device_dispatch_table->CreateImage(device, pCreateInfo, pAllocator, pImage);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06004098 if (VK_SUCCESS == result) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004099 IMAGE_NODE* image_node = new IMAGE_NODE;
Michael Lentineabc5e922015-10-12 11:30:14 -05004100 image_node->layout = pCreateInfo->initialLayout;
Tobin Ehlis75cd1c52016-01-21 10:21:04 -07004101 image_node->format = pCreateInfo->format;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06004102 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004103 dev_data->imageMap[*pImage] = unique_ptr<VkImageCreateInfo>(new VkImageCreateInfo(*pCreateInfo));
Michael Lentineabc5e922015-10-12 11:30:14 -05004104 dev_data->imageLayoutMap[*pImage] = image_node;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004105 loader_platform_thread_unlock_mutex(&globalLock);
4106 }
4107 return result;
4108}
4109
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004110VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkImageView* pView)
4111{
4112 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4113 VkResult result = dev_data->device_dispatch_table->CreateImageView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004114 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004115 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004116 dev_data->imageViewMap[*pView] = unique_ptr<VkImageViewCreateInfo>(new VkImageViewCreateInfo(*pCreateInfo));
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004117 loader_platform_thread_unlock_mutex(&globalLock);
4118 }
4119 return result;
4120}
4121
Michael Lentine37767342016-02-02 22:24:26 -06004122VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
4123 vkCreateFence(VkDevice device, const VkFenceCreateInfo* pCreateInfo,
4124 const VkAllocationCallbacks* pAllocator, VkFence* pFence) {
4125 layer_data *dev_data =
4126 get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4127 VkResult result = dev_data->device_dispatch_table->CreateFence(
4128 device, pCreateInfo, pAllocator, pFence);
4129 if (VK_SUCCESS == result) {
4130 loader_platform_thread_lock_mutex(&globalLock);
4131 dev_data->fenceMap[*pFence].in_use.store(0);
4132 loader_platform_thread_unlock_mutex(&globalLock);
4133 }
4134 return result;
4135}
4136
4137// TODO handle pipeline caches
4138VKAPI_ATTR VkResult VKAPI_CALL
4139 vkCreatePipelineCache(VkDevice device,
4140 const VkPipelineCacheCreateInfo *pCreateInfo,
4141 const VkAllocationCallbacks *pAllocator,
4142 VkPipelineCache *pPipelineCache) {
4143 layer_data *dev_data =
4144 get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4145 VkResult result = dev_data->device_dispatch_table->CreatePipelineCache(
4146 device, pCreateInfo, pAllocator, pPipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06004147 return result;
4148}
4149
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004150VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineCache(
4151 VkDevice device,
4152 VkPipelineCache pipelineCache,
4153 const VkAllocationCallbacks* pAllocator)
4154{
4155 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4156 dev_data->device_dispatch_table->DestroyPipelineCache(device, pipelineCache, pAllocator);
Jon Ashburnc669cc62015-07-09 15:02:25 -06004157}
4158
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004159VKAPI_ATTR VkResult VKAPI_CALL vkGetPipelineCacheData(
4160 VkDevice device,
4161 VkPipelineCache pipelineCache,
4162 size_t* pDataSize,
4163 void* pData)
4164{
4165 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4166 VkResult result = dev_data->device_dispatch_table->GetPipelineCacheData(device, pipelineCache, pDataSize, pData);
Jon Ashburnc669cc62015-07-09 15:02:25 -06004167 return result;
4168}
4169
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004170VKAPI_ATTR VkResult VKAPI_CALL vkMergePipelineCaches(
4171 VkDevice device,
4172 VkPipelineCache dstCache,
4173 uint32_t srcCacheCount,
4174 const VkPipelineCache* pSrcCaches)
4175{
4176 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4177 VkResult result = dev_data->device_dispatch_table->MergePipelineCaches(device, dstCache, srcCacheCount, pSrcCaches);
Jon Ashburnc669cc62015-07-09 15:02:25 -06004178 return result;
4179}
4180
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004181VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateGraphicsPipelines(
4182 VkDevice device,
4183 VkPipelineCache pipelineCache,
4184 uint32_t count,
4185 const VkGraphicsPipelineCreateInfo *pCreateInfos,
4186 const VkAllocationCallbacks *pAllocator,
4187 VkPipeline *pPipelines)
4188{
Courtney Goeltzenleuchtered894072015-09-04 13:39:59 -06004189 VkResult result = VK_SUCCESS;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004190 //TODO What to do with pipelineCache?
Tobin Ehlis75283bf2015-06-18 15:59:33 -06004191 // The order of operations here is a little convoluted but gets the job done
4192 // 1. Pipeline create state is first shadowed into PIPELINE_NODE struct
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004193 // 2. Create state is then validated (which uses flags setup during shadowing)
4194 // 3. If everything looks good, we'll then create the pipeline and add NODE to pipelineMap
Tobin Ehlis11efc302015-09-16 10:33:53 -06004195 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004196 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
4197 vector<PIPELINE_NODE*> pPipeNode(count);
4198 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004199
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004200 uint32_t i=0;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06004201 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004202
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004203 for (i=0; i<count; i++) {
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004204 pPipeNode[i] = initGraphicsPipeline(dev_data, &pCreateInfos[i], NULL);
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004205 skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
Tobin Ehlis11efc302015-09-16 10:33:53 -06004206 }
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004207
Tobin Ehlis75283bf2015-06-18 15:59:33 -06004208 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07004209
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07004210 if (VK_FALSE == skipCall) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004211 result = dev_data->device_dispatch_table->CreateGraphicsPipelines(device,
4212 pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
Tobin Ehlis75283bf2015-06-18 15:59:33 -06004213 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004214 for (i=0; i<count; i++) {
Tobin Ehlis11efc302015-09-16 10:33:53 -06004215 pPipeNode[i]->pipeline = pPipelines[i];
Chia-I Wue2fc5522015-10-26 20:04:44 +08004216 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
Tobin Ehlis11efc302015-09-16 10:33:53 -06004217 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06004218 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisce132d82015-06-19 15:07:05 -06004219 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004220 for (i=0; i<count; i++) {
Tobin Ehlis11efc302015-09-16 10:33:53 -06004221 if (pPipeNode[i]) {
4222 // If we allocated a pipeNode, need to clean it up here
4223 delete[] pPipeNode[i]->pVertexBindingDescriptions;
4224 delete[] pPipeNode[i]->pVertexAttributeDescriptions;
4225 delete[] pPipeNode[i]->pAttachments;
4226 delete pPipeNode[i];
4227 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06004228 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004229 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06004230 }
Courtney Goeltzenleuchtere2aaad02015-04-13 16:16:04 -06004231 return result;
4232}
4233
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004234VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateComputePipelines(
4235 VkDevice device,
4236 VkPipelineCache pipelineCache,
4237 uint32_t count,
4238 const VkComputePipelineCreateInfo *pCreateInfos,
4239 const VkAllocationCallbacks *pAllocator,
4240 VkPipeline *pPipelines)
4241{
4242 VkResult result = VK_SUCCESS;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004243 VkBool32 skipCall = VK_FALSE;
4244
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004245 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
4246 vector<PIPELINE_NODE*> pPipeNode(count);
4247 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004248
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004249 uint32_t i=0;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004250 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004251 for (i=0; i<count; i++) {
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004252 // TODO: Verify compute stage bits
4253
4254 // Create and initialize internal tracking data structure
4255 pPipeNode[i] = new PIPELINE_NODE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004256 memcpy(&pPipeNode[i]->computePipelineCI, (const void*)&pCreateInfos[i], sizeof(VkComputePipelineCreateInfo));
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004257
4258 // TODO: Add Compute Pipeline Verification
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004259 // skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004260 }
4261 loader_platform_thread_unlock_mutex(&globalLock);
4262
4263 if (VK_FALSE == skipCall) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004264 result = dev_data->device_dispatch_table->CreateComputePipelines(device, pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004265 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004266 for (i=0; i<count; i++) {
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004267 pPipeNode[i]->pipeline = pPipelines[i];
4268 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
4269 }
4270 loader_platform_thread_unlock_mutex(&globalLock);
4271 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004272 for (i=0; i<count; i++) {
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004273 if (pPipeNode[i]) {
4274 // Clean up any locally allocated data structures
4275 delete pPipeNode[i];
4276 }
4277 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004278 return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004279 }
4280 return result;
4281}
4282
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004283VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSampler* pSampler)
4284{
4285 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4286 VkResult result = dev_data->device_dispatch_table->CreateSampler(device, pCreateInfo, pAllocator, pSampler);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004287 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004288 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004289 dev_data->sampleMap[*pSampler] = unique_ptr<SAMPLER_NODE>(new SAMPLER_NODE(pSampler, pCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004290 loader_platform_thread_unlock_mutex(&globalLock);
4291 }
4292 return result;
4293}
4294
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004295VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDescriptorSetLayout* pSetLayout)
4296{
4297 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4298 VkResult result = dev_data->device_dispatch_table->CreateDescriptorSetLayout(device, pCreateInfo, pAllocator, pSetLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004299 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07004300 // TODOSC : Capture layout bindings set
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004301 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004302 if (NULL == pNewNode) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004303 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",
4304 "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004305 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004306 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004307 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
4308 pNewNode->createInfo.pBindings = new VkDescriptorSetLayoutBinding[pCreateInfo->bindingCount];
4309 memcpy((void*)pNewNode->createInfo.pBindings, pCreateInfo->pBindings, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->bindingCount);
Chia-I Wud46e6ae2015-10-31 00:31:16 +08004310 // g++ does not like reserve with size 0
4311 if (pCreateInfo->bindingCount)
Tobin Ehlis684924e2016-02-02 09:57:25 -07004312 pNewNode->bindingToIndexMap.reserve(pCreateInfo->bindingCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004313 uint32_t totalCount = 0;
Tobin Ehlis684924e2016-02-02 09:57:25 -07004314 for (uint32_t i = 0; i < pCreateInfo->bindingCount; i++) {
4315 if (!pNewNode->bindingToIndexMap.emplace(pCreateInfo->pBindings[i].binding, i).second) {
4316 if (log_msg(
4317 dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
4318 VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT,
4319 (uint64_t)*pSetLayout, __LINE__,
4320 DRAWSTATE_INVALID_LAYOUT, "DS",
4321 "duplicated binding number in "
4322 "VkDescriptorSetLayoutBinding"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004323 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis684924e2016-02-02 09:57:25 -07004324 } else {
4325 pNewNode->bindingToIndexMap[pCreateInfo->pBindings[i].binding] = i;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08004326 }
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07004327 totalCount += pCreateInfo->pBindings[i].descriptorCount;
4328 if (pCreateInfo->pBindings[i].pImmutableSamplers) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004329 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBindings[i].pImmutableSamplers;
4330 *ppIS = new VkSampler[pCreateInfo->pBindings[i].descriptorCount];
4331 memcpy(*ppIS, pCreateInfo->pBindings[i].pImmutableSamplers, pCreateInfo->pBindings[i].descriptorCount*sizeof(VkSampler));
Tobin Ehlis793ad302015-04-03 12:01:11 -06004332 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004333 }
Tobin Ehlis43c39c02016-01-11 13:18:40 -07004334 pNewNode->layout = *pSetLayout;
4335 pNewNode->startIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004336 if (totalCount > 0) {
Cody Northrop43751cc2015-10-26 14:07:35 -06004337 pNewNode->descriptorTypes.resize(totalCount);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06004338 pNewNode->stageFlags.resize(totalCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004339 uint32_t offset = 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06004340 uint32_t j = 0;
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07004341 VkDescriptorType dType;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004342 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07004343 dType = pCreateInfo->pBindings[i].descriptorType;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004344 for (j = 0; j < pCreateInfo->pBindings[i].descriptorCount; j++) {
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07004345 pNewNode->descriptorTypes[offset + j] = dType;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004346 pNewNode->stageFlags[offset + j] = pCreateInfo->pBindings[i].stageFlags;
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07004347 if ((dType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
4348 (dType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
4349 pNewNode->dynamicDescriptorCount++;
4350 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004351 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06004352 offset += j;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004353 }
Tobin Ehlis43c39c02016-01-11 13:18:40 -07004354 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
4355 } else { // no descriptors
4356 pNewNode->endIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004357 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004358 // Put new node at Head of global Layer list
4359 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07004360 dev_data->descriptorSetLayoutMap[*pSetLayout] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004361 loader_platform_thread_unlock_mutex(&globalLock);
4362 }
4363 return result;
4364}
4365
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004366VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkPipelineLayout* pPipelineLayout)
4367{
4368 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4369 VkResult result = dev_data->device_dispatch_table->CreatePipelineLayout(device, pCreateInfo, pAllocator, pPipelineLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004370 if (VK_SUCCESS == result) {
Ian Elliott8c8b2662016-01-30 10:57:03 -07004371 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07004372 // TODOSC : Merge capture of the setLayouts per pipeline
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004373 PIPELINE_LAYOUT_NODE& plNode = dev_data->pipelineLayoutMap[*pPipelineLayout];
Chia-I Wud50a7d72015-10-26 20:48:51 +08004374 plNode.descriptorSetLayouts.resize(pCreateInfo->setLayoutCount);
Tobin Ehlis644ff042015-10-20 10:11:55 -06004375 uint32_t i = 0;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004376 for (i=0; i<pCreateInfo->setLayoutCount; ++i) {
Tobin Ehlis644ff042015-10-20 10:11:55 -06004377 plNode.descriptorSetLayouts[i] = pCreateInfo->pSetLayouts[i];
4378 }
Cody Northrop43751cc2015-10-26 14:07:35 -06004379 plNode.pushConstantRanges.resize(pCreateInfo->pushConstantRangeCount);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004380 for (i=0; i<pCreateInfo->pushConstantRangeCount; ++i) {
Tobin Ehlis644ff042015-10-20 10:11:55 -06004381 plNode.pushConstantRanges[i] = pCreateInfo->pPushConstantRanges[i];
4382 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07004383 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis793ad302015-04-03 12:01:11 -06004384 }
4385 return result;
4386}
4387
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004388VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDescriptorPool* pDescriptorPool)
4389{
4390 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4391 VkResult result = dev_data->device_dispatch_table->CreateDescriptorPool(device, pCreateInfo, pAllocator, pDescriptorPool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004392 if (VK_SUCCESS == result) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06004393 // Insert this pool into Global Pool LL at head
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004394 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",
4395 "Created Descriptor Pool %#" PRIxLEAST64, (uint64_t) *pDescriptorPool))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004396 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004397 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004398 DESCRIPTOR_POOL_NODE* pNewNode = new DESCRIPTOR_POOL_NODE(*pDescriptorPool, pCreateInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004399 if (NULL == pNewNode) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004400 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",
4401 "Out of memory while attempting to allocate DESCRIPTOR_POOL_NODE in vkCreateDescriptorPool()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004402 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisce132d82015-06-19 15:07:05 -06004403 } else {
Mark Lobodzinski39298632015-11-18 08:38:27 -07004404 dev_data->descriptorPoolMap[*pDescriptorPool] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004405 }
4406 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisce132d82015-06-19 15:07:05 -06004407 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06004408 // Need to do anything if pool create fails?
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004409 }
4410 return result;
4411}
4412
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004413VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorPoolResetFlags flags)
4414{
4415 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4416 VkResult result = dev_data->device_dispatch_table->ResetDescriptorPool(device, descriptorPool, flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004417 if (VK_SUCCESS == result) {
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004418 clearDescriptorPool(dev_data, device, descriptorPool, flags);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004419 }
4420 return result;
4421}
4422
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004423VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo* pAllocateInfo, VkDescriptorSet* pDescriptorSets)
4424{
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004425 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004426 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004427 // Verify that requested descriptorSets are available in pool
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004428 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004429 if (!pPoolNode) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004430 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",
4431 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pAllocateInfo->descriptorPool);
4432 } else { // Make sure pool has all the available descriptors before calling down chain
4433 skipCall |= validate_descriptor_availability_in_pool(dev_data, pPoolNode, pAllocateInfo->descriptorSetCount, pAllocateInfo->pSetLayouts);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004434 }
4435 if (skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004436 return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004437 VkResult result = dev_data->device_dispatch_table->AllocateDescriptorSets(device, pAllocateInfo, pDescriptorSets);
Cody Northrop1e4f8022015-08-03 12:47:29 -06004438 if (VK_SUCCESS == result) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004439 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004440 if (pPoolNode) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004441 if (pAllocateInfo->descriptorSetCount == 0) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004442 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 +08004443 "AllocateDescriptorSets called with 0 count");
Cody Northrop1e4f8022015-08-03 12:47:29 -06004444 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07004445 for (uint32_t i = 0; i < pAllocateInfo->descriptorSetCount; i++) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004446 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",
4447 "Created Descriptor Set %#" PRIxLEAST64, (uint64_t) pDescriptorSets[i]);
Tobin Ehlis793ad302015-04-03 12:01:11 -06004448 // Create new set node and add to head of pool nodes
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004449 SET_NODE* pNewNode = new SET_NODE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004450 if (NULL == pNewNode) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004451 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",
4452 "Out of memory while attempting to allocate SET_NODE in vkAllocateDescriptorSets()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004453 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisce132d82015-06-19 15:07:05 -06004454 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004455 // TODO : Pool should store a total count of each type of Descriptor available
4456 // When descriptors are allocated, decrement the count and validate here
4457 // that the count doesn't go below 0. One reset/free need to bump count back up.
Tobin Ehlis793ad302015-04-03 12:01:11 -06004458 // Insert set at head of Set LL for this pool
4459 pNewNode->pNext = pPoolNode->pSets;
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07004460 pNewNode->in_use.store(0);
Tobin Ehlis793ad302015-04-03 12:01:11 -06004461 pPoolNode->pSets = pNewNode;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004462 LAYOUT_NODE* pLayout = getLayoutNode(dev_data, pAllocateInfo->pSetLayouts[i]);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004463 if (NULL == pLayout) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004464 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",
4465 "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 -07004466 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004467 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07004468 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis793ad302015-04-03 12:01:11 -06004469 pNewNode->pLayout = pLayout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004470 pNewNode->pool = pAllocateInfo->descriptorPool;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004471 pNewNode->set = pDescriptorSets[i];
Tobin Ehlise703fa92016-01-29 07:52:45 -07004472 pNewNode->descriptorCount = (pLayout->createInfo.bindingCount != 0) ? pLayout->endIndex + 1 : 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004473 if (pNewNode->descriptorCount) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004474 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
4475 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004476 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
4477 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08004478 dev_data->setMap[pDescriptorSets[i]] = pNewNode;
Ian Elliott8c8b2662016-01-30 10:57:03 -07004479 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004480 }
4481 }
4482 }
4483 }
4484 return result;
4485}
4486
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004487VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, const VkDescriptorSet* pDescriptorSets)
4488{
Tobin Ehlise735c692015-10-08 13:13:50 -06004489 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004490 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07004491 // Make sure that no sets being destroyed are in-flight
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004492 for (uint32_t i=0; i<count; ++i)
4493 skipCall |= validateIdleDescriptorSet(dev_data, pDescriptorSets[i], "vkFreeDesriptorSets");
Mark Lobodzinski39298632015-11-18 08:38:27 -07004494 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, descriptorPool);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004495 if (pPoolNode && !(VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT & pPoolNode->createInfo.flags)) {
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004496 // Can't Free from a NON_FREE pool
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004497 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",
4498 "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 -06004499 }
Mark Youngb20a6a82016-01-07 15:41:43 -07004500 if (VK_FALSE != skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004501 return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004502 VkResult result = dev_data->device_dispatch_table->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004503 if (VK_SUCCESS == result) {
4504 // For each freed descriptor add it back into the pool as available
Ian Elliott8c8b2662016-01-30 10:57:03 -07004505 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004506 for (uint32_t i=0; i<count; ++i) {
4507 SET_NODE* pSet = dev_data->setMap[pDescriptorSets[i]]; // getSetNode() without locking
Tobin Ehlise6e574b2016-01-24 23:25:31 -07004508 invalidateBoundCmdBuffers(dev_data, pSet);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004509 LAYOUT_NODE* pLayout = pSet->pLayout;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004510 uint32_t typeIndex = 0, poolSizeCount = 0;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004511 for (uint32_t j=0; j<pLayout->createInfo.bindingCount; ++j) {
4512 typeIndex = static_cast<uint32_t>(pLayout->createInfo.pBindings[j].descriptorType);
4513 poolSizeCount = pLayout->createInfo.pBindings[j].descriptorCount;
4514 pPoolNode->availableDescriptorTypeCount[typeIndex] += poolSizeCount;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004515 }
4516 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07004517 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004518 }
4519 // TODO : Any other clean-up or book-keeping to do here?
Tony Barbour34ec6922015-07-10 10:50:45 -06004520 return result;
4521}
4522
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004523VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount, const VkWriteDescriptorSet* pDescriptorWrites, uint32_t descriptorCopyCount, const VkCopyDescriptorSet* pDescriptorCopies)
4524{
4525 // dsUpdate will return VK_TRUE only if a bailout error occurs, so we want to call down tree when update returns VK_FALSE
4526 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4527 if (!dsUpdate(dev_data, device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies)) {
4528 dev_data->device_dispatch_table->UpdateDescriptorSets(device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies);
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004529 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004530}
4531
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004532VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo* pCreateInfo, VkCommandBuffer* pCommandBuffer)
4533{
4534 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4535 VkResult result = dev_data->device_dispatch_table->AllocateCommandBuffers(device, pCreateInfo, pCommandBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004536 if (VK_SUCCESS == result) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004537 for (uint32_t i = 0; i < pCreateInfo->commandBufferCount; i++) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07004538 // Validate command pool
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004539 if (dev_data->commandPoolMap.find(pCreateInfo->commandPool) != dev_data->commandPoolMap.end()) {
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07004540 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07004541 // Add command buffer to its commandPool map
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004542 dev_data->commandPoolMap[pCreateInfo->commandPool].commandBuffers.push_back(pCommandBuffer[i]);
4543 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
Mark Lobodzinski39298632015-11-18 08:38:27 -07004544 // Add command buffer to map
4545 dev_data->commandBufferMap[pCommandBuffer[i]] = pCB;
4546 resetCB(dev_data, pCommandBuffer[i]);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004547 pCB->createInfo = *pCreateInfo;
4548 pCB->device = device;
Tobin Ehlis74714d22016-01-25 15:24:34 -08004549 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07004550 }
4551 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004552 }
4553 return result;
4554}
4555
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004556VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo* pBeginInfo)
4557{
Mark Youngb20a6a82016-01-07 15:41:43 -07004558 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004559 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004560 // Validate command buffer level
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004561 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004562 if (pCB) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004563 if (pCB->createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
4564 // Secondary Command Buffer
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004565 const VkCommandBufferInheritanceInfo *pInfo = pBeginInfo->pInheritanceInfo;
Michael Lentine7d26c572016-01-28 11:55:28 -06004566 if (!pInfo) {
4567 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>(commandBuffer), __LINE__,
4568 DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS", "vkBeginCommandBuffer(): Secondary Command Buffer (%p) must have inheritance info.",
4569 reinterpret_cast<void*>(commandBuffer));
4570 } else {
4571 if (pBeginInfo->flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT) {
4572 if (!pInfo->renderPass) { // renderpass should NOT be null for an Secondary CB
4573 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>(commandBuffer),
4574 __LINE__, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
4575 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) must specify a valid renderpass parameter.", reinterpret_cast<void*>(commandBuffer));
Tobin Ehlis651d9b02015-12-16 05:01:22 -07004576 }
Michael Lentine7d26c572016-01-28 11:55:28 -06004577 if (!pInfo->framebuffer) { // framebuffer may be null for an Secondary CB, but this affects perf
4578 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, reinterpret_cast<uint64_t>(commandBuffer),
4579 __LINE__, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
4580 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) may perform better if a valid framebuffer parameter is specified.",
4581 reinterpret_cast<void*>(commandBuffer));
4582 } else {
4583 string errorString = "";
4584 VkRenderPass fbRP = dev_data->frameBufferMap[pInfo->framebuffer]->renderPass;
4585 if (!verify_renderpass_compatibility(dev_data, fbRP, pInfo->renderPass, errorString)) {
4586 // renderPass that framebuffer was created with must be compatible with local renderPass
4587 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>(commandBuffer),
4588 __LINE__, DRAWSTATE_RENDERPASS_INCOMPATIBLE, "DS",
4589 "vkBeginCommandBuffer(): Secondary Command Buffer (%p) renderPass (%#" PRIxLEAST64 ") is incompatible w/ framebuffer (%#" PRIxLEAST64
Dustin Graves4383a2d2016-02-04 10:57:00 -07004590 ") w/ render pass (%#" PRIxLEAST64 ") due to: %s", reinterpret_cast<void*>(commandBuffer), (uint64_t)(pInfo->renderPass),
4591 (uint64_t)(pInfo->framebuffer), (uint64_t)(fbRP), errorString.c_str());
Michael Lentine7d26c572016-01-28 11:55:28 -06004592 }
4593 }
4594 }
4595 if ((pInfo->occlusionQueryEnable == VK_FALSE || dev_data->physDevProperties.features.occlusionQueryPrecise == VK_FALSE) && (pInfo->queryFlags & VK_QUERY_CONTROL_PRECISE_BIT)) {
4596 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>(commandBuffer),
4597 __LINE__, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
4598 "vkBeginCommandBuffer(): Secondary Command Buffer (%p) must not have VK_QUERY_CONTROL_PRECISE_BIT if occulusionQuery is disabled or the device does not "
4599 "support precise occlusion queries.", reinterpret_cast<void*>(commandBuffer));
Tobin Ehlis651d9b02015-12-16 05:01:22 -07004600 }
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004601 }
Michael Lentine539b0222016-02-02 17:28:24 -06004602 if (pInfo->renderPass != VK_NULL_HANDLE) {
4603 auto rp_data = dev_data->renderPassMap.find(pInfo->renderPass);
4604 if (rp_data != dev_data->renderPassMap.end() && rp_data->second && rp_data->second->pCreateInfo) {
4605 if (pInfo->subpass >= rp_data->second->pCreateInfo->subpassCount) {
4606 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer,
4607 __LINE__, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
4608 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) must has a subpass index (%d) that is less than the number of subpasses (%d).",
4609 (void*)commandBuffer, pInfo->subpass, rp_data->second->pCreateInfo->subpassCount);
4610 }
4611 }
4612 }
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004613 }
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004614 if (CB_RECORDING == pCB->state) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004615 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",
4616 "vkBeginCommandBuffer(): Cannot call Begin on CB (%#" PRIxLEAST64 ") in the RECORDING state. Must first call vkEndCommandBuffer().", (uint64_t)commandBuffer);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004617 } else if (CB_RECORDED == pCB->state) {
4618 VkCommandPool cmdPool = pCB->createInfo.commandPool;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004619 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
4620 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer,
4621 __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
4622 "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.",
4623 (uint64_t) commandBuffer, (uint64_t) cmdPool);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004624 }
Tobin Ehlis74714d22016-01-25 15:24:34 -08004625 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisef694652016-01-19 12:03:34 -07004626 resetCB(dev_data, commandBuffer);
Tobin Ehlis74714d22016-01-25 15:24:34 -08004627 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004628 }
Tobin Ehlisef694652016-01-19 12:03:34 -07004629 // Set updated state here in case implicit reset occurs above
Tobin Ehlis74714d22016-01-25 15:24:34 -08004630 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisef694652016-01-19 12:03:34 -07004631 pCB->state = CB_RECORDING;
4632 pCB->beginInfo = *pBeginInfo;
Tobin Ehliscd5bfd82016-01-19 13:12:52 -07004633 if (pCB->beginInfo.pInheritanceInfo) {
4634 pCB->inheritanceInfo = *(pCB->beginInfo.pInheritanceInfo);
4635 pCB->beginInfo.pInheritanceInfo = &pCB->inheritanceInfo;
4636 }
Tobin Ehlis74714d22016-01-25 15:24:34 -08004637 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004638 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004639 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",
4640 "In vkBeginCommandBuffer() and unable to find CommandBuffer Node for CB %p!", (void*)commandBuffer);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004641 }
Mark Youngb20a6a82016-01-07 15:41:43 -07004642 if (VK_FALSE != skipCall) {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004643 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter5fe086f2015-09-04 15:03:52 -06004644 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004645 VkResult result = dev_data->device_dispatch_table->BeginCommandBuffer(commandBuffer, pBeginInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004646 return result;
4647}
4648
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004649VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEndCommandBuffer(VkCommandBuffer commandBuffer)
4650{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004651 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchtered894072015-09-04 13:39:59 -06004652 VkResult result = VK_SUCCESS;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004653 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4654 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004655 if (pCB) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004656 if (pCB->state != CB_RECORDING) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004657 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkEndCommandBuffer()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004658 }
Michael Lentinedc6f8de2016-02-02 18:29:30 -06004659 for (auto query : pCB->activeQueries) {
4660 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_QUERY, "DS",
4661 "Ending command buffer with in progress query: queryPool %" PRIu64 ", index %d", (uint64_t)(query.pool), query.index);
4662 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004663 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004664 if (VK_FALSE == skipCall) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004665 result = dev_data->device_dispatch_table->EndCommandBuffer(commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004666 if (VK_SUCCESS == result) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004667 pCB->state = CB_RECORDED;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004668 // Reset CB status flags
4669 pCB->status = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004670 printCB(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004671 }
4672 } else {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004673 result = VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004674 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004675 return result;
4676}
4677
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004678VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags)
4679{
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004680 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004681 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4682 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004683 VkCommandPool cmdPool = pCB->createInfo.commandPool;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004684 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
4685 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t) commandBuffer,
4686 __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
4687 "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.",
4688 (uint64_t) commandBuffer, (uint64_t) cmdPool);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004689 }
Michael Lentine5f6dc4f2016-01-27 20:42:07 -06004690 if (dev_data->globalInFlightCmdBuffers.count(commandBuffer)) {
4691 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t) commandBuffer,
4692 __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
4693 "Attempt to reset command buffer (%#" PRIxLEAST64 ") which is in use.", reinterpret_cast<uint64_t>(commandBuffer));
4694 }
Mark Youngb20a6a82016-01-07 15:41:43 -07004695 if (skipCall != VK_FALSE)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004696 return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004697 VkResult result = dev_data->device_dispatch_table->ResetCommandBuffer(commandBuffer, flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004698 if (VK_SUCCESS == result) {
Tobin Ehlis74714d22016-01-25 15:24:34 -08004699 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004700 resetCB(dev_data, commandBuffer);
Tobin Ehlis74714d22016-01-25 15:24:34 -08004701 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004702 }
4703 return result;
4704}
4705
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004706VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
4707{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004708 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004709 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4710 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004711 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004712 skipCall |= addCmd(dev_data, pCB, CMD_BINDPIPELINE, "vkCmdBindPipeline()");
4713 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
4714 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, (uint64_t) pipeline,
4715 __LINE__, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
4716 "Incorrectly binding compute pipeline (%#" PRIxLEAST64 ") during active RenderPass (%#" PRIxLEAST64 ")",
4717 (uint64_t) pipeline, (uint64_t) pCB->activeRenderPass);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004718 } else if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004719 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdBindPipeline");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004720 }
4721
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004722 PIPELINE_NODE* pPN = getPipeline(dev_data, pipeline);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004723 if (pPN) {
4724 pCB->lastBoundPipeline = pipeline;
4725 loader_platform_thread_lock_mutex(&globalLock);
4726 set_cb_pso_status(pCB, pPN);
4727 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004728 skipCall |= validatePipelineState(dev_data, pCB, pipelineBindPoint, pipeline);
Tobin Ehlisce132d82015-06-19 15:07:05 -06004729 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004730 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
4731 (uint64_t) pipeline, __LINE__, DRAWSTATE_INVALID_PIPELINE, "DS",
4732 "Attempt to bind Pipeline %#" PRIxLEAST64 " that doesn't exist!", (uint64_t)(pipeline));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004733 }
4734 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004735 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004736 dev_data->device_dispatch_table->CmdBindPipeline(commandBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004737}
4738
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004739VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetViewport(
4740 VkCommandBuffer commandBuffer,
4741 uint32_t firstViewport,
4742 uint32_t viewportCount,
4743 const VkViewport* pViewports)
4744{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004745 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004746 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4747 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004748 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004749 loader_platform_thread_lock_mutex(&globalLock);
Ian Elliott8c8b2662016-01-30 10:57:03 -07004750 skipCall |= addCmd(dev_data, pCB, CMD_SETVIEWPORTSTATE, "vkCmdSetViewport()");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004751 pCB->status |= CBSTATUS_VIEWPORT_SET;
4752 pCB->viewports.resize(viewportCount);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004753 memcpy(pCB->viewports.data(), pViewports, viewportCount * sizeof(VkViewport));
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004754 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004755 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004756 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004757 dev_data->device_dispatch_table->CmdSetViewport(commandBuffer, firstViewport, viewportCount, pViewports);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004758}
4759
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004760VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetScissor(
4761 VkCommandBuffer commandBuffer,
4762 uint32_t firstScissor,
4763 uint32_t scissorCount,
4764 const VkRect2D* pScissors)
4765{
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004766 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004767 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4768 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004769 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004770 loader_platform_thread_lock_mutex(&globalLock);
Ian Elliott8c8b2662016-01-30 10:57:03 -07004771 skipCall |= addCmd(dev_data, pCB, CMD_SETSCISSORSTATE, "vkCmdSetScissor()");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004772 pCB->status |= CBSTATUS_SCISSOR_SET;
4773 pCB->scissors.resize(scissorCount);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004774 memcpy(pCB->scissors.data(), pScissors, scissorCount * sizeof(VkRect2D));
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004775 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004776 }
4777 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004778 dev_data->device_dispatch_table->CmdSetScissor(commandBuffer, firstScissor, scissorCount, pScissors);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004779}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004780
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004781VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth)
4782{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004783 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004784 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4785 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004786 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004787 loader_platform_thread_lock_mutex(&globalLock);
Ian Elliott8c8b2662016-01-30 10:57:03 -07004788 skipCall |= addCmd(dev_data, pCB, CMD_SETLINEWIDTHSTATE, "vkCmdSetLineWidth()");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004789 pCB->status |= CBSTATUS_LINE_WIDTH_SET;
4790 pCB->lineWidth = lineWidth;
4791 loader_platform_thread_unlock_mutex(&globalLock);
Cody Northrop12365112015-08-17 11:10:49 -06004792 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004793 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004794 dev_data->device_dispatch_table->CmdSetLineWidth(commandBuffer, lineWidth);
Cody Northrop12365112015-08-17 11:10:49 -06004795}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004796
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004797VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBias(
4798 VkCommandBuffer commandBuffer,
4799 float depthBiasConstantFactor,
4800 float depthBiasClamp,
4801 float depthBiasSlopeFactor)
4802{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004803 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004804 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4805 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northrop12365112015-08-17 11:10:49 -06004806 if (pCB) {
Ian Elliott8c8b2662016-01-30 10:57:03 -07004807 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004808 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBIASSTATE, "vkCmdSetDepthBias()");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004809 pCB->status |= CBSTATUS_DEPTH_BIAS_SET;
4810 pCB->depthBiasConstantFactor = depthBiasConstantFactor;
4811 pCB->depthBiasClamp = depthBiasClamp;
4812 pCB->depthBiasSlopeFactor = depthBiasSlopeFactor;
Ian Elliott8c8b2662016-01-30 10:57:03 -07004813 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004814 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004815 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004816 dev_data->device_dispatch_table->CmdSetDepthBias(commandBuffer, depthBiasConstantFactor, depthBiasClamp, depthBiasSlopeFactor);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004817}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004818
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004819VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4])
4820{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004821 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004822 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4823 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004824 if (pCB) {
Ian Elliott8c8b2662016-01-30 10:57:03 -07004825 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004826 skipCall |= addCmd(dev_data, pCB, CMD_SETBLENDSTATE, "vkCmdSetBlendConstants()");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004827 pCB->status |= CBSTATUS_BLEND_SET;
4828 memcpy(pCB->blendConstants, blendConstants, 4 * sizeof(float));
Ian Elliott8c8b2662016-01-30 10:57:03 -07004829 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004830 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004831 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004832 dev_data->device_dispatch_table->CmdSetBlendConstants(commandBuffer, blendConstants);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004833}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004834
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004835VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBounds(
4836 VkCommandBuffer commandBuffer,
4837 float minDepthBounds,
4838 float maxDepthBounds)
4839{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004840 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004841 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4842 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004843 if (pCB) {
Ian Elliott8c8b2662016-01-30 10:57:03 -07004844 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004845 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBOUNDSSTATE, "vkCmdSetDepthBounds()");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004846 pCB->status |= CBSTATUS_DEPTH_BOUNDS_SET;
4847 pCB->minDepthBounds = minDepthBounds;
4848 pCB->maxDepthBounds = maxDepthBounds;
Ian Elliott8c8b2662016-01-30 10:57:03 -07004849 loader_platform_thread_unlock_mutex(&globalLock);
Cody Northrop82485a82015-08-18 15:21:16 -06004850 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004851 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004852 dev_data->device_dispatch_table->CmdSetDepthBounds(commandBuffer, minDepthBounds, maxDepthBounds);
Cody Northrop82485a82015-08-18 15:21:16 -06004853}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004854
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004855VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilCompareMask(
4856 VkCommandBuffer commandBuffer,
4857 VkStencilFaceFlags faceMask,
4858 uint32_t compareMask)
4859{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004860 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004861 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4862 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northrop82485a82015-08-18 15:21:16 -06004863 if (pCB) {
Ian Elliott8c8b2662016-01-30 10:57:03 -07004864 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004865 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREADMASKSTATE, "vkCmdSetStencilCompareMask()");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004866 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4867 pCB->front.compareMask = compareMask;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004868 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004869 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4870 pCB->back.compareMask = compareMask;
4871 }
4872 /* TODO: Do we need to track front and back separately? */
4873 /* TODO: We aren't capturing the faceMask, do we need to? */
4874 pCB->status |= CBSTATUS_STENCIL_READ_MASK_SET;
Ian Elliott8c8b2662016-01-30 10:57:03 -07004875 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004876 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004877 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004878 dev_data->device_dispatch_table->CmdSetStencilCompareMask(commandBuffer, faceMask, compareMask);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004879}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004880
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004881VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilWriteMask(
4882 VkCommandBuffer commandBuffer,
4883 VkStencilFaceFlags faceMask,
4884 uint32_t writeMask)
4885{
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004886 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004887 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4888 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004889 if (pCB) {
Ian Elliott8c8b2662016-01-30 10:57:03 -07004890 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004891 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILWRITEMASKSTATE, "vkCmdSetStencilWriteMask()");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004892 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4893 pCB->front.writeMask = writeMask;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004894 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004895 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4896 pCB->back.writeMask = writeMask;
4897 }
4898 pCB->status |= CBSTATUS_STENCIL_WRITE_MASK_SET;
Ian Elliott8c8b2662016-01-30 10:57:03 -07004899 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004900 }
4901 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004902 dev_data->device_dispatch_table->CmdSetStencilWriteMask(commandBuffer, faceMask, writeMask);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004903}
4904
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004905VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilReference(
4906 VkCommandBuffer commandBuffer,
4907 VkStencilFaceFlags faceMask,
4908 uint32_t reference)
4909{
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004910 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004911 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4912 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004913 if (pCB) {
Ian Elliott8c8b2662016-01-30 10:57:03 -07004914 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004915 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREFERENCESTATE, "vkCmdSetStencilReference()");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004916 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4917 pCB->front.reference = reference;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004918 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004919 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4920 pCB->back.reference = reference;
4921 }
4922 pCB->status |= CBSTATUS_STENCIL_REFERENCE_SET;
Ian Elliott8c8b2662016-01-30 10:57:03 -07004923 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004924 }
4925 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004926 dev_data->device_dispatch_table->CmdSetStencilReference(commandBuffer, faceMask, reference);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004927}
4928
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004929VK_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)
4930{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004931 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004932 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07004933 loader_platform_thread_lock_mutex(&globalLock);
4934 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004935 if (pCB) {
Tobin Ehlisf6585052015-12-17 11:48:42 -07004936 if (pCB->state == CB_RECORDING) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004937 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
4938 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
4939 "Incorrectly binding compute DescriptorSets during active RenderPass (%#" PRIxLEAST64 ")", (uint64_t) pCB->activeRenderPass);
Tobin Ehlisf6585052015-12-17 11:48:42 -07004940 } else if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004941 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdBindDescriptorSets");
Mark Lobodzinski74635932015-12-18 15:35:38 -07004942 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07004943 if (VK_FALSE == skipCall) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004944 // Track total count of dynamic descriptor types to make sure we have an offset for each one
Tobin Ehlisf6585052015-12-17 11:48:42 -07004945 uint32_t totalDynamicDescriptors = 0;
4946 string errorString = "";
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004947 uint32_t lastSetIndex = firstSet+setCount-1;
Tobin Ehlisf6585052015-12-17 11:48:42 -07004948 if (lastSetIndex >= pCB->boundDescriptorSets.size())
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004949 pCB->boundDescriptorSets.resize(lastSetIndex+1);
4950 VkDescriptorSet oldFinalBoundSet = pCB->boundDescriptorSets[lastSetIndex];
4951 for (uint32_t i=0; i<setCount; i++) {
Ian Elliott8c8b2662016-01-30 10:57:03 -07004952 SET_NODE* pSet = getSetNode(dev_data, pDescriptorSets[i], false);
Tobin Ehlisf6585052015-12-17 11:48:42 -07004953 if (pSet) {
Tobin Ehlise6e574b2016-01-24 23:25:31 -07004954 pCB->uniqueBoundSets.insert(pDescriptorSets[i]);
4955 pSet->boundCmdBuffers.insert(commandBuffer);
Tobin Ehlisf6585052015-12-17 11:48:42 -07004956 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
4957 pCB->lastBoundPipelineLayout = layout;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004958 pCB->boundDescriptorSets[i+firstSet] = pDescriptorSets[i];
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004959 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",
4960 "DS %#" PRIxLEAST64 " bound on pipeline %s", (uint64_t) pDescriptorSets[i], string_VkPipelineBindPoint(pipelineBindPoint));
4961 if (!pSet->pUpdateStructs && (pSet->descriptorCount != 0)) {
4962 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",
4963 "DS %#" PRIxLEAST64 " bound but it was never updated. You may want to either update it or not bind it.", (uint64_t) pDescriptorSets[i]);
Tobin Ehlisf6585052015-12-17 11:48:42 -07004964 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004965 // Verify that set being bound is compatible with overlapping setLayout of pipelineLayout
4966 if (!verify_set_layout_compatibility(dev_data, pSet, layout, i+firstSet, errorString)) {
4967 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",
4968 "descriptorSet #%u being bound is not compatible with overlapping layout in pipelineLayout due to: %s", i, errorString.c_str());
Tobin Ehlisf6585052015-12-17 11:48:42 -07004969 }
4970 if (pSet->pLayout->dynamicDescriptorCount) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004971 // First make sure we won't overstep bounds of pDynamicOffsets array
4972 if ((totalDynamicDescriptors + pSet->pLayout->dynamicDescriptorCount) > dynamicOffsetCount) {
4973 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",
4974 "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.",
4975 i, (uint64_t) pDescriptorSets[i], pSet->pLayout->dynamicDescriptorCount, (dynamicOffsetCount - totalDynamicDescriptors));
4976 } else { // Validate and store dynamic offsets with the set
Mark Lobodzinski941aea92016-01-13 10:23:15 -07004977 // Validate Dynamic Offset Minimums
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004978 uint32_t cur_dyn_offset = totalDynamicDescriptors;
4979 for (uint32_t d = 0; d < pSet->descriptorCount; d++) {
4980 if (pSet->pLayout->descriptorTypes[i] == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) {
Michael Lentine26870f32016-01-26 21:36:08 -06004981 if (vk_safe_modulo(pDynamicOffsets[cur_dyn_offset], dev_data->physDevProperties.properties.limits.minUniformBufferOffsetAlignment) != 0) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004982 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0,
4983 __LINE__, DRAWSTATE_INVALID_UNIFORM_BUFFER_OFFSET, "DS",
4984 "vkCmdBindDescriptorSets(): pDynamicOffsets[%d] is %d but must be a multiple of device limit minUniformBufferOffsetAlignment %#" PRIxLEAST64,
Michael Lentine26870f32016-01-26 21:36:08 -06004985 cur_dyn_offset, pDynamicOffsets[cur_dyn_offset], dev_data->physDevProperties.properties.limits.minUniformBufferOffsetAlignment);
Mark Lobodzinski941aea92016-01-13 10:23:15 -07004986 }
4987 cur_dyn_offset++;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004988 } else if (pSet->pLayout->descriptorTypes[i] == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC) {
Michael Lentine26870f32016-01-26 21:36:08 -06004989 if (vk_safe_modulo(pDynamicOffsets[cur_dyn_offset], dev_data->physDevProperties.properties.limits.minStorageBufferOffsetAlignment) != 0) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004990 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0,
4991 __LINE__, DRAWSTATE_INVALID_STORAGE_BUFFER_OFFSET, "DS",
4992 "vkCmdBindDescriptorSets(): pDynamicOffsets[%d] is %d but must be a multiple of device limit minStorageBufferOffsetAlignment %#" PRIxLEAST64,
Michael Lentine26870f32016-01-26 21:36:08 -06004993 cur_dyn_offset, pDynamicOffsets[cur_dyn_offset], dev_data->physDevProperties.properties.limits.minStorageBufferOffsetAlignment);
Mark Lobodzinski941aea92016-01-13 10:23:15 -07004994 }
4995 cur_dyn_offset++;
4996 }
4997 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004998 // Keep running total of dynamic descriptor count to verify at the end
4999 totalDynamicDescriptors += pSet->pLayout->dynamicDescriptorCount;
Tobin Ehlisf6585052015-12-17 11:48:42 -07005000 }
5001 }
5002 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005003 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",
5004 "Attempt to bind DS %#" PRIxLEAST64 " that doesn't exist!", (uint64_t) pDescriptorSets[i]);
Tobin Ehlisf6585052015-12-17 11:48:42 -07005005 }
5006 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005007 skipCall |= addCmd(dev_data, pCB, CMD_BINDDESCRIPTORSETS, "vkCmdBindDescrsiptorSets()");
5008 // For any previously bound sets, need to set them to "invalid" if they were disturbed by this update
Tobin Ehlisf6585052015-12-17 11:48:42 -07005009 if (firstSet > 0) { // Check set #s below the first bound set
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005010 for (uint32_t i=0; i<firstSet; ++i) {
5011 if (pCB->boundDescriptorSets[i] && !verify_set_layout_compatibility(dev_data, dev_data->setMap[pCB->boundDescriptorSets[i]], layout, i, errorString)) {
5012 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",
5013 "DescriptorSetDS %#" PRIxLEAST64 " previously bound as set #%u was disturbed by newly bound pipelineLayout (%#" PRIxLEAST64 ")", (uint64_t) pCB->boundDescriptorSets[i], i, (uint64_t) layout);
Tobin Ehlisf6585052015-12-17 11:48:42 -07005014 pCB->boundDescriptorSets[i] = VK_NULL_HANDLE;
5015 }
5016 }
5017 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005018 // Check if newly last bound set invalidates any remaining bound sets
5019 if ((pCB->boundDescriptorSets.size()-1) > (lastSetIndex)) {
5020 if (oldFinalBoundSet && !verify_set_layout_compatibility(dev_data, dev_data->setMap[oldFinalBoundSet], layout, lastSetIndex, errorString)) {
5021 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",
5022 "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);
5023 pCB->boundDescriptorSets.resize(lastSetIndex+1);
Tobin Ehlisf6585052015-12-17 11:48:42 -07005024 }
5025 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005026 // dynamicOffsetCount must equal the total number of dynamic descriptors in the sets being bound
Tobin Ehlisf6585052015-12-17 11:48:42 -07005027 if (totalDynamicDescriptors != dynamicOffsetCount) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005028 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",
5029 "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 -07005030 }
Tobin Ehlisd2393772016-01-29 11:50:47 -07005031 if (dynamicOffsetCount) {
5032 // Save dynamicOffsets bound to this CB
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005033 pCB->dynamicOffsets.assign(pDynamicOffsets, pDynamicOffsets + dynamicOffsetCount);
Tobin Ehlisd2393772016-01-29 11:50:47 -07005034 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005035 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07005036 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005037 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindDescriptorSets()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005038 }
5039 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005040 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005041 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005042 dev_data->device_dispatch_table->CmdBindDescriptorSets(commandBuffer, pipelineBindPoint, layout, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005043}
5044
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005045VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
5046{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005047 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005048 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005049 loader_platform_thread_lock_mutex(&globalLock);
5050 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005051 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005052 skipCall |= addCmd(dev_data, pCB, CMD_BINDINDEXBUFFER, "vkCmdBindIndexBuffer()");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005053 VkDeviceSize offset_align = 0;
5054 switch (indexType) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005055 case VK_INDEX_TYPE_UINT16:
5056 offset_align = 2;
5057 break;
5058 case VK_INDEX_TYPE_UINT32:
5059 offset_align = 4;
5060 break;
5061 default:
5062 // ParamChecker should catch bad enum, we'll also throw alignment error below if offset_align stays 0
5063 break;
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005064 }
5065 if (!offset_align || (offset % offset_align)) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005066 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VTX_INDEX_ALIGNMENT_ERROR, "DS",
5067 "vkCmdBindIndexBuffer() offset (%#" PRIxLEAST64 ") does not fall on alignment (%s) boundary.", offset, string_VkIndexType(indexType));
Tobin Ehlis9c536442015-06-19 13:00:59 -06005068 }
Tobin Ehlisc4c23182015-09-17 12:24:13 -06005069 pCB->status |= CBSTATUS_INDEX_BUFFER_BOUND;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005070 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005071 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005072 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005073 dev_data->device_dispatch_table->CmdBindIndexBuffer(commandBuffer, buffer, offset, indexType);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005074}
5075
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005076void updateResourceTracking(GLOBAL_CB_NODE* pCB, uint32_t firstBinding, uint32_t bindingCount, const VkBuffer* pBuffers) {
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07005077 uint32_t end = firstBinding + bindingCount;
Michael Lentine700b0aa2015-10-30 17:57:32 -07005078 if (pCB->currentDrawData.buffers.size() < end) {
5079 pCB->currentDrawData.buffers.resize(end);
5080 }
5081 for (uint32_t i = 0; i < bindingCount; ++i) {
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07005082 pCB->currentDrawData.buffers[i + firstBinding] = pBuffers[i];
Michael Lentine700b0aa2015-10-30 17:57:32 -07005083 }
5084}
5085
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005086void updateResourceTrackingOnDraw(GLOBAL_CB_NODE* pCB) {
Michael Lentine700b0aa2015-10-30 17:57:32 -07005087 pCB->drawData.push_back(pCB->currentDrawData);
5088}
5089
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005090VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindVertexBuffers(
5091 VkCommandBuffer commandBuffer,
5092 uint32_t firstBinding,
5093 uint32_t bindingCount,
5094 const VkBuffer *pBuffers,
5095 const VkDeviceSize *pOffsets)
5096{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005097 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005098 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005099 loader_platform_thread_lock_mutex(&globalLock);
5100 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005101 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005102 addCmd(dev_data, pCB, CMD_BINDVERTEXBUFFER, "vkCmdBindVertexBuffer()");
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07005103 updateResourceTracking(pCB, firstBinding, bindingCount, pBuffers);
Michael Lentine700b0aa2015-10-30 17:57:32 -07005104 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005105 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindVertexBuffer()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005106 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005107 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005108 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005109 dev_data->device_dispatch_table->CmdBindVertexBuffers(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005110}
5111
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005112VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance)
5113{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005114 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005115 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005116 loader_platform_thread_lock_mutex(&globalLock);
5117 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005118 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005119 skipCall |= addCmd(dev_data, pCB, CMD_DRAW, "vkCmdDraw()");
5120 pCB->drawCount[DRAW]++;
Ian Elliott8c8b2662016-01-30 10:57:03 -07005121 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005122 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005123 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005124 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005125 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",
5126 "vkCmdDraw() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW]++);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005127 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07005128 if (VK_FALSE == skipCall) {
5129 updateResourceTrackingOnDraw(pCB);
5130 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005131 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDraw");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06005132 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005133 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005134 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005135 dev_data->device_dispatch_table->CmdDraw(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005136}
5137
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005138VK_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)
5139{
5140 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005141 loader_platform_thread_lock_mutex(&globalLock);
5142 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005143 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005144 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005145 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXED, "vkCmdDrawIndexed()");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005146 pCB->drawCount[DRAW_INDEXED]++;
Ian Elliott8c8b2662016-01-30 10:57:03 -07005147 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005148 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005149 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005150 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005151 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",
5152 "vkCmdDrawIndexed() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED]++);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005153 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07005154 if (VK_FALSE == skipCall) {
5155 updateResourceTrackingOnDraw(pCB);
5156 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005157 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexed");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06005158 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005159 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005160 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005161 dev_data->device_dispatch_table->CmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005162}
5163
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005164VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
5165{
5166 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005167 loader_platform_thread_lock_mutex(&globalLock);
5168 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005169 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005170 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005171 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDIRECT, "vkCmdDrawIndirect()");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005172 pCB->drawCount[DRAW_INDIRECT]++;
Ian Elliott8c8b2662016-01-30 10:57:03 -07005173 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005174 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005175 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005176 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005177 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",
5178 "vkCmdDrawIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005179 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07005180 if (VK_FALSE == skipCall) {
5181 updateResourceTrackingOnDraw(pCB);
5182 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005183 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndirect");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06005184 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005185 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005186 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005187 dev_data->device_dispatch_table->CmdDrawIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005188}
5189
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005190VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
5191{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005192 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005193 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005194 loader_platform_thread_lock_mutex(&globalLock);
5195 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005196 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005197 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXEDINDIRECT, "vkCmdDrawIndexedIndirect()");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005198 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
Ian Elliott8c8b2662016-01-30 10:57:03 -07005199 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005200 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005201 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005202 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005203 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",
5204 "vkCmdDrawIndexedIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005205 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07005206 if (VK_FALSE == skipCall) {
5207 updateResourceTrackingOnDraw(pCB);
5208 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005209 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexedIndirect");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06005210 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005211 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005212 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005213 dev_data->device_dispatch_table->CmdDrawIndexedIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005214}
5215
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005216VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z)
5217{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005218 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005219 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005220 loader_platform_thread_lock_mutex(&globalLock);
5221 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005222 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005223 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCH, "vkCmdDispatch()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005224 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatch");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005225 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005226 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005227 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005228 dev_data->device_dispatch_table->CmdDispatch(commandBuffer, x, y, z);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005229}
5230
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005231VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset)
5232{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005233 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005234 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005235 loader_platform_thread_lock_mutex(&globalLock);
5236 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005237 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005238 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCHINDIRECT, "vkCmdDispatchIndirect()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005239 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatchIndirect");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005240 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005241 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005242 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005243 dev_data->device_dispatch_table->CmdDispatchIndirect(commandBuffer, buffer, offset);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005244}
5245
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005246VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
5247{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005248 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005249 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005250 loader_platform_thread_lock_mutex(&globalLock);
5251 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005252 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005253 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFER, "vkCmdCopyBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005254 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005255 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005256 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005257 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005258 dev_data->device_dispatch_table->CmdCopyBuffer(commandBuffer, srcBuffer, dstBuffer, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005259}
5260
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005261VkBool32 VerifySourceImageLayout(VkCommandBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005262 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005263
5264#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
5265 // TODO: Fix -- initialLayout may have been set in a previous command buffer
5266 return skip_call;
5267#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5268
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005269 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5270 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Michael Lentineabc5e922015-10-12 11:30:14 -05005271 auto src_image_element = pCB->imageLayoutMap.find(srcImage);
5272 if (src_image_element == pCB->imageLayoutMap.end()) {
5273 pCB->imageLayoutMap[srcImage].initialLayout = srcImageLayout;
5274 pCB->imageLayoutMap[srcImage].layout = srcImageLayout;
Mark Youngb20a6a82016-01-07 15:41:43 -07005275 return VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05005276 }
5277 if (src_image_element->second.layout != srcImageLayout) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005278 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",
5279 "Cannot copy from an image whose source layout is %d and doesn't match the current layout %d.", srcImageLayout, src_image_element->second.layout);
Michael Lentineabc5e922015-10-12 11:30:14 -05005280 }
5281 if (srcImageLayout != VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL) {
5282 if (srcImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005283 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
5284 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
5285 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Michael Lentineabc5e922015-10-12 11:30:14 -05005286 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005287 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
5288 "Layout for input image is %d but can only be TRANSFER_SRC_OPTIMAL or GENERAL.", srcImageLayout);
Michael Lentineabc5e922015-10-12 11:30:14 -05005289 }
5290 }
5291 return skip_call;
5292}
5293
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005294VkBool32 VerifyDestImageLayout(VkCommandBuffer cmdBuffer, VkImage destImage, VkImageLayout destImageLayout) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005295 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005296
5297#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
5298 // TODO: Fix -- initialLayout may have been set in a previous command buffer
5299 return skip_call;
5300#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5301
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005302 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5303 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Michael Lentineabc5e922015-10-12 11:30:14 -05005304 auto dest_image_element = pCB->imageLayoutMap.find(destImage);
5305 if (dest_image_element == pCB->imageLayoutMap.end()) {
5306 pCB->imageLayoutMap[destImage].initialLayout = destImageLayout;
5307 pCB->imageLayoutMap[destImage].layout = destImageLayout;
Mark Youngb20a6a82016-01-07 15:41:43 -07005308 return VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05005309 }
5310 if (dest_image_element->second.layout != destImageLayout) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005311 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",
5312 "Cannot copy from an image whose dest layout is %d and doesn't match the current layout %d.", destImageLayout, dest_image_element->second.layout);
Michael Lentineabc5e922015-10-12 11:30:14 -05005313 }
5314 if (destImageLayout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) {
5315 if (destImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005316 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
5317 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
5318 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Michael Lentineabc5e922015-10-12 11:30:14 -05005319 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005320 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
5321 "Layout for output image is %d but can only be TRANSFER_DST_OPTIMAL or GENERAL.", destImageLayout);
Michael Lentineabc5e922015-10-12 11:30:14 -05005322 }
5323 }
5324 return skip_call;
5325}
5326
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005327VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImage(VkCommandBuffer commandBuffer,
5328 VkImage srcImage,
5329 VkImageLayout srcImageLayout,
5330 VkImage dstImage,
5331 VkImageLayout dstImageLayout,
5332 uint32_t regionCount, const VkImageCopy* pRegions)
5333{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005334 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005335 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005336 loader_platform_thread_lock_mutex(&globalLock);
5337 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005338 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005339 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGE, "vkCmdCopyImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005340 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImage");
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005341 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
5342 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005343 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005344 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005345 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005346 dev_data->device_dispatch_table->CmdCopyImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005347}
5348
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005349VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBlitImage(VkCommandBuffer commandBuffer,
5350 VkImage srcImage, VkImageLayout srcImageLayout,
5351 VkImage dstImage, VkImageLayout dstImageLayout,
5352 uint32_t regionCount, const VkImageBlit* pRegions,
5353 VkFilter filter)
5354{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005355 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005356 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005357 loader_platform_thread_lock_mutex(&globalLock);
5358 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06005359 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005360 skipCall |= addCmd(dev_data, pCB, CMD_BLITIMAGE, "vkCmdBlitImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005361 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBlitImage");
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06005362 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005363 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005364 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005365 dev_data->device_dispatch_table->CmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter);
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06005366}
5367
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005368VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer,
5369 VkBuffer srcBuffer,
5370 VkImage dstImage, VkImageLayout dstImageLayout,
5371 uint32_t regionCount, const VkBufferImageCopy* pRegions)
5372{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005373 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005374 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005375 loader_platform_thread_lock_mutex(&globalLock);
5376 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005377 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005378 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFERTOIMAGE, "vkCmdCopyBufferToImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005379 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBufferToImage");
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005380 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005381 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005382 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005383 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005384 dev_data->device_dispatch_table->CmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005385}
5386
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005387VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer,
5388 VkImage srcImage, VkImageLayout srcImageLayout,
5389 VkBuffer dstBuffer,
5390 uint32_t regionCount, const VkBufferImageCopy* pRegions)
5391{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005392 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005393 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005394 loader_platform_thread_lock_mutex(&globalLock);
5395 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005396 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005397 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGETOBUFFER, "vkCmdCopyImageToBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005398 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImageToBuffer");
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005399 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005400 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005401 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005402 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005403 dev_data->device_dispatch_table->CmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005404}
5405
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005406VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize dataSize, const uint32_t* pData)
5407{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005408 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005409 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005410 loader_platform_thread_lock_mutex(&globalLock);
5411 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005412 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005413 skipCall |= addCmd(dev_data, pCB, CMD_UPDATEBUFFER, "vkCmdUpdateBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005414 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyUpdateBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005415 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005416 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005417 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005418 dev_data->device_dispatch_table->CmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005419}
5420
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005421VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize size, uint32_t data)
5422{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005423 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005424 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005425 loader_platform_thread_lock_mutex(&globalLock);
5426 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005427 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005428 skipCall |= addCmd(dev_data, pCB, CMD_FILLBUFFER, "vkCmdFillBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005429 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyFillBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005430 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005431 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005432 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005433 dev_data->device_dispatch_table->CmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005434}
5435
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005436VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearAttachments(
5437 VkCommandBuffer commandBuffer,
5438 uint32_t attachmentCount,
5439 const VkClearAttachment* pAttachments,
5440 uint32_t rectCount,
5441 const VkClearRect* pRects)
5442{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005443 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005444 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005445 loader_platform_thread_lock_mutex(&globalLock);
5446 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06005447 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005448 skipCall |= addCmd(dev_data, pCB, CMD_CLEARATTACHMENTS, "vkCmdClearAttachments()");
5449 // Warn if this is issued prior to Draw Cmd and clearing the entire attachment
5450 if (!hasDrawCmd(pCB) &&
5451 (pCB->activeRenderPassBeginInfo.renderArea.extent.width == pRects[0].rect.extent.width) &&
5452 (pCB->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005453 // TODO : commandBuffer should be srcObj
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005454 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",
5455 "vkCmdClearAttachments() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
5456 " It is recommended you use RenderPass LOAD_OP_CLEAR on Attachments prior to any Draw.", (uint64_t)(commandBuffer));
Tobin Ehlis53eddda2015-07-01 16:46:13 -06005457 }
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06005458 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdClearAttachments");
5459 }
5460
5461 // Validate that attachment is in reference list of active subpass
5462 if (pCB->activeRenderPass) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005463 const VkRenderPassCreateInfo *pRPCI = dev_data->renderPassMap[pCB->activeRenderPass]->pCreateInfo;
5464 const VkSubpassDescription *pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06005465
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005466 for (uint32_t attachment_idx = 0; attachment_idx < attachmentCount; attachment_idx++) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06005467 const VkClearAttachment *attachment = &pAttachments[attachment_idx];
5468 if (attachment->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) {
5469 VkBool32 found = VK_FALSE;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005470 for (uint32_t i = 0; i < pSD->colorAttachmentCount; i++) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005471 if (attachment->colorAttachment == pSD->pColorAttachments[i].attachment) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06005472 found = VK_TRUE;
5473 break;
5474 }
5475 }
5476 if (VK_FALSE == found) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005477 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
5478 (uint64_t)commandBuffer, __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
5479 "vkCmdClearAttachments() attachment index %d not found in attachment reference array of active subpass %d",
5480 attachment->colorAttachment, pCB->activeSubpass);
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06005481 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005482 } else if (attachment->aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) {
5483 if (!pSD->pDepthStencilAttachment || // Says no DS will be used in active subpass
5484 (pSD->pDepthStencilAttachment->attachment == VK_ATTACHMENT_UNUSED)) { // Says no DS will be used in active subpass
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07005485
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005486 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
5487 (uint64_t)commandBuffer, __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
5488 "vkCmdClearAttachments() attachment index %d does not match depthStencilAttachment.attachment (%d) found in active subpass %d",
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07005489 attachment->colorAttachment,
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005490 (pSD->pDepthStencilAttachment) ? pSD->pDepthStencilAttachment->attachment : VK_ATTACHMENT_UNUSED,
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07005491 pCB->activeSubpass);
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06005492 }
5493 }
5494 }
Tobin Ehlis53eddda2015-07-01 16:46:13 -06005495 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005496 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005497 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005498 dev_data->device_dispatch_table->CmdClearAttachments(commandBuffer, attachmentCount, pAttachments, rectCount, pRects);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06005499}
5500
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005501VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearColorImage(
5502 VkCommandBuffer commandBuffer,
5503 VkImage image, VkImageLayout imageLayout,
5504 const VkClearColorValue *pColor,
5505 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
5506{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005507 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005508 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005509 loader_platform_thread_lock_mutex(&globalLock);
5510 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005511 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005512 skipCall |= addCmd(dev_data, pCB, CMD_CLEARCOLORIMAGE, "vkCmdClearColorImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005513 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearColorImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005514 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005515 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005516 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005517 dev_data->device_dispatch_table->CmdClearColorImage(commandBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005518}
5519
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005520VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearDepthStencilImage(
5521 VkCommandBuffer commandBuffer,
5522 VkImage image, VkImageLayout imageLayout,
5523 const VkClearDepthStencilValue *pDepthStencil,
5524 uint32_t rangeCount,
5525 const VkImageSubresourceRange* pRanges)
5526{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005527 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005528 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005529 loader_platform_thread_lock_mutex(&globalLock);
5530 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005531 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005532 skipCall |= addCmd(dev_data, pCB, CMD_CLEARDEPTHSTENCILIMAGE, "vkCmdClearDepthStencilImage()");
5533 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearDepthStencilImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005534 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005535 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005536 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005537 dev_data->device_dispatch_table->CmdClearDepthStencilImage(commandBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005538}
5539
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005540VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResolveImage(VkCommandBuffer commandBuffer,
5541 VkImage srcImage, VkImageLayout srcImageLayout,
5542 VkImage dstImage, VkImageLayout dstImageLayout,
5543 uint32_t regionCount, const VkImageResolve* pRegions)
5544{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005545 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005546 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005547 loader_platform_thread_lock_mutex(&globalLock);
5548 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005549 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005550 skipCall |= addCmd(dev_data, pCB, CMD_RESOLVEIMAGE, "vkCmdResolveImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005551 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResolveImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005552 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005553 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005554 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005555 dev_data->device_dispatch_table->CmdResolveImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005556}
5557
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005558VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
5559{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005560 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005561 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005562 loader_platform_thread_lock_mutex(&globalLock);
5563 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005564 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005565 skipCall |= addCmd(dev_data, pCB, CMD_SETEVENT, "vkCmdSetEvent()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005566 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdSetEvent");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005567 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005568 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005569 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005570 dev_data->device_dispatch_table->CmdSetEvent(commandBuffer, event, stageMask);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005571}
5572
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005573VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
5574{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005575 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005576 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005577 loader_platform_thread_lock_mutex(&globalLock);
5578 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005579 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005580 skipCall |= addCmd(dev_data, pCB, CMD_RESETEVENT, "vkCmdResetEvent()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005581 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResetEvent");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005582 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005583 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005584 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005585 dev_data->device_dispatch_table->CmdResetEvent(commandBuffer, event, stageMask);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005586}
5587
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005588VkBool32 TransitionImageLayouts(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const VkImageMemoryBarrier* pImgMemBarriers) {
5589 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005590 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer, false);
Mark Youngb20a6a82016-01-07 15:41:43 -07005591 VkBool32 skip = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005592
5593#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005594 // TODO: Fix -- pay attention to image subresource ranges -- not all subresources transition at the same time
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005595 return skip;
5596#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5597
Michael Lentineabc5e922015-10-12 11:30:14 -05005598 for (uint32_t i = 0; i < memBarrierCount; ++i) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005599 auto mem_barrier = &pImgMemBarriers[i];
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005600 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005601 auto image_data = pCB->imageLayoutMap.find(mem_barrier->image);
Michael Lentineabc5e922015-10-12 11:30:14 -05005602 if (image_data == pCB->imageLayoutMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005603 pCB->imageLayoutMap[mem_barrier->image].initialLayout = mem_barrier->oldLayout;
5604 pCB->imageLayoutMap[mem_barrier->image].layout = mem_barrier->newLayout;
Michael Lentineabc5e922015-10-12 11:30:14 -05005605 } else {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005606 if (image_data->second.layout != mem_barrier->oldLayout) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005607 skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
5608 "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 -05005609 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07005610 image_data->second.layout = mem_barrier->newLayout;
Michael Lentineabc5e922015-10-12 11:30:14 -05005611 }
5612 }
5613 }
5614 return skip;
5615}
5616
Mark Lobodzinskia3a86112016-01-05 17:17:55 -07005617// Print readable FlagBits in FlagMask
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005618std::string string_VkAccessFlags(VkAccessFlags accessMask)
5619{
Mark Lobodzinskia3a86112016-01-05 17:17:55 -07005620 std::string result;
5621 std::string separator;
5622
5623 if (accessMask == 0) {
5624 result = "[None]";
5625 } else {
5626 result = "[";
5627 for (auto i = 0; i < 32; i++) {
5628 if (accessMask & (1 << i)) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005629 result = result + separator + string_VkAccessFlagBits((VkAccessFlagBits)(1 << i));
Mark Lobodzinskia3a86112016-01-05 17:17:55 -07005630 separator = " | ";
5631 }
5632 }
5633 result = result + "]";
5634 }
5635 return result;
5636}
5637
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005638// AccessFlags MUST have 'required_bit' set, and may have one or more of 'optional_bits' set.
5639// If required_bit is zero, accessMask must have at least one of 'optional_bits' set
5640// TODO: Add tracking to ensure that at least one barrier has been set for these layout transitions
5641VkBool32 ValidateMaskBits(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout,
5642 VkAccessFlags required_bit, VkAccessFlags optional_bits, const char* type) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005643 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005644
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005645 if ((accessMask & required_bit) || (!required_bit && (accessMask & optional_bits))) {
Michael Lentine97eb7462015-11-20 09:48:52 -08005646 if (accessMask & !(required_bit | optional_bits)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005647 // TODO: Verify against Valid Use
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005648 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
5649 "Additional bits in %s accessMask %d %s are specified when layout is %s.",
5650 type, accessMask, string_VkAccessFlags(accessMask).c_str(), string_VkImageLayout(layout));
Michael Lentineecc32b72015-10-16 18:08:09 -05005651 }
5652 } else {
Michael Lentine97eb7462015-11-20 09:48:52 -08005653 if (!required_bit) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005654 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
5655 "%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.",
5656 type, accessMask, string_VkAccessFlags(accessMask).c_str(), optional_bits,
5657 string_VkAccessFlags(optional_bits).c_str(), string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08005658 } else {
Mark Lobodzinskif2cc2a52016-01-05 13:35:29 -07005659 std::string opt_bits;
5660 if (optional_bits != 0) {
Michael Lentine6bd4f122016-01-19 14:00:53 -06005661 std::stringstream ss;
5662 ss << optional_bits;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005663 opt_bits = "and may have optional bits " + ss.str() + ' ' + string_VkAccessFlags(optional_bits);
Mark Lobodzinskif2cc2a52016-01-05 13:35:29 -07005664 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005665 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
5666 "%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.",
5667 type, accessMask, string_VkAccessFlags(accessMask).c_str(),
5668 required_bit, string_VkAccessFlags(required_bit).c_str(),
5669 opt_bits.c_str(), string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08005670 }
Michael Lentineecc32b72015-10-16 18:08:09 -05005671 }
5672 return skip_call;
5673}
5674
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005675VkBool32 ValidateMaskBitsFromLayouts(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout, const char* type) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005676 VkBool32 skip_call = VK_FALSE;
Michael Lentine97eb7462015-11-20 09:48:52 -08005677 switch (layout) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005678 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: {
5679 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_COLOR_ATTACHMENT_READ_BIT, type);
5680 break;
Michael Lentineecc32b72015-10-16 18:08:09 -05005681 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005682 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: {
5683 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT, type);
5684 break;
5685 }
5686 case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: {
5687 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_WRITE_BIT, 0, type);
5688 break;
5689 }
5690 case VK_IMAGE_LAYOUT_PREINITIALIZED: {
5691 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_HOST_WRITE_BIT, 0, type);
5692 break;
5693 }
5694 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: {
5695 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, 0, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT, type);
5696 break;
5697 }
5698 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: {
5699 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, 0, VK_ACCESS_INPUT_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT, type);
5700 break;
5701 }
5702 case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: {
5703 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_READ_BIT, 0, type);
5704 break;
5705 }
5706 case VK_IMAGE_LAYOUT_UNDEFINED: {
5707 if (accessMask != 0) {
5708 // TODO: Verify against Valid Use section spec
5709 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
5710 "Additional bits in %s accessMask %d %s are specified when layout is %s.", type, accessMask, string_VkAccessFlags(accessMask).c_str(),
5711 string_VkImageLayout(layout));
5712 }
5713 break;
5714 }
5715 case VK_IMAGE_LAYOUT_GENERAL:
5716 default: {
5717 break;
5718 }
Michael Lentineecc32b72015-10-16 18:08:09 -05005719 }
5720 return skip_call;
5721}
5722
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005723VkBool32 ValidateBarriers(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const VkMemoryBarrier* pMemBarriers, uint32_t imageMemBarrierCount, const VkImageMemoryBarrier *pImageMemBarriers)
5724{
Mark Youngb20a6a82016-01-07 15:41:43 -07005725 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005726 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005727 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer, false);
Michael Lentine48930b82015-10-15 17:07:00 -05005728 if (pCB->activeRenderPass && memBarrierCount) {
5729 for (uint32_t i = 0; i < memBarrierCount; ++i) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005730 auto mem_barrier = &pMemBarriers[i];
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005731 if (mem_barrier && mem_barrier->sType != VK_STRUCTURE_TYPE_MEMORY_BARRIER) {
5732 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
5733 "Image or Buffers Barriers cannot be used during a render pass.");
Michael Lentine48930b82015-10-15 17:07:00 -05005734 }
5735 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005736 if (!dev_data->renderPassMap[pCB->activeRenderPass]->hasSelfDependency[pCB->activeSubpass]) {
5737 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
5738 "Barriers cannot be set during subpass %d with no self dependency specified.", pCB->activeSubpass);
Michael Lentine48930b82015-10-15 17:07:00 -05005739 }
5740 }
Mark Lobodzinski73a37ec2015-11-20 09:27:27 -07005741
Jon Ashburnf19916e2016-01-11 13:12:43 -07005742 for (uint32_t i = 0; i < imageMemBarrierCount; ++i) {
5743 auto mem_barrier = &pImageMemBarriers[i];
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005744 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
5745 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, mem_barrier->srcAccessMask, mem_barrier->oldLayout, "Source");
5746 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, mem_barrier->dstAccessMask, mem_barrier->newLayout, "Dest");
Michael Lentineecc32b72015-10-16 18:08:09 -05005747 }
5748 }
Mark Lobodzinski3cba24a2015-12-03 15:42:32 -07005749
Michael Lentine48930b82015-10-15 17:07:00 -05005750 return skip_call;
5751}
5752
Jon Ashburnf19916e2016-01-11 13:12:43 -07005753VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdWaitEvents(
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005754 VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent* pEvents,
5755 VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask,
5756 uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers,
5757 uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers,
5758 uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers)
5759{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005760 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005761 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005762 loader_platform_thread_lock_mutex(&globalLock);
5763 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005764 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005765 for (uint32_t i = 0; i < eventCount; ++i) {
5766 pCB->waitedEvents.push_back(pEvents[i]);
5767 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005768 if (pCB->state == CB_RECORDING) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005769 skipCall |= addCmd(dev_data, pCB, CMD_WAITEVENTS, "vkCmdWaitEvents()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005770 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005771 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdWaitEvents()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005772 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005773 skipCall |= TransitionImageLayouts(commandBuffer, imageMemoryBarrierCount, pImageMemoryBarriers);
5774 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, pMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005775 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005776 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005777 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005778 dev_data->device_dispatch_table->CmdWaitEvents(commandBuffer, eventCount, pEvents, sourceStageMask, dstStageMask,
5779 memoryBarrierCount, pMemoryBarriers,
5780 bufferMemoryBarrierCount, pBufferMemoryBarriers,
5781 imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005782}
5783
Jon Ashburnf19916e2016-01-11 13:12:43 -07005784VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdPipelineBarrier(
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005785 VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask,
5786 VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags,
5787 uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers,
5788 uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers,
5789 uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers)
5790{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005791 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005792 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005793 loader_platform_thread_lock_mutex(&globalLock);
5794 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005795 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005796 skipCall |= addCmd(dev_data, pCB, CMD_PIPELINEBARRIER, "vkCmdPipelineBarrier()");
5797 skipCall |= TransitionImageLayouts(commandBuffer, imageMemoryBarrierCount, pImageMemoryBarriers);
5798 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, pMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005799 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005800 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005801 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005802 dev_data->device_dispatch_table->CmdPipelineBarrier(commandBuffer, srcStageMask, dstStageMask, dependencyFlags,
5803 memoryBarrierCount, pMemoryBarriers,
5804 bufferMemoryBarrierCount, pBufferMemoryBarriers,
5805 imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005806}
5807
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005808VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
5809{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005810 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005811 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005812 loader_platform_thread_lock_mutex(&globalLock);
5813 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005814 if (pCB) {
Michael Lentinedc6f8de2016-02-02 18:29:30 -06005815 QueryObject query = {queryPool, slot};
5816 pCB->activeQueries.insert(query);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005817 skipCall |= addCmd(dev_data, pCB, CMD_BEGINQUERY, "vkCmdBeginQuery()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005818 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005819 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005820 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005821 dev_data->device_dispatch_table->CmdBeginQuery(commandBuffer, queryPool, slot, flags);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005822}
5823
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005824VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot)
5825{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005826 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005827 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005828 loader_platform_thread_lock_mutex(&globalLock);
5829 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005830 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005831 QueryObject query = {queryPool, slot};
Michael Lentinedc6f8de2016-02-02 18:29:30 -06005832 if (!pCB->activeQueries.count(query)) {
5833 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_QUERY, "DS",
5834 "Ending a query before it was started: queryPool %" PRIu64 ", index %d", (uint64_t)(queryPool), slot);
5835 } else {
5836 pCB->activeQueries.erase(query);
5837 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06005838 pCB->queryToStateMap[query] = 1;
Mark Lobodzinskice738852016-01-07 10:04:02 -07005839 if (pCB->state == CB_RECORDING) {
5840 skipCall |= addCmd(dev_data, pCB, CMD_ENDQUERY, "VkCmdEndQuery()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005841 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005842 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdEndQuery()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005843 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005844 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005845 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005846 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005847 dev_data->device_dispatch_table->CmdEndQuery(commandBuffer, queryPool, slot);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005848}
5849
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005850VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResetQueryPool(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount)
5851{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005852 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005853 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005854 loader_platform_thread_lock_mutex(&globalLock);
5855 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005856 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005857 for (uint32_t i = 0; i < queryCount; i++) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005858 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06005859 pCB->waitedEventsBeforeQueryReset[query] = pCB->waitedEvents;
5860 pCB->queryToStateMap[query] = 0;
5861 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005862 if (pCB->state == CB_RECORDING) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005863 skipCall |= addCmd(dev_data, pCB, CMD_RESETQUERYPOOL, "VkCmdResetQueryPool()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005864 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005865 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdResetQueryPool()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005866 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005867 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdQueryPool");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005868 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005869 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005870 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005871 dev_data->device_dispatch_table->CmdResetQueryPool(commandBuffer, queryPool, firstQuery, queryCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005872}
5873
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005874VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery,
5875 uint32_t queryCount, VkBuffer dstBuffer, VkDeviceSize dstOffset,
5876 VkDeviceSize stride, VkQueryResultFlags flags)
5877{
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005878 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005879 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005880 loader_platform_thread_lock_mutex(&globalLock);
5881 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005882 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005883 for (uint32_t i = 0; i < queryCount; i++) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005884 QueryObject query = {queryPool, firstQuery + i};
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005885 if(!pCB->queryToStateMap[query]) {
5886 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_QUERY, "DS",
5887 "Requesting a copy from query to buffer with invalid query: queryPool %" PRIu64 ", index %d", (uint64_t)(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06005888 }
5889 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005890 if (pCB->state == CB_RECORDING) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005891 skipCall |= addCmd(dev_data, pCB, CMD_COPYQUERYPOOLRESULTS, "vkCmdCopyQueryPoolResults()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005892 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005893 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdCopyQueryPoolResults()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005894 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005895 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyQueryPoolResults");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005896 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005897 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005898 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005899 dev_data->device_dispatch_table->CmdCopyQueryPoolResults(commandBuffer, queryPool,
5900 firstQuery, queryCount, dstBuffer, dstOffset, stride, flags);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005901}
5902
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005903VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, VkQueryPool queryPool, uint32_t slot)
5904{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005905 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005906 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005907 loader_platform_thread_lock_mutex(&globalLock);
5908 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005909 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005910 QueryObject query = {queryPool, slot};
5911 pCB->queryToStateMap[query] = 1;
Mark Lobodzinskice738852016-01-07 10:04:02 -07005912 if (pCB->state == CB_RECORDING) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005913 skipCall |= addCmd(dev_data, pCB, CMD_WRITETIMESTAMP, "vkCmdWriteTimestamp()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005914 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005915 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdWriteTimestamp()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005916 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005917 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005918 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005919 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005920 dev_data->device_dispatch_table->CmdWriteTimestamp(commandBuffer, pipelineStage, queryPool, slot);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005921}
5922
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005923VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkFramebuffer* pFramebuffer)
5924{
5925 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5926 VkResult result = dev_data->device_dispatch_table->CreateFramebuffer(device, pCreateInfo, pAllocator, pFramebuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005927 if (VK_SUCCESS == result) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06005928 // Shadow create info and store in map
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005929 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +08005930 if (pCreateInfo->pAttachments) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005931 localFBCI->pAttachments = new VkImageView[localFBCI->attachmentCount];
5932 memcpy((void*)localFBCI->pAttachments, pCreateInfo->pAttachments, localFBCI->attachmentCount*sizeof(VkImageView));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005933 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005934 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08005935 dev_data->frameBufferMap[*pFramebuffer] = localFBCI;
Ian Elliott8c8b2662016-01-30 10:57:03 -07005936 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehliseba312c2015-04-01 08:40:34 -06005937 }
5938 return result;
5939}
5940
Michael Lentineb6986752015-10-06 14:56:18 -07005941// Store the DAG.
5942struct DAGNode {
5943 uint32_t pass;
5944 std::vector<uint32_t> prev;
5945 std::vector<uint32_t> next;
5946};
5947
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005948VkBool32 FindDependency(const int index, const int dependent, const std::vector<DAGNode>& subpass_to_node, std::unordered_set<uint32_t>& processed_nodes) {
5949 // If we have already checked this node we have not found a dependency path so return false.
Michael Lentineb6986752015-10-06 14:56:18 -07005950 if (processed_nodes.count(index))
Mark Youngb20a6a82016-01-07 15:41:43 -07005951 return VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005952 processed_nodes.insert(index);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005953 const DAGNode& node = subpass_to_node[index];
5954 // Look for a dependency path. If one exists return true else recurse on the previous nodes.
5955 if (std::find(node.prev.begin(), node.prev.end(), dependent) == node.prev.end()) {
Michael Lentineb6986752015-10-06 14:56:18 -07005956 for (auto elem : node.prev) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005957 if (FindDependency(elem, dependent, subpass_to_node, processed_nodes))
Mark Youngb20a6a82016-01-07 15:41:43 -07005958 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005959 }
5960 } else {
Mark Youngb20a6a82016-01-07 15:41:43 -07005961 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005962 }
Mark Youngb20a6a82016-01-07 15:41:43 -07005963 return VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005964}
5965
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005966VkBool32 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 -07005967 VkBool32 result = VK_TRUE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005968 // Loop through all subpasses that share the same attachment and make sure a dependency exists
Michael Lentineb6986752015-10-06 14:56:18 -07005969 for (uint32_t k = 0; k < dependent_subpasses.size(); ++k) {
5970 if (subpass == dependent_subpasses[k])
5971 continue;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005972 const DAGNode& node = subpass_to_node[subpass];
5973 // Check for a specified dependency between the two nodes. If one exists we are done.
5974 auto prev_elem = std::find(node.prev.begin(), node.prev.end(), dependent_subpasses[k]);
5975 auto next_elem = std::find(node.next.begin(), node.next.end(), dependent_subpasses[k]);
Michael Lentineb6986752015-10-06 14:56:18 -07005976 if (prev_elem == node.prev.end() && next_elem == node.next.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005977 // If no dependency exits an implicit dependency still might. If so, warn and if not throw an error.
Michael Lentineb6986752015-10-06 14:56:18 -07005978 std::unordered_set<uint32_t> processed_nodes;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005979 if (FindDependency(subpass, dependent_subpasses[k], subpass_to_node, processed_nodes) ||
5980 FindDependency(dependent_subpasses[k], subpass, subpass_to_node, processed_nodes)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005981 // TODO: Verify against Valid Use section of spec
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005982 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
5983 "A dependency between subpasses %d and %d must exist but only an implicit one is specified.",
5984 subpass, dependent_subpasses[k]);
Michael Lentineb6986752015-10-06 14:56:18 -07005985 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005986 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
5987 "A dependency between subpasses %d and %d must exist but one is not specified.",
5988 subpass, dependent_subpasses[k]);
Mark Youngb20a6a82016-01-07 15:41:43 -07005989 result = VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005990 }
5991 }
5992 }
5993 return result;
5994}
5995
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005996VkBool32 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) {
5997 const DAGNode& node = subpass_to_node[index];
5998 // If this node writes to the attachment return true as next nodes need to preserve the attachment.
5999 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Chia-I Wud50a7d72015-10-26 20:48:51 +08006000 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07006001 if (attachment == subpass.pColorAttachments[j].attachment)
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07006002 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07006003 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08006004 if (subpass.pDepthStencilAttachment &&
6005 subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
6006 if (attachment == subpass.pDepthStencilAttachment->attachment)
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07006007 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07006008 }
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07006009 VkBool32 result = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006010 // Loop through previous nodes and see if any of them write to the attachment.
Michael Lentineb6986752015-10-06 14:56:18 -07006011 for (auto elem : node.prev) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006012 result |= CheckPreserved(my_data, device, pCreateInfo, elem, attachment, subpass_to_node, depth + 1, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07006013 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006014 // If the attachment was written to by a previous node than this node needs to preserve it.
Michael Lentineb6986752015-10-06 14:56:18 -07006015 if (result && depth > 0) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006016 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Mark Youngb20a6a82016-01-07 15:41:43 -07006017 VkBool32 has_preserved = VK_FALSE;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006018 for (uint32_t j = 0; j < subpass.preserveAttachmentCount; ++j) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07006019 if (subpass.pPreserveAttachments[j] == attachment) {
Mark Youngb20a6a82016-01-07 15:41:43 -07006020 has_preserved = VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07006021 break;
6022 }
6023 }
Mark Youngb20a6a82016-01-07 15:41:43 -07006024 if (has_preserved == VK_FALSE) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006025 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
6026 "Attachment %d is used by a later subpass and must be preserved in subpass %d.", attachment, index);
Michael Lentineb6986752015-10-06 14:56:18 -07006027 }
6028 }
6029 return result;
6030}
6031
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006032VkBool32 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 -07006033 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006034 std::vector<std::vector<uint32_t>> output_attachment_to_subpass(pCreateInfo->attachmentCount);
6035 std::vector<std::vector<uint32_t>> input_attachment_to_subpass(pCreateInfo->attachmentCount);
Michael Lentineb6986752015-10-06 14:56:18 -07006036 // Find for each attachment the subpasses that use them.
6037 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006038 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08006039 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006040 input_attachment_to_subpass[subpass.pInputAttachments[j].attachment].push_back(i);
Michael Lentineb6986752015-10-06 14:56:18 -07006041 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08006042 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006043 output_attachment_to_subpass[subpass.pColorAttachments[j].attachment].push_back(i);
Michael Lentineb6986752015-10-06 14:56:18 -07006044 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006045 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
6046 output_attachment_to_subpass[subpass.pDepthStencilAttachment->attachment].push_back(i);
Michael Lentineb6986752015-10-06 14:56:18 -07006047 }
6048 }
6049 // If there is a dependency needed make sure one exists
6050 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006051 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
6052 // If the attachment is an input then all subpasses that output must have a dependency relationship
Chia-I Wud50a7d72015-10-26 20:48:51 +08006053 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006054 const uint32_t& attachment = subpass.pInputAttachments[j].attachment;
6055 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07006056 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006057 // 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 +08006058 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006059 const uint32_t& attachment = subpass.pColorAttachments[j].attachment;
6060 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
6061 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07006062 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006063 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
6064 const uint32_t& attachment = subpass.pDepthStencilAttachment->attachment;
6065 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
6066 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07006067 }
6068 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006069 // Loop through implicit dependencies, if this pass reads make sure the attachment is preserved for all passes after it was written.
Michael Lentineb6986752015-10-06 14:56:18 -07006070 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006071 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08006072 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006073 CheckPreserved(my_data, device, pCreateInfo, i, subpass.pInputAttachments[j].attachment, subpass_to_node, 0, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07006074 }
6075 }
6076 return skip_call;
6077}
6078
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006079VkBool32 ValidateLayouts(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo) {
Mark Youngb20a6a82016-01-07 15:41:43 -07006080 VkBool32 skip = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006081
6082#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
6083 return skip;
6084#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
6085
Michael Lentineabc5e922015-10-12 11:30:14 -05006086 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006087 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Michael Lentineabc5e922015-10-12 11:30:14 -05006088 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006089 if (subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL &&
6090 subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) {
6091 if (subpass.pInputAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
6092 // TODO: Verify Valid Use in spec. I believe this is allowed (valid) but may not be optimal performance
6093 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
6094 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Michael Lentineabc5e922015-10-12 11:30:14 -05006095 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006096 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
6097 "Layout for input attachment is %d but can only be READ_ONLY_OPTIMAL or GENERAL.", subpass.pInputAttachments[j].attachment);
Michael Lentineabc5e922015-10-12 11:30:14 -05006098 }
6099 }
6100 }
6101 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006102 if (subpass.pColorAttachments[j].layout != VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) {
6103 if (subpass.pColorAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
6104 // TODO: Verify Valid Use in spec. I believe this is allowed (valid) but may not be optimal performance
6105 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
6106 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Michael Lentineabc5e922015-10-12 11:30:14 -05006107 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006108 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
6109 "Layout for color attachment is %d but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.", subpass.pColorAttachments[j].attachment);
Michael Lentineabc5e922015-10-12 11:30:14 -05006110 }
6111 }
6112 }
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06006113 if ((subpass.pDepthStencilAttachment != NULL) &&
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006114 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
6115 if (subpass.pDepthStencilAttachment->layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) {
6116 if (subpass.pDepthStencilAttachment->layout == VK_IMAGE_LAYOUT_GENERAL) {
6117 // TODO: Verify Valid Use in spec. I believe this is allowed (valid) but may not be optimal performance
6118 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
6119 "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL.");
Michael Lentineabc5e922015-10-12 11:30:14 -05006120 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006121 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
6122 "Layout for depth attachment is %d but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL.", subpass.pDepthStencilAttachment->attachment);
Michael Lentineabc5e922015-10-12 11:30:14 -05006123 }
6124 }
6125 }
6126 }
6127 return skip;
6128}
6129
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006130VkBool32 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 -07006131 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05006132 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006133 DAGNode& subpass_node = subpass_to_node[i];
Michael Lentineabc5e922015-10-12 11:30:14 -05006134 subpass_node.pass = i;
6135 }
6136 for (uint32_t i = 0; i < pCreateInfo->dependencyCount; ++i) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006137 const VkSubpassDependency& dependency = pCreateInfo->pDependencies[i];
6138 if (dependency.srcSubpass > dependency.dstSubpass && dependency.srcSubpass != VK_SUBPASS_EXTERNAL && dependency.dstSubpass != VK_SUBPASS_EXTERNAL) {
6139 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
6140 "Depedency graph must be specified such that an earlier pass cannot depend on a later pass.");
6141 } else if (dependency.srcSubpass == VK_SUBPASS_EXTERNAL && dependency.dstSubpass == VK_SUBPASS_EXTERNAL) {
6142 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
6143 "The src and dest subpasses cannot both be external.");
Michael Lentine48930b82015-10-15 17:07:00 -05006144 } else if (dependency.srcSubpass == dependency.dstSubpass) {
6145 has_self_dependency[dependency.srcSubpass] = true;
Michael Lentineabc5e922015-10-12 11:30:14 -05006146 }
Michael Lentine6bd4f122016-01-19 14:00:53 -06006147 if (dependency.dstSubpass != VK_SUBPASS_EXTERNAL) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006148 subpass_to_node[dependency.dstSubpass].prev.push_back(dependency.srcSubpass);
Michael Lentine6bd4f122016-01-19 14:00:53 -06006149 }
6150 if (dependency.srcSubpass != VK_SUBPASS_EXTERNAL) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006151 subpass_to_node[dependency.srcSubpass].next.push_back(dependency.dstSubpass);
Michael Lentine6bd4f122016-01-19 14:00:53 -06006152 }
Michael Lentineabc5e922015-10-12 11:30:14 -05006153 }
6154 return skip_call;
6155}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006156// TODOSC : Add intercept of vkCreateShaderModule
Michael Lentineabc5e922015-10-12 11:30:14 -05006157
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006158VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateShaderModule(
6159 VkDevice device,
6160 const VkShaderModuleCreateInfo *pCreateInfo,
6161 const VkAllocationCallbacks* pAllocator,
6162 VkShaderModule *pShaderModule)
6163{
6164 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07006165 VkBool32 skip_call = VK_FALSE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006166 if (!shader_is_spirv(pCreateInfo)) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006167 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
6168 /* dev */ 0, __LINE__, SHADER_CHECKER_NON_SPIRV_SHADER, "SC",
6169 "Shader is not SPIR-V");
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006170 }
6171
Mark Youngb20a6a82016-01-07 15:41:43 -07006172 if (VK_FALSE != skip_call)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07006173 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006174
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006175 VkResult res = my_data->device_dispatch_table->CreateShaderModule(device, pCreateInfo, pAllocator, pShaderModule);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006176
6177 if (res == VK_SUCCESS) {
6178 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006179 my_data->shaderModuleMap[*pShaderModule] = new shader_module(pCreateInfo);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006180 loader_platform_thread_unlock_mutex(&globalLock);
6181 }
6182 return res;
6183}
6184
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006185VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkRenderPass* pRenderPass)
6186{
Mark Youngb20a6a82016-01-07 15:41:43 -07006187 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006188 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07006189 loader_platform_thread_lock_mutex(&globalLock);
Michael Lentineabc5e922015-10-12 11:30:14 -05006190 // Create DAG
Michael Lentine48930b82015-10-15 17:07:00 -05006191 std::vector<bool> has_self_dependency(pCreateInfo->subpassCount);
Michael Lentineabc5e922015-10-12 11:30:14 -05006192 std::vector<DAGNode> subpass_to_node(pCreateInfo->subpassCount);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006193 skip_call |= CreatePassDAG(dev_data, device, pCreateInfo, subpass_to_node, has_self_dependency);
Michael Lentineabc5e922015-10-12 11:30:14 -05006194 // Validate using DAG
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006195 skip_call |= ValidateDependencies(dev_data, device, pCreateInfo, subpass_to_node);
Michael Lentineabc5e922015-10-12 11:30:14 -05006196 skip_call |= ValidateLayouts(dev_data, device, pCreateInfo);
Mark Youngb20a6a82016-01-07 15:41:43 -07006197 if (VK_FALSE != skip_call) {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07006198 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentineb6986752015-10-06 14:56:18 -07006199 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07006200 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006201 VkResult result = dev_data->device_dispatch_table->CreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006202 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006203 // TODOSC : Merge in tracking of renderpass from ShaderChecker
Tobin Ehliseba312c2015-04-01 08:40:34 -06006204 // Shadow create info and store in map
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006205 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +08006206 if (pCreateInfo->pAttachments) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006207 localRPCI->pAttachments = new VkAttachmentDescription[localRPCI->attachmentCount];
6208 memcpy((void*)localRPCI->pAttachments, pCreateInfo->pAttachments, localRPCI->attachmentCount*sizeof(VkAttachmentDescription));
Tobin Ehliseba312c2015-04-01 08:40:34 -06006209 }
Chia-I Wu08accc62015-07-07 11:50:03 +08006210 if (pCreateInfo->pSubpasses) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006211 localRPCI->pSubpasses = new VkSubpassDescription[localRPCI->subpassCount];
6212 memcpy((void*)localRPCI->pSubpasses, pCreateInfo->pSubpasses, localRPCI->subpassCount*sizeof(VkSubpassDescription));
Chia-I Wu08accc62015-07-07 11:50:03 +08006213
6214 for (uint32_t i = 0; i < localRPCI->subpassCount; i++) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006215 VkSubpassDescription *subpass = (VkSubpassDescription *) &localRPCI->pSubpasses[i];
6216 const uint32_t attachmentCount = subpass->inputAttachmentCount +
6217 subpass->colorAttachmentCount * (1 + (subpass->pResolveAttachments?1:0)) +
6218 ((subpass->pDepthStencilAttachment) ? 1 : 0) + subpass->preserveAttachmentCount;
6219 VkAttachmentReference *attachments = new VkAttachmentReference[attachmentCount];
Chia-I Wu08accc62015-07-07 11:50:03 +08006220
Cody Northropa505dda2015-08-04 11:16:41 -06006221 memcpy(attachments, subpass->pInputAttachments,
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006222 sizeof(attachments[0]) * subpass->inputAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06006223 subpass->pInputAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006224 attachments += subpass->inputAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08006225
Cody Northropa505dda2015-08-04 11:16:41 -06006226 memcpy(attachments, subpass->pColorAttachments,
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006227 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06006228 subpass->pColorAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006229 attachments += subpass->colorAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08006230
Cody Northropa505dda2015-08-04 11:16:41 -06006231 if (subpass->pResolveAttachments) {
6232 memcpy(attachments, subpass->pResolveAttachments,
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006233 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06006234 subpass->pResolveAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006235 attachments += subpass->colorAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08006236 }
6237
Chia-I Wu1efb7e52015-10-26 17:32:47 +08006238 if (subpass->pDepthStencilAttachment) {
6239 memcpy(attachments, subpass->pDepthStencilAttachment,
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006240 sizeof(attachments[0]) * 1);
Chia-I Wu1efb7e52015-10-26 17:32:47 +08006241 subpass->pDepthStencilAttachment = attachments;
6242 attachments += 1;
6243 }
6244
Cody Northropa505dda2015-08-04 11:16:41 -06006245 memcpy(attachments, subpass->pPreserveAttachments,
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006246 sizeof(attachments[0]) * subpass->preserveAttachmentCount);
Jon Ashburnf19916e2016-01-11 13:12:43 -07006247 subpass->pPreserveAttachments = &attachments->attachment;
Chia-I Wu08accc62015-07-07 11:50:03 +08006248 }
Tobin Ehliseba312c2015-04-01 08:40:34 -06006249 }
Chia-I Wu08accc62015-07-07 11:50:03 +08006250 if (pCreateInfo->pDependencies) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006251 localRPCI->pDependencies = new VkSubpassDependency[localRPCI->dependencyCount];
6252 memcpy((void*)localRPCI->pDependencies, pCreateInfo->pDependencies, localRPCI->dependencyCount*sizeof(VkSubpassDependency));
Tobin Ehliseba312c2015-04-01 08:40:34 -06006253 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006254 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07006255 dev_data->renderPassMap[*pRenderPass] = new RENDER_PASS_NODE(localRPCI);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006256 dev_data->renderPassMap[*pRenderPass]->hasSelfDependency = has_self_dependency;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006257 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehliseba312c2015-04-01 08:40:34 -06006258 }
6259 return result;
6260}
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06006261// Free the renderpass shadow
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006262static void deleteRenderPasses(layer_data* my_data)
6263{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06006264 if (my_data->renderPassMap.size() <= 0)
6265 return;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006266 for (auto ii=my_data->renderPassMap.begin(); ii!=my_data->renderPassMap.end(); ++ii) {
6267 const VkRenderPassCreateInfo* pRenderPassInfo = (*ii).second->pCreateInfo;
Michael Lentine48930b82015-10-15 17:07:00 -05006268 if (pRenderPassInfo->pAttachments) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006269 delete[] pRenderPassInfo->pAttachments;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06006270 }
Michael Lentine48930b82015-10-15 17:07:00 -05006271 if (pRenderPassInfo->pSubpasses) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006272 for (uint32_t i=0; i<pRenderPassInfo->subpassCount; ++i) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06006273 // Attachements are all allocated in a block, so just need to
6274 // find the first non-null one to delete
Michael Lentine48930b82015-10-15 17:07:00 -05006275 if (pRenderPassInfo->pSubpasses[i].pInputAttachments) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006276 delete[] pRenderPassInfo->pSubpasses[i].pInputAttachments;
Michael Lentine48930b82015-10-15 17:07:00 -05006277 } else if (pRenderPassInfo->pSubpasses[i].pColorAttachments) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006278 delete[] pRenderPassInfo->pSubpasses[i].pColorAttachments;
Michael Lentine48930b82015-10-15 17:07:00 -05006279 } else if (pRenderPassInfo->pSubpasses[i].pResolveAttachments) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006280 delete[] pRenderPassInfo->pSubpasses[i].pResolveAttachments;
6281 } else if (pRenderPassInfo->pSubpasses[i].pPreserveAttachments) {
6282 delete[] pRenderPassInfo->pSubpasses[i].pPreserveAttachments;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06006283 }
6284 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006285 delete[] pRenderPassInfo->pSubpasses;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06006286 }
Michael Lentine48930b82015-10-15 17:07:00 -05006287 if (pRenderPassInfo->pDependencies) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006288 delete[] pRenderPassInfo->pDependencies;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06006289 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07006290 delete pRenderPassInfo;
Michael Lentine48930b82015-10-15 17:07:00 -05006291 delete (*ii).second;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06006292 }
6293 my_data->renderPassMap.clear();
6294}
Michael Lentineabc5e922015-10-12 11:30:14 -05006295
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006296VkBool32 VerifyFramebufferAndRenderPassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
Mark Youngb20a6a82016-01-07 15:41:43 -07006297 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006298 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07006299 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer, false);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006300 const VkRenderPassCreateInfo* pRenderPassInfo = dev_data->renderPassMap[pRenderPassBegin->renderPass]->pCreateInfo;
6301 const VkFramebufferCreateInfo* pFramebufferInfo = dev_data->frameBufferMap[pRenderPassBegin->framebuffer];
Michael Lentineabc5e922015-10-12 11:30:14 -05006302 if (pRenderPassInfo->attachmentCount != pFramebufferInfo->attachmentCount) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006303 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
6304 "You cannot start a render pass using a framebuffer with a different number of attachments.");
Michael Lentineabc5e922015-10-12 11:30:14 -05006305 }
6306 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006307 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
6308 const VkImage& image = dev_data->imageViewMap[image_view]->image;
Michael Lentineabc5e922015-10-12 11:30:14 -05006309 auto image_data = pCB->imageLayoutMap.find(image);
6310 if (image_data == pCB->imageLayoutMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006311 pCB->imageLayoutMap[image].initialLayout = pRenderPassInfo->pAttachments[i].initialLayout;
6312 pCB->imageLayoutMap[image].layout = pRenderPassInfo->pAttachments[i].initialLayout;
6313 } else if (pRenderPassInfo->pAttachments[i].initialLayout != image_data->second.layout) {
6314 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
6315 "You cannot start a render pass using attachment %i where the intial layout differs from the starting layout.", i);
Michael Lentineabc5e922015-10-12 11:30:14 -05006316 }
6317 }
6318 return skip_call;
6319}
6320
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006321void TransitionSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, const int subpass_index) {
6322 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07006323 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer, false);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006324 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
Michael Lentineabc5e922015-10-12 11:30:14 -05006325 if (render_pass_data == dev_data->renderPassMap.end()) {
6326 return;
6327 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006328 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
6329 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
Michael Lentineabc5e922015-10-12 11:30:14 -05006330 if (framebuffer_data == dev_data->frameBufferMap.end()) {
6331 return;
6332 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006333 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
6334 const VkSubpassDescription& subpass = pRenderPassInfo->pSubpasses[subpass_index];
Michael Lentineabc5e922015-10-12 11:30:14 -05006335 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006336 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pInputAttachments[j].attachment];
Michael Lentineabc5e922015-10-12 11:30:14 -05006337 auto image_view_data = dev_data->imageViewMap.find(image_view);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006338 if (image_view_data != dev_data->imageViewMap.end()) {
6339 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
Michael Lentineabc5e922015-10-12 11:30:14 -05006340 if (image_layout != pCB->imageLayoutMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006341 image_layout->second.layout = subpass.pInputAttachments[j].layout;
Michael Lentineabc5e922015-10-12 11:30:14 -05006342 }
6343 }
6344 }
6345 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006346 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pColorAttachments[j].attachment];
Michael Lentineabc5e922015-10-12 11:30:14 -05006347 auto image_view_data = dev_data->imageViewMap.find(image_view);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006348 if (image_view_data != dev_data->imageViewMap.end()) {
6349 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
Michael Lentineabc5e922015-10-12 11:30:14 -05006350 if (image_layout != pCB->imageLayoutMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006351 image_layout->second.layout = subpass.pColorAttachments[j].layout;
Michael Lentineabc5e922015-10-12 11:30:14 -05006352 }
6353 }
6354 }
Michael Lentine3dea6512015-10-28 15:55:18 -07006355 if ((subpass.pDepthStencilAttachment != NULL) &&
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06006356 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006357 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pDepthStencilAttachment->attachment];
Michael Lentineabc5e922015-10-12 11:30:14 -05006358 auto image_view_data = dev_data->imageViewMap.find(image_view);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006359 if (image_view_data != dev_data->imageViewMap.end()) {
6360 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
Michael Lentineabc5e922015-10-12 11:30:14 -05006361 if (image_layout != pCB->imageLayoutMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006362 image_layout->second.layout = subpass.pDepthStencilAttachment->layout;
Michael Lentineabc5e922015-10-12 11:30:14 -05006363 }
6364 }
6365 }
6366}
6367
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006368VkBool32 validatePrimaryCommandBuffer(const layer_data* my_data, const GLOBAL_CB_NODE* pCB, const std::string& cmd_name) {
Mark Youngb20a6a82016-01-07 15:41:43 -07006369 VkBool32 skip_call = VK_FALSE;
Michael Lentine3dea6512015-10-28 15:55:18 -07006370 if (pCB->createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006371 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER, "DS",
6372 "Cannot execute command %s on a secondary command buffer.", cmd_name.c_str());
Michael Lentine3dea6512015-10-28 15:55:18 -07006373 }
6374 return skip_call;
6375}
6376
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006377void TransitionFinalSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
6378 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07006379 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer, false);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006380 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
Michael Lentineabc5e922015-10-12 11:30:14 -05006381 if (render_pass_data == dev_data->renderPassMap.end()) {
6382 return;
6383 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006384 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
6385 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
Michael Lentineabc5e922015-10-12 11:30:14 -05006386 if (framebuffer_data == dev_data->frameBufferMap.end()) {
6387 return;
6388 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006389 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
Michael Lentineabc5e922015-10-12 11:30:14 -05006390 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006391 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
Michael Lentineabc5e922015-10-12 11:30:14 -05006392 auto image_view_data = dev_data->imageViewMap.find(image_view);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006393 if (image_view_data != dev_data->imageViewMap.end()) {
6394 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
Michael Lentineabc5e922015-10-12 11:30:14 -05006395 if (image_layout != pCB->imageLayoutMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006396 image_layout->second.layout = pRenderPassInfo->pAttachments[i].finalLayout;
Michael Lentineabc5e922015-10-12 11:30:14 -05006397 }
6398 }
6399 }
6400}
6401
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006402VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, VkSubpassContents contents)
6403{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006404 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006405 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07006406 loader_platform_thread_lock_mutex(&globalLock);
6407 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006408 if (pCB) {
Tobin Ehlis259730a2015-06-23 16:13:03 -06006409 if (pRenderPassBegin && pRenderPassBegin->renderPass) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006410 skipCall |= VerifyFramebufferAndRenderPassLayouts(commandBuffer, pRenderPassBegin);
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06006411 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBeginRenderPass");
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006412 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdBeginRenderPass");
6413 skipCall |= addCmd(dev_data, pCB, CMD_BEGINRENDERPASS, "vkCmdBeginRenderPass()");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06006414 pCB->activeRenderPass = pRenderPassBegin->renderPass;
Michael Lentineabc5e922015-10-12 11:30:14 -05006415 // This is a shallow copy as that is all that is needed for now
6416 pCB->activeRenderPassBeginInfo = *pRenderPassBegin;
Mark Lobodzinski5495d132015-09-30 16:19:16 -06006417 pCB->activeSubpass = 0;
Michael Lentine2e068b22015-12-29 16:05:27 -06006418 pCB->activeSubpassContents = contents;
Mark Lobodzinski5495d132015-09-30 16:19:16 -06006419 pCB->framebuffer = pRenderPassBegin->framebuffer;
Tobin Ehlis502480b2015-06-24 15:53:07 -06006420 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006421 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
6422 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tony Barbourbadda992015-04-06 11:09:26 -06006423 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006424 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07006425 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06006426 if (VK_FALSE == skipCall) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006427 dev_data->device_dispatch_table->CmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents);
Ian Elliott8c8b2662016-01-30 10:57:03 -07006428 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06006429 // This is a shallow copy as that is all that is needed for now
6430 dev_data->renderPassBeginInfo = *pRenderPassBegin;
6431 dev_data->currentSubpass = 0;
Ian Elliott8c8b2662016-01-30 10:57:03 -07006432 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06006433 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006434}
6435
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006436VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents)
6437{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006438 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006439 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07006440 loader_platform_thread_lock_mutex(&globalLock);
6441 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006442 TransitionSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo, ++dev_data->currentSubpass);
Chia-I Wu08accc62015-07-07 11:50:03 +08006443 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006444 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdNextSubpass");
6445 skipCall |= addCmd(dev_data, pCB, CMD_NEXTSUBPASS, "vkCmdNextSubpass()");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06006446 pCB->activeSubpass++;
Michael Lentine2e068b22015-12-29 16:05:27 -06006447 pCB->activeSubpassContents = contents;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006448 TransitionSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo, pCB->activeSubpass);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06006449 if (pCB->lastBoundPipeline) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006450 skipCall |= validatePipelineState(dev_data, pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Chia-I Wu08accc62015-07-07 11:50:03 +08006451 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06006452 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdNextSubpass");
Chia-I Wu08accc62015-07-07 11:50:03 +08006453 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07006454 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006455 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006456 dev_data->device_dispatch_table->CmdNextSubpass(commandBuffer, contents);
Chia-I Wu08accc62015-07-07 11:50:03 +08006457}
6458
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006459VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndRenderPass(VkCommandBuffer commandBuffer)
6460{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006461 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006462 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07006463 loader_platform_thread_lock_mutex(&globalLock);
6464 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006465 TransitionFinalSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006466 if (pCB) {
Michael Lentine3dea6512015-10-28 15:55:18 -07006467 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdEndRenderpass");
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006468 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdEndRenderPass");
6469 skipCall |= addCmd(dev_data, pCB, CMD_ENDRENDERPASS, "vkCmdEndRenderPass()");
6470 TransitionFinalSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06006471 pCB->activeRenderPass = 0;
6472 pCB->activeSubpass = 0;
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08006473 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07006474 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006475 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006476 dev_data->device_dispatch_table->CmdEndRenderPass(commandBuffer);
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08006477}
6478
Michael Lentine3124af62016-02-02 14:26:02 -06006479bool logInvalidAttachmentMessage(layer_data* dev_data, VkCommandBuffer secondaryBuffer, VkRenderPass secondaryPass, VkRenderPass primaryPass, uint32_t primaryAttach, uint32_t secondaryAttach, const char* msg) {
6480 return log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_SECONDARY_COMMAND_BUFFER, "DS",
6481 "vkCmdExecuteCommands() called w/ invalid Cmd Buffer %p which has a render pass %" PRIx64 " that is not compatible with the current render pass %" PRIx64 "."
6482 "Attachment %" PRIu32 " is not compatable with %" PRIu32 ". %s",
Dustin Graves962b01e2016-02-04 11:38:48 -07006483 (void*)secondaryBuffer, (uint64_t)(secondaryPass), (uint64_t)(primaryPass), primaryAttach, secondaryAttach, msg);
Michael Lentine3124af62016-02-02 14:26:02 -06006484}
6485
6486bool validateAttachmentCompatibility(layer_data* dev_data, VkCommandBuffer primaryBuffer, VkRenderPass primaryPass, uint32_t primaryAttach, VkCommandBuffer secondaryBuffer, VkRenderPass secondaryPass, uint32_t secondaryAttach, bool is_multi) {
6487 bool skip_call = false;
6488 auto primary_data = dev_data->renderPassMap.find(primaryPass);
6489 auto secondary_data = dev_data->renderPassMap.find(secondaryPass);
6490 if (primary_data->second->pCreateInfo->attachmentCount <= primaryAttach) {
6491 primaryAttach = VK_ATTACHMENT_UNUSED;
6492 }
6493 if (secondary_data->second->pCreateInfo->attachmentCount <= secondaryAttach) {
6494 secondaryAttach = VK_ATTACHMENT_UNUSED;
6495 }
6496 if (primaryAttach == VK_ATTACHMENT_UNUSED && secondaryAttach == VK_ATTACHMENT_UNUSED) {
6497 return skip_call;
6498 }
6499 if (primaryAttach == VK_ATTACHMENT_UNUSED) {
6500 skip_call |= logInvalidAttachmentMessage(dev_data, secondaryBuffer, secondaryPass, primaryPass, primaryAttach, secondaryAttach, "The first is unused while the second is not.");
6501 return skip_call;
6502 }
6503 if (secondaryAttach == VK_ATTACHMENT_UNUSED) {
6504 skip_call |= logInvalidAttachmentMessage(dev_data, secondaryBuffer, secondaryPass, primaryPass, primaryAttach, secondaryAttach, "The second is unused while the first is not.");
6505 return skip_call;
6506 }
6507 if (primary_data->second->pCreateInfo->pAttachments[primaryAttach].format != secondary_data->second->pCreateInfo->pAttachments[secondaryAttach].format) {
6508 skip_call |= logInvalidAttachmentMessage(dev_data, secondaryBuffer, secondaryPass, primaryPass, primaryAttach, secondaryAttach, "They have different formats.");
6509 }
6510 if (primary_data->second->pCreateInfo->pAttachments[primaryAttach].samples != secondary_data->second->pCreateInfo->pAttachments[secondaryAttach].samples) {
6511 skip_call |= logInvalidAttachmentMessage(dev_data, secondaryBuffer, secondaryPass, primaryPass, primaryAttach, secondaryAttach, "They have different samples.");
6512 }
6513 if (is_multi && primary_data->second->pCreateInfo->pAttachments[primaryAttach].flags != secondary_data->second->pCreateInfo->pAttachments[secondaryAttach].flags) {
6514 skip_call |= logInvalidAttachmentMessage(dev_data, secondaryBuffer, secondaryPass, primaryPass, primaryAttach, secondaryAttach, "They have different flags.");
6515 }
6516 return skip_call;
6517}
6518
6519bool validateSubpassCompatibility(layer_data* dev_data, VkCommandBuffer primaryBuffer, VkRenderPass primaryPass, VkCommandBuffer secondaryBuffer, VkRenderPass secondaryPass, const int subpass, bool is_multi) {
6520 bool skip_call = false;
6521 auto primary_data = dev_data->renderPassMap.find(primaryPass);
6522 auto secondary_data = dev_data->renderPassMap.find(secondaryPass);
6523 const VkSubpassDescription& primary_desc = primary_data->second->pCreateInfo->pSubpasses[subpass];
6524 const VkSubpassDescription& secondary_desc = secondary_data->second->pCreateInfo->pSubpasses[subpass];
6525 uint32_t maxInputAttachmentCount = std::max(primary_desc.inputAttachmentCount, secondary_desc.inputAttachmentCount);
6526 for (uint32_t i = 0; i < maxInputAttachmentCount; ++i) {
6527 uint32_t primary_input_attach = VK_ATTACHMENT_UNUSED, secondary_input_attach = VK_ATTACHMENT_UNUSED;
6528 if (i < primary_desc.inputAttachmentCount) {
6529 primary_input_attach = primary_desc.pInputAttachments[i].attachment;
6530 }
6531 if (i < secondary_desc.inputAttachmentCount) {
6532 secondary_input_attach = secondary_desc.pInputAttachments[i].attachment;
6533 }
6534 skip_call |= validateAttachmentCompatibility(dev_data, primaryBuffer, primaryPass, primary_input_attach, secondaryBuffer, secondaryPass, secondary_input_attach, is_multi);
6535 }
6536 maxInputAttachmentCount = std::max(primary_desc.colorAttachmentCount, secondary_desc.colorAttachmentCount);
6537 for (uint32_t i = 0; i < maxInputAttachmentCount; ++i) {
6538 uint32_t primary_color_attach = VK_ATTACHMENT_UNUSED, secondary_color_attach = VK_ATTACHMENT_UNUSED;
6539 if (i < primary_desc.colorAttachmentCount) {
6540 primary_color_attach = primary_desc.pColorAttachments[i].attachment;
6541 }
6542 if (i < secondary_desc.inputAttachmentCount) {
6543 secondary_color_attach = secondary_desc.pColorAttachments[i].attachment;
6544 }
6545 skip_call |= validateAttachmentCompatibility(dev_data, primaryBuffer, primaryPass, primary_color_attach, secondaryBuffer, secondaryPass, secondary_color_attach, is_multi);
6546 uint32_t primary_resolve_attach = VK_ATTACHMENT_UNUSED, secondary_resolve_attach = VK_ATTACHMENT_UNUSED;
6547 if (i < primary_desc.colorAttachmentCount && primary_desc.pResolveAttachments) {
6548 primary_resolve_attach = primary_desc.pResolveAttachments[i].attachment;
6549 }
6550 if (i < secondary_desc.inputAttachmentCount && secondary_desc.pResolveAttachments) {
6551 secondary_resolve_attach = secondary_desc.pResolveAttachments[i].attachment;
6552 }
6553 skip_call |= validateAttachmentCompatibility(dev_data, primaryBuffer, primaryPass, primary_resolve_attach, secondaryBuffer, secondaryPass, secondary_resolve_attach, is_multi);
6554 }
6555 uint32_t primary_depthstencil_attach = VK_ATTACHMENT_UNUSED, secondary_depthstencil_attach = VK_ATTACHMENT_UNUSED;
6556 if (primary_desc.pDepthStencilAttachment) {
6557 primary_depthstencil_attach = primary_desc.pDepthStencilAttachment[0].attachment;
6558 }
6559 if (secondary_desc.pDepthStencilAttachment) {
6560 secondary_depthstencil_attach = secondary_desc.pDepthStencilAttachment[0].attachment;
6561 }
6562 skip_call |= validateAttachmentCompatibility(dev_data, primaryBuffer, primaryPass, primary_depthstencil_attach, secondaryBuffer, secondaryPass, secondary_depthstencil_attach, is_multi);
6563 return skip_call;
6564}
6565
6566bool validateRenderPassCompatibility(layer_data* dev_data, VkCommandBuffer primaryBuffer, VkRenderPass primaryPass, VkCommandBuffer secondaryBuffer, VkRenderPass secondaryPass) {
6567 bool skip_call = false;
6568 auto primary_data = dev_data->renderPassMap.find(primaryPass);
6569 auto secondary_data = dev_data->renderPassMap.find(secondaryPass);
6570 if (primary_data == dev_data->renderPassMap.end() || primary_data->second == nullptr) {
6571 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_SECONDARY_COMMAND_BUFFER, "DS",
6572 "vkCmdExecuteCommands() called w/ invalid current Cmd Buffer %p which has invalid render pass %" PRIx64 ".",
Dustin Graves962b01e2016-02-04 11:38:48 -07006573 (void*)primaryBuffer, (uint64_t)(primaryPass));
Michael Lentine3124af62016-02-02 14:26:02 -06006574 return skip_call;
6575 }
6576 if (secondary_data == dev_data->renderPassMap.end() || secondary_data->second == nullptr) {
6577 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_SECONDARY_COMMAND_BUFFER, "DS",
6578 "vkCmdExecuteCommands() called w/ invalid secondary Cmd Buffer %p which has invalid render pass %" PRIx64 ".",
Dustin Graves962b01e2016-02-04 11:38:48 -07006579 (void*)secondaryBuffer, (uint64_t)(secondaryPass));
Michael Lentine3124af62016-02-02 14:26:02 -06006580 return skip_call;
6581 }
6582 if (primary_data->second->pCreateInfo->subpassCount != secondary_data->second->pCreateInfo->subpassCount) {
6583 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_SECONDARY_COMMAND_BUFFER, "DS",
6584 "vkCmdExecuteCommands() called w/ invalid Cmd Buffer %p which has a render pass %" PRIx64 " that is not compatible with the current render pass %" PRIx64 "."
6585 "They have a different number of subpasses.",
Dustin Graves962b01e2016-02-04 11:38:48 -07006586 (void*)secondaryBuffer, (uint64_t)(secondaryPass), (uint64_t)(primaryPass));
Michael Lentine3124af62016-02-02 14:26:02 -06006587 return skip_call;
6588 }
6589 bool is_multi = primary_data->second->pCreateInfo->subpassCount > 1;
6590 for (uint32_t i = 0; i < primary_data->second->pCreateInfo->subpassCount; ++i) {
6591 skip_call |= validateSubpassCompatibility(dev_data, primaryBuffer, primaryPass, secondaryBuffer, secondaryPass, i, is_multi);
6592 }
6593 return skip_call;
6594}
6595
Michael Lentinef6592ef2016-02-02 15:24:27 -06006596bool validateFramebuffer(layer_data* dev_data, VkCommandBuffer primaryBuffer, const GLOBAL_CB_NODE* pCB, VkCommandBuffer secondaryBuffer, const GLOBAL_CB_NODE* pSubCB) {
6597 bool skip_call = false;
6598 if (!pSubCB->beginInfo.pInheritanceInfo) {
6599 return skip_call;
6600 }
6601 VkFramebuffer primary_fb = pCB->framebuffer;
6602 VkFramebuffer secondary_fb = pSubCB->beginInfo.pInheritanceInfo->framebuffer;
Michael Lentine3009b622016-02-02 16:47:58 -06006603 if (secondary_fb != VK_NULL_HANDLE) {
6604 if (primary_fb != secondary_fb) {
6605 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_SECONDARY_COMMAND_BUFFER, "DS",
6606 "vkCmdExecuteCommands() called w/ invalid Cmd Buffer %p which has a framebuffer %" PRIx64 " that is not compatible with the current framebuffer %" PRIx64 ".",
Dustin Graves962b01e2016-02-04 11:38:48 -07006607 (void*)secondaryBuffer, (uint64_t)(secondary_fb), (uint64_t)(primary_fb));
Michael Lentine3009b622016-02-02 16:47:58 -06006608 }
6609 auto fb_data = dev_data->frameBufferMap.find(secondary_fb);
6610 if (fb_data == dev_data->frameBufferMap.end() || !fb_data->second) {
6611 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_SECONDARY_COMMAND_BUFFER, "DS",
6612 "vkCmdExecuteCommands() called w/ invalid Cmd Buffer %p which has invalid framebuffer %" PRIx64 ".",
Dustin Graves962b01e2016-02-04 11:38:48 -07006613 (void*)secondaryBuffer, (uint64_t)(secondary_fb));
Michael Lentine3009b622016-02-02 16:47:58 -06006614 return skip_call;
6615 }
6616 skip_call |= validateRenderPassCompatibility(dev_data, secondaryBuffer, fb_data->second->renderPass, secondaryBuffer, pSubCB->beginInfo.pInheritanceInfo->renderPass);
Michael Lentinef6592ef2016-02-02 15:24:27 -06006617 }
6618 return skip_call;
6619}
6620
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006621VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount, const VkCommandBuffer* pCommandBuffers)
6622{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006623 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006624 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07006625 loader_platform_thread_lock_mutex(&globalLock);
6626 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08006627 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006628 GLOBAL_CB_NODE* pSubCB = NULL;
6629 for (uint32_t i=0; i<commandBuffersCount; i++) {
Ian Elliott8c8b2662016-01-30 10:57:03 -07006630 pSubCB = getCBNode(dev_data, pCommandBuffers[i], false);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06006631 if (!pSubCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006632 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_SECONDARY_COMMAND_BUFFER, "DS",
6633 "vkCmdExecuteCommands() called w/ invalid Cmd Buffer %p in element %u of pCommandBuffers array.", (void*)pCommandBuffers[i], i);
6634 } else if (VK_COMMAND_BUFFER_LEVEL_PRIMARY == pSubCB->createInfo.level) {
6635 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_SECONDARY_COMMAND_BUFFER, "DS",
6636 "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);
6637 } else if (pCB->activeRenderPass) { // Secondary CB w/i RenderPass must have *CONTINUE_BIT set
6638 if (!(pSubCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT)) {
6639 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",
6640 "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);
Michael Lentine3124af62016-02-02 14:26:02 -06006641 } else {
6642 // Make sure render pass is compatible with parent command buffer pass if has continue
6643 skipCall |= validateRenderPassCompatibility(dev_data, commandBuffer, pCB->activeRenderPass, pCommandBuffers[i], pSubCB->beginInfo.pInheritanceInfo->renderPass);
Michael Lentinef6592ef2016-02-02 15:24:27 -06006644 skipCall |= validateFramebuffer(dev_data, commandBuffer, pCB, pCommandBuffers[i], pSubCB);
Tobin Ehlis651d9b02015-12-16 05:01:22 -07006645 }
6646 string errorString = "";
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006647 if (!verify_renderpass_compatibility(dev_data, pCB->activeRenderPass, pSubCB->beginInfo.pInheritanceInfo->renderPass, errorString)) {
6648 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",
6649 "vkCmdExecuteCommands(): Secondary Command Buffer (%p) w/ render pass (%#" PRIxLEAST64 ") is incompatible w/ primary command buffer (%p) w/ render pass (%#" PRIxLEAST64 ") due to: %s",
6650 (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 -07006651 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006652 // If framebuffer for secondary CB is not NULL, then it must match FB from vkCmdBeginRenderPass()
6653 // 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 -07006654 if (pSubCB->beginInfo.pInheritanceInfo->framebuffer) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006655 if (pSubCB->beginInfo.pInheritanceInfo->framebuffer != pCB->activeRenderPassBeginInfo.framebuffer) {
6656 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",
6657 "vkCmdExecuteCommands(): Secondary Command Buffer (%p) references framebuffer (%#" PRIxLEAST64 ") that does not match framebuffer (%#" PRIxLEAST64 ") in active renderpass (%#" PRIxLEAST64 ").",
6658 (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 -07006659 }
6660 }
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06006661 }
Michael Lentine0998ede2016-02-03 14:26:30 -06006662 validateCommandBufferState(dev_data, pSubCB);
6663 // Secondary cmdBuffers are considered pending execution starting w/
6664 // being recorded
6665 if (!(pSubCB->beginInfo.flags &
6666 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT)) {
6667 if (dev_data->globalInFlightCmdBuffers.find(
6668 pSubCB->commandBuffer) !=
6669 dev_data->globalInFlightCmdBuffers.end()) {
6670 skipCall |= log_msg(
6671 dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
6672 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
6673 (uint64_t)(pCB->commandBuffer), __LINE__,
6674 DRAWSTATE_INVALID_CB_SIMULTANEOUS_USE, "DS",
6675 "Attempt to simultaneously execute CB %#" PRIxLEAST64
6676 " w/o VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT "
6677 "set!",
6678 (uint64_t)(pCB->commandBuffer));
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07006679 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006680 if (pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT) {
6681 // Warn that non-simultaneous secondary cmd buffer renders primary non-simultaneous
6682 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)(pCommandBuffers[i]), __LINE__, DRAWSTATE_INVALID_CB_SIMULTANEOUS_USE, "DS",
6683 "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.",
6684 (uint64_t)(pCommandBuffers[i]), (uint64_t)(pCB->commandBuffer));
6685 pCB->beginInfo.flags &= ~VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07006686 }
6687 }
Michael Lentined7621bb2016-02-03 10:55:23 -06006688 pSubCB->primaryCommandBuffer = pCB->commandBuffer;
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07006689 pCB->secondaryCommandBuffers.insert(pSubCB->commandBuffer);
Tobin Ehlis74714d22016-01-25 15:24:34 -08006690 dev_data->globalInFlightCmdBuffers.insert(pSubCB->commandBuffer);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06006691 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006692 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdExecuteComands");
6693 skipCall |= addCmd(dev_data, pCB, CMD_EXECUTECOMMANDS, "vkCmdExecuteComands()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006694 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07006695 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006696 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006697 dev_data->device_dispatch_table->CmdExecuteCommands(commandBuffer, commandBuffersCount, pCommandBuffers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006698}
6699
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07006700VkBool32 ValidateMapImageLayouts(VkDevice device, VkDeviceMemory mem) {
Mark Youngb20a6a82016-01-07 15:41:43 -07006701 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006702 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentine7b236262015-10-23 12:41:44 -07006703 auto mem_data = dev_data->memImageMap.find(mem);
6704 if (mem_data != dev_data->memImageMap.end()) {
6705 auto image_data = dev_data->imageLayoutMap.find(mem_data->second);
6706 if (image_data != dev_data->imageLayoutMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006707 if (image_data->second->layout != VK_IMAGE_LAYOUT_PREINITIALIZED && image_data->second->layout != VK_IMAGE_LAYOUT_GENERAL) {
6708 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
6709 "Cannot map an image with layout %d. Only GENERAL or PREINITIALIZED are supported.", image_data->second->layout);
Michael Lentine7b236262015-10-23 12:41:44 -07006710 }
6711 }
6712 }
6713 return skip_call;
6714}
6715
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006716VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkMapMemory(
6717 VkDevice device,
6718 VkDeviceMemory mem,
6719 VkDeviceSize offset,
6720 VkDeviceSize size,
6721 VkFlags flags,
6722 void **ppData)
6723{
6724 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006725
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07006726 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006727#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
Ian Elliott8c8b2662016-01-30 10:57:03 -07006728 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006729 skip_call = ValidateMapImageLayouts(device, mem);
Ian Elliott8c8b2662016-01-30 10:57:03 -07006730 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006731#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
6732
Michael Lentine7b236262015-10-23 12:41:44 -07006733 if (VK_FALSE == skip_call) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006734 return dev_data->device_dispatch_table->MapMemory(device, mem, offset, size, flags, ppData);
Michael Lentine7b236262015-10-23 12:41:44 -07006735 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07006736 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine7b236262015-10-23 12:41:44 -07006737}
6738
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006739VKAPI_ATTR VkResult VKAPI_CALL vkBindImageMemory(
6740 VkDevice device,
6741 VkImage image,
6742 VkDeviceMemory mem,
6743 VkDeviceSize memOffset)
6744{
6745 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6746 VkResult result = dev_data->device_dispatch_table->BindImageMemory(device, image, mem, memOffset);
Michael Lentine7b236262015-10-23 12:41:44 -07006747 loader_platform_thread_lock_mutex(&globalLock);
6748 dev_data->memImageMap[mem] = image;
6749 loader_platform_thread_unlock_mutex(&globalLock);
6750 return result;
6751}
6752
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006753
Michael Lentineb887b0a2015-12-29 14:12:11 -06006754VKAPI_ATTR VkResult VKAPI_CALL vkSetEvent(VkDevice device, VkEvent event) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006755 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07006756 loader_platform_thread_lock_mutex(&globalLock);
Michael Lentineb887b0a2015-12-29 14:12:11 -06006757 dev_data->eventMap[event].needsSignaled = false;
Ian Elliott8c8b2662016-01-30 10:57:03 -07006758 loader_platform_thread_unlock_mutex(&globalLock);
Michael Lentineb887b0a2015-12-29 14:12:11 -06006759 VkResult result = dev_data->device_dispatch_table->SetEvent(device, event);
6760 return result;
6761}
6762
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006763VKAPI_ATTR VkResult VKAPI_CALL vkQueueBindSparse(
6764 VkQueue queue,
6765 uint32_t bindInfoCount,
6766 const VkBindSparseInfo* pBindInfo,
6767 VkFence fence)
6768{
6769 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07006770 VkBool32 skip_call = VK_FALSE;
Michael Lentine15a47882016-01-06 10:05:48 -06006771
Ian Elliott8c8b2662016-01-30 10:57:03 -07006772 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006773 for (uint32_t bindIdx=0; bindIdx < bindInfoCount; ++bindIdx) {
6774 const VkBindSparseInfo& bindInfo = pBindInfo[bindIdx];
6775 for (uint32_t i=0; i < bindInfo.waitSemaphoreCount; ++i) {
Michael Lentine15a47882016-01-06 10:05:48 -06006776 if (dev_data->semaphoreSignaledMap[bindInfo.pWaitSemaphores[i]]) {
6777 dev_data->semaphoreSignaledMap[bindInfo.pWaitSemaphores[i]] = 0;
6778 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006779 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",
6780 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
6781 (uint64_t)(queue), (uint64_t)(bindInfo.pWaitSemaphores[i]));
Michael Lentine15a47882016-01-06 10:05:48 -06006782 }
6783 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006784 for (uint32_t i=0; i < bindInfo.signalSemaphoreCount; ++i) {
Michael Lentine15a47882016-01-06 10:05:48 -06006785 dev_data->semaphoreSignaledMap[bindInfo.pSignalSemaphores[i]] = 1;
6786 }
6787 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07006788 loader_platform_thread_unlock_mutex(&globalLock);
Michael Lentine15a47882016-01-06 10:05:48 -06006789
Mark Youngb20a6a82016-01-07 15:41:43 -07006790 if (VK_FALSE == skip_call)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006791 return dev_data->device_dispatch_table->QueueBindSparse(queue, bindInfoCount, pBindInfo, fence);
Mark Youngb20a6a82016-01-07 15:41:43 -07006792 else
6793 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine15a47882016-01-06 10:05:48 -06006794}
6795
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006796VKAPI_ATTR VkResult VKAPI_CALL vkCreateSemaphore(
6797 VkDevice device,
6798 const VkSemaphoreCreateInfo* pCreateInfo,
6799 const VkAllocationCallbacks* pAllocator,
6800 VkSemaphore* pSemaphore)
6801{
6802 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6803 VkResult result = dev_data->device_dispatch_table->CreateSemaphore(device, pCreateInfo, pAllocator, pSemaphore);
Michael Lentine15a47882016-01-06 10:05:48 -06006804 if (result == VK_SUCCESS) {
Ian Elliott8c8b2662016-01-30 10:57:03 -07006805 loader_platform_thread_lock_mutex(&globalLock);
Michael Lentine15a47882016-01-06 10:05:48 -06006806 dev_data->semaphoreSignaledMap[*pSemaphore] = 0;
Ian Elliott8c8b2662016-01-30 10:57:03 -07006807 loader_platform_thread_unlock_mutex(&globalLock);
Michael Lentine15a47882016-01-06 10:05:48 -06006808 }
Tobin Ehlis51b78af2016-01-06 10:27:47 -07006809 return result;
Michael Lentine15a47882016-01-06 10:05:48 -06006810}
6811
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006812VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(
6813 VkDevice device,
6814 const VkSwapchainCreateInfoKHR *pCreateInfo,
6815 const VkAllocationCallbacks *pAllocator,
6816 VkSwapchainKHR *pSwapchain)
6817{
6818 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6819 VkResult result = dev_data->device_dispatch_table->CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
Michael Lentineabc5e922015-10-12 11:30:14 -05006820
6821 if (VK_SUCCESS == result) {
Tobin Ehlis75cd1c52016-01-21 10:21:04 -07006822 SWAPCHAIN_NODE *swapchain_data = new SWAPCHAIN_NODE(pCreateInfo);
Michael Lentineabc5e922015-10-12 11:30:14 -05006823 loader_platform_thread_lock_mutex(&globalLock);
6824 dev_data->device_extensions.swapchainMap[*pSwapchain] = swapchain_data;
6825 loader_platform_thread_unlock_mutex(&globalLock);
6826 }
6827
6828 return result;
6829}
6830
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006831VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR(
6832 VkDevice device,
6833 VkSwapchainKHR swapchain,
6834 const VkAllocationCallbacks *pAllocator)
6835{
6836 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentineabc5e922015-10-12 11:30:14 -05006837
6838 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006839 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(swapchain);
Michael Lentineabc5e922015-10-12 11:30:14 -05006840 if (swapchain_data != dev_data->device_extensions.swapchainMap.end()) {
6841 if (swapchain_data->second->images.size() > 0) {
6842 for (auto swapchain_image : swapchain_data->second->images) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006843 auto image_item = dev_data->imageLayoutMap.find(swapchain_image);
Michael Lentineabc5e922015-10-12 11:30:14 -05006844 if (image_item != dev_data->imageLayoutMap.end())
6845 dev_data->imageLayoutMap.erase(image_item);
6846 }
6847 }
6848 delete swapchain_data->second;
6849 dev_data->device_extensions.swapchainMap.erase(swapchain);
6850 }
6851 loader_platform_thread_unlock_mutex(&globalLock);
Ian Elliott8c8b2662016-01-30 10:57:03 -07006852 dev_data->device_dispatch_table->DestroySwapchainKHR(device, swapchain, pAllocator);
Michael Lentineabc5e922015-10-12 11:30:14 -05006853}
6854
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006855VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR(
6856 VkDevice device,
6857 VkSwapchainKHR swapchain,
6858 uint32_t* pCount,
6859 VkImage* pSwapchainImages)
6860{
6861 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6862 VkResult result = dev_data->device_dispatch_table->GetSwapchainImagesKHR(device, swapchain, pCount, pSwapchainImages);
Michael Lentineabc5e922015-10-12 11:30:14 -05006863
6864 if (result == VK_SUCCESS && pSwapchainImages != NULL) {
6865 // This should never happen and is checked by param checker.
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006866 if (!pCount) return result;
Ian Elliott8c8b2662016-01-30 10:57:03 -07006867 loader_platform_thread_lock_mutex(&globalLock);
Michael Lentineabc5e922015-10-12 11:30:14 -05006868 for (uint32_t i = 0; i < *pCount; ++i) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006869 IMAGE_NODE* image_node = new IMAGE_NODE;
Michael Lentineabc5e922015-10-12 11:30:14 -05006870 image_node->layout = VK_IMAGE_LAYOUT_UNDEFINED;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006871 auto swapchain_node = dev_data->device_extensions.swapchainMap[swapchain];
Tobin Ehlis75cd1c52016-01-21 10:21:04 -07006872 image_node->format = swapchain_node->createInfo.imageFormat;
6873 swapchain_node->images.push_back(pSwapchainImages[i]);
Michael Lentineabc5e922015-10-12 11:30:14 -05006874 dev_data->imageLayoutMap[pSwapchainImages[i]] = image_node;
Michael Lentineabc5e922015-10-12 11:30:14 -05006875 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07006876 loader_platform_thread_unlock_mutex(&globalLock);
Michael Lentineabc5e922015-10-12 11:30:14 -05006877 }
6878 return result;
6879}
6880
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006881VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo)
6882{
6883 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07006884 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05006885
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006886#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentineabc5e922015-10-12 11:30:14 -05006887 if (pPresentInfo) {
Ian Elliott8c8b2662016-01-30 10:57:03 -07006888 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006889 for (uint32_t i=0; i < pPresentInfo->waitSemaphoreCount; ++i) {
6890 if (dev_data->semaphoreSignaledMap[pPresentInfo->pWaitSemaphores[i]]) {
6891 dev_data->semaphoreSignaledMap[pPresentInfo->pWaitSemaphores[i]] = 0;
Michael Lentine15a47882016-01-06 10:05:48 -06006892 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006893 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",
6894 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
6895 (uint64_t)(queue), (uint64_t)(pPresentInfo->pWaitSemaphores[i]));
Michael Lentine15a47882016-01-06 10:05:48 -06006896 }
6897 }
Michael Lentineabc5e922015-10-12 11:30:14 -05006898 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006899 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(pPresentInfo->pSwapchains[i]);
6900 if (swapchain_data != dev_data->device_extensions.swapchainMap.end() && pPresentInfo->pImageIndices[i] < swapchain_data->second->images.size()) {
6901 VkImage image = swapchain_data->second->images[pPresentInfo->pImageIndices[i]];
Michael Lentineabc5e922015-10-12 11:30:14 -05006902 auto image_data = dev_data->imageLayoutMap.find(image);
6903 if (image_data != dev_data->imageLayoutMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006904 if (image_data->second->layout != VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) {
6905 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",
6906 "Images passed to present must be in layout PRESENT_SOURCE_KHR but is in %d", image_data->second->layout);
Michael Lentineabc5e922015-10-12 11:30:14 -05006907 }
6908 }
6909 }
6910 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07006911 loader_platform_thread_unlock_mutex(&globalLock);
Michael Lentineabc5e922015-10-12 11:30:14 -05006912 }
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006913#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentineabc5e922015-10-12 11:30:14 -05006914
6915 if (VK_FALSE == skip_call)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006916 return dev_data->device_dispatch_table->QueuePresentKHR(queue, pPresentInfo);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07006917 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentineabc5e922015-10-12 11:30:14 -05006918}
6919
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006920VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImageKHR(
6921 VkDevice device,
6922 VkSwapchainKHR swapchain,
6923 uint64_t timeout,
6924 VkSemaphore semaphore,
6925 VkFence fence,
6926 uint32_t* pImageIndex)
6927{
6928 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07006929 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006930 VkResult result = dev_data->device_dispatch_table->AcquireNextImageKHR(device, swapchain, timeout, semaphore, fence, pImageIndex);
Michael Lentine15a47882016-01-06 10:05:48 -06006931 dev_data->semaphoreSignaledMap[semaphore] = 1;
Ian Elliott8c8b2662016-01-30 10:57:03 -07006932 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis51b78af2016-01-06 10:27:47 -07006933 return result;
Michael Lentine15a47882016-01-06 10:05:48 -06006934}
6935
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006936VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006937 VkInstance instance,
6938 const VkDebugReportCallbackCreateInfoEXT* pCreateInfo,
6939 const VkAllocationCallbacks* pAllocator,
6940 VkDebugReportCallbackEXT* pMsgCallback)
6941{
6942 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006943 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006944 VkResult res = pTable->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06006945 if (VK_SUCCESS == res) {
Ian Elliott8c8b2662016-01-30 10:57:03 -07006946 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006947 res = layer_create_msg_callback(my_data->report_data, pCreateInfo, pAllocator, pMsgCallback);
Ian Elliott8c8b2662016-01-30 10:57:03 -07006948 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06006949 }
6950 return res;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006951}
6952
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006953VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(
6954 VkInstance instance,
6955 VkDebugReportCallbackEXT msgCallback,
6956 const VkAllocationCallbacks* pAllocator)
6957{
6958 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006959 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006960 pTable->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
Ian Elliott8c8b2662016-01-30 10:57:03 -07006961 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006962 layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator);
Ian Elliott8c8b2662016-01-30 10:57:03 -07006963 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006964}
6965
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006966VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDebugReportMessageEXT(
6967 VkInstance instance,
6968 VkDebugReportFlagsEXT flags,
6969 VkDebugReportObjectTypeEXT objType,
6970 uint64_t object,
6971 size_t location,
6972 int32_t msgCode,
6973 const char* pLayerPrefix,
6974 const char* pMsg)
6975{
6976 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
6977 my_data->instance_dispatch_table->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg);
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07006978}
6979
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006980VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerBegin(VkCommandBuffer commandBuffer, const char* pMarker)
6981{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006982 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006983 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07006984 loader_platform_thread_lock_mutex(&globalLock);
6985 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis0b632332015-10-07 09:38:40 -06006986 if (!dev_data->device_extensions.debug_marker_enabled) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006987 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",
6988 "Attempt to use CmdDbgMarkerBegin but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06006989 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06006990 } else if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006991 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKERBEGIN, "vkCmdDbgMarkerBegin()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006992 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07006993 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006994 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006995 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerBegin(commandBuffer, pMarker);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006996}
6997
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006998VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerEnd(VkCommandBuffer commandBuffer)
6999{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06007000 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007001 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07007002 loader_platform_thread_lock_mutex(&globalLock);
7003 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis0b632332015-10-07 09:38:40 -06007004 if (!dev_data->device_extensions.debug_marker_enabled) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007005 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",
7006 "Attempt to use CmdDbgMarkerEnd but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06007007 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06007008 } else if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007009 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKEREND, "vkCmdDbgMarkerEnd()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06007010 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07007011 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06007012 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007013 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerEnd(commandBuffer);
Jon Ashburneab34492015-06-01 09:37:38 -06007014}
7015
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007016VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
7017{
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07007018 if (!strcmp(funcName, "vkGetDeviceProcAddr"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007019 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007020 if (!strcmp(funcName, "vkDestroyDevice"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007021 return (PFN_vkVoidFunction) vkDestroyDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007022 if (!strcmp(funcName, "vkQueueSubmit"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007023 return (PFN_vkVoidFunction) vkQueueSubmit;
Michael Lentine700b0aa2015-10-30 17:57:32 -07007024 if (!strcmp(funcName, "vkWaitForFences"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007025 return (PFN_vkVoidFunction) vkWaitForFences;
Michael Lentine700b0aa2015-10-30 17:57:32 -07007026 if (!strcmp(funcName, "vkGetFenceStatus"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007027 return (PFN_vkVoidFunction) vkGetFenceStatus;
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07007028 if (!strcmp(funcName, "vkQueueWaitIdle"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007029 return (PFN_vkVoidFunction) vkQueueWaitIdle;
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07007030 if (!strcmp(funcName, "vkDeviceWaitIdle"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007031 return (PFN_vkVoidFunction) vkDeviceWaitIdle;
Michael Lentine700b0aa2015-10-30 17:57:32 -07007032 if (!strcmp(funcName, "vkGetDeviceQueue"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007033 return (PFN_vkVoidFunction) vkGetDeviceQueue;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06007034 if (!strcmp(funcName, "vkDestroyInstance"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007035 return (PFN_vkVoidFunction) vkDestroyInstance;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06007036 if (!strcmp(funcName, "vkDestroyDevice"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007037 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06007038 if (!strcmp(funcName, "vkDestroyFence"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007039 return (PFN_vkVoidFunction) vkDestroyFence;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06007040 if (!strcmp(funcName, "vkDestroySemaphore"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007041 return (PFN_vkVoidFunction) vkDestroySemaphore;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06007042 if (!strcmp(funcName, "vkDestroyEvent"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007043 return (PFN_vkVoidFunction) vkDestroyEvent;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06007044 if (!strcmp(funcName, "vkDestroyQueryPool"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007045 return (PFN_vkVoidFunction) vkDestroyQueryPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06007046 if (!strcmp(funcName, "vkDestroyBuffer"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007047 return (PFN_vkVoidFunction) vkDestroyBuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06007048 if (!strcmp(funcName, "vkDestroyBufferView"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007049 return (PFN_vkVoidFunction) vkDestroyBufferView;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06007050 if (!strcmp(funcName, "vkDestroyImage"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007051 return (PFN_vkVoidFunction) vkDestroyImage;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06007052 if (!strcmp(funcName, "vkDestroyImageView"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007053 return (PFN_vkVoidFunction) vkDestroyImageView;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06007054 if (!strcmp(funcName, "vkDestroyShaderModule"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007055 return (PFN_vkVoidFunction) vkDestroyShaderModule;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06007056 if (!strcmp(funcName, "vkDestroyPipeline"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007057 return (PFN_vkVoidFunction) vkDestroyPipeline;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06007058 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007059 return (PFN_vkVoidFunction) vkDestroyPipelineLayout;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06007060 if (!strcmp(funcName, "vkDestroySampler"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007061 return (PFN_vkVoidFunction) vkDestroySampler;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06007062 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007063 return (PFN_vkVoidFunction) vkDestroyDescriptorSetLayout;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06007064 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007065 return (PFN_vkVoidFunction) vkDestroyDescriptorPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06007066 if (!strcmp(funcName, "vkDestroyFramebuffer"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007067 return (PFN_vkVoidFunction) vkDestroyFramebuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06007068 if (!strcmp(funcName, "vkDestroyRenderPass"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007069 return (PFN_vkVoidFunction) vkDestroyRenderPass;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007070 if (!strcmp(funcName, "vkCreateBuffer"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007071 return (PFN_vkVoidFunction) vkCreateBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007072 if (!strcmp(funcName, "vkCreateBufferView"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007073 return (PFN_vkVoidFunction) vkCreateBufferView;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007074 if (!strcmp(funcName, "vkCreateImage"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007075 return (PFN_vkVoidFunction) vkCreateImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007076 if (!strcmp(funcName, "vkCreateImageView"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007077 return (PFN_vkVoidFunction) vkCreateImageView;
Michael Lentine37767342016-02-02 22:24:26 -06007078 if (!strcmp(funcName, "vkCreateFence"))
7079 return (PFN_vkVoidFunction) vkCreateFence;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007080 if (!strcmp(funcName, "CreatePipelineCache"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007081 return (PFN_vkVoidFunction) vkCreatePipelineCache;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007082 if (!strcmp(funcName, "DestroyPipelineCache"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007083 return (PFN_vkVoidFunction) vkDestroyPipelineCache;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007084 if (!strcmp(funcName, "GetPipelineCacheData"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007085 return (PFN_vkVoidFunction) vkGetPipelineCacheData;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007086 if (!strcmp(funcName, "MergePipelineCaches"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007087 return (PFN_vkVoidFunction) vkMergePipelineCaches;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007088 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007089 return (PFN_vkVoidFunction) vkCreateGraphicsPipelines;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07007090 if (!strcmp(funcName, "vkCreateComputePipelines"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007091 return (PFN_vkVoidFunction) vkCreateComputePipelines;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007092 if (!strcmp(funcName, "vkCreateSampler"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007093 return (PFN_vkVoidFunction) vkCreateSampler;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007094 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007095 return (PFN_vkVoidFunction) vkCreateDescriptorSetLayout;
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05007096 if (!strcmp(funcName, "vkCreatePipelineLayout"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007097 return (PFN_vkVoidFunction) vkCreatePipelineLayout;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007098 if (!strcmp(funcName, "vkCreateDescriptorPool"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007099 return (PFN_vkVoidFunction) vkCreateDescriptorPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007100 if (!strcmp(funcName, "vkResetDescriptorPool"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007101 return (PFN_vkVoidFunction) vkResetDescriptorPool;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007102 if (!strcmp(funcName, "vkAllocateDescriptorSets"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007103 return (PFN_vkVoidFunction) vkAllocateDescriptorSets;
Tobin Ehlise735c692015-10-08 13:13:50 -06007104 if (!strcmp(funcName, "vkFreeDescriptorSets"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007105 return (PFN_vkVoidFunction) vkFreeDescriptorSets;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007106 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007107 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
Mark Lobodzinski39298632015-11-18 08:38:27 -07007108 if (!strcmp(funcName, "vkCreateCommandPool"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007109 return (PFN_vkVoidFunction) vkCreateCommandPool;
Mark Lobodzinski39298632015-11-18 08:38:27 -07007110 if (!strcmp(funcName, "vkDestroyCommandPool"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007111 return (PFN_vkVoidFunction) vkDestroyCommandPool;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007112 if (!strcmp(funcName, "vkResetCommandPool"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007113 return (PFN_vkVoidFunction) vkResetCommandPool;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007114 if (!strcmp(funcName, "vkAllocateCommandBuffers"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007115 return (PFN_vkVoidFunction) vkAllocateCommandBuffers;
Mark Lobodzinski39298632015-11-18 08:38:27 -07007116 if (!strcmp(funcName, "vkFreeCommandBuffers"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007117 return (PFN_vkVoidFunction) vkFreeCommandBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007118 if (!strcmp(funcName, "vkBeginCommandBuffer"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007119 return (PFN_vkVoidFunction) vkBeginCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007120 if (!strcmp(funcName, "vkEndCommandBuffer"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007121 return (PFN_vkVoidFunction) vkEndCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007122 if (!strcmp(funcName, "vkResetCommandBuffer"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007123 return (PFN_vkVoidFunction) vkResetCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007124 if (!strcmp(funcName, "vkCmdBindPipeline"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007125 return (PFN_vkVoidFunction) vkCmdBindPipeline;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06007126 if (!strcmp(funcName, "vkCmdSetViewport"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007127 return (PFN_vkVoidFunction) vkCmdSetViewport;
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06007128 if (!strcmp(funcName, "vkCmdSetScissor"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007129 return (PFN_vkVoidFunction) vkCmdSetScissor;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06007130 if (!strcmp(funcName, "vkCmdSetLineWidth"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007131 return (PFN_vkVoidFunction) vkCmdSetLineWidth;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06007132 if (!strcmp(funcName, "vkCmdSetDepthBias"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007133 return (PFN_vkVoidFunction) vkCmdSetDepthBias;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06007134 if (!strcmp(funcName, "vkCmdSetBlendConstants"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007135 return (PFN_vkVoidFunction) vkCmdSetBlendConstants;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06007136 if (!strcmp(funcName, "vkCmdSetDepthBounds"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007137 return (PFN_vkVoidFunction) vkCmdSetDepthBounds;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06007138 if (!strcmp(funcName, "vkCmdSetStencilCompareMask"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007139 return (PFN_vkVoidFunction) vkCmdSetStencilCompareMask;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06007140 if (!strcmp(funcName, "vkCmdSetStencilWriteMask"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007141 return (PFN_vkVoidFunction) vkCmdSetStencilWriteMask;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06007142 if (!strcmp(funcName, "vkCmdSetStencilReference"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007143 return (PFN_vkVoidFunction) vkCmdSetStencilReference;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007144 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007145 return (PFN_vkVoidFunction) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06007146 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007147 return (PFN_vkVoidFunction) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007148 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007149 return (PFN_vkVoidFunction) vkCmdBindIndexBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007150 if (!strcmp(funcName, "vkCmdDraw"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007151 return (PFN_vkVoidFunction) vkCmdDraw;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007152 if (!strcmp(funcName, "vkCmdDrawIndexed"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007153 return (PFN_vkVoidFunction) vkCmdDrawIndexed;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007154 if (!strcmp(funcName, "vkCmdDrawIndirect"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007155 return (PFN_vkVoidFunction) vkCmdDrawIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007156 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007157 return (PFN_vkVoidFunction) vkCmdDrawIndexedIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007158 if (!strcmp(funcName, "vkCmdDispatch"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007159 return (PFN_vkVoidFunction) vkCmdDispatch;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007160 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007161 return (PFN_vkVoidFunction) vkCmdDispatchIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007162 if (!strcmp(funcName, "vkCmdCopyBuffer"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007163 return (PFN_vkVoidFunction) vkCmdCopyBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007164 if (!strcmp(funcName, "vkCmdCopyImage"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007165 return (PFN_vkVoidFunction) vkCmdCopyImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007166 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007167 return (PFN_vkVoidFunction) vkCmdCopyBufferToImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007168 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007169 return (PFN_vkVoidFunction) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007170 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007171 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007172 if (!strcmp(funcName, "vkCmdFillBuffer"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007173 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007174 if (!strcmp(funcName, "vkCmdClearColorImage"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007175 return (PFN_vkVoidFunction) vkCmdClearColorImage;
Chris Forbesd9be82b2015-06-22 17:21:59 +12007176 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007177 return (PFN_vkVoidFunction) vkCmdClearDepthStencilImage;
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007178 if (!strcmp(funcName, "vkCmdClearAttachments"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007179 return (PFN_vkVoidFunction) vkCmdClearAttachments;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007180 if (!strcmp(funcName, "vkCmdResolveImage"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007181 return (PFN_vkVoidFunction) vkCmdResolveImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007182 if (!strcmp(funcName, "vkCmdSetEvent"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007183 return (PFN_vkVoidFunction) vkCmdSetEvent;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007184 if (!strcmp(funcName, "vkCmdResetEvent"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007185 return (PFN_vkVoidFunction) vkCmdResetEvent;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007186 if (!strcmp(funcName, "vkCmdWaitEvents"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007187 return (PFN_vkVoidFunction) vkCmdWaitEvents;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007188 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007189 return (PFN_vkVoidFunction) vkCmdPipelineBarrier;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007190 if (!strcmp(funcName, "vkCmdBeginQuery"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007191 return (PFN_vkVoidFunction) vkCmdBeginQuery;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007192 if (!strcmp(funcName, "vkCmdEndQuery"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007193 return (PFN_vkVoidFunction) vkCmdEndQuery;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007194 if (!strcmp(funcName, "vkCmdResetQueryPool"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007195 return (PFN_vkVoidFunction) vkCmdResetQueryPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007196 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007197 return (PFN_vkVoidFunction) vkCmdWriteTimestamp;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007198 if (!strcmp(funcName, "vkCreateFramebuffer"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007199 return (PFN_vkVoidFunction) vkCreateFramebuffer;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07007200 if (!strcmp(funcName, "vkCreateShaderModule"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007201 return (PFN_vkVoidFunction) vkCreateShaderModule;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007202 if (!strcmp(funcName, "vkCreateRenderPass"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007203 return (PFN_vkVoidFunction) vkCreateRenderPass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007204 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007205 return (PFN_vkVoidFunction) vkCmdBeginRenderPass;
Chia-I Wu08accc62015-07-07 11:50:03 +08007206 if (!strcmp(funcName, "vkCmdNextSubpass"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007207 return (PFN_vkVoidFunction) vkCmdNextSubpass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007208 if (!strcmp(funcName, "vkCmdEndRenderPass"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007209 return (PFN_vkVoidFunction) vkCmdEndRenderPass;
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007210 if (!strcmp(funcName, "vkCmdExecuteCommands"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007211 return (PFN_vkVoidFunction) vkCmdExecuteCommands;
Michael Lentineb887b0a2015-12-29 14:12:11 -06007212 if (!strcmp(funcName, "vkSetEvent"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007213 return (PFN_vkVoidFunction) vkSetEvent;
Michael Lentine7b236262015-10-23 12:41:44 -07007214 if (!strcmp(funcName, "vkMapMemory"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007215 return (PFN_vkVoidFunction) vkMapMemory;
Michael Lentineb887b0a2015-12-29 14:12:11 -06007216 if (!strcmp(funcName, "vkGetQueryPoolResults"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007217 return (PFN_vkVoidFunction) vkGetQueryPoolResults;
Michael Lentine15a47882016-01-06 10:05:48 -06007218 if (!strcmp(funcName, "vkBindImageMemory"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007219 return (PFN_vkVoidFunction) vkBindImageMemory;
Michael Lentine15a47882016-01-06 10:05:48 -06007220 if (!strcmp(funcName, "vkQueueBindSparse"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007221 return (PFN_vkVoidFunction) vkQueueBindSparse;
Michael Lentine15a47882016-01-06 10:05:48 -06007222 if (!strcmp(funcName, "vkCreateSemaphore"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007223 return (PFN_vkVoidFunction) vkCreateSemaphore;
Jon Ashburneab34492015-06-01 09:37:38 -06007224
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07007225 if (dev == NULL)
7226 return NULL;
7227
7228 layer_data *dev_data;
7229 dev_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map);
7230
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007231 if (dev_data->device_extensions.wsi_enabled)
7232 {
Michael Lentineabc5e922015-10-12 11:30:14 -05007233 if (!strcmp(funcName, "vkCreateSwapchainKHR"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007234 return (PFN_vkVoidFunction) vkCreateSwapchainKHR;
Michael Lentineabc5e922015-10-12 11:30:14 -05007235 if (!strcmp(funcName, "vkDestroySwapchainKHR"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007236 return (PFN_vkVoidFunction) vkDestroySwapchainKHR;
Michael Lentineabc5e922015-10-12 11:30:14 -05007237 if (!strcmp(funcName, "vkGetSwapchainImagesKHR"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007238 return (PFN_vkVoidFunction) vkGetSwapchainImagesKHR;
Michael Lentine15a47882016-01-06 10:05:48 -06007239 if (!strcmp(funcName, "vkAcquireNextImageKHR"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007240 return (PFN_vkVoidFunction) vkAcquireNextImageKHR;
Michael Lentineabc5e922015-10-12 11:30:14 -05007241 if (!strcmp(funcName, "vkQueuePresentKHR"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007242 return (PFN_vkVoidFunction) vkQueuePresentKHR;
Michael Lentineabc5e922015-10-12 11:30:14 -05007243 }
7244
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007245 VkLayerDispatchTable* pTable = dev_data->device_dispatch_table;
7246 if (dev_data->device_extensions.debug_marker_enabled)
7247 {
Jon Ashburn747f2b62015-06-18 15:02:58 -06007248 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007249 return (PFN_vkVoidFunction) vkCmdDbgMarkerBegin;
Jon Ashburn747f2b62015-06-18 15:02:58 -06007250 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007251 return (PFN_vkVoidFunction) vkCmdDbgMarkerEnd;
Jon Ashburneab34492015-06-01 09:37:38 -06007252 }
7253 {
Jon Ashburn8fd08252015-05-28 16:25:02 -06007254 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06007255 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -06007256 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburnf6b33db2015-05-05 14:22:52 -06007257 }
7258}
7259
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007260VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
7261{
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07007262 if (!strcmp(funcName, "vkGetInstanceProcAddr"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007263 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07007264 if (!strcmp(funcName, "vkGetDeviceProcAddr"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007265 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06007266 if (!strcmp(funcName, "vkCreateInstance"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007267 return (PFN_vkVoidFunction) vkCreateInstance;
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07007268 if (!strcmp(funcName, "vkCreateDevice"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007269 return (PFN_vkVoidFunction) vkCreateDevice;
Jon Ashburn3950e1b2015-05-20 09:00:28 -06007270 if (!strcmp(funcName, "vkDestroyInstance"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007271 return (PFN_vkVoidFunction) vkDestroyInstance;
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -06007272 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007273 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -06007274 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007275 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -06007276 if (!strcmp(funcName, "vkEnumerateDeviceLayerProperties"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007277 return (PFN_vkVoidFunction) vkEnumerateDeviceLayerProperties;
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -06007278 if (!strcmp(funcName, "vkEnumerateDeviceExtensionProperties"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007279 return (PFN_vkVoidFunction) vkEnumerateDeviceExtensionProperties;
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06007280
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07007281 if (instance == NULL)
7282 return NULL;
7283
7284 PFN_vkVoidFunction fptr;
7285
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007286 layer_data* my_data;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07007287 my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06007288 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06007289 if (fptr)
7290 return fptr;
7291
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007292 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07007293 if (pTable->GetInstanceProcAddr == NULL)
7294 return NULL;
7295 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06007296}