blob: 6ba56888984fef2dcccebcd5e3b3a6a3c9f17925 [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
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001139 auto set = my_data->descriptorSetLayoutMap[(*pipelineLayout)[slot.first]]->bindings;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001140
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001141 return (set.find(slot.second) != set.end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001142}
1143
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001144static uint32_t get_shader_stage_id(VkShaderStageFlagBits stage)
1145{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001146 uint32_t bit_pos = u_ffs(stage);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001147 return bit_pos-1;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001148}
1149
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001150// Block of code at start here for managing/tracking Pipeline state that this layer cares about
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001151
1152static uint64_t g_drawCount[NUM_DRAW_TYPES] = {0, 0, 0, 0};
1153
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001154// TODO : Should be tracking lastBound per commandBuffer and when draws occur, report based on that cmd buffer lastBound
1155// Then need to synchronize the accesses based on cmd buffer so that if I'm reading state on one cmd buffer, updates
1156// to that same cmd buffer by separate thread are not changing state from underneath us
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001157// Track the last cmd buffer touched by this thread
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001158
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001159// prototype
Ian Elliott8c8b2662016-01-30 10:57:03 -07001160static GLOBAL_CB_NODE* getCBNode(layer_data*, const VkCommandBuffer, bool doLock = true);
Tobin Ehlis559c6382015-11-05 09:52:49 -07001161
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001162static VkBool32 hasDrawCmd(GLOBAL_CB_NODE* pCB)
1163{
1164 for (uint32_t i=0; i<NUM_DRAW_TYPES; i++) {
Tobin Ehlis53eddda2015-07-01 16:46:13 -06001165 if (pCB->drawCount[i])
1166 return VK_TRUE;
1167 }
1168 return VK_FALSE;
1169}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001170
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001171// Check object status for selected flag state
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001172static 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)
1173{
1174 // If non-zero enable mask is present, check it against status but if enable_mask
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001175 // is 0 then no enable required so we should always just check status
1176 if ((!enable_mask) || (enable_mask & pNode->status)) {
1177 if ((pNode->status & status_mask) != status_flag) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001178 // TODO : How to pass dispatchable objects as srcObject? Here src obj should be cmd buffer
1179 return log_msg(my_data->report_data, msg_flags, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, error_code, "DS",
1180 "CB object %#" PRIxLEAST64 ": %s", (uint64_t)(pNode->commandBuffer), fail_msg);
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001181 }
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001182 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001183 return VK_FALSE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001184}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001185
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001186// Retrieve pipeline node ptr for given pipeline object
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001187static PIPELINE_NODE* getPipeline(layer_data* my_data, const VkPipeline pipeline)
1188{
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001189 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08001190 if (my_data->pipelineMap.find(pipeline) == my_data->pipelineMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001191 loader_platform_thread_unlock_mutex(&globalLock);
1192 return NULL;
1193 }
1194 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08001195 return my_data->pipelineMap[pipeline];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001196}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001197
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001198// Return VK_TRUE if for a given PSO, the given state enum is dynamic, else return VK_FALSE
1199static VkBool32 isDynamic(const PIPELINE_NODE* pPipeline, const VkDynamicState state)
1200{
Tobin Ehlisd332f282015-10-02 11:00:56 -06001201 if (pPipeline && pPipeline->graphicsPipelineCI.pDynamicState) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001202 for (uint32_t i=0; i<pPipeline->graphicsPipelineCI.pDynamicState->dynamicStateCount; i++) {
1203 if (state == pPipeline->graphicsPipelineCI.pDynamicState->pDynamicStates[i])
Tobin Ehlisd332f282015-10-02 11:00:56 -06001204 return VK_TRUE;
1205 }
1206 }
1207 return VK_FALSE;
1208}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001209
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001210// Validate state stored as flags at time of draw call
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001211static VkBool32 validate_draw_state_flags(layer_data* my_data, GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06001212 VkBool32 result;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001213 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");
1214 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");
1215 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");
1216 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");
1217 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");
1218 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");
1219 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");
1220 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");
1221 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 -06001222 if (indexedDraw)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001223 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 -06001224 return result;
1225}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001226
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001227// Verify attachment reference compatibility according to spec
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001228// If one array is larger, treat missing elements of shorter array as VK_ATTACHMENT_UNUSED & other array much match this
1229// If both AttachmentReference arrays have requested index, check their corresponding AttachementDescriptions
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001230// to make sure that format and samples counts match.
1231// If not, they are not compatible.
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001232static bool attachment_references_compatible(const uint32_t index, const VkAttachmentReference* pPrimary, const uint32_t primaryCount, const VkAttachmentDescription* pPrimaryAttachments,
1233 const VkAttachmentReference* pSecondary, const uint32_t secondaryCount, const VkAttachmentDescription* pSecondaryAttachments)
1234{
1235 if (index >= primaryCount) { // Check secondary as if primary is VK_ATTACHMENT_UNUSED
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001236 if (VK_ATTACHMENT_UNUSED != pSecondary[index].attachment)
1237 return false;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001238 } else if (index >= secondaryCount) { // Check primary as if secondary is VK_ATTACHMENT_UNUSED
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001239 if (VK_ATTACHMENT_UNUSED != pPrimary[index].attachment)
1240 return false;
1241 } else { // format and sample count must match
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001242 if ((pPrimaryAttachments[pPrimary[index].attachment].format == pSecondaryAttachments[pSecondary[index].attachment].format) &&
1243 (pPrimaryAttachments[pPrimary[index].attachment].samples == pSecondaryAttachments[pSecondary[index].attachment].samples))
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001244 return true;
1245 }
1246 // Format and sample counts didn't match
1247 return false;
1248}
1249
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001250// For give primary and secondary RenderPass objects, verify that they're compatible
1251static bool verify_renderpass_compatibility(layer_data* my_data, const VkRenderPass primaryRP, const VkRenderPass secondaryRP, string& errorMsg)
1252{
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001253 stringstream errorStr;
Ian Elliott8c8b2662016-01-30 10:57:03 -07001254 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001255 if (my_data->renderPassMap.find(primaryRP) == my_data->renderPassMap.end()) {
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001256 errorStr << "invalid VkRenderPass (" << primaryRP << ")";
1257 errorMsg = errorStr.str();
Ian Elliott8c8b2662016-01-30 10:57:03 -07001258 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001259 return false;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001260 } else if (my_data->renderPassMap.find(secondaryRP) == my_data->renderPassMap.end()) {
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001261 errorStr << "invalid VkRenderPass (" << secondaryRP << ")";
1262 errorMsg = errorStr.str();
Ian Elliott8c8b2662016-01-30 10:57:03 -07001263 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001264 return false;
1265 }
1266 // Trivial pass case is exact same RP
Ian Elliott8c8b2662016-01-30 10:57:03 -07001267 if (primaryRP == secondaryRP) {
1268 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001269 return true;
Ian Elliott8c8b2662016-01-30 10:57:03 -07001270 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001271 const VkRenderPassCreateInfo* primaryRPCI = my_data->renderPassMap[primaryRP]->pCreateInfo;
1272 const VkRenderPassCreateInfo* secondaryRPCI = my_data->renderPassMap[secondaryRP]->pCreateInfo;
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001273 if (primaryRPCI->subpassCount != secondaryRPCI->subpassCount) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001274 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 -07001275 errorMsg = errorStr.str();
Ian Elliott8c8b2662016-01-30 10:57:03 -07001276 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001277 return false;
1278 }
1279 uint32_t spIndex = 0;
1280 for (spIndex = 0; spIndex < primaryRPCI->subpassCount; ++spIndex) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001281 // For each subpass, verify that corresponding color, input, resolve & depth/stencil attachment references are compatible
1282 uint32_t primaryColorCount = primaryRPCI->pSubpasses[spIndex].colorAttachmentCount;
1283 uint32_t secondaryColorCount = secondaryRPCI->pSubpasses[spIndex].colorAttachmentCount;
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001284 uint32_t colorMax = std::max(primaryColorCount, secondaryColorCount);
1285 for (uint32_t cIdx = 0; cIdx < colorMax; ++cIdx) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001286 if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pColorAttachments, primaryColorCount, primaryRPCI->pAttachments,
1287 secondaryRPCI->pSubpasses[spIndex].pColorAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1288 errorStr << "color attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001289 errorMsg = errorStr.str();
Ian Elliott8c8b2662016-01-30 10:57:03 -07001290 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001291 return false;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001292 } else if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pResolveAttachments, primaryColorCount, primaryRPCI->pAttachments,
1293 secondaryRPCI->pSubpasses[spIndex].pResolveAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1294 errorStr << "resolve attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001295 errorMsg = errorStr.str();
Ian Elliott8c8b2662016-01-30 10:57:03 -07001296 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001297 return false;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001298 } else if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pDepthStencilAttachment, primaryColorCount, primaryRPCI->pAttachments,
1299 secondaryRPCI->pSubpasses[spIndex].pDepthStencilAttachment, secondaryColorCount, secondaryRPCI->pAttachments)) {
1300 errorStr << "depth/stencil attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001301 errorMsg = errorStr.str();
Ian Elliott8c8b2662016-01-30 10:57:03 -07001302 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001303 return false;
1304 }
1305 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001306 uint32_t primaryInputCount = primaryRPCI->pSubpasses[spIndex].inputAttachmentCount;
1307 uint32_t secondaryInputCount = secondaryRPCI->pSubpasses[spIndex].inputAttachmentCount;
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001308 uint32_t inputMax = std::max(primaryInputCount, secondaryInputCount);
1309 for (uint32_t i = 0; i < inputMax; ++i) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001310 if (!attachment_references_compatible(i, primaryRPCI->pSubpasses[spIndex].pInputAttachments, primaryColorCount, primaryRPCI->pAttachments,
1311 secondaryRPCI->pSubpasses[spIndex].pInputAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1312 errorStr << "input attachments at index " << i << " of subpass index " << spIndex << " are not compatible.";
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001313 errorMsg = errorStr.str();
Ian Elliott8c8b2662016-01-30 10:57:03 -07001314 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001315 return false;
1316 }
1317 }
1318 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07001319 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001320 return true;
1321}
1322
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001323// For give SET_NODE, verify that its Set is compatible w/ the setLayout corresponding to pipelineLayout[layoutIndex]
1324static bool verify_set_layout_compatibility(layer_data* my_data, const SET_NODE* pSet, const VkPipelineLayout layout, const uint32_t layoutIndex, string& errorMsg)
1325{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001326 stringstream errorStr;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001327 if (my_data->pipelineLayoutMap.find(layout) == my_data->pipelineLayoutMap.end()) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001328 errorStr << "invalid VkPipelineLayout (" << layout << ")";
1329 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001330 return false;
1331 }
1332 PIPELINE_LAYOUT_NODE pl = my_data->pipelineLayoutMap[layout];
1333 if (layoutIndex >= pl.descriptorSetLayouts.size()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001334 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 -07001335 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001336 return false;
1337 }
1338 // Get the specific setLayout from PipelineLayout that overlaps this set
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001339 LAYOUT_NODE* pLayoutNode = my_data->descriptorSetLayoutMap[pl.descriptorSetLayouts[layoutIndex]];
Tobin Ehlis559c6382015-11-05 09:52:49 -07001340 if (pLayoutNode->layout == pSet->pLayout->layout) { // trivial pass case
1341 return true;
1342 }
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07001343 size_t descriptorCount = pLayoutNode->descriptorTypes.size();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001344 if (descriptorCount != pSet->pLayout->descriptorTypes.size()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001345 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 -07001346 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001347 return false; // trivial fail case
1348 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001349 // Now need to check set against corresponding pipelineLayout to verify compatibility
1350 for (size_t i=0; i<descriptorCount; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07001351 // Need to verify that layouts are identically defined
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001352 // TODO : Is below sufficient? Making sure that types & stageFlags match per descriptor
Tobin Ehlis559c6382015-11-05 09:52:49 -07001353 // do we also need to check immutable samplers?
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001354 if (pLayoutNode->descriptorTypes[i] != pSet->pLayout->descriptorTypes[i]) {
1355 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 -07001356 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001357 return false;
1358 }
1359 if (pLayoutNode->stageFlags[i] != pSet->pLayout->stageFlags[i]) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001360 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 -07001361 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001362 return false;
1363 }
1364 }
1365 return true;
1366}
1367
Tobin Ehlis88452832015-12-03 09:40:56 -07001368// Validate that the shaders used by the given pipeline
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001369// As a side effect this function also records the sets that are actually used by the pipeline
1370static VkBool32
1371validate_pipeline_shaders(layer_data *my_data, VkDevice dev, PIPELINE_NODE* pPipeline)
1372{
1373 VkGraphicsPipelineCreateInfo const *pCreateInfo = &pPipeline->graphicsPipelineCI;
1374 /* We seem to allow pipeline stages to be specified out of order, so collect and identify them
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001375 * before trying to do anything more: */
1376 int vertex_stage = get_shader_stage_id(VK_SHADER_STAGE_VERTEX_BIT);
1377 int geometry_stage = get_shader_stage_id(VK_SHADER_STAGE_GEOMETRY_BIT);
1378 int fragment_stage = get_shader_stage_id(VK_SHADER_STAGE_FRAGMENT_BIT);
1379
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001380 shader_module **shaders = new shader_module*[fragment_stage + 1]; /* exclude CS */
1381 memset(shaders, 0, sizeof(shader_module *) * (fragment_stage +1));
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001382 RENDER_PASS_NODE const *rp = 0;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001383 VkPipelineVertexInputStateCreateInfo const *vi = 0;
Mark Youngb20a6a82016-01-07 15:41:43 -07001384 VkBool32 pass = VK_TRUE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001385
1386 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001387 VkPipelineShaderStageCreateInfo const *pStage = &pCreateInfo->pStages[i];
1388 if (pStage->sType == VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001389
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001390 if ((pStage->stage & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_GEOMETRY_BIT | VK_SHADER_STAGE_FRAGMENT_BIT
1391 | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT)) == 0) {
1392 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",
1393 "Unknown shader stage %d", pStage->stage)) {
Mark Youngb20a6a82016-01-07 15:41:43 -07001394 pass = VK_FALSE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001395 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001396 }
1397 else {
1398 shader_module *module = my_data->shaderModuleMap[pStage->module];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001399 shaders[get_shader_stage_id(pStage->stage)] = module;
1400
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001401 /* validate descriptor set layout against what the spirv module actually uses */
1402 std::map<std::pair<unsigned, unsigned>, interface_var> descriptor_uses;
1403 collect_interface_by_descriptor_slot(my_data, dev, module, spv::StorageClassUniform,
1404 descriptor_uses);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001405
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001406 auto layouts = pCreateInfo->layout != VK_NULL_HANDLE ?
1407 &(my_data->pipelineLayoutMap[pCreateInfo->layout].descriptorSetLayouts) : nullptr;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001408
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001409 for (auto it = descriptor_uses.begin(); it != descriptor_uses.end(); it++) {
1410 // As a side-effect of this function, capture which sets are used by the pipeline
Tobin Ehlis88452832015-12-03 09:40:56 -07001411 pPipeline->active_sets.insert(it->first.first);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001412
1413 /* find the matching binding */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001414 auto found = has_descriptor_binding(my_data, layouts, it->first);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001415
1416 if (!found) {
1417 char type_name[1024];
1418 describe_type(type_name, module, it->second.type_id);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001419 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__,
1420 SHADER_CHECKER_MISSING_DESCRIPTOR, "SC",
1421 "Shader uses descriptor slot %u.%u (used as type `%s`) but not declared in pipeline layout",
1422 it->first.first, it->first.second, type_name)) {
Mark Youngb20a6a82016-01-07 15:41:43 -07001423 pass = VK_FALSE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001424 }
1425 }
1426 }
1427 }
1428 }
1429 }
1430
1431 if (pCreateInfo->renderPass != VK_NULL_HANDLE)
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001432 rp = my_data->renderPassMap[pCreateInfo->renderPass];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001433
1434 vi = pCreateInfo->pVertexInputState;
1435
1436 if (vi) {
1437 pass = validate_vi_consistency(my_data, dev, vi) && pass;
1438 }
1439
1440 if (shaders[vertex_stage]) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001441 pass = validate_vi_against_vs_inputs(my_data, dev, vi, shaders[vertex_stage]) && pass;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001442 }
1443
1444 /* TODO: enforce rules about present combinations of shaders */
1445 int producer = get_shader_stage_id(VK_SHADER_STAGE_VERTEX_BIT);
1446 int consumer = get_shader_stage_id(VK_SHADER_STAGE_GEOMETRY_BIT);
1447
1448 while (!shaders[producer] && producer != fragment_stage) {
1449 producer++;
1450 consumer++;
1451 }
1452
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001453 for (; producer != fragment_stage && consumer <= fragment_stage; consumer++) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001454 assert(shaders[producer]);
1455 if (shaders[consumer]) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001456 pass = validate_interface_between_stages(my_data, dev,
1457 shaders[producer], shader_stage_attribs[producer].name,
1458 shaders[consumer], shader_stage_attribs[consumer].name,
1459 shader_stage_attribs[consumer].arrayed_input) && pass;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001460
1461 producer = consumer;
1462 }
1463 }
1464
1465 if (shaders[fragment_stage] && rp) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001466 pass = validate_fs_outputs_against_render_pass(my_data, dev, shaders[fragment_stage], rp, pCreateInfo->subpass) && pass;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001467 }
1468
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001469 delete [] shaders;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001470
1471 return pass;
1472}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001473
Tobin Ehlisf6585052015-12-17 11:48:42 -07001474// Return Set node ptr for specified set or else NULL
Ian Elliott8c8b2662016-01-30 10:57:03 -07001475static SET_NODE* getSetNode(layer_data* my_data, const VkDescriptorSet set, bool doLock = true)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001476{
Ian Elliott8c8b2662016-01-30 10:57:03 -07001477 if (doLock) {
1478 loader_platform_thread_lock_mutex(&globalLock);
1479 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07001480 if (my_data->setMap.find(set) == my_data->setMap.end()) {
Ian Elliott8c8b2662016-01-30 10:57:03 -07001481 if (doLock) {
1482 loader_platform_thread_unlock_mutex(&globalLock);
1483 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07001484 return NULL;
1485 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07001486 SET_NODE *rtn = my_data->setMap[set];
1487 if (doLock) {
1488 loader_platform_thread_unlock_mutex(&globalLock);
1489 }
1490 return rtn;
Tobin Ehlisf6585052015-12-17 11:48:42 -07001491}
Tobin Ehlisd2393772016-01-29 11:50:47 -07001492// For the given command buffer, verify that for each set set in activeSetNodes
1493// that any dynamic descriptor in that set has a valid dynamic offset bound.
1494// To be valid, the dynamic offset combined with the offet and range from its
1495// descriptor update must not overflow the size of its buffer being updated
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001496static VkBool32 validate_dynamic_offsets(layer_data* my_data, const GLOBAL_CB_NODE* pCB, const vector<SET_NODE*> activeSetNodes)
1497{
Tobin Ehlisf6585052015-12-17 11:48:42 -07001498 VkBool32 result = VK_FALSE;
Tobin Ehlisf6585052015-12-17 11:48:42 -07001499
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001500 VkWriteDescriptorSet* pWDS = NULL;
Tobin Ehlisf6585052015-12-17 11:48:42 -07001501 uint32_t dynOffsetIndex = 0;
1502 VkDeviceSize bufferSize = 0;
Tobin Ehlisd2393772016-01-29 11:50:47 -07001503 for (auto set_node : activeSetNodes) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001504 for (uint32_t i=0; i < set_node->descriptorCount; ++i) {
Tobin Ehlisd2393772016-01-29 11:50:47 -07001505 switch (set_node->ppDescriptors[i]->sType) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001506 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1507 pWDS = (VkWriteDescriptorSet*)set_node->ppDescriptors[i];
1508 if ((pWDS->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
1509 (pWDS->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
1510 for (uint32_t j=0; j<pWDS->descriptorCount; ++j) {
1511 bufferSize = my_data->bufferMap[pWDS->pBufferInfo[j].buffer].create_info->size;
1512 if ((pCB->dynamicOffsets[dynOffsetIndex] + pWDS->pBufferInfo[j].offset + pWDS->pBufferInfo[j].range) > bufferSize) {
1513 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",
1514 "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 ".",
1515 (uint64_t)set_node->set, i, pCB->dynamicOffsets[dynOffsetIndex], pWDS->pBufferInfo[j].offset, pWDS->pBufferInfo[j].range, (uint64_t)pWDS->pBufferInfo[j].buffer, bufferSize);
1516 }
1517 dynOffsetIndex++;
1518 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 -07001519 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07001520 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001521 break;
1522 default: // Currently only shadowing Write update nodes so shouldn't get here
1523 assert(0);
1524 continue;
Tobin Ehlisd2393772016-01-29 11:50:47 -07001525 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07001526 }
1527 }
1528 return result;
1529}
1530
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001531// Validate overall state at the time of a draw call
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001532static VkBool32 validate_draw_state(layer_data* my_data, GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001533 // First check flag states
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001534 VkBool32 result = validate_draw_state_flags(my_data, pCB, indexedDraw);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001535 PIPELINE_NODE* pPipe = getPipeline(my_data, pCB->lastBoundPipeline);
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001536 // Now complete other state checks
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001537 // TODO : Currently only performing next check if *something* was bound (non-zero last bound)
1538 // There is probably a better way to gate when this check happens, and to know if something *should* have been bound
1539 // We should have that check separately and then gate this check based on that check
Mark Lobodzinski74635932015-12-18 15:35:38 -07001540 if (pPipe) {
Tobin Ehlisd2393772016-01-29 11:50:47 -07001541 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski74635932015-12-18 15:35:38 -07001542 if (pCB->lastBoundPipelineLayout) {
1543 string errorString;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001544 // Need a vector (vs. std::set) of active Sets for dynamicOffset validation in case same set bound w/ different offsets
1545 vector<SET_NODE*> activeSetNodes;
Mark Lobodzinski74635932015-12-18 15:35:38 -07001546 for (auto setIndex : pPipe->active_sets) {
1547 // If valid set is not bound throw an error
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001548 if ((pCB->boundDescriptorSets.size() <= setIndex) || (!pCB->boundDescriptorSets[setIndex])) {
1549 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_DESCRIPTOR_SET_NOT_BOUND, "DS",
1550 "VkPipeline %#" PRIxLEAST64 " uses set #%u but that set is not bound.", (uint64_t)pPipe->pipeline, setIndex);
1551 } else if (!verify_set_layout_compatibility(my_data, my_data->setMap[pCB->boundDescriptorSets[setIndex]], pPipe->graphicsPipelineCI.layout, setIndex, errorString)) {
1552 // Set is bound but not compatible w/ overlapping pipelineLayout from PSO
1553 VkDescriptorSet setHandle = my_data->setMap[pCB->boundDescriptorSets[setIndex]]->set;
1554 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",
1555 "VkDescriptorSet (%#" PRIxLEAST64 ") bound as set #%u is not compatible with overlapping VkPipelineLayout %#" PRIxLEAST64 " due to: %s",
1556 (uint64_t)setHandle, setIndex, (uint64_t)pPipe->graphicsPipelineCI.layout, errorString.c_str());
1557 } 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 -07001558 // Pull the set node
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001559 SET_NODE* pSet = my_data->setMap[pCB->boundDescriptorSets[setIndex]];
1560 // Save vector of all active sets to verify dynamicOffsets below
Tobin Ehlisd2393772016-01-29 11:50:47 -07001561 activeSetNodes.push_back(pSet);
Tobin Ehlis43c39c02016-01-11 13:18:40 -07001562 // Make sure set has been updated
1563 if (!pSet->pUpdateStructs) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001564 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",
1565 "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 -07001566 }
Mark Lobodzinski74635932015-12-18 15:35:38 -07001567 }
Tobin Ehlis88452832015-12-03 09:40:56 -07001568 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001569 // For each dynamic descriptor, make sure dynamic offset doesn't overstep buffer
Tobin Ehlisd2393772016-01-29 11:50:47 -07001570 if (!pCB->dynamicOffsets.empty())
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001571 result |= validate_dynamic_offsets(my_data, pCB, activeSetNodes);
Tobin Ehlis88452832015-12-03 09:40:56 -07001572 }
Mark Lobodzinski74635932015-12-18 15:35:38 -07001573 // Verify Vtx binding
1574 if (pPipe->vtxBindingCount > 0) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001575 VkPipelineVertexInputStateCreateInfo *vtxInCI = &pPipe->vertexInputCI;
1576 for (uint32_t i = 0; i < vtxInCI->vertexBindingDescriptionCount; i++) {
1577 if ((pCB->currentDrawData.buffers.size() < (i+1)) || (pCB->currentDrawData.buffers[i] == VK_NULL_HANDLE)) {
1578 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS",
1579 "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 -07001580 (uint64_t)pCB->lastBoundPipeline, i);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001581
Mark Lobodzinski74635932015-12-18 15:35:38 -07001582 }
1583 }
1584 } else {
Michael Lentine700b0aa2015-10-30 17:57:32 -07001585 if (!pCB->currentDrawData.buffers.empty()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001586 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS,
1587 "DS", "Vertex buffers are bound to command buffer (%#" PRIxLEAST64 ") but no vertex buffers are attached to this Pipeline State Object (%#" PRIxLEAST64 ").",
1588 (uint64_t)pCB->commandBuffer, (uint64_t)pCB->lastBoundPipeline);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06001589 }
1590 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001591 // If Viewport or scissors are dynamic, verify that dynamic count matches PSO count
Mark Lobodzinski74635932015-12-18 15:35:38 -07001592 VkBool32 dynViewport = isDynamic(pPipe, VK_DYNAMIC_STATE_VIEWPORT);
1593 VkBool32 dynScissor = isDynamic(pPipe, VK_DYNAMIC_STATE_SCISSOR);
1594 if (dynViewport) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001595 if (pCB->viewports.size() != pPipe->graphicsPipelineCI.pViewportState->viewportCount) {
1596 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
1597 "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 -07001598 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001599 }
Mark Lobodzinski74635932015-12-18 15:35:38 -07001600 if (dynScissor) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001601 if (pCB->scissors.size() != pPipe->graphicsPipelineCI.pViewportState->scissorCount) {
1602 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
1603 "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 -07001604 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001605 }
Tobin Ehlisd2393772016-01-29 11:50:47 -07001606 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisd332f282015-10-02 11:00:56 -06001607 }
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001608 return result;
1609}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001610
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001611// Verify that create state for a pipeline is valid
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001612static VkBool32 verifyPipelineCreateState(layer_data* my_data, const VkDevice device, PIPELINE_NODE* pPipeline)
1613{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001614 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski2fd2d032015-12-16 14:25:22 -07001615
Tobin Ehlis88452832015-12-03 09:40:56 -07001616 if (!validate_pipeline_shaders(my_data, device, pPipeline)) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001617 skipCall = VK_TRUE;
1618 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001619 // VS is required
1620 if (!(pPipeline->active_shaders & VK_SHADER_STAGE_VERTEX_BIT)) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001621 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
1622 "Invalid Pipeline CreateInfo State: Vtx Shader required");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001623 }
1624 // Either both or neither TC/TE shaders should be defined
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001625 if (((pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) == 0) !=
1626 ((pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) == 0) ) {
1627 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
1628 "Invalid Pipeline CreateInfo State: TE and TC shaders must be included or excluded as a pair");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001629 }
1630 // Compute shaders should be specified independent of Gfx shaders
1631 if ((pPipeline->active_shaders & VK_SHADER_STAGE_COMPUTE_BIT) &&
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001632 (pPipeline->active_shaders & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT |
1633 VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT | VK_SHADER_STAGE_GEOMETRY_BIT |
1634 VK_SHADER_STAGE_FRAGMENT_BIT))) {
1635 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
1636 "Invalid Pipeline CreateInfo State: Do not specify Compute Shader for Gfx Pipeline");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001637 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001638 // VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology is only valid for tessellation pipelines.
1639 // Mismatching primitive topology and tessellation fails graphics pipeline creation.
1640 if (pPipeline->active_shaders & (VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) &&
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001641 (pPipeline->iaStateCI.topology != VK_PRIMITIVE_TOPOLOGY_PATCH_LIST)) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001642 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
1643 "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 -06001644 }
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001645 if (pPipeline->iaStateCI.topology == VK_PRIMITIVE_TOPOLOGY_PATCH_LIST) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001646 if (~pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) {
1647 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
1648 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology is only valid for tessellation pipelines");
Tobin Ehlis912df022015-09-17 08:46:18 -06001649 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001650 if (!pPipeline->tessStateCI.patchControlPoints || (pPipeline->tessStateCI.patchControlPoints > 32)) {
1651 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
1652 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology used with patchControlPoints value %u."
1653 " patchControlPoints should be >0 and <=32.", pPipeline->tessStateCI.patchControlPoints);
Tobin Ehlis912df022015-09-17 08:46:18 -06001654 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001655 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001656 // Viewport state must be included and viewport and scissor counts should always match
1657 // NOTE : Even if these are flagged as dynamic, counts need to be set correctly for shader compiler
Tobin Ehlisd332f282015-10-02 11:00:56 -06001658 if (!pPipeline->graphicsPipelineCI.pViewportState) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001659 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
1660 "Gfx Pipeline pViewportState is null. Even if viewport and scissors are dynamic PSO must include viewportCount and scissorCount in pViewportState.");
1661 } else if (pPipeline->graphicsPipelineCI.pViewportState->scissorCount != pPipeline->graphicsPipelineCI.pViewportState->viewportCount) {
1662 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
1663 "Gfx Pipeline viewport count (%u) must match scissor count (%u).", pPipeline->vpStateCI.viewportCount, pPipeline->vpStateCI.scissorCount);
Tobin Ehlisd332f282015-10-02 11:00:56 -06001664 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001665 // If viewport or scissor are not dynamic, then verify that data is appropriate for count
Tobin Ehlisd332f282015-10-02 11:00:56 -06001666 VkBool32 dynViewport = isDynamic(pPipeline, VK_DYNAMIC_STATE_VIEWPORT);
1667 VkBool32 dynScissor = isDynamic(pPipeline, VK_DYNAMIC_STATE_SCISSOR);
1668 if (!dynViewport) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001669 if (pPipeline->graphicsPipelineCI.pViewportState->viewportCount && !pPipeline->graphicsPipelineCI.pViewportState->pViewports) {
1670 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
1671 "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 -06001672 }
1673 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001674 if (!dynScissor) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001675 if (pPipeline->graphicsPipelineCI.pViewportState->scissorCount && !pPipeline->graphicsPipelineCI.pViewportState->pScissors) {
1676 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
1677 "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 -06001678 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06001679 }
1680 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001681 return skipCall;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001682}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001683
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001684// Init the pipeline mapping info based on pipeline create info LL tree
1685// Threading note : Calls to this function should wrapped in mutex
Tobin Ehlis88452832015-12-03 09:40:56 -07001686// TODO : this should really just be in the constructor for PIPELINE_NODE
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001687static PIPELINE_NODE* initGraphicsPipeline(layer_data* dev_data, const VkGraphicsPipelineCreateInfo* pCreateInfo, PIPELINE_NODE* pBasePipeline)
1688{
1689 PIPELINE_NODE* pPipeline = new PIPELINE_NODE;
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001690
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001691 if (pBasePipeline) {
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001692 *pPipeline = *pBasePipeline;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001693 }
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001694
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001695 // First init create info
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001696 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001697
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001698 size_t bufferSize = 0;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001699 const VkPipelineVertexInputStateCreateInfo* pVICI = NULL;
1700 const VkPipelineColorBlendStateCreateInfo* pCBCI = NULL;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001701
1702 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001703 const VkPipelineShaderStageCreateInfo *pPSSCI = &pCreateInfo->pStages[i];
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001704
Chia-I Wu28e06912015-10-31 00:31:16 +08001705 switch (pPSSCI->stage) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001706 case VK_SHADER_STAGE_VERTEX_BIT:
1707 memcpy(&pPipeline->vsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1708 pPipeline->active_shaders |= VK_SHADER_STAGE_VERTEX_BIT;
1709 break;
1710 case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT:
1711 memcpy(&pPipeline->tcsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1712 pPipeline->active_shaders |= VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
1713 break;
1714 case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT:
1715 memcpy(&pPipeline->tesCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1716 pPipeline->active_shaders |= VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
1717 break;
1718 case VK_SHADER_STAGE_GEOMETRY_BIT:
1719 memcpy(&pPipeline->gsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1720 pPipeline->active_shaders |= VK_SHADER_STAGE_GEOMETRY_BIT;
1721 break;
1722 case VK_SHADER_STAGE_FRAGMENT_BIT:
1723 memcpy(&pPipeline->fsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1724 pPipeline->active_shaders |= VK_SHADER_STAGE_FRAGMENT_BIT;
1725 break;
1726 case VK_SHADER_STAGE_COMPUTE_BIT:
1727 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
1728 pPipeline->active_shaders |= VK_SHADER_STAGE_COMPUTE_BIT;
1729 break;
1730 default:
1731 // TODO : Flag error
1732 break;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001733 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001734 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001735 // Copy over GraphicsPipelineCreateInfo structure embedded pointers
1736 if (pCreateInfo->stageCount != 0) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001737 pPipeline->graphicsPipelineCI.pStages = new VkPipelineShaderStageCreateInfo[pCreateInfo->stageCount];
1738 bufferSize = pCreateInfo->stageCount * sizeof(VkPipelineShaderStageCreateInfo);
1739 memcpy((void*)pPipeline->graphicsPipelineCI.pStages, pCreateInfo->pStages, bufferSize);
Tobin Ehlis963a4042015-09-29 08:18:34 -06001740 }
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001741 if (pCreateInfo->pVertexInputState != NULL) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001742 memcpy((void*)&pPipeline->vertexInputCI, pCreateInfo->pVertexInputState , sizeof(VkPipelineVertexInputStateCreateInfo));
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001743 // Copy embedded ptrs
1744 pVICI = pCreateInfo->pVertexInputState;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001745 pPipeline->vtxBindingCount = pVICI->vertexBindingDescriptionCount;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001746 if (pPipeline->vtxBindingCount) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001747 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
1748 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
1749 memcpy((void*)pPipeline->pVertexBindingDescriptions, pVICI->pVertexBindingDescriptions, bufferSize);
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001750 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08001751 pPipeline->vtxAttributeCount = pVICI->vertexAttributeDescriptionCount;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001752 if (pPipeline->vtxAttributeCount) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001753 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
1754 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
1755 memcpy((void*)pPipeline->pVertexAttributeDescriptions, pVICI->pVertexAttributeDescriptions, bufferSize);
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001756 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001757 pPipeline->graphicsPipelineCI.pVertexInputState = &pPipeline->vertexInputCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001758 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001759 if (pCreateInfo->pInputAssemblyState != NULL) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001760 memcpy((void*)&pPipeline->iaStateCI, pCreateInfo->pInputAssemblyState, sizeof(VkPipelineInputAssemblyStateCreateInfo));
1761 pPipeline->graphicsPipelineCI.pInputAssemblyState = &pPipeline->iaStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001762 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001763 if (pCreateInfo->pTessellationState != NULL) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001764 memcpy((void*)&pPipeline->tessStateCI, pCreateInfo->pTessellationState, sizeof(VkPipelineTessellationStateCreateInfo));
1765 pPipeline->graphicsPipelineCI.pTessellationState = &pPipeline->tessStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001766 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001767 if (pCreateInfo->pViewportState != NULL) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001768 memcpy((void*)&pPipeline->vpStateCI, pCreateInfo->pViewportState, sizeof(VkPipelineViewportStateCreateInfo));
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001769 pPipeline->graphicsPipelineCI.pViewportState = &pPipeline->vpStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001770 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001771 if (pCreateInfo->pRasterizationState != NULL) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001772 memcpy((void*)&pPipeline->rsStateCI, pCreateInfo->pRasterizationState, sizeof(VkPipelineRasterizationStateCreateInfo));
1773 pPipeline->graphicsPipelineCI.pRasterizationState = &pPipeline->rsStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001774 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001775 if (pCreateInfo->pMultisampleState != NULL) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001776 memcpy((void*)&pPipeline->msStateCI, pCreateInfo->pMultisampleState, sizeof(VkPipelineMultisampleStateCreateInfo));
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001777 pPipeline->graphicsPipelineCI.pMultisampleState = &pPipeline->msStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001778 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001779 if (pCreateInfo->pDepthStencilState != NULL) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001780 memcpy((void*)&pPipeline->dsStateCI, pCreateInfo->pDepthStencilState, sizeof(VkPipelineDepthStencilStateCreateInfo));
1781 pPipeline->graphicsPipelineCI.pDepthStencilState = &pPipeline->dsStateCI;
Tobin Ehlis963a4042015-09-29 08:18:34 -06001782 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001783 if (pCreateInfo->pColorBlendState != NULL) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001784 memcpy((void*)&pPipeline->cbStateCI, pCreateInfo->pColorBlendState, sizeof(VkPipelineColorBlendStateCreateInfo));
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001785 // Copy embedded ptrs
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001786 pCBCI = pCreateInfo->pColorBlendState;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001787 pPipeline->attachmentCount = pCBCI->attachmentCount;
1788 if (pPipeline->attachmentCount) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001789 pPipeline->pAttachments = new VkPipelineColorBlendAttachmentState[pPipeline->attachmentCount];
1790 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineColorBlendAttachmentState);
1791 memcpy((void*)pPipeline->pAttachments, pCBCI->pAttachments, bufferSize);
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001792 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001793 pPipeline->graphicsPipelineCI.pColorBlendState = &pPipeline->cbStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001794 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001795 if (pCreateInfo->pDynamicState != NULL) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001796 memcpy((void*)&pPipeline->dynStateCI, pCreateInfo->pDynamicState, sizeof(VkPipelineDynamicStateCreateInfo));
Tobin Ehlis963a4042015-09-29 08:18:34 -06001797 if (pPipeline->dynStateCI.dynamicStateCount) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001798 pPipeline->dynStateCI.pDynamicStates = new VkDynamicState[pPipeline->dynStateCI.dynamicStateCount];
1799 bufferSize = pPipeline->dynStateCI.dynamicStateCount * sizeof(VkDynamicState);
1800 memcpy((void*)pPipeline->dynStateCI.pDynamicStates, pCreateInfo->pDynamicState->pDynamicStates, bufferSize);
Tobin Ehlis963a4042015-09-29 08:18:34 -06001801 }
1802 pPipeline->graphicsPipelineCI.pDynamicState = &pPipeline->dynStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001803 }
Tobin Ehlis88452832015-12-03 09:40:56 -07001804 pPipeline->active_sets.clear();
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001805 return pPipeline;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001806}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001807
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001808// Free the Pipeline nodes
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001809static void deletePipelines(layer_data* my_data)
1810{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001811 if (my_data->pipelineMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06001812 return;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001813 for (auto ii=my_data->pipelineMap.begin(); ii!=my_data->pipelineMap.end(); ++ii) {
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001814 if ((*ii).second->graphicsPipelineCI.stageCount != 0) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001815 delete[] (*ii).second->graphicsPipelineCI.pStages;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001816 }
Tobin Ehlisf313c8b2015-04-01 11:59:08 -06001817 if ((*ii).second->pVertexBindingDescriptions) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001818 delete[] (*ii).second->pVertexBindingDescriptions;
Tobin Ehlisf313c8b2015-04-01 11:59:08 -06001819 }
1820 if ((*ii).second->pVertexAttributeDescriptions) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001821 delete[] (*ii).second->pVertexAttributeDescriptions;
Tobin Ehlisf313c8b2015-04-01 11:59:08 -06001822 }
1823 if ((*ii).second->pAttachments) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001824 delete[] (*ii).second->pAttachments;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001825 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001826 if ((*ii).second->dynStateCI.dynamicStateCount != 0) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001827 delete[] (*ii).second->dynStateCI.pDynamicStates;
Tobin Ehlis963a4042015-09-29 08:18:34 -06001828 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001829 delete (*ii).second;
1830 }
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001831 my_data->pipelineMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001832}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001833
Tobin Ehliseba312c2015-04-01 08:40:34 -06001834// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001835static VkSampleCountFlagBits getNumSamples(layer_data* my_data, const VkPipeline pipeline)
1836{
Ian Elliott8c8b2662016-01-30 10:57:03 -07001837 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001838 PIPELINE_NODE* pPipe = my_data->pipelineMap[pipeline];
Ian Elliott8c8b2662016-01-30 10:57:03 -07001839 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001840 if (VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001841 return pPipe->msStateCI.rasterizationSamples;
Tobin Ehlis577188e2015-07-13 14:51:15 -06001842 }
Chia-I Wu5c17c962015-10-31 00:31:16 +08001843 return VK_SAMPLE_COUNT_1_BIT;
Tobin Ehliseba312c2015-04-01 08:40:34 -06001844}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001845
Tobin Ehliseba312c2015-04-01 08:40:34 -06001846// Validate state related to the PSO
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001847static VkBool32 validatePipelineState(layer_data* my_data, const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
1848{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001849 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06001850 // Verify that any MSAA request in PSO matches sample# in bound FB
Chia-I Wu5c17c962015-10-31 00:31:16 +08001851 VkSampleCountFlagBits psoNumSamples = getNumSamples(my_data, pipeline);
Tobin Ehliseba312c2015-04-01 08:40:34 -06001852 if (pCB->activeRenderPass) {
Ian Elliott8c8b2662016-01-30 10:57:03 -07001853 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001854 const VkRenderPassCreateInfo* pRPCI = my_data->renderPassMap[pCB->activeRenderPass]->pCreateInfo;
1855 const VkSubpassDescription* pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
Ian Elliott8c8b2662016-01-30 10:57:03 -07001856 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001857 VkSampleCountFlagBits subpassNumSamples = (VkSampleCountFlagBits) 0;
Chia-I Wu08accc62015-07-07 11:50:03 +08001858 uint32_t i;
1859
Chia-I Wud50a7d72015-10-26 20:48:51 +08001860 for (i = 0; i < pSD->colorAttachmentCount; i++) {
Chia-I Wu5c17c962015-10-31 00:31:16 +08001861 VkSampleCountFlagBits samples;
Chia-I Wu08accc62015-07-07 11:50:03 +08001862
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001863 if (pSD->pColorAttachments[i].attachment == VK_ATTACHMENT_UNUSED)
Chia-I Wu08accc62015-07-07 11:50:03 +08001864 continue;
1865
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001866 samples = pRPCI->pAttachments[pSD->pColorAttachments[i].attachment].samples;
1867 if (subpassNumSamples == (VkSampleCountFlagBits) 0) {
Chia-I Wu08accc62015-07-07 11:50:03 +08001868 subpassNumSamples = samples;
1869 } else if (subpassNumSamples != samples) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001870 subpassNumSamples = (VkSampleCountFlagBits) -1;
Chia-I Wu08accc62015-07-07 11:50:03 +08001871 break;
1872 }
1873 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001874 if (pSD->pDepthStencilAttachment && pSD->pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
1875 const VkSampleCountFlagBits samples = pRPCI->pAttachments[pSD->pDepthStencilAttachment->attachment].samples;
1876 if (subpassNumSamples == (VkSampleCountFlagBits) 0)
Chia-I Wu08accc62015-07-07 11:50:03 +08001877 subpassNumSamples = samples;
1878 else if (subpassNumSamples != samples)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001879 subpassNumSamples = (VkSampleCountFlagBits) -1;
Chia-I Wu08accc62015-07-07 11:50:03 +08001880 }
1881
1882 if (psoNumSamples != subpassNumSamples) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001883 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",
1884 "Num samples mismatch! Binding PSO (%#" PRIxLEAST64 ") with %u samples while current RenderPass (%#" PRIxLEAST64 ") w/ %u samples!",
1885 (uint64_t) pipeline, psoNumSamples, (uint64_t) pCB->activeRenderPass, subpassNumSamples);
Tobin Ehliseba312c2015-04-01 08:40:34 -06001886 }
1887 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001888 // 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 -06001889 // Verify and flag error as appropriate
1890 }
1891 // TODO : Add more checks here
1892 } else {
1893 // TODO : Validate non-gfx pipeline updates
1894 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001895 return VK_FALSE;
Tobin Ehliseba312c2015-04-01 08:40:34 -06001896}
1897
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001898// Block of code at start here specifically for managing/tracking DSs
1899
Tobin Ehlis793ad302015-04-03 12:01:11 -06001900// Return Pool node ptr for specified pool or else NULL
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001901static DESCRIPTOR_POOL_NODE* getPoolNode(layer_data* my_data, const VkDescriptorPool pool)
1902{
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001903 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001904 if (my_data->descriptorPoolMap.find(pool) == my_data->descriptorPoolMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001905 loader_platform_thread_unlock_mutex(&globalLock);
1906 return NULL;
1907 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07001908 DESCRIPTOR_POOL_NODE *rtn = my_data->descriptorPoolMap[pool];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001909 loader_platform_thread_unlock_mutex(&globalLock);
Ian Elliott8c8b2662016-01-30 10:57:03 -07001910 return rtn;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001911}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001912
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001913static LAYOUT_NODE* getLayoutNode(layer_data* my_data, const VkDescriptorSetLayout layout) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001914 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001915 if (my_data->descriptorSetLayoutMap.find(layout) == my_data->descriptorSetLayoutMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001916 loader_platform_thread_unlock_mutex(&globalLock);
1917 return NULL;
1918 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07001919 LAYOUT_NODE *rtn = my_data->descriptorSetLayoutMap[layout];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001920 loader_platform_thread_unlock_mutex(&globalLock);
Ian Elliott8c8b2662016-01-30 10:57:03 -07001921 return rtn;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001922}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001923
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001924// Return VK_FALSE if update struct is of valid type, otherwise flag error and return code from callback
1925static VkBool32 validUpdateStruct(layer_data* my_data, const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
1926{
1927 switch (pUpdateStruct->sType)
1928 {
1929 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1930 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
1931 return VK_FALSE;
1932 default:
1933 return log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
1934 "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 -06001935 }
1936}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001937
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001938// Set count for given update struct in the last parameter
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001939// Return value of skipCall, which is only VK_TRUE if error occurs and callback signals execution to cease
1940static uint32_t getUpdateCount(layer_data* my_data, const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
1941{
1942 switch (pUpdateStruct->sType)
1943 {
1944 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1945 return ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorCount;
1946 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
1947 // TODO : Need to understand this case better and make sure code is correct
1948 return ((VkCopyDescriptorSet*)pUpdateStruct)->descriptorCount;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001949 }
Courtney Goeltzenleuchter7f47bca2015-12-16 16:08:08 -07001950
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001951 return 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001952}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001953
Tobin Ehlis793ad302015-04-03 12:01:11 -06001954// For given Layout Node and binding, return index where that binding begins
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001955static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
1956{
Tobin Ehlis793ad302015-04-03 12:01:11 -06001957 uint32_t offsetIndex = 0;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001958 for (uint32_t i = 0; i < pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001959 if (pLayout->createInfo.pBindings[i].binding == binding)
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001960 break;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001961 offsetIndex += pLayout->createInfo.pBindings[i].descriptorCount;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001962 }
1963 return offsetIndex;
1964}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001965
Tobin Ehlis793ad302015-04-03 12:01:11 -06001966// For given layout node and binding, return last index that is updated
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001967static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
1968{
Tobin Ehlis793ad302015-04-03 12:01:11 -06001969 uint32_t offsetIndex = 0;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001970 for (uint32_t i = 0; i < pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001971 offsetIndex += pLayout->createInfo.pBindings[i].descriptorCount;
1972 if (pLayout->createInfo.pBindings[i].binding == binding)
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001973 break;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001974 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001975 return offsetIndex-1;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001976}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001977
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001978// For given layout and update, return the first overall index of the layout that is updated
1979static 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)
1980{
1981 return getBindingStartIndex(pLayout, binding)+arrayIndex;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001982}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001983
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001984// For given layout and update, return the last overall index of the layout that is updated
1985static 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)
1986{
Tobin Ehlis8a62e632015-10-27 15:43:38 -06001987 uint32_t count = getUpdateCount(my_data, device, pUpdateStruct);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001988 return getBindingStartIndex(pLayout, binding)+arrayIndex+count-1;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001989}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001990
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001991// Verify that the descriptor type in the update struct matches what's expected by the layout
1992static VkBool32 validateUpdateConsistency(layer_data* my_data, const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct, uint32_t startIndex, uint32_t endIndex)
1993{
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001994 // First get actual type of update
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001995 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001996 VkDescriptorType actualType;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001997 uint32_t i = 0;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001998 switch (pUpdateStruct->sType)
1999 {
2000 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
2001 actualType = ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorType;
2002 break;
2003 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
2004 /* no need to validate */
2005 return VK_FALSE;
2006 break;
2007 default:
2008 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
2009 "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 -06002010 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002011 if (VK_FALSE == skipCall) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002012 // Set first stageFlags as reference and verify that all other updates match it
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002013 VkShaderStageFlags refStageFlags = pLayout->stageFlags[startIndex];
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002014 for (i = startIndex; i <= endIndex; i++) {
Tobin Ehlis644ff042015-10-20 10:11:55 -06002015 if (pLayout->descriptorTypes[i] != actualType) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002016 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, "DS",
2017 "Write descriptor update has descriptor type %s that does not match overlapping binding descriptor type of %s!",
2018 string_VkDescriptorType(actualType), string_VkDescriptorType(pLayout->descriptorTypes[i]));
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002019 }
2020 if (pLayout->stageFlags[i] != refStageFlags) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002021 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_DESCRIPTOR_STAGEFLAGS_MISMATCH, "DS",
2022 "Write descriptor update has stageFlags %x that do not match overlapping binding descriptor stageFlags of %x!",
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002023 refStageFlags, pLayout->stageFlags[i]);
Tobin Ehlis483cc352015-09-30 08:30:20 -06002024 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002025 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002026 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002027 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002028}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002029
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002030// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
2031// struct into the pNewNode param. Return VK_TRUE if error condition encountered and callback signals early exit.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002032// NOTE : Calls to this function should be wrapped in mutex
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002033static VkBool32 shadowUpdateNode(layer_data* my_data, const VkDevice device, GENERIC_HEADER* pUpdate, GENERIC_HEADER** pNewNode)
2034{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002035 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002036 VkWriteDescriptorSet* pWDS = NULL;
2037 VkCopyDescriptorSet* pCDS = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002038 size_t array_size = 0;
2039 size_t base_array_size = 0;
2040 size_t total_array_size = 0;
2041 size_t baseBuffAddr = 0;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002042 switch (pUpdate->sType)
2043 {
2044 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
2045 pWDS = new VkWriteDescriptorSet;
2046 *pNewNode = (GENERIC_HEADER*)pWDS;
2047 memcpy(pWDS, pUpdate, sizeof(VkWriteDescriptorSet));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06002048
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002049 switch (pWDS->descriptorType) {
2050 case VK_DESCRIPTOR_TYPE_SAMPLER:
2051 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
2052 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2053 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
2054 {
2055 VkDescriptorImageInfo *info = new VkDescriptorImageInfo[pWDS->descriptorCount];
2056 memcpy(info, pWDS->pImageInfo, pWDS->descriptorCount * sizeof(VkDescriptorImageInfo));
2057 pWDS->pImageInfo = info;
2058 }
2059 break;
2060 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2061 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
2062 {
2063 VkBufferView *info = new VkBufferView[pWDS->descriptorCount];
2064 memcpy(info, pWDS->pTexelBufferView, pWDS->descriptorCount * sizeof(VkBufferView));
2065 pWDS->pTexelBufferView = info;
2066 }
2067 break;
2068 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2069 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2070 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2071 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
2072 {
2073 VkDescriptorBufferInfo *info = new VkDescriptorBufferInfo[pWDS->descriptorCount];
2074 memcpy(info, pWDS->pBufferInfo, pWDS->descriptorCount * sizeof(VkDescriptorBufferInfo));
2075 pWDS->pBufferInfo = info;
2076 }
2077 break;
2078 default:
2079 return VK_ERROR_VALIDATION_FAILED_EXT;
2080 break;
2081 }
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -07002082 break;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002083 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
2084 pCDS = new VkCopyDescriptorSet;
2085 *pNewNode = (GENERIC_HEADER*)pCDS;
2086 memcpy(pCDS, pUpdate, sizeof(VkCopyDescriptorSet));
2087 break;
2088 default:
2089 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
2090 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdate->sType), pUpdate->sType))
2091 return VK_TRUE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002092 }
2093 // Make sure that pNext for the end of shadow copy is NULL
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002094 (*pNewNode)->pNext = NULL;
2095 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002096}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002097
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002098// Verify that given sampler is valid
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002099static VkBool32 validateSampler(const layer_data* my_data, const VkSampler* pSampler, const VkBool32 immutable)
2100{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002101 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002102 auto sampIt = my_data->sampleMap.find(*pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002103 if (sampIt == my_data->sampleMap.end()) {
2104 if (!immutable) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002105 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",
2106 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid sampler %#" PRIxLEAST64, (uint64_t) *pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002107 } else { // immutable
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002108 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",
2109 "vkUpdateDescriptorSets: Attempt to update descriptor whose binding has an invalid immutable sampler %#" PRIxLEAST64, (uint64_t) *pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002110 }
2111 } else {
2112 // TODO : Any further checks we want to do on the sampler?
2113 }
2114 return skipCall;
2115}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002116
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002117// Verify that given imageView is valid
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002118static VkBool32 validateImageView(const layer_data* my_data, const VkImageView* pImageView, const VkImageLayout imageLayout)
2119{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002120 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002121 auto ivIt = my_data->imageViewMap.find(*pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002122 if (ivIt == my_data->imageViewMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002123 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",
2124 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid imageView %#" PRIxLEAST64, (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002125 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002126 // Validate that imageLayout is compatible with aspectMask and image format
2127 VkImageAspectFlags aspectMask = ivIt->second->subresourceRange.aspectMask;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002128 VkImage image = ivIt->second->image;
Michael Lentine7b236262015-10-23 12:41:44 -07002129 // TODO : Check here in case we have a bad image
Tobin Ehlis75cd1c52016-01-21 10:21:04 -07002130 auto imgIt = my_data->imageLayoutMap.find(image);
2131 if (imgIt == my_data->imageLayoutMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002132 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",
2133 "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 -06002134 } else {
2135 VkFormat format = (*imgIt).second->format;
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07002136 VkBool32 ds = vk_format_is_depth_or_stencil(format);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002137 switch (imageLayout) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002138 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
2139 // Only Color bit must be set
2140 if ((aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) != VK_IMAGE_ASPECT_COLOR_BIT) {
2141 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__,
2142 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL and imageView %#" PRIxLEAST64 ""
2143 " that does not have VK_IMAGE_ASPECT_COLOR_BIT set.", (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002144 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002145 // format must NOT be DS
2146 if (ds) {
2147 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__,
2148 DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL and imageView %#" PRIxLEAST64 ""
2149 " but the image format is %s which is not a color format.", (uint64_t) *pImageView, string_VkFormat(format));
2150 }
2151 break;
2152 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
2153 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
2154 // Depth or stencil bit must be set, but both must NOT be set
2155 if (aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) {
2156 if (aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) {
2157 // both must NOT be set
2158 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__,
2159 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with imageView %#" PRIxLEAST64 ""
2160 " that has both STENCIL and DEPTH aspects set", (uint64_t) *pImageView);
2161 }
2162 } else if (!(aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)) {
2163 // Neither were set
2164 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__,
2165 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout %s and imageView %#" PRIxLEAST64 ""
2166 " that does not have STENCIL or DEPTH aspect set.", string_VkImageLayout(imageLayout), (uint64_t) *pImageView);
2167 }
2168 // format must be DS
2169 if (!ds) {
2170 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__,
2171 DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout %s and imageView %#" PRIxLEAST64 ""
2172 " but the image format is %s which is not a depth/stencil format.", string_VkImageLayout(imageLayout), (uint64_t) *pImageView, string_VkFormat(format));
2173 }
2174 break;
2175 default:
2176 // anything to check for other layouts?
2177 break;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002178 }
2179 }
2180 }
2181 return skipCall;
2182}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002183
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002184// Verify that given bufferView is valid
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002185static VkBool32 validateBufferView(const layer_data* my_data, const VkBufferView* pBufferView)
2186{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002187 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002188 auto sampIt = my_data->bufferViewMap.find(*pBufferView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002189 if (sampIt == my_data->bufferViewMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002190 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",
2191 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid bufferView %#" PRIxLEAST64, (uint64_t) *pBufferView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002192 } else {
2193 // TODO : Any further checks we want to do on the bufferView?
2194 }
2195 return skipCall;
2196}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002197
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002198// Verify that given bufferInfo is valid
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002199static VkBool32 validateBufferInfo(const layer_data* my_data, const VkDescriptorBufferInfo* pBufferInfo)
2200{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002201 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002202 auto sampIt = my_data->bufferMap.find(pBufferInfo->buffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002203 if (sampIt == my_data->bufferMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002204 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",
2205 "vkUpdateDescriptorSets: Attempt to update descriptor where bufferInfo has invalid buffer %#" PRIxLEAST64, (uint64_t) pBufferInfo->buffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002206 } else {
2207 // TODO : Any further checks we want to do on the bufferView?
2208 }
2209 return skipCall;
2210}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002211
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002212static VkBool32 validateUpdateContents(const layer_data* my_data, const VkWriteDescriptorSet *pWDS, const VkDescriptorSetLayoutBinding* pLayoutBinding)
2213{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002214 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002215 // First verify that for the given Descriptor type, the correct DescriptorInfo data is supplied
2216 VkBufferView* pBufferView = NULL;
2217 const VkSampler* pSampler = NULL;
2218 VkImageView* pImageView = NULL;
2219 VkImageLayout* pImageLayout = NULL;
2220 VkDescriptorBufferInfo* pBufferInfo = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002221 VkBool32 immutable = VK_FALSE;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002222 uint32_t i = 0;
2223 // For given update type, verify that update contents are correct
2224 switch (pWDS->descriptorType) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002225 case VK_DESCRIPTOR_TYPE_SAMPLER:
2226 for (i=0; i<pWDS->descriptorCount; ++i) {
2227 skipCall |= validateSampler(my_data, &(pWDS->pImageInfo[i].sampler), immutable);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002228 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002229 break;
2230 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
2231 for (i=0; i<pWDS->descriptorCount; ++i) {
2232 if (NULL == pLayoutBinding->pImmutableSamplers) {
2233 pSampler = &(pWDS->pImageInfo[i].sampler);
2234 if (immutable) {
2235 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",
2236 "vkUpdateDescriptorSets: Update #%u is not an immutable sampler %#" PRIxLEAST64 ", but previous update(s) from this "
2237 "VkWriteDescriptorSet struct used an immutable sampler. All updates from a single struct must either "
2238 "use immutable or non-immutable samplers.", i, (uint64_t) *pSampler);
2239 }
2240 } else {
2241 if (i>0 && !immutable) {
2242 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",
2243 "vkUpdateDescriptorSets: Update #%u is an immutable sampler, but previous update(s) from this "
2244 "VkWriteDescriptorSet struct used a non-immutable sampler. All updates from a single struct must either "
2245 "use immutable or non-immutable samplers.", i);
2246 }
2247 immutable = VK_TRUE;
2248 pSampler = &(pLayoutBinding->pImmutableSamplers[i]);
2249 }
2250 skipCall |= validateSampler(my_data, pSampler, immutable);
2251 }
2252 // Intentionally fall through here to also validate image stuff
2253 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2254 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
2255 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
2256 for (i=0; i<pWDS->descriptorCount; ++i) {
2257 skipCall |= validateImageView(my_data, &(pWDS->pImageInfo[i].imageView), pWDS->pImageInfo[i].imageLayout);
2258 }
2259 break;
2260 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2261 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
2262 for (i=0; i<pWDS->descriptorCount; ++i) {
2263 skipCall |= validateBufferView(my_data, &(pWDS->pTexelBufferView[i]));
2264 }
2265 break;
2266 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2267 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2268 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2269 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
2270 for (i=0; i<pWDS->descriptorCount; ++i) {
2271 skipCall |= validateBufferInfo(my_data, &(pWDS->pBufferInfo[i]));
2272 }
2273 break;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002274 }
2275 return skipCall;
2276}
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002277// 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 -07002278// func_str is the name of the calling function
2279// Return VK_FALSE if no errors occur
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002280// Return VK_TRUE if validation error occurs and callback returns VK_TRUE (to skip upcoming API call down the chain)
2281VkBool32 validateIdleDescriptorSet(const layer_data* my_data, VkDescriptorSet set, std::string func_str) {
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002282 VkBool32 skip_call = VK_FALSE;
2283 auto set_node = my_data->setMap.find(set);
2284 if (set_node == my_data->setMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002285 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",
2286 "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 -07002287 } else {
2288 if (set_node->second->in_use.load()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002289 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",
2290 "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 -07002291 }
2292 }
2293 return skip_call;
2294}
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002295static void invalidateBoundCmdBuffers(layer_data* dev_data, const SET_NODE* pSet)
2296{
Tobin Ehlise6e574b2016-01-24 23:25:31 -07002297 // Flag any CBs this set is bound to as INVALID
2298 for (auto cb : pSet->boundCmdBuffers) {
2299 auto cb_node = dev_data->commandBufferMap.find(cb);
2300 if (cb_node != dev_data->commandBufferMap.end()) {
2301 cb_node->second->state = CB_INVALID;
2302 }
2303 }
2304}
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002305// update DS mappings based on write and copy update arrays
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002306static VkBool32 dsUpdate(layer_data* my_data, VkDevice device, uint32_t descriptorWriteCount, const VkWriteDescriptorSet* pWDS, uint32_t descriptorCopyCount, const VkCopyDescriptorSet* pCDS)
2307{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002308 VkBool32 skipCall = VK_FALSE;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002309
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002310 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002311 LAYOUT_NODE* pLayout = NULL;
2312 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002313 // Validate Write updates
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002314 uint32_t i = 0;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002315 for (i=0; i < descriptorWriteCount; i++) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002316 VkDescriptorSet ds = pWDS[i].dstSet;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002317 SET_NODE* pSet = my_data->setMap[ds];
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002318 // Set being updated cannot be in-flight
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002319 if ((skipCall = validateIdleDescriptorSet(my_data, ds, "VkUpdateDescriptorSets")) == VK_TRUE)
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002320 return skipCall;
Tobin Ehlise6e574b2016-01-24 23:25:31 -07002321 // If set is bound to any cmdBuffers, mark them invalid
2322 invalidateBoundCmdBuffers(my_data, pSet);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002323 GENERIC_HEADER* pUpdate = (GENERIC_HEADER*) &pWDS[i];
Tobin Ehlis793ad302015-04-03 12:01:11 -06002324 pLayout = pSet->pLayout;
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002325 // First verify valid update struct
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002326 if ((skipCall = validUpdateStruct(my_data, device, pUpdate)) == VK_TRUE) {
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002327 break;
2328 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002329 uint32_t binding = 0, endIndex = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002330 binding = pWDS[i].dstBinding;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002331 // Make sure that layout being updated has the binding being updated
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002332 if (pLayout->bindings.find(binding) == pLayout->bindings.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002333 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t)(ds), __LINE__, DRAWSTATE_INVALID_UPDATE_INDEX, "DS",
2334 "Descriptor Set %" PRIu64 " does not have binding to match update binding %u for update type %s!", (uint64_t)(ds), binding, string_VkStructureType(pUpdate->sType));
Tobin Ehlis9c536442015-06-19 13:00:59 -06002335 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06002336 // Next verify that update falls within size of given binding
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002337 endIndex = getUpdateEndIndex(my_data, device, pLayout, binding, pWDS[i].dstArrayElement, pUpdate);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002338 if (getBindingEndIndex(pLayout, binding) < endIndex) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06002339 pLayoutCI = &pLayout->createInfo;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002340 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
2341 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",
2342 "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());
2343 } else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002344 uint32_t startIndex;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002345 startIndex = getUpdateStartIndex(my_data, device, pLayout, binding, pWDS[i].dstArrayElement, pUpdate);
2346 // Layout bindings match w/ update, now verify that update type & stageFlags are the same for entire update
2347 if ((skipCall = validateUpdateConsistency(my_data, device, pLayout, pUpdate, startIndex, endIndex)) == VK_FALSE) {
2348 // The update is within bounds and consistent, but need to make sure contents make sense as well
2349 if ((skipCall = validateUpdateContents(my_data, &pWDS[i], &pLayout->createInfo.pBindings[binding])) == VK_FALSE) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002350 // Update is good. Save the update info
2351 // Create new update struct for this set's shadow copy
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002352 GENERIC_HEADER* pNewNode = NULL;
2353 skipCall |= shadowUpdateNode(my_data, device, pUpdate, &pNewNode);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002354 if (NULL == pNewNode) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002355 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",
2356 "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002357 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002358 // Insert shadow node into LL of updates for this set
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002359 pNewNode->pNext = pSet->pUpdateStructs;
2360 pSet->pUpdateStructs = pNewNode;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002361 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002362 for (uint32_t j = startIndex; j <= endIndex; j++) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002363 assert(j<pSet->descriptorCount);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002364 pSet->ppDescriptors[j] = pNewNode;
2365 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002366 }
2367 }
2368 }
2369 }
2370 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002371 }
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002372 // Now validate copy updates
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002373 for (i=0; i < descriptorCopyCount; ++i) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002374 SET_NODE *pSrcSet = NULL, *pDstSet = NULL;
2375 LAYOUT_NODE *pSrcLayout = NULL, *pDstLayout = NULL;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002376 uint32_t srcStartIndex = 0, srcEndIndex = 0, dstStartIndex = 0, dstEndIndex = 0;
2377 // For each copy make sure that update falls within given layout and that types match
Chia-I Wue2fc5522015-10-26 20:04:44 +08002378 pSrcSet = my_data->setMap[pCDS[i].srcSet];
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002379 pDstSet = my_data->setMap[pCDS[i].dstSet];
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002380 // Set being updated cannot be in-flight
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002381 if ((skipCall = validateIdleDescriptorSet(my_data, pDstSet->set, "VkUpdateDescriptorSets")) == VK_TRUE)
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002382 return skipCall;
Tobin Ehlise6e574b2016-01-24 23:25:31 -07002383 invalidateBoundCmdBuffers(my_data, pDstSet);
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002384 pSrcLayout = pSrcSet->pLayout;
2385 pDstLayout = pDstSet->pLayout;
2386 // Validate that src binding is valid for src set layout
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002387 if (pSrcLayout->bindings.find(pCDS[i].srcBinding) == pSrcLayout->bindings.end()) {
2388 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pSrcSet->set, __LINE__, DRAWSTATE_INVALID_UPDATE_INDEX, "DS",
2389 "Copy descriptor update %u has srcBinding %u which is out of bounds for underlying SetLayout %#" PRIxLEAST64 " which only has bindings 0-%u.",
2390 i, pCDS[i].srcBinding, (uint64_t) pSrcLayout->layout, pSrcLayout->createInfo.bindingCount-1);
2391 } else if (pDstLayout->bindings.find(pCDS[i].dstBinding) == pDstLayout->bindings.end()) {
2392 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pDstSet->set, __LINE__, DRAWSTATE_INVALID_UPDATE_INDEX, "DS",
2393 "Copy descriptor update %u has dstBinding %u which is out of bounds for underlying SetLayout %#" PRIxLEAST64 " which only has bindings 0-%u.",
2394 i, pCDS[i].dstBinding, (uint64_t) pDstLayout->layout, pDstLayout->createInfo.bindingCount-1);
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002395 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002396 // Proceed with validation. Bindings are ok, but make sure update is within bounds of given layout
2397 srcEndIndex = getUpdateEndIndex(my_data, device, pSrcLayout, pCDS[i].srcBinding, pCDS[i].srcArrayElement, (const GENERIC_HEADER*)&(pCDS[i]));
2398 dstEndIndex = getUpdateEndIndex(my_data, device, pDstLayout, pCDS[i].dstBinding, pCDS[i].dstArrayElement, (const GENERIC_HEADER*)&(pCDS[i]));
2399 if (getBindingEndIndex(pSrcLayout, pCDS[i].srcBinding) < srcEndIndex) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002400 pLayoutCI = &pSrcLayout->createInfo;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002401 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
2402 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",
2403 "Copy descriptor src update is out of bounds for matching binding %u in Layout w/ CI:\n%s!", pCDS[i].srcBinding, DSstr.c_str());
2404 } else if (getBindingEndIndex(pDstLayout, pCDS[i].dstBinding) < dstEndIndex) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002405 pLayoutCI = &pDstLayout->createInfo;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002406 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
2407 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",
2408 "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 -06002409 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002410 srcStartIndex = getUpdateStartIndex(my_data, device, pSrcLayout, pCDS[i].srcBinding, pCDS[i].srcArrayElement, (const GENERIC_HEADER*)&(pCDS[i]));
2411 dstStartIndex = getUpdateStartIndex(my_data, device, pDstLayout, pCDS[i].dstBinding, pCDS[i].dstArrayElement, (const GENERIC_HEADER*)&(pCDS[i]));
2412 for (uint32_t j=0; j<pCDS[i].descriptorCount; ++j) {
2413 // For copy just make sure that the types match and then perform the update
2414 if (pSrcLayout->descriptorTypes[srcStartIndex+j] != pDstLayout->descriptorTypes[dstStartIndex+j]) {
2415 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, "DS",
2416 "Copy descriptor update index %u, update count #%u, has src update descriptor type %s that does not match overlapping dest descriptor type of %s!",
2417 i, j+1, string_VkDescriptorType(pSrcLayout->descriptorTypes[srcStartIndex+j]), string_VkDescriptorType(pDstLayout->descriptorTypes[dstStartIndex+j]));
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002418 } else {
2419 // point dst descriptor at corresponding src descriptor
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002420 // TODO : This may be a hole. I believe copy should be its own copy,
2421 // otherwise a subsequent write update to src will incorrectly affect the copy
2422 pDstSet->ppDescriptors[j+dstStartIndex] = pSrcSet->ppDescriptors[j+srcStartIndex];
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002423 }
2424 }
2425 }
2426 }
2427 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002428 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002429 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002430}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002431
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002432// Verify that given pool has descriptors that are being requested for allocation
2433static VkBool32 validate_descriptor_availability_in_pool(layer_data* dev_data, DESCRIPTOR_POOL_NODE* pPoolNode, uint32_t count, const VkDescriptorSetLayout* pSetLayouts)
2434{
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002435 VkBool32 skipCall = VK_FALSE;
2436 uint32_t i = 0, j = 0;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002437 for (i=0; i<count; ++i) {
2438 LAYOUT_NODE* pLayout = getLayoutNode(dev_data, pSetLayouts[i]);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002439 if (NULL == pLayout) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002440 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",
2441 "Unable to find set layout node for layout %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pSetLayouts[i]);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002442 } else {
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002443 uint32_t typeIndex = 0, poolSizeCount = 0;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002444 for (j=0; j<pLayout->createInfo.bindingCount; ++j) {
2445 typeIndex = static_cast<uint32_t>(pLayout->createInfo.pBindings[j].descriptorType);
2446 poolSizeCount = pLayout->createInfo.pBindings[j].descriptorCount;
2447 if (poolSizeCount > pPoolNode->availableDescriptorTypeCount[typeIndex]) {
2448 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",
2449 "Unable to allocate %u descriptors of type %s from pool %#" PRIxLEAST64 ". This pool only has %u descriptors of this type remaining.",
2450 poolSizeCount, string_VkDescriptorType(pLayout->createInfo.pBindings[j].descriptorType), (uint64_t) pPoolNode->pool, pPoolNode->availableDescriptorTypeCount[typeIndex]);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002451 } else { // Decrement available descriptors of this type
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002452 pPoolNode->availableDescriptorTypeCount[typeIndex] -= poolSizeCount;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002453 }
2454 }
2455 }
2456 }
2457 return skipCall;
2458}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002459
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002460// Free the shadowed update node for this Set
2461// NOTE : Calls to this function should be wrapped in mutex
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002462static void freeShadowUpdateTree(SET_NODE* pSet)
2463{
2464 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002465 pSet->pUpdateStructs = NULL;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002466 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002467 // Clear the descriptor mappings as they will now be invalid
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002468 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
2469 while(pShadowUpdate) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002470 pFreeUpdate = pShadowUpdate;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002471 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002472 uint32_t index = 0;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002473 VkWriteDescriptorSet * pWDS = NULL;
2474 VkCopyDescriptorSet * pCDS = NULL;
2475 void** ppToFree = NULL;
2476 switch (pFreeUpdate->sType)
2477 {
2478 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
2479 pWDS = (VkWriteDescriptorSet*)pFreeUpdate;
2480 switch (pWDS->descriptorType) {
2481 case VK_DESCRIPTOR_TYPE_SAMPLER:
2482 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
2483 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2484 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
2485 {
2486 delete[] pWDS->pImageInfo;
2487 }
2488 break;
2489 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2490 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
2491 {
2492 delete[] pWDS->pTexelBufferView;
2493 }
2494 break;
2495 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2496 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2497 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2498 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
2499 {
2500 delete[] pWDS->pBufferInfo;
2501 }
2502 break;
2503 default:
2504 break;
2505 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002506 break;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002507 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
2508 break;
2509 default:
2510 assert(0);
2511 break;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002512 }
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002513 delete pFreeUpdate;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002514 }
2515}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002516
Tobin Ehlis793ad302015-04-03 12:01:11 -06002517// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002518// NOTE : Calls to this function should be wrapped in mutex
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002519static void deletePools(layer_data* my_data)
2520{
Mark Lobodzinski39298632015-11-18 08:38:27 -07002521 if (my_data->descriptorPoolMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06002522 return;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002523 for (auto ii=my_data->descriptorPoolMap.begin(); ii!=my_data->descriptorPoolMap.end(); ++ii) {
2524 SET_NODE* pSet = (*ii).second->pSets;
2525 SET_NODE* pFreeSet = pSet;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002526 while (pSet) {
2527 pFreeSet = pSet;
2528 pSet = pSet->pNext;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002529 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002530 // Free Update shadow struct tree
2531 freeShadowUpdateTree(pFreeSet);
2532 if (pFreeSet->ppDescriptors) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002533 delete[] pFreeSet->ppDescriptors;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002534 }
2535 delete pFreeSet;
2536 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002537 delete (*ii).second;
2538 }
Mark Lobodzinski39298632015-11-18 08:38:27 -07002539 my_data->descriptorPoolMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002540}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002541
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002542// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002543// NOTE : Calls to this function should be wrapped in mutex
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002544static void deleteLayouts(layer_data* my_data)
2545{
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07002546 if (my_data->descriptorSetLayoutMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06002547 return;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002548 for (auto ii=my_data->descriptorSetLayoutMap.begin(); ii!=my_data->descriptorSetLayoutMap.end(); ++ii) {
2549 LAYOUT_NODE* pLayout = (*ii).second;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002550 if (pLayout->createInfo.pBindings) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002551 for (uint32_t i=0; i<pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002552 if (pLayout->createInfo.pBindings[i].pImmutableSamplers)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002553 delete[] pLayout->createInfo.pBindings[i].pImmutableSamplers;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002554 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002555 delete[] pLayout->createInfo.pBindings;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002556 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002557 delete pLayout;
2558 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07002559 my_data->descriptorSetLayoutMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002560}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002561
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002562// Currently clearing a set is removing all previous updates to that set
2563// TODO : Validate if this is correct clearing behavior
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002564static void clearDescriptorSet(layer_data* my_data, VkDescriptorSet set)
2565{
2566 SET_NODE* pSet = getSetNode(my_data, set);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002567 if (!pSet) {
2568 // TODO : Return error
Tobin Ehlisce132d82015-06-19 15:07:05 -06002569 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002570 loader_platform_thread_lock_mutex(&globalLock);
2571 freeShadowUpdateTree(pSet);
2572 loader_platform_thread_unlock_mutex(&globalLock);
2573 }
2574}
2575
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002576static void clearDescriptorPool(layer_data* my_data, const VkDevice device, const VkDescriptorPool pool, VkDescriptorPoolResetFlags flags)
2577{
2578 DESCRIPTOR_POOL_NODE* pPool = getPoolNode(my_data, pool);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002579 if (!pPool) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002580 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",
2581 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkResetDescriptorPool() call", (uint64_t) pool);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002582 } else {
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002583 // TODO: validate flags
Tobin Ehlis793ad302015-04-03 12:01:11 -06002584 // For every set off of this pool, clear it
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002585 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002586 while (pSet) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002587 clearDescriptorSet(my_data, pSet->set);
Mark Lobodzinskidcce0792016-01-04 09:40:19 -07002588 pSet = pSet->pNext;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002589 }
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002590 // Reset available count to max count for this pool
Ian Elliott8c8b2662016-01-30 10:57:03 -07002591 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002592 for (uint32_t i=0; i<pPool->availableDescriptorTypeCount.size(); ++i) {
2593 pPool->availableDescriptorTypeCount[i] = pPool->maxDescriptorTypeCount[i];
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002594 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07002595 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002596 }
2597}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002598
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002599// For given CB object, fetch associated CB Node from map
Ian Elliott8c8b2662016-01-30 10:57:03 -07002600static GLOBAL_CB_NODE* getCBNode(layer_data* my_data, const VkCommandBuffer cb, bool doLock)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002601{
Ian Elliott8c8b2662016-01-30 10:57:03 -07002602 if (doLock) {
2603 loader_platform_thread_lock_mutex(&globalLock);
2604 }
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002605 if (my_data->commandBufferMap.count(cb) == 0) {
Ian Elliott8c8b2662016-01-30 10:57:03 -07002606 if (doLock) {
2607 loader_platform_thread_unlock_mutex(&globalLock);
2608 }
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002609 // TODO : How to pass cb as srcObj here?
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002610 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",
2611 "Attempt to use CommandBuffer %#" PRIxLEAST64 " that doesn't exist!", (uint64_t)(cb));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002612 return NULL;
2613 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07002614 GLOBAL_CB_NODE *rtn = my_data->commandBufferMap[cb];
2615 if (doLock) {
2616 loader_platform_thread_unlock_mutex(&globalLock);
2617 }
2618 return rtn;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002619}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002620
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002621// Free all CB Nodes
2622// NOTE : Calls to this function should be wrapped in mutex
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002623static void deleteCommandBuffers(layer_data* my_data)
2624{
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002625 if (my_data->commandBufferMap.size() <= 0) {
David Pinedod8f83d82015-04-27 16:36:17 -06002626 return;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002627 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002628 for (auto ii=my_data->commandBufferMap.begin(); ii!=my_data->commandBufferMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002629 delete (*ii).second;
2630 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002631 my_data->commandBufferMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002632}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002633
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002634static VkBool32 report_error_no_cb_begin(const layer_data* dev_data, const VkCommandBuffer cb, const char* caller_name)
2635{
2636 return log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2637 (uint64_t)cb, __LINE__, DRAWSTATE_NO_BEGIN_COMMAND_BUFFER, "DS",
2638 "You must call vkBeginCommandBuffer() before this call to %s", caller_name);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002639}
Michael Lentine3dea6512015-10-28 15:55:18 -07002640
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002641VkBool32 validateCmdsInCmdBuffer(const layer_data* dev_data, const GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd_type) {
2642 if (!pCB->activeRenderPass) return VK_FALSE;
Mark Youngb20a6a82016-01-07 15:41:43 -07002643 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002644 if (pCB->activeSubpassContents == VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS && cmd_type != CMD_EXECUTECOMMANDS) {
2645 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
2646 DRAWSTATE_INVALID_COMMAND_BUFFER, "DS", "Commands cannot be called in a subpass using secondary command buffers.");
2647 } else if (pCB->activeSubpassContents == VK_SUBPASS_CONTENTS_INLINE && cmd_type == CMD_EXECUTECOMMANDS) {
2648 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
2649 DRAWSTATE_INVALID_COMMAND_BUFFER, "DS", "vkCmdExecuteCommands() cannot be called in a subpass using inline commands.");
Michael Lentine2e068b22015-12-29 16:05:27 -06002650 }
Michael Lentine3dea6512015-10-28 15:55:18 -07002651 return skip_call;
2652}
2653
Michael Lentine26870f32016-01-26 21:36:08 -06002654static bool checkGraphicsBit(const layer_data* my_data, VkQueueFlags flags, const char* name) {
2655 if (!(flags & VK_QUEUE_GRAPHICS_BIT))
2656 return log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
2657 DRAWSTATE_INVALID_COMMAND_BUFFER, "DS", "Cannot call %s on a command buffer allocated from a pool without graphics capabilities.", name);
2658 return false;
2659}
2660
2661static bool checkComputeBit(const layer_data* my_data, VkQueueFlags flags, const char* name) {
2662 if (!(flags & VK_QUEUE_COMPUTE_BIT))
2663 return log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
2664 DRAWSTATE_INVALID_COMMAND_BUFFER, "DS", "Cannot call %s on a command buffer allocated from a pool without compute capabilities.", name);
2665 return false;
2666}
2667
2668static bool checkGraphicsOrComputeBit(const layer_data* my_data, VkQueueFlags flags, const char* name) {
2669 if (!((flags & VK_QUEUE_GRAPHICS_BIT) || (flags & VK_QUEUE_COMPUTE_BIT)))
2670 return log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
2671 DRAWSTATE_INVALID_COMMAND_BUFFER, "DS", "Cannot call %s on a command buffer allocated from a pool without graphics capabilities.", name);
2672 return false;
2673}
2674
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002675// Add specified CMD to the CmdBuffer in given pCB, flagging errors if CB is not
2676// in the recording state or if there's an issue with the Cmd ordering
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002677static VkBool32 addCmd(const layer_data* my_data, GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd, const char* caller_name)
2678{
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002679 VkBool32 skipCall = VK_FALSE;
Michael Lentine26870f32016-01-26 21:36:08 -06002680 auto pool_data = my_data->commandPoolMap.find(pCB->createInfo.commandPool);
2681 if (pool_data != my_data->commandPoolMap.end()) {
2682 VkQueueFlags flags = my_data->physDevProperties.queue_family_properties[pool_data->second.queueFamilyIndex].queueFlags;
2683 switch (cmd)
2684 {
2685 case CMD_BINDPIPELINE:
2686 case CMD_BINDPIPELINEDELTA:
2687 case CMD_BINDDESCRIPTORSETS:
2688 case CMD_FILLBUFFER:
2689 case CMD_CLEARCOLORIMAGE:
2690 case CMD_SETEVENT:
2691 case CMD_RESETEVENT:
2692 case CMD_WAITEVENTS:
2693 case CMD_BEGINQUERY:
2694 case CMD_ENDQUERY:
2695 case CMD_RESETQUERYPOOL:
2696 case CMD_COPYQUERYPOOLRESULTS:
2697 case CMD_WRITETIMESTAMP:
2698 skipCall |= checkGraphicsOrComputeBit(my_data, flags, cmdTypeToString(cmd).c_str());
2699 break;
2700 case CMD_SETVIEWPORTSTATE:
2701 case CMD_SETSCISSORSTATE:
2702 case CMD_SETLINEWIDTHSTATE:
2703 case CMD_SETDEPTHBIASSTATE:
2704 case CMD_SETBLENDSTATE:
2705 case CMD_SETDEPTHBOUNDSSTATE:
2706 case CMD_SETSTENCILREADMASKSTATE:
2707 case CMD_SETSTENCILWRITEMASKSTATE:
2708 case CMD_SETSTENCILREFERENCESTATE:
2709 case CMD_BINDINDEXBUFFER:
2710 case CMD_BINDVERTEXBUFFER:
2711 case CMD_DRAW:
2712 case CMD_DRAWINDEXED:
2713 case CMD_DRAWINDIRECT:
2714 case CMD_DRAWINDEXEDINDIRECT:
2715 case CMD_BLITIMAGE:
2716 case CMD_CLEARATTACHMENTS:
2717 case CMD_CLEARDEPTHSTENCILIMAGE:
2718 case CMD_RESOLVEIMAGE:
2719 case CMD_BEGINRENDERPASS:
2720 case CMD_NEXTSUBPASS:
2721 case CMD_ENDRENDERPASS:
2722 skipCall |= checkGraphicsBit(my_data, flags, cmdTypeToString(cmd).c_str());
2723 break;
2724 case CMD_DISPATCH:
2725 case CMD_DISPATCHINDIRECT:
2726 skipCall |= checkComputeBit(my_data, flags, cmdTypeToString(cmd).c_str());
2727 break;
2728 case CMD_COPYBUFFER:
2729 case CMD_COPYIMAGE:
2730 case CMD_COPYBUFFERTOIMAGE:
2731 case CMD_COPYIMAGETOBUFFER:
2732 case CMD_CLONEIMAGEDATA:
2733 case CMD_UPDATEBUFFER:
2734 case CMD_PIPELINEBARRIER:
2735 case CMD_EXECUTECOMMANDS:
2736 break;
2737 default:
2738 break;
2739 }
2740 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002741 if (pCB->state != CB_RECORDING) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002742 skipCall |= report_error_no_cb_begin(my_data, pCB->commandBuffer, caller_name);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002743 skipCall |= validateCmdsInCmdBuffer(my_data, pCB, cmd);
Tobin Ehlis9a874302016-01-20 10:25:29 -07002744 CMD_NODE cmdNode = {};
2745 // init cmd node and append to end of cmd LL
2746 cmdNode.cmdNumber = ++pCB->numCmds;
2747 cmdNode.type = cmd;
2748 pCB->cmds.push_back(cmdNode);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002749 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002750 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002751}
Tobin Ehlisef694652016-01-19 12:03:34 -07002752// Reset the command buffer state
2753// Maintain the createInfo and set state to CB_NEW, but clear all other state
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002754static void resetCB(layer_data* my_data, const VkCommandBuffer cb)
2755{
2756 GLOBAL_CB_NODE* pCB = my_data->commandBufferMap[cb];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002757 if (pCB) {
Tobin Ehlis9a874302016-01-20 10:25:29 -07002758 pCB->cmds.clear();
Tobin Ehlisef694652016-01-19 12:03:34 -07002759 // Reset CB state (note that createInfo is not cleared)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002760 pCB->commandBuffer = cb;
Michael Lentineabc5e922015-10-12 11:30:14 -05002761 memset(&pCB->beginInfo, 0, sizeof(VkCommandBufferBeginInfo));
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002762 memset(&pCB->inheritanceInfo, 0, sizeof(VkCommandBufferInheritanceInfo));
Michael Lentineabc5e922015-10-12 11:30:14 -05002763 pCB->fence = 0;
2764 pCB->numCmds = 0;
2765 memset(pCB->drawCount, 0, NUM_DRAW_TYPES * sizeof(uint64_t));
2766 pCB->state = CB_NEW;
2767 pCB->submitCount = 0;
2768 pCB->status = 0;
Michael Lentineabc5e922015-10-12 11:30:14 -05002769 pCB->lastBoundPipeline = 0;
Chris Forbes82c123c2016-02-02 15:45:40 +13002770 pCB->lastVtxBinding = 0;
2771 pCB->boundVtxBuffers.clear();
Michael Lentineabc5e922015-10-12 11:30:14 -05002772 pCB->viewports.clear();
2773 pCB->scissors.clear();
2774 pCB->lineWidth = 0;
2775 pCB->depthBiasConstantFactor = 0;
2776 pCB->depthBiasClamp = 0;
2777 pCB->depthBiasSlopeFactor = 0;
2778 memset(pCB->blendConstants, 0, 4 * sizeof(float));
2779 pCB->minDepthBounds = 0;
2780 pCB->maxDepthBounds = 0;
2781 memset(&pCB->front, 0, sizeof(stencil_data));
2782 memset(&pCB->back, 0, sizeof(stencil_data));
2783 pCB->lastBoundDescriptorSet = 0;
2784 pCB->lastBoundPipelineLayout = 0;
Chris Forbes82c123c2016-02-02 15:45:40 +13002785 memset(&pCB->activeRenderPassBeginInfo, 0, sizeof(pCB->activeRenderPassBeginInfo));
Michael Lentineabc5e922015-10-12 11:30:14 -05002786 pCB->activeRenderPass = 0;
Chris Forbes82c123c2016-02-02 15:45:40 +13002787 pCB->activeSubpassContents = VK_SUBPASS_CONTENTS_INLINE;
Michael Lentineabc5e922015-10-12 11:30:14 -05002788 pCB->activeSubpass = 0;
Chris Forbes82c123c2016-02-02 15:45:40 +13002789 pCB->framebuffer = 0;
Tobin Ehlise6e574b2016-01-24 23:25:31 -07002790 // Before clearing uniqueBoundSets, remove this CB off of its boundCBs
2791 for (auto set : pCB->uniqueBoundSets) {
2792 auto set_node = my_data->setMap.find(set);
2793 if (set_node != my_data->setMap.end()) {
2794 set_node->second->boundCmdBuffers.erase(pCB->commandBuffer);
2795 }
2796 }
2797 pCB->uniqueBoundSets.clear();
Chris Forbes82c123c2016-02-02 15:45:40 +13002798 pCB->destroyedSets.clear();
2799 pCB->updatedSets.clear();
Michael Lentineabc5e922015-10-12 11:30:14 -05002800 pCB->boundDescriptorSets.clear();
Michael Lentineb887b0a2015-12-29 14:12:11 -06002801 pCB->waitedEvents.clear();
2802 pCB->waitedEventsBeforeQueryReset.clear();
2803 pCB->queryToStateMap.clear();
Michael Lentinedc6f8de2016-02-02 18:29:30 -06002804 pCB->activeQueries.clear();
Chris Forbes82c123c2016-02-02 15:45:40 +13002805 pCB->imageLayoutMap.clear();
2806 pCB->drawData.clear();
2807 pCB->currentDrawData.buffers.clear();
Michael Lentined7621bb2016-02-03 10:55:23 -06002808 pCB->primaryCommandBuffer = VK_NULL_HANDLE;
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07002809 pCB->secondaryCommandBuffers.clear();
Chris Forbes82c123c2016-02-02 15:45:40 +13002810 pCB->dynamicOffsets.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002811 }
2812}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002813
Tobin Ehlis963a4042015-09-29 08:18:34 -06002814// Set PSO-related status bits for CB, including dynamic state set via PSO
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002815static void set_cb_pso_status(GLOBAL_CB_NODE* pCB, const PIPELINE_NODE* pPipe)
2816{
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002817 for (uint32_t i = 0; i < pPipe->cbStateCI.attachmentCount; i++) {
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002818 if (0 != pPipe->pAttachments[i].colorWriteMask) {
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002819 pCB->status |= CBSTATUS_COLOR_BLEND_WRITE_ENABLE;
2820 }
2821 }
2822 if (pPipe->dsStateCI.depthWriteEnable) {
Cody Northrop82485a82015-08-18 15:21:16 -06002823 pCB->status |= CBSTATUS_DEPTH_WRITE_ENABLE;
2824 }
Cody Northrop82485a82015-08-18 15:21:16 -06002825 if (pPipe->dsStateCI.stencilTestEnable) {
2826 pCB->status |= CBSTATUS_STENCIL_TEST_ENABLE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002827 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06002828 // Account for any dynamic state not set via this PSO
2829 if (!pPipe->dynStateCI.dynamicStateCount) { // All state is static
2830 pCB->status = CBSTATUS_ALL;
2831 } else {
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002832 // First consider all state on
2833 // Then unset any state that's noted as dynamic in PSO
2834 // Finally OR that into CB statemask
2835 CBStatusFlags psoDynStateMask = CBSTATUS_ALL;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002836 for (uint32_t i=0; i < pPipe->dynStateCI.dynamicStateCount; i++) {
Tobin Ehlis963a4042015-09-29 08:18:34 -06002837 switch (pPipe->dynStateCI.pDynamicStates[i]) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002838 case VK_DYNAMIC_STATE_VIEWPORT:
2839 psoDynStateMask &= ~CBSTATUS_VIEWPORT_SET;
2840 break;
2841 case VK_DYNAMIC_STATE_SCISSOR:
2842 psoDynStateMask &= ~CBSTATUS_SCISSOR_SET;
2843 break;
2844 case VK_DYNAMIC_STATE_LINE_WIDTH:
2845 psoDynStateMask &= ~CBSTATUS_LINE_WIDTH_SET;
2846 break;
2847 case VK_DYNAMIC_STATE_DEPTH_BIAS:
2848 psoDynStateMask &= ~CBSTATUS_DEPTH_BIAS_SET;
2849 break;
2850 case VK_DYNAMIC_STATE_BLEND_CONSTANTS:
2851 psoDynStateMask &= ~CBSTATUS_BLEND_SET;
2852 break;
2853 case VK_DYNAMIC_STATE_DEPTH_BOUNDS:
2854 psoDynStateMask &= ~CBSTATUS_DEPTH_BOUNDS_SET;
2855 break;
2856 case VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK:
2857 psoDynStateMask &= ~CBSTATUS_STENCIL_READ_MASK_SET;
2858 break;
2859 case VK_DYNAMIC_STATE_STENCIL_WRITE_MASK:
2860 psoDynStateMask &= ~CBSTATUS_STENCIL_WRITE_MASK_SET;
2861 break;
2862 case VK_DYNAMIC_STATE_STENCIL_REFERENCE:
2863 psoDynStateMask &= ~CBSTATUS_STENCIL_REFERENCE_SET;
2864 break;
2865 default:
2866 // TODO : Flag error here
2867 break;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002868 }
2869 }
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002870 pCB->status |= psoDynStateMask;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002871 }
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002872}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002873
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002874// Print the last bound Gfx Pipeline
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002875static VkBool32 printPipeline(layer_data* my_data, const VkCommandBuffer cb)
2876{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002877 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002878 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002879 if (pCB) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002880 PIPELINE_NODE *pPipeTrav = getPipeline(my_data, pCB->lastBoundPipeline);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002881 if (!pPipeTrav) {
2882 // nothing to print
Tobin Ehlisce132d82015-06-19 15:07:05 -06002883 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002884 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
2885 "%s", vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002886 }
2887 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002888 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002889}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002890
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002891// Print details of DS config to stdout
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002892static VkBool32 printDSConfig(layer_data* my_data, const VkCommandBuffer cb)
2893{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002894 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002895 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.
2896 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis93f89e82015-06-09 08:39:32 -06002897 if (pCB && pCB->lastBoundDescriptorSet) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002898 SET_NODE* pSet = getSetNode(my_data, pCB->lastBoundDescriptorSet);
2899 DESCRIPTOR_POOL_NODE* pPool = getPoolNode(my_data, pSet->pool);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002900 // Print out pool details
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002901 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
2902 "Details for pool %#" PRIxLEAST64 ".", (uint64_t) pPool->pool);
2903 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
2904 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
2905 "%s", poolStr.c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002906 // Print out set details
2907 char prefix[10];
2908 uint32_t index = 0;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002909 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
2910 "Details for descriptor set %#" PRIxLEAST64 ".", (uint64_t) pSet->set);
2911 LAYOUT_NODE* pLayout = pSet->pLayout;
Tobin Ehlis793ad302015-04-03 12:01:11 -06002912 // Print layout details
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002913 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
2914 "Layout #%u, (object %#" PRIxLEAST64 ") for DS %#" PRIxLEAST64 ".", index+1, (uint64_t)(pLayout->layout), (uint64_t)(pSet->set));
Tobin Ehlis793ad302015-04-03 12:01:11 -06002915 sprintf(prefix, " [L%u] ", index);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002916 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
2917 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
2918 "%s", DSLstr.c_str());
Tobin Ehlis793ad302015-04-03 12:01:11 -06002919 index++;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002920 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002921 if (pUpdate) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002922 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
2923 "Update Chain [UC] for descriptor set %#" PRIxLEAST64 ":", (uint64_t) pSet->set);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002924 sprintf(prefix, " [UC] ");
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002925 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
2926 "%s", dynamic_display(pUpdate, prefix).c_str());
2927 // TODO : If there is a "view" associated with this update, print CI for that view
Tobin Ehlisce132d82015-06-19 15:07:05 -06002928 } else {
Tobin Ehlisbf081f32015-06-15 08:41:17 -06002929 if (0 != pSet->descriptorCount) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002930 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
2931 "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 -06002932 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002933 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
2934 "FYI: No descriptors in descriptor set %#" PRIxLEAST64 ".", (uint64_t) pSet->set);
Tobin Ehlisbf081f32015-06-15 08:41:17 -06002935 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002936 }
2937 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002938 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002939}
2940
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002941static void printCB(layer_data* my_data, const VkCommandBuffer cb)
2942{
2943 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis9a874302016-01-20 10:25:29 -07002944 if (pCB && pCB->cmds.size() > 0) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002945 log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
2946 "Cmds in CB %p", (void*)cb);
Tobin Ehlis9a874302016-01-20 10:25:29 -07002947 vector<CMD_NODE> cmds = pCB->cmds;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002948 for (auto ii=cmds.begin(); ii!=cmds.end(); ++ii) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002949 // TODO : Need to pass cb as srcObj here
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002950 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",
2951 " CMD#%" PRIu64 ": %s", (*ii).cmdNumber, cmdTypeToString((*ii).type).c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002952 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002953 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002954 // Nothing to print
2955 }
2956}
2957
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002958static VkBool32 synchAndPrintDSConfig(layer_data* my_data, const VkCommandBuffer cb)
2959{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002960 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002961 if (!(my_data->report_data->active_flags & VK_DEBUG_REPORT_INFO_BIT_EXT)) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002962 return skipCall;
Mike Stroyanba35e352015-08-12 17:11:28 -06002963 }
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002964 skipCall |= printDSConfig(my_data, cb);
2965 skipCall |= printPipeline(my_data, cb);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002966 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002967}
2968
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002969// Flags validation error if the associated call is made inside a render pass. The apiName
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002970// routine should ONLY be called outside a render pass.
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002971static VkBool32 insideRenderPass(const layer_data* my_data, GLOBAL_CB_NODE *pCB, const char *apiName)
2972{
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002973 VkBool32 inside = VK_FALSE;
2974 if (pCB->activeRenderPass) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002975 inside = log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2976 (uint64_t)pCB->commandBuffer, __LINE__, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2977 "%s: It is invalid to issue this call inside an active render pass (%#" PRIxLEAST64 ")",
2978 apiName, (uint64_t) pCB->activeRenderPass);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002979 }
2980 return inside;
2981}
2982
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002983// Flags validation error if the associated call is made outside a render pass. The apiName
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002984// routine should ONLY be called inside a render pass.
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002985static VkBool32 outsideRenderPass(const layer_data* my_data, GLOBAL_CB_NODE *pCB, const char *apiName)
2986{
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002987 VkBool32 outside = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002988 if (((pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) &&
2989 (!pCB->activeRenderPass)) ||
Mark Lobodzinski74635932015-12-18 15:35:38 -07002990 ((pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) &&
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002991 (!pCB->activeRenderPass) &&
2992 !(pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT))) {
2993 outside = log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2994 (uint64_t)pCB->commandBuffer, __LINE__, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2995 "%s: This call must be issued inside an active render pass.", apiName);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002996 }
2997 return outside;
2998}
2999
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003000static void init_draw_state(layer_data *my_data, const VkAllocationCallbacks *pAllocator)
3001{
Tobin Ehlisa16e8922015-06-16 15:50:44 -06003002 uint32_t report_flags = 0;
3003 uint32_t debug_action = 0;
3004 FILE *log_output = NULL;
3005 const char *option_str;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003006 VkDebugReportCallbackEXT callback;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003007 // initialize DrawState options
Tobin Ehlisa16e8922015-06-16 15:50:44 -06003008 report_flags = getLayerOptionFlags("DrawStateReportFlags", 0);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003009 getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &debug_action);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003010
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003011 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
3012 {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06003013 option_str = getLayerOption("DrawStateLogFilename");
Tobin Ehlisb1df55e2015-09-15 09:55:54 -06003014 log_output = getLayerLogOutput(option_str, "DrawState");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003015 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07003016 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003017 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07003018 dbgInfo.pfnCallback = log_callback;
3019 dbgInfo.pUserData = log_output;
3020 dbgInfo.flags = report_flags;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003021 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06003022 my_data->logging_callback.push_back(callback);
3023 }
3024
3025 if (debug_action & VK_DBG_LAYER_ACTION_DEBUG_OUTPUT) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003026 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07003027 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003028 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07003029 dbgInfo.pfnCallback = win32_debug_output_msg;
3030 dbgInfo.pUserData = log_output;
3031 dbgInfo.flags = report_flags;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003032 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06003033 my_data->logging_callback.push_back(callback);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003034 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003035
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003036 if (!globalLockInitialized)
3037 {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003038 loader_platform_thread_create_mutex(&globalLock);
3039 globalLockInitialized = 1;
3040 }
3041}
3042
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003043VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance)
3044{
3045 VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06003046
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07003047 assert(chain_info->u.pLayerInfo);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003048 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
3049 PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance) fpGetInstanceProcAddr(NULL, "vkCreateInstance");
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07003050 if (fpCreateInstance == NULL) {
3051 return VK_ERROR_INITIALIZATION_FAILED;
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06003052 }
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07003053
3054 // Advance the link info for the next element on the chain
3055 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
3056
3057 VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
3058 if (result != VK_SUCCESS)
3059 return result;
3060
Ian Elliott8c8b2662016-01-30 10:57:03 -07003061 // TBD: Need any locking this early, in case this function is called at the
3062 // same time by more than one thread?
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003063 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07003064 my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003065 layer_init_instance_dispatch_table(*pInstance, my_data->instance_dispatch_table, fpGetInstanceProcAddr);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07003066
3067 my_data->report_data = debug_report_create_instance(
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003068 my_data->instance_dispatch_table,
3069 *pInstance,
3070 pCreateInfo->enabledExtensionCount,
3071 pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07003072
3073 init_draw_state(my_data, pAllocator);
3074
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06003075 return result;
3076}
3077
Jon Ashburn3950e1b2015-05-20 09:00:28 -06003078/* hook DestroyInstance to remove tableInstanceMap entry */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003079VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator)
3080{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003081 // TODOSC : Shouldn't need any customization here
Tobin Ehlisa16e8922015-06-16 15:50:44 -06003082 dispatch_key key = get_dispatch_key(instance);
Ian Elliott8c8b2662016-01-30 10:57:03 -07003083 // TBD: Need any locking this early, in case this function is called at the
3084 // same time by more than one thread?
Tobin Ehlis0b632332015-10-07 09:38:40 -06003085 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
3086 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003087 pTable->DestroyInstance(instance, pAllocator);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06003088
3089 // Clean up logging callback, if any
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06003090 while (my_data->logging_callback.size() > 0) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003091 VkDebugReportCallbackEXT callback = my_data->logging_callback.back();
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07003092 layer_destroy_msg_callback(my_data->report_data, callback, pAllocator);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06003093 my_data->logging_callback.pop_back();
Tobin Ehlisa16e8922015-06-16 15:50:44 -06003094 }
3095
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06003096 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlis0b632332015-10-07 09:38:40 -06003097 delete my_data->instance_dispatch_table;
3098 layer_data_map.erase(key);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003099 // TODO : Potential race here with separate threads creating/destroying instance
Tobin Ehlis0b632332015-10-07 09:38:40 -06003100 if (layer_data_map.empty()) {
Mike Stroyanfcb4ba62015-08-18 15:56:18 -06003101 // Release mutex when destroying last instance.
3102 loader_platform_thread_delete_mutex(&globalLock);
3103 globalLockInitialized = 0;
3104 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06003105}
3106
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003107static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
3108{
Tony Barbour3b4732f2015-07-13 13:37:24 -06003109 uint32_t i;
Ian Elliott8c8b2662016-01-30 10:57:03 -07003110 // TBD: Need any locking, in case this function is called at the same time
3111 // by more than one thread?
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003112 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlis0b632332015-10-07 09:38:40 -06003113 dev_data->device_extensions.debug_marker_enabled = false;
Michael Lentineabc5e922015-10-12 11:30:14 -05003114 dev_data->device_extensions.wsi_enabled = false;
3115
3116
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003117 VkLayerDispatchTable *pDisp = dev_data->device_dispatch_table;
3118 PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr;
3119
3120 pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR) gpa(device, "vkCreateSwapchainKHR");
3121 pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR) gpa(device, "vkDestroySwapchainKHR");
3122 pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR) gpa(device, "vkGetSwapchainImagesKHR");
3123 pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR) gpa(device, "vkAcquireNextImageKHR");
3124 pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR) gpa(device, "vkQueuePresentKHR");
Jon Ashburne68a9ff2015-05-25 14:11:37 -06003125
Jon Ashburnf19916e2016-01-11 13:12:43 -07003126 for (i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003127 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) {
Michael Lentineabc5e922015-10-12 11:30:14 -05003128 dev_data->device_extensions.wsi_enabled = true;
3129 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003130 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
3131 /* Found a matching extension name, mark it enabled and init dispatch table*/
Tobin Ehlis0b632332015-10-07 09:38:40 -06003132 dev_data->device_extensions.debug_marker_enabled = true;
Jon Ashburn1d4b1282015-12-10 19:12:21 -07003133 initDebugMarkerTable(device);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003134
Jon Ashburne68a9ff2015-05-25 14:11:37 -06003135 }
Jon Ashburne68a9ff2015-05-25 14:11:37 -06003136 }
3137}
3138
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003139VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDevice* pDevice)
3140{
3141 VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
Mark Lobodzinski941aea92016-01-13 10:23:15 -07003142
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07003143 assert(chain_info->u.pLayerInfo);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003144 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
3145 PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr;
3146 PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice) fpGetInstanceProcAddr(NULL, "vkCreateDevice");
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07003147 if (fpCreateDevice == NULL) {
3148 return VK_ERROR_INITIALIZATION_FAILED;
Tobin Ehlisa16e8922015-06-16 15:50:44 -06003149 }
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07003150
3151 // Advance the link info for the next element on the chain
3152 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
3153
3154 VkResult result = fpCreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
3155 if (result != VK_SUCCESS) {
3156 return result;
3157 }
3158
Ian Elliott8c8b2662016-01-30 10:57:03 -07003159 // TBD: Need any locking, in case this function is called at the same time
3160 // by more than one thread?
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003161 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
3162 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07003163
3164 // Setup device dispatch table
3165 my_device_data->device_dispatch_table = new VkLayerDispatchTable;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003166 layer_init_device_dispatch_table(*pDevice, my_device_data->device_dispatch_table, fpGetDeviceProcAddr);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07003167
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003168 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07003169 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
3170 // Get physical device limits for this device
Michael Lentine26870f32016-01-26 21:36:08 -06003171 my_instance_data->instance_dispatch_table->GetPhysicalDeviceProperties(gpu, &(my_device_data->physDevProperties.properties));
Michael Lentine7d26c572016-01-28 11:55:28 -06003172 my_instance_data->instance_dispatch_table->GetPhysicalDeviceFeatures(gpu, &(my_device_data->physDevProperties.features));
Michael Lentine26870f32016-01-26 21:36:08 -06003173 uint32_t count;
3174 my_instance_data->instance_dispatch_table->GetPhysicalDeviceQueueFamilyProperties(gpu, &count, nullptr);
3175 my_device_data->physDevProperties.queue_family_properties.resize(count);
3176 my_instance_data->instance_dispatch_table->GetPhysicalDeviceQueueFamilyProperties(gpu, &count, &my_device_data->physDevProperties.queue_family_properties[0]);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003177 return result;
3178}
Tobin Ehlis559c6382015-11-05 09:52:49 -07003179
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06003180// prototype
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003181static void deleteRenderPasses(layer_data*);
3182VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator)
3183{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003184 // TODOSC : Shouldn't need any customization here
Jeremy Hayes5d29ce32015-06-19 11:37:38 -06003185 dispatch_key key = get_dispatch_key(device);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003186 layer_data* dev_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06003187 // Free all the memory
3188 loader_platform_thread_lock_mutex(&globalLock);
3189 deletePipelines(dev_data);
3190 deleteRenderPasses(dev_data);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003191 deleteCommandBuffers(dev_data);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06003192 deletePools(dev_data);
3193 deleteLayouts(dev_data);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003194 dev_data->imageViewMap.clear();
3195 dev_data->imageMap.clear();
3196 dev_data->bufferViewMap.clear();
3197 dev_data->bufferMap.clear();
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06003198 loader_platform_thread_unlock_mutex(&globalLock);
3199
Chia-I Wuf7458c52015-10-26 21:10:41 +08003200 dev_data->device_dispatch_table->DestroyDevice(device, pAllocator);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06003201 tableDebugMarkerMap.erase(key);
Tobin Ehlis0b632332015-10-07 09:38:40 -06003202 delete dev_data->device_dispatch_table;
3203 layer_data_map.erase(key);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003204}
3205
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07003206static const VkExtensionProperties instance_extensions[] = {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003207 {
3208 VK_EXT_DEBUG_REPORT_EXTENSION_NAME,
3209 VK_EXT_DEBUG_REPORT_SPEC_VERSION
3210 }
3211};
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06003212
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003213VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(
3214 const char *pLayerName,
3215 uint32_t *pCount,
3216 VkExtensionProperties* pProperties)
3217{
3218 return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003219}
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06003220
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003221static const VkLayerProperties ds_global_layers[] = {
3222 {
3223 "VK_LAYER_LUNARG_draw_state",
3224 VK_API_VERSION,
3225 VK_MAKE_VERSION(0, 1, 0),
3226 "Validation layer: draw_state",
3227 }
3228};
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07003229
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003230VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(
3231 uint32_t *pCount,
3232 VkLayerProperties* pProperties)
3233{
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003234 return util_GetLayerProperties(ARRAY_SIZE(ds_global_layers),
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003235 ds_global_layers,
3236 pCount, pProperties);
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003237}
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06003238
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003239static const VkExtensionProperties ds_device_extensions[] = {
3240 {
3241 DEBUG_MARKER_EXTENSION_NAME,
3242 VK_MAKE_VERSION(0, 1, 0),
3243 }
3244};
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003245
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003246static const VkLayerProperties ds_device_layers[] = {
3247 {
3248 "VK_LAYER_LUNARG_draw_state",
3249 VK_API_VERSION,
3250 VK_MAKE_VERSION(0, 1, 0),
3251 "Validation layer: draw_state",
3252 }
3253};
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003254
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003255VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(
3256 VkPhysicalDevice physicalDevice,
3257 const char* pLayerName,
3258 uint32_t* pCount,
3259 VkExtensionProperties* pProperties)
3260{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003261 // DrawState does not have any physical device extensions
Jon Ashburn751c4842015-11-02 17:37:20 -07003262 if (pLayerName == NULL) {
3263 dispatch_key key = get_dispatch_key(physicalDevice);
3264 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003265 return my_data->instance_dispatch_table->EnumerateDeviceExtensionProperties(
3266 physicalDevice,
3267 NULL,
3268 pCount,
3269 pProperties);
Jon Ashburn751c4842015-11-02 17:37:20 -07003270 } else {
3271 return util_GetExtensionProperties(ARRAY_SIZE(ds_device_extensions),
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003272 ds_device_extensions,
3273 pCount, pProperties);
Jon Ashburn751c4842015-11-02 17:37:20 -07003274 }
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003275}
3276
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003277VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(
3278 VkPhysicalDevice physicalDevice,
3279 uint32_t* pCount,
3280 VkLayerProperties* pProperties)
3281{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003282 /* DrawState physical device layers are the same as global */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003283 return util_GetLayerProperties(ARRAY_SIZE(ds_device_layers), ds_device_layers,
3284 pCount, pProperties);
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06003285}
3286
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07003287VkBool32 ValidateCmdBufImageLayouts(VkCommandBuffer cmdBuffer) {
Mark Youngb20a6a82016-01-07 15:41:43 -07003288 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003289 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
3290 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Michael Lentineabc5e922015-10-12 11:30:14 -05003291 for (auto cb_image_data : pCB->imageLayoutMap) {
3292 auto image_data = dev_data->imageLayoutMap.find(cb_image_data.first);
3293 if (image_data == dev_data->imageLayoutMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003294 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",
3295 "Cannot submit cmd buffer using deleted image %" PRIu64 ".", (uint64_t)(cb_image_data.first));
Michael Lentineabc5e922015-10-12 11:30:14 -05003296 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003297 if (dev_data->imageLayoutMap[cb_image_data.first]->layout != cb_image_data.second.initialLayout) {
3298 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",
3299 "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 -05003300 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003301 dev_data->imageLayoutMap[cb_image_data.first]->layout = cb_image_data.second.layout;
Michael Lentineabc5e922015-10-12 11:30:14 -05003302 }
3303 }
3304 return skip_call;
3305}
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003306// Track which resources are in-flight by atomically incrementing their "in_use" count
3307VkBool32 validateAndIncrementResources(layer_data* my_data, GLOBAL_CB_NODE* pCB) {
Mark Youngb20a6a82016-01-07 15:41:43 -07003308 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003309 for (auto drawDataElement : pCB->drawData) {
3310 for (auto buffer : drawDataElement.buffers) {
3311 auto buffer_data = my_data->bufferMap.find(buffer);
3312 if (buffer_data == my_data->bufferMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003313 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",
3314 "Cannot submit cmd buffer using deleted buffer %" PRIu64 ".", (uint64_t)(buffer));
Michael Lentine700b0aa2015-10-30 17:57:32 -07003315 } else {
3316 buffer_data->second.in_use.fetch_add(1);
3317 }
3318 }
3319 }
Tobin Ehlise6e574b2016-01-24 23:25:31 -07003320 for (auto set : pCB->uniqueBoundSets) {
3321 auto setNode = my_data->setMap.find(set);
3322 if (setNode == my_data->setMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003323 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",
3324 "Cannot submit cmd buffer using deleted descriptor set %" PRIu64 ".", (uint64_t)(set));
Tobin Ehlise6e574b2016-01-24 23:25:31 -07003325 } else {
3326 setNode->second->in_use.fetch_add(1);
3327 }
3328 }
Michael Lentine2e068b22015-12-29 16:05:27 -06003329 return skip_call;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003330}
3331
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003332void decrementResources(layer_data* my_data, VkCommandBuffer cmdBuffer) {
3333 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cmdBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07003334 for (auto drawDataElement : pCB->drawData) {
3335 for (auto buffer : drawDataElement.buffers) {
3336 auto buffer_data = my_data->bufferMap.find(buffer);
3337 if (buffer_data != my_data->bufferMap.end()) {
3338 buffer_data->second.in_use.fetch_sub(1);
3339 }
3340 }
3341 }
Tobin Ehlise6e574b2016-01-24 23:25:31 -07003342 for (auto set : pCB->uniqueBoundSets) {
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07003343 auto setNode = my_data->setMap.find(set);
3344 if (setNode != my_data->setMap.end()) {
3345 setNode->second->in_use.fetch_sub(1);
3346 }
3347 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003348 for (auto queryStatePair : pCB->queryToStateMap) {
3349 my_data->queryToStateMap[queryStatePair.first] = queryStatePair.second;
3350 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003351}
3352
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003353void decrementResources(layer_data* my_data, uint32_t fenceCount, const VkFence* pFences) {
Michael Lentine700b0aa2015-10-30 17:57:32 -07003354 for (uint32_t i = 0; i < fenceCount; ++i) {
3355 auto fence_data = my_data->fenceMap.find(pFences[i]);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003356 if (fence_data == my_data->fenceMap.end() || !fence_data->second.needsSignaled) return;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003357 fence_data->second.needsSignaled = false;
Michael Lentine37767342016-02-02 22:24:26 -06003358 fence_data->second.in_use.fetch_sub(1);
Michael Lentine700b0aa2015-10-30 17:57:32 -07003359 if (fence_data->second.priorFence != VK_NULL_HANDLE) {
3360 decrementResources(my_data, 1, &fence_data->second.priorFence);
3361 }
3362 for (auto cmdBuffer : fence_data->second.cmdBuffers) {
3363 decrementResources(my_data, cmdBuffer);
3364 }
3365 }
3366}
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07003367
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003368void decrementResources(layer_data* my_data, VkQueue queue) {
Michael Lentine700b0aa2015-10-30 17:57:32 -07003369 auto queue_data = my_data->queueMap.find(queue);
3370 if (queue_data != my_data->queueMap.end()) {
3371 for (auto cmdBuffer : queue_data->second.untrackedCmdBuffers) {
3372 decrementResources(my_data, cmdBuffer);
3373 }
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07003374 queue_data->second.untrackedCmdBuffers.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07003375 decrementResources(my_data, 1, &queue_data->second.priorFence);
3376 }
3377}
3378
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003379void trackCommandBuffers(layer_data* my_data, VkQueue queue, uint32_t cmdBufferCount, const VkCommandBuffer* pCmdBuffers, VkFence fence) {
Michael Lentine700b0aa2015-10-30 17:57:32 -07003380 auto queue_data = my_data->queueMap.find(queue);
3381 if (fence != VK_NULL_HANDLE) {
3382 VkFence priorFence = VK_NULL_HANDLE;
Michael Lentine37767342016-02-02 22:24:26 -06003383 auto fence_data = my_data->fenceMap.find(fence);
3384 if (fence_data == my_data->fenceMap.end()) {
3385 return;
3386 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003387 if (queue_data != my_data->queueMap.end()) {
3388 priorFence = queue_data->second.priorFence;
3389 queue_data->second.priorFence = fence;
3390 for (auto cmdBuffer : queue_data->second.untrackedCmdBuffers) {
Michael Lentine37767342016-02-02 22:24:26 -06003391 fence_data->second.cmdBuffers.push_back(cmdBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07003392 }
3393 queue_data->second.untrackedCmdBuffers.clear();
3394 }
Michael Lentine37767342016-02-02 22:24:26 -06003395 fence_data->second.cmdBuffers.clear();
3396 fence_data->second.priorFence = priorFence;
3397 fence_data->second.needsSignaled = true;
3398 fence_data->second.queue = queue;
3399 fence_data->second.in_use.fetch_add(1);
Michael Lentine700b0aa2015-10-30 17:57:32 -07003400 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
Michael Lentine37767342016-02-02 22:24:26 -06003401 for (auto secondaryCmdBuffer :
3402 my_data->commandBufferMap[pCmdBuffers[i]]
3403 ->secondaryCommandBuffers) {
3404 fence_data->second.cmdBuffers.push_back(
3405 secondaryCmdBuffer);
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003406 }
Michael Lentine37767342016-02-02 22:24:26 -06003407 fence_data->second.cmdBuffers.push_back(pCmdBuffers[i]);
Michael Lentine700b0aa2015-10-30 17:57:32 -07003408 }
3409 } else {
3410 if (queue_data != my_data->queueMap.end()) {
3411 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003412 for (auto secondaryCmdBuffer : my_data->commandBufferMap[pCmdBuffers[i]]->secondaryCommandBuffers) {
3413 queue_data->second.untrackedCmdBuffers.push_back(secondaryCmdBuffer);
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003414 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003415 queue_data->second.untrackedCmdBuffers.push_back(pCmdBuffers[i]);
Michael Lentine700b0aa2015-10-30 17:57:32 -07003416 }
3417 }
3418 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003419 if (queue_data != my_data->queueMap.end()) {
3420 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003421 // Add cmdBuffers to both the global set and queue set
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003422 for (auto secondaryCmdBuffer : my_data->commandBufferMap[pCmdBuffers[i]]->secondaryCommandBuffers) {
Tobin Ehlis74714d22016-01-25 15:24:34 -08003423 my_data->globalInFlightCmdBuffers.insert(secondaryCmdBuffer);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003424 queue_data->second.inFlightCmdBuffers.insert(secondaryCmdBuffer);
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003425 }
Tobin Ehlis74714d22016-01-25 15:24:34 -08003426 my_data->globalInFlightCmdBuffers.insert(pCmdBuffers[i]);
3427 queue_data->second.inFlightCmdBuffers.insert(pCmdBuffers[i]);
3428 }
3429 }
3430}
3431
Michael Lentinec7cf9182016-02-03 09:20:33 -06003432bool validateCommandBufferSimultaneousUse(layer_data *dev_data,
3433 GLOBAL_CB_NODE *pCB) {
3434 bool skip_call = false;
3435 if (dev_data->globalInFlightCmdBuffers.count(pCB->commandBuffer) &&
3436 !(pCB->beginInfo.flags &
3437 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT)) {
3438 skip_call |= log_msg(
3439 dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
3440 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__,
3441 DRAWSTATE_INVALID_FENCE, "DS",
3442 "Command Buffer %#" PRIx64 " is already in use and is not marked "
3443 "for simultaneous use.",
3444 reinterpret_cast<uint64_t>(pCB->commandBuffer));
3445 }
3446 return skip_call;
3447}
3448
3449static VkBool32 validateCommandBufferState(layer_data *dev_data,
3450 GLOBAL_CB_NODE *pCB) {
Tobin Ehlis74714d22016-01-25 15:24:34 -08003451 // Track in-use for resources off of primary and any secondary CBs
3452 VkBool32 skipCall = validateAndIncrementResources(dev_data, pCB);
3453 if (!pCB->secondaryCommandBuffers.empty()) {
3454 for (auto secondaryCmdBuffer : pCB->secondaryCommandBuffers) {
Michael Lentinec7cf9182016-02-03 09:20:33 -06003455 skipCall |= validateAndIncrementResources(
3456 dev_data, dev_data->commandBufferMap[secondaryCmdBuffer]);
3457 GLOBAL_CB_NODE* pSubCB = getCBNode(dev_data, secondaryCmdBuffer);
3458 skipCall |= validateCommandBufferSimultaneousUse(dev_data, pSubCB);
Michael Lentined7621bb2016-02-03 10:55:23 -06003459 if (pSubCB->primaryCommandBuffer != pCB->commandBuffer) {
3460 log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
3461 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0,
3462 __LINE__,
3463 DRAWSTATE_COMMAND_BUFFER_SINGLE_SUBMIT_VIOLATION, "DS",
3464 "CB %#" PRIxLEAST64
3465 " was submitted with secondary buffer %#" PRIxLEAST64
3466 " but that buffer has subsequently been bound to "
3467 "primary cmd buffer %#" PRIxLEAST64 ".",
3468 reinterpret_cast<uint64_t>(pCB->commandBuffer),
3469 reinterpret_cast<uint64_t>(secondaryCmdBuffer),
3470 reinterpret_cast<uint64_t>(
3471 pSubCB->primaryCommandBuffer));
3472 }
Tobin Ehlis74714d22016-01-25 15:24:34 -08003473 }
3474 }
Michael Lentinec7cf9182016-02-03 09:20:33 -06003475 if ((pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT) &&
3476 (pCB->submitCount > 1)) {
3477 skipCall |=
3478 log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
3479 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__,
3480 DRAWSTATE_COMMAND_BUFFER_SINGLE_SUBMIT_VIOLATION, "DS",
3481 "CB %#" PRIxLEAST64
3482 " was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT "
3483 "set, but has been submitted %#" PRIxLEAST64 " times.",
3484 (uint64_t)(pCB->commandBuffer), pCB->submitCount);
Tobin Ehlis74714d22016-01-25 15:24:34 -08003485 }
3486 // Validate that cmd buffers have been updated
3487 if (CB_RECORDED != pCB->state) {
3488 if (CB_INVALID == pCB->state) {
3489 // Inform app of reason CB invalid
3490 if (!pCB->destroyedSets.empty()) {
3491 std::stringstream set_string;
3492 for (auto set : pCB->destroyedSets) {
3493 set_string << " " << set;
3494 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003495 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",
3496 "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 -08003497 }
3498 if (!pCB->updatedSets.empty()) {
3499 std::stringstream set_string;
3500 for (auto set : pCB->updatedSets) {
3501 set_string << " " << set;
3502 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003503 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",
3504 "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 -08003505 }
3506 } else { // Flag error for using CB w/o vkEndCommandBuffer() called
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003507 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",
3508 "You must call vkEndCommandBuffer() on CB %#" PRIxLEAST64 " before this call to vkQueueSubmit()!", (uint64_t)(pCB->commandBuffer));
Tobin Ehlis74714d22016-01-25 15:24:34 -08003509 }
3510 }
Michael Lentine0998ede2016-02-03 14:26:30 -06003511 return skipCall;
3512}
3513
3514static VkBool32 validatePrimaryCommandBufferState(layer_data *dev_data,
3515 GLOBAL_CB_NODE *pCB) {
3516 // Track in-use for resources off of primary and any secondary CBs
3517 VkBool32 skipCall = validateAndIncrementResources(dev_data, pCB);
3518 if (!pCB->secondaryCommandBuffers.empty()) {
3519 for (auto secondaryCmdBuffer : pCB->secondaryCommandBuffers) {
3520 skipCall |= validateAndIncrementResources(
3521 dev_data, dev_data->commandBufferMap[secondaryCmdBuffer]);
3522 }
3523 }
3524 if ((pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT) &&
3525 (pCB->submitCount > 1)) {
3526 skipCall |=
3527 log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
3528 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__,
3529 DRAWSTATE_COMMAND_BUFFER_SINGLE_SUBMIT_VIOLATION, "DS",
3530 "CB %#" PRIxLEAST64
3531 " was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT "
3532 "set, but has been submitted %#" PRIxLEAST64 " times.",
3533 (uint64_t)(pCB->commandBuffer), pCB->submitCount);
3534 }
3535 validateCommandBufferState(dev_data, pCB);
Michael Lentinec7cf9182016-02-03 09:20:33 -06003536 // If USAGE_SIMULTANEOUS_USE_BIT not set then CB cannot already be executing
3537 // on device
3538 skipCall |= validateCommandBufferSimultaneousUse(dev_data, pCB);
Tobin Ehlisceb0b862016-02-01 06:50:57 -08003539 return skipCall;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003540}
3541
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003542VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence fence)
3543{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003544 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003545 GLOBAL_CB_NODE* pCB = NULL;
3546 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07003547 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003548 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08003549 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003550 for (uint32_t i=0; i < submit->waitSemaphoreCount; ++i) {
Michael Lentine15a47882016-01-06 10:05:48 -06003551 if (dev_data->semaphoreSignaledMap[submit->pWaitSemaphores[i]]) {
3552 dev_data->semaphoreSignaledMap[submit->pWaitSemaphores[i]] = 0;
3553 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003554 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",
3555 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
3556 (uint64_t)(queue), (uint64_t)(submit->pWaitSemaphores[i]));
Michael Lentine15a47882016-01-06 10:05:48 -06003557 }
3558 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003559 for (uint32_t i=0; i < submit->signalSemaphoreCount; ++i) {
Michael Lentine15a47882016-01-06 10:05:48 -06003560 dev_data->semaphoreSignaledMap[submit->pSignalSemaphores[i]] = 1;
3561 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003562 for (uint32_t i=0; i < submit->commandBufferCount; i++) {
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07003563#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
Ian Elliott8c8b2662016-01-30 10:57:03 -07003564 skipCall |= ValidateCmdBufImageLayouts(submit->pCommandBuffers[i]);
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07003565#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
3566
Ian Elliott8c8b2662016-01-30 10:57:03 -07003567 pCB = getCBNode(dev_data, submit->pCommandBuffers[i], false);
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003568 pCB->submitCount++; // increment submit count
Michael Lentine0998ede2016-02-03 14:26:30 -06003569 skipCall |= validatePrimaryCommandBufferState(dev_data, pCB);
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06003570 }
Michael Lentine37767342016-02-02 22:24:26 -06003571 if (dev_data->fenceMap[fence].in_use.load()) {
3572 skipCall |= log_msg(
3573 dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
3574 VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT,
Dustin Graves962b01e2016-02-04 11:38:48 -07003575 (uint64_t)(fence), __LINE__,
Michael Lentine37767342016-02-02 22:24:26 -06003576 DRAWSTATE_INVALID_FENCE, "DS",
3577 "Fence %#" PRIx64 " is already in use by another submission.",
Dustin Graves962b01e2016-02-04 11:38:48 -07003578 (uint64_t)(fence));
Michael Lentine37767342016-02-02 22:24:26 -06003579 }
3580 trackCommandBuffers(dev_data, queue, submit->commandBufferCount,
3581 submit->pCommandBuffers, fence);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003582 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07003583 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003584 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003585 return dev_data->device_dispatch_table->QueueSubmit(queue, submitCount, pSubmits, fence);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003586 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003587}
3588
Ian Elliott8c8b2662016-01-30 10:57:03 -07003589// Note: This function assumes that the global lock is held by the calling
3590// thread.
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003591VkBool32 cleanInFlightCmdBuffer(layer_data* my_data, VkCommandBuffer cmdBuffer) {
Mark Youngb20a6a82016-01-07 15:41:43 -07003592 VkBool32 skip_call = VK_FALSE;
Ian Elliott8c8b2662016-01-30 10:57:03 -07003593 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cmdBuffer, false);
Mark Lobodzinskia9e7c042016-01-25 14:27:49 -07003594 if (pCB) {
3595 for (auto queryEventsPair : pCB->waitedEventsBeforeQueryReset) {
3596 for (auto event : queryEventsPair.second) {
3597 if (my_data->eventMap[event].needsSignaled) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003598 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",
3599 "Cannot get query results on queryPool %" PRIu64 " with index %d which was guarded by unsignaled event %" PRIu64 ".",
3600 (uint64_t)(queryEventsPair.first.pool), queryEventsPair.first.index, (uint64_t)(event));
Mark Lobodzinskia9e7c042016-01-25 14:27:49 -07003601 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003602 }
3603 }
3604 }
3605 return skip_call;
3606}
Tobin Ehlis74714d22016-01-25 15:24:34 -08003607// Remove given cmd_buffer from the global inFlight set.
3608// Also, if given queue is valid, then remove the cmd_buffer from that queues
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003609// inFlightCmdBuffer set. Finally, check all other queues and if given cmd_buffer
Tobin Ehlis74714d22016-01-25 15:24:34 -08003610// is still in flight on another queue, add it back into the global set.
Ian Elliott8c8b2662016-01-30 10:57:03 -07003611// Note: This function assumes that the global lock is held by the calling
3612// thread.
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003613static inline void removeInFlightCmdBuffer(layer_data* dev_data, VkCommandBuffer cmd_buffer, VkQueue queue)
3614{
3615 // 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 -08003616 dev_data->globalInFlightCmdBuffers.erase(cmd_buffer);
3617 if (dev_data->queueMap.find(queue) != dev_data->queueMap.end()) {
3618 dev_data->queueMap[queue].inFlightCmdBuffers.erase(cmd_buffer);
3619 for (auto q : dev_data->queues) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003620 if ((q != queue) && (dev_data->queueMap[q].inFlightCmdBuffers.find(cmd_buffer) != dev_data->queueMap[q].inFlightCmdBuffers.end())) {
Tobin Ehlis74714d22016-01-25 15:24:34 -08003621 dev_data->globalInFlightCmdBuffers.insert(cmd_buffer);
3622 break;
3623 }
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003624 }
3625 }
3626}
Michael Lentineb887b0a2015-12-29 14:12:11 -06003627
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003628VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence* pFences, VkBool32 waitAll, uint64_t timeout)
3629{
3630 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3631 VkResult result = dev_data->device_dispatch_table->WaitForFences(device, fenceCount, pFences, waitAll, timeout);
Mark Youngb20a6a82016-01-07 15:41:43 -07003632 VkBool32 skip_call = VK_FALSE;
Ian Elliott8c8b2662016-01-30 10:57:03 -07003633 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis74714d22016-01-25 15:24:34 -08003634 if (result == VK_SUCCESS) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003635 // When we know that all fences are complete we can clean/remove their CBs
Tobin Ehlis74714d22016-01-25 15:24:34 -08003636 if (waitAll || fenceCount == 1) {
3637 for (uint32_t i = 0; i < fenceCount; ++i) {
3638 VkQueue fence_queue = dev_data->fenceMap[pFences[i]].queue;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003639 for (auto cmdBuffer : dev_data->fenceMap[pFences[i]].cmdBuffers) {
Tobin Ehlis74714d22016-01-25 15:24:34 -08003640 skip_call |= cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3641 removeInFlightCmdBuffer(dev_data, cmdBuffer, fence_queue);
3642 }
3643 }
3644 decrementResources(dev_data, fenceCount, pFences);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003645 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003646 // NOTE : Alternate case not handled here is when some fences have completed. In
3647 // this case for app to guarantee which fences completed it will have to call
3648 // vkGetFenceStatus() at which point we'll clean/remove their CBs if complete.
Michael Lentine700b0aa2015-10-30 17:57:32 -07003649 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07003650 loader_platform_thread_unlock_mutex(&globalLock);
Mark Youngb20a6a82016-01-07 15:41:43 -07003651 if (VK_FALSE != skip_call)
Mark Lobodzinskice738852016-01-07 10:04:02 -07003652 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003653 return result;
3654}
3655
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003656
3657VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetFenceStatus(VkDevice device, VkFence fence)
3658{
3659 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3660 VkResult result = dev_data->device_dispatch_table->GetFenceStatus(device, fence);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003661 VkBool32 skip_call = VK_FALSE;
Ian Elliott8c8b2662016-01-30 10:57:03 -07003662 loader_platform_thread_lock_mutex(&globalLock);
Michael Lentine700b0aa2015-10-30 17:57:32 -07003663 if (result == VK_SUCCESS) {
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003664 auto fence_queue = dev_data->fenceMap[fence].queue;
Michael Lentineb887b0a2015-12-29 14:12:11 -06003665 for (auto cmdBuffer : dev_data->fenceMap[fence].cmdBuffers) {
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003666 skip_call |= cleanInFlightCmdBuffer(dev_data, cmdBuffer);
Tobin Ehlis74714d22016-01-25 15:24:34 -08003667 removeInFlightCmdBuffer(dev_data, cmdBuffer, fence_queue);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003668 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003669 decrementResources(dev_data, 1, &fence);
3670 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07003671 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003672 if (VK_FALSE != skip_call)
3673 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003674 return result;
3675}
3676
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003677VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue* pQueue)
3678{
3679 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07003680 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003681 dev_data->device_dispatch_table->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003682 dev_data->queues.push_back(*pQueue);
Michael Lentine700b0aa2015-10-30 17:57:32 -07003683 dev_data->queueMap[*pQueue].device = device;
Ian Elliott8c8b2662016-01-30 10:57:03 -07003684 loader_platform_thread_unlock_mutex(&globalLock);
Michael Lentine700b0aa2015-10-30 17:57:32 -07003685}
3686
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003687VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueueWaitIdle(VkQueue queue)
3688{
3689 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Michael Lentine700b0aa2015-10-30 17:57:32 -07003690 decrementResources(dev_data, queue);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003691 VkBool32 skip_call = VK_FALSE;
Ian Elliott8c8b2662016-01-30 10:57:03 -07003692 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003693 // Iterate over local set since we erase set members as we go in for loop
3694 auto local_cb_set = dev_data->queueMap[queue].inFlightCmdBuffers;
3695 for (auto cmdBuffer : local_cb_set) {
3696 skip_call |= cleanInFlightCmdBuffer(dev_data, cmdBuffer);
Tobin Ehlis74714d22016-01-25 15:24:34 -08003697 removeInFlightCmdBuffer(dev_data, cmdBuffer, queue);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003698 }
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003699 dev_data->queueMap[queue].inFlightCmdBuffers.clear();
Ian Elliott8c8b2662016-01-30 10:57:03 -07003700 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003701 if (VK_FALSE != skip_call)
3702 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003703 return dev_data->device_dispatch_table->QueueWaitIdle(queue);
3704}
3705
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003706VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkDeviceWaitIdle(VkDevice device)
3707{
Tobin Ehlis74714d22016-01-25 15:24:34 -08003708 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003709 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07003710 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003711 for (auto queue : dev_data->queues) {
3712 decrementResources(dev_data, queue);
Tobin Ehlis74714d22016-01-25 15:24:34 -08003713 if (dev_data->queueMap.find(queue) != dev_data->queueMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003714 // Clear all of the queue inFlightCmdBuffers (global set cleared below)
Tobin Ehlis74714d22016-01-25 15:24:34 -08003715 dev_data->queueMap[queue].inFlightCmdBuffers.clear();
3716 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003717 }
Tobin Ehlis74714d22016-01-25 15:24:34 -08003718 for (auto cmdBuffer : dev_data->globalInFlightCmdBuffers) {
3719 skip_call |= cleanInFlightCmdBuffer(dev_data, cmdBuffer);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003720 }
Tobin Ehlis74714d22016-01-25 15:24:34 -08003721 dev_data->globalInFlightCmdBuffers.clear();
Ian Elliott8c8b2662016-01-30 10:57:03 -07003722 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis74714d22016-01-25 15:24:34 -08003723 if (VK_FALSE != skip_call)
3724 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003725 return dev_data->device_dispatch_table->DeviceWaitIdle(device);
3726}
3727
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003728VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks* pAllocator)
3729{
3730 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 -06003731 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003732}
3733
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003734VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySemaphore(VkDevice device, VkSemaphore semaphore, const VkAllocationCallbacks* pAllocator)
3735{
3736 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3737 dev_data->device_dispatch_table->DestroySemaphore(device, semaphore, pAllocator);
Ian Elliott8c8b2662016-01-30 10:57:03 -07003738 loader_platform_thread_lock_mutex(&globalLock);
Michael Lentine15a47882016-01-06 10:05:48 -06003739 dev_data->semaphoreSignaledMap.erase(semaphore);
Ian Elliott8c8b2662016-01-30 10:57:03 -07003740 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003741 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003742}
3743
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003744VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks* pAllocator)
3745{
3746 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 -06003747 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003748}
3749
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003750VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool, const VkAllocationCallbacks* pAllocator)
3751{
3752 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 -06003753 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003754}
3755
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003756VKAPI_ATTR VkResult VKAPI_CALL vkGetQueryPoolResults(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount,
3757 size_t dataSize, void* pData, VkDeviceSize stride, VkQueryResultFlags flags) {
3758 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003759 unordered_map<QueryObject, vector<VkCommandBuffer>> queriesInFlight;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003760 GLOBAL_CB_NODE* pCB = nullptr;
Ian Elliott8c8b2662016-01-30 10:57:03 -07003761 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis74714d22016-01-25 15:24:34 -08003762 for (auto cmdBuffer : dev_data->globalInFlightCmdBuffers) {
Ian Elliott8c8b2662016-01-30 10:57:03 -07003763 pCB = getCBNode(dev_data, cmdBuffer, false);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003764 for (auto queryStatePair : pCB->queryToStateMap) {
3765 queriesInFlight[queryStatePair.first].push_back(cmdBuffer);
3766 }
3767 }
Mark Youngb20a6a82016-01-07 15:41:43 -07003768 VkBool32 skip_call = VK_FALSE;
Michael Lentineb887b0a2015-12-29 14:12:11 -06003769 for (uint32_t i = 0; i < queryCount; ++i) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003770 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06003771 auto queryElement = queriesInFlight.find(query);
3772 auto queryToStateElement = dev_data->queryToStateMap.find(query);
3773 if (queryToStateElement != dev_data->queryToStateMap.end()) {
3774 }
3775 // Available and in flight
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003776 if(queryElement != queriesInFlight.end() && queryToStateElement != dev_data->queryToStateMap.end() && queryToStateElement->second) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06003777 for (auto cmdBuffer : queryElement->second) {
Ian Elliott8c8b2662016-01-30 10:57:03 -07003778 pCB = getCBNode(dev_data, cmdBuffer, false);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003779 auto queryEventElement = pCB->waitedEventsBeforeQueryReset.find(query);
3780 if (queryEventElement == pCB->waitedEventsBeforeQueryReset.end()) {
3781 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT, 0, __LINE__,
3782 DRAWSTATE_INVALID_QUERY, "DS", "Cannot get query results on queryPool %" PRIu64 " with index %d which is in flight.",
3783 (uint64_t)(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003784 } else {
3785 for (auto event : queryEventElement->second) {
3786 dev_data->eventMap[event].needsSignaled = true;
3787 }
3788 }
3789 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003790 // Unavailable and in flight
3791 } else if (queryElement != queriesInFlight.end() && queryToStateElement != dev_data->queryToStateMap.end() && !queryToStateElement->second) {
3792 // TODO : Can there be the same query in use by multiple command buffers in flight?
Michael Lentineb887b0a2015-12-29 14:12:11 -06003793 bool make_available = false;
3794 for (auto cmdBuffer : queryElement->second) {
Ian Elliott8c8b2662016-01-30 10:57:03 -07003795 pCB = getCBNode(dev_data, cmdBuffer, false);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003796 make_available |= pCB->queryToStateMap[query];
3797 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003798 if (!(((flags & VK_QUERY_RESULT_PARTIAL_BIT) || (flags & VK_QUERY_RESULT_WAIT_BIT)) && make_available)) {
3799 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",
3800 "Cannot get query results on queryPool %" PRIu64 " with index %d which is unavailable.",
3801 (uint64_t)(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003802 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003803 // Unavailable
3804 } else if (queryToStateElement != dev_data->queryToStateMap.end() && !queryToStateElement->second) {
3805 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",
3806 "Cannot get query results on queryPool %" PRIu64 " with index %d which is unavailable.",
3807 (uint64_t)(queryPool), firstQuery + i);
3808 // Unitialized
Michael Lentineb887b0a2015-12-29 14:12:11 -06003809 } else if (queryToStateElement == dev_data->queryToStateMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003810 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",
3811 "Cannot get query results on queryPool %" PRIu64 " with index %d which is uninitialized.",
3812 (uint64_t)(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003813 }
3814 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07003815 loader_platform_thread_unlock_mutex(&globalLock);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003816 if (skip_call)
Mark Lobodzinskice738852016-01-07 10:04:02 -07003817 return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003818 return dev_data->device_dispatch_table->GetQueryPoolResults(device, queryPool, firstQuery, queryCount, dataSize, pData, stride, flags);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003819}
3820
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003821VkBool32 validateIdleBuffer(const layer_data* my_data, VkBuffer buffer) {
Mark Youngb20a6a82016-01-07 15:41:43 -07003822 VkBool32 skip_call = VK_FALSE;
Ian Elliott8c8b2662016-01-30 10:57:03 -07003823 loader_platform_thread_lock_mutex(&globalLock);
Michael Lentine700b0aa2015-10-30 17:57:32 -07003824 auto buffer_data = my_data->bufferMap.find(buffer);
3825 if (buffer_data == my_data->bufferMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003826 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",
3827 "Cannot free buffer %" PRIxLEAST64 " that has not been allocated.", (uint64_t)(buffer));
Michael Lentine700b0aa2015-10-30 17:57:32 -07003828 } else {
3829 if (buffer_data->second.in_use.load()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003830 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",
3831 "Cannot free buffer %" PRIxLEAST64 " that is in use by a command buffer.", (uint64_t)(buffer));
Michael Lentine700b0aa2015-10-30 17:57:32 -07003832 }
3833 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07003834 loader_platform_thread_unlock_mutex(&globalLock);
Michael Lentine700b0aa2015-10-30 17:57:32 -07003835 return skip_call;
3836}
3837
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003838VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks* pAllocator)
3839{
3840 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07003841 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003842 if (!validateIdleBuffer(dev_data, buffer)) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003843 dev_data->device_dispatch_table->DestroyBuffer(device, buffer, pAllocator);
Michael Lentine700b0aa2015-10-30 17:57:32 -07003844 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07003845 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003846 dev_data->bufferMap.erase(buffer);
Ian Elliott8c8b2662016-01-30 10:57:03 -07003847 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003848}
3849
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003850VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBufferView(VkDevice device, VkBufferView bufferView, const VkAllocationCallbacks* pAllocator)
3851{
3852 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3853 dev_data->device_dispatch_table->DestroyBufferView(device, bufferView, pAllocator);
Ian Elliott8c8b2662016-01-30 10:57:03 -07003854 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003855 dev_data->bufferViewMap.erase(bufferView);
Ian Elliott8c8b2662016-01-30 10:57:03 -07003856 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003857}
3858
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003859VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks* pAllocator)
3860{
3861 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003862 dev_data->device_dispatch_table->DestroyImage(device, image, pAllocator);
Ian Elliott8c8b2662016-01-30 10:57:03 -07003863 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003864 dev_data->imageMap.erase(image);
Ian Elliott8c8b2662016-01-30 10:57:03 -07003865 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003866}
3867
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003868VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyImageView(VkDevice device, VkImageView imageView, const VkAllocationCallbacks* pAllocator)
3869{
3870 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 -06003871 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003872}
3873
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003874VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule, const VkAllocationCallbacks* pAllocator)
3875{
3876 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 -06003877 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003878}
3879
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003880VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyPipeline(VkDevice device, VkPipeline pipeline, const VkAllocationCallbacks* pAllocator)
3881{
3882 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 -06003883 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003884}
3885
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003886VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout, const VkAllocationCallbacks* pAllocator)
3887{
3888 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 -06003889 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003890}
3891
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003892VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySampler(VkDevice device, VkSampler sampler, const VkAllocationCallbacks* pAllocator)
3893{
3894 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 -06003895 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003896}
3897
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003898VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout, const VkAllocationCallbacks* pAllocator)
3899{
3900 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 -06003901 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003902}
3903
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003904VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, const VkAllocationCallbacks* pAllocator)
3905{
3906 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 -06003907 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003908}
3909
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003910VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t count, const VkCommandBuffer *pCommandBuffers)
3911{
3912 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003913
Michael Lentine5f6dc4f2016-01-27 20:42:07 -06003914 bool skip_call = false;
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07003915 for (uint32_t i = 0; i < count; i++) {
Tobin Ehlis74714d22016-01-25 15:24:34 -08003916 loader_platform_thread_lock_mutex(&globalLock);
Michael Lentine5f6dc4f2016-01-27 20:42:07 -06003917 if (dev_data->globalInFlightCmdBuffers.count(pCommandBuffers[i])) {
3918 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
3919 reinterpret_cast<uint64_t>(pCommandBuffers[i]), __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
3920 "Attempt to free command buffer (%#" PRIxLEAST64 ") which is in use.", reinterpret_cast<uint64_t>(pCommandBuffers[i]));
3921 }
Mark Lobodzinski39298632015-11-18 08:38:27 -07003922 // Delete CB information structure, and remove from commandBufferMap
3923 auto cb = dev_data->commandBufferMap.find(pCommandBuffers[i]);
3924 if (cb != dev_data->commandBufferMap.end()) {
Tobin Ehlise6e574b2016-01-24 23:25:31 -07003925 // reset prior to delete for data clean-up
3926 resetCB(dev_data, (*cb).second->commandBuffer);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003927 delete (*cb).second;
3928 dev_data->commandBufferMap.erase(cb);
3929 }
3930
3931 // Remove commandBuffer reference from commandPoolMap
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003932 dev_data->commandPoolMap[commandPool].commandBuffers.remove(pCommandBuffers[i]);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003933 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003934 }
3935
Michael Lentine5f6dc4f2016-01-27 20:42:07 -06003936 if (!skip_call)
3937 dev_data->device_dispatch_table->FreeCommandBuffers(device, commandPool, count, pCommandBuffers);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003938}
3939
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003940VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkCommandPool* pCommandPool)
3941{
3942 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003943
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003944 VkResult result = dev_data->device_dispatch_table->CreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003945
3946 if (VK_SUCCESS == result) {
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003947 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003948 dev_data->commandPoolMap[*pCommandPool].createFlags = pCreateInfo->flags;
Michael Lentined1b2a8b2016-02-03 21:20:25 -06003949 dev_data->commandPoolMap[*pCommandPool].queueFamilyIndex = pCreateInfo->queueFamilyIndex;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003950 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003951 }
3952 return result;
3953}
Michael Lentinee063fe42016-01-27 17:52:20 -06003954
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003955VkBool32 validateCommandBuffersNotInUse(const layer_data* dev_data, VkCommandPool commandPool) {
Mark Youngbaa677f2016-01-28 09:36:15 -07003956 VkBool32 skipCall = VK_FALSE;
Michael Lentinee063fe42016-01-27 17:52:20 -06003957 loader_platform_thread_lock_mutex(&globalLock);
3958 auto pool_data = dev_data->commandPoolMap.find(commandPool);
3959 if (pool_data != dev_data->commandPoolMap.end()) {
3960 for (auto cmdBuffer : pool_data->second.commandBuffers) {
Tobin Ehlis74714d22016-01-25 15:24:34 -08003961 if (dev_data->globalInFlightCmdBuffers.count(cmdBuffer)) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003962 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT, (uint64_t)(commandPool),
3963 __LINE__, DRAWSTATE_OBJECT_INUSE, "DS", "Cannot reset command pool %" PRIx64 " when allocated command buffer %" PRIx64 " is in use.",
3964 (uint64_t)(commandPool), (uint64_t)(cmdBuffer));
Michael Lentinee063fe42016-01-27 17:52:20 -06003965 }
3966 }
3967 }
3968 loader_platform_thread_unlock_mutex(&globalLock);
Mark Youngbaa677f2016-01-28 09:36:15 -07003969 return skipCall;
Michael Lentinee063fe42016-01-27 17:52:20 -06003970}
3971
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003972// Destroy commandPool along with all of the commandBuffers allocated from that pool
3973VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks* pAllocator)
3974{
3975 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003976 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003977
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003978 // Must remove cmdpool from cmdpoolmap, after removing all cmdbuffers in its list from the commandPoolMap
3979 if (dev_data->commandPoolMap.find(commandPool) != dev_data->commandPoolMap.end()) {
3980 for (auto poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.begin(); poolCb != dev_data->commandPoolMap[commandPool].commandBuffers.end();) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003981 auto del_cb = dev_data->commandBufferMap.find(*poolCb);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003982 delete (*del_cb).second; // delete CB info structure
3983 dev_data->commandBufferMap.erase(del_cb); // Remove this command buffer from cbMap
3984 poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.erase(poolCb); // Remove CB reference from commandPoolMap's list
Mark Lobodzinski39298632015-11-18 08:38:27 -07003985 }
3986 }
3987 dev_data->commandPoolMap.erase(commandPool);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003988
3989 loader_platform_thread_unlock_mutex(&globalLock);
Michael Lentinee063fe42016-01-27 17:52:20 -06003990
Mark Youngbaa677f2016-01-28 09:36:15 -07003991 if (VK_TRUE == validateCommandBuffersNotInUse(dev_data, commandPool))
Michael Lentinee063fe42016-01-27 17:52:20 -06003992 return;
3993
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003994 dev_data->device_dispatch_table->DestroyCommandPool(device, commandPool, pAllocator);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003995}
3996
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003997VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandPool(
3998 VkDevice device,
3999 VkCommandPool commandPool,
4000 VkCommandPoolResetFlags flags)
4001{
4002 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4003 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004004
Mark Youngbaa677f2016-01-28 09:36:15 -07004005 if (VK_TRUE == validateCommandBuffersNotInUse(dev_data, commandPool))
Michael Lentined2a7d632016-01-27 17:02:39 -06004006 return VK_ERROR_VALIDATION_FAILED_EXT;
4007
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004008 result = dev_data->device_dispatch_table->ResetCommandPool(device, commandPool, flags);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004009 // Reset all of the CBs allocated from this pool
4010 if (VK_SUCCESS == result) {
Tobin Ehlis74714d22016-01-25 15:24:34 -08004011 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004012 auto it = dev_data->commandPoolMap[commandPool].commandBuffers.begin();
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004013 while (it != dev_data->commandPoolMap[commandPool].commandBuffers.end()) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004014 resetCB(dev_data, (*it));
4015 ++it;
4016 }
Tobin Ehlis74714d22016-01-25 15:24:34 -08004017 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004018 }
4019 return result;
4020}
4021
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004022VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer, const VkAllocationCallbacks* pAllocator)
4023{
4024 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 -06004025 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004026}
4027
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004028VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass, const VkAllocationCallbacks* pAllocator)
4029{
4030 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 -06004031 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004032}
4033
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004034VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateBuffer(VkDevice device, const VkBufferCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkBuffer* pBuffer)
4035{
4036 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4037 VkResult result = dev_data->device_dispatch_table->CreateBuffer(device, pCreateInfo, pAllocator, pBuffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06004038 if (VK_SUCCESS == result) {
4039 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004040 // TODO : This doesn't create deep copy of pQueueFamilyIndices so need to fix that if/when we want that data to be valid
4041 dev_data->bufferMap[*pBuffer].create_info = unique_ptr<VkBufferCreateInfo>(new VkBufferCreateInfo(*pCreateInfo));
Michael Lentine700b0aa2015-10-30 17:57:32 -07004042 dev_data->bufferMap[*pBuffer].in_use.store(0);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06004043 loader_platform_thread_unlock_mutex(&globalLock);
4044 }
4045 return result;
4046}
4047
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004048VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkBufferView* pView)
4049{
4050 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4051 VkResult result = dev_data->device_dispatch_table->CreateBufferView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004052 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004053 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004054 dev_data->bufferViewMap[*pView] = unique_ptr<VkBufferViewCreateInfo>(new VkBufferViewCreateInfo(*pCreateInfo));
Tobin Ehlisa1c28562015-10-23 16:00:08 -06004055 loader_platform_thread_unlock_mutex(&globalLock);
4056 }
4057 return result;
4058}
4059
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004060VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateImage(VkDevice device, const VkImageCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkImage* pImage)
4061{
4062 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4063 VkResult result = dev_data->device_dispatch_table->CreateImage(device, pCreateInfo, pAllocator, pImage);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06004064 if (VK_SUCCESS == result) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004065 IMAGE_NODE* image_node = new IMAGE_NODE;
Michael Lentineabc5e922015-10-12 11:30:14 -05004066 image_node->layout = pCreateInfo->initialLayout;
Tobin Ehlis75cd1c52016-01-21 10:21:04 -07004067 image_node->format = pCreateInfo->format;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06004068 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004069 dev_data->imageMap[*pImage] = unique_ptr<VkImageCreateInfo>(new VkImageCreateInfo(*pCreateInfo));
Michael Lentineabc5e922015-10-12 11:30:14 -05004070 dev_data->imageLayoutMap[*pImage] = image_node;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004071 loader_platform_thread_unlock_mutex(&globalLock);
4072 }
4073 return result;
4074}
4075
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004076VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkImageView* pView)
4077{
4078 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4079 VkResult result = dev_data->device_dispatch_table->CreateImageView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004080 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004081 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004082 dev_data->imageViewMap[*pView] = unique_ptr<VkImageViewCreateInfo>(new VkImageViewCreateInfo(*pCreateInfo));
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004083 loader_platform_thread_unlock_mutex(&globalLock);
4084 }
4085 return result;
4086}
4087
Michael Lentine37767342016-02-02 22:24:26 -06004088VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
4089 vkCreateFence(VkDevice device, const VkFenceCreateInfo* pCreateInfo,
4090 const VkAllocationCallbacks* pAllocator, VkFence* pFence) {
4091 layer_data *dev_data =
4092 get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4093 VkResult result = dev_data->device_dispatch_table->CreateFence(
4094 device, pCreateInfo, pAllocator, pFence);
4095 if (VK_SUCCESS == result) {
4096 loader_platform_thread_lock_mutex(&globalLock);
4097 dev_data->fenceMap[*pFence].in_use.store(0);
4098 loader_platform_thread_unlock_mutex(&globalLock);
4099 }
4100 return result;
4101}
4102
4103// TODO handle pipeline caches
4104VKAPI_ATTR VkResult VKAPI_CALL
4105 vkCreatePipelineCache(VkDevice device,
4106 const VkPipelineCacheCreateInfo *pCreateInfo,
4107 const VkAllocationCallbacks *pAllocator,
4108 VkPipelineCache *pPipelineCache) {
4109 layer_data *dev_data =
4110 get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4111 VkResult result = dev_data->device_dispatch_table->CreatePipelineCache(
4112 device, pCreateInfo, pAllocator, pPipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06004113 return result;
4114}
4115
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004116VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineCache(
4117 VkDevice device,
4118 VkPipelineCache pipelineCache,
4119 const VkAllocationCallbacks* pAllocator)
4120{
4121 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4122 dev_data->device_dispatch_table->DestroyPipelineCache(device, pipelineCache, pAllocator);
Jon Ashburnc669cc62015-07-09 15:02:25 -06004123}
4124
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004125VKAPI_ATTR VkResult VKAPI_CALL vkGetPipelineCacheData(
4126 VkDevice device,
4127 VkPipelineCache pipelineCache,
4128 size_t* pDataSize,
4129 void* pData)
4130{
4131 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4132 VkResult result = dev_data->device_dispatch_table->GetPipelineCacheData(device, pipelineCache, pDataSize, pData);
Jon Ashburnc669cc62015-07-09 15:02:25 -06004133 return result;
4134}
4135
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004136VKAPI_ATTR VkResult VKAPI_CALL vkMergePipelineCaches(
4137 VkDevice device,
4138 VkPipelineCache dstCache,
4139 uint32_t srcCacheCount,
4140 const VkPipelineCache* pSrcCaches)
4141{
4142 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4143 VkResult result = dev_data->device_dispatch_table->MergePipelineCaches(device, dstCache, srcCacheCount, pSrcCaches);
Jon Ashburnc669cc62015-07-09 15:02:25 -06004144 return result;
4145}
4146
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004147VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateGraphicsPipelines(
4148 VkDevice device,
4149 VkPipelineCache pipelineCache,
4150 uint32_t count,
4151 const VkGraphicsPipelineCreateInfo *pCreateInfos,
4152 const VkAllocationCallbacks *pAllocator,
4153 VkPipeline *pPipelines)
4154{
Courtney Goeltzenleuchtered894072015-09-04 13:39:59 -06004155 VkResult result = VK_SUCCESS;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004156 //TODO What to do with pipelineCache?
Tobin Ehlis75283bf2015-06-18 15:59:33 -06004157 // The order of operations here is a little convoluted but gets the job done
4158 // 1. Pipeline create state is first shadowed into PIPELINE_NODE struct
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004159 // 2. Create state is then validated (which uses flags setup during shadowing)
4160 // 3. If everything looks good, we'll then create the pipeline and add NODE to pipelineMap
Tobin Ehlis11efc302015-09-16 10:33:53 -06004161 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004162 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
4163 vector<PIPELINE_NODE*> pPipeNode(count);
4164 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004165
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004166 uint32_t i=0;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06004167 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004168
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004169 for (i=0; i<count; i++) {
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004170 pPipeNode[i] = initGraphicsPipeline(dev_data, &pCreateInfos[i], NULL);
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004171 skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
Tobin Ehlis11efc302015-09-16 10:33:53 -06004172 }
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004173
Tobin Ehlis75283bf2015-06-18 15:59:33 -06004174 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07004175
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07004176 if (VK_FALSE == skipCall) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004177 result = dev_data->device_dispatch_table->CreateGraphicsPipelines(device,
4178 pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
Tobin Ehlis75283bf2015-06-18 15:59:33 -06004179 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004180 for (i=0; i<count; i++) {
Tobin Ehlis11efc302015-09-16 10:33:53 -06004181 pPipeNode[i]->pipeline = pPipelines[i];
Chia-I Wue2fc5522015-10-26 20:04:44 +08004182 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
Tobin Ehlis11efc302015-09-16 10:33:53 -06004183 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06004184 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisce132d82015-06-19 15:07:05 -06004185 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004186 for (i=0; i<count; i++) {
Tobin Ehlis11efc302015-09-16 10:33:53 -06004187 if (pPipeNode[i]) {
4188 // If we allocated a pipeNode, need to clean it up here
4189 delete[] pPipeNode[i]->pVertexBindingDescriptions;
4190 delete[] pPipeNode[i]->pVertexAttributeDescriptions;
4191 delete[] pPipeNode[i]->pAttachments;
4192 delete pPipeNode[i];
4193 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06004194 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004195 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06004196 }
Courtney Goeltzenleuchtere2aaad02015-04-13 16:16:04 -06004197 return result;
4198}
4199
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004200VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateComputePipelines(
4201 VkDevice device,
4202 VkPipelineCache pipelineCache,
4203 uint32_t count,
4204 const VkComputePipelineCreateInfo *pCreateInfos,
4205 const VkAllocationCallbacks *pAllocator,
4206 VkPipeline *pPipelines)
4207{
4208 VkResult result = VK_SUCCESS;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004209 VkBool32 skipCall = VK_FALSE;
4210
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004211 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
4212 vector<PIPELINE_NODE*> pPipeNode(count);
4213 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004214
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004215 uint32_t i=0;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004216 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004217 for (i=0; i<count; i++) {
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004218 // TODO: Verify compute stage bits
4219
4220 // Create and initialize internal tracking data structure
4221 pPipeNode[i] = new PIPELINE_NODE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004222 memcpy(&pPipeNode[i]->computePipelineCI, (const void*)&pCreateInfos[i], sizeof(VkComputePipelineCreateInfo));
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004223
4224 // TODO: Add Compute Pipeline Verification
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004225 // skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004226 }
4227 loader_platform_thread_unlock_mutex(&globalLock);
4228
4229 if (VK_FALSE == skipCall) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004230 result = dev_data->device_dispatch_table->CreateComputePipelines(device, pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004231 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004232 for (i=0; i<count; i++) {
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004233 pPipeNode[i]->pipeline = pPipelines[i];
4234 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
4235 }
4236 loader_platform_thread_unlock_mutex(&globalLock);
4237 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004238 for (i=0; i<count; i++) {
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004239 if (pPipeNode[i]) {
4240 // Clean up any locally allocated data structures
4241 delete pPipeNode[i];
4242 }
4243 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004244 return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004245 }
4246 return result;
4247}
4248
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004249VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSampler* pSampler)
4250{
4251 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4252 VkResult result = dev_data->device_dispatch_table->CreateSampler(device, pCreateInfo, pAllocator, pSampler);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004253 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004254 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004255 dev_data->sampleMap[*pSampler] = unique_ptr<SAMPLER_NODE>(new SAMPLER_NODE(pSampler, pCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004256 loader_platform_thread_unlock_mutex(&globalLock);
4257 }
4258 return result;
4259}
4260
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004261VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDescriptorSetLayout* pSetLayout)
4262{
4263 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4264 VkResult result = dev_data->device_dispatch_table->CreateDescriptorSetLayout(device, pCreateInfo, pAllocator, pSetLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004265 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07004266 // TODOSC : Capture layout bindings set
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004267 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004268 if (NULL == pNewNode) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004269 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",
4270 "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004271 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004272 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004273 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
4274 pNewNode->createInfo.pBindings = new VkDescriptorSetLayoutBinding[pCreateInfo->bindingCount];
4275 memcpy((void*)pNewNode->createInfo.pBindings, pCreateInfo->pBindings, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->bindingCount);
Chia-I Wud46e6ae2015-10-31 00:31:16 +08004276 // g++ does not like reserve with size 0
4277 if (pCreateInfo->bindingCount)
4278 pNewNode->bindings.reserve(pCreateInfo->bindingCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004279 uint32_t totalCount = 0;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004280 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
4281 if (!pNewNode->bindings.insert(pCreateInfo->pBindings[i].binding).second) {
4282 if (log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, (uint64_t) *pSetLayout, __LINE__, DRAWSTATE_INVALID_LAYOUT, "DS",
4283 "duplicated binding number in VkDescriptorSetLayoutBinding"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004284 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08004285 }
4286
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07004287 totalCount += pCreateInfo->pBindings[i].descriptorCount;
4288 if (pCreateInfo->pBindings[i].pImmutableSamplers) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004289 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBindings[i].pImmutableSamplers;
4290 *ppIS = new VkSampler[pCreateInfo->pBindings[i].descriptorCount];
4291 memcpy(*ppIS, pCreateInfo->pBindings[i].pImmutableSamplers, pCreateInfo->pBindings[i].descriptorCount*sizeof(VkSampler));
Tobin Ehlis793ad302015-04-03 12:01:11 -06004292 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004293 }
Tobin Ehlis43c39c02016-01-11 13:18:40 -07004294 pNewNode->layout = *pSetLayout;
4295 pNewNode->startIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004296 if (totalCount > 0) {
Cody Northrop43751cc2015-10-26 14:07:35 -06004297 pNewNode->descriptorTypes.resize(totalCount);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06004298 pNewNode->stageFlags.resize(totalCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004299 uint32_t offset = 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06004300 uint32_t j = 0;
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07004301 VkDescriptorType dType;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004302 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07004303 dType = pCreateInfo->pBindings[i].descriptorType;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004304 for (j = 0; j < pCreateInfo->pBindings[i].descriptorCount; j++) {
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07004305 pNewNode->descriptorTypes[offset + j] = dType;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004306 pNewNode->stageFlags[offset + j] = pCreateInfo->pBindings[i].stageFlags;
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07004307 if ((dType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
4308 (dType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
4309 pNewNode->dynamicDescriptorCount++;
4310 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004311 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06004312 offset += j;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004313 }
Tobin Ehlis43c39c02016-01-11 13:18:40 -07004314 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
4315 } else { // no descriptors
4316 pNewNode->endIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004317 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004318 // Put new node at Head of global Layer list
4319 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07004320 dev_data->descriptorSetLayoutMap[*pSetLayout] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004321 loader_platform_thread_unlock_mutex(&globalLock);
4322 }
4323 return result;
4324}
4325
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004326VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkPipelineLayout* pPipelineLayout)
4327{
4328 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4329 VkResult result = dev_data->device_dispatch_table->CreatePipelineLayout(device, pCreateInfo, pAllocator, pPipelineLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004330 if (VK_SUCCESS == result) {
Ian Elliott8c8b2662016-01-30 10:57:03 -07004331 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07004332 // TODOSC : Merge capture of the setLayouts per pipeline
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004333 PIPELINE_LAYOUT_NODE& plNode = dev_data->pipelineLayoutMap[*pPipelineLayout];
Chia-I Wud50a7d72015-10-26 20:48:51 +08004334 plNode.descriptorSetLayouts.resize(pCreateInfo->setLayoutCount);
Tobin Ehlis644ff042015-10-20 10:11:55 -06004335 uint32_t i = 0;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004336 for (i=0; i<pCreateInfo->setLayoutCount; ++i) {
Tobin Ehlis644ff042015-10-20 10:11:55 -06004337 plNode.descriptorSetLayouts[i] = pCreateInfo->pSetLayouts[i];
4338 }
Cody Northrop43751cc2015-10-26 14:07:35 -06004339 plNode.pushConstantRanges.resize(pCreateInfo->pushConstantRangeCount);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004340 for (i=0; i<pCreateInfo->pushConstantRangeCount; ++i) {
Tobin Ehlis644ff042015-10-20 10:11:55 -06004341 plNode.pushConstantRanges[i] = pCreateInfo->pPushConstantRanges[i];
4342 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07004343 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis793ad302015-04-03 12:01:11 -06004344 }
4345 return result;
4346}
4347
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004348VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDescriptorPool* pDescriptorPool)
4349{
4350 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4351 VkResult result = dev_data->device_dispatch_table->CreateDescriptorPool(device, pCreateInfo, pAllocator, pDescriptorPool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004352 if (VK_SUCCESS == result) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06004353 // Insert this pool into Global Pool LL at head
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004354 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",
4355 "Created Descriptor Pool %#" PRIxLEAST64, (uint64_t) *pDescriptorPool))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004356 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004357 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004358 DESCRIPTOR_POOL_NODE* pNewNode = new DESCRIPTOR_POOL_NODE(*pDescriptorPool, pCreateInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004359 if (NULL == pNewNode) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004360 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",
4361 "Out of memory while attempting to allocate DESCRIPTOR_POOL_NODE in vkCreateDescriptorPool()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004362 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisce132d82015-06-19 15:07:05 -06004363 } else {
Mark Lobodzinski39298632015-11-18 08:38:27 -07004364 dev_data->descriptorPoolMap[*pDescriptorPool] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004365 }
4366 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisce132d82015-06-19 15:07:05 -06004367 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06004368 // Need to do anything if pool create fails?
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004369 }
4370 return result;
4371}
4372
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004373VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorPoolResetFlags flags)
4374{
4375 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4376 VkResult result = dev_data->device_dispatch_table->ResetDescriptorPool(device, descriptorPool, flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004377 if (VK_SUCCESS == result) {
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004378 clearDescriptorPool(dev_data, device, descriptorPool, flags);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004379 }
4380 return result;
4381}
4382
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004383VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo* pAllocateInfo, VkDescriptorSet* pDescriptorSets)
4384{
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004385 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004386 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004387 // Verify that requested descriptorSets are available in pool
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004388 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004389 if (!pPoolNode) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004390 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",
4391 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pAllocateInfo->descriptorPool);
4392 } else { // Make sure pool has all the available descriptors before calling down chain
4393 skipCall |= validate_descriptor_availability_in_pool(dev_data, pPoolNode, pAllocateInfo->descriptorSetCount, pAllocateInfo->pSetLayouts);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004394 }
4395 if (skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004396 return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004397 VkResult result = dev_data->device_dispatch_table->AllocateDescriptorSets(device, pAllocateInfo, pDescriptorSets);
Cody Northrop1e4f8022015-08-03 12:47:29 -06004398 if (VK_SUCCESS == result) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004399 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004400 if (pPoolNode) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004401 if (pAllocateInfo->descriptorSetCount == 0) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004402 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 +08004403 "AllocateDescriptorSets called with 0 count");
Cody Northrop1e4f8022015-08-03 12:47:29 -06004404 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07004405 for (uint32_t i = 0; i < pAllocateInfo->descriptorSetCount; i++) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004406 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",
4407 "Created Descriptor Set %#" PRIxLEAST64, (uint64_t) pDescriptorSets[i]);
Tobin Ehlis793ad302015-04-03 12:01:11 -06004408 // Create new set node and add to head of pool nodes
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004409 SET_NODE* pNewNode = new SET_NODE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004410 if (NULL == pNewNode) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004411 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",
4412 "Out of memory while attempting to allocate SET_NODE in vkAllocateDescriptorSets()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004413 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisce132d82015-06-19 15:07:05 -06004414 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004415 // TODO : Pool should store a total count of each type of Descriptor available
4416 // When descriptors are allocated, decrement the count and validate here
4417 // that the count doesn't go below 0. One reset/free need to bump count back up.
Tobin Ehlis793ad302015-04-03 12:01:11 -06004418 // Insert set at head of Set LL for this pool
4419 pNewNode->pNext = pPoolNode->pSets;
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07004420 pNewNode->in_use.store(0);
Tobin Ehlis793ad302015-04-03 12:01:11 -06004421 pPoolNode->pSets = pNewNode;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004422 LAYOUT_NODE* pLayout = getLayoutNode(dev_data, pAllocateInfo->pSetLayouts[i]);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004423 if (NULL == pLayout) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004424 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",
4425 "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 -07004426 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004427 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07004428 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis793ad302015-04-03 12:01:11 -06004429 pNewNode->pLayout = pLayout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004430 pNewNode->pool = pAllocateInfo->descriptorPool;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004431 pNewNode->set = pDescriptorSets[i];
Tobin Ehlise703fa92016-01-29 07:52:45 -07004432 pNewNode->descriptorCount = (pLayout->createInfo.bindingCount != 0) ? pLayout->endIndex + 1 : 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004433 if (pNewNode->descriptorCount) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004434 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
4435 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004436 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
4437 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08004438 dev_data->setMap[pDescriptorSets[i]] = pNewNode;
Ian Elliott8c8b2662016-01-30 10:57:03 -07004439 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004440 }
4441 }
4442 }
4443 }
4444 return result;
4445}
4446
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004447VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, const VkDescriptorSet* pDescriptorSets)
4448{
Tobin Ehlise735c692015-10-08 13:13:50 -06004449 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004450 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07004451 // Make sure that no sets being destroyed are in-flight
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004452 for (uint32_t i=0; i<count; ++i)
4453 skipCall |= validateIdleDescriptorSet(dev_data, pDescriptorSets[i], "vkFreeDesriptorSets");
Mark Lobodzinski39298632015-11-18 08:38:27 -07004454 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, descriptorPool);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004455 if (pPoolNode && !(VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT & pPoolNode->createInfo.flags)) {
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004456 // Can't Free from a NON_FREE pool
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004457 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",
4458 "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 -06004459 }
Mark Youngb20a6a82016-01-07 15:41:43 -07004460 if (VK_FALSE != skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004461 return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004462 VkResult result = dev_data->device_dispatch_table->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004463 if (VK_SUCCESS == result) {
4464 // For each freed descriptor add it back into the pool as available
Ian Elliott8c8b2662016-01-30 10:57:03 -07004465 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004466 for (uint32_t i=0; i<count; ++i) {
4467 SET_NODE* pSet = dev_data->setMap[pDescriptorSets[i]]; // getSetNode() without locking
Tobin Ehlise6e574b2016-01-24 23:25:31 -07004468 invalidateBoundCmdBuffers(dev_data, pSet);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004469 LAYOUT_NODE* pLayout = pSet->pLayout;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004470 uint32_t typeIndex = 0, poolSizeCount = 0;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004471 for (uint32_t j=0; j<pLayout->createInfo.bindingCount; ++j) {
4472 typeIndex = static_cast<uint32_t>(pLayout->createInfo.pBindings[j].descriptorType);
4473 poolSizeCount = pLayout->createInfo.pBindings[j].descriptorCount;
4474 pPoolNode->availableDescriptorTypeCount[typeIndex] += poolSizeCount;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004475 }
4476 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07004477 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004478 }
4479 // TODO : Any other clean-up or book-keeping to do here?
Tony Barbour34ec6922015-07-10 10:50:45 -06004480 return result;
4481}
4482
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004483VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount, const VkWriteDescriptorSet* pDescriptorWrites, uint32_t descriptorCopyCount, const VkCopyDescriptorSet* pDescriptorCopies)
4484{
4485 // dsUpdate will return VK_TRUE only if a bailout error occurs, so we want to call down tree when update returns VK_FALSE
4486 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4487 if (!dsUpdate(dev_data, device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies)) {
4488 dev_data->device_dispatch_table->UpdateDescriptorSets(device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies);
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004489 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004490}
4491
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004492VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo* pCreateInfo, VkCommandBuffer* pCommandBuffer)
4493{
4494 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4495 VkResult result = dev_data->device_dispatch_table->AllocateCommandBuffers(device, pCreateInfo, pCommandBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004496 if (VK_SUCCESS == result) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004497 for (uint32_t i = 0; i < pCreateInfo->commandBufferCount; i++) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07004498 // Validate command pool
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004499 if (dev_data->commandPoolMap.find(pCreateInfo->commandPool) != dev_data->commandPoolMap.end()) {
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07004500 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07004501 // Add command buffer to its commandPool map
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004502 dev_data->commandPoolMap[pCreateInfo->commandPool].commandBuffers.push_back(pCommandBuffer[i]);
4503 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
Mark Lobodzinski39298632015-11-18 08:38:27 -07004504 // Add command buffer to map
4505 dev_data->commandBufferMap[pCommandBuffer[i]] = pCB;
4506 resetCB(dev_data, pCommandBuffer[i]);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004507 pCB->createInfo = *pCreateInfo;
4508 pCB->device = device;
Tobin Ehlis74714d22016-01-25 15:24:34 -08004509 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07004510 }
4511 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004512 }
4513 return result;
4514}
4515
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004516VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo* pBeginInfo)
4517{
Mark Youngb20a6a82016-01-07 15:41:43 -07004518 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004519 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004520 // Validate command buffer level
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004521 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004522 if (pCB) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004523 if (pCB->createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
4524 // Secondary Command Buffer
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004525 const VkCommandBufferInheritanceInfo *pInfo = pBeginInfo->pInheritanceInfo;
Michael Lentine7d26c572016-01-28 11:55:28 -06004526 if (!pInfo) {
4527 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__,
4528 DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS", "vkBeginCommandBuffer(): Secondary Command Buffer (%p) must have inheritance info.",
4529 reinterpret_cast<void*>(commandBuffer));
4530 } else {
4531 if (pBeginInfo->flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT) {
4532 if (!pInfo->renderPass) { // renderpass should NOT be null for an Secondary CB
4533 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),
4534 __LINE__, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
4535 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) must specify a valid renderpass parameter.", reinterpret_cast<void*>(commandBuffer));
Tobin Ehlis651d9b02015-12-16 05:01:22 -07004536 }
Michael Lentine7d26c572016-01-28 11:55:28 -06004537 if (!pInfo->framebuffer) { // framebuffer may be null for an Secondary CB, but this affects perf
4538 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),
4539 __LINE__, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
4540 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) may perform better if a valid framebuffer parameter is specified.",
4541 reinterpret_cast<void*>(commandBuffer));
4542 } else {
4543 string errorString = "";
4544 VkRenderPass fbRP = dev_data->frameBufferMap[pInfo->framebuffer]->renderPass;
4545 if (!verify_renderpass_compatibility(dev_data, fbRP, pInfo->renderPass, errorString)) {
4546 // renderPass that framebuffer was created with must be compatible with local renderPass
4547 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),
4548 __LINE__, DRAWSTATE_RENDERPASS_INCOMPATIBLE, "DS",
4549 "vkBeginCommandBuffer(): Secondary Command Buffer (%p) renderPass (%#" PRIxLEAST64 ") is incompatible w/ framebuffer (%#" PRIxLEAST64
Dustin Graves4383a2d2016-02-04 10:57:00 -07004550 ") w/ render pass (%#" PRIxLEAST64 ") due to: %s", reinterpret_cast<void*>(commandBuffer), (uint64_t)(pInfo->renderPass),
4551 (uint64_t)(pInfo->framebuffer), (uint64_t)(fbRP), errorString.c_str());
Michael Lentine7d26c572016-01-28 11:55:28 -06004552 }
4553 }
4554 }
4555 if ((pInfo->occlusionQueryEnable == VK_FALSE || dev_data->physDevProperties.features.occlusionQueryPrecise == VK_FALSE) && (pInfo->queryFlags & VK_QUERY_CONTROL_PRECISE_BIT)) {
4556 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),
4557 __LINE__, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
4558 "vkBeginCommandBuffer(): Secondary Command Buffer (%p) must not have VK_QUERY_CONTROL_PRECISE_BIT if occulusionQuery is disabled or the device does not "
4559 "support precise occlusion queries.", reinterpret_cast<void*>(commandBuffer));
Tobin Ehlis651d9b02015-12-16 05:01:22 -07004560 }
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004561 }
Michael Lentine539b0222016-02-02 17:28:24 -06004562 if (pInfo->renderPass != VK_NULL_HANDLE) {
4563 auto rp_data = dev_data->renderPassMap.find(pInfo->renderPass);
4564 if (rp_data != dev_data->renderPassMap.end() && rp_data->second && rp_data->second->pCreateInfo) {
4565 if (pInfo->subpass >= rp_data->second->pCreateInfo->subpassCount) {
4566 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer,
4567 __LINE__, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
4568 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) must has a subpass index (%d) that is less than the number of subpasses (%d).",
4569 (void*)commandBuffer, pInfo->subpass, rp_data->second->pCreateInfo->subpassCount);
4570 }
4571 }
4572 }
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004573 }
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004574 if (CB_RECORDING == pCB->state) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004575 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",
4576 "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 -07004577 } else if (CB_RECORDED == pCB->state) {
4578 VkCommandPool cmdPool = pCB->createInfo.commandPool;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004579 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
4580 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer,
4581 __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
4582 "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.",
4583 (uint64_t) commandBuffer, (uint64_t) cmdPool);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004584 }
Tobin Ehlis74714d22016-01-25 15:24:34 -08004585 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisef694652016-01-19 12:03:34 -07004586 resetCB(dev_data, commandBuffer);
Tobin Ehlis74714d22016-01-25 15:24:34 -08004587 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004588 }
Tobin Ehlisef694652016-01-19 12:03:34 -07004589 // Set updated state here in case implicit reset occurs above
Tobin Ehlis74714d22016-01-25 15:24:34 -08004590 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisef694652016-01-19 12:03:34 -07004591 pCB->state = CB_RECORDING;
4592 pCB->beginInfo = *pBeginInfo;
Tobin Ehliscd5bfd82016-01-19 13:12:52 -07004593 if (pCB->beginInfo.pInheritanceInfo) {
4594 pCB->inheritanceInfo = *(pCB->beginInfo.pInheritanceInfo);
4595 pCB->beginInfo.pInheritanceInfo = &pCB->inheritanceInfo;
4596 }
Tobin Ehlis74714d22016-01-25 15:24:34 -08004597 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004598 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004599 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",
4600 "In vkBeginCommandBuffer() and unable to find CommandBuffer Node for CB %p!", (void*)commandBuffer);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004601 }
Mark Youngb20a6a82016-01-07 15:41:43 -07004602 if (VK_FALSE != skipCall) {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004603 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter5fe086f2015-09-04 15:03:52 -06004604 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004605 VkResult result = dev_data->device_dispatch_table->BeginCommandBuffer(commandBuffer, pBeginInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004606 return result;
4607}
4608
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004609VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEndCommandBuffer(VkCommandBuffer commandBuffer)
4610{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004611 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchtered894072015-09-04 13:39:59 -06004612 VkResult result = VK_SUCCESS;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004613 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4614 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004615 if (pCB) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004616 if (pCB->state != CB_RECORDING) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004617 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkEndCommandBuffer()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004618 }
Michael Lentinedc6f8de2016-02-02 18:29:30 -06004619 for (auto query : pCB->activeQueries) {
4620 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_QUERY, "DS",
4621 "Ending command buffer with in progress query: queryPool %" PRIu64 ", index %d", (uint64_t)(query.pool), query.index);
4622 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004623 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004624 if (VK_FALSE == skipCall) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004625 result = dev_data->device_dispatch_table->EndCommandBuffer(commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004626 if (VK_SUCCESS == result) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004627 pCB->state = CB_RECORDED;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004628 // Reset CB status flags
4629 pCB->status = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004630 printCB(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004631 }
4632 } else {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004633 result = VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004634 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004635 return result;
4636}
4637
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004638VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags)
4639{
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004640 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004641 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4642 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004643 VkCommandPool cmdPool = pCB->createInfo.commandPool;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004644 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
4645 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t) commandBuffer,
4646 __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
4647 "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.",
4648 (uint64_t) commandBuffer, (uint64_t) cmdPool);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004649 }
Michael Lentine5f6dc4f2016-01-27 20:42:07 -06004650 if (dev_data->globalInFlightCmdBuffers.count(commandBuffer)) {
4651 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t) commandBuffer,
4652 __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
4653 "Attempt to reset command buffer (%#" PRIxLEAST64 ") which is in use.", reinterpret_cast<uint64_t>(commandBuffer));
4654 }
Mark Youngb20a6a82016-01-07 15:41:43 -07004655 if (skipCall != VK_FALSE)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004656 return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004657 VkResult result = dev_data->device_dispatch_table->ResetCommandBuffer(commandBuffer, flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004658 if (VK_SUCCESS == result) {
Tobin Ehlis74714d22016-01-25 15:24:34 -08004659 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004660 resetCB(dev_data, commandBuffer);
Tobin Ehlis74714d22016-01-25 15:24:34 -08004661 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004662 }
4663 return result;
4664}
4665
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004666VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
4667{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004668 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004669 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4670 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004671 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004672 skipCall |= addCmd(dev_data, pCB, CMD_BINDPIPELINE, "vkCmdBindPipeline()");
4673 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
4674 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, (uint64_t) pipeline,
4675 __LINE__, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
4676 "Incorrectly binding compute pipeline (%#" PRIxLEAST64 ") during active RenderPass (%#" PRIxLEAST64 ")",
4677 (uint64_t) pipeline, (uint64_t) pCB->activeRenderPass);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004678 } else if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004679 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdBindPipeline");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004680 }
4681
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004682 PIPELINE_NODE* pPN = getPipeline(dev_data, pipeline);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004683 if (pPN) {
4684 pCB->lastBoundPipeline = pipeline;
4685 loader_platform_thread_lock_mutex(&globalLock);
4686 set_cb_pso_status(pCB, pPN);
4687 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004688 skipCall |= validatePipelineState(dev_data, pCB, pipelineBindPoint, pipeline);
Tobin Ehlisce132d82015-06-19 15:07:05 -06004689 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004690 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
4691 (uint64_t) pipeline, __LINE__, DRAWSTATE_INVALID_PIPELINE, "DS",
4692 "Attempt to bind Pipeline %#" PRIxLEAST64 " that doesn't exist!", (uint64_t)(pipeline));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004693 }
4694 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004695 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004696 dev_data->device_dispatch_table->CmdBindPipeline(commandBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004697}
4698
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004699VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetViewport(
4700 VkCommandBuffer commandBuffer,
4701 uint32_t firstViewport,
4702 uint32_t viewportCount,
4703 const VkViewport* pViewports)
4704{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004705 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004706 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4707 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004708 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004709 loader_platform_thread_lock_mutex(&globalLock);
Ian Elliott8c8b2662016-01-30 10:57:03 -07004710 skipCall |= addCmd(dev_data, pCB, CMD_SETVIEWPORTSTATE, "vkCmdSetViewport()");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004711 pCB->status |= CBSTATUS_VIEWPORT_SET;
4712 pCB->viewports.resize(viewportCount);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004713 memcpy(pCB->viewports.data(), pViewports, viewportCount * sizeof(VkViewport));
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004714 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004715 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004716 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004717 dev_data->device_dispatch_table->CmdSetViewport(commandBuffer, firstViewport, viewportCount, pViewports);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004718}
4719
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004720VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetScissor(
4721 VkCommandBuffer commandBuffer,
4722 uint32_t firstScissor,
4723 uint32_t scissorCount,
4724 const VkRect2D* pScissors)
4725{
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004726 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004727 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4728 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004729 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004730 loader_platform_thread_lock_mutex(&globalLock);
Ian Elliott8c8b2662016-01-30 10:57:03 -07004731 skipCall |= addCmd(dev_data, pCB, CMD_SETSCISSORSTATE, "vkCmdSetScissor()");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004732 pCB->status |= CBSTATUS_SCISSOR_SET;
4733 pCB->scissors.resize(scissorCount);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004734 memcpy(pCB->scissors.data(), pScissors, scissorCount * sizeof(VkRect2D));
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004735 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004736 }
4737 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004738 dev_data->device_dispatch_table->CmdSetScissor(commandBuffer, firstScissor, scissorCount, pScissors);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004739}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004740
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004741VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth)
4742{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004743 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004744 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4745 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004746 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004747 loader_platform_thread_lock_mutex(&globalLock);
Ian Elliott8c8b2662016-01-30 10:57:03 -07004748 skipCall |= addCmd(dev_data, pCB, CMD_SETLINEWIDTHSTATE, "vkCmdSetLineWidth()");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004749 pCB->status |= CBSTATUS_LINE_WIDTH_SET;
4750 pCB->lineWidth = lineWidth;
4751 loader_platform_thread_unlock_mutex(&globalLock);
Cody Northrop12365112015-08-17 11:10:49 -06004752 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004753 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004754 dev_data->device_dispatch_table->CmdSetLineWidth(commandBuffer, lineWidth);
Cody Northrop12365112015-08-17 11:10:49 -06004755}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004756
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004757VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBias(
4758 VkCommandBuffer commandBuffer,
4759 float depthBiasConstantFactor,
4760 float depthBiasClamp,
4761 float depthBiasSlopeFactor)
4762{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004763 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004764 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4765 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northrop12365112015-08-17 11:10:49 -06004766 if (pCB) {
Ian Elliott8c8b2662016-01-30 10:57:03 -07004767 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004768 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBIASSTATE, "vkCmdSetDepthBias()");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004769 pCB->status |= CBSTATUS_DEPTH_BIAS_SET;
4770 pCB->depthBiasConstantFactor = depthBiasConstantFactor;
4771 pCB->depthBiasClamp = depthBiasClamp;
4772 pCB->depthBiasSlopeFactor = depthBiasSlopeFactor;
Ian Elliott8c8b2662016-01-30 10:57:03 -07004773 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004774 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004775 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004776 dev_data->device_dispatch_table->CmdSetDepthBias(commandBuffer, depthBiasConstantFactor, depthBiasClamp, depthBiasSlopeFactor);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004777}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004778
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004779VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4])
4780{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004781 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004782 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4783 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004784 if (pCB) {
Ian Elliott8c8b2662016-01-30 10:57:03 -07004785 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004786 skipCall |= addCmd(dev_data, pCB, CMD_SETBLENDSTATE, "vkCmdSetBlendConstants()");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004787 pCB->status |= CBSTATUS_BLEND_SET;
4788 memcpy(pCB->blendConstants, blendConstants, 4 * sizeof(float));
Ian Elliott8c8b2662016-01-30 10:57:03 -07004789 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004790 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004791 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004792 dev_data->device_dispatch_table->CmdSetBlendConstants(commandBuffer, blendConstants);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004793}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004794
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004795VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBounds(
4796 VkCommandBuffer commandBuffer,
4797 float minDepthBounds,
4798 float maxDepthBounds)
4799{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004800 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004801 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4802 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004803 if (pCB) {
Ian Elliott8c8b2662016-01-30 10:57:03 -07004804 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004805 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBOUNDSSTATE, "vkCmdSetDepthBounds()");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004806 pCB->status |= CBSTATUS_DEPTH_BOUNDS_SET;
4807 pCB->minDepthBounds = minDepthBounds;
4808 pCB->maxDepthBounds = maxDepthBounds;
Ian Elliott8c8b2662016-01-30 10:57:03 -07004809 loader_platform_thread_unlock_mutex(&globalLock);
Cody Northrop82485a82015-08-18 15:21:16 -06004810 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004811 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004812 dev_data->device_dispatch_table->CmdSetDepthBounds(commandBuffer, minDepthBounds, maxDepthBounds);
Cody Northrop82485a82015-08-18 15:21:16 -06004813}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004814
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004815VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilCompareMask(
4816 VkCommandBuffer commandBuffer,
4817 VkStencilFaceFlags faceMask,
4818 uint32_t compareMask)
4819{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004820 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004821 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4822 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northrop82485a82015-08-18 15:21:16 -06004823 if (pCB) {
Ian Elliott8c8b2662016-01-30 10:57:03 -07004824 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004825 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREADMASKSTATE, "vkCmdSetStencilCompareMask()");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004826 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4827 pCB->front.compareMask = compareMask;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004828 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004829 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4830 pCB->back.compareMask = compareMask;
4831 }
4832 /* TODO: Do we need to track front and back separately? */
4833 /* TODO: We aren't capturing the faceMask, do we need to? */
4834 pCB->status |= CBSTATUS_STENCIL_READ_MASK_SET;
Ian Elliott8c8b2662016-01-30 10:57:03 -07004835 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004836 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004837 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004838 dev_data->device_dispatch_table->CmdSetStencilCompareMask(commandBuffer, faceMask, compareMask);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004839}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004840
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004841VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilWriteMask(
4842 VkCommandBuffer commandBuffer,
4843 VkStencilFaceFlags faceMask,
4844 uint32_t writeMask)
4845{
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004846 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004847 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4848 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004849 if (pCB) {
Ian Elliott8c8b2662016-01-30 10:57:03 -07004850 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004851 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILWRITEMASKSTATE, "vkCmdSetStencilWriteMask()");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004852 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4853 pCB->front.writeMask = writeMask;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004854 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004855 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4856 pCB->back.writeMask = writeMask;
4857 }
4858 pCB->status |= CBSTATUS_STENCIL_WRITE_MASK_SET;
Ian Elliott8c8b2662016-01-30 10:57:03 -07004859 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004860 }
4861 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004862 dev_data->device_dispatch_table->CmdSetStencilWriteMask(commandBuffer, faceMask, writeMask);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004863}
4864
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004865VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilReference(
4866 VkCommandBuffer commandBuffer,
4867 VkStencilFaceFlags faceMask,
4868 uint32_t reference)
4869{
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004870 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004871 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4872 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004873 if (pCB) {
Ian Elliott8c8b2662016-01-30 10:57:03 -07004874 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004875 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREFERENCESTATE, "vkCmdSetStencilReference()");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004876 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4877 pCB->front.reference = reference;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004878 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004879 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4880 pCB->back.reference = reference;
4881 }
4882 pCB->status |= CBSTATUS_STENCIL_REFERENCE_SET;
Ian Elliott8c8b2662016-01-30 10:57:03 -07004883 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004884 }
4885 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004886 dev_data->device_dispatch_table->CmdSetStencilReference(commandBuffer, faceMask, reference);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004887}
4888
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004889VK_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)
4890{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004891 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004892 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07004893 loader_platform_thread_lock_mutex(&globalLock);
4894 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004895 if (pCB) {
Tobin Ehlisf6585052015-12-17 11:48:42 -07004896 if (pCB->state == CB_RECORDING) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004897 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
4898 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
4899 "Incorrectly binding compute DescriptorSets during active RenderPass (%#" PRIxLEAST64 ")", (uint64_t) pCB->activeRenderPass);
Tobin Ehlisf6585052015-12-17 11:48:42 -07004900 } else if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004901 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdBindDescriptorSets");
Mark Lobodzinski74635932015-12-18 15:35:38 -07004902 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07004903 if (VK_FALSE == skipCall) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004904 // Track total count of dynamic descriptor types to make sure we have an offset for each one
Tobin Ehlisf6585052015-12-17 11:48:42 -07004905 uint32_t totalDynamicDescriptors = 0;
4906 string errorString = "";
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004907 uint32_t lastSetIndex = firstSet+setCount-1;
Tobin Ehlisf6585052015-12-17 11:48:42 -07004908 if (lastSetIndex >= pCB->boundDescriptorSets.size())
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004909 pCB->boundDescriptorSets.resize(lastSetIndex+1);
4910 VkDescriptorSet oldFinalBoundSet = pCB->boundDescriptorSets[lastSetIndex];
4911 for (uint32_t i=0; i<setCount; i++) {
Ian Elliott8c8b2662016-01-30 10:57:03 -07004912 SET_NODE* pSet = getSetNode(dev_data, pDescriptorSets[i], false);
Tobin Ehlisf6585052015-12-17 11:48:42 -07004913 if (pSet) {
Tobin Ehlise6e574b2016-01-24 23:25:31 -07004914 pCB->uniqueBoundSets.insert(pDescriptorSets[i]);
4915 pSet->boundCmdBuffers.insert(commandBuffer);
Tobin Ehlisf6585052015-12-17 11:48:42 -07004916 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
4917 pCB->lastBoundPipelineLayout = layout;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004918 pCB->boundDescriptorSets[i+firstSet] = pDescriptorSets[i];
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004919 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",
4920 "DS %#" PRIxLEAST64 " bound on pipeline %s", (uint64_t) pDescriptorSets[i], string_VkPipelineBindPoint(pipelineBindPoint));
4921 if (!pSet->pUpdateStructs && (pSet->descriptorCount != 0)) {
4922 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",
4923 "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 -07004924 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004925 // Verify that set being bound is compatible with overlapping setLayout of pipelineLayout
4926 if (!verify_set_layout_compatibility(dev_data, pSet, layout, i+firstSet, errorString)) {
4927 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",
4928 "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 -07004929 }
4930 if (pSet->pLayout->dynamicDescriptorCount) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004931 // First make sure we won't overstep bounds of pDynamicOffsets array
4932 if ((totalDynamicDescriptors + pSet->pLayout->dynamicDescriptorCount) > dynamicOffsetCount) {
4933 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",
4934 "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.",
4935 i, (uint64_t) pDescriptorSets[i], pSet->pLayout->dynamicDescriptorCount, (dynamicOffsetCount - totalDynamicDescriptors));
4936 } else { // Validate and store dynamic offsets with the set
Mark Lobodzinski941aea92016-01-13 10:23:15 -07004937 // Validate Dynamic Offset Minimums
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004938 uint32_t cur_dyn_offset = totalDynamicDescriptors;
4939 for (uint32_t d = 0; d < pSet->descriptorCount; d++) {
4940 if (pSet->pLayout->descriptorTypes[i] == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) {
Michael Lentine26870f32016-01-26 21:36:08 -06004941 if (vk_safe_modulo(pDynamicOffsets[cur_dyn_offset], dev_data->physDevProperties.properties.limits.minUniformBufferOffsetAlignment) != 0) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004942 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0,
4943 __LINE__, DRAWSTATE_INVALID_UNIFORM_BUFFER_OFFSET, "DS",
4944 "vkCmdBindDescriptorSets(): pDynamicOffsets[%d] is %d but must be a multiple of device limit minUniformBufferOffsetAlignment %#" PRIxLEAST64,
Michael Lentine26870f32016-01-26 21:36:08 -06004945 cur_dyn_offset, pDynamicOffsets[cur_dyn_offset], dev_data->physDevProperties.properties.limits.minUniformBufferOffsetAlignment);
Mark Lobodzinski941aea92016-01-13 10:23:15 -07004946 }
4947 cur_dyn_offset++;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004948 } else if (pSet->pLayout->descriptorTypes[i] == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC) {
Michael Lentine26870f32016-01-26 21:36:08 -06004949 if (vk_safe_modulo(pDynamicOffsets[cur_dyn_offset], dev_data->physDevProperties.properties.limits.minStorageBufferOffsetAlignment) != 0) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004950 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0,
4951 __LINE__, DRAWSTATE_INVALID_STORAGE_BUFFER_OFFSET, "DS",
4952 "vkCmdBindDescriptorSets(): pDynamicOffsets[%d] is %d but must be a multiple of device limit minStorageBufferOffsetAlignment %#" PRIxLEAST64,
Michael Lentine26870f32016-01-26 21:36:08 -06004953 cur_dyn_offset, pDynamicOffsets[cur_dyn_offset], dev_data->physDevProperties.properties.limits.minStorageBufferOffsetAlignment);
Mark Lobodzinski941aea92016-01-13 10:23:15 -07004954 }
4955 cur_dyn_offset++;
4956 }
4957 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004958 // Keep running total of dynamic descriptor count to verify at the end
4959 totalDynamicDescriptors += pSet->pLayout->dynamicDescriptorCount;
Tobin Ehlisf6585052015-12-17 11:48:42 -07004960 }
4961 }
4962 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004963 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",
4964 "Attempt to bind DS %#" PRIxLEAST64 " that doesn't exist!", (uint64_t) pDescriptorSets[i]);
Tobin Ehlisf6585052015-12-17 11:48:42 -07004965 }
4966 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004967 skipCall |= addCmd(dev_data, pCB, CMD_BINDDESCRIPTORSETS, "vkCmdBindDescrsiptorSets()");
4968 // 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 -07004969 if (firstSet > 0) { // Check set #s below the first bound set
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004970 for (uint32_t i=0; i<firstSet; ++i) {
4971 if (pCB->boundDescriptorSets[i] && !verify_set_layout_compatibility(dev_data, dev_data->setMap[pCB->boundDescriptorSets[i]], layout, i, errorString)) {
4972 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",
4973 "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 -07004974 pCB->boundDescriptorSets[i] = VK_NULL_HANDLE;
4975 }
4976 }
4977 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004978 // Check if newly last bound set invalidates any remaining bound sets
4979 if ((pCB->boundDescriptorSets.size()-1) > (lastSetIndex)) {
4980 if (oldFinalBoundSet && !verify_set_layout_compatibility(dev_data, dev_data->setMap[oldFinalBoundSet], layout, lastSetIndex, errorString)) {
4981 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",
4982 "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);
4983 pCB->boundDescriptorSets.resize(lastSetIndex+1);
Tobin Ehlisf6585052015-12-17 11:48:42 -07004984 }
4985 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004986 // dynamicOffsetCount must equal the total number of dynamic descriptors in the sets being bound
Tobin Ehlisf6585052015-12-17 11:48:42 -07004987 if (totalDynamicDescriptors != dynamicOffsetCount) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004988 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",
4989 "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 -07004990 }
Tobin Ehlisd2393772016-01-29 11:50:47 -07004991 if (dynamicOffsetCount) {
4992 // Save dynamicOffsets bound to this CB
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004993 pCB->dynamicOffsets.assign(pDynamicOffsets, pDynamicOffsets + dynamicOffsetCount);
Tobin Ehlisd2393772016-01-29 11:50:47 -07004994 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004995 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07004996 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004997 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindDescriptorSets()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004998 }
4999 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005000 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005001 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005002 dev_data->device_dispatch_table->CmdBindDescriptorSets(commandBuffer, pipelineBindPoint, layout, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005003}
5004
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005005VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
5006{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005007 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005008 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005009 loader_platform_thread_lock_mutex(&globalLock);
5010 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005011 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005012 skipCall |= addCmd(dev_data, pCB, CMD_BINDINDEXBUFFER, "vkCmdBindIndexBuffer()");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005013 VkDeviceSize offset_align = 0;
5014 switch (indexType) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005015 case VK_INDEX_TYPE_UINT16:
5016 offset_align = 2;
5017 break;
5018 case VK_INDEX_TYPE_UINT32:
5019 offset_align = 4;
5020 break;
5021 default:
5022 // ParamChecker should catch bad enum, we'll also throw alignment error below if offset_align stays 0
5023 break;
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005024 }
5025 if (!offset_align || (offset % offset_align)) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005026 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VTX_INDEX_ALIGNMENT_ERROR, "DS",
5027 "vkCmdBindIndexBuffer() offset (%#" PRIxLEAST64 ") does not fall on alignment (%s) boundary.", offset, string_VkIndexType(indexType));
Tobin Ehlis9c536442015-06-19 13:00:59 -06005028 }
Tobin Ehlisc4c23182015-09-17 12:24:13 -06005029 pCB->status |= CBSTATUS_INDEX_BUFFER_BOUND;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005030 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005031 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005032 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005033 dev_data->device_dispatch_table->CmdBindIndexBuffer(commandBuffer, buffer, offset, indexType);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005034}
5035
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005036void updateResourceTracking(GLOBAL_CB_NODE* pCB, uint32_t firstBinding, uint32_t bindingCount, const VkBuffer* pBuffers) {
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07005037 uint32_t end = firstBinding + bindingCount;
Michael Lentine700b0aa2015-10-30 17:57:32 -07005038 if (pCB->currentDrawData.buffers.size() < end) {
5039 pCB->currentDrawData.buffers.resize(end);
5040 }
5041 for (uint32_t i = 0; i < bindingCount; ++i) {
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07005042 pCB->currentDrawData.buffers[i + firstBinding] = pBuffers[i];
Michael Lentine700b0aa2015-10-30 17:57:32 -07005043 }
5044}
5045
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005046void updateResourceTrackingOnDraw(GLOBAL_CB_NODE* pCB) {
Michael Lentine700b0aa2015-10-30 17:57:32 -07005047 pCB->drawData.push_back(pCB->currentDrawData);
5048}
5049
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005050VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindVertexBuffers(
5051 VkCommandBuffer commandBuffer,
5052 uint32_t firstBinding,
5053 uint32_t bindingCount,
5054 const VkBuffer *pBuffers,
5055 const VkDeviceSize *pOffsets)
5056{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005057 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005058 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005059 loader_platform_thread_lock_mutex(&globalLock);
5060 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005061 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005062 addCmd(dev_data, pCB, CMD_BINDVERTEXBUFFER, "vkCmdBindVertexBuffer()");
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07005063 updateResourceTracking(pCB, firstBinding, bindingCount, pBuffers);
Michael Lentine700b0aa2015-10-30 17:57:32 -07005064 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005065 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindVertexBuffer()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005066 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005067 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005068 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005069 dev_data->device_dispatch_table->CmdBindVertexBuffers(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005070}
5071
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005072VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance)
5073{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005074 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005075 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005076 loader_platform_thread_lock_mutex(&globalLock);
5077 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005078 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005079 skipCall |= addCmd(dev_data, pCB, CMD_DRAW, "vkCmdDraw()");
5080 pCB->drawCount[DRAW]++;
Ian Elliott8c8b2662016-01-30 10:57:03 -07005081 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005082 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005083 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005084 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005085 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",
5086 "vkCmdDraw() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW]++);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005087 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07005088 if (VK_FALSE == skipCall) {
5089 updateResourceTrackingOnDraw(pCB);
5090 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005091 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDraw");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06005092 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005093 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005094 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005095 dev_data->device_dispatch_table->CmdDraw(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005096}
5097
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005098VK_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)
5099{
5100 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005101 loader_platform_thread_lock_mutex(&globalLock);
5102 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005103 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005104 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005105 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXED, "vkCmdDrawIndexed()");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005106 pCB->drawCount[DRAW_INDEXED]++;
Ian Elliott8c8b2662016-01-30 10:57:03 -07005107 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005108 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005109 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005110 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005111 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",
5112 "vkCmdDrawIndexed() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED]++);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005113 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07005114 if (VK_FALSE == skipCall) {
5115 updateResourceTrackingOnDraw(pCB);
5116 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005117 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexed");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06005118 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005119 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005120 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005121 dev_data->device_dispatch_table->CmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005122}
5123
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005124VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
5125{
5126 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005127 loader_platform_thread_lock_mutex(&globalLock);
5128 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005129 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005130 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005131 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDIRECT, "vkCmdDrawIndirect()");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005132 pCB->drawCount[DRAW_INDIRECT]++;
Ian Elliott8c8b2662016-01-30 10:57:03 -07005133 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005134 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005135 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005136 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005137 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",
5138 "vkCmdDrawIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005139 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07005140 if (VK_FALSE == skipCall) {
5141 updateResourceTrackingOnDraw(pCB);
5142 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005143 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndirect");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06005144 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005145 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005146 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005147 dev_data->device_dispatch_table->CmdDrawIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005148}
5149
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005150VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
5151{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005152 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005153 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005154 loader_platform_thread_lock_mutex(&globalLock);
5155 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005156 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005157 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXEDINDIRECT, "vkCmdDrawIndexedIndirect()");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005158 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
Ian Elliott8c8b2662016-01-30 10:57:03 -07005159 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005160 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005161 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005162 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005163 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",
5164 "vkCmdDrawIndexedIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005165 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07005166 if (VK_FALSE == skipCall) {
5167 updateResourceTrackingOnDraw(pCB);
5168 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005169 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexedIndirect");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06005170 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005171 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005172 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005173 dev_data->device_dispatch_table->CmdDrawIndexedIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005174}
5175
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005176VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z)
5177{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005178 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005179 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005180 loader_platform_thread_lock_mutex(&globalLock);
5181 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005182 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005183 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCH, "vkCmdDispatch()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005184 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatch");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005185 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005186 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005187 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005188 dev_data->device_dispatch_table->CmdDispatch(commandBuffer, x, y, z);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005189}
5190
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005191VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset)
5192{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005193 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005194 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005195 loader_platform_thread_lock_mutex(&globalLock);
5196 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005197 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005198 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCHINDIRECT, "vkCmdDispatchIndirect()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005199 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatchIndirect");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005200 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005201 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005202 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005203 dev_data->device_dispatch_table->CmdDispatchIndirect(commandBuffer, buffer, offset);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005204}
5205
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005206VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
5207{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005208 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005209 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005210 loader_platform_thread_lock_mutex(&globalLock);
5211 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005212 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005213 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFER, "vkCmdCopyBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005214 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005215 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005216 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005217 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005218 dev_data->device_dispatch_table->CmdCopyBuffer(commandBuffer, srcBuffer, dstBuffer, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005219}
5220
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005221VkBool32 VerifySourceImageLayout(VkCommandBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005222 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005223
5224#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
5225 // TODO: Fix -- initialLayout may have been set in a previous command buffer
5226 return skip_call;
5227#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5228
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005229 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5230 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Michael Lentineabc5e922015-10-12 11:30:14 -05005231 auto src_image_element = pCB->imageLayoutMap.find(srcImage);
5232 if (src_image_element == pCB->imageLayoutMap.end()) {
5233 pCB->imageLayoutMap[srcImage].initialLayout = srcImageLayout;
5234 pCB->imageLayoutMap[srcImage].layout = srcImageLayout;
Mark Youngb20a6a82016-01-07 15:41:43 -07005235 return VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05005236 }
5237 if (src_image_element->second.layout != srcImageLayout) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005238 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",
5239 "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 -05005240 }
5241 if (srcImageLayout != VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL) {
5242 if (srcImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005243 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
5244 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
5245 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Michael Lentineabc5e922015-10-12 11:30:14 -05005246 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005247 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
5248 "Layout for input image is %d but can only be TRANSFER_SRC_OPTIMAL or GENERAL.", srcImageLayout);
Michael Lentineabc5e922015-10-12 11:30:14 -05005249 }
5250 }
5251 return skip_call;
5252}
5253
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005254VkBool32 VerifyDestImageLayout(VkCommandBuffer cmdBuffer, VkImage destImage, VkImageLayout destImageLayout) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005255 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005256
5257#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
5258 // TODO: Fix -- initialLayout may have been set in a previous command buffer
5259 return skip_call;
5260#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5261
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005262 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5263 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Michael Lentineabc5e922015-10-12 11:30:14 -05005264 auto dest_image_element = pCB->imageLayoutMap.find(destImage);
5265 if (dest_image_element == pCB->imageLayoutMap.end()) {
5266 pCB->imageLayoutMap[destImage].initialLayout = destImageLayout;
5267 pCB->imageLayoutMap[destImage].layout = destImageLayout;
Mark Youngb20a6a82016-01-07 15:41:43 -07005268 return VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05005269 }
5270 if (dest_image_element->second.layout != destImageLayout) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005271 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",
5272 "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 -05005273 }
5274 if (destImageLayout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) {
5275 if (destImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005276 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
5277 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
5278 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Michael Lentineabc5e922015-10-12 11:30:14 -05005279 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005280 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
5281 "Layout for output image is %d but can only be TRANSFER_DST_OPTIMAL or GENERAL.", destImageLayout);
Michael Lentineabc5e922015-10-12 11:30:14 -05005282 }
5283 }
5284 return skip_call;
5285}
5286
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005287VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImage(VkCommandBuffer commandBuffer,
5288 VkImage srcImage,
5289 VkImageLayout srcImageLayout,
5290 VkImage dstImage,
5291 VkImageLayout dstImageLayout,
5292 uint32_t regionCount, const VkImageCopy* pRegions)
5293{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005294 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005295 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005296 loader_platform_thread_lock_mutex(&globalLock);
5297 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005298 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005299 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGE, "vkCmdCopyImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005300 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImage");
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005301 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
5302 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005303 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005304 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005305 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005306 dev_data->device_dispatch_table->CmdCopyImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005307}
5308
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005309VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBlitImage(VkCommandBuffer commandBuffer,
5310 VkImage srcImage, VkImageLayout srcImageLayout,
5311 VkImage dstImage, VkImageLayout dstImageLayout,
5312 uint32_t regionCount, const VkImageBlit* pRegions,
5313 VkFilter filter)
5314{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005315 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005316 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005317 loader_platform_thread_lock_mutex(&globalLock);
5318 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06005319 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005320 skipCall |= addCmd(dev_data, pCB, CMD_BLITIMAGE, "vkCmdBlitImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005321 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBlitImage");
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06005322 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005323 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005324 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005325 dev_data->device_dispatch_table->CmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter);
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06005326}
5327
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005328VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer,
5329 VkBuffer srcBuffer,
5330 VkImage dstImage, VkImageLayout dstImageLayout,
5331 uint32_t regionCount, const VkBufferImageCopy* pRegions)
5332{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005333 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005334 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005335 loader_platform_thread_lock_mutex(&globalLock);
5336 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005337 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005338 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFERTOIMAGE, "vkCmdCopyBufferToImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005339 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBufferToImage");
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005340 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005341 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005342 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005343 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005344 dev_data->device_dispatch_table->CmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005345}
5346
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005347VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer,
5348 VkImage srcImage, VkImageLayout srcImageLayout,
5349 VkBuffer dstBuffer,
5350 uint32_t regionCount, const VkBufferImageCopy* pRegions)
5351{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005352 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005353 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005354 loader_platform_thread_lock_mutex(&globalLock);
5355 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005356 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005357 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGETOBUFFER, "vkCmdCopyImageToBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005358 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImageToBuffer");
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005359 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005360 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005361 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005362 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005363 dev_data->device_dispatch_table->CmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005364}
5365
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005366VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize dataSize, const uint32_t* pData)
5367{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005368 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005369 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005370 loader_platform_thread_lock_mutex(&globalLock);
5371 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005372 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005373 skipCall |= addCmd(dev_data, pCB, CMD_UPDATEBUFFER, "vkCmdUpdateBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005374 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyUpdateBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005375 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005376 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005377 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005378 dev_data->device_dispatch_table->CmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005379}
5380
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005381VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize size, uint32_t data)
5382{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005383 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005384 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005385 loader_platform_thread_lock_mutex(&globalLock);
5386 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005387 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005388 skipCall |= addCmd(dev_data, pCB, CMD_FILLBUFFER, "vkCmdFillBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005389 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyFillBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005390 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005391 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005392 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005393 dev_data->device_dispatch_table->CmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005394}
5395
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005396VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearAttachments(
5397 VkCommandBuffer commandBuffer,
5398 uint32_t attachmentCount,
5399 const VkClearAttachment* pAttachments,
5400 uint32_t rectCount,
5401 const VkClearRect* pRects)
5402{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005403 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005404 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005405 loader_platform_thread_lock_mutex(&globalLock);
5406 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06005407 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005408 skipCall |= addCmd(dev_data, pCB, CMD_CLEARATTACHMENTS, "vkCmdClearAttachments()");
5409 // Warn if this is issued prior to Draw Cmd and clearing the entire attachment
5410 if (!hasDrawCmd(pCB) &&
5411 (pCB->activeRenderPassBeginInfo.renderArea.extent.width == pRects[0].rect.extent.width) &&
5412 (pCB->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005413 // TODO : commandBuffer should be srcObj
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005414 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",
5415 "vkCmdClearAttachments() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
5416 " 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 -06005417 }
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06005418 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdClearAttachments");
5419 }
5420
5421 // Validate that attachment is in reference list of active subpass
5422 if (pCB->activeRenderPass) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005423 const VkRenderPassCreateInfo *pRPCI = dev_data->renderPassMap[pCB->activeRenderPass]->pCreateInfo;
5424 const VkSubpassDescription *pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06005425
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005426 for (uint32_t attachment_idx = 0; attachment_idx < attachmentCount; attachment_idx++) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06005427 const VkClearAttachment *attachment = &pAttachments[attachment_idx];
5428 if (attachment->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) {
5429 VkBool32 found = VK_FALSE;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005430 for (uint32_t i = 0; i < pSD->colorAttachmentCount; i++) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005431 if (attachment->colorAttachment == pSD->pColorAttachments[i].attachment) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06005432 found = VK_TRUE;
5433 break;
5434 }
5435 }
5436 if (VK_FALSE == found) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005437 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
5438 (uint64_t)commandBuffer, __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
5439 "vkCmdClearAttachments() attachment index %d not found in attachment reference array of active subpass %d",
5440 attachment->colorAttachment, pCB->activeSubpass);
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06005441 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005442 } else if (attachment->aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) {
5443 if (!pSD->pDepthStencilAttachment || // Says no DS will be used in active subpass
5444 (pSD->pDepthStencilAttachment->attachment == VK_ATTACHMENT_UNUSED)) { // Says no DS will be used in active subpass
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07005445
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005446 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
5447 (uint64_t)commandBuffer, __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
5448 "vkCmdClearAttachments() attachment index %d does not match depthStencilAttachment.attachment (%d) found in active subpass %d",
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07005449 attachment->colorAttachment,
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005450 (pSD->pDepthStencilAttachment) ? pSD->pDepthStencilAttachment->attachment : VK_ATTACHMENT_UNUSED,
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07005451 pCB->activeSubpass);
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06005452 }
5453 }
5454 }
Tobin Ehlis53eddda2015-07-01 16:46:13 -06005455 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005456 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005457 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005458 dev_data->device_dispatch_table->CmdClearAttachments(commandBuffer, attachmentCount, pAttachments, rectCount, pRects);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06005459}
5460
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005461VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearColorImage(
5462 VkCommandBuffer commandBuffer,
5463 VkImage image, VkImageLayout imageLayout,
5464 const VkClearColorValue *pColor,
5465 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
5466{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005467 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005468 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005469 loader_platform_thread_lock_mutex(&globalLock);
5470 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005471 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005472 skipCall |= addCmd(dev_data, pCB, CMD_CLEARCOLORIMAGE, "vkCmdClearColorImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005473 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearColorImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005474 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005475 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005476 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005477 dev_data->device_dispatch_table->CmdClearColorImage(commandBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005478}
5479
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005480VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearDepthStencilImage(
5481 VkCommandBuffer commandBuffer,
5482 VkImage image, VkImageLayout imageLayout,
5483 const VkClearDepthStencilValue *pDepthStencil,
5484 uint32_t rangeCount,
5485 const VkImageSubresourceRange* pRanges)
5486{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005487 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005488 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005489 loader_platform_thread_lock_mutex(&globalLock);
5490 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005491 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005492 skipCall |= addCmd(dev_data, pCB, CMD_CLEARDEPTHSTENCILIMAGE, "vkCmdClearDepthStencilImage()");
5493 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearDepthStencilImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005494 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005495 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005496 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005497 dev_data->device_dispatch_table->CmdClearDepthStencilImage(commandBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005498}
5499
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005500VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResolveImage(VkCommandBuffer commandBuffer,
5501 VkImage srcImage, VkImageLayout srcImageLayout,
5502 VkImage dstImage, VkImageLayout dstImageLayout,
5503 uint32_t regionCount, const VkImageResolve* pRegions)
5504{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005505 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005506 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005507 loader_platform_thread_lock_mutex(&globalLock);
5508 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005509 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005510 skipCall |= addCmd(dev_data, pCB, CMD_RESOLVEIMAGE, "vkCmdResolveImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005511 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResolveImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005512 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005513 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005514 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005515 dev_data->device_dispatch_table->CmdResolveImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005516}
5517
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005518VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
5519{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005520 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005521 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005522 loader_platform_thread_lock_mutex(&globalLock);
5523 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005524 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005525 skipCall |= addCmd(dev_data, pCB, CMD_SETEVENT, "vkCmdSetEvent()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005526 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdSetEvent");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005527 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005528 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005529 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005530 dev_data->device_dispatch_table->CmdSetEvent(commandBuffer, event, stageMask);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005531}
5532
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005533VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
5534{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005535 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005536 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005537 loader_platform_thread_lock_mutex(&globalLock);
5538 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005539 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005540 skipCall |= addCmd(dev_data, pCB, CMD_RESETEVENT, "vkCmdResetEvent()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005541 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResetEvent");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005542 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005543 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005544 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005545 dev_data->device_dispatch_table->CmdResetEvent(commandBuffer, event, stageMask);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005546}
5547
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005548VkBool32 TransitionImageLayouts(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const VkImageMemoryBarrier* pImgMemBarriers) {
5549 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005550 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer, false);
Mark Youngb20a6a82016-01-07 15:41:43 -07005551 VkBool32 skip = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005552
5553#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005554 // TODO: Fix -- pay attention to image subresource ranges -- not all subresources transition at the same time
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005555 return skip;
5556#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5557
Michael Lentineabc5e922015-10-12 11:30:14 -05005558 for (uint32_t i = 0; i < memBarrierCount; ++i) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005559 auto mem_barrier = &pImgMemBarriers[i];
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005560 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005561 auto image_data = pCB->imageLayoutMap.find(mem_barrier->image);
Michael Lentineabc5e922015-10-12 11:30:14 -05005562 if (image_data == pCB->imageLayoutMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005563 pCB->imageLayoutMap[mem_barrier->image].initialLayout = mem_barrier->oldLayout;
5564 pCB->imageLayoutMap[mem_barrier->image].layout = mem_barrier->newLayout;
Michael Lentineabc5e922015-10-12 11:30:14 -05005565 } else {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005566 if (image_data->second.layout != mem_barrier->oldLayout) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005567 skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
5568 "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 -05005569 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07005570 image_data->second.layout = mem_barrier->newLayout;
Michael Lentineabc5e922015-10-12 11:30:14 -05005571 }
5572 }
5573 }
5574 return skip;
5575}
5576
Mark Lobodzinskia3a86112016-01-05 17:17:55 -07005577// Print readable FlagBits in FlagMask
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005578std::string string_VkAccessFlags(VkAccessFlags accessMask)
5579{
Mark Lobodzinskia3a86112016-01-05 17:17:55 -07005580 std::string result;
5581 std::string separator;
5582
5583 if (accessMask == 0) {
5584 result = "[None]";
5585 } else {
5586 result = "[";
5587 for (auto i = 0; i < 32; i++) {
5588 if (accessMask & (1 << i)) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005589 result = result + separator + string_VkAccessFlagBits((VkAccessFlagBits)(1 << i));
Mark Lobodzinskia3a86112016-01-05 17:17:55 -07005590 separator = " | ";
5591 }
5592 }
5593 result = result + "]";
5594 }
5595 return result;
5596}
5597
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005598// AccessFlags MUST have 'required_bit' set, and may have one or more of 'optional_bits' set.
5599// If required_bit is zero, accessMask must have at least one of 'optional_bits' set
5600// TODO: Add tracking to ensure that at least one barrier has been set for these layout transitions
5601VkBool32 ValidateMaskBits(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout,
5602 VkAccessFlags required_bit, VkAccessFlags optional_bits, const char* type) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005603 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005604
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005605 if ((accessMask & required_bit) || (!required_bit && (accessMask & optional_bits))) {
Michael Lentine97eb7462015-11-20 09:48:52 -08005606 if (accessMask & !(required_bit | optional_bits)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005607 // TODO: Verify against Valid Use
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005608 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
5609 "Additional bits in %s accessMask %d %s are specified when layout is %s.",
5610 type, accessMask, string_VkAccessFlags(accessMask).c_str(), string_VkImageLayout(layout));
Michael Lentineecc32b72015-10-16 18:08:09 -05005611 }
5612 } else {
Michael Lentine97eb7462015-11-20 09:48:52 -08005613 if (!required_bit) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005614 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
5615 "%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.",
5616 type, accessMask, string_VkAccessFlags(accessMask).c_str(), optional_bits,
5617 string_VkAccessFlags(optional_bits).c_str(), string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08005618 } else {
Mark Lobodzinskif2cc2a52016-01-05 13:35:29 -07005619 std::string opt_bits;
5620 if (optional_bits != 0) {
Michael Lentine6bd4f122016-01-19 14:00:53 -06005621 std::stringstream ss;
5622 ss << optional_bits;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005623 opt_bits = "and may have optional bits " + ss.str() + ' ' + string_VkAccessFlags(optional_bits);
Mark Lobodzinskif2cc2a52016-01-05 13:35:29 -07005624 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005625 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
5626 "%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.",
5627 type, accessMask, string_VkAccessFlags(accessMask).c_str(),
5628 required_bit, string_VkAccessFlags(required_bit).c_str(),
5629 opt_bits.c_str(), string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08005630 }
Michael Lentineecc32b72015-10-16 18:08:09 -05005631 }
5632 return skip_call;
5633}
5634
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005635VkBool32 ValidateMaskBitsFromLayouts(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout, const char* type) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005636 VkBool32 skip_call = VK_FALSE;
Michael Lentine97eb7462015-11-20 09:48:52 -08005637 switch (layout) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005638 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: {
5639 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_COLOR_ATTACHMENT_READ_BIT, type);
5640 break;
Michael Lentineecc32b72015-10-16 18:08:09 -05005641 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005642 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: {
5643 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT, type);
5644 break;
5645 }
5646 case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: {
5647 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_WRITE_BIT, 0, type);
5648 break;
5649 }
5650 case VK_IMAGE_LAYOUT_PREINITIALIZED: {
5651 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_HOST_WRITE_BIT, 0, type);
5652 break;
5653 }
5654 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: {
5655 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, 0, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT, type);
5656 break;
5657 }
5658 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: {
5659 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, 0, VK_ACCESS_INPUT_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT, type);
5660 break;
5661 }
5662 case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: {
5663 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_READ_BIT, 0, type);
5664 break;
5665 }
5666 case VK_IMAGE_LAYOUT_UNDEFINED: {
5667 if (accessMask != 0) {
5668 // TODO: Verify against Valid Use section spec
5669 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
5670 "Additional bits in %s accessMask %d %s are specified when layout is %s.", type, accessMask, string_VkAccessFlags(accessMask).c_str(),
5671 string_VkImageLayout(layout));
5672 }
5673 break;
5674 }
5675 case VK_IMAGE_LAYOUT_GENERAL:
5676 default: {
5677 break;
5678 }
Michael Lentineecc32b72015-10-16 18:08:09 -05005679 }
5680 return skip_call;
5681}
5682
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005683VkBool32 ValidateBarriers(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const VkMemoryBarrier* pMemBarriers, uint32_t imageMemBarrierCount, const VkImageMemoryBarrier *pImageMemBarriers)
5684{
Mark Youngb20a6a82016-01-07 15:41:43 -07005685 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005686 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005687 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer, false);
Michael Lentine48930b82015-10-15 17:07:00 -05005688 if (pCB->activeRenderPass && memBarrierCount) {
5689 for (uint32_t i = 0; i < memBarrierCount; ++i) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005690 auto mem_barrier = &pMemBarriers[i];
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005691 if (mem_barrier && mem_barrier->sType != VK_STRUCTURE_TYPE_MEMORY_BARRIER) {
5692 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
5693 "Image or Buffers Barriers cannot be used during a render pass.");
Michael Lentine48930b82015-10-15 17:07:00 -05005694 }
5695 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005696 if (!dev_data->renderPassMap[pCB->activeRenderPass]->hasSelfDependency[pCB->activeSubpass]) {
5697 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
5698 "Barriers cannot be set during subpass %d with no self dependency specified.", pCB->activeSubpass);
Michael Lentine48930b82015-10-15 17:07:00 -05005699 }
5700 }
Mark Lobodzinski73a37ec2015-11-20 09:27:27 -07005701
Jon Ashburnf19916e2016-01-11 13:12:43 -07005702 for (uint32_t i = 0; i < imageMemBarrierCount; ++i) {
5703 auto mem_barrier = &pImageMemBarriers[i];
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005704 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
5705 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, mem_barrier->srcAccessMask, mem_barrier->oldLayout, "Source");
5706 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, mem_barrier->dstAccessMask, mem_barrier->newLayout, "Dest");
Michael Lentineecc32b72015-10-16 18:08:09 -05005707 }
5708 }
Mark Lobodzinski3cba24a2015-12-03 15:42:32 -07005709
Michael Lentine48930b82015-10-15 17:07:00 -05005710 return skip_call;
5711}
5712
Jon Ashburnf19916e2016-01-11 13:12:43 -07005713VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdWaitEvents(
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005714 VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent* pEvents,
5715 VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask,
5716 uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers,
5717 uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers,
5718 uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers)
5719{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005720 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005721 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005722 loader_platform_thread_lock_mutex(&globalLock);
5723 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005724 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005725 for (uint32_t i = 0; i < eventCount; ++i) {
5726 pCB->waitedEvents.push_back(pEvents[i]);
5727 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005728 if (pCB->state == CB_RECORDING) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005729 skipCall |= addCmd(dev_data, pCB, CMD_WAITEVENTS, "vkCmdWaitEvents()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005730 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005731 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdWaitEvents()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005732 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005733 skipCall |= TransitionImageLayouts(commandBuffer, imageMemoryBarrierCount, pImageMemoryBarriers);
5734 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, pMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005735 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005736 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005737 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005738 dev_data->device_dispatch_table->CmdWaitEvents(commandBuffer, eventCount, pEvents, sourceStageMask, dstStageMask,
5739 memoryBarrierCount, pMemoryBarriers,
5740 bufferMemoryBarrierCount, pBufferMemoryBarriers,
5741 imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005742}
5743
Jon Ashburnf19916e2016-01-11 13:12:43 -07005744VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdPipelineBarrier(
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005745 VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask,
5746 VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags,
5747 uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers,
5748 uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers,
5749 uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers)
5750{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005751 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005752 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005753 loader_platform_thread_lock_mutex(&globalLock);
5754 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005755 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005756 skipCall |= addCmd(dev_data, pCB, CMD_PIPELINEBARRIER, "vkCmdPipelineBarrier()");
5757 skipCall |= TransitionImageLayouts(commandBuffer, imageMemoryBarrierCount, pImageMemoryBarriers);
5758 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, pMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005759 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005760 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005761 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005762 dev_data->device_dispatch_table->CmdPipelineBarrier(commandBuffer, srcStageMask, dstStageMask, dependencyFlags,
5763 memoryBarrierCount, pMemoryBarriers,
5764 bufferMemoryBarrierCount, pBufferMemoryBarriers,
5765 imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005766}
5767
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005768VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
5769{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005770 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005771 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005772 loader_platform_thread_lock_mutex(&globalLock);
5773 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005774 if (pCB) {
Michael Lentinedc6f8de2016-02-02 18:29:30 -06005775 QueryObject query = {queryPool, slot};
5776 pCB->activeQueries.insert(query);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005777 skipCall |= addCmd(dev_data, pCB, CMD_BEGINQUERY, "vkCmdBeginQuery()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005778 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005779 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005780 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005781 dev_data->device_dispatch_table->CmdBeginQuery(commandBuffer, queryPool, slot, flags);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005782}
5783
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005784VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot)
5785{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005786 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005787 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005788 loader_platform_thread_lock_mutex(&globalLock);
5789 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005790 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005791 QueryObject query = {queryPool, slot};
Michael Lentinedc6f8de2016-02-02 18:29:30 -06005792 if (!pCB->activeQueries.count(query)) {
5793 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_QUERY, "DS",
5794 "Ending a query before it was started: queryPool %" PRIu64 ", index %d", (uint64_t)(queryPool), slot);
5795 } else {
5796 pCB->activeQueries.erase(query);
5797 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06005798 pCB->queryToStateMap[query] = 1;
Mark Lobodzinskice738852016-01-07 10:04:02 -07005799 if (pCB->state == CB_RECORDING) {
5800 skipCall |= addCmd(dev_data, pCB, CMD_ENDQUERY, "VkCmdEndQuery()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005801 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005802 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdEndQuery()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005803 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005804 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005805 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005806 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005807 dev_data->device_dispatch_table->CmdEndQuery(commandBuffer, queryPool, slot);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005808}
5809
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005810VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResetQueryPool(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount)
5811{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005812 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005813 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005814 loader_platform_thread_lock_mutex(&globalLock);
5815 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005816 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005817 for (uint32_t i = 0; i < queryCount; i++) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005818 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06005819 pCB->waitedEventsBeforeQueryReset[query] = pCB->waitedEvents;
5820 pCB->queryToStateMap[query] = 0;
5821 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005822 if (pCB->state == CB_RECORDING) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005823 skipCall |= addCmd(dev_data, pCB, CMD_RESETQUERYPOOL, "VkCmdResetQueryPool()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005824 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005825 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdResetQueryPool()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005826 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005827 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdQueryPool");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005828 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005829 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005830 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005831 dev_data->device_dispatch_table->CmdResetQueryPool(commandBuffer, queryPool, firstQuery, queryCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005832}
5833
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005834VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery,
5835 uint32_t queryCount, VkBuffer dstBuffer, VkDeviceSize dstOffset,
5836 VkDeviceSize stride, VkQueryResultFlags flags)
5837{
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005838 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005839 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005840 loader_platform_thread_lock_mutex(&globalLock);
5841 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005842 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005843 for (uint32_t i = 0; i < queryCount; i++) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005844 QueryObject query = {queryPool, firstQuery + i};
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005845 if(!pCB->queryToStateMap[query]) {
5846 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_QUERY, "DS",
5847 "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 -06005848 }
5849 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005850 if (pCB->state == CB_RECORDING) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005851 skipCall |= addCmd(dev_data, pCB, CMD_COPYQUERYPOOLRESULTS, "vkCmdCopyQueryPoolResults()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005852 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005853 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdCopyQueryPoolResults()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005854 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005855 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyQueryPoolResults");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005856 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005857 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005858 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005859 dev_data->device_dispatch_table->CmdCopyQueryPoolResults(commandBuffer, queryPool,
5860 firstQuery, queryCount, dstBuffer, dstOffset, stride, flags);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005861}
5862
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005863VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, VkQueryPool queryPool, uint32_t slot)
5864{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005865 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005866 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07005867 loader_platform_thread_lock_mutex(&globalLock);
5868 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005869 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005870 QueryObject query = {queryPool, slot};
5871 pCB->queryToStateMap[query] = 1;
Mark Lobodzinskice738852016-01-07 10:04:02 -07005872 if (pCB->state == CB_RECORDING) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005873 skipCall |= addCmd(dev_data, pCB, CMD_WRITETIMESTAMP, "vkCmdWriteTimestamp()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005874 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005875 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdWriteTimestamp()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005876 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005877 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005878 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005879 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005880 dev_data->device_dispatch_table->CmdWriteTimestamp(commandBuffer, pipelineStage, queryPool, slot);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005881}
5882
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005883VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkFramebuffer* pFramebuffer)
5884{
5885 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5886 VkResult result = dev_data->device_dispatch_table->CreateFramebuffer(device, pCreateInfo, pAllocator, pFramebuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005887 if (VK_SUCCESS == result) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06005888 // Shadow create info and store in map
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005889 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +08005890 if (pCreateInfo->pAttachments) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005891 localFBCI->pAttachments = new VkImageView[localFBCI->attachmentCount];
5892 memcpy((void*)localFBCI->pAttachments, pCreateInfo->pAttachments, localFBCI->attachmentCount*sizeof(VkImageView));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005893 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07005894 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08005895 dev_data->frameBufferMap[*pFramebuffer] = localFBCI;
Ian Elliott8c8b2662016-01-30 10:57:03 -07005896 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehliseba312c2015-04-01 08:40:34 -06005897 }
5898 return result;
5899}
5900
Michael Lentineb6986752015-10-06 14:56:18 -07005901// Store the DAG.
5902struct DAGNode {
5903 uint32_t pass;
5904 std::vector<uint32_t> prev;
5905 std::vector<uint32_t> next;
5906};
5907
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005908VkBool32 FindDependency(const int index, const int dependent, const std::vector<DAGNode>& subpass_to_node, std::unordered_set<uint32_t>& processed_nodes) {
5909 // If we have already checked this node we have not found a dependency path so return false.
Michael Lentineb6986752015-10-06 14:56:18 -07005910 if (processed_nodes.count(index))
Mark Youngb20a6a82016-01-07 15:41:43 -07005911 return VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005912 processed_nodes.insert(index);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005913 const DAGNode& node = subpass_to_node[index];
5914 // Look for a dependency path. If one exists return true else recurse on the previous nodes.
5915 if (std::find(node.prev.begin(), node.prev.end(), dependent) == node.prev.end()) {
Michael Lentineb6986752015-10-06 14:56:18 -07005916 for (auto elem : node.prev) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005917 if (FindDependency(elem, dependent, subpass_to_node, processed_nodes))
Mark Youngb20a6a82016-01-07 15:41:43 -07005918 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005919 }
5920 } else {
Mark Youngb20a6a82016-01-07 15:41:43 -07005921 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005922 }
Mark Youngb20a6a82016-01-07 15:41:43 -07005923 return VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005924}
5925
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005926VkBool32 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 -07005927 VkBool32 result = VK_TRUE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005928 // Loop through all subpasses that share the same attachment and make sure a dependency exists
Michael Lentineb6986752015-10-06 14:56:18 -07005929 for (uint32_t k = 0; k < dependent_subpasses.size(); ++k) {
5930 if (subpass == dependent_subpasses[k])
5931 continue;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005932 const DAGNode& node = subpass_to_node[subpass];
5933 // Check for a specified dependency between the two nodes. If one exists we are done.
5934 auto prev_elem = std::find(node.prev.begin(), node.prev.end(), dependent_subpasses[k]);
5935 auto next_elem = std::find(node.next.begin(), node.next.end(), dependent_subpasses[k]);
Michael Lentineb6986752015-10-06 14:56:18 -07005936 if (prev_elem == node.prev.end() && next_elem == node.next.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005937 // 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 -07005938 std::unordered_set<uint32_t> processed_nodes;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005939 if (FindDependency(subpass, dependent_subpasses[k], subpass_to_node, processed_nodes) ||
5940 FindDependency(dependent_subpasses[k], subpass, subpass_to_node, processed_nodes)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005941 // TODO: Verify against Valid Use section of spec
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005942 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
5943 "A dependency between subpasses %d and %d must exist but only an implicit one is specified.",
5944 subpass, dependent_subpasses[k]);
Michael Lentineb6986752015-10-06 14:56:18 -07005945 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005946 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
5947 "A dependency between subpasses %d and %d must exist but one is not specified.",
5948 subpass, dependent_subpasses[k]);
Mark Youngb20a6a82016-01-07 15:41:43 -07005949 result = VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005950 }
5951 }
5952 }
5953 return result;
5954}
5955
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005956VkBool32 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) {
5957 const DAGNode& node = subpass_to_node[index];
5958 // If this node writes to the attachment return true as next nodes need to preserve the attachment.
5959 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005960 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005961 if (attachment == subpass.pColorAttachments[j].attachment)
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005962 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005963 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005964 if (subpass.pDepthStencilAttachment &&
5965 subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
5966 if (attachment == subpass.pDepthStencilAttachment->attachment)
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005967 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005968 }
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005969 VkBool32 result = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005970 // Loop through previous nodes and see if any of them write to the attachment.
Michael Lentineb6986752015-10-06 14:56:18 -07005971 for (auto elem : node.prev) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005972 result |= CheckPreserved(my_data, device, pCreateInfo, elem, attachment, subpass_to_node, depth + 1, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005973 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005974 // If the attachment was written to by a previous node than this node needs to preserve it.
Michael Lentineb6986752015-10-06 14:56:18 -07005975 if (result && depth > 0) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005976 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Mark Youngb20a6a82016-01-07 15:41:43 -07005977 VkBool32 has_preserved = VK_FALSE;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005978 for (uint32_t j = 0; j < subpass.preserveAttachmentCount; ++j) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005979 if (subpass.pPreserveAttachments[j] == attachment) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005980 has_preserved = VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005981 break;
5982 }
5983 }
Mark Youngb20a6a82016-01-07 15:41:43 -07005984 if (has_preserved == VK_FALSE) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005985 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
5986 "Attachment %d is used by a later subpass and must be preserved in subpass %d.", attachment, index);
Michael Lentineb6986752015-10-06 14:56:18 -07005987 }
5988 }
5989 return result;
5990}
5991
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005992VkBool32 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 -07005993 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005994 std::vector<std::vector<uint32_t>> output_attachment_to_subpass(pCreateInfo->attachmentCount);
5995 std::vector<std::vector<uint32_t>> input_attachment_to_subpass(pCreateInfo->attachmentCount);
Michael Lentineb6986752015-10-06 14:56:18 -07005996 // Find for each attachment the subpasses that use them.
5997 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005998 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005999 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006000 input_attachment_to_subpass[subpass.pInputAttachments[j].attachment].push_back(i);
Michael Lentineb6986752015-10-06 14:56:18 -07006001 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08006002 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006003 output_attachment_to_subpass[subpass.pColorAttachments[j].attachment].push_back(i);
Michael Lentineb6986752015-10-06 14:56:18 -07006004 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006005 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
6006 output_attachment_to_subpass[subpass.pDepthStencilAttachment->attachment].push_back(i);
Michael Lentineb6986752015-10-06 14:56:18 -07006007 }
6008 }
6009 // If there is a dependency needed make sure one exists
6010 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006011 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
6012 // If the attachment is an input then all subpasses that output must have a dependency relationship
Chia-I Wud50a7d72015-10-26 20:48:51 +08006013 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006014 const uint32_t& attachment = subpass.pInputAttachments[j].attachment;
6015 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07006016 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006017 // 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 +08006018 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006019 const uint32_t& attachment = subpass.pColorAttachments[j].attachment;
6020 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
6021 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07006022 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006023 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
6024 const uint32_t& attachment = subpass.pDepthStencilAttachment->attachment;
6025 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
6026 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07006027 }
6028 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006029 // 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 -07006030 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006031 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08006032 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006033 CheckPreserved(my_data, device, pCreateInfo, i, subpass.pInputAttachments[j].attachment, subpass_to_node, 0, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07006034 }
6035 }
6036 return skip_call;
6037}
6038
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006039VkBool32 ValidateLayouts(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo) {
Mark Youngb20a6a82016-01-07 15:41:43 -07006040 VkBool32 skip = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006041
6042#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
6043 return skip;
6044#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
6045
Michael Lentineabc5e922015-10-12 11:30:14 -05006046 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006047 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Michael Lentineabc5e922015-10-12 11:30:14 -05006048 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006049 if (subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL &&
6050 subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) {
6051 if (subpass.pInputAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
6052 // TODO: Verify Valid Use in spec. I believe this is allowed (valid) but may not be optimal performance
6053 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
6054 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Michael Lentineabc5e922015-10-12 11:30:14 -05006055 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006056 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
6057 "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 -05006058 }
6059 }
6060 }
6061 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006062 if (subpass.pColorAttachments[j].layout != VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) {
6063 if (subpass.pColorAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
6064 // TODO: Verify Valid Use in spec. I believe this is allowed (valid) but may not be optimal performance
6065 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
6066 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Michael Lentineabc5e922015-10-12 11:30:14 -05006067 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006068 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
6069 "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 -05006070 }
6071 }
6072 }
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06006073 if ((subpass.pDepthStencilAttachment != NULL) &&
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006074 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
6075 if (subpass.pDepthStencilAttachment->layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) {
6076 if (subpass.pDepthStencilAttachment->layout == VK_IMAGE_LAYOUT_GENERAL) {
6077 // TODO: Verify Valid Use in spec. I believe this is allowed (valid) but may not be optimal performance
6078 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
6079 "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL.");
Michael Lentineabc5e922015-10-12 11:30:14 -05006080 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006081 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
6082 "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 -05006083 }
6084 }
6085 }
6086 }
6087 return skip;
6088}
6089
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006090VkBool32 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 -07006091 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05006092 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006093 DAGNode& subpass_node = subpass_to_node[i];
Michael Lentineabc5e922015-10-12 11:30:14 -05006094 subpass_node.pass = i;
6095 }
6096 for (uint32_t i = 0; i < pCreateInfo->dependencyCount; ++i) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006097 const VkSubpassDependency& dependency = pCreateInfo->pDependencies[i];
6098 if (dependency.srcSubpass > dependency.dstSubpass && dependency.srcSubpass != VK_SUBPASS_EXTERNAL && dependency.dstSubpass != VK_SUBPASS_EXTERNAL) {
6099 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
6100 "Depedency graph must be specified such that an earlier pass cannot depend on a later pass.");
6101 } else if (dependency.srcSubpass == VK_SUBPASS_EXTERNAL && dependency.dstSubpass == VK_SUBPASS_EXTERNAL) {
6102 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
6103 "The src and dest subpasses cannot both be external.");
Michael Lentine48930b82015-10-15 17:07:00 -05006104 } else if (dependency.srcSubpass == dependency.dstSubpass) {
6105 has_self_dependency[dependency.srcSubpass] = true;
Michael Lentineabc5e922015-10-12 11:30:14 -05006106 }
Michael Lentine6bd4f122016-01-19 14:00:53 -06006107 if (dependency.dstSubpass != VK_SUBPASS_EXTERNAL) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006108 subpass_to_node[dependency.dstSubpass].prev.push_back(dependency.srcSubpass);
Michael Lentine6bd4f122016-01-19 14:00:53 -06006109 }
6110 if (dependency.srcSubpass != VK_SUBPASS_EXTERNAL) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006111 subpass_to_node[dependency.srcSubpass].next.push_back(dependency.dstSubpass);
Michael Lentine6bd4f122016-01-19 14:00:53 -06006112 }
Michael Lentineabc5e922015-10-12 11:30:14 -05006113 }
6114 return skip_call;
6115}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006116// TODOSC : Add intercept of vkCreateShaderModule
Michael Lentineabc5e922015-10-12 11:30:14 -05006117
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006118VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateShaderModule(
6119 VkDevice device,
6120 const VkShaderModuleCreateInfo *pCreateInfo,
6121 const VkAllocationCallbacks* pAllocator,
6122 VkShaderModule *pShaderModule)
6123{
6124 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07006125 VkBool32 skip_call = VK_FALSE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006126 if (!shader_is_spirv(pCreateInfo)) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006127 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
6128 /* dev */ 0, __LINE__, SHADER_CHECKER_NON_SPIRV_SHADER, "SC",
6129 "Shader is not SPIR-V");
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006130 }
6131
Mark Youngb20a6a82016-01-07 15:41:43 -07006132 if (VK_FALSE != skip_call)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07006133 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006134
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006135 VkResult res = my_data->device_dispatch_table->CreateShaderModule(device, pCreateInfo, pAllocator, pShaderModule);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006136
6137 if (res == VK_SUCCESS) {
6138 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006139 my_data->shaderModuleMap[*pShaderModule] = new shader_module(pCreateInfo);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006140 loader_platform_thread_unlock_mutex(&globalLock);
6141 }
6142 return res;
6143}
6144
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006145VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkRenderPass* pRenderPass)
6146{
Mark Youngb20a6a82016-01-07 15:41:43 -07006147 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006148 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07006149 loader_platform_thread_lock_mutex(&globalLock);
Michael Lentineabc5e922015-10-12 11:30:14 -05006150 // Create DAG
Michael Lentine48930b82015-10-15 17:07:00 -05006151 std::vector<bool> has_self_dependency(pCreateInfo->subpassCount);
Michael Lentineabc5e922015-10-12 11:30:14 -05006152 std::vector<DAGNode> subpass_to_node(pCreateInfo->subpassCount);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006153 skip_call |= CreatePassDAG(dev_data, device, pCreateInfo, subpass_to_node, has_self_dependency);
Michael Lentineabc5e922015-10-12 11:30:14 -05006154 // Validate using DAG
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006155 skip_call |= ValidateDependencies(dev_data, device, pCreateInfo, subpass_to_node);
Michael Lentineabc5e922015-10-12 11:30:14 -05006156 skip_call |= ValidateLayouts(dev_data, device, pCreateInfo);
Mark Youngb20a6a82016-01-07 15:41:43 -07006157 if (VK_FALSE != skip_call) {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07006158 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentineb6986752015-10-06 14:56:18 -07006159 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07006160 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006161 VkResult result = dev_data->device_dispatch_table->CreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006162 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006163 // TODOSC : Merge in tracking of renderpass from ShaderChecker
Tobin Ehliseba312c2015-04-01 08:40:34 -06006164 // Shadow create info and store in map
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006165 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +08006166 if (pCreateInfo->pAttachments) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006167 localRPCI->pAttachments = new VkAttachmentDescription[localRPCI->attachmentCount];
6168 memcpy((void*)localRPCI->pAttachments, pCreateInfo->pAttachments, localRPCI->attachmentCount*sizeof(VkAttachmentDescription));
Tobin Ehliseba312c2015-04-01 08:40:34 -06006169 }
Chia-I Wu08accc62015-07-07 11:50:03 +08006170 if (pCreateInfo->pSubpasses) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006171 localRPCI->pSubpasses = new VkSubpassDescription[localRPCI->subpassCount];
6172 memcpy((void*)localRPCI->pSubpasses, pCreateInfo->pSubpasses, localRPCI->subpassCount*sizeof(VkSubpassDescription));
Chia-I Wu08accc62015-07-07 11:50:03 +08006173
6174 for (uint32_t i = 0; i < localRPCI->subpassCount; i++) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006175 VkSubpassDescription *subpass = (VkSubpassDescription *) &localRPCI->pSubpasses[i];
6176 const uint32_t attachmentCount = subpass->inputAttachmentCount +
6177 subpass->colorAttachmentCount * (1 + (subpass->pResolveAttachments?1:0)) +
6178 ((subpass->pDepthStencilAttachment) ? 1 : 0) + subpass->preserveAttachmentCount;
6179 VkAttachmentReference *attachments = new VkAttachmentReference[attachmentCount];
Chia-I Wu08accc62015-07-07 11:50:03 +08006180
Cody Northropa505dda2015-08-04 11:16:41 -06006181 memcpy(attachments, subpass->pInputAttachments,
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006182 sizeof(attachments[0]) * subpass->inputAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06006183 subpass->pInputAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006184 attachments += subpass->inputAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08006185
Cody Northropa505dda2015-08-04 11:16:41 -06006186 memcpy(attachments, subpass->pColorAttachments,
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006187 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06006188 subpass->pColorAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006189 attachments += subpass->colorAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08006190
Cody Northropa505dda2015-08-04 11:16:41 -06006191 if (subpass->pResolveAttachments) {
6192 memcpy(attachments, subpass->pResolveAttachments,
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006193 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06006194 subpass->pResolveAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006195 attachments += subpass->colorAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08006196 }
6197
Chia-I Wu1efb7e52015-10-26 17:32:47 +08006198 if (subpass->pDepthStencilAttachment) {
6199 memcpy(attachments, subpass->pDepthStencilAttachment,
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006200 sizeof(attachments[0]) * 1);
Chia-I Wu1efb7e52015-10-26 17:32:47 +08006201 subpass->pDepthStencilAttachment = attachments;
6202 attachments += 1;
6203 }
6204
Cody Northropa505dda2015-08-04 11:16:41 -06006205 memcpy(attachments, subpass->pPreserveAttachments,
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006206 sizeof(attachments[0]) * subpass->preserveAttachmentCount);
Jon Ashburnf19916e2016-01-11 13:12:43 -07006207 subpass->pPreserveAttachments = &attachments->attachment;
Chia-I Wu08accc62015-07-07 11:50:03 +08006208 }
Tobin Ehliseba312c2015-04-01 08:40:34 -06006209 }
Chia-I Wu08accc62015-07-07 11:50:03 +08006210 if (pCreateInfo->pDependencies) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006211 localRPCI->pDependencies = new VkSubpassDependency[localRPCI->dependencyCount];
6212 memcpy((void*)localRPCI->pDependencies, pCreateInfo->pDependencies, localRPCI->dependencyCount*sizeof(VkSubpassDependency));
Tobin Ehliseba312c2015-04-01 08:40:34 -06006213 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006214 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07006215 dev_data->renderPassMap[*pRenderPass] = new RENDER_PASS_NODE(localRPCI);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006216 dev_data->renderPassMap[*pRenderPass]->hasSelfDependency = has_self_dependency;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006217 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehliseba312c2015-04-01 08:40:34 -06006218 }
6219 return result;
6220}
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06006221// Free the renderpass shadow
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006222static void deleteRenderPasses(layer_data* my_data)
6223{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06006224 if (my_data->renderPassMap.size() <= 0)
6225 return;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006226 for (auto ii=my_data->renderPassMap.begin(); ii!=my_data->renderPassMap.end(); ++ii) {
6227 const VkRenderPassCreateInfo* pRenderPassInfo = (*ii).second->pCreateInfo;
Michael Lentine48930b82015-10-15 17:07:00 -05006228 if (pRenderPassInfo->pAttachments) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006229 delete[] pRenderPassInfo->pAttachments;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06006230 }
Michael Lentine48930b82015-10-15 17:07:00 -05006231 if (pRenderPassInfo->pSubpasses) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006232 for (uint32_t i=0; i<pRenderPassInfo->subpassCount; ++i) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06006233 // Attachements are all allocated in a block, so just need to
6234 // find the first non-null one to delete
Michael Lentine48930b82015-10-15 17:07:00 -05006235 if (pRenderPassInfo->pSubpasses[i].pInputAttachments) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006236 delete[] pRenderPassInfo->pSubpasses[i].pInputAttachments;
Michael Lentine48930b82015-10-15 17:07:00 -05006237 } else if (pRenderPassInfo->pSubpasses[i].pColorAttachments) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006238 delete[] pRenderPassInfo->pSubpasses[i].pColorAttachments;
Michael Lentine48930b82015-10-15 17:07:00 -05006239 } else if (pRenderPassInfo->pSubpasses[i].pResolveAttachments) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006240 delete[] pRenderPassInfo->pSubpasses[i].pResolveAttachments;
6241 } else if (pRenderPassInfo->pSubpasses[i].pPreserveAttachments) {
6242 delete[] pRenderPassInfo->pSubpasses[i].pPreserveAttachments;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06006243 }
6244 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006245 delete[] pRenderPassInfo->pSubpasses;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06006246 }
Michael Lentine48930b82015-10-15 17:07:00 -05006247 if (pRenderPassInfo->pDependencies) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006248 delete[] pRenderPassInfo->pDependencies;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06006249 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07006250 delete pRenderPassInfo;
Michael Lentine48930b82015-10-15 17:07:00 -05006251 delete (*ii).second;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06006252 }
6253 my_data->renderPassMap.clear();
6254}
Michael Lentineabc5e922015-10-12 11:30:14 -05006255
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006256VkBool32 VerifyFramebufferAndRenderPassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
Mark Youngb20a6a82016-01-07 15:41:43 -07006257 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006258 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07006259 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer, false);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006260 const VkRenderPassCreateInfo* pRenderPassInfo = dev_data->renderPassMap[pRenderPassBegin->renderPass]->pCreateInfo;
6261 const VkFramebufferCreateInfo* pFramebufferInfo = dev_data->frameBufferMap[pRenderPassBegin->framebuffer];
Michael Lentineabc5e922015-10-12 11:30:14 -05006262 if (pRenderPassInfo->attachmentCount != pFramebufferInfo->attachmentCount) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006263 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
6264 "You cannot start a render pass using a framebuffer with a different number of attachments.");
Michael Lentineabc5e922015-10-12 11:30:14 -05006265 }
6266 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006267 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
6268 const VkImage& image = dev_data->imageViewMap[image_view]->image;
Michael Lentineabc5e922015-10-12 11:30:14 -05006269 auto image_data = pCB->imageLayoutMap.find(image);
6270 if (image_data == pCB->imageLayoutMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006271 pCB->imageLayoutMap[image].initialLayout = pRenderPassInfo->pAttachments[i].initialLayout;
6272 pCB->imageLayoutMap[image].layout = pRenderPassInfo->pAttachments[i].initialLayout;
6273 } else if (pRenderPassInfo->pAttachments[i].initialLayout != image_data->second.layout) {
6274 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
6275 "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 -05006276 }
6277 }
6278 return skip_call;
6279}
6280
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006281void TransitionSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, const int subpass_index) {
6282 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07006283 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer, false);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006284 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
Michael Lentineabc5e922015-10-12 11:30:14 -05006285 if (render_pass_data == dev_data->renderPassMap.end()) {
6286 return;
6287 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006288 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
6289 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
Michael Lentineabc5e922015-10-12 11:30:14 -05006290 if (framebuffer_data == dev_data->frameBufferMap.end()) {
6291 return;
6292 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006293 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
6294 const VkSubpassDescription& subpass = pRenderPassInfo->pSubpasses[subpass_index];
Michael Lentineabc5e922015-10-12 11:30:14 -05006295 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006296 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pInputAttachments[j].attachment];
Michael Lentineabc5e922015-10-12 11:30:14 -05006297 auto image_view_data = dev_data->imageViewMap.find(image_view);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006298 if (image_view_data != dev_data->imageViewMap.end()) {
6299 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
Michael Lentineabc5e922015-10-12 11:30:14 -05006300 if (image_layout != pCB->imageLayoutMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006301 image_layout->second.layout = subpass.pInputAttachments[j].layout;
Michael Lentineabc5e922015-10-12 11:30:14 -05006302 }
6303 }
6304 }
6305 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006306 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pColorAttachments[j].attachment];
Michael Lentineabc5e922015-10-12 11:30:14 -05006307 auto image_view_data = dev_data->imageViewMap.find(image_view);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006308 if (image_view_data != dev_data->imageViewMap.end()) {
6309 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
Michael Lentineabc5e922015-10-12 11:30:14 -05006310 if (image_layout != pCB->imageLayoutMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006311 image_layout->second.layout = subpass.pColorAttachments[j].layout;
Michael Lentineabc5e922015-10-12 11:30:14 -05006312 }
6313 }
6314 }
Michael Lentine3dea6512015-10-28 15:55:18 -07006315 if ((subpass.pDepthStencilAttachment != NULL) &&
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06006316 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006317 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pDepthStencilAttachment->attachment];
Michael Lentineabc5e922015-10-12 11:30:14 -05006318 auto image_view_data = dev_data->imageViewMap.find(image_view);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006319 if (image_view_data != dev_data->imageViewMap.end()) {
6320 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
Michael Lentineabc5e922015-10-12 11:30:14 -05006321 if (image_layout != pCB->imageLayoutMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006322 image_layout->second.layout = subpass.pDepthStencilAttachment->layout;
Michael Lentineabc5e922015-10-12 11:30:14 -05006323 }
6324 }
6325 }
6326}
6327
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006328VkBool32 validatePrimaryCommandBuffer(const layer_data* my_data, const GLOBAL_CB_NODE* pCB, const std::string& cmd_name) {
Mark Youngb20a6a82016-01-07 15:41:43 -07006329 VkBool32 skip_call = VK_FALSE;
Michael Lentine3dea6512015-10-28 15:55:18 -07006330 if (pCB->createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006331 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER, "DS",
6332 "Cannot execute command %s on a secondary command buffer.", cmd_name.c_str());
Michael Lentine3dea6512015-10-28 15:55:18 -07006333 }
6334 return skip_call;
6335}
6336
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006337void TransitionFinalSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
6338 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07006339 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer, false);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006340 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
Michael Lentineabc5e922015-10-12 11:30:14 -05006341 if (render_pass_data == dev_data->renderPassMap.end()) {
6342 return;
6343 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006344 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
6345 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
Michael Lentineabc5e922015-10-12 11:30:14 -05006346 if (framebuffer_data == dev_data->frameBufferMap.end()) {
6347 return;
6348 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006349 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
Michael Lentineabc5e922015-10-12 11:30:14 -05006350 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006351 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
Michael Lentineabc5e922015-10-12 11:30:14 -05006352 auto image_view_data = dev_data->imageViewMap.find(image_view);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006353 if (image_view_data != dev_data->imageViewMap.end()) {
6354 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
Michael Lentineabc5e922015-10-12 11:30:14 -05006355 if (image_layout != pCB->imageLayoutMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006356 image_layout->second.layout = pRenderPassInfo->pAttachments[i].finalLayout;
Michael Lentineabc5e922015-10-12 11:30:14 -05006357 }
6358 }
6359 }
6360}
6361
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006362VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, VkSubpassContents contents)
6363{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006364 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006365 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07006366 loader_platform_thread_lock_mutex(&globalLock);
6367 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006368 if (pCB) {
Tobin Ehlis259730a2015-06-23 16:13:03 -06006369 if (pRenderPassBegin && pRenderPassBegin->renderPass) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006370 skipCall |= VerifyFramebufferAndRenderPassLayouts(commandBuffer, pRenderPassBegin);
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06006371 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBeginRenderPass");
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006372 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdBeginRenderPass");
6373 skipCall |= addCmd(dev_data, pCB, CMD_BEGINRENDERPASS, "vkCmdBeginRenderPass()");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06006374 pCB->activeRenderPass = pRenderPassBegin->renderPass;
Michael Lentineabc5e922015-10-12 11:30:14 -05006375 // This is a shallow copy as that is all that is needed for now
6376 pCB->activeRenderPassBeginInfo = *pRenderPassBegin;
Mark Lobodzinski5495d132015-09-30 16:19:16 -06006377 pCB->activeSubpass = 0;
Michael Lentine2e068b22015-12-29 16:05:27 -06006378 pCB->activeSubpassContents = contents;
Mark Lobodzinski5495d132015-09-30 16:19:16 -06006379 pCB->framebuffer = pRenderPassBegin->framebuffer;
Tobin Ehlis502480b2015-06-24 15:53:07 -06006380 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006381 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
6382 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tony Barbourbadda992015-04-06 11:09:26 -06006383 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006384 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07006385 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06006386 if (VK_FALSE == skipCall) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006387 dev_data->device_dispatch_table->CmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents);
Ian Elliott8c8b2662016-01-30 10:57:03 -07006388 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06006389 // This is a shallow copy as that is all that is needed for now
6390 dev_data->renderPassBeginInfo = *pRenderPassBegin;
6391 dev_data->currentSubpass = 0;
Ian Elliott8c8b2662016-01-30 10:57:03 -07006392 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06006393 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006394}
6395
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006396VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents)
6397{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006398 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006399 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07006400 loader_platform_thread_lock_mutex(&globalLock);
6401 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006402 TransitionSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo, ++dev_data->currentSubpass);
Chia-I Wu08accc62015-07-07 11:50:03 +08006403 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006404 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdNextSubpass");
6405 skipCall |= addCmd(dev_data, pCB, CMD_NEXTSUBPASS, "vkCmdNextSubpass()");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06006406 pCB->activeSubpass++;
Michael Lentine2e068b22015-12-29 16:05:27 -06006407 pCB->activeSubpassContents = contents;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006408 TransitionSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo, pCB->activeSubpass);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06006409 if (pCB->lastBoundPipeline) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006410 skipCall |= validatePipelineState(dev_data, pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Chia-I Wu08accc62015-07-07 11:50:03 +08006411 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06006412 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdNextSubpass");
Chia-I Wu08accc62015-07-07 11:50:03 +08006413 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07006414 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006415 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006416 dev_data->device_dispatch_table->CmdNextSubpass(commandBuffer, contents);
Chia-I Wu08accc62015-07-07 11:50:03 +08006417}
6418
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006419VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndRenderPass(VkCommandBuffer commandBuffer)
6420{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006421 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006422 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07006423 loader_platform_thread_lock_mutex(&globalLock);
6424 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006425 TransitionFinalSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006426 if (pCB) {
Michael Lentine3dea6512015-10-28 15:55:18 -07006427 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdEndRenderpass");
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006428 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdEndRenderPass");
6429 skipCall |= addCmd(dev_data, pCB, CMD_ENDRENDERPASS, "vkCmdEndRenderPass()");
6430 TransitionFinalSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06006431 pCB->activeRenderPass = 0;
6432 pCB->activeSubpass = 0;
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08006433 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07006434 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006435 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006436 dev_data->device_dispatch_table->CmdEndRenderPass(commandBuffer);
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08006437}
6438
Michael Lentine3124af62016-02-02 14:26:02 -06006439bool logInvalidAttachmentMessage(layer_data* dev_data, VkCommandBuffer secondaryBuffer, VkRenderPass secondaryPass, VkRenderPass primaryPass, uint32_t primaryAttach, uint32_t secondaryAttach, const char* msg) {
6440 return log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_SECONDARY_COMMAND_BUFFER, "DS",
6441 "vkCmdExecuteCommands() called w/ invalid Cmd Buffer %p which has a render pass %" PRIx64 " that is not compatible with the current render pass %" PRIx64 "."
6442 "Attachment %" PRIu32 " is not compatable with %" PRIu32 ". %s",
Dustin Graves962b01e2016-02-04 11:38:48 -07006443 (void*)secondaryBuffer, (uint64_t)(secondaryPass), (uint64_t)(primaryPass), primaryAttach, secondaryAttach, msg);
Michael Lentine3124af62016-02-02 14:26:02 -06006444}
6445
6446bool validateAttachmentCompatibility(layer_data* dev_data, VkCommandBuffer primaryBuffer, VkRenderPass primaryPass, uint32_t primaryAttach, VkCommandBuffer secondaryBuffer, VkRenderPass secondaryPass, uint32_t secondaryAttach, bool is_multi) {
6447 bool skip_call = false;
6448 auto primary_data = dev_data->renderPassMap.find(primaryPass);
6449 auto secondary_data = dev_data->renderPassMap.find(secondaryPass);
6450 if (primary_data->second->pCreateInfo->attachmentCount <= primaryAttach) {
6451 primaryAttach = VK_ATTACHMENT_UNUSED;
6452 }
6453 if (secondary_data->second->pCreateInfo->attachmentCount <= secondaryAttach) {
6454 secondaryAttach = VK_ATTACHMENT_UNUSED;
6455 }
6456 if (primaryAttach == VK_ATTACHMENT_UNUSED && secondaryAttach == VK_ATTACHMENT_UNUSED) {
6457 return skip_call;
6458 }
6459 if (primaryAttach == VK_ATTACHMENT_UNUSED) {
6460 skip_call |= logInvalidAttachmentMessage(dev_data, secondaryBuffer, secondaryPass, primaryPass, primaryAttach, secondaryAttach, "The first is unused while the second is not.");
6461 return skip_call;
6462 }
6463 if (secondaryAttach == VK_ATTACHMENT_UNUSED) {
6464 skip_call |= logInvalidAttachmentMessage(dev_data, secondaryBuffer, secondaryPass, primaryPass, primaryAttach, secondaryAttach, "The second is unused while the first is not.");
6465 return skip_call;
6466 }
6467 if (primary_data->second->pCreateInfo->pAttachments[primaryAttach].format != secondary_data->second->pCreateInfo->pAttachments[secondaryAttach].format) {
6468 skip_call |= logInvalidAttachmentMessage(dev_data, secondaryBuffer, secondaryPass, primaryPass, primaryAttach, secondaryAttach, "They have different formats.");
6469 }
6470 if (primary_data->second->pCreateInfo->pAttachments[primaryAttach].samples != secondary_data->second->pCreateInfo->pAttachments[secondaryAttach].samples) {
6471 skip_call |= logInvalidAttachmentMessage(dev_data, secondaryBuffer, secondaryPass, primaryPass, primaryAttach, secondaryAttach, "They have different samples.");
6472 }
6473 if (is_multi && primary_data->second->pCreateInfo->pAttachments[primaryAttach].flags != secondary_data->second->pCreateInfo->pAttachments[secondaryAttach].flags) {
6474 skip_call |= logInvalidAttachmentMessage(dev_data, secondaryBuffer, secondaryPass, primaryPass, primaryAttach, secondaryAttach, "They have different flags.");
6475 }
6476 return skip_call;
6477}
6478
6479bool validateSubpassCompatibility(layer_data* dev_data, VkCommandBuffer primaryBuffer, VkRenderPass primaryPass, VkCommandBuffer secondaryBuffer, VkRenderPass secondaryPass, const int subpass, bool is_multi) {
6480 bool skip_call = false;
6481 auto primary_data = dev_data->renderPassMap.find(primaryPass);
6482 auto secondary_data = dev_data->renderPassMap.find(secondaryPass);
6483 const VkSubpassDescription& primary_desc = primary_data->second->pCreateInfo->pSubpasses[subpass];
6484 const VkSubpassDescription& secondary_desc = secondary_data->second->pCreateInfo->pSubpasses[subpass];
6485 uint32_t maxInputAttachmentCount = std::max(primary_desc.inputAttachmentCount, secondary_desc.inputAttachmentCount);
6486 for (uint32_t i = 0; i < maxInputAttachmentCount; ++i) {
6487 uint32_t primary_input_attach = VK_ATTACHMENT_UNUSED, secondary_input_attach = VK_ATTACHMENT_UNUSED;
6488 if (i < primary_desc.inputAttachmentCount) {
6489 primary_input_attach = primary_desc.pInputAttachments[i].attachment;
6490 }
6491 if (i < secondary_desc.inputAttachmentCount) {
6492 secondary_input_attach = secondary_desc.pInputAttachments[i].attachment;
6493 }
6494 skip_call |= validateAttachmentCompatibility(dev_data, primaryBuffer, primaryPass, primary_input_attach, secondaryBuffer, secondaryPass, secondary_input_attach, is_multi);
6495 }
6496 maxInputAttachmentCount = std::max(primary_desc.colorAttachmentCount, secondary_desc.colorAttachmentCount);
6497 for (uint32_t i = 0; i < maxInputAttachmentCount; ++i) {
6498 uint32_t primary_color_attach = VK_ATTACHMENT_UNUSED, secondary_color_attach = VK_ATTACHMENT_UNUSED;
6499 if (i < primary_desc.colorAttachmentCount) {
6500 primary_color_attach = primary_desc.pColorAttachments[i].attachment;
6501 }
6502 if (i < secondary_desc.inputAttachmentCount) {
6503 secondary_color_attach = secondary_desc.pColorAttachments[i].attachment;
6504 }
6505 skip_call |= validateAttachmentCompatibility(dev_data, primaryBuffer, primaryPass, primary_color_attach, secondaryBuffer, secondaryPass, secondary_color_attach, is_multi);
6506 uint32_t primary_resolve_attach = VK_ATTACHMENT_UNUSED, secondary_resolve_attach = VK_ATTACHMENT_UNUSED;
6507 if (i < primary_desc.colorAttachmentCount && primary_desc.pResolveAttachments) {
6508 primary_resolve_attach = primary_desc.pResolveAttachments[i].attachment;
6509 }
6510 if (i < secondary_desc.inputAttachmentCount && secondary_desc.pResolveAttachments) {
6511 secondary_resolve_attach = secondary_desc.pResolveAttachments[i].attachment;
6512 }
6513 skip_call |= validateAttachmentCompatibility(dev_data, primaryBuffer, primaryPass, primary_resolve_attach, secondaryBuffer, secondaryPass, secondary_resolve_attach, is_multi);
6514 }
6515 uint32_t primary_depthstencil_attach = VK_ATTACHMENT_UNUSED, secondary_depthstencil_attach = VK_ATTACHMENT_UNUSED;
6516 if (primary_desc.pDepthStencilAttachment) {
6517 primary_depthstencil_attach = primary_desc.pDepthStencilAttachment[0].attachment;
6518 }
6519 if (secondary_desc.pDepthStencilAttachment) {
6520 secondary_depthstencil_attach = secondary_desc.pDepthStencilAttachment[0].attachment;
6521 }
6522 skip_call |= validateAttachmentCompatibility(dev_data, primaryBuffer, primaryPass, primary_depthstencil_attach, secondaryBuffer, secondaryPass, secondary_depthstencil_attach, is_multi);
6523 return skip_call;
6524}
6525
6526bool validateRenderPassCompatibility(layer_data* dev_data, VkCommandBuffer primaryBuffer, VkRenderPass primaryPass, VkCommandBuffer secondaryBuffer, VkRenderPass secondaryPass) {
6527 bool skip_call = false;
6528 auto primary_data = dev_data->renderPassMap.find(primaryPass);
6529 auto secondary_data = dev_data->renderPassMap.find(secondaryPass);
6530 if (primary_data == dev_data->renderPassMap.end() || primary_data->second == nullptr) {
6531 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_SECONDARY_COMMAND_BUFFER, "DS",
6532 "vkCmdExecuteCommands() called w/ invalid current Cmd Buffer %p which has invalid render pass %" PRIx64 ".",
Dustin Graves962b01e2016-02-04 11:38:48 -07006533 (void*)primaryBuffer, (uint64_t)(primaryPass));
Michael Lentine3124af62016-02-02 14:26:02 -06006534 return skip_call;
6535 }
6536 if (secondary_data == dev_data->renderPassMap.end() || secondary_data->second == nullptr) {
6537 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_SECONDARY_COMMAND_BUFFER, "DS",
6538 "vkCmdExecuteCommands() called w/ invalid secondary Cmd Buffer %p which has invalid render pass %" PRIx64 ".",
Dustin Graves962b01e2016-02-04 11:38:48 -07006539 (void*)secondaryBuffer, (uint64_t)(secondaryPass));
Michael Lentine3124af62016-02-02 14:26:02 -06006540 return skip_call;
6541 }
6542 if (primary_data->second->pCreateInfo->subpassCount != secondary_data->second->pCreateInfo->subpassCount) {
6543 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_SECONDARY_COMMAND_BUFFER, "DS",
6544 "vkCmdExecuteCommands() called w/ invalid Cmd Buffer %p which has a render pass %" PRIx64 " that is not compatible with the current render pass %" PRIx64 "."
6545 "They have a different number of subpasses.",
Dustin Graves962b01e2016-02-04 11:38:48 -07006546 (void*)secondaryBuffer, (uint64_t)(secondaryPass), (uint64_t)(primaryPass));
Michael Lentine3124af62016-02-02 14:26:02 -06006547 return skip_call;
6548 }
6549 bool is_multi = primary_data->second->pCreateInfo->subpassCount > 1;
6550 for (uint32_t i = 0; i < primary_data->second->pCreateInfo->subpassCount; ++i) {
6551 skip_call |= validateSubpassCompatibility(dev_data, primaryBuffer, primaryPass, secondaryBuffer, secondaryPass, i, is_multi);
6552 }
6553 return skip_call;
6554}
6555
Michael Lentinef6592ef2016-02-02 15:24:27 -06006556bool validateFramebuffer(layer_data* dev_data, VkCommandBuffer primaryBuffer, const GLOBAL_CB_NODE* pCB, VkCommandBuffer secondaryBuffer, const GLOBAL_CB_NODE* pSubCB) {
6557 bool skip_call = false;
6558 if (!pSubCB->beginInfo.pInheritanceInfo) {
6559 return skip_call;
6560 }
6561 VkFramebuffer primary_fb = pCB->framebuffer;
6562 VkFramebuffer secondary_fb = pSubCB->beginInfo.pInheritanceInfo->framebuffer;
Michael Lentine3009b622016-02-02 16:47:58 -06006563 if (secondary_fb != VK_NULL_HANDLE) {
6564 if (primary_fb != secondary_fb) {
6565 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_SECONDARY_COMMAND_BUFFER, "DS",
6566 "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 -07006567 (void*)secondaryBuffer, (uint64_t)(secondary_fb), (uint64_t)(primary_fb));
Michael Lentine3009b622016-02-02 16:47:58 -06006568 }
6569 auto fb_data = dev_data->frameBufferMap.find(secondary_fb);
6570 if (fb_data == dev_data->frameBufferMap.end() || !fb_data->second) {
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 Cmd Buffer %p which has invalid framebuffer %" PRIx64 ".",
Dustin Graves962b01e2016-02-04 11:38:48 -07006573 (void*)secondaryBuffer, (uint64_t)(secondary_fb));
Michael Lentine3009b622016-02-02 16:47:58 -06006574 return skip_call;
6575 }
6576 skip_call |= validateRenderPassCompatibility(dev_data, secondaryBuffer, fb_data->second->renderPass, secondaryBuffer, pSubCB->beginInfo.pInheritanceInfo->renderPass);
Michael Lentinef6592ef2016-02-02 15:24:27 -06006577 }
6578 return skip_call;
6579}
6580
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006581VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount, const VkCommandBuffer* pCommandBuffers)
6582{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006583 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006584 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07006585 loader_platform_thread_lock_mutex(&globalLock);
6586 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08006587 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006588 GLOBAL_CB_NODE* pSubCB = NULL;
6589 for (uint32_t i=0; i<commandBuffersCount; i++) {
Ian Elliott8c8b2662016-01-30 10:57:03 -07006590 pSubCB = getCBNode(dev_data, pCommandBuffers[i], false);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06006591 if (!pSubCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006592 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_SECONDARY_COMMAND_BUFFER, "DS",
6593 "vkCmdExecuteCommands() called w/ invalid Cmd Buffer %p in element %u of pCommandBuffers array.", (void*)pCommandBuffers[i], i);
6594 } else if (VK_COMMAND_BUFFER_LEVEL_PRIMARY == pSubCB->createInfo.level) {
6595 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_SECONDARY_COMMAND_BUFFER, "DS",
6596 "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);
6597 } else if (pCB->activeRenderPass) { // Secondary CB w/i RenderPass must have *CONTINUE_BIT set
6598 if (!(pSubCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT)) {
6599 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",
6600 "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 -06006601 } else {
6602 // Make sure render pass is compatible with parent command buffer pass if has continue
6603 skipCall |= validateRenderPassCompatibility(dev_data, commandBuffer, pCB->activeRenderPass, pCommandBuffers[i], pSubCB->beginInfo.pInheritanceInfo->renderPass);
Michael Lentinef6592ef2016-02-02 15:24:27 -06006604 skipCall |= validateFramebuffer(dev_data, commandBuffer, pCB, pCommandBuffers[i], pSubCB);
Tobin Ehlis651d9b02015-12-16 05:01:22 -07006605 }
6606 string errorString = "";
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006607 if (!verify_renderpass_compatibility(dev_data, pCB->activeRenderPass, pSubCB->beginInfo.pInheritanceInfo->renderPass, errorString)) {
6608 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",
6609 "vkCmdExecuteCommands(): Secondary Command Buffer (%p) w/ render pass (%#" PRIxLEAST64 ") is incompatible w/ primary command buffer (%p) w/ render pass (%#" PRIxLEAST64 ") due to: %s",
6610 (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 -07006611 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006612 // If framebuffer for secondary CB is not NULL, then it must match FB from vkCmdBeginRenderPass()
6613 // 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 -07006614 if (pSubCB->beginInfo.pInheritanceInfo->framebuffer) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006615 if (pSubCB->beginInfo.pInheritanceInfo->framebuffer != pCB->activeRenderPassBeginInfo.framebuffer) {
6616 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",
6617 "vkCmdExecuteCommands(): Secondary Command Buffer (%p) references framebuffer (%#" PRIxLEAST64 ") that does not match framebuffer (%#" PRIxLEAST64 ") in active renderpass (%#" PRIxLEAST64 ").",
6618 (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 -07006619 }
6620 }
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06006621 }
Michael Lentine0998ede2016-02-03 14:26:30 -06006622 validateCommandBufferState(dev_data, pSubCB);
6623 // Secondary cmdBuffers are considered pending execution starting w/
6624 // being recorded
6625 if (!(pSubCB->beginInfo.flags &
6626 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT)) {
6627 if (dev_data->globalInFlightCmdBuffers.find(
6628 pSubCB->commandBuffer) !=
6629 dev_data->globalInFlightCmdBuffers.end()) {
6630 skipCall |= log_msg(
6631 dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
6632 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
6633 (uint64_t)(pCB->commandBuffer), __LINE__,
6634 DRAWSTATE_INVALID_CB_SIMULTANEOUS_USE, "DS",
6635 "Attempt to simultaneously execute CB %#" PRIxLEAST64
6636 " w/o VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT "
6637 "set!",
6638 (uint64_t)(pCB->commandBuffer));
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07006639 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006640 if (pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT) {
6641 // Warn that non-simultaneous secondary cmd buffer renders primary non-simultaneous
6642 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",
6643 "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.",
6644 (uint64_t)(pCommandBuffers[i]), (uint64_t)(pCB->commandBuffer));
6645 pCB->beginInfo.flags &= ~VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07006646 }
6647 }
Michael Lentined7621bb2016-02-03 10:55:23 -06006648 pSubCB->primaryCommandBuffer = pCB->commandBuffer;
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07006649 pCB->secondaryCommandBuffers.insert(pSubCB->commandBuffer);
Tobin Ehlis74714d22016-01-25 15:24:34 -08006650 dev_data->globalInFlightCmdBuffers.insert(pSubCB->commandBuffer);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06006651 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006652 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdExecuteComands");
6653 skipCall |= addCmd(dev_data, pCB, CMD_EXECUTECOMMANDS, "vkCmdExecuteComands()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006654 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07006655 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006656 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006657 dev_data->device_dispatch_table->CmdExecuteCommands(commandBuffer, commandBuffersCount, pCommandBuffers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006658}
6659
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07006660VkBool32 ValidateMapImageLayouts(VkDevice device, VkDeviceMemory mem) {
Mark Youngb20a6a82016-01-07 15:41:43 -07006661 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006662 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentine7b236262015-10-23 12:41:44 -07006663 auto mem_data = dev_data->memImageMap.find(mem);
6664 if (mem_data != dev_data->memImageMap.end()) {
6665 auto image_data = dev_data->imageLayoutMap.find(mem_data->second);
6666 if (image_data != dev_data->imageLayoutMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006667 if (image_data->second->layout != VK_IMAGE_LAYOUT_PREINITIALIZED && image_data->second->layout != VK_IMAGE_LAYOUT_GENERAL) {
6668 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
6669 "Cannot map an image with layout %d. Only GENERAL or PREINITIALIZED are supported.", image_data->second->layout);
Michael Lentine7b236262015-10-23 12:41:44 -07006670 }
6671 }
6672 }
6673 return skip_call;
6674}
6675
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006676VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkMapMemory(
6677 VkDevice device,
6678 VkDeviceMemory mem,
6679 VkDeviceSize offset,
6680 VkDeviceSize size,
6681 VkFlags flags,
6682 void **ppData)
6683{
6684 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006685
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07006686 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006687#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
Ian Elliott8c8b2662016-01-30 10:57:03 -07006688 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006689 skip_call = ValidateMapImageLayouts(device, mem);
Ian Elliott8c8b2662016-01-30 10:57:03 -07006690 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006691#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
6692
Michael Lentine7b236262015-10-23 12:41:44 -07006693 if (VK_FALSE == skip_call) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006694 return dev_data->device_dispatch_table->MapMemory(device, mem, offset, size, flags, ppData);
Michael Lentine7b236262015-10-23 12:41:44 -07006695 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07006696 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine7b236262015-10-23 12:41:44 -07006697}
6698
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006699VKAPI_ATTR VkResult VKAPI_CALL vkBindImageMemory(
6700 VkDevice device,
6701 VkImage image,
6702 VkDeviceMemory mem,
6703 VkDeviceSize memOffset)
6704{
6705 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6706 VkResult result = dev_data->device_dispatch_table->BindImageMemory(device, image, mem, memOffset);
Michael Lentine7b236262015-10-23 12:41:44 -07006707 loader_platform_thread_lock_mutex(&globalLock);
6708 dev_data->memImageMap[mem] = image;
6709 loader_platform_thread_unlock_mutex(&globalLock);
6710 return result;
6711}
6712
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006713
Michael Lentineb887b0a2015-12-29 14:12:11 -06006714VKAPI_ATTR VkResult VKAPI_CALL vkSetEvent(VkDevice device, VkEvent event) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006715 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07006716 loader_platform_thread_lock_mutex(&globalLock);
Michael Lentineb887b0a2015-12-29 14:12:11 -06006717 dev_data->eventMap[event].needsSignaled = false;
Ian Elliott8c8b2662016-01-30 10:57:03 -07006718 loader_platform_thread_unlock_mutex(&globalLock);
Michael Lentineb887b0a2015-12-29 14:12:11 -06006719 VkResult result = dev_data->device_dispatch_table->SetEvent(device, event);
6720 return result;
6721}
6722
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006723VKAPI_ATTR VkResult VKAPI_CALL vkQueueBindSparse(
6724 VkQueue queue,
6725 uint32_t bindInfoCount,
6726 const VkBindSparseInfo* pBindInfo,
6727 VkFence fence)
6728{
6729 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07006730 VkBool32 skip_call = VK_FALSE;
Michael Lentine15a47882016-01-06 10:05:48 -06006731
Ian Elliott8c8b2662016-01-30 10:57:03 -07006732 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006733 for (uint32_t bindIdx=0; bindIdx < bindInfoCount; ++bindIdx) {
6734 const VkBindSparseInfo& bindInfo = pBindInfo[bindIdx];
6735 for (uint32_t i=0; i < bindInfo.waitSemaphoreCount; ++i) {
Michael Lentine15a47882016-01-06 10:05:48 -06006736 if (dev_data->semaphoreSignaledMap[bindInfo.pWaitSemaphores[i]]) {
6737 dev_data->semaphoreSignaledMap[bindInfo.pWaitSemaphores[i]] = 0;
6738 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006739 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",
6740 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
6741 (uint64_t)(queue), (uint64_t)(bindInfo.pWaitSemaphores[i]));
Michael Lentine15a47882016-01-06 10:05:48 -06006742 }
6743 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006744 for (uint32_t i=0; i < bindInfo.signalSemaphoreCount; ++i) {
Michael Lentine15a47882016-01-06 10:05:48 -06006745 dev_data->semaphoreSignaledMap[bindInfo.pSignalSemaphores[i]] = 1;
6746 }
6747 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07006748 loader_platform_thread_unlock_mutex(&globalLock);
Michael Lentine15a47882016-01-06 10:05:48 -06006749
Mark Youngb20a6a82016-01-07 15:41:43 -07006750 if (VK_FALSE == skip_call)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006751 return dev_data->device_dispatch_table->QueueBindSparse(queue, bindInfoCount, pBindInfo, fence);
Mark Youngb20a6a82016-01-07 15:41:43 -07006752 else
6753 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine15a47882016-01-06 10:05:48 -06006754}
6755
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006756VKAPI_ATTR VkResult VKAPI_CALL vkCreateSemaphore(
6757 VkDevice device,
6758 const VkSemaphoreCreateInfo* pCreateInfo,
6759 const VkAllocationCallbacks* pAllocator,
6760 VkSemaphore* pSemaphore)
6761{
6762 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6763 VkResult result = dev_data->device_dispatch_table->CreateSemaphore(device, pCreateInfo, pAllocator, pSemaphore);
Michael Lentine15a47882016-01-06 10:05:48 -06006764 if (result == VK_SUCCESS) {
Ian Elliott8c8b2662016-01-30 10:57:03 -07006765 loader_platform_thread_lock_mutex(&globalLock);
Michael Lentine15a47882016-01-06 10:05:48 -06006766 dev_data->semaphoreSignaledMap[*pSemaphore] = 0;
Ian Elliott8c8b2662016-01-30 10:57:03 -07006767 loader_platform_thread_unlock_mutex(&globalLock);
Michael Lentine15a47882016-01-06 10:05:48 -06006768 }
Tobin Ehlis51b78af2016-01-06 10:27:47 -07006769 return result;
Michael Lentine15a47882016-01-06 10:05:48 -06006770}
6771
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006772VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(
6773 VkDevice device,
6774 const VkSwapchainCreateInfoKHR *pCreateInfo,
6775 const VkAllocationCallbacks *pAllocator,
6776 VkSwapchainKHR *pSwapchain)
6777{
6778 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6779 VkResult result = dev_data->device_dispatch_table->CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
Michael Lentineabc5e922015-10-12 11:30:14 -05006780
6781 if (VK_SUCCESS == result) {
Tobin Ehlis75cd1c52016-01-21 10:21:04 -07006782 SWAPCHAIN_NODE *swapchain_data = new SWAPCHAIN_NODE(pCreateInfo);
Michael Lentineabc5e922015-10-12 11:30:14 -05006783 loader_platform_thread_lock_mutex(&globalLock);
6784 dev_data->device_extensions.swapchainMap[*pSwapchain] = swapchain_data;
6785 loader_platform_thread_unlock_mutex(&globalLock);
6786 }
6787
6788 return result;
6789}
6790
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006791VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR(
6792 VkDevice device,
6793 VkSwapchainKHR swapchain,
6794 const VkAllocationCallbacks *pAllocator)
6795{
6796 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentineabc5e922015-10-12 11:30:14 -05006797
6798 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006799 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(swapchain);
Michael Lentineabc5e922015-10-12 11:30:14 -05006800 if (swapchain_data != dev_data->device_extensions.swapchainMap.end()) {
6801 if (swapchain_data->second->images.size() > 0) {
6802 for (auto swapchain_image : swapchain_data->second->images) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006803 auto image_item = dev_data->imageLayoutMap.find(swapchain_image);
Michael Lentineabc5e922015-10-12 11:30:14 -05006804 if (image_item != dev_data->imageLayoutMap.end())
6805 dev_data->imageLayoutMap.erase(image_item);
6806 }
6807 }
6808 delete swapchain_data->second;
6809 dev_data->device_extensions.swapchainMap.erase(swapchain);
6810 }
6811 loader_platform_thread_unlock_mutex(&globalLock);
Ian Elliott8c8b2662016-01-30 10:57:03 -07006812 dev_data->device_dispatch_table->DestroySwapchainKHR(device, swapchain, pAllocator);
Michael Lentineabc5e922015-10-12 11:30:14 -05006813}
6814
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006815VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR(
6816 VkDevice device,
6817 VkSwapchainKHR swapchain,
6818 uint32_t* pCount,
6819 VkImage* pSwapchainImages)
6820{
6821 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6822 VkResult result = dev_data->device_dispatch_table->GetSwapchainImagesKHR(device, swapchain, pCount, pSwapchainImages);
Michael Lentineabc5e922015-10-12 11:30:14 -05006823
6824 if (result == VK_SUCCESS && pSwapchainImages != NULL) {
6825 // This should never happen and is checked by param checker.
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006826 if (!pCount) return result;
Ian Elliott8c8b2662016-01-30 10:57:03 -07006827 loader_platform_thread_lock_mutex(&globalLock);
Michael Lentineabc5e922015-10-12 11:30:14 -05006828 for (uint32_t i = 0; i < *pCount; ++i) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006829 IMAGE_NODE* image_node = new IMAGE_NODE;
Michael Lentineabc5e922015-10-12 11:30:14 -05006830 image_node->layout = VK_IMAGE_LAYOUT_UNDEFINED;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006831 auto swapchain_node = dev_data->device_extensions.swapchainMap[swapchain];
Tobin Ehlis75cd1c52016-01-21 10:21:04 -07006832 image_node->format = swapchain_node->createInfo.imageFormat;
6833 swapchain_node->images.push_back(pSwapchainImages[i]);
Michael Lentineabc5e922015-10-12 11:30:14 -05006834 dev_data->imageLayoutMap[pSwapchainImages[i]] = image_node;
Michael Lentineabc5e922015-10-12 11:30:14 -05006835 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07006836 loader_platform_thread_unlock_mutex(&globalLock);
Michael Lentineabc5e922015-10-12 11:30:14 -05006837 }
6838 return result;
6839}
6840
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006841VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo)
6842{
6843 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07006844 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05006845
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006846#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentineabc5e922015-10-12 11:30:14 -05006847 if (pPresentInfo) {
Ian Elliott8c8b2662016-01-30 10:57:03 -07006848 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006849 for (uint32_t i=0; i < pPresentInfo->waitSemaphoreCount; ++i) {
6850 if (dev_data->semaphoreSignaledMap[pPresentInfo->pWaitSemaphores[i]]) {
6851 dev_data->semaphoreSignaledMap[pPresentInfo->pWaitSemaphores[i]] = 0;
Michael Lentine15a47882016-01-06 10:05:48 -06006852 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006853 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",
6854 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
6855 (uint64_t)(queue), (uint64_t)(pPresentInfo->pWaitSemaphores[i]));
Michael Lentine15a47882016-01-06 10:05:48 -06006856 }
6857 }
Michael Lentineabc5e922015-10-12 11:30:14 -05006858 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006859 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(pPresentInfo->pSwapchains[i]);
6860 if (swapchain_data != dev_data->device_extensions.swapchainMap.end() && pPresentInfo->pImageIndices[i] < swapchain_data->second->images.size()) {
6861 VkImage image = swapchain_data->second->images[pPresentInfo->pImageIndices[i]];
Michael Lentineabc5e922015-10-12 11:30:14 -05006862 auto image_data = dev_data->imageLayoutMap.find(image);
6863 if (image_data != dev_data->imageLayoutMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006864 if (image_data->second->layout != VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) {
6865 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",
6866 "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 -05006867 }
6868 }
6869 }
6870 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07006871 loader_platform_thread_unlock_mutex(&globalLock);
Michael Lentineabc5e922015-10-12 11:30:14 -05006872 }
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006873#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentineabc5e922015-10-12 11:30:14 -05006874
6875 if (VK_FALSE == skip_call)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006876 return dev_data->device_dispatch_table->QueuePresentKHR(queue, pPresentInfo);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07006877 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentineabc5e922015-10-12 11:30:14 -05006878}
6879
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006880VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImageKHR(
6881 VkDevice device,
6882 VkSwapchainKHR swapchain,
6883 uint64_t timeout,
6884 VkSemaphore semaphore,
6885 VkFence fence,
6886 uint32_t* pImageIndex)
6887{
6888 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07006889 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006890 VkResult result = dev_data->device_dispatch_table->AcquireNextImageKHR(device, swapchain, timeout, semaphore, fence, pImageIndex);
Michael Lentine15a47882016-01-06 10:05:48 -06006891 dev_data->semaphoreSignaledMap[semaphore] = 1;
Ian Elliott8c8b2662016-01-30 10:57:03 -07006892 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis51b78af2016-01-06 10:27:47 -07006893 return result;
Michael Lentine15a47882016-01-06 10:05:48 -06006894}
6895
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006896VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006897 VkInstance instance,
6898 const VkDebugReportCallbackCreateInfoEXT* pCreateInfo,
6899 const VkAllocationCallbacks* pAllocator,
6900 VkDebugReportCallbackEXT* pMsgCallback)
6901{
6902 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006903 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006904 VkResult res = pTable->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06006905 if (VK_SUCCESS == res) {
Ian Elliott8c8b2662016-01-30 10:57:03 -07006906 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006907 res = layer_create_msg_callback(my_data->report_data, pCreateInfo, pAllocator, pMsgCallback);
Ian Elliott8c8b2662016-01-30 10:57:03 -07006908 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06006909 }
6910 return res;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006911}
6912
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006913VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(
6914 VkInstance instance,
6915 VkDebugReportCallbackEXT msgCallback,
6916 const VkAllocationCallbacks* pAllocator)
6917{
6918 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006919 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006920 pTable->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
Ian Elliott8c8b2662016-01-30 10:57:03 -07006921 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006922 layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator);
Ian Elliott8c8b2662016-01-30 10:57:03 -07006923 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006924}
6925
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006926VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDebugReportMessageEXT(
6927 VkInstance instance,
6928 VkDebugReportFlagsEXT flags,
6929 VkDebugReportObjectTypeEXT objType,
6930 uint64_t object,
6931 size_t location,
6932 int32_t msgCode,
6933 const char* pLayerPrefix,
6934 const char* pMsg)
6935{
6936 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
6937 my_data->instance_dispatch_table->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg);
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07006938}
6939
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006940VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerBegin(VkCommandBuffer commandBuffer, const char* pMarker)
6941{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006942 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006943 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07006944 loader_platform_thread_lock_mutex(&globalLock);
6945 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis0b632332015-10-07 09:38:40 -06006946 if (!dev_data->device_extensions.debug_marker_enabled) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006947 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",
6948 "Attempt to use CmdDbgMarkerBegin but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06006949 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06006950 } else if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006951 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKERBEGIN, "vkCmdDbgMarkerBegin()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006952 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07006953 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006954 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006955 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerBegin(commandBuffer, pMarker);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006956}
6957
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006958VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerEnd(VkCommandBuffer commandBuffer)
6959{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006960 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006961 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Ian Elliott8c8b2662016-01-30 10:57:03 -07006962 loader_platform_thread_lock_mutex(&globalLock);
6963 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer, false);
Tobin Ehlis0b632332015-10-07 09:38:40 -06006964 if (!dev_data->device_extensions.debug_marker_enabled) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006965 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",
6966 "Attempt to use CmdDbgMarkerEnd but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06006967 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06006968 } else if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006969 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKEREND, "vkCmdDbgMarkerEnd()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006970 }
Ian Elliott8c8b2662016-01-30 10:57:03 -07006971 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006972 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006973 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerEnd(commandBuffer);
Jon Ashburneab34492015-06-01 09:37:38 -06006974}
6975
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006976VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
6977{
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006978 if (!strcmp(funcName, "vkGetDeviceProcAddr"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006979 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006980 if (!strcmp(funcName, "vkDestroyDevice"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006981 return (PFN_vkVoidFunction) vkDestroyDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006982 if (!strcmp(funcName, "vkQueueSubmit"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006983 return (PFN_vkVoidFunction) vkQueueSubmit;
Michael Lentine700b0aa2015-10-30 17:57:32 -07006984 if (!strcmp(funcName, "vkWaitForFences"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006985 return (PFN_vkVoidFunction) vkWaitForFences;
Michael Lentine700b0aa2015-10-30 17:57:32 -07006986 if (!strcmp(funcName, "vkGetFenceStatus"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006987 return (PFN_vkVoidFunction) vkGetFenceStatus;
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07006988 if (!strcmp(funcName, "vkQueueWaitIdle"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006989 return (PFN_vkVoidFunction) vkQueueWaitIdle;
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07006990 if (!strcmp(funcName, "vkDeviceWaitIdle"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006991 return (PFN_vkVoidFunction) vkDeviceWaitIdle;
Michael Lentine700b0aa2015-10-30 17:57:32 -07006992 if (!strcmp(funcName, "vkGetDeviceQueue"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006993 return (PFN_vkVoidFunction) vkGetDeviceQueue;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006994 if (!strcmp(funcName, "vkDestroyInstance"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006995 return (PFN_vkVoidFunction) vkDestroyInstance;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006996 if (!strcmp(funcName, "vkDestroyDevice"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006997 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006998 if (!strcmp(funcName, "vkDestroyFence"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006999 return (PFN_vkVoidFunction) vkDestroyFence;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06007000 if (!strcmp(funcName, "vkDestroySemaphore"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007001 return (PFN_vkVoidFunction) vkDestroySemaphore;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06007002 if (!strcmp(funcName, "vkDestroyEvent"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007003 return (PFN_vkVoidFunction) vkDestroyEvent;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06007004 if (!strcmp(funcName, "vkDestroyQueryPool"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007005 return (PFN_vkVoidFunction) vkDestroyQueryPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06007006 if (!strcmp(funcName, "vkDestroyBuffer"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007007 return (PFN_vkVoidFunction) vkDestroyBuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06007008 if (!strcmp(funcName, "vkDestroyBufferView"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007009 return (PFN_vkVoidFunction) vkDestroyBufferView;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06007010 if (!strcmp(funcName, "vkDestroyImage"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007011 return (PFN_vkVoidFunction) vkDestroyImage;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06007012 if (!strcmp(funcName, "vkDestroyImageView"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007013 return (PFN_vkVoidFunction) vkDestroyImageView;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06007014 if (!strcmp(funcName, "vkDestroyShaderModule"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007015 return (PFN_vkVoidFunction) vkDestroyShaderModule;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06007016 if (!strcmp(funcName, "vkDestroyPipeline"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007017 return (PFN_vkVoidFunction) vkDestroyPipeline;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06007018 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007019 return (PFN_vkVoidFunction) vkDestroyPipelineLayout;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06007020 if (!strcmp(funcName, "vkDestroySampler"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007021 return (PFN_vkVoidFunction) vkDestroySampler;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06007022 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007023 return (PFN_vkVoidFunction) vkDestroyDescriptorSetLayout;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06007024 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007025 return (PFN_vkVoidFunction) vkDestroyDescriptorPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06007026 if (!strcmp(funcName, "vkDestroyFramebuffer"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007027 return (PFN_vkVoidFunction) vkDestroyFramebuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06007028 if (!strcmp(funcName, "vkDestroyRenderPass"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007029 return (PFN_vkVoidFunction) vkDestroyRenderPass;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007030 if (!strcmp(funcName, "vkCreateBuffer"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007031 return (PFN_vkVoidFunction) vkCreateBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007032 if (!strcmp(funcName, "vkCreateBufferView"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007033 return (PFN_vkVoidFunction) vkCreateBufferView;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007034 if (!strcmp(funcName, "vkCreateImage"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007035 return (PFN_vkVoidFunction) vkCreateImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007036 if (!strcmp(funcName, "vkCreateImageView"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007037 return (PFN_vkVoidFunction) vkCreateImageView;
Michael Lentine37767342016-02-02 22:24:26 -06007038 if (!strcmp(funcName, "vkCreateFence"))
7039 return (PFN_vkVoidFunction) vkCreateFence;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007040 if (!strcmp(funcName, "CreatePipelineCache"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007041 return (PFN_vkVoidFunction) vkCreatePipelineCache;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007042 if (!strcmp(funcName, "DestroyPipelineCache"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007043 return (PFN_vkVoidFunction) vkDestroyPipelineCache;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007044 if (!strcmp(funcName, "GetPipelineCacheData"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007045 return (PFN_vkVoidFunction) vkGetPipelineCacheData;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007046 if (!strcmp(funcName, "MergePipelineCaches"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007047 return (PFN_vkVoidFunction) vkMergePipelineCaches;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007048 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007049 return (PFN_vkVoidFunction) vkCreateGraphicsPipelines;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07007050 if (!strcmp(funcName, "vkCreateComputePipelines"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007051 return (PFN_vkVoidFunction) vkCreateComputePipelines;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007052 if (!strcmp(funcName, "vkCreateSampler"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007053 return (PFN_vkVoidFunction) vkCreateSampler;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007054 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007055 return (PFN_vkVoidFunction) vkCreateDescriptorSetLayout;
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05007056 if (!strcmp(funcName, "vkCreatePipelineLayout"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007057 return (PFN_vkVoidFunction) vkCreatePipelineLayout;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007058 if (!strcmp(funcName, "vkCreateDescriptorPool"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007059 return (PFN_vkVoidFunction) vkCreateDescriptorPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007060 if (!strcmp(funcName, "vkResetDescriptorPool"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007061 return (PFN_vkVoidFunction) vkResetDescriptorPool;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007062 if (!strcmp(funcName, "vkAllocateDescriptorSets"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007063 return (PFN_vkVoidFunction) vkAllocateDescriptorSets;
Tobin Ehlise735c692015-10-08 13:13:50 -06007064 if (!strcmp(funcName, "vkFreeDescriptorSets"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007065 return (PFN_vkVoidFunction) vkFreeDescriptorSets;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007066 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007067 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
Mark Lobodzinski39298632015-11-18 08:38:27 -07007068 if (!strcmp(funcName, "vkCreateCommandPool"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007069 return (PFN_vkVoidFunction) vkCreateCommandPool;
Mark Lobodzinski39298632015-11-18 08:38:27 -07007070 if (!strcmp(funcName, "vkDestroyCommandPool"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007071 return (PFN_vkVoidFunction) vkDestroyCommandPool;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007072 if (!strcmp(funcName, "vkResetCommandPool"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007073 return (PFN_vkVoidFunction) vkResetCommandPool;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007074 if (!strcmp(funcName, "vkAllocateCommandBuffers"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007075 return (PFN_vkVoidFunction) vkAllocateCommandBuffers;
Mark Lobodzinski39298632015-11-18 08:38:27 -07007076 if (!strcmp(funcName, "vkFreeCommandBuffers"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007077 return (PFN_vkVoidFunction) vkFreeCommandBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007078 if (!strcmp(funcName, "vkBeginCommandBuffer"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007079 return (PFN_vkVoidFunction) vkBeginCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007080 if (!strcmp(funcName, "vkEndCommandBuffer"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007081 return (PFN_vkVoidFunction) vkEndCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007082 if (!strcmp(funcName, "vkResetCommandBuffer"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007083 return (PFN_vkVoidFunction) vkResetCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007084 if (!strcmp(funcName, "vkCmdBindPipeline"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007085 return (PFN_vkVoidFunction) vkCmdBindPipeline;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06007086 if (!strcmp(funcName, "vkCmdSetViewport"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007087 return (PFN_vkVoidFunction) vkCmdSetViewport;
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06007088 if (!strcmp(funcName, "vkCmdSetScissor"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007089 return (PFN_vkVoidFunction) vkCmdSetScissor;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06007090 if (!strcmp(funcName, "vkCmdSetLineWidth"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007091 return (PFN_vkVoidFunction) vkCmdSetLineWidth;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06007092 if (!strcmp(funcName, "vkCmdSetDepthBias"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007093 return (PFN_vkVoidFunction) vkCmdSetDepthBias;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06007094 if (!strcmp(funcName, "vkCmdSetBlendConstants"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007095 return (PFN_vkVoidFunction) vkCmdSetBlendConstants;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06007096 if (!strcmp(funcName, "vkCmdSetDepthBounds"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007097 return (PFN_vkVoidFunction) vkCmdSetDepthBounds;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06007098 if (!strcmp(funcName, "vkCmdSetStencilCompareMask"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007099 return (PFN_vkVoidFunction) vkCmdSetStencilCompareMask;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06007100 if (!strcmp(funcName, "vkCmdSetStencilWriteMask"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007101 return (PFN_vkVoidFunction) vkCmdSetStencilWriteMask;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06007102 if (!strcmp(funcName, "vkCmdSetStencilReference"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007103 return (PFN_vkVoidFunction) vkCmdSetStencilReference;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007104 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007105 return (PFN_vkVoidFunction) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06007106 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007107 return (PFN_vkVoidFunction) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007108 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007109 return (PFN_vkVoidFunction) vkCmdBindIndexBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007110 if (!strcmp(funcName, "vkCmdDraw"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007111 return (PFN_vkVoidFunction) vkCmdDraw;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007112 if (!strcmp(funcName, "vkCmdDrawIndexed"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007113 return (PFN_vkVoidFunction) vkCmdDrawIndexed;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007114 if (!strcmp(funcName, "vkCmdDrawIndirect"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007115 return (PFN_vkVoidFunction) vkCmdDrawIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007116 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007117 return (PFN_vkVoidFunction) vkCmdDrawIndexedIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007118 if (!strcmp(funcName, "vkCmdDispatch"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007119 return (PFN_vkVoidFunction) vkCmdDispatch;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007120 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007121 return (PFN_vkVoidFunction) vkCmdDispatchIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007122 if (!strcmp(funcName, "vkCmdCopyBuffer"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007123 return (PFN_vkVoidFunction) vkCmdCopyBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007124 if (!strcmp(funcName, "vkCmdCopyImage"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007125 return (PFN_vkVoidFunction) vkCmdCopyImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007126 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007127 return (PFN_vkVoidFunction) vkCmdCopyBufferToImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007128 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007129 return (PFN_vkVoidFunction) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007130 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007131 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007132 if (!strcmp(funcName, "vkCmdFillBuffer"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007133 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007134 if (!strcmp(funcName, "vkCmdClearColorImage"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007135 return (PFN_vkVoidFunction) vkCmdClearColorImage;
Chris Forbesd9be82b2015-06-22 17:21:59 +12007136 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007137 return (PFN_vkVoidFunction) vkCmdClearDepthStencilImage;
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007138 if (!strcmp(funcName, "vkCmdClearAttachments"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007139 return (PFN_vkVoidFunction) vkCmdClearAttachments;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007140 if (!strcmp(funcName, "vkCmdResolveImage"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007141 return (PFN_vkVoidFunction) vkCmdResolveImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007142 if (!strcmp(funcName, "vkCmdSetEvent"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007143 return (PFN_vkVoidFunction) vkCmdSetEvent;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007144 if (!strcmp(funcName, "vkCmdResetEvent"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007145 return (PFN_vkVoidFunction) vkCmdResetEvent;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007146 if (!strcmp(funcName, "vkCmdWaitEvents"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007147 return (PFN_vkVoidFunction) vkCmdWaitEvents;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007148 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007149 return (PFN_vkVoidFunction) vkCmdPipelineBarrier;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007150 if (!strcmp(funcName, "vkCmdBeginQuery"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007151 return (PFN_vkVoidFunction) vkCmdBeginQuery;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007152 if (!strcmp(funcName, "vkCmdEndQuery"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007153 return (PFN_vkVoidFunction) vkCmdEndQuery;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007154 if (!strcmp(funcName, "vkCmdResetQueryPool"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007155 return (PFN_vkVoidFunction) vkCmdResetQueryPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007156 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007157 return (PFN_vkVoidFunction) vkCmdWriteTimestamp;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007158 if (!strcmp(funcName, "vkCreateFramebuffer"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007159 return (PFN_vkVoidFunction) vkCreateFramebuffer;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07007160 if (!strcmp(funcName, "vkCreateShaderModule"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007161 return (PFN_vkVoidFunction) vkCreateShaderModule;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007162 if (!strcmp(funcName, "vkCreateRenderPass"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007163 return (PFN_vkVoidFunction) vkCreateRenderPass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007164 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007165 return (PFN_vkVoidFunction) vkCmdBeginRenderPass;
Chia-I Wu08accc62015-07-07 11:50:03 +08007166 if (!strcmp(funcName, "vkCmdNextSubpass"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007167 return (PFN_vkVoidFunction) vkCmdNextSubpass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06007168 if (!strcmp(funcName, "vkCmdEndRenderPass"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007169 return (PFN_vkVoidFunction) vkCmdEndRenderPass;
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007170 if (!strcmp(funcName, "vkCmdExecuteCommands"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007171 return (PFN_vkVoidFunction) vkCmdExecuteCommands;
Michael Lentineb887b0a2015-12-29 14:12:11 -06007172 if (!strcmp(funcName, "vkSetEvent"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007173 return (PFN_vkVoidFunction) vkSetEvent;
Michael Lentine7b236262015-10-23 12:41:44 -07007174 if (!strcmp(funcName, "vkMapMemory"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007175 return (PFN_vkVoidFunction) vkMapMemory;
Michael Lentineb887b0a2015-12-29 14:12:11 -06007176 if (!strcmp(funcName, "vkGetQueryPoolResults"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007177 return (PFN_vkVoidFunction) vkGetQueryPoolResults;
Michael Lentine15a47882016-01-06 10:05:48 -06007178 if (!strcmp(funcName, "vkBindImageMemory"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007179 return (PFN_vkVoidFunction) vkBindImageMemory;
Michael Lentine15a47882016-01-06 10:05:48 -06007180 if (!strcmp(funcName, "vkQueueBindSparse"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007181 return (PFN_vkVoidFunction) vkQueueBindSparse;
Michael Lentine15a47882016-01-06 10:05:48 -06007182 if (!strcmp(funcName, "vkCreateSemaphore"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007183 return (PFN_vkVoidFunction) vkCreateSemaphore;
Jon Ashburneab34492015-06-01 09:37:38 -06007184
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07007185 if (dev == NULL)
7186 return NULL;
7187
7188 layer_data *dev_data;
7189 dev_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map);
7190
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007191 if (dev_data->device_extensions.wsi_enabled)
7192 {
Michael Lentineabc5e922015-10-12 11:30:14 -05007193 if (!strcmp(funcName, "vkCreateSwapchainKHR"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007194 return (PFN_vkVoidFunction) vkCreateSwapchainKHR;
Michael Lentineabc5e922015-10-12 11:30:14 -05007195 if (!strcmp(funcName, "vkDestroySwapchainKHR"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007196 return (PFN_vkVoidFunction) vkDestroySwapchainKHR;
Michael Lentineabc5e922015-10-12 11:30:14 -05007197 if (!strcmp(funcName, "vkGetSwapchainImagesKHR"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007198 return (PFN_vkVoidFunction) vkGetSwapchainImagesKHR;
Michael Lentine15a47882016-01-06 10:05:48 -06007199 if (!strcmp(funcName, "vkAcquireNextImageKHR"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007200 return (PFN_vkVoidFunction) vkAcquireNextImageKHR;
Michael Lentineabc5e922015-10-12 11:30:14 -05007201 if (!strcmp(funcName, "vkQueuePresentKHR"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007202 return (PFN_vkVoidFunction) vkQueuePresentKHR;
Michael Lentineabc5e922015-10-12 11:30:14 -05007203 }
7204
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007205 VkLayerDispatchTable* pTable = dev_data->device_dispatch_table;
7206 if (dev_data->device_extensions.debug_marker_enabled)
7207 {
Jon Ashburn747f2b62015-06-18 15:02:58 -06007208 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007209 return (PFN_vkVoidFunction) vkCmdDbgMarkerBegin;
Jon Ashburn747f2b62015-06-18 15:02:58 -06007210 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007211 return (PFN_vkVoidFunction) vkCmdDbgMarkerEnd;
Jon Ashburneab34492015-06-01 09:37:38 -06007212 }
7213 {
Jon Ashburn8fd08252015-05-28 16:25:02 -06007214 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06007215 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -06007216 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburnf6b33db2015-05-05 14:22:52 -06007217 }
7218}
7219
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007220VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
7221{
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07007222 if (!strcmp(funcName, "vkGetInstanceProcAddr"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007223 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07007224 if (!strcmp(funcName, "vkGetDeviceProcAddr"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007225 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06007226 if (!strcmp(funcName, "vkCreateInstance"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007227 return (PFN_vkVoidFunction) vkCreateInstance;
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07007228 if (!strcmp(funcName, "vkCreateDevice"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007229 return (PFN_vkVoidFunction) vkCreateDevice;
Jon Ashburn3950e1b2015-05-20 09:00:28 -06007230 if (!strcmp(funcName, "vkDestroyInstance"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007231 return (PFN_vkVoidFunction) vkDestroyInstance;
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -06007232 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007233 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -06007234 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007235 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -06007236 if (!strcmp(funcName, "vkEnumerateDeviceLayerProperties"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007237 return (PFN_vkVoidFunction) vkEnumerateDeviceLayerProperties;
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -06007238 if (!strcmp(funcName, "vkEnumerateDeviceExtensionProperties"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007239 return (PFN_vkVoidFunction) vkEnumerateDeviceExtensionProperties;
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06007240
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07007241 if (instance == NULL)
7242 return NULL;
7243
7244 PFN_vkVoidFunction fptr;
7245
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007246 layer_data* my_data;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07007247 my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06007248 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06007249 if (fptr)
7250 return fptr;
7251
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07007252 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07007253 if (pTable->GetInstanceProcAddr == NULL)
7254 return NULL;
7255 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06007256}