blob: 5952625daf0fe58a393b347c1c6ef9da1c192018 [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>
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060035 */
36
Mark Lobodzinski78da8cb2015-12-28 15:51:07 -070037// Allow use of STL min and max functions in Windows
38#define NOMINMAX
39
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060040#include <stdio.h>
41#include <stdlib.h>
42#include <string.h>
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070043#include <assert.h>
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060044#include <unordered_map>
Michael Lentineb6986752015-10-06 14:56:18 -070045#include <unordered_set>
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070046#include <map>
47#include <string>
48#include <iostream>
49#include <algorithm>
Mark Lobodzinski39298632015-11-18 08:38:27 -070050#include <list>
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070051#include <spirv.hpp>
Tobin Ehlis88452832015-12-03 09:40:56 -070052#include <set>
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060053
Tobin Ehlisb835d1b2015-07-03 10:34:49 -060054#include "vk_loader_platform.h"
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060055#include "vk_dispatch_table_helper.h"
56#include "vk_struct_string_helper_cpp.h"
Tony Barbour18f71552015-04-22 11:36:22 -060057#if defined(__GNUC__)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060058#pragma GCC diagnostic ignored "-Wwrite-strings"
Tony Barbour18f71552015-04-22 11:36:22 -060059#endif
Tony Barbour18f71552015-04-22 11:36:22 -060060#if defined(__GNUC__)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060061#pragma GCC diagnostic warning "-Wwrite-strings"
Tony Barbour18f71552015-04-22 11:36:22 -060062#endif
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060063#include "vk_struct_size_helper.h"
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060064#include "draw_state.h"
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -060065#include "vk_layer_config.h"
Michael Lentine97eb7462015-11-20 09:48:52 -080066#include "vulkan/vk_debug_marker_layer.h"
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -060067#include "vk_layer_table.h"
68#include "vk_layer_debug_marker_table.h"
69#include "vk_layer_data.h"
70#include "vk_layer_logging.h"
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -060071#include "vk_layer_extension_utils.h"
Tobin Ehlisa1c28562015-10-23 16:00:08 -060072#include "vk_layer_utils.h"
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060073
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -070074// This definition controls whether image layout transitions are enabled/disabled.
Mark Lobodzinski31e5f282015-11-30 16:48:53 -070075// disable until corner cases are fixed
76#define DISABLE_IMAGE_LAYOUT_VALIDATION
77
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070078using std::unordered_map;
79using std::unordered_set;
80
Tobin Ehlisac0ef842015-12-14 13:46:38 -070081// Track command pools and their command buffers
82struct CMD_POOL_INFO {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -070083 VkCommandPoolCreateFlags createFlags;
Michael Lentine26870f32016-01-26 21:36:08 -060084 uint32_t queueFamilyIndex;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -070085 list<VkCommandBuffer> commandBuffers; // list container of cmd buffers allocated from this pool
Tobin Ehlisac0ef842015-12-14 13:46:38 -070086};
87
Tobin Ehlis0b632332015-10-07 09:38:40 -060088struct devExts {
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -070089 VkBool32 debug_marker_enabled;
Michael Lentineabc5e922015-10-12 11:30:14 -050090 VkBool32 wsi_enabled;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -070091 unordered_map<VkSwapchainKHR, SWAPCHAIN_NODE*> swapchainMap;
Tobin Ehlis0b632332015-10-07 09:38:40 -060092};
93
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070094// fwd decls
95struct shader_module;
96struct render_pass;
97
Cody Northrop55443ef2015-09-28 15:09:32 -060098struct layer_data {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -070099 debug_report_data* report_data;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700100 std::vector<VkDebugReportCallbackEXT> logging_callback;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700101 VkLayerDispatchTable* device_dispatch_table;
102 VkLayerInstanceDispatchTable* instance_dispatch_table;
Tobin Ehlis0b632332015-10-07 09:38:40 -0600103 devExts device_extensions;
Tobin Ehlisae82e7f2016-01-20 16:23:37 -0700104 vector<VkQueue> queues; // all queues under given device
Tobin Ehlis74714d22016-01-25 15:24:34 -0800105 // Global set of all cmdBuffers that are inFlight on this device
106 unordered_set<VkCommandBuffer> globalInFlightCmdBuffers;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -0600107 // Layer specific data
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700108 unordered_map<VkSampler, unique_ptr<SAMPLER_NODE>> sampleMap;
109 unordered_map<VkImageView, unique_ptr<VkImageViewCreateInfo>> imageViewMap;
110 unordered_map<VkImage, unique_ptr<VkImageCreateInfo>> imageMap;
111 unordered_map<VkBufferView, unique_ptr<VkBufferViewCreateInfo>> bufferViewMap;
112 unordered_map<VkBuffer, BUFFER_NODE> bufferMap;
113 unordered_map<VkPipeline, PIPELINE_NODE*> pipelineMap;
114 unordered_map<VkCommandPool, CMD_POOL_INFO> commandPoolMap;
115 unordered_map<VkDescriptorPool, DESCRIPTOR_POOL_NODE*> descriptorPoolMap;
116 unordered_map<VkDescriptorSet, SET_NODE*> setMap;
117 unordered_map<VkDescriptorSetLayout, LAYOUT_NODE*> descriptorSetLayoutMap;
118 unordered_map<VkPipelineLayout, PIPELINE_LAYOUT_NODE> pipelineLayoutMap;
119 unordered_map<VkDeviceMemory, VkImage> memImageMap;
120 unordered_map<VkFence, FENCE_NODE> fenceMap;
121 unordered_map<VkQueue, QUEUE_NODE> queueMap;
122 unordered_map<VkEvent, EVENT_NODE> eventMap;
123 unordered_map<QueryObject, bool> queryToStateMap;
124 unordered_map<VkSemaphore, uint32_t> semaphoreSignaledMap;
125 unordered_map<void*, GLOBAL_CB_NODE*> commandBufferMap;
126 unordered_map<VkFramebuffer, VkFramebufferCreateInfo*> frameBufferMap;
127 unordered_map<VkImage, IMAGE_NODE*> imageLayoutMap;
128 unordered_map<VkRenderPass, RENDER_PASS_NODE*> renderPassMap;
129 unordered_map<VkShaderModule, shader_module*> shaderModuleMap;
Michael Lentineabc5e922015-10-12 11:30:14 -0500130 // Current render pass
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700131 VkRenderPassBeginInfo renderPassBeginInfo;
132 uint32_t currentSubpass;
Michael Lentine26870f32016-01-26 21:36:08 -0600133
134 // Device specific data
135 PHYS_DEV_PROPERTIES_NODE physDevProperties;
Cody Northrop55443ef2015-09-28 15:09:32 -0600136
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700137 layer_data() :
138 report_data(nullptr),
139 device_dispatch_table(nullptr),
140 instance_dispatch_table(nullptr),
141 device_extensions()
142 {};
Cody Northrop55443ef2015-09-28 15:09:32 -0600143};
Michael Lentine15a47882016-01-06 10:05:48 -0600144
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700145// Code imported from ShaderChecker
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700146static void
147build_def_index(shader_module *);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700148
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700149// A forward iterator over spirv instructions. Provides easy access to len, opcode, and content words
150// without the caller needing to care too much about the physical SPIRV module layout.
Chris Forbesc7e2e202016-01-18 08:56:40 +1300151struct spirv_inst_iter {
152 std::vector<uint32_t>::const_iterator zero;
153 std::vector<uint32_t>::const_iterator it;
154
155 uint32_t len() { return *it >> 16; }
156 uint32_t opcode() { return *it & 0x0ffffu; }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700157 uint32_t const & word(unsigned n) { return it[n]; }
Mark Youngd652d132016-01-25 13:37:06 -0700158 uint32_t offset() { return (uint32_t)(it - zero); }
Chris Forbesc7e2e202016-01-18 08:56:40 +1300159
160 spirv_inst_iter(std::vector<uint32_t>::const_iterator zero,
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700161 std::vector<uint32_t>::const_iterator it) : zero(zero), it(it) {}
Chris Forbesc7e2e202016-01-18 08:56:40 +1300162
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700163 bool operator== (spirv_inst_iter const & other) {
164 return it == other.it;
165 }
Chris Forbesc7e2e202016-01-18 08:56:40 +1300166
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700167 bool operator!= (spirv_inst_iter const & other) {
168 return it != other.it;
169 }
Chris Forbesc7e2e202016-01-18 08:56:40 +1300170
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700171 spirv_inst_iter operator++ (int) { /* x++ */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300172 spirv_inst_iter ii = *this;
173 it += len();
174 return ii;
175 }
176
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700177 spirv_inst_iter operator++ () { /* ++x; */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300178 it += len();
179 return *this;
180 }
181
182 /* The iterator and the value are the same thing. */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700183 spirv_inst_iter & operator* () { return *this; }
184 spirv_inst_iter const & operator* () const { return *this; }
Chris Forbesc7e2e202016-01-18 08:56:40 +1300185};
186
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700187struct shader_module {
188 /* the spirv image itself */
189 vector<uint32_t> words;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700190 /* a mapping of <id> to the first word of its def. this is useful because walking type
191 * trees, constant expressions, etc requires jumping all over the instruction stream.
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700192 */
Chris Forbes21977d92016-01-26 13:41:39 +1300193 unordered_map<unsigned, unsigned> def_index;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700194
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700195 shader_module(VkShaderModuleCreateInfo const *pCreateInfo) :
196 words((uint32_t *)pCreateInfo->pCode, (uint32_t *)pCreateInfo->pCode + pCreateInfo->codeSize / sizeof(uint32_t)),
197 def_index() {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700198
Chris Forbes21977d92016-01-26 13:41:39 +1300199 build_def_index(this);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700200 }
Chris Forbesc7e2e202016-01-18 08:56:40 +1300201
202 /* expose begin() / end() to enable range-based for */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700203 spirv_inst_iter begin() const { return spirv_inst_iter(words.begin(), words.begin() + 5); } /* first insn */
204 spirv_inst_iter end() const { return spirv_inst_iter(words.begin(), words.end()); } /* just past last insn */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300205 /* given an offset into the module, produce an iterator there. */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700206 spirv_inst_iter at(unsigned offset) const { return spirv_inst_iter(words.begin(), words.begin() + offset); }
Chris Forbes1257f912016-01-18 12:07:01 +1300207
Chris Forbes21977d92016-01-26 13:41:39 +1300208 /* gets an iterator to the definition of an id */
209 spirv_inst_iter get_def(unsigned id) const {
210 auto it = def_index.find(id);
211 if (it == def_index.end()) {
Chris Forbes1257f912016-01-18 12:07:01 +1300212 return end();
213 }
214 return at(it->second);
215 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700216};
217
Tobin Ehlisb212dfc2015-10-07 15:40:22 -0600218// TODO : Do we need to guard access to layer_data_map w/ lock?
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700219static unordered_map<void*, layer_data*> layer_data_map;
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -0600220
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600221static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700222// TODO : This can be much smarter, using separate locks for separate global data
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600223static int globalLockInitialized = 0;
224static loader_platform_thread_mutex globalLock;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600225#define MAX_TID 513
226static loader_platform_thread_id g_tidMapping[MAX_TID] = {0};
227static uint32_t g_maxTID = 0;
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600228
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700229template layer_data *get_my_data_ptr<layer_data>(
230 void *data_key,
231 std::unordered_map<void *, layer_data *> &data_map);
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600232
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600233// Map actual TID to an index value and return that index
234// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs
235static uint32_t getTIDIndex() {
236 loader_platform_thread_id tid = loader_platform_get_thread_id();
237 for (uint32_t i = 0; i < g_maxTID; i++) {
238 if (tid == g_tidMapping[i])
239 return i;
240 }
241 // Don't yet have mapping, set it and return newly set index
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700242 uint32_t retVal = (uint32_t) g_maxTID;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600243 g_tidMapping[g_maxTID++] = tid;
244 assert(g_maxTID < MAX_TID);
245 return retVal;
246}
Tobin Ehlis559c6382015-11-05 09:52:49 -0700247
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600248// Return a string representation of CMD_TYPE enum
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700249static string cmdTypeToString(CMD_TYPE cmd)
250{
251 switch (cmd)
252 {
253 case CMD_BINDPIPELINE:
254 return "CMD_BINDPIPELINE";
255 case CMD_BINDPIPELINEDELTA:
256 return "CMD_BINDPIPELINEDELTA";
257 case CMD_SETVIEWPORTSTATE:
258 return "CMD_SETVIEWPORTSTATE";
259 case CMD_SETLINEWIDTHSTATE:
260 return "CMD_SETLINEWIDTHSTATE";
261 case CMD_SETDEPTHBIASSTATE:
262 return "CMD_SETDEPTHBIASSTATE";
263 case CMD_SETBLENDSTATE:
264 return "CMD_SETBLENDSTATE";
265 case CMD_SETDEPTHBOUNDSSTATE:
266 return "CMD_SETDEPTHBOUNDSSTATE";
267 case CMD_SETSTENCILREADMASKSTATE:
268 return "CMD_SETSTENCILREADMASKSTATE";
269 case CMD_SETSTENCILWRITEMASKSTATE:
270 return "CMD_SETSTENCILWRITEMASKSTATE";
271 case CMD_SETSTENCILREFERENCESTATE:
272 return "CMD_SETSTENCILREFERENCESTATE";
273 case CMD_BINDDESCRIPTORSETS:
274 return "CMD_BINDDESCRIPTORSETS";
275 case CMD_BINDINDEXBUFFER:
276 return "CMD_BINDINDEXBUFFER";
277 case CMD_BINDVERTEXBUFFER:
278 return "CMD_BINDVERTEXBUFFER";
279 case CMD_DRAW:
280 return "CMD_DRAW";
281 case CMD_DRAWINDEXED:
282 return "CMD_DRAWINDEXED";
283 case CMD_DRAWINDIRECT:
284 return "CMD_DRAWINDIRECT";
285 case CMD_DRAWINDEXEDINDIRECT:
286 return "CMD_DRAWINDEXEDINDIRECT";
287 case CMD_DISPATCH:
288 return "CMD_DISPATCH";
289 case CMD_DISPATCHINDIRECT:
290 return "CMD_DISPATCHINDIRECT";
291 case CMD_COPYBUFFER:
292 return "CMD_COPYBUFFER";
293 case CMD_COPYIMAGE:
294 return "CMD_COPYIMAGE";
295 case CMD_BLITIMAGE:
296 return "CMD_BLITIMAGE";
297 case CMD_COPYBUFFERTOIMAGE:
298 return "CMD_COPYBUFFERTOIMAGE";
299 case CMD_COPYIMAGETOBUFFER:
300 return "CMD_COPYIMAGETOBUFFER";
301 case CMD_CLONEIMAGEDATA:
302 return "CMD_CLONEIMAGEDATA";
303 case CMD_UPDATEBUFFER:
304 return "CMD_UPDATEBUFFER";
305 case CMD_FILLBUFFER:
306 return "CMD_FILLBUFFER";
307 case CMD_CLEARCOLORIMAGE:
308 return "CMD_CLEARCOLORIMAGE";
309 case CMD_CLEARATTACHMENTS:
310 return "CMD_CLEARCOLORATTACHMENT";
311 case CMD_CLEARDEPTHSTENCILIMAGE:
312 return "CMD_CLEARDEPTHSTENCILIMAGE";
313 case CMD_RESOLVEIMAGE:
314 return "CMD_RESOLVEIMAGE";
315 case CMD_SETEVENT:
316 return "CMD_SETEVENT";
317 case CMD_RESETEVENT:
318 return "CMD_RESETEVENT";
319 case CMD_WAITEVENTS:
320 return "CMD_WAITEVENTS";
321 case CMD_PIPELINEBARRIER:
322 return "CMD_PIPELINEBARRIER";
323 case CMD_BEGINQUERY:
324 return "CMD_BEGINQUERY";
325 case CMD_ENDQUERY:
326 return "CMD_ENDQUERY";
327 case CMD_RESETQUERYPOOL:
328 return "CMD_RESETQUERYPOOL";
329 case CMD_COPYQUERYPOOLRESULTS:
330 return "CMD_COPYQUERYPOOLRESULTS";
331 case CMD_WRITETIMESTAMP:
332 return "CMD_WRITETIMESTAMP";
333 case CMD_INITATOMICCOUNTERS:
334 return "CMD_INITATOMICCOUNTERS";
335 case CMD_LOADATOMICCOUNTERS:
336 return "CMD_LOADATOMICCOUNTERS";
337 case CMD_SAVEATOMICCOUNTERS:
338 return "CMD_SAVEATOMICCOUNTERS";
339 case CMD_BEGINRENDERPASS:
340 return "CMD_BEGINRENDERPASS";
341 case CMD_ENDRENDERPASS:
342 return "CMD_ENDRENDERPASS";
343 case CMD_DBGMARKERBEGIN:
344 return "CMD_DBGMARKERBEGIN";
345 case CMD_DBGMARKEREND:
346 return "CMD_DBGMARKEREND";
347 default:
348 return "UNKNOWN";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600349 }
350}
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700351
352// SPIRV utility functions
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700353static void
354build_def_index(shader_module *module)
355{
Chris Forbesc7e2e202016-01-18 08:56:40 +1300356 for (auto insn : *module) {
357 switch (insn.opcode()) {
Chris Forbes92b9ab02016-01-26 13:49:27 +1300358 /* Types */
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700359 case spv::OpTypeVoid:
360 case spv::OpTypeBool:
361 case spv::OpTypeInt:
362 case spv::OpTypeFloat:
363 case spv::OpTypeVector:
364 case spv::OpTypeMatrix:
365 case spv::OpTypeImage:
366 case spv::OpTypeSampler:
367 case spv::OpTypeSampledImage:
368 case spv::OpTypeArray:
369 case spv::OpTypeRuntimeArray:
370 case spv::OpTypeStruct:
371 case spv::OpTypeOpaque:
372 case spv::OpTypePointer:
373 case spv::OpTypeFunction:
374 case spv::OpTypeEvent:
375 case spv::OpTypeDeviceEvent:
376 case spv::OpTypeReserveId:
377 case spv::OpTypeQueue:
378 case spv::OpTypePipe:
Chris Forbes21977d92016-01-26 13:41:39 +1300379 module->def_index[insn.word(1)] = insn.offset();
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700380 break;
381
Chris Forbes92b9ab02016-01-26 13:49:27 +1300382 /* Fixed constants */
383 case spv::OpConstantTrue:
384 case spv::OpConstantFalse:
385 case spv::OpConstant:
386 case spv::OpConstantComposite:
387 case spv::OpConstantSampler:
388 case spv::OpConstantNull:
389 module->def_index[insn.word(2)] = insn.offset();
390 break;
391
392 /* Specialization constants */
393 case spv::OpSpecConstantTrue:
394 case spv::OpSpecConstantFalse:
395 case spv::OpSpecConstant:
396 case spv::OpSpecConstantComposite:
397 case spv::OpSpecConstantOp:
398 module->def_index[insn.word(2)] = insn.offset();
399 break;
400
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700401 default:
Chris Forbes92b9ab02016-01-26 13:49:27 +1300402 /* We don't care about any other defs for now. */
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700403 break;
404 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700405 }
406}
407
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700408bool
409shader_is_spirv(VkShaderModuleCreateInfo const *pCreateInfo)
410{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700411 uint32_t *words = (uint32_t *)pCreateInfo->pCode;
412 size_t sizeInWords = pCreateInfo->codeSize / sizeof(uint32_t);
413
414 /* Just validate that the header makes sense. */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700415 return sizeInWords >= 5 && words[0] == spv::MagicNumber && words[1] == spv::Version;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700416}
417
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700418static char const *
419storage_class_name(unsigned sc)
420{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700421 switch (sc) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700422 case spv::StorageClassInput: return "input";
423 case spv::StorageClassOutput: return "output";
424 case spv::StorageClassUniformConstant: return "const uniform";
425 case spv::StorageClassUniform: return "uniform";
426 case spv::StorageClassWorkgroup: return "workgroup local";
427 case spv::StorageClassCrossWorkgroup: return "workgroup global";
428 case spv::StorageClassPrivate: return "private global";
429 case spv::StorageClassFunction: return "function";
430 case spv::StorageClassGeneric: return "generic";
431 case spv::StorageClassAtomicCounter: return "atomic counter";
432 case spv::StorageClassImage: return "image";
433 default: return "unknown";
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700434 }
435}
436
Chris Forbes204207a2016-01-26 14:07:16 +1300437/* get the value of an integral constant */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700438unsigned
439get_constant_value(shader_module const *src, unsigned id)
440{
Chris Forbes204207a2016-01-26 14:07:16 +1300441 auto value = src->get_def(id);
442 assert(value != src->end());
443
444 if (value.opcode() != spv::OpConstant) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700445 /* TODO: Either ensure that the specialization transform is already performed on a module we're
Chris Forbes204207a2016-01-26 14:07:16 +1300446 considering here, OR -- specialize on the fly now.
447 */
448 return 1;
449 }
450
451 return value.word(3);
452}
453
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700454/* returns ptr to null terminator */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700455static char *
456describe_type(char *dst, shader_module const *src, unsigned type)
457{
Chris Forbes21977d92016-01-26 13:41:39 +1300458 auto insn = src->get_def(type);
Chris Forbes1257f912016-01-18 12:07:01 +1300459 assert(insn != src->end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700460
Chris Forbes1257f912016-01-18 12:07:01 +1300461 switch (insn.opcode()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700462 case spv::OpTypeBool:
463 return dst + sprintf(dst, "bool");
464 case spv::OpTypeInt:
465 return dst + sprintf(dst, "%cint%d", insn.word(3) ? 's' : 'u', insn.word(2));
466 case spv::OpTypeFloat:
467 return dst + sprintf(dst, "float%d", insn.word(2));
468 case spv::OpTypeVector:
469 dst += sprintf(dst, "vec%d of ", insn.word(3));
470 return describe_type(dst, src, insn.word(2));
471 case spv::OpTypeMatrix:
472 dst += sprintf(dst, "mat%d of ", insn.word(3));
473 return describe_type(dst, src, insn.word(2));
474 case spv::OpTypeArray:
475 dst += sprintf(dst, "arr[%d] of ", get_constant_value(src, insn.word(3)));
476 return describe_type(dst, src, insn.word(2));
477 case spv::OpTypePointer:
478 dst += sprintf(dst, "ptr to %s ", storage_class_name(insn.word(2)));
479 return describe_type(dst, src, insn.word(3));
480 case spv::OpTypeStruct:
481 {
482 dst += sprintf(dst, "struct of (");
483 for (unsigned i = 2; i < insn.len(); i++) {
484 dst = describe_type(dst, src, insn.word(i));
485 dst += sprintf(dst, i == insn.len()-1 ? ")" : ", ");
486 }
487 return dst;
488 }
489 case spv::OpTypeSampler:
490 return dst + sprintf(dst, "sampler");
491 default:
492 return dst + sprintf(dst, "oddtype");
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700493 }
494}
495
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700496static bool
497types_match(shader_module const *a, shader_module const *b, unsigned a_type, unsigned b_type, bool b_arrayed)
498{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700499 /* walk two type trees together, and complain about differences */
Chris Forbes21977d92016-01-26 13:41:39 +1300500 auto a_insn = a->get_def(a_type);
501 auto b_insn = b->get_def(b_type);
Chris Forbes1257f912016-01-18 12:07:01 +1300502 assert(a_insn != a->end());
503 assert(b_insn != b->end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700504
Chris Forbes1257f912016-01-18 12:07:01 +1300505 if (b_arrayed && b_insn.opcode() == spv::OpTypeArray) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700506 /* 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 +1300507 return types_match(a, b, a_type, b_insn.word(2), false);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700508 }
509
Chris Forbes1257f912016-01-18 12:07:01 +1300510 if (a_insn.opcode() != b_insn.opcode()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700511 return false;
512 }
513
Chris Forbes1257f912016-01-18 12:07:01 +1300514 switch (a_insn.opcode()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700515 /* if b_arrayed and we hit a leaf type, then we can't match -- there's nowhere for the extra OpTypeArray to be! */
516 case spv::OpTypeBool:
517 return true && !b_arrayed;
518 case spv::OpTypeInt:
519 /* match on width, signedness */
520 return a_insn.word(2) == b_insn.word(2) && a_insn.word(3) == b_insn.word(3) && !b_arrayed;
521 case spv::OpTypeFloat:
522 /* match on width */
523 return a_insn.word(2) == b_insn.word(2) && !b_arrayed;
524 case spv::OpTypeVector:
525 case spv::OpTypeMatrix:
526 /* match on element type, count. these all have the same layout. we don't get here if
527 * b_arrayed -- that is handled above. */
528 return !b_arrayed &&
529 types_match(a, b, a_insn.word(2), b_insn.word(2), b_arrayed) &&
530 a_insn.word(3) == b_insn.word(3);
531 case spv::OpTypeArray:
532 /* match on element type, count. these all have the same layout. we don't get here if
533 * b_arrayed. This differs from vector & matrix types in that the array size is the id of a constant instruction,
534 * not a literal within OpTypeArray */
535 return !b_arrayed &&
536 types_match(a, b, a_insn.word(2), b_insn.word(2), b_arrayed) &&
537 get_constant_value(a, a_insn.word(3)) == get_constant_value(b, b_insn.word(3));
538 case spv::OpTypeStruct:
539 /* match on all element types */
540 {
541 if (b_arrayed) {
542 /* for the purposes of matching different levels of arrayness, structs are leaves. */
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700543 return false;
544 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700545
546 if (a_insn.len() != b_insn.len()) {
547 return false; /* structs cannot match if member counts differ */
548 }
549
550 for (unsigned i = 2; i < a_insn.len(); i++) {
551 if (!types_match(a, b, a_insn.word(i), b_insn.word(i), b_arrayed)) {
552 return false;
553 }
554 }
555
556 return true;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700557 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700558 case spv::OpTypePointer:
559 /* match on pointee type. storage class is expected to differ */
560 return types_match(a, b, a_insn.word(3), b_insn.word(3), b_arrayed);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700561
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700562 default:
563 /* remaining types are CLisms, or may not appear in the interfaces we
564 * are interested in. Just claim no match.
565 */
566 return false;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700567
568 }
569}
570
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700571static int
572value_or_default(std::unordered_map<unsigned, unsigned> const &map, unsigned id, int def)
573{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700574 auto it = map.find(id);
575 if (it == map.end())
576 return def;
577 else
578 return it->second;
579}
580
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700581
582static unsigned
583get_locations_consumed_by_type(shader_module const *src, unsigned type, bool strip_array_level)
584{
Chris Forbes21977d92016-01-26 13:41:39 +1300585 auto insn = src->get_def(type);
Chris Forbes1257f912016-01-18 12:07:01 +1300586 assert(insn != src->end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700587
Chris Forbesc7e2e202016-01-18 08:56:40 +1300588 switch (insn.opcode()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700589 case spv::OpTypePointer:
590 /* see through the ptr -- this is only ever at the toplevel for graphics shaders;
591 * we're never actually passing pointers around. */
592 return get_locations_consumed_by_type(src, insn.word(3), strip_array_level);
593 case spv::OpTypeArray:
594 if (strip_array_level) {
595 return get_locations_consumed_by_type(src, insn.word(2), false);
596 }
597 else {
598 return get_constant_value(src, insn.word(3)) * get_locations_consumed_by_type(src, insn.word(2), false);
599 }
600 case spv::OpTypeMatrix:
601 /* num locations is the dimension * element size */
602 return insn.word(3) * get_locations_consumed_by_type(src, insn.word(2), false);
603 default:
604 /* everything else is just 1. */
605 return 1;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700606
607 /* TODO: extend to handle 64bit scalar types, whose vectors may need
608 * multiple locations. */
609 }
610}
611
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700612
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700613struct interface_var {
614 uint32_t id;
615 uint32_t type_id;
616 uint32_t offset;
617 /* TODO: collect the name, too? Isn't required to be present. */
618};
619
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700620
621static void
622collect_interface_block_members(layer_data *my_data, VkDevice dev,
623 shader_module const *src,
624 std::map<uint32_t, interface_var> &out,
625 std::map<uint32_t, interface_var> &builtins_out,
626 std::unordered_map<unsigned, unsigned> const &blocks,
627 bool is_array_of_verts,
628 uint32_t id,
629 uint32_t type_id)
630{
631 /* Walk down the type_id presented, trying to determine whether it's actually an interface block. */
Chris Forbes21977d92016-01-26 13:41:39 +1300632 auto type = src->get_def(type_id);
Chris Forbes1257f912016-01-18 12:07:01 +1300633
Chris Forbesa3e85f62016-01-15 14:53:11 +1300634 while (true) {
635
Chris Forbes1257f912016-01-18 12:07:01 +1300636 if (type.opcode() == spv::OpTypePointer) {
Chris Forbes21977d92016-01-26 13:41:39 +1300637 type = src->get_def(type.word(3));
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700638 }
639 else if (type.opcode() == spv::OpTypeArray && is_array_of_verts) {
Chris Forbes21977d92016-01-26 13:41:39 +1300640 type = src->get_def(type.word(2));
Chris Forbesa3e85f62016-01-15 14:53:11 +1300641 is_array_of_verts = false;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700642 }
643 else if (type.opcode() == spv::OpTypeStruct) {
Chris Forbes1257f912016-01-18 12:07:01 +1300644 if (blocks.find(type.word(1)) == blocks.end()) {
Chris Forbesa3e85f62016-01-15 14:53:11 +1300645 /* This isn't an interface block. */
646 return;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700647 }
648 else {
Chris Forbesa3e85f62016-01-15 14:53:11 +1300649 /* We have found the correct type. Walk its members. */
650 break;
651 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700652 }
653 else {
Chris Forbesa3e85f62016-01-15 14:53:11 +1300654 /* not an interface block */
655 return;
656 }
657 }
658
Chris Forbes1257f912016-01-18 12:07:01 +1300659 /* Walk all the OpMemberDecorate for type's result id. */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300660 for (auto insn : *src) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700661 if (insn.opcode() == spv::OpMemberDecorate && insn.word(1) == type.word(1)) {
Chris Forbesc7e2e202016-01-18 08:56:40 +1300662 unsigned member_index = insn.word(2);
Chris Forbes1257f912016-01-18 12:07:01 +1300663 unsigned member_type_id = type.word(2 + member_index);
Chris Forbesa3e85f62016-01-15 14:53:11 +1300664
Chris Forbesc7e2e202016-01-18 08:56:40 +1300665 if (insn.word(3) == spv::DecorationLocation) {
666 unsigned location = insn.word(4);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700667 unsigned num_locations = get_locations_consumed_by_type(src, member_type_id, false);
668 for (unsigned int offset = 0; offset < num_locations; offset++) {
Chris Forbesa3e85f62016-01-15 14:53:11 +1300669 interface_var v;
670 v.id = id;
671 /* TODO: member index in interface_var too? */
672 v.type_id = member_type_id;
673 v.offset = offset;
674 out[location + offset] = v;
675 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700676 }
677 else if (insn.word(3) == spv::DecorationBuiltIn) {
Chris Forbesc7e2e202016-01-18 08:56:40 +1300678 unsigned builtin = insn.word(4);
Chris Forbesa3e85f62016-01-15 14:53:11 +1300679 interface_var v;
680 v.id = id;
681 v.type_id = member_type_id;
682 v.offset = 0;
683 builtins_out[builtin] = v;
684 }
685 }
Chris Forbesa3e85f62016-01-15 14:53:11 +1300686 }
687}
688
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700689static void
690collect_interface_by_location(layer_data *my_data, VkDevice dev,
691 shader_module const *src, spv::StorageClass sinterface,
692 std::map<uint32_t, interface_var> &out,
693 std::map<uint32_t, interface_var> &builtins_out,
694 bool is_array_of_verts)
695{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700696 std::unordered_map<unsigned, unsigned> var_locations;
697 std::unordered_map<unsigned, unsigned> var_builtins;
Chris Forbesa3e85f62016-01-15 14:53:11 +1300698 std::unordered_map<unsigned, unsigned> blocks;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700699
Chris Forbesc7e2e202016-01-18 08:56:40 +1300700 for (auto insn : *src) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700701
702 /* We consider two interface models: SSO rendezvous-by-location, and
703 * builtins. Complain about anything that fits neither model.
704 */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300705 if (insn.opcode() == spv::OpDecorate) {
706 if (insn.word(2) == spv::DecorationLocation) {
707 var_locations[insn.word(1)] = insn.word(3);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700708 }
709
Chris Forbesc7e2e202016-01-18 08:56:40 +1300710 if (insn.word(2) == spv::DecorationBuiltIn) {
711 var_builtins[insn.word(1)] = insn.word(3);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700712 }
Chris Forbesa3e85f62016-01-15 14:53:11 +1300713
Chris Forbesc7e2e202016-01-18 08:56:40 +1300714 if (insn.word(2) == spv::DecorationBlock) {
715 blocks[insn.word(1)] = 1;
Chris Forbesa3e85f62016-01-15 14:53:11 +1300716 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700717 }
718
719 /* TODO: handle grouped decorations */
720 /* TODO: handle index=1 dual source outputs from FS -- two vars will
721 * have the same location, and we DONT want to clobber. */
722
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700723 else if (insn.opcode() == spv::OpVariable && insn.word(3) == sinterface) {
Chris Forbesc7e2e202016-01-18 08:56:40 +1300724 unsigned id = insn.word(2);
725 unsigned type = insn.word(1);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700726
Chris Forbesc7e2e202016-01-18 08:56:40 +1300727 int location = value_or_default(var_locations, id, -1);
728 int builtin = value_or_default(var_builtins, id, -1);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700729
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700730 /* All variables and interface block members in the Input or Output storage classes
Chris Forbesf5020cf2016-01-13 09:29:31 +1300731 * must be decorated with either a builtin or an explicit location.
732 *
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700733 * TODO: integrate the interface block support here. For now, don't complain --
734 * a valid SPIRV module will only hit this path for the interface block case, as the
735 * individual members of the type are decorated, rather than variable declarations.
Chris Forbesf5020cf2016-01-13 09:29:31 +1300736 */
737
738 if (location != -1) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700739 /* A user-defined interface variable, with a location. Where a variable
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700740 * occupied multiple locations, emit one result for each. */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700741 unsigned num_locations = get_locations_consumed_by_type(src, type,
742 is_array_of_verts);
743 for (unsigned int offset = 0; offset < num_locations; offset++) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700744 interface_var v;
745 v.id = id;
746 v.type_id = type;
747 v.offset = offset;
748 out[location + offset] = v;
749 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700750 }
751 else if (builtin != -1) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700752 /* A builtin interface variable */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700753 /* Note that since builtin interface variables do not consume numbered
754 * locations, there is no larger-than-vec4 consideration as above
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700755 */
756 interface_var v;
757 v.id = id;
758 v.type_id = type;
759 v.offset = 0;
760 builtins_out[builtin] = v;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700761 }
762 else {
Chris Forbesa3e85f62016-01-15 14:53:11 +1300763 /* An interface block instance */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700764 collect_interface_block_members(my_data, dev, src, out, builtins_out,
765 blocks, is_array_of_verts, id, type);
Chris Forbesa3e85f62016-01-15 14:53:11 +1300766 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700767 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700768 }
769}
770
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700771static void
772collect_interface_by_descriptor_slot(layer_data *my_data, VkDevice dev,
773 shader_module const *src, spv::StorageClass sinterface,
774 std::map<std::pair<unsigned, unsigned>, interface_var> &out)
775{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700776
777 std::unordered_map<unsigned, unsigned> var_sets;
778 std::unordered_map<unsigned, unsigned> var_bindings;
779
Chris Forbesc7e2e202016-01-18 08:56:40 +1300780 for (auto insn : *src) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700781 /* All variables in the Uniform or UniformConstant storage classes are required to be decorated with both
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700782 * DecorationDescriptorSet and DecorationBinding.
783 */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300784 if (insn.opcode() == spv::OpDecorate) {
785 if (insn.word(2) == spv::DecorationDescriptorSet) {
786 var_sets[insn.word(1)] = insn.word(3);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700787 }
788
Chris Forbesc7e2e202016-01-18 08:56:40 +1300789 if (insn.word(2) == spv::DecorationBinding) {
790 var_bindings[insn.word(1)] = insn.word(3);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700791 }
792 }
793
Chris Forbesc7e2e202016-01-18 08:56:40 +1300794 else if (insn.opcode() == spv::OpVariable &&
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700795 (insn.word(3) == spv::StorageClassUniform ||
796 insn.word(3) == spv::StorageClassUniformConstant)) {
Chris Forbesc7e2e202016-01-18 08:56:40 +1300797 unsigned set = value_or_default(var_sets, insn.word(2), 0);
798 unsigned binding = value_or_default(var_bindings, insn.word(2), 0);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700799
800 auto existing_it = out.find(std::make_pair(set, binding));
801 if (existing_it != out.end()) {
802 /* conflict within spv image */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700803 log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__,
804 SHADER_CHECKER_INCONSISTENT_SPIRV, "SC",
805 "var %d (type %d) in %s interface in descriptor slot (%u,%u) conflicts with existing definition",
806 insn.word(2), insn.word(1), storage_class_name(sinterface),
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700807 existing_it->first.first, existing_it->first.second);
808 }
809
810 interface_var v;
Chris Forbesc7e2e202016-01-18 08:56:40 +1300811 v.id = insn.word(2);
812 v.type_id = insn.word(1);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700813 out[std::make_pair(set, binding)] = v;
814 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700815 }
816}
817
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700818static bool
819validate_interface_between_stages(layer_data *my_data, VkDevice dev,
820 shader_module const *producer, char const *producer_name,
821 shader_module const *consumer, char const *consumer_name,
822 bool consumer_arrayed_input)
823{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700824 std::map<uint32_t, interface_var> outputs;
825 std::map<uint32_t, interface_var> inputs;
826
827 std::map<uint32_t, interface_var> builtin_outputs;
828 std::map<uint32_t, interface_var> builtin_inputs;
829
830 bool pass = true;
831
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700832 collect_interface_by_location(my_data, dev, producer, spv::StorageClassOutput, outputs, builtin_outputs, false);
833 collect_interface_by_location(my_data, dev, consumer, spv::StorageClassInput, inputs, builtin_inputs,
834 consumer_arrayed_input);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700835
836 auto a_it = outputs.begin();
837 auto b_it = inputs.begin();
838
839 /* maps sorted by key (location); walk them together to find mismatches */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700840 while ((outputs.size() > 0 && a_it != outputs.end()) || ( inputs.size() && b_it != inputs.end())) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700841 bool a_at_end = outputs.size() == 0 || a_it == outputs.end();
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700842 bool b_at_end = inputs.size() == 0 || b_it == inputs.end();
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700843 auto a_first = a_at_end ? 0 : a_it->first;
844 auto b_first = b_at_end ? 0 : b_it->first;
845
846 if (b_at_end || ((!a_at_end) && (a_first < b_first))) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700847 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",
848 "%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 -0700849 pass = false;
850 }
851 a_it++;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700852 }
853 else if (a_at_end || a_first > b_first) {
854 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",
855 "%s consumes input location %d which is not written by %s", consumer_name, b_first, producer_name)) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700856 pass = false;
857 }
858 b_it++;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700859 }
860 else {
861 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 -0700862 /* OK! */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700863 }
864 else {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700865 char producer_type[1024];
866 char consumer_type[1024];
867 describe_type(producer_type, producer, a_it->second.type_id);
868 describe_type(consumer_type, consumer, b_it->second.type_id);
869
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700870 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",
871 "Type mismatch on location %d: '%s' vs '%s'", a_it->first, producer_type, consumer_type)) {
872 pass = false;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700873 }
874 }
875 a_it++;
876 b_it++;
877 }
878 }
879
880 return pass;
881}
882
883enum FORMAT_TYPE {
884 FORMAT_TYPE_UNDEFINED,
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700885 FORMAT_TYPE_FLOAT, /* UNORM, SNORM, FLOAT, USCALED, SSCALED, SRGB -- anything we consider float in the shader */
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700886 FORMAT_TYPE_SINT,
887 FORMAT_TYPE_UINT,
888};
889
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700890static unsigned
891get_format_type(VkFormat fmt) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700892 switch (fmt) {
893 case VK_FORMAT_UNDEFINED:
894 return FORMAT_TYPE_UNDEFINED;
895 case VK_FORMAT_R8_SINT:
896 case VK_FORMAT_R8G8_SINT:
897 case VK_FORMAT_R8G8B8_SINT:
898 case VK_FORMAT_R8G8B8A8_SINT:
899 case VK_FORMAT_R16_SINT:
900 case VK_FORMAT_R16G16_SINT:
901 case VK_FORMAT_R16G16B16_SINT:
902 case VK_FORMAT_R16G16B16A16_SINT:
903 case VK_FORMAT_R32_SINT:
904 case VK_FORMAT_R32G32_SINT:
905 case VK_FORMAT_R32G32B32_SINT:
906 case VK_FORMAT_R32G32B32A32_SINT:
907 case VK_FORMAT_B8G8R8_SINT:
908 case VK_FORMAT_B8G8R8A8_SINT:
909 case VK_FORMAT_A2B10G10R10_SINT_PACK32:
910 case VK_FORMAT_A2R10G10B10_SINT_PACK32:
911 return FORMAT_TYPE_SINT;
912 case VK_FORMAT_R8_UINT:
913 case VK_FORMAT_R8G8_UINT:
914 case VK_FORMAT_R8G8B8_UINT:
915 case VK_FORMAT_R8G8B8A8_UINT:
916 case VK_FORMAT_R16_UINT:
917 case VK_FORMAT_R16G16_UINT:
918 case VK_FORMAT_R16G16B16_UINT:
919 case VK_FORMAT_R16G16B16A16_UINT:
920 case VK_FORMAT_R32_UINT:
921 case VK_FORMAT_R32G32_UINT:
922 case VK_FORMAT_R32G32B32_UINT:
923 case VK_FORMAT_R32G32B32A32_UINT:
924 case VK_FORMAT_B8G8R8_UINT:
925 case VK_FORMAT_B8G8R8A8_UINT:
926 case VK_FORMAT_A2B10G10R10_UINT_PACK32:
927 case VK_FORMAT_A2R10G10B10_UINT_PACK32:
928 return FORMAT_TYPE_UINT;
929 default:
930 return FORMAT_TYPE_FLOAT;
931 }
932}
933
934/* characterizes a SPIR-V type appearing in an interface to a FF stage,
935 * for comparison to a VkFormat's characterization above. */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700936static unsigned
937get_fundamental_type(shader_module const *src, unsigned type)
938{
Chris Forbes21977d92016-01-26 13:41:39 +1300939 auto insn = src->get_def(type);
Chris Forbes1257f912016-01-18 12:07:01 +1300940 assert(insn != src->end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700941
Chris Forbes1257f912016-01-18 12:07:01 +1300942 switch (insn.opcode()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700943 case spv::OpTypeInt:
944 return insn.word(3) ? FORMAT_TYPE_SINT : FORMAT_TYPE_UINT;
945 case spv::OpTypeFloat:
946 return FORMAT_TYPE_FLOAT;
947 case spv::OpTypeVector:
948 return get_fundamental_type(src, insn.word(2));
949 case spv::OpTypeMatrix:
950 return get_fundamental_type(src, insn.word(2));
951 case spv::OpTypeArray:
952 return get_fundamental_type(src, insn.word(2));
953 case spv::OpTypePointer:
954 return get_fundamental_type(src, insn.word(3));
955 default:
956 return FORMAT_TYPE_UNDEFINED;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700957 }
958}
959
960static bool
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700961validate_vi_consistency(layer_data *my_data, VkDevice dev, VkPipelineVertexInputStateCreateInfo const *vi)
962{
963 /* walk the binding descriptions, which describe the step rate and stride of each vertex buffer.
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700964 * each binding should be specified only once.
965 */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700966 std::unordered_map<uint32_t, VkVertexInputBindingDescription const *> bindings;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700967 bool pass = true;
968
969 for (unsigned i = 0; i < vi->vertexBindingDescriptionCount; i++) {
970 auto desc = &vi->pVertexBindingDescriptions[i];
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700971 auto & binding = bindings[desc->binding];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700972 if (binding) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700973 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",
974 "Duplicate vertex input binding descriptions for binding %d", desc->binding)) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700975 pass = false;
976 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700977 }
978 else {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700979 binding = desc;
980 }
981 }
982
983 return pass;
984}
985
986static bool
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700987validate_vi_against_vs_inputs(layer_data *my_data, VkDevice dev, VkPipelineVertexInputStateCreateInfo const *vi, shader_module const *vs)
988{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700989 std::map<uint32_t, interface_var> inputs;
990 /* we collect builtin inputs, but they will never appear in the VI state --
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700991 * the vs builtin inputs are generated in the pipeline, not sourced from buffers (VertexID, etc)
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700992 */
993 std::map<uint32_t, interface_var> builtin_inputs;
994 bool pass = true;
995
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700996 collect_interface_by_location(my_data, dev, vs, spv::StorageClassInput, inputs, builtin_inputs, false);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700997
998 /* Build index by location */
999 std::map<uint32_t, VkVertexInputAttributeDescription const *> attribs;
1000 if (vi) {
1001 for (unsigned i = 0; i < vi->vertexAttributeDescriptionCount; i++)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001002 attribs[vi->pVertexAttributeDescriptions[i].location] = &vi->pVertexAttributeDescriptions[i];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001003 }
1004
1005 auto it_a = attribs.begin();
1006 auto it_b = inputs.begin();
1007
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001008 while ((attribs.size() > 0 && it_a != attribs.end()) || (inputs.size() > 0 && it_b != inputs.end())) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001009 bool a_at_end = attribs.size() == 0 || it_a == attribs.end();
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001010 bool b_at_end = inputs.size() == 0 || it_b == inputs.end();
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001011 auto a_first = a_at_end ? 0 : it_a->first;
1012 auto b_first = b_at_end ? 0 : it_b->first;
Chris Forbes7d83cd52016-01-15 11:32:03 +13001013 if (!a_at_end && (b_at_end || a_first < b_first)) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001014 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",
1015 "Vertex attribute at location %d not consumed by VS", a_first)) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001016 pass = false;
1017 }
1018 it_a++;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001019 }
1020 else if (!b_at_end && (a_at_end || b_first < a_first)) {
1021 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",
1022 "VS consumes input at location %d but not provided", b_first)) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001023 pass = false;
1024 }
1025 it_b++;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001026 }
1027 else {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001028 unsigned attrib_type = get_format_type(it_a->second->format);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001029 unsigned input_type = get_fundamental_type(vs, it_b->second.type_id);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001030
1031 /* type checking */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001032 if (attrib_type != FORMAT_TYPE_UNDEFINED && input_type != FORMAT_TYPE_UNDEFINED && attrib_type != input_type) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001033 char vs_type[1024];
1034 describe_type(vs_type, vs, it_b->second.type_id);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001035 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",
1036 "Attribute type of `%s` at location %d does not match VS input type of `%s`",
1037 string_VkFormat(it_a->second->format), a_first, vs_type)) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001038 pass = false;
1039 }
1040 }
1041
1042 /* OK! */
1043 it_a++;
1044 it_b++;
1045 }
1046 }
1047
1048 return pass;
1049}
1050
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001051static bool
1052validate_fs_outputs_against_render_pass(layer_data *my_data, VkDevice dev, shader_module const *fs, RENDER_PASS_NODE const *rp, uint32_t subpass)
1053{
1054 const std::vector<VkFormat> &color_formats = rp->subpassColorFormats[subpass];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001055 std::map<uint32_t, interface_var> outputs;
1056 std::map<uint32_t, interface_var> builtin_outputs;
1057 bool pass = true;
1058
1059 /* TODO: dual source blend index (spv::DecIndex, zero if not provided) */
1060
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001061 collect_interface_by_location(my_data, dev, fs, spv::StorageClassOutput, outputs, builtin_outputs, false);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001062
1063 auto it = outputs.begin();
1064 uint32_t attachment = 0;
1065
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001066 /* Walk attachment list and outputs together -- this is a little overpowered since attachments
1067 * are currently dense, but the parallel with matching between shader stages is nice.
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001068 */
1069
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001070 while ((outputs.size() > 0 && it != outputs.end()) || attachment < color_formats.size()) {
1071 if (attachment == color_formats.size() || ( it != outputs.end() && it->first < attachment)) {
1072 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",
1073 "FS writes to output location %d with no matching attachment", it->first)) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001074 pass = false;
1075 }
1076 it++;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001077 }
1078 else if (it == outputs.end() || it->first > attachment) {
1079 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",
1080 "Attachment %d not written by FS", attachment)) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001081 pass = false;
1082 }
1083 attachment++;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001084 }
1085 else {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001086 unsigned output_type = get_fundamental_type(fs, it->second.type_id);
1087 unsigned att_type = get_format_type(color_formats[attachment]);
1088
1089 /* type checking */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001090 if (att_type != FORMAT_TYPE_UNDEFINED && output_type != FORMAT_TYPE_UNDEFINED && att_type != output_type) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001091 char fs_type[1024];
1092 describe_type(fs_type, fs, it->second.type_id);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001093 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",
1094 "Attachment %d of type `%s` does not match FS output type of `%s`",
1095 attachment, string_VkFormat(color_formats[attachment]), fs_type)) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001096 pass = false;
1097 }
1098 }
1099
1100 /* OK! */
1101 it++;
1102 attachment++;
1103 }
1104 }
1105
1106 return pass;
1107}
1108
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001109
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001110struct shader_stage_attributes {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001111 char const * const name;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001112 bool arrayed_input;
1113};
1114
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001115
1116static shader_stage_attributes
1117shader_stage_attribs[] = {
1118 { "vertex shader", false },
1119 { "tessellation control shader", true },
1120 { "tessellation evaluation shader", false },
1121 { "geometry shader", true },
1122 { "fragment shader", false },
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001123};
1124
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001125// For given pipelineLayout verify that the setLayout at slot.first
1126// has the requested binding at slot.second
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001127static bool
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001128has_descriptor_binding(layer_data* my_data,
1129 vector<VkDescriptorSetLayout>* pipelineLayout,
1130 std::pair<unsigned, unsigned> slot)
1131{
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001132 if (!pipelineLayout)
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001133 return false;
1134
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001135 if (slot.first >= pipelineLayout->size())
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001136 return false;
1137
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001138 auto set = my_data->descriptorSetLayoutMap[(*pipelineLayout)[slot.first]]->bindings;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001139
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001140 return (set.find(slot.second) != set.end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001141}
1142
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001143static uint32_t get_shader_stage_id(VkShaderStageFlagBits stage)
1144{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001145 uint32_t bit_pos = u_ffs(stage);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001146 return bit_pos-1;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001147}
1148
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001149// Block of code at start here for managing/tracking Pipeline state that this layer cares about
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001150
1151static uint64_t g_drawCount[NUM_DRAW_TYPES] = {0, 0, 0, 0};
1152
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001153// TODO : Should be tracking lastBound per commandBuffer and when draws occur, report based on that cmd buffer lastBound
1154// Then need to synchronize the accesses based on cmd buffer so that if I'm reading state on one cmd buffer, updates
1155// to that same cmd buffer by separate thread are not changing state from underneath us
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001156// Track the last cmd buffer touched by this thread
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001157
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001158// prototype
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001159static GLOBAL_CB_NODE* getCBNode(layer_data*, const VkCommandBuffer);
Tobin Ehlis559c6382015-11-05 09:52:49 -07001160
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001161static VkBool32 hasDrawCmd(GLOBAL_CB_NODE* pCB)
1162{
1163 for (uint32_t i=0; i<NUM_DRAW_TYPES; i++) {
Tobin Ehlis53eddda2015-07-01 16:46:13 -06001164 if (pCB->drawCount[i])
1165 return VK_TRUE;
1166 }
1167 return VK_FALSE;
1168}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001169
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001170// Check object status for selected flag state
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001171static 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)
1172{
1173 // If non-zero enable mask is present, check it against status but if enable_mask
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001174 // is 0 then no enable required so we should always just check status
1175 if ((!enable_mask) || (enable_mask & pNode->status)) {
1176 if ((pNode->status & status_mask) != status_flag) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001177 // TODO : How to pass dispatchable objects as srcObject? Here src obj should be cmd buffer
1178 return log_msg(my_data->report_data, msg_flags, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, error_code, "DS",
1179 "CB object %#" PRIxLEAST64 ": %s", (uint64_t)(pNode->commandBuffer), fail_msg);
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001180 }
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001181 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001182 return VK_FALSE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001183}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001184
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001185// Retrieve pipeline node ptr for given pipeline object
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001186static PIPELINE_NODE* getPipeline(layer_data* my_data, const VkPipeline pipeline)
1187{
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001188 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08001189 if (my_data->pipelineMap.find(pipeline) == my_data->pipelineMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001190 loader_platform_thread_unlock_mutex(&globalLock);
1191 return NULL;
1192 }
1193 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08001194 return my_data->pipelineMap[pipeline];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001195}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001196
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001197// Return VK_TRUE if for a given PSO, the given state enum is dynamic, else return VK_FALSE
1198static VkBool32 isDynamic(const PIPELINE_NODE* pPipeline, const VkDynamicState state)
1199{
Tobin Ehlisd332f282015-10-02 11:00:56 -06001200 if (pPipeline && pPipeline->graphicsPipelineCI.pDynamicState) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001201 for (uint32_t i=0; i<pPipeline->graphicsPipelineCI.pDynamicState->dynamicStateCount; i++) {
1202 if (state == pPipeline->graphicsPipelineCI.pDynamicState->pDynamicStates[i])
Tobin Ehlisd332f282015-10-02 11:00:56 -06001203 return VK_TRUE;
1204 }
1205 }
1206 return VK_FALSE;
1207}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001208
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001209// Validate state stored as flags at time of draw call
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001210static VkBool32 validate_draw_state_flags(layer_data* my_data, GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06001211 VkBool32 result;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001212 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");
1213 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");
1214 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");
1215 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");
1216 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");
1217 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");
1218 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");
1219 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");
1220 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 -06001221 if (indexedDraw)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001222 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 -06001223 return result;
1224}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001225
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001226// Verify attachment reference compatibility according to spec
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001227// If one array is larger, treat missing elements of shorter array as VK_ATTACHMENT_UNUSED & other array much match this
1228// If both AttachmentReference arrays have requested index, check their corresponding AttachementDescriptions
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001229// to make sure that format and samples counts match.
1230// If not, they are not compatible.
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001231static bool attachment_references_compatible(const uint32_t index, const VkAttachmentReference* pPrimary, const uint32_t primaryCount, const VkAttachmentDescription* pPrimaryAttachments,
1232 const VkAttachmentReference* pSecondary, const uint32_t secondaryCount, const VkAttachmentDescription* pSecondaryAttachments)
1233{
1234 if (index >= primaryCount) { // Check secondary as if primary is VK_ATTACHMENT_UNUSED
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001235 if (VK_ATTACHMENT_UNUSED != pSecondary[index].attachment)
1236 return false;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001237 } else if (index >= secondaryCount) { // Check primary as if secondary is VK_ATTACHMENT_UNUSED
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001238 if (VK_ATTACHMENT_UNUSED != pPrimary[index].attachment)
1239 return false;
1240 } else { // format and sample count must match
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001241 if ((pPrimaryAttachments[pPrimary[index].attachment].format == pSecondaryAttachments[pSecondary[index].attachment].format) &&
1242 (pPrimaryAttachments[pPrimary[index].attachment].samples == pSecondaryAttachments[pSecondary[index].attachment].samples))
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001243 return true;
1244 }
1245 // Format and sample counts didn't match
1246 return false;
1247}
1248
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001249// For give primary and secondary RenderPass objects, verify that they're compatible
1250static bool verify_renderpass_compatibility(layer_data* my_data, const VkRenderPass primaryRP, const VkRenderPass secondaryRP, string& errorMsg)
1251{
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001252 stringstream errorStr;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001253 if (my_data->renderPassMap.find(primaryRP) == my_data->renderPassMap.end()) {
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001254 errorStr << "invalid VkRenderPass (" << primaryRP << ")";
1255 errorMsg = errorStr.str();
1256 return false;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001257 } else if (my_data->renderPassMap.find(secondaryRP) == my_data->renderPassMap.end()) {
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001258 errorStr << "invalid VkRenderPass (" << secondaryRP << ")";
1259 errorMsg = errorStr.str();
1260 return false;
1261 }
1262 // Trivial pass case is exact same RP
1263 if (primaryRP == secondaryRP)
1264 return true;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001265 const VkRenderPassCreateInfo* primaryRPCI = my_data->renderPassMap[primaryRP]->pCreateInfo;
1266 const VkRenderPassCreateInfo* secondaryRPCI = my_data->renderPassMap[secondaryRP]->pCreateInfo;
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001267 if (primaryRPCI->subpassCount != secondaryRPCI->subpassCount) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001268 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 -07001269 errorMsg = errorStr.str();
1270 return false;
1271 }
1272 uint32_t spIndex = 0;
1273 for (spIndex = 0; spIndex < primaryRPCI->subpassCount; ++spIndex) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001274 // For each subpass, verify that corresponding color, input, resolve & depth/stencil attachment references are compatible
1275 uint32_t primaryColorCount = primaryRPCI->pSubpasses[spIndex].colorAttachmentCount;
1276 uint32_t secondaryColorCount = secondaryRPCI->pSubpasses[spIndex].colorAttachmentCount;
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001277 uint32_t colorMax = std::max(primaryColorCount, secondaryColorCount);
1278 for (uint32_t cIdx = 0; cIdx < colorMax; ++cIdx) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001279 if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pColorAttachments, primaryColorCount, primaryRPCI->pAttachments,
1280 secondaryRPCI->pSubpasses[spIndex].pColorAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1281 errorStr << "color attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001282 errorMsg = errorStr.str();
1283 return false;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001284 } else if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pResolveAttachments, primaryColorCount, primaryRPCI->pAttachments,
1285 secondaryRPCI->pSubpasses[spIndex].pResolveAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1286 errorStr << "resolve attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001287 errorMsg = errorStr.str();
1288 return false;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001289 } else if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pDepthStencilAttachment, primaryColorCount, primaryRPCI->pAttachments,
1290 secondaryRPCI->pSubpasses[spIndex].pDepthStencilAttachment, secondaryColorCount, secondaryRPCI->pAttachments)) {
1291 errorStr << "depth/stencil attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001292 errorMsg = errorStr.str();
1293 return false;
1294 }
1295 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001296 uint32_t primaryInputCount = primaryRPCI->pSubpasses[spIndex].inputAttachmentCount;
1297 uint32_t secondaryInputCount = secondaryRPCI->pSubpasses[spIndex].inputAttachmentCount;
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001298 uint32_t inputMax = std::max(primaryInputCount, secondaryInputCount);
1299 for (uint32_t i = 0; i < inputMax; ++i) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001300 if (!attachment_references_compatible(i, primaryRPCI->pSubpasses[spIndex].pInputAttachments, primaryColorCount, primaryRPCI->pAttachments,
1301 secondaryRPCI->pSubpasses[spIndex].pInputAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1302 errorStr << "input attachments at index " << i << " of subpass index " << spIndex << " are not compatible.";
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001303 errorMsg = errorStr.str();
1304 return false;
1305 }
1306 }
1307 }
1308 return true;
1309}
1310
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001311// For give SET_NODE, verify that its Set is compatible w/ the setLayout corresponding to pipelineLayout[layoutIndex]
1312static bool verify_set_layout_compatibility(layer_data* my_data, const SET_NODE* pSet, const VkPipelineLayout layout, const uint32_t layoutIndex, string& errorMsg)
1313{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001314 stringstream errorStr;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001315 if (my_data->pipelineLayoutMap.find(layout) == my_data->pipelineLayoutMap.end()) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001316 errorStr << "invalid VkPipelineLayout (" << layout << ")";
1317 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001318 return false;
1319 }
1320 PIPELINE_LAYOUT_NODE pl = my_data->pipelineLayoutMap[layout];
1321 if (layoutIndex >= pl.descriptorSetLayouts.size()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001322 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 -07001323 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001324 return false;
1325 }
1326 // Get the specific setLayout from PipelineLayout that overlaps this set
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001327 LAYOUT_NODE* pLayoutNode = my_data->descriptorSetLayoutMap[pl.descriptorSetLayouts[layoutIndex]];
Tobin Ehlis559c6382015-11-05 09:52:49 -07001328 if (pLayoutNode->layout == pSet->pLayout->layout) { // trivial pass case
1329 return true;
1330 }
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07001331 size_t descriptorCount = pLayoutNode->descriptorTypes.size();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001332 if (descriptorCount != pSet->pLayout->descriptorTypes.size()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001333 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 -07001334 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001335 return false; // trivial fail case
1336 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001337 // Now need to check set against corresponding pipelineLayout to verify compatibility
1338 for (size_t i=0; i<descriptorCount; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07001339 // Need to verify that layouts are identically defined
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001340 // TODO : Is below sufficient? Making sure that types & stageFlags match per descriptor
Tobin Ehlis559c6382015-11-05 09:52:49 -07001341 // do we also need to check immutable samplers?
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001342 if (pLayoutNode->descriptorTypes[i] != pSet->pLayout->descriptorTypes[i]) {
1343 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 -07001344 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001345 return false;
1346 }
1347 if (pLayoutNode->stageFlags[i] != pSet->pLayout->stageFlags[i]) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001348 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 -07001349 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001350 return false;
1351 }
1352 }
1353 return true;
1354}
1355
Tobin Ehlis88452832015-12-03 09:40:56 -07001356// Validate that the shaders used by the given pipeline
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001357// As a side effect this function also records the sets that are actually used by the pipeline
1358static VkBool32
1359validate_pipeline_shaders(layer_data *my_data, VkDevice dev, PIPELINE_NODE* pPipeline)
1360{
1361 VkGraphicsPipelineCreateInfo const *pCreateInfo = &pPipeline->graphicsPipelineCI;
1362 /* We seem to allow pipeline stages to be specified out of order, so collect and identify them
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001363 * before trying to do anything more: */
1364 int vertex_stage = get_shader_stage_id(VK_SHADER_STAGE_VERTEX_BIT);
1365 int geometry_stage = get_shader_stage_id(VK_SHADER_STAGE_GEOMETRY_BIT);
1366 int fragment_stage = get_shader_stage_id(VK_SHADER_STAGE_FRAGMENT_BIT);
1367
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001368 shader_module **shaders = new shader_module*[fragment_stage + 1]; /* exclude CS */
1369 memset(shaders, 0, sizeof(shader_module *) * (fragment_stage +1));
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001370 RENDER_PASS_NODE const *rp = 0;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001371 VkPipelineVertexInputStateCreateInfo const *vi = 0;
Mark Youngb20a6a82016-01-07 15:41:43 -07001372 VkBool32 pass = VK_TRUE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001373
1374 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001375 VkPipelineShaderStageCreateInfo const *pStage = &pCreateInfo->pStages[i];
1376 if (pStage->sType == VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001377
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001378 if ((pStage->stage & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_GEOMETRY_BIT | VK_SHADER_STAGE_FRAGMENT_BIT
1379 | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT)) == 0) {
1380 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",
1381 "Unknown shader stage %d", pStage->stage)) {
Mark Youngb20a6a82016-01-07 15:41:43 -07001382 pass = VK_FALSE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001383 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001384 }
1385 else {
1386 shader_module *module = my_data->shaderModuleMap[pStage->module];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001387 shaders[get_shader_stage_id(pStage->stage)] = module;
1388
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001389 /* validate descriptor set layout against what the spirv module actually uses */
1390 std::map<std::pair<unsigned, unsigned>, interface_var> descriptor_uses;
1391 collect_interface_by_descriptor_slot(my_data, dev, module, spv::StorageClassUniform,
1392 descriptor_uses);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001393
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001394 auto layouts = pCreateInfo->layout != VK_NULL_HANDLE ?
1395 &(my_data->pipelineLayoutMap[pCreateInfo->layout].descriptorSetLayouts) : nullptr;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001396
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001397 for (auto it = descriptor_uses.begin(); it != descriptor_uses.end(); it++) {
1398 // As a side-effect of this function, capture which sets are used by the pipeline
Tobin Ehlis88452832015-12-03 09:40:56 -07001399 pPipeline->active_sets.insert(it->first.first);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001400
1401 /* find the matching binding */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001402 auto found = has_descriptor_binding(my_data, layouts, it->first);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001403
1404 if (!found) {
1405 char type_name[1024];
1406 describe_type(type_name, module, it->second.type_id);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001407 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__,
1408 SHADER_CHECKER_MISSING_DESCRIPTOR, "SC",
1409 "Shader uses descriptor slot %u.%u (used as type `%s`) but not declared in pipeline layout",
1410 it->first.first, it->first.second, type_name)) {
Mark Youngb20a6a82016-01-07 15:41:43 -07001411 pass = VK_FALSE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001412 }
1413 }
1414 }
1415 }
1416 }
1417 }
1418
1419 if (pCreateInfo->renderPass != VK_NULL_HANDLE)
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001420 rp = my_data->renderPassMap[pCreateInfo->renderPass];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001421
1422 vi = pCreateInfo->pVertexInputState;
1423
1424 if (vi) {
1425 pass = validate_vi_consistency(my_data, dev, vi) && pass;
1426 }
1427
1428 if (shaders[vertex_stage]) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001429 pass = validate_vi_against_vs_inputs(my_data, dev, vi, shaders[vertex_stage]) && pass;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001430 }
1431
1432 /* TODO: enforce rules about present combinations of shaders */
1433 int producer = get_shader_stage_id(VK_SHADER_STAGE_VERTEX_BIT);
1434 int consumer = get_shader_stage_id(VK_SHADER_STAGE_GEOMETRY_BIT);
1435
1436 while (!shaders[producer] && producer != fragment_stage) {
1437 producer++;
1438 consumer++;
1439 }
1440
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001441 for (; producer != fragment_stage && consumer <= fragment_stage; consumer++) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001442 assert(shaders[producer]);
1443 if (shaders[consumer]) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001444 pass = validate_interface_between_stages(my_data, dev,
1445 shaders[producer], shader_stage_attribs[producer].name,
1446 shaders[consumer], shader_stage_attribs[consumer].name,
1447 shader_stage_attribs[consumer].arrayed_input) && pass;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001448
1449 producer = consumer;
1450 }
1451 }
1452
1453 if (shaders[fragment_stage] && rp) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001454 pass = validate_fs_outputs_against_render_pass(my_data, dev, shaders[fragment_stage], rp, pCreateInfo->subpass) && pass;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001455 }
1456
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001457 delete [] shaders;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001458
1459 return pass;
1460}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001461
Tobin Ehlisf6585052015-12-17 11:48:42 -07001462// Return Set node ptr for specified set or else NULL
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001463static SET_NODE* getSetNode(layer_data* my_data, const VkDescriptorSet set)
1464{
Tobin Ehlisf6585052015-12-17 11:48:42 -07001465 loader_platform_thread_lock_mutex(&globalLock);
1466 if (my_data->setMap.find(set) == my_data->setMap.end()) {
1467 loader_platform_thread_unlock_mutex(&globalLock);
1468 return NULL;
1469 }
1470 loader_platform_thread_unlock_mutex(&globalLock);
1471 return my_data->setMap[set];
1472}
Tobin Ehlisd2393772016-01-29 11:50:47 -07001473// For the given command buffer, verify that for each set set in activeSetNodes
1474// that any dynamic descriptor in that set has a valid dynamic offset bound.
1475// To be valid, the dynamic offset combined with the offet and range from its
1476// descriptor update must not overflow the size of its buffer being updated
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001477static VkBool32 validate_dynamic_offsets(layer_data* my_data, const GLOBAL_CB_NODE* pCB, const vector<SET_NODE*> activeSetNodes)
1478{
Tobin Ehlisf6585052015-12-17 11:48:42 -07001479 VkBool32 result = VK_FALSE;
Tobin Ehlisf6585052015-12-17 11:48:42 -07001480
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001481 VkWriteDescriptorSet* pWDS = NULL;
Tobin Ehlisf6585052015-12-17 11:48:42 -07001482 uint32_t dynOffsetIndex = 0;
1483 VkDeviceSize bufferSize = 0;
Tobin Ehlisd2393772016-01-29 11:50:47 -07001484 for (auto set_node : activeSetNodes) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001485 for (uint32_t i=0; i < set_node->descriptorCount; ++i) {
Tobin Ehlisd2393772016-01-29 11:50:47 -07001486 switch (set_node->ppDescriptors[i]->sType) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001487 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1488 pWDS = (VkWriteDescriptorSet*)set_node->ppDescriptors[i];
1489 if ((pWDS->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
1490 (pWDS->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
1491 for (uint32_t j=0; j<pWDS->descriptorCount; ++j) {
1492 bufferSize = my_data->bufferMap[pWDS->pBufferInfo[j].buffer].create_info->size;
1493 if ((pCB->dynamicOffsets[dynOffsetIndex] + pWDS->pBufferInfo[j].offset + pWDS->pBufferInfo[j].range) > bufferSize) {
1494 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",
1495 "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 ".",
1496 (uint64_t)set_node->set, i, pCB->dynamicOffsets[dynOffsetIndex], pWDS->pBufferInfo[j].offset, pWDS->pBufferInfo[j].range, (uint64_t)pWDS->pBufferInfo[j].buffer, bufferSize);
1497 }
1498 dynOffsetIndex++;
1499 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 -07001500 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07001501 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001502 break;
1503 default: // Currently only shadowing Write update nodes so shouldn't get here
1504 assert(0);
1505 continue;
Tobin Ehlisd2393772016-01-29 11:50:47 -07001506 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07001507 }
1508 }
1509 return result;
1510}
1511
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001512// Validate overall state at the time of a draw call
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001513static VkBool32 validate_draw_state(layer_data* my_data, GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001514 // First check flag states
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001515 VkBool32 result = validate_draw_state_flags(my_data, pCB, indexedDraw);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001516 PIPELINE_NODE* pPipe = getPipeline(my_data, pCB->lastBoundPipeline);
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001517 // Now complete other state checks
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001518 // TODO : Currently only performing next check if *something* was bound (non-zero last bound)
1519 // There is probably a better way to gate when this check happens, and to know if something *should* have been bound
1520 // We should have that check separately and then gate this check based on that check
Mark Lobodzinski74635932015-12-18 15:35:38 -07001521 if (pPipe) {
Tobin Ehlisd2393772016-01-29 11:50:47 -07001522 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski74635932015-12-18 15:35:38 -07001523 if (pCB->lastBoundPipelineLayout) {
1524 string errorString;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001525 // Need a vector (vs. std::set) of active Sets for dynamicOffset validation in case same set bound w/ different offsets
1526 vector<SET_NODE*> activeSetNodes;
Mark Lobodzinski74635932015-12-18 15:35:38 -07001527 for (auto setIndex : pPipe->active_sets) {
1528 // If valid set is not bound throw an error
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001529 if ((pCB->boundDescriptorSets.size() <= setIndex) || (!pCB->boundDescriptorSets[setIndex])) {
1530 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_DESCRIPTOR_SET_NOT_BOUND, "DS",
1531 "VkPipeline %#" PRIxLEAST64 " uses set #%u but that set is not bound.", (uint64_t)pPipe->pipeline, setIndex);
1532 } else if (!verify_set_layout_compatibility(my_data, my_data->setMap[pCB->boundDescriptorSets[setIndex]], pPipe->graphicsPipelineCI.layout, setIndex, errorString)) {
1533 // Set is bound but not compatible w/ overlapping pipelineLayout from PSO
1534 VkDescriptorSet setHandle = my_data->setMap[pCB->boundDescriptorSets[setIndex]]->set;
1535 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",
1536 "VkDescriptorSet (%#" PRIxLEAST64 ") bound as set #%u is not compatible with overlapping VkPipelineLayout %#" PRIxLEAST64 " due to: %s",
1537 (uint64_t)setHandle, setIndex, (uint64_t)pPipe->graphicsPipelineCI.layout, errorString.c_str());
1538 } 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 -07001539 // Pull the set node
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001540 SET_NODE* pSet = my_data->setMap[pCB->boundDescriptorSets[setIndex]];
1541 // Save vector of all active sets to verify dynamicOffsets below
Tobin Ehlisd2393772016-01-29 11:50:47 -07001542 activeSetNodes.push_back(pSet);
Tobin Ehlis43c39c02016-01-11 13:18:40 -07001543 // Make sure set has been updated
1544 if (!pSet->pUpdateStructs) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001545 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",
1546 "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 -07001547 }
Mark Lobodzinski74635932015-12-18 15:35:38 -07001548 }
Tobin Ehlis88452832015-12-03 09:40:56 -07001549 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001550 // For each dynamic descriptor, make sure dynamic offset doesn't overstep buffer
Tobin Ehlisd2393772016-01-29 11:50:47 -07001551 if (!pCB->dynamicOffsets.empty())
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001552 result |= validate_dynamic_offsets(my_data, pCB, activeSetNodes);
Tobin Ehlis88452832015-12-03 09:40:56 -07001553 }
Mark Lobodzinski74635932015-12-18 15:35:38 -07001554 // Verify Vtx binding
1555 if (pPipe->vtxBindingCount > 0) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001556 VkPipelineVertexInputStateCreateInfo *vtxInCI = &pPipe->vertexInputCI;
1557 for (uint32_t i = 0; i < vtxInCI->vertexBindingDescriptionCount; i++) {
1558 if ((pCB->currentDrawData.buffers.size() < (i+1)) || (pCB->currentDrawData.buffers[i] == VK_NULL_HANDLE)) {
1559 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS",
1560 "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 -07001561 (uint64_t)pCB->lastBoundPipeline, i);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001562
Mark Lobodzinski74635932015-12-18 15:35:38 -07001563 }
1564 }
1565 } else {
Michael Lentine700b0aa2015-10-30 17:57:32 -07001566 if (!pCB->currentDrawData.buffers.empty()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001567 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS,
1568 "DS", "Vertex buffers are bound to command buffer (%#" PRIxLEAST64 ") but no vertex buffers are attached to this Pipeline State Object (%#" PRIxLEAST64 ").",
1569 (uint64_t)pCB->commandBuffer, (uint64_t)pCB->lastBoundPipeline);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06001570 }
1571 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001572 // If Viewport or scissors are dynamic, verify that dynamic count matches PSO count
Mark Lobodzinski74635932015-12-18 15:35:38 -07001573 VkBool32 dynViewport = isDynamic(pPipe, VK_DYNAMIC_STATE_VIEWPORT);
1574 VkBool32 dynScissor = isDynamic(pPipe, VK_DYNAMIC_STATE_SCISSOR);
1575 if (dynViewport) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001576 if (pCB->viewports.size() != pPipe->graphicsPipelineCI.pViewportState->viewportCount) {
1577 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
1578 "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 -07001579 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001580 }
Mark Lobodzinski74635932015-12-18 15:35:38 -07001581 if (dynScissor) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001582 if (pCB->scissors.size() != pPipe->graphicsPipelineCI.pViewportState->scissorCount) {
1583 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
1584 "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 -07001585 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001586 }
Tobin Ehlisd2393772016-01-29 11:50:47 -07001587 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisd332f282015-10-02 11:00:56 -06001588 }
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001589 return result;
1590}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001591
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001592// Verify that create state for a pipeline is valid
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001593static VkBool32 verifyPipelineCreateState(layer_data* my_data, const VkDevice device, PIPELINE_NODE* pPipeline)
1594{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001595 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski2fd2d032015-12-16 14:25:22 -07001596
Tobin Ehlis88452832015-12-03 09:40:56 -07001597 if (!validate_pipeline_shaders(my_data, device, pPipeline)) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001598 skipCall = VK_TRUE;
1599 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001600 // VS is required
1601 if (!(pPipeline->active_shaders & VK_SHADER_STAGE_VERTEX_BIT)) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001602 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
1603 "Invalid Pipeline CreateInfo State: Vtx Shader required");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001604 }
1605 // Either both or neither TC/TE shaders should be defined
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001606 if (((pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) == 0) !=
1607 ((pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) == 0) ) {
1608 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
1609 "Invalid Pipeline CreateInfo State: TE and TC shaders must be included or excluded as a pair");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001610 }
1611 // Compute shaders should be specified independent of Gfx shaders
1612 if ((pPipeline->active_shaders & VK_SHADER_STAGE_COMPUTE_BIT) &&
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001613 (pPipeline->active_shaders & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT |
1614 VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT | VK_SHADER_STAGE_GEOMETRY_BIT |
1615 VK_SHADER_STAGE_FRAGMENT_BIT))) {
1616 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
1617 "Invalid Pipeline CreateInfo State: Do not specify Compute Shader for Gfx Pipeline");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001618 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001619 // VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology is only valid for tessellation pipelines.
1620 // Mismatching primitive topology and tessellation fails graphics pipeline creation.
1621 if (pPipeline->active_shaders & (VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) &&
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001622 (pPipeline->iaStateCI.topology != VK_PRIMITIVE_TOPOLOGY_PATCH_LIST)) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001623 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
1624 "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 -06001625 }
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001626 if (pPipeline->iaStateCI.topology == VK_PRIMITIVE_TOPOLOGY_PATCH_LIST) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001627 if (~pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) {
1628 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
1629 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology is only valid for tessellation pipelines");
Tobin Ehlis912df022015-09-17 08:46:18 -06001630 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001631 if (!pPipeline->tessStateCI.patchControlPoints || (pPipeline->tessStateCI.patchControlPoints > 32)) {
1632 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
1633 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology used with patchControlPoints value %u."
1634 " patchControlPoints should be >0 and <=32.", pPipeline->tessStateCI.patchControlPoints);
Tobin Ehlis912df022015-09-17 08:46:18 -06001635 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001636 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001637 // Viewport state must be included and viewport and scissor counts should always match
1638 // NOTE : Even if these are flagged as dynamic, counts need to be set correctly for shader compiler
Tobin Ehlisd332f282015-10-02 11:00:56 -06001639 if (!pPipeline->graphicsPipelineCI.pViewportState) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001640 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
1641 "Gfx Pipeline pViewportState is null. Even if viewport and scissors are dynamic PSO must include viewportCount and scissorCount in pViewportState.");
1642 } else if (pPipeline->graphicsPipelineCI.pViewportState->scissorCount != pPipeline->graphicsPipelineCI.pViewportState->viewportCount) {
1643 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
1644 "Gfx Pipeline viewport count (%u) must match scissor count (%u).", pPipeline->vpStateCI.viewportCount, pPipeline->vpStateCI.scissorCount);
Tobin Ehlisd332f282015-10-02 11:00:56 -06001645 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001646 // If viewport or scissor are not dynamic, then verify that data is appropriate for count
Tobin Ehlisd332f282015-10-02 11:00:56 -06001647 VkBool32 dynViewport = isDynamic(pPipeline, VK_DYNAMIC_STATE_VIEWPORT);
1648 VkBool32 dynScissor = isDynamic(pPipeline, VK_DYNAMIC_STATE_SCISSOR);
1649 if (!dynViewport) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001650 if (pPipeline->graphicsPipelineCI.pViewportState->viewportCount && !pPipeline->graphicsPipelineCI.pViewportState->pViewports) {
1651 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
1652 "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 -06001653 }
1654 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001655 if (!dynScissor) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001656 if (pPipeline->graphicsPipelineCI.pViewportState->scissorCount && !pPipeline->graphicsPipelineCI.pViewportState->pScissors) {
1657 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
1658 "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 -06001659 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06001660 }
1661 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001662 return skipCall;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001663}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001664
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001665// Init the pipeline mapping info based on pipeline create info LL tree
1666// Threading note : Calls to this function should wrapped in mutex
Tobin Ehlis88452832015-12-03 09:40:56 -07001667// TODO : this should really just be in the constructor for PIPELINE_NODE
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001668static PIPELINE_NODE* initGraphicsPipeline(layer_data* dev_data, const VkGraphicsPipelineCreateInfo* pCreateInfo, PIPELINE_NODE* pBasePipeline)
1669{
1670 PIPELINE_NODE* pPipeline = new PIPELINE_NODE;
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001671
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001672 if (pBasePipeline) {
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001673 *pPipeline = *pBasePipeline;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001674 }
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001675
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001676 // First init create info
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001677 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001678
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001679 size_t bufferSize = 0;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001680 const VkPipelineVertexInputStateCreateInfo* pVICI = NULL;
1681 const VkPipelineColorBlendStateCreateInfo* pCBCI = NULL;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001682
1683 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001684 const VkPipelineShaderStageCreateInfo *pPSSCI = &pCreateInfo->pStages[i];
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001685
Chia-I Wu28e06912015-10-31 00:31:16 +08001686 switch (pPSSCI->stage) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001687 case VK_SHADER_STAGE_VERTEX_BIT:
1688 memcpy(&pPipeline->vsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1689 pPipeline->active_shaders |= VK_SHADER_STAGE_VERTEX_BIT;
1690 break;
1691 case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT:
1692 memcpy(&pPipeline->tcsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1693 pPipeline->active_shaders |= VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
1694 break;
1695 case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT:
1696 memcpy(&pPipeline->tesCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1697 pPipeline->active_shaders |= VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
1698 break;
1699 case VK_SHADER_STAGE_GEOMETRY_BIT:
1700 memcpy(&pPipeline->gsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1701 pPipeline->active_shaders |= VK_SHADER_STAGE_GEOMETRY_BIT;
1702 break;
1703 case VK_SHADER_STAGE_FRAGMENT_BIT:
1704 memcpy(&pPipeline->fsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1705 pPipeline->active_shaders |= VK_SHADER_STAGE_FRAGMENT_BIT;
1706 break;
1707 case VK_SHADER_STAGE_COMPUTE_BIT:
1708 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
1709 pPipeline->active_shaders |= VK_SHADER_STAGE_COMPUTE_BIT;
1710 break;
1711 default:
1712 // TODO : Flag error
1713 break;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001714 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001715 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001716 // Copy over GraphicsPipelineCreateInfo structure embedded pointers
1717 if (pCreateInfo->stageCount != 0) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001718 pPipeline->graphicsPipelineCI.pStages = new VkPipelineShaderStageCreateInfo[pCreateInfo->stageCount];
1719 bufferSize = pCreateInfo->stageCount * sizeof(VkPipelineShaderStageCreateInfo);
1720 memcpy((void*)pPipeline->graphicsPipelineCI.pStages, pCreateInfo->pStages, bufferSize);
Tobin Ehlis963a4042015-09-29 08:18:34 -06001721 }
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001722 if (pCreateInfo->pVertexInputState != NULL) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001723 memcpy((void*)&pPipeline->vertexInputCI, pCreateInfo->pVertexInputState , sizeof(VkPipelineVertexInputStateCreateInfo));
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001724 // Copy embedded ptrs
1725 pVICI = pCreateInfo->pVertexInputState;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001726 pPipeline->vtxBindingCount = pVICI->vertexBindingDescriptionCount;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001727 if (pPipeline->vtxBindingCount) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001728 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
1729 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
1730 memcpy((void*)pPipeline->pVertexBindingDescriptions, pVICI->pVertexBindingDescriptions, bufferSize);
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001731 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08001732 pPipeline->vtxAttributeCount = pVICI->vertexAttributeDescriptionCount;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001733 if (pPipeline->vtxAttributeCount) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001734 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
1735 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
1736 memcpy((void*)pPipeline->pVertexAttributeDescriptions, pVICI->pVertexAttributeDescriptions, bufferSize);
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001737 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001738 pPipeline->graphicsPipelineCI.pVertexInputState = &pPipeline->vertexInputCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001739 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001740 if (pCreateInfo->pInputAssemblyState != NULL) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001741 memcpy((void*)&pPipeline->iaStateCI, pCreateInfo->pInputAssemblyState, sizeof(VkPipelineInputAssemblyStateCreateInfo));
1742 pPipeline->graphicsPipelineCI.pInputAssemblyState = &pPipeline->iaStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001743 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001744 if (pCreateInfo->pTessellationState != NULL) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001745 memcpy((void*)&pPipeline->tessStateCI, pCreateInfo->pTessellationState, sizeof(VkPipelineTessellationStateCreateInfo));
1746 pPipeline->graphicsPipelineCI.pTessellationState = &pPipeline->tessStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001747 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001748 if (pCreateInfo->pViewportState != NULL) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001749 memcpy((void*)&pPipeline->vpStateCI, pCreateInfo->pViewportState, sizeof(VkPipelineViewportStateCreateInfo));
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001750 pPipeline->graphicsPipelineCI.pViewportState = &pPipeline->vpStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001751 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001752 if (pCreateInfo->pRasterizationState != NULL) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001753 memcpy((void*)&pPipeline->rsStateCI, pCreateInfo->pRasterizationState, sizeof(VkPipelineRasterizationStateCreateInfo));
1754 pPipeline->graphicsPipelineCI.pRasterizationState = &pPipeline->rsStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001755 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001756 if (pCreateInfo->pMultisampleState != NULL) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001757 memcpy((void*)&pPipeline->msStateCI, pCreateInfo->pMultisampleState, sizeof(VkPipelineMultisampleStateCreateInfo));
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001758 pPipeline->graphicsPipelineCI.pMultisampleState = &pPipeline->msStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001759 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001760 if (pCreateInfo->pDepthStencilState != NULL) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001761 memcpy((void*)&pPipeline->dsStateCI, pCreateInfo->pDepthStencilState, sizeof(VkPipelineDepthStencilStateCreateInfo));
1762 pPipeline->graphicsPipelineCI.pDepthStencilState = &pPipeline->dsStateCI;
Tobin Ehlis963a4042015-09-29 08:18:34 -06001763 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001764 if (pCreateInfo->pColorBlendState != NULL) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001765 memcpy((void*)&pPipeline->cbStateCI, pCreateInfo->pColorBlendState, sizeof(VkPipelineColorBlendStateCreateInfo));
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001766 // Copy embedded ptrs
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001767 pCBCI = pCreateInfo->pColorBlendState;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001768 pPipeline->attachmentCount = pCBCI->attachmentCount;
1769 if (pPipeline->attachmentCount) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001770 pPipeline->pAttachments = new VkPipelineColorBlendAttachmentState[pPipeline->attachmentCount];
1771 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineColorBlendAttachmentState);
1772 memcpy((void*)pPipeline->pAttachments, pCBCI->pAttachments, bufferSize);
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001773 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001774 pPipeline->graphicsPipelineCI.pColorBlendState = &pPipeline->cbStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001775 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001776 if (pCreateInfo->pDynamicState != NULL) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001777 memcpy((void*)&pPipeline->dynStateCI, pCreateInfo->pDynamicState, sizeof(VkPipelineDynamicStateCreateInfo));
Tobin Ehlis963a4042015-09-29 08:18:34 -06001778 if (pPipeline->dynStateCI.dynamicStateCount) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001779 pPipeline->dynStateCI.pDynamicStates = new VkDynamicState[pPipeline->dynStateCI.dynamicStateCount];
1780 bufferSize = pPipeline->dynStateCI.dynamicStateCount * sizeof(VkDynamicState);
1781 memcpy((void*)pPipeline->dynStateCI.pDynamicStates, pCreateInfo->pDynamicState->pDynamicStates, bufferSize);
Tobin Ehlis963a4042015-09-29 08:18:34 -06001782 }
1783 pPipeline->graphicsPipelineCI.pDynamicState = &pPipeline->dynStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001784 }
Tobin Ehlis88452832015-12-03 09:40:56 -07001785 pPipeline->active_sets.clear();
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001786 return pPipeline;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001787}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001788
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001789// Free the Pipeline nodes
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001790static void deletePipelines(layer_data* my_data)
1791{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001792 if (my_data->pipelineMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06001793 return;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001794 for (auto ii=my_data->pipelineMap.begin(); ii!=my_data->pipelineMap.end(); ++ii) {
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001795 if ((*ii).second->graphicsPipelineCI.stageCount != 0) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001796 delete[] (*ii).second->graphicsPipelineCI.pStages;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001797 }
Tobin Ehlisf313c8b2015-04-01 11:59:08 -06001798 if ((*ii).second->pVertexBindingDescriptions) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001799 delete[] (*ii).second->pVertexBindingDescriptions;
Tobin Ehlisf313c8b2015-04-01 11:59:08 -06001800 }
1801 if ((*ii).second->pVertexAttributeDescriptions) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001802 delete[] (*ii).second->pVertexAttributeDescriptions;
Tobin Ehlisf313c8b2015-04-01 11:59:08 -06001803 }
1804 if ((*ii).second->pAttachments) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001805 delete[] (*ii).second->pAttachments;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001806 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001807 if ((*ii).second->dynStateCI.dynamicStateCount != 0) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001808 delete[] (*ii).second->dynStateCI.pDynamicStates;
Tobin Ehlis963a4042015-09-29 08:18:34 -06001809 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001810 delete (*ii).second;
1811 }
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001812 my_data->pipelineMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001813}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001814
Tobin Ehliseba312c2015-04-01 08:40:34 -06001815// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001816static VkSampleCountFlagBits getNumSamples(layer_data* my_data, const VkPipeline pipeline)
1817{
1818 PIPELINE_NODE* pPipe = my_data->pipelineMap[pipeline];
1819 if (VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001820 return pPipe->msStateCI.rasterizationSamples;
Tobin Ehlis577188e2015-07-13 14:51:15 -06001821 }
Chia-I Wu5c17c962015-10-31 00:31:16 +08001822 return VK_SAMPLE_COUNT_1_BIT;
Tobin Ehliseba312c2015-04-01 08:40:34 -06001823}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001824
Tobin Ehliseba312c2015-04-01 08:40:34 -06001825// Validate state related to the PSO
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001826static VkBool32 validatePipelineState(layer_data* my_data, const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
1827{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001828 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06001829 // Verify that any MSAA request in PSO matches sample# in bound FB
Chia-I Wu5c17c962015-10-31 00:31:16 +08001830 VkSampleCountFlagBits psoNumSamples = getNumSamples(my_data, pipeline);
Tobin Ehliseba312c2015-04-01 08:40:34 -06001831 if (pCB->activeRenderPass) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001832 const VkRenderPassCreateInfo* pRPCI = my_data->renderPassMap[pCB->activeRenderPass]->pCreateInfo;
1833 const VkSubpassDescription* pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
1834 VkSampleCountFlagBits subpassNumSamples = (VkSampleCountFlagBits) 0;
Chia-I Wu08accc62015-07-07 11:50:03 +08001835 uint32_t i;
1836
Chia-I Wud50a7d72015-10-26 20:48:51 +08001837 for (i = 0; i < pSD->colorAttachmentCount; i++) {
Chia-I Wu5c17c962015-10-31 00:31:16 +08001838 VkSampleCountFlagBits samples;
Chia-I Wu08accc62015-07-07 11:50:03 +08001839
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001840 if (pSD->pColorAttachments[i].attachment == VK_ATTACHMENT_UNUSED)
Chia-I Wu08accc62015-07-07 11:50:03 +08001841 continue;
1842
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001843 samples = pRPCI->pAttachments[pSD->pColorAttachments[i].attachment].samples;
1844 if (subpassNumSamples == (VkSampleCountFlagBits) 0) {
Chia-I Wu08accc62015-07-07 11:50:03 +08001845 subpassNumSamples = samples;
1846 } else if (subpassNumSamples != samples) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001847 subpassNumSamples = (VkSampleCountFlagBits) -1;
Chia-I Wu08accc62015-07-07 11:50:03 +08001848 break;
1849 }
1850 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001851 if (pSD->pDepthStencilAttachment && pSD->pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
1852 const VkSampleCountFlagBits samples = pRPCI->pAttachments[pSD->pDepthStencilAttachment->attachment].samples;
1853 if (subpassNumSamples == (VkSampleCountFlagBits) 0)
Chia-I Wu08accc62015-07-07 11:50:03 +08001854 subpassNumSamples = samples;
1855 else if (subpassNumSamples != samples)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001856 subpassNumSamples = (VkSampleCountFlagBits) -1;
Chia-I Wu08accc62015-07-07 11:50:03 +08001857 }
1858
1859 if (psoNumSamples != subpassNumSamples) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001860 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",
1861 "Num samples mismatch! Binding PSO (%#" PRIxLEAST64 ") with %u samples while current RenderPass (%#" PRIxLEAST64 ") w/ %u samples!",
1862 (uint64_t) pipeline, psoNumSamples, (uint64_t) pCB->activeRenderPass, subpassNumSamples);
Tobin Ehliseba312c2015-04-01 08:40:34 -06001863 }
1864 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001865 // 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 -06001866 // Verify and flag error as appropriate
1867 }
1868 // TODO : Add more checks here
1869 } else {
1870 // TODO : Validate non-gfx pipeline updates
1871 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001872 return VK_FALSE;
Tobin Ehliseba312c2015-04-01 08:40:34 -06001873}
1874
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001875// Block of code at start here specifically for managing/tracking DSs
1876
Tobin Ehlis793ad302015-04-03 12:01:11 -06001877// Return Pool node ptr for specified pool or else NULL
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001878static DESCRIPTOR_POOL_NODE* getPoolNode(layer_data* my_data, const VkDescriptorPool pool)
1879{
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001880 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001881 if (my_data->descriptorPoolMap.find(pool) == my_data->descriptorPoolMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001882 loader_platform_thread_unlock_mutex(&globalLock);
1883 return NULL;
1884 }
1885 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07001886 return my_data->descriptorPoolMap[pool];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001887}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001888
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001889static LAYOUT_NODE* getLayoutNode(layer_data* my_data, const VkDescriptorSetLayout layout) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001890 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001891 if (my_data->descriptorSetLayoutMap.find(layout) == my_data->descriptorSetLayoutMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001892 loader_platform_thread_unlock_mutex(&globalLock);
1893 return NULL;
1894 }
1895 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001896 return my_data->descriptorSetLayoutMap[layout];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001897}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001898
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001899// Return VK_FALSE if update struct is of valid type, otherwise flag error and return code from callback
1900static VkBool32 validUpdateStruct(layer_data* my_data, const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
1901{
1902 switch (pUpdateStruct->sType)
1903 {
1904 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1905 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
1906 return VK_FALSE;
1907 default:
1908 return log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
1909 "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 -06001910 }
1911}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001912
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001913// Set count for given update struct in the last parameter
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001914// Return value of skipCall, which is only VK_TRUE if error occurs and callback signals execution to cease
1915static uint32_t getUpdateCount(layer_data* my_data, const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
1916{
1917 switch (pUpdateStruct->sType)
1918 {
1919 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1920 return ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorCount;
1921 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
1922 // TODO : Need to understand this case better and make sure code is correct
1923 return ((VkCopyDescriptorSet*)pUpdateStruct)->descriptorCount;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001924 }
Courtney Goeltzenleuchter7f47bca2015-12-16 16:08:08 -07001925
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001926 return 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001927}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001928
Tobin Ehlis793ad302015-04-03 12:01:11 -06001929// For given Layout Node and binding, return index where that binding begins
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001930static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
1931{
Tobin Ehlis793ad302015-04-03 12:01:11 -06001932 uint32_t offsetIndex = 0;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001933 for (uint32_t i = 0; i < pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001934 if (pLayout->createInfo.pBindings[i].binding == binding)
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001935 break;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001936 offsetIndex += pLayout->createInfo.pBindings[i].descriptorCount;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001937 }
1938 return offsetIndex;
1939}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001940
Tobin Ehlis793ad302015-04-03 12:01:11 -06001941// For given layout node and binding, return last index that is updated
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001942static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
1943{
Tobin Ehlis793ad302015-04-03 12:01:11 -06001944 uint32_t offsetIndex = 0;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001945 for (uint32_t i = 0; i < pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001946 offsetIndex += pLayout->createInfo.pBindings[i].descriptorCount;
1947 if (pLayout->createInfo.pBindings[i].binding == binding)
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001948 break;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001949 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001950 return offsetIndex-1;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001951}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001952
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001953// For given layout and update, return the first overall index of the layout that is updated
1954static 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)
1955{
1956 return getBindingStartIndex(pLayout, binding)+arrayIndex;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001957}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001958
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001959// For given layout and update, return the last overall index of the layout that is updated
1960static 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)
1961{
Tobin Ehlis8a62e632015-10-27 15:43:38 -06001962 uint32_t count = getUpdateCount(my_data, device, pUpdateStruct);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001963 return getBindingStartIndex(pLayout, binding)+arrayIndex+count-1;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001964}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001965
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001966// Verify that the descriptor type in the update struct matches what's expected by the layout
1967static VkBool32 validateUpdateConsistency(layer_data* my_data, const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct, uint32_t startIndex, uint32_t endIndex)
1968{
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001969 // First get actual type of update
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001970 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001971 VkDescriptorType actualType;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001972 uint32_t i = 0;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001973 switch (pUpdateStruct->sType)
1974 {
1975 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1976 actualType = ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorType;
1977 break;
1978 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
1979 /* no need to validate */
1980 return VK_FALSE;
1981 break;
1982 default:
1983 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
1984 "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 -06001985 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001986 if (VK_FALSE == skipCall) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001987 // Set first stageFlags as reference and verify that all other updates match it
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001988 VkShaderStageFlags refStageFlags = pLayout->stageFlags[startIndex];
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001989 for (i = startIndex; i <= endIndex; i++) {
Tobin Ehlis644ff042015-10-20 10:11:55 -06001990 if (pLayout->descriptorTypes[i] != actualType) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001991 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, "DS",
1992 "Write descriptor update has descriptor type %s that does not match overlapping binding descriptor type of %s!",
1993 string_VkDescriptorType(actualType), string_VkDescriptorType(pLayout->descriptorTypes[i]));
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001994 }
1995 if (pLayout->stageFlags[i] != refStageFlags) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07001996 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_DESCRIPTOR_STAGEFLAGS_MISMATCH, "DS",
1997 "Write descriptor update has stageFlags %x that do not match overlapping binding descriptor stageFlags of %x!",
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001998 refStageFlags, pLayout->stageFlags[i]);
Tobin Ehlis483cc352015-09-30 08:30:20 -06001999 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002000 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002001 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002002 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002003}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002004
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002005// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
2006// struct into the pNewNode param. Return VK_TRUE if error condition encountered and callback signals early exit.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002007// NOTE : Calls to this function should be wrapped in mutex
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002008static VkBool32 shadowUpdateNode(layer_data* my_data, const VkDevice device, GENERIC_HEADER* pUpdate, GENERIC_HEADER** pNewNode)
2009{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002010 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002011 VkWriteDescriptorSet* pWDS = NULL;
2012 VkCopyDescriptorSet* pCDS = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002013 size_t array_size = 0;
2014 size_t base_array_size = 0;
2015 size_t total_array_size = 0;
2016 size_t baseBuffAddr = 0;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002017 switch (pUpdate->sType)
2018 {
2019 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
2020 pWDS = new VkWriteDescriptorSet;
2021 *pNewNode = (GENERIC_HEADER*)pWDS;
2022 memcpy(pWDS, pUpdate, sizeof(VkWriteDescriptorSet));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06002023
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002024 switch (pWDS->descriptorType) {
2025 case VK_DESCRIPTOR_TYPE_SAMPLER:
2026 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
2027 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2028 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
2029 {
2030 VkDescriptorImageInfo *info = new VkDescriptorImageInfo[pWDS->descriptorCount];
2031 memcpy(info, pWDS->pImageInfo, pWDS->descriptorCount * sizeof(VkDescriptorImageInfo));
2032 pWDS->pImageInfo = info;
2033 }
2034 break;
2035 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2036 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
2037 {
2038 VkBufferView *info = new VkBufferView[pWDS->descriptorCount];
2039 memcpy(info, pWDS->pTexelBufferView, pWDS->descriptorCount * sizeof(VkBufferView));
2040 pWDS->pTexelBufferView = info;
2041 }
2042 break;
2043 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2044 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2045 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2046 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
2047 {
2048 VkDescriptorBufferInfo *info = new VkDescriptorBufferInfo[pWDS->descriptorCount];
2049 memcpy(info, pWDS->pBufferInfo, pWDS->descriptorCount * sizeof(VkDescriptorBufferInfo));
2050 pWDS->pBufferInfo = info;
2051 }
2052 break;
2053 default:
2054 return VK_ERROR_VALIDATION_FAILED_EXT;
2055 break;
2056 }
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -07002057 break;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002058 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
2059 pCDS = new VkCopyDescriptorSet;
2060 *pNewNode = (GENERIC_HEADER*)pCDS;
2061 memcpy(pCDS, pUpdate, sizeof(VkCopyDescriptorSet));
2062 break;
2063 default:
2064 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
2065 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdate->sType), pUpdate->sType))
2066 return VK_TRUE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002067 }
2068 // Make sure that pNext for the end of shadow copy is NULL
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002069 (*pNewNode)->pNext = NULL;
2070 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002071}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002072
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002073// Verify that given sampler is valid
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002074static VkBool32 validateSampler(const layer_data* my_data, const VkSampler* pSampler, const VkBool32 immutable)
2075{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002076 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002077 auto sampIt = my_data->sampleMap.find(*pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002078 if (sampIt == my_data->sampleMap.end()) {
2079 if (!immutable) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002080 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",
2081 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid sampler %#" PRIxLEAST64, (uint64_t) *pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002082 } else { // immutable
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002083 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",
2084 "vkUpdateDescriptorSets: Attempt to update descriptor whose binding has an invalid immutable sampler %#" PRIxLEAST64, (uint64_t) *pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002085 }
2086 } else {
2087 // TODO : Any further checks we want to do on the sampler?
2088 }
2089 return skipCall;
2090}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002091
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002092// Verify that given imageView is valid
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002093static VkBool32 validateImageView(const layer_data* my_data, const VkImageView* pImageView, const VkImageLayout imageLayout)
2094{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002095 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002096 auto ivIt = my_data->imageViewMap.find(*pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002097 if (ivIt == my_data->imageViewMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002098 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",
2099 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid imageView %#" PRIxLEAST64, (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002100 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002101 // Validate that imageLayout is compatible with aspectMask and image format
2102 VkImageAspectFlags aspectMask = ivIt->second->subresourceRange.aspectMask;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002103 VkImage image = ivIt->second->image;
Michael Lentine7b236262015-10-23 12:41:44 -07002104 // TODO : Check here in case we have a bad image
Tobin Ehlis75cd1c52016-01-21 10:21:04 -07002105 auto imgIt = my_data->imageLayoutMap.find(image);
2106 if (imgIt == my_data->imageLayoutMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002107 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",
2108 "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 -06002109 } else {
2110 VkFormat format = (*imgIt).second->format;
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07002111 VkBool32 ds = vk_format_is_depth_or_stencil(format);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002112 switch (imageLayout) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002113 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
2114 // Only Color bit must be set
2115 if ((aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) != VK_IMAGE_ASPECT_COLOR_BIT) {
2116 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__,
2117 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL and imageView %#" PRIxLEAST64 ""
2118 " that does not have VK_IMAGE_ASPECT_COLOR_BIT set.", (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002119 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002120 // format must NOT be DS
2121 if (ds) {
2122 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__,
2123 DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL and imageView %#" PRIxLEAST64 ""
2124 " but the image format is %s which is not a color format.", (uint64_t) *pImageView, string_VkFormat(format));
2125 }
2126 break;
2127 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
2128 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
2129 // Depth or stencil bit must be set, but both must NOT be set
2130 if (aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) {
2131 if (aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) {
2132 // both must NOT be set
2133 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__,
2134 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with imageView %#" PRIxLEAST64 ""
2135 " that has both STENCIL and DEPTH aspects set", (uint64_t) *pImageView);
2136 }
2137 } else if (!(aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)) {
2138 // Neither were set
2139 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__,
2140 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout %s and imageView %#" PRIxLEAST64 ""
2141 " that does not have STENCIL or DEPTH aspect set.", string_VkImageLayout(imageLayout), (uint64_t) *pImageView);
2142 }
2143 // format must be DS
2144 if (!ds) {
2145 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__,
2146 DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout %s and imageView %#" PRIxLEAST64 ""
2147 " but the image format is %s which is not a depth/stencil format.", string_VkImageLayout(imageLayout), (uint64_t) *pImageView, string_VkFormat(format));
2148 }
2149 break;
2150 default:
2151 // anything to check for other layouts?
2152 break;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002153 }
2154 }
2155 }
2156 return skipCall;
2157}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002158
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002159// Verify that given bufferView is valid
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002160static VkBool32 validateBufferView(const layer_data* my_data, const VkBufferView* pBufferView)
2161{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002162 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002163 auto sampIt = my_data->bufferViewMap.find(*pBufferView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002164 if (sampIt == my_data->bufferViewMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002165 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",
2166 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid bufferView %#" PRIxLEAST64, (uint64_t) *pBufferView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002167 } else {
2168 // TODO : Any further checks we want to do on the bufferView?
2169 }
2170 return skipCall;
2171}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002172
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002173// Verify that given bufferInfo is valid
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002174static VkBool32 validateBufferInfo(const layer_data* my_data, const VkDescriptorBufferInfo* pBufferInfo)
2175{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002176 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002177 auto sampIt = my_data->bufferMap.find(pBufferInfo->buffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002178 if (sampIt == my_data->bufferMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002179 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",
2180 "vkUpdateDescriptorSets: Attempt to update descriptor where bufferInfo has invalid buffer %#" PRIxLEAST64, (uint64_t) pBufferInfo->buffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002181 } else {
2182 // TODO : Any further checks we want to do on the bufferView?
2183 }
2184 return skipCall;
2185}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002186
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002187static VkBool32 validateUpdateContents(const layer_data* my_data, const VkWriteDescriptorSet *pWDS, const VkDescriptorSetLayoutBinding* pLayoutBinding)
2188{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002189 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002190 // First verify that for the given Descriptor type, the correct DescriptorInfo data is supplied
2191 VkBufferView* pBufferView = NULL;
2192 const VkSampler* pSampler = NULL;
2193 VkImageView* pImageView = NULL;
2194 VkImageLayout* pImageLayout = NULL;
2195 VkDescriptorBufferInfo* pBufferInfo = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002196 VkBool32 immutable = VK_FALSE;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002197 uint32_t i = 0;
2198 // For given update type, verify that update contents are correct
2199 switch (pWDS->descriptorType) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002200 case VK_DESCRIPTOR_TYPE_SAMPLER:
2201 for (i=0; i<pWDS->descriptorCount; ++i) {
2202 skipCall |= validateSampler(my_data, &(pWDS->pImageInfo[i].sampler), immutable);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002203 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002204 break;
2205 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
2206 for (i=0; i<pWDS->descriptorCount; ++i) {
2207 if (NULL == pLayoutBinding->pImmutableSamplers) {
2208 pSampler = &(pWDS->pImageInfo[i].sampler);
2209 if (immutable) {
2210 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",
2211 "vkUpdateDescriptorSets: Update #%u is not an immutable sampler %#" PRIxLEAST64 ", but previous update(s) from this "
2212 "VkWriteDescriptorSet struct used an immutable sampler. All updates from a single struct must either "
2213 "use immutable or non-immutable samplers.", i, (uint64_t) *pSampler);
2214 }
2215 } else {
2216 if (i>0 && !immutable) {
2217 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",
2218 "vkUpdateDescriptorSets: Update #%u is an immutable sampler, but previous update(s) from this "
2219 "VkWriteDescriptorSet struct used a non-immutable sampler. All updates from a single struct must either "
2220 "use immutable or non-immutable samplers.", i);
2221 }
2222 immutable = VK_TRUE;
2223 pSampler = &(pLayoutBinding->pImmutableSamplers[i]);
2224 }
2225 skipCall |= validateSampler(my_data, pSampler, immutable);
2226 }
2227 // Intentionally fall through here to also validate image stuff
2228 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2229 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
2230 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
2231 for (i=0; i<pWDS->descriptorCount; ++i) {
2232 skipCall |= validateImageView(my_data, &(pWDS->pImageInfo[i].imageView), pWDS->pImageInfo[i].imageLayout);
2233 }
2234 break;
2235 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2236 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
2237 for (i=0; i<pWDS->descriptorCount; ++i) {
2238 skipCall |= validateBufferView(my_data, &(pWDS->pTexelBufferView[i]));
2239 }
2240 break;
2241 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2242 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2243 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2244 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
2245 for (i=0; i<pWDS->descriptorCount; ++i) {
2246 skipCall |= validateBufferInfo(my_data, &(pWDS->pBufferInfo[i]));
2247 }
2248 break;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002249 }
2250 return skipCall;
2251}
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002252// 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 -07002253// func_str is the name of the calling function
2254// Return VK_FALSE if no errors occur
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002255// Return VK_TRUE if validation error occurs and callback returns VK_TRUE (to skip upcoming API call down the chain)
2256VkBool32 validateIdleDescriptorSet(const layer_data* my_data, VkDescriptorSet set, std::string func_str) {
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002257 VkBool32 skip_call = VK_FALSE;
2258 auto set_node = my_data->setMap.find(set);
2259 if (set_node == my_data->setMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002260 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",
2261 "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 -07002262 } else {
2263 if (set_node->second->in_use.load()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002264 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",
2265 "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 -07002266 }
2267 }
2268 return skip_call;
2269}
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002270static void invalidateBoundCmdBuffers(layer_data* dev_data, const SET_NODE* pSet)
2271{
Tobin Ehlise6e574b2016-01-24 23:25:31 -07002272 // Flag any CBs this set is bound to as INVALID
2273 for (auto cb : pSet->boundCmdBuffers) {
2274 auto cb_node = dev_data->commandBufferMap.find(cb);
2275 if (cb_node != dev_data->commandBufferMap.end()) {
2276 cb_node->second->state = CB_INVALID;
2277 }
2278 }
2279}
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002280// update DS mappings based on write and copy update arrays
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002281static VkBool32 dsUpdate(layer_data* my_data, VkDevice device, uint32_t descriptorWriteCount, const VkWriteDescriptorSet* pWDS, uint32_t descriptorCopyCount, const VkCopyDescriptorSet* pCDS)
2282{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002283 VkBool32 skipCall = VK_FALSE;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002284
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002285 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002286 LAYOUT_NODE* pLayout = NULL;
2287 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002288 // Validate Write updates
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002289 uint32_t i = 0;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002290 for (i=0; i < descriptorWriteCount; i++) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002291 VkDescriptorSet ds = pWDS[i].dstSet;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002292 SET_NODE* pSet = my_data->setMap[ds];
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002293 // Set being updated cannot be in-flight
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002294 if ((skipCall = validateIdleDescriptorSet(my_data, ds, "VkUpdateDescriptorSets")) == VK_TRUE)
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002295 return skipCall;
Tobin Ehlise6e574b2016-01-24 23:25:31 -07002296 // If set is bound to any cmdBuffers, mark them invalid
2297 invalidateBoundCmdBuffers(my_data, pSet);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002298 GENERIC_HEADER* pUpdate = (GENERIC_HEADER*) &pWDS[i];
Tobin Ehlis793ad302015-04-03 12:01:11 -06002299 pLayout = pSet->pLayout;
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002300 // First verify valid update struct
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002301 if ((skipCall = validUpdateStruct(my_data, device, pUpdate)) == VK_TRUE) {
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002302 break;
2303 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002304 uint32_t binding = 0, endIndex = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002305 binding = pWDS[i].dstBinding;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002306 // Make sure that layout being updated has the binding being updated
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002307 if (pLayout->bindings.find(binding) == pLayout->bindings.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002308 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",
2309 "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 -06002310 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06002311 // Next verify that update falls within size of given binding
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002312 endIndex = getUpdateEndIndex(my_data, device, pLayout, binding, pWDS[i].dstArrayElement, pUpdate);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002313 if (getBindingEndIndex(pLayout, binding) < endIndex) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06002314 pLayoutCI = &pLayout->createInfo;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002315 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
2316 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",
2317 "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());
2318 } else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002319 uint32_t startIndex;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002320 startIndex = getUpdateStartIndex(my_data, device, pLayout, binding, pWDS[i].dstArrayElement, pUpdate);
2321 // Layout bindings match w/ update, now verify that update type & stageFlags are the same for entire update
2322 if ((skipCall = validateUpdateConsistency(my_data, device, pLayout, pUpdate, startIndex, endIndex)) == VK_FALSE) {
2323 // The update is within bounds and consistent, but need to make sure contents make sense as well
2324 if ((skipCall = validateUpdateContents(my_data, &pWDS[i], &pLayout->createInfo.pBindings[binding])) == VK_FALSE) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002325 // Update is good. Save the update info
2326 // Create new update struct for this set's shadow copy
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002327 GENERIC_HEADER* pNewNode = NULL;
2328 skipCall |= shadowUpdateNode(my_data, device, pUpdate, &pNewNode);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002329 if (NULL == pNewNode) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002330 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",
2331 "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002332 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002333 // Insert shadow node into LL of updates for this set
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002334 pNewNode->pNext = pSet->pUpdateStructs;
2335 pSet->pUpdateStructs = pNewNode;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002336 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002337 for (uint32_t j = startIndex; j <= endIndex; j++) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002338 assert(j<pSet->descriptorCount);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002339 pSet->ppDescriptors[j] = pNewNode;
2340 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002341 }
2342 }
2343 }
2344 }
2345 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002346 }
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002347 // Now validate copy updates
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002348 for (i=0; i < descriptorCopyCount; ++i) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002349 SET_NODE *pSrcSet = NULL, *pDstSet = NULL;
2350 LAYOUT_NODE *pSrcLayout = NULL, *pDstLayout = NULL;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002351 uint32_t srcStartIndex = 0, srcEndIndex = 0, dstStartIndex = 0, dstEndIndex = 0;
2352 // For each copy make sure that update falls within given layout and that types match
Chia-I Wue2fc5522015-10-26 20:04:44 +08002353 pSrcSet = my_data->setMap[pCDS[i].srcSet];
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002354 pDstSet = my_data->setMap[pCDS[i].dstSet];
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002355 // Set being updated cannot be in-flight
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002356 if ((skipCall = validateIdleDescriptorSet(my_data, pDstSet->set, "VkUpdateDescriptorSets")) == VK_TRUE)
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002357 return skipCall;
Tobin Ehlise6e574b2016-01-24 23:25:31 -07002358 invalidateBoundCmdBuffers(my_data, pDstSet);
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002359 pSrcLayout = pSrcSet->pLayout;
2360 pDstLayout = pDstSet->pLayout;
2361 // Validate that src binding is valid for src set layout
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002362 if (pSrcLayout->bindings.find(pCDS[i].srcBinding) == pSrcLayout->bindings.end()) {
2363 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",
2364 "Copy descriptor update %u has srcBinding %u which is out of bounds for underlying SetLayout %#" PRIxLEAST64 " which only has bindings 0-%u.",
2365 i, pCDS[i].srcBinding, (uint64_t) pSrcLayout->layout, pSrcLayout->createInfo.bindingCount-1);
2366 } else if (pDstLayout->bindings.find(pCDS[i].dstBinding) == pDstLayout->bindings.end()) {
2367 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",
2368 "Copy descriptor update %u has dstBinding %u which is out of bounds for underlying SetLayout %#" PRIxLEAST64 " which only has bindings 0-%u.",
2369 i, pCDS[i].dstBinding, (uint64_t) pDstLayout->layout, pDstLayout->createInfo.bindingCount-1);
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002370 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002371 // Proceed with validation. Bindings are ok, but make sure update is within bounds of given layout
2372 srcEndIndex = getUpdateEndIndex(my_data, device, pSrcLayout, pCDS[i].srcBinding, pCDS[i].srcArrayElement, (const GENERIC_HEADER*)&(pCDS[i]));
2373 dstEndIndex = getUpdateEndIndex(my_data, device, pDstLayout, pCDS[i].dstBinding, pCDS[i].dstArrayElement, (const GENERIC_HEADER*)&(pCDS[i]));
2374 if (getBindingEndIndex(pSrcLayout, pCDS[i].srcBinding) < srcEndIndex) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002375 pLayoutCI = &pSrcLayout->createInfo;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002376 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
2377 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",
2378 "Copy descriptor src update is out of bounds for matching binding %u in Layout w/ CI:\n%s!", pCDS[i].srcBinding, DSstr.c_str());
2379 } else if (getBindingEndIndex(pDstLayout, pCDS[i].dstBinding) < dstEndIndex) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002380 pLayoutCI = &pDstLayout->createInfo;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002381 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
2382 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",
2383 "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 -06002384 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002385 srcStartIndex = getUpdateStartIndex(my_data, device, pSrcLayout, pCDS[i].srcBinding, pCDS[i].srcArrayElement, (const GENERIC_HEADER*)&(pCDS[i]));
2386 dstStartIndex = getUpdateStartIndex(my_data, device, pDstLayout, pCDS[i].dstBinding, pCDS[i].dstArrayElement, (const GENERIC_HEADER*)&(pCDS[i]));
2387 for (uint32_t j=0; j<pCDS[i].descriptorCount; ++j) {
2388 // For copy just make sure that the types match and then perform the update
2389 if (pSrcLayout->descriptorTypes[srcStartIndex+j] != pDstLayout->descriptorTypes[dstStartIndex+j]) {
2390 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, "DS",
2391 "Copy descriptor update index %u, update count #%u, has src update descriptor type %s that does not match overlapping dest descriptor type of %s!",
2392 i, j+1, string_VkDescriptorType(pSrcLayout->descriptorTypes[srcStartIndex+j]), string_VkDescriptorType(pDstLayout->descriptorTypes[dstStartIndex+j]));
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002393 } else {
2394 // point dst descriptor at corresponding src descriptor
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002395 // TODO : This may be a hole. I believe copy should be its own copy,
2396 // otherwise a subsequent write update to src will incorrectly affect the copy
2397 pDstSet->ppDescriptors[j+dstStartIndex] = pSrcSet->ppDescriptors[j+srcStartIndex];
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002398 }
2399 }
2400 }
2401 }
2402 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002403 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002404 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002405}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002406
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002407// Verify that given pool has descriptors that are being requested for allocation
2408static VkBool32 validate_descriptor_availability_in_pool(layer_data* dev_data, DESCRIPTOR_POOL_NODE* pPoolNode, uint32_t count, const VkDescriptorSetLayout* pSetLayouts)
2409{
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002410 VkBool32 skipCall = VK_FALSE;
2411 uint32_t i = 0, j = 0;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002412 for (i=0; i<count; ++i) {
2413 LAYOUT_NODE* pLayout = getLayoutNode(dev_data, pSetLayouts[i]);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002414 if (NULL == pLayout) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002415 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",
2416 "Unable to find set layout node for layout %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pSetLayouts[i]);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002417 } else {
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002418 uint32_t typeIndex = 0, poolSizeCount = 0;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002419 for (j=0; j<pLayout->createInfo.bindingCount; ++j) {
2420 typeIndex = static_cast<uint32_t>(pLayout->createInfo.pBindings[j].descriptorType);
2421 poolSizeCount = pLayout->createInfo.pBindings[j].descriptorCount;
2422 if (poolSizeCount > pPoolNode->availableDescriptorTypeCount[typeIndex]) {
2423 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",
2424 "Unable to allocate %u descriptors of type %s from pool %#" PRIxLEAST64 ". This pool only has %u descriptors of this type remaining.",
2425 poolSizeCount, string_VkDescriptorType(pLayout->createInfo.pBindings[j].descriptorType), (uint64_t) pPoolNode->pool, pPoolNode->availableDescriptorTypeCount[typeIndex]);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002426 } else { // Decrement available descriptors of this type
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002427 pPoolNode->availableDescriptorTypeCount[typeIndex] -= poolSizeCount;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002428 }
2429 }
2430 }
2431 }
2432 return skipCall;
2433}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002434
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002435// Free the shadowed update node for this Set
2436// NOTE : Calls to this function should be wrapped in mutex
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002437static void freeShadowUpdateTree(SET_NODE* pSet)
2438{
2439 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002440 pSet->pUpdateStructs = NULL;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002441 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002442 // Clear the descriptor mappings as they will now be invalid
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002443 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
2444 while(pShadowUpdate) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002445 pFreeUpdate = pShadowUpdate;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002446 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002447 uint32_t index = 0;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002448 VkWriteDescriptorSet * pWDS = NULL;
2449 VkCopyDescriptorSet * pCDS = NULL;
2450 void** ppToFree = NULL;
2451 switch (pFreeUpdate->sType)
2452 {
2453 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
2454 pWDS = (VkWriteDescriptorSet*)pFreeUpdate;
2455 switch (pWDS->descriptorType) {
2456 case VK_DESCRIPTOR_TYPE_SAMPLER:
2457 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
2458 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2459 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
2460 {
2461 delete[] pWDS->pImageInfo;
2462 }
2463 break;
2464 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2465 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
2466 {
2467 delete[] pWDS->pTexelBufferView;
2468 }
2469 break;
2470 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2471 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2472 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2473 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
2474 {
2475 delete[] pWDS->pBufferInfo;
2476 }
2477 break;
2478 default:
2479 break;
2480 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002481 break;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002482 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
2483 break;
2484 default:
2485 assert(0);
2486 break;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002487 }
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002488 delete pFreeUpdate;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002489 }
2490}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002491
Tobin Ehlis793ad302015-04-03 12:01:11 -06002492// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002493// NOTE : Calls to this function should be wrapped in mutex
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002494static void deletePools(layer_data* my_data)
2495{
Mark Lobodzinski39298632015-11-18 08:38:27 -07002496 if (my_data->descriptorPoolMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06002497 return;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002498 for (auto ii=my_data->descriptorPoolMap.begin(); ii!=my_data->descriptorPoolMap.end(); ++ii) {
2499 SET_NODE* pSet = (*ii).second->pSets;
2500 SET_NODE* pFreeSet = pSet;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002501 while (pSet) {
2502 pFreeSet = pSet;
2503 pSet = pSet->pNext;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002504 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002505 // Free Update shadow struct tree
2506 freeShadowUpdateTree(pFreeSet);
2507 if (pFreeSet->ppDescriptors) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002508 delete[] pFreeSet->ppDescriptors;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002509 }
2510 delete pFreeSet;
2511 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002512 delete (*ii).second;
2513 }
Mark Lobodzinski39298632015-11-18 08:38:27 -07002514 my_data->descriptorPoolMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002515}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002516
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002517// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
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 deleteLayouts(layer_data* my_data)
2520{
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07002521 if (my_data->descriptorSetLayoutMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06002522 return;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002523 for (auto ii=my_data->descriptorSetLayoutMap.begin(); ii!=my_data->descriptorSetLayoutMap.end(); ++ii) {
2524 LAYOUT_NODE* pLayout = (*ii).second;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002525 if (pLayout->createInfo.pBindings) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002526 for (uint32_t i=0; i<pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002527 if (pLayout->createInfo.pBindings[i].pImmutableSamplers)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002528 delete[] pLayout->createInfo.pBindings[i].pImmutableSamplers;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002529 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002530 delete[] pLayout->createInfo.pBindings;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002531 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002532 delete pLayout;
2533 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07002534 my_data->descriptorSetLayoutMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002535}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002536
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002537// Currently clearing a set is removing all previous updates to that set
2538// TODO : Validate if this is correct clearing behavior
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002539static void clearDescriptorSet(layer_data* my_data, VkDescriptorSet set)
2540{
2541 SET_NODE* pSet = getSetNode(my_data, set);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002542 if (!pSet) {
2543 // TODO : Return error
Tobin Ehlisce132d82015-06-19 15:07:05 -06002544 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002545 loader_platform_thread_lock_mutex(&globalLock);
2546 freeShadowUpdateTree(pSet);
2547 loader_platform_thread_unlock_mutex(&globalLock);
2548 }
2549}
2550
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002551static void clearDescriptorPool(layer_data* my_data, const VkDevice device, const VkDescriptorPool pool, VkDescriptorPoolResetFlags flags)
2552{
2553 DESCRIPTOR_POOL_NODE* pPool = getPoolNode(my_data, pool);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002554 if (!pPool) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002555 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",
2556 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkResetDescriptorPool() call", (uint64_t) pool);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002557 } else {
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002558 // TODO: validate flags
Tobin Ehlis793ad302015-04-03 12:01:11 -06002559 // For every set off of this pool, clear it
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002560 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002561 while (pSet) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002562 clearDescriptorSet(my_data, pSet->set);
Mark Lobodzinskidcce0792016-01-04 09:40:19 -07002563 pSet = pSet->pNext;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002564 }
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002565 // Reset available count to max count for this pool
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002566 for (uint32_t i=0; i<pPool->availableDescriptorTypeCount.size(); ++i) {
2567 pPool->availableDescriptorTypeCount[i] = pPool->maxDescriptorTypeCount[i];
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002568 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002569 }
2570}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002571
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002572// For given CB object, fetch associated CB Node from map
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002573static GLOBAL_CB_NODE* getCBNode(layer_data* my_data, const VkCommandBuffer cb)
2574{
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002575 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002576 if (my_data->commandBufferMap.count(cb) == 0) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002577 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002578 // TODO : How to pass cb as srcObj here?
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002579 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",
2580 "Attempt to use CommandBuffer %#" PRIxLEAST64 " that doesn't exist!", (uint64_t)(cb));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002581 return NULL;
2582 }
2583 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002584 return my_data->commandBufferMap[cb];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002585}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002586
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002587// Free all CB Nodes
2588// NOTE : Calls to this function should be wrapped in mutex
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002589static void deleteCommandBuffers(layer_data* my_data)
2590{
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002591 if (my_data->commandBufferMap.size() <= 0) {
David Pinedod8f83d82015-04-27 16:36:17 -06002592 return;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002593 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002594 for (auto ii=my_data->commandBufferMap.begin(); ii!=my_data->commandBufferMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002595 delete (*ii).second;
2596 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002597 my_data->commandBufferMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002598}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002599
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002600static VkBool32 report_error_no_cb_begin(const layer_data* dev_data, const VkCommandBuffer cb, const char* caller_name)
2601{
2602 return log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2603 (uint64_t)cb, __LINE__, DRAWSTATE_NO_BEGIN_COMMAND_BUFFER, "DS",
2604 "You must call vkBeginCommandBuffer() before this call to %s", caller_name);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002605}
Michael Lentine3dea6512015-10-28 15:55:18 -07002606
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002607VkBool32 validateCmdsInCmdBuffer(const layer_data* dev_data, const GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd_type) {
2608 if (!pCB->activeRenderPass) return VK_FALSE;
Mark Youngb20a6a82016-01-07 15:41:43 -07002609 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002610 if (pCB->activeSubpassContents == VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS && cmd_type != CMD_EXECUTECOMMANDS) {
2611 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
2612 DRAWSTATE_INVALID_COMMAND_BUFFER, "DS", "Commands cannot be called in a subpass using secondary command buffers.");
2613 } else if (pCB->activeSubpassContents == VK_SUBPASS_CONTENTS_INLINE && cmd_type == CMD_EXECUTECOMMANDS) {
2614 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
2615 DRAWSTATE_INVALID_COMMAND_BUFFER, "DS", "vkCmdExecuteCommands() cannot be called in a subpass using inline commands.");
Michael Lentine2e068b22015-12-29 16:05:27 -06002616 }
Michael Lentine3dea6512015-10-28 15:55:18 -07002617 return skip_call;
2618}
2619
Michael Lentine26870f32016-01-26 21:36:08 -06002620static bool checkGraphicsBit(const layer_data* my_data, VkQueueFlags flags, const char* name) {
2621 if (!(flags & VK_QUEUE_GRAPHICS_BIT))
2622 return log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
2623 DRAWSTATE_INVALID_COMMAND_BUFFER, "DS", "Cannot call %s on a command buffer allocated from a pool without graphics capabilities.", name);
2624 return false;
2625}
2626
2627static bool checkComputeBit(const layer_data* my_data, VkQueueFlags flags, const char* name) {
2628 if (!(flags & VK_QUEUE_COMPUTE_BIT))
2629 return log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
2630 DRAWSTATE_INVALID_COMMAND_BUFFER, "DS", "Cannot call %s on a command buffer allocated from a pool without compute capabilities.", name);
2631 return false;
2632}
2633
2634static bool checkGraphicsOrComputeBit(const layer_data* my_data, VkQueueFlags flags, const char* name) {
2635 if (!((flags & VK_QUEUE_GRAPHICS_BIT) || (flags & VK_QUEUE_COMPUTE_BIT)))
2636 return log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
2637 DRAWSTATE_INVALID_COMMAND_BUFFER, "DS", "Cannot call %s on a command buffer allocated from a pool without graphics capabilities.", name);
2638 return false;
2639}
2640
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002641// Add specified CMD to the CmdBuffer in given pCB, flagging errors if CB is not
2642// in the recording state or if there's an issue with the Cmd ordering
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002643static VkBool32 addCmd(const layer_data* my_data, GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd, const char* caller_name)
2644{
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002645 VkBool32 skipCall = VK_FALSE;
Michael Lentine26870f32016-01-26 21:36:08 -06002646 auto pool_data = my_data->commandPoolMap.find(pCB->createInfo.commandPool);
2647 if (pool_data != my_data->commandPoolMap.end()) {
2648 VkQueueFlags flags = my_data->physDevProperties.queue_family_properties[pool_data->second.queueFamilyIndex].queueFlags;
2649 switch (cmd)
2650 {
2651 case CMD_BINDPIPELINE:
2652 case CMD_BINDPIPELINEDELTA:
2653 case CMD_BINDDESCRIPTORSETS:
2654 case CMD_FILLBUFFER:
2655 case CMD_CLEARCOLORIMAGE:
2656 case CMD_SETEVENT:
2657 case CMD_RESETEVENT:
2658 case CMD_WAITEVENTS:
2659 case CMD_BEGINQUERY:
2660 case CMD_ENDQUERY:
2661 case CMD_RESETQUERYPOOL:
2662 case CMD_COPYQUERYPOOLRESULTS:
2663 case CMD_WRITETIMESTAMP:
2664 skipCall |= checkGraphicsOrComputeBit(my_data, flags, cmdTypeToString(cmd).c_str());
2665 break;
2666 case CMD_SETVIEWPORTSTATE:
2667 case CMD_SETSCISSORSTATE:
2668 case CMD_SETLINEWIDTHSTATE:
2669 case CMD_SETDEPTHBIASSTATE:
2670 case CMD_SETBLENDSTATE:
2671 case CMD_SETDEPTHBOUNDSSTATE:
2672 case CMD_SETSTENCILREADMASKSTATE:
2673 case CMD_SETSTENCILWRITEMASKSTATE:
2674 case CMD_SETSTENCILREFERENCESTATE:
2675 case CMD_BINDINDEXBUFFER:
2676 case CMD_BINDVERTEXBUFFER:
2677 case CMD_DRAW:
2678 case CMD_DRAWINDEXED:
2679 case CMD_DRAWINDIRECT:
2680 case CMD_DRAWINDEXEDINDIRECT:
2681 case CMD_BLITIMAGE:
2682 case CMD_CLEARATTACHMENTS:
2683 case CMD_CLEARDEPTHSTENCILIMAGE:
2684 case CMD_RESOLVEIMAGE:
2685 case CMD_BEGINRENDERPASS:
2686 case CMD_NEXTSUBPASS:
2687 case CMD_ENDRENDERPASS:
2688 skipCall |= checkGraphicsBit(my_data, flags, cmdTypeToString(cmd).c_str());
2689 break;
2690 case CMD_DISPATCH:
2691 case CMD_DISPATCHINDIRECT:
2692 skipCall |= checkComputeBit(my_data, flags, cmdTypeToString(cmd).c_str());
2693 break;
2694 case CMD_COPYBUFFER:
2695 case CMD_COPYIMAGE:
2696 case CMD_COPYBUFFERTOIMAGE:
2697 case CMD_COPYIMAGETOBUFFER:
2698 case CMD_CLONEIMAGEDATA:
2699 case CMD_UPDATEBUFFER:
2700 case CMD_PIPELINEBARRIER:
2701 case CMD_EXECUTECOMMANDS:
2702 break;
2703 default:
2704 break;
2705 }
2706 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002707 if (pCB->state != CB_RECORDING) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002708 skipCall |= report_error_no_cb_begin(my_data, pCB->commandBuffer, caller_name);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002709 skipCall |= validateCmdsInCmdBuffer(my_data, pCB, cmd);
Tobin Ehlis9a874302016-01-20 10:25:29 -07002710 CMD_NODE cmdNode = {};
2711 // init cmd node and append to end of cmd LL
2712 cmdNode.cmdNumber = ++pCB->numCmds;
2713 cmdNode.type = cmd;
2714 pCB->cmds.push_back(cmdNode);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002715 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002716 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002717}
Tobin Ehlisef694652016-01-19 12:03:34 -07002718// Reset the command buffer state
2719// Maintain the createInfo and set state to CB_NEW, but clear all other state
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002720static void resetCB(layer_data* my_data, const VkCommandBuffer cb)
2721{
2722 GLOBAL_CB_NODE* pCB = my_data->commandBufferMap[cb];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002723 if (pCB) {
Tobin Ehlis9a874302016-01-20 10:25:29 -07002724 pCB->cmds.clear();
Tobin Ehlisef694652016-01-19 12:03:34 -07002725 // Reset CB state (note that createInfo is not cleared)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002726 pCB->commandBuffer = cb;
Michael Lentineabc5e922015-10-12 11:30:14 -05002727 memset(&pCB->beginInfo, 0, sizeof(VkCommandBufferBeginInfo));
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002728 memset(&pCB->inheritanceInfo, 0, sizeof(VkCommandBufferInheritanceInfo));
Michael Lentineabc5e922015-10-12 11:30:14 -05002729 pCB->fence = 0;
2730 pCB->numCmds = 0;
2731 memset(pCB->drawCount, 0, NUM_DRAW_TYPES * sizeof(uint64_t));
2732 pCB->state = CB_NEW;
2733 pCB->submitCount = 0;
2734 pCB->status = 0;
Michael Lentineabc5e922015-10-12 11:30:14 -05002735 pCB->lastBoundPipeline = 0;
Chris Forbes82c123c2016-02-02 15:45:40 +13002736 pCB->lastVtxBinding = 0;
2737 pCB->boundVtxBuffers.clear();
Michael Lentineabc5e922015-10-12 11:30:14 -05002738 pCB->viewports.clear();
2739 pCB->scissors.clear();
2740 pCB->lineWidth = 0;
2741 pCB->depthBiasConstantFactor = 0;
2742 pCB->depthBiasClamp = 0;
2743 pCB->depthBiasSlopeFactor = 0;
2744 memset(pCB->blendConstants, 0, 4 * sizeof(float));
2745 pCB->minDepthBounds = 0;
2746 pCB->maxDepthBounds = 0;
2747 memset(&pCB->front, 0, sizeof(stencil_data));
2748 memset(&pCB->back, 0, sizeof(stencil_data));
2749 pCB->lastBoundDescriptorSet = 0;
2750 pCB->lastBoundPipelineLayout = 0;
Chris Forbes82c123c2016-02-02 15:45:40 +13002751 memset(&pCB->activeRenderPassBeginInfo, 0, sizeof(pCB->activeRenderPassBeginInfo));
Michael Lentineabc5e922015-10-12 11:30:14 -05002752 pCB->activeRenderPass = 0;
Chris Forbes82c123c2016-02-02 15:45:40 +13002753 pCB->activeSubpassContents = VK_SUBPASS_CONTENTS_INLINE;
Michael Lentineabc5e922015-10-12 11:30:14 -05002754 pCB->activeSubpass = 0;
Chris Forbes82c123c2016-02-02 15:45:40 +13002755 pCB->framebuffer = 0;
Tobin Ehlise6e574b2016-01-24 23:25:31 -07002756 // Before clearing uniqueBoundSets, remove this CB off of its boundCBs
2757 for (auto set : pCB->uniqueBoundSets) {
2758 auto set_node = my_data->setMap.find(set);
2759 if (set_node != my_data->setMap.end()) {
2760 set_node->second->boundCmdBuffers.erase(pCB->commandBuffer);
2761 }
2762 }
2763 pCB->uniqueBoundSets.clear();
Chris Forbes82c123c2016-02-02 15:45:40 +13002764 pCB->destroyedSets.clear();
2765 pCB->updatedSets.clear();
Michael Lentineabc5e922015-10-12 11:30:14 -05002766 pCB->boundDescriptorSets.clear();
Michael Lentineb887b0a2015-12-29 14:12:11 -06002767 pCB->waitedEvents.clear();
2768 pCB->waitedEventsBeforeQueryReset.clear();
2769 pCB->queryToStateMap.clear();
Michael Lentinedc6f8de2016-02-02 18:29:30 -06002770 pCB->activeQueries.clear();
Chris Forbes82c123c2016-02-02 15:45:40 +13002771 pCB->imageLayoutMap.clear();
2772 pCB->drawData.clear();
2773 pCB->currentDrawData.buffers.clear();
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07002774 pCB->secondaryCommandBuffers.clear();
Chris Forbes82c123c2016-02-02 15:45:40 +13002775 pCB->dynamicOffsets.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002776 }
2777}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002778
Tobin Ehlis963a4042015-09-29 08:18:34 -06002779// Set PSO-related status bits for CB, including dynamic state set via PSO
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002780static void set_cb_pso_status(GLOBAL_CB_NODE* pCB, const PIPELINE_NODE* pPipe)
2781{
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002782 for (uint32_t i = 0; i < pPipe->cbStateCI.attachmentCount; i++) {
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002783 if (0 != pPipe->pAttachments[i].colorWriteMask) {
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002784 pCB->status |= CBSTATUS_COLOR_BLEND_WRITE_ENABLE;
2785 }
2786 }
2787 if (pPipe->dsStateCI.depthWriteEnable) {
Cody Northrop82485a82015-08-18 15:21:16 -06002788 pCB->status |= CBSTATUS_DEPTH_WRITE_ENABLE;
2789 }
Cody Northrop82485a82015-08-18 15:21:16 -06002790 if (pPipe->dsStateCI.stencilTestEnable) {
2791 pCB->status |= CBSTATUS_STENCIL_TEST_ENABLE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002792 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06002793 // Account for any dynamic state not set via this PSO
2794 if (!pPipe->dynStateCI.dynamicStateCount) { // All state is static
2795 pCB->status = CBSTATUS_ALL;
2796 } else {
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002797 // First consider all state on
2798 // Then unset any state that's noted as dynamic in PSO
2799 // Finally OR that into CB statemask
2800 CBStatusFlags psoDynStateMask = CBSTATUS_ALL;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002801 for (uint32_t i=0; i < pPipe->dynStateCI.dynamicStateCount; i++) {
Tobin Ehlis963a4042015-09-29 08:18:34 -06002802 switch (pPipe->dynStateCI.pDynamicStates[i]) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002803 case VK_DYNAMIC_STATE_VIEWPORT:
2804 psoDynStateMask &= ~CBSTATUS_VIEWPORT_SET;
2805 break;
2806 case VK_DYNAMIC_STATE_SCISSOR:
2807 psoDynStateMask &= ~CBSTATUS_SCISSOR_SET;
2808 break;
2809 case VK_DYNAMIC_STATE_LINE_WIDTH:
2810 psoDynStateMask &= ~CBSTATUS_LINE_WIDTH_SET;
2811 break;
2812 case VK_DYNAMIC_STATE_DEPTH_BIAS:
2813 psoDynStateMask &= ~CBSTATUS_DEPTH_BIAS_SET;
2814 break;
2815 case VK_DYNAMIC_STATE_BLEND_CONSTANTS:
2816 psoDynStateMask &= ~CBSTATUS_BLEND_SET;
2817 break;
2818 case VK_DYNAMIC_STATE_DEPTH_BOUNDS:
2819 psoDynStateMask &= ~CBSTATUS_DEPTH_BOUNDS_SET;
2820 break;
2821 case VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK:
2822 psoDynStateMask &= ~CBSTATUS_STENCIL_READ_MASK_SET;
2823 break;
2824 case VK_DYNAMIC_STATE_STENCIL_WRITE_MASK:
2825 psoDynStateMask &= ~CBSTATUS_STENCIL_WRITE_MASK_SET;
2826 break;
2827 case VK_DYNAMIC_STATE_STENCIL_REFERENCE:
2828 psoDynStateMask &= ~CBSTATUS_STENCIL_REFERENCE_SET;
2829 break;
2830 default:
2831 // TODO : Flag error here
2832 break;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002833 }
2834 }
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002835 pCB->status |= psoDynStateMask;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002836 }
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002837}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002838
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002839// Print the last bound Gfx Pipeline
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002840static VkBool32 printPipeline(layer_data* my_data, const VkCommandBuffer cb)
2841{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002842 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002843 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002844 if (pCB) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002845 PIPELINE_NODE *pPipeTrav = getPipeline(my_data, pCB->lastBoundPipeline);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002846 if (!pPipeTrav) {
2847 // nothing to print
Tobin Ehlisce132d82015-06-19 15:07:05 -06002848 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002849 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
2850 "%s", vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002851 }
2852 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002853 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002854}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002855
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002856// Print details of DS config to stdout
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002857static VkBool32 printDSConfig(layer_data* my_data, const VkCommandBuffer cb)
2858{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002859 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002860 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.
2861 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis93f89e82015-06-09 08:39:32 -06002862 if (pCB && pCB->lastBoundDescriptorSet) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002863 SET_NODE* pSet = getSetNode(my_data, pCB->lastBoundDescriptorSet);
2864 DESCRIPTOR_POOL_NODE* pPool = getPoolNode(my_data, pSet->pool);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002865 // Print out pool details
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002866 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
2867 "Details for pool %#" PRIxLEAST64 ".", (uint64_t) pPool->pool);
2868 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
2869 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
2870 "%s", poolStr.c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002871 // Print out set details
2872 char prefix[10];
2873 uint32_t index = 0;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002874 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
2875 "Details for descriptor set %#" PRIxLEAST64 ".", (uint64_t) pSet->set);
2876 LAYOUT_NODE* pLayout = pSet->pLayout;
Tobin Ehlis793ad302015-04-03 12:01:11 -06002877 // Print layout details
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002878 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
2879 "Layout #%u, (object %#" PRIxLEAST64 ") for DS %#" PRIxLEAST64 ".", index+1, (uint64_t)(pLayout->layout), (uint64_t)(pSet->set));
Tobin Ehlis793ad302015-04-03 12:01:11 -06002880 sprintf(prefix, " [L%u] ", index);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002881 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
2882 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
2883 "%s", DSLstr.c_str());
Tobin Ehlis793ad302015-04-03 12:01:11 -06002884 index++;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002885 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002886 if (pUpdate) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002887 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
2888 "Update Chain [UC] for descriptor set %#" PRIxLEAST64 ":", (uint64_t) pSet->set);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002889 sprintf(prefix, " [UC] ");
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002890 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
2891 "%s", dynamic_display(pUpdate, prefix).c_str());
2892 // TODO : If there is a "view" associated with this update, print CI for that view
Tobin Ehlisce132d82015-06-19 15:07:05 -06002893 } else {
Tobin Ehlisbf081f32015-06-15 08:41:17 -06002894 if (0 != pSet->descriptorCount) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002895 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
2896 "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 -06002897 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002898 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
2899 "FYI: No descriptors in descriptor set %#" PRIxLEAST64 ".", (uint64_t) pSet->set);
Tobin Ehlisbf081f32015-06-15 08:41:17 -06002900 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002901 }
2902 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002903 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002904}
2905
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002906static void printCB(layer_data* my_data, const VkCommandBuffer cb)
2907{
2908 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis9a874302016-01-20 10:25:29 -07002909 if (pCB && pCB->cmds.size() > 0) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002910 log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
2911 "Cmds in CB %p", (void*)cb);
Tobin Ehlis9a874302016-01-20 10:25:29 -07002912 vector<CMD_NODE> cmds = pCB->cmds;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002913 for (auto ii=cmds.begin(); ii!=cmds.end(); ++ii) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002914 // TODO : Need to pass cb as srcObj here
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002915 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",
2916 " CMD#%" PRIu64 ": %s", (*ii).cmdNumber, cmdTypeToString((*ii).type).c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002917 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002918 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002919 // Nothing to print
2920 }
2921}
2922
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002923static VkBool32 synchAndPrintDSConfig(layer_data* my_data, const VkCommandBuffer cb)
2924{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002925 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002926 if (!(my_data->report_data->active_flags & VK_DEBUG_REPORT_INFO_BIT_EXT)) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002927 return skipCall;
Mike Stroyanba35e352015-08-12 17:11:28 -06002928 }
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002929 skipCall |= printDSConfig(my_data, cb);
2930 skipCall |= printPipeline(my_data, cb);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002931 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002932}
2933
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002934// Flags validation error if the associated call is made inside a render pass. The apiName
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002935// routine should ONLY be called outside a render pass.
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002936static VkBool32 insideRenderPass(const layer_data* my_data, GLOBAL_CB_NODE *pCB, const char *apiName)
2937{
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002938 VkBool32 inside = VK_FALSE;
2939 if (pCB->activeRenderPass) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002940 inside = log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2941 (uint64_t)pCB->commandBuffer, __LINE__, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2942 "%s: It is invalid to issue this call inside an active render pass (%#" PRIxLEAST64 ")",
2943 apiName, (uint64_t) pCB->activeRenderPass);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002944 }
2945 return inside;
2946}
2947
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002948// Flags validation error if the associated call is made outside a render pass. The apiName
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002949// routine should ONLY be called inside a render pass.
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002950static VkBool32 outsideRenderPass(const layer_data* my_data, GLOBAL_CB_NODE *pCB, const char *apiName)
2951{
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002952 VkBool32 outside = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002953 if (((pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) &&
2954 (!pCB->activeRenderPass)) ||
Mark Lobodzinski74635932015-12-18 15:35:38 -07002955 ((pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) &&
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002956 (!pCB->activeRenderPass) &&
2957 !(pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT))) {
2958 outside = log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2959 (uint64_t)pCB->commandBuffer, __LINE__, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2960 "%s: This call must be issued inside an active render pass.", apiName);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002961 }
2962 return outside;
2963}
2964
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002965static void init_draw_state(layer_data *my_data, const VkAllocationCallbacks *pAllocator)
2966{
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002967 uint32_t report_flags = 0;
2968 uint32_t debug_action = 0;
2969 FILE *log_output = NULL;
2970 const char *option_str;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002971 VkDebugReportCallbackEXT callback;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002972 // initialize DrawState options
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002973 report_flags = getLayerOptionFlags("DrawStateReportFlags", 0);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002974 getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &debug_action);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002975
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002976 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
2977 {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002978 option_str = getLayerOption("DrawStateLogFilename");
Tobin Ehlisb1df55e2015-09-15 09:55:54 -06002979 log_output = getLayerLogOutput(option_str, "DrawState");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002980 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002981 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002982 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002983 dbgInfo.pfnCallback = log_callback;
2984 dbgInfo.pUserData = log_output;
2985 dbgInfo.flags = report_flags;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002986 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002987 my_data->logging_callback.push_back(callback);
2988 }
2989
2990 if (debug_action & VK_DBG_LAYER_ACTION_DEBUG_OUTPUT) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002991 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002992 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002993 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002994 dbgInfo.pfnCallback = win32_debug_output_msg;
2995 dbgInfo.pUserData = log_output;
2996 dbgInfo.flags = report_flags;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07002997 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002998 my_data->logging_callback.push_back(callback);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002999 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003000
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003001 if (!globalLockInitialized)
3002 {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003003 loader_platform_thread_create_mutex(&globalLock);
3004 globalLockInitialized = 1;
3005 }
3006}
3007
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003008VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance)
3009{
3010 VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06003011
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07003012 assert(chain_info->u.pLayerInfo);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003013 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
3014 PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance) fpGetInstanceProcAddr(NULL, "vkCreateInstance");
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07003015 if (fpCreateInstance == NULL) {
3016 return VK_ERROR_INITIALIZATION_FAILED;
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06003017 }
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07003018
3019 // Advance the link info for the next element on the chain
3020 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
3021
3022 VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
3023 if (result != VK_SUCCESS)
3024 return result;
3025
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003026 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07003027 my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003028 layer_init_instance_dispatch_table(*pInstance, my_data->instance_dispatch_table, fpGetInstanceProcAddr);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07003029
3030 my_data->report_data = debug_report_create_instance(
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003031 my_data->instance_dispatch_table,
3032 *pInstance,
3033 pCreateInfo->enabledExtensionCount,
3034 pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07003035
3036 init_draw_state(my_data, pAllocator);
3037
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06003038 return result;
3039}
3040
Jon Ashburn3950e1b2015-05-20 09:00:28 -06003041/* hook DestroyInstance to remove tableInstanceMap entry */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003042VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator)
3043{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003044 // TODOSC : Shouldn't need any customization here
Tobin Ehlisa16e8922015-06-16 15:50:44 -06003045 dispatch_key key = get_dispatch_key(instance);
Tobin Ehlis0b632332015-10-07 09:38:40 -06003046 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
3047 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003048 pTable->DestroyInstance(instance, pAllocator);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06003049
3050 // Clean up logging callback, if any
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06003051 while (my_data->logging_callback.size() > 0) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003052 VkDebugReportCallbackEXT callback = my_data->logging_callback.back();
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07003053 layer_destroy_msg_callback(my_data->report_data, callback, pAllocator);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06003054 my_data->logging_callback.pop_back();
Tobin Ehlisa16e8922015-06-16 15:50:44 -06003055 }
3056
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06003057 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlis0b632332015-10-07 09:38:40 -06003058 delete my_data->instance_dispatch_table;
3059 layer_data_map.erase(key);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003060 // TODO : Potential race here with separate threads creating/destroying instance
Tobin Ehlis0b632332015-10-07 09:38:40 -06003061 if (layer_data_map.empty()) {
Mike Stroyanfcb4ba62015-08-18 15:56:18 -06003062 // Release mutex when destroying last instance.
3063 loader_platform_thread_delete_mutex(&globalLock);
3064 globalLockInitialized = 0;
3065 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06003066}
3067
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003068static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
3069{
Tony Barbour3b4732f2015-07-13 13:37:24 -06003070 uint32_t i;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003071 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlis0b632332015-10-07 09:38:40 -06003072 dev_data->device_extensions.debug_marker_enabled = false;
Michael Lentineabc5e922015-10-12 11:30:14 -05003073 dev_data->device_extensions.wsi_enabled = false;
3074
3075
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003076 VkLayerDispatchTable *pDisp = dev_data->device_dispatch_table;
3077 PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr;
3078
3079 pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR) gpa(device, "vkCreateSwapchainKHR");
3080 pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR) gpa(device, "vkDestroySwapchainKHR");
3081 pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR) gpa(device, "vkGetSwapchainImagesKHR");
3082 pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR) gpa(device, "vkAcquireNextImageKHR");
3083 pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR) gpa(device, "vkQueuePresentKHR");
Jon Ashburne68a9ff2015-05-25 14:11:37 -06003084
Jon Ashburnf19916e2016-01-11 13:12:43 -07003085 for (i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003086 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) {
Michael Lentineabc5e922015-10-12 11:30:14 -05003087 dev_data->device_extensions.wsi_enabled = true;
3088 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003089 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
3090 /* Found a matching extension name, mark it enabled and init dispatch table*/
Tobin Ehlis0b632332015-10-07 09:38:40 -06003091 dev_data->device_extensions.debug_marker_enabled = true;
Jon Ashburn1d4b1282015-12-10 19:12:21 -07003092 initDebugMarkerTable(device);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003093
Jon Ashburne68a9ff2015-05-25 14:11:37 -06003094 }
Jon Ashburne68a9ff2015-05-25 14:11:37 -06003095 }
3096}
3097
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003098VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDevice* pDevice)
3099{
3100 VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
Mark Lobodzinski941aea92016-01-13 10:23:15 -07003101
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07003102 assert(chain_info->u.pLayerInfo);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003103 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
3104 PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr;
3105 PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice) fpGetInstanceProcAddr(NULL, "vkCreateDevice");
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07003106 if (fpCreateDevice == NULL) {
3107 return VK_ERROR_INITIALIZATION_FAILED;
Tobin Ehlisa16e8922015-06-16 15:50:44 -06003108 }
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07003109
3110 // Advance the link info for the next element on the chain
3111 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
3112
3113 VkResult result = fpCreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
3114 if (result != VK_SUCCESS) {
3115 return result;
3116 }
3117
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003118 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
3119 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07003120
3121 // Setup device dispatch table
3122 my_device_data->device_dispatch_table = new VkLayerDispatchTable;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003123 layer_init_device_dispatch_table(*pDevice, my_device_data->device_dispatch_table, fpGetDeviceProcAddr);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07003124
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003125 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07003126 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
3127 // Get physical device limits for this device
Michael Lentine26870f32016-01-26 21:36:08 -06003128 my_instance_data->instance_dispatch_table->GetPhysicalDeviceProperties(gpu, &(my_device_data->physDevProperties.properties));
Michael Lentine7d26c572016-01-28 11:55:28 -06003129 my_instance_data->instance_dispatch_table->GetPhysicalDeviceFeatures(gpu, &(my_device_data->physDevProperties.features));
Michael Lentine26870f32016-01-26 21:36:08 -06003130 uint32_t count;
3131 my_instance_data->instance_dispatch_table->GetPhysicalDeviceQueueFamilyProperties(gpu, &count, nullptr);
3132 my_device_data->physDevProperties.queue_family_properties.resize(count);
3133 my_instance_data->instance_dispatch_table->GetPhysicalDeviceQueueFamilyProperties(gpu, &count, &my_device_data->physDevProperties.queue_family_properties[0]);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003134 return result;
3135}
Tobin Ehlis559c6382015-11-05 09:52:49 -07003136
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06003137// prototype
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003138static void deleteRenderPasses(layer_data*);
3139VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator)
3140{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003141 // TODOSC : Shouldn't need any customization here
Jeremy Hayes5d29ce32015-06-19 11:37:38 -06003142 dispatch_key key = get_dispatch_key(device);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003143 layer_data* dev_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06003144 // Free all the memory
3145 loader_platform_thread_lock_mutex(&globalLock);
3146 deletePipelines(dev_data);
3147 deleteRenderPasses(dev_data);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003148 deleteCommandBuffers(dev_data);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06003149 deletePools(dev_data);
3150 deleteLayouts(dev_data);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003151 dev_data->imageViewMap.clear();
3152 dev_data->imageMap.clear();
3153 dev_data->bufferViewMap.clear();
3154 dev_data->bufferMap.clear();
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06003155 loader_platform_thread_unlock_mutex(&globalLock);
3156
Chia-I Wuf7458c52015-10-26 21:10:41 +08003157 dev_data->device_dispatch_table->DestroyDevice(device, pAllocator);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06003158 tableDebugMarkerMap.erase(key);
Tobin Ehlis0b632332015-10-07 09:38:40 -06003159 delete dev_data->device_dispatch_table;
3160 layer_data_map.erase(key);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003161}
3162
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07003163static const VkExtensionProperties instance_extensions[] = {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003164 {
3165 VK_EXT_DEBUG_REPORT_EXTENSION_NAME,
3166 VK_EXT_DEBUG_REPORT_SPEC_VERSION
3167 }
3168};
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06003169
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003170VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(
3171 const char *pLayerName,
3172 uint32_t *pCount,
3173 VkExtensionProperties* pProperties)
3174{
3175 return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003176}
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06003177
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003178static const VkLayerProperties ds_global_layers[] = {
3179 {
3180 "VK_LAYER_LUNARG_draw_state",
3181 VK_API_VERSION,
3182 VK_MAKE_VERSION(0, 1, 0),
3183 "Validation layer: draw_state",
3184 }
3185};
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07003186
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003187VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(
3188 uint32_t *pCount,
3189 VkLayerProperties* pProperties)
3190{
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003191 return util_GetLayerProperties(ARRAY_SIZE(ds_global_layers),
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003192 ds_global_layers,
3193 pCount, pProperties);
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003194}
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06003195
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003196static const VkExtensionProperties ds_device_extensions[] = {
3197 {
3198 DEBUG_MARKER_EXTENSION_NAME,
3199 VK_MAKE_VERSION(0, 1, 0),
3200 }
3201};
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003202
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003203static const VkLayerProperties ds_device_layers[] = {
3204 {
3205 "VK_LAYER_LUNARG_draw_state",
3206 VK_API_VERSION,
3207 VK_MAKE_VERSION(0, 1, 0),
3208 "Validation layer: draw_state",
3209 }
3210};
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003211
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003212VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(
3213 VkPhysicalDevice physicalDevice,
3214 const char* pLayerName,
3215 uint32_t* pCount,
3216 VkExtensionProperties* pProperties)
3217{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003218 // DrawState does not have any physical device extensions
Jon Ashburn751c4842015-11-02 17:37:20 -07003219 if (pLayerName == NULL) {
3220 dispatch_key key = get_dispatch_key(physicalDevice);
3221 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003222 return my_data->instance_dispatch_table->EnumerateDeviceExtensionProperties(
3223 physicalDevice,
3224 NULL,
3225 pCount,
3226 pProperties);
Jon Ashburn751c4842015-11-02 17:37:20 -07003227 } else {
3228 return util_GetExtensionProperties(ARRAY_SIZE(ds_device_extensions),
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003229 ds_device_extensions,
3230 pCount, pProperties);
Jon Ashburn751c4842015-11-02 17:37:20 -07003231 }
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003232}
3233
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003234VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(
3235 VkPhysicalDevice physicalDevice,
3236 uint32_t* pCount,
3237 VkLayerProperties* pProperties)
3238{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003239 /* DrawState physical device layers are the same as global */
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003240 return util_GetLayerProperties(ARRAY_SIZE(ds_device_layers), ds_device_layers,
3241 pCount, pProperties);
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06003242}
3243
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07003244VkBool32 ValidateCmdBufImageLayouts(VkCommandBuffer cmdBuffer) {
Mark Youngb20a6a82016-01-07 15:41:43 -07003245 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003246 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
3247 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Michael Lentineabc5e922015-10-12 11:30:14 -05003248 for (auto cb_image_data : pCB->imageLayoutMap) {
3249 auto image_data = dev_data->imageLayoutMap.find(cb_image_data.first);
3250 if (image_data == dev_data->imageLayoutMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003251 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",
3252 "Cannot submit cmd buffer using deleted image %" PRIu64 ".", (uint64_t)(cb_image_data.first));
Michael Lentineabc5e922015-10-12 11:30:14 -05003253 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003254 if (dev_data->imageLayoutMap[cb_image_data.first]->layout != cb_image_data.second.initialLayout) {
3255 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",
3256 "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 -05003257 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003258 dev_data->imageLayoutMap[cb_image_data.first]->layout = cb_image_data.second.layout;
Michael Lentineabc5e922015-10-12 11:30:14 -05003259 }
3260 }
3261 return skip_call;
3262}
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003263// Track which resources are in-flight by atomically incrementing their "in_use" count
3264VkBool32 validateAndIncrementResources(layer_data* my_data, GLOBAL_CB_NODE* pCB) {
Mark Youngb20a6a82016-01-07 15:41:43 -07003265 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003266 for (auto drawDataElement : pCB->drawData) {
3267 for (auto buffer : drawDataElement.buffers) {
3268 auto buffer_data = my_data->bufferMap.find(buffer);
3269 if (buffer_data == my_data->bufferMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003270 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",
3271 "Cannot submit cmd buffer using deleted buffer %" PRIu64 ".", (uint64_t)(buffer));
Michael Lentine700b0aa2015-10-30 17:57:32 -07003272 } else {
3273 buffer_data->second.in_use.fetch_add(1);
3274 }
3275 }
3276 }
Tobin Ehlise6e574b2016-01-24 23:25:31 -07003277 for (auto set : pCB->uniqueBoundSets) {
3278 auto setNode = my_data->setMap.find(set);
3279 if (setNode == my_data->setMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003280 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",
3281 "Cannot submit cmd buffer using deleted descriptor set %" PRIu64 ".", (uint64_t)(set));
Tobin Ehlise6e574b2016-01-24 23:25:31 -07003282 } else {
3283 setNode->second->in_use.fetch_add(1);
3284 }
3285 }
Michael Lentine2e068b22015-12-29 16:05:27 -06003286 return skip_call;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003287}
3288
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003289void decrementResources(layer_data* my_data, VkCommandBuffer cmdBuffer) {
3290 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cmdBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07003291 for (auto drawDataElement : pCB->drawData) {
3292 for (auto buffer : drawDataElement.buffers) {
3293 auto buffer_data = my_data->bufferMap.find(buffer);
3294 if (buffer_data != my_data->bufferMap.end()) {
3295 buffer_data->second.in_use.fetch_sub(1);
3296 }
3297 }
3298 }
Tobin Ehlise6e574b2016-01-24 23:25:31 -07003299 for (auto set : pCB->uniqueBoundSets) {
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07003300 auto setNode = my_data->setMap.find(set);
3301 if (setNode != my_data->setMap.end()) {
3302 setNode->second->in_use.fetch_sub(1);
3303 }
3304 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003305 for (auto queryStatePair : pCB->queryToStateMap) {
3306 my_data->queryToStateMap[queryStatePair.first] = queryStatePair.second;
3307 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003308}
3309
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003310void decrementResources(layer_data* my_data, uint32_t fenceCount, const VkFence* pFences) {
Michael Lentine700b0aa2015-10-30 17:57:32 -07003311 for (uint32_t i = 0; i < fenceCount; ++i) {
3312 auto fence_data = my_data->fenceMap.find(pFences[i]);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003313 if (fence_data == my_data->fenceMap.end() || !fence_data->second.needsSignaled) return;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003314 fence_data->second.needsSignaled = false;
Michael Lentine37767342016-02-02 22:24:26 -06003315 fence_data->second.in_use.fetch_sub(1);
Michael Lentine700b0aa2015-10-30 17:57:32 -07003316 if (fence_data->second.priorFence != VK_NULL_HANDLE) {
3317 decrementResources(my_data, 1, &fence_data->second.priorFence);
3318 }
3319 for (auto cmdBuffer : fence_data->second.cmdBuffers) {
3320 decrementResources(my_data, cmdBuffer);
3321 }
3322 }
3323}
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07003324
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003325void decrementResources(layer_data* my_data, VkQueue queue) {
Michael Lentine700b0aa2015-10-30 17:57:32 -07003326 auto queue_data = my_data->queueMap.find(queue);
3327 if (queue_data != my_data->queueMap.end()) {
3328 for (auto cmdBuffer : queue_data->second.untrackedCmdBuffers) {
3329 decrementResources(my_data, cmdBuffer);
3330 }
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07003331 queue_data->second.untrackedCmdBuffers.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07003332 decrementResources(my_data, 1, &queue_data->second.priorFence);
3333 }
3334}
3335
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003336void trackCommandBuffers(layer_data* my_data, VkQueue queue, uint32_t cmdBufferCount, const VkCommandBuffer* pCmdBuffers, VkFence fence) {
Michael Lentine700b0aa2015-10-30 17:57:32 -07003337 auto queue_data = my_data->queueMap.find(queue);
3338 if (fence != VK_NULL_HANDLE) {
3339 VkFence priorFence = VK_NULL_HANDLE;
Michael Lentine37767342016-02-02 22:24:26 -06003340 auto fence_data = my_data->fenceMap.find(fence);
3341 if (fence_data == my_data->fenceMap.end()) {
3342 return;
3343 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003344 if (queue_data != my_data->queueMap.end()) {
3345 priorFence = queue_data->second.priorFence;
3346 queue_data->second.priorFence = fence;
3347 for (auto cmdBuffer : queue_data->second.untrackedCmdBuffers) {
Michael Lentine37767342016-02-02 22:24:26 -06003348 fence_data->second.cmdBuffers.push_back(cmdBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07003349 }
3350 queue_data->second.untrackedCmdBuffers.clear();
3351 }
Michael Lentine37767342016-02-02 22:24:26 -06003352 fence_data->second.cmdBuffers.clear();
3353 fence_data->second.priorFence = priorFence;
3354 fence_data->second.needsSignaled = true;
3355 fence_data->second.queue = queue;
3356 fence_data->second.in_use.fetch_add(1);
Michael Lentine700b0aa2015-10-30 17:57:32 -07003357 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
Michael Lentine37767342016-02-02 22:24:26 -06003358 for (auto secondaryCmdBuffer :
3359 my_data->commandBufferMap[pCmdBuffers[i]]
3360 ->secondaryCommandBuffers) {
3361 fence_data->second.cmdBuffers.push_back(
3362 secondaryCmdBuffer);
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003363 }
Michael Lentine37767342016-02-02 22:24:26 -06003364 fence_data->second.cmdBuffers.push_back(pCmdBuffers[i]);
Michael Lentine700b0aa2015-10-30 17:57:32 -07003365 }
3366 } else {
3367 if (queue_data != my_data->queueMap.end()) {
3368 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003369 for (auto secondaryCmdBuffer : my_data->commandBufferMap[pCmdBuffers[i]]->secondaryCommandBuffers) {
3370 queue_data->second.untrackedCmdBuffers.push_back(secondaryCmdBuffer);
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003371 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003372 queue_data->second.untrackedCmdBuffers.push_back(pCmdBuffers[i]);
Michael Lentine700b0aa2015-10-30 17:57:32 -07003373 }
3374 }
3375 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003376 if (queue_data != my_data->queueMap.end()) {
3377 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003378 // Add cmdBuffers to both the global set and queue set
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003379 for (auto secondaryCmdBuffer : my_data->commandBufferMap[pCmdBuffers[i]]->secondaryCommandBuffers) {
Tobin Ehlis74714d22016-01-25 15:24:34 -08003380 my_data->globalInFlightCmdBuffers.insert(secondaryCmdBuffer);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003381 queue_data->second.inFlightCmdBuffers.insert(secondaryCmdBuffer);
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003382 }
Tobin Ehlis74714d22016-01-25 15:24:34 -08003383 my_data->globalInFlightCmdBuffers.insert(pCmdBuffers[i]);
3384 queue_data->second.inFlightCmdBuffers.insert(pCmdBuffers[i]);
3385 }
3386 }
3387}
3388
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003389static VkBool32 validateCommandBufferState(layer_data* dev_data, GLOBAL_CB_NODE* pCB)
3390{
Tobin Ehlis74714d22016-01-25 15:24:34 -08003391 // Track in-use for resources off of primary and any secondary CBs
3392 VkBool32 skipCall = validateAndIncrementResources(dev_data, pCB);
3393 if (!pCB->secondaryCommandBuffers.empty()) {
3394 for (auto secondaryCmdBuffer : pCB->secondaryCommandBuffers) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003395 skipCall |= validateAndIncrementResources(dev_data, dev_data->commandBufferMap[secondaryCmdBuffer]);
Tobin Ehlis74714d22016-01-25 15:24:34 -08003396 }
3397 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003398 if ((pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT) && (pCB->submitCount > 1)) {
3399 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_COMMAND_BUFFER_SINGLE_SUBMIT_VIOLATION, "DS",
3400 "CB %#" PRIxLEAST64 " was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted %#" PRIxLEAST64 " times.",
3401 (uint64_t)(pCB->commandBuffer), pCB->submitCount);
Tobin Ehlis74714d22016-01-25 15:24:34 -08003402 }
3403 // Validate that cmd buffers have been updated
3404 if (CB_RECORDED != pCB->state) {
3405 if (CB_INVALID == pCB->state) {
3406 // Inform app of reason CB invalid
3407 if (!pCB->destroyedSets.empty()) {
3408 std::stringstream set_string;
3409 for (auto set : pCB->destroyedSets) {
3410 set_string << " " << set;
3411 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003412 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",
3413 "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 -08003414 }
3415 if (!pCB->updatedSets.empty()) {
3416 std::stringstream set_string;
3417 for (auto set : pCB->updatedSets) {
3418 set_string << " " << set;
3419 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003420 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",
3421 "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 -08003422 }
3423 } else { // Flag error for using CB w/o vkEndCommandBuffer() called
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003424 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",
3425 "You must call vkEndCommandBuffer() on CB %#" PRIxLEAST64 " before this call to vkQueueSubmit()!", (uint64_t)(pCB->commandBuffer));
Tobin Ehlis74714d22016-01-25 15:24:34 -08003426 }
3427 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003428 // If USAGE_SIMULTANEOUS_USE_BIT not set then CB cannot already be executing on device
3429 if (!(pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT)) {
3430 if (dev_data->globalInFlightCmdBuffers.find(pCB->commandBuffer) != dev_data->globalInFlightCmdBuffers.end()) {
3431 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)(pCB->commandBuffer), __LINE__, DRAWSTATE_INVALID_CB_SIMULTANEOUS_USE, "DS",
3432 "Attempt to simultaneously execute CB %#" PRIxLEAST64 " w/o VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!", (uint64_t)(pCB->commandBuffer));
Michael Lentineb887b0a2015-12-29 14:12:11 -06003433 }
3434 }
Tobin Ehlisceb0b862016-02-01 06:50:57 -08003435 return skipCall;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003436}
3437
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003438VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence fence)
3439{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003440 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003441 GLOBAL_CB_NODE* pCB = NULL;
3442 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003443 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08003444 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003445 for (uint32_t i=0; i < submit->waitSemaphoreCount; ++i) {
Michael Lentine15a47882016-01-06 10:05:48 -06003446 if (dev_data->semaphoreSignaledMap[submit->pWaitSemaphores[i]]) {
3447 dev_data->semaphoreSignaledMap[submit->pWaitSemaphores[i]] = 0;
3448 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003449 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",
3450 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
3451 (uint64_t)(queue), (uint64_t)(submit->pWaitSemaphores[i]));
Michael Lentine15a47882016-01-06 10:05:48 -06003452 }
3453 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003454 for (uint32_t i=0; i < submit->signalSemaphoreCount; ++i) {
Michael Lentine15a47882016-01-06 10:05:48 -06003455 dev_data->semaphoreSignaledMap[submit->pSignalSemaphores[i]] = 1;
3456 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003457 for (uint32_t i=0; i < submit->commandBufferCount; i++) {
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07003458
3459#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003460 skipCall |= ValidateCmdBufImageLayouts(submit->pCommandBuffers[i]);
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07003461#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
3462
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003463 pCB = getCBNode(dev_data, submit->pCommandBuffers[i]);
3464 loader_platform_thread_lock_mutex(&globalLock);
3465 pCB->submitCount++; // increment submit count
Tobin Ehlise6e574b2016-01-24 23:25:31 -07003466 skipCall |= validateCommandBufferState(dev_data, pCB);
Tobin Ehlisc4bdde12015-05-27 14:30:06 -06003467 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06003468 }
Michael Lentine37767342016-02-02 22:24:26 -06003469 if (dev_data->fenceMap[fence].in_use.load()) {
3470 skipCall |= log_msg(
3471 dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
3472 VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT,
3473 reinterpret_cast<uint64_t>(fence), __LINE__,
3474 DRAWSTATE_INVALID_FENCE, "DS",
3475 "Fence %#" PRIx64 " is already in use by another submission.",
3476 reinterpret_cast<uint64_t>(fence));
3477 }
3478 trackCommandBuffers(dev_data, queue, submit->commandBufferCount,
3479 submit->pCommandBuffers, fence);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003480 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003481 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003482 return dev_data->device_dispatch_table->QueueSubmit(queue, submitCount, pSubmits, fence);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003483 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003484}
3485
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003486VkBool32 cleanInFlightCmdBuffer(layer_data* my_data, VkCommandBuffer cmdBuffer) {
Mark Youngb20a6a82016-01-07 15:41:43 -07003487 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003488 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cmdBuffer);
Mark Lobodzinskia9e7c042016-01-25 14:27:49 -07003489 if (pCB) {
3490 for (auto queryEventsPair : pCB->waitedEventsBeforeQueryReset) {
3491 for (auto event : queryEventsPair.second) {
3492 if (my_data->eventMap[event].needsSignaled) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003493 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",
3494 "Cannot get query results on queryPool %" PRIu64 " with index %d which was guarded by unsignaled event %" PRIu64 ".",
3495 (uint64_t)(queryEventsPair.first.pool), queryEventsPair.first.index, (uint64_t)(event));
Mark Lobodzinskia9e7c042016-01-25 14:27:49 -07003496 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003497 }
3498 }
3499 }
3500 return skip_call;
3501}
Tobin Ehlis74714d22016-01-25 15:24:34 -08003502// Remove given cmd_buffer from the global inFlight set.
3503// Also, if given queue is valid, then remove the cmd_buffer from that queues
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003504// inFlightCmdBuffer set. Finally, check all other queues and if given cmd_buffer
Tobin Ehlis74714d22016-01-25 15:24:34 -08003505// is still in flight on another queue, add it back into the global set.
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003506static inline void removeInFlightCmdBuffer(layer_data* dev_data, VkCommandBuffer cmd_buffer, VkQueue queue)
3507{
3508 // 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 -08003509 dev_data->globalInFlightCmdBuffers.erase(cmd_buffer);
3510 if (dev_data->queueMap.find(queue) != dev_data->queueMap.end()) {
3511 dev_data->queueMap[queue].inFlightCmdBuffers.erase(cmd_buffer);
3512 for (auto q : dev_data->queues) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003513 if ((q != queue) && (dev_data->queueMap[q].inFlightCmdBuffers.find(cmd_buffer) != dev_data->queueMap[q].inFlightCmdBuffers.end())) {
Tobin Ehlis74714d22016-01-25 15:24:34 -08003514 dev_data->globalInFlightCmdBuffers.insert(cmd_buffer);
3515 break;
3516 }
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003517 }
3518 }
3519}
Michael Lentineb887b0a2015-12-29 14:12:11 -06003520
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003521VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence* pFences, VkBool32 waitAll, uint64_t timeout)
3522{
3523 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3524 VkResult result = dev_data->device_dispatch_table->WaitForFences(device, fenceCount, pFences, waitAll, timeout);
Mark Youngb20a6a82016-01-07 15:41:43 -07003525 VkBool32 skip_call = VK_FALSE;
Tobin Ehlis74714d22016-01-25 15:24:34 -08003526 if (result == VK_SUCCESS) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003527 // When we know that all fences are complete we can clean/remove their CBs
Tobin Ehlis74714d22016-01-25 15:24:34 -08003528 if (waitAll || fenceCount == 1) {
3529 for (uint32_t i = 0; i < fenceCount; ++i) {
3530 VkQueue fence_queue = dev_data->fenceMap[pFences[i]].queue;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003531 for (auto cmdBuffer : dev_data->fenceMap[pFences[i]].cmdBuffers) {
Tobin Ehlis74714d22016-01-25 15:24:34 -08003532 skip_call |= cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3533 removeInFlightCmdBuffer(dev_data, cmdBuffer, fence_queue);
3534 }
3535 }
3536 decrementResources(dev_data, fenceCount, pFences);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003537 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003538 // NOTE : Alternate case not handled here is when some fences have completed. In
3539 // this case for app to guarantee which fences completed it will have to call
3540 // vkGetFenceStatus() at which point we'll clean/remove their CBs if complete.
Michael Lentine700b0aa2015-10-30 17:57:32 -07003541 }
Mark Youngb20a6a82016-01-07 15:41:43 -07003542 if (VK_FALSE != skip_call)
Mark Lobodzinskice738852016-01-07 10:04:02 -07003543 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003544 return result;
3545}
3546
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003547
3548VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetFenceStatus(VkDevice device, VkFence fence)
3549{
3550 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3551 VkResult result = dev_data->device_dispatch_table->GetFenceStatus(device, fence);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003552 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003553 if (result == VK_SUCCESS) {
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003554 auto fence_queue = dev_data->fenceMap[fence].queue;
Michael Lentineb887b0a2015-12-29 14:12:11 -06003555 for (auto cmdBuffer : dev_data->fenceMap[fence].cmdBuffers) {
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003556 skip_call |= cleanInFlightCmdBuffer(dev_data, cmdBuffer);
Tobin Ehlis74714d22016-01-25 15:24:34 -08003557 removeInFlightCmdBuffer(dev_data, cmdBuffer, fence_queue);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003558 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003559 decrementResources(dev_data, 1, &fence);
3560 }
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003561 if (VK_FALSE != skip_call)
3562 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003563 return result;
3564}
3565
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003566VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue* pQueue)
3567{
3568 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3569 dev_data->device_dispatch_table->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003570 dev_data->queues.push_back(*pQueue);
Michael Lentine700b0aa2015-10-30 17:57:32 -07003571 dev_data->queueMap[*pQueue].device = device;
3572}
3573
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003574VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueueWaitIdle(VkQueue queue)
3575{
3576 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Michael Lentine700b0aa2015-10-30 17:57:32 -07003577 decrementResources(dev_data, queue);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003578 VkBool32 skip_call = VK_FALSE;
3579 // Iterate over local set since we erase set members as we go in for loop
3580 auto local_cb_set = dev_data->queueMap[queue].inFlightCmdBuffers;
3581 for (auto cmdBuffer : local_cb_set) {
3582 skip_call |= cleanInFlightCmdBuffer(dev_data, cmdBuffer);
Tobin Ehlis74714d22016-01-25 15:24:34 -08003583 removeInFlightCmdBuffer(dev_data, cmdBuffer, queue);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003584 }
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003585 dev_data->queueMap[queue].inFlightCmdBuffers.clear();
3586 if (VK_FALSE != skip_call)
3587 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003588 return dev_data->device_dispatch_table->QueueWaitIdle(queue);
3589}
3590
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003591VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkDeviceWaitIdle(VkDevice device)
3592{
Tobin Ehlis74714d22016-01-25 15:24:34 -08003593 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003594 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003595 for (auto queue : dev_data->queues) {
3596 decrementResources(dev_data, queue);
Tobin Ehlis74714d22016-01-25 15:24:34 -08003597 if (dev_data->queueMap.find(queue) != dev_data->queueMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003598 // Clear all of the queue inFlightCmdBuffers (global set cleared below)
Tobin Ehlis74714d22016-01-25 15:24:34 -08003599 dev_data->queueMap[queue].inFlightCmdBuffers.clear();
3600 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003601 }
Tobin Ehlis74714d22016-01-25 15:24:34 -08003602 for (auto cmdBuffer : dev_data->globalInFlightCmdBuffers) {
3603 skip_call |= cleanInFlightCmdBuffer(dev_data, cmdBuffer);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003604 }
Tobin Ehlis74714d22016-01-25 15:24:34 -08003605 dev_data->globalInFlightCmdBuffers.clear();
3606 if (VK_FALSE != skip_call)
3607 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003608 return dev_data->device_dispatch_table->DeviceWaitIdle(device);
3609}
3610
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003611VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks* pAllocator)
3612{
3613 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 -06003614 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003615}
3616
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003617VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySemaphore(VkDevice device, VkSemaphore semaphore, const VkAllocationCallbacks* pAllocator)
3618{
3619 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3620 dev_data->device_dispatch_table->DestroySemaphore(device, semaphore, pAllocator);
Michael Lentine15a47882016-01-06 10:05:48 -06003621 dev_data->semaphoreSignaledMap.erase(semaphore);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003622 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003623}
3624
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003625VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks* pAllocator)
3626{
3627 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 -06003628 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003629}
3630
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003631VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool, const VkAllocationCallbacks* pAllocator)
3632{
3633 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 -06003634 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003635}
3636
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003637VKAPI_ATTR VkResult VKAPI_CALL vkGetQueryPoolResults(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount,
3638 size_t dataSize, void* pData, VkDeviceSize stride, VkQueryResultFlags flags) {
3639 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003640 unordered_map<QueryObject, vector<VkCommandBuffer>> queriesInFlight;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003641 GLOBAL_CB_NODE* pCB = nullptr;
Tobin Ehlis74714d22016-01-25 15:24:34 -08003642 for (auto cmdBuffer : dev_data->globalInFlightCmdBuffers) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06003643 pCB = getCBNode(dev_data, cmdBuffer);
3644 for (auto queryStatePair : pCB->queryToStateMap) {
3645 queriesInFlight[queryStatePair.first].push_back(cmdBuffer);
3646 }
3647 }
Mark Youngb20a6a82016-01-07 15:41:43 -07003648 VkBool32 skip_call = VK_FALSE;
Michael Lentineb887b0a2015-12-29 14:12:11 -06003649 for (uint32_t i = 0; i < queryCount; ++i) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003650 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06003651 auto queryElement = queriesInFlight.find(query);
3652 auto queryToStateElement = dev_data->queryToStateMap.find(query);
3653 if (queryToStateElement != dev_data->queryToStateMap.end()) {
3654 }
3655 // Available and in flight
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003656 if(queryElement != queriesInFlight.end() && queryToStateElement != dev_data->queryToStateMap.end() && queryToStateElement->second) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06003657 for (auto cmdBuffer : queryElement->second) {
3658 pCB = getCBNode(dev_data, cmdBuffer);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003659 auto queryEventElement = pCB->waitedEventsBeforeQueryReset.find(query);
3660 if (queryEventElement == pCB->waitedEventsBeforeQueryReset.end()) {
3661 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT, 0, __LINE__,
3662 DRAWSTATE_INVALID_QUERY, "DS", "Cannot get query results on queryPool %" PRIu64 " with index %d which is in flight.",
3663 (uint64_t)(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003664 } else {
3665 for (auto event : queryEventElement->second) {
3666 dev_data->eventMap[event].needsSignaled = true;
3667 }
3668 }
3669 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003670 // Unavailable and in flight
3671 } else if (queryElement != queriesInFlight.end() && queryToStateElement != dev_data->queryToStateMap.end() && !queryToStateElement->second) {
3672 // TODO : Can there be the same query in use by multiple command buffers in flight?
Michael Lentineb887b0a2015-12-29 14:12:11 -06003673 bool make_available = false;
3674 for (auto cmdBuffer : queryElement->second) {
3675 pCB = getCBNode(dev_data, cmdBuffer);
3676 make_available |= pCB->queryToStateMap[query];
3677 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003678 if (!(((flags & VK_QUERY_RESULT_PARTIAL_BIT) || (flags & VK_QUERY_RESULT_WAIT_BIT)) && make_available)) {
3679 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",
3680 "Cannot get query results on queryPool %" PRIu64 " with index %d which is unavailable.",
3681 (uint64_t)(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003682 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003683 // Unavailable
3684 } else if (queryToStateElement != dev_data->queryToStateMap.end() && !queryToStateElement->second) {
3685 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",
3686 "Cannot get query results on queryPool %" PRIu64 " with index %d which is unavailable.",
3687 (uint64_t)(queryPool), firstQuery + i);
3688 // Unitialized
Michael Lentineb887b0a2015-12-29 14:12:11 -06003689 } else if (queryToStateElement == dev_data->queryToStateMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003690 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",
3691 "Cannot get query results on queryPool %" PRIu64 " with index %d which is uninitialized.",
3692 (uint64_t)(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003693 }
3694 }
3695 if (skip_call)
Mark Lobodzinskice738852016-01-07 10:04:02 -07003696 return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003697 return dev_data->device_dispatch_table->GetQueryPoolResults(device, queryPool, firstQuery, queryCount, dataSize, pData, stride, flags);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003698}
3699
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003700VkBool32 validateIdleBuffer(const layer_data* my_data, VkBuffer buffer) {
Mark Youngb20a6a82016-01-07 15:41:43 -07003701 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003702 auto buffer_data = my_data->bufferMap.find(buffer);
3703 if (buffer_data == my_data->bufferMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003704 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",
3705 "Cannot free buffer %" PRIxLEAST64 " that has not been allocated.", (uint64_t)(buffer));
Michael Lentine700b0aa2015-10-30 17:57:32 -07003706 } else {
3707 if (buffer_data->second.in_use.load()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003708 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",
3709 "Cannot free buffer %" PRIxLEAST64 " that is in use by a command buffer.", (uint64_t)(buffer));
Michael Lentine700b0aa2015-10-30 17:57:32 -07003710 }
3711 }
3712 return skip_call;
3713}
3714
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003715VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks* pAllocator)
3716{
3717 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07003718 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003719 if (!validateIdleBuffer(dev_data, buffer)) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003720 dev_data->device_dispatch_table->DestroyBuffer(device, buffer, pAllocator);
Michael Lentine700b0aa2015-10-30 17:57:32 -07003721 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08003722 dev_data->bufferMap.erase(buffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003723}
3724
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003725VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBufferView(VkDevice device, VkBufferView bufferView, const VkAllocationCallbacks* pAllocator)
3726{
3727 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3728 dev_data->device_dispatch_table->DestroyBufferView(device, bufferView, pAllocator);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003729 dev_data->bufferViewMap.erase(bufferView);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003730}
3731
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003732VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks* pAllocator)
3733{
3734 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003735 dev_data->device_dispatch_table->DestroyImage(device, image, pAllocator);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003736 dev_data->imageMap.erase(image);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003737}
3738
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003739VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyImageView(VkDevice device, VkImageView imageView, const VkAllocationCallbacks* pAllocator)
3740{
3741 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 -06003742 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003743}
3744
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003745VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule, const VkAllocationCallbacks* pAllocator)
3746{
3747 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 -06003748 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003749}
3750
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003751VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyPipeline(VkDevice device, VkPipeline pipeline, const VkAllocationCallbacks* pAllocator)
3752{
3753 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 -06003754 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003755}
3756
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003757VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout, const VkAllocationCallbacks* pAllocator)
3758{
3759 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 -06003760 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003761}
3762
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003763VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySampler(VkDevice device, VkSampler sampler, const VkAllocationCallbacks* pAllocator)
3764{
3765 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 -06003766 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003767}
3768
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003769VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout, const VkAllocationCallbacks* pAllocator)
3770{
3771 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 -06003772 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003773}
3774
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003775VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, const VkAllocationCallbacks* pAllocator)
3776{
3777 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 -06003778 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003779}
3780
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003781VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t count, const VkCommandBuffer *pCommandBuffers)
3782{
3783 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003784
Michael Lentine5f6dc4f2016-01-27 20:42:07 -06003785 bool skip_call = false;
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07003786 for (uint32_t i = 0; i < count; i++) {
Tobin Ehlis74714d22016-01-25 15:24:34 -08003787 loader_platform_thread_lock_mutex(&globalLock);
Michael Lentine5f6dc4f2016-01-27 20:42:07 -06003788 if (dev_data->globalInFlightCmdBuffers.count(pCommandBuffers[i])) {
3789 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
3790 reinterpret_cast<uint64_t>(pCommandBuffers[i]), __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
3791 "Attempt to free command buffer (%#" PRIxLEAST64 ") which is in use.", reinterpret_cast<uint64_t>(pCommandBuffers[i]));
3792 }
Mark Lobodzinski39298632015-11-18 08:38:27 -07003793 // Delete CB information structure, and remove from commandBufferMap
3794 auto cb = dev_data->commandBufferMap.find(pCommandBuffers[i]);
3795 if (cb != dev_data->commandBufferMap.end()) {
Tobin Ehlise6e574b2016-01-24 23:25:31 -07003796 // reset prior to delete for data clean-up
3797 resetCB(dev_data, (*cb).second->commandBuffer);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003798 delete (*cb).second;
3799 dev_data->commandBufferMap.erase(cb);
3800 }
3801
3802 // Remove commandBuffer reference from commandPoolMap
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003803 dev_data->commandPoolMap[commandPool].commandBuffers.remove(pCommandBuffers[i]);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003804 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003805 }
3806
Michael Lentine5f6dc4f2016-01-27 20:42:07 -06003807 if (!skip_call)
3808 dev_data->device_dispatch_table->FreeCommandBuffers(device, commandPool, count, pCommandBuffers);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003809}
3810
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003811VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkCommandPool* pCommandPool)
3812{
3813 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003814
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003815 VkResult result = dev_data->device_dispatch_table->CreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003816
3817 if (VK_SUCCESS == result) {
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003818 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003819 dev_data->commandPoolMap[*pCommandPool].createFlags = pCreateInfo->flags;
Michael Lentined1b2a8b2016-02-03 21:20:25 -06003820 dev_data->commandPoolMap[*pCommandPool].queueFamilyIndex = pCreateInfo->queueFamilyIndex;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003821 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003822 }
3823 return result;
3824}
Michael Lentinee063fe42016-01-27 17:52:20 -06003825
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003826VkBool32 validateCommandBuffersNotInUse(const layer_data* dev_data, VkCommandPool commandPool) {
Mark Youngbaa677f2016-01-28 09:36:15 -07003827 VkBool32 skipCall = VK_FALSE;
Michael Lentinee063fe42016-01-27 17:52:20 -06003828 loader_platform_thread_lock_mutex(&globalLock);
3829 auto pool_data = dev_data->commandPoolMap.find(commandPool);
3830 if (pool_data != dev_data->commandPoolMap.end()) {
3831 for (auto cmdBuffer : pool_data->second.commandBuffers) {
Tobin Ehlis74714d22016-01-25 15:24:34 -08003832 if (dev_data->globalInFlightCmdBuffers.count(cmdBuffer)) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003833 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT, (uint64_t)(commandPool),
3834 __LINE__, DRAWSTATE_OBJECT_INUSE, "DS", "Cannot reset command pool %" PRIx64 " when allocated command buffer %" PRIx64 " is in use.",
3835 (uint64_t)(commandPool), (uint64_t)(cmdBuffer));
Michael Lentinee063fe42016-01-27 17:52:20 -06003836 }
3837 }
3838 }
3839 loader_platform_thread_unlock_mutex(&globalLock);
Mark Youngbaa677f2016-01-28 09:36:15 -07003840 return skipCall;
Michael Lentinee063fe42016-01-27 17:52:20 -06003841}
3842
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003843// Destroy commandPool along with all of the commandBuffers allocated from that pool
3844VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks* pAllocator)
3845{
3846 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003847 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003848
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003849 // Must remove cmdpool from cmdpoolmap, after removing all cmdbuffers in its list from the commandPoolMap
3850 if (dev_data->commandPoolMap.find(commandPool) != dev_data->commandPoolMap.end()) {
3851 for (auto poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.begin(); poolCb != dev_data->commandPoolMap[commandPool].commandBuffers.end();) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003852 auto del_cb = dev_data->commandBufferMap.find(*poolCb);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003853 delete (*del_cb).second; // delete CB info structure
3854 dev_data->commandBufferMap.erase(del_cb); // Remove this command buffer from cbMap
3855 poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.erase(poolCb); // Remove CB reference from commandPoolMap's list
Mark Lobodzinski39298632015-11-18 08:38:27 -07003856 }
3857 }
3858 dev_data->commandPoolMap.erase(commandPool);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003859
3860 loader_platform_thread_unlock_mutex(&globalLock);
Michael Lentinee063fe42016-01-27 17:52:20 -06003861
Mark Youngbaa677f2016-01-28 09:36:15 -07003862 if (VK_TRUE == validateCommandBuffersNotInUse(dev_data, commandPool))
Michael Lentinee063fe42016-01-27 17:52:20 -06003863 return;
3864
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003865 dev_data->device_dispatch_table->DestroyCommandPool(device, commandPool, pAllocator);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003866}
3867
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003868VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandPool(
3869 VkDevice device,
3870 VkCommandPool commandPool,
3871 VkCommandPoolResetFlags flags)
3872{
3873 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3874 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003875
Mark Youngbaa677f2016-01-28 09:36:15 -07003876 if (VK_TRUE == validateCommandBuffersNotInUse(dev_data, commandPool))
Michael Lentined2a7d632016-01-27 17:02:39 -06003877 return VK_ERROR_VALIDATION_FAILED_EXT;
3878
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003879 result = dev_data->device_dispatch_table->ResetCommandPool(device, commandPool, flags);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003880 // Reset all of the CBs allocated from this pool
3881 if (VK_SUCCESS == result) {
Tobin Ehlis74714d22016-01-25 15:24:34 -08003882 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003883 auto it = dev_data->commandPoolMap[commandPool].commandBuffers.begin();
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003884 while (it != dev_data->commandPoolMap[commandPool].commandBuffers.end()) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003885 resetCB(dev_data, (*it));
3886 ++it;
3887 }
Tobin Ehlis74714d22016-01-25 15:24:34 -08003888 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003889 }
3890 return result;
3891}
3892
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003893VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer, const VkAllocationCallbacks* pAllocator)
3894{
3895 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 -06003896 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003897}
3898
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003899VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass, const VkAllocationCallbacks* pAllocator)
3900{
3901 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 -06003902 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003903}
3904
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003905VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateBuffer(VkDevice device, const VkBufferCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkBuffer* pBuffer)
3906{
3907 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3908 VkResult result = dev_data->device_dispatch_table->CreateBuffer(device, pCreateInfo, pAllocator, pBuffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003909 if (VK_SUCCESS == result) {
3910 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003911 // TODO : This doesn't create deep copy of pQueueFamilyIndices so need to fix that if/when we want that data to be valid
3912 dev_data->bufferMap[*pBuffer].create_info = unique_ptr<VkBufferCreateInfo>(new VkBufferCreateInfo(*pCreateInfo));
Michael Lentine700b0aa2015-10-30 17:57:32 -07003913 dev_data->bufferMap[*pBuffer].in_use.store(0);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003914 loader_platform_thread_unlock_mutex(&globalLock);
3915 }
3916 return result;
3917}
3918
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003919VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkBufferView* pView)
3920{
3921 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3922 VkResult result = dev_data->device_dispatch_table->CreateBufferView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003923 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003924 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003925 dev_data->bufferViewMap[*pView] = unique_ptr<VkBufferViewCreateInfo>(new VkBufferViewCreateInfo(*pCreateInfo));
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003926 loader_platform_thread_unlock_mutex(&globalLock);
3927 }
3928 return result;
3929}
3930
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003931VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateImage(VkDevice device, const VkImageCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkImage* pImage)
3932{
3933 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3934 VkResult result = dev_data->device_dispatch_table->CreateImage(device, pCreateInfo, pAllocator, pImage);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003935 if (VK_SUCCESS == result) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003936 IMAGE_NODE* image_node = new IMAGE_NODE;
Michael Lentineabc5e922015-10-12 11:30:14 -05003937 image_node->layout = pCreateInfo->initialLayout;
Tobin Ehlis75cd1c52016-01-21 10:21:04 -07003938 image_node->format = pCreateInfo->format;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003939 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003940 dev_data->imageMap[*pImage] = unique_ptr<VkImageCreateInfo>(new VkImageCreateInfo(*pCreateInfo));
Michael Lentineabc5e922015-10-12 11:30:14 -05003941 dev_data->imageLayoutMap[*pImage] = image_node;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003942 loader_platform_thread_unlock_mutex(&globalLock);
3943 }
3944 return result;
3945}
3946
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003947VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkImageView* pView)
3948{
3949 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3950 VkResult result = dev_data->device_dispatch_table->CreateImageView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003951 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003952 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003953 dev_data->imageViewMap[*pView] = unique_ptr<VkImageViewCreateInfo>(new VkImageViewCreateInfo(*pCreateInfo));
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003954 loader_platform_thread_unlock_mutex(&globalLock);
3955 }
3956 return result;
3957}
3958
Michael Lentine37767342016-02-02 22:24:26 -06003959VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
3960 vkCreateFence(VkDevice device, const VkFenceCreateInfo* pCreateInfo,
3961 const VkAllocationCallbacks* pAllocator, VkFence* pFence) {
3962 layer_data *dev_data =
3963 get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3964 VkResult result = dev_data->device_dispatch_table->CreateFence(
3965 device, pCreateInfo, pAllocator, pFence);
3966 if (VK_SUCCESS == result) {
3967 loader_platform_thread_lock_mutex(&globalLock);
3968 dev_data->fenceMap[*pFence].in_use.store(0);
3969 loader_platform_thread_unlock_mutex(&globalLock);
3970 }
3971 return result;
3972}
3973
3974// TODO handle pipeline caches
3975VKAPI_ATTR VkResult VKAPI_CALL
3976 vkCreatePipelineCache(VkDevice device,
3977 const VkPipelineCacheCreateInfo *pCreateInfo,
3978 const VkAllocationCallbacks *pAllocator,
3979 VkPipelineCache *pPipelineCache) {
3980 layer_data *dev_data =
3981 get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3982 VkResult result = dev_data->device_dispatch_table->CreatePipelineCache(
3983 device, pCreateInfo, pAllocator, pPipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003984 return result;
3985}
3986
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003987VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineCache(
3988 VkDevice device,
3989 VkPipelineCache pipelineCache,
3990 const VkAllocationCallbacks* pAllocator)
3991{
3992 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3993 dev_data->device_dispatch_table->DestroyPipelineCache(device, pipelineCache, pAllocator);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003994}
3995
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07003996VKAPI_ATTR VkResult VKAPI_CALL vkGetPipelineCacheData(
3997 VkDevice device,
3998 VkPipelineCache pipelineCache,
3999 size_t* pDataSize,
4000 void* pData)
4001{
4002 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4003 VkResult result = dev_data->device_dispatch_table->GetPipelineCacheData(device, pipelineCache, pDataSize, pData);
Jon Ashburnc669cc62015-07-09 15:02:25 -06004004 return result;
4005}
4006
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004007VKAPI_ATTR VkResult VKAPI_CALL vkMergePipelineCaches(
4008 VkDevice device,
4009 VkPipelineCache dstCache,
4010 uint32_t srcCacheCount,
4011 const VkPipelineCache* pSrcCaches)
4012{
4013 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4014 VkResult result = dev_data->device_dispatch_table->MergePipelineCaches(device, dstCache, srcCacheCount, pSrcCaches);
Jon Ashburnc669cc62015-07-09 15:02:25 -06004015 return result;
4016}
4017
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004018VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateGraphicsPipelines(
4019 VkDevice device,
4020 VkPipelineCache pipelineCache,
4021 uint32_t count,
4022 const VkGraphicsPipelineCreateInfo *pCreateInfos,
4023 const VkAllocationCallbacks *pAllocator,
4024 VkPipeline *pPipelines)
4025{
Courtney Goeltzenleuchtered894072015-09-04 13:39:59 -06004026 VkResult result = VK_SUCCESS;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004027 //TODO What to do with pipelineCache?
Tobin Ehlis75283bf2015-06-18 15:59:33 -06004028 // The order of operations here is a little convoluted but gets the job done
4029 // 1. Pipeline create state is first shadowed into PIPELINE_NODE struct
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004030 // 2. Create state is then validated (which uses flags setup during shadowing)
4031 // 3. If everything looks good, we'll then create the pipeline and add NODE to pipelineMap
Tobin Ehlis11efc302015-09-16 10:33:53 -06004032 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004033 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
4034 vector<PIPELINE_NODE*> pPipeNode(count);
4035 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004036
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004037 uint32_t i=0;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06004038 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004039
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004040 for (i=0; i<count; i++) {
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004041 pPipeNode[i] = initGraphicsPipeline(dev_data, &pCreateInfos[i], NULL);
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004042 skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
Tobin Ehlis11efc302015-09-16 10:33:53 -06004043 }
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004044
Tobin Ehlis75283bf2015-06-18 15:59:33 -06004045 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07004046
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07004047 if (VK_FALSE == skipCall) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004048 result = dev_data->device_dispatch_table->CreateGraphicsPipelines(device,
4049 pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
Tobin Ehlis75283bf2015-06-18 15:59:33 -06004050 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004051 for (i=0; i<count; i++) {
Tobin Ehlis11efc302015-09-16 10:33:53 -06004052 pPipeNode[i]->pipeline = pPipelines[i];
Chia-I Wue2fc5522015-10-26 20:04:44 +08004053 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
Tobin Ehlis11efc302015-09-16 10:33:53 -06004054 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06004055 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisce132d82015-06-19 15:07:05 -06004056 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004057 for (i=0; i<count; i++) {
Tobin Ehlis11efc302015-09-16 10:33:53 -06004058 if (pPipeNode[i]) {
4059 // If we allocated a pipeNode, need to clean it up here
4060 delete[] pPipeNode[i]->pVertexBindingDescriptions;
4061 delete[] pPipeNode[i]->pVertexAttributeDescriptions;
4062 delete[] pPipeNode[i]->pAttachments;
4063 delete pPipeNode[i];
4064 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06004065 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004066 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06004067 }
Courtney Goeltzenleuchtere2aaad02015-04-13 16:16:04 -06004068 return result;
4069}
4070
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004071VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateComputePipelines(
4072 VkDevice device,
4073 VkPipelineCache pipelineCache,
4074 uint32_t count,
4075 const VkComputePipelineCreateInfo *pCreateInfos,
4076 const VkAllocationCallbacks *pAllocator,
4077 VkPipeline *pPipelines)
4078{
4079 VkResult result = VK_SUCCESS;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004080 VkBool32 skipCall = VK_FALSE;
4081
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004082 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
4083 vector<PIPELINE_NODE*> pPipeNode(count);
4084 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004085
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004086 uint32_t i=0;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004087 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004088 for (i=0; i<count; i++) {
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004089 // TODO: Verify compute stage bits
4090
4091 // Create and initialize internal tracking data structure
4092 pPipeNode[i] = new PIPELINE_NODE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004093 memcpy(&pPipeNode[i]->computePipelineCI, (const void*)&pCreateInfos[i], sizeof(VkComputePipelineCreateInfo));
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004094
4095 // TODO: Add Compute Pipeline Verification
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004096 // skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004097 }
4098 loader_platform_thread_unlock_mutex(&globalLock);
4099
4100 if (VK_FALSE == skipCall) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004101 result = dev_data->device_dispatch_table->CreateComputePipelines(device, pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004102 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004103 for (i=0; i<count; i++) {
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004104 pPipeNode[i]->pipeline = pPipelines[i];
4105 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
4106 }
4107 loader_platform_thread_unlock_mutex(&globalLock);
4108 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004109 for (i=0; i<count; i++) {
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004110 if (pPipeNode[i]) {
4111 // Clean up any locally allocated data structures
4112 delete pPipeNode[i];
4113 }
4114 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004115 return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07004116 }
4117 return result;
4118}
4119
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004120VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSampler* pSampler)
4121{
4122 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4123 VkResult result = dev_data->device_dispatch_table->CreateSampler(device, pCreateInfo, pAllocator, pSampler);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004124 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004125 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004126 dev_data->sampleMap[*pSampler] = unique_ptr<SAMPLER_NODE>(new SAMPLER_NODE(pSampler, pCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004127 loader_platform_thread_unlock_mutex(&globalLock);
4128 }
4129 return result;
4130}
4131
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004132VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDescriptorSetLayout* pSetLayout)
4133{
4134 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4135 VkResult result = dev_data->device_dispatch_table->CreateDescriptorSetLayout(device, pCreateInfo, pAllocator, pSetLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004136 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07004137 // TODOSC : Capture layout bindings set
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004138 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004139 if (NULL == pNewNode) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004140 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",
4141 "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004142 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004143 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004144 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
4145 pNewNode->createInfo.pBindings = new VkDescriptorSetLayoutBinding[pCreateInfo->bindingCount];
4146 memcpy((void*)pNewNode->createInfo.pBindings, pCreateInfo->pBindings, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->bindingCount);
Chia-I Wud46e6ae2015-10-31 00:31:16 +08004147 // g++ does not like reserve with size 0
4148 if (pCreateInfo->bindingCount)
4149 pNewNode->bindings.reserve(pCreateInfo->bindingCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004150 uint32_t totalCount = 0;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004151 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
4152 if (!pNewNode->bindings.insert(pCreateInfo->pBindings[i].binding).second) {
4153 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",
4154 "duplicated binding number in VkDescriptorSetLayoutBinding"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004155 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08004156 }
4157
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07004158 totalCount += pCreateInfo->pBindings[i].descriptorCount;
4159 if (pCreateInfo->pBindings[i].pImmutableSamplers) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004160 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBindings[i].pImmutableSamplers;
4161 *ppIS = new VkSampler[pCreateInfo->pBindings[i].descriptorCount];
4162 memcpy(*ppIS, pCreateInfo->pBindings[i].pImmutableSamplers, pCreateInfo->pBindings[i].descriptorCount*sizeof(VkSampler));
Tobin Ehlis793ad302015-04-03 12:01:11 -06004163 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004164 }
Tobin Ehlis43c39c02016-01-11 13:18:40 -07004165 pNewNode->layout = *pSetLayout;
4166 pNewNode->startIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004167 if (totalCount > 0) {
Cody Northrop43751cc2015-10-26 14:07:35 -06004168 pNewNode->descriptorTypes.resize(totalCount);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06004169 pNewNode->stageFlags.resize(totalCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004170 uint32_t offset = 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06004171 uint32_t j = 0;
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07004172 VkDescriptorType dType;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004173 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07004174 dType = pCreateInfo->pBindings[i].descriptorType;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004175 for (j = 0; j < pCreateInfo->pBindings[i].descriptorCount; j++) {
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07004176 pNewNode->descriptorTypes[offset + j] = dType;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004177 pNewNode->stageFlags[offset + j] = pCreateInfo->pBindings[i].stageFlags;
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07004178 if ((dType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
4179 (dType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
4180 pNewNode->dynamicDescriptorCount++;
4181 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004182 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06004183 offset += j;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004184 }
Tobin Ehlis43c39c02016-01-11 13:18:40 -07004185 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
4186 } else { // no descriptors
4187 pNewNode->endIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004188 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004189 // Put new node at Head of global Layer list
4190 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07004191 dev_data->descriptorSetLayoutMap[*pSetLayout] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004192 loader_platform_thread_unlock_mutex(&globalLock);
4193 }
4194 return result;
4195}
4196
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004197VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkPipelineLayout* pPipelineLayout)
4198{
4199 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4200 VkResult result = dev_data->device_dispatch_table->CreatePipelineLayout(device, pCreateInfo, pAllocator, pPipelineLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004201 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07004202 // TODOSC : Merge capture of the setLayouts per pipeline
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004203 PIPELINE_LAYOUT_NODE& plNode = dev_data->pipelineLayoutMap[*pPipelineLayout];
Chia-I Wud50a7d72015-10-26 20:48:51 +08004204 plNode.descriptorSetLayouts.resize(pCreateInfo->setLayoutCount);
Tobin Ehlis644ff042015-10-20 10:11:55 -06004205 uint32_t i = 0;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004206 for (i=0; i<pCreateInfo->setLayoutCount; ++i) {
Tobin Ehlis644ff042015-10-20 10:11:55 -06004207 plNode.descriptorSetLayouts[i] = pCreateInfo->pSetLayouts[i];
4208 }
Cody Northrop43751cc2015-10-26 14:07:35 -06004209 plNode.pushConstantRanges.resize(pCreateInfo->pushConstantRangeCount);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004210 for (i=0; i<pCreateInfo->pushConstantRangeCount; ++i) {
Tobin Ehlis644ff042015-10-20 10:11:55 -06004211 plNode.pushConstantRanges[i] = pCreateInfo->pPushConstantRanges[i];
4212 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06004213 }
4214 return result;
4215}
4216
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004217VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDescriptorPool* pDescriptorPool)
4218{
4219 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4220 VkResult result = dev_data->device_dispatch_table->CreateDescriptorPool(device, pCreateInfo, pAllocator, pDescriptorPool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004221 if (VK_SUCCESS == result) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06004222 // Insert this pool into Global Pool LL at head
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004223 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",
4224 "Created Descriptor Pool %#" PRIxLEAST64, (uint64_t) *pDescriptorPool))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004225 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004226 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004227 DESCRIPTOR_POOL_NODE* pNewNode = new DESCRIPTOR_POOL_NODE(*pDescriptorPool, pCreateInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004228 if (NULL == pNewNode) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004229 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",
4230 "Out of memory while attempting to allocate DESCRIPTOR_POOL_NODE in vkCreateDescriptorPool()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004231 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisce132d82015-06-19 15:07:05 -06004232 } else {
Mark Lobodzinski39298632015-11-18 08:38:27 -07004233 dev_data->descriptorPoolMap[*pDescriptorPool] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004234 }
4235 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisce132d82015-06-19 15:07:05 -06004236 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06004237 // Need to do anything if pool create fails?
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004238 }
4239 return result;
4240}
4241
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004242VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorPoolResetFlags flags)
4243{
4244 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4245 VkResult result = dev_data->device_dispatch_table->ResetDescriptorPool(device, descriptorPool, flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004246 if (VK_SUCCESS == result) {
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004247 clearDescriptorPool(dev_data, device, descriptorPool, flags);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004248 }
4249 return result;
4250}
4251
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004252VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo* pAllocateInfo, VkDescriptorSet* pDescriptorSets)
4253{
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004254 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004255 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004256 // Verify that requested descriptorSets are available in pool
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004257 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004258 if (!pPoolNode) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004259 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",
4260 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pAllocateInfo->descriptorPool);
4261 } else { // Make sure pool has all the available descriptors before calling down chain
4262 skipCall |= validate_descriptor_availability_in_pool(dev_data, pPoolNode, pAllocateInfo->descriptorSetCount, pAllocateInfo->pSetLayouts);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004263 }
4264 if (skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004265 return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004266 VkResult result = dev_data->device_dispatch_table->AllocateDescriptorSets(device, pAllocateInfo, pDescriptorSets);
Cody Northrop1e4f8022015-08-03 12:47:29 -06004267 if (VK_SUCCESS == result) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004268 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004269 if (pPoolNode) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004270 if (pAllocateInfo->descriptorSetCount == 0) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004271 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 +08004272 "AllocateDescriptorSets called with 0 count");
Cody Northrop1e4f8022015-08-03 12:47:29 -06004273 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07004274 for (uint32_t i = 0; i < pAllocateInfo->descriptorSetCount; i++) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004275 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",
4276 "Created Descriptor Set %#" PRIxLEAST64, (uint64_t) pDescriptorSets[i]);
Tobin Ehlis793ad302015-04-03 12:01:11 -06004277 // Create new set node and add to head of pool nodes
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004278 SET_NODE* pNewNode = new SET_NODE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004279 if (NULL == pNewNode) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004280 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",
4281 "Out of memory while attempting to allocate SET_NODE in vkAllocateDescriptorSets()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004282 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisce132d82015-06-19 15:07:05 -06004283 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004284 // TODO : Pool should store a total count of each type of Descriptor available
4285 // When descriptors are allocated, decrement the count and validate here
4286 // that the count doesn't go below 0. One reset/free need to bump count back up.
Tobin Ehlis793ad302015-04-03 12:01:11 -06004287 // Insert set at head of Set LL for this pool
4288 pNewNode->pNext = pPoolNode->pSets;
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07004289 pNewNode->in_use.store(0);
Tobin Ehlis793ad302015-04-03 12:01:11 -06004290 pPoolNode->pSets = pNewNode;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004291 LAYOUT_NODE* pLayout = getLayoutNode(dev_data, pAllocateInfo->pSetLayouts[i]);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004292 if (NULL == pLayout) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004293 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",
4294 "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 -07004295 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004296 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06004297 pNewNode->pLayout = pLayout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004298 pNewNode->pool = pAllocateInfo->descriptorPool;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004299 pNewNode->set = pDescriptorSets[i];
Tobin Ehlise703fa92016-01-29 07:52:45 -07004300 pNewNode->descriptorCount = (pLayout->createInfo.bindingCount != 0) ? pLayout->endIndex + 1 : 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004301 if (pNewNode->descriptorCount) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004302 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
4303 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004304 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
4305 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08004306 dev_data->setMap[pDescriptorSets[i]] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004307 }
4308 }
4309 }
4310 }
4311 return result;
4312}
4313
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004314VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, const VkDescriptorSet* pDescriptorSets)
4315{
Tobin Ehlise735c692015-10-08 13:13:50 -06004316 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004317 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07004318 // Make sure that no sets being destroyed are in-flight
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004319 for (uint32_t i=0; i<count; ++i)
4320 skipCall |= validateIdleDescriptorSet(dev_data, pDescriptorSets[i], "vkFreeDesriptorSets");
Mark Lobodzinski39298632015-11-18 08:38:27 -07004321 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, descriptorPool);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004322 if (pPoolNode && !(VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT & pPoolNode->createInfo.flags)) {
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004323 // Can't Free from a NON_FREE pool
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004324 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",
4325 "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 -06004326 }
Mark Youngb20a6a82016-01-07 15:41:43 -07004327 if (VK_FALSE != skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004328 return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004329 VkResult result = dev_data->device_dispatch_table->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004330 if (VK_SUCCESS == result) {
4331 // For each freed descriptor add it back into the pool as available
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004332 for (uint32_t i=0; i<count; ++i) {
4333 SET_NODE* pSet = dev_data->setMap[pDescriptorSets[i]]; // getSetNode() without locking
Tobin Ehlise6e574b2016-01-24 23:25:31 -07004334 invalidateBoundCmdBuffers(dev_data, pSet);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004335 LAYOUT_NODE* pLayout = pSet->pLayout;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004336 uint32_t typeIndex = 0, poolSizeCount = 0;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004337 for (uint32_t j=0; j<pLayout->createInfo.bindingCount; ++j) {
4338 typeIndex = static_cast<uint32_t>(pLayout->createInfo.pBindings[j].descriptorType);
4339 poolSizeCount = pLayout->createInfo.pBindings[j].descriptorCount;
4340 pPoolNode->availableDescriptorTypeCount[typeIndex] += poolSizeCount;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004341 }
4342 }
4343 }
4344 // TODO : Any other clean-up or book-keeping to do here?
Tony Barbour34ec6922015-07-10 10:50:45 -06004345 return result;
4346}
4347
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004348VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount, const VkWriteDescriptorSet* pDescriptorWrites, uint32_t descriptorCopyCount, const VkCopyDescriptorSet* pDescriptorCopies)
4349{
4350 // dsUpdate will return VK_TRUE only if a bailout error occurs, so we want to call down tree when update returns VK_FALSE
4351 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4352 if (!dsUpdate(dev_data, device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies)) {
4353 dev_data->device_dispatch_table->UpdateDescriptorSets(device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies);
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004354 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004355}
4356
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004357VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo* pCreateInfo, VkCommandBuffer* pCommandBuffer)
4358{
4359 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
4360 VkResult result = dev_data->device_dispatch_table->AllocateCommandBuffers(device, pCreateInfo, pCommandBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004361 if (VK_SUCCESS == result) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004362 for (uint32_t i = 0; i < pCreateInfo->commandBufferCount; i++) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07004363 // Validate command pool
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004364 if (dev_data->commandPoolMap.find(pCreateInfo->commandPool) != dev_data->commandPoolMap.end()) {
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07004365 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07004366 // Add command buffer to its commandPool map
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004367 dev_data->commandPoolMap[pCreateInfo->commandPool].commandBuffers.push_back(pCommandBuffer[i]);
4368 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
Mark Lobodzinski39298632015-11-18 08:38:27 -07004369 // Add command buffer to map
4370 dev_data->commandBufferMap[pCommandBuffer[i]] = pCB;
4371 resetCB(dev_data, pCommandBuffer[i]);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004372 pCB->createInfo = *pCreateInfo;
4373 pCB->device = device;
Tobin Ehlis74714d22016-01-25 15:24:34 -08004374 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07004375 }
4376 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004377 }
4378 return result;
4379}
4380
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004381VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo* pBeginInfo)
4382{
Mark Youngb20a6a82016-01-07 15:41:43 -07004383 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004384 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004385 // Validate command buffer level
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004386 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004387 if (pCB) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004388 if (pCB->createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
4389 // Secondary Command Buffer
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004390 const VkCommandBufferInheritanceInfo *pInfo = pBeginInfo->pInheritanceInfo;
Michael Lentine7d26c572016-01-28 11:55:28 -06004391 if (!pInfo) {
4392 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__,
4393 DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS", "vkBeginCommandBuffer(): Secondary Command Buffer (%p) must have inheritance info.",
4394 reinterpret_cast<void*>(commandBuffer));
4395 } else {
4396 if (pBeginInfo->flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT) {
4397 if (!pInfo->renderPass) { // renderpass should NOT be null for an Secondary CB
4398 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),
4399 __LINE__, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
4400 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) must specify a valid renderpass parameter.", reinterpret_cast<void*>(commandBuffer));
Tobin Ehlis651d9b02015-12-16 05:01:22 -07004401 }
Michael Lentine7d26c572016-01-28 11:55:28 -06004402 if (!pInfo->framebuffer) { // framebuffer may be null for an Secondary CB, but this affects perf
4403 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),
4404 __LINE__, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
4405 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) may perform better if a valid framebuffer parameter is specified.",
4406 reinterpret_cast<void*>(commandBuffer));
4407 } else {
4408 string errorString = "";
4409 VkRenderPass fbRP = dev_data->frameBufferMap[pInfo->framebuffer]->renderPass;
4410 if (!verify_renderpass_compatibility(dev_data, fbRP, pInfo->renderPass, errorString)) {
4411 // renderPass that framebuffer was created with must be compatible with local renderPass
4412 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),
4413 __LINE__, DRAWSTATE_RENDERPASS_INCOMPATIBLE, "DS",
4414 "vkBeginCommandBuffer(): Secondary Command Buffer (%p) renderPass (%#" PRIxLEAST64 ") is incompatible w/ framebuffer (%#" PRIxLEAST64
Dustin Graves4383a2d2016-02-04 10:57:00 -07004415 ") w/ render pass (%#" PRIxLEAST64 ") due to: %s", reinterpret_cast<void*>(commandBuffer), (uint64_t)(pInfo->renderPass),
4416 (uint64_t)(pInfo->framebuffer), (uint64_t)(fbRP), errorString.c_str());
Michael Lentine7d26c572016-01-28 11:55:28 -06004417 }
4418 }
4419 }
4420 if ((pInfo->occlusionQueryEnable == VK_FALSE || dev_data->physDevProperties.features.occlusionQueryPrecise == VK_FALSE) && (pInfo->queryFlags & VK_QUERY_CONTROL_PRECISE_BIT)) {
4421 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),
4422 __LINE__, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
4423 "vkBeginCommandBuffer(): Secondary Command Buffer (%p) must not have VK_QUERY_CONTROL_PRECISE_BIT if occulusionQuery is disabled or the device does not "
4424 "support precise occlusion queries.", reinterpret_cast<void*>(commandBuffer));
Tobin Ehlis651d9b02015-12-16 05:01:22 -07004425 }
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004426 }
Michael Lentine539b0222016-02-02 17:28:24 -06004427 if (pInfo->renderPass != VK_NULL_HANDLE) {
4428 auto rp_data = dev_data->renderPassMap.find(pInfo->renderPass);
4429 if (rp_data != dev_data->renderPassMap.end() && rp_data->second && rp_data->second->pCreateInfo) {
4430 if (pInfo->subpass >= rp_data->second->pCreateInfo->subpassCount) {
4431 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer,
4432 __LINE__, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
4433 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) must has a subpass index (%d) that is less than the number of subpasses (%d).",
4434 (void*)commandBuffer, pInfo->subpass, rp_data->second->pCreateInfo->subpassCount);
4435 }
4436 }
4437 }
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004438 }
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004439 if (CB_RECORDING == pCB->state) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004440 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",
4441 "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 -07004442 } else if (CB_RECORDED == pCB->state) {
4443 VkCommandPool cmdPool = pCB->createInfo.commandPool;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004444 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
4445 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer,
4446 __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
4447 "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.",
4448 (uint64_t) commandBuffer, (uint64_t) cmdPool);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004449 }
Tobin Ehlis74714d22016-01-25 15:24:34 -08004450 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisef694652016-01-19 12:03:34 -07004451 resetCB(dev_data, commandBuffer);
Tobin Ehlis74714d22016-01-25 15:24:34 -08004452 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004453 }
Tobin Ehlisef694652016-01-19 12:03:34 -07004454 // Set updated state here in case implicit reset occurs above
Tobin Ehlis74714d22016-01-25 15:24:34 -08004455 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisef694652016-01-19 12:03:34 -07004456 pCB->state = CB_RECORDING;
4457 pCB->beginInfo = *pBeginInfo;
Tobin Ehliscd5bfd82016-01-19 13:12:52 -07004458 if (pCB->beginInfo.pInheritanceInfo) {
4459 pCB->inheritanceInfo = *(pCB->beginInfo.pInheritanceInfo);
4460 pCB->beginInfo.pInheritanceInfo = &pCB->inheritanceInfo;
4461 }
Tobin Ehlis74714d22016-01-25 15:24:34 -08004462 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004463 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004464 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",
4465 "In vkBeginCommandBuffer() and unable to find CommandBuffer Node for CB %p!", (void*)commandBuffer);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004466 }
Mark Youngb20a6a82016-01-07 15:41:43 -07004467 if (VK_FALSE != skipCall) {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004468 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter5fe086f2015-09-04 15:03:52 -06004469 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004470 VkResult result = dev_data->device_dispatch_table->BeginCommandBuffer(commandBuffer, pBeginInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004471 return result;
4472}
4473
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004474VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEndCommandBuffer(VkCommandBuffer commandBuffer)
4475{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004476 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchtered894072015-09-04 13:39:59 -06004477 VkResult result = VK_SUCCESS;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004478 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4479 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004480 if (pCB) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004481 if (pCB->state != CB_RECORDING) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004482 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkEndCommandBuffer()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004483 }
Michael Lentinedc6f8de2016-02-02 18:29:30 -06004484 for (auto query : pCB->activeQueries) {
4485 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_QUERY, "DS",
4486 "Ending command buffer with in progress query: queryPool %" PRIu64 ", index %d", (uint64_t)(query.pool), query.index);
4487 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004488 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004489 if (VK_FALSE == skipCall) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004490 result = dev_data->device_dispatch_table->EndCommandBuffer(commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004491 if (VK_SUCCESS == result) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004492 pCB->state = CB_RECORDED;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004493 // Reset CB status flags
4494 pCB->status = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004495 printCB(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004496 }
4497 } else {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004498 result = VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004499 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004500 return result;
4501}
4502
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004503VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags)
4504{
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004505 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004506 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4507 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004508 VkCommandPool cmdPool = pCB->createInfo.commandPool;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004509 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
4510 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t) commandBuffer,
4511 __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
4512 "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.",
4513 (uint64_t) commandBuffer, (uint64_t) cmdPool);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004514 }
Michael Lentine5f6dc4f2016-01-27 20:42:07 -06004515 if (dev_data->globalInFlightCmdBuffers.count(commandBuffer)) {
4516 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t) commandBuffer,
4517 __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
4518 "Attempt to reset command buffer (%#" PRIxLEAST64 ") which is in use.", reinterpret_cast<uint64_t>(commandBuffer));
4519 }
Mark Youngb20a6a82016-01-07 15:41:43 -07004520 if (skipCall != VK_FALSE)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004521 return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004522 VkResult result = dev_data->device_dispatch_table->ResetCommandBuffer(commandBuffer, flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004523 if (VK_SUCCESS == result) {
Tobin Ehlis74714d22016-01-25 15:24:34 -08004524 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004525 resetCB(dev_data, commandBuffer);
Tobin Ehlis74714d22016-01-25 15:24:34 -08004526 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004527 }
4528 return result;
4529}
4530
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004531VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
4532{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004533 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004534 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4535 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004536 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004537 skipCall |= addCmd(dev_data, pCB, CMD_BINDPIPELINE, "vkCmdBindPipeline()");
4538 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
4539 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, (uint64_t) pipeline,
4540 __LINE__, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
4541 "Incorrectly binding compute pipeline (%#" PRIxLEAST64 ") during active RenderPass (%#" PRIxLEAST64 ")",
4542 (uint64_t) pipeline, (uint64_t) pCB->activeRenderPass);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004543 } else if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004544 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdBindPipeline");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004545 }
4546
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004547 PIPELINE_NODE* pPN = getPipeline(dev_data, pipeline);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004548 if (pPN) {
4549 pCB->lastBoundPipeline = pipeline;
4550 loader_platform_thread_lock_mutex(&globalLock);
4551 set_cb_pso_status(pCB, pPN);
4552 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004553 skipCall |= validatePipelineState(dev_data, pCB, pipelineBindPoint, pipeline);
Tobin Ehlisce132d82015-06-19 15:07:05 -06004554 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004555 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
4556 (uint64_t) pipeline, __LINE__, DRAWSTATE_INVALID_PIPELINE, "DS",
4557 "Attempt to bind Pipeline %#" PRIxLEAST64 " that doesn't exist!", (uint64_t)(pipeline));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004558 }
4559 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004560 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004561 dev_data->device_dispatch_table->CmdBindPipeline(commandBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004562}
4563
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004564VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetViewport(
4565 VkCommandBuffer commandBuffer,
4566 uint32_t firstViewport,
4567 uint32_t viewportCount,
4568 const VkViewport* pViewports)
4569{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004570 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004571 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4572 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004573 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004574 skipCall |= addCmd(dev_data, pCB, CMD_SETVIEWPORTSTATE, "vkCmdSetViewport()");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004575 loader_platform_thread_lock_mutex(&globalLock);
4576 pCB->status |= CBSTATUS_VIEWPORT_SET;
4577 pCB->viewports.resize(viewportCount);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004578 memcpy(pCB->viewports.data(), pViewports, viewportCount * sizeof(VkViewport));
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004579 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004580 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004581 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004582 dev_data->device_dispatch_table->CmdSetViewport(commandBuffer, firstViewport, viewportCount, pViewports);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004583}
4584
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004585VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetScissor(
4586 VkCommandBuffer commandBuffer,
4587 uint32_t firstScissor,
4588 uint32_t scissorCount,
4589 const VkRect2D* pScissors)
4590{
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004591 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004592 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4593 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004594 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004595 skipCall |= addCmd(dev_data, pCB, CMD_SETSCISSORSTATE, "vkCmdSetScissor()");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004596 loader_platform_thread_lock_mutex(&globalLock);
4597 pCB->status |= CBSTATUS_SCISSOR_SET;
4598 pCB->scissors.resize(scissorCount);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004599 memcpy(pCB->scissors.data(), pScissors, scissorCount * sizeof(VkRect2D));
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004600 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004601 }
4602 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004603 dev_data->device_dispatch_table->CmdSetScissor(commandBuffer, firstScissor, scissorCount, pScissors);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004604}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004605
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004606VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth)
4607{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004608 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004609 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4610 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004611 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004612 skipCall |= addCmd(dev_data, pCB, CMD_SETLINEWIDTHSTATE, "vkCmdSetLineWidth()");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004613 /* TODO: Do we still need this lock? */
4614 loader_platform_thread_lock_mutex(&globalLock);
4615 pCB->status |= CBSTATUS_LINE_WIDTH_SET;
4616 pCB->lineWidth = lineWidth;
4617 loader_platform_thread_unlock_mutex(&globalLock);
Cody Northrop12365112015-08-17 11:10:49 -06004618 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004619 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004620 dev_data->device_dispatch_table->CmdSetLineWidth(commandBuffer, lineWidth);
Cody Northrop12365112015-08-17 11:10:49 -06004621}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004622
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004623VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBias(
4624 VkCommandBuffer commandBuffer,
4625 float depthBiasConstantFactor,
4626 float depthBiasClamp,
4627 float depthBiasSlopeFactor)
4628{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004629 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004630 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4631 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northrop12365112015-08-17 11:10:49 -06004632 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004633 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBIASSTATE, "vkCmdSetDepthBias()");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004634 pCB->status |= CBSTATUS_DEPTH_BIAS_SET;
4635 pCB->depthBiasConstantFactor = depthBiasConstantFactor;
4636 pCB->depthBiasClamp = depthBiasClamp;
4637 pCB->depthBiasSlopeFactor = depthBiasSlopeFactor;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004638 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004639 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004640 dev_data->device_dispatch_table->CmdSetDepthBias(commandBuffer, depthBiasConstantFactor, depthBiasClamp, depthBiasSlopeFactor);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004641}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004642
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004643VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4])
4644{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004645 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004646 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4647 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004648 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004649 skipCall |= addCmd(dev_data, pCB, CMD_SETBLENDSTATE, "vkCmdSetBlendConstants()");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004650 pCB->status |= CBSTATUS_BLEND_SET;
4651 memcpy(pCB->blendConstants, blendConstants, 4 * sizeof(float));
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004652 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004653 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004654 dev_data->device_dispatch_table->CmdSetBlendConstants(commandBuffer, blendConstants);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004655}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004656
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004657VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBounds(
4658 VkCommandBuffer commandBuffer,
4659 float minDepthBounds,
4660 float maxDepthBounds)
4661{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004662 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004663 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4664 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004665 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004666 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBOUNDSSTATE, "vkCmdSetDepthBounds()");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004667 pCB->status |= CBSTATUS_DEPTH_BOUNDS_SET;
4668 pCB->minDepthBounds = minDepthBounds;
4669 pCB->maxDepthBounds = maxDepthBounds;
Cody Northrop82485a82015-08-18 15:21:16 -06004670 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004671 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004672 dev_data->device_dispatch_table->CmdSetDepthBounds(commandBuffer, minDepthBounds, maxDepthBounds);
Cody Northrop82485a82015-08-18 15:21:16 -06004673}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004674
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004675VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilCompareMask(
4676 VkCommandBuffer commandBuffer,
4677 VkStencilFaceFlags faceMask,
4678 uint32_t compareMask)
4679{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004680 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004681 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4682 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northrop82485a82015-08-18 15:21:16 -06004683 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004684 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREADMASKSTATE, "vkCmdSetStencilCompareMask()");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004685 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4686 pCB->front.compareMask = compareMask;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004687 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004688 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4689 pCB->back.compareMask = compareMask;
4690 }
4691 /* TODO: Do we need to track front and back separately? */
4692 /* TODO: We aren't capturing the faceMask, do we need to? */
4693 pCB->status |= CBSTATUS_STENCIL_READ_MASK_SET;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004694 }
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->CmdSetStencilCompareMask(commandBuffer, faceMask, compareMask);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004697}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004698
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004699VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilWriteMask(
4700 VkCommandBuffer commandBuffer,
4701 VkStencilFaceFlags faceMask,
4702 uint32_t writeMask)
4703{
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004704 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004705 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4706 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004707 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004708 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILWRITEMASKSTATE, "vkCmdSetStencilWriteMask()");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004709 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4710 pCB->front.writeMask = writeMask;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004711 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004712 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4713 pCB->back.writeMask = writeMask;
4714 }
4715 pCB->status |= CBSTATUS_STENCIL_WRITE_MASK_SET;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004716 }
4717 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004718 dev_data->device_dispatch_table->CmdSetStencilWriteMask(commandBuffer, faceMask, writeMask);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004719}
4720
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004721VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilReference(
4722 VkCommandBuffer commandBuffer,
4723 VkStencilFaceFlags faceMask,
4724 uint32_t reference)
4725{
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -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 Goeltzenleuchter49c73082015-09-17 15:06:17 -06004729 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004730 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREFERENCESTATE, "vkCmdSetStencilReference()");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004731 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4732 pCB->front.reference = reference;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004733 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004734 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4735 pCB->back.reference = reference;
4736 }
4737 pCB->status |= CBSTATUS_STENCIL_REFERENCE_SET;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004738 }
4739 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004740 dev_data->device_dispatch_table->CmdSetStencilReference(commandBuffer, faceMask, reference);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004741}
4742
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004743VK_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)
4744{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004745 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004746 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4747 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004748 if (pCB) {
Tobin Ehlisf6585052015-12-17 11:48:42 -07004749 if (pCB->state == CB_RECORDING) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004750 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
4751 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
4752 "Incorrectly binding compute DescriptorSets during active RenderPass (%#" PRIxLEAST64 ")", (uint64_t) pCB->activeRenderPass);
Tobin Ehlisf6585052015-12-17 11:48:42 -07004753 } else if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004754 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdBindDescriptorSets");
Mark Lobodzinski74635932015-12-18 15:35:38 -07004755 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07004756 if (VK_FALSE == skipCall) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004757 // Track total count of dynamic descriptor types to make sure we have an offset for each one
Tobin Ehlisf6585052015-12-17 11:48:42 -07004758 uint32_t totalDynamicDescriptors = 0;
4759 string errorString = "";
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004760 uint32_t lastSetIndex = firstSet+setCount-1;
Tobin Ehlisf6585052015-12-17 11:48:42 -07004761 if (lastSetIndex >= pCB->boundDescriptorSets.size())
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004762 pCB->boundDescriptorSets.resize(lastSetIndex+1);
4763 VkDescriptorSet oldFinalBoundSet = pCB->boundDescriptorSets[lastSetIndex];
4764 for (uint32_t i=0; i<setCount; i++) {
4765 SET_NODE* pSet = getSetNode(dev_data, pDescriptorSets[i]);
Tobin Ehlisf6585052015-12-17 11:48:42 -07004766 if (pSet) {
4767 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlise6e574b2016-01-24 23:25:31 -07004768 pCB->uniqueBoundSets.insert(pDescriptorSets[i]);
4769 pSet->boundCmdBuffers.insert(commandBuffer);
Tobin Ehlisf6585052015-12-17 11:48:42 -07004770 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
4771 pCB->lastBoundPipelineLayout = layout;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004772 pCB->boundDescriptorSets[i+firstSet] = pDescriptorSets[i];
Tobin Ehlisf6585052015-12-17 11:48:42 -07004773 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004774 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",
4775 "DS %#" PRIxLEAST64 " bound on pipeline %s", (uint64_t) pDescriptorSets[i], string_VkPipelineBindPoint(pipelineBindPoint));
4776 if (!pSet->pUpdateStructs && (pSet->descriptorCount != 0)) {
4777 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",
4778 "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 -07004779 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004780 // Verify that set being bound is compatible with overlapping setLayout of pipelineLayout
4781 if (!verify_set_layout_compatibility(dev_data, pSet, layout, i+firstSet, errorString)) {
4782 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",
4783 "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 -07004784 }
4785 if (pSet->pLayout->dynamicDescriptorCount) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004786 // First make sure we won't overstep bounds of pDynamicOffsets array
4787 if ((totalDynamicDescriptors + pSet->pLayout->dynamicDescriptorCount) > dynamicOffsetCount) {
4788 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",
4789 "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.",
4790 i, (uint64_t) pDescriptorSets[i], pSet->pLayout->dynamicDescriptorCount, (dynamicOffsetCount - totalDynamicDescriptors));
4791 } else { // Validate and store dynamic offsets with the set
Mark Lobodzinski941aea92016-01-13 10:23:15 -07004792 // Validate Dynamic Offset Minimums
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004793 uint32_t cur_dyn_offset = totalDynamicDescriptors;
4794 for (uint32_t d = 0; d < pSet->descriptorCount; d++) {
4795 if (pSet->pLayout->descriptorTypes[i] == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) {
Michael Lentine26870f32016-01-26 21:36:08 -06004796 if (vk_safe_modulo(pDynamicOffsets[cur_dyn_offset], dev_data->physDevProperties.properties.limits.minUniformBufferOffsetAlignment) != 0) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004797 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0,
4798 __LINE__, DRAWSTATE_INVALID_UNIFORM_BUFFER_OFFSET, "DS",
4799 "vkCmdBindDescriptorSets(): pDynamicOffsets[%d] is %d but must be a multiple of device limit minUniformBufferOffsetAlignment %#" PRIxLEAST64,
Michael Lentine26870f32016-01-26 21:36:08 -06004800 cur_dyn_offset, pDynamicOffsets[cur_dyn_offset], dev_data->physDevProperties.properties.limits.minUniformBufferOffsetAlignment);
Mark Lobodzinski941aea92016-01-13 10:23:15 -07004801 }
4802 cur_dyn_offset++;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004803 } else if (pSet->pLayout->descriptorTypes[i] == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC) {
Michael Lentine26870f32016-01-26 21:36:08 -06004804 if (vk_safe_modulo(pDynamicOffsets[cur_dyn_offset], dev_data->physDevProperties.properties.limits.minStorageBufferOffsetAlignment) != 0) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004805 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0,
4806 __LINE__, DRAWSTATE_INVALID_STORAGE_BUFFER_OFFSET, "DS",
4807 "vkCmdBindDescriptorSets(): pDynamicOffsets[%d] is %d but must be a multiple of device limit minStorageBufferOffsetAlignment %#" PRIxLEAST64,
Michael Lentine26870f32016-01-26 21:36:08 -06004808 cur_dyn_offset, pDynamicOffsets[cur_dyn_offset], dev_data->physDevProperties.properties.limits.minStorageBufferOffsetAlignment);
Mark Lobodzinski941aea92016-01-13 10:23:15 -07004809 }
4810 cur_dyn_offset++;
4811 }
4812 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004813 // Keep running total of dynamic descriptor count to verify at the end
4814 totalDynamicDescriptors += pSet->pLayout->dynamicDescriptorCount;
Tobin Ehlisf6585052015-12-17 11:48:42 -07004815 }
4816 }
4817 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004818 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",
4819 "Attempt to bind DS %#" PRIxLEAST64 " that doesn't exist!", (uint64_t) pDescriptorSets[i]);
Tobin Ehlisf6585052015-12-17 11:48:42 -07004820 }
4821 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004822 skipCall |= addCmd(dev_data, pCB, CMD_BINDDESCRIPTORSETS, "vkCmdBindDescrsiptorSets()");
4823 // 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 -07004824 if (firstSet > 0) { // Check set #s below the first bound set
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004825 for (uint32_t i=0; i<firstSet; ++i) {
4826 if (pCB->boundDescriptorSets[i] && !verify_set_layout_compatibility(dev_data, dev_data->setMap[pCB->boundDescriptorSets[i]], layout, i, errorString)) {
4827 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",
4828 "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 -07004829 pCB->boundDescriptorSets[i] = VK_NULL_HANDLE;
4830 }
4831 }
4832 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004833 // Check if newly last bound set invalidates any remaining bound sets
4834 if ((pCB->boundDescriptorSets.size()-1) > (lastSetIndex)) {
4835 if (oldFinalBoundSet && !verify_set_layout_compatibility(dev_data, dev_data->setMap[oldFinalBoundSet], layout, lastSetIndex, errorString)) {
4836 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",
4837 "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);
4838 pCB->boundDescriptorSets.resize(lastSetIndex+1);
Tobin Ehlisf6585052015-12-17 11:48:42 -07004839 }
4840 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004841 // dynamicOffsetCount must equal the total number of dynamic descriptors in the sets being bound
Tobin Ehlisf6585052015-12-17 11:48:42 -07004842 if (totalDynamicDescriptors != dynamicOffsetCount) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004843 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",
4844 "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 -07004845 }
Tobin Ehlisd2393772016-01-29 11:50:47 -07004846 if (dynamicOffsetCount) {
4847 // Save dynamicOffsets bound to this CB
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004848 pCB->dynamicOffsets.assign(pDynamicOffsets, pDynamicOffsets + dynamicOffsetCount);
Tobin Ehlisd2393772016-01-29 11:50:47 -07004849 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004850 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07004851 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004852 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindDescriptorSets()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004853 }
4854 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004855 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004856 dev_data->device_dispatch_table->CmdBindDescriptorSets(commandBuffer, pipelineBindPoint, layout, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004857}
4858
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004859VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
4860{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004861 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004862 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4863 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004864 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004865 skipCall |= addCmd(dev_data, pCB, CMD_BINDINDEXBUFFER, "vkCmdBindIndexBuffer()");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004866 VkDeviceSize offset_align = 0;
4867 switch (indexType) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004868 case VK_INDEX_TYPE_UINT16:
4869 offset_align = 2;
4870 break;
4871 case VK_INDEX_TYPE_UINT32:
4872 offset_align = 4;
4873 break;
4874 default:
4875 // ParamChecker should catch bad enum, we'll also throw alignment error below if offset_align stays 0
4876 break;
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004877 }
4878 if (!offset_align || (offset % offset_align)) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004879 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VTX_INDEX_ALIGNMENT_ERROR, "DS",
4880 "vkCmdBindIndexBuffer() offset (%#" PRIxLEAST64 ") does not fall on alignment (%s) boundary.", offset, string_VkIndexType(indexType));
Tobin Ehlis9c536442015-06-19 13:00:59 -06004881 }
Tobin Ehlisc4c23182015-09-17 12:24:13 -06004882 pCB->status |= CBSTATUS_INDEX_BUFFER_BOUND;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004883 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004884 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004885 dev_data->device_dispatch_table->CmdBindIndexBuffer(commandBuffer, buffer, offset, indexType);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004886}
4887
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004888void updateResourceTracking(GLOBAL_CB_NODE* pCB, uint32_t firstBinding, uint32_t bindingCount, const VkBuffer* pBuffers) {
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07004889 uint32_t end = firstBinding + bindingCount;
Michael Lentine700b0aa2015-10-30 17:57:32 -07004890 if (pCB->currentDrawData.buffers.size() < end) {
4891 pCB->currentDrawData.buffers.resize(end);
4892 }
4893 for (uint32_t i = 0; i < bindingCount; ++i) {
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07004894 pCB->currentDrawData.buffers[i + firstBinding] = pBuffers[i];
Michael Lentine700b0aa2015-10-30 17:57:32 -07004895 }
4896}
4897
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004898void updateResourceTrackingOnDraw(GLOBAL_CB_NODE* pCB) {
Michael Lentine700b0aa2015-10-30 17:57:32 -07004899 pCB->drawData.push_back(pCB->currentDrawData);
4900}
4901
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004902VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindVertexBuffers(
4903 VkCommandBuffer commandBuffer,
4904 uint32_t firstBinding,
4905 uint32_t bindingCount,
4906 const VkBuffer *pBuffers,
4907 const VkDeviceSize *pOffsets)
4908{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004909 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004910 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4911 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004912 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004913 addCmd(dev_data, pCB, CMD_BINDVERTEXBUFFER, "vkCmdBindVertexBuffer()");
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07004914 updateResourceTracking(pCB, firstBinding, bindingCount, pBuffers);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004915 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004916 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindVertexBuffer()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004917 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004918 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004919 dev_data->device_dispatch_table->CmdBindVertexBuffers(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004920}
4921
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004922VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance)
4923{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004924 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004925 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4926 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004927 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004928 skipCall |= addCmd(dev_data, pCB, CMD_DRAW, "vkCmdDraw()");
4929 pCB->drawCount[DRAW]++;
4930 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
4931 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004932 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",
4933 "vkCmdDraw() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW]++);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004934 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004935 if (VK_FALSE == skipCall) {
4936 updateResourceTrackingOnDraw(pCB);
4937 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004938 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDraw");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004939 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004940 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004941 dev_data->device_dispatch_table->CmdDraw(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004942}
4943
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004944VK_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)
4945{
4946 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4947 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004948 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004949 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004950 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXED, "vkCmdDrawIndexed()");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004951 pCB->drawCount[DRAW_INDEXED]++;
4952 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
4953 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004954 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",
4955 "vkCmdDrawIndexed() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED]++);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004956 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004957 if (VK_FALSE == skipCall) {
4958 updateResourceTrackingOnDraw(pCB);
4959 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004960 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexed");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004961 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004962 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004963 dev_data->device_dispatch_table->CmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004964}
4965
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004966VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
4967{
4968 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4969 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004970 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004971 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004972 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDIRECT, "vkCmdDrawIndirect()");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004973 pCB->drawCount[DRAW_INDIRECT]++;
4974 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
4975 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004976 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",
4977 "vkCmdDrawIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004978 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004979 if (VK_FALSE == skipCall) {
4980 updateResourceTrackingOnDraw(pCB);
4981 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004982 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndirect");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004983 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004984 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004985 dev_data->device_dispatch_table->CmdDrawIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004986}
4987
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004988VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
4989{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004990 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004991 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4992 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004993 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004994 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXEDINDIRECT, "vkCmdDrawIndexedIndirect()");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004995 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
4996 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
4997 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07004998 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",
4999 "vkCmdDrawIndexedIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005000 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07005001 if (VK_FALSE == skipCall) {
5002 updateResourceTrackingOnDraw(pCB);
5003 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005004 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexedIndirect");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06005005 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005006 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005007 dev_data->device_dispatch_table->CmdDrawIndexedIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005008}
5009
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005010VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z)
5011{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005012 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005013 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5014 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005015 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005016 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCH, "vkCmdDispatch()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005017 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatch");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005018 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005019 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005020 dev_data->device_dispatch_table->CmdDispatch(commandBuffer, x, y, z);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005021}
5022
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005023VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset)
5024{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005025 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005026 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5027 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005028 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005029 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCHINDIRECT, "vkCmdDispatchIndirect()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005030 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatchIndirect");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005031 }
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->CmdDispatchIndirect(commandBuffer, buffer, offset);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005034}
5035
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005036VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
5037{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005038 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005039 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5040 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005041 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005042 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFER, "vkCmdCopyBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005043 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005044 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005045 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005046 dev_data->device_dispatch_table->CmdCopyBuffer(commandBuffer, srcBuffer, dstBuffer, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005047}
5048
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005049VkBool32 VerifySourceImageLayout(VkCommandBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005050 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005051
5052#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
5053 // TODO: Fix -- initialLayout may have been set in a previous command buffer
5054 return skip_call;
5055#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5056
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005057 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5058 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Michael Lentineabc5e922015-10-12 11:30:14 -05005059 auto src_image_element = pCB->imageLayoutMap.find(srcImage);
5060 if (src_image_element == pCB->imageLayoutMap.end()) {
5061 pCB->imageLayoutMap[srcImage].initialLayout = srcImageLayout;
5062 pCB->imageLayoutMap[srcImage].layout = srcImageLayout;
Mark Youngb20a6a82016-01-07 15:41:43 -07005063 return VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05005064 }
5065 if (src_image_element->second.layout != srcImageLayout) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005066 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",
5067 "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 -05005068 }
5069 if (srcImageLayout != VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL) {
5070 if (srcImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005071 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
5072 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
5073 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Michael Lentineabc5e922015-10-12 11:30:14 -05005074 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005075 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
5076 "Layout for input image is %d but can only be TRANSFER_SRC_OPTIMAL or GENERAL.", srcImageLayout);
Michael Lentineabc5e922015-10-12 11:30:14 -05005077 }
5078 }
5079 return skip_call;
5080}
5081
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005082VkBool32 VerifyDestImageLayout(VkCommandBuffer cmdBuffer, VkImage destImage, VkImageLayout destImageLayout) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005083 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005084
5085#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
5086 // TODO: Fix -- initialLayout may have been set in a previous command buffer
5087 return skip_call;
5088#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5089
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005090 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5091 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Michael Lentineabc5e922015-10-12 11:30:14 -05005092 auto dest_image_element = pCB->imageLayoutMap.find(destImage);
5093 if (dest_image_element == pCB->imageLayoutMap.end()) {
5094 pCB->imageLayoutMap[destImage].initialLayout = destImageLayout;
5095 pCB->imageLayoutMap[destImage].layout = destImageLayout;
Mark Youngb20a6a82016-01-07 15:41:43 -07005096 return VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05005097 }
5098 if (dest_image_element->second.layout != destImageLayout) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005099 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",
5100 "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 -05005101 }
5102 if (destImageLayout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) {
5103 if (destImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005104 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
5105 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
5106 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Michael Lentineabc5e922015-10-12 11:30:14 -05005107 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005108 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
5109 "Layout for output image is %d but can only be TRANSFER_DST_OPTIMAL or GENERAL.", destImageLayout);
Michael Lentineabc5e922015-10-12 11:30:14 -05005110 }
5111 }
5112 return skip_call;
5113}
5114
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005115VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImage(VkCommandBuffer commandBuffer,
5116 VkImage srcImage,
5117 VkImageLayout srcImageLayout,
5118 VkImage dstImage,
5119 VkImageLayout dstImageLayout,
5120 uint32_t regionCount, const VkImageCopy* pRegions)
5121{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005122 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005123 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5124 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005125 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005126 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGE, "vkCmdCopyImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005127 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImage");
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005128 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
5129 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005130 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005131 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005132 dev_data->device_dispatch_table->CmdCopyImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005133}
5134
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005135VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBlitImage(VkCommandBuffer commandBuffer,
5136 VkImage srcImage, VkImageLayout srcImageLayout,
5137 VkImage dstImage, VkImageLayout dstImageLayout,
5138 uint32_t regionCount, const VkImageBlit* pRegions,
5139 VkFilter filter)
5140{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005141 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005142 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5143 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06005144 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005145 skipCall |= addCmd(dev_data, pCB, CMD_BLITIMAGE, "vkCmdBlitImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005146 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBlitImage");
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06005147 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005148 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005149 dev_data->device_dispatch_table->CmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter);
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06005150}
5151
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005152VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer,
5153 VkBuffer srcBuffer,
5154 VkImage dstImage, VkImageLayout dstImageLayout,
5155 uint32_t regionCount, const VkBufferImageCopy* pRegions)
5156{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005157 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005158 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5159 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005160 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005161 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFERTOIMAGE, "vkCmdCopyBufferToImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005162 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBufferToImage");
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005163 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005164 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005165 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005166 dev_data->device_dispatch_table->CmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005167}
5168
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005169VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer,
5170 VkImage srcImage, VkImageLayout srcImageLayout,
5171 VkBuffer dstBuffer,
5172 uint32_t regionCount, const VkBufferImageCopy* pRegions)
5173{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005174 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005175 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5176 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005177 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005178 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGETOBUFFER, "vkCmdCopyImageToBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005179 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImageToBuffer");
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005180 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005181 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005182 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005183 dev_data->device_dispatch_table->CmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005184}
5185
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005186VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize dataSize, const uint32_t* pData)
5187{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005188 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005189 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5190 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005191 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005192 skipCall |= addCmd(dev_data, pCB, CMD_UPDATEBUFFER, "vkCmdUpdateBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005193 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyUpdateBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005194 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005195 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005196 dev_data->device_dispatch_table->CmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005197}
5198
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005199VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize size, uint32_t data)
5200{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005201 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005202 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5203 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005204 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005205 skipCall |= addCmd(dev_data, pCB, CMD_FILLBUFFER, "vkCmdFillBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005206 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyFillBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005207 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005208 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005209 dev_data->device_dispatch_table->CmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005210}
5211
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005212VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearAttachments(
5213 VkCommandBuffer commandBuffer,
5214 uint32_t attachmentCount,
5215 const VkClearAttachment* pAttachments,
5216 uint32_t rectCount,
5217 const VkClearRect* pRects)
5218{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005219 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005220 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5221 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06005222 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005223 skipCall |= addCmd(dev_data, pCB, CMD_CLEARATTACHMENTS, "vkCmdClearAttachments()");
5224 // Warn if this is issued prior to Draw Cmd and clearing the entire attachment
5225 if (!hasDrawCmd(pCB) &&
5226 (pCB->activeRenderPassBeginInfo.renderArea.extent.width == pRects[0].rect.extent.width) &&
5227 (pCB->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005228 // TODO : commandBuffer should be srcObj
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005229 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",
5230 "vkCmdClearAttachments() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
5231 " 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 -06005232 }
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06005233 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdClearAttachments");
5234 }
5235
5236 // Validate that attachment is in reference list of active subpass
5237 if (pCB->activeRenderPass) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005238 const VkRenderPassCreateInfo *pRPCI = dev_data->renderPassMap[pCB->activeRenderPass]->pCreateInfo;
5239 const VkSubpassDescription *pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06005240
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005241 for (uint32_t attachment_idx = 0; attachment_idx < attachmentCount; attachment_idx++) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06005242 const VkClearAttachment *attachment = &pAttachments[attachment_idx];
5243 if (attachment->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) {
5244 VkBool32 found = VK_FALSE;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005245 for (uint32_t i = 0; i < pSD->colorAttachmentCount; i++) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005246 if (attachment->colorAttachment == pSD->pColorAttachments[i].attachment) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06005247 found = VK_TRUE;
5248 break;
5249 }
5250 }
5251 if (VK_FALSE == found) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005252 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
5253 (uint64_t)commandBuffer, __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
5254 "vkCmdClearAttachments() attachment index %d not found in attachment reference array of active subpass %d",
5255 attachment->colorAttachment, pCB->activeSubpass);
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06005256 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005257 } else if (attachment->aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) {
5258 if (!pSD->pDepthStencilAttachment || // Says no DS will be used in active subpass
5259 (pSD->pDepthStencilAttachment->attachment == VK_ATTACHMENT_UNUSED)) { // Says no DS will be used in active subpass
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07005260
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005261 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
5262 (uint64_t)commandBuffer, __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
5263 "vkCmdClearAttachments() attachment index %d does not match depthStencilAttachment.attachment (%d) found in active subpass %d",
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07005264 attachment->colorAttachment,
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005265 (pSD->pDepthStencilAttachment) ? pSD->pDepthStencilAttachment->attachment : VK_ATTACHMENT_UNUSED,
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07005266 pCB->activeSubpass);
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06005267 }
5268 }
5269 }
Tobin Ehlis53eddda2015-07-01 16:46:13 -06005270 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005271 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005272 dev_data->device_dispatch_table->CmdClearAttachments(commandBuffer, attachmentCount, pAttachments, rectCount, pRects);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06005273}
5274
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005275VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearColorImage(
5276 VkCommandBuffer commandBuffer,
5277 VkImage image, VkImageLayout imageLayout,
5278 const VkClearColorValue *pColor,
5279 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
5280{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005281 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005282 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5283 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005284 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005285 skipCall |= addCmd(dev_data, pCB, CMD_CLEARCOLORIMAGE, "vkCmdClearColorImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005286 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearColorImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005287 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005288 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005289 dev_data->device_dispatch_table->CmdClearColorImage(commandBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005290}
5291
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005292VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearDepthStencilImage(
5293 VkCommandBuffer commandBuffer,
5294 VkImage image, VkImageLayout imageLayout,
5295 const VkClearDepthStencilValue *pDepthStencil,
5296 uint32_t rangeCount,
5297 const VkImageSubresourceRange* pRanges)
5298{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005299 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005300 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5301 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005302 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005303 skipCall |= addCmd(dev_data, pCB, CMD_CLEARDEPTHSTENCILIMAGE, "vkCmdClearDepthStencilImage()");
5304 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearDepthStencilImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005305 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005306 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005307 dev_data->device_dispatch_table->CmdClearDepthStencilImage(commandBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005308}
5309
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005310VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResolveImage(VkCommandBuffer commandBuffer,
5311 VkImage srcImage, VkImageLayout srcImageLayout,
5312 VkImage dstImage, VkImageLayout dstImageLayout,
5313 uint32_t regionCount, const VkImageResolve* pRegions)
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);
5317 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005318 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005319 skipCall |= addCmd(dev_data, pCB, CMD_RESOLVEIMAGE, "vkCmdResolveImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005320 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResolveImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005321 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005322 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005323 dev_data->device_dispatch_table->CmdResolveImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005324}
5325
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005326VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
5327{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005328 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005329 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5330 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005331 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005332 skipCall |= addCmd(dev_data, pCB, CMD_SETEVENT, "vkCmdSetEvent()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005333 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdSetEvent");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005334 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005335 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005336 dev_data->device_dispatch_table->CmdSetEvent(commandBuffer, event, stageMask);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005337}
5338
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005339VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
5340{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005341 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005342 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5343 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005344 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005345 skipCall |= addCmd(dev_data, pCB, CMD_RESETEVENT, "vkCmdResetEvent()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005346 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResetEvent");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005347 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005348 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005349 dev_data->device_dispatch_table->CmdResetEvent(commandBuffer, event, stageMask);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005350}
5351
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005352VkBool32 TransitionImageLayouts(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const VkImageMemoryBarrier* pImgMemBarriers) {
5353 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5354 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Mark Youngb20a6a82016-01-07 15:41:43 -07005355 VkBool32 skip = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005356
5357#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005358 // TODO: Fix -- pay attention to image subresource ranges -- not all subresources transition at the same time
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005359 return skip;
5360#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5361
Michael Lentineabc5e922015-10-12 11:30:14 -05005362 for (uint32_t i = 0; i < memBarrierCount; ++i) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005363 auto mem_barrier = &pImgMemBarriers[i];
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005364 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005365 auto image_data = pCB->imageLayoutMap.find(mem_barrier->image);
Michael Lentineabc5e922015-10-12 11:30:14 -05005366 if (image_data == pCB->imageLayoutMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005367 pCB->imageLayoutMap[mem_barrier->image].initialLayout = mem_barrier->oldLayout;
5368 pCB->imageLayoutMap[mem_barrier->image].layout = mem_barrier->newLayout;
Michael Lentineabc5e922015-10-12 11:30:14 -05005369 } else {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005370 if (image_data->second.layout != mem_barrier->oldLayout) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005371 skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
5372 "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 -05005373 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07005374 image_data->second.layout = mem_barrier->newLayout;
Michael Lentineabc5e922015-10-12 11:30:14 -05005375 }
5376 }
5377 }
5378 return skip;
5379}
5380
Mark Lobodzinskia3a86112016-01-05 17:17:55 -07005381// Print readable FlagBits in FlagMask
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005382std::string string_VkAccessFlags(VkAccessFlags accessMask)
5383{
Mark Lobodzinskia3a86112016-01-05 17:17:55 -07005384 std::string result;
5385 std::string separator;
5386
5387 if (accessMask == 0) {
5388 result = "[None]";
5389 } else {
5390 result = "[";
5391 for (auto i = 0; i < 32; i++) {
5392 if (accessMask & (1 << i)) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005393 result = result + separator + string_VkAccessFlagBits((VkAccessFlagBits)(1 << i));
Mark Lobodzinskia3a86112016-01-05 17:17:55 -07005394 separator = " | ";
5395 }
5396 }
5397 result = result + "]";
5398 }
5399 return result;
5400}
5401
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005402// AccessFlags MUST have 'required_bit' set, and may have one or more of 'optional_bits' set.
5403// If required_bit is zero, accessMask must have at least one of 'optional_bits' set
5404// TODO: Add tracking to ensure that at least one barrier has been set for these layout transitions
5405VkBool32 ValidateMaskBits(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout,
5406 VkAccessFlags required_bit, VkAccessFlags optional_bits, const char* type) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005407 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005408
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005409 if ((accessMask & required_bit) || (!required_bit && (accessMask & optional_bits))) {
Michael Lentine97eb7462015-11-20 09:48:52 -08005410 if (accessMask & !(required_bit | optional_bits)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005411 // TODO: Verify against Valid Use
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005412 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
5413 "Additional bits in %s accessMask %d %s are specified when layout is %s.",
5414 type, accessMask, string_VkAccessFlags(accessMask).c_str(), string_VkImageLayout(layout));
Michael Lentineecc32b72015-10-16 18:08:09 -05005415 }
5416 } else {
Michael Lentine97eb7462015-11-20 09:48:52 -08005417 if (!required_bit) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005418 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
5419 "%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.",
5420 type, accessMask, string_VkAccessFlags(accessMask).c_str(), optional_bits,
5421 string_VkAccessFlags(optional_bits).c_str(), string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08005422 } else {
Mark Lobodzinskif2cc2a52016-01-05 13:35:29 -07005423 std::string opt_bits;
5424 if (optional_bits != 0) {
Michael Lentine6bd4f122016-01-19 14:00:53 -06005425 std::stringstream ss;
5426 ss << optional_bits;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005427 opt_bits = "and may have optional bits " + ss.str() + ' ' + string_VkAccessFlags(optional_bits);
Mark Lobodzinskif2cc2a52016-01-05 13:35:29 -07005428 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005429 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
5430 "%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.",
5431 type, accessMask, string_VkAccessFlags(accessMask).c_str(),
5432 required_bit, string_VkAccessFlags(required_bit).c_str(),
5433 opt_bits.c_str(), string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08005434 }
Michael Lentineecc32b72015-10-16 18:08:09 -05005435 }
5436 return skip_call;
5437}
5438
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005439VkBool32 ValidateMaskBitsFromLayouts(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout, const char* type) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005440 VkBool32 skip_call = VK_FALSE;
Michael Lentine97eb7462015-11-20 09:48:52 -08005441 switch (layout) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005442 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: {
5443 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_COLOR_ATTACHMENT_READ_BIT, type);
5444 break;
Michael Lentineecc32b72015-10-16 18:08:09 -05005445 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005446 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: {
5447 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT, type);
5448 break;
5449 }
5450 case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: {
5451 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_WRITE_BIT, 0, type);
5452 break;
5453 }
5454 case VK_IMAGE_LAYOUT_PREINITIALIZED: {
5455 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_HOST_WRITE_BIT, 0, type);
5456 break;
5457 }
5458 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: {
5459 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, 0, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT, type);
5460 break;
5461 }
5462 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: {
5463 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, 0, VK_ACCESS_INPUT_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT, type);
5464 break;
5465 }
5466 case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: {
5467 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_READ_BIT, 0, type);
5468 break;
5469 }
5470 case VK_IMAGE_LAYOUT_UNDEFINED: {
5471 if (accessMask != 0) {
5472 // TODO: Verify against Valid Use section spec
5473 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
5474 "Additional bits in %s accessMask %d %s are specified when layout is %s.", type, accessMask, string_VkAccessFlags(accessMask).c_str(),
5475 string_VkImageLayout(layout));
5476 }
5477 break;
5478 }
5479 case VK_IMAGE_LAYOUT_GENERAL:
5480 default: {
5481 break;
5482 }
Michael Lentineecc32b72015-10-16 18:08:09 -05005483 }
5484 return skip_call;
5485}
5486
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005487VkBool32 ValidateBarriers(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const VkMemoryBarrier* pMemBarriers, uint32_t imageMemBarrierCount, const VkImageMemoryBarrier *pImageMemBarriers)
5488{
Mark Youngb20a6a82016-01-07 15:41:43 -07005489 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005490 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5491 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Michael Lentine48930b82015-10-15 17:07:00 -05005492 if (pCB->activeRenderPass && memBarrierCount) {
5493 for (uint32_t i = 0; i < memBarrierCount; ++i) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005494 auto mem_barrier = &pMemBarriers[i];
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005495 if (mem_barrier && mem_barrier->sType != VK_STRUCTURE_TYPE_MEMORY_BARRIER) {
5496 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
5497 "Image or Buffers Barriers cannot be used during a render pass.");
Michael Lentine48930b82015-10-15 17:07:00 -05005498 }
5499 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005500 if (!dev_data->renderPassMap[pCB->activeRenderPass]->hasSelfDependency[pCB->activeSubpass]) {
5501 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
5502 "Barriers cannot be set during subpass %d with no self dependency specified.", pCB->activeSubpass);
Michael Lentine48930b82015-10-15 17:07:00 -05005503 }
5504 }
Mark Lobodzinski73a37ec2015-11-20 09:27:27 -07005505
Jon Ashburnf19916e2016-01-11 13:12:43 -07005506 for (uint32_t i = 0; i < imageMemBarrierCount; ++i) {
5507 auto mem_barrier = &pImageMemBarriers[i];
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005508 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
5509 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, mem_barrier->srcAccessMask, mem_barrier->oldLayout, "Source");
5510 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, mem_barrier->dstAccessMask, mem_barrier->newLayout, "Dest");
Michael Lentineecc32b72015-10-16 18:08:09 -05005511 }
5512 }
Mark Lobodzinski3cba24a2015-12-03 15:42:32 -07005513
Michael Lentine48930b82015-10-15 17:07:00 -05005514 return skip_call;
5515}
5516
Jon Ashburnf19916e2016-01-11 13:12:43 -07005517VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdWaitEvents(
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005518 VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent* pEvents,
5519 VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask,
5520 uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers,
5521 uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers,
5522 uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers)
5523{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005524 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005525 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5526 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005527 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005528 for (uint32_t i = 0; i < eventCount; ++i) {
5529 pCB->waitedEvents.push_back(pEvents[i]);
5530 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005531 if (pCB->state == CB_RECORDING) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005532 skipCall |= addCmd(dev_data, pCB, CMD_WAITEVENTS, "vkCmdWaitEvents()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005533 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005534 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdWaitEvents()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005535 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005536 skipCall |= TransitionImageLayouts(commandBuffer, imageMemoryBarrierCount, pImageMemoryBarriers);
5537 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, pMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005538 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005539 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005540 dev_data->device_dispatch_table->CmdWaitEvents(commandBuffer, eventCount, pEvents, sourceStageMask, dstStageMask,
5541 memoryBarrierCount, pMemoryBarriers,
5542 bufferMemoryBarrierCount, pBufferMemoryBarriers,
5543 imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005544}
5545
Jon Ashburnf19916e2016-01-11 13:12:43 -07005546VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdPipelineBarrier(
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005547 VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask,
5548 VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags,
5549 uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers,
5550 uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers,
5551 uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers)
5552{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005553 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005554 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5555 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005556 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005557 skipCall |= addCmd(dev_data, pCB, CMD_PIPELINEBARRIER, "vkCmdPipelineBarrier()");
5558 skipCall |= TransitionImageLayouts(commandBuffer, imageMemoryBarrierCount, pImageMemoryBarriers);
5559 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, pMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005560 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005561 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005562 dev_data->device_dispatch_table->CmdPipelineBarrier(commandBuffer, srcStageMask, dstStageMask, dependencyFlags,
5563 memoryBarrierCount, pMemoryBarriers,
5564 bufferMemoryBarrierCount, pBufferMemoryBarriers,
5565 imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005566}
5567
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005568VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
5569{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005570 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005571 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5572 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005573 if (pCB) {
Michael Lentinedc6f8de2016-02-02 18:29:30 -06005574 QueryObject query = {queryPool, slot};
5575 pCB->activeQueries.insert(query);
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005576 skipCall |= addCmd(dev_data, pCB, CMD_BEGINQUERY, "vkCmdBeginQuery()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005577 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005578 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005579 dev_data->device_dispatch_table->CmdBeginQuery(commandBuffer, queryPool, slot, flags);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005580}
5581
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005582VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot)
5583{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005584 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005585 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5586 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005587 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005588 QueryObject query = {queryPool, slot};
Michael Lentinedc6f8de2016-02-02 18:29:30 -06005589 if (!pCB->activeQueries.count(query)) {
5590 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_QUERY, "DS",
5591 "Ending a query before it was started: queryPool %" PRIu64 ", index %d", (uint64_t)(queryPool), slot);
5592 } else {
5593 pCB->activeQueries.erase(query);
5594 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06005595 pCB->queryToStateMap[query] = 1;
Mark Lobodzinskice738852016-01-07 10:04:02 -07005596 if (pCB->state == CB_RECORDING) {
5597 skipCall |= addCmd(dev_data, pCB, CMD_ENDQUERY, "VkCmdEndQuery()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005598 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005599 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdEndQuery()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005600 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005601 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005602 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005603 dev_data->device_dispatch_table->CmdEndQuery(commandBuffer, queryPool, slot);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005604}
5605
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005606VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResetQueryPool(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount)
5607{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005608 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005609 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5610 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005611 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005612 for (uint32_t i = 0; i < queryCount; i++) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005613 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06005614 pCB->waitedEventsBeforeQueryReset[query] = pCB->waitedEvents;
5615 pCB->queryToStateMap[query] = 0;
5616 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005617 if (pCB->state == CB_RECORDING) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005618 skipCall |= addCmd(dev_data, pCB, CMD_RESETQUERYPOOL, "VkCmdResetQueryPool()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005619 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005620 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdResetQueryPool()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005621 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005622 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdQueryPool");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005623 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005624 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005625 dev_data->device_dispatch_table->CmdResetQueryPool(commandBuffer, queryPool, firstQuery, queryCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005626}
5627
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005628VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery,
5629 uint32_t queryCount, VkBuffer dstBuffer, VkDeviceSize dstOffset,
5630 VkDeviceSize stride, VkQueryResultFlags flags)
5631{
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005632 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005633 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5634 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005635 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005636 for (uint32_t i = 0; i < queryCount; i++) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005637 QueryObject query = {queryPool, firstQuery + i};
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005638 if(!pCB->queryToStateMap[query]) {
5639 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_QUERY, "DS",
5640 "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 -06005641 }
5642 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005643 if (pCB->state == CB_RECORDING) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005644 skipCall |= addCmd(dev_data, pCB, CMD_COPYQUERYPOOLRESULTS, "vkCmdCopyQueryPoolResults()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005645 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005646 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdCopyQueryPoolResults()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005647 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005648 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyQueryPoolResults");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005649 }
5650 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005651 dev_data->device_dispatch_table->CmdCopyQueryPoolResults(commandBuffer, queryPool,
5652 firstQuery, queryCount, dstBuffer, dstOffset, stride, flags);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005653}
5654
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005655VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, VkQueryPool queryPool, uint32_t slot)
5656{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005657 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005658 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5659 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005660 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005661 QueryObject query = {queryPool, slot};
5662 pCB->queryToStateMap[query] = 1;
Mark Lobodzinskice738852016-01-07 10:04:02 -07005663 if (pCB->state == CB_RECORDING) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005664 skipCall |= addCmd(dev_data, pCB, CMD_WRITETIMESTAMP, "vkCmdWriteTimestamp()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005665 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005666 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdWriteTimestamp()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005667 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005668 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005669 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005670 dev_data->device_dispatch_table->CmdWriteTimestamp(commandBuffer, pipelineStage, queryPool, slot);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005671}
5672
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005673VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkFramebuffer* pFramebuffer)
5674{
5675 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5676 VkResult result = dev_data->device_dispatch_table->CreateFramebuffer(device, pCreateInfo, pAllocator, pFramebuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005677 if (VK_SUCCESS == result) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06005678 // Shadow create info and store in map
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005679 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +08005680 if (pCreateInfo->pAttachments) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005681 localFBCI->pAttachments = new VkImageView[localFBCI->attachmentCount];
5682 memcpy((void*)localFBCI->pAttachments, pCreateInfo->pAttachments, localFBCI->attachmentCount*sizeof(VkImageView));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005683 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08005684 dev_data->frameBufferMap[*pFramebuffer] = localFBCI;
Tobin Ehliseba312c2015-04-01 08:40:34 -06005685 }
5686 return result;
5687}
5688
Michael Lentineb6986752015-10-06 14:56:18 -07005689// Store the DAG.
5690struct DAGNode {
5691 uint32_t pass;
5692 std::vector<uint32_t> prev;
5693 std::vector<uint32_t> next;
5694};
5695
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005696VkBool32 FindDependency(const int index, const int dependent, const std::vector<DAGNode>& subpass_to_node, std::unordered_set<uint32_t>& processed_nodes) {
5697 // If we have already checked this node we have not found a dependency path so return false.
Michael Lentineb6986752015-10-06 14:56:18 -07005698 if (processed_nodes.count(index))
Mark Youngb20a6a82016-01-07 15:41:43 -07005699 return VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005700 processed_nodes.insert(index);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005701 const DAGNode& node = subpass_to_node[index];
5702 // Look for a dependency path. If one exists return true else recurse on the previous nodes.
5703 if (std::find(node.prev.begin(), node.prev.end(), dependent) == node.prev.end()) {
Michael Lentineb6986752015-10-06 14:56:18 -07005704 for (auto elem : node.prev) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005705 if (FindDependency(elem, dependent, subpass_to_node, processed_nodes))
Mark Youngb20a6a82016-01-07 15:41:43 -07005706 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005707 }
5708 } else {
Mark Youngb20a6a82016-01-07 15:41:43 -07005709 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005710 }
Mark Youngb20a6a82016-01-07 15:41:43 -07005711 return VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005712}
5713
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005714VkBool32 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 -07005715 VkBool32 result = VK_TRUE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005716 // Loop through all subpasses that share the same attachment and make sure a dependency exists
Michael Lentineb6986752015-10-06 14:56:18 -07005717 for (uint32_t k = 0; k < dependent_subpasses.size(); ++k) {
5718 if (subpass == dependent_subpasses[k])
5719 continue;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005720 const DAGNode& node = subpass_to_node[subpass];
5721 // Check for a specified dependency between the two nodes. If one exists we are done.
5722 auto prev_elem = std::find(node.prev.begin(), node.prev.end(), dependent_subpasses[k]);
5723 auto next_elem = std::find(node.next.begin(), node.next.end(), dependent_subpasses[k]);
Michael Lentineb6986752015-10-06 14:56:18 -07005724 if (prev_elem == node.prev.end() && next_elem == node.next.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005725 // 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 -07005726 std::unordered_set<uint32_t> processed_nodes;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005727 if (FindDependency(subpass, dependent_subpasses[k], subpass_to_node, processed_nodes) ||
5728 FindDependency(dependent_subpasses[k], subpass, subpass_to_node, processed_nodes)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005729 // TODO: Verify against Valid Use section of spec
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005730 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
5731 "A dependency between subpasses %d and %d must exist but only an implicit one is specified.",
5732 subpass, dependent_subpasses[k]);
Michael Lentineb6986752015-10-06 14:56:18 -07005733 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005734 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
5735 "A dependency between subpasses %d and %d must exist but one is not specified.",
5736 subpass, dependent_subpasses[k]);
Mark Youngb20a6a82016-01-07 15:41:43 -07005737 result = VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005738 }
5739 }
5740 }
5741 return result;
5742}
5743
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005744VkBool32 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) {
5745 const DAGNode& node = subpass_to_node[index];
5746 // If this node writes to the attachment return true as next nodes need to preserve the attachment.
5747 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005748 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005749 if (attachment == subpass.pColorAttachments[j].attachment)
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005750 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005751 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005752 if (subpass.pDepthStencilAttachment &&
5753 subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
5754 if (attachment == subpass.pDepthStencilAttachment->attachment)
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005755 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005756 }
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005757 VkBool32 result = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005758 // Loop through previous nodes and see if any of them write to the attachment.
Michael Lentineb6986752015-10-06 14:56:18 -07005759 for (auto elem : node.prev) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005760 result |= CheckPreserved(my_data, device, pCreateInfo, elem, attachment, subpass_to_node, depth + 1, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005761 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005762 // If the attachment was written to by a previous node than this node needs to preserve it.
Michael Lentineb6986752015-10-06 14:56:18 -07005763 if (result && depth > 0) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005764 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Mark Youngb20a6a82016-01-07 15:41:43 -07005765 VkBool32 has_preserved = VK_FALSE;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005766 for (uint32_t j = 0; j < subpass.preserveAttachmentCount; ++j) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005767 if (subpass.pPreserveAttachments[j] == attachment) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005768 has_preserved = VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005769 break;
5770 }
5771 }
Mark Youngb20a6a82016-01-07 15:41:43 -07005772 if (has_preserved == VK_FALSE) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005773 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
5774 "Attachment %d is used by a later subpass and must be preserved in subpass %d.", attachment, index);
Michael Lentineb6986752015-10-06 14:56:18 -07005775 }
5776 }
5777 return result;
5778}
5779
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005780VkBool32 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 -07005781 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005782 std::vector<std::vector<uint32_t>> output_attachment_to_subpass(pCreateInfo->attachmentCount);
5783 std::vector<std::vector<uint32_t>> input_attachment_to_subpass(pCreateInfo->attachmentCount);
Michael Lentineb6986752015-10-06 14:56:18 -07005784 // Find for each attachment the subpasses that use them.
5785 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005786 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005787 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005788 input_attachment_to_subpass[subpass.pInputAttachments[j].attachment].push_back(i);
Michael Lentineb6986752015-10-06 14:56:18 -07005789 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08005790 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005791 output_attachment_to_subpass[subpass.pColorAttachments[j].attachment].push_back(i);
Michael Lentineb6986752015-10-06 14:56:18 -07005792 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005793 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
5794 output_attachment_to_subpass[subpass.pDepthStencilAttachment->attachment].push_back(i);
Michael Lentineb6986752015-10-06 14:56:18 -07005795 }
5796 }
5797 // If there is a dependency needed make sure one exists
5798 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005799 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
5800 // If the attachment is an input then all subpasses that output must have a dependency relationship
Chia-I Wud50a7d72015-10-26 20:48:51 +08005801 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005802 const uint32_t& attachment = subpass.pInputAttachments[j].attachment;
5803 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005804 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005805 // 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 +08005806 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005807 const uint32_t& attachment = subpass.pColorAttachments[j].attachment;
5808 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
5809 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005810 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005811 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
5812 const uint32_t& attachment = subpass.pDepthStencilAttachment->attachment;
5813 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
5814 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005815 }
5816 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005817 // 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 -07005818 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005819 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005820 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005821 CheckPreserved(my_data, device, pCreateInfo, i, subpass.pInputAttachments[j].attachment, subpass_to_node, 0, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005822 }
5823 }
5824 return skip_call;
5825}
5826
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005827VkBool32 ValidateLayouts(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005828 VkBool32 skip = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005829
5830#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
5831 return skip;
5832#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5833
Michael Lentineabc5e922015-10-12 11:30:14 -05005834 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005835 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Michael Lentineabc5e922015-10-12 11:30:14 -05005836 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005837 if (subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL &&
5838 subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) {
5839 if (subpass.pInputAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
5840 // TODO: Verify Valid Use in spec. I believe this is allowed (valid) but may not be optimal performance
5841 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
5842 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Michael Lentineabc5e922015-10-12 11:30:14 -05005843 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005844 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
5845 "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 -05005846 }
5847 }
5848 }
5849 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005850 if (subpass.pColorAttachments[j].layout != VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) {
5851 if (subpass.pColorAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
5852 // TODO: Verify Valid Use in spec. I believe this is allowed (valid) but may not be optimal performance
5853 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
5854 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Michael Lentineabc5e922015-10-12 11:30:14 -05005855 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005856 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
5857 "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 -05005858 }
5859 }
5860 }
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005861 if ((subpass.pDepthStencilAttachment != NULL) &&
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005862 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
5863 if (subpass.pDepthStencilAttachment->layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) {
5864 if (subpass.pDepthStencilAttachment->layout == VK_IMAGE_LAYOUT_GENERAL) {
5865 // TODO: Verify Valid Use in spec. I believe this is allowed (valid) but may not be optimal performance
5866 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
5867 "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL.");
Michael Lentineabc5e922015-10-12 11:30:14 -05005868 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005869 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
5870 "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 -05005871 }
5872 }
5873 }
5874 }
5875 return skip;
5876}
5877
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005878VkBool32 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 -07005879 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05005880 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005881 DAGNode& subpass_node = subpass_to_node[i];
Michael Lentineabc5e922015-10-12 11:30:14 -05005882 subpass_node.pass = i;
5883 }
5884 for (uint32_t i = 0; i < pCreateInfo->dependencyCount; ++i) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005885 const VkSubpassDependency& dependency = pCreateInfo->pDependencies[i];
5886 if (dependency.srcSubpass > dependency.dstSubpass && dependency.srcSubpass != VK_SUBPASS_EXTERNAL && dependency.dstSubpass != VK_SUBPASS_EXTERNAL) {
5887 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
5888 "Depedency graph must be specified such that an earlier pass cannot depend on a later pass.");
5889 } else if (dependency.srcSubpass == VK_SUBPASS_EXTERNAL && dependency.dstSubpass == VK_SUBPASS_EXTERNAL) {
5890 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
5891 "The src and dest subpasses cannot both be external.");
Michael Lentine48930b82015-10-15 17:07:00 -05005892 } else if (dependency.srcSubpass == dependency.dstSubpass) {
5893 has_self_dependency[dependency.srcSubpass] = true;
Michael Lentineabc5e922015-10-12 11:30:14 -05005894 }
Michael Lentine6bd4f122016-01-19 14:00:53 -06005895 if (dependency.dstSubpass != VK_SUBPASS_EXTERNAL) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005896 subpass_to_node[dependency.dstSubpass].prev.push_back(dependency.srcSubpass);
Michael Lentine6bd4f122016-01-19 14:00:53 -06005897 }
5898 if (dependency.srcSubpass != VK_SUBPASS_EXTERNAL) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005899 subpass_to_node[dependency.srcSubpass].next.push_back(dependency.dstSubpass);
Michael Lentine6bd4f122016-01-19 14:00:53 -06005900 }
Michael Lentineabc5e922015-10-12 11:30:14 -05005901 }
5902 return skip_call;
5903}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005904// TODOSC : Add intercept of vkCreateShaderModule
Michael Lentineabc5e922015-10-12 11:30:14 -05005905
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005906VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateShaderModule(
5907 VkDevice device,
5908 const VkShaderModuleCreateInfo *pCreateInfo,
5909 const VkAllocationCallbacks* pAllocator,
5910 VkShaderModule *pShaderModule)
5911{
5912 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07005913 VkBool32 skip_call = VK_FALSE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005914 if (!shader_is_spirv(pCreateInfo)) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005915 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
5916 /* dev */ 0, __LINE__, SHADER_CHECKER_NON_SPIRV_SHADER, "SC",
5917 "Shader is not SPIR-V");
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005918 }
5919
Mark Youngb20a6a82016-01-07 15:41:43 -07005920 if (VK_FALSE != skip_call)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005921 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005922
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005923 VkResult res = my_data->device_dispatch_table->CreateShaderModule(device, pCreateInfo, pAllocator, pShaderModule);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005924
5925 if (res == VK_SUCCESS) {
5926 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005927 my_data->shaderModuleMap[*pShaderModule] = new shader_module(pCreateInfo);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005928 loader_platform_thread_unlock_mutex(&globalLock);
5929 }
5930 return res;
5931}
5932
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005933VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkRenderPass* pRenderPass)
5934{
Mark Youngb20a6a82016-01-07 15:41:43 -07005935 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005936 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentineabc5e922015-10-12 11:30:14 -05005937 // Create DAG
Michael Lentine48930b82015-10-15 17:07:00 -05005938 std::vector<bool> has_self_dependency(pCreateInfo->subpassCount);
Michael Lentineabc5e922015-10-12 11:30:14 -05005939 std::vector<DAGNode> subpass_to_node(pCreateInfo->subpassCount);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005940 skip_call |= CreatePassDAG(dev_data, device, pCreateInfo, subpass_to_node, has_self_dependency);
Michael Lentineabc5e922015-10-12 11:30:14 -05005941 // Validate using DAG
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005942 skip_call |= ValidateDependencies(dev_data, device, pCreateInfo, subpass_to_node);
Michael Lentineabc5e922015-10-12 11:30:14 -05005943 skip_call |= ValidateLayouts(dev_data, device, pCreateInfo);
Mark Youngb20a6a82016-01-07 15:41:43 -07005944 if (VK_FALSE != skip_call) {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005945 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentineb6986752015-10-06 14:56:18 -07005946 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005947 VkResult result = dev_data->device_dispatch_table->CreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005948 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005949 // TODOSC : Merge in tracking of renderpass from ShaderChecker
Tobin Ehliseba312c2015-04-01 08:40:34 -06005950 // Shadow create info and store in map
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005951 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +08005952 if (pCreateInfo->pAttachments) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005953 localRPCI->pAttachments = new VkAttachmentDescription[localRPCI->attachmentCount];
5954 memcpy((void*)localRPCI->pAttachments, pCreateInfo->pAttachments, localRPCI->attachmentCount*sizeof(VkAttachmentDescription));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005955 }
Chia-I Wu08accc62015-07-07 11:50:03 +08005956 if (pCreateInfo->pSubpasses) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005957 localRPCI->pSubpasses = new VkSubpassDescription[localRPCI->subpassCount];
5958 memcpy((void*)localRPCI->pSubpasses, pCreateInfo->pSubpasses, localRPCI->subpassCount*sizeof(VkSubpassDescription));
Chia-I Wu08accc62015-07-07 11:50:03 +08005959
5960 for (uint32_t i = 0; i < localRPCI->subpassCount; i++) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005961 VkSubpassDescription *subpass = (VkSubpassDescription *) &localRPCI->pSubpasses[i];
5962 const uint32_t attachmentCount = subpass->inputAttachmentCount +
5963 subpass->colorAttachmentCount * (1 + (subpass->pResolveAttachments?1:0)) +
5964 ((subpass->pDepthStencilAttachment) ? 1 : 0) + subpass->preserveAttachmentCount;
5965 VkAttachmentReference *attachments = new VkAttachmentReference[attachmentCount];
Chia-I Wu08accc62015-07-07 11:50:03 +08005966
Cody Northropa505dda2015-08-04 11:16:41 -06005967 memcpy(attachments, subpass->pInputAttachments,
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005968 sizeof(attachments[0]) * subpass->inputAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005969 subpass->pInputAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005970 attachments += subpass->inputAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005971
Cody Northropa505dda2015-08-04 11:16:41 -06005972 memcpy(attachments, subpass->pColorAttachments,
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005973 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005974 subpass->pColorAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005975 attachments += subpass->colorAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005976
Cody Northropa505dda2015-08-04 11:16:41 -06005977 if (subpass->pResolveAttachments) {
5978 memcpy(attachments, subpass->pResolveAttachments,
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005979 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005980 subpass->pResolveAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005981 attachments += subpass->colorAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005982 }
5983
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005984 if (subpass->pDepthStencilAttachment) {
5985 memcpy(attachments, subpass->pDepthStencilAttachment,
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005986 sizeof(attachments[0]) * 1);
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005987 subpass->pDepthStencilAttachment = attachments;
5988 attachments += 1;
5989 }
5990
Cody Northropa505dda2015-08-04 11:16:41 -06005991 memcpy(attachments, subpass->pPreserveAttachments,
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005992 sizeof(attachments[0]) * subpass->preserveAttachmentCount);
Jon Ashburnf19916e2016-01-11 13:12:43 -07005993 subpass->pPreserveAttachments = &attachments->attachment;
Chia-I Wu08accc62015-07-07 11:50:03 +08005994 }
Tobin Ehliseba312c2015-04-01 08:40:34 -06005995 }
Chia-I Wu08accc62015-07-07 11:50:03 +08005996 if (pCreateInfo->pDependencies) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07005997 localRPCI->pDependencies = new VkSubpassDependency[localRPCI->dependencyCount];
5998 memcpy((void*)localRPCI->pDependencies, pCreateInfo->pDependencies, localRPCI->dependencyCount*sizeof(VkSubpassDependency));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005999 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006000 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07006001 dev_data->renderPassMap[*pRenderPass] = new RENDER_PASS_NODE(localRPCI);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006002 dev_data->renderPassMap[*pRenderPass]->hasSelfDependency = has_self_dependency;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006003 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehliseba312c2015-04-01 08:40:34 -06006004 }
6005 return result;
6006}
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06006007// Free the renderpass shadow
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006008static void deleteRenderPasses(layer_data* my_data)
6009{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06006010 if (my_data->renderPassMap.size() <= 0)
6011 return;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006012 for (auto ii=my_data->renderPassMap.begin(); ii!=my_data->renderPassMap.end(); ++ii) {
6013 const VkRenderPassCreateInfo* pRenderPassInfo = (*ii).second->pCreateInfo;
Michael Lentine48930b82015-10-15 17:07:00 -05006014 if (pRenderPassInfo->pAttachments) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006015 delete[] pRenderPassInfo->pAttachments;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06006016 }
Michael Lentine48930b82015-10-15 17:07:00 -05006017 if (pRenderPassInfo->pSubpasses) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006018 for (uint32_t i=0; i<pRenderPassInfo->subpassCount; ++i) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06006019 // Attachements are all allocated in a block, so just need to
6020 // find the first non-null one to delete
Michael Lentine48930b82015-10-15 17:07:00 -05006021 if (pRenderPassInfo->pSubpasses[i].pInputAttachments) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006022 delete[] pRenderPassInfo->pSubpasses[i].pInputAttachments;
Michael Lentine48930b82015-10-15 17:07:00 -05006023 } else if (pRenderPassInfo->pSubpasses[i].pColorAttachments) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006024 delete[] pRenderPassInfo->pSubpasses[i].pColorAttachments;
Michael Lentine48930b82015-10-15 17:07:00 -05006025 } else if (pRenderPassInfo->pSubpasses[i].pResolveAttachments) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006026 delete[] pRenderPassInfo->pSubpasses[i].pResolveAttachments;
6027 } else if (pRenderPassInfo->pSubpasses[i].pPreserveAttachments) {
6028 delete[] pRenderPassInfo->pSubpasses[i].pPreserveAttachments;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06006029 }
6030 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006031 delete[] pRenderPassInfo->pSubpasses;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06006032 }
Michael Lentine48930b82015-10-15 17:07:00 -05006033 if (pRenderPassInfo->pDependencies) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006034 delete[] pRenderPassInfo->pDependencies;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06006035 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07006036 delete pRenderPassInfo;
Michael Lentine48930b82015-10-15 17:07:00 -05006037 delete (*ii).second;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06006038 }
6039 my_data->renderPassMap.clear();
6040}
Michael Lentineabc5e922015-10-12 11:30:14 -05006041
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006042VkBool32 VerifyFramebufferAndRenderPassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
Mark Youngb20a6a82016-01-07 15:41:43 -07006043 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006044 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
6045 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
6046 const VkRenderPassCreateInfo* pRenderPassInfo = dev_data->renderPassMap[pRenderPassBegin->renderPass]->pCreateInfo;
6047 const VkFramebufferCreateInfo* pFramebufferInfo = dev_data->frameBufferMap[pRenderPassBegin->framebuffer];
Michael Lentineabc5e922015-10-12 11:30:14 -05006048 if (pRenderPassInfo->attachmentCount != pFramebufferInfo->attachmentCount) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006049 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
6050 "You cannot start a render pass using a framebuffer with a different number of attachments.");
Michael Lentineabc5e922015-10-12 11:30:14 -05006051 }
6052 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006053 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
6054 const VkImage& image = dev_data->imageViewMap[image_view]->image;
Michael Lentineabc5e922015-10-12 11:30:14 -05006055 auto image_data = pCB->imageLayoutMap.find(image);
6056 if (image_data == pCB->imageLayoutMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006057 pCB->imageLayoutMap[image].initialLayout = pRenderPassInfo->pAttachments[i].initialLayout;
6058 pCB->imageLayoutMap[image].layout = pRenderPassInfo->pAttachments[i].initialLayout;
6059 } else if (pRenderPassInfo->pAttachments[i].initialLayout != image_data->second.layout) {
6060 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
6061 "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 -05006062 }
6063 }
6064 return skip_call;
6065}
6066
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006067void TransitionSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, const int subpass_index) {
6068 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
6069 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
6070 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
Michael Lentineabc5e922015-10-12 11:30:14 -05006071 if (render_pass_data == dev_data->renderPassMap.end()) {
6072 return;
6073 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006074 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
6075 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
Michael Lentineabc5e922015-10-12 11:30:14 -05006076 if (framebuffer_data == dev_data->frameBufferMap.end()) {
6077 return;
6078 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006079 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
6080 const VkSubpassDescription& subpass = pRenderPassInfo->pSubpasses[subpass_index];
Michael Lentineabc5e922015-10-12 11:30:14 -05006081 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006082 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pInputAttachments[j].attachment];
Michael Lentineabc5e922015-10-12 11:30:14 -05006083 auto image_view_data = dev_data->imageViewMap.find(image_view);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006084 if (image_view_data != dev_data->imageViewMap.end()) {
6085 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
Michael Lentineabc5e922015-10-12 11:30:14 -05006086 if (image_layout != pCB->imageLayoutMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006087 image_layout->second.layout = subpass.pInputAttachments[j].layout;
Michael Lentineabc5e922015-10-12 11:30:14 -05006088 }
6089 }
6090 }
6091 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006092 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pColorAttachments[j].attachment];
Michael Lentineabc5e922015-10-12 11:30:14 -05006093 auto image_view_data = dev_data->imageViewMap.find(image_view);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006094 if (image_view_data != dev_data->imageViewMap.end()) {
6095 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
Michael Lentineabc5e922015-10-12 11:30:14 -05006096 if (image_layout != pCB->imageLayoutMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006097 image_layout->second.layout = subpass.pColorAttachments[j].layout;
Michael Lentineabc5e922015-10-12 11:30:14 -05006098 }
6099 }
6100 }
Michael Lentine3dea6512015-10-28 15:55:18 -07006101 if ((subpass.pDepthStencilAttachment != NULL) &&
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06006102 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006103 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pDepthStencilAttachment->attachment];
Michael Lentineabc5e922015-10-12 11:30:14 -05006104 auto image_view_data = dev_data->imageViewMap.find(image_view);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006105 if (image_view_data != dev_data->imageViewMap.end()) {
6106 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
Michael Lentineabc5e922015-10-12 11:30:14 -05006107 if (image_layout != pCB->imageLayoutMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006108 image_layout->second.layout = subpass.pDepthStencilAttachment->layout;
Michael Lentineabc5e922015-10-12 11:30:14 -05006109 }
6110 }
6111 }
6112}
6113
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006114VkBool32 validatePrimaryCommandBuffer(const layer_data* my_data, const GLOBAL_CB_NODE* pCB, const std::string& cmd_name) {
Mark Youngb20a6a82016-01-07 15:41:43 -07006115 VkBool32 skip_call = VK_FALSE;
Michael Lentine3dea6512015-10-28 15:55:18 -07006116 if (pCB->createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006117 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER, "DS",
6118 "Cannot execute command %s on a secondary command buffer.", cmd_name.c_str());
Michael Lentine3dea6512015-10-28 15:55:18 -07006119 }
6120 return skip_call;
6121}
6122
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006123void TransitionFinalSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
6124 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
6125 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
6126 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
Michael Lentineabc5e922015-10-12 11:30:14 -05006127 if (render_pass_data == dev_data->renderPassMap.end()) {
6128 return;
6129 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006130 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
6131 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
Michael Lentineabc5e922015-10-12 11:30:14 -05006132 if (framebuffer_data == dev_data->frameBufferMap.end()) {
6133 return;
6134 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006135 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
Michael Lentineabc5e922015-10-12 11:30:14 -05006136 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006137 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
Michael Lentineabc5e922015-10-12 11:30:14 -05006138 auto image_view_data = dev_data->imageViewMap.find(image_view);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006139 if (image_view_data != dev_data->imageViewMap.end()) {
6140 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
Michael Lentineabc5e922015-10-12 11:30:14 -05006141 if (image_layout != pCB->imageLayoutMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006142 image_layout->second.layout = pRenderPassInfo->pAttachments[i].finalLayout;
Michael Lentineabc5e922015-10-12 11:30:14 -05006143 }
6144 }
6145 }
6146}
6147
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006148VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, VkSubpassContents contents)
6149{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006150 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006151 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
6152 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006153 if (pCB) {
Tobin Ehlis259730a2015-06-23 16:13:03 -06006154 if (pRenderPassBegin && pRenderPassBegin->renderPass) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006155 skipCall |= VerifyFramebufferAndRenderPassLayouts(commandBuffer, pRenderPassBegin);
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06006156 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBeginRenderPass");
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006157 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdBeginRenderPass");
6158 skipCall |= addCmd(dev_data, pCB, CMD_BEGINRENDERPASS, "vkCmdBeginRenderPass()");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06006159 pCB->activeRenderPass = pRenderPassBegin->renderPass;
Michael Lentineabc5e922015-10-12 11:30:14 -05006160 // This is a shallow copy as that is all that is needed for now
6161 pCB->activeRenderPassBeginInfo = *pRenderPassBegin;
Mark Lobodzinski5495d132015-09-30 16:19:16 -06006162 pCB->activeSubpass = 0;
Michael Lentine2e068b22015-12-29 16:05:27 -06006163 pCB->activeSubpassContents = contents;
Mark Lobodzinski5495d132015-09-30 16:19:16 -06006164 pCB->framebuffer = pRenderPassBegin->framebuffer;
Tobin Ehlis502480b2015-06-24 15:53:07 -06006165 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006166 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
6167 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tony Barbourbadda992015-04-06 11:09:26 -06006168 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006169 }
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06006170 if (VK_FALSE == skipCall) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006171 dev_data->device_dispatch_table->CmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents);
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06006172 // This is a shallow copy as that is all that is needed for now
6173 dev_data->renderPassBeginInfo = *pRenderPassBegin;
6174 dev_data->currentSubpass = 0;
6175 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006176}
6177
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006178VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents)
6179{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006180 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006181 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
6182 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
6183 TransitionSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo, ++dev_data->currentSubpass);
Chia-I Wu08accc62015-07-07 11:50:03 +08006184 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006185 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdNextSubpass");
6186 skipCall |= addCmd(dev_data, pCB, CMD_NEXTSUBPASS, "vkCmdNextSubpass()");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06006187 pCB->activeSubpass++;
Michael Lentine2e068b22015-12-29 16:05:27 -06006188 pCB->activeSubpassContents = contents;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006189 TransitionSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo, pCB->activeSubpass);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06006190 if (pCB->lastBoundPipeline) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006191 skipCall |= validatePipelineState(dev_data, pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Chia-I Wu08accc62015-07-07 11:50:03 +08006192 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06006193 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdNextSubpass");
Chia-I Wu08accc62015-07-07 11:50:03 +08006194 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006195 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006196 dev_data->device_dispatch_table->CmdNextSubpass(commandBuffer, contents);
Chia-I Wu08accc62015-07-07 11:50:03 +08006197}
6198
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006199VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndRenderPass(VkCommandBuffer commandBuffer)
6200{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006201 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006202 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
6203 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
6204 TransitionFinalSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006205 if (pCB) {
Michael Lentine3dea6512015-10-28 15:55:18 -07006206 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdEndRenderpass");
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006207 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdEndRenderPass");
6208 skipCall |= addCmd(dev_data, pCB, CMD_ENDRENDERPASS, "vkCmdEndRenderPass()");
6209 TransitionFinalSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06006210 pCB->activeRenderPass = 0;
6211 pCB->activeSubpass = 0;
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08006212 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006213 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006214 dev_data->device_dispatch_table->CmdEndRenderPass(commandBuffer);
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08006215}
6216
Michael Lentine3124af62016-02-02 14:26:02 -06006217bool logInvalidAttachmentMessage(layer_data* dev_data, VkCommandBuffer secondaryBuffer, VkRenderPass secondaryPass, VkRenderPass primaryPass, uint32_t primaryAttach, uint32_t secondaryAttach, const char* msg) {
6218 return log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_SECONDARY_COMMAND_BUFFER, "DS",
6219 "vkCmdExecuteCommands() called w/ invalid Cmd Buffer %p which has a render pass %" PRIx64 " that is not compatible with the current render pass %" PRIx64 "."
6220 "Attachment %" PRIu32 " is not compatable with %" PRIu32 ". %s",
6221 (void*)secondaryBuffer, reinterpret_cast<uint64_t>(secondaryPass), reinterpret_cast<uint64_t>(primaryPass), primaryAttach, secondaryAttach, msg);
6222}
6223
6224bool validateAttachmentCompatibility(layer_data* dev_data, VkCommandBuffer primaryBuffer, VkRenderPass primaryPass, uint32_t primaryAttach, VkCommandBuffer secondaryBuffer, VkRenderPass secondaryPass, uint32_t secondaryAttach, bool is_multi) {
6225 bool skip_call = false;
6226 auto primary_data = dev_data->renderPassMap.find(primaryPass);
6227 auto secondary_data = dev_data->renderPassMap.find(secondaryPass);
6228 if (primary_data->second->pCreateInfo->attachmentCount <= primaryAttach) {
6229 primaryAttach = VK_ATTACHMENT_UNUSED;
6230 }
6231 if (secondary_data->second->pCreateInfo->attachmentCount <= secondaryAttach) {
6232 secondaryAttach = VK_ATTACHMENT_UNUSED;
6233 }
6234 if (primaryAttach == VK_ATTACHMENT_UNUSED && secondaryAttach == VK_ATTACHMENT_UNUSED) {
6235 return skip_call;
6236 }
6237 if (primaryAttach == VK_ATTACHMENT_UNUSED) {
6238 skip_call |= logInvalidAttachmentMessage(dev_data, secondaryBuffer, secondaryPass, primaryPass, primaryAttach, secondaryAttach, "The first is unused while the second is not.");
6239 return skip_call;
6240 }
6241 if (secondaryAttach == VK_ATTACHMENT_UNUSED) {
6242 skip_call |= logInvalidAttachmentMessage(dev_data, secondaryBuffer, secondaryPass, primaryPass, primaryAttach, secondaryAttach, "The second is unused while the first is not.");
6243 return skip_call;
6244 }
6245 if (primary_data->second->pCreateInfo->pAttachments[primaryAttach].format != secondary_data->second->pCreateInfo->pAttachments[secondaryAttach].format) {
6246 skip_call |= logInvalidAttachmentMessage(dev_data, secondaryBuffer, secondaryPass, primaryPass, primaryAttach, secondaryAttach, "They have different formats.");
6247 }
6248 if (primary_data->second->pCreateInfo->pAttachments[primaryAttach].samples != secondary_data->second->pCreateInfo->pAttachments[secondaryAttach].samples) {
6249 skip_call |= logInvalidAttachmentMessage(dev_data, secondaryBuffer, secondaryPass, primaryPass, primaryAttach, secondaryAttach, "They have different samples.");
6250 }
6251 if (is_multi && primary_data->second->pCreateInfo->pAttachments[primaryAttach].flags != secondary_data->second->pCreateInfo->pAttachments[secondaryAttach].flags) {
6252 skip_call |= logInvalidAttachmentMessage(dev_data, secondaryBuffer, secondaryPass, primaryPass, primaryAttach, secondaryAttach, "They have different flags.");
6253 }
6254 return skip_call;
6255}
6256
6257bool validateSubpassCompatibility(layer_data* dev_data, VkCommandBuffer primaryBuffer, VkRenderPass primaryPass, VkCommandBuffer secondaryBuffer, VkRenderPass secondaryPass, const int subpass, bool is_multi) {
6258 bool skip_call = false;
6259 auto primary_data = dev_data->renderPassMap.find(primaryPass);
6260 auto secondary_data = dev_data->renderPassMap.find(secondaryPass);
6261 const VkSubpassDescription& primary_desc = primary_data->second->pCreateInfo->pSubpasses[subpass];
6262 const VkSubpassDescription& secondary_desc = secondary_data->second->pCreateInfo->pSubpasses[subpass];
6263 uint32_t maxInputAttachmentCount = std::max(primary_desc.inputAttachmentCount, secondary_desc.inputAttachmentCount);
6264 for (uint32_t i = 0; i < maxInputAttachmentCount; ++i) {
6265 uint32_t primary_input_attach = VK_ATTACHMENT_UNUSED, secondary_input_attach = VK_ATTACHMENT_UNUSED;
6266 if (i < primary_desc.inputAttachmentCount) {
6267 primary_input_attach = primary_desc.pInputAttachments[i].attachment;
6268 }
6269 if (i < secondary_desc.inputAttachmentCount) {
6270 secondary_input_attach = secondary_desc.pInputAttachments[i].attachment;
6271 }
6272 skip_call |= validateAttachmentCompatibility(dev_data, primaryBuffer, primaryPass, primary_input_attach, secondaryBuffer, secondaryPass, secondary_input_attach, is_multi);
6273 }
6274 maxInputAttachmentCount = std::max(primary_desc.colorAttachmentCount, secondary_desc.colorAttachmentCount);
6275 for (uint32_t i = 0; i < maxInputAttachmentCount; ++i) {
6276 uint32_t primary_color_attach = VK_ATTACHMENT_UNUSED, secondary_color_attach = VK_ATTACHMENT_UNUSED;
6277 if (i < primary_desc.colorAttachmentCount) {
6278 primary_color_attach = primary_desc.pColorAttachments[i].attachment;
6279 }
6280 if (i < secondary_desc.inputAttachmentCount) {
6281 secondary_color_attach = secondary_desc.pColorAttachments[i].attachment;
6282 }
6283 skip_call |= validateAttachmentCompatibility(dev_data, primaryBuffer, primaryPass, primary_color_attach, secondaryBuffer, secondaryPass, secondary_color_attach, is_multi);
6284 uint32_t primary_resolve_attach = VK_ATTACHMENT_UNUSED, secondary_resolve_attach = VK_ATTACHMENT_UNUSED;
6285 if (i < primary_desc.colorAttachmentCount && primary_desc.pResolveAttachments) {
6286 primary_resolve_attach = primary_desc.pResolveAttachments[i].attachment;
6287 }
6288 if (i < secondary_desc.inputAttachmentCount && secondary_desc.pResolveAttachments) {
6289 secondary_resolve_attach = secondary_desc.pResolveAttachments[i].attachment;
6290 }
6291 skip_call |= validateAttachmentCompatibility(dev_data, primaryBuffer, primaryPass, primary_resolve_attach, secondaryBuffer, secondaryPass, secondary_resolve_attach, is_multi);
6292 }
6293 uint32_t primary_depthstencil_attach = VK_ATTACHMENT_UNUSED, secondary_depthstencil_attach = VK_ATTACHMENT_UNUSED;
6294 if (primary_desc.pDepthStencilAttachment) {
6295 primary_depthstencil_attach = primary_desc.pDepthStencilAttachment[0].attachment;
6296 }
6297 if (secondary_desc.pDepthStencilAttachment) {
6298 secondary_depthstencil_attach = secondary_desc.pDepthStencilAttachment[0].attachment;
6299 }
6300 skip_call |= validateAttachmentCompatibility(dev_data, primaryBuffer, primaryPass, primary_depthstencil_attach, secondaryBuffer, secondaryPass, secondary_depthstencil_attach, is_multi);
6301 return skip_call;
6302}
6303
6304bool validateRenderPassCompatibility(layer_data* dev_data, VkCommandBuffer primaryBuffer, VkRenderPass primaryPass, VkCommandBuffer secondaryBuffer, VkRenderPass secondaryPass) {
6305 bool skip_call = false;
6306 auto primary_data = dev_data->renderPassMap.find(primaryPass);
6307 auto secondary_data = dev_data->renderPassMap.find(secondaryPass);
6308 if (primary_data == dev_data->renderPassMap.end() || primary_data->second == nullptr) {
6309 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_SECONDARY_COMMAND_BUFFER, "DS",
6310 "vkCmdExecuteCommands() called w/ invalid current Cmd Buffer %p which has invalid render pass %" PRIx64 ".",
6311 (void*)primaryBuffer, reinterpret_cast<uint64_t>(primaryPass));
6312 return skip_call;
6313 }
6314 if (secondary_data == dev_data->renderPassMap.end() || secondary_data->second == nullptr) {
6315 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_SECONDARY_COMMAND_BUFFER, "DS",
6316 "vkCmdExecuteCommands() called w/ invalid secondary Cmd Buffer %p which has invalid render pass %" PRIx64 ".",
6317 (void*)secondaryBuffer, reinterpret_cast<uint64_t>(secondaryPass));
6318 return skip_call;
6319 }
6320 if (primary_data->second->pCreateInfo->subpassCount != secondary_data->second->pCreateInfo->subpassCount) {
6321 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_SECONDARY_COMMAND_BUFFER, "DS",
6322 "vkCmdExecuteCommands() called w/ invalid Cmd Buffer %p which has a render pass %" PRIx64 " that is not compatible with the current render pass %" PRIx64 "."
6323 "They have a different number of subpasses.",
6324 (void*)secondaryBuffer, reinterpret_cast<uint64_t>(secondaryPass), reinterpret_cast<uint64_t>(primaryPass));
6325 return skip_call;
6326 }
6327 bool is_multi = primary_data->second->pCreateInfo->subpassCount > 1;
6328 for (uint32_t i = 0; i < primary_data->second->pCreateInfo->subpassCount; ++i) {
6329 skip_call |= validateSubpassCompatibility(dev_data, primaryBuffer, primaryPass, secondaryBuffer, secondaryPass, i, is_multi);
6330 }
6331 return skip_call;
6332}
6333
Michael Lentinef6592ef2016-02-02 15:24:27 -06006334bool validateFramebuffer(layer_data* dev_data, VkCommandBuffer primaryBuffer, const GLOBAL_CB_NODE* pCB, VkCommandBuffer secondaryBuffer, const GLOBAL_CB_NODE* pSubCB) {
6335 bool skip_call = false;
6336 if (!pSubCB->beginInfo.pInheritanceInfo) {
6337 return skip_call;
6338 }
6339 VkFramebuffer primary_fb = pCB->framebuffer;
6340 VkFramebuffer secondary_fb = pSubCB->beginInfo.pInheritanceInfo->framebuffer;
Michael Lentine3009b622016-02-02 16:47:58 -06006341 if (secondary_fb != VK_NULL_HANDLE) {
6342 if (primary_fb != secondary_fb) {
6343 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_SECONDARY_COMMAND_BUFFER, "DS",
6344 "vkCmdExecuteCommands() called w/ invalid Cmd Buffer %p which has a framebuffer %" PRIx64 " that is not compatible with the current framebuffer %" PRIx64 ".",
6345 (void*)secondaryBuffer, reinterpret_cast<uint64_t>(secondary_fb), reinterpret_cast<uint64_t>(primary_fb));
6346 }
6347 auto fb_data = dev_data->frameBufferMap.find(secondary_fb);
6348 if (fb_data == dev_data->frameBufferMap.end() || !fb_data->second) {
6349 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_SECONDARY_COMMAND_BUFFER, "DS",
6350 "vkCmdExecuteCommands() called w/ invalid Cmd Buffer %p which has invalid framebuffer %" PRIx64 ".",
6351 (void*)secondaryBuffer, reinterpret_cast<uint64_t>(secondary_fb));
6352 return skip_call;
6353 }
6354 skip_call |= validateRenderPassCompatibility(dev_data, secondaryBuffer, fb_data->second->renderPass, secondaryBuffer, pSubCB->beginInfo.pInheritanceInfo->renderPass);
Michael Lentinef6592ef2016-02-02 15:24:27 -06006355 }
6356 return skip_call;
6357}
6358
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006359VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount, const VkCommandBuffer* pCommandBuffers)
6360{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006361 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006362 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
6363 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08006364 if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006365 GLOBAL_CB_NODE* pSubCB = NULL;
6366 for (uint32_t i=0; i<commandBuffersCount; i++) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006367 pSubCB = getCBNode(dev_data, pCommandBuffers[i]);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06006368 if (!pSubCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006369 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_SECONDARY_COMMAND_BUFFER, "DS",
6370 "vkCmdExecuteCommands() called w/ invalid Cmd Buffer %p in element %u of pCommandBuffers array.", (void*)pCommandBuffers[i], i);
6371 } else if (VK_COMMAND_BUFFER_LEVEL_PRIMARY == pSubCB->createInfo.level) {
6372 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_SECONDARY_COMMAND_BUFFER, "DS",
6373 "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);
6374 } else if (pCB->activeRenderPass) { // Secondary CB w/i RenderPass must have *CONTINUE_BIT set
6375 if (!(pSubCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT)) {
6376 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",
6377 "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 -06006378 } else {
6379 // Make sure render pass is compatible with parent command buffer pass if has continue
6380 skipCall |= validateRenderPassCompatibility(dev_data, commandBuffer, pCB->activeRenderPass, pCommandBuffers[i], pSubCB->beginInfo.pInheritanceInfo->renderPass);
Michael Lentinef6592ef2016-02-02 15:24:27 -06006381 skipCall |= validateFramebuffer(dev_data, commandBuffer, pCB, pCommandBuffers[i], pSubCB);
Tobin Ehlis651d9b02015-12-16 05:01:22 -07006382 }
6383 string errorString = "";
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006384 if (!verify_renderpass_compatibility(dev_data, pCB->activeRenderPass, pSubCB->beginInfo.pInheritanceInfo->renderPass, errorString)) {
6385 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",
6386 "vkCmdExecuteCommands(): Secondary Command Buffer (%p) w/ render pass (%#" PRIxLEAST64 ") is incompatible w/ primary command buffer (%p) w/ render pass (%#" PRIxLEAST64 ") due to: %s",
6387 (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 -07006388 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006389 // If framebuffer for secondary CB is not NULL, then it must match FB from vkCmdBeginRenderPass()
6390 // 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 -07006391 if (pSubCB->beginInfo.pInheritanceInfo->framebuffer) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006392 if (pSubCB->beginInfo.pInheritanceInfo->framebuffer != pCB->activeRenderPassBeginInfo.framebuffer) {
6393 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",
6394 "vkCmdExecuteCommands(): Secondary Command Buffer (%p) references framebuffer (%#" PRIxLEAST64 ") that does not match framebuffer (%#" PRIxLEAST64 ") in active renderpass (%#" PRIxLEAST64 ").",
6395 (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 -07006396 }
6397 }
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06006398 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006399 // Secondary cmdBuffers are considered pending execution starting w/ being recorded
6400 if (!(pSubCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT)) {
6401 if (dev_data->globalInFlightCmdBuffers.find(pSubCB->commandBuffer) != dev_data->globalInFlightCmdBuffers.end()) {
6402 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)(pCB->commandBuffer), __LINE__, DRAWSTATE_INVALID_CB_SIMULTANEOUS_USE, "DS",
6403 "Attempt to simultaneously execute CB %#" PRIxLEAST64 " w/o VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!", (uint64_t)(pCB->commandBuffer));
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07006404 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006405 if (pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT) {
6406 // Warn that non-simultaneous secondary cmd buffer renders primary non-simultaneous
6407 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",
6408 "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.",
6409 (uint64_t)(pCommandBuffers[i]), (uint64_t)(pCB->commandBuffer));
6410 pCB->beginInfo.flags &= ~VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07006411 }
6412 }
6413 pCB->secondaryCommandBuffers.insert(pSubCB->commandBuffer);
Tobin Ehlis74714d22016-01-25 15:24:34 -08006414 dev_data->globalInFlightCmdBuffers.insert(pSubCB->commandBuffer);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06006415 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006416 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdExecuteComands");
6417 skipCall |= addCmd(dev_data, pCB, CMD_EXECUTECOMMANDS, "vkCmdExecuteComands()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006418 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006419 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006420 dev_data->device_dispatch_table->CmdExecuteCommands(commandBuffer, commandBuffersCount, pCommandBuffers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006421}
6422
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07006423VkBool32 ValidateMapImageLayouts(VkDevice device, VkDeviceMemory mem) {
Mark Youngb20a6a82016-01-07 15:41:43 -07006424 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006425 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentine7b236262015-10-23 12:41:44 -07006426 auto mem_data = dev_data->memImageMap.find(mem);
6427 if (mem_data != dev_data->memImageMap.end()) {
6428 auto image_data = dev_data->imageLayoutMap.find(mem_data->second);
6429 if (image_data != dev_data->imageLayoutMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006430 if (image_data->second->layout != VK_IMAGE_LAYOUT_PREINITIALIZED && image_data->second->layout != VK_IMAGE_LAYOUT_GENERAL) {
6431 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
6432 "Cannot map an image with layout %d. Only GENERAL or PREINITIALIZED are supported.", image_data->second->layout);
Michael Lentine7b236262015-10-23 12:41:44 -07006433 }
6434 }
6435 }
6436 return skip_call;
6437}
6438
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006439VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkMapMemory(
6440 VkDevice device,
6441 VkDeviceMemory mem,
6442 VkDeviceSize offset,
6443 VkDeviceSize size,
6444 VkFlags flags,
6445 void **ppData)
6446{
6447 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006448
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07006449 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006450#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
6451 skip_call = ValidateMapImageLayouts(device, mem);
6452#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
6453
Michael Lentine7b236262015-10-23 12:41:44 -07006454 if (VK_FALSE == skip_call) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006455 return dev_data->device_dispatch_table->MapMemory(device, mem, offset, size, flags, ppData);
Michael Lentine7b236262015-10-23 12:41:44 -07006456 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07006457 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine7b236262015-10-23 12:41:44 -07006458}
6459
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006460VKAPI_ATTR VkResult VKAPI_CALL vkBindImageMemory(
6461 VkDevice device,
6462 VkImage image,
6463 VkDeviceMemory mem,
6464 VkDeviceSize memOffset)
6465{
6466 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6467 VkResult result = dev_data->device_dispatch_table->BindImageMemory(device, image, mem, memOffset);
Michael Lentine7b236262015-10-23 12:41:44 -07006468 loader_platform_thread_lock_mutex(&globalLock);
6469 dev_data->memImageMap[mem] = image;
6470 loader_platform_thread_unlock_mutex(&globalLock);
6471 return result;
6472}
6473
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006474
Michael Lentineb887b0a2015-12-29 14:12:11 -06006475VKAPI_ATTR VkResult VKAPI_CALL vkSetEvent(VkDevice device, VkEvent event) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006476 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentineb887b0a2015-12-29 14:12:11 -06006477 dev_data->eventMap[event].needsSignaled = false;
6478 VkResult result = dev_data->device_dispatch_table->SetEvent(device, event);
6479 return result;
6480}
6481
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006482VKAPI_ATTR VkResult VKAPI_CALL vkQueueBindSparse(
6483 VkQueue queue,
6484 uint32_t bindInfoCount,
6485 const VkBindSparseInfo* pBindInfo,
6486 VkFence fence)
6487{
6488 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07006489 VkBool32 skip_call = VK_FALSE;
Michael Lentine15a47882016-01-06 10:05:48 -06006490
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006491 for (uint32_t bindIdx=0; bindIdx < bindInfoCount; ++bindIdx) {
6492 const VkBindSparseInfo& bindInfo = pBindInfo[bindIdx];
6493 for (uint32_t i=0; i < bindInfo.waitSemaphoreCount; ++i) {
Michael Lentine15a47882016-01-06 10:05:48 -06006494 if (dev_data->semaphoreSignaledMap[bindInfo.pWaitSemaphores[i]]) {
6495 dev_data->semaphoreSignaledMap[bindInfo.pWaitSemaphores[i]] = 0;
6496 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006497 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",
6498 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
6499 (uint64_t)(queue), (uint64_t)(bindInfo.pWaitSemaphores[i]));
Michael Lentine15a47882016-01-06 10:05:48 -06006500 }
6501 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006502 for (uint32_t i=0; i < bindInfo.signalSemaphoreCount; ++i) {
Michael Lentine15a47882016-01-06 10:05:48 -06006503 dev_data->semaphoreSignaledMap[bindInfo.pSignalSemaphores[i]] = 1;
6504 }
6505 }
6506
Mark Youngb20a6a82016-01-07 15:41:43 -07006507 if (VK_FALSE == skip_call)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006508 return dev_data->device_dispatch_table->QueueBindSparse(queue, bindInfoCount, pBindInfo, fence);
Mark Youngb20a6a82016-01-07 15:41:43 -07006509 else
6510 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine15a47882016-01-06 10:05:48 -06006511}
6512
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006513VKAPI_ATTR VkResult VKAPI_CALL vkCreateSemaphore(
6514 VkDevice device,
6515 const VkSemaphoreCreateInfo* pCreateInfo,
6516 const VkAllocationCallbacks* pAllocator,
6517 VkSemaphore* pSemaphore)
6518{
6519 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6520 VkResult result = dev_data->device_dispatch_table->CreateSemaphore(device, pCreateInfo, pAllocator, pSemaphore);
Michael Lentine15a47882016-01-06 10:05:48 -06006521 if (result == VK_SUCCESS) {
6522 dev_data->semaphoreSignaledMap[*pSemaphore] = 0;
6523 }
Tobin Ehlis51b78af2016-01-06 10:27:47 -07006524 return result;
Michael Lentine15a47882016-01-06 10:05:48 -06006525}
6526
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006527VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(
6528 VkDevice device,
6529 const VkSwapchainCreateInfoKHR *pCreateInfo,
6530 const VkAllocationCallbacks *pAllocator,
6531 VkSwapchainKHR *pSwapchain)
6532{
6533 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6534 VkResult result = dev_data->device_dispatch_table->CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
Michael Lentineabc5e922015-10-12 11:30:14 -05006535
6536 if (VK_SUCCESS == result) {
Tobin Ehlis75cd1c52016-01-21 10:21:04 -07006537 SWAPCHAIN_NODE *swapchain_data = new SWAPCHAIN_NODE(pCreateInfo);
Michael Lentineabc5e922015-10-12 11:30:14 -05006538 loader_platform_thread_lock_mutex(&globalLock);
6539 dev_data->device_extensions.swapchainMap[*pSwapchain] = swapchain_data;
6540 loader_platform_thread_unlock_mutex(&globalLock);
6541 }
6542
6543 return result;
6544}
6545
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006546VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR(
6547 VkDevice device,
6548 VkSwapchainKHR swapchain,
6549 const VkAllocationCallbacks *pAllocator)
6550{
6551 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentineabc5e922015-10-12 11:30:14 -05006552
6553 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006554 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(swapchain);
Michael Lentineabc5e922015-10-12 11:30:14 -05006555 if (swapchain_data != dev_data->device_extensions.swapchainMap.end()) {
6556 if (swapchain_data->second->images.size() > 0) {
6557 for (auto swapchain_image : swapchain_data->second->images) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006558 auto image_item = dev_data->imageLayoutMap.find(swapchain_image);
Michael Lentineabc5e922015-10-12 11:30:14 -05006559 if (image_item != dev_data->imageLayoutMap.end())
6560 dev_data->imageLayoutMap.erase(image_item);
6561 }
6562 }
6563 delete swapchain_data->second;
6564 dev_data->device_extensions.swapchainMap.erase(swapchain);
6565 }
6566 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006567 return dev_data->device_dispatch_table->DestroySwapchainKHR(device, swapchain, pAllocator);
Michael Lentineabc5e922015-10-12 11:30:14 -05006568}
6569
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006570VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR(
6571 VkDevice device,
6572 VkSwapchainKHR swapchain,
6573 uint32_t* pCount,
6574 VkImage* pSwapchainImages)
6575{
6576 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6577 VkResult result = dev_data->device_dispatch_table->GetSwapchainImagesKHR(device, swapchain, pCount, pSwapchainImages);
Michael Lentineabc5e922015-10-12 11:30:14 -05006578
6579 if (result == VK_SUCCESS && pSwapchainImages != NULL) {
6580 // This should never happen and is checked by param checker.
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006581 if (!pCount) return result;
Michael Lentineabc5e922015-10-12 11:30:14 -05006582 for (uint32_t i = 0; i < *pCount; ++i) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006583 IMAGE_NODE* image_node = new IMAGE_NODE;
Michael Lentineabc5e922015-10-12 11:30:14 -05006584 image_node->layout = VK_IMAGE_LAYOUT_UNDEFINED;
6585 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006586 auto swapchain_node = dev_data->device_extensions.swapchainMap[swapchain];
Tobin Ehlis75cd1c52016-01-21 10:21:04 -07006587 image_node->format = swapchain_node->createInfo.imageFormat;
6588 swapchain_node->images.push_back(pSwapchainImages[i]);
Michael Lentineabc5e922015-10-12 11:30:14 -05006589 dev_data->imageLayoutMap[pSwapchainImages[i]] = image_node;
6590 loader_platform_thread_unlock_mutex(&globalLock);
6591 }
6592 }
6593 return result;
6594}
6595
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006596VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo)
6597{
6598 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07006599 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05006600
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006601#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentineabc5e922015-10-12 11:30:14 -05006602 if (pPresentInfo) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006603 for (uint32_t i=0; i < pPresentInfo->waitSemaphoreCount; ++i) {
6604 if (dev_data->semaphoreSignaledMap[pPresentInfo->pWaitSemaphores[i]]) {
6605 dev_data->semaphoreSignaledMap[pPresentInfo->pWaitSemaphores[i]] = 0;
Michael Lentine15a47882016-01-06 10:05:48 -06006606 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006607 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",
6608 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
6609 (uint64_t)(queue), (uint64_t)(pPresentInfo->pWaitSemaphores[i]));
Michael Lentine15a47882016-01-06 10:05:48 -06006610 }
6611 }
Michael Lentineabc5e922015-10-12 11:30:14 -05006612 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006613 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(pPresentInfo->pSwapchains[i]);
6614 if (swapchain_data != dev_data->device_extensions.swapchainMap.end() && pPresentInfo->pImageIndices[i] < swapchain_data->second->images.size()) {
6615 VkImage image = swapchain_data->second->images[pPresentInfo->pImageIndices[i]];
Michael Lentineabc5e922015-10-12 11:30:14 -05006616 auto image_data = dev_data->imageLayoutMap.find(image);
6617 if (image_data != dev_data->imageLayoutMap.end()) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006618 if (image_data->second->layout != VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) {
6619 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",
6620 "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 -05006621 }
6622 }
6623 }
6624 }
6625 }
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006626#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentineabc5e922015-10-12 11:30:14 -05006627
6628 if (VK_FALSE == skip_call)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006629 return dev_data->device_dispatch_table->QueuePresentKHR(queue, pPresentInfo);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07006630 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentineabc5e922015-10-12 11:30:14 -05006631}
6632
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006633VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImageKHR(
6634 VkDevice device,
6635 VkSwapchainKHR swapchain,
6636 uint64_t timeout,
6637 VkSemaphore semaphore,
6638 VkFence fence,
6639 uint32_t* pImageIndex)
6640{
6641 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6642 VkResult result = dev_data->device_dispatch_table->AcquireNextImageKHR(device, swapchain, timeout, semaphore, fence, pImageIndex);
Michael Lentine15a47882016-01-06 10:05:48 -06006643 dev_data->semaphoreSignaledMap[semaphore] = 1;
Tobin Ehlis51b78af2016-01-06 10:27:47 -07006644 return result;
Michael Lentine15a47882016-01-06 10:05:48 -06006645}
6646
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006647VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006648 VkInstance instance,
6649 const VkDebugReportCallbackCreateInfoEXT* pCreateInfo,
6650 const VkAllocationCallbacks* pAllocator,
6651 VkDebugReportCallbackEXT* pMsgCallback)
6652{
6653 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006654 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006655 VkResult res = pTable->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06006656 if (VK_SUCCESS == res) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006657 res = layer_create_msg_callback(my_data->report_data, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06006658 }
6659 return res;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006660}
6661
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006662VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(
6663 VkInstance instance,
6664 VkDebugReportCallbackEXT msgCallback,
6665 const VkAllocationCallbacks* pAllocator)
6666{
6667 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006668 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006669 pTable->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006670 layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006671}
6672
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006673VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDebugReportMessageEXT(
6674 VkInstance instance,
6675 VkDebugReportFlagsEXT flags,
6676 VkDebugReportObjectTypeEXT objType,
6677 uint64_t object,
6678 size_t location,
6679 int32_t msgCode,
6680 const char* pLayerPrefix,
6681 const char* pMsg)
6682{
6683 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
6684 my_data->instance_dispatch_table->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg);
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07006685}
6686
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006687VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerBegin(VkCommandBuffer commandBuffer, const char* pMarker)
6688{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006689 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006690 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
6691 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis0b632332015-10-07 09:38:40 -06006692 if (!dev_data->device_extensions.debug_marker_enabled) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006693 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",
6694 "Attempt to use CmdDbgMarkerBegin but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06006695 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06006696 } else if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006697 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKERBEGIN, "vkCmdDbgMarkerBegin()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006698 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006699 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006700 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerBegin(commandBuffer, pMarker);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006701}
6702
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006703VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerEnd(VkCommandBuffer commandBuffer)
6704{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006705 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006706 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
6707 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis0b632332015-10-07 09:38:40 -06006708 if (!dev_data->device_extensions.debug_marker_enabled) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006709 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",
6710 "Attempt to use CmdDbgMarkerEnd but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06006711 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06006712 } else if (pCB) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006713 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKEREND, "vkCmdDbgMarkerEnd()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006714 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006715 if (VK_FALSE == skipCall)
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006716 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerEnd(commandBuffer);
Jon Ashburneab34492015-06-01 09:37:38 -06006717}
6718
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006719VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
6720{
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006721 if (!strcmp(funcName, "vkGetDeviceProcAddr"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006722 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006723 if (!strcmp(funcName, "vkDestroyDevice"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006724 return (PFN_vkVoidFunction) vkDestroyDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006725 if (!strcmp(funcName, "vkQueueSubmit"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006726 return (PFN_vkVoidFunction) vkQueueSubmit;
Michael Lentine700b0aa2015-10-30 17:57:32 -07006727 if (!strcmp(funcName, "vkWaitForFences"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006728 return (PFN_vkVoidFunction) vkWaitForFences;
Michael Lentine700b0aa2015-10-30 17:57:32 -07006729 if (!strcmp(funcName, "vkGetFenceStatus"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006730 return (PFN_vkVoidFunction) vkGetFenceStatus;
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07006731 if (!strcmp(funcName, "vkQueueWaitIdle"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006732 return (PFN_vkVoidFunction) vkQueueWaitIdle;
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07006733 if (!strcmp(funcName, "vkDeviceWaitIdle"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006734 return (PFN_vkVoidFunction) vkDeviceWaitIdle;
Michael Lentine700b0aa2015-10-30 17:57:32 -07006735 if (!strcmp(funcName, "vkGetDeviceQueue"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006736 return (PFN_vkVoidFunction) vkGetDeviceQueue;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006737 if (!strcmp(funcName, "vkDestroyInstance"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006738 return (PFN_vkVoidFunction) vkDestroyInstance;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006739 if (!strcmp(funcName, "vkDestroyDevice"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006740 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006741 if (!strcmp(funcName, "vkDestroyFence"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006742 return (PFN_vkVoidFunction) vkDestroyFence;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006743 if (!strcmp(funcName, "vkDestroySemaphore"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006744 return (PFN_vkVoidFunction) vkDestroySemaphore;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006745 if (!strcmp(funcName, "vkDestroyEvent"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006746 return (PFN_vkVoidFunction) vkDestroyEvent;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006747 if (!strcmp(funcName, "vkDestroyQueryPool"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006748 return (PFN_vkVoidFunction) vkDestroyQueryPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006749 if (!strcmp(funcName, "vkDestroyBuffer"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006750 return (PFN_vkVoidFunction) vkDestroyBuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006751 if (!strcmp(funcName, "vkDestroyBufferView"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006752 return (PFN_vkVoidFunction) vkDestroyBufferView;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006753 if (!strcmp(funcName, "vkDestroyImage"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006754 return (PFN_vkVoidFunction) vkDestroyImage;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006755 if (!strcmp(funcName, "vkDestroyImageView"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006756 return (PFN_vkVoidFunction) vkDestroyImageView;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006757 if (!strcmp(funcName, "vkDestroyShaderModule"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006758 return (PFN_vkVoidFunction) vkDestroyShaderModule;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006759 if (!strcmp(funcName, "vkDestroyPipeline"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006760 return (PFN_vkVoidFunction) vkDestroyPipeline;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006761 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006762 return (PFN_vkVoidFunction) vkDestroyPipelineLayout;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006763 if (!strcmp(funcName, "vkDestroySampler"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006764 return (PFN_vkVoidFunction) vkDestroySampler;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006765 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006766 return (PFN_vkVoidFunction) vkDestroyDescriptorSetLayout;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006767 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006768 return (PFN_vkVoidFunction) vkDestroyDescriptorPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006769 if (!strcmp(funcName, "vkDestroyFramebuffer"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006770 return (PFN_vkVoidFunction) vkDestroyFramebuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006771 if (!strcmp(funcName, "vkDestroyRenderPass"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006772 return (PFN_vkVoidFunction) vkDestroyRenderPass;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006773 if (!strcmp(funcName, "vkCreateBuffer"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006774 return (PFN_vkVoidFunction) vkCreateBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006775 if (!strcmp(funcName, "vkCreateBufferView"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006776 return (PFN_vkVoidFunction) vkCreateBufferView;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006777 if (!strcmp(funcName, "vkCreateImage"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006778 return (PFN_vkVoidFunction) vkCreateImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006779 if (!strcmp(funcName, "vkCreateImageView"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006780 return (PFN_vkVoidFunction) vkCreateImageView;
Michael Lentine37767342016-02-02 22:24:26 -06006781 if (!strcmp(funcName, "vkCreateFence"))
6782 return (PFN_vkVoidFunction) vkCreateFence;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006783 if (!strcmp(funcName, "CreatePipelineCache"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006784 return (PFN_vkVoidFunction) vkCreatePipelineCache;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006785 if (!strcmp(funcName, "DestroyPipelineCache"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006786 return (PFN_vkVoidFunction) vkDestroyPipelineCache;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006787 if (!strcmp(funcName, "GetPipelineCacheData"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006788 return (PFN_vkVoidFunction) vkGetPipelineCacheData;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006789 if (!strcmp(funcName, "MergePipelineCaches"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006790 return (PFN_vkVoidFunction) vkMergePipelineCaches;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006791 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006792 return (PFN_vkVoidFunction) vkCreateGraphicsPipelines;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07006793 if (!strcmp(funcName, "vkCreateComputePipelines"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006794 return (PFN_vkVoidFunction) vkCreateComputePipelines;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006795 if (!strcmp(funcName, "vkCreateSampler"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006796 return (PFN_vkVoidFunction) vkCreateSampler;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006797 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006798 return (PFN_vkVoidFunction) vkCreateDescriptorSetLayout;
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05006799 if (!strcmp(funcName, "vkCreatePipelineLayout"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006800 return (PFN_vkVoidFunction) vkCreatePipelineLayout;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006801 if (!strcmp(funcName, "vkCreateDescriptorPool"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006802 return (PFN_vkVoidFunction) vkCreateDescriptorPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006803 if (!strcmp(funcName, "vkResetDescriptorPool"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006804 return (PFN_vkVoidFunction) vkResetDescriptorPool;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006805 if (!strcmp(funcName, "vkAllocateDescriptorSets"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006806 return (PFN_vkVoidFunction) vkAllocateDescriptorSets;
Tobin Ehlise735c692015-10-08 13:13:50 -06006807 if (!strcmp(funcName, "vkFreeDescriptorSets"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006808 return (PFN_vkVoidFunction) vkFreeDescriptorSets;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08006809 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006810 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
Mark Lobodzinski39298632015-11-18 08:38:27 -07006811 if (!strcmp(funcName, "vkCreateCommandPool"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006812 return (PFN_vkVoidFunction) vkCreateCommandPool;
Mark Lobodzinski39298632015-11-18 08:38:27 -07006813 if (!strcmp(funcName, "vkDestroyCommandPool"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006814 return (PFN_vkVoidFunction) vkDestroyCommandPool;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006815 if (!strcmp(funcName, "vkResetCommandPool"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006816 return (PFN_vkVoidFunction) vkResetCommandPool;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006817 if (!strcmp(funcName, "vkAllocateCommandBuffers"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006818 return (PFN_vkVoidFunction) vkAllocateCommandBuffers;
Mark Lobodzinski39298632015-11-18 08:38:27 -07006819 if (!strcmp(funcName, "vkFreeCommandBuffers"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006820 return (PFN_vkVoidFunction) vkFreeCommandBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006821 if (!strcmp(funcName, "vkBeginCommandBuffer"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006822 return (PFN_vkVoidFunction) vkBeginCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006823 if (!strcmp(funcName, "vkEndCommandBuffer"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006824 return (PFN_vkVoidFunction) vkEndCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006825 if (!strcmp(funcName, "vkResetCommandBuffer"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006826 return (PFN_vkVoidFunction) vkResetCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006827 if (!strcmp(funcName, "vkCmdBindPipeline"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006828 return (PFN_vkVoidFunction) vkCmdBindPipeline;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06006829 if (!strcmp(funcName, "vkCmdSetViewport"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006830 return (PFN_vkVoidFunction) vkCmdSetViewport;
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06006831 if (!strcmp(funcName, "vkCmdSetScissor"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006832 return (PFN_vkVoidFunction) vkCmdSetScissor;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06006833 if (!strcmp(funcName, "vkCmdSetLineWidth"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006834 return (PFN_vkVoidFunction) vkCmdSetLineWidth;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06006835 if (!strcmp(funcName, "vkCmdSetDepthBias"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006836 return (PFN_vkVoidFunction) vkCmdSetDepthBias;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06006837 if (!strcmp(funcName, "vkCmdSetBlendConstants"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006838 return (PFN_vkVoidFunction) vkCmdSetBlendConstants;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06006839 if (!strcmp(funcName, "vkCmdSetDepthBounds"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006840 return (PFN_vkVoidFunction) vkCmdSetDepthBounds;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06006841 if (!strcmp(funcName, "vkCmdSetStencilCompareMask"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006842 return (PFN_vkVoidFunction) vkCmdSetStencilCompareMask;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06006843 if (!strcmp(funcName, "vkCmdSetStencilWriteMask"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006844 return (PFN_vkVoidFunction) vkCmdSetStencilWriteMask;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06006845 if (!strcmp(funcName, "vkCmdSetStencilReference"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006846 return (PFN_vkVoidFunction) vkCmdSetStencilReference;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006847 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006848 return (PFN_vkVoidFunction) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06006849 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006850 return (PFN_vkVoidFunction) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006851 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006852 return (PFN_vkVoidFunction) vkCmdBindIndexBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006853 if (!strcmp(funcName, "vkCmdDraw"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006854 return (PFN_vkVoidFunction) vkCmdDraw;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006855 if (!strcmp(funcName, "vkCmdDrawIndexed"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006856 return (PFN_vkVoidFunction) vkCmdDrawIndexed;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006857 if (!strcmp(funcName, "vkCmdDrawIndirect"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006858 return (PFN_vkVoidFunction) vkCmdDrawIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006859 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006860 return (PFN_vkVoidFunction) vkCmdDrawIndexedIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006861 if (!strcmp(funcName, "vkCmdDispatch"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006862 return (PFN_vkVoidFunction) vkCmdDispatch;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006863 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006864 return (PFN_vkVoidFunction) vkCmdDispatchIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006865 if (!strcmp(funcName, "vkCmdCopyBuffer"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006866 return (PFN_vkVoidFunction) vkCmdCopyBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006867 if (!strcmp(funcName, "vkCmdCopyImage"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006868 return (PFN_vkVoidFunction) vkCmdCopyImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006869 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006870 return (PFN_vkVoidFunction) vkCmdCopyBufferToImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006871 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006872 return (PFN_vkVoidFunction) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006873 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006874 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006875 if (!strcmp(funcName, "vkCmdFillBuffer"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006876 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006877 if (!strcmp(funcName, "vkCmdClearColorImage"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006878 return (PFN_vkVoidFunction) vkCmdClearColorImage;
Chris Forbesd9be82b2015-06-22 17:21:59 +12006879 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006880 return (PFN_vkVoidFunction) vkCmdClearDepthStencilImage;
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06006881 if (!strcmp(funcName, "vkCmdClearAttachments"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006882 return (PFN_vkVoidFunction) vkCmdClearAttachments;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006883 if (!strcmp(funcName, "vkCmdResolveImage"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006884 return (PFN_vkVoidFunction) vkCmdResolveImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006885 if (!strcmp(funcName, "vkCmdSetEvent"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006886 return (PFN_vkVoidFunction) vkCmdSetEvent;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006887 if (!strcmp(funcName, "vkCmdResetEvent"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006888 return (PFN_vkVoidFunction) vkCmdResetEvent;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006889 if (!strcmp(funcName, "vkCmdWaitEvents"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006890 return (PFN_vkVoidFunction) vkCmdWaitEvents;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006891 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006892 return (PFN_vkVoidFunction) vkCmdPipelineBarrier;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006893 if (!strcmp(funcName, "vkCmdBeginQuery"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006894 return (PFN_vkVoidFunction) vkCmdBeginQuery;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006895 if (!strcmp(funcName, "vkCmdEndQuery"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006896 return (PFN_vkVoidFunction) vkCmdEndQuery;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006897 if (!strcmp(funcName, "vkCmdResetQueryPool"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006898 return (PFN_vkVoidFunction) vkCmdResetQueryPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006899 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006900 return (PFN_vkVoidFunction) vkCmdWriteTimestamp;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006901 if (!strcmp(funcName, "vkCreateFramebuffer"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006902 return (PFN_vkVoidFunction) vkCreateFramebuffer;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006903 if (!strcmp(funcName, "vkCreateShaderModule"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006904 return (PFN_vkVoidFunction) vkCreateShaderModule;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006905 if (!strcmp(funcName, "vkCreateRenderPass"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006906 return (PFN_vkVoidFunction) vkCreateRenderPass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006907 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006908 return (PFN_vkVoidFunction) vkCmdBeginRenderPass;
Chia-I Wu08accc62015-07-07 11:50:03 +08006909 if (!strcmp(funcName, "vkCmdNextSubpass"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006910 return (PFN_vkVoidFunction) vkCmdNextSubpass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006911 if (!strcmp(funcName, "vkCmdEndRenderPass"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006912 return (PFN_vkVoidFunction) vkCmdEndRenderPass;
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06006913 if (!strcmp(funcName, "vkCmdExecuteCommands"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006914 return (PFN_vkVoidFunction) vkCmdExecuteCommands;
Michael Lentineb887b0a2015-12-29 14:12:11 -06006915 if (!strcmp(funcName, "vkSetEvent"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006916 return (PFN_vkVoidFunction) vkSetEvent;
Michael Lentine7b236262015-10-23 12:41:44 -07006917 if (!strcmp(funcName, "vkMapMemory"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006918 return (PFN_vkVoidFunction) vkMapMemory;
Michael Lentineb887b0a2015-12-29 14:12:11 -06006919 if (!strcmp(funcName, "vkGetQueryPoolResults"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006920 return (PFN_vkVoidFunction) vkGetQueryPoolResults;
Michael Lentine15a47882016-01-06 10:05:48 -06006921 if (!strcmp(funcName, "vkBindImageMemory"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006922 return (PFN_vkVoidFunction) vkBindImageMemory;
Michael Lentine15a47882016-01-06 10:05:48 -06006923 if (!strcmp(funcName, "vkQueueBindSparse"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006924 return (PFN_vkVoidFunction) vkQueueBindSparse;
Michael Lentine15a47882016-01-06 10:05:48 -06006925 if (!strcmp(funcName, "vkCreateSemaphore"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006926 return (PFN_vkVoidFunction) vkCreateSemaphore;
Jon Ashburneab34492015-06-01 09:37:38 -06006927
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006928 if (dev == NULL)
6929 return NULL;
6930
6931 layer_data *dev_data;
6932 dev_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map);
6933
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006934 if (dev_data->device_extensions.wsi_enabled)
6935 {
Michael Lentineabc5e922015-10-12 11:30:14 -05006936 if (!strcmp(funcName, "vkCreateSwapchainKHR"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006937 return (PFN_vkVoidFunction) vkCreateSwapchainKHR;
Michael Lentineabc5e922015-10-12 11:30:14 -05006938 if (!strcmp(funcName, "vkDestroySwapchainKHR"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006939 return (PFN_vkVoidFunction) vkDestroySwapchainKHR;
Michael Lentineabc5e922015-10-12 11:30:14 -05006940 if (!strcmp(funcName, "vkGetSwapchainImagesKHR"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006941 return (PFN_vkVoidFunction) vkGetSwapchainImagesKHR;
Michael Lentine15a47882016-01-06 10:05:48 -06006942 if (!strcmp(funcName, "vkAcquireNextImageKHR"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006943 return (PFN_vkVoidFunction) vkAcquireNextImageKHR;
Michael Lentineabc5e922015-10-12 11:30:14 -05006944 if (!strcmp(funcName, "vkQueuePresentKHR"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006945 return (PFN_vkVoidFunction) vkQueuePresentKHR;
Michael Lentineabc5e922015-10-12 11:30:14 -05006946 }
6947
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006948 VkLayerDispatchTable* pTable = dev_data->device_dispatch_table;
6949 if (dev_data->device_extensions.debug_marker_enabled)
6950 {
Jon Ashburn747f2b62015-06-18 15:02:58 -06006951 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006952 return (PFN_vkVoidFunction) vkCmdDbgMarkerBegin;
Jon Ashburn747f2b62015-06-18 15:02:58 -06006953 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006954 return (PFN_vkVoidFunction) vkCmdDbgMarkerEnd;
Jon Ashburneab34492015-06-01 09:37:38 -06006955 }
6956 {
Jon Ashburn8fd08252015-05-28 16:25:02 -06006957 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006958 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006959 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburnf6b33db2015-05-05 14:22:52 -06006960 }
6961}
6962
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006963VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
6964{
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006965 if (!strcmp(funcName, "vkGetInstanceProcAddr"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006966 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006967 if (!strcmp(funcName, "vkGetDeviceProcAddr"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006968 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06006969 if (!strcmp(funcName, "vkCreateInstance"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006970 return (PFN_vkVoidFunction) vkCreateInstance;
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006971 if (!strcmp(funcName, "vkCreateDevice"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006972 return (PFN_vkVoidFunction) vkCreateDevice;
Jon Ashburn3950e1b2015-05-20 09:00:28 -06006973 if (!strcmp(funcName, "vkDestroyInstance"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006974 return (PFN_vkVoidFunction) vkDestroyInstance;
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -06006975 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006976 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -06006977 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006978 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -06006979 if (!strcmp(funcName, "vkEnumerateDeviceLayerProperties"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006980 return (PFN_vkVoidFunction) vkEnumerateDeviceLayerProperties;
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -06006981 if (!strcmp(funcName, "vkEnumerateDeviceExtensionProperties"))
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006982 return (PFN_vkVoidFunction) vkEnumerateDeviceExtensionProperties;
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06006983
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006984 if (instance == NULL)
6985 return NULL;
6986
6987 PFN_vkVoidFunction fptr;
6988
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006989 layer_data* my_data;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006990 my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06006991 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06006992 if (fptr)
6993 return fptr;
6994
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -07006995 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006996 if (pTable->GetInstanceProcAddr == NULL)
6997 return NULL;
6998 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006999}