blob: 46b6d8fae39f3ea1527c01d260c70fe5452f937a [file] [log] [blame]
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001/*
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002 *
Courtney Goeltzenleuchterfcbe16f2015-10-29 13:50:34 -06003 * Copyright (C) 2015 Valve Corporation
Michael Lentineb6986752015-10-06 14:56:18 -07004 * Copyright (C) 2015 Google, Inc.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060023 *
Tobin Ehlis88452832015-12-03 09:40:56 -070024 * Author: Cody Northrop <cnorthrop@google.com>
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060025 * Author: Michael Lentine <mlentine@google.com>
Tobin Ehlis88452832015-12-03 09:40:56 -070026 * Author: Tobin Ehlis <tobine@google.com>
27 * Author: Chia-I Wu <olv@google.com>
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070028 * Author: Chris Forbes <chrisf@ijw.co.nz>
Mark Lobodzinski78da8cb2015-12-28 15:51:07 -070029 * Author: Mark Lobodzinski <mark@lunarg.com>
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060030 */
31
Mark Lobodzinski78da8cb2015-12-28 15:51:07 -070032// Allow use of STL min and max functions in Windows
33#define NOMINMAX
34
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060035#include <stdio.h>
36#include <stdlib.h>
37#include <string.h>
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070038#include <assert.h>
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060039#include <unordered_map>
Michael Lentineb6986752015-10-06 14:56:18 -070040#include <unordered_set>
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070041#include <map>
42#include <string>
43#include <iostream>
44#include <algorithm>
Mark Lobodzinski39298632015-11-18 08:38:27 -070045#include <list>
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070046#include <spirv.hpp>
Tobin Ehlis88452832015-12-03 09:40:56 -070047#include <set>
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060048
Tobin Ehlisb835d1b2015-07-03 10:34:49 -060049#include "vk_loader_platform.h"
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060050#include "vk_dispatch_table_helper.h"
51#include "vk_struct_string_helper_cpp.h"
Tony Barbour18f71552015-04-22 11:36:22 -060052#if defined(__GNUC__)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060053#pragma GCC diagnostic ignored "-Wwrite-strings"
Tony Barbour18f71552015-04-22 11:36:22 -060054#endif
Tony Barbour18f71552015-04-22 11:36:22 -060055#if defined(__GNUC__)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060056#pragma GCC diagnostic warning "-Wwrite-strings"
Tony Barbour18f71552015-04-22 11:36:22 -060057#endif
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060058#include "vk_struct_size_helper.h"
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060059#include "draw_state.h"
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -060060#include "vk_layer_config.h"
Michael Lentine97eb7462015-11-20 09:48:52 -080061#include "vulkan/vk_debug_marker_layer.h"
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -060062#include "vk_layer_table.h"
63#include "vk_layer_debug_marker_table.h"
64#include "vk_layer_data.h"
65#include "vk_layer_logging.h"
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -060066#include "vk_layer_extension_utils.h"
Tobin Ehlisa1c28562015-10-23 16:00:08 -060067#include "vk_layer_utils.h"
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060068
Mark Lobodzinski31e5f282015-11-30 16:48:53 -070069// This definition controls whether image layout transitions are enabled/disabled.
70// disable until corner cases are fixed
71#define DISABLE_IMAGE_LAYOUT_VALIDATION
72
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070073using std::unordered_map;
74using std::unordered_set;
75
Tobin Ehlisac0ef842015-12-14 13:46:38 -070076// Track command pools and their command buffers
77struct CMD_POOL_INFO {
78 VkCommandPoolCreateFlags createFlags;
79 list<VkCommandBuffer> commandBuffers; // list container of cmd buffers allocated from this pool
80};
81
Tobin Ehlis0b632332015-10-07 09:38:40 -060082struct devExts {
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -070083 VkBool32 debug_marker_enabled;
Michael Lentineabc5e922015-10-12 11:30:14 -050084 VkBool32 wsi_enabled;
85 unordered_map<VkSwapchainKHR, SWAPCHAIN_NODE*> swapchainMap;
Tobin Ehlis0b632332015-10-07 09:38:40 -060086};
87
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070088// fwd decls
89struct shader_module;
90struct render_pass;
91
Cody Northrop55443ef2015-09-28 15:09:32 -060092struct layer_data {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -070093 debug_report_data* report_data;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070094 std::vector<VkDebugReportCallbackEXT> logging_callback;
Tobin Ehlis0b632332015-10-07 09:38:40 -060095 VkLayerDispatchTable* device_dispatch_table;
96 VkLayerInstanceDispatchTable* instance_dispatch_table;
97 devExts device_extensions;
Tobin Ehlisae82e7f2016-01-20 16:23:37 -070098 vector<VkQueue> queues; // all queues under given device
Michael Lentineb887b0a2015-12-29 14:12:11 -060099 unordered_set<VkCommandBuffer> inFlightCmdBuffers;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -0600100 // Layer specific data
Mark Lobodzinski39298632015-11-18 08:38:27 -0700101 unordered_map<VkSampler, unique_ptr<SAMPLER_NODE>> sampleMap;
102 unordered_map<VkImageView, unique_ptr<VkImageViewCreateInfo>> imageViewMap;
103 unordered_map<VkImage, unique_ptr<VkImageCreateInfo>> imageMap;
104 unordered_map<VkBufferView, unique_ptr<VkBufferViewCreateInfo>> bufferViewMap;
Michael Lentine700b0aa2015-10-30 17:57:32 -0700105 unordered_map<VkBuffer, BUFFER_NODE> bufferMap;
Mark Lobodzinski39298632015-11-18 08:38:27 -0700106 unordered_map<VkPipeline, PIPELINE_NODE*> pipelineMap;
Tobin Ehlisac0ef842015-12-14 13:46:38 -0700107 unordered_map<VkCommandPool, CMD_POOL_INFO> commandPoolMap;
Mark Lobodzinski39298632015-11-18 08:38:27 -0700108 unordered_map<VkDescriptorPool, DESCRIPTOR_POOL_NODE*> descriptorPoolMap;
109 unordered_map<VkDescriptorSet, SET_NODE*> setMap;
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -0700110 unordered_map<VkDescriptorSetLayout, LAYOUT_NODE*> descriptorSetLayoutMap;
Mark Lobodzinski39298632015-11-18 08:38:27 -0700111 unordered_map<VkPipelineLayout, PIPELINE_LAYOUT_NODE> pipelineLayoutMap;
112 unordered_map<VkDeviceMemory, VkImage> memImageMap;
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -0700113 unordered_map<VkFence, FENCE_NODE> fenceMap;
114 unordered_map<VkQueue, QUEUE_NODE> queueMap;
Michael Lentineb887b0a2015-12-29 14:12:11 -0600115 unordered_map<VkEvent, EVENT_NODE> eventMap;
116 unordered_map<QueryObject, bool> queryToStateMap;
Michael Lentine15a47882016-01-06 10:05:48 -0600117 unordered_map<VkSemaphore, uint32_t> semaphoreSignaledMap;
Mark Lobodzinski39298632015-11-18 08:38:27 -0700118 unordered_map<void*, GLOBAL_CB_NODE*> commandBufferMap;
119 unordered_map<VkFramebuffer, VkFramebufferCreateInfo*> frameBufferMap;
120 unordered_map<VkImage, IMAGE_NODE*> imageLayoutMap;
121 unordered_map<VkRenderPass, RENDER_PASS_NODE*> renderPassMap;
Michael Lentine15a47882016-01-06 10:05:48 -0600122 unordered_map<VkShaderModule, shader_module*> shaderModuleMap;
Michael Lentineabc5e922015-10-12 11:30:14 -0500123 // Current render pass
Michael Lentine15a47882016-01-06 10:05:48 -0600124 VkRenderPassBeginInfo renderPassBeginInfo;
125 uint32_t currentSubpass;
Mark Lobodzinski941aea92016-01-13 10:23:15 -0700126 unordered_map<VkDevice, VkPhysicalDeviceProperties> physDevPropertyMap;
Cody Northrop55443ef2015-09-28 15:09:32 -0600127
128 layer_data() :
129 report_data(nullptr),
Tobin Ehlis0b632332015-10-07 09:38:40 -0600130 device_dispatch_table(nullptr),
131 instance_dispatch_table(nullptr),
132 device_extensions()
Cody Northrop55443ef2015-09-28 15:09:32 -0600133 {};
134};
Michael Lentine15a47882016-01-06 10:05:48 -0600135
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700136// Code imported from ShaderChecker
137static void
Chris Forbes21977d92016-01-26 13:41:39 +1300138build_def_index(shader_module *);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700139
Chris Forbesc7e2e202016-01-18 08:56:40 +1300140// A forward iterator over spirv instructions. Provides easy access to len, opcode, and content words
141// without the caller needing to care too much about the physical SPIRV module layout.
142struct spirv_inst_iter {
143 std::vector<uint32_t>::const_iterator zero;
144 std::vector<uint32_t>::const_iterator it;
145
146 uint32_t len() { return *it >> 16; }
147 uint32_t opcode() { return *it & 0x0ffffu; }
148 uint32_t const & word(unsigned n) { return it[n]; }
Mark Youngd652d132016-01-25 13:37:06 -0700149 uint32_t offset() { return (uint32_t)(it - zero); }
Chris Forbesc7e2e202016-01-18 08:56:40 +1300150
151 spirv_inst_iter(std::vector<uint32_t>::const_iterator zero,
152 std::vector<uint32_t>::const_iterator it) : zero(zero), it(it) {}
153
154 bool operator== (spirv_inst_iter const & other) {
155 return it == other.it;
156 }
157
158 bool operator!= (spirv_inst_iter const & other) {
159 return it != other.it;
160 }
161
162 spirv_inst_iter operator++ (int) { /* x++ */
163 spirv_inst_iter ii = *this;
164 it += len();
165 return ii;
166 }
167
168 spirv_inst_iter operator++ () { /* ++x; */
169 it += len();
170 return *this;
171 }
172
173 /* The iterator and the value are the same thing. */
174 spirv_inst_iter & operator* () { return *this; }
175 spirv_inst_iter const & operator* () const { return *this; }
176};
177
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700178struct shader_module {
179 /* the spirv image itself */
180 vector<uint32_t> words;
181 /* a mapping of <id> to the first word of its def. this is useful because walking type
Chris Forbes21977d92016-01-26 13:41:39 +1300182 * trees, constant expressions, etc requires jumping all over the instruction stream.
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700183 */
Chris Forbes21977d92016-01-26 13:41:39 +1300184 unordered_map<unsigned, unsigned> def_index;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700185
186 shader_module(VkShaderModuleCreateInfo const *pCreateInfo) :
187 words((uint32_t *)pCreateInfo->pCode, (uint32_t *)pCreateInfo->pCode + pCreateInfo->codeSize / sizeof(uint32_t)),
Chris Forbes21977d92016-01-26 13:41:39 +1300188 def_index() {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700189
Chris Forbes21977d92016-01-26 13:41:39 +1300190 build_def_index(this);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700191 }
Chris Forbesc7e2e202016-01-18 08:56:40 +1300192
193 /* expose begin() / end() to enable range-based for */
194 spirv_inst_iter begin() const { return spirv_inst_iter(words.begin(), words.begin() + 5); } /* first insn */
195 spirv_inst_iter end() const { return spirv_inst_iter(words.begin(), words.end()); } /* just past last insn */
196 /* given an offset into the module, produce an iterator there. */
197 spirv_inst_iter at(unsigned offset) const { return spirv_inst_iter(words.begin(), words.begin() + offset); }
Chris Forbes1257f912016-01-18 12:07:01 +1300198
Chris Forbes21977d92016-01-26 13:41:39 +1300199 /* gets an iterator to the definition of an id */
200 spirv_inst_iter get_def(unsigned id) const {
201 auto it = def_index.find(id);
202 if (it == def_index.end()) {
Chris Forbes1257f912016-01-18 12:07:01 +1300203 return end();
204 }
205 return at(it->second);
206 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700207};
208
Tobin Ehlisb212dfc2015-10-07 15:40:22 -0600209// TODO : Do we need to guard access to layer_data_map w/ lock?
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -0700210static unordered_map<void*, layer_data*> layer_data_map;
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -0600211
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600212static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
213// TODO : This can be much smarter, using separate locks for separate global data
214static int globalLockInitialized = 0;
215static loader_platform_thread_mutex globalLock;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600216#define MAX_TID 513
217static loader_platform_thread_id g_tidMapping[MAX_TID] = {0};
218static uint32_t g_maxTID = 0;
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600219
220template layer_data *get_my_data_ptr<layer_data>(
221 void *data_key,
222 std::unordered_map<void *, layer_data *> &data_map);
223
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600224// Map actual TID to an index value and return that index
225// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs
226static uint32_t getTIDIndex() {
227 loader_platform_thread_id tid = loader_platform_get_thread_id();
228 for (uint32_t i = 0; i < g_maxTID; i++) {
229 if (tid == g_tidMapping[i])
230 return i;
231 }
232 // Don't yet have mapping, set it and return newly set index
233 uint32_t retVal = (uint32_t) g_maxTID;
234 g_tidMapping[g_maxTID++] = tid;
235 assert(g_maxTID < MAX_TID);
236 return retVal;
237}
Tobin Ehlis559c6382015-11-05 09:52:49 -0700238
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600239// Return a string representation of CMD_TYPE enum
240static string cmdTypeToString(CMD_TYPE cmd)
241{
242 switch (cmd)
243 {
244 case CMD_BINDPIPELINE:
245 return "CMD_BINDPIPELINE";
246 case CMD_BINDPIPELINEDELTA:
247 return "CMD_BINDPIPELINEDELTA";
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600248 case CMD_SETVIEWPORTSTATE:
249 return "CMD_SETVIEWPORTSTATE";
250 case CMD_SETLINEWIDTHSTATE:
251 return "CMD_SETLINEWIDTHSTATE";
252 case CMD_SETDEPTHBIASSTATE:
253 return "CMD_SETDEPTHBIASSTATE";
254 case CMD_SETBLENDSTATE:
255 return "CMD_SETBLENDSTATE";
256 case CMD_SETDEPTHBOUNDSSTATE:
257 return "CMD_SETDEPTHBOUNDSSTATE";
258 case CMD_SETSTENCILREADMASKSTATE:
259 return "CMD_SETSTENCILREADMASKSTATE";
260 case CMD_SETSTENCILWRITEMASKSTATE:
261 return "CMD_SETSTENCILWRITEMASKSTATE";
262 case CMD_SETSTENCILREFERENCESTATE:
263 return "CMD_SETSTENCILREFERENCESTATE";
Tobin Ehlis793ad302015-04-03 12:01:11 -0600264 case CMD_BINDDESCRIPTORSETS:
265 return "CMD_BINDDESCRIPTORSETS";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600266 case CMD_BINDINDEXBUFFER:
267 return "CMD_BINDINDEXBUFFER";
268 case CMD_BINDVERTEXBUFFER:
269 return "CMD_BINDVERTEXBUFFER";
270 case CMD_DRAW:
271 return "CMD_DRAW";
272 case CMD_DRAWINDEXED:
273 return "CMD_DRAWINDEXED";
274 case CMD_DRAWINDIRECT:
275 return "CMD_DRAWINDIRECT";
276 case CMD_DRAWINDEXEDINDIRECT:
277 return "CMD_DRAWINDEXEDINDIRECT";
278 case CMD_DISPATCH:
279 return "CMD_DISPATCH";
280 case CMD_DISPATCHINDIRECT:
281 return "CMD_DISPATCHINDIRECT";
282 case CMD_COPYBUFFER:
283 return "CMD_COPYBUFFER";
284 case CMD_COPYIMAGE:
285 return "CMD_COPYIMAGE";
Tobin Ehlis793ad302015-04-03 12:01:11 -0600286 case CMD_BLITIMAGE:
287 return "CMD_BLITIMAGE";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600288 case CMD_COPYBUFFERTOIMAGE:
289 return "CMD_COPYBUFFERTOIMAGE";
290 case CMD_COPYIMAGETOBUFFER:
291 return "CMD_COPYIMAGETOBUFFER";
292 case CMD_CLONEIMAGEDATA:
293 return "CMD_CLONEIMAGEDATA";
294 case CMD_UPDATEBUFFER:
295 return "CMD_UPDATEBUFFER";
296 case CMD_FILLBUFFER:
297 return "CMD_FILLBUFFER";
298 case CMD_CLEARCOLORIMAGE:
299 return "CMD_CLEARCOLORIMAGE";
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -0600300 case CMD_CLEARATTACHMENTS:
Tobin Ehlis53eddda2015-07-01 16:46:13 -0600301 return "CMD_CLEARCOLORATTACHMENT";
302 case CMD_CLEARDEPTHSTENCILIMAGE:
303 return "CMD_CLEARDEPTHSTENCILIMAGE";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600304 case CMD_RESOLVEIMAGE:
305 return "CMD_RESOLVEIMAGE";
306 case CMD_SETEVENT:
307 return "CMD_SETEVENT";
308 case CMD_RESETEVENT:
309 return "CMD_RESETEVENT";
310 case CMD_WAITEVENTS:
311 return "CMD_WAITEVENTS";
312 case CMD_PIPELINEBARRIER:
313 return "CMD_PIPELINEBARRIER";
314 case CMD_BEGINQUERY:
315 return "CMD_BEGINQUERY";
316 case CMD_ENDQUERY:
317 return "CMD_ENDQUERY";
318 case CMD_RESETQUERYPOOL:
319 return "CMD_RESETQUERYPOOL";
Mark Lobodzinski5495d132015-09-30 16:19:16 -0600320 case CMD_COPYQUERYPOOLRESULTS:
321 return "CMD_COPYQUERYPOOLRESULTS";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600322 case CMD_WRITETIMESTAMP:
323 return "CMD_WRITETIMESTAMP";
324 case CMD_INITATOMICCOUNTERS:
325 return "CMD_INITATOMICCOUNTERS";
326 case CMD_LOADATOMICCOUNTERS:
327 return "CMD_LOADATOMICCOUNTERS";
328 case CMD_SAVEATOMICCOUNTERS:
329 return "CMD_SAVEATOMICCOUNTERS";
330 case CMD_BEGINRENDERPASS:
331 return "CMD_BEGINRENDERPASS";
332 case CMD_ENDRENDERPASS:
333 return "CMD_ENDRENDERPASS";
334 case CMD_DBGMARKERBEGIN:
335 return "CMD_DBGMARKERBEGIN";
336 case CMD_DBGMARKEREND:
337 return "CMD_DBGMARKEREND";
338 default:
339 return "UNKNOWN";
340 }
341}
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700342
343// SPIRV utility functions
344static void
Chris Forbes21977d92016-01-26 13:41:39 +1300345build_def_index(shader_module *module)
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700346{
Chris Forbesc7e2e202016-01-18 08:56:40 +1300347 for (auto insn : *module) {
348 switch (insn.opcode()) {
Chris Forbes92b9ab02016-01-26 13:49:27 +1300349 /* Types */
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700350 case spv::OpTypeVoid:
351 case spv::OpTypeBool:
352 case spv::OpTypeInt:
353 case spv::OpTypeFloat:
354 case spv::OpTypeVector:
355 case spv::OpTypeMatrix:
356 case spv::OpTypeImage:
357 case spv::OpTypeSampler:
358 case spv::OpTypeSampledImage:
359 case spv::OpTypeArray:
360 case spv::OpTypeRuntimeArray:
361 case spv::OpTypeStruct:
362 case spv::OpTypeOpaque:
363 case spv::OpTypePointer:
364 case spv::OpTypeFunction:
365 case spv::OpTypeEvent:
366 case spv::OpTypeDeviceEvent:
367 case spv::OpTypeReserveId:
368 case spv::OpTypeQueue:
369 case spv::OpTypePipe:
Chris Forbes21977d92016-01-26 13:41:39 +1300370 module->def_index[insn.word(1)] = insn.offset();
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700371 break;
372
Chris Forbes92b9ab02016-01-26 13:49:27 +1300373 /* Fixed constants */
374 case spv::OpConstantTrue:
375 case spv::OpConstantFalse:
376 case spv::OpConstant:
377 case spv::OpConstantComposite:
378 case spv::OpConstantSampler:
379 case spv::OpConstantNull:
380 module->def_index[insn.word(2)] = insn.offset();
381 break;
382
383 /* Specialization constants */
384 case spv::OpSpecConstantTrue:
385 case spv::OpSpecConstantFalse:
386 case spv::OpSpecConstant:
387 case spv::OpSpecConstantComposite:
388 case spv::OpSpecConstantOp:
389 module->def_index[insn.word(2)] = insn.offset();
390 break;
391
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700392 default:
Chris Forbes92b9ab02016-01-26 13:49:27 +1300393 /* We don't care about any other defs for now. */
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700394 break;
395 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700396 }
397}
398
399bool
400shader_is_spirv(VkShaderModuleCreateInfo const *pCreateInfo)
401{
402 uint32_t *words = (uint32_t *)pCreateInfo->pCode;
403 size_t sizeInWords = pCreateInfo->codeSize / sizeof(uint32_t);
404
405 /* Just validate that the header makes sense. */
406 return sizeInWords >= 5 && words[0] == spv::MagicNumber && words[1] == spv::Version;
407}
408
409static char const *
410storage_class_name(unsigned sc)
411{
412 switch (sc) {
413 case spv::StorageClassInput: return "input";
414 case spv::StorageClassOutput: return "output";
415 case spv::StorageClassUniformConstant: return "const uniform";
416 case spv::StorageClassUniform: return "uniform";
417 case spv::StorageClassWorkgroup: return "workgroup local";
418 case spv::StorageClassCrossWorkgroup: return "workgroup global";
419 case spv::StorageClassPrivate: return "private global";
420 case spv::StorageClassFunction: return "function";
421 case spv::StorageClassGeneric: return "generic";
422 case spv::StorageClassAtomicCounter: return "atomic counter";
423 case spv::StorageClassImage: return "image";
424 default: return "unknown";
425 }
426}
427
Chris Forbes204207a2016-01-26 14:07:16 +1300428/* get the value of an integral constant */
429unsigned
430get_constant_value(shader_module const *src, unsigned id)
431{
432 auto value = src->get_def(id);
433 assert(value != src->end());
434
435 if (value.opcode() != spv::OpConstant) {
436 /* TODO: Either ensure that the specialization transform is already performed on a module we're
437 considering here, OR -- specialize on the fly now.
438 */
439 return 1;
440 }
441
442 return value.word(3);
443}
444
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700445/* returns ptr to null terminator */
446static char *
447describe_type(char *dst, shader_module const *src, unsigned type)
448{
Chris Forbes21977d92016-01-26 13:41:39 +1300449 auto insn = src->get_def(type);
Chris Forbes1257f912016-01-18 12:07:01 +1300450 assert(insn != src->end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700451
Chris Forbes1257f912016-01-18 12:07:01 +1300452 switch (insn.opcode()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700453 case spv::OpTypeBool:
454 return dst + sprintf(dst, "bool");
455 case spv::OpTypeInt:
Chris Forbes1257f912016-01-18 12:07:01 +1300456 return dst + sprintf(dst, "%cint%d", insn.word(3) ? 's' : 'u', insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700457 case spv::OpTypeFloat:
Chris Forbes1257f912016-01-18 12:07:01 +1300458 return dst + sprintf(dst, "float%d", insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700459 case spv::OpTypeVector:
Chris Forbes1257f912016-01-18 12:07:01 +1300460 dst += sprintf(dst, "vec%d of ", insn.word(3));
461 return describe_type(dst, src, insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700462 case spv::OpTypeMatrix:
Chris Forbes1257f912016-01-18 12:07:01 +1300463 dst += sprintf(dst, "mat%d of ", insn.word(3));
464 return describe_type(dst, src, insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700465 case spv::OpTypeArray:
Chris Forbes95c98052016-01-26 14:08:53 +1300466 dst += sprintf(dst, "arr[%d] of ", get_constant_value(src, insn.word(3)));
Chris Forbes1257f912016-01-18 12:07:01 +1300467 return describe_type(dst, src, insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700468 case spv::OpTypePointer:
Chris Forbes1257f912016-01-18 12:07:01 +1300469 dst += sprintf(dst, "ptr to %s ", storage_class_name(insn.word(2)));
470 return describe_type(dst, src, insn.word(3));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700471 case spv::OpTypeStruct:
472 {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700473 dst += sprintf(dst, "struct of (");
Chris Forbes1257f912016-01-18 12:07:01 +1300474 for (unsigned i = 2; i < insn.len(); i++) {
475 dst = describe_type(dst, src, insn.word(i));
476 dst += sprintf(dst, i == insn.len()-1 ? ")" : ", ");
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700477 }
478 return dst;
479 }
480 case spv::OpTypeSampler:
481 return dst + sprintf(dst, "sampler");
482 default:
483 return dst + sprintf(dst, "oddtype");
484 }
485}
486
487static bool
488types_match(shader_module const *a, shader_module const *b, unsigned a_type, unsigned b_type, bool b_arrayed)
489{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700490 /* walk two type trees together, and complain about differences */
Chris Forbes21977d92016-01-26 13:41:39 +1300491 auto a_insn = a->get_def(a_type);
492 auto b_insn = b->get_def(b_type);
Chris Forbes1257f912016-01-18 12:07:01 +1300493 assert(a_insn != a->end());
494 assert(b_insn != b->end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700495
Chris Forbes1257f912016-01-18 12:07:01 +1300496 if (b_arrayed && b_insn.opcode() == spv::OpTypeArray) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700497 /* 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 +1300498 return types_match(a, b, a_type, b_insn.word(2), false);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700499 }
500
Chris Forbes1257f912016-01-18 12:07:01 +1300501 if (a_insn.opcode() != b_insn.opcode()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700502 return false;
503 }
504
Chris Forbes1257f912016-01-18 12:07:01 +1300505 switch (a_insn.opcode()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700506 /* if b_arrayed and we hit a leaf type, then we can't match -- there's nowhere for the extra OpTypeArray to be! */
507 case spv::OpTypeBool:
508 return true && !b_arrayed;
509 case spv::OpTypeInt:
510 /* match on width, signedness */
Chris Forbes1257f912016-01-18 12:07:01 +1300511 return a_insn.word(2) == b_insn.word(2) && a_insn.word(3) == b_insn.word(3) && !b_arrayed;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700512 case spv::OpTypeFloat:
513 /* match on width */
Chris Forbes1257f912016-01-18 12:07:01 +1300514 return a_insn.word(2) == b_insn.word(2) && !b_arrayed;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700515 case spv::OpTypeVector:
516 case spv::OpTypeMatrix:
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700517 /* match on element type, count. these all have the same layout. we don't get here if
518 * b_arrayed -- that is handled above. */
Chris Forbes95c98052016-01-26 14:08:53 +1300519 return !b_arrayed &&
520 types_match(a, b, a_insn.word(2), b_insn.word(2), b_arrayed) &&
521 a_insn.word(3) == b_insn.word(3);
522 case spv::OpTypeArray:
523 /* match on element type, count. these all have the same layout. we don't get here if
524 * b_arrayed. This differs from vector & matrix types in that the array size is the id of a constant instruction,
525 * not a literal within OpTypeArray */
526 return !b_arrayed &&
527 types_match(a, b, a_insn.word(2), b_insn.word(2), b_arrayed) &&
528 get_constant_value(a, a_insn.word(3)) == get_constant_value(b, b_insn.word(3));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700529 case spv::OpTypeStruct:
530 /* match on all element types */
531 {
532 if (b_arrayed) {
533 /* for the purposes of matching different levels of arrayness, structs are leaves. */
534 return false;
535 }
536
Chris Forbes1257f912016-01-18 12:07:01 +1300537 if (a_insn.len() != b_insn.len()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700538 return false; /* structs cannot match if member counts differ */
539 }
540
Chris Forbes1257f912016-01-18 12:07:01 +1300541 for (unsigned i = 2; i < a_insn.len(); i++) {
542 if (!types_match(a, b, a_insn.word(i), b_insn.word(i), b_arrayed)) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700543 return false;
544 }
545 }
546
547 return true;
548 }
549 case spv::OpTypePointer:
550 /* match on pointee type. storage class is expected to differ */
Chris Forbes1257f912016-01-18 12:07:01 +1300551 return types_match(a, b, a_insn.word(3), b_insn.word(3), b_arrayed);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700552
553 default:
554 /* remaining types are CLisms, or may not appear in the interfaces we
555 * are interested in. Just claim no match.
556 */
557 return false;
558
559 }
560}
561
562static int
563value_or_default(std::unordered_map<unsigned, unsigned> const &map, unsigned id, int def)
564{
565 auto it = map.find(id);
566 if (it == map.end())
567 return def;
568 else
569 return it->second;
570}
571
572
573static unsigned
574get_locations_consumed_by_type(shader_module const *src, unsigned type, bool strip_array_level)
575{
Chris Forbes21977d92016-01-26 13:41:39 +1300576 auto insn = src->get_def(type);
Chris Forbes1257f912016-01-18 12:07:01 +1300577 assert(insn != src->end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700578
Chris Forbesc7e2e202016-01-18 08:56:40 +1300579 switch (insn.opcode()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700580 case spv::OpTypePointer:
581 /* see through the ptr -- this is only ever at the toplevel for graphics shaders;
582 * we're never actually passing pointers around. */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300583 return get_locations_consumed_by_type(src, insn.word(3), strip_array_level);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700584 case spv::OpTypeArray:
585 if (strip_array_level) {
Chris Forbesc7e2e202016-01-18 08:56:40 +1300586 return get_locations_consumed_by_type(src, insn.word(2), false);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700587 }
588 else {
Chris Forbes95c98052016-01-26 14:08:53 +1300589 return get_constant_value(src, insn.word(3)) * get_locations_consumed_by_type(src, insn.word(2), false);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700590 }
591 case spv::OpTypeMatrix:
592 /* num locations is the dimension * element size */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300593 return insn.word(3) * get_locations_consumed_by_type(src, insn.word(2), false);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700594 default:
595 /* everything else is just 1. */
596 return 1;
597
598 /* TODO: extend to handle 64bit scalar types, whose vectors may need
599 * multiple locations. */
600 }
601}
602
603
604struct interface_var {
605 uint32_t id;
606 uint32_t type_id;
607 uint32_t offset;
608 /* TODO: collect the name, too? Isn't required to be present. */
609};
610
Chris Forbesa3e85f62016-01-15 14:53:11 +1300611
612static void
613collect_interface_block_members(layer_data *my_data, VkDevice dev,
614 shader_module const *src,
615 std::map<uint32_t, interface_var> &out,
616 std::map<uint32_t, interface_var> &builtins_out,
617 std::unordered_map<unsigned, unsigned> const &blocks,
618 bool is_array_of_verts,
619 uint32_t id,
620 uint32_t type_id)
621{
622 /* Walk down the type_id presented, trying to determine whether it's actually an interface block. */
Chris Forbes21977d92016-01-26 13:41:39 +1300623 auto type = src->get_def(type_id);
Chris Forbes1257f912016-01-18 12:07:01 +1300624
Chris Forbesa3e85f62016-01-15 14:53:11 +1300625 while (true) {
626
Chris Forbes1257f912016-01-18 12:07:01 +1300627 if (type.opcode() == spv::OpTypePointer) {
Chris Forbes21977d92016-01-26 13:41:39 +1300628 type = src->get_def(type.word(3));
Chris Forbesa3e85f62016-01-15 14:53:11 +1300629 }
Chris Forbes1257f912016-01-18 12:07:01 +1300630 else if (type.opcode() == spv::OpTypeArray && is_array_of_verts) {
Chris Forbes21977d92016-01-26 13:41:39 +1300631 type = src->get_def(type.word(2));
Chris Forbesa3e85f62016-01-15 14:53:11 +1300632 is_array_of_verts = false;
633 }
Chris Forbes1257f912016-01-18 12:07:01 +1300634 else if (type.opcode() == spv::OpTypeStruct) {
635 if (blocks.find(type.word(1)) == blocks.end()) {
Chris Forbesa3e85f62016-01-15 14:53:11 +1300636 /* This isn't an interface block. */
637 return;
638 }
639 else {
640 /* We have found the correct type. Walk its members. */
641 break;
642 }
643 }
644 else {
645 /* not an interface block */
646 return;
647 }
648 }
649
Chris Forbes1257f912016-01-18 12:07:01 +1300650 /* Walk all the OpMemberDecorate for type's result id. */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300651 for (auto insn : *src) {
Chris Forbes1257f912016-01-18 12:07:01 +1300652 if (insn.opcode() == spv::OpMemberDecorate && insn.word(1) == type.word(1)) {
Chris Forbesc7e2e202016-01-18 08:56:40 +1300653 unsigned member_index = insn.word(2);
Chris Forbes1257f912016-01-18 12:07:01 +1300654 unsigned member_type_id = type.word(2 + member_index);
Chris Forbesa3e85f62016-01-15 14:53:11 +1300655
Chris Forbesc7e2e202016-01-18 08:56:40 +1300656 if (insn.word(3) == spv::DecorationLocation) {
657 unsigned location = insn.word(4);
Chris Forbesa3e85f62016-01-15 14:53:11 +1300658 unsigned num_locations = get_locations_consumed_by_type(src, member_type_id, false);
659 for (unsigned int offset = 0; offset < num_locations; offset++) {
660 interface_var v;
661 v.id = id;
662 /* TODO: member index in interface_var too? */
663 v.type_id = member_type_id;
664 v.offset = offset;
665 out[location + offset] = v;
666 }
667 }
Chris Forbesc7e2e202016-01-18 08:56:40 +1300668 else if (insn.word(3) == spv::DecorationBuiltIn) {
669 unsigned builtin = insn.word(4);
Chris Forbesa3e85f62016-01-15 14:53:11 +1300670 interface_var v;
671 v.id = id;
672 v.type_id = member_type_id;
673 v.offset = 0;
674 builtins_out[builtin] = v;
675 }
676 }
Chris Forbesa3e85f62016-01-15 14:53:11 +1300677 }
678}
679
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700680static void
681collect_interface_by_location(layer_data *my_data, VkDevice dev,
682 shader_module const *src, spv::StorageClass sinterface,
683 std::map<uint32_t, interface_var> &out,
684 std::map<uint32_t, interface_var> &builtins_out,
685 bool is_array_of_verts)
686{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700687 std::unordered_map<unsigned, unsigned> var_locations;
688 std::unordered_map<unsigned, unsigned> var_builtins;
Chris Forbesa3e85f62016-01-15 14:53:11 +1300689 std::unordered_map<unsigned, unsigned> blocks;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700690
Chris Forbesc7e2e202016-01-18 08:56:40 +1300691 for (auto insn : *src) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700692
693 /* We consider two interface models: SSO rendezvous-by-location, and
694 * builtins. Complain about anything that fits neither model.
695 */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300696 if (insn.opcode() == spv::OpDecorate) {
697 if (insn.word(2) == spv::DecorationLocation) {
698 var_locations[insn.word(1)] = insn.word(3);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700699 }
700
Chris Forbesc7e2e202016-01-18 08:56:40 +1300701 if (insn.word(2) == spv::DecorationBuiltIn) {
702 var_builtins[insn.word(1)] = insn.word(3);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700703 }
Chris Forbesa3e85f62016-01-15 14:53:11 +1300704
Chris Forbesc7e2e202016-01-18 08:56:40 +1300705 if (insn.word(2) == spv::DecorationBlock) {
706 blocks[insn.word(1)] = 1;
Chris Forbesa3e85f62016-01-15 14:53:11 +1300707 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700708 }
709
710 /* TODO: handle grouped decorations */
711 /* TODO: handle index=1 dual source outputs from FS -- two vars will
712 * have the same location, and we DONT want to clobber. */
713
Chris Forbesc7e2e202016-01-18 08:56:40 +1300714 else if (insn.opcode() == spv::OpVariable && insn.word(3) == sinterface) {
715 unsigned id = insn.word(2);
716 unsigned type = insn.word(1);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700717
Chris Forbesc7e2e202016-01-18 08:56:40 +1300718 int location = value_or_default(var_locations, id, -1);
719 int builtin = value_or_default(var_builtins, id, -1);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700720
Chris Forbesf5020cf2016-01-13 09:29:31 +1300721 /* All variables and interface block members in the Input or Output storage classes
722 * must be decorated with either a builtin or an explicit location.
723 *
724 * TODO: integrate the interface block support here. For now, don't complain --
725 * a valid SPIRV module will only hit this path for the interface block case, as the
726 * individual members of the type are decorated, rather than variable declarations.
727 */
728
729 if (location != -1) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700730 /* A user-defined interface variable, with a location. Where a variable
731 * occupied multiple locations, emit one result for each. */
732 unsigned num_locations = get_locations_consumed_by_type(src, type,
733 is_array_of_verts);
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -0700734 for (unsigned int offset = 0; offset < num_locations; offset++) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700735 interface_var v;
736 v.id = id;
737 v.type_id = type;
738 v.offset = offset;
739 out[location + offset] = v;
740 }
741 }
Chris Forbesf5020cf2016-01-13 09:29:31 +1300742 else if (builtin != -1) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700743 /* A builtin interface variable */
744 /* Note that since builtin interface variables do not consume numbered
745 * locations, there is no larger-than-vec4 consideration as above
746 */
747 interface_var v;
748 v.id = id;
749 v.type_id = type;
750 v.offset = 0;
751 builtins_out[builtin] = v;
752 }
Chris Forbesa3e85f62016-01-15 14:53:11 +1300753 else {
754 /* An interface block instance */
755 collect_interface_block_members(my_data, dev, src, out, builtins_out,
756 blocks, is_array_of_verts, id, type);
757 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700758 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700759 }
760}
761
762static void
763collect_interface_by_descriptor_slot(layer_data *my_data, VkDevice dev,
764 shader_module const *src, spv::StorageClass sinterface,
765 std::map<std::pair<unsigned, unsigned>, interface_var> &out)
766{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700767
768 std::unordered_map<unsigned, unsigned> var_sets;
769 std::unordered_map<unsigned, unsigned> var_bindings;
770
Chris Forbesc7e2e202016-01-18 08:56:40 +1300771 for (auto insn : *src) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700772 /* All variables in the Uniform or UniformConstant storage classes are required to be decorated with both
773 * DecorationDescriptorSet and DecorationBinding.
774 */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300775 if (insn.opcode() == spv::OpDecorate) {
776 if (insn.word(2) == spv::DecorationDescriptorSet) {
777 var_sets[insn.word(1)] = insn.word(3);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700778 }
779
Chris Forbesc7e2e202016-01-18 08:56:40 +1300780 if (insn.word(2) == spv::DecorationBinding) {
781 var_bindings[insn.word(1)] = insn.word(3);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700782 }
783 }
784
Chris Forbesc7e2e202016-01-18 08:56:40 +1300785 else if (insn.opcode() == spv::OpVariable &&
786 (insn.word(3) == spv::StorageClassUniform ||
787 insn.word(3) == spv::StorageClassUniformConstant)) {
788 unsigned set = value_or_default(var_sets, insn.word(2), 0);
789 unsigned binding = value_or_default(var_bindings, insn.word(2), 0);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700790
791 auto existing_it = out.find(std::make_pair(set, binding));
792 if (existing_it != out.end()) {
793 /* conflict within spv image */
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700794 log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__,
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700795 SHADER_CHECKER_INCONSISTENT_SPIRV, "SC",
796 "var %d (type %d) in %s interface in descriptor slot (%u,%u) conflicts with existing definition",
Chris Forbesc7e2e202016-01-18 08:56:40 +1300797 insn.word(2), insn.word(1), storage_class_name(sinterface),
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700798 existing_it->first.first, existing_it->first.second);
799 }
800
801 interface_var v;
Chris Forbesc7e2e202016-01-18 08:56:40 +1300802 v.id = insn.word(2);
803 v.type_id = insn.word(1);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700804 out[std::make_pair(set, binding)] = v;
805 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700806 }
807}
808
809static bool
810validate_interface_between_stages(layer_data *my_data, VkDevice dev,
811 shader_module const *producer, char const *producer_name,
812 shader_module const *consumer, char const *consumer_name,
813 bool consumer_arrayed_input)
814{
815 std::map<uint32_t, interface_var> outputs;
816 std::map<uint32_t, interface_var> inputs;
817
818 std::map<uint32_t, interface_var> builtin_outputs;
819 std::map<uint32_t, interface_var> builtin_inputs;
820
821 bool pass = true;
822
823 collect_interface_by_location(my_data, dev, producer, spv::StorageClassOutput, outputs, builtin_outputs, false);
824 collect_interface_by_location(my_data, dev, consumer, spv::StorageClassInput, inputs, builtin_inputs,
825 consumer_arrayed_input);
826
827 auto a_it = outputs.begin();
828 auto b_it = inputs.begin();
829
830 /* maps sorted by key (location); walk them together to find mismatches */
831 while ((outputs.size() > 0 && a_it != outputs.end()) || ( inputs.size() && b_it != inputs.end())) {
832 bool a_at_end = outputs.size() == 0 || a_it == outputs.end();
833 bool b_at_end = inputs.size() == 0 || b_it == inputs.end();
834 auto a_first = a_at_end ? 0 : a_it->first;
835 auto b_first = b_at_end ? 0 : b_it->first;
836
837 if (b_at_end || ((!a_at_end) && (a_first < b_first))) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700838 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__, SHADER_CHECKER_OUTPUT_NOT_CONSUMED, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700839 "%s writes to output location %d which is not consumed by %s", producer_name, a_first, consumer_name)) {
840 pass = false;
841 }
842 a_it++;
843 }
844 else if (a_at_end || a_first > b_first) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700845 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__, SHADER_CHECKER_INPUT_NOT_PRODUCED, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700846 "%s consumes input location %d which is not written by %s", consumer_name, b_first, producer_name)) {
847 pass = false;
848 }
849 b_it++;
850 }
851 else {
852 if (types_match(producer, consumer, a_it->second.type_id, b_it->second.type_id, consumer_arrayed_input)) {
853 /* OK! */
854 }
855 else {
856 char producer_type[1024];
857 char consumer_type[1024];
858 describe_type(producer_type, producer, a_it->second.type_id);
859 describe_type(consumer_type, consumer, b_it->second.type_id);
860
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700861 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__, SHADER_CHECKER_INTERFACE_TYPE_MISMATCH, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700862 "Type mismatch on location %d: '%s' vs '%s'", a_it->first, producer_type, consumer_type)) {
863 pass = false;
864 }
865 }
866 a_it++;
867 b_it++;
868 }
869 }
870
871 return pass;
872}
873
874enum FORMAT_TYPE {
875 FORMAT_TYPE_UNDEFINED,
876 FORMAT_TYPE_FLOAT, /* UNORM, SNORM, FLOAT, USCALED, SSCALED, SRGB -- anything we consider float in the shader */
877 FORMAT_TYPE_SINT,
878 FORMAT_TYPE_UINT,
879};
880
881static unsigned
882get_format_type(VkFormat fmt) {
883 switch (fmt) {
884 case VK_FORMAT_UNDEFINED:
885 return FORMAT_TYPE_UNDEFINED;
886 case VK_FORMAT_R8_SINT:
887 case VK_FORMAT_R8G8_SINT:
888 case VK_FORMAT_R8G8B8_SINT:
889 case VK_FORMAT_R8G8B8A8_SINT:
890 case VK_FORMAT_R16_SINT:
891 case VK_FORMAT_R16G16_SINT:
892 case VK_FORMAT_R16G16B16_SINT:
893 case VK_FORMAT_R16G16B16A16_SINT:
894 case VK_FORMAT_R32_SINT:
895 case VK_FORMAT_R32G32_SINT:
896 case VK_FORMAT_R32G32B32_SINT:
897 case VK_FORMAT_R32G32B32A32_SINT:
898 case VK_FORMAT_B8G8R8_SINT:
899 case VK_FORMAT_B8G8R8A8_SINT:
900 case VK_FORMAT_A2B10G10R10_SINT_PACK32:
901 case VK_FORMAT_A2R10G10B10_SINT_PACK32:
902 return FORMAT_TYPE_SINT;
903 case VK_FORMAT_R8_UINT:
904 case VK_FORMAT_R8G8_UINT:
905 case VK_FORMAT_R8G8B8_UINT:
906 case VK_FORMAT_R8G8B8A8_UINT:
907 case VK_FORMAT_R16_UINT:
908 case VK_FORMAT_R16G16_UINT:
909 case VK_FORMAT_R16G16B16_UINT:
910 case VK_FORMAT_R16G16B16A16_UINT:
911 case VK_FORMAT_R32_UINT:
912 case VK_FORMAT_R32G32_UINT:
913 case VK_FORMAT_R32G32B32_UINT:
914 case VK_FORMAT_R32G32B32A32_UINT:
915 case VK_FORMAT_B8G8R8_UINT:
916 case VK_FORMAT_B8G8R8A8_UINT:
917 case VK_FORMAT_A2B10G10R10_UINT_PACK32:
918 case VK_FORMAT_A2R10G10B10_UINT_PACK32:
919 return FORMAT_TYPE_UINT;
920 default:
921 return FORMAT_TYPE_FLOAT;
922 }
923}
924
925/* characterizes a SPIR-V type appearing in an interface to a FF stage,
926 * for comparison to a VkFormat's characterization above. */
927static unsigned
928get_fundamental_type(shader_module const *src, unsigned type)
929{
Chris Forbes21977d92016-01-26 13:41:39 +1300930 auto insn = src->get_def(type);
Chris Forbes1257f912016-01-18 12:07:01 +1300931 assert(insn != src->end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700932
Chris Forbes1257f912016-01-18 12:07:01 +1300933 switch (insn.opcode()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700934 case spv::OpTypeInt:
Chris Forbes1257f912016-01-18 12:07:01 +1300935 return insn.word(3) ? FORMAT_TYPE_SINT : FORMAT_TYPE_UINT;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700936 case spv::OpTypeFloat:
937 return FORMAT_TYPE_FLOAT;
938 case spv::OpTypeVector:
Chris Forbes1257f912016-01-18 12:07:01 +1300939 return get_fundamental_type(src, insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700940 case spv::OpTypeMatrix:
Chris Forbes1257f912016-01-18 12:07:01 +1300941 return get_fundamental_type(src, insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700942 case spv::OpTypeArray:
Chris Forbes1257f912016-01-18 12:07:01 +1300943 return get_fundamental_type(src, insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700944 case spv::OpTypePointer:
Chris Forbes1257f912016-01-18 12:07:01 +1300945 return get_fundamental_type(src, insn.word(3));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700946 default:
947 return FORMAT_TYPE_UNDEFINED;
948 }
949}
950
951static bool
952validate_vi_consistency(layer_data *my_data, VkDevice dev, VkPipelineVertexInputStateCreateInfo const *vi)
953{
954 /* walk the binding descriptions, which describe the step rate and stride of each vertex buffer.
955 * each binding should be specified only once.
956 */
957 std::unordered_map<uint32_t, VkVertexInputBindingDescription const *> bindings;
958 bool pass = true;
959
960 for (unsigned i = 0; i < vi->vertexBindingDescriptionCount; i++) {
961 auto desc = &vi->pVertexBindingDescriptions[i];
962 auto & binding = bindings[desc->binding];
963 if (binding) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700964 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__, SHADER_CHECKER_INCONSISTENT_VI, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700965 "Duplicate vertex input binding descriptions for binding %d", desc->binding)) {
966 pass = false;
967 }
968 }
969 else {
970 binding = desc;
971 }
972 }
973
974 return pass;
975}
976
977static bool
978validate_vi_against_vs_inputs(layer_data *my_data, VkDevice dev, VkPipelineVertexInputStateCreateInfo const *vi, shader_module const *vs)
979{
980 std::map<uint32_t, interface_var> inputs;
981 /* we collect builtin inputs, but they will never appear in the VI state --
982 * the vs builtin inputs are generated in the pipeline, not sourced from buffers (VertexID, etc)
983 */
984 std::map<uint32_t, interface_var> builtin_inputs;
985 bool pass = true;
986
987 collect_interface_by_location(my_data, dev, vs, spv::StorageClassInput, inputs, builtin_inputs, false);
988
989 /* Build index by location */
990 std::map<uint32_t, VkVertexInputAttributeDescription const *> attribs;
991 if (vi) {
992 for (unsigned i = 0; i < vi->vertexAttributeDescriptionCount; i++)
993 attribs[vi->pVertexAttributeDescriptions[i].location] = &vi->pVertexAttributeDescriptions[i];
994 }
995
996 auto it_a = attribs.begin();
997 auto it_b = inputs.begin();
998
999 while ((attribs.size() > 0 && it_a != attribs.end()) || (inputs.size() > 0 && it_b != inputs.end())) {
1000 bool a_at_end = attribs.size() == 0 || it_a == attribs.end();
1001 bool b_at_end = inputs.size() == 0 || it_b == inputs.end();
1002 auto a_first = a_at_end ? 0 : it_a->first;
1003 auto b_first = b_at_end ? 0 : it_b->first;
Chris Forbes7d83cd52016-01-15 11:32:03 +13001004 if (!a_at_end && (b_at_end || a_first < b_first)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001005 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__, SHADER_CHECKER_OUTPUT_NOT_CONSUMED, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001006 "Vertex attribute at location %d not consumed by VS", a_first)) {
1007 pass = false;
1008 }
1009 it_a++;
1010 }
Chris Forbes7d83cd52016-01-15 11:32:03 +13001011 else if (!b_at_end && (a_at_end || b_first < a_first)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001012 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__, SHADER_CHECKER_INPUT_NOT_PRODUCED, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001013 "VS consumes input at location %d but not provided", b_first)) {
1014 pass = false;
1015 }
1016 it_b++;
1017 }
1018 else {
1019 unsigned attrib_type = get_format_type(it_a->second->format);
1020 unsigned input_type = get_fundamental_type(vs, it_b->second.type_id);
1021
1022 /* type checking */
1023 if (attrib_type != FORMAT_TYPE_UNDEFINED && input_type != FORMAT_TYPE_UNDEFINED && attrib_type != input_type) {
1024 char vs_type[1024];
1025 describe_type(vs_type, vs, it_b->second.type_id);
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001026 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__, SHADER_CHECKER_INTERFACE_TYPE_MISMATCH, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001027 "Attribute type of `%s` at location %d does not match VS input type of `%s`",
1028 string_VkFormat(it_a->second->format), a_first, vs_type)) {
1029 pass = false;
1030 }
1031 }
1032
1033 /* OK! */
1034 it_a++;
1035 it_b++;
1036 }
1037 }
1038
1039 return pass;
1040}
1041
1042static bool
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001043validate_fs_outputs_against_render_pass(layer_data *my_data, VkDevice dev, shader_module const *fs, RENDER_PASS_NODE const *rp, uint32_t subpass)
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001044{
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001045 const std::vector<VkFormat> &color_formats = rp->subpassColorFormats[subpass];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001046 std::map<uint32_t, interface_var> outputs;
1047 std::map<uint32_t, interface_var> builtin_outputs;
1048 bool pass = true;
1049
1050 /* TODO: dual source blend index (spv::DecIndex, zero if not provided) */
1051
1052 collect_interface_by_location(my_data, dev, fs, spv::StorageClassOutput, outputs, builtin_outputs, false);
1053
1054 auto it = outputs.begin();
1055 uint32_t attachment = 0;
1056
1057 /* Walk attachment list and outputs together -- this is a little overpowered since attachments
1058 * are currently dense, but the parallel with matching between shader stages is nice.
1059 */
1060
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001061 while ((outputs.size() > 0 && it != outputs.end()) || attachment < color_formats.size()) {
1062 if (attachment == color_formats.size() || ( it != outputs.end() && it->first < attachment)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001063 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__, SHADER_CHECKER_OUTPUT_NOT_CONSUMED, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001064 "FS writes to output location %d with no matching attachment", it->first)) {
1065 pass = false;
1066 }
1067 it++;
1068 }
1069 else if (it == outputs.end() || it->first > attachment) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001070 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__, SHADER_CHECKER_INPUT_NOT_PRODUCED, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001071 "Attachment %d not written by FS", attachment)) {
1072 pass = false;
1073 }
1074 attachment++;
1075 }
1076 else {
1077 unsigned output_type = get_fundamental_type(fs, it->second.type_id);
1078 unsigned att_type = get_format_type(color_formats[attachment]);
1079
1080 /* type checking */
1081 if (att_type != FORMAT_TYPE_UNDEFINED && output_type != FORMAT_TYPE_UNDEFINED && att_type != output_type) {
1082 char fs_type[1024];
1083 describe_type(fs_type, fs, it->second.type_id);
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001084 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__, SHADER_CHECKER_INTERFACE_TYPE_MISMATCH, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001085 "Attachment %d of type `%s` does not match FS output type of `%s`",
1086 attachment, string_VkFormat(color_formats[attachment]), fs_type)) {
1087 pass = false;
1088 }
1089 }
1090
1091 /* OK! */
1092 it++;
1093 attachment++;
1094 }
1095 }
1096
1097 return pass;
1098}
1099
1100
1101struct shader_stage_attributes {
1102 char const * const name;
1103 bool arrayed_input;
1104};
1105
1106
1107static shader_stage_attributes
1108shader_stage_attribs[] = {
1109 { "vertex shader", false },
1110 { "tessellation control shader", true },
1111 { "tessellation evaluation shader", false },
1112 { "geometry shader", true },
1113 { "fragment shader", false },
1114};
1115
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001116// For given pipelineLayout verify that the setLayout at slot.first
1117// has the requested binding at slot.second
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001118static bool
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001119has_descriptor_binding(layer_data* my_data,
1120 vector<VkDescriptorSetLayout>* pipelineLayout,
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001121 std::pair<unsigned, unsigned> slot)
1122{
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001123 if (!pipelineLayout)
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001124 return false;
1125
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001126 if (slot.first >= pipelineLayout->size())
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001127 return false;
1128
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001129 auto set = my_data->descriptorSetLayoutMap[(*pipelineLayout)[slot.first]]->bindings;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001130
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001131 return (set.find(slot.second) != set.end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001132}
1133
1134static uint32_t get_shader_stage_id(VkShaderStageFlagBits stage)
1135{
1136 uint32_t bit_pos = u_ffs(stage);
1137 return bit_pos-1;
1138}
1139
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001140// Block of code at start here for managing/tracking Pipeline state that this layer cares about
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001141
1142static uint64_t g_drawCount[NUM_DRAW_TYPES] = {0, 0, 0, 0};
1143
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001144// TODO : Should be tracking lastBound per commandBuffer and when draws occur, report based on that cmd buffer lastBound
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001145// Then need to synchronize the accesses based on cmd buffer so that if I'm reading state on one cmd buffer, updates
1146// to that same cmd buffer by separate thread are not changing state from underneath us
1147// Track the last cmd buffer touched by this thread
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001148
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001149// prototype
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001150static GLOBAL_CB_NODE* getCBNode(layer_data*, const VkCommandBuffer);
Tobin Ehlis559c6382015-11-05 09:52:49 -07001151
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06001152static VkBool32 hasDrawCmd(GLOBAL_CB_NODE* pCB)
Tobin Ehlis53eddda2015-07-01 16:46:13 -06001153{
1154 for (uint32_t i=0; i<NUM_DRAW_TYPES; i++) {
1155 if (pCB->drawCount[i])
1156 return VK_TRUE;
1157 }
1158 return VK_FALSE;
1159}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001160
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001161// Check object status for selected flag state
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001162static VkBool32 validate_status(layer_data* my_data, GLOBAL_CB_NODE* pNode, CBStatusFlags enable_mask, CBStatusFlags status_mask, CBStatusFlags status_flag, VkFlags msg_flags, DRAW_STATE_ERROR error_code, const char* fail_msg)
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001163{
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001164 // If non-zero enable mask is present, check it against status but if enable_mask
1165 // is 0 then no enable required so we should always just check status
1166 if ((!enable_mask) || (enable_mask & pNode->status)) {
1167 if ((pNode->status & status_mask) != status_flag) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001168 // TODO : How to pass dispatchable objects as srcObject? Here src obj should be cmd buffer
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001169 return log_msg(my_data->report_data, msg_flags, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, error_code, "DS",
Mark Youngee3f3a22016-01-25 12:18:32 -07001170 "CB object %#" PRIxLEAST64 ": %s", (uint64_t)(pNode->commandBuffer), fail_msg);
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001171 }
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001172 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001173 return VK_FALSE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001174}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001175
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001176// Retrieve pipeline node ptr for given pipeline object
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001177static PIPELINE_NODE* getPipeline(layer_data* my_data, const VkPipeline pipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001178{
1179 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08001180 if (my_data->pipelineMap.find(pipeline) == my_data->pipelineMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001181 loader_platform_thread_unlock_mutex(&globalLock);
1182 return NULL;
1183 }
1184 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08001185 return my_data->pipelineMap[pipeline];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001186}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001187
Tobin Ehlisd332f282015-10-02 11:00:56 -06001188// Return VK_TRUE if for a given PSO, the given state enum is dynamic, else return VK_FALSE
1189static VkBool32 isDynamic(const PIPELINE_NODE* pPipeline, const VkDynamicState state)
1190{
1191 if (pPipeline && pPipeline->graphicsPipelineCI.pDynamicState) {
1192 for (uint32_t i=0; i<pPipeline->graphicsPipelineCI.pDynamicState->dynamicStateCount; i++) {
1193 if (state == pPipeline->graphicsPipelineCI.pDynamicState->pDynamicStates[i])
1194 return VK_TRUE;
1195 }
1196 }
1197 return VK_FALSE;
1198}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001199
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001200// Validate state stored as flags at time of draw call
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001201static VkBool32 validate_draw_state_flags(layer_data* my_data, GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06001202 VkBool32 result;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001203 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");
1204 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");
1205 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");
1206 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");
1207 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");
1208 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");
1209 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");
1210 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");
1211 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 -06001212 if (indexedDraw)
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001213 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 -06001214 return result;
1215}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001216
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001217// Verify attachment reference compatibility according to spec
1218// If one array is larger, treat missing elements of shorter array as VK_ATTACHMENT_UNUSED & other array much match this
1219// If both AttachmentReference arrays have requested index, check their corresponding AttachementDescriptions
1220// to make sure that format and samples counts match.
1221// If not, they are not compatible.
1222static bool attachment_references_compatible(const uint32_t index, const VkAttachmentReference* pPrimary, const uint32_t primaryCount, const VkAttachmentDescription* pPrimaryAttachments,
1223 const VkAttachmentReference* pSecondary, const uint32_t secondaryCount, const VkAttachmentDescription* pSecondaryAttachments)
1224{
1225 if (index >= primaryCount) { // Check secondary as if primary is VK_ATTACHMENT_UNUSED
1226 if (VK_ATTACHMENT_UNUSED != pSecondary[index].attachment)
1227 return false;
1228 } else if (index >= secondaryCount) { // Check primary as if secondary is VK_ATTACHMENT_UNUSED
1229 if (VK_ATTACHMENT_UNUSED != pPrimary[index].attachment)
1230 return false;
1231 } else { // format and sample count must match
1232 if ((pPrimaryAttachments[pPrimary[index].attachment].format == pSecondaryAttachments[pSecondary[index].attachment].format) &&
1233 (pPrimaryAttachments[pPrimary[index].attachment].samples == pSecondaryAttachments[pSecondary[index].attachment].samples))
1234 return true;
1235 }
1236 // Format and sample counts didn't match
1237 return false;
1238}
1239
1240// For give primary and secondary RenderPass objects, verify that they're compatible
1241static bool verify_renderpass_compatibility(layer_data* my_data, const VkRenderPass primaryRP, const VkRenderPass secondaryRP, string& errorMsg)
1242{
1243 stringstream errorStr;
1244 if (my_data->renderPassMap.find(primaryRP) == my_data->renderPassMap.end()) {
1245 errorStr << "invalid VkRenderPass (" << primaryRP << ")";
1246 errorMsg = errorStr.str();
1247 return false;
1248 } else if (my_data->renderPassMap.find(secondaryRP) == my_data->renderPassMap.end()) {
1249 errorStr << "invalid VkRenderPass (" << secondaryRP << ")";
1250 errorMsg = errorStr.str();
1251 return false;
1252 }
1253 // Trivial pass case is exact same RP
1254 if (primaryRP == secondaryRP)
1255 return true;
1256 const VkRenderPassCreateInfo* primaryRPCI = my_data->renderPassMap[primaryRP]->pCreateInfo;
1257 const VkRenderPassCreateInfo* secondaryRPCI = my_data->renderPassMap[secondaryRP]->pCreateInfo;
1258 if (primaryRPCI->subpassCount != secondaryRPCI->subpassCount) {
1259 errorStr << "RenderPass for primary cmdBuffer has " << primaryRPCI->subpassCount << " subpasses but renderPass for secondary cmdBuffer has " << secondaryRPCI->subpassCount << " subpasses.";
1260 errorMsg = errorStr.str();
1261 return false;
1262 }
1263 uint32_t spIndex = 0;
1264 for (spIndex = 0; spIndex < primaryRPCI->subpassCount; ++spIndex) {
1265 // For each subpass, verify that corresponding color, input, resolve & depth/stencil attachment references are compatible
1266 uint32_t primaryColorCount = primaryRPCI->pSubpasses[spIndex].colorAttachmentCount;
1267 uint32_t secondaryColorCount = secondaryRPCI->pSubpasses[spIndex].colorAttachmentCount;
1268 uint32_t colorMax = std::max(primaryColorCount, secondaryColorCount);
1269 for (uint32_t cIdx = 0; cIdx < colorMax; ++cIdx) {
1270 if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pColorAttachments, primaryColorCount, primaryRPCI->pAttachments,
1271 secondaryRPCI->pSubpasses[spIndex].pColorAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1272 errorStr << "color attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
1273 errorMsg = errorStr.str();
1274 return false;
1275 } else if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pResolveAttachments, primaryColorCount, primaryRPCI->pAttachments,
1276 secondaryRPCI->pSubpasses[spIndex].pResolveAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1277 errorStr << "resolve attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
1278 errorMsg = errorStr.str();
1279 return false;
1280 } else if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pDepthStencilAttachment, primaryColorCount, primaryRPCI->pAttachments,
1281 secondaryRPCI->pSubpasses[spIndex].pDepthStencilAttachment, secondaryColorCount, secondaryRPCI->pAttachments)) {
1282 errorStr << "depth/stencil attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
1283 errorMsg = errorStr.str();
1284 return false;
1285 }
1286 }
1287 uint32_t primaryInputCount = primaryRPCI->pSubpasses[spIndex].inputAttachmentCount;
1288 uint32_t secondaryInputCount = secondaryRPCI->pSubpasses[spIndex].inputAttachmentCount;
1289 uint32_t inputMax = std::max(primaryInputCount, secondaryInputCount);
1290 for (uint32_t i = 0; i < inputMax; ++i) {
1291 if (!attachment_references_compatible(i, primaryRPCI->pSubpasses[spIndex].pInputAttachments, primaryColorCount, primaryRPCI->pAttachments,
1292 secondaryRPCI->pSubpasses[spIndex].pInputAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1293 errorStr << "input attachments at index " << i << " of subpass index " << spIndex << " are not compatible.";
1294 errorMsg = errorStr.str();
1295 return false;
1296 }
1297 }
1298 }
1299 return true;
1300}
1301
Tobin Ehlis559c6382015-11-05 09:52:49 -07001302// For give SET_NODE, verify that its Set is compatible w/ the setLayout corresponding to pipelineLayout[layoutIndex]
1303static bool verify_set_layout_compatibility(layer_data* my_data, const SET_NODE* pSet, const VkPipelineLayout layout, const uint32_t layoutIndex, string& errorMsg)
1304{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001305 stringstream errorStr;
Tobin Ehlis559c6382015-11-05 09:52:49 -07001306 if (my_data->pipelineLayoutMap.find(layout) == my_data->pipelineLayoutMap.end()) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001307 errorStr << "invalid VkPipelineLayout (" << layout << ")";
1308 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001309 return false;
1310 }
1311 PIPELINE_LAYOUT_NODE pl = my_data->pipelineLayoutMap[layout];
1312 if (layoutIndex >= pl.descriptorSetLayouts.size()) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001313 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;
1314 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001315 return false;
1316 }
1317 // Get the specific setLayout from PipelineLayout that overlaps this set
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001318 LAYOUT_NODE* pLayoutNode = my_data->descriptorSetLayoutMap[pl.descriptorSetLayouts[layoutIndex]];
Tobin Ehlis559c6382015-11-05 09:52:49 -07001319 if (pLayoutNode->layout == pSet->pLayout->layout) { // trivial pass case
1320 return true;
1321 }
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07001322 size_t descriptorCount = pLayoutNode->descriptorTypes.size();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001323 if (descriptorCount != pSet->pLayout->descriptorTypes.size()) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001324 errorStr << "setLayout " << layoutIndex << " from pipelineLayout " << layout << " has " << descriptorCount << " descriptors, but corresponding set being bound has " << pSet->pLayout->descriptorTypes.size() << " descriptors.";
1325 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001326 return false; // trivial fail case
1327 }
1328 // Now need to check set against corresponding pipelineLayout to verify compatibility
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07001329 for (size_t i=0; i<descriptorCount; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07001330 // Need to verify that layouts are identically defined
1331 // TODO : Is below sufficient? Making sure that types & stageFlags match per descriptor
1332 // do we also need to check immutable samplers?
1333 if (pLayoutNode->descriptorTypes[i] != pSet->pLayout->descriptorTypes[i]) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001334 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]) << "'";
1335 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001336 return false;
1337 }
1338 if (pLayoutNode->stageFlags[i] != pSet->pLayout->stageFlags[i]) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001339 errorStr << "stageFlags " << i << " for descriptorSet being bound is " << pSet->pLayout->stageFlags[i] << "' but corresponding descriptor from pipelineLayout has stageFlags " << pLayoutNode->stageFlags[i];
1340 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001341 return false;
1342 }
1343 }
1344 return true;
1345}
1346
Tobin Ehlis88452832015-12-03 09:40:56 -07001347// Validate that the shaders used by the given pipeline
1348// As a side effect this function also records the sets that are actually used by the pipeline
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07001349static VkBool32
Tobin Ehlis88452832015-12-03 09:40:56 -07001350validate_pipeline_shaders(layer_data *my_data, VkDevice dev, PIPELINE_NODE* pPipeline)
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001351{
Tobin Ehlis88452832015-12-03 09:40:56 -07001352 VkGraphicsPipelineCreateInfo const *pCreateInfo = &pPipeline->graphicsPipelineCI;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001353 /* We seem to allow pipeline stages to be specified out of order, so collect and identify them
1354 * before trying to do anything more: */
1355 int vertex_stage = get_shader_stage_id(VK_SHADER_STAGE_VERTEX_BIT);
1356 int geometry_stage = get_shader_stage_id(VK_SHADER_STAGE_GEOMETRY_BIT);
1357 int fragment_stage = get_shader_stage_id(VK_SHADER_STAGE_FRAGMENT_BIT);
1358
1359 shader_module **shaders = new shader_module*[fragment_stage + 1]; /* exclude CS */
1360 memset(shaders, 0, sizeof(shader_module *) * (fragment_stage +1));
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001361 RENDER_PASS_NODE const *rp = 0;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001362 VkPipelineVertexInputStateCreateInfo const *vi = 0;
Mark Youngb20a6a82016-01-07 15:41:43 -07001363 VkBool32 pass = VK_TRUE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001364
1365 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
1366 VkPipelineShaderStageCreateInfo const *pStage = &pCreateInfo->pStages[i];
1367 if (pStage->sType == VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO) {
1368
1369 if ((pStage->stage & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_GEOMETRY_BIT | VK_SHADER_STAGE_FRAGMENT_BIT
1370 | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT)) == 0) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001371 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__, SHADER_CHECKER_UNKNOWN_STAGE, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001372 "Unknown shader stage %d", pStage->stage)) {
Mark Youngb20a6a82016-01-07 15:41:43 -07001373 pass = VK_FALSE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001374 }
1375 }
1376 else {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001377 shader_module *module = my_data->shaderModuleMap[pStage->module];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001378 shaders[get_shader_stage_id(pStage->stage)] = module;
1379
1380 /* validate descriptor set layout against what the spirv module actually uses */
1381 std::map<std::pair<unsigned, unsigned>, interface_var> descriptor_uses;
1382 collect_interface_by_descriptor_slot(my_data, dev, module, spv::StorageClassUniform,
1383 descriptor_uses);
1384
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001385 auto layouts = pCreateInfo->layout != VK_NULL_HANDLE ?
1386 &(my_data->pipelineLayoutMap[pCreateInfo->layout].descriptorSetLayouts) : nullptr;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001387
1388 for (auto it = descriptor_uses.begin(); it != descriptor_uses.end(); it++) {
Tobin Ehlis88452832015-12-03 09:40:56 -07001389 // As a side-effect of this function, capture which sets are used by the pipeline
1390 pPipeline->active_sets.insert(it->first.first);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001391
1392 /* find the matching binding */
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001393 auto found = has_descriptor_binding(my_data, layouts, it->first);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001394
1395 if (!found) {
1396 char type_name[1024];
1397 describe_type(type_name, module, it->second.type_id);
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001398 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, /*dev*/0, __LINE__,
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001399 SHADER_CHECKER_MISSING_DESCRIPTOR, "SC",
1400 "Shader uses descriptor slot %u.%u (used as type `%s`) but not declared in pipeline layout",
1401 it->first.first, it->first.second, type_name)) {
Mark Youngb20a6a82016-01-07 15:41:43 -07001402 pass = VK_FALSE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001403 }
1404 }
1405 }
1406 }
1407 }
1408 }
1409
1410 if (pCreateInfo->renderPass != VK_NULL_HANDLE)
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001411 rp = my_data->renderPassMap[pCreateInfo->renderPass];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001412
1413 vi = pCreateInfo->pVertexInputState;
1414
1415 if (vi) {
1416 pass = validate_vi_consistency(my_data, dev, vi) && pass;
1417 }
1418
1419 if (shaders[vertex_stage]) {
1420 pass = validate_vi_against_vs_inputs(my_data, dev, vi, shaders[vertex_stage]) && pass;
1421 }
1422
1423 /* TODO: enforce rules about present combinations of shaders */
1424 int producer = get_shader_stage_id(VK_SHADER_STAGE_VERTEX_BIT);
1425 int consumer = get_shader_stage_id(VK_SHADER_STAGE_GEOMETRY_BIT);
1426
1427 while (!shaders[producer] && producer != fragment_stage) {
1428 producer++;
1429 consumer++;
1430 }
1431
1432 for (; producer != fragment_stage && consumer <= fragment_stage; consumer++) {
1433 assert(shaders[producer]);
1434 if (shaders[consumer]) {
1435 pass = validate_interface_between_stages(my_data, dev,
1436 shaders[producer], shader_stage_attribs[producer].name,
1437 shaders[consumer], shader_stage_attribs[consumer].name,
1438 shader_stage_attribs[consumer].arrayed_input) && pass;
1439
1440 producer = consumer;
1441 }
1442 }
1443
1444 if (shaders[fragment_stage] && rp) {
1445 pass = validate_fs_outputs_against_render_pass(my_data, dev, shaders[fragment_stage], rp, pCreateInfo->subpass) && pass;
1446 }
1447
Chris Forbes47f4f6f2015-12-17 17:10:19 +13001448 delete [] shaders;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001449
1450 return pass;
1451}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001452
Tobin Ehlisf6585052015-12-17 11:48:42 -07001453// Return Set node ptr for specified set or else NULL
1454static SET_NODE* getSetNode(layer_data* my_data, const VkDescriptorSet set)
1455{
1456 loader_platform_thread_lock_mutex(&globalLock);
1457 if (my_data->setMap.find(set) == my_data->setMap.end()) {
1458 loader_platform_thread_unlock_mutex(&globalLock);
1459 return NULL;
1460 }
1461 loader_platform_thread_unlock_mutex(&globalLock);
1462 return my_data->setMap[set];
1463}
1464
1465// For the given set, verify that for each dynamic descriptor in that set that its
1466// dynamic offset combined with the offet and range from its descriptor update
1467// do not overflow the size of its buffer being updated
1468static VkBool32 validate_dynamic_offsets(layer_data* my_data, const SET_NODE* pSet)
1469{
1470 VkBool32 result = VK_FALSE;
1471 if (pSet->dynamicOffsets.empty())
1472 return result;
1473
1474 VkWriteDescriptorSet* pWDS = NULL;
1475 uint32_t dynOffsetIndex = 0;
1476 VkDeviceSize bufferSize = 0;
1477 for (uint32_t i=0; i < pSet->descriptorCount; ++i) {
1478 switch (pSet->ppDescriptors[i]->sType) {
1479 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1480 pWDS = (VkWriteDescriptorSet*)pSet->ppDescriptors[i];
1481 if ((pWDS->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
1482 (pWDS->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
1483 for (uint32_t j=0; j<pWDS->descriptorCount; ++j) {
Michael Lentine700b0aa2015-10-30 17:57:32 -07001484 bufferSize = my_data->bufferMap[pWDS->pBufferInfo[j].buffer].create_info->size;
Tobin Ehlisf6585052015-12-17 11:48:42 -07001485 if ((pSet->dynamicOffsets[dynOffsetIndex] + pWDS->pBufferInfo[j].offset + pWDS->pBufferInfo[j].range) > bufferSize) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001486 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t)pSet->set, __LINE__, DRAWSTATE_DYNAMIC_OFFSET_OVERFLOW, "DS",
Tobin Ehlisf6585052015-12-17 11:48:42 -07001487 "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 ".",
1488 (uint64_t)pSet->set, i, pSet->dynamicOffsets[dynOffsetIndex], pWDS->pBufferInfo[j].offset, pWDS->pBufferInfo[j].range, (uint64_t)pWDS->pBufferInfo[j].buffer, bufferSize);
1489 }
1490 dynOffsetIndex++;
1491 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)
1492 }
1493 }
1494 break;
1495 default: // Currently only shadowing Write update nodes so shouldn't get here
1496 assert(0);
1497 continue;
1498 }
1499 }
1500 return result;
1501}
1502
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001503// Validate overall state at the time of a draw call
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001504static VkBool32 validate_draw_state(layer_data* my_data, GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001505 // First check flag states
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001506 VkBool32 result = validate_draw_state_flags(my_data, pCB, indexedDraw);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001507 PIPELINE_NODE* pPipe = getPipeline(my_data, pCB->lastBoundPipeline);
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001508 // Now complete other state checks
Tobin Ehlise90e66d2015-09-09 13:31:01 -06001509 // TODO : Currently only performing next check if *something* was bound (non-zero last bound)
1510 // There is probably a better way to gate when this check happens, and to know if something *should* have been bound
1511 // We should have that check separately and then gate this check based on that check
Mark Lobodzinski74635932015-12-18 15:35:38 -07001512 if (pPipe) {
1513 if (pCB->lastBoundPipelineLayout) {
1514 string errorString;
1515 for (auto setIndex : pPipe->active_sets) {
1516 // If valid set is not bound throw an error
1517 if ((pCB->boundDescriptorSets.size() <= setIndex) || (!pCB->boundDescriptorSets[setIndex])) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001518 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_DESCRIPTOR_SET_NOT_BOUND, "DS",
Mark Lobodzinski74635932015-12-18 15:35:38 -07001519 "VkPipeline %#" PRIxLEAST64 " uses set #%u but that set is not bound.", (uint64_t)pPipe->pipeline, setIndex);
1520 } else if (!verify_set_layout_compatibility(my_data, my_data->setMap[pCB->boundDescriptorSets[setIndex]], pPipe->graphicsPipelineCI.layout, setIndex, errorString)) {
1521 // Set is bound but not compatible w/ overlapping pipelineLayout from PSO
1522 VkDescriptorSet setHandle = my_data->setMap[pCB->boundDescriptorSets[setIndex]]->set;
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001523 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t)setHandle, __LINE__, DRAWSTATE_PIPELINE_LAYOUTS_INCOMPATIBLE, "DS",
Mark Lobodzinski74635932015-12-18 15:35:38 -07001524 "VkDescriptorSet (%#" PRIxLEAST64 ") bound as set #%u is not compatible with overlapping VkPipelineLayout %#" PRIxLEAST64 " due to: %s",
1525 (uint64_t)setHandle, setIndex, (uint64_t)pPipe->graphicsPipelineCI.layout, errorString.c_str());
Tobin Ehlis43c39c02016-01-11 13:18:40 -07001526 } else { // Valid set is bound and layout compatible, validate that it's updated and verify any dynamic offsets
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07001527 // Add this set as a valid set for this CB
1528 pCB->activeSets.insert(pCB->boundDescriptorSets[setIndex]);
Tobin Ehlis43c39c02016-01-11 13:18:40 -07001529 // Pull the set node
Tobin Ehlisf6585052015-12-17 11:48:42 -07001530 SET_NODE* pSet = getSetNode(my_data, pCB->boundDescriptorSets[setIndex]);
Tobin Ehlis43c39c02016-01-11 13:18:40 -07001531 // Make sure set has been updated
1532 if (!pSet->pUpdateStructs) {
1533 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",
1534 "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);
1535 }
1536 // For each dynamic descriptor, make sure dynamic offset doesn't overstep buffer
Tobin Ehlisf6585052015-12-17 11:48:42 -07001537 result |= validate_dynamic_offsets(my_data, pSet);
Mark Lobodzinski74635932015-12-18 15:35:38 -07001538 }
Tobin Ehlis88452832015-12-03 09:40:56 -07001539 }
1540 }
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07001541
Mark Lobodzinski74635932015-12-18 15:35:38 -07001542 // Verify Vtx binding
1543 if (pPipe->vtxBindingCount > 0) {
1544 VkPipelineVertexInputStateCreateInfo *vtxInCI = &pPipe->vertexInputCI;
1545 for (uint32_t i = 0; i < vtxInCI->vertexBindingDescriptionCount; i++) {
Michael Lentine700b0aa2015-10-30 17:57:32 -07001546 if ((pCB->currentDrawData.buffers.size() < (i+1)) || (pCB->currentDrawData.buffers[i] == VK_NULL_HANDLE)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001547 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS",
Mark Lobodzinski74635932015-12-18 15:35:38 -07001548 "The Pipeline State Object (%#" PRIxLEAST64 ") expects that this Command Buffer's vertex binding Index %d should be set via vkCmdBindVertexBuffers.",
1549 (uint64_t)pCB->lastBoundPipeline, i);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001550
Mark Lobodzinski74635932015-12-18 15:35:38 -07001551 }
1552 }
1553 } else {
Michael Lentine700b0aa2015-10-30 17:57:32 -07001554 if (!pCB->currentDrawData.buffers.empty()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001555 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS,
Mark Lobodzinski74635932015-12-18 15:35:38 -07001556 "DS", "Vertex buffers are bound to command buffer (%#" PRIxLEAST64 ") but no vertex buffers are attached to this Pipeline State Object (%#" PRIxLEAST64 ").",
1557 (uint64_t)pCB->commandBuffer, (uint64_t)pCB->lastBoundPipeline);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06001558 }
1559 }
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07001560
Mark Lobodzinski74635932015-12-18 15:35:38 -07001561 // If Viewport or scissors are dynamic, verify that dynamic count matches PSO count
1562 VkBool32 dynViewport = isDynamic(pPipe, VK_DYNAMIC_STATE_VIEWPORT);
1563 VkBool32 dynScissor = isDynamic(pPipe, VK_DYNAMIC_STATE_SCISSOR);
1564 if (dynViewport) {
1565 if (pCB->viewports.size() != pPipe->graphicsPipelineCI.pViewportState->viewportCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001566 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
Mark Lobodzinski74635932015-12-18 15:35:38 -07001567 "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);
1568 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001569 }
Mark Lobodzinski74635932015-12-18 15:35:38 -07001570 if (dynScissor) {
1571 if (pCB->scissors.size() != pPipe->graphicsPipelineCI.pViewportState->scissorCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001572 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
Mark Lobodzinski74635932015-12-18 15:35:38 -07001573 "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);
1574 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001575 }
1576 }
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001577 return result;
1578}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001579
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001580// Verify that create state for a pipeline is valid
Tobin Ehlis88452832015-12-03 09:40:56 -07001581static VkBool32 verifyPipelineCreateState(layer_data* my_data, const VkDevice device, PIPELINE_NODE* pPipeline)
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001582{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001583 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski2fd2d032015-12-16 14:25:22 -07001584
Tobin Ehlis88452832015-12-03 09:40:56 -07001585 if (!validate_pipeline_shaders(my_data, device, pPipeline)) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001586 skipCall = VK_TRUE;
1587 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001588 // VS is required
1589 if (!(pPipeline->active_shaders & VK_SHADER_STAGE_VERTEX_BIT)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001590 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001591 "Invalid Pipeline CreateInfo State: Vtx Shader required");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001592 }
1593 // Either both or neither TC/TE shaders should be defined
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001594 if (((pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) == 0) !=
1595 ((pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) == 0) ) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001596 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001597 "Invalid Pipeline CreateInfo State: TE and TC shaders must be included or excluded as a pair");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001598 }
1599 // Compute shaders should be specified independent of Gfx shaders
1600 if ((pPipeline->active_shaders & VK_SHADER_STAGE_COMPUTE_BIT) &&
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001601 (pPipeline->active_shaders & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT |
1602 VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT | VK_SHADER_STAGE_GEOMETRY_BIT |
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001603 VK_SHADER_STAGE_FRAGMENT_BIT))) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001604 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001605 "Invalid Pipeline CreateInfo State: Do not specify Compute Shader for Gfx Pipeline");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001606 }
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001607 // VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology is only valid for tessellation pipelines.
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001608 // Mismatching primitive topology and tessellation fails graphics pipeline creation.
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001609 if (pPipeline->active_shaders & (VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) &&
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001610 (pPipeline->iaStateCI.topology != VK_PRIMITIVE_TOPOLOGY_PATCH_LIST)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001611 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001612 "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 -06001613 }
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001614 if (pPipeline->iaStateCI.topology == VK_PRIMITIVE_TOPOLOGY_PATCH_LIST) {
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001615 if (~pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001616 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001617 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology is only valid for tessellation pipelines");
Tobin Ehlis912df022015-09-17 08:46:18 -06001618 }
1619 if (!pPipeline->tessStateCI.patchControlPoints || (pPipeline->tessStateCI.patchControlPoints > 32)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001620 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001621 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology used with patchControlPoints value %u."
Tobin Ehlis912df022015-09-17 08:46:18 -06001622 " patchControlPoints should be >0 and <=32.", pPipeline->tessStateCI.patchControlPoints);
1623 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001624 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001625 // Viewport state must be included and viewport and scissor counts should always match
Tobin Ehlise68360f2015-10-01 11:15:13 -06001626 // NOTE : Even if these are flagged as dynamic, counts need to be set correctly for shader compiler
Tobin Ehlisd332f282015-10-02 11:00:56 -06001627 if (!pPipeline->graphicsPipelineCI.pViewportState) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001628 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
Tobin Ehlisd332f282015-10-02 11:00:56 -06001629 "Gfx Pipeline pViewportState is null. Even if viewport and scissors are dynamic PSO must include viewportCount and scissorCount in pViewportState.");
1630 } else if (pPipeline->graphicsPipelineCI.pViewportState->scissorCount != pPipeline->graphicsPipelineCI.pViewportState->viewportCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001631 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
Tobin Ehlise68360f2015-10-01 11:15:13 -06001632 "Gfx Pipeline viewport count (%u) must match scissor count (%u).", pPipeline->vpStateCI.viewportCount, pPipeline->vpStateCI.scissorCount);
Tobin Ehlisd332f282015-10-02 11:00:56 -06001633 } else {
1634 // If viewport or scissor are not dynamic, then verify that data is appropriate for count
1635 VkBool32 dynViewport = isDynamic(pPipeline, VK_DYNAMIC_STATE_VIEWPORT);
1636 VkBool32 dynScissor = isDynamic(pPipeline, VK_DYNAMIC_STATE_SCISSOR);
1637 if (!dynViewport) {
1638 if (pPipeline->graphicsPipelineCI.pViewportState->viewportCount && !pPipeline->graphicsPipelineCI.pViewportState->pViewports) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001639 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
Courtney Goeltzenleuchterb19042e2015-11-25 11:38:54 -07001640 "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 -06001641 }
1642 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001643 if (!dynScissor) {
1644 if (pPipeline->graphicsPipelineCI.pViewportState->scissorCount && !pPipeline->graphicsPipelineCI.pViewportState->pScissors) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001645 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
Courtney Goeltzenleuchterb19042e2015-11-25 11:38:54 -07001646 "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 -06001647 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06001648 }
1649 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001650 return skipCall;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001651}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001652
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001653// Init the pipeline mapping info based on pipeline create info LL tree
1654// Threading note : Calls to this function should wrapped in mutex
Tobin Ehlis88452832015-12-03 09:40:56 -07001655// TODO : this should really just be in the constructor for PIPELINE_NODE
Mark Lobodzinski475a2182015-11-10 15:25:01 -07001656static PIPELINE_NODE* initGraphicsPipeline(layer_data* dev_data, const VkGraphicsPipelineCreateInfo* pCreateInfo, PIPELINE_NODE* pBasePipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001657{
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001658 PIPELINE_NODE* pPipeline = new PIPELINE_NODE;
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001659
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001660 if (pBasePipeline) {
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001661 *pPipeline = *pBasePipeline;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001662 }
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001663
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001664 // First init create info
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001665 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001666
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001667 size_t bufferSize = 0;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001668 const VkPipelineVertexInputStateCreateInfo* pVICI = NULL;
Tobin Ehlis5a65cca2015-07-13 13:14:24 -06001669 const VkPipelineColorBlendStateCreateInfo* pCBCI = NULL;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001670
1671 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
1672 const VkPipelineShaderStageCreateInfo *pPSSCI = &pCreateInfo->pStages[i];
1673
Chia-I Wu28e06912015-10-31 00:31:16 +08001674 switch (pPSSCI->stage) {
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001675 case VK_SHADER_STAGE_VERTEX_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001676 memcpy(&pPipeline->vsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1677 pPipeline->active_shaders |= VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001678 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001679 case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001680 memcpy(&pPipeline->tcsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001681 pPipeline->active_shaders |= VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001682 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001683 case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001684 memcpy(&pPipeline->tesCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001685 pPipeline->active_shaders |= VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001686 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001687 case VK_SHADER_STAGE_GEOMETRY_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001688 memcpy(&pPipeline->gsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1689 pPipeline->active_shaders |= VK_SHADER_STAGE_GEOMETRY_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001690 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001691 case VK_SHADER_STAGE_FRAGMENT_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001692 memcpy(&pPipeline->fsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1693 pPipeline->active_shaders |= VK_SHADER_STAGE_FRAGMENT_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001694 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001695 case VK_SHADER_STAGE_COMPUTE_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001696 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
1697 pPipeline->active_shaders |= VK_SHADER_STAGE_COMPUTE_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001698 break;
1699 default:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001700 // TODO : Flag error
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001701 break;
1702 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001703 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001704 // Copy over GraphicsPipelineCreateInfo structure embedded pointers
1705 if (pCreateInfo->stageCount != 0) {
1706 pPipeline->graphicsPipelineCI.pStages = new VkPipelineShaderStageCreateInfo[pCreateInfo->stageCount];
1707 bufferSize = pCreateInfo->stageCount * sizeof(VkPipelineShaderStageCreateInfo);
1708 memcpy((void*)pPipeline->graphicsPipelineCI.pStages, pCreateInfo->pStages, bufferSize);
1709 }
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001710 if (pCreateInfo->pVertexInputState != NULL) {
1711 memcpy((void*)&pPipeline->vertexInputCI, pCreateInfo->pVertexInputState , sizeof(VkPipelineVertexInputStateCreateInfo));
1712 // Copy embedded ptrs
1713 pVICI = pCreateInfo->pVertexInputState;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001714 pPipeline->vtxBindingCount = pVICI->vertexBindingDescriptionCount;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001715 if (pPipeline->vtxBindingCount) {
1716 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
1717 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
1718 memcpy((void*)pPipeline->pVertexBindingDescriptions, pVICI->pVertexBindingDescriptions, bufferSize);
1719 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08001720 pPipeline->vtxAttributeCount = pVICI->vertexAttributeDescriptionCount;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001721 if (pPipeline->vtxAttributeCount) {
1722 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
1723 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
1724 memcpy((void*)pPipeline->pVertexAttributeDescriptions, pVICI->pVertexAttributeDescriptions, bufferSize);
1725 }
1726 pPipeline->graphicsPipelineCI.pVertexInputState = &pPipeline->vertexInputCI;
1727 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001728 if (pCreateInfo->pInputAssemblyState != NULL) {
1729 memcpy((void*)&pPipeline->iaStateCI, pCreateInfo->pInputAssemblyState, sizeof(VkPipelineInputAssemblyStateCreateInfo));
1730 pPipeline->graphicsPipelineCI.pInputAssemblyState = &pPipeline->iaStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001731 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001732 if (pCreateInfo->pTessellationState != NULL) {
1733 memcpy((void*)&pPipeline->tessStateCI, pCreateInfo->pTessellationState, sizeof(VkPipelineTessellationStateCreateInfo));
1734 pPipeline->graphicsPipelineCI.pTessellationState = &pPipeline->tessStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001735 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001736 if (pCreateInfo->pViewportState != NULL) {
1737 memcpy((void*)&pPipeline->vpStateCI, pCreateInfo->pViewportState, sizeof(VkPipelineViewportStateCreateInfo));
1738 pPipeline->graphicsPipelineCI.pViewportState = &pPipeline->vpStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001739 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001740 if (pCreateInfo->pRasterizationState != NULL) {
1741 memcpy((void*)&pPipeline->rsStateCI, pCreateInfo->pRasterizationState, sizeof(VkPipelineRasterizationStateCreateInfo));
1742 pPipeline->graphicsPipelineCI.pRasterizationState = &pPipeline->rsStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001743 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001744 if (pCreateInfo->pMultisampleState != NULL) {
1745 memcpy((void*)&pPipeline->msStateCI, pCreateInfo->pMultisampleState, sizeof(VkPipelineMultisampleStateCreateInfo));
1746 pPipeline->graphicsPipelineCI.pMultisampleState = &pPipeline->msStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001747 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001748 if (pCreateInfo->pDepthStencilState != NULL) {
1749 memcpy((void*)&pPipeline->dsStateCI, pCreateInfo->pDepthStencilState, sizeof(VkPipelineDepthStencilStateCreateInfo));
1750 pPipeline->graphicsPipelineCI.pDepthStencilState = &pPipeline->dsStateCI;
1751 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001752 if (pCreateInfo->pColorBlendState != NULL) {
1753 memcpy((void*)&pPipeline->cbStateCI, pCreateInfo->pColorBlendState, sizeof(VkPipelineColorBlendStateCreateInfo));
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001754 // Copy embedded ptrs
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001755 pCBCI = pCreateInfo->pColorBlendState;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001756 pPipeline->attachmentCount = pCBCI->attachmentCount;
1757 if (pPipeline->attachmentCount) {
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001758 pPipeline->pAttachments = new VkPipelineColorBlendAttachmentState[pPipeline->attachmentCount];
1759 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineColorBlendAttachmentState);
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001760 memcpy((void*)pPipeline->pAttachments, pCBCI->pAttachments, bufferSize);
1761 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001762 pPipeline->graphicsPipelineCI.pColorBlendState = &pPipeline->cbStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001763 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001764 if (pCreateInfo->pDynamicState != NULL) {
1765 memcpy((void*)&pPipeline->dynStateCI, pCreateInfo->pDynamicState, sizeof(VkPipelineDynamicStateCreateInfo));
1766 if (pPipeline->dynStateCI.dynamicStateCount) {
1767 pPipeline->dynStateCI.pDynamicStates = new VkDynamicState[pPipeline->dynStateCI.dynamicStateCount];
1768 bufferSize = pPipeline->dynStateCI.dynamicStateCount * sizeof(VkDynamicState);
1769 memcpy((void*)pPipeline->dynStateCI.pDynamicStates, pCreateInfo->pDynamicState->pDynamicStates, bufferSize);
1770 }
1771 pPipeline->graphicsPipelineCI.pDynamicState = &pPipeline->dynStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001772 }
Tobin Ehlis88452832015-12-03 09:40:56 -07001773 pPipeline->active_sets.clear();
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001774 return pPipeline;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001775}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001776
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001777// Free the Pipeline nodes
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001778static void deletePipelines(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001779{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001780 if (my_data->pipelineMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06001781 return;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001782 for (auto ii=my_data->pipelineMap.begin(); ii!=my_data->pipelineMap.end(); ++ii) {
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001783 if ((*ii).second->graphicsPipelineCI.stageCount != 0) {
1784 delete[] (*ii).second->graphicsPipelineCI.pStages;
1785 }
Tobin Ehlisf313c8b2015-04-01 11:59:08 -06001786 if ((*ii).second->pVertexBindingDescriptions) {
1787 delete[] (*ii).second->pVertexBindingDescriptions;
1788 }
1789 if ((*ii).second->pVertexAttributeDescriptions) {
1790 delete[] (*ii).second->pVertexAttributeDescriptions;
1791 }
1792 if ((*ii).second->pAttachments) {
1793 delete[] (*ii).second->pAttachments;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001794 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001795 if ((*ii).second->dynStateCI.dynamicStateCount != 0) {
1796 delete[] (*ii).second->dynStateCI.pDynamicStates;
1797 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001798 delete (*ii).second;
1799 }
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001800 my_data->pipelineMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001801}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001802
Tobin Ehliseba312c2015-04-01 08:40:34 -06001803// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Chia-I Wu5c17c962015-10-31 00:31:16 +08001804static VkSampleCountFlagBits getNumSamples(layer_data* my_data, const VkPipeline pipeline)
Tobin Ehliseba312c2015-04-01 08:40:34 -06001805{
Chia-I Wue2fc5522015-10-26 20:04:44 +08001806 PIPELINE_NODE* pPipe = my_data->pipelineMap[pipeline];
Tobin Ehlis577188e2015-07-13 14:51:15 -06001807 if (VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001808 return pPipe->msStateCI.rasterizationSamples;
Tobin Ehlis577188e2015-07-13 14:51:15 -06001809 }
Chia-I Wu5c17c962015-10-31 00:31:16 +08001810 return VK_SAMPLE_COUNT_1_BIT;
Tobin Ehliseba312c2015-04-01 08:40:34 -06001811}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001812
Tobin Ehliseba312c2015-04-01 08:40:34 -06001813// Validate state related to the PSO
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001814static VkBool32 validatePipelineState(layer_data* my_data, const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehliseba312c2015-04-01 08:40:34 -06001815{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001816 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06001817 // Verify that any MSAA request in PSO matches sample# in bound FB
Chia-I Wu5c17c962015-10-31 00:31:16 +08001818 VkSampleCountFlagBits psoNumSamples = getNumSamples(my_data, pipeline);
Tobin Ehliseba312c2015-04-01 08:40:34 -06001819 if (pCB->activeRenderPass) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001820 const VkRenderPassCreateInfo* pRPCI = my_data->renderPassMap[pCB->activeRenderPass]->pCreateInfo;
Chia-I Wu08accc62015-07-07 11:50:03 +08001821 const VkSubpassDescription* pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
Chia-I Wu5c17c962015-10-31 00:31:16 +08001822 VkSampleCountFlagBits subpassNumSamples = (VkSampleCountFlagBits) 0;
Chia-I Wu08accc62015-07-07 11:50:03 +08001823 uint32_t i;
1824
Chia-I Wud50a7d72015-10-26 20:48:51 +08001825 for (i = 0; i < pSD->colorAttachmentCount; i++) {
Chia-I Wu5c17c962015-10-31 00:31:16 +08001826 VkSampleCountFlagBits samples;
Chia-I Wu08accc62015-07-07 11:50:03 +08001827
Cody Northropa505dda2015-08-04 11:16:41 -06001828 if (pSD->pColorAttachments[i].attachment == VK_ATTACHMENT_UNUSED)
Chia-I Wu08accc62015-07-07 11:50:03 +08001829 continue;
1830
Cody Northropa505dda2015-08-04 11:16:41 -06001831 samples = pRPCI->pAttachments[pSD->pColorAttachments[i].attachment].samples;
Chia-I Wu5c17c962015-10-31 00:31:16 +08001832 if (subpassNumSamples == (VkSampleCountFlagBits) 0) {
Chia-I Wu08accc62015-07-07 11:50:03 +08001833 subpassNumSamples = samples;
1834 } else if (subpassNumSamples != samples) {
Chia-I Wu5c17c962015-10-31 00:31:16 +08001835 subpassNumSamples = (VkSampleCountFlagBits) -1;
Chia-I Wu08accc62015-07-07 11:50:03 +08001836 break;
1837 }
1838 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08001839 if (pSD->pDepthStencilAttachment && pSD->pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
Chia-I Wu5c17c962015-10-31 00:31:16 +08001840 const VkSampleCountFlagBits samples = pRPCI->pAttachments[pSD->pDepthStencilAttachment->attachment].samples;
1841 if (subpassNumSamples == (VkSampleCountFlagBits) 0)
Chia-I Wu08accc62015-07-07 11:50:03 +08001842 subpassNumSamples = samples;
1843 else if (subpassNumSamples != samples)
Chia-I Wu5c17c962015-10-31 00:31:16 +08001844 subpassNumSamples = (VkSampleCountFlagBits) -1;
Chia-I Wu08accc62015-07-07 11:50:03 +08001845 }
1846
1847 if (psoNumSamples != subpassNumSamples) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001848 return log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, (uint64_t) pipeline, __LINE__, DRAWSTATE_NUM_SAMPLES_MISMATCH, "DS",
Mark Lobodzinski5495d132015-09-30 16:19:16 -06001849 "Num samples mismatch! Binding PSO (%#" PRIxLEAST64 ") with %u samples while current RenderPass (%#" PRIxLEAST64 ") w/ %u samples!",
Chia-I Wue2fc5522015-10-26 20:04:44 +08001850 (uint64_t) pipeline, psoNumSamples, (uint64_t) pCB->activeRenderPass, subpassNumSamples);
Tobin Ehliseba312c2015-04-01 08:40:34 -06001851 }
1852 } else {
1853 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
1854 // Verify and flag error as appropriate
1855 }
1856 // TODO : Add more checks here
1857 } else {
1858 // TODO : Validate non-gfx pipeline updates
1859 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001860 return VK_FALSE;
Tobin Ehliseba312c2015-04-01 08:40:34 -06001861}
1862
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001863// Block of code at start here specifically for managing/tracking DSs
1864
Tobin Ehlis793ad302015-04-03 12:01:11 -06001865// Return Pool node ptr for specified pool or else NULL
Mark Lobodzinski39298632015-11-18 08:38:27 -07001866static DESCRIPTOR_POOL_NODE* getPoolNode(layer_data* my_data, const VkDescriptorPool pool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001867{
1868 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07001869 if (my_data->descriptorPoolMap.find(pool) == my_data->descriptorPoolMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001870 loader_platform_thread_unlock_mutex(&globalLock);
1871 return NULL;
1872 }
1873 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07001874 return my_data->descriptorPoolMap[pool];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001875}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001876
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001877static LAYOUT_NODE* getLayoutNode(layer_data* my_data, const VkDescriptorSetLayout layout) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001878 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001879 if (my_data->descriptorSetLayoutMap.find(layout) == my_data->descriptorSetLayoutMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001880 loader_platform_thread_unlock_mutex(&globalLock);
1881 return NULL;
1882 }
1883 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001884 return my_data->descriptorSetLayoutMap[layout];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001885}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001886
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001887// Return VK_FALSE if update struct is of valid type, otherwise flag error and return code from callback
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001888static VkBool32 validUpdateStruct(layer_data* my_data, const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001889{
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001890 switch (pUpdateStruct->sType)
1891 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001892 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1893 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001894 return VK_FALSE;
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001895 default:
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001896 return log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001897 "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 -06001898 }
1899}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001900
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001901// Set count for given update struct in the last parameter
Courtney Goeltzenleuchter085f8dd2015-12-16 16:08:44 -07001902// Return value of skipCall, which is only VK_TRUE if error occurs and callback signals execution to cease
Tobin Ehlisbaca3ab2015-10-27 12:54:50 -06001903static uint32_t getUpdateCount(layer_data* my_data, const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis793ad302015-04-03 12:01:11 -06001904{
1905 switch (pUpdateStruct->sType)
1906 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001907 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
Chia-I Wud50a7d72015-10-26 20:48:51 +08001908 return ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorCount;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001909 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis793ad302015-04-03 12:01:11 -06001910 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wud50a7d72015-10-26 20:48:51 +08001911 return ((VkCopyDescriptorSet*)pUpdateStruct)->descriptorCount;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001912 }
Courtney Goeltzenleuchter7f47bca2015-12-16 16:08:08 -07001913
1914 return 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001915}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001916
Tobin Ehlis793ad302015-04-03 12:01:11 -06001917// For given Layout Node and binding, return index where that binding begins
1918static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
1919{
1920 uint32_t offsetIndex = 0;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001921 for (uint32_t i = 0; i < pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001922 if (pLayout->createInfo.pBindings[i].binding == binding)
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001923 break;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001924 offsetIndex += pLayout->createInfo.pBindings[i].descriptorCount;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001925 }
1926 return offsetIndex;
1927}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001928
Tobin Ehlis793ad302015-04-03 12:01:11 -06001929// For given layout node and binding, return last index that is updated
1930static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
1931{
1932 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 offsetIndex += pLayout->createInfo.pBindings[i].descriptorCount;
1935 if (pLayout->createInfo.pBindings[i].binding == binding)
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001936 break;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001937 }
1938 return offsetIndex-1;
1939}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001940
Tobin Ehlisbaca3ab2015-10-27 12:54:50 -06001941// For given layout and update, return the first overall index of the layout that is updated
Tobin Ehlis8a62e632015-10-27 15:43:38 -06001942static uint32_t getUpdateStartIndex(layer_data* my_data, const VkDevice device, const LAYOUT_NODE* pLayout, const uint32_t binding, const uint32_t arrayIndex, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis793ad302015-04-03 12:01:11 -06001943{
Tobin Ehlisbaca3ab2015-10-27 12:54:50 -06001944 return getBindingStartIndex(pLayout, binding)+arrayIndex;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001945}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001946
Tobin Ehlis8a62e632015-10-27 15:43:38 -06001947// For given layout and update, return the last overall index of the layout that is updated
1948static uint32_t getUpdateEndIndex(layer_data* my_data, const VkDevice device, const LAYOUT_NODE* pLayout, const uint32_t binding, const uint32_t arrayIndex, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis793ad302015-04-03 12:01:11 -06001949{
Tobin Ehlis8a62e632015-10-27 15:43:38 -06001950 uint32_t count = getUpdateCount(my_data, device, pUpdateStruct);
Tobin Ehlisbaca3ab2015-10-27 12:54:50 -06001951 return getBindingStartIndex(pLayout, binding)+arrayIndex+count-1;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001952}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001953
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001954// Verify that the descriptor type in the update struct matches what's expected by the layout
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001955static VkBool32 validateUpdateConsistency(layer_data* my_data, const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct, uint32_t startIndex, uint32_t endIndex)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001956{
1957 // First get actual type of update
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001958 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001959 VkDescriptorType actualType;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001960 uint32_t i = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001961 switch (pUpdateStruct->sType)
1962 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001963 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1964 actualType = ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorType;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001965 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001966 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
1967 /* no need to validate */
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001968 return VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001969 break;
1970 default:
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001971 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001972 "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 -06001973 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001974 if (VK_FALSE == skipCall) {
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001975 // Set first stageFlags as reference and verify that all other updates match it
1976 VkShaderStageFlags refStageFlags = pLayout->stageFlags[startIndex];
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001977 for (i = startIndex; i <= endIndex; i++) {
Tobin Ehlis644ff042015-10-20 10:11:55 -06001978 if (pLayout->descriptorTypes[i] != actualType) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001979 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, "DS",
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001980 "Write descriptor update has descriptor type %s that does not match overlapping binding descriptor type of %s!",
1981 string_VkDescriptorType(actualType), string_VkDescriptorType(pLayout->descriptorTypes[i]));
1982 }
1983 if (pLayout->stageFlags[i] != refStageFlags) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001984 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_DESCRIPTOR_STAGEFLAGS_MISMATCH, "DS",
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001985 "Write descriptor update has stageFlags %x that do not match overlapping binding descriptor stageFlags of %x!",
1986 refStageFlags, pLayout->stageFlags[i]);
Tobin Ehlis483cc352015-09-30 08:30:20 -06001987 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001988 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001989 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001990 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001991}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001992
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001993// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001994// struct into the pNewNode param. Return VK_TRUE if error condition encountered and callback signals early exit.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001995// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001996static VkBool32 shadowUpdateNode(layer_data* my_data, const VkDevice device, GENERIC_HEADER* pUpdate, GENERIC_HEADER** pNewNode)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001997{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001998 VkBool32 skipCall = VK_FALSE;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001999 VkWriteDescriptorSet* pWDS = NULL;
2000 VkCopyDescriptorSet* pCDS = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002001 size_t array_size = 0;
2002 size_t base_array_size = 0;
2003 size_t total_array_size = 0;
2004 size_t baseBuffAddr = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002005 switch (pUpdate->sType)
2006 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002007 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
2008 pWDS = new VkWriteDescriptorSet;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002009 *pNewNode = (GENERIC_HEADER*)pWDS;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002010 memcpy(pWDS, pUpdate, sizeof(VkWriteDescriptorSet));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06002011
2012 switch (pWDS->descriptorType) {
2013 case VK_DESCRIPTOR_TYPE_SAMPLER:
2014 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
2015 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2016 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
2017 {
Chia-I Wud50a7d72015-10-26 20:48:51 +08002018 VkDescriptorImageInfo *info = new VkDescriptorImageInfo[pWDS->descriptorCount];
2019 memcpy(info, pWDS->pImageInfo, pWDS->descriptorCount * sizeof(VkDescriptorImageInfo));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06002020 pWDS->pImageInfo = info;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002021 }
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06002022 break;
2023 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2024 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
2025 {
Chia-I Wud50a7d72015-10-26 20:48:51 +08002026 VkBufferView *info = new VkBufferView[pWDS->descriptorCount];
2027 memcpy(info, pWDS->pTexelBufferView, pWDS->descriptorCount * sizeof(VkBufferView));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06002028 pWDS->pTexelBufferView = info;
2029 }
2030 break;
2031 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2032 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2033 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2034 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
2035 {
Chia-I Wud50a7d72015-10-26 20:48:51 +08002036 VkDescriptorBufferInfo *info = new VkDescriptorBufferInfo[pWDS->descriptorCount];
2037 memcpy(info, pWDS->pBufferInfo, pWDS->descriptorCount * sizeof(VkDescriptorBufferInfo));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06002038 pWDS->pBufferInfo = info;
2039 }
2040 break;
2041 default:
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07002042 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06002043 break;
2044 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002045 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002046 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
2047 pCDS = new VkCopyDescriptorSet;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002048 *pNewNode = (GENERIC_HEADER*)pCDS;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002049 memcpy(pCDS, pUpdate, sizeof(VkCopyDescriptorSet));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002050 break;
2051 default:
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002052 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002053 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdate->sType), pUpdate->sType))
2054 return VK_TRUE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002055 }
2056 // Make sure that pNext for the end of shadow copy is NULL
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002057 (*pNewNode)->pNext = NULL;
2058 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002059}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002060
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002061// Verify that given sampler is valid
2062static VkBool32 validateSampler(const layer_data* my_data, const VkSampler* pSampler, const VkBool32 immutable)
2063{
2064 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002065 auto sampIt = my_data->sampleMap.find(*pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002066 if (sampIt == my_data->sampleMap.end()) {
2067 if (!immutable) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002068 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT, (uint64_t) *pSampler, __LINE__, DRAWSTATE_SAMPLER_DESCRIPTOR_ERROR, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002069 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid sampler %#" PRIxLEAST64, (uint64_t) *pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002070 } else { // immutable
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002071 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT, (uint64_t) *pSampler, __LINE__, DRAWSTATE_SAMPLER_DESCRIPTOR_ERROR, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002072 "vkUpdateDescriptorSets: Attempt to update descriptor whose binding has an invalid immutable sampler %#" PRIxLEAST64, (uint64_t) *pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002073 }
2074 } else {
2075 // TODO : Any further checks we want to do on the sampler?
2076 }
2077 return skipCall;
2078}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002079
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002080// Verify that given imageView is valid
2081static VkBool32 validateImageView(const layer_data* my_data, const VkImageView* pImageView, const VkImageLayout imageLayout)
2082{
2083 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002084 auto ivIt = my_data->imageViewMap.find(*pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002085 if (ivIt == my_data->imageViewMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002086 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, (uint64_t) *pImageView, __LINE__, DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002087 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid imageView %#" PRIxLEAST64, (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002088 } else {
2089 // Validate that imageLayout is compatible with aspectMask and image format
2090 VkImageAspectFlags aspectMask = ivIt->second->subresourceRange.aspectMask;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002091 VkImage image = ivIt->second->image;
Michael Lentine7b236262015-10-23 12:41:44 -07002092 // TODO : Check here in case we have a bad image
Tobin Ehlis75cd1c52016-01-21 10:21:04 -07002093 auto imgIt = my_data->imageLayoutMap.find(image);
2094 if (imgIt == my_data->imageLayoutMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002095 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t) image, __LINE__, DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, "DS",
Michael Lentine7b236262015-10-23 12:41:44 -07002096 "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 -06002097 } else {
2098 VkFormat format = (*imgIt).second->format;
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07002099 VkBool32 ds = vk_format_is_depth_or_stencil(format);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002100 switch (imageLayout) {
2101 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
2102 // Only Color bit must be set
2103 if ((aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) != VK_IMAGE_ASPECT_COLOR_BIT) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002104 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, (uint64_t) *pImageView, __LINE__,
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002105 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL and imageView %#" PRIxLEAST64 ""
Chia-I Wue2fc5522015-10-26 20:04:44 +08002106 " that does not have VK_IMAGE_ASPECT_COLOR_BIT set.", (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002107 }
2108 // format must NOT be DS
2109 if (ds) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002110 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, (uint64_t) *pImageView, __LINE__,
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002111 DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL and imageView %#" PRIxLEAST64 ""
Chia-I Wue2fc5522015-10-26 20:04:44 +08002112 " but the image format is %s which is not a color format.", (uint64_t) *pImageView, string_VkFormat(format));
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002113 }
2114 break;
2115 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
2116 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
2117 // Depth or stencil bit must be set, but both must NOT be set
2118 if (aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) {
2119 if (aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) {
2120 // both must NOT be set
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002121 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, (uint64_t) *pImageView, __LINE__,
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002122 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with imageView %#" PRIxLEAST64 ""
Chia-I Wue2fc5522015-10-26 20:04:44 +08002123 " that has both STENCIL and DEPTH aspects set", (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002124 }
2125 } else if (!(aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)) {
2126 // Neither were set
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002127 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, (uint64_t) *pImageView, __LINE__,
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002128 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout %s and imageView %#" PRIxLEAST64 ""
Chia-I Wue2fc5522015-10-26 20:04:44 +08002129 " that does not have STENCIL or DEPTH aspect set.", string_VkImageLayout(imageLayout), (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002130 }
2131 // format must be DS
2132 if (!ds) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002133 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, (uint64_t) *pImageView, __LINE__,
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002134 DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout %s and imageView %#" PRIxLEAST64 ""
Chia-I Wue2fc5522015-10-26 20:04:44 +08002135 " but the image format is %s which is not a depth/stencil format.", string_VkImageLayout(imageLayout), (uint64_t) *pImageView, string_VkFormat(format));
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002136 }
2137 break;
2138 default:
2139 // anything to check for other layouts?
2140 break;
2141 }
2142 }
2143 }
2144 return skipCall;
2145}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002146
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002147// Verify that given bufferView is valid
2148static VkBool32 validateBufferView(const layer_data* my_data, const VkBufferView* pBufferView)
2149{
2150 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002151 auto sampIt = my_data->bufferViewMap.find(*pBufferView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002152 if (sampIt == my_data->bufferViewMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002153 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_VIEW_EXT, (uint64_t) *pBufferView, __LINE__, DRAWSTATE_BUFFERVIEW_DESCRIPTOR_ERROR, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002154 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid bufferView %#" PRIxLEAST64, (uint64_t) *pBufferView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002155 } else {
2156 // TODO : Any further checks we want to do on the bufferView?
2157 }
2158 return skipCall;
2159}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002160
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002161// Verify that given bufferInfo is valid
2162static VkBool32 validateBufferInfo(const layer_data* my_data, const VkDescriptorBufferInfo* pBufferInfo)
2163{
2164 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002165 auto sampIt = my_data->bufferMap.find(pBufferInfo->buffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002166 if (sampIt == my_data->bufferMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002167 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, (uint64_t) pBufferInfo->buffer, __LINE__, DRAWSTATE_BUFFERINFO_DESCRIPTOR_ERROR, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002168 "vkUpdateDescriptorSets: Attempt to update descriptor where bufferInfo has invalid buffer %#" PRIxLEAST64, (uint64_t) pBufferInfo->buffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002169 } else {
2170 // TODO : Any further checks we want to do on the bufferView?
2171 }
2172 return skipCall;
2173}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002174
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002175static VkBool32 validateUpdateContents(const layer_data* my_data, const VkWriteDescriptorSet *pWDS, const VkDescriptorSetLayoutBinding* pLayoutBinding)
2176{
2177 VkBool32 skipCall = VK_FALSE;
2178 // First verify that for the given Descriptor type, the correct DescriptorInfo data is supplied
2179 VkBufferView* pBufferView = NULL;
2180 const VkSampler* pSampler = NULL;
2181 VkImageView* pImageView = NULL;
2182 VkImageLayout* pImageLayout = NULL;
2183 VkDescriptorBufferInfo* pBufferInfo = NULL;
2184 VkBool32 immutable = VK_FALSE;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002185 uint32_t i = 0;
2186 // For given update type, verify that update contents are correct
2187 switch (pWDS->descriptorType) {
2188 case VK_DESCRIPTOR_TYPE_SAMPLER:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002189 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002190 skipCall |= validateSampler(my_data, &(pWDS->pImageInfo[i].sampler), immutable);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002191 }
2192 break;
2193 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002194 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002195 if (NULL == pLayoutBinding->pImmutableSamplers) {
2196 pSampler = &(pWDS->pImageInfo[i].sampler);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002197 if (immutable) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002198 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT, (uint64_t) *pSampler, __LINE__, DRAWSTATE_INCONSISTENT_IMMUTABLE_SAMPLER_UPDATE, "DS",
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002199 "vkUpdateDescriptorSets: Update #%u is not an immutable sampler %#" PRIxLEAST64 ", but previous update(s) from this "
2200 "VkWriteDescriptorSet struct used an immutable sampler. All updates from a single struct must either "
Chia-I Wue2fc5522015-10-26 20:04:44 +08002201 "use immutable or non-immutable samplers.", i, (uint64_t) *pSampler);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002202 }
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002203 } else {
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002204 if (i>0 && !immutable) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002205 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT, (uint64_t) *pSampler, __LINE__, DRAWSTATE_INCONSISTENT_IMMUTABLE_SAMPLER_UPDATE, "DS",
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002206 "vkUpdateDescriptorSets: Update #%u is an immutable sampler, but previous update(s) from this "
2207 "VkWriteDescriptorSet struct used a non-immutable sampler. All updates from a single struct must either "
2208 "use immutable or non-immutable samplers.", i);
2209 }
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002210 immutable = VK_TRUE;
2211 pSampler = &(pLayoutBinding->pImmutableSamplers[i]);
2212 }
2213 skipCall |= validateSampler(my_data, pSampler, immutable);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002214 }
2215 // Intentionally fall through here to also validate image stuff
2216 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2217 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
2218 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002219 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002220 skipCall |= validateImageView(my_data, &(pWDS->pImageInfo[i].imageView), pWDS->pImageInfo[i].imageLayout);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002221 }
2222 break;
2223 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2224 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002225 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002226 skipCall |= validateBufferView(my_data, &(pWDS->pTexelBufferView[i]));
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002227 }
2228 break;
2229 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2230 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2231 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2232 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002233 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002234 skipCall |= validateBufferInfo(my_data, &(pWDS->pBufferInfo[i]));
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002235 }
2236 break;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002237 }
2238 return skipCall;
2239}
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002240// Validate that given set is valid and that it's not being used by an in-flight CmdBuffer
2241// func_str is the name of the calling function
2242// Return VK_FALSE if no errors occur
2243// Return VK_TRUE if validation error occurs and callback returns VK_TRUE (to skip upcoming API call down the chain)
2244VkBool32 validateIdleDescriptorSet(const layer_data* my_data, VkDescriptorSet set, std::string func_str) {
2245 VkBool32 skip_call = VK_FALSE;
2246 auto set_node = my_data->setMap.find(set);
2247 if (set_node == my_data->setMap.end()) {
Mark Youngee3f3a22016-01-25 12:18:32 -07002248 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",
2249 "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 -07002250 } else {
2251 if (set_node->second->in_use.load()) {
Mark Youngee3f3a22016-01-25 12:18:32 -07002252 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",
2253 "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 -07002254 }
2255 }
2256 return skip_call;
2257}
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002258// update DS mappings based on write and copy update arrays
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08002259static VkBool32 dsUpdate(layer_data* my_data, VkDevice device, uint32_t descriptorWriteCount, const VkWriteDescriptorSet* pWDS, uint32_t descriptorCopyCount, const VkCopyDescriptorSet* pCDS)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002260{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002261 VkBool32 skipCall = VK_FALSE;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002262
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002263 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002264 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002265 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002266 // Validate Write updates
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002267 uint32_t i = 0;
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08002268 for (i=0; i < descriptorWriteCount; i++) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002269 VkDescriptorSet ds = pWDS[i].dstSet;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002270 SET_NODE* pSet = my_data->setMap[ds];
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002271 // Set being updated cannot be in-flight
2272 if ((skipCall = validateIdleDescriptorSet(my_data, ds, "VkUpdateDescriptorSets")) == VK_TRUE)
2273 return skipCall;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002274 GENERIC_HEADER* pUpdate = (GENERIC_HEADER*) &pWDS[i];
Tobin Ehlis793ad302015-04-03 12:01:11 -06002275 pLayout = pSet->pLayout;
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002276 // First verify valid update struct
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06002277 if ((skipCall = validUpdateStruct(my_data, device, pUpdate)) == VK_TRUE) {
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002278 break;
2279 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002280 uint32_t binding = 0, endIndex = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002281 binding = pWDS[i].dstBinding;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002282 // Make sure that layout being updated has the binding being updated
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002283 if (pLayout->bindings.find(binding) == pLayout->bindings.end()) {
Mark Young93ecb1d2016-01-13 13:47:16 -07002284 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",
2285 "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 -06002286 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06002287 // Next verify that update falls within size of given binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002288 endIndex = getUpdateEndIndex(my_data, device, pLayout, binding, pWDS[i].dstArrayElement, pUpdate);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002289 if (getBindingEndIndex(pLayout, binding) < endIndex) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06002290 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002291 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Mark Young93ecb1d2016-01-13 13:47:16 -07002292 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t)(ds), __LINE__, DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, "DS",
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002293 "Descriptor update type of %s is out of bounds for matching binding %u in Layout w/ CI:\n%s!", string_VkStructureType(pUpdate->sType), binding, DSstr.c_str());
Tobin Ehlis9c536442015-06-19 13:00:59 -06002294 } else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002295 uint32_t startIndex;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002296 startIndex = getUpdateStartIndex(my_data, device, pLayout, binding, pWDS[i].dstArrayElement, pUpdate);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002297 // Layout bindings match w/ update, now verify that update type & stageFlags are the same for entire update
2298 if ((skipCall = validateUpdateConsistency(my_data, device, pLayout, pUpdate, startIndex, endIndex)) == VK_FALSE) {
2299 // The update is within bounds and consistent, but need to make sure contents make sense as well
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002300 if ((skipCall = validateUpdateContents(my_data, &pWDS[i], &pLayout->createInfo.pBindings[binding])) == VK_FALSE) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002301 // Update is good. Save the update info
2302 // Create new update struct for this set's shadow copy
2303 GENERIC_HEADER* pNewNode = NULL;
2304 skipCall |= shadowUpdateNode(my_data, device, pUpdate, &pNewNode);
2305 if (NULL == pNewNode) {
Mark Young93ecb1d2016-01-13 13:47:16 -07002306 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t)(ds), __LINE__, DRAWSTATE_OUT_OF_MEMORY, "DS",
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002307 "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
2308 } else {
2309 // Insert shadow node into LL of updates for this set
2310 pNewNode->pNext = pSet->pUpdateStructs;
2311 pSet->pUpdateStructs = pNewNode;
2312 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002313 for (uint32_t j = startIndex; j <= endIndex; j++) {
2314 assert(j<pSet->descriptorCount);
2315 pSet->ppDescriptors[j] = pNewNode;
2316 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002317 }
2318 }
2319 }
2320 }
2321 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002322 }
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002323 // Now validate copy updates
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08002324 for (i=0; i < descriptorCopyCount; ++i) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002325 SET_NODE *pSrcSet = NULL, *pDstSet = NULL;
2326 LAYOUT_NODE *pSrcLayout = NULL, *pDstLayout = NULL;
2327 uint32_t srcStartIndex = 0, srcEndIndex = 0, dstStartIndex = 0, dstEndIndex = 0;
2328 // For each copy make sure that update falls within given layout and that types match
Chia-I Wue2fc5522015-10-26 20:04:44 +08002329 pSrcSet = my_data->setMap[pCDS[i].srcSet];
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002330 pDstSet = my_data->setMap[pCDS[i].dstSet];
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002331 // Set being updated cannot be in-flight
2332 if ((skipCall = validateIdleDescriptorSet(my_data, pDstSet->set, "VkUpdateDescriptorSets")) == VK_TRUE)
2333 return skipCall;
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002334 pSrcLayout = pSrcSet->pLayout;
2335 pDstLayout = pDstSet->pLayout;
2336 // Validate that src binding is valid for src set layout
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002337 if (pSrcLayout->bindings.find(pCDS[i].srcBinding) == pSrcLayout->bindings.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002338 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pSrcSet->set, __LINE__, DRAWSTATE_INVALID_UPDATE_INDEX, "DS",
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002339 "Copy descriptor update %u has srcBinding %u which is out of bounds for underlying SetLayout %#" PRIxLEAST64 " which only has bindings 0-%u.",
Chia-I Wud50a7d72015-10-26 20:48:51 +08002340 i, pCDS[i].srcBinding, (uint64_t) pSrcLayout->layout, pSrcLayout->createInfo.bindingCount-1);
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002341 } else if (pDstLayout->bindings.find(pCDS[i].dstBinding) == pDstLayout->bindings.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002342 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pDstSet->set, __LINE__, DRAWSTATE_INVALID_UPDATE_INDEX, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002343 "Copy descriptor update %u has dstBinding %u which is out of bounds for underlying SetLayout %#" PRIxLEAST64 " which only has bindings 0-%u.",
2344 i, pCDS[i].dstBinding, (uint64_t) pDstLayout->layout, pDstLayout->createInfo.bindingCount-1);
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002345 } else {
2346 // Proceed with validation. Bindings are ok, but make sure update is within bounds of given layout
2347 srcEndIndex = getUpdateEndIndex(my_data, device, pSrcLayout, pCDS[i].srcBinding, pCDS[i].srcArrayElement, (const GENERIC_HEADER*)&(pCDS[i]));
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002348 dstEndIndex = getUpdateEndIndex(my_data, device, pDstLayout, pCDS[i].dstBinding, pCDS[i].dstArrayElement, (const GENERIC_HEADER*)&(pCDS[i]));
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002349 if (getBindingEndIndex(pSrcLayout, pCDS[i].srcBinding) < srcEndIndex) {
2350 pLayoutCI = &pSrcLayout->createInfo;
2351 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002352 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pSrcSet->set, __LINE__, DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, "DS",
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002353 "Copy descriptor src update is out of bounds for matching binding %u in Layout w/ CI:\n%s!", pCDS[i].srcBinding, DSstr.c_str());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002354 } else if (getBindingEndIndex(pDstLayout, pCDS[i].dstBinding) < dstEndIndex) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002355 pLayoutCI = &pDstLayout->createInfo;
2356 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002357 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pDstSet->set, __LINE__, DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002358 "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 -06002359 } else {
2360 srcStartIndex = getUpdateStartIndex(my_data, device, pSrcLayout, pCDS[i].srcBinding, pCDS[i].srcArrayElement, (const GENERIC_HEADER*)&(pCDS[i]));
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002361 dstStartIndex = getUpdateStartIndex(my_data, device, pDstLayout, pCDS[i].dstBinding, pCDS[i].dstArrayElement, (const GENERIC_HEADER*)&(pCDS[i]));
Chia-I Wud50a7d72015-10-26 20:48:51 +08002362 for (uint32_t j=0; j<pCDS[i].descriptorCount; ++j) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002363 // For copy just make sure that the types match and then perform the update
2364 if (pSrcLayout->descriptorTypes[srcStartIndex+j] != pDstLayout->descriptorTypes[dstStartIndex+j]) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002365 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, "DS",
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002366 "Copy descriptor update index %u, update count #%u, has src update descriptor type %s that does not match overlapping dest descriptor type of %s!",
2367 i, j+1, string_VkDescriptorType(pSrcLayout->descriptorTypes[srcStartIndex+j]), string_VkDescriptorType(pDstLayout->descriptorTypes[dstStartIndex+j]));
2368 } else {
2369 // point dst descriptor at corresponding src descriptor
Tobin Ehlisf6585052015-12-17 11:48:42 -07002370 // TODO : This may be a hole. I believe copy should be its own copy,
2371 // otherwise a subsequent write update to src will incorrectly affect the copy
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002372 pDstSet->ppDescriptors[j+dstStartIndex] = pSrcSet->ppDescriptors[j+srcStartIndex];
2373 }
2374 }
2375 }
2376 }
2377 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002378 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002379 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002380}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002381
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002382// Verify that given pool has descriptors that are being requested for allocation
Mark Lobodzinski39298632015-11-18 08:38:27 -07002383static VkBool32 validate_descriptor_availability_in_pool(layer_data* dev_data, DESCRIPTOR_POOL_NODE* pPoolNode, uint32_t count, const VkDescriptorSetLayout* pSetLayouts)
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002384{
2385 VkBool32 skipCall = VK_FALSE;
2386 uint32_t i = 0, j = 0;
2387 for (i=0; i<count; ++i) {
2388 LAYOUT_NODE* pLayout = getLayoutNode(dev_data, pSetLayouts[i]);
2389 if (NULL == pLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002390 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, (uint64_t) pSetLayouts[i], __LINE__, DRAWSTATE_INVALID_LAYOUT, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002391 "Unable to find set layout node for layout %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pSetLayouts[i]);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002392 } else {
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002393 uint32_t typeIndex = 0, poolSizeCount = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002394 for (j=0; j<pLayout->createInfo.bindingCount; ++j) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002395 typeIndex = static_cast<uint32_t>(pLayout->createInfo.pBindings[j].descriptorType);
2396 poolSizeCount = pLayout->createInfo.pBindings[j].descriptorCount;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002397 if (poolSizeCount > pPoolNode->availableDescriptorTypeCount[typeIndex]) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002398 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, (uint64_t) pLayout->layout, __LINE__, DRAWSTATE_DESCRIPTOR_POOL_EMPTY, "DS",
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002399 "Unable to allocate %u descriptors of type %s from pool %#" PRIxLEAST64 ". This pool only has %u descriptors of this type remaining.",
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002400 poolSizeCount, string_VkDescriptorType(pLayout->createInfo.pBindings[j].descriptorType), (uint64_t) pPoolNode->pool, pPoolNode->availableDescriptorTypeCount[typeIndex]);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002401 } else { // Decrement available descriptors of this type
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002402 pPoolNode->availableDescriptorTypeCount[typeIndex] -= poolSizeCount;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002403 }
2404 }
2405 }
2406 }
2407 return skipCall;
2408}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002409
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002410// Free the shadowed update node for this Set
2411// NOTE : Calls to this function should be wrapped in mutex
2412static void freeShadowUpdateTree(SET_NODE* pSet)
2413{
2414 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
2415 pSet->pUpdateStructs = NULL;
2416 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
2417 // Clear the descriptor mappings as they will now be invalid
2418 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
2419 while(pShadowUpdate) {
2420 pFreeUpdate = pShadowUpdate;
2421 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
2422 uint32_t index = 0;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002423 VkWriteDescriptorSet * pWDS = NULL;
2424 VkCopyDescriptorSet * pCDS = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002425 void** ppToFree = NULL;
2426 switch (pFreeUpdate->sType)
2427 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002428 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
2429 pWDS = (VkWriteDescriptorSet*)pFreeUpdate;
Tony Barbourb1947942015-11-02 11:46:29 -07002430 switch (pWDS->descriptorType) {
2431 case VK_DESCRIPTOR_TYPE_SAMPLER:
2432 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
2433 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2434 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
2435 {
2436 delete[] pWDS->pImageInfo;
2437 }
2438 break;
2439 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2440 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
2441 {
2442 delete[] pWDS->pTexelBufferView;
2443 }
2444 break;
2445 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2446 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2447 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2448 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
2449 {
2450 delete[] pWDS->pBufferInfo;
2451 }
2452 break;
2453 default:
2454 break;
Courtney Goeltzenleuchteraa132e72015-10-22 15:31:56 -06002455 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002456 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002457 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002458 break;
2459 default:
2460 assert(0);
2461 break;
2462 }
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002463 delete pFreeUpdate;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002464 }
2465}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002466
Tobin Ehlis793ad302015-04-03 12:01:11 -06002467// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002468// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002469static void deletePools(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002470{
Mark Lobodzinski39298632015-11-18 08:38:27 -07002471 if (my_data->descriptorPoolMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06002472 return;
Mark Lobodzinski39298632015-11-18 08:38:27 -07002473 for (auto ii=my_data->descriptorPoolMap.begin(); ii!=my_data->descriptorPoolMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002474 SET_NODE* pSet = (*ii).second->pSets;
2475 SET_NODE* pFreeSet = pSet;
2476 while (pSet) {
2477 pFreeSet = pSet;
2478 pSet = pSet->pNext;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002479 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002480 // Free Update shadow struct tree
2481 freeShadowUpdateTree(pFreeSet);
2482 if (pFreeSet->ppDescriptors) {
Chris Forbes02038792015-06-04 10:49:27 +12002483 delete[] pFreeSet->ppDescriptors;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002484 }
2485 delete pFreeSet;
2486 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002487 delete (*ii).second;
2488 }
Mark Lobodzinski39298632015-11-18 08:38:27 -07002489 my_data->descriptorPoolMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002490}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002491
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002492// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002493// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002494static void deleteLayouts(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002495{
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07002496 if (my_data->descriptorSetLayoutMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06002497 return;
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07002498 for (auto ii=my_data->descriptorSetLayoutMap.begin(); ii!=my_data->descriptorSetLayoutMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002499 LAYOUT_NODE* pLayout = (*ii).second;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002500 if (pLayout->createInfo.pBindings) {
Chia-I Wud50a7d72015-10-26 20:48:51 +08002501 for (uint32_t i=0; i<pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002502 if (pLayout->createInfo.pBindings[i].pImmutableSamplers)
2503 delete[] pLayout->createInfo.pBindings[i].pImmutableSamplers;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002504 }
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002505 delete[] pLayout->createInfo.pBindings;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002506 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002507 delete pLayout;
2508 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07002509 my_data->descriptorSetLayoutMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002510}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002511
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002512// Currently clearing a set is removing all previous updates to that set
2513// TODO : Validate if this is correct clearing behavior
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002514static void clearDescriptorSet(layer_data* my_data, VkDescriptorSet set)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002515{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002516 SET_NODE* pSet = getSetNode(my_data, set);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002517 if (!pSet) {
2518 // TODO : Return error
Tobin Ehlisce132d82015-06-19 15:07:05 -06002519 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002520 loader_platform_thread_lock_mutex(&globalLock);
2521 freeShadowUpdateTree(pSet);
2522 loader_platform_thread_unlock_mutex(&globalLock);
2523 }
2524}
2525
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002526static void clearDescriptorPool(layer_data* my_data, const VkDevice device, const VkDescriptorPool pool, VkDescriptorPoolResetFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002527{
Mark Lobodzinski39298632015-11-18 08:38:27 -07002528 DESCRIPTOR_POOL_NODE* pPool = getPoolNode(my_data, pool);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002529 if (!pPool) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002530 log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, (uint64_t) pool, __LINE__, DRAWSTATE_INVALID_POOL, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002531 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkResetDescriptorPool() call", (uint64_t) pool);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002532 } else {
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002533 // TODO: validate flags
Tobin Ehlis793ad302015-04-03 12:01:11 -06002534 // For every set off of this pool, clear it
2535 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002536 while (pSet) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002537 clearDescriptorSet(my_data, pSet->set);
Mark Lobodzinskidcce0792016-01-04 09:40:19 -07002538 pSet = pSet->pNext;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002539 }
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002540 // Reset available count to max count for this pool
2541 for (uint32_t i=0; i<pPool->availableDescriptorTypeCount.size(); ++i) {
2542 pPool->availableDescriptorTypeCount[i] = pPool->maxDescriptorTypeCount[i];
2543 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002544 }
2545}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002546
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002547// For given CB object, fetch associated CB Node from map
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002548static GLOBAL_CB_NODE* getCBNode(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002549{
2550 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002551 if (my_data->commandBufferMap.count(cb) == 0) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002552 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002553 // TODO : How to pass cb as srcObj here?
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002554 log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER, "DS",
Mark Youngee3f3a22016-01-25 12:18:32 -07002555 "Attempt to use CommandBuffer %#" PRIxLEAST64 " that doesn't exist!", (uint64_t)(cb));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002556 return NULL;
2557 }
2558 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002559 return my_data->commandBufferMap[cb];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002560}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002561
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002562// Free all CB Nodes
2563// NOTE : Calls to this function should be wrapped in mutex
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002564static void deleteCommandBuffers(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002565{
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002566 if (my_data->commandBufferMap.size() <= 0) {
David Pinedod8f83d82015-04-27 16:36:17 -06002567 return;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002568 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002569 for (auto ii=my_data->commandBufferMap.begin(); ii!=my_data->commandBufferMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002570 delete (*ii).second;
2571 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002572 my_data->commandBufferMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002573}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002574
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002575static VkBool32 report_error_no_cb_begin(const layer_data* dev_data, const VkCommandBuffer cb, const char* caller_name)
Tobin Ehlis9c536442015-06-19 13:00:59 -06002576{
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002577 return log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002578 (uint64_t)cb, __LINE__, DRAWSTATE_NO_BEGIN_COMMAND_BUFFER, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002579 "You must call vkBeginCommandBuffer() before this call to %s", caller_name);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002580}
Michael Lentine3dea6512015-10-28 15:55:18 -07002581
Mark Youngb20a6a82016-01-07 15:41:43 -07002582VkBool32 validateCmdsInCmdBuffer(const layer_data* dev_data, const GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd_type) {
2583 if (!pCB->activeRenderPass) return VK_FALSE;
2584 VkBool32 skip_call = VK_FALSE;
Michael Lentine2e068b22015-12-29 16:05:27 -06002585 if (pCB->activeSubpassContents == VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS && cmd_type != CMD_EXECUTECOMMANDS) {
2586 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
2587 DRAWSTATE_INVALID_COMMAND_BUFFER, "DS", "Commands cannot be called in a subpass using secondary command buffers.");
2588 } else if (pCB->activeSubpassContents == VK_SUBPASS_CONTENTS_INLINE && cmd_type == CMD_EXECUTECOMMANDS) {
2589 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
2590 DRAWSTATE_INVALID_COMMAND_BUFFER, "DS", "vkCmdExecuteCommands() cannot be called in a subpass using inline commands.");
2591 }
Michael Lentine3dea6512015-10-28 15:55:18 -07002592 return skip_call;
2593}
2594
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002595// Add specified CMD to the CmdBuffer in given pCB, flagging errors if CB is not
2596// in the recording state or if there's an issue with the Cmd ordering
2597static VkBool32 addCmd(const layer_data* my_data, GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd, const char* caller_name)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002598{
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002599 VkBool32 skipCall = VK_FALSE;
2600 if (pCB->state != CB_RECORDING) {
2601 skipCall |= report_error_no_cb_begin(my_data, pCB->commandBuffer, caller_name);
2602 skipCall |= validateCmdsInCmdBuffer(my_data, pCB, cmd);
Tobin Ehlis9a874302016-01-20 10:25:29 -07002603 CMD_NODE cmdNode = {};
2604 // init cmd node and append to end of cmd LL
2605 cmdNode.cmdNumber = ++pCB->numCmds;
2606 cmdNode.type = cmd;
2607 pCB->cmds.push_back(cmdNode);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002608 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002609 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002610}
Tobin Ehlisef694652016-01-19 12:03:34 -07002611// Reset the command buffer state
2612// Maintain the createInfo and set state to CB_NEW, but clear all other state
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002613static void resetCB(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002614{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002615 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002616 if (pCB) {
Tobin Ehlis9a874302016-01-20 10:25:29 -07002617 pCB->cmds.clear();
Tobin Ehlisef694652016-01-19 12:03:34 -07002618 // Reset CB state (note that createInfo is not cleared)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002619 pCB->commandBuffer = cb;
Michael Lentineabc5e922015-10-12 11:30:14 -05002620 memset(&pCB->beginInfo, 0, sizeof(VkCommandBufferBeginInfo));
Tobin Ehliscd5bfd82016-01-19 13:12:52 -07002621 memset(&pCB->inheritanceInfo, 0, sizeof(VkCommandBufferInheritanceInfo));
Michael Lentineabc5e922015-10-12 11:30:14 -05002622 pCB->fence = 0;
2623 pCB->numCmds = 0;
2624 memset(pCB->drawCount, 0, NUM_DRAW_TYPES * sizeof(uint64_t));
2625 pCB->state = CB_NEW;
2626 pCB->submitCount = 0;
2627 pCB->status = 0;
Michael Lentineabc5e922015-10-12 11:30:14 -05002628 pCB->lastBoundPipeline = 0;
2629 pCB->viewports.clear();
2630 pCB->scissors.clear();
2631 pCB->lineWidth = 0;
2632 pCB->depthBiasConstantFactor = 0;
2633 pCB->depthBiasClamp = 0;
2634 pCB->depthBiasSlopeFactor = 0;
2635 memset(pCB->blendConstants, 0, 4 * sizeof(float));
2636 pCB->minDepthBounds = 0;
2637 pCB->maxDepthBounds = 0;
2638 memset(&pCB->front, 0, sizeof(stencil_data));
2639 memset(&pCB->back, 0, sizeof(stencil_data));
2640 pCB->lastBoundDescriptorSet = 0;
2641 pCB->lastBoundPipelineLayout = 0;
2642 pCB->activeRenderPass = 0;
2643 pCB->activeSubpass = 0;
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002644 pCB->activeSets.clear();
Michael Lentineabc5e922015-10-12 11:30:14 -05002645 pCB->framebuffer = 0;
Michael Lentineabc5e922015-10-12 11:30:14 -05002646 pCB->boundDescriptorSets.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07002647 pCB->drawData.clear();
2648 pCB->currentDrawData.buffers.clear();
Michael Lentineabc5e922015-10-12 11:30:14 -05002649 pCB->imageLayoutMap.clear();
Michael Lentineb887b0a2015-12-29 14:12:11 -06002650 pCB->waitedEvents.clear();
2651 pCB->waitedEventsBeforeQueryReset.clear();
2652 pCB->queryToStateMap.clear();
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07002653 pCB->secondaryCommandBuffers.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002654 }
2655}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002656
Tobin Ehlis963a4042015-09-29 08:18:34 -06002657// Set PSO-related status bits for CB, including dynamic state set via PSO
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002658static void set_cb_pso_status(GLOBAL_CB_NODE* pCB, const PIPELINE_NODE* pPipe)
2659{
2660 for (uint32_t i = 0; i < pPipe->cbStateCI.attachmentCount; i++) {
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002661 if (0 != pPipe->pAttachments[i].colorWriteMask) {
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002662 pCB->status |= CBSTATUS_COLOR_BLEND_WRITE_ENABLE;
2663 }
2664 }
2665 if (pPipe->dsStateCI.depthWriteEnable) {
Cody Northrop82485a82015-08-18 15:21:16 -06002666 pCB->status |= CBSTATUS_DEPTH_WRITE_ENABLE;
2667 }
Cody Northrop82485a82015-08-18 15:21:16 -06002668 if (pPipe->dsStateCI.stencilTestEnable) {
2669 pCB->status |= CBSTATUS_STENCIL_TEST_ENABLE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002670 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06002671 // Account for any dynamic state not set via this PSO
2672 if (!pPipe->dynStateCI.dynamicStateCount) { // All state is static
2673 pCB->status = CBSTATUS_ALL;
2674 } else {
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002675 // First consider all state on
2676 // Then unset any state that's noted as dynamic in PSO
2677 // Finally OR that into CB statemask
2678 CBStatusFlags psoDynStateMask = CBSTATUS_ALL;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002679 for (uint32_t i=0; i < pPipe->dynStateCI.dynamicStateCount; i++) {
2680 switch (pPipe->dynStateCI.pDynamicStates[i]) {
2681 case VK_DYNAMIC_STATE_VIEWPORT:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002682 psoDynStateMask &= ~CBSTATUS_VIEWPORT_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002683 break;
2684 case VK_DYNAMIC_STATE_SCISSOR:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002685 psoDynStateMask &= ~CBSTATUS_SCISSOR_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002686 break;
2687 case VK_DYNAMIC_STATE_LINE_WIDTH:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002688 psoDynStateMask &= ~CBSTATUS_LINE_WIDTH_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002689 break;
2690 case VK_DYNAMIC_STATE_DEPTH_BIAS:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002691 psoDynStateMask &= ~CBSTATUS_DEPTH_BIAS_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002692 break;
2693 case VK_DYNAMIC_STATE_BLEND_CONSTANTS:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002694 psoDynStateMask &= ~CBSTATUS_BLEND_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002695 break;
2696 case VK_DYNAMIC_STATE_DEPTH_BOUNDS:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002697 psoDynStateMask &= ~CBSTATUS_DEPTH_BOUNDS_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002698 break;
2699 case VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002700 psoDynStateMask &= ~CBSTATUS_STENCIL_READ_MASK_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002701 break;
2702 case VK_DYNAMIC_STATE_STENCIL_WRITE_MASK:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002703 psoDynStateMask &= ~CBSTATUS_STENCIL_WRITE_MASK_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002704 break;
2705 case VK_DYNAMIC_STATE_STENCIL_REFERENCE:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002706 psoDynStateMask &= ~CBSTATUS_STENCIL_REFERENCE_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002707 break;
2708 default:
2709 // TODO : Flag error here
2710 break;
2711 }
2712 }
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002713 pCB->status |= psoDynStateMask;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002714 }
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002715}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002716
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002717// Print the last bound Gfx Pipeline
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002718static VkBool32 printPipeline(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002719{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002720 VkBool32 skipCall = VK_FALSE;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002721 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002722 if (pCB) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002723 PIPELINE_NODE *pPipeTrav = getPipeline(my_data, pCB->lastBoundPipeline);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002724 if (!pPipeTrav) {
2725 // nothing to print
Tobin Ehlisce132d82015-06-19 15:07:05 -06002726 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002727 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
Michael Lentine010f4692015-11-03 16:19:46 -08002728 "%s", vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002729 }
2730 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002731 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002732}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002733
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002734// Print details of DS config to stdout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002735static VkBool32 printDSConfig(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002736{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002737 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002738 char ds_config_str[1024*256] = {0}; // TODO : Currently making this buffer HUGE w/o overrun protection. Need to be smarter, start smaller, and grow as needed.
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002739 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis93f89e82015-06-09 08:39:32 -06002740 if (pCB && pCB->lastBoundDescriptorSet) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002741 SET_NODE* pSet = getSetNode(my_data, pCB->lastBoundDescriptorSet);
Mark Lobodzinski39298632015-11-18 08:38:27 -07002742 DESCRIPTOR_POOL_NODE* pPool = getPoolNode(my_data, pSet->pool);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002743 // Print out pool details
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002744 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002745 "Details for pool %#" PRIxLEAST64 ".", (uint64_t) pPool->pool);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002746 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002747 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002748 "%s", poolStr.c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002749 // Print out set details
2750 char prefix[10];
2751 uint32_t index = 0;
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002752 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002753 "Details for descriptor set %#" PRIxLEAST64 ".", (uint64_t) pSet->set);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002754 LAYOUT_NODE* pLayout = pSet->pLayout;
2755 // Print layout details
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002756 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
Mark Young93ecb1d2016-01-13 13:47:16 -07002757 "Layout #%u, (object %#" PRIxLEAST64 ") for DS %#" PRIxLEAST64 ".", index+1, (uint64_t)(pLayout->layout), (uint64_t)(pSet->set));
Tobin Ehlis793ad302015-04-03 12:01:11 -06002758 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002759 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002760 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002761 "%s", DSLstr.c_str());
Tobin Ehlis793ad302015-04-03 12:01:11 -06002762 index++;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002763 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
2764 if (pUpdate) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002765 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002766 "Update Chain [UC] for descriptor set %#" PRIxLEAST64 ":", (uint64_t) pSet->set);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002767 sprintf(prefix, " [UC] ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002768 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
Michael Lentine010f4692015-11-03 16:19:46 -08002769 "%s", dynamic_display(pUpdate, prefix).c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002770 // TODO : If there is a "view" associated with this update, print CI for that view
Tobin Ehlisce132d82015-06-19 15:07:05 -06002771 } else {
Tobin Ehlisbf081f32015-06-15 08:41:17 -06002772 if (0 != pSet->descriptorCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002773 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002774 "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 -06002775 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002776 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002777 "FYI: No descriptors in descriptor set %#" PRIxLEAST64 ".", (uint64_t) pSet->set);
Tobin Ehlisbf081f32015-06-15 08:41:17 -06002778 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002779 }
2780 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002781 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002782}
2783
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002784static void printCB(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002785{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002786 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis9a874302016-01-20 10:25:29 -07002787 if (pCB && pCB->cmds.size() > 0) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002788 log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002789 "Cmds in CB %p", (void*)cb);
Tobin Ehlis9a874302016-01-20 10:25:29 -07002790 vector<CMD_NODE> cmds = pCB->cmds;
2791 for (auto ii=cmds.begin(); ii!=cmds.end(); ++ii) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002792 // TODO : Need to pass cb as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002793 log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_NONE, "DS",
Tobin Ehlis9a874302016-01-20 10:25:29 -07002794 " CMD#%" PRIu64 ": %s", (*ii).cmdNumber, cmdTypeToString((*ii).type).c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002795 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002796 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002797 // Nothing to print
2798 }
2799}
2800
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002801static VkBool32 synchAndPrintDSConfig(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002802{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002803 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002804 if (!(my_data->report_data->active_flags & VK_DEBUG_REPORT_INFO_BIT_EXT)) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002805 return skipCall;
Mike Stroyanba35e352015-08-12 17:11:28 -06002806 }
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002807 skipCall |= printDSConfig(my_data, cb);
2808 skipCall |= printPipeline(my_data, cb);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002809 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002810}
2811
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002812// Flags validation error if the associated call is made inside a render pass. The apiName
2813// routine should ONLY be called outside a render pass.
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06002814static VkBool32 insideRenderPass(const layer_data* my_data, GLOBAL_CB_NODE *pCB, const char *apiName)
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002815{
2816 VkBool32 inside = VK_FALSE;
2817 if (pCB->activeRenderPass) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002818 inside = log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002819 (uint64_t)pCB->commandBuffer, __LINE__, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002820 "%s: It is invalid to issue this call inside an active render pass (%#" PRIxLEAST64 ")",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002821 apiName, (uint64_t) pCB->activeRenderPass);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002822 }
2823 return inside;
2824}
2825
2826// Flags validation error if the associated call is made outside a render pass. The apiName
2827// routine should ONLY be called inside a render pass.
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06002828static VkBool32 outsideRenderPass(const layer_data* my_data, GLOBAL_CB_NODE *pCB, const char *apiName)
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002829{
2830 VkBool32 outside = VK_FALSE;
Mark Lobodzinski74635932015-12-18 15:35:38 -07002831 if (((pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) &&
2832 (!pCB->activeRenderPass)) ||
2833 ((pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) &&
2834 (!pCB->activeRenderPass) &&
2835 !(pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT))) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002836 outside = log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002837 (uint64_t)pCB->commandBuffer, __LINE__, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002838 "%s: This call must be issued inside an active render pass.", apiName);
2839 }
2840 return outside;
2841}
2842
Courtney Goeltzenleuchter6d8e8182015-11-25 14:31:49 -07002843static void init_draw_state(layer_data *my_data, const VkAllocationCallbacks *pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002844{
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002845 uint32_t report_flags = 0;
2846 uint32_t debug_action = 0;
2847 FILE *log_output = NULL;
2848 const char *option_str;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002849 VkDebugReportCallbackEXT callback;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002850 // initialize DrawState options
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002851 report_flags = getLayerOptionFlags("DrawStateReportFlags", 0);
2852 getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &debug_action);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002853
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002854 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002855 {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002856 option_str = getLayerOption("DrawStateLogFilename");
Tobin Ehlisb1df55e2015-09-15 09:55:54 -06002857 log_output = getLayerLogOutput(option_str, "DrawState");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002858 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002859 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002860 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002861 dbgInfo.pfnCallback = log_callback;
2862 dbgInfo.pUserData = log_output;
2863 dbgInfo.flags = report_flags;
2864 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002865 my_data->logging_callback.push_back(callback);
2866 }
2867
2868 if (debug_action & VK_DBG_LAYER_ACTION_DEBUG_OUTPUT) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002869 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002870 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002871 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002872 dbgInfo.pfnCallback = win32_debug_output_msg;
2873 dbgInfo.pUserData = log_output;
2874 dbgInfo.flags = report_flags;
2875 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002876 my_data->logging_callback.push_back(callback);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002877 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002878
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002879 if (!globalLockInitialized)
2880 {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002881 loader_platform_thread_create_mutex(&globalLock);
2882 globalLockInitialized = 1;
2883 }
2884}
2885
Chia-I Wu9ab61502015-11-06 06:42:02 +08002886VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance)
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002887{
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07002888 VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002889
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07002890 assert(chain_info->u.pLayerInfo);
2891 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
2892 PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance) fpGetInstanceProcAddr(NULL, "vkCreateInstance");
2893 if (fpCreateInstance == NULL) {
2894 return VK_ERROR_INITIALIZATION_FAILED;
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002895 }
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07002896
2897 // Advance the link info for the next element on the chain
2898 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
2899
2900 VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
2901 if (result != VK_SUCCESS)
2902 return result;
2903
2904 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
2905 my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
2906 layer_init_instance_dispatch_table(*pInstance, my_data->instance_dispatch_table, fpGetInstanceProcAddr);
2907
2908 my_data->report_data = debug_report_create_instance(
2909 my_data->instance_dispatch_table,
2910 *pInstance,
2911 pCreateInfo->enabledExtensionCount,
2912 pCreateInfo->ppEnabledExtensionNames);
2913
2914 init_draw_state(my_data, pAllocator);
2915
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002916 return result;
2917}
2918
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002919/* hook DestroyInstance to remove tableInstanceMap entry */
Chia-I Wu9ab61502015-11-06 06:42:02 +08002920VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator)
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002921{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002922 // TODOSC : Shouldn't need any customization here
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002923 dispatch_key key = get_dispatch_key(instance);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002924 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
2925 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002926 pTable->DestroyInstance(instance, pAllocator);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002927
2928 // Clean up logging callback, if any
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002929 while (my_data->logging_callback.size() > 0) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002930 VkDebugReportCallbackEXT callback = my_data->logging_callback.back();
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002931 layer_destroy_msg_callback(my_data->report_data, callback, pAllocator);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002932 my_data->logging_callback.pop_back();
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002933 }
2934
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06002935 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002936 delete my_data->instance_dispatch_table;
2937 layer_data_map.erase(key);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002938 // TODO : Potential race here with separate threads creating/destroying instance
Tobin Ehlis0b632332015-10-07 09:38:40 -06002939 if (layer_data_map.empty()) {
Mike Stroyanfcb4ba62015-08-18 15:56:18 -06002940 // Release mutex when destroying last instance.
2941 loader_platform_thread_delete_mutex(&globalLock);
2942 globalLockInitialized = 0;
2943 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002944}
2945
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002946static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
2947{
Tony Barbour3b4732f2015-07-13 13:37:24 -06002948 uint32_t i;
Tobin Ehlis0b632332015-10-07 09:38:40 -06002949 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
2950 dev_data->device_extensions.debug_marker_enabled = false;
Michael Lentineabc5e922015-10-12 11:30:14 -05002951 dev_data->device_extensions.wsi_enabled = false;
2952
2953
2954 VkLayerDispatchTable *pDisp = dev_data->device_dispatch_table;
2955 PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr;
2956
Michael Lentineabc5e922015-10-12 11:30:14 -05002957 pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR) gpa(device, "vkCreateSwapchainKHR");
2958 pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR) gpa(device, "vkDestroySwapchainKHR");
2959 pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR) gpa(device, "vkGetSwapchainImagesKHR");
2960 pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR) gpa(device, "vkAcquireNextImageKHR");
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07002961 pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR) gpa(device, "vkQueuePresentKHR");
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002962
Jon Ashburnf19916e2016-01-11 13:12:43 -07002963 for (i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
Ian Elliott05846062015-11-20 14:13:17 -07002964 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) {
Michael Lentineabc5e922015-10-12 11:30:14 -05002965 dev_data->device_extensions.wsi_enabled = true;
2966 }
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002967 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
Jon Ashburneab34492015-06-01 09:37:38 -06002968 /* Found a matching extension name, mark it enabled and init dispatch table*/
Tobin Ehlis0b632332015-10-07 09:38:40 -06002969 dev_data->device_extensions.debug_marker_enabled = true;
Jon Ashburn1d4b1282015-12-10 19:12:21 -07002970 initDebugMarkerTable(device);
2971
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002972 }
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002973 }
2974}
2975
Chia-I Wu9ab61502015-11-06 06:42:02 +08002976VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDevice* pDevice)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002977{
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07002978 VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
Mark Lobodzinski941aea92016-01-13 10:23:15 -07002979
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07002980 assert(chain_info->u.pLayerInfo);
2981 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
2982 PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr;
2983 PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice) fpGetInstanceProcAddr(NULL, "vkCreateDevice");
2984 if (fpCreateDevice == NULL) {
2985 return VK_ERROR_INITIALIZATION_FAILED;
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002986 }
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07002987
2988 // Advance the link info for the next element on the chain
2989 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
2990
2991 VkResult result = fpCreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
2992 if (result != VK_SUCCESS) {
2993 return result;
2994 }
2995
2996 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
2997 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
2998
2999 // Setup device dispatch table
3000 my_device_data->device_dispatch_table = new VkLayerDispatchTable;
3001 layer_init_device_dispatch_table(*pDevice, my_device_data->device_dispatch_table, fpGetDeviceProcAddr);
3002
3003 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
3004 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
3005 // Get physical device limits for this device
3006 my_instance_data->instance_dispatch_table->GetPhysicalDeviceProperties(gpu, &(my_instance_data->physDevPropertyMap[*pDevice]));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003007 return result;
3008}
Tobin Ehlis559c6382015-11-05 09:52:49 -07003009
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06003010// prototype
3011static void deleteRenderPasses(layer_data*);
Chia-I Wu9ab61502015-11-06 06:42:02 +08003012VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003013{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003014 // TODOSC : Shouldn't need any customization here
Jeremy Hayes5d29ce32015-06-19 11:37:38 -06003015 dispatch_key key = get_dispatch_key(device);
Tobin Ehlis0b632332015-10-07 09:38:40 -06003016 layer_data* dev_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06003017 // Free all the memory
3018 loader_platform_thread_lock_mutex(&globalLock);
3019 deletePipelines(dev_data);
3020 deleteRenderPasses(dev_data);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003021 deleteCommandBuffers(dev_data);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06003022 deletePools(dev_data);
3023 deleteLayouts(dev_data);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003024 dev_data->imageViewMap.clear();
3025 dev_data->imageMap.clear();
3026 dev_data->bufferViewMap.clear();
3027 dev_data->bufferMap.clear();
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06003028 loader_platform_thread_unlock_mutex(&globalLock);
3029
Chia-I Wuf7458c52015-10-26 21:10:41 +08003030 dev_data->device_dispatch_table->DestroyDevice(device, pAllocator);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06003031 tableDebugMarkerMap.erase(key);
Tobin Ehlis0b632332015-10-07 09:38:40 -06003032 delete dev_data->device_dispatch_table;
3033 layer_data_map.erase(key);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003034}
3035
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07003036static const VkExtensionProperties instance_extensions[] = {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003037 {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003038 VK_EXT_DEBUG_REPORT_EXTENSION_NAME,
Courtney Goeltzenleuchterb69cd592016-01-19 16:08:39 -07003039 VK_EXT_DEBUG_REPORT_SPEC_VERSION
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003040 }
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06003041};
3042
Chia-I Wu9ab61502015-11-06 06:42:02 +08003043VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003044 const char *pLayerName,
3045 uint32_t *pCount,
3046 VkExtensionProperties* pProperties)
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06003047{
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07003048 return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003049}
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06003050
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07003051static const VkLayerProperties ds_global_layers[] = {
3052 {
Michael Lentine03107b42015-12-11 10:49:51 -08003053 "VK_LAYER_LUNARG_draw_state",
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07003054 VK_API_VERSION,
3055 VK_MAKE_VERSION(0, 1, 0),
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -07003056 "Validation layer: draw_state",
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07003057 }
3058};
3059
Chia-I Wu9ab61502015-11-06 06:42:02 +08003060VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003061 uint32_t *pCount,
3062 VkLayerProperties* pProperties)
3063{
3064 return util_GetLayerProperties(ARRAY_SIZE(ds_global_layers),
3065 ds_global_layers,
3066 pCount, pProperties);
3067}
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06003068
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003069static const VkExtensionProperties ds_device_extensions[] = {
3070 {
3071 DEBUG_MARKER_EXTENSION_NAME,
3072 VK_MAKE_VERSION(0, 1, 0),
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003073 }
3074};
3075
3076static const VkLayerProperties ds_device_layers[] = {
3077 {
Michael Lentine1f8d4412016-01-19 14:19:38 -06003078 "VK_LAYER_LUNARG_draw_state",
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003079 VK_API_VERSION,
3080 VK_MAKE_VERSION(0, 1, 0),
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -07003081 "Validation layer: draw_state",
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003082 }
3083};
3084
Chia-I Wu9ab61502015-11-06 06:42:02 +08003085VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003086 VkPhysicalDevice physicalDevice,
3087 const char* pLayerName,
3088 uint32_t* pCount,
3089 VkExtensionProperties* pProperties)
3090{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003091 // DrawState does not have any physical device extensions
Jon Ashburn751c4842015-11-02 17:37:20 -07003092 if (pLayerName == NULL) {
3093 dispatch_key key = get_dispatch_key(physicalDevice);
3094 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003095 return my_data->instance_dispatch_table->EnumerateDeviceExtensionProperties(
Jon Ashburn751c4842015-11-02 17:37:20 -07003096 physicalDevice,
3097 NULL,
3098 pCount,
3099 pProperties);
3100 } else {
3101 return util_GetExtensionProperties(ARRAY_SIZE(ds_device_extensions),
3102 ds_device_extensions,
3103 pCount, pProperties);
3104 }
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003105}
3106
Chia-I Wu9ab61502015-11-06 06:42:02 +08003107VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003108 VkPhysicalDevice physicalDevice,
3109 uint32_t* pCount,
3110 VkLayerProperties* pProperties)
3111{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003112 /* DrawState physical device layers are the same as global */
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003113 return util_GetLayerProperties(ARRAY_SIZE(ds_device_layers), ds_device_layers,
3114 pCount, pProperties);
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06003115}
3116
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07003117VkBool32 ValidateCmdBufImageLayouts(VkCommandBuffer cmdBuffer) {
Mark Youngb20a6a82016-01-07 15:41:43 -07003118 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05003119 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
3120 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
3121 for (auto cb_image_data : pCB->imageLayoutMap) {
3122 auto image_data = dev_data->imageLayoutMap.find(cb_image_data.first);
3123 if (image_data == dev_data->imageLayoutMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003124 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Mark Young93ecb1d2016-01-13 13:47:16 -07003125 "Cannot submit cmd buffer using deleted image %" PRIu64 ".", (uint64_t)(cb_image_data.first));
Michael Lentineabc5e922015-10-12 11:30:14 -05003126 } else {
3127 if (dev_data->imageLayoutMap[cb_image_data.first]->layout != cb_image_data.second.initialLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003128 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05003129 "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);
3130 }
3131 dev_data->imageLayoutMap[cb_image_data.first]->layout = cb_image_data.second.layout;
3132 }
3133 }
3134 return skip_call;
3135}
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07003136// Descriptor sets are unique vs. other resources in that they may be consumed at bind time:
3137// From spec section on vkCmdBindDescriptorSets - The descriptor set contents bound by a call
3138// to vkCmdBindDescriptorSets may be consumed during host execution of the command, or during
3139// shader execution of the resulting draws, or any time in between.
3140VkBool32 validateAndIncrementDescriptorSets(layer_data* my_data, GLOBAL_CB_NODE* pCB) {
3141 VkBool32 skip_call = VK_FALSE;
3142 // Verify that any active sets for this CB are valid and mark them in use
3143 for (auto set : pCB->activeSets) {
3144 auto setNode = my_data->setMap.find(set);
3145 if (setNode == my_data->setMap.end()) {
Mark Youngee3f3a22016-01-25 12:18:32 -07003146 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",
3147 "Cannot submit cmd buffer using deleted descriptor set %" PRIu64 ".", (uint64_t)(set));
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07003148 } else {
3149 setNode->second->in_use.fetch_add(1);
3150 }
3151 }
3152 return skip_call;
3153}
Michael Lentineabc5e922015-10-12 11:30:14 -05003154
Mark Young7a69c302016-01-07 09:48:47 -07003155VkBool32 validateAndIncrementResources(layer_data* my_data, GLOBAL_CB_NODE* pCB) {
Mark Youngb20a6a82016-01-07 15:41:43 -07003156 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003157 for (auto drawDataElement : pCB->drawData) {
3158 for (auto buffer : drawDataElement.buffers) {
3159 auto buffer_data = my_data->bufferMap.find(buffer);
3160 if (buffer_data == my_data->bufferMap.end()) {
Mark Young93ecb1d2016-01-13 13:47:16 -07003161 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",
3162 "Cannot submit cmd buffer using deleted buffer %" PRIu64 ".", (uint64_t)(buffer));
Michael Lentine700b0aa2015-10-30 17:57:32 -07003163 } else {
3164 buffer_data->second.in_use.fetch_add(1);
3165 }
3166 }
3167 }
Michael Lentine2e068b22015-12-29 16:05:27 -06003168 return skip_call;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003169}
3170
3171void decrementResources(layer_data* my_data, VkCommandBuffer cmdBuffer) {
3172 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cmdBuffer);
3173 for (auto drawDataElement : pCB->drawData) {
3174 for (auto buffer : drawDataElement.buffers) {
3175 auto buffer_data = my_data->bufferMap.find(buffer);
3176 if (buffer_data != my_data->bufferMap.end()) {
3177 buffer_data->second.in_use.fetch_sub(1);
3178 }
3179 }
3180 }
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07003181 for (auto set : pCB->activeSets) {
3182 auto setNode = my_data->setMap.find(set);
3183 if (setNode != my_data->setMap.end()) {
3184 setNode->second->in_use.fetch_sub(1);
3185 }
3186 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003187 for (auto queryStatePair : pCB->queryToStateMap) {
3188 my_data->queryToStateMap[queryStatePair.first] = queryStatePair.second;
3189 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003190}
3191
3192void decrementResources(layer_data* my_data, uint32_t fenceCount, const VkFence* pFences) {
3193 for (uint32_t i = 0; i < fenceCount; ++i) {
3194 auto fence_data = my_data->fenceMap.find(pFences[i]);
3195 if (fence_data == my_data->fenceMap.end() || !fence_data->second.needsSignaled) return;
3196 fence_data->second.needsSignaled = false;
3197 if (fence_data->second.priorFence != VK_NULL_HANDLE) {
3198 decrementResources(my_data, 1, &fence_data->second.priorFence);
3199 }
3200 for (auto cmdBuffer : fence_data->second.cmdBuffers) {
3201 decrementResources(my_data, cmdBuffer);
3202 }
3203 }
3204}
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07003205
Michael Lentine700b0aa2015-10-30 17:57:32 -07003206void decrementResources(layer_data* my_data, VkQueue queue) {
3207 auto queue_data = my_data->queueMap.find(queue);
3208 if (queue_data != my_data->queueMap.end()) {
3209 for (auto cmdBuffer : queue_data->second.untrackedCmdBuffers) {
3210 decrementResources(my_data, cmdBuffer);
3211 }
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07003212 queue_data->second.untrackedCmdBuffers.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07003213 decrementResources(my_data, 1, &queue_data->second.priorFence);
3214 }
3215}
3216
3217void trackCommandBuffers(layer_data* my_data, VkQueue queue, uint32_t cmdBufferCount, const VkCommandBuffer* pCmdBuffers, VkFence fence) {
3218 auto queue_data = my_data->queueMap.find(queue);
3219 if (fence != VK_NULL_HANDLE) {
3220 VkFence priorFence = VK_NULL_HANDLE;
3221 if (queue_data != my_data->queueMap.end()) {
3222 priorFence = queue_data->second.priorFence;
3223 queue_data->second.priorFence = fence;
3224 for (auto cmdBuffer : queue_data->second.untrackedCmdBuffers) {
3225 my_data->fenceMap[fence].cmdBuffers.push_back(cmdBuffer);
3226 }
3227 queue_data->second.untrackedCmdBuffers.clear();
3228 }
3229 my_data->fenceMap[fence].cmdBuffers.clear();
3230 my_data->fenceMap[fence].priorFence = priorFence;
3231 my_data->fenceMap[fence].needsSignaled = true;
3232 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003233 for (auto secondaryCmdBuffer : my_data->commandBufferMap[pCmdBuffers[i]]->secondaryCommandBuffers) {
3234 my_data->fenceMap[fence].cmdBuffers.push_back(secondaryCmdBuffer);
3235 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003236 my_data->fenceMap[fence].cmdBuffers.push_back(pCmdBuffers[i]);
3237 }
3238 } else {
3239 if (queue_data != my_data->queueMap.end()) {
3240 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003241 for (auto secondaryCmdBuffer : my_data->commandBufferMap[pCmdBuffers[i]]->secondaryCommandBuffers) {
3242 queue_data->second.untrackedCmdBuffers.push_back(secondaryCmdBuffer);
3243 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003244 queue_data->second.untrackedCmdBuffers.push_back(pCmdBuffers[i]);
3245 }
3246 }
3247 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003248 if (queue_data != my_data->queueMap.end()) {
3249 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003250 // Add cmdBuffers to both the global set and queue set
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003251 for (auto secondaryCmdBuffer : my_data->commandBufferMap[pCmdBuffers[i]]->secondaryCommandBuffers) {
3252 my_data->inFlightCmdBuffers.insert(secondaryCmdBuffer);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003253 my_data->queueMap[queue].inFlightCmdBuffers.insert(secondaryCmdBuffer);
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003254 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003255 my_data->inFlightCmdBuffers.insert(pCmdBuffers[i]);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003256 my_data->queueMap[queue].inFlightCmdBuffers.insert(pCmdBuffers[i]);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003257 }
3258 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003259}
3260
Chia-I Wu9ab61502015-11-06 06:42:02 +08003261VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence fence)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003262{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003263 VkBool32 skipCall = VK_FALSE;
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06003264 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlis0b632332015-10-07 09:38:40 -06003265 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003266 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08003267 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Michael Lentine15a47882016-01-06 10:05:48 -06003268 for (uint32_t i=0; i < submit->waitSemaphoreCount; ++i) {
3269 if (dev_data->semaphoreSignaledMap[submit->pWaitSemaphores[i]]) {
3270 dev_data->semaphoreSignaledMap[submit->pWaitSemaphores[i]] = 0;
3271 } else {
3272 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",
3273 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
Mark Youngee3f3a22016-01-25 12:18:32 -07003274 (uint64_t)(queue), (uint64_t)(submit->pWaitSemaphores[i]));
Michael Lentine15a47882016-01-06 10:05:48 -06003275 }
3276 }
3277 for (uint32_t i=0; i < submit->signalSemaphoreCount; ++i) {
3278 dev_data->semaphoreSignaledMap[submit->pSignalSemaphores[i]] = 1;
3279 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08003280 for (uint32_t i=0; i < submit->commandBufferCount; i++) {
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07003281
3282#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
3283 skipCall |= ValidateCmdBufImageLayouts(submit->pCommandBuffers[i]);
3284#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
3285
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003286 // Validate that cmd buffers have been updated
3287 pCB = getCBNode(dev_data, submit->pCommandBuffers[i]);
3288 loader_platform_thread_lock_mutex(&globalLock);
3289 pCB->submitCount++; // increment submit count
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003290 // Track in-use for resources off of primary and any secondary CBs
Michael Lentine700b0aa2015-10-30 17:57:32 -07003291 skipCall |= validateAndIncrementResources(dev_data, pCB);
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003292 if (!pCB->secondaryCommandBuffers.empty()) {
3293 for (auto secondaryCmdBuffer : pCB->secondaryCommandBuffers) {
3294 skipCall |= validateAndIncrementResources(dev_data, dev_data->commandBufferMap[secondaryCmdBuffer]);
3295 }
3296 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003297 if ((pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT) && (pCB->submitCount > 1)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003298 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_COMMAND_BUFFER_SINGLE_SUBMIT_VIOLATION, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05003299 "CB %#" PRIxLEAST64 " was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted %#" PRIxLEAST64 " times.",
Mark Youngee3f3a22016-01-25 12:18:32 -07003300 (uint64_t)(pCB->commandBuffer), pCB->submitCount);
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003301 }
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003302 if (CB_RECORDED != pCB->state) {
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003303 // Flag error for using CB w/o vkEndCommandBuffer() called
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003304 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_NO_END_COMMAND_BUFFER, "DS",
Mark Youngee3f3a22016-01-25 12:18:32 -07003305 "You must call vkEndCommandBuffer() on CB %#" PRIxLEAST64 " before this call to vkQueueSubmit()!", (uint64_t)(pCB->commandBuffer));
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003306 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003307 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003308 }
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003309 // If USAGE_SIMULTANEOUS_USE_BIT not set then CB cannot already be executing on device
3310 if (!(pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT)) {
3311 if (dev_data->inFlightCmdBuffers.find(pCB->commandBuffer) != dev_data->inFlightCmdBuffers.end()) {
Mark Youngee3f3a22016-01-25 12:18:32 -07003312 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",
3313 "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 -07003314 }
3315 }
Tobin Ehlisc4bdde12015-05-27 14:30:06 -06003316 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06003317 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003318 trackCommandBuffers(dev_data, queue, submit->commandBufferCount, submit->pCommandBuffers, fence);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003319 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003320 if (VK_FALSE == skipCall)
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08003321 return dev_data->device_dispatch_table->QueueSubmit(queue, submitCount, pSubmits, fence);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003322 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003323}
3324
Mark Youngb20a6a82016-01-07 15:41:43 -07003325VkBool32 cleanInFlightCmdBuffer(layer_data* my_data, VkCommandBuffer cmdBuffer) {
3326 VkBool32 skip_call = VK_FALSE;
Michael Lentineb887b0a2015-12-29 14:12:11 -06003327 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cmdBuffer);
Mark Lobodzinskia9e7c042016-01-25 14:27:49 -07003328 if (pCB) {
3329 for (auto queryEventsPair : pCB->waitedEventsBeforeQueryReset) {
3330 for (auto event : queryEventsPair.second) {
3331 if (my_data->eventMap[event].needsSignaled) {
3332 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",
3333 "Cannot get query results on queryPool %" PRIu64 " with index %d which was guarded by unsignaled event %" PRIu64 ".",
3334 (uint64_t)(queryEventsPair.first.pool), queryEventsPair.first.index, (uint64_t)(event));
3335 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003336 }
3337 }
3338 }
3339 return skip_call;
3340}
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003341// Remove given cmd_buffer from inFlight set for given queue
3342// If cmd_buffer is not inFlight on any other queues, also remove it from global inFlight set
3343static inline void removeInFlightCmdBuffer(layer_data* dev_data, VkQueue queue, VkCommandBuffer cmd_buffer)
3344{
3345 dev_data->queueMap[queue].inFlightCmdBuffers.erase(cmd_buffer);
3346 // Pull it off of global list initially, but if we find it in any other queue list, add it back in
3347 dev_data->inFlightCmdBuffers.erase(cmd_buffer);
3348 for (auto q : dev_data->queues) {
3349 if ((q != queue) && (dev_data->queueMap[q].inFlightCmdBuffers.find(cmd_buffer) != dev_data->queueMap[q].inFlightCmdBuffers.end())) {
3350 dev_data->inFlightCmdBuffers.insert(cmd_buffer);
3351 break;
3352 }
3353 }
3354}
Michael Lentineb887b0a2015-12-29 14:12:11 -06003355
Michael Lentine700b0aa2015-10-30 17:57:32 -07003356VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence* pFences, VkBool32 waitAll, uint64_t timeout)
3357{
3358 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3359 VkResult result = dev_data->device_dispatch_table->WaitForFences(device, fenceCount, pFences, waitAll, timeout);
Mark Youngb20a6a82016-01-07 15:41:43 -07003360 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003361 if ((waitAll || fenceCount == 1) && result == VK_SUCCESS) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06003362 for (uint32_t i = 0; i < fenceCount; ++i) {
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003363 VkQueue fence_queue = dev_data->fenceMap[pFences[i]].queue;
Michael Lentineb887b0a2015-12-29 14:12:11 -06003364 for (auto cmdBuffer : dev_data->fenceMap[pFences[i]].cmdBuffers) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06003365 skip_call |= cleanInFlightCmdBuffer(dev_data, cmdBuffer);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003366 removeInFlightCmdBuffer(dev_data, fence_queue, cmdBuffer);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003367 }
3368 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003369 decrementResources(dev_data, fenceCount, pFences);
3370 }
Mark Youngb20a6a82016-01-07 15:41:43 -07003371 if (VK_FALSE != skip_call)
Mark Lobodzinskice738852016-01-07 10:04:02 -07003372 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003373 return result;
3374}
3375
3376
3377VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetFenceStatus(VkDevice device, VkFence fence)
3378{
3379 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3380 VkResult result = dev_data->device_dispatch_table->GetFenceStatus(device, fence);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003381 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003382 if (result == VK_SUCCESS) {
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003383 auto fence_queue = dev_data->fenceMap[fence].queue;
Michael Lentineb887b0a2015-12-29 14:12:11 -06003384 for (auto cmdBuffer : dev_data->fenceMap[fence].cmdBuffers) {
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003385 skip_call |= cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3386 removeInFlightCmdBuffer(dev_data, fence_queue, cmdBuffer);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003387 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003388 decrementResources(dev_data, 1, &fence);
3389 }
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003390 if (VK_FALSE != skip_call)
3391 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003392 return result;
3393}
3394
3395VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue* pQueue)
3396{
3397 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3398 dev_data->device_dispatch_table->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003399 dev_data->queues.push_back(*pQueue);
Michael Lentine700b0aa2015-10-30 17:57:32 -07003400 dev_data->queueMap[*pQueue].device = device;
3401}
3402
3403VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueueWaitIdle(VkQueue queue)
3404{
3405 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
3406 decrementResources(dev_data, queue);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003407 VkBool32 skip_call = VK_FALSE;
3408 // Iterate over local set since we erase set members as we go in for loop
3409 auto local_cb_set = dev_data->queueMap[queue].inFlightCmdBuffers;
3410 for (auto cmdBuffer : local_cb_set) {
3411 skip_call |= cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3412 removeInFlightCmdBuffer(dev_data, queue, cmdBuffer);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003413 }
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003414 dev_data->queueMap[queue].inFlightCmdBuffers.clear();
3415 if (VK_FALSE != skip_call)
3416 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003417 return dev_data->device_dispatch_table->QueueWaitIdle(queue);
3418}
3419
3420VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkDeviceWaitIdle(VkDevice device)
3421{
3422 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003423 for (auto queue : dev_data->queues) {
3424 decrementResources(dev_data, queue);
3425 // Clear all of the queue inFlightCmdBuffers (global set cleared below)
3426 dev_data->queueMap[queue].inFlightCmdBuffers.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07003427 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003428 for (auto cmdBuffer : dev_data->inFlightCmdBuffers) {
3429 cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3430 }
3431 dev_data->inFlightCmdBuffers.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07003432 return dev_data->device_dispatch_table->DeviceWaitIdle(device);
3433}
3434
Chia-I Wu9ab61502015-11-06 06:42:02 +08003435VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003436{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003437 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 -06003438 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003439}
3440
Chia-I Wu9ab61502015-11-06 06:42:02 +08003441VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySemaphore(VkDevice device, VkSemaphore semaphore, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003442{
Michael Lentine15a47882016-01-06 10:05:48 -06003443 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3444 dev_data->device_dispatch_table->DestroySemaphore(device, semaphore, pAllocator);
3445 dev_data->semaphoreSignaledMap.erase(semaphore);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003446 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003447}
3448
Chia-I Wu9ab61502015-11-06 06:42:02 +08003449VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003450{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003451 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 -06003452 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003453}
3454
Chia-I Wu9ab61502015-11-06 06:42:02 +08003455VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003456{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003457 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 -06003458 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003459}
3460
Mark Lobodzinskice738852016-01-07 10:04:02 -07003461VKAPI_ATTR VkResult VKAPI_CALL vkGetQueryPoolResults(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount,
Michael Lentineb887b0a2015-12-29 14:12:11 -06003462 size_t dataSize, void* pData, VkDeviceSize stride, VkQueryResultFlags flags) {
3463 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3464 unordered_map<QueryObject, vector<VkCommandBuffer>> queriesInFlight;
3465 GLOBAL_CB_NODE* pCB = nullptr;
3466 for (auto cmdBuffer : dev_data->inFlightCmdBuffers) {
3467 pCB = getCBNode(dev_data, cmdBuffer);
3468 for (auto queryStatePair : pCB->queryToStateMap) {
3469 queriesInFlight[queryStatePair.first].push_back(cmdBuffer);
3470 }
3471 }
Mark Youngb20a6a82016-01-07 15:41:43 -07003472 VkBool32 skip_call = VK_FALSE;
Michael Lentineb887b0a2015-12-29 14:12:11 -06003473 for (uint32_t i = 0; i < queryCount; ++i) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003474 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06003475 auto queryElement = queriesInFlight.find(query);
3476 auto queryToStateElement = dev_data->queryToStateMap.find(query);
3477 if (queryToStateElement != dev_data->queryToStateMap.end()) {
3478 }
3479 // Available and in flight
3480 if(queryElement != queriesInFlight.end() && queryToStateElement != dev_data->queryToStateMap.end() && queryToStateElement->second) {
3481 for (auto cmdBuffer : queryElement->second) {
3482 pCB = getCBNode(dev_data, cmdBuffer);
3483 auto queryEventElement = pCB->waitedEventsBeforeQueryReset.find(query);
3484 if (queryEventElement == pCB->waitedEventsBeforeQueryReset.end()) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003485 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT, 0, __LINE__,
3486 DRAWSTATE_INVALID_QUERY, "DS", "Cannot get query results on queryPool %" PRIu64 " with index %d which is in flight.",
Mark Young93ecb1d2016-01-13 13:47:16 -07003487 (uint64_t)(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003488 } else {
3489 for (auto event : queryEventElement->second) {
3490 dev_data->eventMap[event].needsSignaled = true;
3491 }
3492 }
3493 }
3494 // Unavailable and in flight
3495 } else if (queryElement != queriesInFlight.end() && queryToStateElement != dev_data->queryToStateMap.end() && !queryToStateElement->second) {
3496 // TODO : Can there be the same query in use by multiple command buffers in flight?
3497 bool make_available = false;
3498 for (auto cmdBuffer : queryElement->second) {
3499 pCB = getCBNode(dev_data, cmdBuffer);
3500 make_available |= pCB->queryToStateMap[query];
3501 }
3502 if (!(((flags & VK_QUERY_RESULT_PARTIAL_BIT) || (flags & VK_QUERY_RESULT_WAIT_BIT)) && make_available)) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003503 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT, 0, __LINE__, DRAWSTATE_INVALID_QUERY, "DS",
Michael Lentineb887b0a2015-12-29 14:12:11 -06003504 "Cannot get query results on queryPool %" PRIu64 " with index %d which is unavailable.",
Mark Young93ecb1d2016-01-13 13:47:16 -07003505 (uint64_t)(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003506 }
3507 // Unavailable
3508 } else if (queryToStateElement != dev_data->queryToStateMap.end() && !queryToStateElement->second) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003509 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT, 0, __LINE__, DRAWSTATE_INVALID_QUERY, "DS",
Michael Lentineb887b0a2015-12-29 14:12:11 -06003510 "Cannot get query results on queryPool %" PRIu64 " with index %d which is unavailable.",
Mark Young93ecb1d2016-01-13 13:47:16 -07003511 (uint64_t)(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003512 // Unitialized
3513 } else if (queryToStateElement == dev_data->queryToStateMap.end()) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003514 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT, 0, __LINE__, DRAWSTATE_INVALID_QUERY, "DS",
Michael Lentineb887b0a2015-12-29 14:12:11 -06003515 "Cannot get query results on queryPool %" PRIu64 " with index %d which is uninitialized.",
Mark Young93ecb1d2016-01-13 13:47:16 -07003516 (uint64_t)(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003517 }
3518 }
3519 if (skip_call)
Mark Lobodzinskice738852016-01-07 10:04:02 -07003520 return VK_ERROR_VALIDATION_FAILED_EXT;
3521 return dev_data->device_dispatch_table->GetQueryPoolResults(device, queryPool, firstQuery, queryCount, dataSize, pData, stride, flags);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003522}
3523
Mark Young7a69c302016-01-07 09:48:47 -07003524VkBool32 validateIdleBuffer(const layer_data* my_data, VkBuffer buffer) {
Mark Youngb20a6a82016-01-07 15:41:43 -07003525 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003526 auto buffer_data = my_data->bufferMap.find(buffer);
3527 if (buffer_data == my_data->bufferMap.end()) {
Mark Young93ecb1d2016-01-13 13:47:16 -07003528 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",
3529 "Cannot free buffer %" PRIxLEAST64 " that has not been allocated.", (uint64_t)(buffer));
Michael Lentine700b0aa2015-10-30 17:57:32 -07003530 } else {
3531 if (buffer_data->second.in_use.load()) {
Mark Young93ecb1d2016-01-13 13:47:16 -07003532 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",
3533 "Cannot free buffer %" PRIxLEAST64 " that is in use by a command buffer.", (uint64_t)(buffer));
Michael Lentine700b0aa2015-10-30 17:57:32 -07003534 }
3535 }
3536 return skip_call;
3537}
3538
Chia-I Wu9ab61502015-11-06 06:42:02 +08003539VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003540{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003541 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07003542 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003543 if (!validateIdleBuffer(dev_data, buffer)) {
3544 dev_data->device_dispatch_table->DestroyBuffer(device, buffer, pAllocator);
3545 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08003546 dev_data->bufferMap.erase(buffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003547}
3548
Chia-I Wu9ab61502015-11-06 06:42:02 +08003549VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBufferView(VkDevice device, VkBufferView bufferView, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003550{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003551 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003552 dev_data->device_dispatch_table->DestroyBufferView(device, bufferView, pAllocator);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003553 dev_data->bufferViewMap.erase(bufferView);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003554}
3555
Chia-I Wu9ab61502015-11-06 06:42:02 +08003556VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003557{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003558 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003559 dev_data->device_dispatch_table->DestroyImage(device, image, pAllocator);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003560 dev_data->imageMap.erase(image);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003561}
3562
Chia-I Wu9ab61502015-11-06 06:42:02 +08003563VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyImageView(VkDevice device, VkImageView imageView, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003564{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003565 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 -06003566 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003567}
3568
Chia-I Wu9ab61502015-11-06 06:42:02 +08003569VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003570{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003571 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 -06003572 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003573}
3574
Chia-I Wu9ab61502015-11-06 06:42:02 +08003575VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyPipeline(VkDevice device, VkPipeline pipeline, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003576{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003577 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 -06003578 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003579}
3580
Chia-I Wu9ab61502015-11-06 06:42:02 +08003581VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003582{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003583 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 -06003584 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003585}
3586
Chia-I Wu9ab61502015-11-06 06:42:02 +08003587VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySampler(VkDevice device, VkSampler sampler, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003588{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003589 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 -06003590 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003591}
3592
Chia-I Wu9ab61502015-11-06 06:42:02 +08003593VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003594{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003595 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 -06003596 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003597}
3598
Chia-I Wu9ab61502015-11-06 06:42:02 +08003599VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003600{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003601 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 -06003602 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003603}
3604
Chia-I Wu9ab61502015-11-06 06:42:02 +08003605VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t count, const VkCommandBuffer *pCommandBuffers)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003606{
Mark Lobodzinski39298632015-11-18 08:38:27 -07003607 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3608
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07003609 for (uint32_t i = 0; i < count; i++) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003610 // Delete CB information structure, and remove from commandBufferMap
3611 auto cb = dev_data->commandBufferMap.find(pCommandBuffers[i]);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003612 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003613 if (cb != dev_data->commandBufferMap.end()) {
3614 delete (*cb).second;
3615 dev_data->commandBufferMap.erase(cb);
3616 }
3617
3618 // Remove commandBuffer reference from commandPoolMap
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003619 dev_data->commandPoolMap[commandPool].commandBuffers.remove(pCommandBuffers[i]);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003620 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003621 }
3622
3623 dev_data->device_dispatch_table->FreeCommandBuffers(device, commandPool, count, pCommandBuffers);
3624}
3625
3626VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkCommandPool* pCommandPool)
3627{
3628 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3629
3630 VkResult result = dev_data->device_dispatch_table->CreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
3631
3632 if (VK_SUCCESS == result) {
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003633 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003634 dev_data->commandPoolMap[*pCommandPool].createFlags = pCreateInfo->flags;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003635 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003636 }
3637 return result;
3638}
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07003639// Destroy commandPool along with all of the commandBuffers allocated from that pool
Mark Lobodzinski39298632015-11-18 08:38:27 -07003640VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks* pAllocator)
3641{
3642 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003643 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003644
3645 // Must remove cmdpool from cmdpoolmap, after removing all cmdbuffers in its list from the commandPoolMap
3646 if (dev_data->commandPoolMap.find(commandPool) != dev_data->commandPoolMap.end()) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003647 for (auto poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.begin(); poolCb != dev_data->commandPoolMap[commandPool].commandBuffers.end();) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003648 auto del_cb = dev_data->commandBufferMap.find(*poolCb);
3649 delete (*del_cb).second; // delete CB info structure
3650 dev_data->commandBufferMap.erase(del_cb); // Remove this command buffer from cbMap
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003651 poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.erase(poolCb); // Remove CB reference from commandPoolMap's list
Mark Lobodzinski39298632015-11-18 08:38:27 -07003652 }
3653 }
3654 dev_data->commandPoolMap.erase(commandPool);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003655
3656 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003657 dev_data->device_dispatch_table->DestroyCommandPool(device, commandPool, pAllocator);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003658}
3659
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003660VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandPool(
3661 VkDevice device,
3662 VkCommandPool commandPool,
3663 VkCommandPoolResetFlags flags)
3664{
3665 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003666 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003667
3668 result = dev_data->device_dispatch_table->ResetCommandPool(device, commandPool, flags);
3669 // Reset all of the CBs allocated from this pool
3670 if (VK_SUCCESS == result) {
3671 auto it = dev_data->commandPoolMap[commandPool].commandBuffers.begin();
3672 while (it != dev_data->commandPoolMap[commandPool].commandBuffers.end()) {
3673 resetCB(dev_data, (*it));
3674 ++it;
3675 }
3676 }
3677 return result;
3678}
3679
Chia-I Wu9ab61502015-11-06 06:42:02 +08003680VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003681{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003682 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 -06003683 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003684}
3685
Chia-I Wu9ab61502015-11-06 06:42:02 +08003686VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003687{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003688 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 -06003689 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003690}
3691
Chia-I Wu9ab61502015-11-06 06:42:02 +08003692VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateBuffer(VkDevice device, const VkBufferCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkBuffer* pBuffer)
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003693{
3694 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003695 VkResult result = dev_data->device_dispatch_table->CreateBuffer(device, pCreateInfo, pAllocator, pBuffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003696 if (VK_SUCCESS == result) {
3697 loader_platform_thread_lock_mutex(&globalLock);
3698 // TODO : This doesn't create deep copy of pQueueFamilyIndices so need to fix that if/when we want that data to be valid
Michael Lentine700b0aa2015-10-30 17:57:32 -07003699 dev_data->bufferMap[*pBuffer].create_info = unique_ptr<VkBufferCreateInfo>(new VkBufferCreateInfo(*pCreateInfo));
3700 dev_data->bufferMap[*pBuffer].in_use.store(0);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003701 loader_platform_thread_unlock_mutex(&globalLock);
3702 }
3703 return result;
3704}
3705
Chia-I Wu9ab61502015-11-06 06:42:02 +08003706VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkBufferView* pView)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003707{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003708 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003709 VkResult result = dev_data->device_dispatch_table->CreateBufferView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003710 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003711 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003712 dev_data->bufferViewMap[*pView] = unique_ptr<VkBufferViewCreateInfo>(new VkBufferViewCreateInfo(*pCreateInfo));
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003713 loader_platform_thread_unlock_mutex(&globalLock);
3714 }
3715 return result;
3716}
3717
Chia-I Wu9ab61502015-11-06 06:42:02 +08003718VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateImage(VkDevice device, const VkImageCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkImage* pImage)
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003719{
3720 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003721 VkResult result = dev_data->device_dispatch_table->CreateImage(device, pCreateInfo, pAllocator, pImage);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003722 if (VK_SUCCESS == result) {
Michael Lentineabc5e922015-10-12 11:30:14 -05003723 IMAGE_NODE* image_node = new IMAGE_NODE;
3724 image_node->layout = pCreateInfo->initialLayout;
Tobin Ehlis75cd1c52016-01-21 10:21:04 -07003725 image_node->format = pCreateInfo->format;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003726 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003727 dev_data->imageMap[*pImage] = unique_ptr<VkImageCreateInfo>(new VkImageCreateInfo(*pCreateInfo));
Michael Lentineabc5e922015-10-12 11:30:14 -05003728 dev_data->imageLayoutMap[*pImage] = image_node;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003729 loader_platform_thread_unlock_mutex(&globalLock);
3730 }
3731 return result;
3732}
3733
Chia-I Wu9ab61502015-11-06 06:42:02 +08003734VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkImageView* pView)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003735{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003736 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003737 VkResult result = dev_data->device_dispatch_table->CreateImageView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003738 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003739 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003740 dev_data->imageViewMap[*pView] = unique_ptr<VkImageViewCreateInfo>(new VkImageViewCreateInfo(*pCreateInfo));
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003741 loader_platform_thread_unlock_mutex(&globalLock);
3742 }
3743 return result;
3744}
3745
Jon Ashburnc669cc62015-07-09 15:02:25 -06003746//TODO handle pipeline caches
Chia-I Wu9ab61502015-11-06 06:42:02 +08003747VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineCache(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003748 VkDevice device,
3749 const VkPipelineCacheCreateInfo* pCreateInfo,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003750 const VkAllocationCallbacks* pAllocator,
Jon Ashburnc669cc62015-07-09 15:02:25 -06003751 VkPipelineCache* pPipelineCache)
3752{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003753 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003754 VkResult result = dev_data->device_dispatch_table->CreatePipelineCache(device, pCreateInfo, pAllocator, pPipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003755 return result;
3756}
3757
Chia-I Wu9ab61502015-11-06 06:42:02 +08003758VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineCache(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003759 VkDevice device,
Chia-I Wuf7458c52015-10-26 21:10:41 +08003760 VkPipelineCache pipelineCache,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003761 const VkAllocationCallbacks* pAllocator)
Jon Ashburnc669cc62015-07-09 15:02:25 -06003762{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003763 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003764 dev_data->device_dispatch_table->DestroyPipelineCache(device, pipelineCache, pAllocator);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003765}
3766
Chia-I Wu9ab61502015-11-06 06:42:02 +08003767VKAPI_ATTR VkResult VKAPI_CALL vkGetPipelineCacheData(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003768 VkDevice device,
3769 VkPipelineCache pipelineCache,
Chia-I Wub16facd2015-10-26 19:17:06 +08003770 size_t* pDataSize,
Jon Ashburnc669cc62015-07-09 15:02:25 -06003771 void* pData)
3772{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003773 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wub16facd2015-10-26 19:17:06 +08003774 VkResult result = dev_data->device_dispatch_table->GetPipelineCacheData(device, pipelineCache, pDataSize, pData);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003775 return result;
3776}
3777
Chia-I Wu9ab61502015-11-06 06:42:02 +08003778VKAPI_ATTR VkResult VKAPI_CALL vkMergePipelineCaches(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003779 VkDevice device,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003780 VkPipelineCache dstCache,
Jon Ashburnc669cc62015-07-09 15:02:25 -06003781 uint32_t srcCacheCount,
3782 const VkPipelineCache* pSrcCaches)
3783{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003784 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003785 VkResult result = dev_data->device_dispatch_table->MergePipelineCaches(device, dstCache, srcCacheCount, pSrcCaches);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003786 return result;
3787}
3788
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003789VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateGraphicsPipelines(
3790 VkDevice device,
3791 VkPipelineCache pipelineCache,
3792 uint32_t count,
3793 const VkGraphicsPipelineCreateInfo *pCreateInfos,
3794 const VkAllocationCallbacks *pAllocator,
3795 VkPipeline *pPipelines)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003796{
Courtney Goeltzenleuchtered894072015-09-04 13:39:59 -06003797 VkResult result = VK_SUCCESS;
Tobin Ehlis11efc302015-09-16 10:33:53 -06003798 //TODO What to do with pipelineCache?
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003799 // The order of operations here is a little convoluted but gets the job done
3800 // 1. Pipeline create state is first shadowed into PIPELINE_NODE struct
3801 // 2. Create state is then validated (which uses flags setup during shadowing)
3802 // 3. If everything looks good, we'll then create the pipeline and add NODE to pipelineMap
Tobin Ehlis11efc302015-09-16 10:33:53 -06003803 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis65399772015-09-17 16:33:58 -06003804 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
3805 vector<PIPELINE_NODE*> pPipeNode(count);
Tobin Ehlis0b632332015-10-07 09:38:40 -06003806 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003807
Tobin Ehlis11efc302015-09-16 10:33:53 -06003808 uint32_t i=0;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003809 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003810
Tobin Ehlis11efc302015-09-16 10:33:53 -06003811 for (i=0; i<count; i++) {
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003812 pPipeNode[i] = initGraphicsPipeline(dev_data, &pCreateInfos[i], NULL);
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06003813 skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
Tobin Ehlis11efc302015-09-16 10:33:53 -06003814 }
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003815
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003816 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003817
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07003818 if (VK_FALSE == skipCall) {
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003819 result = dev_data->device_dispatch_table->CreateGraphicsPipelines(device,
3820 pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003821 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis11efc302015-09-16 10:33:53 -06003822 for (i=0; i<count; i++) {
3823 pPipeNode[i]->pipeline = pPipelines[i];
Chia-I Wue2fc5522015-10-26 20:04:44 +08003824 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
Tobin Ehlis11efc302015-09-16 10:33:53 -06003825 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003826 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisce132d82015-06-19 15:07:05 -06003827 } else {
Tobin Ehlis11efc302015-09-16 10:33:53 -06003828 for (i=0; i<count; i++) {
3829 if (pPipeNode[i]) {
3830 // If we allocated a pipeNode, need to clean it up here
3831 delete[] pPipeNode[i]->pVertexBindingDescriptions;
3832 delete[] pPipeNode[i]->pVertexAttributeDescriptions;
3833 delete[] pPipeNode[i]->pAttachments;
3834 delete pPipeNode[i];
3835 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003836 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003837 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003838 }
Courtney Goeltzenleuchtere2aaad02015-04-13 16:16:04 -06003839 return result;
3840}
3841
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003842VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateComputePipelines(
3843 VkDevice device,
3844 VkPipelineCache pipelineCache,
3845 uint32_t count,
3846 const VkComputePipelineCreateInfo *pCreateInfos,
3847 const VkAllocationCallbacks *pAllocator,
3848 VkPipeline *pPipelines)
3849{
3850 VkResult result = VK_SUCCESS;
3851 VkBool32 skipCall = VK_FALSE;
3852
3853 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
3854 vector<PIPELINE_NODE*> pPipeNode(count);
3855 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3856
3857 uint32_t i=0;
3858 loader_platform_thread_lock_mutex(&globalLock);
3859 for (i=0; i<count; i++) {
3860 // TODO: Verify compute stage bits
3861
3862 // Create and initialize internal tracking data structure
3863 pPipeNode[i] = new PIPELINE_NODE;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003864 memcpy(&pPipeNode[i]->computePipelineCI, (const void*)&pCreateInfos[i], sizeof(VkComputePipelineCreateInfo));
3865
3866 // TODO: Add Compute Pipeline Verification
3867 // skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
3868 }
3869 loader_platform_thread_unlock_mutex(&globalLock);
3870
3871 if (VK_FALSE == skipCall) {
3872 result = dev_data->device_dispatch_table->CreateComputePipelines(device, pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
3873 loader_platform_thread_lock_mutex(&globalLock);
3874 for (i=0; i<count; i++) {
3875 pPipeNode[i]->pipeline = pPipelines[i];
3876 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
3877 }
3878 loader_platform_thread_unlock_mutex(&globalLock);
3879 } else {
3880 for (i=0; i<count; i++) {
3881 if (pPipeNode[i]) {
3882 // Clean up any locally allocated data structures
3883 delete pPipeNode[i];
3884 }
3885 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003886 return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003887 }
3888 return result;
3889}
3890
Chia-I Wu9ab61502015-11-06 06:42:02 +08003891VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSampler* pSampler)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003892{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003893 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003894 VkResult result = dev_data->device_dispatch_table->CreateSampler(device, pCreateInfo, pAllocator, pSampler);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003895 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003896 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003897 dev_data->sampleMap[*pSampler] = unique_ptr<SAMPLER_NODE>(new SAMPLER_NODE(pSampler, pCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003898 loader_platform_thread_unlock_mutex(&globalLock);
3899 }
3900 return result;
3901}
3902
Chia-I Wu9ab61502015-11-06 06:42:02 +08003903VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDescriptorSetLayout* pSetLayout)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003904{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003905 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003906 VkResult result = dev_data->device_dispatch_table->CreateDescriptorSetLayout(device, pCreateInfo, pAllocator, pSetLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003907 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003908 // TODOSC : Capture layout bindings set
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003909 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
3910 if (NULL == pNewNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003911 if (log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, (uint64_t) *pSetLayout, __LINE__, DRAWSTATE_OUT_OF_MEMORY, "DS",
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003912 "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003913 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003914 }
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06003915 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003916 pNewNode->createInfo.pBindings = new VkDescriptorSetLayoutBinding[pCreateInfo->bindingCount];
3917 memcpy((void*)pNewNode->createInfo.pBindings, pCreateInfo->pBindings, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->bindingCount);
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003918 // g++ does not like reserve with size 0
3919 if (pCreateInfo->bindingCount)
3920 pNewNode->bindings.reserve(pCreateInfo->bindingCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003921 uint32_t totalCount = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003922 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003923 if (!pNewNode->bindings.insert(pCreateInfo->pBindings[i].binding).second) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003924 if (log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, (uint64_t) *pSetLayout, __LINE__, DRAWSTATE_INVALID_LAYOUT, "DS",
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003925 "duplicated binding number in VkDescriptorSetLayoutBinding"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003926 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003927 }
3928
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003929 totalCount += pCreateInfo->pBindings[i].descriptorCount;
3930 if (pCreateInfo->pBindings[i].pImmutableSamplers) {
3931 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBindings[i].pImmutableSamplers;
3932 *ppIS = new VkSampler[pCreateInfo->pBindings[i].descriptorCount];
3933 memcpy(*ppIS, pCreateInfo->pBindings[i].pImmutableSamplers, pCreateInfo->pBindings[i].descriptorCount*sizeof(VkSampler));
Tobin Ehlis793ad302015-04-03 12:01:11 -06003934 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003935 }
Tobin Ehlis43c39c02016-01-11 13:18:40 -07003936 pNewNode->layout = *pSetLayout;
3937 pNewNode->startIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003938 if (totalCount > 0) {
Cody Northrop43751cc2015-10-26 14:07:35 -06003939 pNewNode->descriptorTypes.resize(totalCount);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06003940 pNewNode->stageFlags.resize(totalCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003941 uint32_t offset = 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06003942 uint32_t j = 0;
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07003943 VkDescriptorType dType;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003944 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003945 dType = pCreateInfo->pBindings[i].descriptorType;
3946 for (j = 0; j < pCreateInfo->pBindings[i].descriptorCount; j++) {
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07003947 pNewNode->descriptorTypes[offset + j] = dType;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003948 pNewNode->stageFlags[offset + j] = pCreateInfo->pBindings[i].stageFlags;
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07003949 if ((dType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
3950 (dType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
3951 pNewNode->dynamicDescriptorCount++;
3952 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003953 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06003954 offset += j;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003955 }
Tobin Ehlis43c39c02016-01-11 13:18:40 -07003956 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
3957 } else { // no descriptors
3958 pNewNode->endIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003959 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003960 // Put new node at Head of global Layer list
3961 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07003962 dev_data->descriptorSetLayoutMap[*pSetLayout] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003963 loader_platform_thread_unlock_mutex(&globalLock);
3964 }
3965 return result;
3966}
3967
Chia-I Wu9ab61502015-11-06 06:42:02 +08003968VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003969{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003970 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003971 VkResult result = dev_data->device_dispatch_table->CreatePipelineLayout(device, pCreateInfo, pAllocator, pPipelineLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003972 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003973 // TODOSC : Merge capture of the setLayouts per pipeline
Tobin Ehlis559c6382015-11-05 09:52:49 -07003974 PIPELINE_LAYOUT_NODE& plNode = dev_data->pipelineLayoutMap[*pPipelineLayout];
Chia-I Wud50a7d72015-10-26 20:48:51 +08003975 plNode.descriptorSetLayouts.resize(pCreateInfo->setLayoutCount);
Tobin Ehlis644ff042015-10-20 10:11:55 -06003976 uint32_t i = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003977 for (i=0; i<pCreateInfo->setLayoutCount; ++i) {
Tobin Ehlis644ff042015-10-20 10:11:55 -06003978 plNode.descriptorSetLayouts[i] = pCreateInfo->pSetLayouts[i];
3979 }
Cody Northrop43751cc2015-10-26 14:07:35 -06003980 plNode.pushConstantRanges.resize(pCreateInfo->pushConstantRangeCount);
Tobin Ehlis644ff042015-10-20 10:11:55 -06003981 for (i=0; i<pCreateInfo->pushConstantRangeCount; ++i) {
3982 plNode.pushConstantRanges[i] = pCreateInfo->pPushConstantRanges[i];
3983 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06003984 }
3985 return result;
3986}
3987
Chia-I Wu9ab61502015-11-06 06:42:02 +08003988VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDescriptorPool* pDescriptorPool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003989{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003990 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003991 VkResult result = dev_data->device_dispatch_table->CreateDescriptorPool(device, pCreateInfo, pAllocator, pDescriptorPool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003992 if (VK_SUCCESS == result) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06003993 // Insert this pool into Global Pool LL at head
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003994 if (log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, (uint64_t) *pDescriptorPool, __LINE__, DRAWSTATE_OUT_OF_MEMORY, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08003995 "Created Descriptor Pool %#" PRIxLEAST64, (uint64_t) *pDescriptorPool))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003996 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003997 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003998 DESCRIPTOR_POOL_NODE* pNewNode = new DESCRIPTOR_POOL_NODE(*pDescriptorPool, pCreateInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003999 if (NULL == pNewNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004000 if (log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, (uint64_t) *pDescriptorPool, __LINE__, DRAWSTATE_OUT_OF_MEMORY, "DS",
Mark Lobodzinski39298632015-11-18 08:38:27 -07004001 "Out of memory while attempting to allocate DESCRIPTOR_POOL_NODE in vkCreateDescriptorPool()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004002 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisce132d82015-06-19 15:07:05 -06004003 } else {
Mark Lobodzinski39298632015-11-18 08:38:27 -07004004 dev_data->descriptorPoolMap[*pDescriptorPool] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004005 }
4006 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisce132d82015-06-19 15:07:05 -06004007 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06004008 // Need to do anything if pool create fails?
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004009 }
4010 return result;
4011}
4012
Chia-I Wu9ab61502015-11-06 06:42:02 +08004013VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorPoolResetFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004014{
Tobin Ehlis0b632332015-10-07 09:38:40 -06004015 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004016 VkResult result = dev_data->device_dispatch_table->ResetDescriptorPool(device, descriptorPool, flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004017 if (VK_SUCCESS == result) {
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004018 clearDescriptorPool(dev_data, device, descriptorPool, flags);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004019 }
4020 return result;
4021}
4022
Chia-I Wu9ab61502015-11-06 06:42:02 +08004023VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo* pAllocateInfo, VkDescriptorSet* pDescriptorSets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004024{
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004025 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis0b632332015-10-07 09:38:40 -06004026 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004027 // Verify that requested descriptorSets are available in pool
Mark Lobodzinski39298632015-11-18 08:38:27 -07004028 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004029 if (!pPoolNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004030 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, (uint64_t) pAllocateInfo->descriptorPool, __LINE__, DRAWSTATE_INVALID_POOL, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004031 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004032 } else { // Make sure pool has all the available descriptors before calling down chain
Jon Ashburnf19916e2016-01-11 13:12:43 -07004033 skipCall |= validate_descriptor_availability_in_pool(dev_data, pPoolNode, pAllocateInfo->descriptorSetCount, pAllocateInfo->pSetLayouts);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004034 }
4035 if (skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004036 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004037 VkResult result = dev_data->device_dispatch_table->AllocateDescriptorSets(device, pAllocateInfo, pDescriptorSets);
Cody Northrop1e4f8022015-08-03 12:47:29 -06004038 if (VK_SUCCESS == result) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07004039 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004040 if (pPoolNode) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004041 if (pAllocateInfo->descriptorSetCount == 0) {
4042 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 +08004043 "AllocateDescriptorSets called with 0 count");
Cody Northrop1e4f8022015-08-03 12:47:29 -06004044 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07004045 for (uint32_t i = 0; i < pAllocateInfo->descriptorSetCount; i++) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004046 log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pDescriptorSets[i], __LINE__, DRAWSTATE_NONE, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08004047 "Created Descriptor Set %#" PRIxLEAST64, (uint64_t) pDescriptorSets[i]);
Tobin Ehlis793ad302015-04-03 12:01:11 -06004048 // Create new set node and add to head of pool nodes
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004049 SET_NODE* pNewNode = new SET_NODE;
4050 if (NULL == pNewNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004051 if (log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pDescriptorSets[i], __LINE__, DRAWSTATE_OUT_OF_MEMORY, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004052 "Out of memory while attempting to allocate SET_NODE in vkAllocateDescriptorSets()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004053 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisce132d82015-06-19 15:07:05 -06004054 } else {
Tobin Ehlis8b5b28c2015-10-19 12:09:13 -06004055 // TODO : Pool should store a total count of each type of Descriptor available
4056 // When descriptors are allocated, decrement the count and validate here
4057 // that the count doesn't go below 0. One reset/free need to bump count back up.
Tobin Ehlis793ad302015-04-03 12:01:11 -06004058 // Insert set at head of Set LL for this pool
4059 pNewNode->pNext = pPoolNode->pSets;
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07004060 pNewNode->in_use.store(0);
Tobin Ehlis793ad302015-04-03 12:01:11 -06004061 pPoolNode->pSets = pNewNode;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004062 LAYOUT_NODE* pLayout = getLayoutNode(dev_data, pAllocateInfo->pSetLayouts[i]);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004063 if (NULL == pLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004064 if (log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, (uint64_t) pAllocateInfo->pSetLayouts[i], __LINE__, DRAWSTATE_INVALID_LAYOUT, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004065 "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 -07004066 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004067 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06004068 pNewNode->pLayout = pLayout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004069 pNewNode->pool = pAllocateInfo->descriptorPool;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004070 pNewNode->set = pDescriptorSets[i];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004071 pNewNode->descriptorCount = pLayout->endIndex + 1;
4072 if (pNewNode->descriptorCount) {
4073 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
4074 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
4075 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
4076 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08004077 dev_data->setMap[pDescriptorSets[i]] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004078 }
4079 }
4080 }
4081 }
4082 return result;
4083}
4084
Chia-I Wu9ab61502015-11-06 06:42:02 +08004085VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, const VkDescriptorSet* pDescriptorSets)
Tony Barbour34ec6922015-07-10 10:50:45 -06004086{
Tobin Ehlise735c692015-10-08 13:13:50 -06004087 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis0b632332015-10-07 09:38:40 -06004088 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07004089 // Make sure that no sets being destroyed are in-flight
4090 for (uint32_t i=0; i<count; ++i)
4091 skipCall |= validateIdleDescriptorSet(dev_data, pDescriptorSets[i], "vkFreeDesriptorSets");
Mark Lobodzinski39298632015-11-18 08:38:27 -07004092 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, descriptorPool);
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004093 if (pPoolNode && !(VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT & pPoolNode->createInfo.flags)) {
4094 // Can't Free from a NON_FREE pool
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004095 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, (uint64_t)device, __LINE__, DRAWSTATE_CANT_FREE_FROM_NON_FREE_POOL, "DS",
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004096 "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 -06004097 }
Mark Youngb20a6a82016-01-07 15:41:43 -07004098 if (VK_FALSE != skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004099 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis0b632332015-10-07 09:38:40 -06004100 VkResult result = dev_data->device_dispatch_table->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004101 if (VK_SUCCESS == result) {
4102 // For each freed descriptor add it back into the pool as available
4103 for (uint32_t i=0; i<count; ++i) {
Chia-I Wue2fc5522015-10-26 20:04:44 +08004104 SET_NODE* pSet = dev_data->setMap[pDescriptorSets[i]]; // getSetNode() without locking
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004105 LAYOUT_NODE* pLayout = pSet->pLayout;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004106 uint32_t typeIndex = 0, poolSizeCount = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004107 for (uint32_t j=0; j<pLayout->createInfo.bindingCount; ++j) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07004108 typeIndex = static_cast<uint32_t>(pLayout->createInfo.pBindings[j].descriptorType);
4109 poolSizeCount = pLayout->createInfo.pBindings[j].descriptorCount;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004110 pPoolNode->availableDescriptorTypeCount[typeIndex] += poolSizeCount;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004111 }
4112 }
4113 }
4114 // TODO : Any other clean-up or book-keeping to do here?
Tony Barbour34ec6922015-07-10 10:50:45 -06004115 return result;
4116}
4117
Chia-I Wu9ab61502015-11-06 06:42:02 +08004118VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount, const VkWriteDescriptorSet* pDescriptorWrites, uint32_t descriptorCopyCount, const VkCopyDescriptorSet* pDescriptorCopies)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004119{
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06004120 // dsUpdate will return VK_TRUE only if a bailout error occurs, so we want to call down tree when update returns VK_FALSE
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06004121 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08004122 if (!dsUpdate(dev_data, device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies)) {
4123 dev_data->device_dispatch_table->UpdateDescriptorSets(device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies);
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004124 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004125}
4126
Chia-I Wu9ab61502015-11-06 06:42:02 +08004127VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo* pCreateInfo, VkCommandBuffer* pCommandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004128{
Tobin Ehlis0b632332015-10-07 09:38:40 -06004129 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004130 VkResult result = dev_data->device_dispatch_table->AllocateCommandBuffers(device, pCreateInfo, pCommandBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004131 if (VK_SUCCESS == result) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004132 for (uint32_t i = 0; i < pCreateInfo->commandBufferCount; i++) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07004133 // Validate command pool
4134 if (dev_data->commandPoolMap.find(pCreateInfo->commandPool) != dev_data->commandPoolMap.end()) {
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07004135 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07004136 // Add command buffer to its commandPool map
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004137 dev_data->commandPoolMap[pCreateInfo->commandPool].commandBuffers.push_back(pCommandBuffer[i]);
Mark Lobodzinski39298632015-11-18 08:38:27 -07004138 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
4139 // Add command buffer to map
4140 dev_data->commandBufferMap[pCommandBuffer[i]] = pCB;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07004141 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07004142 resetCB(dev_data, pCommandBuffer[i]);
4143 pCB->commandBuffer = pCommandBuffer[i];
4144 pCB->createInfo = *pCreateInfo;
Mark Lobodzinski941aea92016-01-13 10:23:15 -07004145 pCB->device = device;
Mark Lobodzinski39298632015-11-18 08:38:27 -07004146 }
4147 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004148 }
4149 return result;
4150}
4151
Chia-I Wu9ab61502015-11-06 06:42:02 +08004152VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo* pBeginInfo)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004153{
Mark Youngb20a6a82016-01-07 15:41:43 -07004154 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004155 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004156 // Validate command buffer level
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004157 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004158 if (pCB) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004159 if (pCB->createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
4160 // Secondary Command Buffer
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004161 // TODO : Add check here from spec "If commandBuffer is a secondary command buffer and either the
4162 // occlusionQueryEnable member of pBeginInfo is VK_FALSE, or the precise occlusion queries feature
4163 // is not enabled, the queryFlags member of pBeginInfo must not contain VK_QUERY_CONTROL_PRECISE_BIT"
Jon Ashburnf19916e2016-01-11 13:12:43 -07004164 const VkCommandBufferInheritanceInfo *pInfo = pBeginInfo->pInheritanceInfo;
Tobin Ehlis651d9b02015-12-16 05:01:22 -07004165 if (pBeginInfo->flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004166 if (!pInfo->renderPass) { // renderpass should NOT be null for an Secondary CB
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004167 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, __LINE__, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
Tobin Ehlis651d9b02015-12-16 05:01:22 -07004168 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) must specify a valid renderpass parameter.", (void*)commandBuffer);
4169 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07004170 if (!pInfo->framebuffer) { // framebuffer may be null for an Secondary CB, but this affects perf
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004171 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, __LINE__, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
Tobin Ehlis651d9b02015-12-16 05:01:22 -07004172 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) may perform better if a valid framebuffer parameter is specified.", (void*)commandBuffer);
4173 } else {
4174 string errorString = "";
Jon Ashburnf19916e2016-01-11 13:12:43 -07004175 VkRenderPass fbRP = dev_data->frameBufferMap[pInfo->framebuffer]->renderPass;
4176 if (!verify_renderpass_compatibility(dev_data, fbRP, pInfo->renderPass, errorString)) {
Tobin Ehlis651d9b02015-12-16 05:01:22 -07004177 // renderPass that framebuffer was created with must be compatible with local renderPass
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004178 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, __LINE__, DRAWSTATE_RENDERPASS_INCOMPATIBLE, "DS",
Tobin Ehlis651d9b02015-12-16 05:01:22 -07004179 "vkBeginCommandBuffer(): Secondary Command Buffer (%p) renderPass (%#" PRIxLEAST64 ") is incompatible w/ framebuffer (%#" PRIxLEAST64 ") w/ render pass (%#" PRIxLEAST64 ") due to: %s",
Jon Ashburnf19916e2016-01-11 13:12:43 -07004180 (void*)commandBuffer, (uint64_t)pInfo->renderPass, (uint64_t)pInfo->framebuffer, (uint64_t)fbRP, errorString.c_str());
Tobin Ehlis651d9b02015-12-16 05:01:22 -07004181 }
4182 }
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004183 }
4184 }
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004185 if (CB_RECORDING == pCB->state) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004186 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, __LINE__, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004187 "vkBeginCommandBuffer(): Cannot call Begin on CB (%#" PRIxLEAST64 ") in the RECORDING state. Must first call vkEndCommandBuffer().", (uint64_t)commandBuffer);
4188 } else if (CB_RECORDED == pCB->state) {
4189 VkCommandPool cmdPool = pCB->createInfo.commandPool;
4190 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004191 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer,
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004192 __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004193 "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.",
4194 (uint64_t) commandBuffer, (uint64_t) cmdPool);
4195 }
Tobin Ehlisef694652016-01-19 12:03:34 -07004196 resetCB(dev_data, commandBuffer);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004197 }
Tobin Ehlisef694652016-01-19 12:03:34 -07004198 // Set updated state here in case implicit reset occurs above
4199 pCB->state = CB_RECORDING;
4200 pCB->beginInfo = *pBeginInfo;
Tobin Ehliscd5bfd82016-01-19 13:12:52 -07004201
4202 if (pCB->beginInfo.pInheritanceInfo) {
4203 pCB->inheritanceInfo = *(pCB->beginInfo.pInheritanceInfo);
4204 pCB->beginInfo.pInheritanceInfo = &pCB->inheritanceInfo;
4205 }
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004206 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004207 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004208 "In vkBeginCommandBuffer() and unable to find CommandBuffer Node for CB %p!", (void*)commandBuffer);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004209 }
Mark Youngb20a6a82016-01-07 15:41:43 -07004210 if (VK_FALSE != skipCall) {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004211 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter5fe086f2015-09-04 15:03:52 -06004212 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004213 VkResult result = dev_data->device_dispatch_table->BeginCommandBuffer(commandBuffer, pBeginInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004214 return result;
4215}
4216
Chia-I Wu9ab61502015-11-06 06:42:02 +08004217VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEndCommandBuffer(VkCommandBuffer commandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004218{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004219 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchtered894072015-09-04 13:39:59 -06004220 VkResult result = VK_SUCCESS;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004221 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4222 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004223 if (pCB) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004224 if (pCB->state != CB_RECORDING) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004225 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkEndCommandBuffer()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004226 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004227 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004228 if (VK_FALSE == skipCall) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004229 result = dev_data->device_dispatch_table->EndCommandBuffer(commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004230 if (VK_SUCCESS == result) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004231 pCB->state = CB_RECORDED;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004232 // Reset CB status flags
4233 pCB->status = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004234 printCB(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004235 }
4236 } else {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004237 result = VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004238 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004239 return result;
4240}
4241
Chia-I Wu9ab61502015-11-06 06:42:02 +08004242VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004243{
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004244 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004245 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004246 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
4247 VkCommandPool cmdPool = pCB->createInfo.commandPool;
4248 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004249 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t) commandBuffer,
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004250 __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004251 "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.",
4252 (uint64_t) commandBuffer, (uint64_t) cmdPool);
4253 }
Mark Youngb20a6a82016-01-07 15:41:43 -07004254 if (skipCall != VK_FALSE)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004255 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004256 VkResult result = dev_data->device_dispatch_table->ResetCommandBuffer(commandBuffer, flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004257 if (VK_SUCCESS == result) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004258 resetCB(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004259 }
4260 return result;
4261}
4262
Chia-I Wu9ab61502015-11-06 06:42:02 +08004263VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004264{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004265 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004266 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4267 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004268 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004269 skipCall |= addCmd(dev_data, pCB, CMD_BINDPIPELINE, "vkCmdBindPipeline()");
4270 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
4271 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, (uint64_t) pipeline,
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004272 __LINE__, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004273 "Incorrectly binding compute pipeline (%#" PRIxLEAST64 ") during active RenderPass (%#" PRIxLEAST64 ")",
4274 (uint64_t) pipeline, (uint64_t) pCB->activeRenderPass);
4275 } else if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
4276 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdBindPipeline");
4277 }
4278
4279 PIPELINE_NODE* pPN = getPipeline(dev_data, pipeline);
4280 if (pPN) {
4281 pCB->lastBoundPipeline = pipeline;
4282 loader_platform_thread_lock_mutex(&globalLock);
4283 set_cb_pso_status(pCB, pPN);
4284 loader_platform_thread_unlock_mutex(&globalLock);
4285 skipCall |= validatePipelineState(dev_data, pCB, pipelineBindPoint, pipeline);
Tobin Ehlisce132d82015-06-19 15:07:05 -06004286 } else {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004287 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004288 (uint64_t) pipeline, __LINE__, DRAWSTATE_INVALID_PIPELINE, "DS",
Mark Young93ecb1d2016-01-13 13:47:16 -07004289 "Attempt to bind Pipeline %#" PRIxLEAST64 " that doesn't exist!", (uint64_t)(pipeline));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004290 }
4291 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004292 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004293 dev_data->device_dispatch_table->CmdBindPipeline(commandBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004294}
4295
Chia-I Wu9ab61502015-11-06 06:42:02 +08004296VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetViewport(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004297 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004298 uint32_t firstViewport,
4299 uint32_t viewportCount,
4300 const VkViewport* pViewports)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004301{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004302 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004303 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4304 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004305 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004306 skipCall |= addCmd(dev_data, pCB, CMD_SETVIEWPORTSTATE, "vkCmdSetViewport()");
4307 loader_platform_thread_lock_mutex(&globalLock);
4308 pCB->status |= CBSTATUS_VIEWPORT_SET;
4309 pCB->viewports.resize(viewportCount);
4310 memcpy(pCB->viewports.data(), pViewports, viewportCount * sizeof(VkViewport));
4311 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004312 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004313 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004314 dev_data->device_dispatch_table->CmdSetViewport(commandBuffer, firstViewport, viewportCount, pViewports);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004315}
4316
Chia-I Wu9ab61502015-11-06 06:42:02 +08004317VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetScissor(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004318 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004319 uint32_t firstScissor,
4320 uint32_t scissorCount,
4321 const VkRect2D* pScissors)
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004322{
4323 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004324 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4325 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004326 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004327 skipCall |= addCmd(dev_data, pCB, CMD_SETSCISSORSTATE, "vkCmdSetScissor()");
4328 loader_platform_thread_lock_mutex(&globalLock);
4329 pCB->status |= CBSTATUS_SCISSOR_SET;
4330 pCB->scissors.resize(scissorCount);
4331 memcpy(pCB->scissors.data(), pScissors, scissorCount * sizeof(VkRect2D));
4332 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004333 }
4334 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004335 dev_data->device_dispatch_table->CmdSetScissor(commandBuffer, firstScissor, scissorCount, pScissors);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004336}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004337
Chia-I Wu9ab61502015-11-06 06:42:02 +08004338VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004339{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004340 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004341 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4342 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004343 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004344 skipCall |= addCmd(dev_data, pCB, CMD_SETLINEWIDTHSTATE, "vkCmdSetLineWidth()");
4345 /* TODO: Do we still need this lock? */
4346 loader_platform_thread_lock_mutex(&globalLock);
4347 pCB->status |= CBSTATUS_LINE_WIDTH_SET;
4348 pCB->lineWidth = lineWidth;
4349 loader_platform_thread_unlock_mutex(&globalLock);
Cody Northrop12365112015-08-17 11:10:49 -06004350 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004351 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004352 dev_data->device_dispatch_table->CmdSetLineWidth(commandBuffer, lineWidth);
Cody Northrop12365112015-08-17 11:10:49 -06004353}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004354
Chia-I Wu9ab61502015-11-06 06:42:02 +08004355VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBias(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004356 VkCommandBuffer commandBuffer,
Chia-I Wud8c946a2015-10-26 19:08:09 +08004357 float depthBiasConstantFactor,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004358 float depthBiasClamp,
Chia-I Wud8c946a2015-10-26 19:08:09 +08004359 float depthBiasSlopeFactor)
Cody Northrop12365112015-08-17 11:10:49 -06004360{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004361 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004362 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4363 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northrop12365112015-08-17 11:10:49 -06004364 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004365 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBIASSTATE, "vkCmdSetDepthBias()");
4366 pCB->status |= CBSTATUS_DEPTH_BIAS_SET;
4367 pCB->depthBiasConstantFactor = depthBiasConstantFactor;
4368 pCB->depthBiasClamp = depthBiasClamp;
4369 pCB->depthBiasSlopeFactor = depthBiasSlopeFactor;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004370 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004371 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004372 dev_data->device_dispatch_table->CmdSetDepthBias(commandBuffer, depthBiasConstantFactor, depthBiasClamp, depthBiasSlopeFactor);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004373}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004374
Chia-I Wu9ab61502015-11-06 06:42:02 +08004375VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4])
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004376{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004377 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004378 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4379 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004380 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004381 skipCall |= addCmd(dev_data, pCB, CMD_SETBLENDSTATE, "vkCmdSetBlendConstants()");
4382 pCB->status |= CBSTATUS_BLEND_SET;
4383 memcpy(pCB->blendConstants, blendConstants, 4 * sizeof(float));
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004384 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004385 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004386 dev_data->device_dispatch_table->CmdSetBlendConstants(commandBuffer, blendConstants);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004387}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004388
Chia-I Wu9ab61502015-11-06 06:42:02 +08004389VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBounds(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004390 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004391 float minDepthBounds,
4392 float maxDepthBounds)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004393{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004394 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004395 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4396 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004397 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004398 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBOUNDSSTATE, "vkCmdSetDepthBounds()");
4399 pCB->status |= CBSTATUS_DEPTH_BOUNDS_SET;
4400 pCB->minDepthBounds = minDepthBounds;
4401 pCB->maxDepthBounds = maxDepthBounds;
Cody Northrop82485a82015-08-18 15:21:16 -06004402 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004403 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004404 dev_data->device_dispatch_table->CmdSetDepthBounds(commandBuffer, minDepthBounds, maxDepthBounds);
Cody Northrop82485a82015-08-18 15:21:16 -06004405}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004406
Chia-I Wu9ab61502015-11-06 06:42:02 +08004407VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilCompareMask(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004408 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004409 VkStencilFaceFlags faceMask,
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004410 uint32_t compareMask)
Cody Northrop82485a82015-08-18 15:21:16 -06004411{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004412 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004413 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4414 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northrop82485a82015-08-18 15:21:16 -06004415 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004416 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREADMASKSTATE, "vkCmdSetStencilCompareMask()");
4417 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4418 pCB->front.compareMask = compareMask;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004419 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004420 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4421 pCB->back.compareMask = compareMask;
4422 }
4423 /* TODO: Do we need to track front and back separately? */
4424 /* TODO: We aren't capturing the faceMask, do we need to? */
4425 pCB->status |= CBSTATUS_STENCIL_READ_MASK_SET;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004426 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004427 if (VK_FALSE == skipCall)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004428 dev_data->device_dispatch_table->CmdSetStencilCompareMask(commandBuffer, faceMask, compareMask);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004429}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004430
Chia-I Wu9ab61502015-11-06 06:42:02 +08004431VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilWriteMask(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004432 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004433 VkStencilFaceFlags faceMask,
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004434 uint32_t writeMask)
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004435{
4436 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004437 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4438 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004439 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004440 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILWRITEMASKSTATE, "vkCmdSetStencilWriteMask()");
4441 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4442 pCB->front.writeMask = writeMask;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004443 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004444 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4445 pCB->back.writeMask = writeMask;
4446 }
4447 pCB->status |= CBSTATUS_STENCIL_WRITE_MASK_SET;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004448 }
4449 if (VK_FALSE == skipCall)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004450 dev_data->device_dispatch_table->CmdSetStencilWriteMask(commandBuffer, faceMask, writeMask);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004451}
4452
Chia-I Wu9ab61502015-11-06 06:42:02 +08004453VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilReference(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004454 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004455 VkStencilFaceFlags faceMask,
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004456 uint32_t reference)
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004457{
4458 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004459 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4460 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004461 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004462 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREFERENCESTATE, "vkCmdSetStencilReference()");
4463 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4464 pCB->front.reference = reference;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004465 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004466 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4467 pCB->back.reference = reference;
4468 }
4469 pCB->status |= CBSTATUS_STENCIL_REFERENCE_SET;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004470 }
4471 if (VK_FALSE == skipCall)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004472 dev_data->device_dispatch_table->CmdSetStencilReference(commandBuffer, faceMask, reference);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004473}
4474
Chia-I Wu9ab61502015-11-06 06:42:02 +08004475VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindDescriptorSets(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, uint32_t firstSet, uint32_t setCount, const VkDescriptorSet* pDescriptorSets, uint32_t dynamicOffsetCount, const uint32_t* pDynamicOffsets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004476{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004477 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004478 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 Ehlis10ae8c12015-03-17 16:24:32 -06004480 if (pCB) {
Tobin Ehlisf6585052015-12-17 11:48:42 -07004481 if (pCB->state == CB_RECORDING) {
4482 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004483 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Tobin Ehlisf6585052015-12-17 11:48:42 -07004484 "Incorrectly binding compute DescriptorSets during active RenderPass (%#" PRIxLEAST64 ")", (uint64_t) pCB->activeRenderPass);
4485 } else if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
4486 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdBindDescriptorSets");
Mark Lobodzinski74635932015-12-18 15:35:38 -07004487 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07004488 if (VK_FALSE == skipCall) {
4489 // Track total count of dynamic descriptor types to make sure we have an offset for each one
4490 uint32_t totalDynamicDescriptors = 0;
4491 string errorString = "";
4492 uint32_t lastSetIndex = firstSet+setCount-1;
4493 if (lastSetIndex >= pCB->boundDescriptorSets.size())
Tobin Ehlis559c6382015-11-05 09:52:49 -07004494 pCB->boundDescriptorSets.resize(lastSetIndex+1);
Tobin Ehlisf6585052015-12-17 11:48:42 -07004495 VkDescriptorSet oldFinalBoundSet = pCB->boundDescriptorSets[lastSetIndex];
4496 for (uint32_t i=0; i<setCount; i++) {
4497 SET_NODE* pSet = getSetNode(dev_data, pDescriptorSets[i]);
4498 if (pSet) {
4499 loader_platform_thread_lock_mutex(&globalLock);
4500 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
4501 pCB->lastBoundPipelineLayout = layout;
4502 pCB->boundDescriptorSets[i+firstSet] = pDescriptorSets[i];
4503 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004504 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pDescriptorSets[i], __LINE__, DRAWSTATE_NONE, "DS",
Tobin Ehlisf6585052015-12-17 11:48:42 -07004505 "DS %#" PRIxLEAST64 " bound on pipeline %s", (uint64_t) pDescriptorSets[i], string_VkPipelineBindPoint(pipelineBindPoint));
Tobin Ehlis43c39c02016-01-11 13:18:40 -07004506 if (!pSet->pUpdateStructs && (pSet->descriptorCount != 0)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004507 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pDescriptorSets[i], __LINE__, DRAWSTATE_DESCRIPTOR_SET_NOT_UPDATED, "DS",
Tobin Ehlisf6585052015-12-17 11:48:42 -07004508 "DS %#" PRIxLEAST64 " bound but it was never updated. You may want to either update it or not bind it.", (uint64_t) pDescriptorSets[i]);
4509 }
4510 // Verify that set being bound is compatible with overlapping setLayout of pipelineLayout
4511 if (!verify_set_layout_compatibility(dev_data, pSet, layout, i+firstSet, errorString)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004512 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pDescriptorSets[i], __LINE__, DRAWSTATE_PIPELINE_LAYOUTS_INCOMPATIBLE, "DS",
Tobin Ehlisf6585052015-12-17 11:48:42 -07004513 "descriptorSet #%u being bound is not compatible with overlapping layout in pipelineLayout due to: %s", i, errorString.c_str());
4514 }
4515 if (pSet->pLayout->dynamicDescriptorCount) {
4516 // First make sure we won't overstep bounds of pDynamicOffsets array
4517 if ((totalDynamicDescriptors + pSet->pLayout->dynamicDescriptorCount) > dynamicOffsetCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004518 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pDescriptorSets[i], __LINE__, DRAWSTATE_INVALID_DYNAMIC_OFFSET_COUNT, "DS",
Tobin Ehlisf6585052015-12-17 11:48:42 -07004519 "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.",
4520 i, (uint64_t) pDescriptorSets[i], pSet->pLayout->dynamicDescriptorCount, (dynamicOffsetCount - totalDynamicDescriptors));
Mark Lobodzinski941aea92016-01-13 10:23:15 -07004521 } else { // Validate and store dynamic offsets with the set
4522 // Validate Dynamic Offset Minimums
4523 uint32_t cur_dyn_offset = totalDynamicDescriptors;
4524 for (uint32_t d = 0; d < pSet->descriptorCount; d++) {
4525 if (pSet->pLayout->descriptorTypes[i] == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) {
4526 if (vk_safe_modulo(pDynamicOffsets[cur_dyn_offset], dev_data->physDevPropertyMap[pCB->device].limits.minUniformBufferOffsetAlignment) != 0) {
4527 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0,
4528 __LINE__, DRAWSTATE_INVALID_UNIFORM_BUFFER_OFFSET, "DS",
4529 "vkCmdBindDescriptorSets(): pDynamicOffsets[%d] is %d but must be a multiple of device limit minUniformBufferOffsetAlignment %#" PRIxLEAST64,
4530 cur_dyn_offset, pDynamicOffsets[cur_dyn_offset], dev_data->physDevPropertyMap[pCB->device].limits.minUniformBufferOffsetAlignment);
4531 }
4532 cur_dyn_offset++;
4533 } else if (pSet->pLayout->descriptorTypes[i] == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC) {
4534 if (vk_safe_modulo(pDynamicOffsets[cur_dyn_offset], dev_data->physDevPropertyMap[pCB->device].limits.minStorageBufferOffsetAlignment) != 0) {
4535 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0,
4536 __LINE__, DRAWSTATE_INVALID_STORAGE_BUFFER_OFFSET, "DS",
4537 "vkCmdBindDescriptorSets(): pDynamicOffsets[%d] is %d but must be a multiple of device limit minStorageBufferOffsetAlignment %#" PRIxLEAST64,
4538 cur_dyn_offset, pDynamicOffsets[cur_dyn_offset], dev_data->physDevPropertyMap[pCB->device].limits.minStorageBufferOffsetAlignment);
4539 }
4540 cur_dyn_offset++;
4541 }
4542 }
4543 // Store offsets
Tobin Ehlisf6585052015-12-17 11:48:42 -07004544 const uint32_t* pStartDynOffset = pDynamicOffsets + totalDynamicDescriptors;
4545 pSet->dynamicOffsets.assign(pStartDynOffset, pStartDynOffset + pSet->pLayout->dynamicDescriptorCount);
4546 totalDynamicDescriptors += pSet->pLayout->dynamicDescriptorCount;
4547 }
4548 }
4549 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004550 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pDescriptorSets[i], __LINE__, DRAWSTATE_INVALID_SET, "DS",
Tobin Ehlisf6585052015-12-17 11:48:42 -07004551 "Attempt to bind DS %#" PRIxLEAST64 " that doesn't exist!", (uint64_t) pDescriptorSets[i]);
4552 }
4553 }
4554 skipCall |= addCmd(dev_data, pCB, CMD_BINDDESCRIPTORSETS, "vkCmdBindDescrsiptorSets()");
4555 // For any previously bound sets, need to set them to "invalid" if they were disturbed by this update
4556 if (firstSet > 0) { // Check set #s below the first bound set
4557 for (uint32_t i=0; i<firstSet; ++i) {
4558 if (pCB->boundDescriptorSets[i] && !verify_set_layout_compatibility(dev_data, dev_data->setMap[pCB->boundDescriptorSets[i]], layout, i, errorString)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004559 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pCB->boundDescriptorSets[i], __LINE__, DRAWSTATE_NONE, "DS",
Tobin Ehlisf6585052015-12-17 11:48:42 -07004560 "DescriptorSetDS %#" PRIxLEAST64 " previously bound as set #%u was disturbed by newly bound pipelineLayout (%#" PRIxLEAST64 ")", (uint64_t) pCB->boundDescriptorSets[i], i, (uint64_t) layout);
4561 pCB->boundDescriptorSets[i] = VK_NULL_HANDLE;
4562 }
4563 }
4564 }
4565 // Check if newly last bound set invalidates any remaining bound sets
4566 if ((pCB->boundDescriptorSets.size()-1) > (lastSetIndex)) {
4567 if (oldFinalBoundSet && !verify_set_layout_compatibility(dev_data, dev_data->setMap[oldFinalBoundSet], layout, lastSetIndex, errorString)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004568 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) oldFinalBoundSet, __LINE__, DRAWSTATE_NONE, "DS",
Tobin Ehlisf6585052015-12-17 11:48:42 -07004569 "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);
4570 pCB->boundDescriptorSets.resize(lastSetIndex+1);
4571 }
4572 }
4573 // dynamicOffsetCount must equal the total number of dynamic descriptors in the sets being bound
4574 if (totalDynamicDescriptors != dynamicOffsetCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004575 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t) commandBuffer, __LINE__, DRAWSTATE_INVALID_DYNAMIC_OFFSET_COUNT, "DS",
Tobin Ehlisf6585052015-12-17 11:48:42 -07004576 "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 -07004577 }
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07004578 validateAndIncrementDescriptorSets(dev_data, pCB);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004579 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07004580 } else {
4581 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindDescriptorSets()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004582 }
4583 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004584 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004585 dev_data->device_dispatch_table->CmdBindDescriptorSets(commandBuffer, pipelineBindPoint, layout, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004586}
4587
Chia-I Wu9ab61502015-11-06 06:42:02 +08004588VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004589{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004590 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004591 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4592 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004593 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004594 skipCall |= addCmd(dev_data, pCB, CMD_BINDINDEXBUFFER, "vkCmdBindIndexBuffer()");
4595 VkDeviceSize offset_align = 0;
4596 switch (indexType) {
4597 case VK_INDEX_TYPE_UINT16:
4598 offset_align = 2;
4599 break;
4600 case VK_INDEX_TYPE_UINT32:
4601 offset_align = 4;
4602 break;
4603 default:
4604 // ParamChecker should catch bad enum, we'll also throw alignment error below if offset_align stays 0
4605 break;
4606 }
4607 if (!offset_align || (offset % offset_align)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004608 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VTX_INDEX_ALIGNMENT_ERROR, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004609 "vkCmdBindIndexBuffer() offset (%#" PRIxLEAST64 ") does not fall on alignment (%s) boundary.", offset, string_VkIndexType(indexType));
Tobin Ehlis9c536442015-06-19 13:00:59 -06004610 }
Tobin Ehlisc4c23182015-09-17 12:24:13 -06004611 pCB->status |= CBSTATUS_INDEX_BUFFER_BOUND;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004612 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004613 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004614 dev_data->device_dispatch_table->CmdBindIndexBuffer(commandBuffer, buffer, offset, indexType);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004615}
4616
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07004617void updateResourceTracking(GLOBAL_CB_NODE* pCB, uint32_t firstBinding, uint32_t bindingCount, const VkBuffer* pBuffers) {
4618 uint32_t end = firstBinding + bindingCount;
Michael Lentine700b0aa2015-10-30 17:57:32 -07004619 if (pCB->currentDrawData.buffers.size() < end) {
4620 pCB->currentDrawData.buffers.resize(end);
4621 }
4622 for (uint32_t i = 0; i < bindingCount; ++i) {
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07004623 pCB->currentDrawData.buffers[i + firstBinding] = pBuffers[i];
Michael Lentine700b0aa2015-10-30 17:57:32 -07004624 }
4625}
4626
4627void updateResourceTrackingOnDraw(GLOBAL_CB_NODE* pCB) {
4628 pCB->drawData.push_back(pCB->currentDrawData);
4629}
4630
Chia-I Wu9ab61502015-11-06 06:42:02 +08004631VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindVertexBuffers(
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07004632 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004633 uint32_t firstBinding,
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06004634 uint32_t bindingCount,
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07004635 const VkBuffer *pBuffers,
4636 const VkDeviceSize *pOffsets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004637{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004638 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004639 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4640 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004641 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004642 addCmd(dev_data, pCB, CMD_BINDVERTEXBUFFER, "vkCmdBindVertexBuffer()");
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07004643 updateResourceTracking(pCB, firstBinding, bindingCount, pBuffers);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004644 } else {
Mark Youngad779052016-01-06 14:26:04 -07004645 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindVertexBuffer()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004646 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004647 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004648 dev_data->device_dispatch_table->CmdBindVertexBuffers(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004649}
4650
Chia-I Wu9ab61502015-11-06 06:42:02 +08004651VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004652{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004653 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004654 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4655 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004656 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004657 skipCall |= addCmd(dev_data, pCB, CMD_DRAW, "vkCmdDraw()");
4658 pCB->drawCount[DRAW]++;
4659 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
4660 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004661 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_NONE, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004662 "vkCmdDraw() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW]++);
4663 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004664 if (VK_FALSE == skipCall) {
4665 updateResourceTrackingOnDraw(pCB);
4666 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004667 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDraw");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004668 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004669 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004670 dev_data->device_dispatch_table->CmdDraw(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004671}
4672
Chia-I Wu9ab61502015-11-06 06:42:02 +08004673VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004674{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004675 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4676 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004677 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004678 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004679 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXED, "vkCmdDrawIndexed()");
4680 pCB->drawCount[DRAW_INDEXED]++;
4681 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
4682 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004683 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_NONE, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004684 "vkCmdDrawIndexed() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED]++);
4685 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004686 if (VK_FALSE == skipCall) {
4687 updateResourceTrackingOnDraw(pCB);
4688 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004689 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexed");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004690 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004691 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004692 dev_data->device_dispatch_table->CmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004693}
4694
Chia-I Wu9ab61502015-11-06 06:42:02 +08004695VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004696{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004697 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4698 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004699 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004700 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004701 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDIRECT, "vkCmdDrawIndirect()");
4702 pCB->drawCount[DRAW_INDIRECT]++;
4703 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
4704 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004705 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_NONE, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004706 "vkCmdDrawIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
4707 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004708 if (VK_FALSE == skipCall) {
4709 updateResourceTrackingOnDraw(pCB);
4710 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004711 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndirect");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004712 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004713 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004714 dev_data->device_dispatch_table->CmdDrawIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004715}
4716
Chia-I Wu9ab61502015-11-06 06:42:02 +08004717VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004718{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004719 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004720 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4721 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004722 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004723 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXEDINDIRECT, "vkCmdDrawIndexedIndirect()");
4724 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
4725 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
4726 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004727 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_NONE, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004728 "vkCmdDrawIndexedIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
4729 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004730 if (VK_FALSE == skipCall) {
4731 updateResourceTrackingOnDraw(pCB);
4732 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004733 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexedIndirect");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004734 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004735 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004736 dev_data->device_dispatch_table->CmdDrawIndexedIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004737}
4738
Chia-I Wu9ab61502015-11-06 06:42:02 +08004739VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004740{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004741 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004742 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4743 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004744 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004745 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCH, "vkCmdDispatch()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004746 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatch");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004747 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004748 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004749 dev_data->device_dispatch_table->CmdDispatch(commandBuffer, x, y, z);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004750}
4751
Chia-I Wu9ab61502015-11-06 06:42:02 +08004752VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004753{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004754 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004755 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4756 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004757 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004758 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCHINDIRECT, "vkCmdDispatchIndirect()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004759 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatchIndirect");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004760 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004761 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004762 dev_data->device_dispatch_table->CmdDispatchIndirect(commandBuffer, buffer, offset);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004763}
4764
Chia-I Wu9ab61502015-11-06 06:42:02 +08004765VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004766{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004767 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004768 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4769 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004770 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004771 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFER, "vkCmdCopyBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004772 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004773 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004774 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004775 dev_data->device_dispatch_table->CmdCopyBuffer(commandBuffer, srcBuffer, dstBuffer, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004776}
4777
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07004778VkBool32 VerifySourceImageLayout(VkCommandBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout) {
Mark Youngb20a6a82016-01-07 15:41:43 -07004779 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07004780
4781#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4782 // TODO: Fix -- initialLayout may have been set in a previous command buffer
4783 return skip_call;
4784#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4785
Michael Lentineabc5e922015-10-12 11:30:14 -05004786 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4787 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4788 auto src_image_element = pCB->imageLayoutMap.find(srcImage);
4789 if (src_image_element == pCB->imageLayoutMap.end()) {
4790 pCB->imageLayoutMap[srcImage].initialLayout = srcImageLayout;
4791 pCB->imageLayoutMap[srcImage].layout = srcImageLayout;
Mark Youngb20a6a82016-01-07 15:41:43 -07004792 return VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05004793 }
4794 if (src_image_element->second.layout != srcImageLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004795 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05004796 "Cannot copy from an image whose source layout is %d and doesn't match the current layout %d.", srcImageLayout, src_image_element->second.layout);
4797 }
4798 if (srcImageLayout != VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL) {
4799 if (srcImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004800 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004801 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineecc32b72015-10-16 18:08:09 -05004802 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Michael Lentineabc5e922015-10-12 11:30:14 -05004803 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004804 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineecc32b72015-10-16 18:08:09 -05004805 "Layout for input image is %d but can only be TRANSFER_SRC_OPTIMAL or GENERAL.", srcImageLayout);
Michael Lentineabc5e922015-10-12 11:30:14 -05004806 }
4807 }
4808 return skip_call;
4809}
4810
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07004811VkBool32 VerifyDestImageLayout(VkCommandBuffer cmdBuffer, VkImage destImage, VkImageLayout destImageLayout) {
Mark Youngb20a6a82016-01-07 15:41:43 -07004812 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07004813
4814#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4815 // TODO: Fix -- initialLayout may have been set in a previous command buffer
4816 return skip_call;
4817#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4818
Michael Lentineabc5e922015-10-12 11:30:14 -05004819 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4820 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4821 auto dest_image_element = pCB->imageLayoutMap.find(destImage);
4822 if (dest_image_element == pCB->imageLayoutMap.end()) {
4823 pCB->imageLayoutMap[destImage].initialLayout = destImageLayout;
4824 pCB->imageLayoutMap[destImage].layout = destImageLayout;
Mark Youngb20a6a82016-01-07 15:41:43 -07004825 return VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05004826 }
4827 if (dest_image_element->second.layout != destImageLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004828 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05004829 "Cannot copy from an image whose dest layout is %d and doesn't match the current layout %d.", destImageLayout, dest_image_element->second.layout);
4830 }
4831 if (destImageLayout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) {
4832 if (destImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004833 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004834 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05004835 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
4836 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004837 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05004838 "Layout for output image is %d but can only be TRANSFER_DST_OPTIMAL or GENERAL.", destImageLayout);
4839 }
4840 }
4841 return skip_call;
4842}
4843
Chia-I Wu9ab61502015-11-06 06:42:02 +08004844VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004845 VkImage srcImage,
4846 VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004847 VkImage dstImage,
4848 VkImageLayout dstImageLayout,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004849 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004850{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004851 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004852 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4853 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004854 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004855 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGE, "vkCmdCopyImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004856 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImage");
Michael Lentineabc5e922015-10-12 11:30:14 -05004857 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
4858 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004859 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004860 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004861 dev_data->device_dispatch_table->CmdCopyImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004862}
4863
Chia-I Wu9ab61502015-11-06 06:42:02 +08004864VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBlitImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004865 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004866 VkImage dstImage, VkImageLayout dstImageLayout,
Mark Lobodzinskiee5eef12015-05-22 14:43:25 -05004867 uint32_t regionCount, const VkImageBlit* pRegions,
Chia-I Wub99df442015-10-26 16:49:32 +08004868 VkFilter filter)
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004869{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004870 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004871 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4872 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004873 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004874 skipCall |= addCmd(dev_data, pCB, CMD_BLITIMAGE, "vkCmdBlitImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004875 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBlitImage");
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004876 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004877 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004878 dev_data->device_dispatch_table->CmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter);
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004879}
4880
Chia-I Wu9ab61502015-11-06 06:42:02 +08004881VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004882 VkBuffer srcBuffer,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004883 VkImage dstImage, VkImageLayout dstImageLayout,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004884 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004885{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004886 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004887 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4888 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004889 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004890 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFERTOIMAGE, "vkCmdCopyBufferToImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004891 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBufferToImage");
Michael Lentineabc5e922015-10-12 11:30:14 -05004892 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004893 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004894 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004895 dev_data->device_dispatch_table->CmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004896}
4897
Chia-I Wu9ab61502015-11-06 06:42:02 +08004898VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004899 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004900 VkBuffer dstBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004901 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004902{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004903 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004904 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4905 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004906 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004907 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGETOBUFFER, "vkCmdCopyImageToBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004908 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImageToBuffer");
Michael Lentineabc5e922015-10-12 11:30:14 -05004909 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004910 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004911 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004912 dev_data->device_dispatch_table->CmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004913}
4914
Chia-I Wu9ab61502015-11-06 06:42:02 +08004915VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize dataSize, const uint32_t* pData)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004916{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004917 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004918 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4919 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004920 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004921 skipCall |= addCmd(dev_data, pCB, CMD_UPDATEBUFFER, "vkCmdUpdateBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004922 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyUpdateBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004923 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004924 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004925 dev_data->device_dispatch_table->CmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004926}
4927
Chia-I Wu9ab61502015-11-06 06:42:02 +08004928VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize size, uint32_t data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004929{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004930 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004931 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4932 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004933 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004934 skipCall |= addCmd(dev_data, pCB, CMD_FILLBUFFER, "vkCmdFillBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004935 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyFillBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004936 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004937 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004938 dev_data->device_dispatch_table->CmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004939}
4940
Chia-I Wu9ab61502015-11-06 06:42:02 +08004941VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearAttachments(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004942 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004943 uint32_t attachmentCount,
4944 const VkClearAttachment* pAttachments,
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004945 uint32_t rectCount,
Courtney Goeltzenleuchter4ca43f62015-10-15 18:22:08 -06004946 const VkClearRect* pRects)
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004947{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004948 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004949 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4950 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004951 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004952 skipCall |= addCmd(dev_data, pCB, CMD_CLEARATTACHMENTS, "vkCmdClearAttachments()");
4953 // Warn if this is issued prior to Draw Cmd and clearing the entire attachment
4954 if (!hasDrawCmd(pCB) &&
4955 (pCB->activeRenderPassBeginInfo.renderArea.extent.width == pRects[0].rect.extent.width) &&
4956 (pCB->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) {
4957 // TODO : commandBuffer should be srcObj
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004958 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_CLEAR_CMD_BEFORE_DRAW, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004959 "vkCmdClearAttachments() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
Mark Youngee3f3a22016-01-25 12:18:32 -07004960 " 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 -06004961 }
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004962 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdClearAttachments");
4963 }
4964
4965 // Validate that attachment is in reference list of active subpass
4966 if (pCB->activeRenderPass) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07004967 const VkRenderPassCreateInfo *pRPCI = dev_data->renderPassMap[pCB->activeRenderPass]->pCreateInfo;
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004968 const VkSubpassDescription *pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
4969
4970 for (uint32_t attachment_idx = 0; attachment_idx < attachmentCount; attachment_idx++) {
4971 const VkClearAttachment *attachment = &pAttachments[attachment_idx];
4972 if (attachment->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) {
4973 VkBool32 found = VK_FALSE;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004974 for (uint32_t i = 0; i < pSD->colorAttachmentCount; i++) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004975 if (attachment->colorAttachment == pSD->pColorAttachments[i].attachment) {
4976 found = VK_TRUE;
4977 break;
4978 }
4979 }
4980 if (VK_FALSE == found) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004981 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004982 (uint64_t)commandBuffer, __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004983 "vkCmdClearAttachments() attachment index %d not found in attachment reference array of active subpass %d",
4984 attachment->colorAttachment, pCB->activeSubpass);
4985 }
4986 } else if (attachment->aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) {
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07004987 if (!pSD->pDepthStencilAttachment || // Says no DS will be used in active subpass
Mark Lobodzinski2fd355a2015-11-18 08:58:31 -07004988 (pSD->pDepthStencilAttachment->attachment == VK_ATTACHMENT_UNUSED)) { // Says no DS will be used in active subpass
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07004989
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004990 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004991 (uint64_t)commandBuffer, __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07004992 "vkCmdClearAttachments() attachment index %d does not match depthStencilAttachment.attachment (%d) found in active subpass %d",
4993 attachment->colorAttachment,
4994 (pSD->pDepthStencilAttachment) ? pSD->pDepthStencilAttachment->attachment : VK_ATTACHMENT_UNUSED,
4995 pCB->activeSubpass);
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004996 }
4997 }
4998 }
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004999 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005000 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005001 dev_data->device_dispatch_table->CmdClearAttachments(commandBuffer, attachmentCount, pAttachments, rectCount, pRects);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06005002}
5003
Chia-I Wu9ab61502015-11-06 06:42:02 +08005004VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearColorImage(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005005 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06005006 VkImage image, VkImageLayout imageLayout,
Chris Forbesf0796e12015-06-24 14:34:53 +12005007 const VkClearColorValue *pColor,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06005008 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005009{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005010 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005011 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5012 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005013 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005014 skipCall |= addCmd(dev_data, pCB, CMD_CLEARCOLORIMAGE, "vkCmdClearColorImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005015 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearColorImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005016 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005017 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005018 dev_data->device_dispatch_table->CmdClearColorImage(commandBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005019}
5020
Chia-I Wu9ab61502015-11-06 06:42:02 +08005021VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearDepthStencilImage(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005022 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter45df9e12015-09-15 18:03:22 -06005023 VkImage image, VkImageLayout imageLayout,
5024 const VkClearDepthStencilValue *pDepthStencil,
5025 uint32_t rangeCount,
5026 const VkImageSubresourceRange* pRanges)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005027{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005028 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005029 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5030 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005031 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005032 skipCall |= addCmd(dev_data, pCB, CMD_CLEARDEPTHSTENCILIMAGE, "vkCmdClearDepthStencilImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005033 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearDepthStencilImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005034 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005035 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005036 dev_data->device_dispatch_table->CmdClearDepthStencilImage(commandBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005037}
5038
Chia-I Wu9ab61502015-11-06 06:42:02 +08005039VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResolveImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06005040 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005041 VkImage dstImage, VkImageLayout dstImageLayout,
Tony Barbour6865d4a2015-04-13 15:02:52 -06005042 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005043{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005044 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005045 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5046 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005047 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005048 skipCall |= addCmd(dev_data, pCB, CMD_RESOLVEIMAGE, "vkCmdResolveImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005049 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResolveImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005050 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005051 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005052 dev_data->device_dispatch_table->CmdResolveImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005053}
5054
Chia-I Wu9ab61502015-11-06 06:42:02 +08005055VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005056{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005057 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005058 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5059 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005060 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005061 skipCall |= addCmd(dev_data, pCB, CMD_SETEVENT, "vkCmdSetEvent()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005062 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdSetEvent");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005063 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005064 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005065 dev_data->device_dispatch_table->CmdSetEvent(commandBuffer, event, stageMask);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005066}
5067
Chia-I Wu9ab61502015-11-06 06:42:02 +08005068VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005069{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005070 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005071 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5072 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005073 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005074 skipCall |= addCmd(dev_data, pCB, CMD_RESETEVENT, "vkCmdResetEvent()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005075 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResetEvent");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005076 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005077 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005078 dev_data->device_dispatch_table->CmdResetEvent(commandBuffer, event, stageMask);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005079}
5080
Jon Ashburnf19916e2016-01-11 13:12:43 -07005081VkBool32 TransitionImageLayouts(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const VkImageMemoryBarrier* pImgMemBarriers) {
Michael Lentineabc5e922015-10-12 11:30:14 -05005082 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5083 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Mark Youngb20a6a82016-01-07 15:41:43 -07005084 VkBool32 skip = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005085
5086#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
5087 // TODO: Fix -- pay attention to image subresource ranges -- not all subresources transition at the same time
5088 return skip;
5089#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5090
Michael Lentineabc5e922015-10-12 11:30:14 -05005091 for (uint32_t i = 0; i < memBarrierCount; ++i) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005092 auto mem_barrier = &pImgMemBarriers[i];
Michael Lentineabc5e922015-10-12 11:30:14 -05005093 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005094 auto image_data = pCB->imageLayoutMap.find(mem_barrier->image);
Michael Lentineabc5e922015-10-12 11:30:14 -05005095 if (image_data == pCB->imageLayoutMap.end()) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005096 pCB->imageLayoutMap[mem_barrier->image].initialLayout = mem_barrier->oldLayout;
5097 pCB->imageLayoutMap[mem_barrier->image].layout = mem_barrier->newLayout;
Michael Lentineabc5e922015-10-12 11:30:14 -05005098 } else {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005099 if (image_data->second.layout != mem_barrier->oldLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005100 skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Jon Ashburnf19916e2016-01-11 13:12:43 -07005101 "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 -05005102 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07005103 image_data->second.layout = mem_barrier->newLayout;
Michael Lentineabc5e922015-10-12 11:30:14 -05005104 }
5105 }
5106 }
5107 return skip;
5108}
5109
Mark Lobodzinskia3a86112016-01-05 17:17:55 -07005110// Print readable FlagBits in FlagMask
5111std::string string_VkAccessFlags(VkAccessFlags accessMask)
5112{
5113 std::string result;
5114 std::string separator;
5115
5116 if (accessMask == 0) {
5117 result = "[None]";
5118 } else {
5119 result = "[";
5120 for (auto i = 0; i < 32; i++) {
5121 if (accessMask & (1 << i)) {
5122 result = result + separator + string_VkAccessFlagBits((VkAccessFlagBits)(1 << i));
5123 separator = " | ";
5124 }
5125 }
5126 result = result + "]";
5127 }
5128 return result;
5129}
5130
Michael Lentine97eb7462015-11-20 09:48:52 -08005131// AccessFlags MUST have 'required_bit' set, and may have one or more of 'optional_bits' set.
5132// If required_bit is zero, accessMask must have at least one of 'optional_bits' set
Mark Lobodzinskifd740fc2016-01-06 12:56:29 -07005133// TODO: Add tracking to ensure that at least one barrier has been set for these layout transitions
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005134VkBool32 ValidateMaskBits(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout,
5135 VkAccessFlags required_bit, VkAccessFlags optional_bits, const char* type) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005136 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005137
Michael Lentine97eb7462015-11-20 09:48:52 -08005138 if ((accessMask & required_bit) || (!required_bit && (accessMask & optional_bits))) {
5139 if (accessMask & !(required_bit | optional_bits)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005140 // TODO: Verify against Valid Use
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005141 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005142 "Additional bits in %s accessMask %d %s are specified when layout is %s.",
5143 type, accessMask, string_VkAccessFlags(accessMask).c_str(), string_VkImageLayout(layout));
Michael Lentineecc32b72015-10-16 18:08:09 -05005144 }
5145 } else {
Michael Lentine97eb7462015-11-20 09:48:52 -08005146 if (!required_bit) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005147 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
Mark Lobodzinskifd740fc2016-01-06 12:56:29 -07005148 "%s AccessMask %d %s must contain at least one of access bits %d %s when layout is %s, unless the app has previously added a barrier for this transition.",
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005149 type, accessMask, string_VkAccessFlags(accessMask).c_str(), optional_bits,
5150 string_VkAccessFlags(optional_bits).c_str(), string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08005151 } else {
Mark Lobodzinskif2cc2a52016-01-05 13:35:29 -07005152 std::string opt_bits;
5153 if (optional_bits != 0) {
Michael Lentine6bd4f122016-01-19 14:00:53 -06005154 std::stringstream ss;
5155 ss << optional_bits;
5156 opt_bits = "and may have optional bits " + ss.str() + ' ' + string_VkAccessFlags(optional_bits);
Mark Lobodzinskif2cc2a52016-01-05 13:35:29 -07005157 }
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005158 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
Mark Lobodzinskifd740fc2016-01-06 12:56:29 -07005159 "%s AccessMask %d %s must have required access bit %d %s %s when layout is %s, unless the app has previously added a barrier for this transition.",
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005160 type, accessMask, string_VkAccessFlags(accessMask).c_str(),
5161 required_bit, string_VkAccessFlags(required_bit).c_str(),
Mark Lobodzinskif2cc2a52016-01-05 13:35:29 -07005162 opt_bits.c_str(), string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08005163 }
Michael Lentineecc32b72015-10-16 18:08:09 -05005164 }
5165 return skip_call;
5166}
5167
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005168VkBool32 ValidateMaskBitsFromLayouts(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout, const char* type) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005169 VkBool32 skip_call = VK_FALSE;
Michael Lentine97eb7462015-11-20 09:48:52 -08005170 switch (layout) {
5171 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005172 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_COLOR_ATTACHMENT_READ_BIT, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08005173 break;
Michael Lentineecc32b72015-10-16 18:08:09 -05005174 }
Michael Lentine97eb7462015-11-20 09:48:52 -08005175 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005176 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08005177 break;
Michael Lentineecc32b72015-10-16 18:08:09 -05005178 }
Michael Lentine97eb7462015-11-20 09:48:52 -08005179 case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005180 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_WRITE_BIT, 0, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08005181 break;
5182 }
5183 case VK_IMAGE_LAYOUT_PREINITIALIZED: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005184 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_HOST_WRITE_BIT, 0, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08005185 break;
5186 }
5187 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005188 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, 0, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08005189 break;
5190 }
5191 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005192 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, 0, VK_ACCESS_INPUT_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08005193 break;
5194 }
5195 case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005196 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_READ_BIT, 0, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08005197 break;
5198 }
5199 case VK_IMAGE_LAYOUT_UNDEFINED: {
5200 if (accessMask != 0) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005201 // TODO: Verify against Valid Use section spec
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005202 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005203 "Additional bits in %s accessMask %d %s are specified when layout is %s.", type, accessMask, string_VkAccessFlags(accessMask).c_str(),
5204 string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08005205 }
5206 break;
5207 }
5208 case VK_IMAGE_LAYOUT_GENERAL:
5209 default: {
5210 break;
5211 }
Michael Lentineecc32b72015-10-16 18:08:09 -05005212 }
5213 return skip_call;
5214}
5215
Jon Ashburnf19916e2016-01-11 13:12:43 -07005216VkBool32 ValidateBarriers(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const VkMemoryBarrier* pMemBarriers, uint32_t imageMemBarrierCount, const VkImageMemoryBarrier *pImageMemBarriers)
5217{
Mark Youngb20a6a82016-01-07 15:41:43 -07005218 VkBool32 skip_call = VK_FALSE;
Michael Lentine48930b82015-10-15 17:07:00 -05005219 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5220 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5221 if (pCB->activeRenderPass && memBarrierCount) {
5222 for (uint32_t i = 0; i < memBarrierCount; ++i) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005223 auto mem_barrier = &pMemBarriers[i];
Michael Lentine48930b82015-10-15 17:07:00 -05005224 if (mem_barrier && mem_barrier->sType != VK_STRUCTURE_TYPE_MEMORY_BARRIER) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005225 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
Michael Lentine48930b82015-10-15 17:07:00 -05005226 "Image or Buffers Barriers cannot be used during a render pass.");
5227 }
5228 }
5229 if (!dev_data->renderPassMap[pCB->activeRenderPass]->hasSelfDependency[pCB->activeSubpass]) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005230 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
Michael Lentine48930b82015-10-15 17:07:00 -05005231 "Barriers cannot be set during subpass %d with no self dependency specified.", pCB->activeSubpass);
5232 }
5233 }
Mark Lobodzinski73a37ec2015-11-20 09:27:27 -07005234
Jon Ashburnf19916e2016-01-11 13:12:43 -07005235 for (uint32_t i = 0; i < imageMemBarrierCount; ++i) {
5236 auto mem_barrier = &pImageMemBarriers[i];
Michael Lentineecc32b72015-10-16 18:08:09 -05005237 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005238 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, mem_barrier->srcAccessMask, mem_barrier->oldLayout, "Source");
5239 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, mem_barrier->dstAccessMask, mem_barrier->newLayout, "Dest");
Michael Lentineecc32b72015-10-16 18:08:09 -05005240 }
5241 }
Mark Lobodzinski3cba24a2015-12-03 15:42:32 -07005242
Michael Lentine48930b82015-10-15 17:07:00 -05005243 return skip_call;
5244}
5245
Jon Ashburnf19916e2016-01-11 13:12:43 -07005246VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdWaitEvents(
5247 VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent* pEvents,
5248 VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask,
5249 uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers,
5250 uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers,
5251 uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005252{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005253 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005254 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5255 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005256 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005257 for (uint32_t i = 0; i < eventCount; ++i) {
5258 pCB->waitedEvents.push_back(pEvents[i]);
5259 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005260 if (pCB->state == CB_RECORDING) {
5261 skipCall |= addCmd(dev_data, pCB, CMD_WAITEVENTS, "vkCmdWaitEvents()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005262 } else {
5263 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdWaitEvents()");
5264 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07005265 skipCall |= TransitionImageLayouts(commandBuffer, imageMemoryBarrierCount, pImageMemoryBarriers);
5266 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, pMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005267 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005268 if (VK_FALSE == skipCall)
Jon Ashburnf19916e2016-01-11 13:12:43 -07005269 dev_data->device_dispatch_table->CmdWaitEvents(commandBuffer, eventCount, pEvents, sourceStageMask, dstStageMask,
5270 memoryBarrierCount, pMemoryBarriers,
5271 bufferMemoryBarrierCount, pBufferMemoryBarriers,
5272 imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005273}
5274
Jon Ashburnf19916e2016-01-11 13:12:43 -07005275VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdPipelineBarrier(
5276 VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask,
5277 VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags,
5278 uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers,
5279 uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers,
5280 uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005281{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005282 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005283 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5284 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005285 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005286 skipCall |= addCmd(dev_data, pCB, CMD_PIPELINEBARRIER, "vkCmdPipelineBarrier()");
Jon Ashburnf19916e2016-01-11 13:12:43 -07005287 skipCall |= TransitionImageLayouts(commandBuffer, imageMemoryBarrierCount, pImageMemoryBarriers);
5288 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, pMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005289 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005290 if (VK_FALSE == skipCall)
Jon Ashburnf19916e2016-01-11 13:12:43 -07005291 dev_data->device_dispatch_table->CmdPipelineBarrier(commandBuffer, srcStageMask, dstStageMask, dependencyFlags,
5292 memoryBarrierCount, pMemoryBarriers,
5293 bufferMemoryBarrierCount, pBufferMemoryBarriers,
5294 imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005295}
5296
Chia-I Wu9ab61502015-11-06 06:42:02 +08005297VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005298{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005299 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005300 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) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005303 skipCall |= addCmd(dev_data, pCB, CMD_BEGINQUERY, "vkCmdBeginQuery()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005304 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005305 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005306 dev_data->device_dispatch_table->CmdBeginQuery(commandBuffer, queryPool, slot, flags);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005307}
5308
Chia-I Wu9ab61502015-11-06 06:42:02 +08005309VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005310{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005311 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005312 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5313 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005314 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005315 QueryObject query = {queryPool, slot};
5316 pCB->queryToStateMap[query] = 1;
Mark Lobodzinskice738852016-01-07 10:04:02 -07005317 if (pCB->state == CB_RECORDING) {
5318 skipCall |= addCmd(dev_data, pCB, CMD_ENDQUERY, "VkCmdEndQuery()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005319 } else {
5320 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdEndQuery()");
5321 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005322 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005323 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005324 dev_data->device_dispatch_table->CmdEndQuery(commandBuffer, queryPool, slot);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005325}
5326
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005327VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResetQueryPool(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005328{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005329 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005330 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5331 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005332 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005333 for (uint32_t i = 0; i < queryCount; i++) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005334 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06005335 pCB->waitedEventsBeforeQueryReset[query] = pCB->waitedEvents;
5336 pCB->queryToStateMap[query] = 0;
5337 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005338 if (pCB->state == CB_RECORDING) {
5339 skipCall |= addCmd(dev_data, pCB, CMD_RESETQUERYPOOL, "VkCmdResetQueryPool()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005340 } else {
5341 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdResetQueryPool()");
5342 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005343 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdQueryPool");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005344 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005345 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005346 dev_data->device_dispatch_table->CmdResetQueryPool(commandBuffer, queryPool, firstQuery, queryCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005347}
5348
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005349VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005350 uint32_t queryCount, VkBuffer dstBuffer, VkDeviceSize dstOffset,
Chia-I Wuccc93a72015-10-26 18:36:20 +08005351 VkDeviceSize stride, VkQueryResultFlags flags)
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005352{
5353 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005354 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5355 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005356 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005357 for (uint32_t i = 0; i < queryCount; i++) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005358 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06005359 if(!pCB->queryToStateMap[query]) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005360 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_QUERY, "DS",
Mark Young93ecb1d2016-01-13 13:47:16 -07005361 "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 -06005362 }
5363 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005364 if (pCB->state == CB_RECORDING) {
5365 skipCall |= addCmd(dev_data, pCB, CMD_COPYQUERYPOOLRESULTS, "vkCmdCopyQueryPoolResults()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005366 } else {
5367 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdCopyQueryPoolResults()");
5368 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005369 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyQueryPoolResults");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005370 }
5371 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005372 dev_data->device_dispatch_table->CmdCopyQueryPoolResults(commandBuffer, queryPool,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005373 firstQuery, queryCount, dstBuffer, dstOffset, stride, flags);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005374}
5375
Chia-I Wu9ab61502015-11-06 06:42:02 +08005376VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005377{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005378 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005379 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5380 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005381 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005382 QueryObject query = {queryPool, slot};
5383 pCB->queryToStateMap[query] = 1;
Mark Lobodzinskice738852016-01-07 10:04:02 -07005384 if (pCB->state == CB_RECORDING) {
5385 skipCall |= addCmd(dev_data, pCB, CMD_WRITETIMESTAMP, "vkCmdWriteTimestamp()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005386 } else {
5387 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdWriteTimestamp()");
5388 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005389 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005390 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005391 dev_data->device_dispatch_table->CmdWriteTimestamp(commandBuffer, pipelineStage, queryPool, slot);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005392}
5393
Chia-I Wu9ab61502015-11-06 06:42:02 +08005394VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkFramebuffer* pFramebuffer)
Tobin Ehliseba312c2015-04-01 08:40:34 -06005395{
Tobin Ehlis0b632332015-10-07 09:38:40 -06005396 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005397 VkResult result = dev_data->device_dispatch_table->CreateFramebuffer(device, pCreateInfo, pAllocator, pFramebuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005398 if (VK_SUCCESS == result) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06005399 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06005400 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +08005401 if (pCreateInfo->pAttachments) {
Courtney Goeltzenleuchter5861a1b2015-09-01 17:30:39 -06005402 localFBCI->pAttachments = new VkImageView[localFBCI->attachmentCount];
5403 memcpy((void*)localFBCI->pAttachments, pCreateInfo->pAttachments, localFBCI->attachmentCount*sizeof(VkImageView));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005404 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08005405 dev_data->frameBufferMap[*pFramebuffer] = localFBCI;
Tobin Ehliseba312c2015-04-01 08:40:34 -06005406 }
5407 return result;
5408}
5409
Michael Lentineb6986752015-10-06 14:56:18 -07005410// Store the DAG.
5411struct DAGNode {
5412 uint32_t pass;
5413 std::vector<uint32_t> prev;
5414 std::vector<uint32_t> next;
5415};
5416
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005417VkBool32 FindDependency(const int index, const int dependent, const std::vector<DAGNode>& subpass_to_node, std::unordered_set<uint32_t>& processed_nodes) {
Michael Lentineb6986752015-10-06 14:56:18 -07005418 // If we have already checked this node we have not found a dependency path so return false.
5419 if (processed_nodes.count(index))
Mark Youngb20a6a82016-01-07 15:41:43 -07005420 return VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005421 processed_nodes.insert(index);
5422 const DAGNode& node = subpass_to_node[index];
5423 // Look for a dependency path. If one exists return true else recurse on the previous nodes.
5424 if (std::find(node.prev.begin(), node.prev.end(), dependent) == node.prev.end()) {
5425 for (auto elem : node.prev) {
5426 if (FindDependency(elem, dependent, subpass_to_node, processed_nodes))
Mark Youngb20a6a82016-01-07 15:41:43 -07005427 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005428 }
5429 } else {
Mark Youngb20a6a82016-01-07 15:41:43 -07005430 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005431 }
Mark Youngb20a6a82016-01-07 15:41:43 -07005432 return VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005433}
5434
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005435VkBool32 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 -07005436 VkBool32 result = VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005437 // Loop through all subpasses that share the same attachment and make sure a dependency exists
5438 for (uint32_t k = 0; k < dependent_subpasses.size(); ++k) {
5439 if (subpass == dependent_subpasses[k])
5440 continue;
5441 const DAGNode& node = subpass_to_node[subpass];
5442 // Check for a specified dependency between the two nodes. If one exists we are done.
5443 auto prev_elem = std::find(node.prev.begin(), node.prev.end(), dependent_subpasses[k]);
5444 auto next_elem = std::find(node.next.begin(), node.next.end(), dependent_subpasses[k]);
5445 if (prev_elem == node.prev.end() && next_elem == node.next.end()) {
5446 // If no dependency exits an implicit dependency still might. If so, warn and if not throw an error.
5447 std::unordered_set<uint32_t> processed_nodes;
5448 if (FindDependency(subpass, dependent_subpasses[k], subpass_to_node, processed_nodes) ||
5449 FindDependency(dependent_subpasses[k], subpass, subpass_to_node, processed_nodes)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005450 // TODO: Verify against Valid Use section of spec
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005451 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
Michael Lentineb6986752015-10-06 14:56:18 -07005452 "A dependency between subpasses %d and %d must exist but only an implicit one is specified.",
5453 subpass, dependent_subpasses[k]);
5454 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005455 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
Michael Lentineb6986752015-10-06 14:56:18 -07005456 "A dependency between subpasses %d and %d must exist but one is not specified.",
5457 subpass, dependent_subpasses[k]);
Mark Youngb20a6a82016-01-07 15:41:43 -07005458 result = VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005459 }
5460 }
5461 }
5462 return result;
5463}
5464
Jon Ashburnf19916e2016-01-11 13:12:43 -07005465VkBool32 CheckPreserved(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, const int index, const uint32_t attachment, const std::vector<DAGNode>& subpass_to_node, int depth, VkBool32& skip_call) {
Michael Lentineb6986752015-10-06 14:56:18 -07005466 const DAGNode& node = subpass_to_node[index];
5467 // If this node writes to the attachment return true as next nodes need to preserve the attachment.
5468 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005469 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005470 if (attachment == subpass.pColorAttachments[j].attachment)
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005471 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005472 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005473 if (subpass.pDepthStencilAttachment &&
5474 subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
5475 if (attachment == subpass.pDepthStencilAttachment->attachment)
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005476 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005477 }
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005478 VkBool32 result = VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005479 // Loop through previous nodes and see if any of them write to the attachment.
5480 for (auto elem : node.prev) {
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005481 result |= CheckPreserved(my_data, device, pCreateInfo, elem, attachment, subpass_to_node, depth + 1, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005482 }
5483 // If the attachment was written to by a previous node than this node needs to preserve it.
5484 if (result && depth > 0) {
5485 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Mark Youngb20a6a82016-01-07 15:41:43 -07005486 VkBool32 has_preserved = VK_FALSE;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005487 for (uint32_t j = 0; j < subpass.preserveAttachmentCount; ++j) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005488 if (subpass.pPreserveAttachments[j] == attachment) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005489 has_preserved = VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005490 break;
5491 }
5492 }
Mark Youngb20a6a82016-01-07 15:41:43 -07005493 if (has_preserved == VK_FALSE) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005494 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
Michael Lentineb6986752015-10-06 14:56:18 -07005495 "Attachment %d is used by a later subpass and must be preserved in subpass %d.", attachment, index);
5496 }
5497 }
5498 return result;
5499}
5500
Michael Lentineb4979492015-12-22 11:36:14 -06005501VkBool32 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 -07005502 VkBool32 skip_call = VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005503 std::vector<std::vector<uint32_t>> output_attachment_to_subpass(pCreateInfo->attachmentCount);
5504 std::vector<std::vector<uint32_t>> input_attachment_to_subpass(pCreateInfo->attachmentCount);
Michael Lentineb6986752015-10-06 14:56:18 -07005505 // Find for each attachment the subpasses that use them.
5506 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5507 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005508 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005509 input_attachment_to_subpass[subpass.pInputAttachments[j].attachment].push_back(i);
5510 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08005511 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005512 output_attachment_to_subpass[subpass.pColorAttachments[j].attachment].push_back(i);
5513 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005514 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
5515 output_attachment_to_subpass[subpass.pDepthStencilAttachment->attachment].push_back(i);
Michael Lentineb6986752015-10-06 14:56:18 -07005516 }
5517 }
5518 // If there is a dependency needed make sure one exists
5519 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5520 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
5521 // If the attachment is an input then all subpasses that output must have a dependency relationship
Chia-I Wud50a7d72015-10-26 20:48:51 +08005522 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005523 const uint32_t& attachment = subpass.pInputAttachments[j].attachment;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005524 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005525 }
5526 // 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 +08005527 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005528 const uint32_t& attachment = subpass.pColorAttachments[j].attachment;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005529 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
5530 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005531 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005532 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
5533 const uint32_t& attachment = subpass.pDepthStencilAttachment->attachment;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005534 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
5535 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005536 }
5537 }
5538 // Loop through implicit dependencies, if this pass reads make sure the attachment is preserved for all passes after it was written.
5539 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5540 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005541 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005542 CheckPreserved(my_data, device, pCreateInfo, i, subpass.pInputAttachments[j].attachment, subpass_to_node, 0, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005543 }
5544 }
5545 return skip_call;
5546}
5547
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005548VkBool32 ValidateLayouts(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005549 VkBool32 skip = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005550
5551#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
5552 return skip;
5553#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5554
Michael Lentineabc5e922015-10-12 11:30:14 -05005555 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5556 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
5557 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
5558 if (subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL &&
5559 subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) {
5560 if (subpass.pInputAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005561 // TODO: Verify Valid Use in spec. I believe this is allowed (valid) but may not be optimal performance
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005562 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05005563 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
5564 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005565 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05005566 "Layout for input attachment is %d but can only be READ_ONLY_OPTIMAL or GENERAL.", subpass.pInputAttachments[j].attachment);
5567 }
5568 }
5569 }
5570 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
5571 if (subpass.pColorAttachments[j].layout != VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) {
5572 if (subpass.pColorAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005573 // TODO: Verify Valid Use in spec. I believe this is allowed (valid) but may not be optimal performance
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005574 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05005575 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
5576 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005577 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05005578 "Layout for color attachment is %d but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.", subpass.pColorAttachments[j].attachment);
5579 }
5580 }
5581 }
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005582 if ((subpass.pDepthStencilAttachment != NULL) &&
5583 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
Michael Lentineabc5e922015-10-12 11:30:14 -05005584 if (subpass.pDepthStencilAttachment->layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) {
5585 if (subpass.pDepthStencilAttachment->layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005586 // TODO: Verify Valid Use in spec. I believe this is allowed (valid) but may not be optimal performance
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005587 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05005588 "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL.");
5589 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005590 skip |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05005591 "Layout for depth attachment is %d but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL.", subpass.pDepthStencilAttachment->attachment);
5592 }
5593 }
5594 }
5595 }
5596 return skip;
5597}
5598
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005599VkBool32 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 -07005600 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05005601 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5602 DAGNode& subpass_node = subpass_to_node[i];
5603 subpass_node.pass = i;
5604 }
5605 for (uint32_t i = 0; i < pCreateInfo->dependencyCount; ++i) {
5606 const VkSubpassDependency& dependency = pCreateInfo->pDependencies[i];
Michael Lentine6bd4f122016-01-19 14:00:53 -06005607 if (dependency.srcSubpass > dependency.dstSubpass && dependency.srcSubpass != VK_SUBPASS_EXTERNAL && dependency.dstSubpass != VK_SUBPASS_EXTERNAL) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005608 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05005609 "Depedency graph must be specified such that an earlier pass cannot depend on a later pass.");
Michael Lentine6bd4f122016-01-19 14:00:53 -06005610 } else if (dependency.srcSubpass == VK_SUBPASS_EXTERNAL && dependency.dstSubpass == VK_SUBPASS_EXTERNAL) {
5611 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
5612 "The src and dest subpasses cannot both be external.");
Michael Lentine48930b82015-10-15 17:07:00 -05005613 } else if (dependency.srcSubpass == dependency.dstSubpass) {
5614 has_self_dependency[dependency.srcSubpass] = true;
Michael Lentineabc5e922015-10-12 11:30:14 -05005615 }
Michael Lentine6bd4f122016-01-19 14:00:53 -06005616 if (dependency.dstSubpass != VK_SUBPASS_EXTERNAL) {
5617 subpass_to_node[dependency.dstSubpass].prev.push_back(dependency.srcSubpass);
5618 }
5619 if (dependency.srcSubpass != VK_SUBPASS_EXTERNAL) {
5620 subpass_to_node[dependency.srcSubpass].next.push_back(dependency.dstSubpass);
5621 }
Michael Lentineabc5e922015-10-12 11:30:14 -05005622 }
5623 return skip_call;
5624}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005625// TODOSC : Add intercept of vkCreateShaderModule
Michael Lentineabc5e922015-10-12 11:30:14 -05005626
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005627VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateShaderModule(
5628 VkDevice device,
5629 const VkShaderModuleCreateInfo *pCreateInfo,
5630 const VkAllocationCallbacks* pAllocator,
5631 VkShaderModule *pShaderModule)
5632{
5633 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07005634 VkBool32 skip_call = VK_FALSE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005635 if (!shader_is_spirv(pCreateInfo)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005636 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005637 /* dev */ 0, __LINE__, SHADER_CHECKER_NON_SPIRV_SHADER, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005638 "Shader is not SPIR-V");
5639 }
5640
Mark Youngb20a6a82016-01-07 15:41:43 -07005641 if (VK_FALSE != skip_call)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005642 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005643
5644 VkResult res = my_data->device_dispatch_table->CreateShaderModule(device, pCreateInfo, pAllocator, pShaderModule);
5645
5646 if (res == VK_SUCCESS) {
5647 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005648 my_data->shaderModuleMap[*pShaderModule] = new shader_module(pCreateInfo);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005649 loader_platform_thread_unlock_mutex(&globalLock);
5650 }
5651 return res;
5652}
5653
Chia-I Wu9ab61502015-11-06 06:42:02 +08005654VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkRenderPass* pRenderPass)
Tobin Ehliseba312c2015-04-01 08:40:34 -06005655{
Mark Youngb20a6a82016-01-07 15:41:43 -07005656 VkBool32 skip_call = VK_FALSE;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005657 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentineabc5e922015-10-12 11:30:14 -05005658 // Create DAG
Michael Lentine48930b82015-10-15 17:07:00 -05005659 std::vector<bool> has_self_dependency(pCreateInfo->subpassCount);
Michael Lentineabc5e922015-10-12 11:30:14 -05005660 std::vector<DAGNode> subpass_to_node(pCreateInfo->subpassCount);
Michael Lentine48930b82015-10-15 17:07:00 -05005661 skip_call |= CreatePassDAG(dev_data, device, pCreateInfo, subpass_to_node, has_self_dependency);
Michael Lentineabc5e922015-10-12 11:30:14 -05005662 // Validate using DAG
5663 skip_call |= ValidateDependencies(dev_data, device, pCreateInfo, subpass_to_node);
5664 skip_call |= ValidateLayouts(dev_data, device, pCreateInfo);
Mark Youngb20a6a82016-01-07 15:41:43 -07005665 if (VK_FALSE != skip_call) {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005666 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentineb6986752015-10-06 14:56:18 -07005667 }
Chia-I Wuf7458c52015-10-26 21:10:41 +08005668 VkResult result = dev_data->device_dispatch_table->CreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005669 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005670 // TODOSC : Merge in tracking of renderpass from ShaderChecker
Tobin Ehliseba312c2015-04-01 08:40:34 -06005671 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06005672 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +08005673 if (pCreateInfo->pAttachments) {
5674 localRPCI->pAttachments = new VkAttachmentDescription[localRPCI->attachmentCount];
5675 memcpy((void*)localRPCI->pAttachments, pCreateInfo->pAttachments, localRPCI->attachmentCount*sizeof(VkAttachmentDescription));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005676 }
Chia-I Wu08accc62015-07-07 11:50:03 +08005677 if (pCreateInfo->pSubpasses) {
5678 localRPCI->pSubpasses = new VkSubpassDescription[localRPCI->subpassCount];
5679 memcpy((void*)localRPCI->pSubpasses, pCreateInfo->pSubpasses, localRPCI->subpassCount*sizeof(VkSubpassDescription));
5680
5681 for (uint32_t i = 0; i < localRPCI->subpassCount; i++) {
5682 VkSubpassDescription *subpass = (VkSubpassDescription *) &localRPCI->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005683 const uint32_t attachmentCount = subpass->inputAttachmentCount +
5684 subpass->colorAttachmentCount * (1 + (subpass->pResolveAttachments?1:0)) +
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005685 ((subpass->pDepthStencilAttachment) ? 1 : 0) + subpass->preserveAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005686 VkAttachmentReference *attachments = new VkAttachmentReference[attachmentCount];
5687
Cody Northropa505dda2015-08-04 11:16:41 -06005688 memcpy(attachments, subpass->pInputAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005689 sizeof(attachments[0]) * subpass->inputAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005690 subpass->pInputAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005691 attachments += subpass->inputAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005692
Cody Northropa505dda2015-08-04 11:16:41 -06005693 memcpy(attachments, subpass->pColorAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005694 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005695 subpass->pColorAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005696 attachments += subpass->colorAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005697
Cody Northropa505dda2015-08-04 11:16:41 -06005698 if (subpass->pResolveAttachments) {
5699 memcpy(attachments, subpass->pResolveAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005700 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005701 subpass->pResolveAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005702 attachments += subpass->colorAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005703 }
5704
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005705 if (subpass->pDepthStencilAttachment) {
5706 memcpy(attachments, subpass->pDepthStencilAttachment,
5707 sizeof(attachments[0]) * 1);
5708 subpass->pDepthStencilAttachment = attachments;
5709 attachments += 1;
5710 }
5711
Cody Northropa505dda2015-08-04 11:16:41 -06005712 memcpy(attachments, subpass->pPreserveAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005713 sizeof(attachments[0]) * subpass->preserveAttachmentCount);
Jon Ashburnf19916e2016-01-11 13:12:43 -07005714 subpass->pPreserveAttachments = &attachments->attachment;
Chia-I Wu08accc62015-07-07 11:50:03 +08005715 }
Tobin Ehliseba312c2015-04-01 08:40:34 -06005716 }
Chia-I Wu08accc62015-07-07 11:50:03 +08005717 if (pCreateInfo->pDependencies) {
5718 localRPCI->pDependencies = new VkSubpassDependency[localRPCI->dependencyCount];
5719 memcpy((void*)localRPCI->pDependencies, pCreateInfo->pDependencies, localRPCI->dependencyCount*sizeof(VkSubpassDependency));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005720 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005721 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005722 dev_data->renderPassMap[*pRenderPass] = new RENDER_PASS_NODE(localRPCI);
Michael Lentine48930b82015-10-15 17:07:00 -05005723 dev_data->renderPassMap[*pRenderPass]->hasSelfDependency = has_self_dependency;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005724 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehliseba312c2015-04-01 08:40:34 -06005725 }
5726 return result;
5727}
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005728// Free the renderpass shadow
5729static void deleteRenderPasses(layer_data* my_data)
5730{
5731 if (my_data->renderPassMap.size() <= 0)
5732 return;
5733 for (auto ii=my_data->renderPassMap.begin(); ii!=my_data->renderPassMap.end(); ++ii) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005734 const VkRenderPassCreateInfo* pRenderPassInfo = (*ii).second->pCreateInfo;
Michael Lentine48930b82015-10-15 17:07:00 -05005735 if (pRenderPassInfo->pAttachments) {
5736 delete[] pRenderPassInfo->pAttachments;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005737 }
Michael Lentine48930b82015-10-15 17:07:00 -05005738 if (pRenderPassInfo->pSubpasses) {
5739 for (uint32_t i=0; i<pRenderPassInfo->subpassCount; ++i) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005740 // Attachements are all allocated in a block, so just need to
5741 // find the first non-null one to delete
Michael Lentine48930b82015-10-15 17:07:00 -05005742 if (pRenderPassInfo->pSubpasses[i].pInputAttachments) {
5743 delete[] pRenderPassInfo->pSubpasses[i].pInputAttachments;
5744 } else if (pRenderPassInfo->pSubpasses[i].pColorAttachments) {
5745 delete[] pRenderPassInfo->pSubpasses[i].pColorAttachments;
5746 } else if (pRenderPassInfo->pSubpasses[i].pResolveAttachments) {
5747 delete[] pRenderPassInfo->pSubpasses[i].pResolveAttachments;
5748 } else if (pRenderPassInfo->pSubpasses[i].pPreserveAttachments) {
5749 delete[] pRenderPassInfo->pSubpasses[i].pPreserveAttachments;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005750 }
5751 }
Michael Lentine48930b82015-10-15 17:07:00 -05005752 delete[] pRenderPassInfo->pSubpasses;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005753 }
Michael Lentine48930b82015-10-15 17:07:00 -05005754 if (pRenderPassInfo->pDependencies) {
5755 delete[] pRenderPassInfo->pDependencies;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005756 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005757 delete pRenderPassInfo;
Michael Lentine48930b82015-10-15 17:07:00 -05005758 delete (*ii).second;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005759 }
5760 my_data->renderPassMap.clear();
5761}
Michael Lentineabc5e922015-10-12 11:30:14 -05005762
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005763VkBool32 VerifyFramebufferAndRenderPassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005764 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05005765 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5766 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005767 const VkRenderPassCreateInfo* pRenderPassInfo = dev_data->renderPassMap[pRenderPassBegin->renderPass]->pCreateInfo;
Michael Lentineabc5e922015-10-12 11:30:14 -05005768 const VkFramebufferCreateInfo* pFramebufferInfo = dev_data->frameBufferMap[pRenderPassBegin->framebuffer];
5769 if (pRenderPassInfo->attachmentCount != pFramebufferInfo->attachmentCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005770 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05005771 "You cannot start a render pass using a framebuffer with a different number of attachments.");
5772 }
5773 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
5774 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
5775 const VkImage& image = dev_data->imageViewMap[image_view]->image;
5776 auto image_data = pCB->imageLayoutMap.find(image);
5777 if (image_data == pCB->imageLayoutMap.end()) {
5778 pCB->imageLayoutMap[image].initialLayout = pRenderPassInfo->pAttachments[i].initialLayout;
5779 pCB->imageLayoutMap[image].layout = pRenderPassInfo->pAttachments[i].initialLayout;
5780 } else if (pRenderPassInfo->pAttachments[i].initialLayout != image_data->second.layout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005781 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05005782 "You cannot start a render pass using attachment %i where the intial layout differs from the starting layout.", i);
5783 }
5784 }
5785 return skip_call;
5786}
5787
5788void TransitionSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, const int subpass_index) {
5789 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5790 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5791 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
5792 if (render_pass_data == dev_data->renderPassMap.end()) {
5793 return;
5794 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005795 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
Michael Lentineabc5e922015-10-12 11:30:14 -05005796 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
5797 if (framebuffer_data == dev_data->frameBufferMap.end()) {
5798 return;
5799 }
5800 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
5801 const VkSubpassDescription& subpass = pRenderPassInfo->pSubpasses[subpass_index];
5802 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
5803 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pInputAttachments[j].attachment];
5804 auto image_view_data = dev_data->imageViewMap.find(image_view);
5805 if (image_view_data != dev_data->imageViewMap.end()) {
5806 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5807 if (image_layout != pCB->imageLayoutMap.end()) {
5808 image_layout->second.layout = subpass.pInputAttachments[j].layout;
5809 }
5810 }
5811 }
5812 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
5813 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pColorAttachments[j].attachment];
5814 auto image_view_data = dev_data->imageViewMap.find(image_view);
5815 if (image_view_data != dev_data->imageViewMap.end()) {
5816 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5817 if (image_layout != pCB->imageLayoutMap.end()) {
5818 image_layout->second.layout = subpass.pColorAttachments[j].layout;
5819 }
5820 }
5821 }
Michael Lentine3dea6512015-10-28 15:55:18 -07005822 if ((subpass.pDepthStencilAttachment != NULL) &&
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005823 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
Michael Lentineabc5e922015-10-12 11:30:14 -05005824 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pDepthStencilAttachment->attachment];
5825 auto image_view_data = dev_data->imageViewMap.find(image_view);
5826 if (image_view_data != dev_data->imageViewMap.end()) {
5827 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5828 if (image_layout != pCB->imageLayoutMap.end()) {
5829 image_layout->second.layout = subpass.pDepthStencilAttachment->layout;
5830 }
5831 }
5832 }
5833}
5834
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005835VkBool32 validatePrimaryCommandBuffer(const layer_data* my_data, const GLOBAL_CB_NODE* pCB, const std::string& cmd_name) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005836 VkBool32 skip_call = VK_FALSE;
Michael Lentine3dea6512015-10-28 15:55:18 -07005837 if (pCB->createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005838 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER, "DS",
Michael Lentine3dea6512015-10-28 15:55:18 -07005839 "Cannot execute command %s on a secondary command buffer.", cmd_name.c_str());
5840 }
5841 return skip_call;
5842}
5843
Michael Lentineabc5e922015-10-12 11:30:14 -05005844void TransitionFinalSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
5845 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5846 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5847 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
5848 if (render_pass_data == dev_data->renderPassMap.end()) {
5849 return;
5850 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005851 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
Michael Lentineabc5e922015-10-12 11:30:14 -05005852 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
5853 if (framebuffer_data == dev_data->frameBufferMap.end()) {
5854 return;
5855 }
5856 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
5857 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
5858 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
5859 auto image_view_data = dev_data->imageViewMap.find(image_view);
5860 if (image_view_data != dev_data->imageViewMap.end()) {
5861 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5862 if (image_layout != pCB->imageLayoutMap.end()) {
5863 image_layout->second.layout = pRenderPassInfo->pAttachments[i].finalLayout;
5864 }
5865 }
5866 }
5867}
5868
Chia-I Wu9ab61502015-11-06 06:42:02 +08005869VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, VkSubpassContents contents)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005870{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005871 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005872 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5873 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005874 if (pCB) {
Tobin Ehlis259730a2015-06-23 16:13:03 -06005875 if (pRenderPassBegin && pRenderPassBegin->renderPass) {
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005876 skipCall |= VerifyFramebufferAndRenderPassLayouts(commandBuffer, pRenderPassBegin);
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005877 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBeginRenderPass");
Michael Lentine3dea6512015-10-28 15:55:18 -07005878 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdBeginRenderPass");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005879 skipCall |= addCmd(dev_data, pCB, CMD_BEGINRENDERPASS, "vkCmdBeginRenderPass()");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005880 pCB->activeRenderPass = pRenderPassBegin->renderPass;
Michael Lentineabc5e922015-10-12 11:30:14 -05005881 // This is a shallow copy as that is all that is needed for now
5882 pCB->activeRenderPassBeginInfo = *pRenderPassBegin;
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005883 pCB->activeSubpass = 0;
Michael Lentine2e068b22015-12-29 16:05:27 -06005884 pCB->activeSubpassContents = contents;
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005885 pCB->framebuffer = pRenderPassBegin->framebuffer;
Tobin Ehlis502480b2015-06-24 15:53:07 -06005886 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005887 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
Tobin Ehlis259730a2015-06-23 16:13:03 -06005888 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tony Barbourbadda992015-04-06 11:09:26 -06005889 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005890 }
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005891 if (VK_FALSE == skipCall) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005892 dev_data->device_dispatch_table->CmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents);
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005893 // This is a shallow copy as that is all that is needed for now
5894 dev_data->renderPassBeginInfo = *pRenderPassBegin;
5895 dev_data->currentSubpass = 0;
5896 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005897}
5898
Chia-I Wu9ab61502015-11-06 06:42:02 +08005899VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents)
Chia-I Wu08accc62015-07-07 11:50:03 +08005900{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005901 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005902 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5903 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Michael Lentineabc5e922015-10-12 11:30:14 -05005904 TransitionSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo, ++dev_data->currentSubpass);
Chia-I Wu08accc62015-07-07 11:50:03 +08005905 if (pCB) {
Michael Lentine3dea6512015-10-28 15:55:18 -07005906 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdNextSubpass");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005907 skipCall |= addCmd(dev_data, pCB, CMD_NEXTSUBPASS, "vkCmdNextSubpass()");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005908 pCB->activeSubpass++;
Michael Lentine2e068b22015-12-29 16:05:27 -06005909 pCB->activeSubpassContents = contents;
Tony Barbourfc5bb6f2016-01-12 11:16:52 -07005910 TransitionSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo, pCB->activeSubpass);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005911 if (pCB->lastBoundPipeline) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005912 skipCall |= validatePipelineState(dev_data, pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Chia-I Wu08accc62015-07-07 11:50:03 +08005913 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005914 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdNextSubpass");
Chia-I Wu08accc62015-07-07 11:50:03 +08005915 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005916 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005917 dev_data->device_dispatch_table->CmdNextSubpass(commandBuffer, contents);
Chia-I Wu08accc62015-07-07 11:50:03 +08005918}
5919
Chia-I Wu9ab61502015-11-06 06:42:02 +08005920VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndRenderPass(VkCommandBuffer commandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005921{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005922 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005923 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5924 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Michael Lentineabc5e922015-10-12 11:30:14 -05005925 TransitionFinalSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005926 if (pCB) {
Michael Lentine3dea6512015-10-28 15:55:18 -07005927 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdEndRenderpass");
Michael Lentine3dea6512015-10-28 15:55:18 -07005928 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdEndRenderPass");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005929 skipCall |= addCmd(dev_data, pCB, CMD_ENDRENDERPASS, "vkCmdEndRenderPass()");
Michael Lentineabc5e922015-10-12 11:30:14 -05005930 TransitionFinalSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005931 pCB->activeRenderPass = 0;
5932 pCB->activeSubpass = 0;
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005933 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005934 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005935 dev_data->device_dispatch_table->CmdEndRenderPass(commandBuffer);
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005936}
5937
Chia-I Wu9ab61502015-11-06 06:42:02 +08005938VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount, const VkCommandBuffer* pCommandBuffers)
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005939{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005940 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005941 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5942 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005943 if (pCB) {
Tobin Ehlis651d9b02015-12-16 05:01:22 -07005944 // TODO : If secondary CB was not created w/ *_USAGE_SIMULTANEOUS_USE_BIT it cannot be used more than once in given primary CB
5945 // ALSO if secondary w/o this flag is set in primary, then primary must not be pending execution more than once at a time
5946 // If not w/ SIMULTANEOUS bit, then any other references to those 2ndary CBs are invalidated, should warn on that case
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06005947 GLOBAL_CB_NODE* pSubCB = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005948 for (uint32_t i=0; i<commandBuffersCount; i++) {
5949 pSubCB = getCBNode(dev_data, pCommandBuffers[i]);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06005950 if (!pSubCB) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005951 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_SECONDARY_COMMAND_BUFFER, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005952 "vkCmdExecuteCommands() called w/ invalid Cmd Buffer %p in element %u of pCommandBuffers array.", (void*)pCommandBuffers[i], i);
5953 } else if (VK_COMMAND_BUFFER_LEVEL_PRIMARY == pSubCB->createInfo.level) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005954 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_SECONDARY_COMMAND_BUFFER, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005955 "vkCmdExecuteCommands() called w/ Primary Cmd Buffer %p in element %u of pCommandBuffers array. All cmd buffers in pCommandBuffers array must be secondary.", (void*)pCommandBuffers[i], i);
Tobin Ehlis651d9b02015-12-16 05:01:22 -07005956 } else if (pCB->activeRenderPass) { // Secondary CB w/i RenderPass must have *CONTINUE_BIT set
5957 if (!(pSubCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005958 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)pCommandBuffers[i], __LINE__, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
Tobin Ehlis651d9b02015-12-16 05:01:22 -07005959 "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);
5960 }
5961 string errorString = "";
Jon Ashburnf19916e2016-01-11 13:12:43 -07005962 if (!verify_renderpass_compatibility(dev_data, pCB->activeRenderPass, pSubCB->beginInfo.pInheritanceInfo->renderPass, errorString)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005963 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)pCommandBuffers[i], __LINE__, DRAWSTATE_RENDERPASS_INCOMPATIBLE, "DS",
Tobin Ehlis651d9b02015-12-16 05:01:22 -07005964 "vkCmdExecuteCommands(): Secondary Command Buffer (%p) w/ render pass (%#" PRIxLEAST64 ") is incompatible w/ primary command buffer (%p) w/ render pass (%#" PRIxLEAST64 ") due to: %s",
Jon Ashburnf19916e2016-01-11 13:12:43 -07005965 (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 -07005966 }
5967 // If framebuffer for secondary CB is not NULL, then it must match FB from vkCmdBeginRenderPass()
5968 // 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 -07005969 if (pSubCB->beginInfo.pInheritanceInfo->framebuffer) {
5970 if (pSubCB->beginInfo.pInheritanceInfo->framebuffer != pCB->activeRenderPassBeginInfo.framebuffer) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005971 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)pCommandBuffers[i], __LINE__, DRAWSTATE_FRAMEBUFFER_INCOMPATIBLE, "DS",
Tobin Ehlis651d9b02015-12-16 05:01:22 -07005972 "vkCmdExecuteCommands(): Secondary Command Buffer (%p) references framebuffer (%#" PRIxLEAST64 ") that does not match framebuffer (%#" PRIxLEAST64 ") in active renderpass (%#" PRIxLEAST64 ").",
Jon Ashburnf19916e2016-01-11 13:12:43 -07005973 (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 -07005974 }
5975 }
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06005976 }
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07005977 // Secondary cmdBuffers are considered pending execution starting w/ being recorded
5978 if (!(pSubCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT)) {
5979 if (dev_data->inFlightCmdBuffers.find(pSubCB->commandBuffer) != dev_data->inFlightCmdBuffers.end()) {
Mark Youngee3f3a22016-01-25 12:18:32 -07005980 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",
5981 "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 -07005982 }
5983 if (pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT) {
5984 // Warn that non-simultaneous secondary cmd buffer renders primary non-simultaneous
Mark Youngee3f3a22016-01-25 12:18:32 -07005985 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)(pCommandBuffers[i]), __LINE__, DRAWSTATE_INVALID_CB_SIMULTANEOUS_USE, "DS",
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07005986 "vkCmdExecuteCommands(): Secondary Command Buffer (%#" PRIxLEAST64 ") does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and will cause primary command buffer (%#" PRIxLEAST64 ") to be treated as if it does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set, even though it does.",
Mark Youngee3f3a22016-01-25 12:18:32 -07005987 (uint64_t)(pCommandBuffers[i]), (uint64_t)(pCB->commandBuffer));
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07005988 pCB->beginInfo.flags &= ~VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
5989 }
5990 }
5991 pCB->secondaryCommandBuffers.insert(pSubCB->commandBuffer);
5992 dev_data->inFlightCmdBuffers.insert(pSubCB->commandBuffer);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06005993 }
Michael Lentine3dea6512015-10-28 15:55:18 -07005994 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdExecuteComands");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005995 skipCall |= addCmd(dev_data, pCB, CMD_EXECUTECOMMANDS, "vkCmdExecuteComands()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005996 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005997 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005998 dev_data->device_dispatch_table->CmdExecuteCommands(commandBuffer, commandBuffersCount, pCommandBuffers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005999}
6000
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07006001VkBool32 ValidateMapImageLayouts(VkDevice device, VkDeviceMemory mem) {
Mark Youngb20a6a82016-01-07 15:41:43 -07006002 VkBool32 skip_call = VK_FALSE;
Michael Lentine7b236262015-10-23 12:41:44 -07006003 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6004 auto mem_data = dev_data->memImageMap.find(mem);
6005 if (mem_data != dev_data->memImageMap.end()) {
6006 auto image_data = dev_data->imageLayoutMap.find(mem_data->second);
6007 if (image_data != dev_data->imageLayoutMap.end()) {
6008 if (image_data->second->layout != VK_IMAGE_LAYOUT_PREINITIALIZED && image_data->second->layout != VK_IMAGE_LAYOUT_GENERAL) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07006009 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentine7b236262015-10-23 12:41:44 -07006010 "Cannot map an image with layout %d. Only GENERAL or PREINITIALIZED are supported.", image_data->second->layout);
6011 }
6012 }
6013 }
6014 return skip_call;
6015}
6016
Chia-I Wu9ab61502015-11-06 06:42:02 +08006017VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkMapMemory(
Michael Lentine7b236262015-10-23 12:41:44 -07006018 VkDevice device,
6019 VkDeviceMemory mem,
6020 VkDeviceSize offset,
6021 VkDeviceSize size,
6022 VkFlags flags,
6023 void **ppData)
6024{
6025 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006026
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07006027 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006028#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
6029 skip_call = ValidateMapImageLayouts(device, mem);
6030#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
6031
Michael Lentine7b236262015-10-23 12:41:44 -07006032 if (VK_FALSE == skip_call) {
6033 return dev_data->device_dispatch_table->MapMemory(device, mem, offset, size, flags, ppData);
6034 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07006035 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine7b236262015-10-23 12:41:44 -07006036}
6037
Chia-I Wu9ab61502015-11-06 06:42:02 +08006038VKAPI_ATTR VkResult VKAPI_CALL vkBindImageMemory(
Michael Lentine7b236262015-10-23 12:41:44 -07006039 VkDevice device,
6040 VkImage image,
6041 VkDeviceMemory mem,
6042 VkDeviceSize memOffset)
6043{
6044 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6045 VkResult result = dev_data->device_dispatch_table->BindImageMemory(device, image, mem, memOffset);
6046 loader_platform_thread_lock_mutex(&globalLock);
6047 dev_data->memImageMap[mem] = image;
6048 loader_platform_thread_unlock_mutex(&globalLock);
6049 return result;
6050}
6051
Michael Lentineb887b0a2015-12-29 14:12:11 -06006052
6053VKAPI_ATTR VkResult VKAPI_CALL vkSetEvent(VkDevice device, VkEvent event) {
6054 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6055 dev_data->eventMap[event].needsSignaled = false;
6056 VkResult result = dev_data->device_dispatch_table->SetEvent(device, event);
6057 return result;
6058}
6059
Michael Lentine15a47882016-01-06 10:05:48 -06006060VKAPI_ATTR VkResult VKAPI_CALL vkQueueBindSparse(
6061 VkQueue queue,
6062 uint32_t bindInfoCount,
6063 const VkBindSparseInfo* pBindInfo,
6064 VkFence fence)
6065{
6066 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07006067 VkBool32 skip_call = VK_FALSE;
Michael Lentine15a47882016-01-06 10:05:48 -06006068
6069 for (uint32_t bindIdx=0; bindIdx < bindInfoCount; ++bindIdx) {
6070 const VkBindSparseInfo& bindInfo = pBindInfo[bindIdx];
6071 for (uint32_t i=0; i < bindInfo.waitSemaphoreCount; ++i) {
6072 if (dev_data->semaphoreSignaledMap[bindInfo.pWaitSemaphores[i]]) {
6073 dev_data->semaphoreSignaledMap[bindInfo.pWaitSemaphores[i]] = 0;
6074 } else {
6075 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",
6076 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
Mark Youngee3f3a22016-01-25 12:18:32 -07006077 (uint64_t)(queue), (uint64_t)(bindInfo.pWaitSemaphores[i]));
Michael Lentine15a47882016-01-06 10:05:48 -06006078 }
6079 }
6080 for (uint32_t i=0; i < bindInfo.signalSemaphoreCount; ++i) {
6081 dev_data->semaphoreSignaledMap[bindInfo.pSignalSemaphores[i]] = 1;
6082 }
6083 }
6084
Mark Youngb20a6a82016-01-07 15:41:43 -07006085 if (VK_FALSE == skip_call)
Michael Lentine15a47882016-01-06 10:05:48 -06006086 return dev_data->device_dispatch_table->QueueBindSparse(queue, bindInfoCount, pBindInfo, fence);
Mark Youngb20a6a82016-01-07 15:41:43 -07006087 else
6088 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine15a47882016-01-06 10:05:48 -06006089}
6090
6091VKAPI_ATTR VkResult VKAPI_CALL vkCreateSemaphore(
6092 VkDevice device,
6093 const VkSemaphoreCreateInfo* pCreateInfo,
6094 const VkAllocationCallbacks* pAllocator,
6095 VkSemaphore* pSemaphore)
6096{
6097 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6098 VkResult result = dev_data->device_dispatch_table->CreateSemaphore(device, pCreateInfo, pAllocator, pSemaphore);
6099 if (result == VK_SUCCESS) {
6100 dev_data->semaphoreSignaledMap[*pSemaphore] = 0;
6101 }
Tobin Ehlis51b78af2016-01-06 10:27:47 -07006102 return result;
Michael Lentine15a47882016-01-06 10:05:48 -06006103}
6104
Chia-I Wu9ab61502015-11-06 06:42:02 +08006105VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(
Michael Lentineabc5e922015-10-12 11:30:14 -05006106 VkDevice device,
6107 const VkSwapchainCreateInfoKHR *pCreateInfo,
Ian Elliott05846062015-11-20 14:13:17 -07006108 const VkAllocationCallbacks *pAllocator,
Michael Lentineabc5e922015-10-12 11:30:14 -05006109 VkSwapchainKHR *pSwapchain)
6110{
6111 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott05846062015-11-20 14:13:17 -07006112 VkResult result = dev_data->device_dispatch_table->CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
Michael Lentineabc5e922015-10-12 11:30:14 -05006113
6114 if (VK_SUCCESS == result) {
Tobin Ehlis75cd1c52016-01-21 10:21:04 -07006115 SWAPCHAIN_NODE *swapchain_data = new SWAPCHAIN_NODE(pCreateInfo);
Michael Lentineabc5e922015-10-12 11:30:14 -05006116 loader_platform_thread_lock_mutex(&globalLock);
6117 dev_data->device_extensions.swapchainMap[*pSwapchain] = swapchain_data;
6118 loader_platform_thread_unlock_mutex(&globalLock);
6119 }
6120
6121 return result;
6122}
6123
Ian Elliott05846062015-11-20 14:13:17 -07006124VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR(
Michael Lentineabc5e922015-10-12 11:30:14 -05006125 VkDevice device,
Ian Elliott05846062015-11-20 14:13:17 -07006126 VkSwapchainKHR swapchain,
6127 const VkAllocationCallbacks *pAllocator)
Michael Lentineabc5e922015-10-12 11:30:14 -05006128{
6129 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentineabc5e922015-10-12 11:30:14 -05006130
6131 loader_platform_thread_lock_mutex(&globalLock);
6132 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(swapchain);
6133 if (swapchain_data != dev_data->device_extensions.swapchainMap.end()) {
6134 if (swapchain_data->second->images.size() > 0) {
6135 for (auto swapchain_image : swapchain_data->second->images) {
6136 auto image_item = dev_data->imageLayoutMap.find(swapchain_image);
6137 if (image_item != dev_data->imageLayoutMap.end())
6138 dev_data->imageLayoutMap.erase(image_item);
6139 }
6140 }
6141 delete swapchain_data->second;
6142 dev_data->device_extensions.swapchainMap.erase(swapchain);
6143 }
6144 loader_platform_thread_unlock_mutex(&globalLock);
Ian Elliott05846062015-11-20 14:13:17 -07006145 return dev_data->device_dispatch_table->DestroySwapchainKHR(device, swapchain, pAllocator);
Michael Lentineabc5e922015-10-12 11:30:14 -05006146}
6147
Chia-I Wu9ab61502015-11-06 06:42:02 +08006148VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR(
Michael Lentineabc5e922015-10-12 11:30:14 -05006149 VkDevice device,
6150 VkSwapchainKHR swapchain,
6151 uint32_t* pCount,
6152 VkImage* pSwapchainImages)
6153{
6154 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6155 VkResult result = dev_data->device_dispatch_table->GetSwapchainImagesKHR(device, swapchain, pCount, pSwapchainImages);
6156
6157 if (result == VK_SUCCESS && pSwapchainImages != NULL) {
6158 // This should never happen and is checked by param checker.
6159 if (!pCount) return result;
6160 for (uint32_t i = 0; i < *pCount; ++i) {
6161 IMAGE_NODE* image_node = new IMAGE_NODE;
6162 image_node->layout = VK_IMAGE_LAYOUT_UNDEFINED;
6163 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis75cd1c52016-01-21 10:21:04 -07006164 auto swapchain_node = dev_data->device_extensions.swapchainMap[swapchain];
6165 image_node->format = swapchain_node->createInfo.imageFormat;
6166 swapchain_node->images.push_back(pSwapchainImages[i]);
Michael Lentineabc5e922015-10-12 11:30:14 -05006167 dev_data->imageLayoutMap[pSwapchainImages[i]] = image_node;
6168 loader_platform_thread_unlock_mutex(&globalLock);
6169 }
6170 }
6171 return result;
6172}
6173
Ian Elliott05846062015-11-20 14:13:17 -07006174VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo)
Michael Lentineabc5e922015-10-12 11:30:14 -05006175{
6176 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07006177 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05006178
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006179#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentineabc5e922015-10-12 11:30:14 -05006180 if (pPresentInfo) {
Michael Lentine15a47882016-01-06 10:05:48 -06006181 for (uint32_t i=0; i < pPresentInfo->waitSemaphoreCount; ++i) {
6182 if (dev_data->semaphoreSignaledMap[pPresentInfo->pWaitSemaphores[i]]) {
6183 dev_data->semaphoreSignaledMap[pPresentInfo->pWaitSemaphores[i]] = 0;
6184 } else {
6185 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",
6186 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
Mark Youngee3f3a22016-01-25 12:18:32 -07006187 (uint64_t)(queue), (uint64_t)(pPresentInfo->pWaitSemaphores[i]));
Michael Lentine15a47882016-01-06 10:05:48 -06006188 }
6189 }
Michael Lentineabc5e922015-10-12 11:30:14 -05006190 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
Ian Elliott05846062015-11-20 14:13:17 -07006191 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(pPresentInfo->pSwapchains[i]);
6192 if (swapchain_data != dev_data->device_extensions.swapchainMap.end() && pPresentInfo->pImageIndices[i] < swapchain_data->second->images.size()) {
6193 VkImage image = swapchain_data->second->images[pPresentInfo->pImageIndices[i]];
Michael Lentineabc5e922015-10-12 11:30:14 -05006194 auto image_data = dev_data->imageLayoutMap.find(image);
6195 if (image_data != dev_data->imageLayoutMap.end()) {
Ian Elliott05846062015-11-20 14:13:17 -07006196 if (image_data->second->layout != VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07006197 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT, (uint64_t)queue, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05006198 "Images passed to present must be in layout PRESENT_SOURCE_KHR but is in %d", image_data->second->layout);
6199 }
6200 }
6201 }
6202 }
6203 }
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006204#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentineabc5e922015-10-12 11:30:14 -05006205
6206 if (VK_FALSE == skip_call)
6207 return dev_data->device_dispatch_table->QueuePresentKHR(queue, pPresentInfo);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07006208 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentineabc5e922015-10-12 11:30:14 -05006209}
6210
Michael Lentine15a47882016-01-06 10:05:48 -06006211VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImageKHR(
6212 VkDevice device,
6213 VkSwapchainKHR swapchain,
6214 uint64_t timeout,
6215 VkSemaphore semaphore,
6216 VkFence fence,
6217 uint32_t* pImageIndex)
6218{
6219 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6220 VkResult result = dev_data->device_dispatch_table->AcquireNextImageKHR(device, swapchain, timeout, semaphore, fence, pImageIndex);
6221 dev_data->semaphoreSignaledMap[semaphore] = 1;
Tobin Ehlis51b78af2016-01-06 10:27:47 -07006222 return result;
Michael Lentine15a47882016-01-06 10:05:48 -06006223}
6224
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006225VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(
6226 VkInstance instance,
6227 const VkDebugReportCallbackCreateInfoEXT* pCreateInfo,
6228 const VkAllocationCallbacks* pAllocator,
6229 VkDebugReportCallbackEXT* pMsgCallback)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006230{
Tobin Ehlis0b632332015-10-07 09:38:40 -06006231 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006232 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006233 VkResult res = pTable->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06006234 if (VK_SUCCESS == res) {
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006235 res = layer_create_msg_callback(my_data->report_data, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06006236 }
6237 return res;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006238}
6239
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006240VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006241 VkInstance instance,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006242 VkDebugReportCallbackEXT msgCallback,
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006243 const VkAllocationCallbacks* pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006244{
Tobin Ehlis0b632332015-10-07 09:38:40 -06006245 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006246 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006247 pTable->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006248 layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006249}
6250
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006251VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDebugReportMessageEXT(
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07006252 VkInstance instance,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006253 VkDebugReportFlagsEXT flags,
6254 VkDebugReportObjectTypeEXT objType,
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07006255 uint64_t object,
6256 size_t location,
6257 int32_t msgCode,
6258 const char* pLayerPrefix,
6259 const char* pMsg)
6260{
6261 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006262 my_data->instance_dispatch_table->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg);
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07006263}
6264
Chia-I Wu9ab61502015-11-06 06:42:02 +08006265VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerBegin(VkCommandBuffer commandBuffer, const char* pMarker)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006266{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006267 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006268 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
6269 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis0b632332015-10-07 09:38:40 -06006270 if (!dev_data->device_extensions.debug_marker_enabled) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07006271 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, __LINE__, DRAWSTATE_INVALID_EXTENSION, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06006272 "Attempt to use CmdDbgMarkerBegin but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06006273 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06006274 } else if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07006275 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKERBEGIN, "vkCmdDbgMarkerBegin()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006276 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006277 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006278 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerBegin(commandBuffer, pMarker);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006279}
6280
Chia-I Wu9ab61502015-11-06 06:42:02 +08006281VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerEnd(VkCommandBuffer commandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006282{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006283 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006284 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
6285 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis0b632332015-10-07 09:38:40 -06006286 if (!dev_data->device_extensions.debug_marker_enabled) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07006287 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, __LINE__, DRAWSTATE_INVALID_EXTENSION, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06006288 "Attempt to use CmdDbgMarkerEnd but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06006289 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06006290 } else if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07006291 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKEREND, "vkCmdDbgMarkerEnd()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006292 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006293 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006294 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerEnd(commandBuffer);
Jon Ashburneab34492015-06-01 09:37:38 -06006295}
6296
Chia-I Wu9ab61502015-11-06 06:42:02 +08006297VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006298{
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006299 if (!strcmp(funcName, "vkGetDeviceProcAddr"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006300 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006301 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006302 return (PFN_vkVoidFunction) vkDestroyDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006303 if (!strcmp(funcName, "vkQueueSubmit"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006304 return (PFN_vkVoidFunction) vkQueueSubmit;
Michael Lentine700b0aa2015-10-30 17:57:32 -07006305 if (!strcmp(funcName, "vkWaitForFences"))
6306 return (PFN_vkVoidFunction) vkWaitForFences;
6307 if (!strcmp(funcName, "vkGetFenceStatus"))
6308 return (PFN_vkVoidFunction) vkGetFenceStatus;
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07006309 if (!strcmp(funcName, "vkQueueWaitIdle"))
6310 return (PFN_vkVoidFunction) vkQueueWaitIdle;
6311 if (!strcmp(funcName, "vkDeviceWaitIdle"))
6312 return (PFN_vkVoidFunction) vkDeviceWaitIdle;
Michael Lentine700b0aa2015-10-30 17:57:32 -07006313 if (!strcmp(funcName, "vkGetDeviceQueue"))
6314 return (PFN_vkVoidFunction) vkGetDeviceQueue;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006315 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006316 return (PFN_vkVoidFunction) vkDestroyInstance;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006317 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006318 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006319 if (!strcmp(funcName, "vkDestroyFence"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006320 return (PFN_vkVoidFunction) vkDestroyFence;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006321 if (!strcmp(funcName, "vkDestroySemaphore"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006322 return (PFN_vkVoidFunction) vkDestroySemaphore;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006323 if (!strcmp(funcName, "vkDestroyEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006324 return (PFN_vkVoidFunction) vkDestroyEvent;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006325 if (!strcmp(funcName, "vkDestroyQueryPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006326 return (PFN_vkVoidFunction) vkDestroyQueryPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006327 if (!strcmp(funcName, "vkDestroyBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006328 return (PFN_vkVoidFunction) vkDestroyBuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006329 if (!strcmp(funcName, "vkDestroyBufferView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006330 return (PFN_vkVoidFunction) vkDestroyBufferView;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006331 if (!strcmp(funcName, "vkDestroyImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006332 return (PFN_vkVoidFunction) vkDestroyImage;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006333 if (!strcmp(funcName, "vkDestroyImageView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006334 return (PFN_vkVoidFunction) vkDestroyImageView;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006335 if (!strcmp(funcName, "vkDestroyShaderModule"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006336 return (PFN_vkVoidFunction) vkDestroyShaderModule;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006337 if (!strcmp(funcName, "vkDestroyPipeline"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006338 return (PFN_vkVoidFunction) vkDestroyPipeline;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006339 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006340 return (PFN_vkVoidFunction) vkDestroyPipelineLayout;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006341 if (!strcmp(funcName, "vkDestroySampler"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006342 return (PFN_vkVoidFunction) vkDestroySampler;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006343 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006344 return (PFN_vkVoidFunction) vkDestroyDescriptorSetLayout;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006345 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006346 return (PFN_vkVoidFunction) vkDestroyDescriptorPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006347 if (!strcmp(funcName, "vkDestroyFramebuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006348 return (PFN_vkVoidFunction) vkDestroyFramebuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006349 if (!strcmp(funcName, "vkDestroyRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006350 return (PFN_vkVoidFunction) vkDestroyRenderPass;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006351 if (!strcmp(funcName, "vkCreateBuffer"))
6352 return (PFN_vkVoidFunction) vkCreateBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006353 if (!strcmp(funcName, "vkCreateBufferView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006354 return (PFN_vkVoidFunction) vkCreateBufferView;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006355 if (!strcmp(funcName, "vkCreateImage"))
6356 return (PFN_vkVoidFunction) vkCreateImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006357 if (!strcmp(funcName, "vkCreateImageView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006358 return (PFN_vkVoidFunction) vkCreateImageView;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006359 if (!strcmp(funcName, "CreatePipelineCache"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006360 return (PFN_vkVoidFunction) vkCreatePipelineCache;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006361 if (!strcmp(funcName, "DestroyPipelineCache"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006362 return (PFN_vkVoidFunction) vkDestroyPipelineCache;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006363 if (!strcmp(funcName, "GetPipelineCacheData"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006364 return (PFN_vkVoidFunction) vkGetPipelineCacheData;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006365 if (!strcmp(funcName, "MergePipelineCaches"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006366 return (PFN_vkVoidFunction) vkMergePipelineCaches;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006367 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006368 return (PFN_vkVoidFunction) vkCreateGraphicsPipelines;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07006369 if (!strcmp(funcName, "vkCreateComputePipelines"))
6370 return (PFN_vkVoidFunction) vkCreateComputePipelines;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006371 if (!strcmp(funcName, "vkCreateSampler"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006372 return (PFN_vkVoidFunction) vkCreateSampler;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006373 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006374 return (PFN_vkVoidFunction) vkCreateDescriptorSetLayout;
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05006375 if (!strcmp(funcName, "vkCreatePipelineLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006376 return (PFN_vkVoidFunction) vkCreatePipelineLayout;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006377 if (!strcmp(funcName, "vkCreateDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006378 return (PFN_vkVoidFunction) vkCreateDescriptorPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006379 if (!strcmp(funcName, "vkResetDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006380 return (PFN_vkVoidFunction) vkResetDescriptorPool;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006381 if (!strcmp(funcName, "vkAllocateDescriptorSets"))
6382 return (PFN_vkVoidFunction) vkAllocateDescriptorSets;
Tobin Ehlise735c692015-10-08 13:13:50 -06006383 if (!strcmp(funcName, "vkFreeDescriptorSets"))
6384 return (PFN_vkVoidFunction) vkFreeDescriptorSets;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08006385 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006386 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
Mark Lobodzinski39298632015-11-18 08:38:27 -07006387 if (!strcmp(funcName, "vkCreateCommandPool"))
6388 return (PFN_vkVoidFunction) vkCreateCommandPool;
6389 if (!strcmp(funcName, "vkDestroyCommandPool"))
6390 return (PFN_vkVoidFunction) vkDestroyCommandPool;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006391 if (!strcmp(funcName, "vkResetCommandPool"))
6392 return (PFN_vkVoidFunction) vkResetCommandPool;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006393 if (!strcmp(funcName, "vkAllocateCommandBuffers"))
6394 return (PFN_vkVoidFunction) vkAllocateCommandBuffers;
Mark Lobodzinski39298632015-11-18 08:38:27 -07006395 if (!strcmp(funcName, "vkFreeCommandBuffers"))
6396 return (PFN_vkVoidFunction) vkFreeCommandBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006397 if (!strcmp(funcName, "vkBeginCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006398 return (PFN_vkVoidFunction) vkBeginCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006399 if (!strcmp(funcName, "vkEndCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006400 return (PFN_vkVoidFunction) vkEndCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006401 if (!strcmp(funcName, "vkResetCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006402 return (PFN_vkVoidFunction) vkResetCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006403 if (!strcmp(funcName, "vkCmdBindPipeline"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006404 return (PFN_vkVoidFunction) vkCmdBindPipeline;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06006405 if (!strcmp(funcName, "vkCmdSetViewport"))
6406 return (PFN_vkVoidFunction) vkCmdSetViewport;
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06006407 if (!strcmp(funcName, "vkCmdSetScissor"))
6408 return (PFN_vkVoidFunction) vkCmdSetScissor;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06006409 if (!strcmp(funcName, "vkCmdSetLineWidth"))
6410 return (PFN_vkVoidFunction) vkCmdSetLineWidth;
6411 if (!strcmp(funcName, "vkCmdSetDepthBias"))
6412 return (PFN_vkVoidFunction) vkCmdSetDepthBias;
6413 if (!strcmp(funcName, "vkCmdSetBlendConstants"))
6414 return (PFN_vkVoidFunction) vkCmdSetBlendConstants;
6415 if (!strcmp(funcName, "vkCmdSetDepthBounds"))
6416 return (PFN_vkVoidFunction) vkCmdSetDepthBounds;
6417 if (!strcmp(funcName, "vkCmdSetStencilCompareMask"))
6418 return (PFN_vkVoidFunction) vkCmdSetStencilCompareMask;
6419 if (!strcmp(funcName, "vkCmdSetStencilWriteMask"))
6420 return (PFN_vkVoidFunction) vkCmdSetStencilWriteMask;
6421 if (!strcmp(funcName, "vkCmdSetStencilReference"))
6422 return (PFN_vkVoidFunction) vkCmdSetStencilReference;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006423 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006424 return (PFN_vkVoidFunction) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06006425 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006426 return (PFN_vkVoidFunction) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006427 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006428 return (PFN_vkVoidFunction) vkCmdBindIndexBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006429 if (!strcmp(funcName, "vkCmdDraw"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006430 return (PFN_vkVoidFunction) vkCmdDraw;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006431 if (!strcmp(funcName, "vkCmdDrawIndexed"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006432 return (PFN_vkVoidFunction) vkCmdDrawIndexed;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006433 if (!strcmp(funcName, "vkCmdDrawIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006434 return (PFN_vkVoidFunction) vkCmdDrawIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006435 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006436 return (PFN_vkVoidFunction) vkCmdDrawIndexedIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006437 if (!strcmp(funcName, "vkCmdDispatch"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006438 return (PFN_vkVoidFunction) vkCmdDispatch;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006439 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006440 return (PFN_vkVoidFunction) vkCmdDispatchIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006441 if (!strcmp(funcName, "vkCmdCopyBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006442 return (PFN_vkVoidFunction) vkCmdCopyBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006443 if (!strcmp(funcName, "vkCmdCopyImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006444 return (PFN_vkVoidFunction) vkCmdCopyImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006445 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006446 return (PFN_vkVoidFunction) vkCmdCopyBufferToImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006447 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006448 return (PFN_vkVoidFunction) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006449 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006450 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006451 if (!strcmp(funcName, "vkCmdFillBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006452 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006453 if (!strcmp(funcName, "vkCmdClearColorImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006454 return (PFN_vkVoidFunction) vkCmdClearColorImage;
Chris Forbesd9be82b2015-06-22 17:21:59 +12006455 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006456 return (PFN_vkVoidFunction) vkCmdClearDepthStencilImage;
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06006457 if (!strcmp(funcName, "vkCmdClearAttachments"))
6458 return (PFN_vkVoidFunction) vkCmdClearAttachments;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006459 if (!strcmp(funcName, "vkCmdResolveImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006460 return (PFN_vkVoidFunction) vkCmdResolveImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006461 if (!strcmp(funcName, "vkCmdSetEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006462 return (PFN_vkVoidFunction) vkCmdSetEvent;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006463 if (!strcmp(funcName, "vkCmdResetEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006464 return (PFN_vkVoidFunction) vkCmdResetEvent;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006465 if (!strcmp(funcName, "vkCmdWaitEvents"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006466 return (PFN_vkVoidFunction) vkCmdWaitEvents;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006467 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006468 return (PFN_vkVoidFunction) vkCmdPipelineBarrier;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006469 if (!strcmp(funcName, "vkCmdBeginQuery"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006470 return (PFN_vkVoidFunction) vkCmdBeginQuery;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006471 if (!strcmp(funcName, "vkCmdEndQuery"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006472 return (PFN_vkVoidFunction) vkCmdEndQuery;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006473 if (!strcmp(funcName, "vkCmdResetQueryPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006474 return (PFN_vkVoidFunction) vkCmdResetQueryPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006475 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006476 return (PFN_vkVoidFunction) vkCmdWriteTimestamp;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006477 if (!strcmp(funcName, "vkCreateFramebuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006478 return (PFN_vkVoidFunction) vkCreateFramebuffer;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006479 if (!strcmp(funcName, "vkCreateShaderModule"))
6480 return (PFN_vkVoidFunction) vkCreateShaderModule;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006481 if (!strcmp(funcName, "vkCreateRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006482 return (PFN_vkVoidFunction) vkCreateRenderPass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006483 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006484 return (PFN_vkVoidFunction) vkCmdBeginRenderPass;
Chia-I Wu08accc62015-07-07 11:50:03 +08006485 if (!strcmp(funcName, "vkCmdNextSubpass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006486 return (PFN_vkVoidFunction) vkCmdNextSubpass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006487 if (!strcmp(funcName, "vkCmdEndRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006488 return (PFN_vkVoidFunction) vkCmdEndRenderPass;
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06006489 if (!strcmp(funcName, "vkCmdExecuteCommands"))
6490 return (PFN_vkVoidFunction) vkCmdExecuteCommands;
Michael Lentineb887b0a2015-12-29 14:12:11 -06006491 if (!strcmp(funcName, "vkSetEvent"))
6492 return (PFN_vkVoidFunction) vkSetEvent;
Michael Lentine7b236262015-10-23 12:41:44 -07006493 if (!strcmp(funcName, "vkMapMemory"))
6494 return (PFN_vkVoidFunction) vkMapMemory;
Michael Lentineb887b0a2015-12-29 14:12:11 -06006495 if (!strcmp(funcName, "vkGetQueryPoolResults"))
6496 return (PFN_vkVoidFunction) vkGetQueryPoolResults;
Michael Lentine15a47882016-01-06 10:05:48 -06006497 if (!strcmp(funcName, "vkBindImageMemory"))
6498 return (PFN_vkVoidFunction) vkBindImageMemory;
6499 if (!strcmp(funcName, "vkQueueBindSparse"))
6500 return (PFN_vkVoidFunction) vkQueueBindSparse;
6501 if (!strcmp(funcName, "vkCreateSemaphore"))
6502 return (PFN_vkVoidFunction) vkCreateSemaphore;
Jon Ashburneab34492015-06-01 09:37:38 -06006503
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006504 if (dev == NULL)
6505 return NULL;
6506
6507 layer_data *dev_data;
6508 dev_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map);
6509
Michael Lentineabc5e922015-10-12 11:30:14 -05006510 if (dev_data->device_extensions.wsi_enabled)
6511 {
6512 if (!strcmp(funcName, "vkCreateSwapchainKHR"))
6513 return (PFN_vkVoidFunction) vkCreateSwapchainKHR;
6514 if (!strcmp(funcName, "vkDestroySwapchainKHR"))
6515 return (PFN_vkVoidFunction) vkDestroySwapchainKHR;
6516 if (!strcmp(funcName, "vkGetSwapchainImagesKHR"))
6517 return (PFN_vkVoidFunction) vkGetSwapchainImagesKHR;
Michael Lentine15a47882016-01-06 10:05:48 -06006518 if (!strcmp(funcName, "vkAcquireNextImageKHR"))
6519 return (PFN_vkVoidFunction) vkAcquireNextImageKHR;
Michael Lentineabc5e922015-10-12 11:30:14 -05006520 if (!strcmp(funcName, "vkQueuePresentKHR"))
6521 return (PFN_vkVoidFunction) vkQueuePresentKHR;
6522 }
6523
Tobin Ehlis0b632332015-10-07 09:38:40 -06006524 VkLayerDispatchTable* pTable = dev_data->device_dispatch_table;
6525 if (dev_data->device_extensions.debug_marker_enabled)
Jon Ashburn8fd08252015-05-28 16:25:02 -06006526 {
Jon Ashburn747f2b62015-06-18 15:02:58 -06006527 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006528 return (PFN_vkVoidFunction) vkCmdDbgMarkerBegin;
Jon Ashburn747f2b62015-06-18 15:02:58 -06006529 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006530 return (PFN_vkVoidFunction) vkCmdDbgMarkerEnd;
Jon Ashburneab34492015-06-01 09:37:38 -06006531 }
6532 {
Jon Ashburn8fd08252015-05-28 16:25:02 -06006533 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006534 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006535 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburnf6b33db2015-05-05 14:22:52 -06006536 }
6537}
6538
Chia-I Wu9ab61502015-11-06 06:42:02 +08006539VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Jon Ashburnf6b33db2015-05-05 14:22:52 -06006540{
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006541 if (!strcmp(funcName, "vkGetInstanceProcAddr"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006542 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006543 if (!strcmp(funcName, "vkGetDeviceProcAddr"))
6544 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06006545 if (!strcmp(funcName, "vkCreateInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006546 return (PFN_vkVoidFunction) vkCreateInstance;
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006547 if (!strcmp(funcName, "vkCreateDevice"))
6548 return (PFN_vkVoidFunction) vkCreateDevice;
Jon Ashburn3950e1b2015-05-20 09:00:28 -06006549 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006550 return (PFN_vkVoidFunction) vkDestroyInstance;
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -06006551 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
6552 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
6553 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
6554 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
6555 if (!strcmp(funcName, "vkEnumerateDeviceLayerProperties"))
6556 return (PFN_vkVoidFunction) vkEnumerateDeviceLayerProperties;
6557 if (!strcmp(funcName, "vkEnumerateDeviceExtensionProperties"))
6558 return (PFN_vkVoidFunction) vkEnumerateDeviceExtensionProperties;
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06006559
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006560 if (instance == NULL)
6561 return NULL;
6562
6563 PFN_vkVoidFunction fptr;
6564
6565 layer_data* my_data;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006566 my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06006567 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06006568 if (fptr)
6569 return fptr;
6570
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006571 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
6572 if (pTable->GetInstanceProcAddr == NULL)
6573 return NULL;
6574 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006575}